view Small_CPU/Inc/scheduler.h @ 240:625d20070261 div-fixes-5

Improvement SPI stability/recoverability The core part of this commit comes from careful code reading. The core is the swap of Scheduler_Request_sync_with_SPI(SPI_SYNC_METHOD_SOFT) and SPI_Start_single_TxRx_with_Master(). This code is sitting in an if-clause that is triggered on SPI comms failure. Instead of blindly trying to communicate again (which will very likely fail again), first try to reset the comms link, and then try to communicate again. That simply makes more sense in this case. This is heavily tested, on 2 simple dives, and 5 very long deco schedules from the simulator (10+ hour deco's), and a lot of small simulated dives (upto 2h runtime). Of all these tests, only one long session failed after 9 out of 11h runtime. Analyzing that one failure, suggests that the RTE is looping in some error handler, which (obviously) results in a SPI comms failure as a result. I consider this not part of this change. Additionally, some more cleanup is done in this code. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author Jan Mulder <jlmulder@xs4all.nl>
date Mon, 08 Apr 2019 11:49:13 +0200
parents e4207f0aaa4b
children 2b9775f71e30
line wrap: on
line source

/**
  ******************************************************************************
  * @file    scheduler.h
  * @author  heinrichs weikamp gmbh
  * @version V0.0.5
  * @date    27-March-2014
  * @brief
  *           
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT(c) 2015 heinrichs weikamp</center></h2>
  *
  ******************************************************************************
  */ 


#ifndef SCHEDULER_H
#define SCHEDULER_H

#ifdef __cplusplus
 extern "C" {
#endif

	 
/* Includes ------------------------------------------------------------------*/
#include "data_central.h"
#include "data_exchange.h"
#include "settings.h"

/* Types -------------------------------------------------------------*/
#define SENSOR_PRESSURE_ID 0
#define MAX_SENSORS 1
 
#define SPI_SYNC_METHOD_NONE	(0u)
#define SPI_SYNC_METHOD_HARD	(1u)	/* Scheduler shall reset all counters to 0 */
#define SPI_SYNC_METHOD_SOFT	(2u)	/* Scheduler shall reset adjust counters to 100ms SPI data exchange cycle */
#define SPI_SYNC_METHOD_INVALID	(4u)

#define SCHEDULER_TICK_EXE1SEC	(980u) 	/* tick count based on cycle start which is used to trigger functions which */
										/* shall be executed once in a second (20ms before cycle restarts) */

typedef struct
{
	uint8_t mode;
	short conservatism;
	short repetitive_dive; 
	long seconds_since_last_dive;
	long no_fly_time_minutes;
	uint8_t whichGas;
	SGas aktualGas[2];
	float ceiling_from_main_CPU_mbar;
	SLifeData lifeData;
	SVpm vpm;
	SSettings settings;
	SDevice deviceData;
	SDataExchangeSlaveToMasterDeviceData deviceDataSendToMaster; 
	SDataExchangeSlaveToMaster dataSendToMaster; 
	SDataReceiveFromMaster 			dataSendToSlave; 
	_Bool demo_mode;
	uint8_t dataSendToSlaveIsValid;
	uint8_t dataSendToSlavePending;
	uint32_t sync_error_count;
	uint32_t check_sync_not_running;
	uint8_t ButtonResponsiveness[4];
	uint8_t chargerStatus;
	uint8_t	dataSendToSlaveIsNotValidCount;
	uint8_t ButtonPICdata[4];
	uint8_t accidentFlag;
	uint32_t accidentRemainingSeconds;
	uint8_t sensorError[MAX_SENSORS];
	uint8_t I2C_SystemStatus;
} SGlobal;

typedef struct
{
	long seconds_since_last_dive;
	long no_fly_time_minutes;
} SBackup;

typedef struct
{
	uint8_t counterSPIdata100msec;
	uint8_t counterPressure100msec;
	uint8_t counterCompass100msec;
	uint8_t counterAmbientLight100msec;
	uint32_t tick_execute1second;
	uint32_t tickstart;
} SScheduleCtrl;


/* Variables ---------------------------------------------------------*/
extern SGlobal global;


/* Function prototypes -----------------------------------------------*/

void initGlobals(void);

void scheduleSurfaceMode(void);
void scheduleDiveMode(void);
void scheduleSleepMode(void);
void scheduleCompassCalibrationMode(void);
void scheduleTestMode(void);

void scheduleUpdateLifeData(int32_t asynchron_milliseconds_since_last);
void scheduleSpecial_Evaluate_DataSendToSlave(void);
void scheduleUpdateDeviceDataChargerFull(void);
void scheduleUpdateDeviceDataChargerCharging(void);

void Scheduler_Request_sync_with_SPI(uint8_t SyncMethod);
void Scheduler_SyncToSPI(void);

uint8_t scheduleSetButtonResponsiveness(void);

void copyBatteryData(void);

//void scheduleSurfaceMode_test(void);
//void scheduleSleepMode_test(void);

#ifdef __cplusplus
}
#endif

#endif /* SCHEDULER_H */

/************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/