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