Mercurial > public > mk2
annotate code_part1/OSTC_code_c_part2/p2_deco.c @ 258:abbf9a2c2c48
Small p2_deco optimizations:
Removed pres_tissue_limit[] and sim_pres_tissue_limit[] (Unused).
Separated read_buhlmann_times() and read_buhlmann_coefficients().
author | JeanDo |
---|---|
date | Sun, 10 Apr 2011 14:17:53 +0200 |
parents | f8f869bafd92 |
children | bde83cac971f |
rev | line source |
---|---|
116 | 1 // ************************************************************** |
2 // p2_deco.c | |
3 // | |
4 // Created on: 12.05.2009 | |
5 // Author: chsw | |
6 // | |
7 // ************************************************************** | |
8 | |
9 ////////////////////////////////////////////////////////////////////////////// | |
10 // OSTC - diving computer code | |
11 // Copyright (C) 2008 HeinrichsWeikamp GbR | |
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 | |
28 // ***************************** | |
29 // ** I N T R O D U C T I O N ** | |
30 // ***************************** | |
31 // | |
32 // OSTC | |
33 // | |
34 // code: | |
35 // p2_deco_main_c_v101.c | |
36 // part2 of the OSTC code | |
37 // code with constant O2 partial pressure routines | |
38 // under construction !! | |
39 // | |
40 // summary: | |
41 // decompression routines | |
42 // for the OSTC experimental project | |
43 // written by Christian Weikamp | |
44 // last revision __________ | |
45 // comments added _________ | |
46 // | |
47 // additional files: | |
48 // p2_tables_v100.romdata (other files) | |
49 // 18f4685_ostc_v100.lkr (linker script) | |
50 // | |
51 // history: | |
52 // 01/03/08 v100: first release candidate | |
53 // 03/13/08 v101: start of programming ppO2 code | |
54 // 03/13/25 v101a: backup of interrim version with ppO2 calculation | |
55 // 03/13/25 v101: open circuit gas change during deco | |
56 // 03/13/25 v101: CNS_fraction calculation | |
57 // 03/13/26 v101: optimization of tissue calc routines | |
58 // 07/xx/08 v102a: debug of bottom time routine | |
59 // 09/xx/08 v102d: Gradient Factor Model implemenation | |
60 // 10/10/08 v104: renamed to build v103 for v118 stable | |
171 | 61 // 10/14/08 v104: integration of char_I_depth_last_deco for Gradient Model |
116 | 62 // 03/31/09 v107: integration of FONT Incon24 |
63 // 05/23/10 v109: 5 gas changes & 1 min timer | |
64 // 07/13/10 v110: cns vault added | |
65 // 12/25/10 v110: split in three files (deco.c, main.c, definitions.h) | |
163 | 66 // 2011/01/20: [jDG] Create a common file included in ASM and C code. |
167 | 67 // 2011/01/23: [jDG] Added read_custom_function(). |
203 | 68 // 2011/01/24: [jDG] Make ascenttime an short. No more overflow! |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
69 // 2011/01/25: [jDG] Fusion deco array for both models. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
70 // 2011/01/25: [jDG] Use CF(54) to reverse deco order. |
193 | 71 // 2011/02/11: [jDG] Reworked gradient-factor implementation. |
197 | 72 // 2011/02/13: [jDG] CF55 for additional gas switch delay in decoplan. |
217 | 73 // 2011/02/24: [jDG] Fixed inconsistencies introduced by gas switch delays. |
257
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
74 // 2011/04/10: [jDG] Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco() |
116 | 75 // |
167 | 76 // TODO: |
77 // + Allow to abort MD2 calculation (have to restart next time). | |
78 // | |
79 // Literature: | |
200 | 80 // Bühlmann, Albert: Tauchmedizin; 4. Auflage [2002]; |
116 | 81 // Schr"oder, Kai & Reith, Steffen; 2000; S"attigungsvorg"ange beim Tauchen, das Modell ZH-L16, Funktionsweise von Tauchcomputern; http://www.achim-und-kai.de/kai/tausim/saett_faq |
82 // Morrison, Stuart; 2000; DIY DECOMPRESSION; http://www.lizardland.co.uk/DIYDeco.html | |
83 // Balthasar, Steffen; Dekompressionstheorie I: Neo Haldane Modelle; http://www.txfreak.de/dekompressionstheorie_1.pdf | |
84 // Baker, Erik C.; Clearing Up The Confusion About "Deep Stops" | |
85 // Baker, Erik C.; Understanding M-values; http://www.txfreak.de/understanding_m-values.pdf | |
167 | 86 // |
87 // | |
116 | 88 |
89 // ********************* | |
90 // ** I N C L U D E S ** | |
91 // ********************* | |
92 #include <math.h> | |
167 | 93 |
192 | 94 // *********************************************** |
95 // ** V A R I A B L E S D E F I N I T I O N S ** | |
96 // *********************************************** | |
97 | |
98 #include "p2_definitions.h" | |
99 #include "shared_definitions.h" | |
100 | |
200 | 101 // Water vapour partial pressure in the lumb. |
233 | 102 #define ppWVapour 0.0627 |
200 | 103 |
167 | 104 // ************************* |
105 // ** P R O T O T Y P E S ** | |
106 // ************************* | |
107 | |
108 static void calc_hauptroutine(void); | |
109 static void calc_nullzeit(void); | |
110 | |
192 | 111 static void calc_tissue(PARAMETER unsigned char period); |
258 | 112 static void calc_limit(void); |
192 | 113 |
167 | 114 static void clear_tissue(void); |
115 static void calc_ascenttime(void); | |
116 static void update_startvalues(void); | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
117 static void clear_deco_table(void); |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
118 static void update_deco_table(void); |
192 | 119 |
120 static void backup_sim_pres_tissue(void); | |
121 static void restore_sim_pres_tissue(void); | |
122 static void sim_tissue(PARAMETER unsigned char period); | |
123 static void sim_limit(PARAMETER float GF_current); | |
167 | 124 static void calc_gradient_factor(void); |
125 static void calc_wo_deco_step_1_min(void); | |
126 | |
127 static void calc_hauptroutine_data_input(void); | |
128 static void calc_hauptroutine_update_tissues(void); | |
129 static void calc_hauptroutine_calc_deco(void); | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
130 static void sim_ascent_to_first_stop(void); |
167 | 131 |
241 | 132 static unsigned char gas_switch_deepest(void); |
133 static void gas_switch_set(void); | |
217 | 134 |
241 | 135 static unsigned char calc_nextdecodepth(void); |
116 | 136 |
200 | 137 //---- Bank 4 parameters ----------------------------------------------------- |
163 | 138 #pragma udata bank4=0x400 |
116 | 139 |
140 static float temp_limit; | |
141 static float GF_low; | |
142 static float GF_high; | |
143 static float GF_delta; | |
192 | 144 static unsigned char low_depth; // Depth of deepest stop |
145 static float locked_GF_step; // GF_delta / low_depth | |
146 | |
147 static unsigned char temp_depth_limit; | |
171 | 148 |
192 | 149 // Simulation context: used to predict ascent. |
150 static unsigned char sim_lead_tissue_no; // Leading compatiment number. | |
151 static float sim_lead_tissue_limit; // Buhlmann tolerated pressure. | |
116 | 152 |
192 | 153 // Real context: what we are doing now. |
154 static float calc_lead_tissue_limit; // | |
116 | 155 |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
156 static unsigned char internal_deco_time[32]; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
157 static unsigned char internal_deco_depth[32]; |
116 | 158 |
159 static float cns_vault; | |
160 static float pres_tissue_vault[32]; | |
161 | |
163 | 162 //---- Bank 5 parameters ----------------------------------------------------- |
163 #pragma udata bank5=0x500 | |
164 | |
167 | 165 static unsigned char ci; |
116 | 166 static float pres_respiration; |
167 static float pres_surface; | |
168 static float temp_deco; | |
236 | 169 static float ppN2; |
200 | 170 static float ppHe; |
116 | 171 static float temp_tissue; |
200 | 172 static float N2_ratio; // Breathed gas nitrogen ratio. |
173 static float He_ratio; // Breathed gas helium ratio. | |
174 static float var_N2_a; // Bühlmann a, for current N2 tissue. | |
175 static float var_N2_b; // Bühlmann b, for current N2 tissue. | |
176 static float var_He_a; // Bühlmann a, for current He tissue. | |
177 static float var_He_b; // Bühlmann b, for current He tissue. | |
178 static float var_N2_e; // Exposition, for current N2 tissue. | |
179 static float var_He_e; // Exposition, for current He tissue. | |
116 | 180 |
164 | 181 static float pres_diluent; // new in v.101 |
182 static float const_ppO2; // new in v.101 | |
183 static float deco_ppO2_change; // new in v.101 | |
184 static float deco_ppO2; // new in v.101 | |
116 | 185 |
241 | 186 static unsigned char sim_gas_last_depth; // Depth of last used gas, to detected a gas switch. |
187 static unsigned char sim_gas_last_used; // Number of last used gas, to detected a gas switch. | |
203 | 188 static unsigned short sim_gas_delay; // Time of gas-switch-stop ends [min on dive]. |
189 static unsigned short sim_dive_mins; // Simulated dive time. | |
200 | 190 static float calc_N2_ratio; // Simulated (switched) nitrogen ratio. |
191 static float calc_He_ratio; // Simulated (switched) helium ratio. | |
192 static float CNS_fraction; // new in v.101 | |
193 static float float_saturation_multiplier; // new in v.101 | |
194 static float float_desaturation_multiplier; // new in v.101 | |
167 | 195 static float float_deco_distance; // new in v.101 |
196 static char flag_in_divemode; // new in v.108 | |
197 | |
225 | 198 static unsigned char deco_gas_change[5]; // new in v.109 |
167 | 199 |
163 | 200 //---- Bank 6 parameters ----------------------------------------------------- |
201 #pragma udata bank6=0x600 | |
116 | 202 |
197 | 203 float pres_tissue[32]; |
116 | 204 |
163 | 205 //---- Bank 7 parameters ----------------------------------------------------- |
206 #pragma udata bank7=0x700 | |
207 | |
197 | 208 float sim_pres_tissue[32]; // 32 floats = 128 bytes. |
116 | 209 static float sim_pres_tissue_backup[32]; |
210 | |
163 | 211 //---- Bank 8 parameters ----------------------------------------------------- |
116 | 212 #pragma udata bank8=0x800 |
163 | 213 |
116 | 214 static char md_pi_subst[256]; |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
215 #define C_STACK md_pi_subst // Overlay C-code data stack here, too. |
116 | 216 |
163 | 217 //---- Bank 9 parameters ----------------------------------------------------- |
167 | 218 #pragma udata bank9=0x900 |
116 | 219 |
163 | 220 static char md_state[48]; // DONT MOVE !! // has to be at the beginning of bank 9 for the asm code!!! |
116 | 221 |
164 | 222 // internal, dbg: |
167 | 223 static unsigned char DBG_char_I_deco_model; // new in v.108. |
164 | 224 static unsigned char DBG_char_I_depth_last_deco; // new in v.108 |
212 | 225 static unsigned char DBG_deco_gas_change; // new in v.108 |
224 | 226 static unsigned char DBG_deco_N2_ratio; // new in v.108 |
227 static unsigned char DBG_deco_He_ratio; // new in v.108 | |
164 | 228 static float DBG_pres_surface; // new in v.108 |
229 static float DBG_GF_low; // new in v.108 | |
230 static float DBG_GF_high; // new in v.108 | |
231 static float DBG_const_ppO2; // new in v.108 | |
232 static float DBG_deco_ppO2_change; // new in v.108 | |
233 static float DBG_deco_ppO2; // new in v.108 | |
234 static float DBG_float_saturation_multiplier; // new in v.108 | |
235 static float DBG_float_desaturation_multiplier; // new in v.108 | |
236 static float DBG_float_deco_distance; // new in v.108 | |
237 static float DBG_N2_ratio; // new in v.108 | |
238 static float DBG_He_ratio; // new in v.108 | |
239 | |
167 | 240 ////////////////////////////////////////////////////////////////////////////// |
241 ////////////////////////////////////////////////////////////////////////////// | |
242 ///////////////////////////// THE LOOKUP TABLES ////////////////////////////// | |
243 ////////////////////////////////////////////////////////////////////////////// | |
244 ////////////////////////////////////////////////////////////////////////////// | |
245 // | |
246 // End of PROM code is 17F00, So push tables on PROM top... | |
247 // | |
248 #pragma romdata buhlmann_tables = 0x017B00 // Needs to be in UPPER bank. | |
249 #include "p2_tables.romdata" // new table for deco_main_v.101 (var_N2_a modified) | |
116 | 250 |
167 | 251 // Magic table to compute the MD2 HASH |
252 // | |
253 #pragma romdata hash_tables = 0x017E00 // Address fixed by ASM access... | |
203 | 254 rom const rom unsigned short md_pi[] = |
116 | 255 { |
256 0x292E, 0x43C9, 0xA2D8, 0x7C01, 0x3D36, 0x54A1, 0xECF0, 0x0613 | |
257 , 0x62A7, 0x05F3, 0xC0C7, 0x738C, 0x9893, 0x2BD9, 0xBC4C, 0x82CA | |
258 , 0x1E9B, 0x573C, 0xFDD4, 0xE016, 0x6742, 0x6F18, 0x8A17, 0xE512 | |
259 , 0xBE4E, 0xC4D6, 0xDA9E, 0xDE49, 0xA0FB, 0xF58E, 0xBB2F, 0xEE7A | |
260 , 0xA968, 0x7991, 0x15B2, 0x073F, 0x94C2, 0x1089, 0x0B22, 0x5F21 | |
261 , 0x807F, 0x5D9A, 0x5A90, 0x3227, 0x353E, 0xCCE7, 0xBFF7, 0x9703 | |
262 , 0xFF19, 0x30B3, 0x48A5, 0xB5D1, 0xD75E, 0x922A, 0xAC56, 0xAAC6 | |
263 , 0x4FB8, 0x38D2, 0x96A4, 0x7DB6, 0x76FC, 0x6BE2, 0x9C74, 0x04F1 | |
264 , 0x459D, 0x7059, 0x6471, 0x8720, 0x865B, 0xCF65, 0xE62D, 0xA802 | |
265 , 0x1B60, 0x25AD, 0xAEB0, 0xB9F6, 0x1C46, 0x6169, 0x3440, 0x7E0F | |
266 , 0x5547, 0xA323, 0xDD51, 0xAF3A, 0xC35C, 0xF9CE, 0xBAC5, 0xEA26 | |
267 , 0x2C53, 0x0D6E, 0x8528, 0x8409, 0xD3DF, 0xCDF4, 0x4181, 0x4D52 | |
268 , 0x6ADC, 0x37C8, 0x6CC1, 0xABFA, 0x24E1, 0x7B08, 0x0CBD, 0xB14A | |
269 , 0x7888, 0x958B, 0xE363, 0xE86D, 0xE9CB, 0xD5FE, 0x3B00, 0x1D39 | |
270 , 0xF2EF, 0xB70E, 0x6658, 0xD0E4, 0xA677, 0x72F8, 0xEB75, 0x4B0A | |
271 , 0x3144, 0x50B4, 0x8FED, 0x1F1A, 0xDB99, 0x8D33, 0x9F11, 0x8314 | |
272 }; | |
273 | |
167 | 274 ////////////////////////////////////////////////////////////////////////////// |
275 ////////////////////////////////////////////////////////////////////////////// | |
276 ////////////////////////////// THE SUBROUTINES /////////////////////////////// | |
277 ////////////////////////////////////////////////////////////////////////////// | |
278 ////////////////////////////////////////////////////////////////////////////// | |
279 // | |
116 | 280 // all new in v.102 |
281 // moved from 0x0D000 to 0x0C000 in v.108 | |
282 | |
283 #pragma code p2_deco = 0x0C000 | |
284 | |
167 | 285 ////////////////////////////////////////////////////////////////////////////// |
286 // DBS - debug on start of dive | |
287 // | |
288 static void create_dbs_set_dbg_and_ndl20mtr(void) | |
116 | 289 { |
167 | 290 overlay char i; // Local loop index. |
291 | |
292 //---- Reset DEBUG bit fields -------------------------------------------- | |
116 | 293 int_O_DBS_bitfield = 0; |
294 int_O_DBS2_bitfield = 0; | |
295 if(int_O_DBG_pre_bitfield & DBG_RUN) | |
296 int_O_DBG_pre_bitfield = DBG_RESTART; | |
297 else | |
298 int_O_DBG_pre_bitfield = DBG_RUN; | |
299 int_O_DBG_post_bitfield = 0; | |
167 | 300 |
301 //---- Set 20meters ND limit --------------------------------------------- | |
116 | 302 char_O_NDL_at_20mtr = 255; |
303 | |
167 | 304 //---- Copy all dive parameters ------------------------------------------ |
116 | 305 DBG_N2_ratio = N2_ratio; |
306 DBG_He_ratio = He_ratio; | |
307 DBG_char_I_deco_model = char_I_deco_model; | |
308 DBG_char_I_depth_last_deco = char_I_depth_last_deco; | |
309 DBG_pres_surface = pres_surface; | |
310 DBG_GF_low = GF_low; | |
311 DBG_GF_high = GF_high; | |
312 DBG_const_ppO2 = const_ppO2; | |
313 DBG_deco_ppO2_change = deco_ppO2_change; | |
314 DBG_deco_ppO2 = deco_ppO2; | |
224 | 315 DBG_deco_N2_ratio = char_I_deco_N2_ratio[0]; |
316 DBG_deco_He_ratio = char_I_deco_He_ratio[0]; | |
225 | 317 DBG_deco_gas_change = deco_gas_change[0]; |
116 | 318 DBG_float_saturation_multiplier = float_saturation_multiplier; |
319 DBG_float_desaturation_multiplier = float_desaturation_multiplier; | |
320 DBG_float_deco_distance = float_deco_distance; | |
321 | |
167 | 322 //---- Setup some error (?) conditions ----------------------------------- |
116 | 323 if(char_I_deco_model) |
324 int_O_DBS_bitfield |= DBS_mode; | |
325 if(const_ppO2) | |
326 int_O_DBS_bitfield |= DBS_ppO2; | |
167 | 327 for(i = 16; i < 32; i++) |
328 if(pres_tissue[i]) | |
116 | 329 int_O_DBS_bitfield |= DBS_HE_sat; |
330 if(deco_ppO2_change) | |
331 int_O_DBS_bitfield |= DBS_ppO2chg; | |
332 if(float_saturation_multiplier < 0.99) | |
333 int_O_DBS_bitfield |= DBS_SAT2l; | |
334 if(float_saturation_multiplier > 1.3) | |
335 int_O_DBS_bitfield |= DBS_SAT2h; | |
336 if(GF_low < 0.19) | |
337 int_O_DBS_bitfield |= DBS_GFLOW2l; | |
338 if(GF_low > 1.01) | |
339 int_O_DBS_bitfield |= DBS_GFLOW2h; | |
340 if(GF_high < 0.6) | |
341 int_O_DBS_bitfield |= DBS_GFHGH2l; | |
342 if(GF_high > 1.01) | |
343 int_O_DBS_bitfield |= DBS_GFHGH2h; | |
344 if((N2_ratio + He_ratio) > 0.95) | |
345 int_O_DBS_bitfield |= DBS_GASO22l; | |
346 if((N2_ratio + He_ratio) < 0.05) | |
347 int_O_DBS_bitfield |= DBS_GASO22h; | |
348 if(float_deco_distance > 0.25) | |
349 int_O_DBS_bitfield |= DBS_DIST2h; | |
350 if(char_I_depth_last_deco > 8) | |
351 int_O_DBS_bitfield |= DBS_LAST2h; | |
224 | 352 if(DBG_deco_gas_change && ((char_I_deco_N2_ratio[0] + char_I_deco_He_ratio[0]) > 95)) |
116 | 353 int_O_DBS_bitfield |= DBS_DECOO2l; |
224 | 354 if(DBG_deco_gas_change && ((char_I_deco_N2_ratio[0] + char_I_deco_He_ratio[0]) < 5)) |
116 | 355 int_O_DBS_bitfield |= DBS_DECOO2h; |
356 if(pres_respiration > 3.0) | |
357 int_O_DBS2_bitfield |= DBS2_PRES2h; | |
358 if(pres_surface - pres_respiration > 0.2) | |
359 int_O_DBS2_bitfield |= DBS2_PRES2l; | |
360 if(pres_surface < 0.75) | |
361 int_O_DBS2_bitfield |= DBS2_SURF2l; | |
362 if(pres_surface > 1.11) | |
363 int_O_DBS2_bitfield |= DBS2_SURF2h; | |
364 if(float_desaturation_multiplier < 0.70) | |
365 int_O_DBS2_bitfield |= DBS2_DESAT2l; | |
366 if(float_desaturation_multiplier > 1.01) | |
367 int_O_DBS2_bitfield |= DBS2_DESAT2h; | |
368 if(GF_low > GF_high) | |
369 int_O_DBS2_bitfield |= DBS2_GFDneg; | |
370 } | |
371 | |
167 | 372 ////////////////////////////////////////////////////////////////////////////// |
373 // DBG - set DBG to end_of_dive | |
374 // | |
375 static void set_dbg_end_of_dive(void) | |
116 | 376 { |
377 int_O_DBG_pre_bitfield &= (~DBG_RUN); | |
378 int_O_DBG_post_bitfield &= (~DBG_RUN); | |
379 } | |
380 | |
167 | 381 ////////////////////////////////////////////////////////////////////////////// |
382 // DBG - NDL at first 20 m. hit | |
383 // | |
384 static void check_ndl(void) | |
116 | 385 { |
167 | 386 if( char_O_NDL_at_20mtr == 255 // Still in NDL mode ? |
387 && int_I_pres_respiration > 3000 // And we hit the 20m limit ? | |
388 ) | |
116 | 389 { |
167 | 390 char_O_NDL_at_20mtr = char_O_nullzeit; // change to max bottom time. |
391 if( char_O_NDL_at_20mtr == 255) // and avoid confusion. | |
184 | 392 char_O_NDL_at_20mtr = 254; |
116 | 393 } |
394 } | |
395 | |
167 | 396 ////////////////////////////////////////////////////////////////////////////// |
397 // DBG - multi main during dive | |
398 // | |
184 | 399 static void check_dbg(PARAMETER char is_post_check) |
116 | 400 { |
203 | 401 overlay unsigned short temp_DBS = 0; |
200 | 402 overlay unsigned char i; // Local loop index. |
167 | 403 |
116 | 404 if( (DBG_N2_ratio != N2_ratio) || (DBG_He_ratio != He_ratio) ) |
405 temp_DBS |= DBG_c_gas; | |
406 if(DBG_const_ppO2 != const_ppO2) | |
407 temp_DBS |= DBG_c_ppO2; | |
167 | 408 if( DBG_float_saturation_multiplier != float_saturation_multiplier |
409 || DBG_float_desaturation_multiplier != float_desaturation_multiplier | |
410 ) | |
116 | 411 temp_DBS |= DBG_CdeSAT; |
412 if(DBG_char_I_deco_model != char_I_deco_model) | |
413 temp_DBS |= DBG_C_MODE; | |
414 if(DBG_pres_surface != pres_surface) | |
415 temp_DBS |= DBG_C_SURF; | |
167 | 416 |
417 if( !DBS_HE_sat && !He_ratio) | |
418 for(i = 16; i < 32; i++) | |
419 if(pres_tissue[i]) | |
116 | 420 temp_DBS |= DBG_HEwoHE; |
167 | 421 |
116 | 422 if(DBG_deco_ppO2 != deco_ppO2) |
423 temp_DBS |= DBG_C_DPPO2; | |
167 | 424 |
225 | 425 if( DBG_deco_gas_change != deco_gas_change[0] |
224 | 426 || DBG_deco_N2_ratio != char_I_deco_N2_ratio[0] |
427 || DBG_deco_He_ratio != char_I_deco_He_ratio[0] ) | |
116 | 428 temp_DBS |= DBG_C_DGAS; |
167 | 429 |
116 | 430 if(DBG_float_deco_distance != float_deco_distance) |
431 temp_DBS |= DBG_C_DIST; | |
432 if(DBG_char_I_depth_last_deco != char_I_depth_last_deco) | |
433 temp_DBS |= DBG_C_LAST; | |
167 | 434 if( DBG_GF_low != GF_low |
435 || DBG_GF_high != GF_high ) | |
116 | 436 temp_DBS |= DBG_C_GF; |
437 if(pres_respiration > 13.0) | |
438 temp_DBS |= DBG_PHIGH; | |
439 if(pres_surface - pres_respiration > 0.2) | |
440 temp_DBS |= DBG_PLOW; | |
441 if(is_post_check) | |
442 int_O_DBG_post_bitfield |= temp_DBS; | |
443 else | |
444 int_O_DBG_pre_bitfield |= temp_DBS; | |
445 } | |
446 | |
167 | 447 ////////////////////////////////////////////////////////////////////////////// |
448 // DBG - prior to calc. of dive | |
449 // | |
450 static void check_pre_dbg(void) | |
116 | 451 { |
452 check_dbg(0); | |
453 } | |
454 | |
167 | 455 ////////////////////////////////////////////////////////////////////////////// |
456 // DBG - after decocalc of dive | |
457 // | |
458 static void check_post_dbg(void) | |
116 | 459 { |
460 check_dbg(1); | |
461 } | |
462 | |
165 | 463 ////////////////////////////////////////////////////////////////////////////// |
167 | 464 ////////////////////////////////////////////////////////////////////////////// |
465 /////////////////////// U T I L I T I E S ///////////////////////////////// | |
466 ////////////////////////////////////////////////////////////////////////////// | |
467 ////////////////////////////////////////////////////////////////////////////// | |
468 | |
235 | 469 ////////////////////////////////////////////////////////////////////////////// |
257
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
470 // Bump to blue-screen when an assert is wrong |
235 | 471 #ifdef __DEBUG |
472 void assert_failed(PARAMETER short int line) | |
473 { | |
474 extern void PLED_resetdebugger(void); | |
475 extern unsigned short temp10; | |
476 | |
257
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
477 temp10 = line; // Show source line number as stack depth. |
235 | 478 PLED_resetdebugger(); |
479 } | |
480 #endif | |
257
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
481 |
235 | 482 ////////////////////////////////////////////////////////////////////////////// |
483 // When calling C code from ASM context, the data stack pointer and | |
484 // frames should be reset. Bank8 is used by stack, when not doing hashing. | |
485 | |
486 #ifdef CROSS_COMPILE | |
487 # define RESET_C_STACK | |
488 #else | |
489 # ifdef __DEBUG | |
490 # define RESET_C_STACK fillDataStack(); | |
491 void fillDataStack(void) | |
492 { | |
493 _asm | |
494 LFSR 1,C_STACK | |
495 MOVLW 0xCC | |
496 loop: MOVWF POSTINC1,0 | |
497 TSTFSZ FSR1L,0 | |
498 BRA loop | |
499 | |
500 LFSR 1,C_STACK | |
501 LFSR 2,C_STACK | |
502 _endasm | |
503 } | |
504 # else | |
505 # define RESET_C_STACK \ | |
506 _asm \ | |
507 LFSR 1, C_STACK \ | |
508 LFSR 2, C_STACK \ | |
509 _endasm | |
510 # endif | |
511 #endif | |
512 | |
513 ////////////////////////////////////////////////////////////////////////////// | |
257
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
514 // Read CF values from the C code. |
235 | 515 |
203 | 516 static short read_custom_function(PARAMETER unsigned char cf) |
167 | 517 { |
184 | 518 #ifdef CROSS_COMPILE |
519 extern unsigned short custom_functions[]; | |
520 return custom_functions[cf]; | |
521 #else | |
167 | 522 extern unsigned char hi, lo; |
523 extern void getcustom15(); | |
524 _asm | |
525 movff cf,WREG | |
526 call getcustom15,0 | |
527 movff lo,PRODL | |
528 movff hi,PRODH | |
529 _endasm | |
184 | 530 #endif |
167 | 531 } |
532 | |
533 ////////////////////////////////////////////////////////////////////////////// | |
257
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
534 // Fast subroutine to read RTC timer 3. |
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
535 // Note: result is in 1/32 of msecs. |
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
536 static unsigned short tmr3(void) |
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
537 { |
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
538 _asm |
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
539 movff 0xfb2,PRODL // TMR3L |
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
540 movff 0xfb3,PRODH // TMR3H |
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
541 _endasm // result in PRODH:PRODL. |
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
542 } |
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
543 |
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
544 ////////////////////////////////////////////////////////////////////////////// |
258 | 545 // read buhlmann tables A and B for compatriment ci |
546 // | |
547 static void read_buhlmann_coefficients(void) | |
165 | 548 { |
184 | 549 #ifndef CROSS_COMPILE |
167 | 550 // Note: we don't use far rom pointer, because the |
551 // 24 bits is to complex, hence we have to set | |
552 // the UPPER page ourself... | |
553 // --> Set zero if tables are moved to lower pages ! | |
554 _asm | |
555 movlw 1 | |
556 movwf TBLPTRU,0 | |
557 _endasm | |
184 | 558 #endif |
258 | 559 |
197 | 560 assert( 0 <= ci && ci < 16 ); |
165 | 561 var_N2_a = buhlmann_a[ci]; |
562 var_N2_b = buhlmann_b[ci]; | |
167 | 563 var_He_a = (buhlmann_a+16)[ci]; |
564 var_He_b = (buhlmann_b+16)[ci]; | |
565 | |
165 | 566 // Check reading consistency: |
567 if( (var_N2_a < 0.231) | |
568 || (var_N2_a > 1.27) | |
569 || (var_N2_b < 0.504) | |
570 || (var_N2_b > 0.966) | |
571 || (var_He_a < 0.510) | |
572 || (var_He_a > 1.75) | |
573 || (var_He_b < 0.423) | |
574 || (var_He_b > 0.927) | |
575 ) | |
258 | 576 int_O_DBG_pre_bitfield |= DBG_ZH16ERR; |
577 } | |
578 | |
579 ////////////////////////////////////////////////////////////////////////////// | |
580 // read buhlmann tables for compatriment ci | |
581 // If period == 0 : 2sec interval | |
582 // 1 : 1 min interval | |
583 // 2 : 10 min interval. | |
584 static void read_buhlmann_times(PARAMETER char period) | |
585 { | |
586 #ifndef CROSS_COMPILE | |
587 // Note: we don't use far rom pointer, because the | |
588 // 24 bits is to complex, hence we have to set | |
589 // the UPPER page ourself... | |
590 // --> Set zero if tables are moved to lower pages ! | |
591 _asm | |
592 movlw 1 | |
593 movwf TBLPTRU,0 | |
594 _endasm | |
595 #endif | |
596 assert( 0 <= ci && ci < 16 ); | |
597 | |
165 | 598 // Integration intervals. |
167 | 599 switch(period) |
165 | 600 { |
601 case 0: //---- 2 sec ----------------------------------------------------- | |
602 var_N2_e = e2secs[ci]; | |
167 | 603 var_He_e = (e2secs+16)[ci]; |
165 | 604 |
605 // Check reading consistency: | |
606 if( (var_N2_e < 0.0000363) | |
607 || (var_N2_e > 0.00577) | |
608 || (var_He_e < 0.0000961) | |
609 || (var_He_e > 0.150) | |
610 ) | |
611 int_O_DBG_pre_bitfield |= DBG_ZH16ERR; | |
612 | |
613 break; | |
614 | |
615 case 1: //---- 1 min ----------------------------------------------------- | |
616 var_N2_e = e1min[ci]; | |
167 | 617 var_He_e = (e1min+16)[ci]; |
165 | 618 |
619 // Check reading consistency: | |
620 if( (var_N2_e < 1.09E-3) | |
621 || (var_N2_e > 0.1592) | |
622 || (var_He_e < 0.00288) | |
623 || (var_He_e > 0.3682) | |
624 ) | |
625 int_O_DBG_pre_bitfield |= DBG_ZH16ERR; | |
626 | |
627 break; | |
628 | |
629 case 2: //---- 10 min ---------------------------------------------------- | |
630 var_N2_e = e10min[ci]; | |
167 | 631 var_He_e = (e10min+16)[ci]; |
165 | 632 |
633 // Check reading consistency: | |
634 if( (var_N2_e < 0.01085) | |
635 || (var_N2_e > 0.82323) | |
636 || (var_He_e < 0.02846) | |
637 || (var_He_e > 0.98986) | |
638 ) | |
639 int_O_DBG_pre_bitfield |= DBG_ZH16ERR; | |
640 | |
641 break; | |
197 | 642 |
643 default: | |
644 assert(0); // Never go there... | |
165 | 645 } |
646 } | |
647 | |
648 ////////////////////////////////////////////////////////////////////////////// | |
167 | 649 // calc_next_decodepth_GF |
165 | 650 // |
116 | 651 // new in v.102 |
165 | 652 // |
116 | 653 // INPUT, changing during dive: |
192 | 654 // low_depth |
167 | 655 // |
116 | 656 // INPUT, fixed during dive: |
167 | 657 // pres_surface |
658 // GF_delta | |
659 // GF_high | |
660 // GF_low | |
171 | 661 // char_I_depth_last_deco |
167 | 662 // float_deco_distance |
663 // | |
241 | 664 // RETURN TRUE iff a stop is needed. |
665 // | |
116 | 666 // OUTPUT |
171 | 667 // locked_GF_step |
167 | 668 // temp_depth_limt |
192 | 669 // low_depth |
167 | 670 // |
241 | 671 static unsigned char calc_nextdecodepth(void) |
167 | 672 { |
241 | 673 //--- Max ascent speed --------------------------------------------------- |
674 // Recompute leading gas limit, at current depth: | |
675 overlay float depth = (temp_deco - pres_surface) / 0.09985; | |
676 | |
677 // At most, ascent 1 minute, at 10m/min == 10.0 m. | |
678 overlay float min_depth = depth - 10.0; | |
679 | |
680 // Do we need to stop at current depth ? | |
681 overlay unsigned char need_stop = 0; | |
682 | |
683 assert( depth >= -0.2 ); // Allow for 200mbar of weather change. | |
684 assert( low_depth < 255 ); | |
685 | |
212 | 686 //---- ZH-L16 + GRADIENT FACTOR model ------------------------------------ |
116 | 687 if (char_I_deco_model == 1) |
688 { | |
241 | 689 if( depth >= low_depth ) |
192 | 690 sim_limit( GF_low ); |
691 else | |
692 sim_limit( GF_high - depth * locked_GF_step ); | |
693 | |
694 // Stops are needed ? | |
695 if( sim_lead_tissue_limit > pres_surface ) | |
696 { | |
241 | 697 // Deepest stop, in meter (rounded up with a margin of 0.5m) |
698 overlay unsigned char first_stop = 3 * (short)(0.83 + (sim_lead_tissue_limit - pres_surface) / 0.29955); | |
192 | 699 assert( first_stop < 128 ); |
171 | 700 |
212 | 701 // Apply correction for the shallowest stop. |
192 | 702 if( first_stop == 3 ) // new in v104 |
703 first_stop = char_I_depth_last_deco; // Use last 3m..6m instead. | |
171 | 704 |
192 | 705 // Check all stops until one is higher than tolerated presure |
706 while(first_stop > 0) | |
707 { | |
708 overlay unsigned char next_stop; // Next index (0..30) | |
709 overlay float pres_stop; // Next depth (0m..90m) | |
171 | 710 |
241 | 711 // Check max speed, or reaching surface. |
712 if( first_stop <= min_depth ) | |
713 break; | |
714 | |
715 // So, there is indeed a stop needed: | |
716 need_stop = 1; | |
717 | |
192 | 718 if( first_stop <= char_I_depth_last_deco ) // new in v104 |
719 next_stop = 0; | |
216 | 720 else if( first_stop == 6 ) |
721 next_stop = char_I_depth_last_deco; | |
192 | 722 else |
723 next_stop = first_stop - 3; // Index of next (upper) stop. | |
167 | 724 |
241 | 725 pres_stop = next_stop * 0.09985 // Meters to bar |
192 | 726 + pres_surface; |
727 | |
212 | 728 // Keep GF_low until a first stop depth is found: |
729 if( next_stop >= low_depth ) | |
730 sim_limit( GF_low ); | |
731 else | |
732 // current GF is GF_high - alpha (GF_high - GF_low) | |
733 // With alpha = currentDepth / maxDepth, hence in [0..1] | |
734 sim_limit( GF_high - next_stop * locked_GF_step ); | |
171 | 735 |
192 | 736 // upper limit (lowest pressure tolerated): |
737 if( sim_lead_tissue_limit >= pres_stop ) // check if ascent to next deco stop is ok | |
738 break; | |
739 | |
740 // Else, validate that stop and loop... | |
741 first_stop = next_stop; | |
742 } | |
171 | 743 |
212 | 744 // Is it a new deepest first stop ? If yes this is the reference for |
745 // the varying gradient factor. So reset that: | |
241 | 746 if( first_stop > min_depth && first_stop > low_depth ) |
212 | 747 { |
748 // Store the deepest stop depth, as reference for GF_low. | |
749 low_depth = first_stop; | |
750 locked_GF_step = GF_delta / low_depth; | |
751 } | |
752 | |
753 // next stop is the last validated depth found, aka first_stop | |
192 | 754 temp_depth_limit = first_stop; // Stop depth, in meter. |
755 } | |
171 | 756 else |
192 | 757 temp_depth_limit = 0; // stop depth, in meter. |
116 | 758 } |
167 | 759 else //---- ZH-L16 model ------------------------------------------------- |
116 | 760 { |
192 | 761 overlay float pres_gradient; |
762 | |
763 // Original model | |
116 | 764 // optimized in v.101 |
171 | 765 // char_I_depth_last_deco included in v.101 |
116 | 766 |
192 | 767 // Compute sim_lead_tissue_limit too, but just once. |
768 sim_limit(1.0); | |
769 | |
770 pres_gradient = sim_lead_tissue_limit - pres_surface; | |
167 | 771 if (pres_gradient >= 0) |
116 | 772 { |
241 | 773 pres_gradient /= 0.29955; // Bar --> stop number; |
203 | 774 temp_depth_limit = 3 * (short) (pres_gradient + 0.99); // --> meter : depth for deco |
241 | 775 need_stop = 1; // Hit. |
776 | |
777 // Implement last stop at 4m/5m/6m... | |
778 if( temp_depth_limit == 3 ) | |
779 temp_depth_limit = char_I_depth_last_deco; | |
171 | 780 } |
116 | 781 else |
241 | 782 temp_depth_limit = 0; |
171 | 783 } |
212 | 784 |
217 | 785 //---- Check gas change -------------------------------------------------- |
241 | 786 need_stop |= gas_switch_deepest(); // Update temp_depth_limit if there is a change, |
787 | |
788 return need_stop; | |
167 | 789 } |
116 | 790 |
167 | 791 ////////////////////////////////////////////////////////////////////////////// |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
792 // copy_deco_table |
167 | 793 // |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
794 // Buffer the stops, once computed, so we can continue to display them |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
795 // while computing the next set. |
167 | 796 // |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
797 static void copy_deco_table(void) |
116 | 798 { |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
799 // Copy depth of the first (deepest) stop, because when reversing |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
800 // order, it will be hard to find... |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
801 char_O_first_deco_depth = internal_deco_depth[0]; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
802 char_O_first_deco_time = internal_deco_time [0]; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
803 |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
804 if( read_custom_function(54) & 1 ) //---- Should we reverse table ? ------ |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
805 { |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
806 overlay unsigned char x, y; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
807 |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
808 //---- First: search the first non-null depth |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
809 for(x=31; x != 0; --x) |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
810 if( internal_deco_depth[x] != 0 ) break; |
116 | 811 |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
812 //---- Second: copy to output table (in reverse order) |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
813 for(y=0; y<32; y++, --x) |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
814 { |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
815 char_O_deco_depth[y] = internal_deco_depth[x]; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
816 char_O_deco_time [y] = internal_deco_time [x]; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
817 |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
818 // Stop only once the last transfer is done. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
819 if( x == 0 ) break; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
820 } |
116 | 821 |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
822 //---- Third: fill table end with null |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
823 for(y++; y<32; y++) |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
824 { |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
825 char_O_deco_time [y] = 0; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
826 char_O_deco_depth[y] = 0; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
827 } |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
828 } |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
829 else //---- Straight copy ------------------------------------------------ |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
830 { |
167 | 831 overlay unsigned char x; |
832 | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
833 for(x=0; x<32; x++) |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
834 { |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
835 char_O_deco_depth[x] = internal_deco_depth[x]; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
836 char_O_deco_time [x] = internal_deco_time [x]; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
837 } |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
838 } |
167 | 839 } |
116 | 840 |
167 | 841 ////////////////////////////////////////////////////////////////////////////// |
116 | 842 // temp_tissue_safety // |
167 | 843 // |
116 | 844 // outsourced in v.102 |
167 | 845 // |
846 // Apply safety factors for brand ZH-L16 model. | |
847 // | |
848 static void temp_tissue_safety(void) | |
116 | 849 { |
197 | 850 assert( 0.0 < float_desaturation_multiplier && float_desaturation_multiplier <= 1.0 ); |
851 assert( 1.0 <= float_saturation_multiplier && float_saturation_multiplier <= 2.0 ); | |
852 | |
167 | 853 if( char_I_deco_model == 0 ) |
116 | 854 { |
855 if (temp_tissue < 0.0) | |
126 | 856 temp_tissue *= float_desaturation_multiplier; |
116 | 857 else |
126 | 858 temp_tissue *= float_saturation_multiplier; |
116 | 859 } |
167 | 860 } |
116 | 861 |
167 | 862 ////////////////////////////////////////////////////////////////////////////// |
863 ////////////////////////////////////////////////////////////////////////////// | |
116 | 864 // ** THE JUMP-IN CODE ** |
865 // ** for the asm code ** | |
167 | 866 ////////////////////////////////////////////////////////////////////////////// |
867 ////////////////////////////////////////////////////////////////////////////// | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
868 |
167 | 869 ////////////////////////////////////////////////////////////////////////////// |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
870 // Called every 2 seconds during diving. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
871 // update tissues every time. |
184 | 872 // |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
873 // Every 6 seconds (or slower when TTS > 16): |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
874 // - update deco table (char_O_deco_time/depth) with new values. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
875 // - update ascent time, |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
876 // - set status to zero (so we can check there is new results). |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
877 // |
116 | 878 void deco_calc_hauptroutine(void) |
879 { | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
880 RESET_C_STACK |
116 | 881 calc_hauptroutine(); |
882 int_O_desaturation_time = 65535; | |
883 } | |
884 | |
167 | 885 ////////////////////////////////////////////////////////////////////////////// |
184 | 886 // Reset decompression model: |
887 // + Set all tissues to equilibrium with Air at ambient pressure. | |
888 // + Reset last stop to 0m | |
889 // + Reset all model output. | |
116 | 890 void deco_clear_tissue(void) |
891 { | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
892 RESET_C_STACK |
116 | 893 clear_tissue(); |
894 } | |
895 | |
167 | 896 ////////////////////////////////////////////////////////////////////////////// |
897 | |
116 | 898 void deco_calc_wo_deco_step_1_min(void) |
899 { | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
900 RESET_C_STACK |
116 | 901 calc_wo_deco_step_1_min(); |
902 deco_calc_desaturation_time(); | |
903 } | |
904 | |
167 | 905 ////////////////////////////////////////////////////////////////////////////// |
906 | |
116 | 907 void deco_debug(void) |
908 { | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
909 RESET_C_STACK |
116 | 910 } |
911 | |
241 | 912 |
913 ////////////////////////////////////////////////////////////////////////////// | |
914 // Find current gas in the list (if any). | |
915 // | |
916 // Input: char_I_deco_N2_ratio[] and He, to detect breathed gas. | |
917 // | |
918 // Output: sim_gas_depth_used | |
919 // | |
920 static void gas_switch_find_current(void) | |
921 { | |
247
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
922 overlay unsigned char j; |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
923 overlay unsigned char N2 = (unsigned char)(N2_ratio * 100 + 0.5); |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
924 overlay unsigned char He = (unsigned char)(He_ratio * 100 + 0.5); |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
925 |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
926 for(j=0; j<5; ++j) |
241 | 927 { |
247
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
928 // Make sure to detect if we are already breathing some gas in |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
929 // the current list (happends when first gas do have a depth). |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
930 if( N2 == char_I_deco_N2_ratio[j] |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
931 && He == char_I_deco_He_ratio[j] |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
932 ) |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
933 { |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
934 temp_depth_limit = sim_gas_last_depth = char_I_deco_gas_change[j]; |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
935 sim_gas_last_used = j+1; |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
936 break; |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
937 } |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
938 } |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
939 |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
940 // If there is no gas-switch-delay running ? |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
941 if( sim_gas_delay <= sim_dive_mins) |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
942 { |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
943 // Compute current depth: |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
944 overlay unsigned char depth = (unsigned char)((pres_respiration - pres_surface) / 0.09985); |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
945 assert( depth < 130 ); |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
946 |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
947 // And if I'm above the last decostop (with the 3m margin) ? |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
948 if( (sim_gas_last_depth-3) > depth ) |
241 | 949 { |
247
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
950 for(j=0; j<5; ++j) |
241 | 951 { |
247
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
952 // And If I am in the range of a valide stop ? |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
953 // (again, with the same 3m margin) |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
954 if( char_I_deco_gas_change[j] |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
955 && depth <= char_I_deco_gas_change[j] |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
956 && depth >= (char_I_deco_gas_change[j] - 3) |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
957 ) |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
958 { |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
959 // Then start gas-switch timer there, |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
960 sim_gas_delay = sim_dive_mins |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
961 + read_custom_function(55); |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
962 |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
963 // And make sure decostop will be recorded at the right depth. |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
964 temp_depth_limit = char_I_deco_gas_change[j]; |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
965 break; |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
966 } |
241 | 967 } |
968 } | |
247
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
969 else |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
970 // Make clear there is no deay anymore. |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
971 sim_gas_delay = 0; |
241 | 972 } |
973 } | |
974 | |
167 | 975 ////////////////////////////////////////////////////////////////////////////// |
217 | 976 // Find deepest available gas. |
201 | 977 // |
241 | 978 // Input: temp_depth_limit, |
979 // deco_gas_change[] | |
980 // sim_gas_delay, sim_gas_depth_used, sim_dive_mins. | |
212 | 981 // |
241 | 982 // RETURNS TRUE if a stop is needed for gas switch. |
983 // | |
984 // Output: temp_depth_limit, sim_gas_delay, sim_gas_depth_used IFF the is a switch. | |
212 | 985 // |
241 | 986 // NOTE: might be called from bottom (when sim_gas_delay and sim_gas_depth_used |
987 // are null), or during the ascent to make sure we are not passing a | |
988 // stop (in which case both can be already set). | |
989 // | |
990 static unsigned char gas_switch_deepest(void) | |
201 | 991 { |
241 | 992 overlay unsigned char switch_deco = 0, switch_last = 0; |
201 | 993 |
994 if (char_I_const_ppO2 == 0) | |
995 { | |
225 | 996 overlay unsigned char j; |
997 | |
241 | 998 // Loop over all enabled gas, to find the deepest one, |
999 // above las gas, but below temp_depth_limit. | |
1000 for(j=0; j<5; ++j) | |
225 | 1001 { |
241 | 1002 // Gas not (yet) allowed ? Skip ! |
1003 if( temp_depth_limit > deco_gas_change[j] ) | |
1004 continue; | |
1005 | |
1006 // Gas deeper than the current/previous one ? Skip ! | |
1007 if( sim_gas_last_depth && deco_gas_change[j] >= sim_gas_last_depth ) | |
1008 continue; | |
1009 | |
1010 // First, or deeper ? | |
247
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
1011 if( switch_deco < deco_gas_change[j] ) |
241 | 1012 { |
1013 switch_deco = deco_gas_change[j]; | |
1014 switch_last = j+1; | |
1015 } | |
225 | 1016 } |
201 | 1017 } |
1018 | |
203 | 1019 // If there is a better gas available |
241 | 1020 if( switch_deco ) |
201 | 1021 { |
241 | 1022 assert( !sim_gas_last_depth || sim_gas_last_depth > switch_deco ); |
201 | 1023 |
241 | 1024 // Should restart gas-switch delay only when gas do changes... |
1025 assert( sim_gas_delay <= sim_dive_mins ); | |
217 | 1026 |
241 | 1027 sim_gas_last_depth = switch_deco; |
1028 sim_gas_last_used = switch_last; | |
1029 sim_gas_delay = read_custom_function(55); | |
217 | 1030 |
241 | 1031 // Apply depth correction ONLY if CF#55 is not null: |
1032 if( sim_gas_delay > 0 ) | |
225 | 1033 { |
241 | 1034 sim_gas_delay += sim_dive_mins; |
1035 temp_depth_limit = switch_deco; | |
1036 return 1; | |
225 | 1037 } |
241 | 1038 |
1039 return 0; | |
217 | 1040 } |
1041 | |
241 | 1042 sim_gas_delay = 0; |
1043 return 0; | |
217 | 1044 } |
1045 | |
1046 ////////////////////////////////////////////////////////////////////////////// | |
1047 // Calculate gas switches | |
1048 // | |
1049 // | |
1050 // Input: N2_ratio, He_ratio. | |
1051 // sim_gas_last_used | |
1052 // | |
1053 // Output: calc_N2_ratio, calc_He_ratio | |
1054 // | |
241 | 1055 static void gas_switch_set(void) |
217 | 1056 { |
224 | 1057 assert( 0 <= sim_gas_last_used && sim_gas_last_used <= 5 ); |
217 | 1058 |
224 | 1059 if( sim_gas_last_used == 0 ) |
1060 { | |
1061 calc_N2_ratio = N2_ratio; | |
1062 calc_He_ratio = He_ratio; | |
1063 } | |
1064 else | |
1065 { | |
1066 calc_N2_ratio = char_I_deco_N2_ratio[sim_gas_last_used-1] * 0.01; | |
1067 calc_He_ratio = char_I_deco_He_ratio[sim_gas_last_used-1] * 0.01; | |
217 | 1068 } |
201 | 1069 |
1070 assert( 0.0 <= calc_N2_ratio && calc_N2_ratio <= 0.95 ); | |
1071 assert( 0.0 <= calc_He_ratio && calc_He_ratio <= 0.95 ); | |
1072 assert( (calc_N2_ratio + calc_He_ratio) <= 1.00 ); | |
1073 } | |
1074 | |
1075 ////////////////////////////////////////////////////////////////////////////// | |
1076 // | |
212 | 1077 // Input: calc_N2_ratio, calc_He_ratio : simulated gas mix. |
1078 // temp_deco : simulated respiration pressure + security offset (deco_distance) | |
1079 // Water-vapor pressure inside lumbs (ppWVapour). | |
1080 // | |
236 | 1081 // Output: ppN2, ppHe. |
212 | 1082 // |
1083 static void sim_alveolar_presures(void) | |
201 | 1084 { |
212 | 1085 overlay float deco_diluent = temp_deco; // new in v.101 |
1086 | |
1087 //---- CCR mode : deco gas switch ? -------------------------------------- | |
201 | 1088 if (char_I_const_ppO2 != 0) |
1089 { | |
212 | 1090 // In CCR mode, calc_XX_ratio == XX_ratio. |
1091 if( temp_deco > deco_ppO2_change ) | |
1092 deco_diluent = ((temp_deco - const_ppO2)/(calc_N2_ratio + calc_He_ratio)); | |
201 | 1093 else |
212 | 1094 deco_diluent = ((temp_deco - deco_ppO2)/(calc_N2_ratio + calc_He_ratio)); |
1095 | |
1096 if (deco_diluent > temp_deco) | |
1097 deco_diluent = temp_deco; | |
201 | 1098 } |
1099 | |
212 | 1100 // Take deco offset into account, but not at surface. |
1101 if( deco_diluent > pres_surface ) | |
1102 deco_diluent += float_deco_distance; | |
1103 | |
1104 if( deco_diluent > ppWVapour ) | |
201 | 1105 { |
236 | 1106 ppN2 = calc_N2_ratio * (deco_diluent - ppWVapour); |
201 | 1107 ppHe = calc_He_ratio * (deco_diluent - ppWVapour); |
1108 } | |
1109 else | |
1110 { | |
236 | 1111 ppN2 = 0.0; |
201 | 1112 ppHe = 0.0; |
1113 } | |
236 | 1114 assert( 0.0 <= ppN2 && ppN2 < 14.0 ); |
201 | 1115 assert( 0.0 <= ppHe && ppHe < 14.0 ); |
1116 } | |
1117 | |
1118 ////////////////////////////////////////////////////////////////////////////// | |
167 | 1119 // clear_tissue |
1120 // | |
165 | 1121 // optimized in v.101 (var_N2_a) |
167 | 1122 // |
1123 // preload tissues with standard pressure for the given ambient pressure. | |
1124 // Note: fixed N2_ratio for standard air. | |
201 | 1125 // |
167 | 1126 static void clear_tissue(void) |
116 | 1127 { |
1128 flag_in_divemode = 0; | |
1129 int_O_DBS_bitfield = 0; | |
1130 int_O_DBS2_bitfield = 0; | |
1131 int_O_DBG_pre_bitfield = 0; | |
1132 int_O_DBG_post_bitfield = 0; | |
1133 char_O_NDL_at_20mtr = 255; | |
1134 | |
167 | 1135 // Kludge: the 0.0002 of 0.7902 are missing with standard air. |
1136 N2_ratio = 0.7902; | |
212 | 1137 pres_respiration = int_I_pres_respiration * 0.001; |
164 | 1138 |
167 | 1139 for(ci=0; ci<16; ci++) |
126 | 1140 { |
197 | 1141 // cycle through the 16 Bühlmann tissues |
200 | 1142 overlay float p = N2_ratio * (pres_respiration - ppWVapour); |
164 | 1143 pres_tissue[ci] = p; |
197 | 1144 |
1145 // cycle through the 16 Bühlmann tissues for Helium | |
167 | 1146 (pres_tissue+16)[ci] = 0.0; |
126 | 1147 } // for 0 to 16 |
116 | 1148 |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1149 clear_deco_table(); |
126 | 1150 char_O_deco_status = 0; |
1151 char_O_nullzeit = 0; | |
168 | 1152 int_O_ascenttime = 0; |
126 | 1153 char_O_gradient_factor = 0; |
1154 char_O_relative_gradient_GF = 0; | |
197 | 1155 char_I_depth_last_deco = 0; // for compatibility with v.101pre_no_last_deco |
258 | 1156 |
1157 calc_lead_tissue_limit = 0.0; | |
1158 char_O_gtissue_no = 0; | |
167 | 1159 } |
116 | 1160 |
167 | 1161 ////////////////////////////////////////////////////////////////////////////// |
1162 // calc_hauptroutine | |
1163 // | |
1164 // this is the major code in dive mode calculates: | |
116 | 1165 // the tissues, |
167 | 1166 // the bottom time, |
1167 // and simulates the ascend with all deco stops. | |
171 | 1168 // |
1169 // The deco_state sequence is : | |
1170 // 3 (at surface) | |
1171 // +---> 0 : calc nullzeit | |
1172 // | 2 : simulate ascent to first stop (at 10m/min, less that 16x 1min simu) | |
1173 // | +-> 1 : simulate up to 16min of stops. | |
1174 // | +------< not finished | |
1175 // +--------< finish | |
1176 // | |
167 | 1177 static void calc_hauptroutine(void) |
116 | 1178 { |
241 | 1179 static unsigned char backup_gas_used = 0; |
1180 static unsigned char backup_gas_depth = 0; | |
217 | 1181 static unsigned char backup_gas_delay = 0; |
186 | 1182 |
116 | 1183 calc_hauptroutine_data_input(); |
1184 | |
1185 if(!flag_in_divemode) | |
1186 { | |
1187 flag_in_divemode = 1; | |
1188 create_dbs_set_dbg_and_ndl20mtr(); | |
1189 } | |
1190 else | |
1191 check_pre_dbg(); | |
1192 | |
1193 calc_hauptroutine_update_tissues(); | |
1194 calc_gradient_factor(); | |
1195 | |
167 | 1196 // toggle between calculation for nullzeit (bottom time), |
1197 // deco stops | |
1198 // and more deco stops (continue) | |
1199 switch( char_O_deco_status ) | |
116 | 1200 { |
186 | 1201 case 3: //---- At surface: start a new dive ------------------------------ |
1202 clear_deco_table(); | |
1203 copy_deco_table(); | |
200 | 1204 int_O_ascenttime = 0; // Reset DTR. |
1205 char_O_nullzeit = 0; // Reset bottom time. | |
1206 char_O_deco_status = 0; // Calc bottom-time/nullzeit next iteration. | |
201 | 1207 |
217 | 1208 // Values that should be reset just once for the full real dive. |
1209 // This is used to record the lowest stop for the whole dive, | |
1210 // Including ACCROSS all simulated ascent. | |
1211 low_depth = 0; | |
1212 | |
1213 // Reset gas switch history. | |
241 | 1214 backup_gas_used = sim_gas_last_used = 0; |
1215 backup_gas_depth = sim_gas_last_depth = 0; | |
217 | 1216 backup_gas_delay = sim_gas_delay = 0; |
203 | 1217 sim_dive_mins = 0; |
1218 break; | |
186 | 1219 |
167 | 1220 case 0: //---- bottom time ----------------------------------------------- |
1221 calc_nullzeit(); | |
1222 check_ndl(); | |
186 | 1223 char_O_deco_status = 2; // calc ascent next time. |
1224 break; | |
1225 | |
1226 case 2: //---- Simulate ascent to first stop ----------------------------- | |
203 | 1227 // Check proposed gas at begin of ascent simulation |
247
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
1228 sim_dive_mins = int_I_divemins; // Init current time. |
241 | 1229 |
247
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
1230 gas_switch_find_current(); // Lookup for current gas & time. |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
1231 gas_switch_set(); // setup calc_ratio's |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
1232 |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
1233 backup_gas_used = sim_gas_last_used; // And save for later simu steps. |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
1234 backup_gas_depth = sim_gas_last_depth; // And save for later simu steps. |
203 | 1235 backup_gas_delay = sim_gas_delay; |
186 | 1236 |
1237 sim_ascent_to_first_stop(); | |
201 | 1238 |
1239 char_O_deco_status = 1; // Calc stops next time (deco or gas switch). | |
167 | 1240 break; |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1241 |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1242 case 1: //---- Simulate stops -------------------------------------------- |
167 | 1243 calc_hauptroutine_calc_deco(); |
186 | 1244 |
1245 // If simulation is finished, restore the GF low reference, so that | |
1246 // next ascent simulation is done from the current depth: | |
217 | 1247 if( char_O_deco_status == 0 ) |
186 | 1248 { |
241 | 1249 sim_gas_last_used = backup_gas_used; |
1250 sim_gas_last_depth = backup_gas_depth; | |
247
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
1251 sim_gas_delay = backup_gas_delay; |
186 | 1252 } |
167 | 1253 break; |
116 | 1254 } |
167 | 1255 |
116 | 1256 check_post_dbg(); |
1257 } | |
1258 | |
167 | 1259 ////////////////////////////////////////////////////////////////////////////// |
1260 // calc_hauptroutine_data_input | |
1261 // | |
1262 // Reset all C-code dive parameters from their ASM-code values. | |
1263 // Detect gas change condition. | |
1264 // | |
116 | 1265 void calc_hauptroutine_data_input(void) |
1266 { | |
203 | 1267 overlay short int_temp; |
126 | 1268 |
197 | 1269 pres_respiration = int_I_pres_respiration * 0.001; |
1270 pres_surface = int_I_pres_surface * 0.001; | |
1271 N2_ratio = char_I_N2_ratio * 0.01; | |
1272 He_ratio = char_I_He_ratio * 0.01; | |
1273 float_deco_distance = char_I_deco_distance * 0.01; // Get offset is in mbar. | |
116 | 1274 |
126 | 1275 // ____________________________________________________ |
1276 // | |
1277 // _____________ G A S _ C H A N G E S ________________ | |
1278 // ____________________________________________________ | |
1279 | |
212 | 1280 // Keep a margin of 150mbar = 1.50m |
1281 int_temp = (int_I_pres_respiration - int_I_pres_surface) | |
1282 + MBAR_REACH_GASCHANGE_AUTO_CHANGE_OFF; | |
126 | 1283 |
225 | 1284 deco_gas_change[0] = 0; |
1285 deco_gas_change[1] = 0; | |
1286 deco_gas_change[2] = 0; | |
1287 deco_gas_change[3] = 0; | |
1288 deco_gas_change[4] = 0; | |
116 | 1289 |
203 | 1290 // Gas are selectable if we did not pass the change depth by more than 1.50m: |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
1291 if(char_I_deco_gas_change[0]) |
126 | 1292 { |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
1293 if( int_temp > 100 *(short)char_I_deco_gas_change[0] ) |
225 | 1294 deco_gas_change[0] = char_I_deco_gas_change[0]; |
126 | 1295 } |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
1296 if(char_I_deco_gas_change[1]) |
126 | 1297 { |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
1298 if( int_temp > 100 *(short)char_I_deco_gas_change[1] ) |
225 | 1299 deco_gas_change[1] = char_I_deco_gas_change[1]; |
126 | 1300 } |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
1301 if(char_I_deco_gas_change[2]) |
126 | 1302 { |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
1303 if( int_temp > 100 *(short)char_I_deco_gas_change[2] ) |
225 | 1304 deco_gas_change[2] = char_I_deco_gas_change[2]; |
126 | 1305 } |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
1306 if(char_I_deco_gas_change[3]) |
126 | 1307 { |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
1308 if( int_temp > 100 *(short)char_I_deco_gas_change[3] ) |
225 | 1309 deco_gas_change[3] = char_I_deco_gas_change[3]; |
126 | 1310 } |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
1311 if(char_I_deco_gas_change[4]) |
126 | 1312 { |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
1313 if( int_temp > 100 *(short)char_I_deco_gas_change[4] ) |
225 | 1314 deco_gas_change[4] = char_I_deco_gas_change[4]; |
126 | 1315 } |
116 | 1316 |
197 | 1317 const_ppO2 = char_I_const_ppO2 * 0.01; |
1318 deco_ppO2_change = char_I_deco_ppO2_change / 99.95 | |
1319 + pres_surface | |
1320 + float_deco_distance; | |
1321 deco_ppO2 = char_I_deco_ppO2 * 0.01; | |
1322 float_desaturation_multiplier = char_I_desaturation_multiplier * 0.01; | |
1323 float_saturation_multiplier = char_I_saturation_multiplier * 0.01; | |
1324 GF_low = char_I_GF_Low_percentage * 0.01; | |
1325 GF_high = char_I_GF_High_percentage * 0.01; | |
126 | 1326 GF_delta = GF_high - GF_low; |
116 | 1327 } |
1328 | |
167 | 1329 ////////////////////////////////////////////////////////////////////////////// |
171 | 1330 // |
1331 // | |
116 | 1332 void calc_hauptroutine_update_tissues(void) |
1333 { | |
197 | 1334 assert( 0.00 <= N2_ratio && N2_ratio <= 1.00 ); |
1335 assert( 0.00 <= He_ratio && He_ratio <= 1.00 ); | |
1336 assert( (N2_ratio + He_ratio) <= 0.95 ); | |
237 | 1337 assert( 0.800 < pres_respiration && pres_respiration < 14.0 ); |
197 | 1338 |
1339 if (char_I_const_ppO2 == 0) // new in v.101 | |
167 | 1340 pres_diluent = pres_respiration; // new in v.101 |
186 | 1341 else |
1342 { | |
167 | 1343 pres_diluent = ((pres_respiration - const_ppO2)/(N2_ratio + He_ratio)); // new in v.101 |
186 | 1344 if (pres_diluent > pres_respiration) // new in v.101 |
1345 pres_diluent = pres_respiration; // new in v.101 | |
1346 } | |
200 | 1347 if (pres_diluent > ppWVapour) // new in v.101 |
116 | 1348 { |
236 | 1349 ppN2 = N2_ratio * (pres_diluent - ppWVapour); // changed in v.101 |
200 | 1350 ppHe = He_ratio * (pres_diluent - ppWVapour); // changed in v.101 |
116 | 1351 char_O_diluent = (char)(pres_diluent/pres_respiration*100.0); |
1352 } | |
167 | 1353 else // new in v.101 |
116 | 1354 { |
236 | 1355 ppN2 = 0.0; // new in v.101 |
200 | 1356 ppHe = 0.0; // new in v.101 |
116 | 1357 char_O_diluent = 0; |
1358 } | |
1359 | |
1360 if(!char_I_step_is_1min) | |
192 | 1361 calc_tissue(0); |
116 | 1362 else |
192 | 1363 calc_tissue(1); |
186 | 1364 |
192 | 1365 // Calc limit for surface, ie. GF_high. |
258 | 1366 calc_limit(); |
186 | 1367 |
203 | 1368 int_O_gtissue_limit = (short)(calc_lead_tissue_limit * 1000); |
1369 int_O_gtissue_press = (short)((pres_tissue[char_O_gtissue_no] + (pres_tissue+16)[char_O_gtissue_no]) * 1000); | |
192 | 1370 |
1371 // if guiding tissue can not be exposed to surface pressure immediately | |
1372 if( calc_lead_tissue_limit > pres_surface && char_O_deco_status == 0) | |
116 | 1373 { |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1374 char_O_nullzeit = 0; // deco necessary |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1375 char_O_deco_status = 2; // calculate ascent on next iteration. |
116 | 1376 } |
171 | 1377 } |
1378 | |
116 | 1379 |
167 | 1380 ////////////////////////////////////////////////////////////////////////////// |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1381 // Compute stops. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1382 // |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1383 // Note: because this can be very long, break on 16 iterations, and set state |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1384 // to 0 when finished, or to 1 when needing to continue. |
257
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
1385 // Note: because this might be very long (~ 66 ms by iteration in 1.84beta), |
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
1386 // break the loop when total time > 512msec. |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1387 // |
116 | 1388 void calc_hauptroutine_calc_deco(void) |
1389 { | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1390 overlay unsigned char loop; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1391 |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1392 for(loop = 0; loop < 16; ++loop) |
116 | 1393 { |
257
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
1394 // Limit loops to 512ms, using the RTC timer 3: |
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
1395 if( tmr3() & (512*32) ) |
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
1396 break; |
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
1397 |
241 | 1398 // Do not ascent while doing a gas switch ? |
203 | 1399 if( sim_gas_delay <= sim_dive_mins ) |
1400 { | |
241 | 1401 if( calc_nextdecodepth() ) |
1402 { | |
1403 if( temp_depth_limit == 0 ) | |
1404 goto Surface; | |
116 | 1405 |
241 | 1406 //---- We hit a stop at temp_depth_limit --------------------- |
1407 temp_deco = temp_depth_limit * 0.09985 // Convert to relative bar, | |
1408 + pres_surface; // To absolute. | |
1409 update_deco_table(); // Adds a one minute stops. | |
1410 } | |
1411 else | |
1412 { | |
1413 //---- No stop ----------------------------------------------- | |
1414 temp_deco -= 0.9985; // Ascend 10m, no wait. | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1415 |
241 | 1416 //---- Finish computations once surface is reached ----------- |
1417 if( temp_deco <= pres_surface ) | |
1418 { | |
1419 Surface: | |
1420 copy_deco_table(); | |
1421 calc_ascenttime(); | |
1422 char_O_deco_status = 0; // calc nullzeit next time. | |
1423 return; | |
1424 } | |
1425 } | |
212 | 1426 |
1427 } | |
1428 else | |
241 | 1429 update_deco_table(); // Just pass one minute. |
197 | 1430 |
241 | 1431 //---- Then update tissue -------------------------------------------- |
203 | 1432 sim_dive_mins++; // Advance simulated time by 1 minute. |
241 | 1433 gas_switch_set(); // Apply any simulated gas change, once validated. |
212 | 1434 sim_alveolar_presures(); // Updates ppN2 and ppHe. |
192 | 1435 sim_tissue(1); // Simulate compartiments for 1 minute. |
116 | 1436 } |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1437 |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1438 // Surface not reached, need more stops... |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1439 char_O_deco_status = 1; // calc more stops next time. |
116 | 1440 } |
1441 | |
167 | 1442 ////////////////////////////////////////////////////////////////////////////// |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1443 // Simulation ascention to first deco stop. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1444 // |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1445 // Note: because we ascent with a constant speed (10m/mn, ie. 1bar/mn), |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1446 // there is no need to break on more that 16 iterations |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1447 // (or we are already in deep shit). |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1448 // |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1449 void sim_ascent_to_first_stop(void) |
116 | 1450 { |
171 | 1451 update_startvalues(); |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1452 clear_deco_table(); |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1453 |
200 | 1454 temp_deco = pres_respiration; // Starts from current real depth. |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1455 |
212 | 1456 // Do we have a gas switch going on ? |
1457 if( sim_gas_delay > sim_dive_mins ) | |
1458 return; | |
1459 | |
241 | 1460 //---- Loop until first stop, gas switch, or surface is reached ---------- |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1461 for(;;) |
116 | 1462 { |
241 | 1463 // Try ascending 1 full minute. |
1464 temp_deco -= 0.9985; // 1 min, at 10m/min. ~ 1bar. | |
203 | 1465 |
212 | 1466 // Compute sim_lead_tissue_limit at GF_low (deepest stop). |
1467 sim_limit(GF_low); | |
1468 | |
1469 // Did we reach deepest remaining stop ? | |
241 | 1470 if( temp_deco < sim_lead_tissue_limit ) |
212 | 1471 { |
241 | 1472 temp_deco += 0.9985; // Restore last correct depth, |
1473 break; // End fast ascent. | |
212 | 1474 } |
1475 | |
203 | 1476 // Did we reach surface ? |
1477 if( temp_deco <= pres_surface ) | |
1478 { | |
1479 temp_deco = pres_surface; // Yes: finished ! | |
1480 break; | |
1481 } | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1482 |
241 | 1483 // Check for gas change below new depth ? |
1484 temp_depth_limit = (temp_deco - pres_surface) / 0.09985; | |
1485 | |
1486 if( gas_switch_deepest() ) | |
1487 { | |
1488 temp_deco = temp_depth_limit * 0.09985 + pres_surface; | |
212 | 1489 break; |
241 | 1490 } |
171 | 1491 |
203 | 1492 sim_dive_mins++; // Advance simulated time by 1 minute. |
241 | 1493 sim_alveolar_presures(); // temp_deco --> ppN2/ppHe |
203 | 1494 sim_tissue(1); // and update tissues for 1 min. |
1495 } | |
167 | 1496 } |
116 | 1497 |
167 | 1498 ////////////////////////////////////////////////////////////////////////////// |
1499 // calc_tissue | |
1500 // | |
116 | 1501 // optimized in v.101 |
167 | 1502 // |
184 | 1503 static void calc_tissue(PARAMETER unsigned char period) |
116 | 1504 { |
251 | 1505 assert( 0.00 <= ppN2 && ppN2 < 11.2 ); // 80% N2 at 130m |
1506 assert( 0.00 <= ppHe && ppHe < 12.6 ); // 90% He at 130m | |
236 | 1507 |
126 | 1508 for (ci=0;ci<16;ci++) |
1509 { | |
258 | 1510 read_buhlmann_times(period); // 2 sec or 1 min period. |
116 | 1511 |
126 | 1512 // N2 |
236 | 1513 temp_tissue = (ppN2 - pres_tissue[ci]) * var_N2_e; |
126 | 1514 temp_tissue_safety(); |
167 | 1515 pres_tissue[ci] += temp_tissue; |
165 | 1516 |
126 | 1517 // He |
200 | 1518 temp_tissue = (ppHe - (pres_tissue+16)[ci]) * var_He_e; |
126 | 1519 temp_tissue_safety(); |
167 | 1520 (pres_tissue+16)[ci] += temp_tissue; |
192 | 1521 } |
167 | 1522 } |
116 | 1523 |
167 | 1524 ////////////////////////////////////////////////////////////////////////////// |
192 | 1525 // calc_limit |
167 | 1526 // |
192 | 1527 // New in v.111 : separated from calc_tissue(), and depends on GF value. |
167 | 1528 // |
258 | 1529 static void calc_limit(void) |
167 | 1530 { |
192 | 1531 char_O_gtissue_no = 255; |
1532 calc_lead_tissue_limit = 0.0; | |
1533 | |
1534 for (ci=0;ci<16;ci++) | |
1535 { | |
1536 overlay float p = pres_tissue[ci] + (pres_tissue+16)[ci]; | |
1537 | |
258 | 1538 read_buhlmann_coefficients(); |
192 | 1539 var_N2_a = (var_N2_a * pres_tissue[ci] + var_He_a * (pres_tissue+16)[ci]) / p; |
1540 var_N2_b = (var_N2_b * pres_tissue[ci] + var_He_b * (pres_tissue+16)[ci]) / p; | |
116 | 1541 |
192 | 1542 // Apply the Eric Baker's varying gradient factor correction. |
1543 // Note: the correction factor depends both on GF and b, | |
1544 // Actual values are in the 1.5 .. 1.0 range (for a GF=30%), | |
1545 // so that can change who is the leading gas... | |
1546 // Note: Also depends of the GF. So the calcul is different for | |
1547 // GF_low, current GF, or GF_high... | |
1548 // *BUT* calc_tissue() is used to compute bottom time, | |
1549 // hence what would happend at surface, | |
1550 // hence at GF_high. | |
1551 if( char_I_deco_model == 1 ) | |
258 | 1552 p = ( p - var_N2_a * GF_high) * var_N2_b |
1553 / (GF_high + var_N2_b * (1.0 - GF_high)); | |
192 | 1554 else |
1555 p = (p - var_N2_a) * var_N2_b; | |
258 | 1556 if( p < 0.0 ) p = 0.0; |
192 | 1557 |
1558 if( p > calc_lead_tissue_limit ) | |
1559 { | |
1560 char_O_gtissue_no = ci; | |
1561 calc_lead_tissue_limit = p; | |
1562 } | |
1563 } | |
197 | 1564 |
1565 assert( char_O_gtissue_no < 16 ); | |
1566 assert( 0.0 <= calc_lead_tissue_limit && calc_lead_tissue_limit <= 14.0); | |
167 | 1567 } |
1568 | |
1569 ////////////////////////////////////////////////////////////////////////////// | |
1570 // calc_nullzeit | |
1571 // | |
1572 // calculates the remaining bottom time | |
1573 // | |
1574 // unchanged in v.101 | |
1575 // | |
1576 static void calc_nullzeit(void) | |
1577 { | |
203 | 1578 overlay unsigned char loop; |
200 | 1579 update_startvalues(); |
167 | 1580 |
116 | 1581 char_O_nullzeit = 0; |
167 | 1582 for(loop = 1; loop <= 17; loop++) |
116 | 1583 { |
1584 backup_sim_pres_tissue(); | |
197 | 1585 sim_tissue(2); // 10 min. |
192 | 1586 sim_limit(GF_high); |
167 | 1587 |
192 | 1588 if( sim_lead_tissue_limit > pres_surface ) // changed in v.102 , if guiding tissue can not be exposed to surface pressure immediately |
185 | 1589 { |
1590 restore_sim_pres_tissue(); | |
1591 break; | |
1592 } | |
1593 // Validate once we know its good. | |
1594 char_O_nullzeit += 10; | |
167 | 1595 } |
1596 | |
116 | 1597 if (char_O_nullzeit < 60) |
1598 { | |
167 | 1599 for(loop=1; loop <= 10; loop++) |
116 | 1600 { |
197 | 1601 sim_tissue(1); // 1 min |
192 | 1602 sim_limit(GF_high); |
1603 | |
1604 if( sim_lead_tissue_limit > pres_surface) // changed in v.102 , if guiding tissue can not be exposed to surface pressure immediately | |
185 | 1605 break; |
1606 char_O_nullzeit++; | |
167 | 1607 } |
185 | 1608 } |
1609 } | |
116 | 1610 |
167 | 1611 ////////////////////////////////////////////////////////////////////////////// |
1612 // backup_sim_pres_tissue | |
1613 // | |
116 | 1614 void backup_sim_pres_tissue(void) |
1615 { | |
167 | 1616 overlay unsigned char x; |
1617 | |
1618 for(x = 0; x<32; x++) | |
126 | 1619 sim_pres_tissue_backup[x] = sim_pres_tissue[x]; |
167 | 1620 } |
116 | 1621 |
167 | 1622 ////////////////////////////////////////////////////////////////////////////// |
1623 // restore_sim_pres_tissue | |
1624 // | |
116 | 1625 void restore_sim_pres_tissue(void) |
1626 { | |
167 | 1627 overlay unsigned char x; |
1628 | |
1629 for(x = 0; x<32; x++) | |
126 | 1630 sim_pres_tissue[x] = sim_pres_tissue_backup[x]; |
167 | 1631 } |
116 | 1632 |
167 | 1633 ////////////////////////////////////////////////////////////////////////////// |
1634 // calc_ascenttime | |
1635 // | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1636 static void calc_ascenttime(void) |
116 | 1637 { |
126 | 1638 if (pres_respiration > pres_surface) |
1639 { | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1640 overlay unsigned char x; |
168 | 1641 |
192 | 1642 // + 0.7 to count 1 minute ascent time from 3 meter to surface |
1643 overlay float ascent = pres_respiration - pres_surface + 0.7; | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1644 if (ascent < 0.0) |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1645 ascent = 0.0; |
203 | 1646 int_O_ascenttime = (unsigned short)(ascent + 0.99); |
168 | 1647 |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1648 for(x=0; x<32 && internal_deco_depth[x]; x++) |
203 | 1649 int_O_ascenttime += (unsigned short)internal_deco_time[x]; |
126 | 1650 } |
1651 else | |
168 | 1652 int_O_ascenttime = 0; |
167 | 1653 } |
116 | 1654 |
167 | 1655 ////////////////////////////////////////////////////////////////////////////// |
1656 // update_startvalues | |
1657 // | |
116 | 1658 // updated in v.102 |
167 | 1659 // |
116 | 1660 void update_startvalues(void) |
1661 { | |
167 | 1662 overlay unsigned char x; |
116 | 1663 |
201 | 1664 // Start ascent simulation with current tissue partial pressures. |
116 | 1665 for (x = 0;x<16;x++) |
1666 { | |
1667 sim_pres_tissue[x] = pres_tissue[x]; | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1668 (sim_pres_tissue+16)[x] = (pres_tissue+16)[x]; |
116 | 1669 } |
197 | 1670 |
201 | 1671 // No leading tissue (yet) for this ascent simulation. |
197 | 1672 sim_lead_tissue_limit = 0.0; |
1673 sim_lead_tissue_no = 255; | |
167 | 1674 } |
116 | 1675 |
167 | 1676 ////////////////////////////////////////////////////////////////////////////// |
192 | 1677 // sim_tissue |
167 | 1678 // |
116 | 1679 // optimized in v.101 |
167 | 1680 // |
1681 // Function very simular to calc_tissue, but: | |
1682 // + Use a 1min or 10min period. | |
1683 // + Do it on sim_pres_tissue, instead of pres_tissue. | |
184 | 1684 static void sim_tissue(PARAMETER unsigned char period) |
116 | 1685 { |
251 | 1686 assert( 0.00 <= ppN2 && ppN2 < 11.2 ); // 80% N2 at 130m |
1687 assert( 0.00 <= ppHe && ppHe < 12.6 ); // 90% He at 130m | |
236 | 1688 |
192 | 1689 for(ci=0; ci<16; ci++) |
126 | 1690 { |
258 | 1691 read_buhlmann_times(period); // 1 or 10 minute(s) interval |
165 | 1692 |
126 | 1693 // N2 |
236 | 1694 temp_tissue = (ppN2 - sim_pres_tissue[ci]) * var_N2_e; |
126 | 1695 temp_tissue_safety(); |
167 | 1696 sim_pres_tissue[ci] += temp_tissue; |
126 | 1697 |
1698 // He | |
200 | 1699 temp_tissue = (ppHe - (sim_pres_tissue+16)[ci]) * var_He_e; |
126 | 1700 temp_tissue_safety(); |
167 | 1701 (sim_pres_tissue+16)[ci] += temp_tissue; |
192 | 1702 } |
167 | 1703 } |
116 | 1704 |
167 | 1705 ////////////////////////////////////////////////////////////////////////////// |
192 | 1706 // sim_limit() |
1707 // | |
1708 // New in v.111 | |
1709 // | |
1710 // Function separated from sim_tissue() to allow recomputing limit on | |
1711 // different depth, because it depends on current gradient factor. | |
167 | 1712 // |
192 | 1713 static void sim_limit(PARAMETER float GF_current) |
116 | 1714 { |
212 | 1715 assert( 0.0 < GF_current && GF_current <= 1.0f); |
1716 | |
192 | 1717 sim_lead_tissue_limit = 0.0; |
212 | 1718 sim_lead_tissue_no = 0; // If no one is critic, keep first tissue. |
192 | 1719 |
1720 for(ci=0; ci<16; ci++) | |
1721 { | |
241 | 1722 overlay float N2 = sim_pres_tissue[ci]; |
1723 overlay float He = (sim_pres_tissue+16)[ci]; | |
1724 overlay float p = N2 + He; | |
192 | 1725 |
258 | 1726 read_buhlmann_coefficients(); |
241 | 1727 var_N2_a = (var_N2_a * N2 + var_He_a * He) / p; |
1728 var_N2_b = (var_N2_b * N2 + var_He_b * He) / p; | |
192 | 1729 |
1730 // Apply the Eric Baker's varying gradient factor correction. | |
1731 // Note: the correction factor depends both on GF and b, | |
1732 // Actual values are in the 1.5 .. 1.0 range (for a GF=30%), | |
1733 // so that can change who is the leading gas... | |
1734 // Note: Also depends of the GF_current... | |
1735 if( char_I_deco_model == 1 ) | |
1736 p = ( p - var_N2_a * GF_current) * var_N2_b | |
1737 / (GF_current + var_N2_b * (1.0 - GF_current)); | |
1738 else | |
1739 p = (p - var_N2_a) * var_N2_b; | |
237 | 1740 if( p < 0.0 ) p = 0.0; |
192 | 1741 |
1742 if( p > sim_lead_tissue_limit ) | |
1743 { | |
1744 sim_lead_tissue_no = ci; | |
1745 sim_lead_tissue_limit = p; | |
1746 } | |
1747 } // for ci | |
197 | 1748 |
1749 assert( sim_lead_tissue_no < 16 ); | |
237 | 1750 assert( 0.0 <= sim_lead_tissue_limit && sim_lead_tissue_limit <= 14.0 ); |
167 | 1751 } |
116 | 1752 |
167 | 1753 ////////////////////////////////////////////////////////////////////////////// |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1754 // clear_deco_table |
167 | 1755 // |
1756 // unchanged in v.101 | |
1757 // | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1758 static void clear_deco_table(void) |
116 | 1759 { |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1760 overlay unsigned char x; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1761 |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1762 for(x=0; x<32; ++x) |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1763 { |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1764 internal_deco_time [x] = 0; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1765 internal_deco_depth[x] = 0; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1766 } |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1767 } |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1768 |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1769 ////////////////////////////////////////////////////////////////////////////// |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1770 // update_deco_table |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1771 // |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1772 // Add 1 min to current stop. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1773 // |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1774 // Inputs: |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1775 // temp_depth_limit = stop's depth, in meters. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1776 // In/Out: |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1777 // internal_deco_depth[] : depth (in meters) of each stops. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1778 // internal_deco_time [] : time (in minutes) of each stops. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1779 // |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1780 static void update_deco_table() |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1781 { |
192 | 1782 overlay unsigned char x; |
247
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
1783 assert( temp_depth_limit < 128 ); // Can't be negativ (overflown). |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
1784 assert( temp_depth_limit > 0 ); // No stop at surface... |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1785 |
192 | 1786 for(x=0; x<32; ++x) |
1787 { | |
212 | 1788 // Make sure deco-stops are recorded in order: |
1789 assert( !internal_deco_depth[x] || temp_depth_limit <= internal_deco_depth[x] ); | |
1790 | |
200 | 1791 if( internal_deco_depth[x] == temp_depth_limit ) |
192 | 1792 { |
1793 // Do not overflow (max 255') | |
1794 if( internal_deco_time[x] < 255 ) | |
1795 { | |
1796 internal_deco_time[x]++; | |
1797 return; | |
1798 } | |
1799 // But store extra in the next stop... | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1800 } |
192 | 1801 |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1802 if( internal_deco_depth[x] == 0 ) |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1803 { |
192 | 1804 internal_deco_depth[x] = temp_depth_limit; |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1805 internal_deco_time[x] = 1; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1806 return; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1807 } |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1808 } |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1809 |
192 | 1810 // Can't store stops at more than 96m. |
1811 // Or stops at less that 3m too. | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1812 // Just do nothing with that... |
167 | 1813 } |
116 | 1814 |
167 | 1815 ////////////////////////////////////////////////////////////////////////////// |
1816 // calc_gradient_factor | |
1817 // | |
165 | 1818 // optimized in v.101 (var_N2_a) |
116 | 1819 // new code in v.102 |
167 | 1820 // |
1821 static void calc_gradient_factor(void) | |
116 | 1822 { |
197 | 1823 overlay float gf; |
237 | 1824 |
197 | 1825 assert( char_O_gtissue_no < 16 ); |
237 | 1826 assert( 0.800 <= pres_respiration && pres_respiration < 14.0 ); |
197 | 1827 |
116 | 1828 // tissue > respiration (entsaettigungsvorgang) |
1829 // gradient ist wieviel prozent an limit mit basis tissue | |
1830 // dh. 0% = respiration == tissue | |
1831 // dh. 100% = respiration == limit | |
197 | 1832 temp_tissue = pres_tissue[char_O_gtissue_no] + (pres_tissue+16)[char_O_gtissue_no]; |
1833 if( temp_tissue < pres_respiration ) | |
1834 gf = 0.0; | |
1835 else | |
1836 { | |
1837 gf = (temp_tissue - pres_respiration) | |
258 | 1838 / (temp_tissue - calc_lead_tissue_limit) |
197 | 1839 * 100.0; |
1840 if( gf > 255.0 ) gf = 255.0; | |
1841 if( gf < 0.0 ) gf = 0.0; | |
1842 } | |
1843 char_O_gradient_factor = (unsigned char)gf; | |
116 | 1844 |
1845 if (char_I_deco_model == 1) // calculate relative gradient factor | |
1846 { | |
197 | 1847 overlay float rgf; |
1848 | |
1849 if( low_depth == 0 ) | |
1850 rgf = GF_high; | |
1851 else | |
1852 { | |
241 | 1853 overlay float temp1 = low_depth * 0.09985; |
197 | 1854 overlay float temp2 = pres_respiration - pres_surface; |
186 | 1855 |
197 | 1856 if (temp2 <= 0) |
1857 rgf = GF_high; | |
1858 else if (temp2 >= temp1) | |
1859 rgf = GF_low; | |
1860 else | |
1861 rgf = GF_low + (temp1 - temp2)/temp1*GF_delta; | |
1862 } | |
186 | 1863 |
197 | 1864 rgf = gf / rgf; // gf is already in percent |
1865 if( rgf < 0.0 ) rgf = 0.0; | |
1866 if( rgf > 255.0 ) rgf = 255.0; | |
1867 char_O_relative_gradient_GF = (unsigned char)rgf; | |
116 | 1868 } // calc relative gradient factor |
1869 else | |
1870 { | |
186 | 1871 char_O_relative_gradient_GF = char_O_gradient_factor; |
116 | 1872 } |
167 | 1873 } |
116 | 1874 |
167 | 1875 ////////////////////////////////////////////////////////////////////////////// |
1876 // deco_calc_desaturation_time | |
1877 // | |
116 | 1878 // FIXED N2_ratio |
1879 // unchanged in v.101 | |
233 | 1880 // Inputs: int_I_pres_surface, ppWVapour, char_I_desaturation_multiplier |
1881 // Outputs: int_O_desaturation_time, char_O_tissue_saturation[0..31] | |
167 | 1882 // |
116 | 1883 void deco_calc_desaturation_time(void) |
1884 { | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
1885 RESET_C_STACK |
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
1886 |
233 | 1887 assert( 800 < int_I_pres_surface && int_I_pres_surface < 1100 ); |
1888 assert( 0 < char_I_desaturation_multiplier && char_I_desaturation_multiplier <= 100 ); | |
1889 | |
237 | 1890 N2_ratio = 0.7902; // FIXED sum as stated in bühlmann |
233 | 1891 pres_surface = int_I_pres_surface * 0.001; |
236 | 1892 ppN2 = N2_ratio * (pres_surface - ppWVapour); |
126 | 1893 int_O_desaturation_time = 0; |
1894 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142) | |
233 | 1895 |
126 | 1896 for (ci=0;ci<16;ci++) |
1897 { | |
251 | 1898 overlay unsigned short desat_time; // For a particular compartiment, in min. |
1899 overlay float temp1; | |
1900 overlay float temp2; | |
1901 overlay float temp3; | |
1902 overlay float temp4; | |
1903 | |
200 | 1904 overlay float var_N2_halftime = buhlmann_ht[ci]; |
1905 overlay float var_He_halftime = (buhlmann_ht+16)[ci]; | |
116 | 1906 |
126 | 1907 // saturation_time (for flight) and N2_saturation in multiples of halftime |
1908 // version v.100: 1.1 = 10 percent distance to totally clean (totally clean is not possible, would take infinite time ) | |
1909 // new in version v.101: 1.07 = 7 percent distance to totally clean (totally clean is not possible, would take infinite time ) | |
1910 // changes in v.101: 1.05 = 5 percent dist to totally clean is new desaturation point for display and noFly calculations | |
1911 // N2 | |
236 | 1912 temp1 = 1.05 * ppN2; |
126 | 1913 temp1 = temp1 - pres_tissue[ci]; |
236 | 1914 temp2 = ppN2 - pres_tissue[ci]; |
126 | 1915 if (temp2 >= 0.0) |
1916 { | |
233 | 1917 temp1 = 0.0; |
1918 temp2 = 0.0; | |
126 | 1919 } |
1920 else | |
1921 temp1 = temp1 / temp2; | |
251 | 1922 if( 0.0 < temp1 && temp1 < 1.0 ) |
126 | 1923 { |
1924 temp1 = log(1.0 - temp1); | |
1925 temp1 = temp1 / -0.6931; // temp1 is the multiples of half times necessary. | |
1926 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested. | |
1927 // minus because log is negative | |
165 | 1928 temp2 = var_N2_halftime * temp1 / float_desaturation_multiplier; // time necessary (in minutes ) for complete desaturation (see comment about 10 percent) , new in v.101: float_desaturation_multiplier |
252 | 1929 |
1930 // HERE ==> This assert fails during simulated dives, and should not.... | |
1931 assert( temp2 < 28800.0 ); // 480h !! | |
126 | 1932 } |
1933 else | |
1934 { | |
233 | 1935 temp1 = 0.0; |
1936 temp2 = 0.0; | |
126 | 1937 } |
116 | 1938 |
126 | 1939 // He |
167 | 1940 temp3 = 0.1 - (pres_tissue+16)[ci]; |
126 | 1941 if (temp3 >= 0.0) |
1942 { | |
233 | 1943 temp3 = 0.0; |
1944 temp4 = 0.0; | |
126 | 1945 } |
1946 else | |
167 | 1947 temp3 = -1.0 * temp3 / (pres_tissue+16)[ci]; |
251 | 1948 if( 0.0 < temp3 && temp3 < 1.0 ) |
126 | 1949 { |
1950 temp3 = log(1.0 - temp3); | |
1951 temp3 = temp3 / -0.6931; // temp1 is the multiples of half times necessary. | |
1952 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested. | |
1953 // minus because log is negative | |
165 | 1954 temp4 = var_He_halftime * temp3 / float_desaturation_multiplier; // time necessary (in minutes ) for "complete" desaturation, new in v.101 float_desaturation_multiplier |
126 | 1955 } |
1956 else | |
1957 { | |
233 | 1958 temp3 = 0.0; |
1959 temp4 = 0.0; | |
126 | 1960 } |
116 | 1961 |
126 | 1962 // saturation_time (for flight) |
1963 if (temp4 > temp2) | |
203 | 1964 desat_time = (unsigned short)temp4; |
126 | 1965 else |
203 | 1966 desat_time = (unsigned short)temp2; |
252 | 1967 |
251 | 1968 if(desat_time > int_O_desaturation_time) |
1969 int_O_desaturation_time = desat_time; | |
116 | 1970 |
126 | 1971 // N2 saturation in multiples of halftime for display purposes |
1972 temp2 = temp1 * 20.0; // 0 = 1/8, 120 = 0, 249 = 8 | |
1973 temp2 = temp2 + 80.0; // set center | |
1974 if (temp2 < 0.0) | |
1975 temp2 = 0.0; | |
1976 if (temp2 > 255.0) | |
1977 temp2 = 255.0; | |
1978 char_O_tissue_saturation[ci] = (char)temp2; | |
233 | 1979 |
126 | 1980 // He saturation in multiples of halftime for display purposes |
1981 temp4 = temp3 * 20.0; // 0 = 1/8, 120 = 0, 249 = 8 | |
1982 temp4 = temp4 + 80.0; // set center | |
1983 if (temp4 < 0.0) | |
1984 temp4 = 0.0; | |
1985 if (temp4 > 255.0) | |
1986 temp4 = 255.0; | |
167 | 1987 (char_O_tissue_saturation+16)[ci] = (char)temp4; |
126 | 1988 } // for |
167 | 1989 } |
116 | 1990 |
167 | 1991 ////////////////////////////////////////////////////////////////////////////// |
1992 // calc_wo_deco_step_1_min | |
1993 // | |
116 | 1994 // FIXED N2 Ratio |
1995 // optimized in v.101 (...saturation_multiplier) | |
1996 // desaturation slowed down to 70,42% | |
167 | 1997 // |
1998 static void calc_wo_deco_step_1_min(void) | |
116 | 1999 { |
251 | 2000 assert( 800 < int_I_pres_surface && int_I_pres_surface < 1100 ); |
2001 assert( 800 < int_I_pres_respiration && int_I_pres_respiration < 1100 ); | |
2002 assert( 100 <= char_I_saturation_multiplier && char_I_saturation_multiplier < 200 ); | |
2003 assert( 0 < char_I_desaturation_multiplier && char_I_desaturation_multiplier <= 100 ); | |
2004 | |
116 | 2005 if(flag_in_divemode) |
2006 { | |
2007 flag_in_divemode = 0; | |
2008 set_dbg_end_of_dive(); | |
2009 } | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
2010 |
126 | 2011 N2_ratio = 0.7902; // FIXED, sum lt. buehlmann |
233 | 2012 pres_respiration = int_I_pres_respiration * 0.001; // assembler code uses different digit system |
2013 pres_surface = int_I_pres_surface * 0.001; // the b"uhlmann formula using pres_surface does not use the N2_ratio | |
236 | 2014 ppN2 = N2_ratio * (pres_respiration - ppWVapour); // ppWVapour is the extra pressure in the body |
200 | 2015 ppHe = 0.0; |
126 | 2016 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142) |
197 | 2017 float_saturation_multiplier = char_I_saturation_multiplier * 0.01; |
126 | 2018 |
192 | 2019 calc_tissue(1); // update the pressure in the 32 tissues in accordance with the new ambient pressure |
167 | 2020 |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
2021 clear_deco_table(); |
200 | 2022 char_O_deco_status = 3; // surface new in v.102 : stays in surface state. |
126 | 2023 char_O_nullzeit = 0; |
168 | 2024 int_O_ascenttime = 0; |
126 | 2025 calc_gradient_factor(); |
167 | 2026 } |
126 | 2027 |
167 | 2028 ////////////////////////////////////////////////////////////////////////////// |
2029 ////////////////////////////////////////////////////////////////////////////// | |
2030 ////////////////////////////////// deco_hash ///////////////////////////////// | |
2031 ////////////////////////////////////////////////////////////////////////////// | |
2032 ////////////////////////////////////////////////////////////////////////////// | |
126 | 2033 |
184 | 2034 #ifndef CROSS_COMPILE |
116 | 2035 void deco_hash(void) |
2036 { | |
167 | 2037 overlay unsigned char md_i, md_j; // Loop index. |
2038 overlay unsigned char md_t; | |
2039 overlay unsigned char md_buffer[16]; | |
2040 overlay unsigned char md_temp; | |
203 | 2041 overlay unsigned short md_pointer; |
167 | 2042 |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
2043 RESET_C_STACK |
126 | 2044 |
2045 // init | |
164 | 2046 for(md_i=0;md_i<16;md_i++) |
126 | 2047 { |
2048 md_state[md_i] = 0; | |
164 | 2049 char_O_hash[md_i] = 0; |
126 | 2050 } // for md_i 16 |
116 | 2051 |
126 | 2052 _asm |
167 | 2053 movlw 0x01 // md_pi address. |
2054 movwf TBLPTRU,0 | |
2055 movlw 0x7E | |
2056 movwf TBLPTRH,0 | |
2057 movlw 0x00 | |
2058 movwf TBLPTRL,0 | |
126 | 2059 _endasm; |
165 | 2060 md_i = 0; |
2061 do { | |
126 | 2062 _asm |
2063 TBLRDPOSTINC | |
2064 movff TABLAT,md_temp | |
2065 _endasm | |
165 | 2066 md_pi_subst[md_i++] = md_temp; |
2067 } while( md_i != 0 ); | |
2068 | |
126 | 2069 _asm |
167 | 2070 movlw 0x00 |
2071 movwf TBLPTRU,0 | |
2072 movlw 0x00 | |
2073 movwf TBLPTRH,0 | |
2074 movlw 0x00 | |
2075 movwf TBLPTRL,0 | |
126 | 2076 _endasm |
167 | 2077 |
126 | 2078 // cycle buffers |
2079 for (md_pointer=0x0000;md_pointer<0x17f3;md_pointer++) | |
2080 { | |
2081 md_t = 0; | |
2082 for (md_i=0;md_i<16;md_i++) | |
2083 { | |
2084 if(md_pointer == 9) | |
164 | 2085 md_temp = char_O_hash[md_i]; |
126 | 2086 else |
2087 { | |
2088 _asm | |
167 | 2089 TBLRDPOSTINC |
2090 movff TABLAT,md_temp | |
126 | 2091 _endasm |
2092 } // else | |
167 | 2093 |
2094 md_buffer[md_i] = md_temp; | |
186 | 2095 md_state[md_i+16] = md_temp; |
2096 md_state[md_i+32] = (unsigned char)(md_temp ^ md_state[md_i]); | |
126 | 2097 } // for md_i 16 |
2098 | |
2099 for (md_i=0;md_i<18;md_i++) | |
2100 { | |
2101 for (md_j=0;md_j<48;md_j++) | |
2102 { | |
167 | 2103 md_state[md_j] ^= md_pi_subst[md_t]; |
126 | 2104 md_t = md_state[md_j]; |
2105 } // for md_j 48 | |
2106 md_t = (unsigned char)(md_t+1); | |
2107 } // for md_i 18 | |
164 | 2108 md_t = char_O_hash[15]; |
126 | 2109 |
2110 for (md_i=0;md_i<16;md_i++) | |
2111 { | |
167 | 2112 char_O_hash[md_i] ^= md_pi_subst[(md_buffer[md_i] ^ md_t)]; |
164 | 2113 md_t = char_O_hash[md_i]; |
126 | 2114 } // for md_i 16 |
2115 } // for md_pointer | |
116 | 2116 } // void deco_hash(void) |
184 | 2117 #endif |
116 | 2118 |
167 | 2119 ////////////////////////////////////////////////////////////////////////////// |
2120 // deco_clear_CNS_fraction | |
2121 // | |
116 | 2122 // new in v.101 |
167 | 2123 // |
116 | 2124 void deco_clear_CNS_fraction(void) |
2125 { | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
2126 RESET_C_STACK |
237 | 2127 |
126 | 2128 CNS_fraction = 0.0; |
2129 char_O_CNS_fraction = 0; | |
167 | 2130 } |
116 | 2131 |
167 | 2132 ////////////////////////////////////////////////////////////////////////////// |
2133 // deco_calc_CNS_fraction | |
2134 // | |
116 | 2135 // new in v.101 |
2136 // optimized in v.102 : with new variables char_I_actual_ppO2 and actual_ppO2 | |
167 | 2137 // |
116 | 2138 // Input: char_I_actual_ppO2 |
2139 // Output: char_O_CNS_fraction | |
2140 // Uses and Updates: CNS_fraction | |
2141 // Uses: acutal_ppO2 | |
167 | 2142 // |
116 | 2143 void deco_calc_CNS_fraction(void) |
2144 { | |
167 | 2145 overlay float actual_ppO2; |
126 | 2146 RESET_C_STACK |
167 | 2147 |
237 | 2148 assert( 0.0 <= CNS_fraction && CNS_fraction <= 2.5 ); |
2149 assert( char_I_actual_ppO2 > 15 ); | |
2150 | |
126 | 2151 actual_ppO2 = (float)char_I_actual_ppO2 / 100.0; |
116 | 2152 |
126 | 2153 if (char_I_actual_ppO2 < 50) |
2154 CNS_fraction = CNS_fraction;// no changes | |
2155 else if (char_I_actual_ppO2 < 60) | |
2156 CNS_fraction = 1/(-54000.0 * actual_ppO2 + 54000.0) + CNS_fraction; | |
2157 else if (char_I_actual_ppO2 < 70) | |
2158 CNS_fraction = 1/(-45000.0 * actual_ppO2 + 48600.0) + CNS_fraction; | |
2159 else if (char_I_actual_ppO2 < 80) | |
2160 CNS_fraction = 1/(-36000.0 * actual_ppO2 + 42300.0) + CNS_fraction; | |
2161 else if (char_I_actual_ppO2 < 90) | |
2162 CNS_fraction = 1/(-27000.0 * actual_ppO2 + 35100.0) + CNS_fraction; | |
2163 else if (char_I_actual_ppO2 < 110) | |
2164 CNS_fraction = 1/(-18000.0 * actual_ppO2 + 27000.0) + CNS_fraction; | |
2165 else if (char_I_actual_ppO2 < 150) | |
2166 CNS_fraction = 1/(-9000.0 * actual_ppO2 + 17100.0) + CNS_fraction; | |
2167 else if (char_I_actual_ppO2 < 160) | |
2168 CNS_fraction = 1/(-22500.0 * actual_ppO2 + 37350.0) + CNS_fraction; | |
2169 else if (char_I_actual_ppO2 < 165) | |
2170 CNS_fraction = 0.000755 + CNS_fraction; // Arieli et all.(2002): Modeling pulmonary and CNS O2 toxicity... Formula (A1) based on value for 1.55 and c=20 | |
2171 else if (char_I_actual_ppO2 < 170) | |
2172 CNS_fraction = 0.00102 + CNS_fraction; // example calculation: Sqrt((1.7/1.55)^20)*0.000404 | |
2173 else if (char_I_actual_ppO2 < 175) | |
2174 CNS_fraction = 0.00136 + CNS_fraction; | |
2175 else if (char_I_actual_ppO2 < 180) | |
2176 CNS_fraction = 0.00180 + CNS_fraction; | |
2177 else if (char_I_actual_ppO2 < 185) | |
2178 CNS_fraction = 0.00237 + CNS_fraction; | |
2179 else if (char_I_actual_ppO2 < 190) | |
2180 CNS_fraction = 0.00310 + CNS_fraction; | |
2181 else if (char_I_actual_ppO2 < 195) | |
2182 CNS_fraction = 0.00401 + CNS_fraction; | |
2183 else if (char_I_actual_ppO2 < 200) | |
2184 CNS_fraction = 0.00517 + CNS_fraction; | |
2185 else if (char_I_actual_ppO2 < 230) | |
2186 CNS_fraction = 0.0209 + CNS_fraction; | |
2187 else | |
2188 CNS_fraction = 0.0482 + CNS_fraction; // value for 2.5 | |
116 | 2189 |
126 | 2190 if (CNS_fraction > 2.5) |
2191 CNS_fraction = 2.5; | |
2192 if (CNS_fraction < 0.0) | |
2193 CNS_fraction = 0.0; | |
2194 | |
2195 char_O_CNS_fraction = (char)((CNS_fraction + 0.005)* 100.0); | |
167 | 2196 } |
116 | 2197 |
167 | 2198 ////////////////////////////////////////////////////////////////////////////// |
2199 // deco_calc_CNS_decrease_15min | |
2200 // | |
116 | 2201 // new in v.101 |
167 | 2202 // |
116 | 2203 // calculates the half time of 90 minutes in 6 steps of 15 min |
200 | 2204 // (Used in sleepmode, for low battery mode). |
167 | 2205 // |
116 | 2206 // Output: char_O_CNS_fraction |
2207 // Uses and Updates: CNS_fraction | |
167 | 2208 // |
116 | 2209 void deco_calc_CNS_decrease_15min(void) |
2210 { | |
237 | 2211 RESET_C_STACK |
2212 assert( 0.0 <= CNS_fraction && CNS_fraction <= 2.5 ); | |
2213 | |
126 | 2214 CNS_fraction = 0.890899 * CNS_fraction; |
167 | 2215 char_O_CNS_fraction = (char)(CNS_fraction * 100.0 + 0.5); |
2216 } | |
116 | 2217 |
167 | 2218 ////////////////////////////////////////////////////////////////////////////// |
2219 // deco_calc_percentage | |
2220 // | |
116 | 2221 // new in v.101 |
167 | 2222 // |
116 | 2223 // calculates int_I_temp * char_I_temp / 100 |
2224 // output is int_I_temp | |
200 | 2225 // |
2226 // Used to compute NoFly remaining time. | |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2227 // |
116 | 2228 void deco_calc_percentage(void) |
2229 { | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
2230 RESET_C_STACK |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2231 |
237 | 2232 assert( 60 <= char_I_temp && char_I_temp <= 100 ); |
2233 assert( 0 <= int_I_temp && int_I_temp < 2880 ); // Less than 48h... | |
2234 | |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2235 int_I_temp = (unsigned short)(((float)int_I_temp * (float)char_I_temp) * 0.01 ); |
237 | 2236 |
2237 assert( int_I_temp < 1440 ); // Less than 24h... | |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2238 } |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2239 |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2240 |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2241 ////////////////////////////////////////////////////////////////////////////// |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2242 // deco_gas_volumes |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2243 // |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2244 // new in v.111 |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2245 // |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2246 // calculates volumes for each gas. |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2247 // |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2248 // Input: char_I_bottom_depth, char_I_bottom_time for planned dive. |
240
d995e220ddac
BUGFIX Gas Usage when first gas is not #1 (bug BB22).
JeanDo
parents:
237
diff
changeset
|
2249 // Gas list. |
d995e220ddac
BUGFIX Gas Usage when first gas is not #1 (bug BB22).
JeanDo
parents:
237
diff
changeset
|
2250 // char_I_first_gas is the bottom gas. |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2251 // decoplan (char_O_deco_depth, char_O_deco_time). |
234
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2252 // CF#54 == TRUE if shallowest stop first. |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2253 // CF#56 == bottom deci-liters/minutes (0.5 .. 50.0) |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2254 // CF#57 == deco deci-liters/minutes (0.5 .. 50.0). |
224 | 2255 // Output: int_O_gas_volumes[0..4] in litters * 0.1 |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2256 // |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2257 void deco_gas_volumes(void) |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2258 { |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2259 overlay float volumes[5]; |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2260 overlay float ascent_usage; |
234
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2261 overlay unsigned char i, deepest_first; |
241 | 2262 overlay unsigned char gas; |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2263 RESET_C_STACK |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2264 |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2265 //---- initialize with bottom consumption -------------------------------- |
240
d995e220ddac
BUGFIX Gas Usage when first gas is not #1 (bug BB22).
JeanDo
parents:
237
diff
changeset
|
2266 for(i=0; i<5; ++i) // Nothing yet... |
d995e220ddac
BUGFIX Gas Usage when first gas is not #1 (bug BB22).
JeanDo
parents:
237
diff
changeset
|
2267 volumes[i] = 0.0; |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2268 |
241 | 2269 assert(1 <= char_I_first_gas && char_I_first_gas <= 5); |
2270 gas = char_I_first_gas - 1; | |
2271 | |
2272 volumes[gas] | |
240
d995e220ddac
BUGFIX Gas Usage when first gas is not #1 (bug BB22).
JeanDo
parents:
237
diff
changeset
|
2273 = (char_I_bottom_depth*0.1 + 1.0) // Use Psurface = 1.0 bar. |
d995e220ddac
BUGFIX Gas Usage when first gas is not #1 (bug BB22).
JeanDo
parents:
237
diff
changeset
|
2274 * char_I_bottom_time // in minutes. |
d995e220ddac
BUGFIX Gas Usage when first gas is not #1 (bug BB22).
JeanDo
parents:
237
diff
changeset
|
2275 * read_custom_function(56) // In deci-liter/minutes. |
d995e220ddac
BUGFIX Gas Usage when first gas is not #1 (bug BB22).
JeanDo
parents:
237
diff
changeset
|
2276 * 0.1; // deci-liters --> liters. |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2277 |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2278 //---- Ascent usage ------------------------------------------------------ |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2279 |
234
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2280 deepest_first = read_custom_function(54) == 0; |
240
d995e220ddac
BUGFIX Gas Usage when first gas is not #1 (bug BB22).
JeanDo
parents:
237
diff
changeset
|
2281 ascent_usage = read_custom_function(57) * 0.1; // In liter/minutes. |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2282 |
224 | 2283 // Usage up to the first stop: |
2284 // - computed at MAX depth (easier, safer), | |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2285 // - with an ascent speed of 10m/min. |
224 | 2286 // - with ascent litter / minutes. |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2287 // - still using bottom gas: |
241 | 2288 volumes[gas] |
240
d995e220ddac
BUGFIX Gas Usage when first gas is not #1 (bug BB22).
JeanDo
parents:
237
diff
changeset
|
2289 += (char_I_bottom_depth*0.1 + 1.0) // Depth -> bar |
d995e220ddac
BUGFIX Gas Usage when first gas is not #1 (bug BB22).
JeanDo
parents:
237
diff
changeset
|
2290 * (char_I_bottom_depth - char_O_first_deco_depth) * 0.1 // ascent time (min) |
d995e220ddac
BUGFIX Gas Usage when first gas is not #1 (bug BB22).
JeanDo
parents:
237
diff
changeset
|
2291 * ascent_usage; // Consumption ( xxx / min @ 1 bar) |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2292 |
234
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2293 for(i=0; i<32; ++i) |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2294 { |
241 | 2295 overlay unsigned char j; |
234
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2296 overlay unsigned char depth, time, ascent; |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2297 |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2298 // Manage stops in reverse order (CF#54) |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2299 if( deepest_first ) |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2300 { |
241 | 2301 time = char_O_deco_time[i]; |
234
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2302 if( time == 0 ) break; // End of table: done. |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2303 |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2304 ascent = depth = char_O_deco_depth[i]; |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2305 if( i < 31 ) |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2306 ascent -= char_O_deco_depth[i+1]; |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2307 } |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2308 else |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2309 { |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2310 time = char_O_deco_time[31-i]; |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2311 if( time == 0 ) continue; // not yet: still searh table. |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2312 |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2313 ascent = depth = char_O_deco_depth[31-i]; |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2314 if( i < 31 ) |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2315 ascent -= char_O_deco_depth[30-i]; |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2316 } |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2317 |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2318 // Gas switch depth ? |
241 | 2319 for(j=0; j<5; ++j) |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2320 { |
234
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2321 if( depth <= char_I_deco_gas_change[j] ) |
241 | 2322 if( !char_I_deco_gas_change[gas] || (char_I_deco_gas_change[gas] > char_I_deco_gas_change[j]) ) |
224 | 2323 gas = j; |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2324 } |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2325 |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2326 // usage during stop: |
224 | 2327 // Note: because first gas is not in there, increment gas+1 |
234
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2328 volumes[gas] += (depth*0.1 + 1.0) // depth --> bar. |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2329 * time // in minutes. |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2330 * ascent_usage // in xxx / min @ 1bar. |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2331 // Plus usage during ascent to the next stop, at 10m/min. |
234
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2332 + (depth*0.1 + 1.0) |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2333 * ascent*0.1 // meter --> min |
225 | 2334 * ascent_usage; |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2335 } |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2336 |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2337 //---- convert results for the ASM interface ----------------------------- |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2338 for(i=0; i<5; ++i) |
224 | 2339 if( volumes[i] > 6553.4 ) |
2340 int_O_gas_volumes[i] = 65535; | |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2341 else |
224 | 2342 int_O_gas_volumes[i] = (unsigned short)(volumes[i]*10.0 + 0.5); |
116 | 2343 } |
2344 | |
167 | 2345 ////////////////////////////////////////////////////////////////////////////// |
2346 | |
116 | 2347 void deco_push_tissues_to_vault(void) |
2348 { | |
167 | 2349 overlay unsigned char x; |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
2350 RESET_C_STACK |
167 | 2351 |
116 | 2352 cns_vault = CNS_fraction; |
167 | 2353 for (x=0;x<32;x++) |
2354 pres_tissue_vault[x] = pres_tissue[x]; | |
116 | 2355 } |
167 | 2356 |
116 | 2357 void deco_pull_tissues_from_vault(void) |
2358 { | |
167 | 2359 overlay unsigned char x; |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
2360 RESET_C_STACK |
167 | 2361 |
116 | 2362 CNS_fraction = cns_vault; |
167 | 2363 for (x=0;x<32;x++) |
2364 pres_tissue[x] = pres_tissue_vault[x]; | |
116 | 2365 } |
2366 | |
167 | 2367 ////////////////////////////////////////////////////////////////////////////// |
2368 // | |
184 | 2369 #ifndef CROSS_COMPILE |
2370 void main() {} | |
2371 #endif |