Mercurial > public > ostc4
annotate Small_CPU/Src/scheduler.c @ 480:3fe9cc747c5c Improve_Button_Sleep
Code cleanup pressure plausibility check:
The function was deactivated (always returning true) some time ago => removed useless code
author | ideenmodellierer |
---|---|
date | Wed, 13 May 2020 21:56:35 +0200 |
parents | 4b000e2386c2 |
children | 9eeab3fead8f |
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 //#define DEBUGMODE | |
25 | |
26 /* Includes ------------------------------------------------------------------*/ | |
27 #include <string.h> | |
28 #include "baseCPU2.h" | |
29 #include "stm32f4xx_hal.h" | |
30 #include "i2c.h" | |
31 #include "scheduler.h" | |
32 #include "pressure.h" | |
33 #include "compass.h" | |
34 #include "batteryGasGauge.h" | |
35 #include "batteryCharger.h" | |
36 #include "spi.h" | |
37 #include "rtc.h" | |
38 #include "dma.h" | |
39 #include "adc.h" | |
40 #include "calc_crush.h" | |
41 #include "stm32f4xx_hal_rtc_ex.h" | |
42 #include "decom.h" | |
43 #include "tm_stm32f4_otp.h" | |
44 | |
414
6886aeeca454
Added compile switch for restoring of last known date after power lost:
ideenmodellierer
parents:
409
diff
changeset
|
45 /* 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
|
46 /* #define RESTORE_LAST_KNOWN_DATE */ |
38 | 47 |
475 | 48 #define INVALID_PREASURE_VALUE (0.0f) |
338
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
49 #define START_DIVE_MOUNTAIN_MODE_BAR (0.88f) |
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
50 #define START_DIVE_IMMEDIATLY_BAR (1.16f) |
135 | 51 |
38 | 52 /* Private types -------------------------------------------------------------*/ |
53 const SGas Air = {79,0,0,0,0}; | |
54 | |
55 /* Exported variables --------------------------------------------------------*/ | |
56 SGlobal global; | |
57 SDevice DeviceDataFlash; | |
58 uint8_t deviceDataFlashValid = 0; | |
59 uint8_t deviceDataSubSeconds = 0; | |
60 | |
61 /* Private variables ---------------------------------------------------------*/ | |
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
62 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
|
63 |
38 | 64 /* can be lost while in sleep */ |
65 uint8_t clearDecoNow = 0; | |
66 uint8_t setButtonsNow = 0; | |
67 | |
68 /* has to be in SRAM2 */ | |
69 uint8_t secondsCount = 0; | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
70 |
207 | 71 static uint8_t dospisync = SPI_SYNC_METHOD_NONE; |
72 | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
73 SScheduleCtrl Scheduler; |
38 | 74 |
75 /* Private function prototypes -----------------------------------------------*/ | |
76 | |
77 _Bool vpm_crush2(void); | |
78 void scheduleUpdateDeviceData(void); | |
79 long get_nofly_time_minutes(void); | |
80 void copyActualGas(SGas gas); | |
81 void copyPressureData(void); | |
82 void copyCnsAndOtuData(void); | |
83 void copyTimeData(void); | |
84 void copyCompassData(void); | |
85 void copyCompassDataDuringCalibration(int16_t dx, int16_t dy, int16_t dz); | |
86 void copyAmbientLightData(void); | |
87 void copyTissueData(void); | |
88 void copyVpmCrushingData(void); | |
89 void copyDeviceData(void); | |
90 void copyPICdata(void); | |
230
3973208c4a20
cleanup: make return void when never used
Jan Mulder <jlmulder@xs4all.nl>
parents:
220
diff
changeset
|
91 static void schedule_update_timer_helper(int8_t thisSeconds); |
38 | 92 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow); |
93 | |
94 void scheduleSetDate(SDeviceLine *line); | |
95 | |
96 /* Exported functions --------------------------------------------------------*/ | |
97 | |
98 void initGlobals(void) | |
99 { | |
231
f6961efb3794
cleanup: do not re-implement a standard function
Jan Mulder <jlmulder@xs4all.nl>
parents:
230
diff
changeset
|
100 bzero(&global, sizeof(SGlobal)); |
38 | 101 |
102 global.dataSendToSlavePending = 0; | |
103 global.dataSendToSlaveIsValid = 1; | |
104 global.dataSendToSlaveIsNotValidCount = 0; | |
105 | |
106 global.mode = MODE_POWERUP; | |
107 global.repetitive_dive = 0; | |
108 global.conservatism = 0; | |
109 global.whichGas = 0; | |
110 global.aktualGas[0] = Air; | |
111 global.lifeData.actualGas = global.aktualGas[0]; | |
112 | |
475 | 113 const uint8_t button_standard_sensitivity = 51; /* 51 equals a percentage of 85% which was the default value before */ |
38 | 114 global.ButtonResponsiveness[0] = button_standard_sensitivity; |
115 global.ButtonResponsiveness[1] = button_standard_sensitivity; | |
116 global.ButtonResponsiveness[2] = button_standard_sensitivity; | |
117 global.ButtonResponsiveness[3] = button_standard_sensitivity; | |
118 | |
119 global.ButtonPICdata[0] = 0xFF; | |
120 global.ButtonPICdata[1] = 0xFF; | |
121 global.ButtonPICdata[2] = 0xFF; | |
122 global.ButtonPICdata[3] = 0xFF; | |
123 | |
240
625d20070261
Improvement SPI stability/recoverability
Jan Mulder <jlmulder@xs4all.nl>
parents:
231
diff
changeset
|
124 global.I2C_SystemStatus = HAL_ERROR; // 0x00 would be everything working |
38 | 125 |
135 | 126 global.lifeData.pressure_ambient_bar = INVALID_PREASURE_VALUE; |
127 global.lifeData.pressure_surface_bar = INVALID_PREASURE_VALUE; | |
38 | 128 decom_reset_with_1000mbar(&global.lifeData); |
129 | |
130 global.demo_mode = 0; | |
131 | |
132 for(int i = 0; i < MAX_SENSORS; i++) | |
133 { | |
134 global.sensorError[i] = HAL_OK; // HAL_OK = 0; | |
135 } | |
136 | |
137 global.dataSendToMaster.RTE_VERSION_high = firmwareVersionHigh();//RTE_VERSION_HIGH;; | |
138 global.dataSendToMaster.RTE_VERSION_low = firmwareVersionLow();//RTE_VERSION_LOW;; | |
139 global.dataSendToMaster.chargeStatus = 0; | |
140 | |
475 | 141 global.dataSendToMaster.power_on_reset = 0; |
38 | 142 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
|
143 global.dataSendToMaster.header.checkCode[1] = SPI_RX_STATE_OFFLINE; |
38 | 144 global.dataSendToMaster.header.checkCode[2] = 0xA3; |
145 global.dataSendToMaster.header.checkCode[3] = 0xA4; | |
146 global.dataSendToMaster.footer.checkCode[3] = 0xE4; | |
147 global.dataSendToMaster.footer.checkCode[2] = 0xE3; | |
148 global.dataSendToMaster.footer.checkCode[1] = 0xE2; | |
149 global.dataSendToMaster.footer.checkCode[0] = 0xE1; | |
150 global.dataSendToMaster.sensorErrors = 0; | |
151 | |
152 global.sync_error_count = 0; | |
153 global.check_sync_not_running = 0; | |
154 | |
155 global.deviceDataSendToMaster.RTE_VERSION_high = firmwareVersionHigh();//RTE_VERSION_HIGH; | |
156 global.deviceDataSendToMaster.RTE_VERSION_low = firmwareVersionLow();//RTE_VERSION_LOW; | |
157 global.deviceDataSendToMaster.chargeStatus = 0; | |
158 | |
475 | 159 global.deviceDataSendToMaster.power_on_reset = 0; |
38 | 160 global.deviceDataSendToMaster.header.checkCode[0] = 0xDF; |
161 global.deviceDataSendToMaster.header.checkCode[1] = 0xDE; | |
162 global.deviceDataSendToMaster.header.checkCode[2] = 0xDD; | |
163 global.deviceDataSendToMaster.header.checkCode[3] = 0xDC; | |
164 global.deviceDataSendToMaster.footer.checkCode[3] = 0xE4; | |
165 global.deviceDataSendToMaster.footer.checkCode[2] = 0xE3; | |
166 global.deviceDataSendToMaster.footer.checkCode[1] = 0xE2; | |
167 global.deviceDataSendToMaster.footer.checkCode[0] = 0xE1; | |
168 | |
169 global.dataSendToSlave.getDeviceDataNow = 0; | |
170 | |
171 global.deviceData.batteryChargeCompleteCycles.value_int32 = 0; | |
172 global.deviceData.batteryChargeCycles.value_int32 = 0; | |
173 global.deviceData.depthMaximum.value_int32 = 0; | |
174 global.deviceData.diveCycles.value_int32 = 0; | |
175 global.deviceData.hoursOfOperation.value_int32 = 0; | |
176 global.deviceData.temperatureMaximum.value_int32 = INT32_MIN; | |
177 global.deviceData.temperatureMinimum.value_int32 = INT32_MAX; | |
178 global.deviceData.voltageMinimum.value_int32 = INT32_MAX; | |
148
ee744c7160ce
Use SPI TX callback to synchronize to main CPU
Ideenmodellierer
parents:
142
diff
changeset
|
179 |
265
a91d99265884
Increase SPI com timeout for cold start and wake up
ideenmodellierer
parents:
264
diff
changeset
|
180 Scheduler.communicationTimeout = SPI_COM_TIMEOUT_START; |
207 | 181 Scheduler_Request_sync_with_SPI(SPI_SYNC_METHOD_HARD); |
38 | 182 } |
183 | |
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
184 void reinitGlobals(void) |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
185 { |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
186 global.dataSendToSlavePending = 0; |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
187 global.dataSendToSlaveIsValid = 0; |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
188 global.dataSendToSlaveIsNotValidCount = 0; |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
189 global.sync_error_count = 0; |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
190 global.check_sync_not_running = 0; |
265
a91d99265884
Increase SPI com timeout for cold start and wake up
ideenmodellierer
parents:
264
diff
changeset
|
191 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
|
192 } |
38 | 193 |
194 void scheduleSpecial_Evaluate_DataSendToSlave(void) | |
195 { | |
104 | 196 //TEMPORARY fix for compass calibration. |
197 //TODO: Fix I2C timeout for complete solving problem. | |
198 if(global.mode==MODE_CALIB){ | |
199 return; | |
200 } | |
90 | 201 |
88 | 202 global.dataSendToSlavePending = 0; |
203 if(!global.dataSendToSlaveIsValid) return; | |
38 | 204 |
205 global.dataSendToMaster.confirmRequest.uw = 0; | |
206 | |
207 if(TM_OTP_Read(0,0) == 0xFF) | |
208 { | |
209 if(global.dataSendToSlave.revisionHardware == (global.dataSendToSlave.revisionCRCx0x7A ^ 0x7A)) | |
210 TM_OTP_Write(0,0,global.dataSendToSlave.revisionHardware); | |
211 } | |
212 | |
213 if(global.dataSendToSlave.setAccidentFlag) | |
214 { | |
215 global.dataSendToMaster.confirmRequest.ub.accident = 1; | |
216 global.deviceData.diveAccident.value_int32 = global.dataSendToSlave.setAccidentFlag; | |
217 scheduleSetDate(&global.deviceData.diveAccident); | |
218 global.accidentFlag |= global.dataSendToSlave.setAccidentFlag; | |
219 if(global.accidentFlag == ACCIDENT_CNS) // LVL1 | |
220 global.accidentRemainingSeconds = 2*60*60; | |
221 else | |
222 global.accidentRemainingSeconds = 24*60*60; | |
223 } | |
224 | |
225 if(global.dataSendToSlave.setTimeNow) | |
226 { | |
227 global.dataSendToMaster.confirmRequest.ub.time = 1; | |
228 RTC_SetTime(global.dataSendToSlave.data.newTime); | |
229 schedule_update_timer_helper(0); | |
230 } | |
231 | |
232 if(global.dataSendToSlave.setDateNow) | |
233 { | |
234 global.dataSendToMaster.confirmRequest.ub.date = 1; | |
235 RTC_SetDate(global.dataSendToSlave.data.newDate); | |
236 schedule_update_timer_helper(0); | |
237 } | |
238 | |
239 if(global.dataSendToSlave.calibrateCompassNow) | |
240 { | |
241 global.dataSendToMaster.confirmRequest.ub.compass = 1; | |
242 global.mode = MODE_CALIB; | |
243 } | |
244 | |
245 if(global.dataSendToSlave.clearDecoNow) | |
246 { | |
247 global.dataSendToMaster.confirmRequest.ub.clearDeco = 1; | |
248 clearDecoNow = 1; | |
249 } | |
250 | |
251 if(global.dataSendToSlave.setButtonSensitivityNow) | |
252 { | |
253 global.dataSendToMaster.confirmRequest.ub.button = 1; | |
254 global.ButtonResponsiveness[0] = global.dataSendToSlave.data.buttonResponsiveness[0]; | |
255 global.ButtonResponsiveness[1] = global.dataSendToSlave.data.buttonResponsiveness[1]; | |
256 global.ButtonResponsiveness[2] = global.dataSendToSlave.data.buttonResponsiveness[2]; | |
257 global.ButtonResponsiveness[3] = global.dataSendToSlave.data.buttonResponsiveness[3]; | |
258 setButtonsNow = 1; | |
259 } | |
260 | |
261 if(global.dataSendToSlave.setBatteryGaugeNow) | |
262 { | |
104 | 263 if(global.mode!=MODE_CALIB){ |
38 | 264 global.dataSendToMaster.confirmRequest.ub.batterygauge = 1; |
265 battery_gas_gauge_set(global.dataSendToSlave.data.newBatteryGaugePercentageFloat); | |
104 | 266 } |
38 | 267 } |
268 | |
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
269 if(global.dataSendToSlave.setEndDive) |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
270 { |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
271 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
|
272 } |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
273 |
38 | 274 if((global.mode == MODE_SURFACE) && (global.dataSendToSlave.mode == MODE_SHUTDOWN)) |
275 { | |
276 global.mode = MODE_SHUTDOWN; | |
277 } | |
278 | |
279 if(global.mode == MODE_DIVE) | |
280 { | |
281 copyActualGas(global.dataSendToSlave.data.actualGas); | |
282 } | |
283 else | |
284 { | |
285 copyActualGas(Air); | |
286 global.settings.divetimeToCreateLogbook = global.dataSendToSlave.data.divetimeToCreateLogbook; | |
287 global.settings.timeoutDiveReachedZeroDepth = global.dataSendToSlave.data.timeoutDiveReachedZeroDepth; | |
288 } | |
289 | |
290 /* for simulation / testing */ | |
291 global.ceiling_from_main_CPU_mbar = global.dataSendToSlave.data.ambient_pressure_mbar_ceiling; | |
292 | |
338
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
293 /* Set pressure and temperature offsets */ |
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
294 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
|
295 |
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
296 |
88 | 297 /* for device data updates */ |
298 deviceDataFlashValid = 0; | |
299 memcpy(&DeviceDataFlash, &global.dataSendToSlave.data.DeviceData, sizeof(SDevice)); | |
300 deviceDataFlashValid = 1; | |
89 | 301 |
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
302 #if 0 |
104 | 303 //TODO: Temporary placed here. Duration ~210 ms. |
304 if (global.I2C_SystemStatus != HAL_OK) { | |
305 MX_I2C1_TestAndClear(); | |
306 MX_I2C1_Init(); | |
307 // init_pressure(); | |
308 // compass_init(0, 7); | |
309 // accelerator_init(); | |
310 } | |
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
311 #endif /* already called once a second */ |
38 | 312 } |
313 | |
314 | |
315 /** | |
316 ****************************************************************************** | |
317 * @brief schedule_time_compare_helper. | |
318 * @author heinrichs weikamp gmbh | |
319 * @version V0.0.1 | |
320 * @date 20-Oct-2016 | |
321 ****************************************************************************** | |
322 */ | |
323 | |
324 uint8_t RtcBugFixChsw(uint8_t inStupidTime) | |
325 { | |
326 uint8_t multiplesOf16 = 0; | |
327 | |
328 multiplesOf16 = inStupidTime / 16; | |
329 | |
330 inStupidTime -= multiplesOf16 * 16; | |
331 | |
332 return (10 * multiplesOf16) + inStupidTime; | |
333 } | |
334 | |
335 uint32_t schedule_time_compare_helper(RTC_TimeTypeDef timeNow, RTC_DateTypeDef dateNow, RTC_TimeTypeDef timeLast, RTC_DateTypeDef dateLast) | |
336 { | |
337 uint32_t nowInSeconds; | |
338 uint32_t lastInSeconds; | |
339 uint32_t resultDiff; | |
340 | |
341 nowInSeconds = (uint32_t)RtcBugFixChsw(timeNow.Hours) * 3600; | |
342 nowInSeconds += (uint32_t)RtcBugFixChsw(timeNow.Minutes) * 60; | |
343 nowInSeconds += (uint32_t)RtcBugFixChsw(timeNow.Seconds); | |
344 | |
345 lastInSeconds = (uint32_t)RtcBugFixChsw(timeLast.Hours) * 3600; | |
346 lastInSeconds += (uint32_t)RtcBugFixChsw(timeLast.Minutes) * 60; | |
347 lastInSeconds += (uint32_t)RtcBugFixChsw(timeLast.Seconds); | |
348 | |
349 if(dateNow.Date != dateLast.Date) | |
350 { | |
351 resultDiff = 86400 + nowInSeconds - lastInSeconds; | |
352 } | |
353 else | |
354 { | |
355 resultDiff = nowInSeconds - lastInSeconds; | |
356 } | |
357 return resultDiff; | |
358 } | |
359 | |
360 | |
361 | |
362 /** | |
363 ****************************************************************************** | |
364 * @brief schedule_update_timer_helper. | |
365 * @author heinrichs weikamp gmbh | |
366 * @version V0.0.1 | |
367 * @date 20-Oct-2016 | |
368 * @brief use 0 for init | |
369 use -1 for RTC controlled | |
370 use >= 1 for manual control | |
371 ****************************************************************************** | |
372 */ | |
373 extern RTC_HandleTypeDef RTCHandle; | |
374 | |
230
3973208c4a20
cleanup: make return void when never used
Jan Mulder <jlmulder@xs4all.nl>
parents:
220
diff
changeset
|
375 static void schedule_update_timer_helper(int8_t thisSeconds) |
38 | 376 { |
377 static RTC_TimeTypeDef sTimeLast; | |
378 static RTC_DateTypeDef sDateLast; | |
379 RTC_TimeTypeDef sTimeNow; | |
380 RTC_DateTypeDef sDateNow; | |
381 uint32_t secondsPast; | |
382 | |
383 HAL_RTC_GetTime(&RTCHandle, &sTimeNow, RTC_FORMAT_BCD); | |
384 HAL_RTC_GetDate(&RTCHandle, &sDateNow, RTC_FORMAT_BCD); | |
385 | |
230
3973208c4a20
cleanup: make return void when never used
Jan Mulder <jlmulder@xs4all.nl>
parents:
220
diff
changeset
|
386 if(thisSeconds != 0) // otherwise just store sTimeLast, sDateLast |
38 | 387 { |
388 if(thisSeconds > 0) // use this value instead, good for pre-loading sTimeLast and sDateLast | |
389 { | |
390 secondsPast = thisSeconds; | |
230
3973208c4a20
cleanup: make return void when never used
Jan Mulder <jlmulder@xs4all.nl>
parents:
220
diff
changeset
|
391 } else { |
3973208c4a20
cleanup: make return void when never used
Jan Mulder <jlmulder@xs4all.nl>
parents:
220
diff
changeset
|
392 // thisSeconds < 0 and not <= ! |
3973208c4a20
cleanup: make return void when never used
Jan Mulder <jlmulder@xs4all.nl>
parents:
220
diff
changeset
|
393 secondsPast = schedule_time_compare_helper(sTimeNow, sDateNow, sTimeLast, sDateLast); |
38 | 394 } |
395 | |
396 if(global.seconds_since_last_dive) | |
397 { | |
398 if(secondsPast >= 777900) | |
399 { | |
400 global.seconds_since_last_dive = 0; | |
401 } | |
402 else | |
403 { | |
230
3973208c4a20
cleanup: make return void when never used
Jan Mulder <jlmulder@xs4all.nl>
parents:
220
diff
changeset
|
404 uint32_t tempNewValue = ((uint32_t)global.seconds_since_last_dive) + secondsPast; |
38 | 405 if(tempNewValue > 777900) // a bit more than nine days [seconds] |
406 global.seconds_since_last_dive = 0; | |
407 else | |
408 global.seconds_since_last_dive = (long)tempNewValue; | |
409 } | |
410 } | |
411 } | |
412 | |
413 sTimeLast = sTimeNow; | |
414 sDateLast = sDateNow; | |
415 } | |
416 | |
417 /** | |
418 ****************************************************************************** | |
419 * @brief schedule_check_resync. | |
420 * @author heinrichs weikamp gmbh | |
421 * @version V0.0.2 | |
422 * @date 18-June-2015 | |
423 ****************************************************************************** | |
424 */ | |
135 | 425 |
38 | 426 void schedule_check_resync(void) |
427 { | |
155
4fd8bbc7d841
Do hard sync after communication timeout > 1 second
Ideenmodellierer
parents:
148
diff
changeset
|
428 /* 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
|
429 if((global.check_sync_not_running >= Scheduler.communicationTimeout)) |
38 | 430 { |
89 | 431 // global.dataSendToSlaveIsNotValidCount = 0; |
135 | 432 global.check_sync_not_running = 0; |
433 global.sync_error_count++; | |
434 | |
435 /* Try to start communication again. If exchange is stuck during execution for some reason the TX will be aborted by the | |
436 * function error handler | |
437 */ | |
277 | 438 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
|
439 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
|
440 Scheduler_Request_sync_with_SPI(SPI_SYNC_METHOD_HARD); |
155
4fd8bbc7d841
Do hard sync after communication timeout > 1 second
Ideenmodellierer
parents:
148
diff
changeset
|
441 } |
38 | 442 } |
443 | |
444 | |
445 /** | |
446 ****************************************************************************** | |
447 * @brief scheduleDiveMode. / Dive Mode: Main Loop | |
448 * @author Peter Ryser | |
449 * @version V0.0.1 | |
450 * @date 22-April-2014 | |
451 ****************************************************************************** | |
452 */ | |
453 void scheduleDiveMode(void) | |
454 { | |
455 uint32_t ticksdiff = 0; | |
456 uint32_t lasttick = 0; | |
457 uint8_t counterAscentRate = 0; | |
458 float lastPressure_bar = 0.0f; | |
459 global.dataSendToMaster.mode = MODE_DIVE; | |
460 global.deviceDataSendToMaster.mode = MODE_DIVE; | |
461 uint8_t counter_exit = 0; | |
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
462 |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
463 Scheduler.counterSPIdata100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
464 Scheduler.counterCompass100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
465 Scheduler.counterPressure100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
466 Scheduler.counterAmbientLight100msec = 0; |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
467 Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC; |
38 | 468 |
469 global.deviceData.diveCycles.value_int32++; | |
470 scheduleSetDate(&global.deviceData.diveCycles); | |
471 global.lifeData.counterSecondsShallowDepth = 0; | |
472 | |
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
473 /* 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
|
474 if(!is_surface_pressure_stable()) |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
475 { |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
476 set_last_surface_pressure_stable(); |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
477 } |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
478 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
|
479 ManualExitDiveCounter = 0; /* reset early exit request */ |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
480 |
240
625d20070261
Improvement SPI stability/recoverability
Jan Mulder <jlmulder@xs4all.nl>
parents:
231
diff
changeset
|
481 Scheduler.tickstart = HAL_GetTick(); |
38 | 482 while(global.mode == MODE_DIVE) |
483 { | |
484 lasttick = HAL_GetTick(); | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
485 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick); |
38 | 486 |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
487 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
488 { |
277 | 489 if(SPI_Evaluate_RX_Data()!=0) /* did we receive something ? */ |
490 { | |
491 Scheduler.counterSPIdata100msec++; | |
492 } | |
493 schedule_check_resync(); | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
494 } |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
495 |
38 | 496 //Evaluate pressure at 20 ms, 120 ms, 220 ms,.... |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
497 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20) |
38 | 498 { |
499 global.check_sync_not_running++; | |
277 | 500 pressure_update_alternating(); |
135 | 501 scheduleUpdateDeviceData(); |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
181
diff
changeset
|
502 #ifdef DEMOMODE |
38 | 503 if(global.demo_mode) |
504 { | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
181
diff
changeset
|
505 int turbo_seconds = demo_modify_temperature_and_pressure(global.lifeData.dive_time_seconds, Scheduler.counterPressure100msec, global.ceiling_from_main_CPU_mbar); |
38 | 506 if(turbo_seconds) |
507 { | |
508 global.lifeData.dive_time_seconds += turbo_seconds; | |
509 decom_tissues_exposure((int)(turbo_seconds), &global.lifeData); | |
510 copyTissueData(); | |
511 } | |
512 if((global.lifeData.counterSecondsShallowDepth > 1) && (global.lifeData.counterSecondsShallowDepth < (global.settings.timeoutDiveReachedZeroDepth - 10))) | |
513 global.lifeData.counterSecondsShallowDepth = (global.settings.timeoutDiveReachedZeroDepth - 10); | |
514 } | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
181
diff
changeset
|
515 #endif |
38 | 516 |
517 //Calc ascentrate every two second (20 * 100 ms) | |
518 counterAscentRate++; | |
519 if(counterAscentRate == 20) | |
520 { | |
521 global.lifeData.pressure_ambient_bar = get_pressure_mbar() / 1000.0f; | |
522 if(lastPressure_bar >= 0) | |
523 { | |
524 //2 seconds * 30 == 1 minute, bar * 10 = meter | |
525 global.lifeData.ascent_rate_meter_per_min = (lastPressure_bar - global.lifeData.pressure_ambient_bar) * 30 * 10; | |
526 } | |
527 lastPressure_bar = global.lifeData.pressure_ambient_bar; | |
528 counterAscentRate = 0; | |
529 } | |
135 | 530 copyPressureData(); |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
531 Scheduler.counterPressure100msec++; |
38 | 532 } |
533 //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
|
534 if(ticksdiff >= Scheduler.counterCompass100msec * 100 + 50) |
135 | 535 { |
536 compass_read(); | |
537 acceleration_read(); | |
538 compass_calc(); | |
539 copyCompassData(); | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
540 Scheduler.counterCompass100msec++; |
135 | 541 } |
38 | 542 |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
543 if(ticksdiff >= Scheduler.counterAmbientLight100msec * 100 + 70) |
38 | 544 { |
545 adc_ambient_light_sensor_get_data(); | |
546 copyAmbientLightData(); | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
547 Scheduler.counterAmbientLight100msec++; |
38 | 548 } |
549 | |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
550 //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
|
551 if(ticksdiff >= Scheduler.tick_execute1second) |
38 | 552 { |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
553 Scheduler.tick_execute1second = 0xFFFFFFFF; /* execute once only in the second cycle */ |
38 | 554 if(global.dataSendToSlave.diveModeInfo != DIVEMODE_Apnea) |
555 { | |
556 scheduleUpdateLifeData(0); // includes tissues | |
557 global.lifeData.dive_time_seconds++; // there is dive_time_seconds_without_surface_time too | |
558 global.lifeData.ppO2 = decom_calc_ppO2(global.lifeData.pressure_ambient_bar, &global.lifeData.actualGas); | |
559 decom_oxygen_calculate_cns(&global.lifeData.cns,global.lifeData.ppO2); | |
560 decom_oxygen_calculate_otu(&global.lifeData.otu,global.lifeData.ppO2); | |
88 | 561 battery_gas_gauge_get_data(); |
38 | 562 |
563 | |
564 /** counter_exit allows safe exit via button for testing | |
565 * and demo_mode is exited too if aplicable. | |
566 */ | |
567 if(global.dataSendToMaster.mode == MODE_ENDDIVE) | |
568 { | |
569 counter_exit++; | |
570 if(counter_exit >= 2) | |
571 { | |
572 global.mode = MODE_SURFACE; | |
573 global.demo_mode = 0; | |
574 } | |
575 } | |
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
576 |
38 | 577 if(is_ambient_pressure_close_to_surface(&global.lifeData)) |
578 { | |
579 global.lifeData.counterSecondsShallowDepth++; | |
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
580 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
|
581 || (ManualExitDiveCounter)) |
38 | 582 { |
583 global.seconds_since_last_dive = 1; // start counter | |
584 schedule_update_timer_helper(0); // zum starten :-) | |
585 global.dataSendToMaster.mode = MODE_ENDDIVE; | |
586 global.deviceDataSendToMaster.mode = MODE_ENDDIVE; | |
587 } | |
588 } | |
589 else | |
590 { | |
591 global.lifeData.counterSecondsShallowDepth = 0; | |
592 global.lifeData.dive_time_seconds_without_surface_time++; | |
593 } | |
594 vpm_crush2(); | |
595 } | |
596 else // DIVEMODE_Apnea | |
597 { | |
598 global.lifeData.dive_time_seconds++; | |
599 | |
600 // exit dive mode | |
601 if(global.dataSendToMaster.mode == MODE_ENDDIVE) | |
602 { | |
603 counter_exit++; | |
604 if(counter_exit >= 2) | |
605 { | |
606 scheduleUpdateLifeData(-1); // 'restart' tissue calculations without calculating time during apnea mode | |
607 global.lifeData.dive_time_seconds = 0; // use backup noflytime and desaturation time | |
608 global.mode = MODE_SURFACE; | |
609 global.demo_mode = 0; | |
610 } | |
611 } | |
612 | |
613 // surface break | |
614 if(is_ambient_pressure_close_to_surface(&global.lifeData)) | |
615 { | |
616 global.lifeData.counterSecondsShallowDepth++; | |
617 if(global.lifeData.counterSecondsShallowDepth > 3) // time for main cpu to copy to apnea_last_dive_time_seconds | |
618 { | |
619 global.lifeData.dive_time_seconds = 0; // this apnea dive ends here | |
620 } | |
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
621 if((global.lifeData.counterSecondsShallowDepth >= global.settings.timeoutDiveReachedZeroDepth) || (ManualExitDiveCounter)) |
38 | 622 { |
623 global.dataSendToMaster.mode = MODE_ENDDIVE; | |
624 global.deviceDataSendToMaster.mode = MODE_ENDDIVE; | |
625 } | |
626 } | |
627 else | |
628 { | |
629 global.lifeData.counterSecondsShallowDepth = 0; | |
630 global.lifeData.dive_time_seconds_without_surface_time++; | |
631 } | |
632 } // standard dive or DIVEMODE_Apnea | |
633 | |
88 | 634 copyVpmCrushingData(); |
635 copyTimeData(); | |
636 copyCnsAndOtuData(); | |
637 copyBatteryData(); | |
38 | 638 |
88 | 639 // new hw 170523 |
640 if(global.I2C_SystemStatus != HAL_OK) | |
641 { | |
642 MX_I2C1_TestAndClear(); | |
643 MX_I2C1_Init(); | |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
644 init_pressure(); |
88 | 645 } |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
646 } |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
647 if(ticksdiff >= 1000) |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
648 { |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
649 /* reset counter */ |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
650 Scheduler.tickstart = HAL_GetTick(); |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
651 Scheduler.counterSPIdata100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
652 Scheduler.counterCompass100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
653 Scheduler.counterPressure100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
654 Scheduler.counterAmbientLight100msec = 0; |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
655 Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC; |
38 | 656 } |
657 } | |
658 } | |
659 | |
660 | |
661 /** | |
662 ****************************************************************************** | |
663 * @brief scheduleSurfaceMode / surface mode: Main Loop | |
664 * @author Peter Ryser | |
665 * @version V0.0.1 | |
666 * @date 22-April-2014 | |
667 ****************************************************************************** | |
668 */ | |
669 | |
670 | |
671 // =============================================================================== | |
672 // scheduleTestMode | |
673 /// @brief included for sealed hardware with permanent RTE update message | |
674 // =============================================================================== | |
675 void scheduleTestMode(void) | |
676 { | |
677 uint32_t ticksdiff = 0; | |
678 uint32_t lasttick = 0; | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
679 Scheduler.tickstart = HAL_GetTick(); |
38 | 680 |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
681 Scheduler.counterPressure100msec = 0; |
38 | 682 |
683 float temperature_carousel = 0.0f; | |
684 float temperature_changer = 0.1f; | |
685 | |
686 while(global.mode == MODE_TEST) | |
687 { | |
688 lasttick = HAL_GetTick(); | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
689 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick); |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
690 |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
691 //Evaluate received data at 10 ms, 110 ms, 210 ms,... |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
692 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
693 { |
277 | 694 if(SPI_Evaluate_RX_Data()!=0) /* did we receive something ? */ |
695 { | |
696 Scheduler.counterSPIdata100msec++; | |
697 } | |
698 schedule_check_resync(); | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
699 } |
38 | 700 |
701 //Evaluate pressure at 20 ms, 120 ms, 220 ms,... | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
702 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20) |
38 | 703 { |
704 global.check_sync_not_running++; | |
705 | |
277 | 706 pressure_update_alternating(); |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
707 scheduleUpdateDeviceData(); |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
708 global.lifeData.ascent_rate_meter_per_min = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
709 copyPressureData(); |
38 | 710 |
711 if(temperature_carousel > 20.0f) | |
712 { | |
713 temperature_carousel = 20.0f; | |
714 temperature_changer = -0.1f; | |
715 } | |
716 else | |
717 if(temperature_carousel < 0) | |
718 { | |
719 temperature_carousel = 0; | |
720 temperature_changer = +0.1f; | |
721 } | |
722 | |
723 temperature_carousel += temperature_changer; | |
724 | |
725 uint8_t boolPressureData = !global.dataSendToMaster.boolPressureData; | |
726 | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
727 global.dataSendToMaster.data[boolPressureData].pressure_mbar = get_pressure_mbar(); |
38 | 728 |
729 global.dataSendToMaster.data[boolPressureData].temperature = temperature_carousel; | |
730 global.dataSendToMaster.data[boolPressureData].pressure_uTick = HAL_GetTick(); | |
731 global.dataSendToMaster.boolPressureData = boolPressureData; | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
732 Scheduler.counterPressure100msec++; |
38 | 733 } |
734 | |
735 if(ticksdiff >= 1000) | |
736 { | |
737 //Set back tick counter | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
738 Scheduler.tickstart = HAL_GetTick(); |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
739 Scheduler.counterPressure100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
740 Scheduler.counterSPIdata100msec = 0; |
38 | 741 } |
742 }; | |
743 } | |
744 | |
745 | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
746 |
38 | 747 void scheduleSurfaceMode(void) |
748 { | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
749 |
38 | 750 uint32_t ticksdiff = 0; |
751 uint32_t lasttick = 0; | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
752 Scheduler.tickstart = HAL_GetTick(); |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
753 Scheduler.counterSPIdata100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
754 Scheduler.counterCompass100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
755 Scheduler.counterPressure100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
756 Scheduler.counterAmbientLight100msec = 0; |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
757 Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC; |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
758 |
38 | 759 global.dataSendToMaster.mode = MODE_SURFACE; |
760 global.deviceDataSendToMaster.mode = MODE_SURFACE; | |
761 | |
762 while(global.mode == MODE_SURFACE) | |
763 { | |
277 | 764 |
38 | 765 lasttick = HAL_GetTick(); |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
766 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick); |
38 | 767 |
768 if(setButtonsNow == 1) | |
769 { | |
770 if(scheduleSetButtonResponsiveness()) | |
771 setButtonsNow = 0; | |
772 } | |
773 | |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
774 /* 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
|
775 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
776 { |
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
777 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
|
778 { |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
779 Scheduler.counterSPIdata100msec++; |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
780 } |
277 | 781 schedule_check_resync(); |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
782 } |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
783 |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
784 /* 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
|
785 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20) |
38 | 786 { |
787 global.check_sync_not_running++; | |
277 | 788 pressure_update_alternating(); |
135 | 789 scheduleUpdateDeviceData(); |
38 | 790 global.lifeData.ascent_rate_meter_per_min = 0; |
135 | 791 copyPressureData(); |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
792 Scheduler.counterPressure100msec++; |
135 | 793 |
301
a09b1855d656
cleanup, RTE: factor out scheduleCheck_pressure_reached_dive_mode_level
Jan Mulder <jlmulder@xs4all.nl>
parents:
277
diff
changeset
|
794 if (!is_ambient_pressure_close_to_surface(&global.lifeData)) |
38 | 795 global.mode = MODE_DIVE; |
796 } | |
797 | |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
798 /* 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
|
799 if(ticksdiff >= Scheduler.counterCompass100msec * 100 + 50) |
135 | 800 { |
801 compass_read(); | |
802 acceleration_read(); | |
803 compass_calc(); | |
804 copyCompassData(); | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
805 Scheduler.counterCompass100msec++; |
135 | 806 } |
38 | 807 |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
808 /* 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
|
809 if(ticksdiff >= Scheduler.counterAmbientLight100msec * 100 + 70) |
38 | 810 { |
811 adc_ambient_light_sensor_get_data(); | |
812 copyAmbientLightData(); | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
813 Scheduler.counterAmbientLight100msec++; |
38 | 814 } |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
815 |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
816 |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
817 |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
818 /* 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
|
819 if(ticksdiff >= Scheduler.tick_execute1second) |
38 | 820 { |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
821 Scheduler.tick_execute1second = 0xFFFFFFFF; |
38 | 822 if(clearDecoNow) |
823 { | |
824 decom_reset_with_1000mbar(&global.lifeData); ///< this should almost reset desaturation time | |
825 // new 160215 hw | |
826 global.repetitive_dive = 0; | |
827 global.seconds_since_last_dive = 0; ///< this will reset OTU and CNS as well | |
828 global.no_fly_time_minutes = 0; | |
829 global.accidentFlag = 0; | |
830 global.accidentRemainingSeconds = 0; | |
831 vpm_init(&global.vpm, global.conservatism, global.repetitive_dive, global.seconds_since_last_dive); | |
832 clearDecoNow = 0; | |
833 } | |
89 | 834 |
349
9d82411d0afa
Decrease ManualExitDiveCounter in surface mode
ideenmodellierer
parents:
346
diff
changeset
|
835 if(ManualExitDiveCounter) |
9d82411d0afa
Decrease ManualExitDiveCounter in surface mode
ideenmodellierer
parents:
346
diff
changeset
|
836 { |
9d82411d0afa
Decrease ManualExitDiveCounter in surface mode
ideenmodellierer
parents:
346
diff
changeset
|
837 ManualExitDiveCounter--; |
9d82411d0afa
Decrease ManualExitDiveCounter in surface mode
ideenmodellierer
parents:
346
diff
changeset
|
838 } |
9d82411d0afa
Decrease ManualExitDiveCounter in surface mode
ideenmodellierer
parents:
346
diff
changeset
|
839 |
38 | 840 if(global.seconds_since_last_dive) |
841 { | |
842 schedule_update_timer_helper(-1); | |
843 } | |
89 | 844 |
38 | 845 if(global.accidentRemainingSeconds) |
846 { | |
847 global.accidentRemainingSeconds--; | |
848 if(!global.accidentRemainingSeconds) | |
849 global.accidentFlag = 0; | |
850 } | |
851 global.dataSendToMaster.accidentFlags = global.accidentFlag; | |
89 | 852 |
38 | 853 update_surface_pressure(1); |
854 scheduleUpdateLifeData(0); | |
855 decom_oxygen_calculate_otu_degrade(&global.lifeData.otu, global.seconds_since_last_dive); | |
856 decom_oxygen_calculate_cns_degrade(&global.lifeData.cns, global.seconds_since_last_dive); | |
135 | 857 |
858 /* start desaturation calculation after first valid measurement has been done */ | |
859 if(global.lifeData.pressure_surface_bar != INVALID_PREASURE_VALUE) | |
860 { | |
861 global.lifeData.desaturation_time_minutes = decom_calc_desaturation_time(global.lifeData.tissue_nitrogen_bar,global.lifeData.tissue_helium_bar,global.lifeData.pressure_surface_bar); | |
862 } | |
863 else | |
864 { | |
865 global.lifeData.desaturation_time_minutes = 0; | |
866 } | |
38 | 867 battery_charger_get_status_and_contral_battery_gas_gauge(0); |
88 | 868 battery_gas_gauge_get_data(); |
89 | 869 |
88 | 870 copyCnsAndOtuData(); |
871 copyTimeData(); | |
872 copyBatteryData(); | |
873 copyDeviceData(); | |
38 | 874 |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
875 /* check if I2C is not up an running and try to reactivate if necessary. Also do initialization if problem occured during startup */ |
88 | 876 if(global.I2C_SystemStatus != HAL_OK) |
877 { | |
878 MX_I2C1_TestAndClear(); | |
879 MX_I2C1_Init(); | |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
880 if(global.I2C_SystemStatus == HAL_OK) |
88 | 881 { |
882 init_pressure(); | |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
883 if(is_init_pressure_done()) /* Init surface data with initial measurement */ |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
884 { |
338
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
885 init_surface_ring(0); |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
886 } |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
887 |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
888 if(!battery_gas_gauge_CheckConfigOK()) |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
889 { |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
890 init_battery_gas_gauge(); |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
891 } |
88 | 892 } |
893 } | |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
894 } |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
895 |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
896 if(ticksdiff >= 1000) |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
897 { |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
898 //Set back tick counter |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
899 Scheduler.tickstart = HAL_GetTick(); |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
900 Scheduler.counterSPIdata100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
901 Scheduler.counterCompass100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
902 Scheduler.counterPressure100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
903 Scheduler.counterAmbientLight100msec = 0; |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
904 Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC; |
38 | 905 } |
906 } | |
907 } | |
908 | |
207 | 909 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
|
910 { |
207 | 911 if( SyncMethod < SPI_SYNC_METHOD_INVALID) |
912 { | |
913 dospisync = SyncMethod; | |
914 } | |
915 } | |
916 | |
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
917 void Scheduler_SyncToSPI(uint8_t TXtick) |
207 | 918 { |
919 uint32_t deltatick = 0; | |
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
920 int8_t TXcompensation; |
207 | 921 |
922 switch(dospisync) | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
923 { |
207 | 924 case SPI_SYNC_METHOD_HARD: |
925 //Set back tick counter | |
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
926 Scheduler.tickstart = HAL_GetTick() - 4; /* consider 4ms offset for transfer */ |
207 | 927 Scheduler.counterSPIdata100msec = 0; |
928 Scheduler.counterCompass100msec = 0; | |
929 Scheduler.counterPressure100msec = 0; | |
930 Scheduler.counterAmbientLight100msec = 0; | |
931 dospisync = SPI_SYNC_METHOD_NONE; | |
932 break; | |
933 case SPI_SYNC_METHOD_SOFT: | |
934 deltatick = time_elapsed_ms(Scheduler.tickstart,HAL_GetTick()); | |
935 deltatick %= 100; /* clip to 100ms window */ | |
936 if(Scheduler.tickstart - deltatick >= 0) /* adjust start time to the next 100ms window */ | |
937 { | |
938 Scheduler.tickstart -= deltatick; | |
939 } | |
940 else | |
941 { | |
942 Scheduler.tickstart = 0xFFFFFFFF- (deltatick - Scheduler.tickstart); | |
943 } | |
944 dospisync = SPI_SYNC_METHOD_NONE; | |
945 break; | |
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
946 default: /* continous sync activity */ |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
947 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
|
948 { |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
949 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
|
950 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
|
951 deltatick %= 100; |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
952 if(deltatick > 50) |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
953 { |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
954 TXcompensation = deltatick - 100; /* neg drift */ |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
955 } |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
956 else |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
957 { |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
958 TXcompensation = deltatick; /* pos drift */ |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
959 } |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
960 TXcompensation = TXtick - TXcompensation; |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
961 Scheduler.tickstart -= TXcompensation; |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
962 } |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
963 else |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
964 { |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
965 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
|
966 } |
207 | 967 break; |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
968 } |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
969 } |
38 | 970 |
971 /** | |
972 ****************************************************************************** | |
973 * @brief scheduleCompassCalibrationMode | |
974 * @author heinrichs weikamp gmbh | |
975 * @version V0.0.1 | |
976 * @since 31-March-2015 | |
977 * @date 31-March-2015 | |
978 ****************************************************************************** | |
979 */ | |
980 void scheduleCompassCalibrationMode(void) | |
981 { | |
982 compass_init(1,7); // fast mode, max gain | |
983 compass_calib(); // duration : 1 minute! | |
984 compass_init(0,7); // back to normal mode | |
985 | |
986 if(global.seconds_since_last_dive) | |
987 { | |
988 schedule_update_timer_helper(-1); | |
989 } | |
990 | |
991 scheduleUpdateLifeData(0); | |
992 global.mode = MODE_SURFACE; | |
993 } | |
994 | |
995 | |
996 /** | |
997 ****************************************************************************** | |
998 * @brief scheduleSleepMode / sleep mode: Main Loop | |
999 * @author heinrichs weikamp gmbh | |
1000 * @version V0.0.2 | |
1001 * @since 31-March-2015 | |
1002 * @date 22-April-2014 | |
1003 ****************************************************************************** | |
1004 */ | |
1005 | |
1006 void scheduleSleepMode(void) | |
1007 { | |
1008 global.dataSendToMaster.mode = 0; | |
1009 global.deviceDataSendToMaster.mode = 0; | |
1010 | |
1011 /* prevent button wake up problem while in sleep_prepare | |
1012 * sleep prepare does I2C_DeInit() | |
1013 */ | |
1014 if(global.mode != MODE_SLEEP) | |
1015 MX_I2C1_Init(); | |
1016 else | |
1017 do | |
1018 { | |
1019 I2C_DeInit(); | |
1020 | |
1021 #ifdef DEBUGMODE | |
1022 HAL_Delay(2000); | |
1023 #else | |
1024 RTC_StopMode_2seconds(); | |
1025 #endif | |
1026 | |
1027 | |
1028 | |
1029 if(global.mode == MODE_SLEEP) | |
1030 secondsCount += 2; | |
1031 | |
1032 MX_I2C1_Init(); | |
1033 pressure_sensor_get_pressure_raw(); | |
1034 | |
475 | 1035 /* 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
|
1036 if(global.I2C_SystemStatus != HAL_OK) |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1037 { |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1038 MX_I2C1_TestAndClear(); |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1039 MX_I2C1_Init(); |
475 | 1040 |
1041 if((global.I2C_SystemStatus == HAL_OK) && (!is_init_pressure_done())) | |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1042 { |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1043 init_pressure(); |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1044 } |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1045 } |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1046 |
38 | 1047 if(secondsCount >= 30) |
1048 { | |
1049 pressure_sensor_get_temperature_raw(); | |
1050 battery_gas_gauge_get_data(); | |
1051 // ReInit_battery_charger_status_pins(); | |
1052 battery_charger_get_status_and_contral_battery_gas_gauge(1); | |
1053 // DeInit_battery_charger_status_pins(); | |
1054 secondsCount = 0; | |
1055 } | |
1056 | |
1057 pressure_calculation(); | |
1058 | |
1059 scheduleUpdateDeviceData(); | |
1060 update_surface_pressure(2); | |
1061 | |
1062 if(global.seconds_since_last_dive) | |
1063 { | |
1064 schedule_update_timer_helper(-1); | |
1065 } | |
1066 | |
1067 if(global.accidentRemainingSeconds) | |
1068 { | |
1069 if(global.accidentRemainingSeconds > 2) | |
1070 global.accidentRemainingSeconds -= 2; | |
1071 else | |
1072 { | |
1073 global.accidentRemainingSeconds = 0; | |
1074 global.accidentFlag = 0; | |
1075 } | |
1076 } | |
1077 | |
338
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
1078 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
|
1079 || (global.lifeData.pressure_ambient_bar > START_DIVE_IMMEDIATLY_BAR)) |
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
1080 { |
38 | 1081 global.mode = MODE_BOOT; |
338
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
1082 } |
38 | 1083 scheduleUpdateLifeData(2000); |
1084 } | |
1085 while(global.mode == MODE_SLEEP); | |
1086 /* new section for system after Standby */ | |
1087 scheduleUpdateLifeData(-1); | |
1088 clearDecoNow = 0; | |
1089 setButtonsNow = 0; | |
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1090 reinitGlobals(); |
38 | 1091 } |
1092 | |
1093 | |
1094 | |
1095 /* Private functions ---------------------------------------------------------*/ | |
1096 | |
1097 /** | |
1098 ****************************************************************************** | |
1099 * @brief scheduleUpdateLifeData / calculates tissues | |
1100 * @author Peter Ryser | |
1101 * @version V0.0.1 | |
1102 * @date 22-April-2014 | |
1103 ****************************************************************************** | |
1104 */ | |
1105 | |
1106 | |
1107 void scheduleUpdateLifeData(int32_t asynchron_milliseconds_since_last) | |
1108 { | |
1109 static _Bool first = 1; | |
1110 static uint32_t tickstart = 0; | |
1111 static uint32_t ticksrest = 0; | |
1112 | |
1113 uint32_t ticksdiff = 0; | |
1114 uint32_t ticksnow = 0; | |
1115 uint32_t time_seconds = 0; | |
1116 uint8_t whichGasTmp = 0; | |
1117 | |
135 | 1118 uint8_t updateTissueData = 0; |
1119 | |
1120 | |
1121 if(global.lifeData.pressure_surface_bar == INVALID_PREASURE_VALUE) | |
1122 { | |
1123 updateTissueData = 1; | |
1124 } | |
1125 | |
38 | 1126 if(asynchron_milliseconds_since_last < 0) |
1127 { | |
1128 first = 1; | |
1129 tickstart = 0; | |
1130 ticksrest = 0; | |
1131 return; | |
1132 } | |
1133 | |
1134 if(!asynchron_milliseconds_since_last && first) | |
1135 { | |
1136 tickstart = HAL_GetTick(); | |
1137 first = 0; | |
1138 return; | |
1139 } | |
1140 | |
1141 whichGasTmp = global.whichGas; | |
1142 global.lifeData.actualGas = global.aktualGas[whichGasTmp]; | |
1143 global.lifeData.pressure_ambient_bar = get_pressure_mbar() / 1000.0f; | |
1144 global.lifeData.pressure_surface_bar = get_surface_mbar() / 1000.0f; | |
1145 | |
135 | 1146 if(updateTissueData) |
1147 { | |
1148 decom_reset_with_ambientmbar(global.lifeData.pressure_surface_bar,&global.lifeData); | |
1149 } | |
1150 | |
38 | 1151 if(!asynchron_milliseconds_since_last) |
1152 { | |
1153 ticksnow = HAL_GetTick(); | |
1154 ticksdiff = time_elapsed_ms(tickstart,ticksnow); | |
1155 } | |
1156 else | |
1157 { | |
1158 first = 1; | |
1159 ticksdiff = asynchron_milliseconds_since_last; | |
1160 } | |
1161 | |
1162 if(ticksrest > 1000) // whatever happens after standby with STM32L476 | |
1163 ticksrest = 0; // maybe move static to SRAM2 | |
1164 | |
1165 ticksdiff += ticksrest; | |
1166 time_seconds = ticksdiff/ 1000; | |
1167 ticksrest = ticksdiff - time_seconds * 1000; | |
1168 tickstart = ticksnow; | |
1169 | |
1170 decom_tissues_exposure((int)time_seconds, &global.lifeData); | |
1171 if(global.demo_mode) | |
1172 decom_tissues_exposure((int)(3*time_seconds), &global.lifeData); | |
1173 copyTissueData(); | |
1174 } | |
1175 | |
1176 | |
1177 /** | |
1178 ****************************************************************************** | |
1179 * @brief scheduleUpdateDeviceData | |
1180 * @author heinrichs weikamp gmbh | |
1181 * @version V0.0.1 | |
1182 * @date 16-March-2015 | |
1183 * | |
1184 * two step process | |
1185 * first compare with data from main CPU == externalLogbookFlash | |
1186 * second update with new sensor data | |
1187 ****************************************************************************** | |
1188 */ | |
1189 void scheduleSetDate(SDeviceLine *line) | |
1190 { | |
1191 extern RTC_HandleTypeDef RTCHandle; | |
1192 | |
1193 line->date_rtc_dr = (uint32_t)(RTCHandle.Instance->DR & RTC_DR_RESERVED_MASK); | |
1194 line->time_rtc_tr = (uint32_t)(RTCHandle.Instance->TR & RTC_TR_RESERVED_MASK); | |
1195 } | |
1196 | |
1197 | |
1198 void scheduleCopyDeviceData(SDeviceLine *lineWrite, const SDeviceLine *lineRead) | |
1199 { | |
1200 lineWrite->date_rtc_dr = lineRead->date_rtc_dr; | |
1201 lineWrite->time_rtc_tr = lineRead->time_rtc_tr; | |
1202 lineWrite->value_int32 = lineRead->value_int32; | |
1203 } | |
1204 | |
1205 | |
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
|
1206 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
|
1207 { |
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
|
1208 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
|
1209 |
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
|
1210 /* 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
|
1211 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
|
1212 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
|
1213 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
|
1214 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
|
1215 |
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
|
1216 /* 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
|
1217 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
|
1218 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
|
1219 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
|
1220 } |
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
|
1221 |
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
|
1222 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
|
1223 { |
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
|
1224 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
|
1225 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
|
1226 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
|
1227 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
|
1228 |
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
|
1229 /* 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
|
1230 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
|
1231 { |
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
|
1232 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
|
1233 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
|
1234 { |
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
|
1235 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
|
1236 } |
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
|
1237 } |
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
|
1238 |
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
|
1239 } |
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
|
1240 |
38 | 1241 void scheduleUpdateDeviceData(void) |
1242 { | |
1243 /* first step, main CPU */ | |
1244 | |
1245 if(deviceDataFlashValid) | |
1246 { | |
1247 /* 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
|
1248 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
|
1249 { |
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
|
1250 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
|
1251 #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
|
1252 scheduleCheckDate(); |
414
6886aeeca454
Added compile switch for restoring of last known date after power lost:
ideenmodellierer
parents:
409
diff
changeset
|
1253 #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
|
1254 } |
38 | 1255 if(global.deviceData.batteryChargeCompleteCycles.value_int32 < DeviceDataFlash.batteryChargeCompleteCycles.value_int32) |
1256 { | |
1257 scheduleCopyDeviceData(&global.deviceData.batteryChargeCompleteCycles, &DeviceDataFlash.batteryChargeCompleteCycles); | |
1258 } | |
1259 if(global.deviceData.batteryChargeCycles.value_int32 < DeviceDataFlash.batteryChargeCycles.value_int32) | |
1260 { | |
1261 scheduleCopyDeviceData(&global.deviceData.batteryChargeCycles, &DeviceDataFlash.batteryChargeCycles); | |
1262 } | |
1263 if(global.deviceData.temperatureMaximum.value_int32 < DeviceDataFlash.temperatureMaximum.value_int32) | |
1264 { | |
1265 scheduleCopyDeviceData(&global.deviceData.temperatureMaximum, &DeviceDataFlash.temperatureMaximum); | |
1266 } | |
1267 if(global.deviceData.depthMaximum.value_int32 < DeviceDataFlash.depthMaximum.value_int32) | |
1268 { | |
1269 scheduleCopyDeviceData(&global.deviceData.depthMaximum, &DeviceDataFlash.depthMaximum); | |
1270 } | |
1271 if(global.deviceData.diveCycles.value_int32 < DeviceDataFlash.diveCycles.value_int32) | |
1272 { | |
1273 scheduleCopyDeviceData(&global.deviceData.diveCycles, &DeviceDataFlash.diveCycles); | |
1274 } | |
1275 | |
1276 /* min values */ | |
1277 if(global.deviceData.temperatureMinimum.value_int32 > DeviceDataFlash.temperatureMinimum.value_int32) | |
1278 { | |
1279 scheduleCopyDeviceData(&global.deviceData.temperatureMinimum, &DeviceDataFlash.temperatureMinimum); | |
1280 } | |
1281 if(global.deviceData.voltageMinimum.value_int32 > DeviceDataFlash.voltageMinimum.value_int32) | |
1282 { | |
1283 scheduleCopyDeviceData(&global.deviceData.voltageMinimum, &DeviceDataFlash.voltageMinimum); | |
1284 } | |
1285 } | |
1286 | |
1287 /* second step, sensor data */ | |
1288 int32_t temperature_centigrad_int32; | |
1289 int32_t pressure_mbar_int32; | |
1290 int32_t voltage_mvolt_int32; | |
1291 | |
1292 temperature_centigrad_int32 = (int32_t)(get_temperature() * 100); | |
1293 if(temperature_centigrad_int32 < global.deviceData.temperatureMinimum.value_int32) | |
1294 { | |
1295 global.deviceData.temperatureMinimum.value_int32 = temperature_centigrad_int32; | |
88 | 1296 scheduleSetDate(&global.deviceData.temperatureMinimum); |
38 | 1297 } |
1298 | |
1299 if(temperature_centigrad_int32 > global.deviceData.temperatureMaximum.value_int32) | |
1300 { | |
1301 global.deviceData.temperatureMaximum.value_int32 = temperature_centigrad_int32; | |
88 | 1302 scheduleSetDate(&global.deviceData.temperatureMaximum); |
38 | 1303 } |
1304 | |
1305 pressure_mbar_int32 = (int32_t)get_pressure_mbar(); | |
1306 if(pressure_mbar_int32 > global.deviceData.depthMaximum.value_int32) | |
1307 { | |
1308 global.deviceData.depthMaximum.value_int32 = pressure_mbar_int32; | |
88 | 1309 scheduleSetDate(&global.deviceData.depthMaximum); |
38 | 1310 } |
1311 | |
1312 voltage_mvolt_int32 = (int32_t)(get_voltage() * 1000); | |
1313 if(voltage_mvolt_int32 < global.deviceData.voltageMinimum.value_int32) | |
1314 { | |
1315 global.deviceData.voltageMinimum.value_int32 = voltage_mvolt_int32; | |
88 | 1316 scheduleSetDate(&global.deviceData.voltageMinimum); |
38 | 1317 } |
1318 | |
1319 /* third step, counter */ | |
1320 switch (global.mode) | |
1321 { | |
1322 case MODE_SURFACE: | |
1323 case MODE_DIVE: | |
1324 default: | |
1325 deviceDataSubSeconds++; | |
1326 if(deviceDataSubSeconds > 10) | |
1327 { | |
1328 deviceDataSubSeconds = 0; | |
1329 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
|
1330 scheduleSetDate(&global.deviceData.hoursOfOperation); |
38 | 1331 } |
1332 break; | |
1333 | |
1334 case MODE_SLEEP: | |
1335 case MODE_SHUTDOWN: | |
1336 break; | |
1337 } | |
1338 } | |
1339 | |
1340 | |
1341 void scheduleUpdateDeviceDataChargerFull(void) | |
1342 { | |
1343 global.deviceData.batteryChargeCompleteCycles.value_int32++; | |
88 | 1344 scheduleSetDate(&global.deviceData.batteryChargeCompleteCycles); |
38 | 1345 } |
1346 | |
1347 | |
1348 void scheduleUpdateDeviceDataChargerCharging(void) | |
1349 { | |
1350 global.deviceData.batteryChargeCycles.value_int32++; | |
88 | 1351 scheduleSetDate(&global.deviceData.batteryChargeCycles); |
38 | 1352 } |
1353 | |
1354 | |
1355 /** | |
1356 ****************************************************************************** | |
1357 * @brief vpm_crush / calls vpm calc_crushing_pressure every four seconds during descend | |
1358 * @author Peter Ryser | |
1359 * @version V0.0.1 | |
1360 * @date 22-April-2014 | |
1361 ****************************************************************************** | |
1362 */ | |
1363 _Bool vpm_crush2(void) | |
1364 { | |
1365 int i = 0; | |
1366 static float starting_ambient_pressure = 0; | |
1367 static float ending_ambient_pressure = 0; | |
1368 static float time_calc_begin = -1; | |
1369 static float initial_helium_pressure[16]; | |
1370 static float initial_nitrogen_pressure[16]; | |
1371 ending_ambient_pressure = global.lifeData.pressure_ambient_bar * 10; | |
1372 | |
1373 if((global.lifeData.dive_time_seconds <= 4) || (starting_ambient_pressure >= ending_ambient_pressure)) | |
1374 { | |
1375 time_calc_begin = global.lifeData.dive_time_seconds; | |
1376 starting_ambient_pressure = global.lifeData.pressure_ambient_bar * 10; | |
1377 for( i = 0; i < 16; i++) | |
1378 { | |
1379 initial_helium_pressure[i] = global.lifeData.tissue_helium_bar[i] * 10; | |
1380 initial_nitrogen_pressure[i] = global.lifeData.tissue_nitrogen_bar[i] * 10; | |
1381 } | |
1382 return 0; | |
1383 } | |
1384 if(global.lifeData.dive_time_seconds - time_calc_begin >= 4) | |
1385 { | |
1386 if(ending_ambient_pressure > starting_ambient_pressure + 0.5f) | |
1387 { | |
1388 float rate = (ending_ambient_pressure - starting_ambient_pressure) * 60 / 4; | |
1389 calc_crushing_pressure(&global.lifeData, &global.vpm, initial_helium_pressure, initial_nitrogen_pressure, starting_ambient_pressure, rate); | |
1390 | |
1391 time_calc_begin = global.lifeData.dive_time_seconds; | |
1392 starting_ambient_pressure = global.lifeData.pressure_ambient_bar * 10; | |
1393 for( i = 0; i < 16; i++) | |
1394 { | |
1395 initial_helium_pressure[i] = global.lifeData.tissue_helium_bar[i] * 10; | |
1396 initial_nitrogen_pressure[i] = global.lifeData.tissue_nitrogen_bar[i] * 10; | |
1397 } | |
1398 | |
1399 return 1; | |
1400 } | |
1401 | |
1402 } | |
1403 return 0; | |
1404 } | |
1405 | |
1406 | |
1407 long get_nofly_time_minutes(void) | |
1408 { | |
1409 | |
1410 if(global.no_fly_time_minutes <= 0) | |
1411 return 0; | |
1412 | |
1413 long minutes_since_last_dive = global.seconds_since_last_dive/60; | |
1414 | |
1415 if((global.seconds_since_last_dive > 0) && (global.no_fly_time_minutes > minutes_since_last_dive)) | |
1416 { | |
1417 return (global.no_fly_time_minutes - minutes_since_last_dive); | |
1418 } | |
1419 else | |
1420 { | |
1421 global.no_fly_time_minutes = 0; | |
1422 return 0; | |
1423 } | |
1424 } | |
1425 | |
1426 | |
1427 //Supports threadsave copying!!! | |
1428 void copyActualGas(SGas gas) | |
1429 { | |
1430 uint8_t whichGas = !global.whichGas; | |
1431 global.aktualGas[whichGas] = gas; | |
1432 global.whichGas = whichGas; | |
1433 } | |
1434 | |
1435 | |
1436 //Supports threadsave copying!!! | |
1437 void copyPressureData(void) | |
1438 { | |
240
625d20070261
Improvement SPI stability/recoverability
Jan Mulder <jlmulder@xs4all.nl>
parents:
231
diff
changeset
|
1439 global.dataSendToMaster.sensorErrors = global.I2C_SystemStatus; |
38 | 1440 uint8_t boolPressureData = !global.dataSendToMaster.boolPressureData; |
1441 global.dataSendToMaster.data[boolPressureData].temperature = get_temperature(); | |
1442 global.dataSendToMaster.data[boolPressureData].pressure_mbar = get_pressure_mbar(); | |
1443 global.dataSendToMaster.data[boolPressureData].surface_mbar = get_surface_mbar(); | |
1444 global.dataSendToMaster.data[boolPressureData].ascent_rate_meter_per_min = global.lifeData.ascent_rate_meter_per_min; | |
1445 global.dataSendToMaster.data[boolPressureData].pressure_uTick = HAL_GetTick(); | |
1446 global.dataSendToMaster.boolPressureData = boolPressureData; | |
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1447 global.dataSendToMaster.data[boolPressureData].SPARE1 = is_surface_pressure_stable(); |
38 | 1448 } |
1449 | |
1450 | |
1451 //Supports threadsave copying!!! | |
1452 void copyCnsAndOtuData(void) | |
1453 { | |
1454 //uint8_t dataSendToMaster. | |
1455 uint8_t boolToxicData = !global.dataSendToMaster.boolToxicData; | |
1456 global.dataSendToMaster.data[boolToxicData].cns = global.lifeData.cns; | |
1457 global.dataSendToMaster.data[boolToxicData].otu = global.lifeData.otu; | |
1458 global.dataSendToMaster.data[boolToxicData].desaturation_time_minutes = global.lifeData.desaturation_time_minutes; | |
1459 global.dataSendToMaster.data[boolToxicData].no_fly_time_minutes = get_nofly_time_minutes(); | |
1460 global.dataSendToMaster.boolToxicData = boolToxicData; | |
1461 } | |
1462 | |
1463 | |
1464 //Supports threadsave copying!!! | |
1465 void copyTimeData(void) | |
1466 { | |
1467 extern RTC_HandleTypeDef RTCHandle; | |
1468 | |
1469 uint8_t boolTimeData = !global.dataSendToMaster.boolTimeData; | |
1470 global.dataSendToMaster.data[boolTimeData].localtime_rtc_tr = (uint32_t)(RTCHandle.Instance->TR & RTC_TR_RESERVED_MASK); | |
1471 global.dataSendToMaster.data[boolTimeData].localtime_rtc_dr = (uint32_t)(RTCHandle.Instance->DR & RTC_DR_RESERVED_MASK); | |
1472 global.dataSendToMaster.data[boolTimeData].divetime_seconds = (uint32_t)global.lifeData.dive_time_seconds; | |
1473 global.dataSendToMaster.data[boolTimeData].dive_time_seconds_without_surface_time = (uint32_t)global.lifeData.dive_time_seconds_without_surface_time; | |
1474 global.dataSendToMaster.data[boolTimeData].surfacetime_seconds = (uint32_t)global.seconds_since_last_dive; | |
1475 global.dataSendToMaster.data[boolTimeData].counterSecondsShallowDepth = (uint32_t)global.lifeData.counterSecondsShallowDepth; | |
1476 global.dataSendToMaster.boolTimeData = boolTimeData; | |
1477 } | |
1478 | |
1479 | |
1480 //Supports threadsave copying!!! | |
1481 void copyCompassData(void) | |
1482 { | |
1483 extern float compass_heading; | |
1484 extern float compass_roll; | |
1485 extern float compass_pitch; | |
1486 //uint8_t dataSendToMaster. | |
1487 uint8_t boolCompassData = !global.dataSendToMaster.boolCompassData; | |
1488 global.dataSendToMaster.data[boolCompassData].compass_heading = compass_heading; | |
1489 global.dataSendToMaster.data[boolCompassData].compass_roll = compass_roll; | |
1490 global.dataSendToMaster.data[boolCompassData].compass_pitch = compass_pitch; | |
1491 global.dataSendToMaster.data[boolCompassData].compass_DX_f = 0; | |
1492 global.dataSendToMaster.data[boolCompassData].compass_DY_f = 0; | |
1493 global.dataSendToMaster.data[boolCompassData].compass_DZ_f = 0; | |
1494 global.dataSendToMaster.data[boolCompassData].compass_uTick = HAL_GetTick(); | |
1495 global.dataSendToMaster.boolCompassData = boolCompassData; | |
1496 } | |
1497 | |
1498 | |
1499 void copyCompassDataDuringCalibration(int16_t dx, int16_t dy, int16_t dz) | |
1500 { | |
1501 extern float compass_heading; | |
1502 extern float compass_roll; | |
1503 extern float compass_pitch; | |
1504 //uint8_t dataSendToMaster. | |
1505 uint8_t boolCompassData = !global.dataSendToMaster.boolCompassData; | |
1506 global.dataSendToMaster.data[boolCompassData].compass_heading = compass_heading; | |
1507 global.dataSendToMaster.data[boolCompassData].compass_roll = compass_roll; | |
1508 global.dataSendToMaster.data[boolCompassData].compass_pitch = compass_pitch; | |
1509 global.dataSendToMaster.data[boolCompassData].compass_DX_f = dx; | |
1510 global.dataSendToMaster.data[boolCompassData].compass_DY_f = dy; | |
1511 global.dataSendToMaster.data[boolCompassData].compass_DZ_f = dz; | |
1512 global.dataSendToMaster.boolCompassData = boolCompassData; | |
1513 } | |
1514 | |
1515 | |
1516 //Supports threadsave copying!!! | |
1517 void copyBatteryData(void) | |
1518 { | |
1519 uint8_t boolBatteryData = !global.dataSendToMaster.boolBatteryData; | |
1520 global.dataSendToMaster.data[boolBatteryData].battery_voltage = get_voltage(); | |
1521 global.dataSendToMaster.data[boolBatteryData].battery_charge= get_charge(); | |
1522 global.dataSendToMaster.boolBatteryData = boolBatteryData; | |
1523 } | |
1524 | |
1525 | |
1526 //Supports threadsave copying!!! | |
1527 void copyAmbientLightData(void) | |
1528 { | |
1529 uint8_t boolAmbientLightData = !global.dataSendToMaster.boolAmbientLightData; | |
1530 global.dataSendToMaster.data[boolAmbientLightData].ambient_light_level = get_ambient_light_level(); | |
1531 global.dataSendToMaster.boolAmbientLightData = boolAmbientLightData; | |
1532 } | |
1533 | |
1534 | |
1535 //Supports threadsave copying!!! | |
1536 void copyTissueData(void) | |
1537 { | |
1538 //uint8_t dataSendToMaster. | |
1539 uint8_t boolTisssueData = !global.dataSendToMaster.boolTisssueData; | |
1540 for(int i = 0; i < 16; i++) | |
1541 { | |
1542 global.dataSendToMaster.data[boolTisssueData].tissue_nitrogen_bar[i] = global.lifeData.tissue_nitrogen_bar[i]; | |
1543 global.dataSendToMaster.data[boolTisssueData].tissue_helium_bar[i] = global.lifeData.tissue_helium_bar[i]; | |
1544 } | |
1545 global.dataSendToMaster.boolTisssueData = boolTisssueData; | |
1546 } | |
1547 | |
1548 | |
1549 //Supports threadsave copying!!! | |
1550 void copyVpmCrushingData(void) | |
1551 { | |
1552 //uint8_t dataSendToMaster. | |
1553 uint8_t boolCrushingData = !global.dataSendToMaster.boolCrushingData; | |
1554 for(int i = 0; i < 16; i++) | |
1555 { | |
1556 global.dataSendToMaster.data[boolCrushingData].max_crushing_pressure_n2[i] = global.vpm.max_crushing_pressure_n2[i]; | |
1557 global.dataSendToMaster.data[boolCrushingData].max_crushing_pressure_he[i] = global.vpm.max_crushing_pressure_he[i]; | |
1558 global.dataSendToMaster.data[boolCrushingData].adjusted_critical_radius_he[i] = global.vpm.adjusted_critical_radius_he[i]; | |
1559 global.dataSendToMaster.data[boolCrushingData].adjusted_critical_radius_n2[i] = global.vpm.adjusted_critical_radius_n2[i]; | |
1560 } | |
1561 global.dataSendToMaster.boolCrushingData = boolCrushingData; | |
1562 } | |
1563 | |
1564 | |
1565 void copyDeviceData(void) | |
1566 { | |
1567 uint8_t boolDeviceData = !global.deviceDataSendToMaster.boolDeviceData; | |
1568 memcpy(&global.deviceDataSendToMaster.DeviceData[boolDeviceData], &global.deviceData,sizeof(SDevice)); | |
1569 global.deviceDataSendToMaster.boolDeviceData = boolDeviceData; | |
1570 | |
1571 global.deviceDataSendToMaster.boolVpmRepetitiveDataValid = 0; | |
1572 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.adjusted_critical_radius_he, &global.vpm.adjusted_critical_radius_he, sizeof(16*4)); | |
1573 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.adjusted_critical_radius_n2, &global.vpm.adjusted_critical_radius_n2, sizeof(16*4)); | |
1574 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.adjusted_crushing_pressure_he, &global.vpm.adjusted_crushing_pressure_he, sizeof(16*4)); | |
1575 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.adjusted_crushing_pressure_n2, &global.vpm.adjusted_crushing_pressure_n2, sizeof(16*4)); | |
1576 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.initial_allowable_gradient_he, &global.vpm.initial_allowable_gradient_he, sizeof(16*4)); | |
1577 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.initial_allowable_gradient_n2, &global.vpm.initial_allowable_gradient_n2, sizeof(16*4)); | |
1578 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.max_actual_gradient, &global.vpm.max_actual_gradient, sizeof(16*4)); | |
1579 global.deviceDataSendToMaster.VpmRepetitiveData.repetitive_variables_not_valid = global.vpm.repetitive_variables_not_valid; | |
1580 global.deviceDataSendToMaster.boolVpmRepetitiveDataValid = 1; | |
1581 } | |
1582 | |
1583 /* copyPICdata(); is used in spi.c */ | |
1584 void copyPICdata(void) | |
1585 { | |
1586 uint8_t boolPICdata = !global.dataSendToMaster.boolPICdata; | |
1587 for(int i = 0; i < 3; i++) | |
1588 { | |
1589 global.dataSendToMaster.data[boolPICdata].button_setting[i] = global.ButtonPICdata[i]; | |
1590 } | |
1591 global.dataSendToMaster.boolPICdata = boolPICdata; | |
1592 } | |
1593 | |
1594 | |
1595 typedef enum | |
1596 { | |
1597 SPI3_OK = 0x00, | |
1598 SPI3_DEINIT = 0x01, | |
1599 } SPI3_StatusTypeDef; | |
1600 /* if spi3 is running and the SPI3_ButtonAdjust call returns OK, all is fine | |
1601 if the SPI3_ButtonAdjust call returns error, the spi3 is DeInit | |
1602 and will be init the next call of scheduleSetButtonResponsiveness() | |
1603 and data will be send again on the third call | |
1604 therefore on return 0 of scheduleSetButtonResponsiveness() the caller flag should kept active | |
1605 */ | |
1606 uint8_t scheduleSetButtonResponsiveness(void) | |
1607 { | |
1608 static uint8_t SPI3status = SPI3_OK; | |
1609 | |
1610 if((SPI3status == SPI3_OK) && (SPI3_ButtonAdjust(global.ButtonResponsiveness, global.ButtonPICdata))) | |
1611 { | |
1612 copyPICdata(); | |
1613 return 1; | |
1614 } | |
1615 else | |
1616 { | |
1617 for(int i=0;i<3;i++) | |
1618 { | |
1619 global.ButtonPICdata[i] = 0xFF; | |
1620 } | |
1621 copyPICdata(); | |
1622 | |
1623 if(SPI3status == SPI3_OK) | |
1624 { | |
1625 MX_SPI3_DeInit(); | |
1626 SPI3status = SPI3_DEINIT; | |
1627 } | |
1628 else | |
1629 { | |
1630 MX_SPI3_Init(); | |
1631 SPI3status = SPI3_OK; | |
1632 } | |
1633 return 0; | |
1634 } | |
1635 } | |
1636 | |
1637 | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
181
diff
changeset
|
1638 //save time difference |
38 | 1639 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow) |
1640 { | |
1641 if(ticksstart <= ticksnow) | |
1642 { | |
1643 return ticksnow - ticksstart; | |
1644 } | |
1645 else | |
1646 { | |
1647 return 0xFFFFFFFF - ticksstart + ticksnow; | |
1648 } | |
1649 } | |
1650 | |
1651 /* same as in data_central.c */ | |
310
95928ef3986f
Make dive mode detection more advanced
Jan Mulder <jlmulder@xs4all.nl>
parents:
301
diff
changeset
|
1652 _Bool is_ambient_pressure_close_to_surface(SLifeData *lifeData) |
38 | 1653 { |
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1654 _Bool retval = true; |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1655 |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1656 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
|
1657 { |
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1658 /* 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
|
1659 if (lifeData->pressure_ambient_bar > START_DIVE_IMMEDIATLY_BAR) |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1660 { |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1661 retval = false; |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1662 } |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1663 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
|
1664 { |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1665 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
|
1666 && (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
|
1667 { |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1668 retval = false; |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1669 } |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1670 } |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1671 } |
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1672 return retval; |
38 | 1673 } |
1674 | |
1675 | |
1676 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ | |
1677 |