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