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