Mercurial > public > ostc4
annotate Small_CPU/Src/scheduler.c @ 1014:8c0134a287da GasConsumption
Add a log data event to the scrubber timer at the start of the dive and every time the timer (in minutes)
is decremented. The event contains a 12 bit signed integer for the remaining scrubber duration, and two
flags for scrubber warning (0x2000, <= 30 minutes remaining) and scrubber error (0x4000, <= 0 minutes remaining).
(mikeller)
| author | heinrichsweikamp |
|---|---|
| date | Sun, 11 May 2025 16:18:20 +0200 |
| parents | c386ae6635e4 |
| children | 9fabad6436a2 |
| 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); |
| 1000 | 1207 #ifdef ENABLE_GNSS_INTERN |
| 988 | 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 } | |
| 1000 | 1253 else |
| 1254 { | |
| 1255 GNSS_IO_init(); | |
| 1256 } | |
| 940 | 1257 } |
| 942 | 1258 #endif |
| 38 | 1259 } |
| 1260 | |
| 1261 | |
| 1262 | |
| 1263 /* Private functions ---------------------------------------------------------*/ | |
| 1264 | |
| 1265 /** | |
| 1266 ****************************************************************************** | |
| 1267 * @brief scheduleUpdateLifeData / calculates tissues | |
|
763
aa6006975e76
increase HAL_Delay to 10ms for cold-start-button reset
heinrichsweikamp
parents:
742
diff
changeset
|
1268 * @author heinrichs weikamp gmbh |
| 38 | 1269 * @version V0.0.1 |
| 1270 * @date 22-April-2014 | |
| 1271 ****************************************************************************** | |
| 1272 */ | |
| 1273 | |
| 1274 | |
| 1275 void scheduleUpdateLifeData(int32_t asynchron_milliseconds_since_last) | |
| 1276 { | |
| 1277 static _Bool first = 1; | |
| 1278 static uint32_t tickstart = 0; | |
| 1279 static uint32_t ticksrest = 0; | |
| 1280 | |
| 1281 uint32_t ticksdiff = 0; | |
| 1282 uint32_t ticksnow = 0; | |
| 1283 uint32_t time_seconds = 0; | |
| 1284 uint8_t whichGasTmp = 0; | |
| 1285 | |
| 135 | 1286 uint8_t updateTissueData = 0; |
| 1287 | |
| 1288 | |
| 1289 if(global.lifeData.pressure_surface_bar == INVALID_PREASURE_VALUE) | |
| 1290 { | |
| 1291 updateTissueData = 1; | |
| 1292 } | |
| 1293 | |
| 38 | 1294 if(asynchron_milliseconds_since_last < 0) |
| 1295 { | |
| 1296 first = 1; | |
| 1297 tickstart = 0; | |
| 1298 ticksrest = 0; | |
| 1299 return; | |
| 1300 } | |
| 1301 | |
| 1302 if(!asynchron_milliseconds_since_last && first) | |
| 1303 { | |
| 1304 tickstart = HAL_GetTick(); | |
| 1305 first = 0; | |
| 1306 return; | |
| 1307 } | |
| 1308 | |
| 1309 whichGasTmp = global.whichGas; | |
| 1310 global.lifeData.actualGas = global.aktualGas[whichGasTmp]; | |
| 1311 global.lifeData.pressure_ambient_bar = get_pressure_mbar() / 1000.0f; | |
| 1312 global.lifeData.pressure_surface_bar = get_surface_mbar() / 1000.0f; | |
| 1313 | |
| 135 | 1314 if(updateTissueData) |
| 1315 { | |
| 1316 decom_reset_with_ambientmbar(global.lifeData.pressure_surface_bar,&global.lifeData); | |
| 1317 } | |
| 1318 | |
| 38 | 1319 if(!asynchron_milliseconds_since_last) |
| 1320 { | |
| 1321 ticksnow = HAL_GetTick(); | |
| 1322 ticksdiff = time_elapsed_ms(tickstart,ticksnow); | |
| 1323 } | |
| 1324 else | |
| 1325 { | |
| 1326 first = 1; | |
| 1327 ticksdiff = asynchron_milliseconds_since_last; | |
| 1328 } | |
| 1329 | |
| 1330 if(ticksrest > 1000) // whatever happens after standby with STM32L476 | |
| 1331 ticksrest = 0; // maybe move static to SRAM2 | |
| 1332 | |
| 1333 ticksdiff += ticksrest; | |
| 1334 time_seconds = ticksdiff/ 1000; | |
| 1335 ticksrest = ticksdiff - time_seconds * 1000; | |
| 1336 tickstart = ticksnow; | |
| 1337 | |
| 1338 decom_tissues_exposure((int)time_seconds, &global.lifeData); | |
| 1339 if(global.demo_mode) | |
| 1340 decom_tissues_exposure((int)(3*time_seconds), &global.lifeData); | |
| 1341 copyTissueData(); | |
| 1342 } | |
| 1343 | |
| 1344 | |
| 1345 /** | |
| 1346 ****************************************************************************** | |
| 1347 * @brief scheduleUpdateDeviceData | |
| 1348 * @author heinrichs weikamp gmbh | |
| 1349 * @version V0.0.1 | |
| 1350 * @date 16-March-2015 | |
| 1351 * | |
| 1352 * two step process | |
| 1353 * first compare with data from main CPU == externalLogbookFlash | |
| 1354 * second update with new sensor data | |
| 1355 ****************************************************************************** | |
| 1356 */ | |
| 1357 void scheduleSetDate(SDeviceLine *line) | |
| 1358 { | |
| 1359 extern RTC_HandleTypeDef RTCHandle; | |
| 1360 | |
| 1361 line->date_rtc_dr = (uint32_t)(RTCHandle.Instance->DR & RTC_DR_RESERVED_MASK); | |
| 1362 line->time_rtc_tr = (uint32_t)(RTCHandle.Instance->TR & RTC_TR_RESERVED_MASK); | |
| 1363 } | |
| 1364 | |
| 1365 | |
| 1366 void scheduleCopyDeviceData(SDeviceLine *lineWrite, const SDeviceLine *lineRead) | |
| 1367 { | |
| 1368 lineWrite->date_rtc_dr = lineRead->date_rtc_dr; | |
| 1369 lineWrite->time_rtc_tr = lineRead->time_rtc_tr; | |
| 1370 lineWrite->value_int32 = lineRead->value_int32; | |
| 1371 } | |
| 1372 | |
| 1373 | |
|
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
|
1374 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
|
1375 { |
|
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 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
|
1377 |
|
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 /* 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
|
1379 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
|
1380 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
|
1381 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
|
1382 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
|
1383 |
|
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 /* 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
|
1385 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
|
1386 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
|
1387 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
|
1388 } |
|
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 |
|
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 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
|
1391 { |
|
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 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
|
1393 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
|
1394 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
|
1395 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
|
1396 |
|
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 /* 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
|
1398 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
|
1399 { |
|
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 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
|
1401 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
|
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 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
|
1404 } |
|
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
|
1405 } |
|
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
|
1406 |
|
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
|
1407 } |
|
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
|
1408 |
| 38 | 1409 void scheduleUpdateDeviceData(void) |
| 1410 { | |
| 1411 /* first step, main CPU */ | |
| 1412 | |
| 1413 if(deviceDataFlashValid) | |
| 1414 { | |
| 1415 /* 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
|
1416 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
|
1417 { |
|
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 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
|
1419 #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
|
1420 scheduleCheckDate(); |
|
414
6886aeeca454
Added compile switch for restoring of last known date after power lost:
ideenmodellierer
parents:
409
diff
changeset
|
1421 #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
|
1422 } |
| 38 | 1423 if(global.deviceData.batteryChargeCompleteCycles.value_int32 < DeviceDataFlash.batteryChargeCompleteCycles.value_int32) |
| 1424 { | |
| 1425 scheduleCopyDeviceData(&global.deviceData.batteryChargeCompleteCycles, &DeviceDataFlash.batteryChargeCompleteCycles); | |
| 1426 } | |
| 1427 if(global.deviceData.batteryChargeCycles.value_int32 < DeviceDataFlash.batteryChargeCycles.value_int32) | |
| 1428 { | |
| 1429 scheduleCopyDeviceData(&global.deviceData.batteryChargeCycles, &DeviceDataFlash.batteryChargeCycles); | |
| 1430 } | |
| 1431 if(global.deviceData.temperatureMaximum.value_int32 < DeviceDataFlash.temperatureMaximum.value_int32) | |
| 1432 { | |
| 1433 scheduleCopyDeviceData(&global.deviceData.temperatureMaximum, &DeviceDataFlash.temperatureMaximum); | |
| 1434 } | |
| 1435 if(global.deviceData.depthMaximum.value_int32 < DeviceDataFlash.depthMaximum.value_int32) | |
| 1436 { | |
| 1437 scheduleCopyDeviceData(&global.deviceData.depthMaximum, &DeviceDataFlash.depthMaximum); | |
| 1438 } | |
| 1439 if(global.deviceData.diveCycles.value_int32 < DeviceDataFlash.diveCycles.value_int32) | |
| 1440 { | |
| 1441 scheduleCopyDeviceData(&global.deviceData.diveCycles, &DeviceDataFlash.diveCycles); | |
| 1442 } | |
| 1443 | |
| 1444 /* min values */ | |
| 1445 if(global.deviceData.temperatureMinimum.value_int32 > DeviceDataFlash.temperatureMinimum.value_int32) | |
| 1446 { | |
| 1447 scheduleCopyDeviceData(&global.deviceData.temperatureMinimum, &DeviceDataFlash.temperatureMinimum); | |
| 1448 } | |
| 1449 if(global.deviceData.voltageMinimum.value_int32 > DeviceDataFlash.voltageMinimum.value_int32) | |
| 1450 { | |
| 1451 scheduleCopyDeviceData(&global.deviceData.voltageMinimum, &DeviceDataFlash.voltageMinimum); | |
| 1452 } | |
| 1453 } | |
| 1454 | |
| 1455 /* second step, sensor data */ | |
| 1456 int32_t temperature_centigrad_int32; | |
| 1457 int32_t pressure_mbar_int32; | |
| 1458 int32_t voltage_mvolt_int32; | |
| 1459 | |
| 1460 temperature_centigrad_int32 = (int32_t)(get_temperature() * 100); | |
| 1461 if(temperature_centigrad_int32 < global.deviceData.temperatureMinimum.value_int32) | |
| 1462 { | |
| 1463 global.deviceData.temperatureMinimum.value_int32 = temperature_centigrad_int32; | |
| 88 | 1464 scheduleSetDate(&global.deviceData.temperatureMinimum); |
| 38 | 1465 } |
| 1466 | |
| 1467 if(temperature_centigrad_int32 > global.deviceData.temperatureMaximum.value_int32) | |
| 1468 { | |
| 1469 global.deviceData.temperatureMaximum.value_int32 = temperature_centigrad_int32; | |
| 88 | 1470 scheduleSetDate(&global.deviceData.temperatureMaximum); |
| 38 | 1471 } |
| 1472 | |
| 1473 pressure_mbar_int32 = (int32_t)get_pressure_mbar(); | |
| 1474 if(pressure_mbar_int32 > global.deviceData.depthMaximum.value_int32) | |
| 1475 { | |
| 1476 global.deviceData.depthMaximum.value_int32 = pressure_mbar_int32; | |
| 88 | 1477 scheduleSetDate(&global.deviceData.depthMaximum); |
| 38 | 1478 } |
| 1479 | |
| 1480 voltage_mvolt_int32 = (int32_t)(get_voltage() * 1000); | |
| 1481 if(voltage_mvolt_int32 < global.deviceData.voltageMinimum.value_int32) | |
| 1482 { | |
| 1483 global.deviceData.voltageMinimum.value_int32 = voltage_mvolt_int32; | |
| 88 | 1484 scheduleSetDate(&global.deviceData.voltageMinimum); |
| 38 | 1485 } |
| 1486 | |
| 1487 /* third step, counter */ | |
| 1488 switch (global.mode) | |
| 1489 { | |
| 1490 case MODE_SURFACE: | |
| 1491 case MODE_DIVE: | |
| 1492 default: | |
| 1493 deviceDataSubSeconds++; | |
| 1494 if(deviceDataSubSeconds > 10) | |
| 1495 { | |
| 1496 deviceDataSubSeconds = 0; | |
| 1497 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
|
1498 scheduleSetDate(&global.deviceData.hoursOfOperation); |
| 38 | 1499 } |
| 1500 break; | |
| 1501 | |
| 662 | 1502 case MODE_SLEEP: |
| 38 | 1503 case MODE_SHUTDOWN: |
| 1504 break; | |
| 1505 } | |
| 1506 } | |
| 1507 | |
| 1508 | |
| 1509 void scheduleUpdateDeviceDataChargerFull(void) | |
| 1510 { | |
| 1511 global.deviceData.batteryChargeCompleteCycles.value_int32++; | |
| 88 | 1512 scheduleSetDate(&global.deviceData.batteryChargeCompleteCycles); |
| 38 | 1513 } |
| 1514 | |
| 1515 | |
| 1516 void scheduleUpdateDeviceDataChargerCharging(void) | |
| 1517 { | |
| 1518 global.deviceData.batteryChargeCycles.value_int32++; | |
| 88 | 1519 scheduleSetDate(&global.deviceData.batteryChargeCycles); |
| 38 | 1520 } |
| 1521 | |
| 1522 | |
| 1523 /** | |
| 1524 ****************************************************************************** | |
| 1525 * @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
|
1526 * @author heinrichs weikamp gmbh |
| 38 | 1527 * @version V0.0.1 |
| 1528 * @date 22-April-2014 | |
| 1529 ****************************************************************************** | |
| 1530 */ | |
| 1531 _Bool vpm_crush2(void) | |
| 1532 { | |
| 1533 int i = 0; | |
| 1534 static float starting_ambient_pressure = 0; | |
| 1535 static float ending_ambient_pressure = 0; | |
| 1536 static float time_calc_begin = -1; | |
| 1537 static float initial_helium_pressure[16]; | |
| 1538 static float initial_nitrogen_pressure[16]; | |
| 1539 ending_ambient_pressure = global.lifeData.pressure_ambient_bar * 10; | |
| 1540 | |
| 1541 if((global.lifeData.dive_time_seconds <= 4) || (starting_ambient_pressure >= ending_ambient_pressure)) | |
| 1542 { | |
| 1543 time_calc_begin = global.lifeData.dive_time_seconds; | |
| 1544 starting_ambient_pressure = global.lifeData.pressure_ambient_bar * 10; | |
| 1545 for( i = 0; i < 16; i++) | |
| 1546 { | |
| 1547 initial_helium_pressure[i] = global.lifeData.tissue_helium_bar[i] * 10; | |
| 1548 initial_nitrogen_pressure[i] = global.lifeData.tissue_nitrogen_bar[i] * 10; | |
| 1549 } | |
| 1550 return 0; | |
| 1551 } | |
| 1552 if(global.lifeData.dive_time_seconds - time_calc_begin >= 4) | |
| 1553 { | |
| 1554 if(ending_ambient_pressure > starting_ambient_pressure + 0.5f) | |
| 1555 { | |
| 1556 float rate = (ending_ambient_pressure - starting_ambient_pressure) * 60 / 4; | |
| 1557 calc_crushing_pressure(&global.lifeData, &global.vpm, initial_helium_pressure, initial_nitrogen_pressure, starting_ambient_pressure, rate); | |
| 1558 | |
| 1559 time_calc_begin = global.lifeData.dive_time_seconds; | |
| 1560 starting_ambient_pressure = global.lifeData.pressure_ambient_bar * 10; | |
| 1561 for( i = 0; i < 16; i++) | |
| 1562 { | |
| 1563 initial_helium_pressure[i] = global.lifeData.tissue_helium_bar[i] * 10; | |
| 1564 initial_nitrogen_pressure[i] = global.lifeData.tissue_nitrogen_bar[i] * 10; | |
| 1565 } | |
| 1566 | |
| 1567 return 1; | |
| 1568 } | |
| 1569 | |
| 1570 } | |
| 1571 return 0; | |
| 1572 } | |
| 1573 | |
| 1574 | |
| 1575 long get_nofly_time_minutes(void) | |
| 1576 { | |
| 1577 | |
| 1578 if(global.no_fly_time_minutes <= 0) | |
| 1579 return 0; | |
| 1580 | |
| 1581 long minutes_since_last_dive = global.seconds_since_last_dive/60; | |
| 1582 | |
| 1583 if((global.seconds_since_last_dive > 0) && (global.no_fly_time_minutes > minutes_since_last_dive)) | |
| 1584 { | |
| 1585 return (global.no_fly_time_minutes - minutes_since_last_dive); | |
| 1586 } | |
| 1587 else | |
| 1588 { | |
| 1589 global.no_fly_time_minutes = 0; | |
| 1590 return 0; | |
| 1591 } | |
| 1592 } | |
| 1593 | |
| 1594 | |
| 1595 //Supports threadsave copying!!! | |
| 1596 void copyActualGas(SGas gas) | |
| 1597 { | |
| 1598 uint8_t whichGas = !global.whichGas; | |
| 1599 global.aktualGas[whichGas] = gas; | |
| 1600 global.whichGas = whichGas; | |
| 1601 } | |
| 1602 | |
| 1603 | |
| 1604 //Supports threadsave copying!!! | |
| 1605 void copyPressureData(void) | |
| 1606 { | |
|
240
625d20070261
Improvement SPI stability/recoverability
Jan Mulder <jlmulder@xs4all.nl>
parents:
231
diff
changeset
|
1607 global.dataSendToMaster.sensorErrors = global.I2C_SystemStatus; |
| 38 | 1608 uint8_t boolPressureData = !global.dataSendToMaster.boolPressureData; |
| 1609 global.dataSendToMaster.data[boolPressureData].temperature = get_temperature(); | |
| 1610 global.dataSendToMaster.data[boolPressureData].pressure_mbar = get_pressure_mbar(); | |
| 1611 global.dataSendToMaster.data[boolPressureData].surface_mbar = get_surface_mbar(); | |
| 1612 global.dataSendToMaster.data[boolPressureData].ascent_rate_meter_per_min = global.lifeData.ascent_rate_meter_per_min; | |
| 1613 global.dataSendToMaster.data[boolPressureData].pressure_uTick = HAL_GetTick(); | |
| 1614 global.dataSendToMaster.boolPressureData = boolPressureData; | |
|
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1615 global.dataSendToMaster.data[boolPressureData].SPARE1 = is_surface_pressure_stable(); |
| 38 | 1616 } |
| 1617 | |
| 1618 | |
| 1619 //Supports threadsave copying!!! | |
| 1620 void copyCnsAndOtuData(void) | |
| 1621 { | |
| 1622 //uint8_t dataSendToMaster. | |
| 1623 uint8_t boolToxicData = !global.dataSendToMaster.boolToxicData; | |
| 1624 global.dataSendToMaster.data[boolToxicData].cns = global.lifeData.cns; | |
| 1625 global.dataSendToMaster.data[boolToxicData].otu = global.lifeData.otu; | |
| 1626 global.dataSendToMaster.data[boolToxicData].desaturation_time_minutes = global.lifeData.desaturation_time_minutes; | |
| 1627 global.dataSendToMaster.data[boolToxicData].no_fly_time_minutes = get_nofly_time_minutes(); | |
| 1628 global.dataSendToMaster.boolToxicData = boolToxicData; | |
| 1629 } | |
| 1630 | |
| 1631 | |
| 1632 //Supports threadsave copying!!! | |
| 1633 void copyTimeData(void) | |
| 1634 { | |
| 1635 extern RTC_HandleTypeDef RTCHandle; | |
| 1636 | |
| 1637 uint8_t boolTimeData = !global.dataSendToMaster.boolTimeData; | |
| 1638 global.dataSendToMaster.data[boolTimeData].localtime_rtc_tr = (uint32_t)(RTCHandle.Instance->TR & RTC_TR_RESERVED_MASK); | |
| 1639 global.dataSendToMaster.data[boolTimeData].localtime_rtc_dr = (uint32_t)(RTCHandle.Instance->DR & RTC_DR_RESERVED_MASK); | |
| 1640 global.dataSendToMaster.data[boolTimeData].divetime_seconds = (uint32_t)global.lifeData.dive_time_seconds; | |
| 1641 global.dataSendToMaster.data[boolTimeData].dive_time_seconds_without_surface_time = (uint32_t)global.lifeData.dive_time_seconds_without_surface_time; | |
| 1642 global.dataSendToMaster.data[boolTimeData].surfacetime_seconds = (uint32_t)global.seconds_since_last_dive; | |
| 1643 global.dataSendToMaster.data[boolTimeData].counterSecondsShallowDepth = (uint32_t)global.lifeData.counterSecondsShallowDepth; | |
| 1644 global.dataSendToMaster.boolTimeData = boolTimeData; | |
| 1645 } | |
| 1646 | |
| 1647 | |
| 1648 //Supports threadsave copying!!! | |
| 1649 void copyCompassData(void) | |
| 1650 { | |
| 1651 extern float compass_heading; | |
| 1652 extern float compass_roll; | |
| 1653 extern float compass_pitch; | |
| 1654 //uint8_t dataSendToMaster. | |
| 1655 uint8_t boolCompassData = !global.dataSendToMaster.boolCompassData; | |
| 1656 global.dataSendToMaster.data[boolCompassData].compass_heading = compass_heading; | |
| 1657 global.dataSendToMaster.data[boolCompassData].compass_roll = compass_roll; | |
| 1658 global.dataSendToMaster.data[boolCompassData].compass_pitch = compass_pitch; | |
| 1659 global.dataSendToMaster.data[boolCompassData].compass_DX_f = 0; | |
| 1660 global.dataSendToMaster.data[boolCompassData].compass_DY_f = 0; | |
| 1661 global.dataSendToMaster.data[boolCompassData].compass_DZ_f = 0; | |
| 1662 global.dataSendToMaster.data[boolCompassData].compass_uTick = HAL_GetTick(); | |
| 1663 global.dataSendToMaster.boolCompassData = boolCompassData; | |
| 1664 } | |
| 1665 | |
| 1666 | |
| 1667 void copyCompassDataDuringCalibration(int16_t dx, int16_t dy, int16_t dz) | |
| 1668 { | |
| 1669 extern float compass_heading; | |
| 1670 extern float compass_roll; | |
| 1671 extern float compass_pitch; | |
| 1672 //uint8_t dataSendToMaster. | |
| 1673 uint8_t boolCompassData = !global.dataSendToMaster.boolCompassData; | |
| 1674 global.dataSendToMaster.data[boolCompassData].compass_heading = compass_heading; | |
| 1675 global.dataSendToMaster.data[boolCompassData].compass_roll = compass_roll; | |
| 1676 global.dataSendToMaster.data[boolCompassData].compass_pitch = compass_pitch; | |
| 1677 global.dataSendToMaster.data[boolCompassData].compass_DX_f = dx; | |
| 1678 global.dataSendToMaster.data[boolCompassData].compass_DY_f = dy; | |
| 1679 global.dataSendToMaster.data[boolCompassData].compass_DZ_f = dz; | |
| 1680 global.dataSendToMaster.boolCompassData = boolCompassData; | |
| 1681 } | |
| 1682 | |
| 1683 | |
| 1684 //Supports threadsave copying!!! | |
| 1685 void copyBatteryData(void) | |
| 1686 { | |
| 1687 uint8_t boolBatteryData = !global.dataSendToMaster.boolBatteryData; | |
| 668 | 1688 global.lifeData.battery_charge = get_charge(); |
| 38 | 1689 global.dataSendToMaster.data[boolBatteryData].battery_voltage = get_voltage(); |
| 668 | 1690 |
| 1691 if(battery_gas_gauge_isChargeValueValid()) | |
| 1692 { | |
| 1693 global.dataSendToMaster.data[boolBatteryData].battery_charge= global.lifeData.battery_charge; | |
| 1694 } | |
| 1695 else | |
| 1696 { | |
| 1697 global.dataSendToMaster.data[boolBatteryData].battery_charge = global.lifeData.battery_charge * -1.0; /* negate value to show that this is just an assumption */ | |
| 1698 } | |
| 38 | 1699 global.dataSendToMaster.boolBatteryData = boolBatteryData; |
| 1700 } | |
| 1701 | |
| 1702 | |
| 1703 //Supports threadsave copying!!! | |
| 1704 void copyAmbientLightData(void) | |
| 1705 { | |
| 1706 uint8_t boolAmbientLightData = !global.dataSendToMaster.boolAmbientLightData; | |
| 1707 global.dataSendToMaster.data[boolAmbientLightData].ambient_light_level = get_ambient_light_level(); | |
| 1708 global.dataSendToMaster.boolAmbientLightData = boolAmbientLightData; | |
| 1709 } | |
| 1710 | |
| 1711 | |
| 1712 //Supports threadsave copying!!! | |
| 1713 void copyTissueData(void) | |
| 1714 { | |
| 1715 //uint8_t dataSendToMaster. | |
| 1716 uint8_t boolTisssueData = !global.dataSendToMaster.boolTisssueData; | |
| 1717 for(int i = 0; i < 16; i++) | |
| 1718 { | |
| 1719 global.dataSendToMaster.data[boolTisssueData].tissue_nitrogen_bar[i] = global.lifeData.tissue_nitrogen_bar[i]; | |
| 1720 global.dataSendToMaster.data[boolTisssueData].tissue_helium_bar[i] = global.lifeData.tissue_helium_bar[i]; | |
| 1721 } | |
| 1722 global.dataSendToMaster.boolTisssueData = boolTisssueData; | |
| 1723 } | |
| 1724 | |
| 1725 | |
| 1726 //Supports threadsave copying!!! | |
| 1727 void copyVpmCrushingData(void) | |
| 1728 { | |
| 1729 //uint8_t dataSendToMaster. | |
| 1730 uint8_t boolCrushingData = !global.dataSendToMaster.boolCrushingData; | |
| 1731 for(int i = 0; i < 16; i++) | |
| 1732 { | |
| 1733 global.dataSendToMaster.data[boolCrushingData].max_crushing_pressure_n2[i] = global.vpm.max_crushing_pressure_n2[i]; | |
| 1734 global.dataSendToMaster.data[boolCrushingData].max_crushing_pressure_he[i] = global.vpm.max_crushing_pressure_he[i]; | |
| 1735 global.dataSendToMaster.data[boolCrushingData].adjusted_critical_radius_he[i] = global.vpm.adjusted_critical_radius_he[i]; | |
| 1736 global.dataSendToMaster.data[boolCrushingData].adjusted_critical_radius_n2[i] = global.vpm.adjusted_critical_radius_n2[i]; | |
| 1737 } | |
| 1738 global.dataSendToMaster.boolCrushingData = boolCrushingData; | |
| 1739 } | |
| 1740 | |
| 1741 | |
| 1742 void copyDeviceData(void) | |
| 1743 { | |
| 1744 uint8_t boolDeviceData = !global.deviceDataSendToMaster.boolDeviceData; | |
| 1745 memcpy(&global.deviceDataSendToMaster.DeviceData[boolDeviceData], &global.deviceData,sizeof(SDevice)); | |
| 1746 global.deviceDataSendToMaster.boolDeviceData = boolDeviceData; | |
| 1747 | |
| 1748 global.deviceDataSendToMaster.boolVpmRepetitiveDataValid = 0; | |
| 1749 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.adjusted_critical_radius_he, &global.vpm.adjusted_critical_radius_he, sizeof(16*4)); | |
| 1750 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.adjusted_critical_radius_n2, &global.vpm.adjusted_critical_radius_n2, sizeof(16*4)); | |
| 1751 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.adjusted_crushing_pressure_he, &global.vpm.adjusted_crushing_pressure_he, sizeof(16*4)); | |
| 1752 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.adjusted_crushing_pressure_n2, &global.vpm.adjusted_crushing_pressure_n2, sizeof(16*4)); | |
| 1753 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.initial_allowable_gradient_he, &global.vpm.initial_allowable_gradient_he, sizeof(16*4)); | |
| 1754 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.initial_allowable_gradient_n2, &global.vpm.initial_allowable_gradient_n2, sizeof(16*4)); | |
| 1755 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.max_actual_gradient, &global.vpm.max_actual_gradient, sizeof(16*4)); | |
| 1756 global.deviceDataSendToMaster.VpmRepetitiveData.repetitive_variables_not_valid = global.vpm.repetitive_variables_not_valid; | |
| 1757 global.deviceDataSendToMaster.boolVpmRepetitiveDataValid = 1; | |
| 1758 } | |
| 1759 | |
| 1760 /* copyPICdata(); is used in spi.c */ | |
| 1761 void copyPICdata(void) | |
| 1762 { | |
| 1763 uint8_t boolPICdata = !global.dataSendToMaster.boolPICdata; | |
| 1764 for(int i = 0; i < 3; i++) | |
| 1765 { | |
| 1766 global.dataSendToMaster.data[boolPICdata].button_setting[i] = global.ButtonPICdata[i]; | |
| 1767 } | |
| 1768 global.dataSendToMaster.boolPICdata = boolPICdata; | |
| 1769 } | |
| 1770 | |
|
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1771 void copyExtADCdata() |
|
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1772 { |
|
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1773 float value; |
|
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1774 |
|
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1775 uint8_t channel = 0; |
|
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1776 |
| 691 | 1777 uint8_t boolADCBuffer = ~(global.dataSendToMaster.boolADCO2Data & DATA_BUFFER_ADC); |
| 1778 | |
| 1779 boolADCBuffer &= DATA_BUFFER_ADC; | |
| 1780 global.dataSendToMaster.boolADCO2Data &= ~DATA_BUFFER_ADC; | |
| 1781 | |
|
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1782 for(channel = 0; channel < MAX_ADC_CHANNEL; channel++) |
|
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1783 { |
|
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1784 value = getExternalInterfaceChannel(channel); |
| 691 | 1785 global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].extADC_voltage[channel] = value; |
|
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1786 } |
| 786 | 1787 global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].externalInterface_SensorID = externalInterface_GetSensorData(0xFF, (uint8_t*)&global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].sensor_data); |
| 731 | 1788 memcpy(global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].sensor_map,externalInterface_GetSensorMapPointer(1),EXT_INTERFACE_SENSOR_CNT); |
| 691 | 1789 global.dataSendToMaster.boolADCO2Data |= boolADCBuffer; |
|
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1790 } |
|
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1791 |
| 662 | 1792 void copyExtCO2data() |
| 1793 { | |
| 1794 uint16_t value; | |
| 691 | 1795 uint8_t boolCO2Buffer = ~(global.dataSendToMaster.boolADCO2Data & DATA_BUFFER_CO2); |
| 1796 | |
| 1797 global.dataSendToMaster.boolADCO2Data &= ~DATA_BUFFER_CO2; | |
| 1798 boolCO2Buffer &= DATA_BUFFER_CO2; | |
| 662 | 1799 |
| 1800 if(externalInterface_GetCO2State()) | |
| 1801 { | |
| 1802 value = externalInterface_GetCO2Value(); | |
| 691 | 1803 global.dataSendToMaster.data[(boolCO2Buffer && DATA_BUFFER_CO2)].CO2_ppm = value; |
| 662 | 1804 value = externalInterface_GetCO2SignalStrength(); |
| 691 | 1805 global.dataSendToMaster.data[(boolCO2Buffer && DATA_BUFFER_CO2)].CO2_signalStrength = value; |
| 1806 global.dataSendToMaster.data[(boolCO2Buffer && DATA_BUFFER_CO2)].externalInterface_CmdAnswer = externalInterface_GetCO2State(); | |
| 662 | 1807 externalInterface_SetCO2State(EXT_INTERFACE_33V_ON); /* clear command responses */ |
| 1808 } | |
| 1809 else | |
| 1810 { | |
| 691 | 1811 global.dataSendToMaster.data[(boolCO2Buffer && DATA_BUFFER_CO2)].CO2_ppm = 0; |
| 1812 global.dataSendToMaster.data[(boolCO2Buffer && DATA_BUFFER_CO2)].CO2_signalStrength = 0; | |
| 1813 global.dataSendToMaster.data[(boolCO2Buffer && DATA_BUFFER_CO2)].externalInterface_CmdAnswer = 0; | |
| 662 | 1814 } |
| 691 | 1815 global.dataSendToMaster.boolADCO2Data |= boolCO2Buffer; |
| 662 | 1816 } |
| 38 | 1817 |
|
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
881
diff
changeset
|
1818 void copyGNSSdata(void) |
|
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
881
diff
changeset
|
1819 { |
| 955 | 1820 RTC_TimeTypeDef sTimeNow; |
| 1821 | |
| 942 | 1822 global.dataSendToMaster.data[0].gnssInfo.coord.fLat = GNSS_Handle.fLat; |
| 1823 global.dataSendToMaster.data[0].gnssInfo.coord.fLon = GNSS_Handle.fLon; | |
| 931 | 1824 global.dataSendToMaster.data[0].gnssInfo.fixType = GNSS_Handle.fixType; |
| 1825 global.dataSendToMaster.data[0].gnssInfo.numSat = GNSS_Handle.numSat; | |
| 947 | 1826 global.dataSendToMaster.data[0].gnssInfo.DateTime.year = (uint8_t) (GNSS_Handle.year - 2000); |
| 1827 global.dataSendToMaster.data[0].gnssInfo.DateTime.month = GNSS_Handle.month; | |
| 1828 global.dataSendToMaster.data[0].gnssInfo.DateTime.day = GNSS_Handle.day; | |
| 1829 global.dataSendToMaster.data[0].gnssInfo.DateTime.hour = GNSS_Handle.hour; | |
| 1830 global.dataSendToMaster.data[0].gnssInfo.DateTime.min = GNSS_Handle.min; | |
| 1831 global.dataSendToMaster.data[0].gnssInfo.DateTime.sec = GNSS_Handle.sec; | |
| 1832 | |
| 940 | 1833 global.dataSendToMaster.data[0].gnssInfo.alive = GNSS_Handle.alive; |
| 1834 | |
| 955 | 1835 if(( GNSS_Handle.fixType < 2) && (GNSS_Handle.alive & GNSS_ALIVE_BACKUP_POS)) /* fallback to last known position ? */ |
| 1836 { | |
| 1837 RTC_GetTime(&sTimeNow); | |
| 1838 if(GNSS_Handle.last_hour > sTimeNow.Hours) | |
| 1839 { | |
| 1840 sTimeNow.Hours += 24; /* compensate date change */ | |
| 1841 } | |
| 1842 if(sTimeNow.Hours - GNSS_Handle.last_hour > 2) | |
| 1843 { | |
| 1844 GNSS_Handle.alive &= ~GNSS_ALIVE_BACKUP_POS; /* position outdated */ | |
| 1845 } | |
| 1846 else | |
| 1847 { | |
| 1848 global.dataSendToMaster.data[0].gnssInfo.coord.fLat = GNSS_Handle.last_fLat; | |
| 1849 global.dataSendToMaster.data[0].gnssInfo.coord.fLon = GNSS_Handle.last_fLon; | |
| 1850 } | |
| 1851 } | |
| 931 | 1852 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
|
1853 } |
|
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
881
diff
changeset
|
1854 |
|
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
881
diff
changeset
|
1855 |
| 38 | 1856 typedef enum |
| 1857 { | |
| 1858 SPI3_OK = 0x00, | |
| 1859 SPI3_DEINIT = 0x01, | |
| 1860 } SPI3_StatusTypeDef; | |
| 1861 /* if spi3 is running and the SPI3_ButtonAdjust call returns OK, all is fine | |
| 1862 if the SPI3_ButtonAdjust call returns error, the spi3 is DeInit | |
| 1863 and will be init the next call of scheduleSetButtonResponsiveness() | |
| 1864 and data will be send again on the third call | |
| 1865 therefore on return 0 of scheduleSetButtonResponsiveness() the caller flag should kept active | |
| 1866 */ | |
| 1867 uint8_t scheduleSetButtonResponsiveness(void) | |
| 1868 { | |
| 1869 static uint8_t SPI3status = SPI3_OK; | |
| 1870 | |
| 1871 if((SPI3status == SPI3_OK) && (SPI3_ButtonAdjust(global.ButtonResponsiveness, global.ButtonPICdata))) | |
| 1872 { | |
| 1873 copyPICdata(); | |
| 1874 return 1; | |
| 1875 } | |
| 1876 else | |
| 1877 { | |
| 1878 for(int i=0;i<3;i++) | |
| 1879 { | |
| 1880 global.ButtonPICdata[i] = 0xFF; | |
| 1881 } | |
| 1882 copyPICdata(); | |
| 1883 | |
| 1884 if(SPI3status == SPI3_OK) | |
| 1885 { | |
| 1886 MX_SPI3_DeInit(); | |
| 1887 SPI3status = SPI3_DEINIT; | |
| 1888 } | |
| 1889 else | |
| 1890 { | |
| 1891 MX_SPI3_Init(); | |
| 1892 SPI3status = SPI3_OK; | |
| 1893 } | |
| 1894 return 0; | |
| 1895 } | |
| 1896 } | |
| 1897 | |
| 1898 | |
|
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
181
diff
changeset
|
1899 //save time difference |
| 38 | 1900 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow) |
| 1901 { | |
| 1902 if(ticksstart <= ticksnow) | |
| 1903 { | |
| 1904 return ticksnow - ticksstart; | |
| 1905 } | |
| 1906 else | |
| 1907 { | |
| 1908 return 0xFFFFFFFF - ticksstart + ticksnow; | |
| 1909 } | |
| 1910 } | |
| 1911 | |
| 1912 /* same as in data_central.c */ | |
|
310
95928ef3986f
Make dive mode detection more advanced
Jan Mulder <jlmulder@xs4all.nl>
parents:
301
diff
changeset
|
1913 _Bool is_ambient_pressure_close_to_surface(SLifeData *lifeData) |
| 38 | 1914 { |
|
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1915 _Bool retval = true; |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1916 |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1917 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
|
1918 { |
|
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1919 /* 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
|
1920 if (lifeData->pressure_ambient_bar > START_DIVE_IMMEDIATLY_BAR) |
|
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 retval = false; |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1923 } |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1924 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
|
1925 { |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1926 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
|
1927 && (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
|
1928 { |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1929 retval = false; |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1930 } |
|
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1931 } |
|
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1932 } |
|
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1933 return retval; |
| 38 | 1934 } |
| 1935 | |
| 881 | 1936 void evaluateAscentSpeed() |
| 1937 { | |
| 1938 static uint32_t lastPressureTick = 0; | |
| 1939 static float lastPressure_bar = 0.0f; | |
| 1940 static AscentStates_t ascentState = ASCENT_NONE; | |
| 1941 static uint8_t ascentStableCnt = 0; | |
| 1942 uint32_t tickPressureDiff = 0; | |
| 1943 uint32_t lasttick = HAL_GetTick(); | |
| 1944 float localAscentRate = 0.0; | |
| 1945 | |
| 1946 tickPressureDiff = time_elapsed_ms(lastPressureTick,lasttick); /* Calculate ascent rate every 400ms use timer to take care for small time shifts */ | |
| 1947 if(tickPressureDiff != 0) | |
| 1948 { | |
| 1949 if(lastPressure_bar >= 0) | |
| 1950 { | |
| 1951 localAscentRate = (lastPressure_bar - global.lifeData.pressure_ambient_bar) * (60000.0 / tickPressureDiff) * 10; /* bar * 10 = meter */ | |
| 904 | 1952 if((fabs(localAscentRate) < 1.0) || (global.lifeData.pressure_ambient_bar < START_DIVE_IMMEDIATLY_BAR)) |
| 881 | 1953 { |
| 1954 ascentState = ASCENT_NONE; | |
| 1955 ascentStableCnt = 0; | |
| 1956 } | |
| 1957 else if(localAscentRate > 0.0) | |
| 1958 { | |
| 1959 if(ascentState != ASCENT_FALLING) | |
| 1960 { | |
| 1961 if(ascentStableCnt < 5) | |
| 1962 { | |
| 1963 ascentStableCnt++; | |
| 1964 } | |
| 1965 else | |
| 1966 { | |
| 1967 ascentState = ASCENT_RISING; | |
| 1968 } | |
| 1969 } | |
| 1970 else | |
| 1971 { | |
| 1972 ascentState = ASCENT_NONE; | |
| 1973 ascentStableCnt = 0; | |
| 1974 } | |
| 1975 } | |
| 1976 else /* must be falling */ | |
| 1977 { | |
| 1978 if(ascentState != ASCENT_RISING) | |
| 1979 { | |
| 1980 if(ascentStableCnt < 5) | |
| 1981 { | |
| 1982 ascentStableCnt++; | |
| 1983 } | |
| 1984 else | |
| 1985 { | |
| 1986 ascentState = ASCENT_FALLING; | |
| 1987 } | |
| 1988 } | |
| 1989 else | |
| 1990 { | |
| 1991 ascentState = ASCENT_NONE; | |
| 1992 ascentStableCnt = 0; | |
| 1993 } | |
| 1994 } | |
| 1995 if(ascentState != ASCENT_NONE) | |
| 1996 { | |
| 1997 global.lifeData.ascent_rate_meter_per_min = localAscentRate; | |
| 1998 } | |
| 1999 else | |
| 2000 { | |
| 2001 global.lifeData.ascent_rate_meter_per_min = 0; | |
| 2002 } | |
| 2003 } | |
| 2004 } | |
| 2005 lastPressure_bar = global.lifeData.pressure_ambient_bar; | |
| 2006 lastPressureTick = lasttick; | |
| 2007 } | |
| 38 | 2008 |
| 2009 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ | |
| 2010 |
