Mercurial > public > ostc4
annotate Common/Inc/data_central.h @ 328:4fe5400567e7 I2C_Improvment
Set I2C speed to 88kHz, use digital filter only and reworked idle clock recovery
The errata describes a possible problem in operation between 88kHz and 100kHz => Set speed as recommended as work around.
Based on reference implementation only one filter should be use. Choice was digital because only drawback is lag of wakeup functionality which is not used
I2C communication may be randomly interrupted e.g. by a RTE reset or firmware update => reworked recovery function to get I2C devices in idle state again (Clk and SDA HIGH)
author | ideenmodellierer |
---|---|
date | Wed, 17 Jul 2019 22:42:15 +0200 |
parents | b0045281cb2d |
children | 58200d756365 |
rev | line source |
---|---|
38 | 1 /////////////////////////////////////////////////////////////////////////////// |
2 /// -*- coding: UTF-8 -*- | |
3 /// | |
4 /// \file Common/Inc/data_central.h | |
5 /// \brief Common Dadatypes Declarations | |
6 /// \author Heinrichs Weikamp | |
7 /// \date 2018 | |
8 /// | |
9 /// $Id$ | |
10 /////////////////////////////////////////////////////////////////////////////// | |
11 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh | |
12 /// | |
13 /// This program is free software: you can redistribute it and/or modify | |
14 /// it under the terms of the GNU General Public License as published by | |
15 /// the Free Software Foundation, either version 3 of the License, or | |
16 /// (at your option) any later version. | |
17 /// | |
18 /// This program is distributed in the hope that it will be useful, | |
19 /// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 /// GNU General Public License for more details. | |
22 /// | |
23 /// You should have received a copy of the GNU General Public License | |
24 /// along with this program. If not, see <http://www.gnu.org/licenses/>. | |
25 ////////////////////////////////////////////////////////////////////////////// | |
26 | |
27 #ifndef DATA_CENTRAL_H | |
28 #define DATA_CENTRAL_H | |
29 | |
30 #include <stdint.h> | |
31 | |
32 #include "settings.h" | |
33 #include "stm32f4xx_hal.h" | |
34 | |
35 #define BUEHLMANN_STRUCT_MAX_GASES 11 | |
36 #define BUEHLMANN_STRUCT_MAX_ASCENDRATES 3 | |
37 #define DECOINFO_STRUCT_MAX_STOPS 50 | |
38 | |
39 #define false 0 | |
40 #define true 1 | |
41 | |
42 /* Helper structs ------------------------------------------------------------*/ | |
43 | |
44 //struct SGas | |
45 //contains gasinfos of single gas for deco calculation | |
46 typedef struct | |
47 { | |
48 uint8_t nitrogen_percentage; | |
49 uint8_t helium_percentage; | |
50 uint8_t setPoint_cbar; | |
51 uint8_t change_during_ascent_depth_meter_otherwise_zero; | |
52 uint8_t GasIdInSettings; | |
53 uint8_t temp1_for16bitalign; | |
54 } SGas; | |
55 | |
56 typedef struct | |
57 { | |
58 float use_from_depth_bar; | |
59 float rate_bar_per_minute; | |
60 } SAscentrate; | |
61 | |
62 | |
63 typedef struct{ | |
64 uint32_t date_rtc_dr; | |
65 uint32_t time_rtc_tr; | |
66 int32_t value_int32; | |
67 } SDeviceLine; | |
68 | |
69 | |
70 typedef struct | |
71 { | |
72 uint16_t ageInMilliSeconds; | |
73 uint8_t numberOfBytes; | |
74 uint8_t status; | |
75 uint8_t data[12]; | |
76 } SDataWireless; | |
77 | |
78 /* Main structs -------------------------------------------------------------*/ | |
79 | |
80 | |
81 //struct SDecoinfo | |
82 //contains result of deco calculation | |
83 typedef struct | |
84 { | |
85 unsigned short output_stop_length_seconds[DECOINFO_STRUCT_MAX_STOPS]; | |
86 int output_time_to_surface_seconds; | |
87 int output_ndl_seconds; | |
88 float output_ceiling_meter; | |
247
3949781096d4
feature: Relative GF to Saturation renames
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
89 float super_saturation; |
38 | 90 uint32_t tickstamp; |
91 } SDecoinfo; | |
92 | |
93 | |
94 typedef struct | |
95 { | |
96 //crushing pressure | |
97 //in/out | |
98 float max_crushing_pressure_he[16]; | |
99 float max_crushing_pressure_n2[16]; | |
100 // | |
101 float run_time_start_of_deco_zone_save; | |
102 float depth_start_of_deco_zone_save; | |
103 float max_first_stop_depth_save; | |
104 short decomode_vpm_plus_conservatism_last_dive; | |
105 _Bool deco_zone_reached; | |
106 //State variables for repetetive dives | |
107 _Bool repetitive_variables_not_valid; | |
108 float adjusted_crushing_pressure_he[16]; | |
109 float adjusted_crushing_pressure_n2[16]; | |
110 float adjusted_critical_radius_he[16]; | |
111 float adjusted_critical_radius_n2[16]; | |
112 float initial_allowable_gradient_he[16]; | |
113 float initial_allowable_gradient_n2[16]; | |
114 float max_actual_gradient[16]; | |
115 } SVpm; | |
116 | |
117 typedef struct | |
118 { | |
119 _Bool repetitive_variables_not_valid; | |
120 _Bool is_data_from_RTE_CPU; | |
121 _Bool spare2; | |
122 _Bool spare3; | |
123 float adjusted_crushing_pressure_he[16]; | |
124 float adjusted_crushing_pressure_n2[16]; | |
125 float adjusted_critical_radius_he[16]; | |
126 float adjusted_critical_radius_n2[16]; | |
127 float initial_allowable_gradient_he[16]; | |
128 float initial_allowable_gradient_n2[16]; | |
129 float max_actual_gradient[16]; | |
130 } SVpmRepetitiveData; | |
131 | |
132 //struct SDevice | |
133 //contains information about usage | |
134 typedef struct | |
135 { | |
136 SDeviceLine batteryChargeCycles; | |
137 SDeviceLine batteryChargeCompleteCycles; | |
138 SDeviceLine temperatureMinimum; | |
139 SDeviceLine temperatureMaximum; | |
140 SDeviceLine depthMaximum; | |
141 SDeviceLine diveCycles; | |
142 SDeviceLine voltageMinimum; | |
143 SDeviceLine hoursOfOperation; | |
144 SDeviceLine diveAccident; | |
145 } SDevice; | |
146 | |
147 /* | |
148 typedef struct | |
149 { | |
150 SDevice device; | |
151 SVpmRepetitiveData vpm; | |
152 } SDeviceState; | |
153 */ | |
154 | |
155 /* struct SLifeData | |
156 * contains data all actual data (pressure, stuturation, etc. as received from second ship | |
157 * and has actualGas to be send to Small CPU (second chip) | |
158 * contains data calculated from actual data after receiption from Small CPU | |
159 */ | |
160 typedef struct | |
161 { | |
162 /* from Small CPU */ | |
163 int32_t dive_time_seconds; | |
164 int32_t dive_time_seconds_without_surface_time; | |
165 uint32_t surface_time_seconds; | |
166 float pressure_ambient_bar; | |
167 float pressure_surface_bar; | |
168 float tissue_nitrogen_bar[16]; | |
169 float tissue_helium_bar[16]; | |
170 float cns; | |
171 float otu; | |
172 uint16_t desaturation_time_minutes; | |
173 uint16_t no_fly_time_minutes; | |
174 float temperature_celsius; | |
175 float compass_heading; | |
176 float compass_roll; | |
177 float compass_pitch; | |
178 int16_t compass_DX_f; | |
179 int16_t compass_DY_f; | |
180 int16_t compass_DZ_f; | |
181 uint16_t counterSecondsShallowDepth; | |
182 float ascent_rate_meter_per_min; | |
183 uint32_t timeBinaryFormat; | |
184 uint32_t dateBinaryFormat; | |
185 float battery_voltage; | |
186 float battery_charge; | |
187 uint16_t ambient_light_level; | |
188 SDataWireless wireless_data[4]; | |
189 uint8_t buttonPICdata[4]; | |
190 | |
191 /* by create DiveSettings() and by setActualGas() | |
192 * is send to Small CPU2 for nitrogen calculation | |
193 * includes setpoint information | |
194 */ | |
195 SGas actualGas; | |
196 uint8_t lastDiluent_GasIdInSettings; | |
197 uint8_t gas_temp2; | |
198 | |
199 /* calculated by DataEX_copy_to_LifeData() | |
200 bottle_bar array size is made like this to have multiples of 32bit | |
201 */ | |
202 float ppO2; | |
203 float depth_meter; | |
204 float max_depth_meter; | |
205 float average_depth_meter; | |
206 float apnea_total_max_depth_meter; | |
207 float apnea_last_max_depth_meter; | |
208 int32_t apnea_last_dive_time_seconds; | |
209 uint16_t bottle_bar[2 * NUM_GASES +1]; | |
210 uint16_t bottle_bar_age_MilliSeconds[2 * NUM_GASES + 1]; | |
211 uint16_t apnea_total_counter; | |
212 | |
213 /* control of DataEX_copy_to_LifeData() | |
214 */ | |
215 uint8_t boolResetAverageDepth; | |
216 uint8_t bool_temp1; | |
217 uint8_t bool_temp2; | |
218 | |
219 /* from local sensor or direct HUD communication */ | |
220 //pp O2 Sensor | |
221 float ppO2Sensor_bar[3]; | |
222 float sensorVoltage_mV[3]; | |
223 float HUD_battery_voltage_V; | |
224 } SLifeData; | |
225 | |
226 | |
227 typedef struct | |
228 { | |
229 uint16_t tissue_nitrogen_desaturation_time_minutes[16]; | |
230 uint16_t tissue_helium_desaturation_time_minutes[16]; | |
231 } SLifeData2; | |
232 | |
233 | |
234 typedef struct | |
235 { | |
236 //warnings | |
237 int8_t decoMissed; | |
238 int8_t aGf; | |
239 int8_t ascentRateHigh; | |
240 int8_t ppO2Low; | |
241 int8_t ppO2High; | |
242 int8_t cnsHigh; | |
243 int8_t slowWarning; | |
244 int8_t lowBattery; | |
245 int8_t numWarnings; | |
246 int8_t sensorLinkLost; | |
247 int8_t sensorOutOfBounds[3]; | |
248 int8_t betterGas; | |
249 int8_t fallback; | |
250 int8_t betterSetpoint; | |
251 } SWarnings; | |
252 | |
253 | |
254 typedef struct | |
255 { | |
256 //Events logbook only | |
257 int16_t manualMarker; | |
258 int16_t gasChange; | |
259 int16_t info_GasChange; | |
260 int16_t setpointChange; | |
261 int16_t info_SetpointChange; | |
281 | 262 int16_t manualGasSet; |
263 int16_t info_manualGasSetHe; | |
264 int16_t info_manualGasSetO2; | |
38 | 265 int16_t bailout; |
266 int16_t info_bailoutHe; | |
267 int16_t info_bailoutO2; | |
268 } SEvents; | |
269 | |
270 | |
271 | |
272 //struct SDiveSettings | |
273 //contains settings necessary for deco calculation | |
274 typedef struct | |
275 { | |
276 float last_stop_depth_bar; | |
277 float input_next_stop_increment_depth_bar; | |
278 float input_second_to_last_stop_depth_bar; | |
279 float ascentRate_meterperminute; | |
280 uint8_t diveMode; /* OC, CC, .. */ | |
281 uint8_t CCR_Mode; | |
282 uint8_t future_TTS_minutes; | |
283 | |
284 /* If beginning of dive is CCR than ccrOption is set true | |
285 * true allows returning from bailout (OC) back to CCR | |
286 * true activates CC gas and setpoint pages in dive menu | |
287 */ | |
288 uint8_t ccrOption; | |
289 uint8_t fallbackOption; | |
290 uint8_t ppo2sensors_deactivated; | |
291 | |
292 split2x4_Type deco_type; /* GF or VPM for standard and alternative seperate */ | |
293 | |
294 /* VPM conservatism, do not change during dive!!! | |
295 * do not change in between dives otherwise repetitve dive is not possible | |
296 */ | |
297 uint8_t vpm_conservatism; | |
298 | |
299 /* B�hlmann GF | |
300 * and a variable that is used by Buehlmann during the dive | |
301 * to remember the position of GF low during ascend | |
302 */ | |
303 uint8_t gf_high; | |
304 uint8_t gf_low; | |
305 | |
306 /* copy of the Settings GasList and SetpintList | |
307 * that can be modified during the dive | |
308 * especially gases can be actived and deactivated | |
309 * gas[0] and setpoint[0] are the special ones configurable during the dive | |
310 */ | |
311 SGasLine gas[1 + (2*NUM_GASES)]; | |
312 SSetpointLine setpoint[1 + NUM_GASES]; | |
313 | |
314 /* List of GasChanges in the actual order | |
315 * this is necessary for VPM and Buehlmann and will be created on start of each calculation | |
316 */ | |
317 SGas decogaslist[BUEHLMANN_STRUCT_MAX_GASES]; // unused filled with 0xFF | |
318 | |
319 /* | |
320 */ | |
321 float internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero; | |
322 uint16_t compassHeading; | |
323 } SDiveSettings; | |
324 | |
325 enum CHARGE_STATUS{ | |
326 CHARGER_off = 0, | |
327 CHARGER_running, | |
328 CHARGER_complete, | |
329 CHARGER_lostConnection | |
330 }; | |
331 | |
332 typedef struct | |
333 { | |
334 SDiveSettings diveSettings; | |
335 SLifeData lifeData; | |
336 SVpm vpm; | |
337 SEvents events; | |
338 SWarnings warnings; | |
339 SDecoinfo decolistVPM; | |
340 SDecoinfo decolistFutureVPM; | |
341 SDecoinfo decolistBuehlmann; // | |
342 SDecoinfo decolistFutureBuehlmann; | |
343 uint8_t mode; /* hw for sleep, surface, dive, .. */ | |
344 uint8_t chargeStatus; | |
345 uint8_t data_old__lost_connection_to_slave; | |
346 | |
347 uint32_t pressure_uTick_new; | |
348 uint32_t compass_uTick_new; | |
349 | |
350 uint32_t pressure_uTick_old; | |
351 uint32_t compass_uTick_old; | |
352 | |
353 uint32_t pressure_uTick_local_new; | |
354 uint32_t compass_uTick_local_new; | |
355 | |
356 uint8_t cnsHigh_at_the_end_of_dive; | |
357 uint8_t decoMissed_at_the_end_of_dive; | |
358 | |
359 uint8_t sensorErrorsRTE; | |
360 | |
361 uint8_t lastKnownBatteryPercentage; | |
362 } SDiveState; | |
363 | |
364 | |
365 typedef struct{ | |
366 uint8_t bit0:1; | |
367 uint8_t bit1:1; | |
368 uint8_t bit2:1; | |
369 uint8_t bit3:1; | |
370 uint8_t bit4:1; | |
371 uint8_t bit5:1; | |
372 uint8_t bit6:1; | |
373 uint8_t bit7:1; | |
374 } ubit8_t; | |
375 | |
376 typedef union{ | |
377 ubit8_t ub; | |
378 uint8_t uw; | |
379 } bit8_Type; | |
380 | |
381 extern SDiveState stateSim; | |
382 extern SDiveState stateDeco; | |
383 extern uint8_t decoLock; | |
271
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
384 extern const SDiveState *stateUsed; |
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
385 extern SDiveState *stateUsedWrite; |
38 | 386 |
387 enum DECO_LOCK{ | |
388 DECO_CALC_running, | |
389 DECO_CALC_ready, | |
390 DECO_CALC_FINSHED_Buehlmann, | |
391 DECO_CALC_FINSHED_vpm, | |
392 DECO_CALC_FINSHED_FutureBuehlmann, | |
393 DECO_CALC_FINSHED_Futurevpm, | |
394 DECO_CALC_init_as_is_start_of_dive, | |
395 DECO_CALC_undefined | |
396 }; | |
397 | |
398 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow); | |
399 | |
400 void set_stateUsedToSim(void); | |
401 void set_stateUsedToReal(void); | |
402 | |
403 _Bool is_stateUsedSetToSim(void); | |
404 | |
405 const SDiveState * stateRealGetPointer(void); | |
406 const SDiveState * stateSimGetPointer(void); | |
407 SDiveState * stateRealGetPointerWrite(void); | |
408 SDiveState * stateSimGetPointerWrite(void); | |
409 const SDevice * stateDeviceGetPointer(void); | |
410 SDevice * stateDeviceGetPointerWrite(void); | |
411 const SVpmRepetitiveData * stateVpmRepetitiveDataGetPointer(void); | |
412 SVpmRepetitiveData * stateVpmRepetitiveDataGetPointerWrite(void); | |
413 | |
414 void UpdateLifeDataTest(SDiveState * diveState); | |
415 | |
416 void setSimulationValues(int _ascent_rate_meter_per_min, int _descent_rate_meter_per_min, int _max_depth, int _bottom_time ); | |
417 | |
418 void createDiveSettings(void); | |
419 void copyDiveSettingsToSim(void); | |
420 void copyVpmRepetetiveDataToSim(void); | |
421 //void fallbackToFixedSetpoints(SLifeData *lifeData); | |
422 void setActualGasFirst(SLifeData *lifeData); | |
423 void setActualGasAir(SLifeData *lifeData); | |
424 void setActualGas(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar); | |
425 void setActualGas_ExtraGas(SLifeData *lifeData, uint8_t oxygen, uint8_t helium, uint8_t setpoint_cbar); | |
426 void setActualGas_DM(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar); | |
427 void setWeekday(RTC_DateTypeDef *sDate); | |
428 void setDate(RTC_DateTypeDef Sdate); | |
429 void setTime(RTC_TimeTypeDef Stime); | |
430 void setBatteryPercentage(uint8_t newChargePercentage); | |
431 void setButtonResponsiveness(uint8_t *ButtonSensitivyList); | |
432 void calibrateCompass(void); | |
433 void clearDeco(void); | |
434 void translateDate(uint32_t datetmpreg, RTC_DateTypeDef *sDate); | |
435 void translateTime(uint32_t tmpreg, RTC_TimeTypeDef *sTime); | |
436 void updateSetpointStateUsed(void); | |
437 | |
438 uint8_t calc_MOD(uint8_t gasId); | |
439 uint8_t calc_MinOD(uint8_t gasId); | |
440 //float calc_ppO2(float input_ambient_pressure_bar, SGas* pGas); | |
441 int current_second(void); | |
442 _Bool vpm_crush(SDiveState* pDiveState); | |
443 _Bool deco_zone_reached(void); | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
444 void resetEvents(const SDiveState *pStateUsed); |
38 | 445 |
446 uint32_t crc32c_checksum(uint8_t* message, uint16_t length, uint8_t* message2, uint16_t length2); | |
447 uint32_t CRC_CalcBlockCRC(uint32_t *buffer, uint32_t words); | |
448 uint32_t CRC_CalcBlockCRC_moreThan768000(uint32_t *buffer1, uint32_t *buffer2, uint32_t words); | |
449 | |
450 _Bool is_ambient_pressure_close_to_surface(SLifeData *lifeData); | |
451 | |
452 #endif // DATA_CENTRAL_H |