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