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