comparison Small_CPU/Src/scheduler.c @ 244:c20c73b0d034

Merged in janlmulder/ostc4/div-fixes-5 (pull request #15) Improvement SPI stability/recoverability and cleanup, and trivial bugfixes
author heinrichsweikamp <bitbucket@heinrichsweikamp.com>
date Tue, 09 Apr 2019 08:52:44 +0000
parents 625d20070261
children b3685fbada3b
comparison
equal deleted inserted replaced
236:ad6ddc4aabcd 244:c20c73b0d034
46 #define INVALID_PREASURE_VALUE (100.0F) 46 #define INVALID_PREASURE_VALUE (100.0F)
47 47
48 /* Private types -------------------------------------------------------------*/ 48 /* Private types -------------------------------------------------------------*/
49 const SGas Air = {79,0,0,0,0}; 49 const SGas Air = {79,0,0,0,0};
50 50
51 uint8_t testarrayindex = 0;
52 uint32_t testarray[256];
53 uint32_t testarrayMain[256];
54
55 /* Exported variables --------------------------------------------------------*/ 51 /* Exported variables --------------------------------------------------------*/
56 SGlobal global; 52 SGlobal global;
57 SDevice DeviceDataFlash; 53 SDevice DeviceDataFlash;
58 uint8_t deviceDataFlashValid = 0; 54 uint8_t deviceDataFlashValid = 0;
59 uint8_t deviceDataSubSeconds = 0; 55 uint8_t deviceDataSubSeconds = 0;
119 global.ButtonPICdata[0] = 0xFF; 115 global.ButtonPICdata[0] = 0xFF;
120 global.ButtonPICdata[1] = 0xFF; 116 global.ButtonPICdata[1] = 0xFF;
121 global.ButtonPICdata[2] = 0xFF; 117 global.ButtonPICdata[2] = 0xFF;
122 global.ButtonPICdata[3] = 0xFF; 118 global.ButtonPICdata[3] = 0xFF;
123 119
124 global.I2C_SystemStatus = 0xFF; // 0x00 would be everything working 120 global.I2C_SystemStatus = HAL_ERROR; // 0x00 would be everything working
125 121
126 global.lifeData.pressure_ambient_bar = INVALID_PREASURE_VALUE; 122 global.lifeData.pressure_ambient_bar = INVALID_PREASURE_VALUE;
127 global.lifeData.pressure_surface_bar = INVALID_PREASURE_VALUE; 123 global.lifeData.pressure_surface_bar = INVALID_PREASURE_VALUE;
128 decom_reset_with_1000mbar(&global.lifeData); 124 decom_reset_with_1000mbar(&global.lifeData);
129 125
413 global.sync_error_count++; 409 global.sync_error_count++;
414 410
415 /* Try to start communication again. If exchange is stuck during execution for some reason the TX will be aborted by the 411 /* Try to start communication again. If exchange is stuck during execution for some reason the TX will be aborted by the
416 * function error handler 412 * function error handler
417 */ 413 */
414 Scheduler_Request_sync_with_SPI(SPI_SYNC_METHOD_SOFT);
418 SPI_Start_single_TxRx_with_Master(); 415 SPI_Start_single_TxRx_with_Master();
419 Scheduler_Request_sync_with_SPI(SPI_SYNC_METHOD_SOFT);
420 } 416 }
421 } 417 }
422 418
423 419
424 /** 420 /**
435 uint32_t lasttick = 0; 431 uint32_t lasttick = 0;
436 uint8_t counterAscentRate = 0; 432 uint8_t counterAscentRate = 0;
437 float lastPressure_bar = 0.0f; 433 float lastPressure_bar = 0.0f;
438 global.dataSendToMaster.mode = MODE_DIVE; 434 global.dataSendToMaster.mode = MODE_DIVE;
439 global.deviceDataSendToMaster.mode = MODE_DIVE; 435 global.deviceDataSendToMaster.mode = MODE_DIVE;
440 //uint16_t counterSecondsShallowDepth = 0;
441 uint8_t counter_exit = 0; 436 uint8_t counter_exit = 0;
442 437
443 Scheduler.tickstart = HAL_GetTick() - 1000;
444 Scheduler.counterSPIdata100msec = 0; 438 Scheduler.counterSPIdata100msec = 0;
445 Scheduler.counterCompass100msec = 0; 439 Scheduler.counterCompass100msec = 0;
446 Scheduler.counterPressure100msec = 0; 440 Scheduler.counterPressure100msec = 0;
447 Scheduler.counterAmbientLight100msec = 0; 441 Scheduler.counterAmbientLight100msec = 0;
448 Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC; 442 Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC;
449 443
450 global.deviceData.diveCycles.value_int32++; 444 global.deviceData.diveCycles.value_int32++;
451 scheduleSetDate(&global.deviceData.diveCycles); 445 scheduleSetDate(&global.deviceData.diveCycles);
452 global.lifeData.counterSecondsShallowDepth = 0; 446 global.lifeData.counterSecondsShallowDepth = 0;
453 447
448 Scheduler.tickstart = HAL_GetTick();
454 while(global.mode == MODE_DIVE) 449 while(global.mode == MODE_DIVE)
455 { 450 {
456 schedule_check_resync(); 451 schedule_check_resync();
457 lasttick = HAL_GetTick(); 452 lasttick = HAL_GetTick();
458 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick); 453 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick);
1333 1328
1334 1329
1335 //Supports threadsave copying!!! 1330 //Supports threadsave copying!!!
1336 void copyPressureData(void) 1331 void copyPressureData(void)
1337 { 1332 {
1338 global.dataSendToMaster.sensorErrors = I2C1_Status(); 1333 global.dataSendToMaster.sensorErrors = global.I2C_SystemStatus;
1339 //uint8_t dataSendToMaster.
1340 uint8_t boolPressureData = !global.dataSendToMaster.boolPressureData; 1334 uint8_t boolPressureData = !global.dataSendToMaster.boolPressureData;
1341 global.dataSendToMaster.data[boolPressureData].temperature = get_temperature(); 1335 global.dataSendToMaster.data[boolPressureData].temperature = get_temperature();
1342 global.dataSendToMaster.data[boolPressureData].pressure_mbar = get_pressure_mbar(); 1336 global.dataSendToMaster.data[boolPressureData].pressure_mbar = get_pressure_mbar();
1343 global.dataSendToMaster.data[boolPressureData].surface_mbar = get_surface_mbar(); 1337 global.dataSendToMaster.data[boolPressureData].surface_mbar = get_surface_mbar();
1344 global.dataSendToMaster.data[boolPressureData].ascent_rate_meter_per_min = global.lifeData.ascent_rate_meter_per_min; 1338 global.dataSendToMaster.data[boolPressureData].ascent_rate_meter_per_min = global.lifeData.ascent_rate_meter_per_min;