Mercurial > public > ostc4
changeset 220:e524a824d8f2 Improve_IPC_Sync
Added schedule point for functions executed once in a second
SPI communication takes place every 100ms triggered by the master (main). Synchronisation is done using the SPI RX complete callback which is called ~4ms after communication was started. In the previous implementation this could happen in parallel to usage of data. To solve this potential problem the execution of functions called once a second was moved from 1000ms to 980ms giving a 20ms window for execution.
author | ideenmodellierer |
---|---|
date | Sun, 31 Mar 2019 15:49:47 +0200 |
parents | f9b17e898a7a |
children | 486dddfba7ce |
files | Small_CPU/Inc/scheduler.h Small_CPU/Src/scheduler.c |
diffstat | 2 files changed, 32 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/Small_CPU/Inc/scheduler.h Sun Mar 31 15:44:56 2019 +0200 +++ b/Small_CPU/Inc/scheduler.h Sun Mar 31 15:49:47 2019 +0200 @@ -37,6 +37,9 @@ #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; @@ -82,6 +85,7 @@ uint8_t counterPressure100msec; uint8_t counterCompass100msec; uint8_t counterAmbientLight100msec; + uint32_t tick_execute1second; uint32_t tickstart; } SScheduleCtrl;
--- a/Small_CPU/Src/scheduler.c Sun Mar 31 15:44:56 2019 +0200 +++ b/Small_CPU/Src/scheduler.c Sun Mar 31 15:49:47 2019 +0200 @@ -458,7 +458,6 @@ { uint32_t ticksdiff = 0; uint32_t lasttick = 0; - uint8_t counterAscentRate = 0; float lastPressure_bar = 0.0f; global.dataSendToMaster.mode = MODE_DIVE; @@ -471,6 +470,7 @@ Scheduler.counterCompass100msec = 0; Scheduler.counterPressure100msec = 0; Scheduler.counterAmbientLight100msec = 0; + Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC; global.deviceData.diveCycles.value_int32++; scheduleSetDate(&global.deviceData.diveCycles); @@ -542,12 +542,10 @@ Scheduler.counterAmbientLight100msec++; } - //Evaluate tissues, toxic data, vpm, etc. once a second - if(ticksdiff >= 1000) + //Evaluate tissues, toxic data, vpm, etc. once a second + if(ticksdiff >= Scheduler.tick_execute1second) { - /* reset counter */ - Scheduler.tickstart = HAL_GetTick(); - + Scheduler.tick_execute1second = 0xFFFFFFFF; /* execute once only in the second cycle */ if(global.dataSendToSlave.diveModeInfo != DIVEMODE_Apnea) { scheduleUpdateLifeData(0); // includes tissues @@ -642,10 +640,16 @@ init_pressure(); } } + } + if(ticksdiff >= 1000) + { + /* reset counter */ + Scheduler.tickstart = HAL_GetTick(); Scheduler.counterSPIdata100msec = 0; Scheduler.counterCompass100msec = 0; Scheduler.counterPressure100msec = 0; Scheduler.counterAmbientLight100msec = 0; + Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC; } } } @@ -735,7 +739,6 @@ - void scheduleSurfaceMode(void) { @@ -746,6 +749,7 @@ Scheduler.counterCompass100msec = 0; Scheduler.counterPressure100msec = 0; Scheduler.counterAmbientLight100msec = 0; + Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC; global.dataSendToMaster.mode = MODE_SURFACE; global.deviceDataSendToMaster.mode = MODE_SURFACE; @@ -762,14 +766,14 @@ setButtonsNow = 0; } - //Evaluate received data at 10 ms, 110 ms, 210 ms,... + /* Evaluate received data at 10 ms, 110 ms, 210 ms,... duration ~<1ms */ if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) { SPI_Evaluate_RX_Data(); Scheduler.counterSPIdata100msec++; } - //Evaluate pressure at 20 ms, 120 ms, 220 ms,... + /* Evaluate pressure at 20 ms, 120 ms, 220 ms,... duration ~22ms] */ if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20) { global.check_sync_not_running++; @@ -783,7 +787,7 @@ global.mode = MODE_DIVE; } - //Evaluate compass data at 50 ms, 150 ms, 250 ms,... + /* Evaluate compass data at 50 ms, 150 ms, 250 ms,... duration ~5ms */ if(ticksdiff >= Scheduler.counterCompass100msec * 100 + 50) { compass_read(); @@ -793,19 +797,20 @@ Scheduler.counterCompass100msec++; } - //evaluate compass data at 70 ms, 170 ms, 270 ms,... + /* evaluate compass data at 70 ms, 170 ms, 270 ms,... duration <1ms */ if(ticksdiff >= Scheduler.counterAmbientLight100msec * 100 + 70) { adc_ambient_light_sensor_get_data(); copyAmbientLightData(); Scheduler.counterAmbientLight100msec++; } - //Evaluate tissues, toxic data, etc. once a second - if(ticksdiff >= 1000) + + + + /* Evaluate tissues, toxic data, etc. once a second... duration ~1ms */ + if(ticksdiff >= Scheduler.tick_execute1second) { - //Set back tick counter - Scheduler.tickstart = HAL_GetTick(); - + Scheduler.tick_execute1second = 0xFFFFFFFF; if(clearDecoNow) { decom_reset_with_1000mbar(&global.lifeData); ///< this should almost reset desaturation time @@ -867,10 +872,17 @@ init_pressure(); } } + } + + if(ticksdiff >= 1000) + { + //Set back tick counter + Scheduler.tickstart = HAL_GetTick(); Scheduler.counterSPIdata100msec = 0; Scheduler.counterCompass100msec = 0; Scheduler.counterPressure100msec = 0; Scheduler.counterAmbientLight100msec = 0; + Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC; } } }