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