comparison Small_CPU/Src/scheduler.c @ 331:b4c578caaafb I2C_Improvment

Added plausibility check for pressure values In case of I2C communication problems at startup the dc jumped into dive mode with depth up to 300m. As no CRC is applied a bit flip may also occure during normal operation without detection => added a plausibility check if last measured value fits to the last measurements
author ideenmodellierer
date Wed, 17 Jul 2019 22:43:51 +0200
parents 95928ef3986f
children b6a59e93cc91
comparison
equal deleted inserted replaced
330:2defc8cd93ce 331:b4c578caaafb
615 // new hw 170523 615 // new hw 170523
616 if(global.I2C_SystemStatus != HAL_OK) 616 if(global.I2C_SystemStatus != HAL_OK)
617 { 617 {
618 MX_I2C1_TestAndClear(); 618 MX_I2C1_TestAndClear();
619 MX_I2C1_Init(); 619 MX_I2C1_Init();
620 if(!is_init_pressure_done()) 620 init_pressure();
621 {
622 init_pressure();
623 }
624 } 621 }
625 } 622 }
626 if(ticksdiff >= 1000) 623 if(ticksdiff >= 1000)
627 { 624 {
628 /* reset counter */ 625 /* reset counter */
844 copyCnsAndOtuData(); 841 copyCnsAndOtuData();
845 copyTimeData(); 842 copyTimeData();
846 copyBatteryData(); 843 copyBatteryData();
847 copyDeviceData(); 844 copyDeviceData();
848 845
849 // new hw 170523 846 /* check if I2C is not up an running and try to reactivate if necessary. Also do initialization if problem occured during startup */
850 if(global.I2C_SystemStatus != HAL_OK) 847 if(global.I2C_SystemStatus != HAL_OK)
851 { 848 {
852 MX_I2C1_TestAndClear(); 849 MX_I2C1_TestAndClear();
853 MX_I2C1_Init(); 850 MX_I2C1_Init();
854 if(!is_init_pressure_done()) 851 if(global.I2C_SystemStatus == HAL_OK)
855 { 852 {
856 init_pressure(); 853 init_pressure();
854 if(is_init_pressure_done()) /* Init surface data with initial measurement */
855 {
856 init_surface_ring();
857 }
858
859 if(!battery_gas_gauge_CheckConfigOK())
860 {
861 init_battery_gas_gauge();
862 }
857 } 863 }
858 } 864 }
859 } 865 }
860 866
861 if(ticksdiff >= 1000) 867 if(ticksdiff >= 1000)
995 secondsCount += 2; 1001 secondsCount += 2;
996 1002
997 MX_I2C1_Init(); 1003 MX_I2C1_Init();
998 pressure_sensor_get_pressure_raw(); 1004 pressure_sensor_get_pressure_raw();
999 1005
1006 /* check if I2C is not up an running and try to reactivate if necessary. Also do initialization if problem occured during startup */
1007 if(global.I2C_SystemStatus != HAL_OK)
1008 {
1009 MX_I2C1_TestAndClear();
1010 MX_I2C1_Init();
1011 if(global.I2C_SystemStatus == HAL_OK)
1012 {
1013 init_pressure();
1014 }
1015 }
1016
1000 if(secondsCount >= 30) 1017 if(secondsCount >= 30)
1001 { 1018 {
1002 pressure_sensor_get_temperature_raw(); 1019 pressure_sensor_get_temperature_raw();
1003 battery_gas_gauge_get_data(); 1020 battery_gas_gauge_get_data();
1004 // ReInit_battery_charger_status_pins(); 1021 // ReInit_battery_charger_status_pins();
1560 } 1577 }
1561 1578
1562 /* same as in data_central.c */ 1579 /* same as in data_central.c */
1563 _Bool is_ambient_pressure_close_to_surface(SLifeData *lifeData) 1580 _Bool is_ambient_pressure_close_to_surface(SLifeData *lifeData)
1564 { 1581 {
1582 if(lifeData->pressure_ambient_bar == INVALID_PREASURE_VALUE) /* as long as no valid data is available expect we are close to surface */
1583 {
1584 return true;
1585 }
1565 if (lifeData->pressure_ambient_bar > 1.16) 1586 if (lifeData->pressure_ambient_bar > 1.16)
1566 return false; 1587 return false;
1567 else if(lifeData->pressure_ambient_bar < (lifeData->pressure_surface_bar + 0.1f)) // hw 161121 now 1 mter, before 0.04f 1588 else if(lifeData->pressure_ambient_bar < (lifeData->pressure_surface_bar + 0.1f)) // hw 161121 now 1 mter, before 0.04f
1568 return true; 1589 return true;
1569 else 1590 else