Mercurial > public > ostc4
annotate Small_CPU/Src/scheduler.c @ 682:8775d3dc6325 Betatest
Bugfix low ppO2 warning in bailout mode:
the code has different sources for divesettings (real and simulated). The ppo2 calculation code used the pointer to the real structure. As result in simulation mode an error occured caused by the ppo2 calculation which was not aware that a bailout happened (because the real structure was references instead of the simulator ones). The problem has been fixed by using the "stateUsed" pointer which is refering to the structure currenty in use.
author | Ideenmodellierer |
---|---|
date | Mon, 25 Apr 2022 21:15:01 +0200 |
parents | 079bb5b22c06 |
children | 52d68cf9994c |
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" | |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
44 #include "externalInterface.h" |
662 | 45 #include "uart.h" |
38 | 46 |
414
6886aeeca454
Added compile switch for restoring of last known date after power lost:
ideenmodellierer
parents:
409
diff
changeset
|
47 /* uncomment to enable restoting of last known date in case of a power loss (RTC looses timing data) */ |
6886aeeca454
Added compile switch for restoring of last known date after power lost:
ideenmodellierer
parents:
409
diff
changeset
|
48 /* #define RESTORE_LAST_KNOWN_DATE */ |
38 | 49 |
475 | 50 #define INVALID_PREASURE_VALUE (0.0f) |
338
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
51 #define START_DIVE_MOUNTAIN_MODE_BAR (0.88f) |
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
52 #define START_DIVE_IMMEDIATLY_BAR (1.16f) |
135 | 53 |
38 | 54 /* Private types -------------------------------------------------------------*/ |
55 const SGas Air = {79,0,0,0,0}; | |
56 | |
57 /* Exported variables --------------------------------------------------------*/ | |
58 SGlobal global; | |
59 SDevice DeviceDataFlash; | |
60 uint8_t deviceDataFlashValid = 0; | |
61 uint8_t deviceDataSubSeconds = 0; | |
62 | |
63 /* Private variables ---------------------------------------------------------*/ | |
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
64 static uint16_t ManualExitDiveCounter = 0; /* The computer will exit dive mode in shallow area immediately. Increase depth to restart dive while counter is active */ |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
65 |
38 | 66 /* can be lost while in sleep */ |
67 uint8_t clearDecoNow = 0; | |
68 uint8_t setButtonsNow = 0; | |
69 | |
70 /* has to be in SRAM2 */ | |
71 uint8_t secondsCount = 0; | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
72 |
207 | 73 static uint8_t dospisync = SPI_SYNC_METHOD_NONE; |
74 | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
75 SScheduleCtrl Scheduler; |
38 | 76 |
77 /* Private function prototypes -----------------------------------------------*/ | |
78 | |
79 _Bool vpm_crush2(void); | |
80 void scheduleUpdateDeviceData(void); | |
81 long get_nofly_time_minutes(void); | |
82 void copyActualGas(SGas gas); | |
83 void copyPressureData(void); | |
84 void copyCnsAndOtuData(void); | |
85 void copyTimeData(void); | |
86 void copyCompassData(void); | |
87 void copyCompassDataDuringCalibration(int16_t dx, int16_t dy, int16_t dz); | |
88 void copyAmbientLightData(void); | |
89 void copyTissueData(void); | |
90 void copyVpmCrushingData(void); | |
91 void copyDeviceData(void); | |
92 void copyPICdata(void); | |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
93 void copyExtADCdata(); |
662 | 94 void copyExtCO2data(); |
230
3973208c4a20
cleanup: make return void when never used
Jan Mulder <jlmulder@xs4all.nl>
parents:
220
diff
changeset
|
95 static void schedule_update_timer_helper(int8_t thisSeconds); |
38 | 96 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow); |
97 | |
98 void scheduleSetDate(SDeviceLine *line); | |
99 | |
100 /* Exported functions --------------------------------------------------------*/ | |
101 | |
102 void initGlobals(void) | |
103 { | |
231
f6961efb3794
cleanup: do not re-implement a standard function
Jan Mulder <jlmulder@xs4all.nl>
parents:
230
diff
changeset
|
104 bzero(&global, sizeof(SGlobal)); |
38 | 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 | |
475 | 117 const uint8_t button_standard_sensitivity = 51; /* 51 equals a percentage of 85% which was the default value before */ |
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 | |
240
625d20070261
Improvement SPI stability/recoverability
Jan Mulder <jlmulder@xs4all.nl>
parents:
231
diff
changeset
|
128 global.I2C_SystemStatus = HAL_ERROR; // 0x00 would be everything working |
38 | 129 |
668 | 130 global.lifeData.battery_voltage = BATTERY_DEFAULT_VOLTAGE; |
131 | |
135 | 132 global.lifeData.pressure_ambient_bar = INVALID_PREASURE_VALUE; |
133 global.lifeData.pressure_surface_bar = INVALID_PREASURE_VALUE; | |
38 | 134 decom_reset_with_1000mbar(&global.lifeData); |
135 | |
136 global.demo_mode = 0; | |
137 | |
138 for(int i = 0; i < MAX_SENSORS; i++) | |
139 { | |
140 global.sensorError[i] = HAL_OK; // HAL_OK = 0; | |
141 } | |
142 | |
143 global.dataSendToMaster.RTE_VERSION_high = firmwareVersionHigh();//RTE_VERSION_HIGH;; | |
144 global.dataSendToMaster.RTE_VERSION_low = firmwareVersionLow();//RTE_VERSION_LOW;; | |
145 global.dataSendToMaster.chargeStatus = 0; | |
146 | |
475 | 147 global.dataSendToMaster.power_on_reset = 0; |
38 | 148 global.dataSendToMaster.header.checkCode[0] = 0xA1; |
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
149 global.dataSendToMaster.header.checkCode[1] = SPI_RX_STATE_OFFLINE; |
38 | 150 global.dataSendToMaster.header.checkCode[2] = 0xA3; |
151 global.dataSendToMaster.header.checkCode[3] = 0xA4; | |
152 global.dataSendToMaster.footer.checkCode[3] = 0xE4; | |
153 global.dataSendToMaster.footer.checkCode[2] = 0xE3; | |
154 global.dataSendToMaster.footer.checkCode[1] = 0xE2; | |
155 global.dataSendToMaster.footer.checkCode[0] = 0xE1; | |
156 global.dataSendToMaster.sensorErrors = 0; | |
157 | |
158 global.sync_error_count = 0; | |
159 global.check_sync_not_running = 0; | |
160 | |
161 global.deviceDataSendToMaster.RTE_VERSION_high = firmwareVersionHigh();//RTE_VERSION_HIGH; | |
162 global.deviceDataSendToMaster.RTE_VERSION_low = firmwareVersionLow();//RTE_VERSION_LOW; | |
163 global.deviceDataSendToMaster.chargeStatus = 0; | |
164 | |
475 | 165 global.deviceDataSendToMaster.power_on_reset = 0; |
38 | 166 global.deviceDataSendToMaster.header.checkCode[0] = 0xDF; |
167 global.deviceDataSendToMaster.header.checkCode[1] = 0xDE; | |
168 global.deviceDataSendToMaster.header.checkCode[2] = 0xDD; | |
169 global.deviceDataSendToMaster.header.checkCode[3] = 0xDC; | |
170 global.deviceDataSendToMaster.footer.checkCode[3] = 0xE4; | |
171 global.deviceDataSendToMaster.footer.checkCode[2] = 0xE3; | |
172 global.deviceDataSendToMaster.footer.checkCode[1] = 0xE2; | |
173 global.deviceDataSendToMaster.footer.checkCode[0] = 0xE1; | |
174 | |
175 global.dataSendToSlave.getDeviceDataNow = 0; | |
176 | |
177 global.deviceData.batteryChargeCompleteCycles.value_int32 = 0; | |
178 global.deviceData.batteryChargeCycles.value_int32 = 0; | |
179 global.deviceData.depthMaximum.value_int32 = 0; | |
180 global.deviceData.diveCycles.value_int32 = 0; | |
181 global.deviceData.hoursOfOperation.value_int32 = 0; | |
182 global.deviceData.temperatureMaximum.value_int32 = INT32_MIN; | |
183 global.deviceData.temperatureMinimum.value_int32 = INT32_MAX; | |
184 global.deviceData.voltageMinimum.value_int32 = INT32_MAX; | |
148
ee744c7160ce
Use SPI TX callback to synchronize to main CPU
Ideenmodellierer
parents:
142
diff
changeset
|
185 |
265
a91d99265884
Increase SPI com timeout for cold start and wake up
ideenmodellierer
parents:
264
diff
changeset
|
186 Scheduler.communicationTimeout = SPI_COM_TIMEOUT_START; |
207 | 187 Scheduler_Request_sync_with_SPI(SPI_SYNC_METHOD_HARD); |
38 | 188 } |
189 | |
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
190 void reinitGlobals(void) |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
191 { |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
192 global.dataSendToSlavePending = 0; |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
193 global.dataSendToSlaveIsValid = 0; |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
194 global.dataSendToSlaveIsNotValidCount = 0; |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
195 global.sync_error_count = 0; |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
196 global.check_sync_not_running = 0; |
265
a91d99265884
Increase SPI com timeout for cold start and wake up
ideenmodellierer
parents:
264
diff
changeset
|
197 Scheduler.communicationTimeout = SPI_COM_TIMEOUT_START; |
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
198 } |
38 | 199 |
200 void scheduleSpecial_Evaluate_DataSendToSlave(void) | |
201 { | |
104 | 202 //TEMPORARY fix for compass calibration. |
203 //TODO: Fix I2C timeout for complete solving problem. | |
204 if(global.mode==MODE_CALIB){ | |
205 return; | |
206 } | |
90 | 207 |
88 | 208 global.dataSendToSlavePending = 0; |
209 if(!global.dataSendToSlaveIsValid) return; | |
38 | 210 |
211 global.dataSendToMaster.confirmRequest.uw = 0; | |
212 | |
213 if(TM_OTP_Read(0,0) == 0xFF) | |
214 { | |
215 if(global.dataSendToSlave.revisionHardware == (global.dataSendToSlave.revisionCRCx0x7A ^ 0x7A)) | |
216 TM_OTP_Write(0,0,global.dataSendToSlave.revisionHardware); | |
217 } | |
218 | |
219 if(global.dataSendToSlave.setAccidentFlag) | |
220 { | |
221 global.dataSendToMaster.confirmRequest.ub.accident = 1; | |
222 global.deviceData.diveAccident.value_int32 = global.dataSendToSlave.setAccidentFlag; | |
223 scheduleSetDate(&global.deviceData.diveAccident); | |
224 global.accidentFlag |= global.dataSendToSlave.setAccidentFlag; | |
225 if(global.accidentFlag == ACCIDENT_CNS) // LVL1 | |
226 global.accidentRemainingSeconds = 2*60*60; | |
227 else | |
228 global.accidentRemainingSeconds = 24*60*60; | |
229 } | |
230 | |
231 if(global.dataSendToSlave.setTimeNow) | |
232 { | |
233 global.dataSendToMaster.confirmRequest.ub.time = 1; | |
234 RTC_SetTime(global.dataSendToSlave.data.newTime); | |
235 schedule_update_timer_helper(0); | |
236 } | |
237 | |
238 if(global.dataSendToSlave.setDateNow) | |
239 { | |
240 global.dataSendToMaster.confirmRequest.ub.date = 1; | |
241 RTC_SetDate(global.dataSendToSlave.data.newDate); | |
242 schedule_update_timer_helper(0); | |
243 } | |
244 | |
245 if(global.dataSendToSlave.calibrateCompassNow) | |
246 { | |
247 global.dataSendToMaster.confirmRequest.ub.compass = 1; | |
248 global.mode = MODE_CALIB; | |
249 } | |
250 | |
251 if(global.dataSendToSlave.clearDecoNow) | |
252 { | |
253 global.dataSendToMaster.confirmRequest.ub.clearDeco = 1; | |
254 clearDecoNow = 1; | |
255 } | |
256 | |
257 if(global.dataSendToSlave.setButtonSensitivityNow) | |
258 { | |
259 global.dataSendToMaster.confirmRequest.ub.button = 1; | |
260 global.ButtonResponsiveness[0] = global.dataSendToSlave.data.buttonResponsiveness[0]; | |
261 global.ButtonResponsiveness[1] = global.dataSendToSlave.data.buttonResponsiveness[1]; | |
262 global.ButtonResponsiveness[2] = global.dataSendToSlave.data.buttonResponsiveness[2]; | |
263 global.ButtonResponsiveness[3] = global.dataSendToSlave.data.buttonResponsiveness[3]; | |
264 setButtonsNow = 1; | |
265 } | |
266 | |
267 if(global.dataSendToSlave.setBatteryGaugeNow) | |
268 { | |
104 | 269 if(global.mode!=MODE_CALIB){ |
38 | 270 global.dataSendToMaster.confirmRequest.ub.batterygauge = 1; |
271 battery_gas_gauge_set(global.dataSendToSlave.data.newBatteryGaugePercentageFloat); | |
104 | 272 } |
38 | 273 } |
274 | |
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
275 if(global.dataSendToSlave.setEndDive) |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
276 { |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
277 ManualExitDiveCounter = 30 * 60; /* This will cause the computer to leave dive mode if in shallow area and increase the depth to enter dive mode for the next 30 minutes */ |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
278 } |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
279 |
38 | 280 if((global.mode == MODE_SURFACE) && (global.dataSendToSlave.mode == MODE_SHUTDOWN)) |
281 { | |
282 global.mode = MODE_SHUTDOWN; | |
283 } | |
284 | |
285 if(global.mode == MODE_DIVE) | |
286 { | |
287 copyActualGas(global.dataSendToSlave.data.actualGas); | |
288 } | |
289 else | |
290 { | |
291 copyActualGas(Air); | |
292 global.settings.divetimeToCreateLogbook = global.dataSendToSlave.data.divetimeToCreateLogbook; | |
293 global.settings.timeoutDiveReachedZeroDepth = global.dataSendToSlave.data.timeoutDiveReachedZeroDepth; | |
294 } | |
295 | |
296 /* for simulation / testing */ | |
297 global.ceiling_from_main_CPU_mbar = global.dataSendToSlave.data.ambient_pressure_mbar_ceiling; | |
298 | |
338
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
299 /* Set pressure and temperature offsets */ |
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
300 pressure_set_offset (global.dataSendToSlave.data.offsetPressureSensor_mbar, global.dataSendToSlave.data.offsetTemperatureSensor_centiDegree); |
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
301 |
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
302 |
88 | 303 /* for device data updates */ |
304 deviceDataFlashValid = 0; | |
305 memcpy(&DeviceDataFlash, &global.dataSendToSlave.data.DeviceData, sizeof(SDevice)); | |
306 deviceDataFlashValid = 1; | |
89 | 307 |
662 | 308 |
309 /* handle external interface requests */ | |
310 | |
311 if((global.dataSendToSlave.data.externalInterface_Cmd && EXT_INTERFACE_33V_ON) != externalInterface_isEnabledPower33()) | |
312 { | |
313 externalInterface_SwitchPower33(global.dataSendToSlave.data.externalInterface_Cmd && EXT_INTERFACE_33V_ON); | |
314 } | |
315 | |
316 if(global.dataSendToSlave.data.externalInterface_Cmd > EXT_INTERFACE_33V_ON) | |
317 { | |
318 externalInterface_ExecuteCmd(global.dataSendToSlave.data.externalInterface_Cmd); | |
319 } | |
320 | |
321 | |
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
322 #if 0 |
104 | 323 //TODO: Temporary placed here. Duration ~210 ms. |
324 if (global.I2C_SystemStatus != HAL_OK) { | |
325 MX_I2C1_TestAndClear(); | |
326 MX_I2C1_Init(); | |
327 // init_pressure(); | |
328 // compass_init(0, 7); | |
329 // accelerator_init(); | |
330 } | |
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
331 #endif /* already called once a second */ |
38 | 332 } |
333 | |
334 | |
335 /** | |
336 ****************************************************************************** | |
337 * @brief schedule_time_compare_helper. | |
338 * @author heinrichs weikamp gmbh | |
339 * @version V0.0.1 | |
340 * @date 20-Oct-2016 | |
341 ****************************************************************************** | |
342 */ | |
343 | |
344 uint8_t RtcBugFixChsw(uint8_t inStupidTime) | |
345 { | |
346 uint8_t multiplesOf16 = 0; | |
347 | |
348 multiplesOf16 = inStupidTime / 16; | |
349 | |
350 inStupidTime -= multiplesOf16 * 16; | |
351 | |
352 return (10 * multiplesOf16) + inStupidTime; | |
353 } | |
354 | |
355 uint32_t schedule_time_compare_helper(RTC_TimeTypeDef timeNow, RTC_DateTypeDef dateNow, RTC_TimeTypeDef timeLast, RTC_DateTypeDef dateLast) | |
356 { | |
357 uint32_t nowInSeconds; | |
358 uint32_t lastInSeconds; | |
359 uint32_t resultDiff; | |
360 | |
361 nowInSeconds = (uint32_t)RtcBugFixChsw(timeNow.Hours) * 3600; | |
362 nowInSeconds += (uint32_t)RtcBugFixChsw(timeNow.Minutes) * 60; | |
363 nowInSeconds += (uint32_t)RtcBugFixChsw(timeNow.Seconds); | |
364 | |
365 lastInSeconds = (uint32_t)RtcBugFixChsw(timeLast.Hours) * 3600; | |
366 lastInSeconds += (uint32_t)RtcBugFixChsw(timeLast.Minutes) * 60; | |
367 lastInSeconds += (uint32_t)RtcBugFixChsw(timeLast.Seconds); | |
368 | |
369 if(dateNow.Date != dateLast.Date) | |
370 { | |
371 resultDiff = 86400 + nowInSeconds - lastInSeconds; | |
372 } | |
373 else | |
374 { | |
375 resultDiff = nowInSeconds - lastInSeconds; | |
376 } | |
377 return resultDiff; | |
378 } | |
379 | |
380 | |
381 | |
382 /** | |
383 ****************************************************************************** | |
384 * @brief schedule_update_timer_helper. | |
385 * @author heinrichs weikamp gmbh | |
386 * @version V0.0.1 | |
387 * @date 20-Oct-2016 | |
388 * @brief use 0 for init | |
389 use -1 for RTC controlled | |
390 use >= 1 for manual control | |
391 ****************************************************************************** | |
392 */ | |
393 extern RTC_HandleTypeDef RTCHandle; | |
394 | |
230
3973208c4a20
cleanup: make return void when never used
Jan Mulder <jlmulder@xs4all.nl>
parents:
220
diff
changeset
|
395 static void schedule_update_timer_helper(int8_t thisSeconds) |
38 | 396 { |
397 static RTC_TimeTypeDef sTimeLast; | |
398 static RTC_DateTypeDef sDateLast; | |
399 RTC_TimeTypeDef sTimeNow; | |
400 RTC_DateTypeDef sDateNow; | |
401 uint32_t secondsPast; | |
402 | |
403 HAL_RTC_GetTime(&RTCHandle, &sTimeNow, RTC_FORMAT_BCD); | |
404 HAL_RTC_GetDate(&RTCHandle, &sDateNow, RTC_FORMAT_BCD); | |
405 | |
230
3973208c4a20
cleanup: make return void when never used
Jan Mulder <jlmulder@xs4all.nl>
parents:
220
diff
changeset
|
406 if(thisSeconds != 0) // otherwise just store sTimeLast, sDateLast |
38 | 407 { |
408 if(thisSeconds > 0) // use this value instead, good for pre-loading sTimeLast and sDateLast | |
409 { | |
410 secondsPast = thisSeconds; | |
230
3973208c4a20
cleanup: make return void when never used
Jan Mulder <jlmulder@xs4all.nl>
parents:
220
diff
changeset
|
411 } else { |
3973208c4a20
cleanup: make return void when never used
Jan Mulder <jlmulder@xs4all.nl>
parents:
220
diff
changeset
|
412 // thisSeconds < 0 and not <= ! |
3973208c4a20
cleanup: make return void when never used
Jan Mulder <jlmulder@xs4all.nl>
parents:
220
diff
changeset
|
413 secondsPast = schedule_time_compare_helper(sTimeNow, sDateNow, sTimeLast, sDateLast); |
38 | 414 } |
415 | |
416 if(global.seconds_since_last_dive) | |
417 { | |
418 if(secondsPast >= 777900) | |
419 { | |
420 global.seconds_since_last_dive = 0; | |
421 } | |
422 else | |
423 { | |
230
3973208c4a20
cleanup: make return void when never used
Jan Mulder <jlmulder@xs4all.nl>
parents:
220
diff
changeset
|
424 uint32_t tempNewValue = ((uint32_t)global.seconds_since_last_dive) + secondsPast; |
38 | 425 if(tempNewValue > 777900) // a bit more than nine days [seconds] |
426 global.seconds_since_last_dive = 0; | |
427 else | |
428 global.seconds_since_last_dive = (long)tempNewValue; | |
429 } | |
430 } | |
431 } | |
432 | |
433 sTimeLast = sTimeNow; | |
434 sDateLast = sDateNow; | |
435 } | |
436 | |
437 /** | |
438 ****************************************************************************** | |
439 * @brief schedule_check_resync. | |
440 * @author heinrichs weikamp gmbh | |
441 * @version V0.0.2 | |
442 * @date 18-June-2015 | |
443 ****************************************************************************** | |
444 */ | |
135 | 445 |
38 | 446 void schedule_check_resync(void) |
447 { | |
155
4fd8bbc7d841
Do hard sync after communication timeout > 1 second
Ideenmodellierer
parents:
148
diff
changeset
|
448 /* counter is incremented in cyclic 100ms loop and reset to 0 if the transmission complete callback is called */ |
265
a91d99265884
Increase SPI com timeout for cold start and wake up
ideenmodellierer
parents:
264
diff
changeset
|
449 if((global.check_sync_not_running >= Scheduler.communicationTimeout)) |
38 | 450 { |
89 | 451 // global.dataSendToSlaveIsNotValidCount = 0; |
135 | 452 global.check_sync_not_running = 0; |
453 global.sync_error_count++; | |
454 | |
455 /* Try to start communication again. If exchange is stuck during execution for some reason the TX will be aborted by the | |
456 * function error handler | |
457 */ | |
277 | 458 HAL_SPI_TransmitReceive_DMA(&hspi1,(uint8_t*) &(global.dataSendToMaster),(uint8_t*) &(global.dataSendToSlave), EXCHANGE_BUFFERSIZE); |
265
a91d99265884
Increase SPI com timeout for cold start and wake up
ideenmodellierer
parents:
264
diff
changeset
|
459 Scheduler.communicationTimeout = SPI_COM_TIMEOUT_COMMON; /* Reduce error detection time */ |
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
460 Scheduler_Request_sync_with_SPI(SPI_SYNC_METHOD_HARD); |
155
4fd8bbc7d841
Do hard sync after communication timeout > 1 second
Ideenmodellierer
parents:
148
diff
changeset
|
461 } |
38 | 462 } |
463 | |
464 | |
465 /** | |
466 ****************************************************************************** | |
467 * @brief scheduleDiveMode. / Dive Mode: Main Loop | |
468 * @author Peter Ryser | |
469 * @version V0.0.1 | |
470 * @date 22-April-2014 | |
471 ****************************************************************************** | |
472 */ | |
473 void scheduleDiveMode(void) | |
474 { | |
475 uint32_t ticksdiff = 0; | |
476 uint32_t lasttick = 0; | |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
477 uint8_t extAdcChannel = 0; |
38 | 478 uint8_t counterAscentRate = 0; |
479 float lastPressure_bar = 0.0f; | |
480 global.dataSendToMaster.mode = MODE_DIVE; | |
481 global.deviceDataSendToMaster.mode = MODE_DIVE; | |
482 uint8_t counter_exit = 0; | |
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
483 |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
484 Scheduler.counterSPIdata100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
485 Scheduler.counterCompass100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
486 Scheduler.counterPressure100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
487 Scheduler.counterAmbientLight100msec = 0; |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
488 Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC; |
38 | 489 |
490 global.deviceData.diveCycles.value_int32++; | |
491 scheduleSetDate(&global.deviceData.diveCycles); | |
492 global.lifeData.counterSecondsShallowDepth = 0; | |
493 | |
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
494 /* Get the last stable value in case of an unstable surface history condition */ |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
495 if(!is_surface_pressure_stable()) |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
496 { |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
497 set_last_surface_pressure_stable(); |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
498 } |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
499 global.lifeData.pressure_surface_bar = get_surface_mbar() / 1000.0f; |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
500 ManualExitDiveCounter = 0; /* reset early exit request */ |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
501 |
240
625d20070261
Improvement SPI stability/recoverability
Jan Mulder <jlmulder@xs4all.nl>
parents:
231
diff
changeset
|
502 Scheduler.tickstart = HAL_GetTick(); |
38 | 503 while(global.mode == MODE_DIVE) |
504 { | |
505 lasttick = HAL_GetTick(); | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
506 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick); |
38 | 507 |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
508 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
509 { |
277 | 510 if(SPI_Evaluate_RX_Data()!=0) /* did we receive something ? */ |
511 { | |
512 Scheduler.counterSPIdata100msec++; | |
513 } | |
514 schedule_check_resync(); | |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
515 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
516 extAdcChannel = externalInterface_ReadAndSwitch(); |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
517 if(extAdcChannel != EXTERNAL_ADC_NO_DATA) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
518 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
519 externalInterface_CalculateADCValue(extAdcChannel); |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
520 copyExtADCdata(); |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
521 } |
662 | 522 copyExtCO2data(); |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
523 } |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
524 |
38 | 525 //Evaluate pressure at 20 ms, 120 ms, 220 ms,.... |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
526 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20) |
38 | 527 { |
528 global.check_sync_not_running++; | |
277 | 529 pressure_update_alternating(); |
135 | 530 scheduleUpdateDeviceData(); |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
181
diff
changeset
|
531 #ifdef DEMOMODE |
38 | 532 if(global.demo_mode) |
533 { | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
181
diff
changeset
|
534 int turbo_seconds = demo_modify_temperature_and_pressure(global.lifeData.dive_time_seconds, Scheduler.counterPressure100msec, global.ceiling_from_main_CPU_mbar); |
38 | 535 if(turbo_seconds) |
536 { | |
537 global.lifeData.dive_time_seconds += turbo_seconds; | |
538 decom_tissues_exposure((int)(turbo_seconds), &global.lifeData); | |
539 copyTissueData(); | |
540 } | |
541 if((global.lifeData.counterSecondsShallowDepth > 1) && (global.lifeData.counterSecondsShallowDepth < (global.settings.timeoutDiveReachedZeroDepth - 10))) | |
542 global.lifeData.counterSecondsShallowDepth = (global.settings.timeoutDiveReachedZeroDepth - 10); | |
543 } | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
181
diff
changeset
|
544 #endif |
38 | 545 |
546 //Calc ascentrate every two second (20 * 100 ms) | |
547 counterAscentRate++; | |
548 if(counterAscentRate == 20) | |
549 { | |
550 global.lifeData.pressure_ambient_bar = get_pressure_mbar() / 1000.0f; | |
551 if(lastPressure_bar >= 0) | |
552 { | |
553 //2 seconds * 30 == 1 minute, bar * 10 = meter | |
554 global.lifeData.ascent_rate_meter_per_min = (lastPressure_bar - global.lifeData.pressure_ambient_bar) * 30 * 10; | |
555 } | |
556 lastPressure_bar = global.lifeData.pressure_ambient_bar; | |
557 counterAscentRate = 0; | |
558 } | |
135 | 559 copyPressureData(); |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
560 Scheduler.counterPressure100msec++; |
38 | 561 } |
562 //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
|
563 if(ticksdiff >= Scheduler.counterCompass100msec * 100 + 50) |
135 | 564 { |
565 compass_read(); | |
566 acceleration_read(); | |
567 compass_calc(); | |
568 copyCompassData(); | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
569 Scheduler.counterCompass100msec++; |
135 | 570 } |
38 | 571 |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
572 if(ticksdiff >= Scheduler.counterAmbientLight100msec * 100 + 70) |
38 | 573 { |
574 adc_ambient_light_sensor_get_data(); | |
575 copyAmbientLightData(); | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
576 Scheduler.counterAmbientLight100msec++; |
38 | 577 } |
578 | |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
579 //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
|
580 if(ticksdiff >= Scheduler.tick_execute1second) |
38 | 581 { |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
582 Scheduler.tick_execute1second = 0xFFFFFFFF; /* execute once only in the second cycle */ |
38 | 583 if(global.dataSendToSlave.diveModeInfo != DIVEMODE_Apnea) |
584 { | |
585 scheduleUpdateLifeData(0); // includes tissues | |
586 global.lifeData.dive_time_seconds++; // there is dive_time_seconds_without_surface_time too | |
587 global.lifeData.ppO2 = decom_calc_ppO2(global.lifeData.pressure_ambient_bar, &global.lifeData.actualGas); | |
588 decom_oxygen_calculate_cns(&global.lifeData.cns,global.lifeData.ppO2); | |
589 decom_oxygen_calculate_otu(&global.lifeData.otu,global.lifeData.ppO2); | |
88 | 590 battery_gas_gauge_get_data(); |
38 | 591 |
592 | |
593 /** counter_exit allows safe exit via button for testing | |
594 * and demo_mode is exited too if aplicable. | |
595 */ | |
596 if(global.dataSendToMaster.mode == MODE_ENDDIVE) | |
597 { | |
598 counter_exit++; | |
599 if(counter_exit >= 2) | |
600 { | |
601 global.mode = MODE_SURFACE; | |
602 global.demo_mode = 0; | |
603 } | |
604 } | |
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
605 |
38 | 606 if(is_ambient_pressure_close_to_surface(&global.lifeData)) |
607 { | |
608 global.lifeData.counterSecondsShallowDepth++; | |
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
609 if((global.lifeData.counterSecondsShallowDepth >= global.settings.timeoutDiveReachedZeroDepth) || ((global.lifeData.dive_time_seconds < 60) && (global.demo_mode == 0)) |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
610 || (ManualExitDiveCounter)) |
38 | 611 { |
612 global.seconds_since_last_dive = 1; // start counter | |
613 schedule_update_timer_helper(0); // zum starten :-) | |
614 global.dataSendToMaster.mode = MODE_ENDDIVE; | |
615 global.deviceDataSendToMaster.mode = MODE_ENDDIVE; | |
616 } | |
617 } | |
618 else | |
619 { | |
620 global.lifeData.counterSecondsShallowDepth = 0; | |
621 global.lifeData.dive_time_seconds_without_surface_time++; | |
622 } | |
623 vpm_crush2(); | |
624 } | |
625 else // DIVEMODE_Apnea | |
626 { | |
627 global.lifeData.dive_time_seconds++; | |
628 | |
629 // exit dive mode | |
630 if(global.dataSendToMaster.mode == MODE_ENDDIVE) | |
631 { | |
632 counter_exit++; | |
633 if(counter_exit >= 2) | |
634 { | |
635 scheduleUpdateLifeData(-1); // 'restart' tissue calculations without calculating time during apnea mode | |
636 global.lifeData.dive_time_seconds = 0; // use backup noflytime and desaturation time | |
637 global.mode = MODE_SURFACE; | |
638 global.demo_mode = 0; | |
639 } | |
640 } | |
641 | |
642 // surface break | |
643 if(is_ambient_pressure_close_to_surface(&global.lifeData)) | |
644 { | |
645 global.lifeData.counterSecondsShallowDepth++; | |
646 if(global.lifeData.counterSecondsShallowDepth > 3) // time for main cpu to copy to apnea_last_dive_time_seconds | |
647 { | |
648 global.lifeData.dive_time_seconds = 0; // this apnea dive ends here | |
649 } | |
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
650 if((global.lifeData.counterSecondsShallowDepth >= global.settings.timeoutDiveReachedZeroDepth) || (ManualExitDiveCounter)) |
38 | 651 { |
652 global.dataSendToMaster.mode = MODE_ENDDIVE; | |
653 global.deviceDataSendToMaster.mode = MODE_ENDDIVE; | |
654 } | |
655 } | |
656 else | |
657 { | |
658 global.lifeData.counterSecondsShallowDepth = 0; | |
659 global.lifeData.dive_time_seconds_without_surface_time++; | |
660 } | |
661 } // standard dive or DIVEMODE_Apnea | |
662 | |
88 | 663 copyVpmCrushingData(); |
664 copyTimeData(); | |
665 copyCnsAndOtuData(); | |
666 copyBatteryData(); | |
38 | 667 |
88 | 668 // new hw 170523 |
669 if(global.I2C_SystemStatus != HAL_OK) | |
670 { | |
671 MX_I2C1_TestAndClear(); | |
488
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
672 HAL_Delay(100); |
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
673 I2C_DeInit(); |
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
674 HAL_Delay(100); |
88 | 675 MX_I2C1_Init(); |
488
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
676 HAL_Delay(100); |
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
677 |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
678 init_pressure(); |
88 | 679 } |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
680 } |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
681 if(ticksdiff >= 1000) |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
682 { |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
683 /* reset counter */ |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
684 Scheduler.tickstart = HAL_GetTick(); |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
685 Scheduler.counterSPIdata100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
686 Scheduler.counterCompass100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
687 Scheduler.counterPressure100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
688 Scheduler.counterAmbientLight100msec = 0; |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
689 Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC; |
38 | 690 } |
691 } | |
692 } | |
693 | |
694 | |
695 /** | |
696 ****************************************************************************** | |
697 * @brief scheduleSurfaceMode / surface mode: Main Loop | |
698 * @author Peter Ryser | |
699 * @version V0.0.1 | |
700 * @date 22-April-2014 | |
701 ****************************************************************************** | |
702 */ | |
703 | |
704 | |
705 // =============================================================================== | |
706 // scheduleTestMode | |
707 /// @brief included for sealed hardware with permanent RTE update message | |
708 // =============================================================================== | |
709 void scheduleTestMode(void) | |
710 { | |
711 uint32_t ticksdiff = 0; | |
712 uint32_t lasttick = 0; | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
713 Scheduler.tickstart = HAL_GetTick(); |
38 | 714 |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
715 Scheduler.counterPressure100msec = 0; |
38 | 716 |
717 float temperature_carousel = 0.0f; | |
718 float temperature_changer = 0.1f; | |
719 | |
720 while(global.mode == MODE_TEST) | |
721 { | |
722 lasttick = HAL_GetTick(); | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
723 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick); |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
724 |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
725 //Evaluate received data at 10 ms, 110 ms, 210 ms,... |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
726 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
727 { |
277 | 728 if(SPI_Evaluate_RX_Data()!=0) /* did we receive something ? */ |
729 { | |
730 Scheduler.counterSPIdata100msec++; | |
731 } | |
732 schedule_check_resync(); | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
733 } |
38 | 734 |
735 //Evaluate pressure at 20 ms, 120 ms, 220 ms,... | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
736 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20) |
38 | 737 { |
738 global.check_sync_not_running++; | |
739 | |
277 | 740 pressure_update_alternating(); |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
741 scheduleUpdateDeviceData(); |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
742 global.lifeData.ascent_rate_meter_per_min = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
743 copyPressureData(); |
38 | 744 |
745 if(temperature_carousel > 20.0f) | |
746 { | |
747 temperature_carousel = 20.0f; | |
748 temperature_changer = -0.1f; | |
749 } | |
750 else | |
751 if(temperature_carousel < 0) | |
752 { | |
753 temperature_carousel = 0; | |
754 temperature_changer = +0.1f; | |
755 } | |
756 | |
757 temperature_carousel += temperature_changer; | |
758 | |
759 uint8_t boolPressureData = !global.dataSendToMaster.boolPressureData; | |
760 | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
761 global.dataSendToMaster.data[boolPressureData].pressure_mbar = get_pressure_mbar(); |
38 | 762 |
763 global.dataSendToMaster.data[boolPressureData].temperature = temperature_carousel; | |
764 global.dataSendToMaster.data[boolPressureData].pressure_uTick = HAL_GetTick(); | |
765 global.dataSendToMaster.boolPressureData = boolPressureData; | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
766 Scheduler.counterPressure100msec++; |
38 | 767 } |
768 | |
769 if(ticksdiff >= 1000) | |
770 { | |
771 //Set back tick counter | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
772 Scheduler.tickstart = HAL_GetTick(); |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
773 Scheduler.counterPressure100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
774 Scheduler.counterSPIdata100msec = 0; |
38 | 775 } |
776 }; | |
777 } | |
778 | |
779 | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
780 |
38 | 781 void scheduleSurfaceMode(void) |
782 { | |
783 uint32_t ticksdiff = 0; | |
784 uint32_t lasttick = 0; | |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
785 uint8_t extAdcChannel = 0; |
662 | 786 uint8_t batteryToggle = 0; /* ADC is operating in automatic 2 second cycles => consider for battery charge function call */ |
787 | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
788 Scheduler.tickstart = HAL_GetTick(); |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
789 Scheduler.counterSPIdata100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
790 Scheduler.counterCompass100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
791 Scheduler.counterPressure100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
792 Scheduler.counterAmbientLight100msec = 0; |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
793 Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC; |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
794 |
38 | 795 global.dataSendToMaster.mode = MODE_SURFACE; |
796 global.deviceDataSendToMaster.mode = MODE_SURFACE; | |
797 | |
798 while(global.mode == MODE_SURFACE) | |
799 { | |
277 | 800 |
38 | 801 lasttick = HAL_GetTick(); |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
802 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick); |
38 | 803 |
804 if(setButtonsNow == 1) | |
805 { | |
806 if(scheduleSetButtonResponsiveness()) | |
807 setButtonsNow = 0; | |
808 } | |
809 | |
662 | 810 HandleUARTData(); |
811 | |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
812 /* 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
|
813 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
814 { |
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
815 if(SPI_Evaluate_RX_Data()!=0) /* did we receive something ? */ |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
816 { |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
817 Scheduler.counterSPIdata100msec++; |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
818 } |
277 | 819 schedule_check_resync(); |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
820 extAdcChannel = externalInterface_ReadAndSwitch(); |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
821 if(extAdcChannel != EXTERNAL_ADC_NO_DATA) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
822 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
823 externalInterface_CalculateADCValue(extAdcChannel); |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
824 copyExtADCdata(); |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
825 } |
662 | 826 copyExtCO2data(); |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
827 } |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
828 |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
829 /* 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
|
830 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20) |
38 | 831 { |
832 global.check_sync_not_running++; | |
277 | 833 pressure_update_alternating(); |
135 | 834 scheduleUpdateDeviceData(); |
38 | 835 global.lifeData.ascent_rate_meter_per_min = 0; |
135 | 836 copyPressureData(); |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
837 Scheduler.counterPressure100msec++; |
135 | 838 |
301
a09b1855d656
cleanup, RTE: factor out scheduleCheck_pressure_reached_dive_mode_level
Jan Mulder <jlmulder@xs4all.nl>
parents:
277
diff
changeset
|
839 if (!is_ambient_pressure_close_to_surface(&global.lifeData)) |
38 | 840 global.mode = MODE_DIVE; |
841 } | |
842 | |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
843 /* 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
|
844 if(ticksdiff >= Scheduler.counterCompass100msec * 100 + 50) |
135 | 845 { |
846 compass_read(); | |
847 acceleration_read(); | |
848 compass_calc(); | |
849 copyCompassData(); | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
850 Scheduler.counterCompass100msec++; |
135 | 851 } |
38 | 852 |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
853 /* 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
|
854 if(ticksdiff >= Scheduler.counterAmbientLight100msec * 100 + 70) |
38 | 855 { |
856 adc_ambient_light_sensor_get_data(); | |
857 copyAmbientLightData(); | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
858 Scheduler.counterAmbientLight100msec++; |
38 | 859 } |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
860 |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
861 |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
862 |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
863 /* 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
|
864 if(ticksdiff >= Scheduler.tick_execute1second) |
38 | 865 { |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
866 Scheduler.tick_execute1second = 0xFFFFFFFF; |
38 | 867 if(clearDecoNow) |
868 { | |
869 decom_reset_with_1000mbar(&global.lifeData); ///< this should almost reset desaturation time | |
870 // new 160215 hw | |
871 global.repetitive_dive = 0; | |
872 global.seconds_since_last_dive = 0; ///< this will reset OTU and CNS as well | |
873 global.no_fly_time_minutes = 0; | |
874 global.accidentFlag = 0; | |
875 global.accidentRemainingSeconds = 0; | |
876 vpm_init(&global.vpm, global.conservatism, global.repetitive_dive, global.seconds_since_last_dive); | |
877 clearDecoNow = 0; | |
878 } | |
89 | 879 |
349
9d82411d0afa
Decrease ManualExitDiveCounter in surface mode
ideenmodellierer
parents:
346
diff
changeset
|
880 if(ManualExitDiveCounter) |
9d82411d0afa
Decrease ManualExitDiveCounter in surface mode
ideenmodellierer
parents:
346
diff
changeset
|
881 { |
9d82411d0afa
Decrease ManualExitDiveCounter in surface mode
ideenmodellierer
parents:
346
diff
changeset
|
882 ManualExitDiveCounter--; |
9d82411d0afa
Decrease ManualExitDiveCounter in surface mode
ideenmodellierer
parents:
346
diff
changeset
|
883 } |
9d82411d0afa
Decrease ManualExitDiveCounter in surface mode
ideenmodellierer
parents:
346
diff
changeset
|
884 |
38 | 885 if(global.seconds_since_last_dive) |
886 { | |
887 schedule_update_timer_helper(-1); | |
888 } | |
89 | 889 |
38 | 890 if(global.accidentRemainingSeconds) |
891 { | |
892 global.accidentRemainingSeconds--; | |
893 if(!global.accidentRemainingSeconds) | |
894 global.accidentFlag = 0; | |
895 } | |
896 global.dataSendToMaster.accidentFlags = global.accidentFlag; | |
89 | 897 |
38 | 898 update_surface_pressure(1); |
899 scheduleUpdateLifeData(0); | |
900 decom_oxygen_calculate_otu_degrade(&global.lifeData.otu, global.seconds_since_last_dive); | |
901 decom_oxygen_calculate_cns_degrade(&global.lifeData.cns, global.seconds_since_last_dive); | |
135 | 902 |
903 /* start desaturation calculation after first valid measurement has been done */ | |
904 if(global.lifeData.pressure_surface_bar != INVALID_PREASURE_VALUE) | |
905 { | |
906 global.lifeData.desaturation_time_minutes = decom_calc_desaturation_time(global.lifeData.tissue_nitrogen_bar,global.lifeData.tissue_helium_bar,global.lifeData.pressure_surface_bar); | |
907 } | |
908 else | |
909 { | |
910 global.lifeData.desaturation_time_minutes = 0; | |
911 } | |
662 | 912 |
913 if(!batteryToggle) | |
914 { | |
915 battery_gas_gauge_get_data(); | |
916 battery_charger_get_status_and_contral_battery_gas_gauge(2); | |
917 batteryToggle = 1; | |
918 } | |
919 else | |
920 { | |
921 batteryToggle = 0; | |
922 } | |
89 | 923 |
88 | 924 copyCnsAndOtuData(); |
925 copyTimeData(); | |
926 copyBatteryData(); | |
927 copyDeviceData(); | |
38 | 928 |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
929 /* check if I2C is not up an running and try to reactivate if necessary. Also do initialization if problem occured during startup */ |
88 | 930 if(global.I2C_SystemStatus != HAL_OK) |
931 { | |
932 MX_I2C1_TestAndClear(); | |
488
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
933 HAL_Delay(100); |
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
934 I2C_DeInit(); |
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
935 HAL_Delay(100); |
88 | 936 MX_I2C1_Init(); |
488
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
937 HAL_Delay(100); |
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
938 |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
939 if(global.I2C_SystemStatus == HAL_OK) |
88 | 940 { |
941 init_pressure(); | |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
942 if(is_init_pressure_done()) /* Init surface data with initial measurement */ |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
943 { |
338
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
944 init_surface_ring(0); |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
945 } |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
946 |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
947 if(!battery_gas_gauge_CheckConfigOK()) |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
948 { |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
949 init_battery_gas_gauge(); |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
950 } |
88 | 951 } |
952 } | |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
953 } |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
954 |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
955 if(ticksdiff >= 1000) |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
956 { |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
957 //Set back tick counter |
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
958 Scheduler.tickstart = HAL_GetTick(); |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
959 Scheduler.counterSPIdata100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
960 Scheduler.counterCompass100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
961 Scheduler.counterPressure100msec = 0; |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
962 Scheduler.counterAmbientLight100msec = 0; |
220
e524a824d8f2
Added schedule point for functions executed once in a second
ideenmodellierer
parents:
207
diff
changeset
|
963 Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC; |
38 | 964 } |
965 } | |
966 } | |
967 | |
207 | 968 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
|
969 { |
207 | 970 if( SyncMethod < SPI_SYNC_METHOD_INVALID) |
971 { | |
972 dospisync = SyncMethod; | |
973 } | |
974 } | |
975 | |
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
976 void Scheduler_SyncToSPI(uint8_t TXtick) |
207 | 977 { |
978 uint32_t deltatick = 0; | |
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
979 int8_t TXcompensation; |
207 | 980 |
981 switch(dospisync) | |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
982 { |
207 | 983 case SPI_SYNC_METHOD_HARD: |
984 //Set back tick counter | |
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
985 Scheduler.tickstart = HAL_GetTick() - 4; /* consider 4ms offset for transfer */ |
207 | 986 Scheduler.counterSPIdata100msec = 0; |
987 Scheduler.counterCompass100msec = 0; | |
988 Scheduler.counterPressure100msec = 0; | |
989 Scheduler.counterAmbientLight100msec = 0; | |
990 dospisync = SPI_SYNC_METHOD_NONE; | |
991 break; | |
992 case SPI_SYNC_METHOD_SOFT: | |
993 deltatick = time_elapsed_ms(Scheduler.tickstart,HAL_GetTick()); | |
994 deltatick %= 100; /* clip to 100ms window */ | |
995 if(Scheduler.tickstart - deltatick >= 0) /* adjust start time to the next 100ms window */ | |
996 { | |
997 Scheduler.tickstart -= deltatick; | |
998 } | |
999 else | |
1000 { | |
1001 Scheduler.tickstart = 0xFFFFFFFF- (deltatick - Scheduler.tickstart); | |
1002 } | |
1003 dospisync = SPI_SYNC_METHOD_NONE; | |
1004 break; | |
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1005 default: /* continous sync activity */ |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1006 if(TXtick < 100) /* do not handle unexpected jump length > 100ms */ |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1007 { |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1008 TXtick += 4; /* add 4ms TX time to offset of 100ms time stamp */ |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1009 deltatick = time_elapsed_ms(Scheduler.tickstart,HAL_GetTick()); |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1010 deltatick %= 100; |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1011 if(deltatick > 50) |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1012 { |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1013 TXcompensation = deltatick - 100; /* neg drift */ |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1014 } |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1015 else |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1016 { |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1017 TXcompensation = deltatick; /* pos drift */ |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1018 } |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1019 TXcompensation = TXtick - TXcompensation; |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1020 Scheduler.tickstart -= TXcompensation; |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1021 } |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1022 else |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1023 { |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1024 Scheduler_Request_sync_with_SPI(SPI_SYNC_METHOD_SOFT); /* A large shift in 100ms cycle occured => clip to 100ms in next sync call */ |
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1025 } |
207 | 1026 break; |
142
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
1027 } |
69f4b8067daa
Use one global structure for all schedule counters
Ideenmodellierer
parents:
135
diff
changeset
|
1028 } |
38 | 1029 |
1030 /** | |
1031 ****************************************************************************** | |
1032 * @brief scheduleCompassCalibrationMode | |
1033 * @author heinrichs weikamp gmbh | |
1034 * @version V0.0.1 | |
1035 * @since 31-March-2015 | |
1036 * @date 31-March-2015 | |
1037 ****************************************************************************** | |
1038 */ | |
1039 void scheduleCompassCalibrationMode(void) | |
1040 { | |
1041 compass_init(1,7); // fast mode, max gain | |
1042 compass_calib(); // duration : 1 minute! | |
1043 compass_init(0,7); // back to normal mode | |
1044 | |
1045 if(global.seconds_since_last_dive) | |
1046 { | |
1047 schedule_update_timer_helper(-1); | |
1048 } | |
1049 | |
1050 scheduleUpdateLifeData(0); | |
1051 global.mode = MODE_SURFACE; | |
1052 } | |
1053 | |
1054 | |
1055 /** | |
1056 ****************************************************************************** | |
1057 * @brief scheduleSleepMode / sleep mode: Main Loop | |
1058 * @author heinrichs weikamp gmbh | |
1059 * @version V0.0.2 | |
1060 * @since 31-March-2015 | |
1061 * @date 22-April-2014 | |
1062 ****************************************************************************** | |
1063 */ | |
1064 | |
1065 void scheduleSleepMode(void) | |
1066 { | |
1067 global.dataSendToMaster.mode = 0; | |
1068 global.deviceDataSendToMaster.mode = 0; | |
668 | 1069 secondsCount = 0; |
38 | 1070 |
1071 /* prevent button wake up problem while in sleep_prepare | |
1072 * sleep prepare does I2C_DeInit() | |
1073 */ | |
1074 if(global.mode != MODE_SLEEP) | |
1075 MX_I2C1_Init(); | |
1076 else | |
1077 do | |
1078 { | |
1079 I2C_DeInit(); | |
1080 | |
1081 #ifdef DEBUGMODE | |
1082 HAL_Delay(2000); | |
1083 #else | |
1084 RTC_StopMode_2seconds(); | |
1085 #endif | |
1086 | |
1087 | |
1088 | |
1089 if(global.mode == MODE_SLEEP) | |
1090 secondsCount += 2; | |
1091 | |
662 | 1092 externalInterface_InitPower33(); |
38 | 1093 MX_I2C1_Init(); |
1094 pressure_sensor_get_pressure_raw(); | |
1095 | |
475 | 1096 /* check if I2C is not up and running and try to reactivate if necessary. Also do initialization if problem occurred during startup */ |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1097 if(global.I2C_SystemStatus != HAL_OK) |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1098 { |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1099 MX_I2C1_TestAndClear(); |
488
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
1100 HAL_Delay(100); |
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
1101 I2C_DeInit(); |
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
1102 HAL_Delay(100); |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1103 MX_I2C1_Init(); |
488
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
1104 HAL_Delay(100); |
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
475
diff
changeset
|
1105 |
475 | 1106 if((global.I2C_SystemStatus == HAL_OK) && (!is_init_pressure_done())) |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1107 { |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1108 init_pressure(); |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1109 } |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1110 } |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1111 |
38 | 1112 if(secondsCount >= 30) |
1113 { | |
1114 pressure_sensor_get_temperature_raw(); | |
1115 battery_gas_gauge_get_data(); | |
662 | 1116 ReInit_battery_charger_status_pins(); |
643
5149cd644fbc
Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents:
554
diff
changeset
|
1117 battery_charger_get_status_and_contral_battery_gas_gauge(30); |
38 | 1118 // DeInit_battery_charger_status_pins(); |
1119 secondsCount = 0; | |
1120 } | |
1121 | |
1122 pressure_calculation(); | |
1123 | |
1124 scheduleUpdateDeviceData(); | |
1125 update_surface_pressure(2); | |
1126 | |
1127 if(global.seconds_since_last_dive) | |
1128 { | |
1129 schedule_update_timer_helper(-1); | |
1130 } | |
1131 | |
1132 if(global.accidentRemainingSeconds) | |
1133 { | |
1134 if(global.accidentRemainingSeconds > 2) | |
1135 global.accidentRemainingSeconds -= 2; | |
1136 else | |
1137 { | |
1138 global.accidentRemainingSeconds = 0; | |
1139 global.accidentFlag = 0; | |
1140 } | |
1141 } | |
1142 | |
338
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
1143 if (((!is_ambient_pressure_close_to_surface(&global.lifeData)) && (global.lifeData.pressure_surface_bar > START_DIVE_MOUNTAIN_MODE_BAR )) |
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
1144 || (global.lifeData.pressure_ambient_bar > START_DIVE_IMMEDIATLY_BAR)) |
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
1145 { |
38 | 1146 global.mode = MODE_BOOT; |
338
b6a59e93cc91
Added function to avoid divemode activation during Landing:
ideenmodellierer
parents:
331
diff
changeset
|
1147 } |
38 | 1148 scheduleUpdateLifeData(2000); |
1149 } | |
1150 while(global.mode == MODE_SLEEP); | |
1151 /* new section for system after Standby */ | |
1152 scheduleUpdateLifeData(-1); | |
1153 clearDecoNow = 0; | |
1154 setButtonsNow = 0; | |
264
b3685fbada3b
Sync to Main 100ms time stamp & added Reinitialization of globals after startup
ideenmodellierer
parents:
240
diff
changeset
|
1155 reinitGlobals(); |
668 | 1156 ReInit_battery_charger_status_pins(); |
38 | 1157 } |
1158 | |
1159 | |
1160 | |
1161 /* Private functions ---------------------------------------------------------*/ | |
1162 | |
1163 /** | |
1164 ****************************************************************************** | |
1165 * @brief scheduleUpdateLifeData / calculates tissues | |
1166 * @author Peter Ryser | |
1167 * @version V0.0.1 | |
1168 * @date 22-April-2014 | |
1169 ****************************************************************************** | |
1170 */ | |
1171 | |
1172 | |
1173 void scheduleUpdateLifeData(int32_t asynchron_milliseconds_since_last) | |
1174 { | |
1175 static _Bool first = 1; | |
1176 static uint32_t tickstart = 0; | |
1177 static uint32_t ticksrest = 0; | |
1178 | |
1179 uint32_t ticksdiff = 0; | |
1180 uint32_t ticksnow = 0; | |
1181 uint32_t time_seconds = 0; | |
1182 uint8_t whichGasTmp = 0; | |
1183 | |
135 | 1184 uint8_t updateTissueData = 0; |
1185 | |
1186 | |
1187 if(global.lifeData.pressure_surface_bar == INVALID_PREASURE_VALUE) | |
1188 { | |
1189 updateTissueData = 1; | |
1190 } | |
1191 | |
38 | 1192 if(asynchron_milliseconds_since_last < 0) |
1193 { | |
1194 first = 1; | |
1195 tickstart = 0; | |
1196 ticksrest = 0; | |
1197 return; | |
1198 } | |
1199 | |
1200 if(!asynchron_milliseconds_since_last && first) | |
1201 { | |
1202 tickstart = HAL_GetTick(); | |
1203 first = 0; | |
1204 return; | |
1205 } | |
1206 | |
1207 whichGasTmp = global.whichGas; | |
1208 global.lifeData.actualGas = global.aktualGas[whichGasTmp]; | |
1209 global.lifeData.pressure_ambient_bar = get_pressure_mbar() / 1000.0f; | |
1210 global.lifeData.pressure_surface_bar = get_surface_mbar() / 1000.0f; | |
1211 | |
135 | 1212 if(updateTissueData) |
1213 { | |
1214 decom_reset_with_ambientmbar(global.lifeData.pressure_surface_bar,&global.lifeData); | |
1215 } | |
1216 | |
38 | 1217 if(!asynchron_milliseconds_since_last) |
1218 { | |
1219 ticksnow = HAL_GetTick(); | |
1220 ticksdiff = time_elapsed_ms(tickstart,ticksnow); | |
1221 } | |
1222 else | |
1223 { | |
1224 first = 1; | |
1225 ticksdiff = asynchron_milliseconds_since_last; | |
1226 } | |
1227 | |
1228 if(ticksrest > 1000) // whatever happens after standby with STM32L476 | |
1229 ticksrest = 0; // maybe move static to SRAM2 | |
1230 | |
1231 ticksdiff += ticksrest; | |
1232 time_seconds = ticksdiff/ 1000; | |
1233 ticksrest = ticksdiff - time_seconds * 1000; | |
1234 tickstart = ticksnow; | |
1235 | |
1236 decom_tissues_exposure((int)time_seconds, &global.lifeData); | |
1237 if(global.demo_mode) | |
1238 decom_tissues_exposure((int)(3*time_seconds), &global.lifeData); | |
1239 copyTissueData(); | |
1240 } | |
1241 | |
1242 | |
1243 /** | |
1244 ****************************************************************************** | |
1245 * @brief scheduleUpdateDeviceData | |
1246 * @author heinrichs weikamp gmbh | |
1247 * @version V0.0.1 | |
1248 * @date 16-March-2015 | |
1249 * | |
1250 * two step process | |
1251 * first compare with data from main CPU == externalLogbookFlash | |
1252 * second update with new sensor data | |
1253 ****************************************************************************** | |
1254 */ | |
1255 void scheduleSetDate(SDeviceLine *line) | |
1256 { | |
1257 extern RTC_HandleTypeDef RTCHandle; | |
1258 | |
1259 line->date_rtc_dr = (uint32_t)(RTCHandle.Instance->DR & RTC_DR_RESERVED_MASK); | |
1260 line->time_rtc_tr = (uint32_t)(RTCHandle.Instance->TR & RTC_TR_RESERVED_MASK); | |
1261 } | |
1262 | |
1263 | |
1264 void scheduleCopyDeviceData(SDeviceLine *lineWrite, const SDeviceLine *lineRead) | |
1265 { | |
1266 lineWrite->date_rtc_dr = lineRead->date_rtc_dr; | |
1267 lineWrite->time_rtc_tr = lineRead->time_rtc_tr; | |
1268 lineWrite->value_int32 = lineRead->value_int32; | |
1269 } | |
1270 | |
1271 | |
409
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1272 void scheduletranslateDate(uint32_t datetmpreg, RTC_DateTypeDef *sDate) |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1273 { |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1274 datetmpreg = (uint32_t)(datetmpreg & RTC_DR_RESERVED_MASK); |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1275 |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1276 /* Fill the structure fields with the read parameters */ |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1277 sDate->Year = (uint8_t)((datetmpreg & (RTC_DR_YT | RTC_DR_YU)) >> 16); |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1278 sDate->Month = (uint8_t)((datetmpreg & (RTC_DR_MT | RTC_DR_MU)) >> 8); |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1279 sDate->Date = (uint8_t)(datetmpreg & (RTC_DR_DT | RTC_DR_DU)); |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1280 sDate->WeekDay = (uint8_t)((datetmpreg & (RTC_DR_WDU)) >> 13); |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1281 |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1282 /* Convert the date structure parameters to Binary format */ |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1283 sDate->Year = (uint8_t)RTC_Bcd2ToByte(sDate->Year); |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1284 sDate->Month = (uint8_t)RTC_Bcd2ToByte(sDate->Month); |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1285 sDate->Date = (uint8_t)RTC_Bcd2ToByte(sDate->Date); |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1286 } |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1287 |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1288 void scheduleCheckDate(void) |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1289 { |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1290 uint32_t localdate; |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1291 RTC_DateTypeDef sDate; |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1292 localdate = (uint32_t)(RTCHandle.Instance->DR & RTC_DR_RESERVED_MASK); |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1293 scheduletranslateDate(localdate, &sDate); |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1294 |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1295 /* RTC start in year 2000 in case of a power loss. Use the operation counter time stamp to bring at last date to a more realistic value */ |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1296 if(sDate.Year < 15) |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1297 { |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1298 scheduletranslateDate(DeviceDataFlash.hoursOfOperation.date_rtc_dr, &sDate); |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1299 if(sDate.Year > 16) |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1300 { |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1301 RTC_SetDate(sDate); |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1302 } |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1303 } |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1304 |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1305 } |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1306 |
38 | 1307 void scheduleUpdateDeviceData(void) |
1308 { | |
1309 /* first step, main CPU */ | |
1310 | |
1311 if(deviceDataFlashValid) | |
1312 { | |
1313 /* max values */ | |
409
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1314 if(global.deviceData.hoursOfOperation.value_int32 < DeviceDataFlash.hoursOfOperation.value_int32) |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1315 { |
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1316 scheduleCopyDeviceData(&global.deviceData.hoursOfOperation, &DeviceDataFlash.hoursOfOperation); |
414
6886aeeca454
Added compile switch for restoring of last known date after power lost:
ideenmodellierer
parents:
409
diff
changeset
|
1317 #ifdef RESTORE_LAST_KNOWN_DATE |
409
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1318 scheduleCheckDate(); |
414
6886aeeca454
Added compile switch for restoring of last known date after power lost:
ideenmodellierer
parents:
409
diff
changeset
|
1319 #endif |
409
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1320 } |
38 | 1321 if(global.deviceData.batteryChargeCompleteCycles.value_int32 < DeviceDataFlash.batteryChargeCompleteCycles.value_int32) |
1322 { | |
1323 scheduleCopyDeviceData(&global.deviceData.batteryChargeCompleteCycles, &DeviceDataFlash.batteryChargeCompleteCycles); | |
1324 } | |
1325 if(global.deviceData.batteryChargeCycles.value_int32 < DeviceDataFlash.batteryChargeCycles.value_int32) | |
1326 { | |
1327 scheduleCopyDeviceData(&global.deviceData.batteryChargeCycles, &DeviceDataFlash.batteryChargeCycles); | |
1328 } | |
1329 if(global.deviceData.temperatureMaximum.value_int32 < DeviceDataFlash.temperatureMaximum.value_int32) | |
1330 { | |
1331 scheduleCopyDeviceData(&global.deviceData.temperatureMaximum, &DeviceDataFlash.temperatureMaximum); | |
1332 } | |
1333 if(global.deviceData.depthMaximum.value_int32 < DeviceDataFlash.depthMaximum.value_int32) | |
1334 { | |
1335 scheduleCopyDeviceData(&global.deviceData.depthMaximum, &DeviceDataFlash.depthMaximum); | |
1336 } | |
1337 if(global.deviceData.diveCycles.value_int32 < DeviceDataFlash.diveCycles.value_int32) | |
1338 { | |
1339 scheduleCopyDeviceData(&global.deviceData.diveCycles, &DeviceDataFlash.diveCycles); | |
1340 } | |
1341 | |
1342 /* min values */ | |
1343 if(global.deviceData.temperatureMinimum.value_int32 > DeviceDataFlash.temperatureMinimum.value_int32) | |
1344 { | |
1345 scheduleCopyDeviceData(&global.deviceData.temperatureMinimum, &DeviceDataFlash.temperatureMinimum); | |
1346 } | |
1347 if(global.deviceData.voltageMinimum.value_int32 > DeviceDataFlash.voltageMinimum.value_int32) | |
1348 { | |
1349 scheduleCopyDeviceData(&global.deviceData.voltageMinimum, &DeviceDataFlash.voltageMinimum); | |
1350 } | |
1351 } | |
1352 | |
1353 /* second step, sensor data */ | |
1354 int32_t temperature_centigrad_int32; | |
1355 int32_t pressure_mbar_int32; | |
1356 int32_t voltage_mvolt_int32; | |
1357 | |
1358 temperature_centigrad_int32 = (int32_t)(get_temperature() * 100); | |
1359 if(temperature_centigrad_int32 < global.deviceData.temperatureMinimum.value_int32) | |
1360 { | |
1361 global.deviceData.temperatureMinimum.value_int32 = temperature_centigrad_int32; | |
88 | 1362 scheduleSetDate(&global.deviceData.temperatureMinimum); |
38 | 1363 } |
1364 | |
1365 if(temperature_centigrad_int32 > global.deviceData.temperatureMaximum.value_int32) | |
1366 { | |
1367 global.deviceData.temperatureMaximum.value_int32 = temperature_centigrad_int32; | |
88 | 1368 scheduleSetDate(&global.deviceData.temperatureMaximum); |
38 | 1369 } |
1370 | |
1371 pressure_mbar_int32 = (int32_t)get_pressure_mbar(); | |
1372 if(pressure_mbar_int32 > global.deviceData.depthMaximum.value_int32) | |
1373 { | |
1374 global.deviceData.depthMaximum.value_int32 = pressure_mbar_int32; | |
88 | 1375 scheduleSetDate(&global.deviceData.depthMaximum); |
38 | 1376 } |
1377 | |
1378 voltage_mvolt_int32 = (int32_t)(get_voltage() * 1000); | |
1379 if(voltage_mvolt_int32 < global.deviceData.voltageMinimum.value_int32) | |
1380 { | |
1381 global.deviceData.voltageMinimum.value_int32 = voltage_mvolt_int32; | |
88 | 1382 scheduleSetDate(&global.deviceData.voltageMinimum); |
38 | 1383 } |
1384 | |
1385 /* third step, counter */ | |
1386 switch (global.mode) | |
1387 { | |
1388 case MODE_SURFACE: | |
1389 case MODE_DIVE: | |
1390 default: | |
1391 deviceDataSubSeconds++; | |
1392 if(deviceDataSubSeconds > 10) | |
1393 { | |
1394 deviceDataSubSeconds = 0; | |
1395 global.deviceData.hoursOfOperation.value_int32++; | |
409
2e2d34c1cc99
Restore last known date: After a power off RTC looses time data and restarts in the year 2000. Code will fix this date to the year 2016. This change will set the date to the last known date of the operation hour counter
ideenmodellierer
parents:
356
diff
changeset
|
1396 scheduleSetDate(&global.deviceData.hoursOfOperation); |
38 | 1397 } |
1398 break; | |
1399 | |
662 | 1400 case MODE_SLEEP: |
38 | 1401 case MODE_SHUTDOWN: |
1402 break; | |
1403 } | |
1404 } | |
1405 | |
1406 | |
1407 void scheduleUpdateDeviceDataChargerFull(void) | |
1408 { | |
1409 global.deviceData.batteryChargeCompleteCycles.value_int32++; | |
88 | 1410 scheduleSetDate(&global.deviceData.batteryChargeCompleteCycles); |
38 | 1411 } |
1412 | |
1413 | |
1414 void scheduleUpdateDeviceDataChargerCharging(void) | |
1415 { | |
1416 global.deviceData.batteryChargeCycles.value_int32++; | |
88 | 1417 scheduleSetDate(&global.deviceData.batteryChargeCycles); |
38 | 1418 } |
1419 | |
1420 | |
1421 /** | |
1422 ****************************************************************************** | |
1423 * @brief vpm_crush / calls vpm calc_crushing_pressure every four seconds during descend | |
1424 * @author Peter Ryser | |
1425 * @version V0.0.1 | |
1426 * @date 22-April-2014 | |
1427 ****************************************************************************** | |
1428 */ | |
1429 _Bool vpm_crush2(void) | |
1430 { | |
1431 int i = 0; | |
1432 static float starting_ambient_pressure = 0; | |
1433 static float ending_ambient_pressure = 0; | |
1434 static float time_calc_begin = -1; | |
1435 static float initial_helium_pressure[16]; | |
1436 static float initial_nitrogen_pressure[16]; | |
1437 ending_ambient_pressure = global.lifeData.pressure_ambient_bar * 10; | |
1438 | |
1439 if((global.lifeData.dive_time_seconds <= 4) || (starting_ambient_pressure >= ending_ambient_pressure)) | |
1440 { | |
1441 time_calc_begin = global.lifeData.dive_time_seconds; | |
1442 starting_ambient_pressure = global.lifeData.pressure_ambient_bar * 10; | |
1443 for( i = 0; i < 16; i++) | |
1444 { | |
1445 initial_helium_pressure[i] = global.lifeData.tissue_helium_bar[i] * 10; | |
1446 initial_nitrogen_pressure[i] = global.lifeData.tissue_nitrogen_bar[i] * 10; | |
1447 } | |
1448 return 0; | |
1449 } | |
1450 if(global.lifeData.dive_time_seconds - time_calc_begin >= 4) | |
1451 { | |
1452 if(ending_ambient_pressure > starting_ambient_pressure + 0.5f) | |
1453 { | |
1454 float rate = (ending_ambient_pressure - starting_ambient_pressure) * 60 / 4; | |
1455 calc_crushing_pressure(&global.lifeData, &global.vpm, initial_helium_pressure, initial_nitrogen_pressure, starting_ambient_pressure, rate); | |
1456 | |
1457 time_calc_begin = global.lifeData.dive_time_seconds; | |
1458 starting_ambient_pressure = global.lifeData.pressure_ambient_bar * 10; | |
1459 for( i = 0; i < 16; i++) | |
1460 { | |
1461 initial_helium_pressure[i] = global.lifeData.tissue_helium_bar[i] * 10; | |
1462 initial_nitrogen_pressure[i] = global.lifeData.tissue_nitrogen_bar[i] * 10; | |
1463 } | |
1464 | |
1465 return 1; | |
1466 } | |
1467 | |
1468 } | |
1469 return 0; | |
1470 } | |
1471 | |
1472 | |
1473 long get_nofly_time_minutes(void) | |
1474 { | |
1475 | |
1476 if(global.no_fly_time_minutes <= 0) | |
1477 return 0; | |
1478 | |
1479 long minutes_since_last_dive = global.seconds_since_last_dive/60; | |
1480 | |
1481 if((global.seconds_since_last_dive > 0) && (global.no_fly_time_minutes > minutes_since_last_dive)) | |
1482 { | |
1483 return (global.no_fly_time_minutes - minutes_since_last_dive); | |
1484 } | |
1485 else | |
1486 { | |
1487 global.no_fly_time_minutes = 0; | |
1488 return 0; | |
1489 } | |
1490 } | |
1491 | |
1492 | |
1493 //Supports threadsave copying!!! | |
1494 void copyActualGas(SGas gas) | |
1495 { | |
1496 uint8_t whichGas = !global.whichGas; | |
1497 global.aktualGas[whichGas] = gas; | |
1498 global.whichGas = whichGas; | |
1499 } | |
1500 | |
1501 | |
1502 //Supports threadsave copying!!! | |
1503 void copyPressureData(void) | |
1504 { | |
240
625d20070261
Improvement SPI stability/recoverability
Jan Mulder <jlmulder@xs4all.nl>
parents:
231
diff
changeset
|
1505 global.dataSendToMaster.sensorErrors = global.I2C_SystemStatus; |
38 | 1506 uint8_t boolPressureData = !global.dataSendToMaster.boolPressureData; |
1507 global.dataSendToMaster.data[boolPressureData].temperature = get_temperature(); | |
1508 global.dataSendToMaster.data[boolPressureData].pressure_mbar = get_pressure_mbar(); | |
1509 global.dataSendToMaster.data[boolPressureData].surface_mbar = get_surface_mbar(); | |
1510 global.dataSendToMaster.data[boolPressureData].ascent_rate_meter_per_min = global.lifeData.ascent_rate_meter_per_min; | |
1511 global.dataSendToMaster.data[boolPressureData].pressure_uTick = HAL_GetTick(); | |
1512 global.dataSendToMaster.boolPressureData = boolPressureData; | |
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1513 global.dataSendToMaster.data[boolPressureData].SPARE1 = is_surface_pressure_stable(); |
38 | 1514 } |
1515 | |
1516 | |
1517 //Supports threadsave copying!!! | |
1518 void copyCnsAndOtuData(void) | |
1519 { | |
1520 //uint8_t dataSendToMaster. | |
1521 uint8_t boolToxicData = !global.dataSendToMaster.boolToxicData; | |
1522 global.dataSendToMaster.data[boolToxicData].cns = global.lifeData.cns; | |
1523 global.dataSendToMaster.data[boolToxicData].otu = global.lifeData.otu; | |
1524 global.dataSendToMaster.data[boolToxicData].desaturation_time_minutes = global.lifeData.desaturation_time_minutes; | |
1525 global.dataSendToMaster.data[boolToxicData].no_fly_time_minutes = get_nofly_time_minutes(); | |
1526 global.dataSendToMaster.boolToxicData = boolToxicData; | |
1527 } | |
1528 | |
1529 | |
1530 //Supports threadsave copying!!! | |
1531 void copyTimeData(void) | |
1532 { | |
1533 extern RTC_HandleTypeDef RTCHandle; | |
1534 | |
1535 uint8_t boolTimeData = !global.dataSendToMaster.boolTimeData; | |
1536 global.dataSendToMaster.data[boolTimeData].localtime_rtc_tr = (uint32_t)(RTCHandle.Instance->TR & RTC_TR_RESERVED_MASK); | |
1537 global.dataSendToMaster.data[boolTimeData].localtime_rtc_dr = (uint32_t)(RTCHandle.Instance->DR & RTC_DR_RESERVED_MASK); | |
1538 global.dataSendToMaster.data[boolTimeData].divetime_seconds = (uint32_t)global.lifeData.dive_time_seconds; | |
1539 global.dataSendToMaster.data[boolTimeData].dive_time_seconds_without_surface_time = (uint32_t)global.lifeData.dive_time_seconds_without_surface_time; | |
1540 global.dataSendToMaster.data[boolTimeData].surfacetime_seconds = (uint32_t)global.seconds_since_last_dive; | |
1541 global.dataSendToMaster.data[boolTimeData].counterSecondsShallowDepth = (uint32_t)global.lifeData.counterSecondsShallowDepth; | |
1542 global.dataSendToMaster.boolTimeData = boolTimeData; | |
1543 } | |
1544 | |
1545 | |
1546 //Supports threadsave copying!!! | |
1547 void copyCompassData(void) | |
1548 { | |
1549 extern float compass_heading; | |
1550 extern float compass_roll; | |
1551 extern float compass_pitch; | |
1552 //uint8_t dataSendToMaster. | |
1553 uint8_t boolCompassData = !global.dataSendToMaster.boolCompassData; | |
1554 global.dataSendToMaster.data[boolCompassData].compass_heading = compass_heading; | |
1555 global.dataSendToMaster.data[boolCompassData].compass_roll = compass_roll; | |
1556 global.dataSendToMaster.data[boolCompassData].compass_pitch = compass_pitch; | |
1557 global.dataSendToMaster.data[boolCompassData].compass_DX_f = 0; | |
1558 global.dataSendToMaster.data[boolCompassData].compass_DY_f = 0; | |
1559 global.dataSendToMaster.data[boolCompassData].compass_DZ_f = 0; | |
1560 global.dataSendToMaster.data[boolCompassData].compass_uTick = HAL_GetTick(); | |
1561 global.dataSendToMaster.boolCompassData = boolCompassData; | |
1562 } | |
1563 | |
1564 | |
1565 void copyCompassDataDuringCalibration(int16_t dx, int16_t dy, int16_t dz) | |
1566 { | |
1567 extern float compass_heading; | |
1568 extern float compass_roll; | |
1569 extern float compass_pitch; | |
1570 //uint8_t dataSendToMaster. | |
1571 uint8_t boolCompassData = !global.dataSendToMaster.boolCompassData; | |
1572 global.dataSendToMaster.data[boolCompassData].compass_heading = compass_heading; | |
1573 global.dataSendToMaster.data[boolCompassData].compass_roll = compass_roll; | |
1574 global.dataSendToMaster.data[boolCompassData].compass_pitch = compass_pitch; | |
1575 global.dataSendToMaster.data[boolCompassData].compass_DX_f = dx; | |
1576 global.dataSendToMaster.data[boolCompassData].compass_DY_f = dy; | |
1577 global.dataSendToMaster.data[boolCompassData].compass_DZ_f = dz; | |
1578 global.dataSendToMaster.boolCompassData = boolCompassData; | |
1579 } | |
1580 | |
1581 | |
1582 //Supports threadsave copying!!! | |
1583 void copyBatteryData(void) | |
1584 { | |
1585 uint8_t boolBatteryData = !global.dataSendToMaster.boolBatteryData; | |
668 | 1586 global.lifeData.battery_charge = get_charge(); |
38 | 1587 global.dataSendToMaster.data[boolBatteryData].battery_voltage = get_voltage(); |
668 | 1588 |
1589 if(battery_gas_gauge_isChargeValueValid()) | |
1590 { | |
1591 global.dataSendToMaster.data[boolBatteryData].battery_charge= global.lifeData.battery_charge; | |
1592 } | |
1593 else | |
1594 { | |
1595 global.dataSendToMaster.data[boolBatteryData].battery_charge = global.lifeData.battery_charge * -1.0; /* negate value to show that this is just an assumption */ | |
1596 } | |
38 | 1597 global.dataSendToMaster.boolBatteryData = boolBatteryData; |
1598 } | |
1599 | |
1600 | |
1601 //Supports threadsave copying!!! | |
1602 void copyAmbientLightData(void) | |
1603 { | |
1604 uint8_t boolAmbientLightData = !global.dataSendToMaster.boolAmbientLightData; | |
1605 global.dataSendToMaster.data[boolAmbientLightData].ambient_light_level = get_ambient_light_level(); | |
1606 global.dataSendToMaster.boolAmbientLightData = boolAmbientLightData; | |
1607 } | |
1608 | |
1609 | |
1610 //Supports threadsave copying!!! | |
1611 void copyTissueData(void) | |
1612 { | |
1613 //uint8_t dataSendToMaster. | |
1614 uint8_t boolTisssueData = !global.dataSendToMaster.boolTisssueData; | |
1615 for(int i = 0; i < 16; i++) | |
1616 { | |
1617 global.dataSendToMaster.data[boolTisssueData].tissue_nitrogen_bar[i] = global.lifeData.tissue_nitrogen_bar[i]; | |
1618 global.dataSendToMaster.data[boolTisssueData].tissue_helium_bar[i] = global.lifeData.tissue_helium_bar[i]; | |
1619 } | |
1620 global.dataSendToMaster.boolTisssueData = boolTisssueData; | |
1621 } | |
1622 | |
1623 | |
1624 //Supports threadsave copying!!! | |
1625 void copyVpmCrushingData(void) | |
1626 { | |
1627 //uint8_t dataSendToMaster. | |
1628 uint8_t boolCrushingData = !global.dataSendToMaster.boolCrushingData; | |
1629 for(int i = 0; i < 16; i++) | |
1630 { | |
1631 global.dataSendToMaster.data[boolCrushingData].max_crushing_pressure_n2[i] = global.vpm.max_crushing_pressure_n2[i]; | |
1632 global.dataSendToMaster.data[boolCrushingData].max_crushing_pressure_he[i] = global.vpm.max_crushing_pressure_he[i]; | |
1633 global.dataSendToMaster.data[boolCrushingData].adjusted_critical_radius_he[i] = global.vpm.adjusted_critical_radius_he[i]; | |
1634 global.dataSendToMaster.data[boolCrushingData].adjusted_critical_radius_n2[i] = global.vpm.adjusted_critical_radius_n2[i]; | |
1635 } | |
1636 global.dataSendToMaster.boolCrushingData = boolCrushingData; | |
1637 } | |
1638 | |
1639 | |
1640 void copyDeviceData(void) | |
1641 { | |
1642 uint8_t boolDeviceData = !global.deviceDataSendToMaster.boolDeviceData; | |
1643 memcpy(&global.deviceDataSendToMaster.DeviceData[boolDeviceData], &global.deviceData,sizeof(SDevice)); | |
1644 global.deviceDataSendToMaster.boolDeviceData = boolDeviceData; | |
1645 | |
1646 global.deviceDataSendToMaster.boolVpmRepetitiveDataValid = 0; | |
1647 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.adjusted_critical_radius_he, &global.vpm.adjusted_critical_radius_he, sizeof(16*4)); | |
1648 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.adjusted_critical_radius_n2, &global.vpm.adjusted_critical_radius_n2, sizeof(16*4)); | |
1649 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.adjusted_crushing_pressure_he, &global.vpm.adjusted_crushing_pressure_he, sizeof(16*4)); | |
1650 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.adjusted_crushing_pressure_n2, &global.vpm.adjusted_crushing_pressure_n2, sizeof(16*4)); | |
1651 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.initial_allowable_gradient_he, &global.vpm.initial_allowable_gradient_he, sizeof(16*4)); | |
1652 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.initial_allowable_gradient_n2, &global.vpm.initial_allowable_gradient_n2, sizeof(16*4)); | |
1653 memcpy(&global.deviceDataSendToMaster.VpmRepetitiveData.max_actual_gradient, &global.vpm.max_actual_gradient, sizeof(16*4)); | |
1654 global.deviceDataSendToMaster.VpmRepetitiveData.repetitive_variables_not_valid = global.vpm.repetitive_variables_not_valid; | |
1655 global.deviceDataSendToMaster.boolVpmRepetitiveDataValid = 1; | |
1656 } | |
1657 | |
1658 /* copyPICdata(); is used in spi.c */ | |
1659 void copyPICdata(void) | |
1660 { | |
1661 uint8_t boolPICdata = !global.dataSendToMaster.boolPICdata; | |
1662 for(int i = 0; i < 3; i++) | |
1663 { | |
1664 global.dataSendToMaster.data[boolPICdata].button_setting[i] = global.ButtonPICdata[i]; | |
1665 } | |
1666 global.dataSendToMaster.boolPICdata = boolPICdata; | |
1667 } | |
1668 | |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1669 void copyExtADCdata() |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1670 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1671 float value; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1672 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1673 uint8_t channel = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1674 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1675 for(channel = 0; channel < MAX_ADC_CHANNEL; channel++) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1676 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1677 value = getExternalInterfaceChannel(channel); |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1678 global.dataSendToMaster.data[0].extADC_voltage[channel] = value; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1679 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1680 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
488
diff
changeset
|
1681 |
662 | 1682 void copyExtCO2data() |
1683 { | |
1684 uint16_t value; | |
1685 | |
1686 if(externalInterface_GetCO2State()) | |
1687 { | |
1688 value = externalInterface_GetCO2Value(); | |
1689 global.dataSendToMaster.data[0].CO2_ppm = value; | |
1690 value = externalInterface_GetCO2SignalStrength(); | |
1691 global.dataSendToMaster.data[0].CO2_signalStrength = value; | |
1692 global.dataSendToMaster.data[0].externalInterface_CmdAnswer = externalInterface_GetCO2State(); | |
1693 externalInterface_SetCO2State(EXT_INTERFACE_33V_ON); /* clear command responses */ | |
1694 } | |
1695 else | |
1696 { | |
1697 global.dataSendToMaster.data[0].CO2_ppm = 0; | |
1698 global.dataSendToMaster.data[0].CO2_signalStrength = 0; | |
1699 global.dataSendToMaster.data[0].externalInterface_CmdAnswer = 0; | |
1700 } | |
1701 } | |
38 | 1702 |
1703 typedef enum | |
1704 { | |
1705 SPI3_OK = 0x00, | |
1706 SPI3_DEINIT = 0x01, | |
1707 } SPI3_StatusTypeDef; | |
1708 /* if spi3 is running and the SPI3_ButtonAdjust call returns OK, all is fine | |
1709 if the SPI3_ButtonAdjust call returns error, the spi3 is DeInit | |
1710 and will be init the next call of scheduleSetButtonResponsiveness() | |
1711 and data will be send again on the third call | |
1712 therefore on return 0 of scheduleSetButtonResponsiveness() the caller flag should kept active | |
1713 */ | |
1714 uint8_t scheduleSetButtonResponsiveness(void) | |
1715 { | |
1716 static uint8_t SPI3status = SPI3_OK; | |
1717 | |
1718 if((SPI3status == SPI3_OK) && (SPI3_ButtonAdjust(global.ButtonResponsiveness, global.ButtonPICdata))) | |
1719 { | |
1720 copyPICdata(); | |
1721 return 1; | |
1722 } | |
1723 else | |
1724 { | |
1725 for(int i=0;i<3;i++) | |
1726 { | |
1727 global.ButtonPICdata[i] = 0xFF; | |
1728 } | |
1729 copyPICdata(); | |
1730 | |
1731 if(SPI3status == SPI3_OK) | |
1732 { | |
1733 MX_SPI3_DeInit(); | |
1734 SPI3status = SPI3_DEINIT; | |
1735 } | |
1736 else | |
1737 { | |
1738 MX_SPI3_Init(); | |
1739 SPI3status = SPI3_OK; | |
1740 } | |
1741 return 0; | |
1742 } | |
1743 } | |
1744 | |
1745 | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
181
diff
changeset
|
1746 //save time difference |
38 | 1747 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow) |
1748 { | |
1749 if(ticksstart <= ticksnow) | |
1750 { | |
1751 return ticksnow - ticksstart; | |
1752 } | |
1753 else | |
1754 { | |
1755 return 0xFFFFFFFF - ticksstart + ticksnow; | |
1756 } | |
1757 } | |
1758 | |
1759 /* same as in data_central.c */ | |
310
95928ef3986f
Make dive mode detection more advanced
Jan Mulder <jlmulder@xs4all.nl>
parents:
301
diff
changeset
|
1760 _Bool is_ambient_pressure_close_to_surface(SLifeData *lifeData) |
38 | 1761 { |
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1762 _Bool retval = true; |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1763 |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1764 if(lifeData->pressure_ambient_bar != INVALID_PREASURE_VALUE) /* as long as no valid data is available expect we are close to surface */ |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1765 { |
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1766 /* this will e.g. apply in case of a significant pressure change during last 30 minutes => use increased offset for surface detection */ |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1767 if (lifeData->pressure_ambient_bar > START_DIVE_IMMEDIATLY_BAR) |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1768 { |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1769 retval = false; |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1770 } |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1771 else if(is_surface_pressure_stable()) /* this is the expected start condition */ |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1772 { |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1773 if((lifeData->pressure_ambient_bar >= (lifeData->pressure_surface_bar + 0.1f)) |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1774 && (ManualExitDiveCounter == 0)) /* only if diver did not request to exit dive mode */ |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1775 { |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1776 retval = false; |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1777 } |
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1778 } |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
310
diff
changeset
|
1779 } |
346
73325a78c907
Added function to support manuel exit of dive mode
ideenmodellierer
parents:
338
diff
changeset
|
1780 return retval; |
38 | 1781 } |
1782 | |
1783 | |
1784 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ | |
1785 |