Mercurial > public > ostc4
annotate Small_CPU/Src/scheduler.c @ 995:768ed327ee69 GasConsumption
update built for test divers
| author | heinrichsweikamp |
|---|---|
| date | Sun, 27 Apr 2025 10:14:25 +0200 |
| parents | d9290c76b840 |
| children | c386ae6635e4 |
| rev | line source |
|---|---|
| 38 | 1 /** |
| 2 ****************************************************************************** | |
| 3 * @file scheduler.c | |
| 4 * @author heinrichs weikamp gmbh | |
| 5 * @date 27-March-2014 | |
| 6 * @version V0.0.6 | |
| 7 * @since 18-June-2015 | |
| 8 * @brief the main part except for base.c | |
| 9 * | |
| 10 @verbatim | |
| 11 ============================================================================== | |
| 12 ##### How to use ##### | |
| 13 ============================================================================== | |
| 14 @endverbatim | |
| 15 ****************************************************************************** | |
| 16 * @attention | |
| 17 * | |
| 18 * <h2><center>© COPYRIGHT(c) 2015 heinrichs weikamp</center></h2> | |
| 19 * | |
| 20 ****************************************************************************** | |
| 21 */ | |
| 22 | |
| 23 | |
| 24 /* Includes ------------------------------------------------------------------*/ | |
| 25 #include <string.h> | |
| 26 #include "baseCPU2.h" | |
| 27 #include "stm32f4xx_hal.h" | |
| 28 #include "i2c.h" | |
| 29 #include "scheduler.h" | |
| 30 #include "pressure.h" | |
| 31 #include "compass.h" | |
| 32 #include "batteryGasGauge.h" | |
| 33 #include "batteryCharger.h" | |
| 34 #include "spi.h" | |
| 35 #include "rtc.h" | |
| 36 #include "dma.h" | |
| 37 #include "adc.h" | |
| 936 | 38 #include "gpio.h" |
| 38 | 39 #include "calc_crush.h" |
| 40 #include "stm32f4xx_hal_rtc_ex.h" | |
| 41 #include "decom.h" | |
| 42 #include "tm_stm32f4_otp.h" | |
|
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
43 #include "externalInterface.h" |
| 662 | 44 #include "uart.h" |
| 932 | 45 #include "uart_Internal.h" |
|
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
881
diff
changeset
|
46 #include "GNSS.h" |
|
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
881
diff
changeset
|
47 #include "uartProtocol_GNSS.h" |
| 881 | 48 #include "math.h" |
|
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
881
diff
changeset
|
49 #include "configuration.h" |
| 38 | 50 |
|
414
6886aeeca454
Added compile switch for restoring of last known date after power lost:
ideenmodellierer
parents:
409
diff
changeset
|
51 /* uncomment to enable restoting of last known date in case of a power loss (RTC looses timing data) */ |
|
6886aeeca454
Added compile switch for restoring of last known date after power lost:
ideenmodellierer
parents:
409
diff
changeset
|
52 /* #define RESTORE_LAST_KNOWN_DATE */ |
| 38 | 53 |
| 475 | 54 #define INVALID_PREASURE_VALUE (0.0f) |
|
338
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
55 #define START_DIVE_MOUNTAIN_MODE_BAR (0.88f) |
|
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
56 #define START_DIVE_IMMEDIATLY_BAR (1.16f) |
| 135 | 57 |
| 881 | 58 /* Ascent rate calculation */ |
| 59 typedef enum | |
| 60 { | |
| 61 ASCENT_NONE = 0, | |
| 62 ASCENT_RISING, | |
| 63 ASCENT_FALLING, | |
| 64 } AscentStates_t; | |
| 65 | |
| 38 | 66 /* Private types -------------------------------------------------------------*/ |
| 67 const SGas Air = {79,0,0,0,0}; | |
| 68 | |
| 69 /* Exported variables --------------------------------------------------------*/ | |
| 70 SGlobal global; | |
| 71 SDevice DeviceDataFlash; | |
| 72 uint8_t deviceDataFlashValid = 0; | |
| 73 uint8_t deviceDataSubSeconds = 0; | |
| 74 | |
| 75 /* Private variables ---------------------------------------------------------*/ | |
|
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
76 static uint16_t ManualExitDiveCounter = 0; /* The computer will exit dive mode in shallow area immediately. Increase depth to restart dive while counter is active */ |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
77 |
| 38 | 78 /* can be lost while in sleep */ |
| 79 uint8_t clearDecoNow = 0; | |
| 80 uint8_t setButtonsNow = 0; | |
| 81 | |
| 82 /* has to be in SRAM2 */ | |
| 83 uint8_t secondsCount = 0; | |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
84 |
| 207 | 85 static uint8_t dospisync = SPI_SYNC_METHOD_NONE; |
| 86 | |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
87 SScheduleCtrl Scheduler; |
| 38 | 88 |
| 89 /* Private function prototypes -----------------------------------------------*/ | |
| 90 | |
| 91 _Bool vpm_crush2(void); | |
| 92 void scheduleUpdateDeviceData(void); | |
| 93 long get_nofly_time_minutes(void); | |
| 94 void copyActualGas(SGas gas); | |
| 95 void copyPressureData(void); | |
| 96 void copyCnsAndOtuData(void); | |
| 97 void copyTimeData(void); | |
| 98 void copyCompassData(void); | |
| 99 void copyCompassDataDuringCalibration(int16_t dx, int16_t dy, int16_t dz); | |
| 100 void copyAmbientLightData(void); | |
| 101 void copyTissueData(void); | |
| 102 void copyVpmCrushingData(void); | |
| 103 void copyDeviceData(void); | |
| 104 void copyPICdata(void); | |
|
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
105 void copyExtADCdata(); |
| 662 | 106 void copyExtCO2data(); |
|
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
881
diff
changeset
|
107 void copyGNSSdata(void); |
|
230
3973208c4a20
cleanup: make return void when never used
Jan Mulder <jlmulder@xs4all.nl>
parents:
220
diff
changeset
|
108 static void schedule_update_timer_helper(int8_t thisSeconds); |
| 881 | 109 static void evaluateAscentSpeed(void); |
| 38 | 110 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow); |
| 111 | |
| 112 void scheduleSetDate(SDeviceLine *line); | |
| 113 | |
| 114 /* Exported functions --------------------------------------------------------*/ | |
| 115 | |
| 116 void initGlobals(void) | |
| 117 { | |
|
231
f6961efb3794
cleanup: do not re-implement a standard function
Jan Mulder <jlmulder@xs4all.nl>
parents:
230
diff
changeset
|
118 bzero(&global, sizeof(SGlobal)); |
| 38 | 119 |
| 120 global.dataSendToSlavePending = 0; | |
| 121 global.dataSendToSlaveIsValid = 1; | |
| 122 global.dataSendToSlaveIsNotValidCount = 0; | |
| 123 | |
| 124 global.mode = MODE_POWERUP; | |
| 125 global.repetitive_dive = 0; | |
| 126 global.conservatism = 0; | |
| 127 global.whichGas = 0; | |
| 128 global.aktualGas[0] = Air; | |
| 129 global.lifeData.actualGas = global.aktualGas[0]; | |
| 130 | |
| 475 | 131 const uint8_t button_standard_sensitivity = 51; /* 51 equals a percentage of 85% which was the default value before */ |
| 38 | 132 global.ButtonResponsiveness[0] = button_standard_sensitivity; |
| 133 global.ButtonResponsiveness[1] = button_standard_sensitivity; | |
| 134 global.ButtonResponsiveness[2] = button_standard_sensitivity; | |
| 135 global.ButtonResponsiveness[3] = button_standard_sensitivity; | |
| 136 | |
| 137 global.ButtonPICdata[0] = 0xFF; | |
| 138 global.ButtonPICdata[1] = 0xFF; | |
| 139 global.ButtonPICdata[2] = 0xFF; | |
| 140 global.ButtonPICdata[3] = 0xFF; | |
| 141 | |
|
240
625d20070261
Improvement SPI stability/recoverability
Jan Mulder <jlmulder@xs4all.nl>
parents:
231
diff
changeset
|
142 global.I2C_SystemStatus = HAL_ERROR; // 0x00 would be everything working |
| 38 | 143 |
| 668 | 144 global.lifeData.battery_voltage = BATTERY_DEFAULT_VOLTAGE; |
| 145 | |
| 135 | 146 global.lifeData.pressure_ambient_bar = INVALID_PREASURE_VALUE; |
| 147 global.lifeData.pressure_surface_bar = INVALID_PREASURE_VALUE; | |
| 38 | 148 decom_reset_with_1000mbar(&global.lifeData); |
| 149 | |
| 150 global.demo_mode = 0; | |
| 151 | |
| 152 for(int i = 0; i < MAX_SENSORS; i++) | |
| 153 { | |
| 154 global.sensorError[i] = HAL_OK; // HAL_OK = 0; | |
| 155 } | |
| 156 | |
| 157 global.dataSendToMaster.RTE_VERSION_high = firmwareVersionHigh();//RTE_VERSION_HIGH;; | |
| 158 global.dataSendToMaster.RTE_VERSION_low = firmwareVersionLow();//RTE_VERSION_LOW;; | |
| 859 | 159 global.dataSendToMaster.chargeStatus = CHARGER_off; |
| 38 | 160 |
| 475 | 161 global.dataSendToMaster.power_on_reset = 0; |
| 38 | 162 global.dataSendToMaster.header.checkCode[0] = 0xA1; |
|
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
163 global.dataSendToMaster.header.checkCode[1] = SPI_RX_STATE_OFFLINE; |
| 38 | 164 global.dataSendToMaster.header.checkCode[2] = 0xA3; |
| 165 global.dataSendToMaster.header.checkCode[3] = 0xA4; | |
| 166 global.dataSendToMaster.footer.checkCode[3] = 0xE4; | |
| 167 global.dataSendToMaster.footer.checkCode[2] = 0xE3; | |
| 168 global.dataSendToMaster.footer.checkCode[1] = 0xE2; | |
| 169 global.dataSendToMaster.footer.checkCode[0] = 0xE1; | |
| 170 global.dataSendToMaster.sensorErrors = 0; | |
| 171 | |
| 942 | 172 global.dataSendToMaster.data[0].gnssInfo.coord.fLat = 0.0; |
| 173 global.dataSendToMaster.data[0].gnssInfo.coord.fLon = 0.0; | |
| 174 global.dataSendToMaster.data[0].gnssInfo.fixType = 0; | |
| 175 global.dataSendToMaster.data[0].gnssInfo.numSat = 0; | |
| 176 | |
| 38 | 177 global.sync_error_count = 0; |
| 178 global.check_sync_not_running = 0; | |
| 179 | |
| 180 global.deviceDataSendToMaster.RTE_VERSION_high = firmwareVersionHigh();//RTE_VERSION_HIGH; | |
| 181 global.deviceDataSendToMaster.RTE_VERSION_low = firmwareVersionLow();//RTE_VERSION_LOW; | |
| 859 | 182 global.deviceDataSendToMaster.chargeStatus = CHARGER_off; |
| 38 | 183 |
| 475 | 184 global.deviceDataSendToMaster.power_on_reset = 0; |
| 38 | 185 global.deviceDataSendToMaster.header.checkCode[0] = 0xDF; |
| 186 global.deviceDataSendToMaster.header.checkCode[1] = 0xDE; | |
| 187 global.deviceDataSendToMaster.header.checkCode[2] = 0xDD; | |
| 188 global.deviceDataSendToMaster.header.checkCode[3] = 0xDC; | |
| 189 global.deviceDataSendToMaster.footer.checkCode[3] = 0xE4; | |
| 190 global.deviceDataSendToMaster.footer.checkCode[2] = 0xE3; | |
| 191 global.deviceDataSendToMaster.footer.checkCode[1] = 0xE2; | |
| 192 global.deviceDataSendToMaster.footer.checkCode[0] = 0xE1; | |
| 193 | |
| 194 global.dataSendToSlave.getDeviceDataNow = 0; | |
| 195 | |
| 196 global.deviceData.batteryChargeCompleteCycles.value_int32 = 0; | |
| 197 global.deviceData.batteryChargeCycles.value_int32 = 0; | |
| 198 global.deviceData.depthMaximum.value_int32 = 0; | |
| 199 global.deviceData.diveCycles.value_int32 = 0; | |
| 200 global.deviceData.hoursOfOperation.value_int32 = 0; | |
| 201 global.deviceData.temperatureMaximum.value_int32 = INT32_MIN; | |
| 202 global.deviceData.temperatureMinimum.value_int32 = INT32_MAX; | |
| 203 global.deviceData.voltageMinimum.value_int32 = INT32_MAX; | |
|
148
ee744c7160ce
Use SPI TX callback to synchronize to main CPU
Ideenmodellierer
parents:
142
diff
changeset
|
204 |
|
265
a91d99265884
Increase SPI com timeout for cold start and wake up
ideenmodellierer
parents:
264
diff
changeset
|
205 Scheduler.communicationTimeout = SPI_COM_TIMEOUT_START; |
| 207 | 206 Scheduler_Request_sync_with_SPI(SPI_SYNC_METHOD_HARD); |
| 38 | 207 } |
| 208 | |
|
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
209 void reinitGlobals(void) |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
210 { |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
211 global.dataSendToSlavePending = 0; |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
212 global.dataSendToSlaveIsValid = 0; |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
213 global.dataSendToSlaveIsNotValidCount = 0; |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
214 global.sync_error_count = 0; |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
215 global.check_sync_not_running = 0; |
|
265
a91d99265884
Increase SPI com timeout for cold start and wake up
ideenmodellierer
parents:
264
diff
changeset
|
216 Scheduler.communicationTimeout = SPI_COM_TIMEOUT_START; |
|
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
217 } |
| 38 | 218 |
| 219 void scheduleSpecial_Evaluate_DataSendToSlave(void) | |
| 220 { | |
| 104 | 221 //TEMPORARY fix for compass calibration. |
| 222 //TODO: Fix I2C timeout for complete solving problem. | |
| 223 if(global.mode==MODE_CALIB){ | |
| 224 return; | |
| 225 } | |
| 90 | 226 |
| 88 | 227 global.dataSendToSlavePending = 0; |
| 228 if(!global.dataSendToSlaveIsValid) return; | |
| 38 | 229 |
| 230 global.dataSendToMaster.confirmRequest.uw = 0; | |
| 231 | |
| 232 if(TM_OTP_Read(0,0) == 0xFF) | |
| 233 { | |
| 234 if(global.dataSendToSlave.revisionHardware == (global.dataSendToSlave.revisionCRCx0x7A ^ 0x7A)) | |
| 235 TM_OTP_Write(0,0,global.dataSendToSlave.revisionHardware); | |
| 236 } | |
| 237 | |
| 238 if(global.dataSendToSlave.setAccidentFlag) | |
| 239 { | |
| 240 global.dataSendToMaster.confirmRequest.ub.accident = 1; | |
| 241 global.deviceData.diveAccident.value_int32 = global.dataSendToSlave.setAccidentFlag; | |
| 242 scheduleSetDate(&global.deviceData.diveAccident); | |
| 243 global.accidentFlag |= global.dataSendToSlave.setAccidentFlag; | |
| 244 if(global.accidentFlag == ACCIDENT_CNS) // LVL1 | |
| 245 global.accidentRemainingSeconds = 2*60*60; | |
| 246 else | |
| 247 global.accidentRemainingSeconds = 24*60*60; | |
| 248 } | |
| 249 | |
| 250 if(global.dataSendToSlave.setTimeNow) | |
| 251 { | |
| 252 global.dataSendToMaster.confirmRequest.ub.time = 1; | |
| 253 RTC_SetTime(global.dataSendToSlave.data.newTime); | |
| 254 schedule_update_timer_helper(0); | |
| 255 } | |
| 256 | |
| 257 if(global.dataSendToSlave.setDateNow) | |
| 258 { | |
| 259 global.dataSendToMaster.confirmRequest.ub.date = 1; | |
| 260 RTC_SetDate(global.dataSendToSlave.data.newDate); | |
| 261 schedule_update_timer_helper(0); | |
| 262 } | |
| 263 | |
| 264 if(global.dataSendToSlave.calibrateCompassNow) | |
| 265 { | |
| 266 global.dataSendToMaster.confirmRequest.ub.compass = 1; | |
| 267 global.mode = MODE_CALIB; | |
| 268 } | |
| 269 | |
| 270 if(global.dataSendToSlave.clearDecoNow) | |
| 271 { | |
| 272 global.dataSendToMaster.confirmRequest.ub.clearDeco = 1; | |
| 273 clearDecoNow = 1; | |
| 274 } | |
| 275 | |
| 276 if(global.dataSendToSlave.setButtonSensitivityNow) | |
| 277 { | |
| 278 global.dataSendToMaster.confirmRequest.ub.button = 1; | |
| 279 global.ButtonResponsiveness[0] = global.dataSendToSlave.data.buttonResponsiveness[0]; | |
| 280 global.ButtonResponsiveness[1] = global.dataSendToSlave.data.buttonResponsiveness[1]; | |
| 281 global.ButtonResponsiveness[2] = global.dataSendToSlave.data.buttonResponsiveness[2]; | |
| 282 global.ButtonResponsiveness[3] = global.dataSendToSlave.data.buttonResponsiveness[3]; | |
| 283 setButtonsNow = 1; | |
| 284 } | |
| 285 | |
| 286 if(global.dataSendToSlave.setBatteryGaugeNow) | |
| 287 { | |
| 104 | 288 if(global.mode!=MODE_CALIB){ |
| 38 | 289 global.dataSendToMaster.confirmRequest.ub.batterygauge = 1; |
| 290 battery_gas_gauge_set(global.dataSendToSlave.data.newBatteryGaugePercentageFloat); | |
| 104 | 291 } |
| 38 | 292 } |
| 293 | |
|
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
294 if(global.dataSendToSlave.setEndDive) |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
295 { |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
296 ManualExitDiveCounter = 30 * 60; /* This will cause the computer to leave dive mode if in shallow area and increase the depth to enter dive mode for the next 30 minutes */ |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
297 } |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
298 |
| 38 | 299 if((global.mode == MODE_SURFACE) && (global.dataSendToSlave.mode == MODE_SHUTDOWN)) |
| 300 { | |
| 301 global.mode = MODE_SHUTDOWN; | |
| 302 } | |
| 303 | |
| 304 if(global.mode == MODE_DIVE) | |
| 305 { | |
| 306 copyActualGas(global.dataSendToSlave.data.actualGas); | |
| 307 } | |
| 308 else | |
| 309 { | |
| 310 copyActualGas(Air); | |
| 311 global.settings.divetimeToCreateLogbook = global.dataSendToSlave.data.divetimeToCreateLogbook; | |
| 312 global.settings.timeoutDiveReachedZeroDepth = global.dataSendToSlave.data.timeoutDiveReachedZeroDepth; | |
| 313 } | |
| 314 | |
| 315 /* for simulation / testing */ | |
| 316 global.ceiling_from_main_CPU_mbar = global.dataSendToSlave.data.ambient_pressure_mbar_ceiling; | |
| 317 | |
|
338
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
318 /* Set pressure and temperature offsets */ |
|
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
319 pressure_set_offset (global.dataSendToSlave.data.offsetPressureSensor_mbar, global.dataSendToSlave.data.offsetTemperatureSensor_centiDegree); |
|
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
320 |
|
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
321 |
| 88 | 322 /* for device data updates */ |
| 323 deviceDataFlashValid = 0; | |
| 324 memcpy(&DeviceDataFlash, &global.dataSendToSlave.data.DeviceData, sizeof(SDevice)); | |
| 325 deviceDataFlashValid = 1; | |
| 89 | 326 |
| 662 | 327 |
| 328 /* handle external interface requests */ | |
| 329 | |
| 330 if((global.dataSendToSlave.data.externalInterface_Cmd && EXT_INTERFACE_33V_ON) != externalInterface_isEnabledPower33()) | |
| 331 { | |
| 332 externalInterface_SwitchPower33(global.dataSendToSlave.data.externalInterface_Cmd && EXT_INTERFACE_33V_ON); | |
| 333 } | |
| 334 | |
| 691 | 335 if(((global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_ADC_ON) != 0) != externalInterface_isEnabledADC()) |
| 336 { | |
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
337 externalInterface_SwitchADC(1-externalInterface_isEnabledADC()); |
| 691 | 338 } |
| 339 | |
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
340 externalInface_SetSensorMap(global.dataSendToSlave.data.externalInterface_SensorMap); |
| 691 | 341 if(global.dataSendToSlave.data.externalInterface_Cmd & 0x00FF) /* lowest nibble for commands */ |
| 662 | 342 { |
| 343 externalInterface_ExecuteCmd(global.dataSendToSlave.data.externalInterface_Cmd); | |
| 344 } | |
| 988 | 345 |
| 346 if(GPIO_GetVersion() < global.dataSendToSlave.displayVersion) | |
| 347 { | |
| 348 GPIO_Activate_V2(); | |
| 349 } | |
| 350 | |
| 351 if(GPIO_GetVersion() > 0) | |
| 352 { | |
| 353 GPIO_HandleBuzzer(); | |
| 354 } | |
| 662 | 355 |
| 356 | |
|
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
357 #if 0 |
| 104 | 358 //TODO: Temporary placed here. Duration ~210 ms. |
| 359 if (global.I2C_SystemStatus != HAL_OK) { | |
| 360 MX_I2C1_TestAndClear(); | |
| 361 MX_I2C1_Init(); | |
| 362 // init_pressure(); | |
| 363 // compass_init(0, 7); | |
| 364 // accelerator_init(); | |
| 365 } | |
|
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
366 #endif /* already called once a second */ |
| 38 | 367 } |
| 368 | |
| 369 | |
| 370 /** | |
| 371 ****************************************************************************** | |
| 372 * @brief schedule_time_compare_helper. | |
| 373 * @author heinrichs weikamp gmbh | |
| 374 * @version V0.0.1 | |
| 375 * @date 20-Oct-2016 | |
| 376 ****************************************************************************** | |
| 377 */ | |
| 378 | |
| 379 uint8_t RtcBugFixChsw(uint8_t inStupidTime) | |
| 380 { | |
| 381 uint8_t multiplesOf16 = 0; | |
| 382 | |
| 383 multiplesOf16 = inStupidTime / 16; | |
| 384 | |
| 385 inStupidTime -= multiplesOf16 * 16; | |
| 386 | |
| 387 return (10 * multiplesOf16) + inStupidTime; | |
| 388 } | |
| 389 | |
| 390 uint32_t schedule_time_compare_helper(RTC_TimeTypeDef timeNow, RTC_DateTypeDef dateNow, RTC_TimeTypeDef timeLast, RTC_DateTypeDef dateLast) | |
| 391 { | |
| 392 uint32_t nowInSeconds; | |
| 393 uint32_t lastInSeconds; | |
| 394 uint32_t resultDiff; | |
| 395 | |
| 396 nowInSeconds = (uint32_t)RtcBugFixChsw(timeNow.Hours) * 3600; | |
| 397 nowInSeconds += (uint32_t)RtcBugFixChsw(timeNow.Minutes) * 60; | |
| 398 nowInSeconds += (uint32_t)RtcBugFixChsw(timeNow.Seconds); | |
| 399 | |
| 400 lastInSeconds = (uint32_t)RtcBugFixChsw(timeLast.Hours) * 3600; | |
| 401 lastInSeconds += (uint32_t)RtcBugFixChsw(timeLast.Minutes) * 60; | |
| 402 lastInSeconds += (uint32_t)RtcBugFixChsw(timeLast.Seconds); | |
| 403 | |
| 404 if(dateNow.Date != dateLast.Date) | |
| 405 { | |
| 406 resultDiff = 86400 + nowInSeconds - lastInSeconds; | |
| 407 } | |
| 408 else | |
| 409 { | |
| 410 resultDiff = nowInSeconds - lastInSeconds; | |
| 411 } | |
| 412 return resultDiff; | |
| 413 } | |
| 414 | |
| 415 | |
| 416 | |
| 417 /** | |
| 418 ****************************************************************************** | |
| 419 * @brief schedule_update_timer_helper. | |
| 420 * @author heinrichs weikamp gmbh | |
| 421 * @version V0.0.1 | |
| 422 * @date 20-Oct-2016 | |
| 423 * @brief use 0 for init | |
| 424 use -1 for RTC controlled | |
| 425 use >= 1 for manual control | |
| 426 ****************************************************************************** | |
| 427 */ | |
| 428 extern RTC_HandleTypeDef RTCHandle; | |
| 429 | |
|
230
3973208c4a20
cleanup: make return void when never used
Jan Mulder <jlmulder@xs4all.nl>
parents:
220
diff
changeset
|
430 static void schedule_update_timer_helper(int8_t thisSeconds) |
| 38 | 431 { |
| 432 static RTC_TimeTypeDef sTimeLast; | |
| 433 static RTC_DateTypeDef sDateLast; | |
| 434 RTC_TimeTypeDef sTimeNow; | |
| 435 RTC_DateTypeDef sDateNow; | |
| 436 uint32_t secondsPast; | |
| 437 | |
| 438 HAL_RTC_GetTime(&RTCHandle, &sTimeNow, RTC_FORMAT_BCD); | |
| 439 HAL_RTC_GetDate(&RTCHandle, &sDateNow, RTC_FORMAT_BCD); | |
| 440 | |
|
230
3973208c4a20
cleanup: make return void when never used
Jan Mulder <jlmulder@xs4all.nl>
parents:
220
diff
changeset
|
441 if(thisSeconds != 0) // otherwise just store sTimeLast, sDateLast |
| 38 | 442 { |
| 443 if(thisSeconds > 0) // use this value instead, good for pre-loading sTimeLast and sDateLast | |
| 444 { | |
| 445 secondsPast = thisSeconds; | |
|
230
3973208c4a20
cleanup: make return void when never used
Jan Mulder <jlmulder@xs4all.nl>
parents:
220
diff
changeset
|
446 } else { |
|
3973208c4a20
cleanup: make return void when never used
Jan Mulder <jlmulder@xs4all.nl>
parents:
220
diff
changeset
|
447 // thisSeconds < 0 and not <= ! |
|
3973208c4a20
cleanup: make return void when never used
Jan Mulder <jlmulder@xs4all.nl>
parents:
220
diff
changeset
|
448 secondsPast = schedule_time_compare_helper(sTimeNow, sDateNow, sTimeLast, sDateLast); |
| 38 | 449 } |
| 450 | |
| 451 if(global.seconds_since_last_dive) | |
| 452 { | |
| 453 if(secondsPast >= 777900) | |
| 454 { | |
| 455 global.seconds_since_last_dive = 0; | |
| 456 } | |
| 457 else | |
| 458 { | |
|
230
3973208c4a20
cleanup: make return void when never used
Jan Mulder <jlmulder@xs4all.nl>
parents:
220
diff
changeset
|
459 uint32_t tempNewValue = ((uint32_t)global.seconds_since_last_dive) + secondsPast; |
| 38 | 460 if(tempNewValue > 777900) // a bit more than nine days [seconds] |
| 461 global.seconds_since_last_dive = 0; | |
| 462 else | |
| 463 global.seconds_since_last_dive = (long)tempNewValue; | |
| 464 } | |
| 465 } | |
| 466 } | |
| 467 | |
| 468 sTimeLast = sTimeNow; | |
| 469 sDateLast = sDateNow; | |
| 470 } | |
| 471 | |
| 472 /** | |
| 473 ****************************************************************************** | |
| 474 * @brief schedule_check_resync. | |
| 475 * @author heinrichs weikamp gmbh | |
| 476 * @version V0.0.2 | |
| 477 * @date 18-June-2015 | |
| 478 ****************************************************************************** | |
| 479 */ | |
| 135 | 480 |
| 38 | 481 void schedule_check_resync(void) |
| 482 { | |
|
155
4fd8bbc7d841
Do hard sync after communication timeout > 1 second
Ideenmodellierer
parents:
148
diff
changeset
|
483 /* counter is incremented in cyclic 100ms loop and reset to 0 if the transmission complete callback is called */ |
|
265
a91d99265884
Increase SPI com timeout for cold start and wake up
ideenmodellierer
parents:
264
diff
changeset
|
484 if((global.check_sync_not_running >= Scheduler.communicationTimeout)) |
| 38 | 485 { |
| 89 | 486 // global.dataSendToSlaveIsNotValidCount = 0; |
| 135 | 487 global.check_sync_not_running = 0; |
| 488 global.sync_error_count++; | |
| 489 | |
| 490 /* Try to start communication again. If exchange is stuck during execution for some reason the TX will be aborted by the | |
| 491 * function error handler | |
| 492 */ | |
| 277 | 493 HAL_SPI_TransmitReceive_DMA(&hspi1,(uint8_t*) &(global.dataSendToMaster),(uint8_t*) &(global.dataSendToSlave), EXCHANGE_BUFFERSIZE); |
|
265
a91d99265884
Increase SPI com timeout for cold start and wake up
ideenmodellierer
parents:
264
diff
changeset
|
494 Scheduler.communicationTimeout = SPI_COM_TIMEOUT_COMMON; /* Reduce error detection time */ |
|
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
495 Scheduler_Request_sync_with_SPI(SPI_SYNC_METHOD_HARD); |
|
155
4fd8bbc7d841
Do hard sync after communication timeout > 1 second
Ideenmodellierer
parents:
148
diff
changeset
|
496 } |
| 38 | 497 } |
| 498 | |
| 499 | |
| 500 /** | |
| 501 ****************************************************************************** | |
| 502 * @brief scheduleDiveMode. / Dive Mode: Main Loop | |
|
763
aa6006975e76
increase HAL_Delay to 10ms for cold-start-button reset
heinrichsweikamp
parents:
742
diff
changeset
|
503 * @author heinrichs weikamp gmbh |
| 38 | 504 * @version V0.0.1 |
| 505 * @date 22-April-2014 | |
| 506 ****************************************************************************** | |
| 507 */ | |
| 508 void scheduleDiveMode(void) | |
| 509 { | |
| 510 uint32_t ticksdiff = 0; | |
| 511 uint32_t lasttick = 0; | |
|
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
512 uint8_t extAdcChannel = 0; |
| 38 | 513 uint8_t counterAscentRate = 0; |
| 514 global.dataSendToMaster.mode = MODE_DIVE; | |
| 515 global.deviceDataSendToMaster.mode = MODE_DIVE; | |
| 516 uint8_t counter_exit = 0; | |
|
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
517 |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
518 Scheduler.counterSPIdata100msec = 0; |
|
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
519 Scheduler.counterCompass100msec = 0; |
|
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
520 Scheduler.counterPressure100msec = 0; |
|
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
521 Scheduler.counterAmbientLight100msec = 0; |
|
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
522 Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC; |
| 38 | 523 |
| 524 global.deviceData.diveCycles.value_int32++; | |
| 525 scheduleSetDate(&global.deviceData.diveCycles); | |
| 526 global.lifeData.counterSecondsShallowDepth = 0; | |
| 527 | |
|
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
528 /* Get the last stable value in case of an unstable surface history condition */ |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
529 if(!is_surface_pressure_stable()) |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
530 { |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
531 set_last_surface_pressure_stable(); |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
532 } |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
533 global.lifeData.pressure_surface_bar = get_surface_mbar() / 1000.0f; |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
534 ManualExitDiveCounter = 0; /* reset early exit request */ |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
535 |
|
240
625d20070261
Improvement SPI stability/recoverability
Jan Mulder <jlmulder@xs4all.nl>
parents:
231
diff
changeset
|
536 Scheduler.tickstart = HAL_GetTick(); |
| 38 | 537 while(global.mode == MODE_DIVE) |
| 538 { | |
| 539 lasttick = HAL_GetTick(); | |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
540 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick); |
| 38 | 541 |
| 802 | 542 externalInterface_HandleUART(); |
| 988 | 543 #ifdef ENABLE_GNSS_INTERN |
| 544 if(GPIO_GetVersion() > 0) | |
| 545 { | |
| 546 UART6_HandleUART(); | |
| 547 } | |
| 942 | 548 #endif |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
549 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) |
|
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
550 { |
| 277 | 551 if(SPI_Evaluate_RX_Data()!=0) /* did we receive something ? */ |
| 552 { | |
| 553 Scheduler.counterSPIdata100msec++; | |
| 554 } | |
| 555 schedule_check_resync(); | |
|
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
556 |
| 691 | 557 if(externalInterface_isEnabledADC()) |
|
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
558 { |
| 691 | 559 extAdcChannel = externalInterface_ReadAndSwitch(); |
| 560 if(extAdcChannel != EXTERNAL_ADC_NO_DATA) | |
| 561 { | |
| 562 externalInterface_CalculateADCValue(extAdcChannel); | |
| 563 } | |
|
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
564 } |
| 691 | 565 copyExtADCdata(); |
| 662 | 566 copyExtCO2data(); |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
567 } |
|
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
568 |
| 38 | 569 //Evaluate pressure at 20 ms, 120 ms, 220 ms,.... |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
570 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20) |
| 38 | 571 { |
| 572 global.check_sync_not_running++; | |
| 277 | 573 pressure_update_alternating(); |
| 135 | 574 scheduleUpdateDeviceData(); |
|
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
181
diff
changeset
|
575 #ifdef DEMOMODE |
| 38 | 576 if(global.demo_mode) |
| 577 { | |
|
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
181
diff
changeset
|
578 int turbo_seconds = demo_modify_temperature_and_pressure(global.lifeData.dive_time_seconds, Scheduler.counterPressure100msec, global.ceiling_from_main_CPU_mbar); |
| 38 | 579 if(turbo_seconds) |
| 580 { | |
| 581 global.lifeData.dive_time_seconds += turbo_seconds; | |
| 582 decom_tissues_exposure((int)(turbo_seconds), &global.lifeData); | |
| 583 copyTissueData(); | |
| 584 } | |
| 585 if((global.lifeData.counterSecondsShallowDepth > 1) && (global.lifeData.counterSecondsShallowDepth < (global.settings.timeoutDiveReachedZeroDepth - 10))) | |
| 586 global.lifeData.counterSecondsShallowDepth = (global.settings.timeoutDiveReachedZeroDepth - 10); | |
| 587 } | |
|
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
181
diff
changeset
|
588 #endif |
|
867
3311b720a072
Decrease calculation interval for ascend speed:
Ideenmodellierer
parents:
859
diff
changeset
|
589 |
| 38 | 590 counterAscentRate++; |
|
867
3311b720a072
Decrease calculation interval for ascend speed:
Ideenmodellierer
parents:
859
diff
changeset
|
591 if(counterAscentRate == 4) |
| 38 | 592 { |
| 881 | 593 global.lifeData.pressure_ambient_bar = get_pressure_mbar() / 1000.0f; |
| 594 evaluateAscentSpeed(); | |
| 38 | 595 counterAscentRate = 0; |
| 596 } | |
| 135 | 597 copyPressureData(); |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
598 Scheduler.counterPressure100msec++; |
| 38 | 599 } |
| 600 //evaluate compass data at 50 ms, 150 ms, 250 ms,.... | |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
601 if(ticksdiff >= Scheduler.counterCompass100msec * 100 + 50) |
| 135 | 602 { |
| 603 compass_read(); | |
| 604 acceleration_read(); | |
| 605 compass_calc(); | |
| 606 copyCompassData(); | |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
607 Scheduler.counterCompass100msec++; |
| 135 | 608 } |
| 38 | 609 |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
610 if(ticksdiff >= Scheduler.counterAmbientLight100msec * 100 + 70) |
| 38 | 611 { |
| 612 adc_ambient_light_sensor_get_data(); | |
| 613 copyAmbientLightData(); | |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
614 Scheduler.counterAmbientLight100msec++; |
| 38 | 615 } |
| 616 | |
|
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
617 //Evaluate tissues, toxic data, vpm, etc. once a second |
|
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
618 if(ticksdiff >= Scheduler.tick_execute1second) |
| 38 | 619 { |
|
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
620 Scheduler.tick_execute1second = 0xFFFFFFFF; /* execute once only in the second cycle */ |
| 38 | 621 if(global.dataSendToSlave.diveModeInfo != DIVEMODE_Apnea) |
| 622 { | |
| 623 scheduleUpdateLifeData(0); // includes tissues | |
| 624 global.lifeData.dive_time_seconds++; // there is dive_time_seconds_without_surface_time too | |
| 625 global.lifeData.ppO2 = decom_calc_ppO2(global.lifeData.pressure_ambient_bar, &global.lifeData.actualGas); | |
| 626 decom_oxygen_calculate_cns(&global.lifeData.cns,global.lifeData.ppO2); | |
| 627 decom_oxygen_calculate_otu(&global.lifeData.otu,global.lifeData.ppO2); | |
| 88 | 628 battery_gas_gauge_get_data(); |
| 38 | 629 |
| 630 | |
| 631 /** counter_exit allows safe exit via button for testing | |
| 881 | 632 * and demo_mode is exited too if applicable. |
| 38 | 633 */ |
| 634 if(global.dataSendToMaster.mode == MODE_ENDDIVE) | |
| 635 { | |
| 636 counter_exit++; | |
| 637 if(counter_exit >= 2) | |
| 638 { | |
| 639 global.mode = MODE_SURFACE; | |
| 640 global.demo_mode = 0; | |
| 641 } | |
| 642 } | |
|
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
643 |
| 38 | 644 if(is_ambient_pressure_close_to_surface(&global.lifeData)) |
| 645 { | |
| 881 | 646 |
| 38 | 647 global.lifeData.counterSecondsShallowDepth++; |
|
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
648 if((global.lifeData.counterSecondsShallowDepth >= global.settings.timeoutDiveReachedZeroDepth) || ((global.lifeData.dive_time_seconds < 60) && (global.demo_mode == 0)) |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
649 || (ManualExitDiveCounter)) |
| 38 | 650 { |
| 651 global.seconds_since_last_dive = 1; // start counter | |
| 652 schedule_update_timer_helper(0); // zum starten :-) | |
| 653 global.dataSendToMaster.mode = MODE_ENDDIVE; | |
| 654 global.deviceDataSendToMaster.mode = MODE_ENDDIVE; | |
| 655 } | |
| 656 } | |
| 657 else | |
| 658 { | |
| 659 global.lifeData.counterSecondsShallowDepth = 0; | |
| 660 global.lifeData.dive_time_seconds_without_surface_time++; | |
| 661 } | |
| 662 vpm_crush2(); | |
| 663 } | |
| 664 else // DIVEMODE_Apnea | |
| 665 { | |
| 666 global.lifeData.dive_time_seconds++; | |
| 667 | |
| 668 // exit dive mode | |
| 669 if(global.dataSendToMaster.mode == MODE_ENDDIVE) | |
| 670 { | |
| 671 counter_exit++; | |
| 672 if(counter_exit >= 2) | |
| 673 { | |
| 674 scheduleUpdateLifeData(-1); // 'restart' tissue calculations without calculating time during apnea mode | |
| 675 global.lifeData.dive_time_seconds = 0; // use backup noflytime and desaturation time | |
| 676 global.mode = MODE_SURFACE; | |
| 677 global.demo_mode = 0; | |
| 678 } | |
| 679 } | |
| 680 | |
| 681 // surface break | |
| 682 if(is_ambient_pressure_close_to_surface(&global.lifeData)) | |
| 683 { | |
| 881 | 684 global.lifeData.ascent_rate_meter_per_min = 0; |
| 38 | 685 global.lifeData.counterSecondsShallowDepth++; |
| 686 if(global.lifeData.counterSecondsShallowDepth > 3) // time for main cpu to copy to apnea_last_dive_time_seconds | |
| 687 { | |
| 688 global.lifeData.dive_time_seconds = 0; // this apnea dive ends here | |
| 689 } | |
|
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
690 if((global.lifeData.counterSecondsShallowDepth >= global.settings.timeoutDiveReachedZeroDepth) || (ManualExitDiveCounter)) |
| 38 | 691 { |
| 692 global.dataSendToMaster.mode = MODE_ENDDIVE; | |
| 693 global.deviceDataSendToMaster.mode = MODE_ENDDIVE; | |
| 694 } | |
| 695 } | |
| 696 else | |
| 697 { | |
| 698 global.lifeData.counterSecondsShallowDepth = 0; | |
| 699 global.lifeData.dive_time_seconds_without_surface_time++; | |
| 700 } | |
| 701 } // standard dive or DIVEMODE_Apnea | |
| 702 | |
| 88 | 703 copyVpmCrushingData(); |
| 704 copyTimeData(); | |
| 705 copyCnsAndOtuData(); | |
| 706 copyBatteryData(); | |
| 38 | 707 |
| 88 | 708 // new hw 170523 |
| 709 if(global.I2C_SystemStatus != HAL_OK) | |
| 710 { | |
| 711 MX_I2C1_TestAndClear(); | |
|
488
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
712 HAL_Delay(100); |
|
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
713 I2C_DeInit(); |
|
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
714 HAL_Delay(100); |
| 88 | 715 MX_I2C1_Init(); |
|
488
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
716 HAL_Delay(100); |
|
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
717 |
|
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
718 init_pressure(); |
| 88 | 719 } |
|
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
720 } |
|
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
721 if(ticksdiff >= 1000) |
|
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
722 { |
|
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
723 /* reset counter */ |
|
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
724 Scheduler.tickstart = HAL_GetTick(); |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
725 Scheduler.counterSPIdata100msec = 0; |
|
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
726 Scheduler.counterCompass100msec = 0; |
|
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
727 Scheduler.counterPressure100msec = 0; |
|
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
728 Scheduler.counterAmbientLight100msec = 0; |
|
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
729 Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC; |
| 38 | 730 } |
| 731 } | |
| 732 } | |
| 733 | |
| 734 | |
| 735 /** | |
| 736 ****************************************************************************** | |
| 737 * @brief scheduleSurfaceMode / surface mode: Main Loop | |
|
763
aa6006975e76
increase HAL_Delay to 10ms for cold-start-button reset
heinrichsweikamp
parents:
742
diff
changeset
|
738 * @author heinrichs weikamp gmbh |
| 38 | 739 * @version V0.0.1 |
| 740 * @date 22-April-2014 | |
| 741 ****************************************************************************** | |
| 742 */ | |
| 743 | |
| 744 | |
| 745 // =============================================================================== | |
| 746 // scheduleTestMode | |
| 747 /// @brief included for sealed hardware with permanent RTE update message | |
| 748 // =============================================================================== | |
| 749 void scheduleTestMode(void) | |
| 750 { | |
| 751 uint32_t ticksdiff = 0; | |
| 752 uint32_t lasttick = 0; | |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
753 Scheduler.tickstart = HAL_GetTick(); |
| 38 | 754 |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
755 Scheduler.counterPressure100msec = 0; |
| 38 | 756 |
| 757 float temperature_carousel = 0.0f; | |
| 758 float temperature_changer = 0.1f; | |
| 759 | |
| 760 while(global.mode == MODE_TEST) | |
| 761 { | |
| 762 lasttick = HAL_GetTick(); | |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
763 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick); |
|
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
764 |
|
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
765 //Evaluate received data at 10 ms, 110 ms, 210 ms,... |
|
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
766 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) |
|
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
767 { |
| 277 | 768 if(SPI_Evaluate_RX_Data()!=0) /* did we receive something ? */ |
| 769 { | |
| 770 Scheduler.counterSPIdata100msec++; | |
| 771 } | |
| 772 schedule_check_resync(); | |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
773 } |
| 38 | 774 |
| 775 //Evaluate pressure at 20 ms, 120 ms, 220 ms,... | |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
776 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20) |
| 38 | 777 { |
| 778 global.check_sync_not_running++; | |
| 779 | |
| 277 | 780 pressure_update_alternating(); |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
781 scheduleUpdateDeviceData(); |
|
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
782 global.lifeData.ascent_rate_meter_per_min = 0; |
|
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
783 copyPressureData(); |
| 38 | 784 |
| 785 if(temperature_carousel > 20.0f) | |
| 786 { | |
| 787 temperature_carousel = 20.0f; | |
| 788 temperature_changer = -0.1f; | |
| 789 } | |
| 790 else | |
| 791 if(temperature_carousel < 0) | |
| 792 { | |
| 793 temperature_carousel = 0; | |
| 794 temperature_changer = +0.1f; | |
| 795 } | |
| 796 | |
| 797 temperature_carousel += temperature_changer; | |
| 798 | |
| 799 uint8_t boolPressureData = !global.dataSendToMaster.boolPressureData; | |
| 800 | |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
801 global.dataSendToMaster.data[boolPressureData].pressure_mbar = get_pressure_mbar(); |
| 38 | 802 |
| 803 global.dataSendToMaster.data[boolPressureData].temperature = temperature_carousel; | |
| 804 global.dataSendToMaster.data[boolPressureData].pressure_uTick = HAL_GetTick(); | |
| 805 global.dataSendToMaster.boolPressureData = boolPressureData; | |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
806 Scheduler.counterPressure100msec++; |
| 38 | 807 } |
| 808 | |
| 809 if(ticksdiff >= 1000) | |
| 810 { | |
| 811 //Set back tick counter | |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
812 Scheduler.tickstart = HAL_GetTick(); |
|
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
813 Scheduler.counterPressure100msec = 0; |
|
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
814 Scheduler.counterSPIdata100msec = 0; |
| 38 | 815 } |
| 816 }; | |
| 817 } | |
| 818 | |
| 819 | |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
820 |
| 38 | 821 void scheduleSurfaceMode(void) |
| 822 { | |
| 823 uint32_t ticksdiff = 0; | |
| 824 uint32_t lasttick = 0; | |
|
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
825 uint8_t extAdcChannel = 0; |
| 662 | 826 uint8_t batteryToggle = 0; /* ADC is operating in automatic 2 second cycles => consider for battery charge function call */ |
| 827 | |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
828 Scheduler.tickstart = HAL_GetTick(); |
|
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
829 Scheduler.counterSPIdata100msec = 0; |
|
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
830 Scheduler.counterCompass100msec = 0; |
|
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
831 Scheduler.counterPressure100msec = 0; |
|
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
832 Scheduler.counterAmbientLight100msec = 0; |
|
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
833 Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC; |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
834 |
| 38 | 835 global.dataSendToMaster.mode = MODE_SURFACE; |
| 836 global.deviceDataSendToMaster.mode = MODE_SURFACE; | |
| 837 | |
| 838 while(global.mode == MODE_SURFACE) | |
| 839 { | |
| 277 | 840 |
| 38 | 841 lasttick = HAL_GetTick(); |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
842 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick); |
| 38 | 843 |
| 844 if(setButtonsNow == 1) | |
| 845 { | |
| 846 if(scheduleSetButtonResponsiveness()) | |
| 847 setButtonsNow = 0; | |
| 848 } | |
| 691 | 849 |
| 802 | 850 externalInterface_HandleUART(); |
| 988 | 851 #ifdef ENABLE_GNSS_INTERN |
| 852 if(GPIO_GetVersion() > 0) | |
| 853 { | |
| 854 UART6_HandleUART(); | |
| 855 } | |
| 922 | 856 #endif |
|
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
857 |
|
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
858 /* Evaluate received data at 10 ms, 110 ms, 210 ms,... duration ~<1ms */ |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
859 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) |
|
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
860 { |
|
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
861 if(SPI_Evaluate_RX_Data()!=0) /* did we receive something ? */ |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
862 { |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
863 Scheduler.counterSPIdata100msec++; |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
864 } |
| 277 | 865 schedule_check_resync(); |
| 691 | 866 if(externalInterface_isEnabledADC()) |
|
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
867 { |
| 691 | 868 extAdcChannel = externalInterface_ReadAndSwitch(); |
| 869 if(extAdcChannel != EXTERNAL_ADC_NO_DATA) | |
| 870 { | |
| 871 externalInterface_CalculateADCValue(extAdcChannel); | |
| 872 | |
| 873 } | |
|
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
874 } |
| 691 | 875 copyExtADCdata(); |
| 662 | 876 copyExtCO2data(); |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
877 } |
|
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
878 |
|
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
879 /* Evaluate pressure at 20 ms, 120 ms, 220 ms,... duration ~22ms] */ |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
880 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20) |
| 38 | 881 { |
| 882 global.check_sync_not_running++; | |
| 277 | 883 pressure_update_alternating(); |
| 135 | 884 scheduleUpdateDeviceData(); |
| 38 | 885 global.lifeData.ascent_rate_meter_per_min = 0; |
| 135 | 886 copyPressureData(); |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
887 Scheduler.counterPressure100msec++; |
| 135 | 888 |
|
301
a09b1855d656
cleanup, RTE: factor out scheduleCheck_pressure_reached_dive_mode_level
Jan Mulder <jlmulder@xs4all.nl>
parents:
277
diff
changeset
|
889 if (!is_ambient_pressure_close_to_surface(&global.lifeData)) |
| 38 | 890 global.mode = MODE_DIVE; |
| 891 } | |
| 892 | |
|
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
893 /* Evaluate compass data at 50 ms, 150 ms, 250 ms,... duration ~5ms */ |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
894 if(ticksdiff >= Scheduler.counterCompass100msec * 100 + 50) |
| 135 | 895 { |
| 896 compass_read(); | |
| 897 acceleration_read(); | |
| 898 compass_calc(); | |
| 899 copyCompassData(); | |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
900 Scheduler.counterCompass100msec++; |
| 135 | 901 } |
| 38 | 902 |
|
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
903 /* evaluate compass data at 70 ms, 170 ms, 270 ms,... duration <1ms */ |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
904 if(ticksdiff >= Scheduler.counterAmbientLight100msec * 100 + 70) |
| 38 | 905 { |
| 906 adc_ambient_light_sensor_get_data(); | |
| 907 copyAmbientLightData(); | |
| 928 | 908 |
| 988 | 909 #if defined ENABLE_GNSS_INTERN || defined ENABLE_GNSS_EXTERN |
|
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
881
diff
changeset
|
910 copyGNSSdata(); |
| 919 | 911 #endif |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
912 Scheduler.counterAmbientLight100msec++; |
| 38 | 913 } |
|
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
914 |
|
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
915 |
|
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
916 |
|
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
917 /* Evaluate tissues, toxic data, etc. once a second... duration ~1ms */ |
|
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
918 if(ticksdiff >= Scheduler.tick_execute1second) |
| 38 | 919 { |
|
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
920 Scheduler.tick_execute1second = 0xFFFFFFFF; |
| 38 | 921 if(clearDecoNow) |
| 922 { | |
| 923 decom_reset_with_1000mbar(&global.lifeData); ///< this should almost reset desaturation time | |
| 924 // new 160215 hw | |
| 925 global.repetitive_dive = 0; | |
| 926 global.seconds_since_last_dive = 0; ///< this will reset OTU and CNS as well | |
| 927 global.no_fly_time_minutes = 0; | |
| 928 global.accidentFlag = 0; | |
| 929 global.accidentRemainingSeconds = 0; | |
| 930 vpm_init(&global.vpm, global.conservatism, global.repetitive_dive, global.seconds_since_last_dive); | |
| 931 clearDecoNow = 0; | |
| 932 } | |
| 89 | 933 |
|
349
9d82411d0afa
Decrease ManualExitDiveCounter in surface mode
ideenmodellierer
parents:
346
diff
changeset
|
934 if(ManualExitDiveCounter) |
|
9d82411d0afa
Decrease ManualExitDiveCounter in surface mode
ideenmodellierer
parents:
346
diff
changeset
|
935 { |
|
9d82411d0afa
Decrease ManualExitDiveCounter in surface mode
ideenmodellierer
parents:
346
diff
changeset
|
936 ManualExitDiveCounter--; |
|
9d82411d0afa
Decrease ManualExitDiveCounter in surface mode
ideenmodellierer
parents:
346
diff
changeset
|
937 } |
|
9d82411d0afa
Decrease ManualExitDiveCounter in surface mode
ideenmodellierer
parents:
346
diff
changeset
|
938 |
| 38 | 939 if(global.seconds_since_last_dive) |
| 940 { | |
| 941 schedule_update_timer_helper(-1); | |
| 942 } | |
| 89 | 943 |
| 38 | 944 if(global.accidentRemainingSeconds) |
| 945 { | |
| 946 global.accidentRemainingSeconds--; | |
| 947 if(!global.accidentRemainingSeconds) | |
| 948 global.accidentFlag = 0; | |
| 949 } | |
| 950 global.dataSendToMaster.accidentFlags = global.accidentFlag; | |
| 89 | 951 |
| 38 | 952 update_surface_pressure(1); |
| 953 scheduleUpdateLifeData(0); | |
| 954 decom_oxygen_calculate_otu_degrade(&global.lifeData.otu, global.seconds_since_last_dive); | |
| 955 decom_oxygen_calculate_cns_degrade(&global.lifeData.cns, global.seconds_since_last_dive); | |
| 135 | 956 |
| 957 /* start desaturation calculation after first valid measurement has been done */ | |
| 958 if(global.lifeData.pressure_surface_bar != INVALID_PREASURE_VALUE) | |
| 959 { | |
| 960 global.lifeData.desaturation_time_minutes = decom_calc_desaturation_time(global.lifeData.tissue_nitrogen_bar,global.lifeData.tissue_helium_bar,global.lifeData.pressure_surface_bar); | |
| 961 } | |
| 962 else | |
| 963 { | |
| 964 global.lifeData.desaturation_time_minutes = 0; | |
| 965 } | |
| 662 | 966 |
| 967 if(!batteryToggle) | |
| 968 { | |
| 969 battery_gas_gauge_get_data(); | |
| 970 battery_charger_get_status_and_contral_battery_gas_gauge(2); | |
| 971 batteryToggle = 1; | |
| 972 } | |
| 973 else | |
| 974 { | |
| 975 batteryToggle = 0; | |
| 976 } | |
| 89 | 977 |
| 88 | 978 copyCnsAndOtuData(); |
| 979 copyTimeData(); | |
| 980 copyBatteryData(); | |
| 981 copyDeviceData(); | |
| 38 | 982 |
| 691 | 983 |
|
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
984 /* check if I2C is not up an running and try to reactivate if necessary. Also do initialization if problem occured during startup */ |
| 88 | 985 if(global.I2C_SystemStatus != HAL_OK) |
| 986 { | |
| 987 MX_I2C1_TestAndClear(); | |
|
488
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
988 HAL_Delay(100); |
|
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
989 I2C_DeInit(); |
|
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
990 HAL_Delay(100); |
| 88 | 991 MX_I2C1_Init(); |
|
488
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
992 HAL_Delay(100); |
|
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
993 |
|
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
994 if(global.I2C_SystemStatus == HAL_OK) |
| 88 | 995 { |
| 996 init_pressure(); | |
|
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
997 if(is_init_pressure_done()) /* Init surface data with initial measurement */ |
|
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
998 { |
|
338
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
999 init_surface_ring(0); |
|
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1000 } |
|
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1001 |
|
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1002 if(!battery_gas_gauge_CheckConfigOK()) |
|
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1003 { |
|
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1004 init_battery_gas_gauge(); |
|
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1005 } |
| 88 | 1006 } |
| 1007 } | |
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
1008 externalInterface_AutodetectSensor(); |
|
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
1009 } |
|
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
1010 |
|
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
1011 if(ticksdiff >= 1000) |
|
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
1012 { |
|
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
1013 //Set back tick counter |
|
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
1014 Scheduler.tickstart = HAL_GetTick(); |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
1015 Scheduler.counterSPIdata100msec = 0; |
|
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
1016 Scheduler.counterCompass100msec = 0; |
|
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
1017 Scheduler.counterPressure100msec = 0; |
|
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
1018 Scheduler.counterAmbientLight100msec = 0; |
|
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
1019 Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC; |
| 38 | 1020 } |
| 1021 } | |
| 1022 } | |
| 1023 | |
| 207 | 1024 inline void Scheduler_Request_sync_with_SPI(uint8_t SyncMethod) |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
1025 { |
| 207 | 1026 if( SyncMethod < SPI_SYNC_METHOD_INVALID) |
| 1027 { | |
| 1028 dospisync = SyncMethod; | |
| 1029 } | |
| 1030 } | |
| 1031 | |
|
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1032 void Scheduler_SyncToSPI(uint8_t TXtick) |
| 207 | 1033 { |
| 1034 uint32_t deltatick = 0; | |
|
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1035 int8_t TXcompensation; |
| 207 | 1036 |
| 1037 switch(dospisync) | |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
1038 { |
| 207 | 1039 case SPI_SYNC_METHOD_HARD: |
| 1040 //Set back tick counter | |
|
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1041 Scheduler.tickstart = HAL_GetTick() - 4; /* consider 4ms offset for transfer */ |
| 207 | 1042 Scheduler.counterSPIdata100msec = 0; |
| 1043 Scheduler.counterCompass100msec = 0; | |
| 1044 Scheduler.counterPressure100msec = 0; | |
| 1045 Scheduler.counterAmbientLight100msec = 0; | |
| 1046 dospisync = SPI_SYNC_METHOD_NONE; | |
| 1047 break; | |
| 1048 case SPI_SYNC_METHOD_SOFT: | |
| 1049 deltatick = time_elapsed_ms(Scheduler.tickstart,HAL_GetTick()); | |
| 1050 deltatick %= 100; /* clip to 100ms window */ | |
| 1051 if(Scheduler.tickstart - deltatick >= 0) /* adjust start time to the next 100ms window */ | |
| 1052 { | |
| 1053 Scheduler.tickstart -= deltatick; | |
| 1054 } | |
| 1055 else | |
| 1056 { | |
| 1057 Scheduler.tickstart = 0xFFFFFFFF- (deltatick - Scheduler.tickstart); | |
| 1058 } | |
| 1059 dospisync = SPI_SYNC_METHOD_NONE; | |
| 1060 break; | |
|
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1061 default: /* continous sync activity */ |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1062 if(TXtick < 100) /* do not handle unexpected jump length > 100ms */ |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1063 { |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1064 TXtick += 4; /* add 4ms TX time to offset of 100ms time stamp */ |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1065 deltatick = time_elapsed_ms(Scheduler.tickstart,HAL_GetTick()); |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1066 deltatick %= 100; |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1067 if(deltatick > 50) |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1068 { |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1069 TXcompensation = deltatick - 100; /* neg drift */ |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1070 } |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1071 else |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1072 { |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1073 TXcompensation = deltatick; /* pos drift */ |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1074 } |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1075 TXcompensation = TXtick - TXcompensation; |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1076 Scheduler.tickstart -= TXcompensation; |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1077 } |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1078 else |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1079 { |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1080 Scheduler_Request_sync_with_SPI(SPI_SYNC_METHOD_SOFT); /* A large shift in 100ms cycle occured => clip to 100ms in next sync call */ |
|
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1081 } |
| 207 | 1082 break; |
|
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
1083 } |
|
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
1084 } |
| 38 | 1085 |
| 1086 /** | |
| 1087 ****************************************************************************** | |
| 1088 * @brief scheduleCompassCalibrationMode | |
| 1089 * @author heinrichs weikamp gmbh | |
| 1090 * @version V0.0.1 | |
| 1091 * @since 31-March-2015 | |
| 1092 * @date 31-March-2015 | |
| 1093 ****************************************************************************** | |
| 1094 */ | |
| 1095 void scheduleCompassCalibrationMode(void) | |
| 1096 { | |
| 1097 compass_init(1,7); // fast mode, max gain | |
| 1098 compass_calib(); // duration : 1 minute! | |
| 1099 compass_init(0,7); // back to normal mode | |
| 1100 | |
| 1101 if(global.seconds_since_last_dive) | |
| 1102 { | |
| 1103 schedule_update_timer_helper(-1); | |
| 1104 } | |
| 1105 | |
| 1106 scheduleUpdateLifeData(0); | |
| 1107 global.mode = MODE_SURFACE; | |
| 1108 } | |
| 1109 | |
| 1110 | |
| 1111 /** | |
| 1112 ****************************************************************************** | |
| 1113 * @brief scheduleSleepMode / sleep mode: Main Loop | |
| 1114 * @author heinrichs weikamp gmbh | |
| 1115 * @version V0.0.2 | |
| 1116 * @since 31-March-2015 | |
| 1117 * @date 22-April-2014 | |
| 1118 ****************************************************************************** | |
| 1119 */ | |
| 1120 | |
| 1121 void scheduleSleepMode(void) | |
| 1122 { | |
| 1123 global.dataSendToMaster.mode = 0; | |
| 1124 global.deviceDataSendToMaster.mode = 0; | |
| 668 | 1125 secondsCount = 0; |
| 988 | 1126 #ifdef ENABLE_GNSS_INTERN |
| 936 | 1127 uint16_t deepSleepCntDwn = 21600; /* 12 hours in 2 second steps */ |
| 947 | 1128 uint8_t deepSleep = 0; |
| 936 | 1129 GPIO_InitTypeDef GPIO_InitStruct; |
| 1130 #endif | |
| 38 | 1131 /* prevent button wake up problem while in sleep_prepare |
| 1132 * sleep prepare does I2C_DeInit() | |
| 1133 */ | |
| 1134 if(global.mode != MODE_SLEEP) | |
| 1135 MX_I2C1_Init(); | |
| 1136 else | |
| 1137 do | |
| 1138 { | |
| 1139 I2C_DeInit(); | |
| 1140 | |
| 937 | 1141 #ifdef ENABLE_SLEEP_DEBUG |
| 38 | 1142 HAL_Delay(2000); |
| 1143 #else | |
| 1144 RTC_StopMode_2seconds(); | |
| 1145 #endif | |
| 1146 | |
| 1147 if(global.mode == MODE_SLEEP) | |
| 1148 secondsCount += 2; | |
| 1149 | |
| 662 | 1150 externalInterface_InitPower33(); |
| 38 | 1151 MX_I2C1_Init(); |
| 1152 pressure_sensor_get_pressure_raw(); | |
| 1153 | |
| 475 | 1154 /* check if I2C is not up and running and try to reactivate if necessary. Also do initialization if problem occurred during startup */ |
|
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1155 if(global.I2C_SystemStatus != HAL_OK) |
|
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1156 { |
|
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1157 MX_I2C1_TestAndClear(); |
|
488
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
1158 HAL_Delay(100); |
|
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
1159 I2C_DeInit(); |
|
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
1160 HAL_Delay(100); |
|
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1161 MX_I2C1_Init(); |
|
488
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
1162 HAL_Delay(100); |
|
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
1163 |
| 475 | 1164 if((global.I2C_SystemStatus == HAL_OK) && (!is_init_pressure_done())) |
|
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1165 { |
|
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1166 init_pressure(); |
|
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1167 } |
|
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1168 } |
|
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1169 |
| 691 | 1170 if((secondsCount >= 30) || (global.mode != MODE_SLEEP)) /* Service battery charge state in case sleep is left */ |
| 38 | 1171 { |
| 1172 pressure_sensor_get_temperature_raw(); | |
| 1173 battery_gas_gauge_get_data(); | |
| 662 | 1174 ReInit_battery_charger_status_pins(); |
| 691 | 1175 battery_charger_get_status_and_contral_battery_gas_gauge(secondsCount); |
| 38 | 1176 // DeInit_battery_charger_status_pins(); |
| 1177 secondsCount = 0; | |
| 1178 } | |
| 1179 | |
| 1180 pressure_calculation(); | |
| 1181 | |
| 1182 scheduleUpdateDeviceData(); | |
| 1183 update_surface_pressure(2); | |
| 1184 | |
| 1185 if(global.seconds_since_last_dive) | |
| 1186 { | |
| 1187 schedule_update_timer_helper(-1); | |
| 1188 } | |
| 1189 | |
| 1190 if(global.accidentRemainingSeconds) | |
| 1191 { | |
| 1192 if(global.accidentRemainingSeconds > 2) | |
| 1193 global.accidentRemainingSeconds -= 2; | |
| 1194 else | |
| 1195 { | |
| 1196 global.accidentRemainingSeconds = 0; | |
| 1197 global.accidentFlag = 0; | |
| 1198 } | |
| 1199 } | |
| 1200 | |
|
338
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
1201 if (((!is_ambient_pressure_close_to_surface(&global.lifeData)) && (global.lifeData.pressure_surface_bar > START_DIVE_MOUNTAIN_MODE_BAR )) |
|
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
1202 || (global.lifeData.pressure_ambient_bar > START_DIVE_IMMEDIATLY_BAR)) |
|
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
1203 { |
| 38 | 1204 global.mode = MODE_BOOT; |
|
338
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
1205 } |
| 38 | 1206 scheduleUpdateLifeData(2000); |
| 988 | 1207 #ifdef ENABLE_GNSS_INTER |
| 1208 if(GPIO_GetVersion() > 0) | |
| 936 | 1209 { |
| 988 | 1210 if(deepSleepCntDwn) |
| 936 | 1211 { |
| 988 | 1212 deepSleepCntDwn--; |
| 1213 if(deepSleepCntDwn == 0) | |
| 1214 { | |
| 1215 deepSleep = 1; | |
| 1216 GPIO_GPS_OFF(); | |
| 1217 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; | |
| 1218 GPIO_InitStruct.Speed = GPIO_SPEED_LOW; | |
| 1219 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
| 1220 GPIO_InitStruct.Pin = GPIO_PIN_All ^ (GPS_POWER_CONTROL_PIN); | |
| 1221 HAL_GPIO_Init( GPIOB, &GPIO_InitStruct); | |
| 1222 uartGnss_SetState(UART_GNSS_INIT); | |
| 1223 } | |
| 942 | 1224 } |
| 988 | 1225 else |
| 942 | 1226 { |
| 988 | 1227 if((deepSleep = 1) && (global.lifeData.battery_voltage < 3.5)) /* switch off backup voltage if battery gets low */ |
| 1228 { | |
| 1229 deepSleep = 2; | |
| 1230 GPIO_GPS_BCKP_OFF(); | |
| 1231 GPIO_InitStruct.Pin = GPIO_PIN_All ^ (GPS_BCKP_CONTROL_PIN); | |
| 1232 HAL_GPIO_Init( GPIOB, &GPIO_InitStruct); | |
| 1233 __HAL_RCC_GPIOB_CLK_DISABLE(); | |
| 1234 } | |
| 936 | 1235 } |
| 1236 } | |
| 1237 #endif | |
| 38 | 1238 } |
| 1239 while(global.mode == MODE_SLEEP); | |
| 1240 /* new section for system after Standby */ | |
| 1241 scheduleUpdateLifeData(-1); | |
| 1242 clearDecoNow = 0; | |
| 1243 setButtonsNow = 0; | |
|
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1244 reinitGlobals(); |
| 668 | 1245 ReInit_battery_charger_status_pins(); |
| 988 | 1246 #ifdef ENABLE_GNSS_INTERN |
| 1247 if(GPIO_GetVersion() > 0) | |
| 940 | 1248 { |
| 988 | 1249 if(deepSleep != 0) |
| 1250 { | |
| 1251 GPIO_GNSS_Init(); | |
| 1252 } | |
| 940 | 1253 } |
| 942 | 1254 #endif |
| 38 | 1255 } |
| 1256 | |
| 1257 | |
| 1258 | |
| 1259 /* Private functions ---------------------------------------------------------*/ | |
| 1260 | |
| 1261 /** | |
| 1262 ****************************************************************************** | |
| 1263 * @brief scheduleUpdateLifeData / calculates tissues | |
|
763
aa6006975e76
increase HAL_Delay to 10ms for cold-start-button reset
heinrichsweikamp
parents:
742
diff
changeset
|
1264 * @author heinrichs weikamp gmbh |
| 38 | 1265 * @version V0.0.1 |
| 1266 * @date 22-April-2014 | |
| 1267 ****************************************************************************** | |
| 1268 */ | |
| 1269 | |
| 1270 | |
| 1271 void scheduleUpdateLifeData(int32_t asynchron_milliseconds_since_last) | |
| 1272 { | |
| 1273 static _Bool first = 1; | |
| 1274 static uint32_t tickstart = 0; | |
| 1275 static uint32_t ticksrest = 0; | |
| 1276 | |
| 1277 uint32_t ticksdiff = 0; | |
| 1278 uint32_t ticksnow = 0; | |
| 1279 uint32_t time_seconds = 0; | |
| 1280 uint8_t whichGasTmp = 0; | |
| 1281 | |
| 135 | 1282 uint8_t updateTissueData = 0; |
| 1283 | |
| 1284 | |
| 1285 if(global.lifeData.pressure_surface_bar == INVALID_PREASURE_VALUE) | |
| 1286 { | |
| 1287 updateTissueData = 1; | |
| 1288 } | |
| 1289 | |
| 38 | 1290 if(asynchron_milliseconds_since_last < 0) |
| 1291 { | |
| 1292 first = 1; | |
| 1293 tickstart = 0; | |
| 1294 ticksrest = 0; | |
| 1295 return; | |
| 1296 } | |
| 1297 | |
| 1298 if(!asynchron_milliseconds_since_last && first) | |
| 1299 { | |
| 1300 tickstart = HAL_GetTick(); | |
| 1301 first = 0; | |
| 1302 return; | |
| 1303 } | |
| 1304 | |
| 1305 whichGasTmp = global.whichGas; | |
| 1306 global.lifeData.actualGas = global.aktualGas[whichGasTmp]; | |
| 1307 global.lifeData.pressure_ambient_bar = get_pressure_mbar() / 1000.0f; | |
| 1308 global.lifeData.pressure_surface_bar = get_surface_mbar() / 1000.0f; | |
| 1309 | |
| 135 | 1310 if(updateTissueData) |
| 1311 { | |
| 1312 decom_reset_with_ambientmbar(global.lifeData.pressure_surface_bar,&global.lifeData); | |
| 1313 } | |
| 1314 | |
| 38 | 1315 if(!asynchron_milliseconds_since_last) |
| 1316 { | |
| 1317 ticksnow = HAL_GetTick(); | |
| 1318 ticksdiff = time_elapsed_ms(tickstart,ticksnow); | |
| 1319 } | |
| 1320 else | |
| 1321 { | |
| 1322 first = 1; | |
| 1323 ticksdiff = asynchron_milliseconds_since_last; | |
| 1324 } | |
| 1325 | |
| 1326 if(ticksrest > 1000) // whatever happens after standby with STM32L476 | |
| 1327 ticksrest = 0; // maybe move static to SRAM2 | |
| 1328 | |
| 1329 ticksdiff += ticksrest; | |
| 1330 time_seconds = ticksdiff/ 1000; | |
| 1331 ticksrest = ticksdiff - time_seconds * 1000; | |
| 1332 tickstart = ticksnow; | |
| 1333 | |
| 1334 decom_tissues_exposure((int)time_seconds, &global.lifeData); | |
| 1335 if(global.demo_mode) | |
| 1336 decom_tissues_exposure((int)(3*time_seconds), &global.lifeData); | |
| 1337 copyTissueData(); | |
| 1338 } | |
| 1339 | |
| 1340 | |
| 1341 /** | |
| 1342 ****************************************************************************** | |
| 1343 * @brief scheduleUpdateDeviceData | |
| 1344 * @author heinrichs weikamp gmbh | |
| 1345 * @version V0.0.1 | |
| 1346 * @date 16-March-2015 | |
| 1347 * | |
| 1348 * two step process | |
| 1349 * first compare with data from main CPU == externalLogbookFlash | |
| 1350 * second update with new sensor data | |
| 1351 ****************************************************************************** | |
| 1352 */ | |
| 1353 void scheduleSetDate(SDeviceLine *line) | |
| 1354 { | |
| 1355 extern RTC_HandleTypeDef RTCHandle; | |
| 1356 | |
| 1357 line->date_rtc_dr = (uint32_t)(RTCHandle.Instance->DR & RTC_DR_RESERVED_MASK); | |
| 1358 line->time_rtc_tr = (uint32_t)(RTCHandle.Instance->TR & RTC_TR_RESERVED_MASK); | |
| 1359 } | |
| 1360 | |
| 1361 | |
| 1362 void scheduleCopyDeviceData(SDeviceLine *lineWrite, const SDeviceLine *lineRead) | |
| 1363 { | |
| 1364 lineWrite->date_rtc_dr = lineRead->date_rtc_dr; | |
| 1365 lineWrite->time_rtc_tr = lineRead->time_rtc_tr; | |
| 1366 lineWrite->value_int32 = lineRead->value_int32; | |
| 1367 } | |
| 1368 | |
| 1369 | |
|
409
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1370 void scheduletranslateDate(uint32_t datetmpreg, RTC_DateTypeDef *sDate) |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1371 { |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1372 datetmpreg = (uint32_t)(datetmpreg & RTC_DR_RESERVED_MASK); |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1373 |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1374 /* Fill the structure fields with the read parameters */ |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1375 sDate->Year = (uint8_t)((datetmpreg & (RTC_DR_YT | RTC_DR_YU)) >> 16); |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1376 sDate->Month = (uint8_t)((datetmpreg & (RTC_DR_MT | RTC_DR_MU)) >> 8); |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1377 sDate->Date = (uint8_t)(datetmpreg & (RTC_DR_DT | RTC_DR_DU)); |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1378 sDate->WeekDay = (uint8_t)((datetmpreg & (RTC_DR_WDU)) >> 13); |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1379 |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1380 /* Convert the date structure parameters to Binary format */ |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1381 sDate->Year = (uint8_t)RTC_Bcd2ToByte(sDate->Year); |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1382 sDate->Month = (uint8_t)RTC_Bcd2ToByte(sDate->Month); |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1383 sDate->Date = (uint8_t)RTC_Bcd2ToByte(sDate->Date); |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1384 } |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1385 |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1386 void scheduleCheckDate(void) |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1387 { |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1388 uint32_t localdate; |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1389 RTC_DateTypeDef sDate; |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1390 localdate = (uint32_t)(RTCHandle.Instance->DR & RTC_DR_RESERVED_MASK); |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1391 scheduletranslateDate(localdate, &sDate); |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1392 |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1393 /* RTC start in year 2000 in case of a power loss. Use the operation counter time stamp to bring at last date to a more realistic value */ |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1394 if(sDate.Year < 15) |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1395 { |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1396 scheduletranslateDate(DeviceDataFlash.hoursOfOperation.date_rtc_dr, &sDate); |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1397 if(sDate.Year > 16) |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1398 { |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1399 RTC_SetDate(sDate); |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1400 } |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1401 } |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1402 |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1403 } |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1404 |
| 38 | 1405 void scheduleUpdateDeviceData(void) |
| 1406 { | |
| 1407 /* first step, main CPU */ | |
| 1408 | |
| 1409 if(deviceDataFlashValid) | |
| 1410 { | |
| 1411 /* max values */ | |
|
409
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1412 if(global.deviceData.hoursOfOperation.value_int32 < DeviceDataFlash.hoursOfOperation.value_int32) |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1413 { |
|
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1414 scheduleCopyDeviceData(&global.deviceData.hoursOfOperation, &DeviceDataFlash.hoursOfOperation); |
|
414
6886aeeca454
Added compile switch for restoring of last known date after power lost:
ideenmodellierer
parents:
409
diff
changeset
|
1415 #ifdef RESTORE_LAST_KNOWN_DATE |
|
409
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1416 scheduleCheckDate(); |
|
414
6886aeeca454
Added compile switch for restoring of last known date after power lost:
ideenmodellierer
parents:
409
diff
changeset
|
1417 #endif |
|
409
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1418 } |
| 38 | 1419 if(global.deviceData.batteryChargeCompleteCycles.value_int32 < DeviceDataFlash.batteryChargeCompleteCycles.value_int32) |
| 1420 { | |
| 1421 scheduleCopyDeviceData(&global.deviceData.batteryChargeCompleteCycles, &DeviceDataFlash.batteryChargeCompleteCycles); | |
| 1422 } | |
| 1423 if(global.deviceData.batteryChargeCycles.value_int32 < DeviceDataFlash.batteryChargeCycles.value_int32) | |
| 1424 { | |
| 1425 scheduleCopyDeviceData(&global.deviceData.batteryChargeCycles, &DeviceDataFlash.batteryChargeCycles); | |
| 1426 } | |
| 1427 if(global.deviceData.temperatureMaximum.value_int32 < DeviceDataFlash.temperatureMaximum.value_int32) | |
| 1428 { | |
| 1429 scheduleCopyDeviceData(&global.deviceData.temperatureMaximum, &DeviceDataFlash.temperatureMaximum); | |
| 1430 } | |
| 1431 if(global.deviceData.depthMaximum.value_int32 < DeviceDataFlash.depthMaximum.value_int32) | |
| 1432 { | |
| 1433 scheduleCopyDeviceData(&global.deviceData.depthMaximum, &DeviceDataFlash.depthMaximum); | |
| 1434 } | |
| 1435 if(global.deviceData.diveCycles.value_int32 < DeviceDataFlash.diveCycles.value_int32) | |
| 1436 { | |
| 1437 scheduleCopyDeviceData(&global.deviceData.diveCycles, &DeviceDataFlash.diveCycles); | |
| 1438 } | |
| 1439 | |
| 1440 /* min values */ | |
| 1441 if(global.deviceData.temperatureMinimum.value_int32 > DeviceDataFlash.temperatureMinimum.value_int32) | |
| 1442 { | |
| 1443 scheduleCopyDeviceData(&global.deviceData.temperatureMinimum, &DeviceDataFlash.temperatureMinimum); | |
| 1444 } | |
| 1445 if(global.deviceData.voltageMinimum.value_int32 > DeviceDataFlash.voltageMinimum.value_int32) | |
| 1446 { | |
| 1447 scheduleCopyDeviceData(&global.deviceData.voltageMinimum, &DeviceDataFlash.voltageMinimum); | |
| 1448 } | |
| 1449 } | |
| 1450 | |
| 1451 /* second step, sensor data */ | |
| 1452 int32_t temperature_centigrad_int32; | |
| 1453 int32_t pressure_mbar_int32; | |
| 1454 int32_t voltage_mvolt_int32; | |
| 1455 | |
| 1456 temperature_centigrad_int32 = (int32_t)(get_temperature() * 100); | |
| 1457 if(temperature_centigrad_int32 < global.deviceData.temperatureMinimum.value_int32) | |
| 1458 { | |
| 1459 global.deviceData.temperatureMinimum.value_int32 = temperature_centigrad_int32; | |
| 88 | 1460 scheduleSetDate(&global.deviceData.temperatureMinimum); |
| 38 | 1461 } |
| 1462 | |
| 1463 if(temperature_centigrad_int32 > global.deviceData.temperatureMaximum.value_int32) | |
| 1464 { | |
| 1465 global.deviceData.temperatureMaximum.value_int32 = temperature_centigrad_int32; | |
| 88 | 1466 scheduleSetDate(&global.deviceData.temperatureMaximum); |
| 38 | 1467 } |
| 1468 | |
| 1469 pressure_mbar_int32 = (int32_t)get_pressure_mbar(); | |
| 1470 if(pressure_mbar_int32 > global.deviceData.depthMaximum.value_int32) | |
| 1471 { | |
| 1472 global.deviceData.depthMaximum.value_int32 = pressure_mbar_int32; | |
| 88 | 1473 scheduleSetDate(&global.deviceData.depthMaximum); |
| 38 | 1474 } |
| 1475 | |
| 1476 voltage_mvolt_int32 = (int32_t)(get_voltage() * 1000); | |
| 1477 if(voltage_mvolt_int32 < global.deviceData.voltageMinimum.value_int32) | |
| 1478 { | |
| 1479 global.deviceData.voltageMinimum.value_int32 = voltage_mvolt_int32; | |
| 88 | 1480 scheduleSetDate(&global.deviceData.voltageMinimum); |
| 38 | 1481 } |
| 1482 | |
| 1483 /* third step, counter */ | |
| 1484 switch (global.mode) | |
| 1485 { | |
| 1486 case MODE_SURFACE: | |
| 1487 case MODE_DIVE: | |
| 1488 default: | |
| 1489 deviceDataSubSeconds++; | |
| 1490 if(deviceDataSubSeconds > 10) | |
| 1491 { | |
| 1492 deviceDataSubSeconds = 0; | |
| 1493 global.deviceData.hoursOfOperation.value_int32++; | |
|
409
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1494 scheduleSetDate(&global.deviceData.hoursOfOperation); |
| 38 | 1495 } |
| 1496 break; | |
| 1497 | |
| 662 | 1498 case MODE_SLEEP: |
| 38 | 1499 case MODE_SHUTDOWN: |
| 1500 break; | |
| 1501 } | |
| 1502 } | |
| 1503 | |
| 1504 | |
| 1505 void scheduleUpdateDeviceDataChargerFull(void) | |
| 1506 { | |
| 1507 global.deviceData.batteryChargeCompleteCycles.value_int32++; | |
| 88 | 1508 scheduleSetDate(&global.deviceData.batteryChargeCompleteCycles); |
| 38 | 1509 } |
| 1510 | |
| 1511 | |
| 1512 void scheduleUpdateDeviceDataChargerCharging(void) | |
| 1513 { | |
| 1514 global.deviceData.batteryChargeCycles.value_int32++; | |
| 88 | 1515 scheduleSetDate(&global.deviceData.batteryChargeCycles); |
| 38 | 1516 } |
| 1517 | |
| 1518 | |
| 1519 /** | |
| 1520 ****************************************************************************** | |
| 1521 * @brief vpm_crush / calls vpm calc_crushing_pressure every four seconds during descend | |
|
763
aa6006975e76
increase HAL_Delay to 10ms for cold-start-button reset
heinrichsweikamp
parents:
742
diff
changeset
|
1522 * @author heinrichs weikamp gmbh |
| 38 | 1523 * @version V0.0.1 |
| 1524 * @date 22-April-2014 | |
| 1525 ****************************************************************************** | |
| 1526 */ | |
| 1527 _Bool vpm_crush2(void) | |
| 1528 { | |
| 1529 int i = 0; | |
| 1530 static float starting_ambient_pressure = 0; | |
| 1531 static float ending_ambient_pressure = 0; | |
| 1532 static float time_calc_begin = -1; | |
| 1533 static float initial_helium_pressure[16]; | |
| 1534 static float initial_nitrogen_pressure[16]; | |
| 1535 ending_ambient_pressure = global.lifeData.pressure_ambient_bar * 10; | |
| 1536 | |
| 1537 if((global.lifeData.dive_time_seconds <= 4) || (starting_ambient_pressure >= ending_ambient_pressure)) | |
| 1538 { | |
| 1539 time_calc_begin = global.lifeData.dive_time_seconds; | |
| 1540 starting_ambient_pressure = global.lifeData.pressure_ambient_bar * 10; | |
| 1541 for( i = 0; i < 16; i++) | |
| 1542 { | |
| 1543 initial_helium_pressure[i] = global.lifeData.tissue_helium_bar[i] * 10; | |
| 1544 initial_nitrogen_pressure[i] = global.lifeData.tissue_nitrogen_bar[i] * 10; | |
| 1545 } | |
| 1546 return 0; | |
| 1547 } | |
| 1548 if(global.lifeData.dive_time_seconds - time_calc_begin >= 4) | |
| 1549 { | |
| 1550 if(ending_ambient_pressure > starting_ambient_pressure + 0.5f) | |
| 1551 { | |
| 1552 float rate = (ending_ambient_pressure - starting_ambient_pressure) * 60 / 4; | |
| 1553 calc_crushing_pressure(&global.lifeData, &global.vpm, initial_helium_pressure, initial_nitrogen_pressure, starting_ambient_pressure, rate); | |
| 1554 | |
| 1555 time_calc_begin = global.lifeData.dive_time_seconds; | |
| 1556 starting_ambient_pressure = global.lifeData.pressure_ambient_bar * 10; | |
| 1557 for( i = 0; i < 16; i++) | |
| 1558 { | |
| 1559 initial_helium_pressure[i] = global.lifeData.tissue_helium_bar[i] * 10; | |
| 1560 initial_nitrogen_pressure[i] = global.lifeData.tissue_nitrogen_bar[i] * 10; | |
| 1561 } | |
| 1562 | |
| 1563 return 1; | |
| 1564 } | |
| 1565 | |
| 1566 } | |
| 1567 return 0; | |
| 1568 } | |
| 1569 | |
| 1570 | |
| 1571 long get_nofly_time_minutes(void) | |
| 1572 { | |
| 1573 | |
| 1574 if(global.no_fly_time_minutes <= 0) | |
| 1575 return 0; | |
| 1576 | |
| 1577 long minutes_since_last_dive = global.seconds_since_last_dive/60; | |
| 1578 | |
| 1579 if((global.seconds_since_last_dive > 0) && (global.no_fly_time_minutes > minutes_since_last_dive)) | |
| 1580 { | |
| 1581 return (global.no_fly_time_minutes - minutes_since_last_dive); | |
| 1582 } | |
| 1583 else | |
| 1584 { | |
| 1585 global.no_fly_time_minutes = 0; | |
| 1586 return 0; | |
| 1587 } | |
| 1588 } | |
| 1589 | |
| 1590 | |
| 1591 //Supports threadsave copying!!! | |
| 1592 void copyActualGas(SGas gas) | |
| 1593 { | |
| 1594 uint8_t whichGas = !global.whichGas; | |
| 1595 global.aktualGas[whichGas] = gas; | |
| 1596 global.whichGas = whichGas; | |
| 1597 } | |
| 1598 | |
| 1599 | |
| 1600 //Supports threadsave copying!!! | |
| 1601 void copyPressureData(void) | |
| 1602 { | |
|
240
625d20070261
Improvement SPI stability/recoverability
Jan Mulder <jlmulder@xs4all.nl>
parents:
231
diff
changeset
|
1603 global.dataSendToMaster.sensorErrors = global.I2C_SystemStatus; |
| 38 | 1604 uint8_t boolPressureData = !global.dataSendToMaster.boolPressureData; |
| 1605 global.dataSendToMaster.data[boolPressureData].temperature = get_temperature(); | |
| 1606 global.dataSendToMaster.data[boolPressureData].pressure_mbar = get_pressure_mbar(); | |
| 1607 global.dataSendToMaster.data[boolPressureData].surface_mbar = get_surface_mbar(); | |
| 1608 global.dataSendToMaster.data[boolPressureData].ascent_rate_meter_per_min = global.lifeData.ascent_rate_meter_per_min; | |
| 1609 global.dataSendToMaster.data[boolPressureData].pressure_uTick = HAL_GetTick(); | |
| 1610 global.dataSendToMaster.boolPressureData = boolPressureData; | |
|
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1611 global.dataSendToMaster.data[boolPressureData].SPARE1 = is_surface_pressure_stable(); |
| 38 | 1612 } |
| 1613 | |
| 1614 | |
| 1615 //Supports threadsave copying!!! | |
| 1616 void copyCnsAndOtuData(void) | |
| 1617 { | |
| 1618 //uint8_t dataSendToMaster. | |
| 1619 uint8_t boolToxicData = !global.dataSendToMaster.boolToxicData; | |
| 1620 global.dataSendToMaster.data[boolToxicData].cns = global.lifeData.cns; | |
| 1621 global.dataSendToMaster.data[boolToxicData].otu = global.lifeData.otu; | |
| 1622 global.dataSendToMaster.data[boolToxicData].desaturation_time_minutes = global.lifeData.desaturation_time_minutes; | |
| 1623 global.dataSendToMaster.data[boolToxicData].no_fly_time_minutes = get_nofly_time_minutes(); | |
| 1624 global.dataSendToMaster.boolToxicData = boolToxicData; | |
| 1625 } | |
| 1626 | |
| 1627 | |
| 1628 //Supports threadsave copying!!! | |
| 1629 void copyTimeData(void) | |
| 1630 { | |
| 1631 extern RTC_HandleTypeDef RTCHandle; | |
| 1632 | |
| 1633 uint8_t boolTimeData = !global.dataSendToMaster.boolTimeData; | |
| 1634 global.dataSendToMaster.data[boolTimeData].localtime_rtc_tr = (uint32_t)(RTCHandle.Instance->TR & RTC_TR_RESERVED_MASK); | |
| 1635 global.dataSendToMaster.data[boolTimeData].localtime_rtc_dr = (uint32_t)(RTCHandle.Instance->DR & RTC_DR_RESERVED_MASK); | |
| 1636 global.dataSendToMaster.data[boolTimeData].divetime_seconds = (uint32_t)global.lifeData.dive_time_seconds; | |
| 1637 global.dataSendToMaster.data[boolTimeData].dive_time_seconds_without_surface_time = (uint32_t)global.lifeData.dive_time_seconds_without_surface_time; | |
| 1638 global.dataSendToMaster.data[boolTimeData].surfacetime_seconds = (uint32_t)global.seconds_since_last_dive; | |
| 1639 global.dataSendToMaster.data[boolTimeData].counterSecondsShallowDepth = (uint32_t)global.lifeData.counterSecondsShallowDepth; | |
| 1640 global.dataSendToMaster.boolTimeData = boolTimeData; | |
| 1641 } | |
| 1642 | |
| 1643 | |
| 1644 //Supports threadsave copying!!! | |
| 1645 void copyCompassData(void) | |
| 1646 { | |
| 1647 extern float compass_heading; | |
| 1648 extern float compass_roll; | |
| 1649 extern float compass_pitch; | |
| 1650 //uint8_t dataSendToMaster. | |
| 1651 uint8_t boolCompassData = !global.dataSendToMaster.boolCompassData; | |
| 1652 global.dataSendToMaster.data[boolCompassData].compass_heading = compass_heading; | |
| 1653 global.dataSendToMaster.data[boolCompassData].compass_roll = compass_roll; | |
| 1654 global.dataSendToMaster.data[boolCompassData].compass_pitch = compass_pitch; | |
| 1655 global.dataSendToMaster.data[boolCompassData].compass_DX_f = 0; | |
| 1656 global.dataSendToMaster.data[boolCompassData].compass_DY_f = 0; | |
| 1657 global.dataSendToMaster.data[boolCompassData].compass_DZ_f = 0; | |
| 1658 global.dataSendToMaster.data[boolCompassData].compass_uTick = HAL_GetTick(); | |
| 1659 global.dataSendToMaster.boolCompassData = boolCompassData; | |
| 1660 } | |
| 1661 | |
| 1662 | |
| 1663 void copyCompassDataDuringCalibration(int16_t dx, int16_t dy, int16_t dz) | |
| 1664 { | |
| 1665 extern float compass_heading; | |
| 1666 extern float compass_roll; | |
| 1667 extern float compass_pitch; | |
| 1668 //uint8_t dataSendToMaster. | |
| 1669 uint8_t boolCompassData = !global.dataSendToMaster.boolCompassData; | |
| 1670 global.dataSendToMaster.data[boolCompassData].compass_heading = compass_heading; | |
| 1671 global.dataSendToMaster.data[boolCompassData].compass_roll = compass_roll; | |
| 1672 global.dataSendToMaster.data[boolCompassData].compass_pitch = compass_pitch; | |
| 1673 global.dataSendToMaster.data[boolCompassData].compass_DX_f = dx; | |
| 1674 global.dataSendToMaster.data[boolCompassData].compass_DY_f = dy; | |
| 1675 global.dataSendToMaster.data[boolCompassData].compass_DZ_f = dz; | |
| 1676 global.dataSendToMaster.boolCompassData = boolCompassData; | |
| 1677 } | |
| 1678 | |
| 1679 | |
| 1680 //Supports threadsave copying!!! | |
| 1681 void copyBatteryData(void) | |
| 1682 { | |
| 1683 uint8_t boolBatteryData = !global.dataSendToMaster.boolBatteryData; | |
| 668 | 1684 global.lifeData.battery_charge = get_charge(); |
| 38 | 1685 global.dataSendToMaster.data[boolBatteryData].battery_voltage = get_voltage(); |
| 668 | 1686 |
| 1687 if(battery_gas_gauge_isChargeValueValid()) | |
| 1688 { | |
| 1689 global.dataSendToMaster.data[boolBatteryData].battery_charge= global.lifeData.battery_charge; | |
| 1690 } | |
| 1691 else | |
| 1692 { | |
| 1693 global.dataSendToMaster.data[boolBatteryData].battery_charge = global.lifeData.battery_charge * -1.0; /* negate value to show that this is just an assumption */ | |
| 1694 } | |
| 38 | 1695 global.dataSendToMaster.boolBatteryData = boolBatteryData; |
| 1696 } | |
| 1697 | |
| 1698 | |
| 1699 //Supports threadsave copying!!! | |
| 1700 void copyAmbientLightData(void) | |
| 1701 { | |
| 1702 uint8_t boolAmbientLightData = !global.dataSendToMaster.boolAmbientLightData; | |
| 1703 global.dataSendToMaster.data[boolAmbientLightData].ambient_light_level = get_ambient_light_level(); | |
| 1704 global.dataSendToMaster.boolAmbientLightData = boolAmbientLightData; | |
| 1705 } | |
| 1706 | |
| 1707 | |
| 1708 //Supports threadsave copying!!! | |
| 1709 void copyTissueData(void) | |
| 1710 { | |
| 1711 //uint8_t dataSendToMaster. | |
| 1712 uint8_t boolTisssueData = !global.dataSendToMaster.boolTisssueData; | |
| 1713 for(int i = 0; i < 16; i++) | |
| 1714 { | |
| 1715 global.dataSendToMaster.data[boolTisssueData].tissue_nitrogen_bar[i] = global.lifeData.tissue_nitrogen_bar[i]; | |
| 1716 global.dataSendToMaster.data[boolTisssueData].tissue_helium_bar[i] = global.lifeData.tissue_helium_bar[i]; | |
| 1717 } | |
| 1718 global.dataSendToMaster.boolTisssueData = boolTisssueData; | |
| 1719 } | |
| 1720 | |
| 1721 | |
| 1722 //Supports threadsave copying!!! | |
| 1723 void copyVpmCrushingData(void) | |
| 1724 { | |
| 1725 //uint8_t dataSendToMaster. | |
| 1726 uint8_t boolCrushingData = !global.dataSendToMaster.boolCrushingData; | |
| 1727 for(int i = 0; i < 16; i++) | |
| 1728 { | |
| 1729 global.dataSendToMaster.data[boolCrushingData].max_crushing_pressure_n2[i] = global.vpm.max_crushing_pressure_n2[i]; | |
| 1730 global.dataSendToMaster.data[boolCrushingData].max_crushing_pressure_he[i] = global.vpm.max_crushing_pressure_he[i]; | |
| 1731 global.dataSendToMaster.data[boolCrushingData].adjusted_critical_radius_he[i] = global.vpm.adjusted_critical_radius_he[i]; | |
| 1732 global.dataSendToMaster.data[boolCrushingData].adjusted_critical_radius_n2[i] = global.vpm.adjusted_critical_radius_n2[i]; | |
| 1733 } | |
| 1734 global.dataSendToMaster.boolCrushingData = boolCrushingData; | |
| 1735 } | |
| 1736 | |
| 1737 | |
| 1738 void copyDeviceData(void) | |
| 1739 { | |
| 1740 uint8_t boolDeviceData = !global.deviceDataSendToMaster.boolDeviceData; | |
| 1741 memcpy(&global.deviceDataSendToMaster.DeviceData[boolDeviceData], &global.deviceData,sizeof(SDevice)); | |
| 1742 global.deviceDataSendToMaster.boolDeviceData = boolDeviceData; | |
| 1743 | |
| 1744 global.deviceDataSendToMaster.boolVpmRepetitiveDataValid = 0; | |
| 1745 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.adjusted_critical_radius_he, &global.vpm.adjusted_critical_radius_he, sizeof(16*4)); | |
| 1746 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.adjusted_critical_radius_n2, &global.vpm.adjusted_critical_radius_n2, sizeof(16*4)); | |
| 1747 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.adjusted_crushing_pressure_he, &global.vpm.adjusted_crushing_pressure_he, sizeof(16*4)); | |
| 1748 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.adjusted_crushing_pressure_n2, &global.vpm.adjusted_crushing_pressure_n2, sizeof(16*4)); | |
| 1749 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.initial_allowable_gradient_he, &global.vpm.initial_allowable_gradient_he, sizeof(16*4)); | |
| 1750 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.initial_allowable_gradient_n2, &global.vpm.initial_allowable_gradient_n2, sizeof(16*4)); | |
| 1751 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.max_actual_gradient, &global.vpm.max_actual_gradient, sizeof(16*4)); | |
| 1752 global.deviceDataSendToMaster.VpmRepetitiveData.repetitive_variables_not_valid = global.vpm.repetitive_variables_not_valid; | |
| 1753 global.deviceDataSendToMaster.boolVpmRepetitiveDataValid = 1; | |
| 1754 } | |
| 1755 | |
| 1756 /* copyPICdata(); is used in spi.c */ | |
| 1757 void copyPICdata(void) | |
| 1758 { | |
| 1759 uint8_t boolPICdata = !global.dataSendToMaster.boolPICdata; | |
| 1760 for(int i = 0; i < 3; i++) | |
| 1761 { | |
| 1762 global.dataSendToMaster.data[boolPICdata].button_setting[i] = global.ButtonPICdata[i]; | |
| 1763 } | |
| 1764 global.dataSendToMaster.boolPICdata = boolPICdata; | |
| 1765 } | |
| 1766 | |
|
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1767 void copyExtADCdata() |
|
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1768 { |
|
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1769 float value; |
|
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1770 |
|
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1771 uint8_t channel = 0; |
|
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1772 |
| 691 | 1773 uint8_t boolADCBuffer = ~(global.dataSendToMaster.boolADCO2Data & DATA_BUFFER_ADC); |
| 1774 | |
| 1775 boolADCBuffer &= DATA_BUFFER_ADC; | |
| 1776 global.dataSendToMaster.boolADCO2Data &= ~DATA_BUFFER_ADC; | |
| 1777 | |
|
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1778 for(channel = 0; channel < MAX_ADC_CHANNEL; channel++) |
|
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1779 { |
|
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1780 value = getExternalInterfaceChannel(channel); |
| 691 | 1781 global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].extADC_voltage[channel] = value; |
|
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1782 } |
| 786 | 1783 global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].externalInterface_SensorID = externalInterface_GetSensorData(0xFF, (uint8_t*)&global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].sensor_data); |
| 731 | 1784 memcpy(global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].sensor_map,externalInterface_GetSensorMapPointer(1),EXT_INTERFACE_SENSOR_CNT); |
| 691 | 1785 global.dataSendToMaster.boolADCO2Data |= boolADCBuffer; |
|
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1786 } |
|
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1787 |
| 662 | 1788 void copyExtCO2data() |
| 1789 { | |
| 1790 uint16_t value; | |
| 691 | 1791 uint8_t boolCO2Buffer = ~(global.dataSendToMaster.boolADCO2Data & DATA_BUFFER_CO2); |
| 1792 | |
| 1793 global.dataSendToMaster.boolADCO2Data &= ~DATA_BUFFER_CO2; | |
| 1794 boolCO2Buffer &= DATA_BUFFER_CO2; | |
| 662 | 1795 |
| 1796 if(externalInterface_GetCO2State()) | |
| 1797 { | |
| 1798 value = externalInterface_GetCO2Value(); | |
| 691 | 1799 global.dataSendToMaster.data[(boolCO2Buffer && DATA_BUFFER_CO2)].CO2_ppm = value; |
| 662 | 1800 value = externalInterface_GetCO2SignalStrength(); |
| 691 | 1801 global.dataSendToMaster.data[(boolCO2Buffer && DATA_BUFFER_CO2)].CO2_signalStrength = value; |
| 1802 global.dataSendToMaster.data[(boolCO2Buffer && DATA_BUFFER_CO2)].externalInterface_CmdAnswer = externalInterface_GetCO2State(); | |
| 662 | 1803 externalInterface_SetCO2State(EXT_INTERFACE_33V_ON); /* clear command responses */ |
| 1804 } | |
| 1805 else | |
| 1806 { | |
| 691 | 1807 global.dataSendToMaster.data[(boolCO2Buffer && DATA_BUFFER_CO2)].CO2_ppm = 0; |
| 1808 global.dataSendToMaster.data[(boolCO2Buffer && DATA_BUFFER_CO2)].CO2_signalStrength = 0; | |
| 1809 global.dataSendToMaster.data[(boolCO2Buffer && DATA_BUFFER_CO2)].externalInterface_CmdAnswer = 0; | |
| 662 | 1810 } |
| 691 | 1811 global.dataSendToMaster.boolADCO2Data |= boolCO2Buffer; |
| 662 | 1812 } |
| 38 | 1813 |
|
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
881
diff
changeset
|
1814 void copyGNSSdata(void) |
|
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
881
diff
changeset
|
1815 { |
| 955 | 1816 RTC_TimeTypeDef sTimeNow; |
| 1817 | |
| 942 | 1818 global.dataSendToMaster.data[0].gnssInfo.coord.fLat = GNSS_Handle.fLat; |
| 1819 global.dataSendToMaster.data[0].gnssInfo.coord.fLon = GNSS_Handle.fLon; | |
| 931 | 1820 global.dataSendToMaster.data[0].gnssInfo.fixType = GNSS_Handle.fixType; |
| 1821 global.dataSendToMaster.data[0].gnssInfo.numSat = GNSS_Handle.numSat; | |
| 947 | 1822 global.dataSendToMaster.data[0].gnssInfo.DateTime.year = (uint8_t) (GNSS_Handle.year - 2000); |
| 1823 global.dataSendToMaster.data[0].gnssInfo.DateTime.month = GNSS_Handle.month; | |
| 1824 global.dataSendToMaster.data[0].gnssInfo.DateTime.day = GNSS_Handle.day; | |
| 1825 global.dataSendToMaster.data[0].gnssInfo.DateTime.hour = GNSS_Handle.hour; | |
| 1826 global.dataSendToMaster.data[0].gnssInfo.DateTime.min = GNSS_Handle.min; | |
| 1827 global.dataSendToMaster.data[0].gnssInfo.DateTime.sec = GNSS_Handle.sec; | |
| 1828 | |
| 940 | 1829 global.dataSendToMaster.data[0].gnssInfo.alive = GNSS_Handle.alive; |
| 1830 | |
| 955 | 1831 if(( GNSS_Handle.fixType < 2) && (GNSS_Handle.alive & GNSS_ALIVE_BACKUP_POS)) /* fallback to last known position ? */ |
| 1832 { | |
| 1833 RTC_GetTime(&sTimeNow); | |
| 1834 if(GNSS_Handle.last_hour > sTimeNow.Hours) | |
| 1835 { | |
| 1836 sTimeNow.Hours += 24; /* compensate date change */ | |
| 1837 } | |
| 1838 if(sTimeNow.Hours - GNSS_Handle.last_hour > 2) | |
| 1839 { | |
| 1840 GNSS_Handle.alive &= ~GNSS_ALIVE_BACKUP_POS; /* position outdated */ | |
| 1841 } | |
| 1842 else | |
| 1843 { | |
| 1844 global.dataSendToMaster.data[0].gnssInfo.coord.fLat = GNSS_Handle.last_fLat; | |
| 1845 global.dataSendToMaster.data[0].gnssInfo.coord.fLon = GNSS_Handle.last_fLon; | |
| 1846 } | |
| 1847 } | |
| 931 | 1848 memcpy(&global.dataSendToMaster.data[0].gnssInfo.signalQual,&GNSS_Handle.statSat, sizeof(GNSS_Handle.statSat)); |
|
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
881
diff
changeset
|
1849 } |
|
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
881
diff
changeset
|
1850 |
|
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
881
diff
changeset
|
1851 |
| 38 | 1852 typedef enum |
| 1853 { | |
| 1854 SPI3_OK = 0x00, | |
| 1855 SPI3_DEINIT = 0x01, | |
| 1856 } SPI3_StatusTypeDef; | |
| 1857 /* if spi3 is running and the SPI3_ButtonAdjust call returns OK, all is fine | |
| 1858 if the SPI3_ButtonAdjust call returns error, the spi3 is DeInit | |
| 1859 and will be init the next call of scheduleSetButtonResponsiveness() | |
| 1860 and data will be send again on the third call | |
| 1861 therefore on return 0 of scheduleSetButtonResponsiveness() the caller flag should kept active | |
| 1862 */ | |
| 1863 uint8_t scheduleSetButtonResponsiveness(void) | |
| 1864 { | |
| 1865 static uint8_t SPI3status = SPI3_OK; | |
| 1866 | |
| 1867 if((SPI3status == SPI3_OK) && (SPI3_ButtonAdjust(global.ButtonResponsiveness, global.ButtonPICdata))) | |
| 1868 { | |
| 1869 copyPICdata(); | |
| 1870 return 1; | |
| 1871 } | |
| 1872 else | |
| 1873 { | |
| 1874 for(int i=0;i<3;i++) | |
| 1875 { | |
| 1876 global.ButtonPICdata[i] = 0xFF; | |
| 1877 } | |
| 1878 copyPICdata(); | |
| 1879 | |
| 1880 if(SPI3status == SPI3_OK) | |
| 1881 { | |
| 1882 MX_SPI3_DeInit(); | |
| 1883 SPI3status = SPI3_DEINIT; | |
| 1884 } | |
| 1885 else | |
| 1886 { | |
| 1887 MX_SPI3_Init(); | |
| 1888 SPI3status = SPI3_OK; | |
| 1889 } | |
| 1890 return 0; | |
| 1891 } | |
| 1892 } | |
| 1893 | |
| 1894 | |
|
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
181
diff
changeset
|
1895 //save time difference |
| 38 | 1896 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow) |
| 1897 { | |
| 1898 if(ticksstart <= ticksnow) | |
| 1899 { | |
| 1900 return ticksnow - ticksstart; | |
| 1901 } | |
| 1902 else | |
| 1903 { | |
| 1904 return 0xFFFFFFFF - ticksstart + ticksnow; | |
| 1905 } | |
| 1906 } | |
| 1907 | |
| 1908 /* same as in data_central.c */ | |
|
310
95928ef3986f
Make dive mode detection more advanced
Jan Mulder <jlmulder@xs4all.nl>
parents:
301
diff
changeset
|
1909 _Bool is_ambient_pressure_close_to_surface(SLifeData *lifeData) |
| 38 | 1910 { |
|
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1911 _Bool retval = true; |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1912 |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1913 if(lifeData->pressure_ambient_bar != INVALID_PREASURE_VALUE) /* as long as no valid data is available expect we are close to surface */ |
|
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1914 { |
|
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1915 /* this will e.g. apply in case of a significant pressure change during last 30 minutes => use increased offset for surface detection */ |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1916 if (lifeData->pressure_ambient_bar > START_DIVE_IMMEDIATLY_BAR) |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1917 { |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1918 retval = false; |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1919 } |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1920 else if(is_surface_pressure_stable()) /* this is the expected start condition */ |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1921 { |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1922 if((lifeData->pressure_ambient_bar >= (lifeData->pressure_surface_bar + 0.1f)) |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1923 && (ManualExitDiveCounter == 0)) /* only if diver did not request to exit dive mode */ |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1924 { |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1925 retval = false; |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1926 } |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1927 } |
|
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1928 } |
|
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1929 return retval; |
| 38 | 1930 } |
| 1931 | |
| 881 | 1932 void evaluateAscentSpeed() |
| 1933 { | |
| 1934 static uint32_t lastPressureTick = 0; | |
| 1935 static float lastPressure_bar = 0.0f; | |
| 1936 static AscentStates_t ascentState = ASCENT_NONE; | |
| 1937 static uint8_t ascentStableCnt = 0; | |
| 1938 uint32_t tickPressureDiff = 0; | |
| 1939 uint32_t lasttick = HAL_GetTick(); | |
| 1940 float localAscentRate = 0.0; | |
| 1941 | |
| 1942 tickPressureDiff = time_elapsed_ms(lastPressureTick,lasttick); /* Calculate ascent rate every 400ms use timer to take care for small time shifts */ | |
| 1943 if(tickPressureDiff != 0) | |
| 1944 { | |
| 1945 if(lastPressure_bar >= 0) | |
| 1946 { | |
| 1947 localAscentRate = (lastPressure_bar - global.lifeData.pressure_ambient_bar) * (60000.0 / tickPressureDiff) * 10; /* bar * 10 = meter */ | |
| 904 | 1948 if((fabs(localAscentRate) < 1.0) || (global.lifeData.pressure_ambient_bar < START_DIVE_IMMEDIATLY_BAR)) |
| 881 | 1949 { |
| 1950 ascentState = ASCENT_NONE; | |
| 1951 ascentStableCnt = 0; | |
| 1952 } | |
| 1953 else if(localAscentRate > 0.0) | |
| 1954 { | |
| 1955 if(ascentState != ASCENT_FALLING) | |
| 1956 { | |
| 1957 if(ascentStableCnt < 5) | |
| 1958 { | |
| 1959 ascentStableCnt++; | |
| 1960 } | |
| 1961 else | |
| 1962 { | |
| 1963 ascentState = ASCENT_RISING; | |
| 1964 } | |
| 1965 } | |
| 1966 else | |
| 1967 { | |
| 1968 ascentState = ASCENT_NONE; | |
| 1969 ascentStableCnt = 0; | |
| 1970 } | |
| 1971 } | |
| 1972 else /* must be falling */ | |
| 1973 { | |
| 1974 if(ascentState != ASCENT_RISING) | |
| 1975 { | |
| 1976 if(ascentStableCnt < 5) | |
| 1977 { | |
| 1978 ascentStableCnt++; | |
| 1979 } | |
| 1980 else | |
| 1981 { | |
| 1982 ascentState = ASCENT_FALLING; | |
| 1983 } | |
| 1984 } | |
| 1985 else | |
| 1986 { | |
| 1987 ascentState = ASCENT_NONE; | |
| 1988 ascentStableCnt = 0; | |
| 1989 } | |
| 1990 } | |
| 1991 if(ascentState != ASCENT_NONE) | |
| 1992 { | |
| 1993 global.lifeData.ascent_rate_meter_per_min = localAscentRate; | |
| 1994 } | |
| 1995 else | |
| 1996 { | |
| 1997 global.lifeData.ascent_rate_meter_per_min = 0; | |
| 1998 } | |
| 1999 } | |
| 2000 } | |
| 2001 lastPressure_bar = global.lifeData.pressure_ambient_bar; | |
| 2002 lastPressureTick = lasttick; | |
| 2003 } | |
| 38 | 2004 |
| 2005 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ | |
| 2006 |
