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