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