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