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