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