Mercurial > public > ostc4
annotate Small_CPU/Src/scheduler.c @ 87:e746bf846638 kittz
tmp
author | Dmitry Romanov <kitt@bk.ru> |
---|---|
date | Wed, 21 Nov 2018 13:57:58 +0300 |
parents | cc41b5eaf1a7 |
children | 3db7389d49cc |
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 | |
47 /* Private types -------------------------------------------------------------*/ | |
48 const SGas Air = {79,0,0,0,0}; | |
49 | |
50 uint8_t testarrayindex = 0; | |
51 uint32_t testarray[256]; | |
52 uint32_t testarrayMain[256]; | |
53 | |
54 /* Exported variables --------------------------------------------------------*/ | |
55 SGlobal global; | |
56 SDevice DeviceDataFlash; | |
57 uint8_t deviceDataFlashValid = 0; | |
58 uint8_t deviceDataSubSeconds = 0; | |
59 | |
60 /* Private variables ---------------------------------------------------------*/ | |
61 /* can be lost while in sleep */ | |
62 uint8_t clearDecoNow = 0; | |
63 uint8_t setButtonsNow = 0; | |
64 | |
65 /* has to be in SRAM2 */ | |
66 uint8_t secondsCount = 0; | |
67 | |
68 /* Private function prototypes -----------------------------------------------*/ | |
69 | |
70 _Bool vpm_crush2(void); | |
71 void scheduleUpdateDeviceData(void); | |
72 void initStructWithZeero(uint8_t* data, uint16_t length); | |
73 long get_nofly_time_minutes(void); | |
74 void copyActualGas(SGas gas); | |
75 void copyPressureData(void); | |
76 void copyCnsAndOtuData(void); | |
77 void copyTimeData(void); | |
78 void copyCompassData(void); | |
79 void copyCompassDataDuringCalibration(int16_t dx, int16_t dy, int16_t dz); | |
80 //void copyBatteryData(void); now in header | |
81 void copyAmbientLightData(void); | |
82 void copyTissueData(void); | |
83 void copyVpmCrushingData(void); | |
84 void copyDeviceData(void); | |
85 void changeAgeWirelessData(void); | |
86 void copyWirelessData(void); | |
87 void copyPICdata(void); | |
88 uint16_t schedule_update_timer_helper(int8_t thisSeconds); | |
89 | |
90 | |
91 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow); | |
92 | |
93 _Bool scheduleCheck_pressure_reached_dive_mode_level(void); | |
94 void scheduleSetDate(SDeviceLine *line); | |
95 | |
96 /* Exported functions --------------------------------------------------------*/ | |
97 | |
98 void initGlobals(void) | |
99 { | |
100 initStructWithZeero((uint8_t*) &global, sizeof(SGlobal)); | |
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 | |
113 const uint8_t button_standard_sensitivity = ((2400-( 90 *24))/10)+15; | |
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 | |
126 global.lifeData.pressure_ambient_bar = 1.0f; | |
127 global.lifeData.pressure_surface_bar = 1.0f; | |
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; | |
179 } | |
180 | |
181 | |
182 void scheduleSpecial_Evaluate_DataSendToSlave(void) | |
183 { | |
84
e6abbef57475
Remove unusable code!!! prepare data for SPI in ONLY 1 IRQ!!!!
Dmitry Romanov <kitt@bk.ru>
parents:
82
diff
changeset
|
184 |
87 | 185 /* for device data updates */ |
186 deviceDataFlashValid = 0; | |
187 memcpy(&DeviceDataFlash, &global.dataSendToSlave.data.DeviceData, sizeof(SDevice)); | |
84
e6abbef57475
Remove unusable code!!! prepare data for SPI in ONLY 1 IRQ!!!!
Dmitry Romanov <kitt@bk.ru>
parents:
82
diff
changeset
|
188 |
87 | 189 //TODO: (kittz) split by current mode. |
190 | |
191 // new hw 170523 | |
192 if(global.I2C_SystemStatus != HAL_OK) | |
193 { | |
194 MX_I2C1_TestAndClear(); | |
195 MX_I2C1_Init(); | |
196 if(!is_init_pressure_done()) | |
197 { | |
198 init_pressure(); | |
199 } | |
200 } | |
201 | |
202 pressure_update(); | |
203 copyPressureData(); | |
204 compass_read(); | |
205 acceleration_read(); | |
206 compass_calc(); | |
207 battery_gas_gauge_get_data(); | |
208 copyCompassData(); | |
209 | |
210 copyCnsAndOtuData(); | |
211 copyTimeData(); | |
212 copyBatteryData(); | |
213 copyDeviceData(); | |
214 copyVpmCrushingData(); | |
215 | |
216 deviceDataFlashValid = 1; | |
217 scheduleUpdateDeviceData(); | |
218 | |
219 | |
220 | |
221 | |
222 // global.dataSendToSlavePending = 0; | |
84
e6abbef57475
Remove unusable code!!! prepare data for SPI in ONLY 1 IRQ!!!!
Dmitry Romanov <kitt@bk.ru>
parents:
82
diff
changeset
|
223 // if(!global.dataSendToSlaveIsValid) return; //TODO: WHAT THE FUCK?????!!!!! |
38 | 224 |
225 global.dataSendToMaster.confirmRequest.uw = 0; | |
226 | |
227 if(TM_OTP_Read(0,0) == 0xFF) | |
228 { | |
229 if(global.dataSendToSlave.revisionHardware == (global.dataSendToSlave.revisionCRCx0x7A ^ 0x7A)) | |
230 TM_OTP_Write(0,0,global.dataSendToSlave.revisionHardware); | |
231 } | |
232 | |
233 if(global.dataSendToSlave.setAccidentFlag) | |
234 { | |
235 global.dataSendToMaster.confirmRequest.ub.accident = 1; | |
236 global.deviceData.diveAccident.value_int32 = global.dataSendToSlave.setAccidentFlag; | |
237 scheduleSetDate(&global.deviceData.diveAccident); | |
238 global.accidentFlag |= global.dataSendToSlave.setAccidentFlag; | |
239 if(global.accidentFlag == ACCIDENT_CNS) // LVL1 | |
240 global.accidentRemainingSeconds = 2*60*60; | |
241 else | |
242 global.accidentRemainingSeconds = 24*60*60; | |
243 } | |
244 | |
245 if(global.dataSendToSlave.setTimeNow) | |
246 { | |
247 global.dataSendToMaster.confirmRequest.ub.time = 1; | |
248 RTC_SetTime(global.dataSendToSlave.data.newTime); | |
249 schedule_update_timer_helper(0); | |
250 } | |
251 | |
252 if(global.dataSendToSlave.setDateNow) | |
253 { | |
254 global.dataSendToMaster.confirmRequest.ub.date = 1; | |
255 RTC_SetDate(global.dataSendToSlave.data.newDate); | |
256 schedule_update_timer_helper(0); | |
257 } | |
258 | |
259 if(global.dataSendToSlave.calibrateCompassNow) | |
260 { | |
261 global.dataSendToMaster.confirmRequest.ub.compass = 1; | |
262 global.mode = MODE_CALIB; | |
263 } | |
264 | |
265 if(global.dataSendToSlave.clearDecoNow) | |
266 { | |
267 global.dataSendToMaster.confirmRequest.ub.clearDeco = 1; | |
268 clearDecoNow = 1; | |
269 } | |
270 | |
271 if(global.dataSendToSlave.setButtonSensitivityNow) | |
272 { | |
273 global.dataSendToMaster.confirmRequest.ub.button = 1; | |
274 global.ButtonResponsiveness[0] = global.dataSendToSlave.data.buttonResponsiveness[0]; | |
275 global.ButtonResponsiveness[1] = global.dataSendToSlave.data.buttonResponsiveness[1]; | |
276 global.ButtonResponsiveness[2] = global.dataSendToSlave.data.buttonResponsiveness[2]; | |
277 global.ButtonResponsiveness[3] = global.dataSendToSlave.data.buttonResponsiveness[3]; | |
278 setButtonsNow = 1; | |
279 } | |
280 | |
281 if(global.dataSendToSlave.setBatteryGaugeNow) | |
282 { | |
283 global.dataSendToMaster.confirmRequest.ub.batterygauge = 1; | |
284 battery_gas_gauge_set(global.dataSendToSlave.data.newBatteryGaugePercentageFloat); | |
285 } | |
286 | |
287 if((global.mode == MODE_SURFACE) && (global.dataSendToSlave.mode == MODE_SHUTDOWN)) | |
288 { | |
289 global.mode = MODE_SHUTDOWN; | |
290 } | |
291 | |
292 if(global.mode == MODE_DIVE) | |
293 { | |
294 copyActualGas(global.dataSendToSlave.data.actualGas); | |
295 } | |
296 else | |
297 { | |
298 copyActualGas(Air); | |
299 global.settings.divetimeToCreateLogbook = global.dataSendToSlave.data.divetimeToCreateLogbook; | |
300 global.settings.timeoutDiveReachedZeroDepth = global.dataSendToSlave.data.timeoutDiveReachedZeroDepth; | |
301 } | |
302 | |
303 /* for simulation / testing */ | |
304 global.ceiling_from_main_CPU_mbar = global.dataSendToSlave.data.ambient_pressure_mbar_ceiling; | |
305 | |
85
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
306 |
38 | 307 } |
308 | |
309 | |
310 /** | |
311 ****************************************************************************** | |
312 * @brief schedule_time_compare_helper. | |
313 * @author heinrichs weikamp gmbh | |
314 * @version V0.0.1 | |
315 * @date 20-Oct-2016 | |
316 ****************************************************************************** | |
317 */ | |
318 | |
319 uint8_t RtcBugFixChsw(uint8_t inStupidTime) | |
320 { | |
321 uint8_t multiplesOf16 = 0; | |
322 | |
323 multiplesOf16 = inStupidTime / 16; | |
324 | |
325 inStupidTime -= multiplesOf16 * 16; | |
326 | |
327 return (10 * multiplesOf16) + inStupidTime; | |
328 } | |
329 | |
330 | |
331 uint32_t minCounterDebug = 0; | |
332 | |
333 uint32_t schedule_time_compare_helper(RTC_TimeTypeDef timeNow, RTC_DateTypeDef dateNow, RTC_TimeTypeDef timeLast, RTC_DateTypeDef dateLast) | |
334 { | |
335 uint32_t nowInSeconds; | |
336 uint32_t lastInSeconds; | |
337 uint32_t resultDiff; | |
338 | |
339 if(timeNow.Minutes != timeLast.Minutes) | |
340 minCounterDebug++; | |
341 | |
342 nowInSeconds = (uint32_t)RtcBugFixChsw(timeNow.Hours) * 3600; | |
343 nowInSeconds += (uint32_t)RtcBugFixChsw(timeNow.Minutes) * 60; | |
344 nowInSeconds += (uint32_t)RtcBugFixChsw(timeNow.Seconds); | |
345 | |
346 lastInSeconds = (uint32_t)RtcBugFixChsw(timeLast.Hours) * 3600; | |
347 lastInSeconds += (uint32_t)RtcBugFixChsw(timeLast.Minutes) * 60; | |
348 lastInSeconds += (uint32_t)RtcBugFixChsw(timeLast.Seconds); | |
349 | |
350 /* | |
351 nowInSeconds = (uint32_t)timeNow.Hours * 3600; | |
352 nowInSeconds += (uint32_t)timeNow.Minutes * 60; | |
353 nowInSeconds += (uint32_t)timeNow.Seconds; | |
354 | |
355 lastInSeconds = (uint32_t)timeLast.Hours * 3600; | |
356 lastInSeconds += (uint32_t)timeLast.Minutes * 60; | |
357 lastInSeconds += (uint32_t)timeLast.Seconds; | |
358 */ | |
359 | |
360 if(dateNow.Date != dateLast.Date) | |
361 { | |
362 resultDiff = 86400 + nowInSeconds - lastInSeconds; | |
363 } | |
364 else | |
365 { | |
366 resultDiff = nowInSeconds - lastInSeconds; | |
367 } | |
368 return resultDiff; | |
369 } | |
370 | |
371 | |
372 | |
373 /** | |
374 ****************************************************************************** | |
375 * @brief schedule_update_timer_helper. | |
376 * @author heinrichs weikamp gmbh | |
377 * @version V0.0.1 | |
378 * @date 20-Oct-2016 | |
379 * @brief use 0 for init | |
380 use -1 for RTC controlled | |
381 use >= 1 for manual control | |
382 ****************************************************************************** | |
383 */ | |
384 extern RTC_HandleTypeDef RTCHandle; | |
385 | |
386 uint16_t schedule_update_timer_helper(int8_t thisSeconds) | |
387 { | |
388 static RTC_TimeTypeDef sTimeLast; | |
389 static RTC_DateTypeDef sDateLast; | |
390 RTC_TimeTypeDef sTimeNow; | |
391 RTC_DateTypeDef sDateNow; | |
392 uint32_t secondsPast; | |
393 uint32_t tempNewValue = 0; | |
394 | |
395 HAL_RTC_GetTime(&RTCHandle, &sTimeNow, RTC_FORMAT_BCD); | |
396 HAL_RTC_GetDate(&RTCHandle, &sDateNow, RTC_FORMAT_BCD); | |
397 | |
398 if(thisSeconds != 0) // otherwise just store sTimeLast, sDateLast and return 0 | |
399 { | |
400 secondsPast = schedule_time_compare_helper(sTimeNow, sDateNow, sTimeLast, sDateLast); | |
401 | |
402 if(thisSeconds > 0) // use this value instead, good for pre-loading sTimeLast and sDateLast | |
403 { | |
404 secondsPast = thisSeconds; | |
405 } | |
406 | |
407 if(global.seconds_since_last_dive) | |
408 { | |
409 if(secondsPast >= 777900) | |
410 { | |
411 global.seconds_since_last_dive = 0; | |
412 } | |
413 else | |
414 { | |
415 tempNewValue = ((uint32_t)global.seconds_since_last_dive) + secondsPast; | |
416 if(tempNewValue > 777900) // a bit more than nine days [seconds] | |
417 global.seconds_since_last_dive = 0; | |
418 else | |
419 global.seconds_since_last_dive = (long)tempNewValue; | |
420 } | |
421 } | |
422 } | |
423 | |
424 sTimeLast = sTimeNow; | |
425 sDateLast = sDateNow; | |
426 | |
427 return tempNewValue; | |
428 } | |
429 | |
430 | |
431 | |
432 | |
433 /** | |
434 ****************************************************************************** | |
435 * @brief schedule_check_resync. | |
436 * @author heinrichs weikamp gmbh | |
437 * @version V0.0.2 | |
438 * @date 18-June-2015 | |
439 ****************************************************************************** | |
440 */ | |
441 void schedule_check_resync(void) | |
442 { | |
82 | 443 //TODO: (kittz) test for stability |
444 if((global.check_sync_not_running >= 10)) | |
38 | 445 { |
446 global.dataSendToSlaveIsNotValidCount = 0; | |
447 global.check_sync_not_running = 0; | |
448 global.sync_error_count++; | |
449 MX_SPI_DeInit(); | |
450 HAL_Delay(30); /* could be closer to length of data transmission 23.Feb.2015 hw */ | |
451 MX_DMA_Init(); | |
452 MX_SPI1_Init(); | |
453 SPI_Start_single_TxRx_with_Master(); | |
454 } | |
455 } | |
456 | |
457 | |
458 /** | |
459 ****************************************************************************** | |
460 * @brief scheduleDiveMode. / Dive Mode: Main Loop | |
461 * @author Peter Ryser | |
462 * @version V0.0.1 | |
463 * @date 22-April-2014 | |
464 ****************************************************************************** | |
465 */ | |
466 void scheduleDiveMode(void) | |
467 { | |
468 uint32_t tickstart = 0; | |
469 uint32_t ticksdiff = 0; | |
470 uint32_t lasttick = 0; | |
471 tickstart = HAL_GetTick(); | |
472 uint8_t counterPressure100msec = 0; | |
473 uint8_t counterCompass100msec = 0; | |
474 uint8_t counterAmbientLight100msec = 0; | |
475 uint16_t counterWireless1msec = 0; | |
476 // uint8_t counterDemo250msec = 0; | |
477 uint32_t turbo_seconds = 0; | |
478 uint8_t counterAscentRate = 0; | |
479 float lastPressure_bar = 0.0f; | |
480 global.dataSendToMaster.mode = MODE_DIVE; | |
481 global.deviceDataSendToMaster.mode = MODE_DIVE; | |
482 //uint16_t counterSecondsShallowDepth = 0; | |
483 uint8_t counter_exit = 0; | |
484 | |
485 tickstart = HAL_GetTick() - 1000; | |
486 | |
487 global.deviceData.diveCycles.value_int32++; | |
488 scheduleSetDate(&global.deviceData.diveCycles); | |
489 global.lifeData.counterSecondsShallowDepth = 0; | |
490 | |
491 while(global.mode == MODE_DIVE) | |
492 { | |
493 schedule_check_resync(); | |
494 lasttick = HAL_GetTick(); | |
495 ticksdiff = time_elapsed_ms(tickstart,lasttick); | |
496 | |
497 | |
498 //Evaluate wireless data every ms, if present | |
499 if(ticksdiff > counterWireless1msec) | |
500 { | |
501 counterWireless1msec++; | |
502 changeAgeWirelessData(); | |
503 global.wirelessReceived = wireless_evaluate(global.wirelessdata,MAX_WIRELESS_BYTES, &global.wirelessConfidenceStatus); | |
504 if((global.wirelessReceived > 0) && !wireless_evaluate_crc_error(global.wirelessdata,global.wirelessReceived)) | |
505 { | |
506 copyWirelessData(); | |
507 } | |
508 } | |
509 | |
510 //Evaluate pressure at 20 ms, 120 ms, 220 ms,.... | |
511 if(ticksdiff >= counterPressure100msec * 100 + 20) | |
512 { | |
513 global.check_sync_not_running++; | |
85
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
514 // pressure_update(); |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
515 // scheduleUpdateDeviceData(); |
38 | 516 if(global.demo_mode) |
517 { | |
518 turbo_seconds = demo_modify_temperature_and_pressure(global.lifeData.dive_time_seconds, counterPressure100msec, global.ceiling_from_main_CPU_mbar); | |
519 if(turbo_seconds) | |
520 { | |
521 global.lifeData.dive_time_seconds += turbo_seconds; | |
522 decom_tissues_exposure((int)(turbo_seconds), &global.lifeData); | |
523 copyTissueData(); | |
524 } | |
525 if((global.lifeData.counterSecondsShallowDepth > 1) && (global.lifeData.counterSecondsShallowDepth < (global.settings.timeoutDiveReachedZeroDepth - 10))) | |
526 global.lifeData.counterSecondsShallowDepth = (global.settings.timeoutDiveReachedZeroDepth - 10); | |
527 } | |
528 | |
529 | |
530 //Calc ascentrate every two second (20 * 100 ms) | |
531 counterAscentRate++; | |
532 if(counterAscentRate == 20) | |
533 { | |
534 global.lifeData.pressure_ambient_bar = get_pressure_mbar() / 1000.0f; | |
535 if(lastPressure_bar >= 0) | |
536 { | |
537 //2 seconds * 30 == 1 minute, bar * 10 = meter | |
538 global.lifeData.ascent_rate_meter_per_min = (lastPressure_bar - global.lifeData.pressure_ambient_bar) * 30 * 10; | |
539 } | |
540 lastPressure_bar = global.lifeData.pressure_ambient_bar; | |
541 counterAscentRate = 0; | |
542 | |
543 // if(global.demo_mode) | |
544 // global.lifeData.ascent_rate_meter_per_min /= 4; | |
545 } | |
85
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
546 // copyPressureData(); |
38 | 547 counterPressure100msec++; |
548 } | |
549 //evaluate compass data at 50 ms, 150 ms, 250 ms,.... | |
550 if(ticksdiff >= counterCompass100msec * 100 + 50) | |
551 { | |
85
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
552 // compass_read(); |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
553 // acceleration_read(); |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
554 // compass_calc(); |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
555 // copyCompassData(); |
38 | 556 counterCompass100msec++; |
557 } | |
558 | |
559 if(ticksdiff >= counterAmbientLight100msec * 100 + 70) | |
560 { | |
561 adc_ambient_light_sensor_get_data(); | |
562 copyAmbientLightData(); | |
563 counterAmbientLight100msec++; | |
564 } | |
565 | |
566 /* if(global.demo_mode && (ticksdiff >= counterDemo250msec * 250 + 10)) | |
567 { | |
568 global.lifeData.dive_time_seconds++; | |
569 copyTimeData(); | |
570 counterDemo250msec++; | |
571 } | |
572 */ | |
573 //Evaluate tissues, toxic data, vpm, etc. once a second | |
574 if(ticksdiff >= 1000) | |
575 { | |
576 if(global.dataSendToSlave.diveModeInfo != DIVEMODE_Apnea) | |
577 { | |
578 scheduleUpdateLifeData(0); // includes tissues | |
579 global.lifeData.dive_time_seconds++; // there is dive_time_seconds_without_surface_time too | |
580 global.lifeData.ppO2 = decom_calc_ppO2(global.lifeData.pressure_ambient_bar, &global.lifeData.actualGas); | |
581 decom_oxygen_calculate_cns(&global.lifeData.cns,global.lifeData.ppO2); | |
582 decom_oxygen_calculate_otu(&global.lifeData.otu,global.lifeData.ppO2); | |
85
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
583 // battery_gas_gauge_get_data(); |
38 | 584 |
585 | |
586 /** counter_exit allows safe exit via button for testing | |
587 * and demo_mode is exited too if aplicable. | |
588 */ | |
589 if(global.dataSendToMaster.mode == MODE_ENDDIVE) | |
590 { | |
591 counter_exit++; | |
592 if(counter_exit >= 2) | |
593 { | |
594 global.mode = MODE_SURFACE; | |
595 global.demo_mode = 0; | |
596 } | |
597 } | |
598 | |
599 if(is_ambient_pressure_close_to_surface(&global.lifeData)) | |
600 { | |
601 global.lifeData.counterSecondsShallowDepth++; | |
602 if((global.lifeData.counterSecondsShallowDepth >= global.settings.timeoutDiveReachedZeroDepth) || ((global.lifeData.dive_time_seconds < 60) && (global.demo_mode == 0)) || (global.dataSendToSlave.setEndDive)) | |
603 { | |
604 global.seconds_since_last_dive = 1; // start counter | |
605 schedule_update_timer_helper(0); // zum starten :-) | |
606 global.dataSendToMaster.mode = MODE_ENDDIVE; | |
607 global.deviceDataSendToMaster.mode = MODE_ENDDIVE; | |
608 } | |
609 } | |
610 else | |
611 { | |
612 global.lifeData.counterSecondsShallowDepth = 0; | |
613 global.lifeData.dive_time_seconds_without_surface_time++; | |
614 } | |
615 vpm_crush2(); | |
616 } | |
617 else // DIVEMODE_Apnea | |
618 { | |
619 global.lifeData.dive_time_seconds++; | |
620 | |
621 // exit dive mode | |
622 if(global.dataSendToMaster.mode == MODE_ENDDIVE) | |
623 { | |
624 counter_exit++; | |
625 if(counter_exit >= 2) | |
626 { | |
627 scheduleUpdateLifeData(-1); // 'restart' tissue calculations without calculating time during apnea mode | |
628 global.lifeData.dive_time_seconds = 0; // use backup noflytime and desaturation time | |
629 global.mode = MODE_SURFACE; | |
630 global.demo_mode = 0; | |
631 } | |
632 } | |
633 | |
634 // surface break | |
635 if(is_ambient_pressure_close_to_surface(&global.lifeData)) | |
636 { | |
637 global.lifeData.counterSecondsShallowDepth++; | |
638 if(global.lifeData.counterSecondsShallowDepth > 3) // time for main cpu to copy to apnea_last_dive_time_seconds | |
639 { | |
640 global.lifeData.dive_time_seconds = 0; // this apnea dive ends here | |
641 } | |
642 if((global.lifeData.counterSecondsShallowDepth >= global.settings.timeoutDiveReachedZeroDepth) || (global.dataSendToSlave.setEndDive)) | |
643 { | |
644 global.dataSendToMaster.mode = MODE_ENDDIVE; | |
645 global.deviceDataSendToMaster.mode = MODE_ENDDIVE; | |
646 } | |
647 } | |
648 else | |
649 { | |
650 global.lifeData.counterSecondsShallowDepth = 0; | |
651 global.lifeData.dive_time_seconds_without_surface_time++; | |
652 } | |
653 } // standard dive or DIVEMODE_Apnea | |
654 | |
84
e6abbef57475
Remove unusable code!!! prepare data for SPI in ONLY 1 IRQ!!!!
Dmitry Romanov <kitt@bk.ru>
parents:
82
diff
changeset
|
655 // copyVpmCrushingData(); |
e6abbef57475
Remove unusable code!!! prepare data for SPI in ONLY 1 IRQ!!!!
Dmitry Romanov <kitt@bk.ru>
parents:
82
diff
changeset
|
656 // copyTimeData(); |
e6abbef57475
Remove unusable code!!! prepare data for SPI in ONLY 1 IRQ!!!!
Dmitry Romanov <kitt@bk.ru>
parents:
82
diff
changeset
|
657 // copyCnsAndOtuData(); |
e6abbef57475
Remove unusable code!!! prepare data for SPI in ONLY 1 IRQ!!!!
Dmitry Romanov <kitt@bk.ru>
parents:
82
diff
changeset
|
658 // copyBatteryData(); |
38 | 659 |
85
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
660 // // new hw 170523 |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
661 // if(global.I2C_SystemStatus != HAL_OK) |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
662 // { |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
663 // MX_I2C1_TestAndClear(); |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
664 // MX_I2C1_Init(); |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
665 // if(!is_init_pressure_done()) |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
666 // { |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
667 // init_pressure(); |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
668 // } |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
669 // } |
38 | 670 |
671 counterCompass100msec = 0; | |
672 counterPressure100msec = 0; | |
673 counterAmbientLight100msec = 0; | |
674 counterWireless1msec = 0; | |
675 // counterDemo250msec = 0; | |
676 | |
677 /** keep it in rhythm, do not drop the execution time | |
678 * therefore do not use tickstart = HAL_GetTick(); | |
679 * here | |
680 */ | |
681 tickstart += 1000; | |
682 } | |
683 } | |
684 } | |
685 | |
686 | |
687 /** | |
688 ****************************************************************************** | |
689 * @brief scheduleSurfaceMode / surface mode: Main Loop | |
690 * @author Peter Ryser | |
691 * @version V0.0.1 | |
692 * @date 22-April-2014 | |
693 ****************************************************************************** | |
694 */ | |
695 | |
696 | |
697 // =============================================================================== | |
698 // scheduleTestMode | |
699 /// @brief included for sealed hardware with permanent RTE update message | |
700 // =============================================================================== | |
701 void scheduleTestMode(void) | |
702 { | |
703 uint32_t tickstart = 0; | |
704 uint32_t ticksdiff = 0; | |
705 uint32_t lasttick = 0; | |
706 tickstart = HAL_GetTick(); | |
707 | |
708 uint8_t counterPressure100msec = 0; | |
709 | |
710 float temperature_carousel = 0.0f; | |
711 float temperature_changer = 0.1f; | |
712 | |
713 while(global.mode == MODE_TEST) | |
714 { | |
715 schedule_check_resync(); | |
716 lasttick = HAL_GetTick(); | |
717 ticksdiff = time_elapsed_ms(tickstart,lasttick); | |
718 | |
719 //Evaluate pressure at 20 ms, 120 ms, 220 ms,... | |
720 if(ticksdiff >= counterPressure100msec * 100 + 20) | |
721 { | |
722 global.check_sync_not_running++; | |
723 | |
85
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
724 //pressure_update(); |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
725 //scheduleUpdateDeviceData(); |
38 | 726 global.lifeData.ascent_rate_meter_per_min = 0; |
85
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
727 //copyPressureData(); |
38 | 728 |
729 if(temperature_carousel > 20.0f) | |
730 { | |
731 temperature_carousel = 20.0f; | |
732 temperature_changer = -0.1f; | |
733 } | |
734 else | |
735 if(temperature_carousel < 0) | |
736 { | |
737 temperature_carousel = 0; | |
738 temperature_changer = +0.1f; | |
739 } | |
740 | |
741 temperature_carousel += temperature_changer; | |
742 | |
743 uint8_t boolPressureData = !global.dataSendToMaster.boolPressureData; | |
744 | |
745 global.dataSendToMaster.data[boolPressureData].pressure_mbar = get_pressure_mbar(); | |
746 | |
747 global.dataSendToMaster.data[boolPressureData].temperature = temperature_carousel; | |
748 global.dataSendToMaster.data[boolPressureData].pressure_uTick = HAL_GetTick(); | |
749 global.dataSendToMaster.boolPressureData = boolPressureData; | |
750 | |
751 | |
752 counterPressure100msec++; | |
753 } | |
754 | |
755 if(ticksdiff >= 1000) | |
756 { | |
757 //Set back tick counter | |
758 tickstart = HAL_GetTick(); | |
759 counterPressure100msec = 0; | |
760 } | |
761 }; | |
762 } | |
763 | |
764 | |
765 void scheduleSurfaceMode(void) | |
766 { | |
767 uint32_t tickstart = 0; | |
768 uint32_t ticksdiff = 0; | |
769 uint32_t lasttick = 0; | |
770 tickstart = HAL_GetTick(); | |
771 uint8_t counterPressure100msec = 0; | |
772 uint8_t counterCompass100msec = 0; | |
773 uint8_t counterAmbientLight100msec = 0; | |
774 uint16_t counterWireless1msec = 0; | |
775 global.dataSendToMaster.mode = MODE_SURFACE; | |
776 global.deviceDataSendToMaster.mode = MODE_SURFACE; | |
777 | |
778 while(global.mode == MODE_SURFACE) | |
779 { | |
780 printf("surface...\n"); | |
781 | |
782 schedule_check_resync(); | |
783 lasttick = HAL_GetTick(); | |
784 ticksdiff = time_elapsed_ms(tickstart,lasttick); | |
785 | |
786 if(ticksdiff > counterWireless1msec) | |
787 { | |
788 counterWireless1msec++; | |
789 changeAgeWirelessData(); | |
790 global.wirelessReceived = wireless_evaluate(global.wirelessdata,MAX_WIRELESS_BYTES, &global.wirelessConfidenceStatus); | |
791 if((global.wirelessReceived > 0) && !wireless_evaluate_crc_error(global.wirelessdata,global.wirelessReceived)) | |
792 { | |
793 copyWirelessData(); | |
794 } | |
795 } | |
796 if(setButtonsNow == 1) | |
797 { | |
798 if(scheduleSetButtonResponsiveness()) | |
799 setButtonsNow = 0; | |
800 } | |
801 | |
802 //Evaluate pressure at 20 ms, 120 ms, 220 ms,... | |
803 if(ticksdiff >= counterPressure100msec * 100 + 20) | |
804 { | |
805 global.check_sync_not_running++; | |
85
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
806 // pressure_update(); |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
807 // scheduleUpdateDeviceData(); |
38 | 808 global.lifeData.ascent_rate_meter_per_min = 0; |
85
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
809 // copyPressureData(); |
38 | 810 counterPressure100msec++; |
811 | |
812 if(scheduleCheck_pressure_reached_dive_mode_level()) | |
813 global.mode = MODE_DIVE; | |
814 } | |
815 | |
816 //evaluate compass data at 50 ms, 150 ms, 250 ms,... | |
817 | |
818 if(ticksdiff >= counterCompass100msec * 100 + 50) | |
819 { | |
85
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
820 // compass_read(); |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
821 // acceleration_read(); |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
822 // compass_calc(); |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
823 // copyCompassData(); |
38 | 824 counterCompass100msec++; |
825 } | |
826 | |
827 //evaluate compass data at 70 ms, 170 ms, 270 ms,... | |
828 if(ticksdiff >= counterAmbientLight100msec * 100 + 70) | |
829 { | |
830 adc_ambient_light_sensor_get_data(); | |
831 copyAmbientLightData(); | |
832 counterAmbientLight100msec++; | |
833 } | |
834 //Evaluate tissues, toxic data, etc. once a second | |
835 if(ticksdiff >= 1000) | |
836 { | |
837 if(clearDecoNow) | |
838 { | |
839 decom_reset_with_1000mbar(&global.lifeData); ///< this should almost reset desaturation time | |
840 // new 160215 hw | |
841 global.repetitive_dive = 0; | |
842 global.seconds_since_last_dive = 0; ///< this will reset OTU and CNS as well | |
843 global.no_fly_time_minutes = 0; | |
844 global.accidentFlag = 0; | |
845 global.accidentRemainingSeconds = 0; | |
846 vpm_init(&global.vpm, global.conservatism, global.repetitive_dive, global.seconds_since_last_dive); | |
847 clearDecoNow = 0; | |
848 } | |
849 | |
850 //Set back tick counter | |
851 tickstart = HAL_GetTick(); | |
852 | |
853 | |
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 } | |
861 | |
862 if(global.accidentRemainingSeconds) | |
863 { | |
864 global.accidentRemainingSeconds--; | |
865 if(!global.accidentRemainingSeconds) | |
866 global.accidentFlag = 0; | |
867 } | |
868 global.dataSendToMaster.accidentFlags = global.accidentFlag; | |
869 | |
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); | |
874 global.lifeData.desaturation_time_minutes = decom_calc_desaturation_time(global.lifeData.tissue_nitrogen_bar,global.lifeData.tissue_helium_bar,global.lifeData.pressure_surface_bar); | |
875 battery_charger_get_status_and_contral_battery_gas_gauge(0); | |
85
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
876 // battery_gas_gauge_get_data(); |
38 | 877 |
84
e6abbef57475
Remove unusable code!!! prepare data for SPI in ONLY 1 IRQ!!!!
Dmitry Romanov <kitt@bk.ru>
parents:
82
diff
changeset
|
878 // copyCnsAndOtuData(); |
e6abbef57475
Remove unusable code!!! prepare data for SPI in ONLY 1 IRQ!!!!
Dmitry Romanov <kitt@bk.ru>
parents:
82
diff
changeset
|
879 // copyTimeData(); |
e6abbef57475
Remove unusable code!!! prepare data for SPI in ONLY 1 IRQ!!!!
Dmitry Romanov <kitt@bk.ru>
parents:
82
diff
changeset
|
880 // copyBatteryData(); |
e6abbef57475
Remove unusable code!!! prepare data for SPI in ONLY 1 IRQ!!!!
Dmitry Romanov <kitt@bk.ru>
parents:
82
diff
changeset
|
881 // copyDeviceData(); |
38 | 882 |
85
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
883 // // new hw 170523 |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
884 // if(global.I2C_SystemStatus != HAL_OK) |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
885 // { |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
886 // MX_I2C1_TestAndClear(); |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
887 // MX_I2C1_Init(); |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
888 // if(!is_init_pressure_done()) |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
889 // { |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
890 // init_pressure(); |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
891 // } |
923c4566a2a1
increased interCPU baudrate, cpu2: i2c in SPI1 IRQ
Dmitry Romanov <kitt@bk.ru>
parents:
84
diff
changeset
|
892 // } |
38 | 893 |
894 counterCompass100msec = 0; | |
895 counterPressure100msec = 0; | |
896 counterAmbientLight100msec = 0; | |
897 counterWireless1msec = 0; | |
898 } | |
899 } | |
900 } | |
901 | |
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 // global.seconds_since_last_dive += 60; | |
922 // if(global.seconds_since_last_dive > 777900) // a bit more than nine days [seconds] | |
923 // global.seconds_since_last_dive = 0; | |
924 } | |
925 | |
926 scheduleUpdateLifeData(0); | |
927 global.mode = MODE_SURFACE; | |
928 } | |
929 | |
930 | |
931 /** | |
932 ****************************************************************************** | |
933 * @brief scheduleSleepMode / sleep mode: Main Loop | |
934 * @author heinrichs weikamp gmbh | |
935 * @version V0.0.2 | |
936 * @since 31-March-2015 | |
937 * @date 22-April-2014 | |
938 ****************************************************************************** | |
939 */ | |
940 | |
941 void scheduleSleepMode(void) | |
942 { | |
943 global.dataSendToMaster.mode = 0; | |
944 global.deviceDataSendToMaster.mode = 0; | |
945 | |
946 /* prevent button wake up problem while in sleep_prepare | |
947 * sleep prepare does I2C_DeInit() | |
948 */ | |
949 if(global.mode != MODE_SLEEP) | |
950 MX_I2C1_Init(); | |
951 else | |
952 do | |
953 { | |
954 I2C_DeInit(); | |
955 | |
956 #ifdef DEBUGMODE | |
957 HAL_Delay(2000); | |
958 #else | |
959 RTC_StopMode_2seconds(); | |
960 #endif | |
961 | |
962 | |
963 | |
964 if(global.mode == MODE_SLEEP) | |
965 secondsCount += 2; | |
966 | |
967 MX_I2C1_Init(); | |
968 pressure_sensor_get_pressure_raw(); | |
969 | |
970 if(secondsCount >= 30) | |
971 { | |
972 pressure_sensor_get_temperature_raw(); | |
973 battery_gas_gauge_get_data(); | |
974 // ReInit_battery_charger_status_pins(); | |
975 battery_charger_get_status_and_contral_battery_gas_gauge(1); | |
976 // DeInit_battery_charger_status_pins(); | |
977 secondsCount = 0; | |
978 } | |
979 | |
980 pressure_calculation(); | |
981 | |
982 scheduleUpdateDeviceData(); | |
983 update_surface_pressure(2); | |
984 | |
985 if(global.seconds_since_last_dive) | |
986 { | |
987 schedule_update_timer_helper(-1); | |
988 // global.seconds_since_last_dive += 2; | |
989 // if(global.seconds_since_last_dive > 777900) // a bit more than nine days [seconds] | |
990 // global.seconds_since_last_dive = 0; | |
991 } | |
992 | |
993 if(global.accidentRemainingSeconds) | |
994 { | |
995 if(global.accidentRemainingSeconds > 2) | |
996 global.accidentRemainingSeconds -= 2; | |
997 else | |
998 { | |
999 global.accidentRemainingSeconds = 0; | |
1000 global.accidentFlag = 0; | |
1001 } | |
1002 } | |
1003 | |
1004 if(scheduleCheck_pressure_reached_dive_mode_level()) | |
1005 global.mode = MODE_BOOT; | |
1006 | |
1007 scheduleUpdateLifeData(2000); | |
1008 } | |
1009 while(global.mode == MODE_SLEEP); | |
1010 /* new section for system after Standby */ | |
1011 scheduleUpdateLifeData(-1); | |
1012 clearDecoNow = 0; | |
1013 setButtonsNow = 0; | |
1014 } | |
1015 | |
1016 | |
1017 | |
1018 /* Private functions ---------------------------------------------------------*/ | |
1019 | |
1020 | |
1021 /** | |
1022 ****************************************************************************** | |
1023 * @brief scheduleCheck_pressure_reached_dive_mode_level | |
1024 * @author heinrichs weikamp gmbh | |
1025 * @version V0.0.1 from inline code | |
1026 * @date 09-Sept-2015 | |
1027 ****************************************************************************** | |
1028 */ | |
1029 _Bool scheduleCheck_pressure_reached_dive_mode_level(void) | |
1030 { | |
1031 if(get_pressure_mbar() > 1160) | |
1032 return 1; | |
1033 else | |
1034 if((global.mode == MODE_SURFACE) && (get_pressure_mbar() > (get_surface_mbar() + 100)) && (get_surface_mbar() > 880)) | |
1035 return 1; | |
1036 else | |
1037 return 0; | |
1038 } | |
1039 | |
1040 | |
1041 /** | |
1042 ****************************************************************************** | |
1043 * @brief scheduleUpdateLifeData / calculates tissues | |
1044 * @author Peter Ryser | |
1045 * @version V0.0.1 | |
1046 * @date 22-April-2014 | |
1047 ****************************************************************************** | |
1048 */ | |
1049 | |
1050 | |
1051 void scheduleUpdateLifeData(int32_t asynchron_milliseconds_since_last) | |
1052 { | |
1053 static _Bool first = 1; | |
1054 static uint32_t tickstart = 0; | |
1055 static uint32_t ticksrest = 0; | |
1056 | |
1057 uint32_t ticksdiff = 0; | |
1058 uint32_t ticksnow = 0; | |
1059 uint32_t time_seconds = 0; | |
1060 uint8_t whichGasTmp = 0; | |
1061 | |
1062 if(asynchron_milliseconds_since_last < 0) | |
1063 { | |
1064 first = 1; | |
1065 tickstart = 0; | |
1066 ticksrest = 0; | |
1067 return; | |
1068 } | |
1069 | |
1070 if(!asynchron_milliseconds_since_last && first) | |
1071 { | |
1072 tickstart = HAL_GetTick(); | |
1073 first = 0; | |
1074 return; | |
1075 } | |
1076 | |
1077 whichGasTmp = global.whichGas; | |
1078 global.lifeData.actualGas = global.aktualGas[whichGasTmp]; | |
1079 global.lifeData.pressure_ambient_bar = get_pressure_mbar() / 1000.0f; | |
1080 global.lifeData.pressure_surface_bar = get_surface_mbar() / 1000.0f; | |
1081 | |
1082 if(!asynchron_milliseconds_since_last) | |
1083 { | |
1084 ticksnow = HAL_GetTick(); | |
1085 ticksdiff = time_elapsed_ms(tickstart,ticksnow); | |
1086 } | |
1087 else | |
1088 { | |
1089 first = 1; | |
1090 ticksdiff = asynchron_milliseconds_since_last; | |
1091 } | |
1092 | |
1093 if(ticksrest > 1000) // whatever happens after standby with STM32L476 | |
1094 ticksrest = 0; // maybe move static to SRAM2 | |
1095 | |
1096 ticksdiff += ticksrest; | |
1097 time_seconds = ticksdiff/ 1000; | |
1098 ticksrest = ticksdiff - time_seconds * 1000; | |
1099 tickstart = ticksnow; | |
1100 | |
1101 decom_tissues_exposure((int)time_seconds, &global.lifeData); | |
1102 if(global.demo_mode) | |
1103 decom_tissues_exposure((int)(3*time_seconds), &global.lifeData); | |
1104 copyTissueData(); | |
1105 } | |
1106 | |
1107 | |
1108 /** | |
1109 ****************************************************************************** | |
1110 * @brief scheduleUpdateDeviceData | |
1111 * @author heinrichs weikamp gmbh | |
1112 * @version V0.0.1 | |
1113 * @date 16-March-2015 | |
1114 * | |
1115 * two step process | |
1116 * first compare with data from main CPU == externalLogbookFlash | |
1117 * second update with new sensor data | |
1118 ****************************************************************************** | |
1119 */ | |
1120 void scheduleSetDate(SDeviceLine *line) | |
1121 { | |
1122 extern RTC_HandleTypeDef RTCHandle; | |
1123 | |
1124 line->date_rtc_dr = (uint32_t)(RTCHandle.Instance->DR & RTC_DR_RESERVED_MASK); | |
1125 line->time_rtc_tr = (uint32_t)(RTCHandle.Instance->TR & RTC_TR_RESERVED_MASK); | |
1126 } | |
1127 | |
1128 | |
1129 void scheduleCopyDeviceData(SDeviceLine *lineWrite, const SDeviceLine *lineRead) | |
1130 { | |
1131 lineWrite->date_rtc_dr = lineRead->date_rtc_dr; | |
1132 lineWrite->time_rtc_tr = lineRead->time_rtc_tr; | |
1133 lineWrite->value_int32 = lineRead->value_int32; | |
1134 } | |
1135 | |
1136 | |
1137 void scheduleUpdateDeviceData(void) | |
1138 { | |
1139 /* first step, main CPU */ | |
1140 | |
1141 if(deviceDataFlashValid) | |
1142 { | |
1143 /* max values */ | |
1144 if(global.deviceData.batteryChargeCompleteCycles.value_int32 < DeviceDataFlash.batteryChargeCompleteCycles.value_int32) | |
1145 { | |
1146 scheduleCopyDeviceData(&global.deviceData.batteryChargeCompleteCycles, &DeviceDataFlash.batteryChargeCompleteCycles); | |
1147 } | |
1148 if(global.deviceData.batteryChargeCycles.value_int32 < DeviceDataFlash.batteryChargeCycles.value_int32) | |
1149 { | |
1150 scheduleCopyDeviceData(&global.deviceData.batteryChargeCycles, &DeviceDataFlash.batteryChargeCycles); | |
1151 } | |
1152 if(global.deviceData.temperatureMaximum.value_int32 < DeviceDataFlash.temperatureMaximum.value_int32) | |
1153 { | |
1154 scheduleCopyDeviceData(&global.deviceData.temperatureMaximum, &DeviceDataFlash.temperatureMaximum); | |
1155 } | |
1156 if(global.deviceData.depthMaximum.value_int32 < DeviceDataFlash.depthMaximum.value_int32) | |
1157 { | |
1158 scheduleCopyDeviceData(&global.deviceData.depthMaximum, &DeviceDataFlash.depthMaximum); | |
1159 } | |
1160 if(global.deviceData.diveCycles.value_int32 < DeviceDataFlash.diveCycles.value_int32) | |
1161 { | |
1162 scheduleCopyDeviceData(&global.deviceData.diveCycles, &DeviceDataFlash.diveCycles); | |
1163 } | |
1164 if(global.deviceData.hoursOfOperation.value_int32 < DeviceDataFlash.hoursOfOperation.value_int32) | |
1165 { | |
1166 scheduleCopyDeviceData(&global.deviceData.hoursOfOperation, &DeviceDataFlash.hoursOfOperation); | |
1167 } | |
1168 | |
1169 /* min values */ | |
1170 if(global.deviceData.temperatureMinimum.value_int32 > DeviceDataFlash.temperatureMinimum.value_int32) | |
1171 { | |
1172 scheduleCopyDeviceData(&global.deviceData.temperatureMinimum, &DeviceDataFlash.temperatureMinimum); | |
1173 } | |
1174 if(global.deviceData.voltageMinimum.value_int32 > DeviceDataFlash.voltageMinimum.value_int32) | |
1175 { | |
1176 scheduleCopyDeviceData(&global.deviceData.voltageMinimum, &DeviceDataFlash.voltageMinimum); | |
1177 } | |
1178 } | |
1179 | |
1180 /* second step, sensor data */ | |
1181 int32_t temperature_centigrad_int32; | |
1182 int32_t pressure_mbar_int32; | |
1183 int32_t voltage_mvolt_int32; | |
1184 | |
1185 temperature_centigrad_int32 = (int32_t)(get_temperature() * 100); | |
1186 if(temperature_centigrad_int32 < global.deviceData.temperatureMinimum.value_int32) | |
1187 { | |
1188 global.deviceData.temperatureMinimum.value_int32 = temperature_centigrad_int32; | |
87 | 1189 /*Last_change_time?*/ scheduleSetDate(&global.deviceData.temperatureMinimum); |
38 | 1190 } |
1191 | |
1192 if(temperature_centigrad_int32 > global.deviceData.temperatureMaximum.value_int32) | |
1193 { | |
1194 global.deviceData.temperatureMaximum.value_int32 = temperature_centigrad_int32; | |
87 | 1195 /*Last_change_time?*/ scheduleSetDate(&global.deviceData.temperatureMaximum); |
38 | 1196 } |
1197 | |
1198 pressure_mbar_int32 = (int32_t)get_pressure_mbar(); | |
1199 if(pressure_mbar_int32 > global.deviceData.depthMaximum.value_int32) | |
1200 { | |
1201 global.deviceData.depthMaximum.value_int32 = pressure_mbar_int32; | |
87 | 1202 /*Last_change_time?*/ scheduleSetDate(&global.deviceData.depthMaximum); |
38 | 1203 } |
1204 | |
1205 voltage_mvolt_int32 = (int32_t)(get_voltage() * 1000); | |
1206 if(voltage_mvolt_int32 < global.deviceData.voltageMinimum.value_int32) | |
1207 { | |
1208 global.deviceData.voltageMinimum.value_int32 = voltage_mvolt_int32; | |
87 | 1209 /*Last_change_time?*/ scheduleSetDate(&global.deviceData.voltageMinimum); |
38 | 1210 } |
1211 | |
1212 /* third step, counter */ | |
1213 switch (global.mode) | |
1214 { | |
1215 case MODE_SURFACE: | |
1216 case MODE_DIVE: | |
1217 default: | |
1218 deviceDataSubSeconds++; | |
1219 if(deviceDataSubSeconds > 10) | |
1220 { | |
1221 deviceDataSubSeconds = 0; | |
1222 global.deviceData.hoursOfOperation.value_int32++; | |
1223 } | |
1224 break; | |
1225 | |
1226 case MODE_SLEEP: | |
1227 case MODE_SHUTDOWN: | |
1228 break; | |
1229 } | |
1230 } | |
1231 | |
1232 | |
1233 void scheduleUpdateDeviceDataChargerFull(void) | |
1234 { | |
1235 global.deviceData.batteryChargeCompleteCycles.value_int32++; | |
87 | 1236 /*Last_change_time?*/ scheduleSetDate(&global.deviceData.batteryChargeCompleteCycles); |
38 | 1237 } |
1238 | |
1239 | |
1240 void scheduleUpdateDeviceDataChargerCharging(void) | |
1241 { | |
1242 global.deviceData.batteryChargeCycles.value_int32++; | |
87 | 1243 /*Last_change_time?*/ scheduleSetDate(&global.deviceData.batteryChargeCycles); |
38 | 1244 } |
1245 | |
1246 | |
1247 /** | |
1248 ****************************************************************************** | |
1249 * @brief vpm_crush / calls vpm calc_crushing_pressure every four seconds during descend | |
1250 * @author Peter Ryser | |
1251 * @version V0.0.1 | |
1252 * @date 22-April-2014 | |
1253 ****************************************************************************** | |
1254 */ | |
1255 _Bool vpm_crush2(void) | |
1256 { | |
1257 int i = 0; | |
1258 static float starting_ambient_pressure = 0; | |
1259 static float ending_ambient_pressure = 0; | |
1260 static float time_calc_begin = -1; | |
1261 static float initial_helium_pressure[16]; | |
1262 static float initial_nitrogen_pressure[16]; | |
1263 ending_ambient_pressure = global.lifeData.pressure_ambient_bar * 10; | |
1264 | |
1265 if((global.lifeData.dive_time_seconds <= 4) || (starting_ambient_pressure >= ending_ambient_pressure)) | |
1266 { | |
1267 time_calc_begin = global.lifeData.dive_time_seconds; | |
1268 starting_ambient_pressure = global.lifeData.pressure_ambient_bar * 10; | |
1269 for( i = 0; i < 16; i++) | |
1270 { | |
1271 initial_helium_pressure[i] = global.lifeData.tissue_helium_bar[i] * 10; | |
1272 initial_nitrogen_pressure[i] = global.lifeData.tissue_nitrogen_bar[i] * 10; | |
1273 } | |
1274 return 0; | |
1275 } | |
1276 if(global.lifeData.dive_time_seconds - time_calc_begin >= 4) | |
1277 { | |
1278 if(ending_ambient_pressure > starting_ambient_pressure + 0.5f) | |
1279 { | |
1280 float rate = (ending_ambient_pressure - starting_ambient_pressure) * 60 / 4; | |
1281 calc_crushing_pressure(&global.lifeData, &global.vpm, initial_helium_pressure, initial_nitrogen_pressure, starting_ambient_pressure, rate); | |
1282 | |
1283 time_calc_begin = global.lifeData.dive_time_seconds; | |
1284 starting_ambient_pressure = global.lifeData.pressure_ambient_bar * 10; | |
1285 for( i = 0; i < 16; i++) | |
1286 { | |
1287 initial_helium_pressure[i] = global.lifeData.tissue_helium_bar[i] * 10; | |
1288 initial_nitrogen_pressure[i] = global.lifeData.tissue_nitrogen_bar[i] * 10; | |
1289 } | |
1290 | |
1291 return 1; | |
1292 } | |
1293 | |
1294 } | |
1295 return 0; | |
1296 }; | |
1297 | |
1298 | |
1299 void initStructWithZeero(uint8_t* data, uint16_t length) | |
1300 { | |
1301 for(uint16_t i = 0; i < length; i++) | |
1302 data[i] = 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 void changeAgeWirelessData(void) | |
1483 { | |
1484 for(int i=0;i<4;i++) | |
1485 { | |
1486 if(global.dataSendToMaster.data[global.dataSendToMaster.boolWirelessData].wireless_data[i].ageInMilliSeconds) | |
1487 global.dataSendToMaster.data[global.dataSendToMaster.boolWirelessData].wireless_data[i].ageInMilliSeconds++; | |
1488 } | |
1489 } | |
1490 | |
1491 void copyWirelessData(void) | |
1492 { | |
1493 uint8_t boolWirelessData = !global.dataSendToMaster.boolWirelessData; | |
1494 SDataWireless *dataOld, *dataNew; | |
1495 for(int i=0;i<3;i++) | |
1496 { | |
1497 dataNew = &global.dataSendToMaster.data[boolWirelessData].wireless_data[i+1]; | |
1498 dataOld = &global.dataSendToMaster.data[!boolWirelessData].wireless_data[i]; | |
1499 dataNew->ageInMilliSeconds = dataOld->ageInMilliSeconds; | |
1500 dataNew->numberOfBytes = dataOld->numberOfBytes; | |
1501 dataNew->status = dataOld->status; | |
1502 memcpy(dataNew->data, dataOld->data,8); | |
1503 } | |
1504 | |
1505 global.dataSendToMaster.data[boolWirelessData].wireless_data[0].ageInMilliSeconds = 1; | |
1506 global.dataSendToMaster.data[boolWirelessData].wireless_data[0].numberOfBytes = global.wirelessReceived; | |
1507 global.dataSendToMaster.data[boolWirelessData].wireless_data[0].status = global.wirelessConfidenceStatus; | |
1508 for(int i=0;i<MAX_WIRELESS_BYTES;i++) | |
1509 global.dataSendToMaster.data[boolWirelessData].wireless_data[0].data[i] = global.wirelessdata[i]; | |
1510 for(int i=MAX_WIRELESS_BYTES;i<12;i++) | |
1511 global.dataSendToMaster.data[boolWirelessData].wireless_data[0].data[i] = 0xFF; | |
1512 | |
1513 global.dataSendToMaster.boolWirelessData = boolWirelessData; | |
1514 } | |
1515 | |
1516 /* copyPICdata(); is used in spi.c */ | |
1517 void copyPICdata(void) | |
1518 { | |
1519 uint8_t boolPICdata = !global.dataSendToMaster.boolPICdata; | |
1520 for(int i = 0; i < 3; i++) | |
1521 { | |
1522 global.dataSendToMaster.data[boolPICdata].button_setting[i] = global.ButtonPICdata[i]; | |
1523 } | |
1524 global.dataSendToMaster.boolPICdata = boolPICdata; | |
1525 } | |
1526 | |
1527 | |
1528 | |
1529 | |
1530 typedef enum | |
1531 { | |
1532 SPI3_OK = 0x00, | |
1533 SPI3_DEINIT = 0x01, | |
1534 } SPI3_StatusTypeDef; | |
1535 /* if spi3 is running and the SPI3_ButtonAdjust call returns OK, all is fine | |
1536 if the SPI3_ButtonAdjust call returns error, the spi3 is DeInit | |
1537 and will be init the next call of scheduleSetButtonResponsiveness() | |
1538 and data will be send again on the third call | |
1539 therefore on return 0 of scheduleSetButtonResponsiveness() the caller flag should kept active | |
1540 */ | |
1541 uint8_t scheduleSetButtonResponsiveness(void) | |
1542 { | |
1543 static uint8_t SPI3status = SPI3_OK; | |
1544 | |
1545 if((SPI3status == SPI3_OK) && (SPI3_ButtonAdjust(global.ButtonResponsiveness, global.ButtonPICdata))) | |
1546 { | |
1547 copyPICdata(); | |
1548 return 1; | |
1549 } | |
1550 else | |
1551 { | |
1552 for(int i=0;i<3;i++) | |
1553 { | |
1554 global.ButtonPICdata[i] = 0xFF; | |
1555 } | |
1556 copyPICdata(); | |
1557 | |
1558 if(SPI3status == SPI3_OK) | |
1559 { | |
1560 MX_SPI3_DeInit(); | |
1561 SPI3status = SPI3_DEINIT; | |
1562 } | |
1563 else | |
1564 { | |
1565 MX_SPI3_Init(); | |
1566 SPI3status = SPI3_OK; | |
1567 } | |
1568 return 0; | |
1569 } | |
1570 } | |
1571 | |
1572 | |
1573 //save time diffenrence | |
1574 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow) | |
1575 { | |
1576 if(ticksstart <= ticksnow) | |
1577 { | |
1578 return ticksnow - ticksstart; | |
1579 } | |
1580 else | |
1581 { | |
1582 return 0xFFFFFFFF - ticksstart + ticksnow; | |
1583 } | |
1584 } | |
1585 | |
1586 /* same as in data_central.c */ | |
1587 _Bool is_ambient_pressure_close_to_surface(SLifeData *lifeDataCall) | |
1588 { | |
1589 if(lifeDataCall->pressure_ambient_bar < (lifeDataCall->pressure_surface_bar + 0.1f)) // hw 161121 now 1 mter, before 0.04f | |
1590 return true; | |
1591 else | |
1592 return false; | |
1593 } | |
1594 | |
1595 | |
1596 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ | |
1597 |