Mercurial > public > ostc4
annotate Small_CPU/Src/scheduler.c @ 227:d5891007fc4c
add update files for testing purposes
author | heinrichsweikamp |
---|---|
date | Tue, 02 Apr 2019 18:18:22 +0200 |
parents | e524a824d8f2 |
children | 3973208c4a20 |
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; | |
461 uint8_t counterAscentRate = 0; | |
462 float lastPressure_bar = 0.0f; | |
463 global.dataSendToMaster.mode = MODE_DIVE; | |
464 global.deviceDataSendToMaster.mode = MODE_DIVE; | |
465 //uint16_t counterSecondsShallowDepth = 0; | |
466 uint8_t counter_exit = 0; | |
467 | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
468 Scheduler.tickstart = HAL_GetTick() - 1000; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
469 Scheduler.counterSPIdata100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
470 Scheduler.counterCompass100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
471 Scheduler.counterPressure100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
472 Scheduler.counterAmbientLight100msec = 0; |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
473 Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC; |
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 | |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
545 //Evaluate tissues, toxic data, vpm, etc. once a second |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
546 if(ticksdiff >= Scheduler.tick_execute1second) |
38 | 547 { |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
548 Scheduler.tick_execute1second = 0xFFFFFFFF; /* execute once only in the second cycle */ |
38 | 549 if(global.dataSendToSlave.diveModeInfo != DIVEMODE_Apnea) |
550 { | |
551 scheduleUpdateLifeData(0); // includes tissues | |
552 global.lifeData.dive_time_seconds++; // there is dive_time_seconds_without_surface_time too | |
553 global.lifeData.ppO2 = decom_calc_ppO2(global.lifeData.pressure_ambient_bar, &global.lifeData.actualGas); | |
554 decom_oxygen_calculate_cns(&global.lifeData.cns,global.lifeData.ppO2); | |
555 decom_oxygen_calculate_otu(&global.lifeData.otu,global.lifeData.ppO2); | |
88 | 556 battery_gas_gauge_get_data(); |
38 | 557 |
558 | |
559 /** counter_exit allows safe exit via button for testing | |
560 * and demo_mode is exited too if aplicable. | |
561 */ | |
562 if(global.dataSendToMaster.mode == MODE_ENDDIVE) | |
563 { | |
564 counter_exit++; | |
565 if(counter_exit >= 2) | |
566 { | |
567 global.mode = MODE_SURFACE; | |
568 global.demo_mode = 0; | |
569 } | |
570 } | |
571 | |
572 if(is_ambient_pressure_close_to_surface(&global.lifeData)) | |
573 { | |
574 global.lifeData.counterSecondsShallowDepth++; | |
575 if((global.lifeData.counterSecondsShallowDepth >= global.settings.timeoutDiveReachedZeroDepth) || ((global.lifeData.dive_time_seconds < 60) && (global.demo_mode == 0)) || (global.dataSendToSlave.setEndDive)) | |
576 { | |
577 global.seconds_since_last_dive = 1; // start counter | |
578 schedule_update_timer_helper(0); // zum starten :-) | |
579 global.dataSendToMaster.mode = MODE_ENDDIVE; | |
580 global.deviceDataSendToMaster.mode = MODE_ENDDIVE; | |
581 } | |
582 } | |
583 else | |
584 { | |
585 global.lifeData.counterSecondsShallowDepth = 0; | |
586 global.lifeData.dive_time_seconds_without_surface_time++; | |
587 } | |
588 vpm_crush2(); | |
589 } | |
590 else // DIVEMODE_Apnea | |
591 { | |
592 global.lifeData.dive_time_seconds++; | |
593 | |
594 // exit dive mode | |
595 if(global.dataSendToMaster.mode == MODE_ENDDIVE) | |
596 { | |
597 counter_exit++; | |
598 if(counter_exit >= 2) | |
599 { | |
600 scheduleUpdateLifeData(-1); // 'restart' tissue calculations without calculating time during apnea mode | |
601 global.lifeData.dive_time_seconds = 0; // use backup noflytime and desaturation time | |
602 global.mode = MODE_SURFACE; | |
603 global.demo_mode = 0; | |
604 } | |
605 } | |
606 | |
607 // surface break | |
608 if(is_ambient_pressure_close_to_surface(&global.lifeData)) | |
609 { | |
610 global.lifeData.counterSecondsShallowDepth++; | |
611 if(global.lifeData.counterSecondsShallowDepth > 3) // time for main cpu to copy to apnea_last_dive_time_seconds | |
612 { | |
613 global.lifeData.dive_time_seconds = 0; // this apnea dive ends here | |
614 } | |
615 if((global.lifeData.counterSecondsShallowDepth >= global.settings.timeoutDiveReachedZeroDepth) || (global.dataSendToSlave.setEndDive)) | |
616 { | |
617 global.dataSendToMaster.mode = MODE_ENDDIVE; | |
618 global.deviceDataSendToMaster.mode = MODE_ENDDIVE; | |
619 } | |
620 } | |
621 else | |
622 { | |
623 global.lifeData.counterSecondsShallowDepth = 0; | |
624 global.lifeData.dive_time_seconds_without_surface_time++; | |
625 } | |
626 } // standard dive or DIVEMODE_Apnea | |
627 | |
88 | 628 copyVpmCrushingData(); |
629 copyTimeData(); | |
630 copyCnsAndOtuData(); | |
631 copyBatteryData(); | |
38 | 632 |
88 | 633 // new hw 170523 |
634 if(global.I2C_SystemStatus != HAL_OK) | |
635 { | |
636 MX_I2C1_TestAndClear(); | |
637 MX_I2C1_Init(); | |
638 if(!is_init_pressure_done()) | |
639 { | |
640 init_pressure(); | |
641 } | |
642 } | |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
643 } |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
644 if(ticksdiff >= 1000) |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
645 { |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
646 /* reset counter */ |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
647 Scheduler.tickstart = HAL_GetTick(); |
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; |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
652 Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC; |
38 | 653 } |
654 } | |
655 } | |
656 | |
657 | |
658 /** | |
659 ****************************************************************************** | |
660 * @brief scheduleSurfaceMode / surface mode: Main Loop | |
661 * @author Peter Ryser | |
662 * @version V0.0.1 | |
663 * @date 22-April-2014 | |
664 ****************************************************************************** | |
665 */ | |
666 | |
667 | |
668 // =============================================================================== | |
669 // scheduleTestMode | |
670 /// @brief included for sealed hardware with permanent RTE update message | |
671 // =============================================================================== | |
672 void scheduleTestMode(void) | |
673 { | |
674 uint32_t ticksdiff = 0; | |
675 uint32_t lasttick = 0; | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
676 Scheduler.tickstart = HAL_GetTick(); |
38 | 677 |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
678 Scheduler.counterPressure100msec = 0; |
38 | 679 |
680 float temperature_carousel = 0.0f; | |
681 float temperature_changer = 0.1f; | |
682 | |
683 while(global.mode == MODE_TEST) | |
684 { | |
685 schedule_check_resync(); | |
686 lasttick = HAL_GetTick(); | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
687 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick); |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
688 |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
689 //Evaluate received data at 10 ms, 110 ms, 210 ms,... |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
690 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
691 { |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
692 SPI_Evaluate_RX_Data(); |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
693 Scheduler.counterSPIdata100msec++; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
694 } |
38 | 695 |
696 //Evaluate pressure at 20 ms, 120 ms, 220 ms,... | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
697 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20) |
38 | 698 { |
699 global.check_sync_not_running++; | |
700 | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
701 pressure_update(); |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
702 scheduleUpdateDeviceData(); |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
703 global.lifeData.ascent_rate_meter_per_min = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
704 copyPressureData(); |
38 | 705 |
706 if(temperature_carousel > 20.0f) | |
707 { | |
708 temperature_carousel = 20.0f; | |
709 temperature_changer = -0.1f; | |
710 } | |
711 else | |
712 if(temperature_carousel < 0) | |
713 { | |
714 temperature_carousel = 0; | |
715 temperature_changer = +0.1f; | |
716 } | |
717 | |
718 temperature_carousel += temperature_changer; | |
719 | |
720 uint8_t boolPressureData = !global.dataSendToMaster.boolPressureData; | |
721 | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
722 global.dataSendToMaster.data[boolPressureData].pressure_mbar = get_pressure_mbar(); |
38 | 723 |
724 global.dataSendToMaster.data[boolPressureData].temperature = temperature_carousel; | |
725 global.dataSendToMaster.data[boolPressureData].pressure_uTick = HAL_GetTick(); | |
726 global.dataSendToMaster.boolPressureData = boolPressureData; | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
727 Scheduler.counterPressure100msec++; |
38 | 728 } |
729 | |
730 if(ticksdiff >= 1000) | |
731 { | |
732 //Set back tick counter | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
733 Scheduler.tickstart = HAL_GetTick(); |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
734 Scheduler.counterPressure100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
735 Scheduler.counterSPIdata100msec = 0; |
38 | 736 } |
737 }; | |
738 } | |
739 | |
740 | |
142
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; |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
752 Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC; |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
753 |
38 | 754 global.dataSendToMaster.mode = MODE_SURFACE; |
755 global.deviceDataSendToMaster.mode = MODE_SURFACE; | |
756 | |
757 while(global.mode == MODE_SURFACE) | |
758 { | |
759 schedule_check_resync(); | |
760 lasttick = HAL_GetTick(); | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
761 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick); |
38 | 762 |
763 if(setButtonsNow == 1) | |
764 { | |
765 if(scheduleSetButtonResponsiveness()) | |
766 setButtonsNow = 0; | |
767 } | |
768 | |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
769 /* Evaluate received data at 10 ms, 110 ms, 210 ms,... duration ~<1ms */ |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
770 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
771 { |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
772 SPI_Evaluate_RX_Data(); |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
773 Scheduler.counterSPIdata100msec++; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
774 } |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
775 |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
776 /* Evaluate pressure at 20 ms, 120 ms, 220 ms,... duration ~22ms] */ |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
777 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20) |
38 | 778 { |
779 global.check_sync_not_running++; | |
135 | 780 pressure_update(); |
781 scheduleUpdateDeviceData(); | |
38 | 782 global.lifeData.ascent_rate_meter_per_min = 0; |
135 | 783 copyPressureData(); |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
784 Scheduler.counterPressure100msec++; |
135 | 785 |
38 | 786 if(scheduleCheck_pressure_reached_dive_mode_level()) |
787 global.mode = MODE_DIVE; | |
788 } | |
789 | |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
790 /* Evaluate compass data at 50 ms, 150 ms, 250 ms,... duration ~5ms */ |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
791 if(ticksdiff >= Scheduler.counterCompass100msec * 100 + 50) |
135 | 792 { |
793 compass_read(); | |
794 acceleration_read(); | |
795 compass_calc(); | |
796 copyCompassData(); | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
797 Scheduler.counterCompass100msec++; |
135 | 798 } |
38 | 799 |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
800 /* evaluate compass data at 70 ms, 170 ms, 270 ms,... duration <1ms */ |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
801 if(ticksdiff >= Scheduler.counterAmbientLight100msec * 100 + 70) |
38 | 802 { |
803 adc_ambient_light_sensor_get_data(); | |
804 copyAmbientLightData(); | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
805 Scheduler.counterAmbientLight100msec++; |
38 | 806 } |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
807 |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
808 |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
809 |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
810 /* Evaluate tissues, toxic data, etc. once a second... duration ~1ms */ |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
811 if(ticksdiff >= Scheduler.tick_execute1second) |
38 | 812 { |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
813 Scheduler.tick_execute1second = 0xFFFFFFFF; |
38 | 814 if(clearDecoNow) |
815 { | |
816 decom_reset_with_1000mbar(&global.lifeData); ///< this should almost reset desaturation time | |
817 // new 160215 hw | |
818 global.repetitive_dive = 0; | |
819 global.seconds_since_last_dive = 0; ///< this will reset OTU and CNS as well | |
820 global.no_fly_time_minutes = 0; | |
821 global.accidentFlag = 0; | |
822 global.accidentRemainingSeconds = 0; | |
823 vpm_init(&global.vpm, global.conservatism, global.repetitive_dive, global.seconds_since_last_dive); | |
824 clearDecoNow = 0; | |
825 } | |
89 | 826 |
38 | 827 if(global.seconds_since_last_dive) |
828 { | |
829 schedule_update_timer_helper(-1); | |
830 // global.seconds_since_last_dive++; | |
831 // if(global.seconds_since_last_dive > 777900) // a bit more than nine days [seconds] | |
832 // global.seconds_since_last_dive = 0; | |
833 } | |
89 | 834 |
38 | 835 if(global.accidentRemainingSeconds) |
836 { | |
837 global.accidentRemainingSeconds--; | |
838 if(!global.accidentRemainingSeconds) | |
839 global.accidentFlag = 0; | |
840 } | |
841 global.dataSendToMaster.accidentFlags = global.accidentFlag; | |
89 | 842 |
38 | 843 update_surface_pressure(1); |
844 scheduleUpdateLifeData(0); | |
845 decom_oxygen_calculate_otu_degrade(&global.lifeData.otu, global.seconds_since_last_dive); | |
846 decom_oxygen_calculate_cns_degrade(&global.lifeData.cns, global.seconds_since_last_dive); | |
135 | 847 |
848 /* start desaturation calculation after first valid measurement has been done */ | |
849 if(global.lifeData.pressure_surface_bar != INVALID_PREASURE_VALUE) | |
850 { | |
851 global.lifeData.desaturation_time_minutes = decom_calc_desaturation_time(global.lifeData.tissue_nitrogen_bar,global.lifeData.tissue_helium_bar,global.lifeData.pressure_surface_bar); | |
852 } | |
853 else | |
854 { | |
855 global.lifeData.desaturation_time_minutes = 0; | |
856 } | |
38 | 857 battery_charger_get_status_and_contral_battery_gas_gauge(0); |
88 | 858 battery_gas_gauge_get_data(); |
89 | 859 |
88 | 860 copyCnsAndOtuData(); |
861 copyTimeData(); | |
862 copyBatteryData(); | |
863 copyDeviceData(); | |
38 | 864 |
88 | 865 // new hw 170523 |
866 if(global.I2C_SystemStatus != HAL_OK) | |
867 { | |
868 MX_I2C1_TestAndClear(); | |
869 MX_I2C1_Init(); | |
870 if(!is_init_pressure_done()) | |
871 { | |
872 init_pressure(); | |
873 } | |
874 } | |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
875 } |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
876 |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
877 if(ticksdiff >= 1000) |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
878 { |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
879 //Set back tick counter |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
880 Scheduler.tickstart = HAL_GetTick(); |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
881 Scheduler.counterSPIdata100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
882 Scheduler.counterCompass100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
883 Scheduler.counterPressure100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
884 Scheduler.counterAmbientLight100msec = 0; |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
885 Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC; |
38 | 886 } |
887 } | |
888 } | |
889 | |
207 | 890 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
|
891 { |
207 | 892 if( SyncMethod < SPI_SYNC_METHOD_INVALID) |
893 { | |
894 dospisync = SyncMethod; | |
895 } | |
896 } | |
897 | |
898 void Scheduler_SyncToSPI() | |
899 { | |
900 uint32_t deltatick = 0; | |
901 | |
902 switch(dospisync) | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
903 { |
207 | 904 case SPI_SYNC_METHOD_HARD: |
905 //Set back tick counter | |
906 Scheduler.tickstart = HAL_GetTick(); | |
907 Scheduler.counterSPIdata100msec = 0; | |
908 Scheduler.counterCompass100msec = 0; | |
909 Scheduler.counterPressure100msec = 0; | |
910 Scheduler.counterAmbientLight100msec = 0; | |
911 dospisync = SPI_SYNC_METHOD_NONE; | |
912 break; | |
913 case SPI_SYNC_METHOD_SOFT: | |
914 deltatick = time_elapsed_ms(Scheduler.tickstart,HAL_GetTick()); | |
915 deltatick %= 100; /* clip to 100ms window */ | |
916 if(Scheduler.tickstart - deltatick >= 0) /* adjust start time to the next 100ms window */ | |
917 { | |
918 Scheduler.tickstart -= deltatick; | |
919 } | |
920 else | |
921 { | |
922 Scheduler.tickstart = 0xFFFFFFFF- (deltatick - Scheduler.tickstart); | |
923 } | |
924 dospisync = SPI_SYNC_METHOD_NONE; | |
925 break; | |
926 default: | |
927 break; | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
928 } |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
929 } |
38 | 930 |
931 /** | |
932 ****************************************************************************** | |
933 * @brief scheduleCompassCalibrationMode | |
934 * @author heinrichs weikamp gmbh | |
935 * @version V0.0.1 | |
936 * @since 31-March-2015 | |
937 * @date 31-March-2015 | |
938 ****************************************************************************** | |
939 */ | |
940 void scheduleCompassCalibrationMode(void) | |
941 { | |
942 compass_init(1,7); // fast mode, max gain | |
943 compass_calib(); // duration : 1 minute! | |
944 compass_init(0,7); // back to normal mode | |
945 | |
946 if(global.seconds_since_last_dive) | |
947 { | |
948 schedule_update_timer_helper(-1); | |
949 // global.seconds_since_last_dive += 60; | |
950 // if(global.seconds_since_last_dive > 777900) // a bit more than nine days [seconds] | |
951 // global.seconds_since_last_dive = 0; | |
952 } | |
953 | |
954 scheduleUpdateLifeData(0); | |
955 global.mode = MODE_SURFACE; | |
956 } | |
957 | |
958 | |
959 /** | |
960 ****************************************************************************** | |
961 * @brief scheduleSleepMode / sleep mode: Main Loop | |
962 * @author heinrichs weikamp gmbh | |
963 * @version V0.0.2 | |
964 * @since 31-March-2015 | |
965 * @date 22-April-2014 | |
966 ****************************************************************************** | |
967 */ | |
968 | |
969 void scheduleSleepMode(void) | |
970 { | |
971 global.dataSendToMaster.mode = 0; | |
972 global.deviceDataSendToMaster.mode = 0; | |
973 | |
974 /* prevent button wake up problem while in sleep_prepare | |
975 * sleep prepare does I2C_DeInit() | |
976 */ | |
977 if(global.mode != MODE_SLEEP) | |
978 MX_I2C1_Init(); | |
979 else | |
980 do | |
981 { | |
982 I2C_DeInit(); | |
983 | |
984 #ifdef DEBUGMODE | |
985 HAL_Delay(2000); | |
986 #else | |
987 RTC_StopMode_2seconds(); | |
988 #endif | |
989 | |
990 | |
991 | |
992 if(global.mode == MODE_SLEEP) | |
993 secondsCount += 2; | |
994 | |
995 MX_I2C1_Init(); | |
996 pressure_sensor_get_pressure_raw(); | |
997 | |
998 if(secondsCount >= 30) | |
999 { | |
1000 pressure_sensor_get_temperature_raw(); | |
1001 battery_gas_gauge_get_data(); | |
1002 // ReInit_battery_charger_status_pins(); | |
1003 battery_charger_get_status_and_contral_battery_gas_gauge(1); | |
1004 // DeInit_battery_charger_status_pins(); | |
1005 secondsCount = 0; | |
1006 } | |
1007 | |
1008 pressure_calculation(); | |
1009 | |
1010 scheduleUpdateDeviceData(); | |
1011 update_surface_pressure(2); | |
1012 | |
1013 if(global.seconds_since_last_dive) | |
1014 { | |
1015 schedule_update_timer_helper(-1); | |
1016 // global.seconds_since_last_dive += 2; | |
1017 // if(global.seconds_since_last_dive > 777900) // a bit more than nine days [seconds] | |
1018 // global.seconds_since_last_dive = 0; | |
1019 } | |
1020 | |
1021 if(global.accidentRemainingSeconds) | |
1022 { | |
1023 if(global.accidentRemainingSeconds > 2) | |
1024 global.accidentRemainingSeconds -= 2; | |
1025 else | |
1026 { | |
1027 global.accidentRemainingSeconds = 0; | |
1028 global.accidentFlag = 0; | |
1029 } | |
1030 } | |
1031 | |
1032 if(scheduleCheck_pressure_reached_dive_mode_level()) | |
1033 global.mode = MODE_BOOT; | |
1034 | |
1035 scheduleUpdateLifeData(2000); | |
1036 } | |
1037 while(global.mode == MODE_SLEEP); | |
1038 /* new section for system after Standby */ | |
1039 scheduleUpdateLifeData(-1); | |
1040 clearDecoNow = 0; | |
1041 setButtonsNow = 0; | |
1042 } | |
1043 | |
1044 | |
1045 | |
1046 /* Private functions ---------------------------------------------------------*/ | |
1047 | |
1048 | |
1049 /** | |
1050 ****************************************************************************** | |
1051 * @brief scheduleCheck_pressure_reached_dive_mode_level | |
1052 * @author heinrichs weikamp gmbh | |
1053 * @version V0.0.1 from inline code | |
1054 * @date 09-Sept-2015 | |
1055 ****************************************************************************** | |
1056 */ | |
1057 _Bool scheduleCheck_pressure_reached_dive_mode_level(void) | |
1058 { | |
1059 if(get_pressure_mbar() > 1160) | |
1060 return 1; | |
1061 else | |
1062 if((global.mode == MODE_SURFACE) && (get_pressure_mbar() > (get_surface_mbar() + 100)) && (get_surface_mbar() > 880)) | |
1063 return 1; | |
1064 else | |
1065 return 0; | |
1066 } | |
1067 | |
1068 | |
1069 /** | |
1070 ****************************************************************************** | |
1071 * @brief scheduleUpdateLifeData / calculates tissues | |
1072 * @author Peter Ryser | |
1073 * @version V0.0.1 | |
1074 * @date 22-April-2014 | |
1075 ****************************************************************************** | |
1076 */ | |
1077 | |
1078 | |
1079 void scheduleUpdateLifeData(int32_t asynchron_milliseconds_since_last) | |
1080 { | |
1081 static _Bool first = 1; | |
1082 static uint32_t tickstart = 0; | |
1083 static uint32_t ticksrest = 0; | |
1084 | |
1085 uint32_t ticksdiff = 0; | |
1086 uint32_t ticksnow = 0; | |
1087 uint32_t time_seconds = 0; | |
1088 uint8_t whichGasTmp = 0; | |
1089 | |
135 | 1090 uint8_t updateTissueData = 0; |
1091 | |
1092 | |
1093 if(global.lifeData.pressure_surface_bar == INVALID_PREASURE_VALUE) | |
1094 { | |
1095 updateTissueData = 1; | |
1096 } | |
1097 | |
38 | 1098 if(asynchron_milliseconds_since_last < 0) |
1099 { | |
1100 first = 1; | |
1101 tickstart = 0; | |
1102 ticksrest = 0; | |
1103 return; | |
1104 } | |
1105 | |
1106 if(!asynchron_milliseconds_since_last && first) | |
1107 { | |
1108 tickstart = HAL_GetTick(); | |
1109 first = 0; | |
1110 return; | |
1111 } | |
1112 | |
1113 whichGasTmp = global.whichGas; | |
1114 global.lifeData.actualGas = global.aktualGas[whichGasTmp]; | |
1115 global.lifeData.pressure_ambient_bar = get_pressure_mbar() / 1000.0f; | |
1116 global.lifeData.pressure_surface_bar = get_surface_mbar() / 1000.0f; | |
1117 | |
135 | 1118 if(updateTissueData) |
1119 { | |
1120 decom_reset_with_ambientmbar(global.lifeData.pressure_surface_bar,&global.lifeData); | |
1121 } | |
1122 | |
38 | 1123 if(!asynchron_milliseconds_since_last) |
1124 { | |
1125 ticksnow = HAL_GetTick(); | |
1126 ticksdiff = time_elapsed_ms(tickstart,ticksnow); | |
1127 } | |
1128 else | |
1129 { | |
1130 first = 1; | |
1131 ticksdiff = asynchron_milliseconds_since_last; | |
1132 } | |
1133 | |
1134 if(ticksrest > 1000) // whatever happens after standby with STM32L476 | |
1135 ticksrest = 0; // maybe move static to SRAM2 | |
1136 | |
1137 ticksdiff += ticksrest; | |
1138 time_seconds = ticksdiff/ 1000; | |
1139 ticksrest = ticksdiff - time_seconds * 1000; | |
1140 tickstart = ticksnow; | |
1141 | |
1142 decom_tissues_exposure((int)time_seconds, &global.lifeData); | |
1143 if(global.demo_mode) | |
1144 decom_tissues_exposure((int)(3*time_seconds), &global.lifeData); | |
1145 copyTissueData(); | |
1146 } | |
1147 | |
1148 | |
1149 /** | |
1150 ****************************************************************************** | |
1151 * @brief scheduleUpdateDeviceData | |
1152 * @author heinrichs weikamp gmbh | |
1153 * @version V0.0.1 | |
1154 * @date 16-March-2015 | |
1155 * | |
1156 * two step process | |
1157 * first compare with data from main CPU == externalLogbookFlash | |
1158 * second update with new sensor data | |
1159 ****************************************************************************** | |
1160 */ | |
1161 void scheduleSetDate(SDeviceLine *line) | |
1162 { | |
1163 extern RTC_HandleTypeDef RTCHandle; | |
1164 | |
1165 line->date_rtc_dr = (uint32_t)(RTCHandle.Instance->DR & RTC_DR_RESERVED_MASK); | |
1166 line->time_rtc_tr = (uint32_t)(RTCHandle.Instance->TR & RTC_TR_RESERVED_MASK); | |
1167 } | |
1168 | |
1169 | |
1170 void scheduleCopyDeviceData(SDeviceLine *lineWrite, const SDeviceLine *lineRead) | |
1171 { | |
1172 lineWrite->date_rtc_dr = lineRead->date_rtc_dr; | |
1173 lineWrite->time_rtc_tr = lineRead->time_rtc_tr; | |
1174 lineWrite->value_int32 = lineRead->value_int32; | |
1175 } | |
1176 | |
1177 | |
1178 void scheduleUpdateDeviceData(void) | |
1179 { | |
1180 /* first step, main CPU */ | |
1181 | |
1182 if(deviceDataFlashValid) | |
1183 { | |
1184 /* max values */ | |
1185 if(global.deviceData.batteryChargeCompleteCycles.value_int32 < DeviceDataFlash.batteryChargeCompleteCycles.value_int32) | |
1186 { | |
1187 scheduleCopyDeviceData(&global.deviceData.batteryChargeCompleteCycles, &DeviceDataFlash.batteryChargeCompleteCycles); | |
1188 } | |
1189 if(global.deviceData.batteryChargeCycles.value_int32 < DeviceDataFlash.batteryChargeCycles.value_int32) | |
1190 { | |
1191 scheduleCopyDeviceData(&global.deviceData.batteryChargeCycles, &DeviceDataFlash.batteryChargeCycles); | |
1192 } | |
1193 if(global.deviceData.temperatureMaximum.value_int32 < DeviceDataFlash.temperatureMaximum.value_int32) | |
1194 { | |
1195 scheduleCopyDeviceData(&global.deviceData.temperatureMaximum, &DeviceDataFlash.temperatureMaximum); | |
1196 } | |
1197 if(global.deviceData.depthMaximum.value_int32 < DeviceDataFlash.depthMaximum.value_int32) | |
1198 { | |
1199 scheduleCopyDeviceData(&global.deviceData.depthMaximum, &DeviceDataFlash.depthMaximum); | |
1200 } | |
1201 if(global.deviceData.diveCycles.value_int32 < DeviceDataFlash.diveCycles.value_int32) | |
1202 { | |
1203 scheduleCopyDeviceData(&global.deviceData.diveCycles, &DeviceDataFlash.diveCycles); | |
1204 } | |
1205 if(global.deviceData.hoursOfOperation.value_int32 < DeviceDataFlash.hoursOfOperation.value_int32) | |
1206 { | |
1207 scheduleCopyDeviceData(&global.deviceData.hoursOfOperation, &DeviceDataFlash.hoursOfOperation); | |
1208 } | |
1209 | |
1210 /* min values */ | |
1211 if(global.deviceData.temperatureMinimum.value_int32 > DeviceDataFlash.temperatureMinimum.value_int32) | |
1212 { | |
1213 scheduleCopyDeviceData(&global.deviceData.temperatureMinimum, &DeviceDataFlash.temperatureMinimum); | |
1214 } | |
1215 if(global.deviceData.voltageMinimum.value_int32 > DeviceDataFlash.voltageMinimum.value_int32) | |
1216 { | |
1217 scheduleCopyDeviceData(&global.deviceData.voltageMinimum, &DeviceDataFlash.voltageMinimum); | |
1218 } | |
1219 } | |
1220 | |
1221 /* second step, sensor data */ | |
1222 int32_t temperature_centigrad_int32; | |
1223 int32_t pressure_mbar_int32; | |
1224 int32_t voltage_mvolt_int32; | |
1225 | |
1226 temperature_centigrad_int32 = (int32_t)(get_temperature() * 100); | |
1227 if(temperature_centigrad_int32 < global.deviceData.temperatureMinimum.value_int32) | |
1228 { | |
1229 global.deviceData.temperatureMinimum.value_int32 = temperature_centigrad_int32; | |
88 | 1230 scheduleSetDate(&global.deviceData.temperatureMinimum); |
38 | 1231 } |
1232 | |
1233 if(temperature_centigrad_int32 > global.deviceData.temperatureMaximum.value_int32) | |
1234 { | |
1235 global.deviceData.temperatureMaximum.value_int32 = temperature_centigrad_int32; | |
88 | 1236 scheduleSetDate(&global.deviceData.temperatureMaximum); |
38 | 1237 } |
1238 | |
1239 pressure_mbar_int32 = (int32_t)get_pressure_mbar(); | |
1240 if(pressure_mbar_int32 > global.deviceData.depthMaximum.value_int32) | |
1241 { | |
1242 global.deviceData.depthMaximum.value_int32 = pressure_mbar_int32; | |
88 | 1243 scheduleSetDate(&global.deviceData.depthMaximum); |
38 | 1244 } |
1245 | |
1246 voltage_mvolt_int32 = (int32_t)(get_voltage() * 1000); | |
1247 if(voltage_mvolt_int32 < global.deviceData.voltageMinimum.value_int32) | |
1248 { | |
1249 global.deviceData.voltageMinimum.value_int32 = voltage_mvolt_int32; | |
88 | 1250 scheduleSetDate(&global.deviceData.voltageMinimum); |
38 | 1251 } |
1252 | |
1253 /* third step, counter */ | |
1254 switch (global.mode) | |
1255 { | |
1256 case MODE_SURFACE: | |
1257 case MODE_DIVE: | |
1258 default: | |
1259 deviceDataSubSeconds++; | |
1260 if(deviceDataSubSeconds > 10) | |
1261 { | |
1262 deviceDataSubSeconds = 0; | |
1263 global.deviceData.hoursOfOperation.value_int32++; | |
1264 } | |
1265 break; | |
1266 | |
1267 case MODE_SLEEP: | |
1268 case MODE_SHUTDOWN: | |
1269 break; | |
1270 } | |
1271 } | |
1272 | |
1273 | |
1274 void scheduleUpdateDeviceDataChargerFull(void) | |
1275 { | |
1276 global.deviceData.batteryChargeCompleteCycles.value_int32++; | |
88 | 1277 scheduleSetDate(&global.deviceData.batteryChargeCompleteCycles); |
38 | 1278 } |
1279 | |
1280 | |
1281 void scheduleUpdateDeviceDataChargerCharging(void) | |
1282 { | |
1283 global.deviceData.batteryChargeCycles.value_int32++; | |
88 | 1284 scheduleSetDate(&global.deviceData.batteryChargeCycles); |
38 | 1285 } |
1286 | |
1287 | |
1288 /** | |
1289 ****************************************************************************** | |
1290 * @brief vpm_crush / calls vpm calc_crushing_pressure every four seconds during descend | |
1291 * @author Peter Ryser | |
1292 * @version V0.0.1 | |
1293 * @date 22-April-2014 | |
1294 ****************************************************************************** | |
1295 */ | |
1296 _Bool vpm_crush2(void) | |
1297 { | |
1298 int i = 0; | |
1299 static float starting_ambient_pressure = 0; | |
1300 static float ending_ambient_pressure = 0; | |
1301 static float time_calc_begin = -1; | |
1302 static float initial_helium_pressure[16]; | |
1303 static float initial_nitrogen_pressure[16]; | |
1304 ending_ambient_pressure = global.lifeData.pressure_ambient_bar * 10; | |
1305 | |
1306 if((global.lifeData.dive_time_seconds <= 4) || (starting_ambient_pressure >= ending_ambient_pressure)) | |
1307 { | |
1308 time_calc_begin = global.lifeData.dive_time_seconds; | |
1309 starting_ambient_pressure = global.lifeData.pressure_ambient_bar * 10; | |
1310 for( i = 0; i < 16; i++) | |
1311 { | |
1312 initial_helium_pressure[i] = global.lifeData.tissue_helium_bar[i] * 10; | |
1313 initial_nitrogen_pressure[i] = global.lifeData.tissue_nitrogen_bar[i] * 10; | |
1314 } | |
1315 return 0; | |
1316 } | |
1317 if(global.lifeData.dive_time_seconds - time_calc_begin >= 4) | |
1318 { | |
1319 if(ending_ambient_pressure > starting_ambient_pressure + 0.5f) | |
1320 { | |
1321 float rate = (ending_ambient_pressure - starting_ambient_pressure) * 60 / 4; | |
1322 calc_crushing_pressure(&global.lifeData, &global.vpm, initial_helium_pressure, initial_nitrogen_pressure, starting_ambient_pressure, rate); | |
1323 | |
1324 time_calc_begin = global.lifeData.dive_time_seconds; | |
1325 starting_ambient_pressure = global.lifeData.pressure_ambient_bar * 10; | |
1326 for( i = 0; i < 16; i++) | |
1327 { | |
1328 initial_helium_pressure[i] = global.lifeData.tissue_helium_bar[i] * 10; | |
1329 initial_nitrogen_pressure[i] = global.lifeData.tissue_nitrogen_bar[i] * 10; | |
1330 } | |
1331 | |
1332 return 1; | |
1333 } | |
1334 | |
1335 } | |
1336 return 0; | |
1337 }; | |
1338 | |
1339 | |
1340 void initStructWithZeero(uint8_t* data, uint16_t length) | |
1341 { | |
1342 for(uint16_t i = 0; i < length; i++) | |
1343 data[i] = 0; | |
1344 } | |
1345 | |
1346 | |
1347 long get_nofly_time_minutes(void) | |
1348 { | |
1349 | |
1350 if(global.no_fly_time_minutes <= 0) | |
1351 return 0; | |
1352 | |
1353 long minutes_since_last_dive = global.seconds_since_last_dive/60; | |
1354 | |
1355 if((global.seconds_since_last_dive > 0) && (global.no_fly_time_minutes > minutes_since_last_dive)) | |
1356 { | |
1357 return (global.no_fly_time_minutes - minutes_since_last_dive); | |
1358 } | |
1359 else | |
1360 { | |
1361 global.no_fly_time_minutes = 0; | |
1362 return 0; | |
1363 } | |
1364 } | |
1365 | |
1366 | |
1367 //Supports threadsave copying!!! | |
1368 void copyActualGas(SGas gas) | |
1369 { | |
1370 uint8_t whichGas = !global.whichGas; | |
1371 global.aktualGas[whichGas] = gas; | |
1372 global.whichGas = whichGas; | |
1373 } | |
1374 | |
1375 | |
1376 //Supports threadsave copying!!! | |
1377 void copyPressureData(void) | |
1378 { | |
1379 global.dataSendToMaster.sensorErrors = I2C1_Status(); | |
1380 //uint8_t dataSendToMaster. | |
1381 uint8_t boolPressureData = !global.dataSendToMaster.boolPressureData; | |
1382 global.dataSendToMaster.data[boolPressureData].temperature = get_temperature(); | |
1383 global.dataSendToMaster.data[boolPressureData].pressure_mbar = get_pressure_mbar(); | |
1384 global.dataSendToMaster.data[boolPressureData].surface_mbar = get_surface_mbar(); | |
1385 global.dataSendToMaster.data[boolPressureData].ascent_rate_meter_per_min = global.lifeData.ascent_rate_meter_per_min; | |
1386 global.dataSendToMaster.data[boolPressureData].pressure_uTick = HAL_GetTick(); | |
1387 global.dataSendToMaster.boolPressureData = boolPressureData; | |
1388 } | |
1389 | |
1390 | |
1391 //Supports threadsave copying!!! | |
1392 void copyCnsAndOtuData(void) | |
1393 { | |
1394 //uint8_t dataSendToMaster. | |
1395 uint8_t boolToxicData = !global.dataSendToMaster.boolToxicData; | |
1396 global.dataSendToMaster.data[boolToxicData].cns = global.lifeData.cns; | |
1397 global.dataSendToMaster.data[boolToxicData].otu = global.lifeData.otu; | |
1398 global.dataSendToMaster.data[boolToxicData].desaturation_time_minutes = global.lifeData.desaturation_time_minutes; | |
1399 global.dataSendToMaster.data[boolToxicData].no_fly_time_minutes = get_nofly_time_minutes(); | |
1400 global.dataSendToMaster.boolToxicData = boolToxicData; | |
1401 } | |
1402 | |
1403 | |
1404 //Supports threadsave copying!!! | |
1405 void copyTimeData(void) | |
1406 { | |
1407 extern RTC_HandleTypeDef RTCHandle; | |
1408 | |
1409 uint8_t boolTimeData = !global.dataSendToMaster.boolTimeData; | |
1410 global.dataSendToMaster.data[boolTimeData].localtime_rtc_tr = (uint32_t)(RTCHandle.Instance->TR & RTC_TR_RESERVED_MASK); | |
1411 global.dataSendToMaster.data[boolTimeData].localtime_rtc_dr = (uint32_t)(RTCHandle.Instance->DR & RTC_DR_RESERVED_MASK); | |
1412 global.dataSendToMaster.data[boolTimeData].divetime_seconds = (uint32_t)global.lifeData.dive_time_seconds; | |
1413 global.dataSendToMaster.data[boolTimeData].dive_time_seconds_without_surface_time = (uint32_t)global.lifeData.dive_time_seconds_without_surface_time; | |
1414 global.dataSendToMaster.data[boolTimeData].surfacetime_seconds = (uint32_t)global.seconds_since_last_dive; | |
1415 global.dataSendToMaster.data[boolTimeData].counterSecondsShallowDepth = (uint32_t)global.lifeData.counterSecondsShallowDepth; | |
1416 global.dataSendToMaster.boolTimeData = boolTimeData; | |
1417 } | |
1418 | |
1419 | |
1420 //Supports threadsave copying!!! | |
1421 void copyCompassData(void) | |
1422 { | |
1423 extern float compass_heading; | |
1424 extern float compass_roll; | |
1425 extern float compass_pitch; | |
1426 //uint8_t dataSendToMaster. | |
1427 uint8_t boolCompassData = !global.dataSendToMaster.boolCompassData; | |
1428 global.dataSendToMaster.data[boolCompassData].compass_heading = compass_heading; | |
1429 global.dataSendToMaster.data[boolCompassData].compass_roll = compass_roll; | |
1430 global.dataSendToMaster.data[boolCompassData].compass_pitch = compass_pitch; | |
1431 global.dataSendToMaster.data[boolCompassData].compass_DX_f = 0; | |
1432 global.dataSendToMaster.data[boolCompassData].compass_DY_f = 0; | |
1433 global.dataSendToMaster.data[boolCompassData].compass_DZ_f = 0; | |
1434 global.dataSendToMaster.data[boolCompassData].compass_uTick = HAL_GetTick(); | |
1435 global.dataSendToMaster.boolCompassData = boolCompassData; | |
1436 } | |
1437 | |
1438 | |
1439 void copyCompassDataDuringCalibration(int16_t dx, int16_t dy, int16_t dz) | |
1440 { | |
1441 extern float compass_heading; | |
1442 extern float compass_roll; | |
1443 extern float compass_pitch; | |
1444 //uint8_t dataSendToMaster. | |
1445 uint8_t boolCompassData = !global.dataSendToMaster.boolCompassData; | |
1446 global.dataSendToMaster.data[boolCompassData].compass_heading = compass_heading; | |
1447 global.dataSendToMaster.data[boolCompassData].compass_roll = compass_roll; | |
1448 global.dataSendToMaster.data[boolCompassData].compass_pitch = compass_pitch; | |
1449 global.dataSendToMaster.data[boolCompassData].compass_DX_f = dx; | |
1450 global.dataSendToMaster.data[boolCompassData].compass_DY_f = dy; | |
1451 global.dataSendToMaster.data[boolCompassData].compass_DZ_f = dz; | |
1452 global.dataSendToMaster.boolCompassData = boolCompassData; | |
1453 } | |
1454 | |
1455 | |
1456 //Supports threadsave copying!!! | |
1457 void copyBatteryData(void) | |
1458 { | |
1459 uint8_t boolBatteryData = !global.dataSendToMaster.boolBatteryData; | |
1460 global.dataSendToMaster.data[boolBatteryData].battery_voltage = get_voltage(); | |
1461 global.dataSendToMaster.data[boolBatteryData].battery_charge= get_charge(); | |
1462 global.dataSendToMaster.boolBatteryData = boolBatteryData; | |
1463 } | |
1464 | |
1465 | |
1466 //Supports threadsave copying!!! | |
1467 void copyAmbientLightData(void) | |
1468 { | |
1469 uint8_t boolAmbientLightData = !global.dataSendToMaster.boolAmbientLightData; | |
1470 global.dataSendToMaster.data[boolAmbientLightData].ambient_light_level = get_ambient_light_level(); | |
1471 global.dataSendToMaster.boolAmbientLightData = boolAmbientLightData; | |
1472 } | |
1473 | |
1474 | |
1475 //Supports threadsave copying!!! | |
1476 void copyTissueData(void) | |
1477 { | |
1478 //uint8_t dataSendToMaster. | |
1479 uint8_t boolTisssueData = !global.dataSendToMaster.boolTisssueData; | |
1480 for(int i = 0; i < 16; i++) | |
1481 { | |
1482 global.dataSendToMaster.data[boolTisssueData].tissue_nitrogen_bar[i] = global.lifeData.tissue_nitrogen_bar[i]; | |
1483 global.dataSendToMaster.data[boolTisssueData].tissue_helium_bar[i] = global.lifeData.tissue_helium_bar[i]; | |
1484 } | |
1485 global.dataSendToMaster.boolTisssueData = boolTisssueData; | |
1486 } | |
1487 | |
1488 | |
1489 //Supports threadsave copying!!! | |
1490 void copyVpmCrushingData(void) | |
1491 { | |
1492 //uint8_t dataSendToMaster. | |
1493 uint8_t boolCrushingData = !global.dataSendToMaster.boolCrushingData; | |
1494 for(int i = 0; i < 16; i++) | |
1495 { | |
1496 global.dataSendToMaster.data[boolCrushingData].max_crushing_pressure_n2[i] = global.vpm.max_crushing_pressure_n2[i]; | |
1497 global.dataSendToMaster.data[boolCrushingData].max_crushing_pressure_he[i] = global.vpm.max_crushing_pressure_he[i]; | |
1498 global.dataSendToMaster.data[boolCrushingData].adjusted_critical_radius_he[i] = global.vpm.adjusted_critical_radius_he[i]; | |
1499 global.dataSendToMaster.data[boolCrushingData].adjusted_critical_radius_n2[i] = global.vpm.adjusted_critical_radius_n2[i]; | |
1500 } | |
1501 global.dataSendToMaster.boolCrushingData = boolCrushingData; | |
1502 } | |
1503 | |
1504 | |
1505 void copyDeviceData(void) | |
1506 { | |
1507 uint8_t boolDeviceData = !global.deviceDataSendToMaster.boolDeviceData; | |
1508 memcpy(&global.deviceDataSendToMaster.DeviceData[boolDeviceData], &global.deviceData,sizeof(SDevice)); | |
1509 global.deviceDataSendToMaster.boolDeviceData = boolDeviceData; | |
1510 | |
1511 global.deviceDataSendToMaster.boolVpmRepetitiveDataValid = 0; | |
1512 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.adjusted_critical_radius_he, &global.vpm.adjusted_critical_radius_he, sizeof(16*4)); | |
1513 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.adjusted_critical_radius_n2, &global.vpm.adjusted_critical_radius_n2, sizeof(16*4)); | |
1514 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.adjusted_crushing_pressure_he, &global.vpm.adjusted_crushing_pressure_he, sizeof(16*4)); | |
1515 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.adjusted_crushing_pressure_n2, &global.vpm.adjusted_crushing_pressure_n2, sizeof(16*4)); | |
1516 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.initial_allowable_gradient_he, &global.vpm.initial_allowable_gradient_he, sizeof(16*4)); | |
1517 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.initial_allowable_gradient_n2, &global.vpm.initial_allowable_gradient_n2, sizeof(16*4)); | |
1518 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.max_actual_gradient, &global.vpm.max_actual_gradient, sizeof(16*4)); | |
1519 global.deviceDataSendToMaster.VpmRepetitiveData.repetitive_variables_not_valid = global.vpm.repetitive_variables_not_valid; | |
1520 global.deviceDataSendToMaster.boolVpmRepetitiveDataValid = 1; | |
1521 } | |
1522 | |
1523 /* copyPICdata(); is used in spi.c */ | |
1524 void copyPICdata(void) | |
1525 { | |
1526 uint8_t boolPICdata = !global.dataSendToMaster.boolPICdata; | |
1527 for(int i = 0; i < 3; i++) | |
1528 { | |
1529 global.dataSendToMaster.data[boolPICdata].button_setting[i] = global.ButtonPICdata[i]; | |
1530 } | |
1531 global.dataSendToMaster.boolPICdata = boolPICdata; | |
1532 } | |
1533 | |
1534 | |
1535 typedef enum | |
1536 { | |
1537 SPI3_OK = 0x00, | |
1538 SPI3_DEINIT = 0x01, | |
1539 } SPI3_StatusTypeDef; | |
1540 /* if spi3 is running and the SPI3_ButtonAdjust call returns OK, all is fine | |
1541 if the SPI3_ButtonAdjust call returns error, the spi3 is DeInit | |
1542 and will be init the next call of scheduleSetButtonResponsiveness() | |
1543 and data will be send again on the third call | |
1544 therefore on return 0 of scheduleSetButtonResponsiveness() the caller flag should kept active | |
1545 */ | |
1546 uint8_t scheduleSetButtonResponsiveness(void) | |
1547 { | |
1548 static uint8_t SPI3status = SPI3_OK; | |
1549 | |
1550 if((SPI3status == SPI3_OK) && (SPI3_ButtonAdjust(global.ButtonResponsiveness, global.ButtonPICdata))) | |
1551 { | |
1552 copyPICdata(); | |
1553 return 1; | |
1554 } | |
1555 else | |
1556 { | |
1557 for(int i=0;i<3;i++) | |
1558 { | |
1559 global.ButtonPICdata[i] = 0xFF; | |
1560 } | |
1561 copyPICdata(); | |
1562 | |
1563 if(SPI3status == SPI3_OK) | |
1564 { | |
1565 MX_SPI3_DeInit(); | |
1566 SPI3status = SPI3_DEINIT; | |
1567 } | |
1568 else | |
1569 { | |
1570 MX_SPI3_Init(); | |
1571 SPI3status = SPI3_OK; | |
1572 } | |
1573 return 0; | |
1574 } | |
1575 } | |
1576 | |
1577 | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
181
diff
changeset
|
1578 //save time difference |
38 | 1579 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow) |
1580 { | |
1581 if(ticksstart <= ticksnow) | |
1582 { | |
1583 return ticksnow - ticksstart; | |
1584 } | |
1585 else | |
1586 { | |
1587 return 0xFFFFFFFF - ticksstart + ticksnow; | |
1588 } | |
1589 } | |
1590 | |
1591 /* same as in data_central.c */ | |
1592 _Bool is_ambient_pressure_close_to_surface(SLifeData *lifeDataCall) | |
1593 { | |
1594 if(lifeDataCall->pressure_ambient_bar < (lifeDataCall->pressure_surface_bar + 0.1f)) // hw 161121 now 1 mter, before 0.04f | |
1595 return true; | |
1596 else | |
1597 return false; | |
1598 } | |
1599 | |
1600 | |
1601 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ | |
1602 |