Mercurial > public > ostc4
changeset 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 |
files | Small_CPU/Src/scheduler.c |
diffstat | 1 files changed, 4 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/Small_CPU/Src/scheduler.c Mon Apr 08 10:35:29 2019 +0200 +++ b/Small_CPU/Src/scheduler.c Mon Apr 08 11:49:13 2019 +0200 @@ -48,10 +48,6 @@ /* Private types -------------------------------------------------------------*/ const SGas Air = {79,0,0,0,0}; -uint8_t testarrayindex = 0; -uint32_t testarray[256]; -uint32_t testarrayMain[256]; - /* Exported variables --------------------------------------------------------*/ SGlobal global; SDevice DeviceDataFlash; @@ -121,7 +117,7 @@ global.ButtonPICdata[2] = 0xFF; global.ButtonPICdata[3] = 0xFF; - global.I2C_SystemStatus = 0xFF; // 0x00 would be everything working + global.I2C_SystemStatus = HAL_ERROR; // 0x00 would be everything working global.lifeData.pressure_ambient_bar = INVALID_PREASURE_VALUE; global.lifeData.pressure_surface_bar = INVALID_PREASURE_VALUE; @@ -415,8 +411,8 @@ /* Try to start communication again. If exchange is stuck during execution for some reason the TX will be aborted by the * function error handler */ + Scheduler_Request_sync_with_SPI(SPI_SYNC_METHOD_SOFT); SPI_Start_single_TxRx_with_Master(); - Scheduler_Request_sync_with_SPI(SPI_SYNC_METHOD_SOFT); } } @@ -437,10 +433,8 @@ float lastPressure_bar = 0.0f; global.dataSendToMaster.mode = MODE_DIVE; global.deviceDataSendToMaster.mode = MODE_DIVE; - //uint16_t counterSecondsShallowDepth = 0; uint8_t counter_exit = 0; - Scheduler.tickstart = HAL_GetTick() - 1000; Scheduler.counterSPIdata100msec = 0; Scheduler.counterCompass100msec = 0; Scheduler.counterPressure100msec = 0; @@ -451,6 +445,7 @@ scheduleSetDate(&global.deviceData.diveCycles); global.lifeData.counterSecondsShallowDepth = 0; + Scheduler.tickstart = HAL_GetTick(); while(global.mode == MODE_DIVE) { schedule_check_resync(); @@ -1335,8 +1330,7 @@ //Supports threadsave copying!!! void copyPressureData(void) { - global.dataSendToMaster.sensorErrors = I2C1_Status(); - //uint8_t dataSendToMaster. + global.dataSendToMaster.sensorErrors = global.I2C_SystemStatus; uint8_t boolPressureData = !global.dataSendToMaster.boolPressureData; global.dataSendToMaster.data[boolPressureData].temperature = get_temperature(); global.dataSendToMaster.data[boolPressureData].pressure_mbar = get_pressure_mbar();