Mercurial > public > mk2
comparison code_part1/OSTC_code_c_part2/p2_main.c @ 167:cb055a7d75f3
+ Use overlay local vars.
+ Make all private functions static.
+ Merge calc_tissue 2sec and 1min
+ Merge sim_tissue 1min and 10min
+ Expose basic display utilities for c-code.
+ Prepare stand-alone utilities for p2_main.c testing platform.
+ New c utility: int read_custom_function(cf#)
author | JeanDo |
---|---|
date | Mon, 24 Jan 2011 23:31:57 +0100 |
parents | 14a074e1a375 |
children |
comparison
equal
deleted
inserted
replaced
166:80de93d72a17 | 167:cb055a7d75f3 |
---|---|
1 // ************************************************************** | 1 // ******************************************************************** |
2 // ** main code for simulation / tests without assembler code ** | 2 // ** main code for simulation / tests without full simulation code ** |
3 // ** This is NOT a part of the OSTC ** | 3 // ** This is NOT a part of the OSTC ** |
4 // ************************************************************** | 4 // ******************************************************************** |
5 | 5 |
6 ////////////////////////////////////////////////////////////////////////////// | 6 ////////////////////////////////////////////////////////////////////////////// |
7 // OSTC - diving computer code | 7 // OSTC - diving computer code |
8 // Copyright (C) 2008 HeinrichsWeikamp GbR | 8 // Copyright (C) 2008 HeinrichsWeikamp GbR |
9 // | 9 // |
19 // | 19 // |
20 // You should have received a copy of the GNU General Public License | 20 // You should have received a copy of the GNU General Public License |
21 // along with this program. If not, see <http://www.gnu.org/licenses/>. | 21 // along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 // | 22 // |
23 ////////////////////////////////////////////////////////////////////////////// | 23 ////////////////////////////////////////////////////////////////////////////// |
24 // history: | 24 // History: |
25 // 12/25/10 v110: [jDG] split in three files (deco.c, main.c, definitions.h) | 25 // 12/25/10 v110: [jDG] split in three files (deco.c, main.c, definitions.h) |
26 // 01/24/11 : [jDG] make it link with oled+wordprocessor display functions | |
26 | 27 |
27 #include <p18f4685.h> | |
28 #include <stdlib.h> | 28 #include <stdlib.h> |
29 #include <stdio.h> | |
29 | 30 |
31 ////////////////////////////////////////////////////////////////////////////// | |
32 // Compile with: | |
33 // p2_deco.c | |
34 // p2_environment.asm | |
35 // To have a linkable application, downloadable on the OSTC. | |
36 ////////////////////////////////////////////////////////////////////////////// | |
37 | |
38 #define TEST_MAIN 1 | |
30 #include "p2_definitions.h" | 39 #include "p2_definitions.h" |
40 #include "../OSTC_code_c_part2/shared_definitions.h" | |
31 | 41 |
32 // ************************************************** | 42 ////////////////////////////////////////////////////////////////////////////// |
33 // ** Make sure to freeze ram banks used elsewhere ** | 43 // |
34 // ************************************************** | |
35 | 44 |
36 #pragma udata bank0=0x060 | 45 static void print_stops(void) |
37 static const unsigned char keep_free_bank0[0xA0]; // used by the assembler code | 46 { |
47 //TODO: print decompression stops using aa_wordprocessor... | |
48 PLED_ClearScreen(); | |
49 win_top = 0; | |
50 win_leftx2 = 0; | |
51 win_font = 0; | |
52 win_invert = 0; | |
53 PLED_standard_color(); | |
38 | 54 |
39 #pragma udata bank1=0x100 | 55 sprintf(letter, "TTS: %d", char_O_ascenttime); |
40 static const unsigned char keep_free_bank1[256]; // used by the assembler code | 56 aa_wordprocessor(); |
41 | 57 |
42 #pragma udata bank7=0x700 | 58 //TODO: Wait click (to continue) |
43 const unsigned char keep_free_bank7[256]; // used by the assembler code (DD font2display) | |
44 | |
45 // ******************************** | |
46 // ** C O N F I G U R A T I O N ** | |
47 // ** for simulation without asm ** | |
48 // ******************************** | |
49 #pragma config OSC = IRCIO67 | |
50 #pragma config FCMEN = OFF | |
51 #pragma config IESO = OFF | |
52 #pragma config PWRT = ON | |
53 #pragma config BOREN = OFF | |
54 #pragma config WDT = OFF | |
55 #pragma config WDTPS = 128 | |
56 #pragma config MCLRE = ON | |
57 #pragma config LPT1OSC = OFF | |
58 #pragma config PBADEN = OFF | |
59 #pragma config DEBUG = OFF | |
60 #pragma config XINST = OFF | |
61 #pragma config LVP = OFF | |
62 #pragma config STVREN = OFF | |
63 | |
64 // ************************* | |
65 // ** P R O T O T Y P E S ** | |
66 // ************************* | |
67 | |
68 void main(void); | |
69 | |
70 // ******************************* | |
71 // ** start ** | |
72 // ** necessary for compilation ** | |
73 // ******************************* | |
74 #pragma romdata der_code = 0x0000 | |
75 #pragma code der_start = 0x0000 | |
76 void der_start(void) | |
77 { | |
78 _asm | |
79 goto main | |
80 _endasm | |
81 } | 59 } |
82 | 60 |
61 ////////////////////////////////////////////////////////////////////////////// | |
83 #pragma code main = 0x9000 | 62 #pragma code main = 0x9000 |
84 #pragma udata | |
85 void main(void) | 63 void main(void) |
86 { | 64 { |
87 static unsigned int i; | 65 static unsigned int i; |
88 static unsigned int debug_temp; | 66 static unsigned int debug_temp; |
89 | |
90 #if 1 | |
91 // new main to test DR-5 | |
92 | 67 |
93 char_I_deco_model = 0; | 68 char_I_deco_model = 0; |
69 deco_clear_CNS_fraction(); | |
94 | 70 |
95 char_I_GF_Low_percentage = 100; | 71 char_I_N2_ratio = 79; //38; |
96 char_I_GF_High_percentage = 100; | 72 char_I_He_ratio = 0; //50; |
73 char_I_deco_distance = 10; // 10 = 1 meter | |
74 char_I_depth_last_deco = 3; // values below 3 (meter) are ignored | |
75 | |
76 char_I_const_ppO2 = 0; | |
77 char_I_deco_ppO2_change = 0; // [dm] 10 = 1 meter | |
78 char_I_deco_ppO2 = 0; | |
79 | |
80 char_I_deco_gas_change1 = 20; // [m] 1 = 1 meter | |
81 char_I_deco_N2_ratio1 = 50; | |
82 char_I_deco_He_ratio1 = 0; | |
83 | |
84 char_I_deco_gas_change2 = 6; // [m] 1 = 1 meter | |
85 char_I_deco_N2_ratio2 = 0; | |
86 char_I_deco_He_ratio2 = 0; | |
87 | |
88 char_I_deco_gas_change3 = 0; // [m] 1 = 1 meter | |
89 char_I_deco_gas_change4 = 0; // [m] 1 = 1 meter | |
90 char_I_deco_gas_change5 = 0; // [m] 1 = 1 meter | |
97 | 91 |
98 deco_clear_CNS_fraction(); | 92 //char_I_actual_ppO2; // 0x507 |
99 //char_I_const_ppO2 = 100; | 93 char_I_GF_High_percentage = 100; // 0x514 new in v.102 |
100 //for (i=0;i<255;i++) | 94 char_I_GF_Low_percentage = 100; // 0x515 new in v.102 |
101 //{ | 95 |
102 //calc_CNS_fraction(); | 96 char_I_saturation_multiplier = 110; |
103 //} //for | 97 char_I_desaturation_multiplier = 90; |
98 | |
99 //---- Starts at zero meter ---------------------------------------------- | |
100 int_I_pres_respiration = 1000;//980; | |
101 int_I_pres_surface = 1000;//980; | |
102 deco_clear_tissue(); | |
104 | 103 |
105 int_I_pres_respiration = 1000;//980; | 104 //---- Calculate 29min at 45m -------------------------------------------- |
106 int_I_pres_surface = 1000;//980; | 105 char_I_step_is_1min = 1; |
107 char_I_N2_ratio = 79; //38; | 106 int_I_pres_respiration = 4500 + int_I_pres_surface; |
108 char_I_He_ratio = 0; //50; | 107 |
109 char_I_deco_distance = 10; // 10 = 1 meter | 108 for (i=0;i<29;i++) |
110 char_I_depth_last_deco = 3; // values below 3 (meter) are ignored | 109 deco_calc_hauptroutine(); |
111 | 110 |
112 char_I_const_ppO2 = 0; | 111 // Wait for one full computation |
113 char_I_deco_ppO2_change = 0; // [dm] 10 = 1 meter | 112 char_I_step_is_1min = 0; |
114 char_I_deco_ppO2 = 0; | 113 char_O_deco_status = 255; |
114 while (char_O_deco_status) | |
115 deco_calc_hauptroutine(); | |
116 print_stops(); | |
115 | 117 |
116 char_I_deco_gas_change = 20; // [m] 1 = 1 meter | 118 // And a second one |
117 char_I_deco_N2_ratio = 50; | 119 while (char_O_deco_status) |
118 char_I_deco_He_ratio = 0; | 120 deco_calc_hauptroutine(); |
121 print_stops(); | |
119 | 122 |
120 char_I_deco_gas_change2 = 6; // [m] 1 = 1 meter | 123 //---- 3000 seconds at 90m ----------------------------------------------- |
121 char_I_deco_N2_ratio2 = 0; | 124 int_I_pres_respiration = 10000; |
122 char_I_deco_He_ratio2 = 0; | 125 for (i=0;i<1500;i++) |
126 deco_calc_hauptroutine(); | |
123 | 127 |
124 char_I_deco_gas_change3 = 0; // [m] 1 = 1 meter | 128 while(char_O_deco_status != 0) |
125 char_I_deco_gas_change4 = 0; // [m] 1 = 1 meter | 129 deco_calc_hauptroutine(); |
126 char_I_deco_gas_change5 = 0; // [m] 1 = 1 meter | 130 print_stops(); |
127 | 131 |
128 //char_I_actual_ppO2; // 0x507 | 132 //---- 300 seconds at 29m ------------------------------------------------ |
129 char_I_GF_High_percentage = 100; // 0x514 new in v.102 | 133 int_I_pres_respiration = 3000; |
130 char_I_GF_Low_percentage = 100; // 0x515 new in v.102 | 134 for (i=0;i<150;i++) |
135 deco_calc_hauptroutine(); | |
131 | 136 |
132 char_I_saturation_multiplier = 110; | 137 while(char_O_deco_status != 0) |
133 char_I_desaturation_multiplier = 90; | 138 deco_calc_hauptroutine(); |
134 calc_hauptroutine_data_input(); | 139 print_stops(); |
135 | |
136 deco_clear_tissue(); | |
137 | |
138 char_I_step_is_1min = 1; | |
139 int_I_pres_respiration = 4500 + int_I_pres_surface; | |
140 | |
141 for (i=0;i<29;i++) | |
142 { | |
143 deco_calc_hauptroutine(); | |
144 } | 140 } |
145 | |
146 char_I_step_is_1min = 0; | |
147 char_O_deco_status = 255; | |
148 while (char_O_deco_status) | |
149 deco_calc_hauptroutine(); | |
150 _asm | |
151 nop | |
152 _endasm | |
153 | |
154 char_O_deco_status = 255; | |
155 while (char_O_deco_status) | |
156 deco_calc_hauptroutine(); | |
157 _asm | |
158 nop | |
159 _endasm | |
160 | |
161 int_I_pres_respiration = 10000; | |
162 for (i=0;i<1500;i++) | |
163 { | |
164 deco_calc_hauptroutine(); | |
165 } | |
166 | |
167 _asm | |
168 nop | |
169 _endasm | |
170 | |
171 | |
172 int_I_pres_respiration = 3000; | |
173 for (i=0;i<150;i++) | |
174 { | |
175 calc_hauptroutine_data_input(); | |
176 calc_hauptroutine_update_tissues(); | |
177 } //for | |
178 | |
179 update_startvalues(); | |
180 clear_decoarray(); | |
181 clear_internal_deco_table_GF(); | |
182 calc_hauptroutine_calc_ascend_to_deco(); | |
183 if (char_O_deco_status > 15) // can't go up to first deco, too deep to calculate in the given time slot | |
184 { | |
185 char_O_deco_status = 2; | |
186 // char_O_lock_depth_list = 255; | |
187 } | |
188 else | |
189 { | |
190 // char_O_lock_depth_list = lock_GF_depth_list; | |
191 calc_hauptroutine_calc_deco(); | |
192 } | |
193 // build_debug_output(); | |
194 | |
195 _asm | |
196 nop | |
197 _endasm | |
198 while (char_O_deco_status == 1) | |
199 { | |
200 char_O_deco_status = 0; | |
201 // char_O_lock_depth_list = 255; | |
202 calc_hauptroutine_calc_deco(); | |
203 // build_debug_output(); | |
204 _asm | |
205 nop | |
206 _endasm | |
207 }; | |
208 debug_temp = 60; // [mtr Aufstieg in 10 mtr/min (30steps'2sec/min] | |
209 int_I_pres_respiration = 9980; | |
210 for (i=0;i<debug_temp;i++) | |
211 { | |
212 int_I_pres_respiration = int_I_pres_respiration - 33; | |
213 calc_hauptroutine_data_input(); | |
214 calc_hauptroutine_update_tissues(); | |
215 int_I_pres_respiration = int_I_pres_respiration - 33; | |
216 calc_hauptroutine_data_input(); | |
217 calc_hauptroutine_update_tissues(); | |
218 int_I_pres_respiration = int_I_pres_respiration - 34; | |
219 calc_hauptroutine_data_input(); | |
220 calc_hauptroutine_update_tissues(); | |
221 } //for | |
222 _asm | |
223 nop | |
224 _endasm | |
225 | |
226 update_startvalues(); | |
227 clear_decoarray(); | |
228 clear_internal_deco_table_GF(); | |
229 calc_hauptroutine_calc_ascend_to_deco(); | |
230 if (char_O_deco_status > 15) // can't go up to first deco, too deep to calculate in the given time slot | |
231 { | |
232 char_O_deco_status = 2; | |
233 // char_O_lock_depth_list = 255; | |
234 } | |
235 else | |
236 { | |
237 // char_O_lock_depth_list = lock_GF_depth_list; | |
238 calc_hauptroutine_calc_deco(); | |
239 } | |
240 // build_debug_output(); | |
241 | |
242 _asm | |
243 nop | |
244 _endasm | |
245 while (char_O_deco_status == 1) | |
246 { | |
247 char_O_deco_status = 0; | |
248 // char_O_lock_depth_list = 255; | |
249 calc_hauptroutine_calc_deco(); | |
250 // build_debug_output(); | |
251 _asm | |
252 nop | |
253 _endasm | |
254 }; | |
255 _asm | |
256 nop | |
257 _endasm | |
258 debug_temp = 60; // [mtr Aufstieg in 10 mtr/min (30steps'2sec/min] | |
259 int_I_pres_respiration = 9980; | |
260 debug_temp = debug_temp * 3; | |
261 for (i=0;i<debug_temp;i++) | |
262 { | |
263 calc_hauptroutine_data_input(); | |
264 calc_hauptroutine_update_tissues(); | |
265 } //for | |
266 _asm | |
267 nop | |
268 _endasm | |
269 #endif | |
270 // ----------------------- | |
271 | |
272 } // main |