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