Mercurial > public > ostc4
annotate Small_CPU/Src/scheduler.c @ 436:079f32a8e68c Improve_BatteryGasGauge
Moved power on detection to RTE:
Removed no longer needed funtion to reset the charger status in case of an power on reset
author | ideenmodellierer |
---|---|
date | Sun, 23 Feb 2020 21:18:49 +0100 |
parents | 6886aeeca454 |
children | 4b000e2386c2 |
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 |
338
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
48 #define INVALID_PREASURE_VALUE (100.0f) |
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 | |
172
c659fda83e44
Minor: Button defaults, release date adjusted, use SPI_SHOW_SYNC_STATS
heinrichsweikamp
parents:
155
diff
changeset
|
113 const uint8_t button_standard_sensitivity = 85; |
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 | |
141 global.dataSendToMaster.power_on_reset = 1; | |
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 | |
159 global.deviceDataSendToMaster.power_on_reset = 1; | |
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 | |
356 | 1035 /* check if I2C is not up an 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(); |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1040 if(global.I2C_SystemStatus == HAL_OK) |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1041 { |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1042 init_pressure(); |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1043 } |
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 |
38 | 1046 if(secondsCount >= 30) |
1047 { | |
1048 pressure_sensor_get_temperature_raw(); | |
1049 battery_gas_gauge_get_data(); | |
1050 // ReInit_battery_charger_status_pins(); | |
1051 battery_charger_get_status_and_contral_battery_gas_gauge(1); | |
1052 // DeInit_battery_charger_status_pins(); | |
1053 secondsCount = 0; | |
1054 } | |
1055 | |
1056 pressure_calculation(); | |
1057 | |
1058 scheduleUpdateDeviceData(); | |
1059 update_surface_pressure(2); | |
1060 | |
1061 if(global.seconds_since_last_dive) | |
1062 { | |
1063 schedule_update_timer_helper(-1); | |
1064 } | |
1065 | |
1066 if(global.accidentRemainingSeconds) | |
1067 { | |
1068 if(global.accidentRemainingSeconds > 2) | |
1069 global.accidentRemainingSeconds -= 2; | |
1070 else | |
1071 { | |
1072 global.accidentRemainingSeconds = 0; | |
1073 global.accidentFlag = 0; | |
1074 } | |
1075 } | |
1076 | |
338
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
1077 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
|
1078 || (global.lifeData.pressure_ambient_bar > START_DIVE_IMMEDIATLY_BAR)) |
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
1079 { |
38 | 1080 global.mode = MODE_BOOT; |
338
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
1081 } |
38 | 1082 scheduleUpdateLifeData(2000); |
1083 } | |
1084 while(global.mode == MODE_SLEEP); | |
1085 /* new section for system after Standby */ | |
1086 scheduleUpdateLifeData(-1); | |
1087 clearDecoNow = 0; | |
1088 setButtonsNow = 0; | |
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1089 reinitGlobals(); |
38 | 1090 } |
1091 | |
1092 | |
1093 | |
1094 /* Private functions ---------------------------------------------------------*/ | |
1095 | |
1096 /** | |
1097 ****************************************************************************** | |
1098 * @brief scheduleUpdateLifeData / calculates tissues | |
1099 * @author Peter Ryser | |
1100 * @version V0.0.1 | |
1101 * @date 22-April-2014 | |
1102 ****************************************************************************** | |
1103 */ | |
1104 | |
1105 | |
1106 void scheduleUpdateLifeData(int32_t asynchron_milliseconds_since_last) | |
1107 { | |
1108 static _Bool first = 1; | |
1109 static uint32_t tickstart = 0; | |
1110 static uint32_t ticksrest = 0; | |
1111 | |
1112 uint32_t ticksdiff = 0; | |
1113 uint32_t ticksnow = 0; | |
1114 uint32_t time_seconds = 0; | |
1115 uint8_t whichGasTmp = 0; | |
1116 | |
135 | 1117 uint8_t updateTissueData = 0; |
1118 | |
1119 | |
1120 if(global.lifeData.pressure_surface_bar == INVALID_PREASURE_VALUE) | |
1121 { | |
1122 updateTissueData = 1; | |
1123 } | |
1124 | |
38 | 1125 if(asynchron_milliseconds_since_last < 0) |
1126 { | |
1127 first = 1; | |
1128 tickstart = 0; | |
1129 ticksrest = 0; | |
1130 return; | |
1131 } | |
1132 | |
1133 if(!asynchron_milliseconds_since_last && first) | |
1134 { | |
1135 tickstart = HAL_GetTick(); | |
1136 first = 0; | |
1137 return; | |
1138 } | |
1139 | |
1140 whichGasTmp = global.whichGas; | |
1141 global.lifeData.actualGas = global.aktualGas[whichGasTmp]; | |
1142 global.lifeData.pressure_ambient_bar = get_pressure_mbar() / 1000.0f; | |
1143 global.lifeData.pressure_surface_bar = get_surface_mbar() / 1000.0f; | |
1144 | |
135 | 1145 if(updateTissueData) |
1146 { | |
1147 decom_reset_with_ambientmbar(global.lifeData.pressure_surface_bar,&global.lifeData); | |
1148 } | |
1149 | |
38 | 1150 if(!asynchron_milliseconds_since_last) |
1151 { | |
1152 ticksnow = HAL_GetTick(); | |
1153 ticksdiff = time_elapsed_ms(tickstart,ticksnow); | |
1154 } | |
1155 else | |
1156 { | |
1157 first = 1; | |
1158 ticksdiff = asynchron_milliseconds_since_last; | |
1159 } | |
1160 | |
1161 if(ticksrest > 1000) // whatever happens after standby with STM32L476 | |
1162 ticksrest = 0; // maybe move static to SRAM2 | |
1163 | |
1164 ticksdiff += ticksrest; | |
1165 time_seconds = ticksdiff/ 1000; | |
1166 ticksrest = ticksdiff - time_seconds * 1000; | |
1167 tickstart = ticksnow; | |
1168 | |
1169 decom_tissues_exposure((int)time_seconds, &global.lifeData); | |
1170 if(global.demo_mode) | |
1171 decom_tissues_exposure((int)(3*time_seconds), &global.lifeData); | |
1172 copyTissueData(); | |
1173 } | |
1174 | |
1175 | |
1176 /** | |
1177 ****************************************************************************** | |
1178 * @brief scheduleUpdateDeviceData | |
1179 * @author heinrichs weikamp gmbh | |
1180 * @version V0.0.1 | |
1181 * @date 16-March-2015 | |
1182 * | |
1183 * two step process | |
1184 * first compare with data from main CPU == externalLogbookFlash | |
1185 * second update with new sensor data | |
1186 ****************************************************************************** | |
1187 */ | |
1188 void scheduleSetDate(SDeviceLine *line) | |
1189 { | |
1190 extern RTC_HandleTypeDef RTCHandle; | |
1191 | |
1192 line->date_rtc_dr = (uint32_t)(RTCHandle.Instance->DR & RTC_DR_RESERVED_MASK); | |
1193 line->time_rtc_tr = (uint32_t)(RTCHandle.Instance->TR & RTC_TR_RESERVED_MASK); | |
1194 } | |
1195 | |
1196 | |
1197 void scheduleCopyDeviceData(SDeviceLine *lineWrite, const SDeviceLine *lineRead) | |
1198 { | |
1199 lineWrite->date_rtc_dr = lineRead->date_rtc_dr; | |
1200 lineWrite->time_rtc_tr = lineRead->time_rtc_tr; | |
1201 lineWrite->value_int32 = lineRead->value_int32; | |
1202 } | |
1203 | |
1204 | |
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
|
1205 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
|
1206 { |
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 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
|
1208 |
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 /* 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
|
1210 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
|
1211 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
|
1212 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
|
1213 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
|
1214 |
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 /* 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
|
1216 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
|
1217 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
|
1218 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
|
1219 } |
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 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
|
1222 { |
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 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
|
1224 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
|
1225 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
|
1226 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
|
1227 |
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 /* 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
|
1229 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
|
1230 { |
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 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
|
1232 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
|
1233 { |
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 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
|
1235 } |
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 |
38 | 1240 void scheduleUpdateDeviceData(void) |
1241 { | |
1242 /* first step, main CPU */ | |
1243 | |
1244 if(deviceDataFlashValid) | |
1245 { | |
1246 /* 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
|
1247 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
|
1248 { |
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 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
|
1250 #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
|
1251 scheduleCheckDate(); |
414
6886aeeca454
Added compile switch for restoring of last known date after power lost:
ideenmodellierer
parents:
409
diff
changeset
|
1252 #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
|
1253 } |
38 | 1254 if(global.deviceData.batteryChargeCompleteCycles.value_int32 < DeviceDataFlash.batteryChargeCompleteCycles.value_int32) |
1255 { | |
1256 scheduleCopyDeviceData(&global.deviceData.batteryChargeCompleteCycles, &DeviceDataFlash.batteryChargeCompleteCycles); | |
1257 } | |
1258 if(global.deviceData.batteryChargeCycles.value_int32 < DeviceDataFlash.batteryChargeCycles.value_int32) | |
1259 { | |
1260 scheduleCopyDeviceData(&global.deviceData.batteryChargeCycles, &DeviceDataFlash.batteryChargeCycles); | |
1261 } | |
1262 if(global.deviceData.temperatureMaximum.value_int32 < DeviceDataFlash.temperatureMaximum.value_int32) | |
1263 { | |
1264 scheduleCopyDeviceData(&global.deviceData.temperatureMaximum, &DeviceDataFlash.temperatureMaximum); | |
1265 } | |
1266 if(global.deviceData.depthMaximum.value_int32 < DeviceDataFlash.depthMaximum.value_int32) | |
1267 { | |
1268 scheduleCopyDeviceData(&global.deviceData.depthMaximum, &DeviceDataFlash.depthMaximum); | |
1269 } | |
1270 if(global.deviceData.diveCycles.value_int32 < DeviceDataFlash.diveCycles.value_int32) | |
1271 { | |
1272 scheduleCopyDeviceData(&global.deviceData.diveCycles, &DeviceDataFlash.diveCycles); | |
1273 } | |
1274 | |
1275 /* min values */ | |
1276 if(global.deviceData.temperatureMinimum.value_int32 > DeviceDataFlash.temperatureMinimum.value_int32) | |
1277 { | |
1278 scheduleCopyDeviceData(&global.deviceData.temperatureMinimum, &DeviceDataFlash.temperatureMinimum); | |
1279 } | |
1280 if(global.deviceData.voltageMinimum.value_int32 > DeviceDataFlash.voltageMinimum.value_int32) | |
1281 { | |
1282 scheduleCopyDeviceData(&global.deviceData.voltageMinimum, &DeviceDataFlash.voltageMinimum); | |
1283 } | |
1284 } | |
1285 | |
1286 /* second step, sensor data */ | |
1287 int32_t temperature_centigrad_int32; | |
1288 int32_t pressure_mbar_int32; | |
1289 int32_t voltage_mvolt_int32; | |
1290 | |
1291 temperature_centigrad_int32 = (int32_t)(get_temperature() * 100); | |
1292 if(temperature_centigrad_int32 < global.deviceData.temperatureMinimum.value_int32) | |
1293 { | |
1294 global.deviceData.temperatureMinimum.value_int32 = temperature_centigrad_int32; | |
88 | 1295 scheduleSetDate(&global.deviceData.temperatureMinimum); |
38 | 1296 } |
1297 | |
1298 if(temperature_centigrad_int32 > global.deviceData.temperatureMaximum.value_int32) | |
1299 { | |
1300 global.deviceData.temperatureMaximum.value_int32 = temperature_centigrad_int32; | |
88 | 1301 scheduleSetDate(&global.deviceData.temperatureMaximum); |
38 | 1302 } |
1303 | |
1304 pressure_mbar_int32 = (int32_t)get_pressure_mbar(); | |
1305 if(pressure_mbar_int32 > global.deviceData.depthMaximum.value_int32) | |
1306 { | |
1307 global.deviceData.depthMaximum.value_int32 = pressure_mbar_int32; | |
88 | 1308 scheduleSetDate(&global.deviceData.depthMaximum); |
38 | 1309 } |
1310 | |
1311 voltage_mvolt_int32 = (int32_t)(get_voltage() * 1000); | |
1312 if(voltage_mvolt_int32 < global.deviceData.voltageMinimum.value_int32) | |
1313 { | |
1314 global.deviceData.voltageMinimum.value_int32 = voltage_mvolt_int32; | |
88 | 1315 scheduleSetDate(&global.deviceData.voltageMinimum); |
38 | 1316 } |
1317 | |
1318 /* third step, counter */ | |
1319 switch (global.mode) | |
1320 { | |
1321 case MODE_SURFACE: | |
1322 case MODE_DIVE: | |
1323 default: | |
1324 deviceDataSubSeconds++; | |
1325 if(deviceDataSubSeconds > 10) | |
1326 { | |
1327 deviceDataSubSeconds = 0; | |
1328 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
|
1329 scheduleSetDate(&global.deviceData.hoursOfOperation); |
38 | 1330 } |
1331 break; | |
1332 | |
1333 case MODE_SLEEP: | |
1334 case MODE_SHUTDOWN: | |
1335 break; | |
1336 } | |
1337 } | |
1338 | |
1339 | |
1340 void scheduleUpdateDeviceDataChargerFull(void) | |
1341 { | |
1342 global.deviceData.batteryChargeCompleteCycles.value_int32++; | |
88 | 1343 scheduleSetDate(&global.deviceData.batteryChargeCompleteCycles); |
38 | 1344 } |
1345 | |
1346 | |
1347 void scheduleUpdateDeviceDataChargerCharging(void) | |
1348 { | |
1349 global.deviceData.batteryChargeCycles.value_int32++; | |
88 | 1350 scheduleSetDate(&global.deviceData.batteryChargeCycles); |
38 | 1351 } |
1352 | |
1353 | |
1354 /** | |
1355 ****************************************************************************** | |
1356 * @brief vpm_crush / calls vpm calc_crushing_pressure every four seconds during descend | |
1357 * @author Peter Ryser | |
1358 * @version V0.0.1 | |
1359 * @date 22-April-2014 | |
1360 ****************************************************************************** | |
1361 */ | |
1362 _Bool vpm_crush2(void) | |
1363 { | |
1364 int i = 0; | |
1365 static float starting_ambient_pressure = 0; | |
1366 static float ending_ambient_pressure = 0; | |
1367 static float time_calc_begin = -1; | |
1368 static float initial_helium_pressure[16]; | |
1369 static float initial_nitrogen_pressure[16]; | |
1370 ending_ambient_pressure = global.lifeData.pressure_ambient_bar * 10; | |
1371 | |
1372 if((global.lifeData.dive_time_seconds <= 4) || (starting_ambient_pressure >= ending_ambient_pressure)) | |
1373 { | |
1374 time_calc_begin = global.lifeData.dive_time_seconds; | |
1375 starting_ambient_pressure = global.lifeData.pressure_ambient_bar * 10; | |
1376 for( i = 0; i < 16; i++) | |
1377 { | |
1378 initial_helium_pressure[i] = global.lifeData.tissue_helium_bar[i] * 10; | |
1379 initial_nitrogen_pressure[i] = global.lifeData.tissue_nitrogen_bar[i] * 10; | |
1380 } | |
1381 return 0; | |
1382 } | |
1383 if(global.lifeData.dive_time_seconds - time_calc_begin >= 4) | |
1384 { | |
1385 if(ending_ambient_pressure > starting_ambient_pressure + 0.5f) | |
1386 { | |
1387 float rate = (ending_ambient_pressure - starting_ambient_pressure) * 60 / 4; | |
1388 calc_crushing_pressure(&global.lifeData, &global.vpm, initial_helium_pressure, initial_nitrogen_pressure, starting_ambient_pressure, rate); | |
1389 | |
1390 time_calc_begin = global.lifeData.dive_time_seconds; | |
1391 starting_ambient_pressure = global.lifeData.pressure_ambient_bar * 10; | |
1392 for( i = 0; i < 16; i++) | |
1393 { | |
1394 initial_helium_pressure[i] = global.lifeData.tissue_helium_bar[i] * 10; | |
1395 initial_nitrogen_pressure[i] = global.lifeData.tissue_nitrogen_bar[i] * 10; | |
1396 } | |
1397 | |
1398 return 1; | |
1399 } | |
1400 | |
1401 } | |
1402 return 0; | |
1403 } | |
1404 | |
1405 | |
1406 long get_nofly_time_minutes(void) | |
1407 { | |
1408 | |
1409 if(global.no_fly_time_minutes <= 0) | |
1410 return 0; | |
1411 | |
1412 long minutes_since_last_dive = global.seconds_since_last_dive/60; | |
1413 | |
1414 if((global.seconds_since_last_dive > 0) && (global.no_fly_time_minutes > minutes_since_last_dive)) | |
1415 { | |
1416 return (global.no_fly_time_minutes - minutes_since_last_dive); | |
1417 } | |
1418 else | |
1419 { | |
1420 global.no_fly_time_minutes = 0; | |
1421 return 0; | |
1422 } | |
1423 } | |
1424 | |
1425 | |
1426 //Supports threadsave copying!!! | |
1427 void copyActualGas(SGas gas) | |
1428 { | |
1429 uint8_t whichGas = !global.whichGas; | |
1430 global.aktualGas[whichGas] = gas; | |
1431 global.whichGas = whichGas; | |
1432 } | |
1433 | |
1434 | |
1435 //Supports threadsave copying!!! | |
1436 void copyPressureData(void) | |
1437 { | |
240
625d20070261
Improvement SPI stability/recoverability
Jan Mulder <jlmulder@xs4all.nl>
parents:
231
diff
changeset
|
1438 global.dataSendToMaster.sensorErrors = global.I2C_SystemStatus; |
38 | 1439 uint8_t boolPressureData = !global.dataSendToMaster.boolPressureData; |
1440 global.dataSendToMaster.data[boolPressureData].temperature = get_temperature(); | |
1441 global.dataSendToMaster.data[boolPressureData].pressure_mbar = get_pressure_mbar(); | |
1442 global.dataSendToMaster.data[boolPressureData].surface_mbar = get_surface_mbar(); | |
1443 global.dataSendToMaster.data[boolPressureData].ascent_rate_meter_per_min = global.lifeData.ascent_rate_meter_per_min; | |
1444 global.dataSendToMaster.data[boolPressureData].pressure_uTick = HAL_GetTick(); | |
1445 global.dataSendToMaster.boolPressureData = boolPressureData; | |
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1446 global.dataSendToMaster.data[boolPressureData].SPARE1 = is_surface_pressure_stable(); |
38 | 1447 } |
1448 | |
1449 | |
1450 //Supports threadsave copying!!! | |
1451 void copyCnsAndOtuData(void) | |
1452 { | |
1453 //uint8_t dataSendToMaster. | |
1454 uint8_t boolToxicData = !global.dataSendToMaster.boolToxicData; | |
1455 global.dataSendToMaster.data[boolToxicData].cns = global.lifeData.cns; | |
1456 global.dataSendToMaster.data[boolToxicData].otu = global.lifeData.otu; | |
1457 global.dataSendToMaster.data[boolToxicData].desaturation_time_minutes = global.lifeData.desaturation_time_minutes; | |
1458 global.dataSendToMaster.data[boolToxicData].no_fly_time_minutes = get_nofly_time_minutes(); | |
1459 global.dataSendToMaster.boolToxicData = boolToxicData; | |
1460 } | |
1461 | |
1462 | |
1463 //Supports threadsave copying!!! | |
1464 void copyTimeData(void) | |
1465 { | |
1466 extern RTC_HandleTypeDef RTCHandle; | |
1467 | |
1468 uint8_t boolTimeData = !global.dataSendToMaster.boolTimeData; | |
1469 global.dataSendToMaster.data[boolTimeData].localtime_rtc_tr = (uint32_t)(RTCHandle.Instance->TR & RTC_TR_RESERVED_MASK); | |
1470 global.dataSendToMaster.data[boolTimeData].localtime_rtc_dr = (uint32_t)(RTCHandle.Instance->DR & RTC_DR_RESERVED_MASK); | |
1471 global.dataSendToMaster.data[boolTimeData].divetime_seconds = (uint32_t)global.lifeData.dive_time_seconds; | |
1472 global.dataSendToMaster.data[boolTimeData].dive_time_seconds_without_surface_time = (uint32_t)global.lifeData.dive_time_seconds_without_surface_time; | |
1473 global.dataSendToMaster.data[boolTimeData].surfacetime_seconds = (uint32_t)global.seconds_since_last_dive; | |
1474 global.dataSendToMaster.data[boolTimeData].counterSecondsShallowDepth = (uint32_t)global.lifeData.counterSecondsShallowDepth; | |
1475 global.dataSendToMaster.boolTimeData = boolTimeData; | |
1476 } | |
1477 | |
1478 | |
1479 //Supports threadsave copying!!! | |
1480 void copyCompassData(void) | |
1481 { | |
1482 extern float compass_heading; | |
1483 extern float compass_roll; | |
1484 extern float compass_pitch; | |
1485 //uint8_t dataSendToMaster. | |
1486 uint8_t boolCompassData = !global.dataSendToMaster.boolCompassData; | |
1487 global.dataSendToMaster.data[boolCompassData].compass_heading = compass_heading; | |
1488 global.dataSendToMaster.data[boolCompassData].compass_roll = compass_roll; | |
1489 global.dataSendToMaster.data[boolCompassData].compass_pitch = compass_pitch; | |
1490 global.dataSendToMaster.data[boolCompassData].compass_DX_f = 0; | |
1491 global.dataSendToMaster.data[boolCompassData].compass_DY_f = 0; | |
1492 global.dataSendToMaster.data[boolCompassData].compass_DZ_f = 0; | |
1493 global.dataSendToMaster.data[boolCompassData].compass_uTick = HAL_GetTick(); | |
1494 global.dataSendToMaster.boolCompassData = boolCompassData; | |
1495 } | |
1496 | |
1497 | |
1498 void copyCompassDataDuringCalibration(int16_t dx, int16_t dy, int16_t dz) | |
1499 { | |
1500 extern float compass_heading; | |
1501 extern float compass_roll; | |
1502 extern float compass_pitch; | |
1503 //uint8_t dataSendToMaster. | |
1504 uint8_t boolCompassData = !global.dataSendToMaster.boolCompassData; | |
1505 global.dataSendToMaster.data[boolCompassData].compass_heading = compass_heading; | |
1506 global.dataSendToMaster.data[boolCompassData].compass_roll = compass_roll; | |
1507 global.dataSendToMaster.data[boolCompassData].compass_pitch = compass_pitch; | |
1508 global.dataSendToMaster.data[boolCompassData].compass_DX_f = dx; | |
1509 global.dataSendToMaster.data[boolCompassData].compass_DY_f = dy; | |
1510 global.dataSendToMaster.data[boolCompassData].compass_DZ_f = dz; | |
1511 global.dataSendToMaster.boolCompassData = boolCompassData; | |
1512 } | |
1513 | |
1514 | |
1515 //Supports threadsave copying!!! | |
1516 void copyBatteryData(void) | |
1517 { | |
1518 uint8_t boolBatteryData = !global.dataSendToMaster.boolBatteryData; | |
1519 global.dataSendToMaster.data[boolBatteryData].battery_voltage = get_voltage(); | |
1520 global.dataSendToMaster.data[boolBatteryData].battery_charge= get_charge(); | |
1521 global.dataSendToMaster.boolBatteryData = boolBatteryData; | |
1522 } | |
1523 | |
1524 | |
1525 //Supports threadsave copying!!! | |
1526 void copyAmbientLightData(void) | |
1527 { | |
1528 uint8_t boolAmbientLightData = !global.dataSendToMaster.boolAmbientLightData; | |
1529 global.dataSendToMaster.data[boolAmbientLightData].ambient_light_level = get_ambient_light_level(); | |
1530 global.dataSendToMaster.boolAmbientLightData = boolAmbientLightData; | |
1531 } | |
1532 | |
1533 | |
1534 //Supports threadsave copying!!! | |
1535 void copyTissueData(void) | |
1536 { | |
1537 //uint8_t dataSendToMaster. | |
1538 uint8_t boolTisssueData = !global.dataSendToMaster.boolTisssueData; | |
1539 for(int i = 0; i < 16; i++) | |
1540 { | |
1541 global.dataSendToMaster.data[boolTisssueData].tissue_nitrogen_bar[i] = global.lifeData.tissue_nitrogen_bar[i]; | |
1542 global.dataSendToMaster.data[boolTisssueData].tissue_helium_bar[i] = global.lifeData.tissue_helium_bar[i]; | |
1543 } | |
1544 global.dataSendToMaster.boolTisssueData = boolTisssueData; | |
1545 } | |
1546 | |
1547 | |
1548 //Supports threadsave copying!!! | |
1549 void copyVpmCrushingData(void) | |
1550 { | |
1551 //uint8_t dataSendToMaster. | |
1552 uint8_t boolCrushingData = !global.dataSendToMaster.boolCrushingData; | |
1553 for(int i = 0; i < 16; i++) | |
1554 { | |
1555 global.dataSendToMaster.data[boolCrushingData].max_crushing_pressure_n2[i] = global.vpm.max_crushing_pressure_n2[i]; | |
1556 global.dataSendToMaster.data[boolCrushingData].max_crushing_pressure_he[i] = global.vpm.max_crushing_pressure_he[i]; | |
1557 global.dataSendToMaster.data[boolCrushingData].adjusted_critical_radius_he[i] = global.vpm.adjusted_critical_radius_he[i]; | |
1558 global.dataSendToMaster.data[boolCrushingData].adjusted_critical_radius_n2[i] = global.vpm.adjusted_critical_radius_n2[i]; | |
1559 } | |
1560 global.dataSendToMaster.boolCrushingData = boolCrushingData; | |
1561 } | |
1562 | |
1563 | |
1564 void copyDeviceData(void) | |
1565 { | |
1566 uint8_t boolDeviceData = !global.deviceDataSendToMaster.boolDeviceData; | |
1567 memcpy(&global.deviceDataSendToMaster.DeviceData[boolDeviceData], &global.deviceData,sizeof(SDevice)); | |
1568 global.deviceDataSendToMaster.boolDeviceData = boolDeviceData; | |
1569 | |
1570 global.deviceDataSendToMaster.boolVpmRepetitiveDataValid = 0; | |
1571 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.adjusted_critical_radius_he, &global.vpm.adjusted_critical_radius_he, sizeof(16*4)); | |
1572 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.adjusted_critical_radius_n2, &global.vpm.adjusted_critical_radius_n2, sizeof(16*4)); | |
1573 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.adjusted_crushing_pressure_he, &global.vpm.adjusted_crushing_pressure_he, sizeof(16*4)); | |
1574 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.adjusted_crushing_pressure_n2, &global.vpm.adjusted_crushing_pressure_n2, sizeof(16*4)); | |
1575 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.initial_allowable_gradient_he, &global.vpm.initial_allowable_gradient_he, sizeof(16*4)); | |
1576 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.initial_allowable_gradient_n2, &global.vpm.initial_allowable_gradient_n2, sizeof(16*4)); | |
1577 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.max_actual_gradient, &global.vpm.max_actual_gradient, sizeof(16*4)); | |
1578 global.deviceDataSendToMaster.VpmRepetitiveData.repetitive_variables_not_valid = global.vpm.repetitive_variables_not_valid; | |
1579 global.deviceDataSendToMaster.boolVpmRepetitiveDataValid = 1; | |
1580 } | |
1581 | |
1582 /* copyPICdata(); is used in spi.c */ | |
1583 void copyPICdata(void) | |
1584 { | |
1585 uint8_t boolPICdata = !global.dataSendToMaster.boolPICdata; | |
1586 for(int i = 0; i < 3; i++) | |
1587 { | |
1588 global.dataSendToMaster.data[boolPICdata].button_setting[i] = global.ButtonPICdata[i]; | |
1589 } | |
1590 global.dataSendToMaster.boolPICdata = boolPICdata; | |
1591 } | |
1592 | |
1593 | |
1594 typedef enum | |
1595 { | |
1596 SPI3_OK = 0x00, | |
1597 SPI3_DEINIT = 0x01, | |
1598 } SPI3_StatusTypeDef; | |
1599 /* if spi3 is running and the SPI3_ButtonAdjust call returns OK, all is fine | |
1600 if the SPI3_ButtonAdjust call returns error, the spi3 is DeInit | |
1601 and will be init the next call of scheduleSetButtonResponsiveness() | |
1602 and data will be send again on the third call | |
1603 therefore on return 0 of scheduleSetButtonResponsiveness() the caller flag should kept active | |
1604 */ | |
1605 uint8_t scheduleSetButtonResponsiveness(void) | |
1606 { | |
1607 static uint8_t SPI3status = SPI3_OK; | |
1608 | |
1609 if((SPI3status == SPI3_OK) && (SPI3_ButtonAdjust(global.ButtonResponsiveness, global.ButtonPICdata))) | |
1610 { | |
1611 copyPICdata(); | |
1612 return 1; | |
1613 } | |
1614 else | |
1615 { | |
1616 for(int i=0;i<3;i++) | |
1617 { | |
1618 global.ButtonPICdata[i] = 0xFF; | |
1619 } | |
1620 copyPICdata(); | |
1621 | |
1622 if(SPI3status == SPI3_OK) | |
1623 { | |
1624 MX_SPI3_DeInit(); | |
1625 SPI3status = SPI3_DEINIT; | |
1626 } | |
1627 else | |
1628 { | |
1629 MX_SPI3_Init(); | |
1630 SPI3status = SPI3_OK; | |
1631 } | |
1632 return 0; | |
1633 } | |
1634 } | |
1635 | |
1636 | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
181
diff
changeset
|
1637 //save time difference |
38 | 1638 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow) |
1639 { | |
1640 if(ticksstart <= ticksnow) | |
1641 { | |
1642 return ticksnow - ticksstart; | |
1643 } | |
1644 else | |
1645 { | |
1646 return 0xFFFFFFFF - ticksstart + ticksnow; | |
1647 } | |
1648 } | |
1649 | |
1650 /* same as in data_central.c */ | |
310
95928ef3986f
Make dive mode detection more advanced
Jan Mulder <jlmulder@xs4all.nl>
parents:
301
diff
changeset
|
1651 _Bool is_ambient_pressure_close_to_surface(SLifeData *lifeData) |
38 | 1652 { |
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1653 _Bool retval = true; |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1654 |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1655 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
|
1656 { |
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1657 /* 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
|
1658 if (lifeData->pressure_ambient_bar > START_DIVE_IMMEDIATLY_BAR) |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1659 { |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1660 retval = false; |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1661 } |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1662 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
|
1663 { |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1664 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
|
1665 && (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
|
1666 { |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1667 retval = false; |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1668 } |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1669 } |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1670 } |
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1671 return retval; |
38 | 1672 } |
1673 | |
1674 | |
1675 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ | |
1676 |