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