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