Mercurial > public > mk2
comparison code_part1/OSTC_code_c_part2/p2_deco.c @ 164:999abb01c78f
+ Change data allocation scheme
author | JeanDo |
---|---|
date | Fri, 21 Jan 2011 01:44:38 +0100 |
parents | 144822282fa3 |
children | 8b5b848db4cd |
comparison
equal
deleted
inserted
replaced
163:144822282fa3 | 164:999abb01c78f |
---|---|
156 static float var2_e1min; | 156 static float var2_e1min; |
157 static float var_halftimes; | 157 static float var_halftimes; |
158 static float var2_halftimes; | 158 static float var2_halftimes; |
159 static float pres_gtissue_limit; | 159 static float pres_gtissue_limit; |
160 static float temp_pres_gtissue_limit; | 160 static float temp_pres_gtissue_limit; |
161 static float actual_ppO2; // new in v.102 | 161 static float actual_ppO2; // new in v.102 |
162 | 162 |
163 static float pres_tissue[32]; | 163 static float pres_diluent; // new in v.101 |
164 static float deco_diluent; // new in v.101 | |
165 static float const_ppO2; // new in v.101 | |
166 static float deco_ppO2_change; // new in v.101 | |
167 static float deco_ppO2; // new in v.101 | |
164 | 168 |
165 //---- Bank 6 parameters ----------------------------------------------------- | 169 //---- Bank 6 parameters ----------------------------------------------------- |
166 #pragma udata bank6=0x600 | 170 #pragma udata bank6=0x600 |
167 | 171 |
172 static float pres_tissue[32]; | |
168 static float pres_tissue_limit[16]; | 173 static float pres_tissue_limit[16]; |
169 static float sim_pres_tissue_limit[16]; | 174 static float sim_pres_tissue_limit[16]; |
170 static float pres_diluent; // new in v.101 | |
171 static float deco_diluent; // new in v.101 | |
172 static float const_ppO2; // new in v.101 | |
173 static float deco_ppO2_change; // new in v.101 | |
174 static float deco_ppO2; // new in v.101 | |
175 | 175 |
176 //---- Bank 7 parameters ----------------------------------------------------- | 176 //---- Bank 7 parameters ----------------------------------------------------- |
177 #pragma udata bank7=0x700 | 177 #pragma udata bank7=0x700 |
178 | 178 |
179 static float sim_pres_tissue[32]; // 32 floats = 128 bytes. | 179 static float sim_pres_tissue[32]; // 32 floats = 128 bytes. |
188 //---- Bank 9 parameters ----------------------------------------------------- | 188 //---- Bank 9 parameters ----------------------------------------------------- |
189 #pragma udata bank9a=0x900 | 189 #pragma udata bank9a=0x900 |
190 | 190 |
191 static char md_state[48]; // DONT MOVE !! // has to be at the beginning of bank 9 for the asm code!!! | 191 static char md_state[48]; // DONT MOVE !! // has to be at the beginning of bank 9 for the asm code!!! |
192 | 192 |
193 // internal: | 193 static char md_t; |
194 static char md_t; | 194 static char md_buffer[16]; |
195 static char md_buffer[16]; | 195 static unsigned char md_i; |
196 static char md_cksum[16]; | 196 static char md_j; |
197 static char md_i; | 197 static char md_temp; |
198 static char md_j; | 198 static unsigned int md_pointer; |
199 static char md_temp; | 199 static float deco_N2_ratio; // new in v.101 |
200 static unsigned int md_pointer; | 200 static float deco_He_ratio; // new in v.101 |
201 static float deco_N2_ratio; // new in v.101 | 201 static float calc_N2_ratio; // new in v.101 |
202 static float deco_He_ratio; // new in v.101 | 202 static float calc_He_ratio; // new in v.101 |
203 static float calc_N2_ratio; // new in v.101 | 203 static float deco_gas_change; // new in v.101 |
204 static float calc_He_ratio; // new in v.101 | 204 static float CNS_fraction; // new in v.101 |
205 static float deco_gas_change; // new in v.101 | 205 static float float_saturation_multiplier; // new in v.101 |
206 static float CNS_fraction; // new in v.101 | 206 static float float_desaturation_multiplier; // new in v.101 |
207 static float float_saturation_multiplier; // new in v.101 | 207 static float float_deco_distance; // new in v.101 |
208 static float float_desaturation_multiplier; // new in v.101 | 208 |
209 static float float_deco_distance; // new in v.101 | 209 // internal, dbg: |
210 // internal, dbg: | 210 static unsigned char DBG_char_I_deco_model; // new in v.108 |
211 static unsigned char DBG_char_I_deco_model; // new in v.108 | 211 static unsigned char DBG_char_I_depth_last_deco; // new in v.108 |
212 static unsigned char DBG_char_I_depth_last_deco; // new in v.108 | 212 static float DBG_pres_surface; // new in v.108 |
213 static float DBG_pres_surface; // new in v.108 | 213 static float DBG_GF_low; // new in v.108 |
214 static float DBG_GF_low; // new in v.108 | 214 static float DBG_GF_high; // new in v.108 |
215 static float DBG_GF_high; // new in v.108 | 215 static float DBG_const_ppO2; // new in v.108 |
216 static float DBG_const_ppO2; // new in v.108 | 216 static float DBG_deco_ppO2_change; // new in v.108 |
217 static float DBG_deco_ppO2_change; // new in v.108 | 217 static float DBG_deco_ppO2; // new in v.108 |
218 static float DBG_deco_ppO2; // new in v.108 | 218 static float DBG_deco_N2_ratio; // new in v.108 |
219 static float DBG_deco_N2_ratio; // new in v.108 | 219 static float DBG_deco_He_ratio; // new in v.108 |
220 static float DBG_deco_He_ratio; // new in v.108 | 220 static float DBG_deco_gas_change; // new in v.108 |
221 static float DBG_deco_gas_change; // new in v.108 | 221 static float DBG_float_saturation_multiplier; // new in v.108 |
222 static float DBG_float_saturation_multiplier; // new in v.108 | 222 static float DBG_float_desaturation_multiplier; // new in v.108 |
223 static float DBG_float_desaturation_multiplier; // new in v.108 | 223 static float DBG_float_deco_distance; // new in v.108 |
224 static float DBG_float_deco_distance; // new in v.108 | 224 static float DBG_deco_N2_ratio; // new in v.108 |
225 static float DBG_deco_N2_ratio; // new in v.108 | 225 static float DBG_deco_He_ratio; // new in v.108 |
226 static float DBG_deco_He_ratio; // new in v.108 | 226 static float DBG_N2_ratio; // new in v.108 |
227 static float DBG_N2_ratio; // new in v.108 | 227 static float DBG_He_ratio; // new in v.108 |
228 static float DBG_He_ratio; // new in v.108 | 228 static char flag_in_divemode; // new in v.108 |
229 static char flag_in_divemode; // new in v.108 | 229 static int int_dbg_i; // new in v.108 |
230 static int int_dbg_i; // new in v.108 | 230 static unsigned int temp_DBS; |
231 static unsigned int temp_DBS; | 231 |
232 | 232 static float deco_gas_change2; // new in v.109 |
233 static float deco_gas_change2; // new in v.109 | 233 static float deco_gas_change3; // new in v.109 |
234 static float deco_gas_change3; // new in v.109 | 234 static float deco_gas_change4; // new in v.109 |
235 static float deco_gas_change4; // new in v.109 | 235 static float deco_gas_change5; // new in v.109 |
236 static float deco_gas_change5; // new in v.109 | 236 |
237 | 237 static float deco_N2_ratio2; // new in v.109 |
238 static float deco_N2_ratio2; // new in v.109 | 238 static float deco_N2_ratio3; // new in v.109 |
239 static float deco_N2_ratio3; // new in v.109 | 239 static float deco_N2_ratio4; // new in v.109 |
240 static float deco_N2_ratio4; // new in v.109 | 240 static float deco_N2_ratio5; // new in v.109 |
241 static float deco_N2_ratio5; // new in v.109 | 241 static float deco_He_ratio2; // new in v.109 |
242 static float deco_He_ratio2; // new in v.109 | 242 static float deco_He_ratio3; // new in v.109 |
243 static float deco_He_ratio3; // new in v.109 | 243 static float deco_He_ratio4; // new in v.109 |
244 static float deco_He_ratio4; // new in v.109 | 244 static float deco_He_ratio5; // new in v.109 |
245 static float deco_He_ratio5; // new in v.109 | |
246 | 245 |
247 // *********************** | 246 // *********************** |
248 // *********************** | 247 // *********************** |
249 // ** THE LOOKUP TABLES ** | 248 // ** THE LOOKUP TABLES ** |
250 // *********************** | 249 // *********************** |
694 MOVLW 1 \ | 693 MOVLW 1 \ |
695 MOVWF TBLPTRU,0 \ | 694 MOVWF TBLPTRU,0 \ |
696 _endasm | 695 _endasm |
697 #endif | 696 #endif |
698 | 697 |
699 | |
700 void deco_calc_hauptroutine(void) | 698 void deco_calc_hauptroutine(void) |
701 { | 699 { |
702 RESET_C_STACK | 700 RESET_C_STACK |
703 calc_hauptroutine(); | 701 calc_hauptroutine(); |
704 int_O_desaturation_time = 65535; | 702 int_O_desaturation_time = 65535; |
739 | 737 |
740 #pragma code p2_deco_suite = 0x10700 | 738 #pragma code p2_deco_suite = 0x10700 |
741 | 739 |
742 void clear_tissue(void) // preload tissues with standard pressure for the given ambient pressure | 740 void clear_tissue(void) // preload tissues with standard pressure for the given ambient pressure |
743 { | 741 { |
744 | |
745 flag_in_divemode = 0; | 742 flag_in_divemode = 0; |
746 int_O_DBS_bitfield = 0; | 743 int_O_DBS_bitfield = 0; |
747 int_O_DBS2_bitfield = 0; | 744 int_O_DBS2_bitfield = 0; |
748 int_O_DBG_pre_bitfield = 0; | 745 int_O_DBG_pre_bitfield = 0; |
749 int_O_DBG_post_bitfield = 0; | 746 int_O_DBG_post_bitfield = 0; |
750 char_O_NDL_at_20mtr = 255; | 747 char_O_NDL_at_20mtr = 255; |
751 | 748 |
752 // N2_ratio = (float)char_I_N2_ratio; // the 0.0002 of 0.7902 are missing with standard air | 749 // N2_ratio = (float)char_I_N2_ratio; // the 0.0002 of 0.7902 are missing with standard air |
753 N2_ratio = 0.7902; // N2_ratio / 100.0; | 750 N2_ratio = 0.7902; // N2_ratio / 100.0; |
754 pres_respiration = (float)int_I_pres_respiration / 1000.0; | 751 pres_respiration = (float)int_I_pres_respiration / 1000.0; |
755 for (ci=0;ci<16;ci++) // cycle through the 16 b"uhlmann tissues | 752 |
753 _asm | |
754 movlw 1 | |
755 movwf TBLPTRU,0 | |
756 _endasm | |
757 for(ci=0;ci<16;ci++) | |
756 { | 758 { |
757 pres_tissue[ci] = N2_ratio * (pres_respiration - 0.0627) ; | 759 overlay float p; |
758 _asm | 760 // cycle through the 16 b"uhlmann tissues |
759 movlw 0x02 | 761 p = N2_ratio * (pres_respiration - 0.0627) ; |
760 movwf TBLPTRH,0 | 762 pres_tissue[ci] = p; |
761 movlb 4 // fuer ci | |
762 movf ci,0,1 | |
763 addwf ci,0,1 | |
764 addwf ci,0,1 | |
765 addwf ci,0,1 | |
766 addlw 0x80 | |
767 movwf TBLPTRL,0 | |
768 TBLRDPOSTINC | |
769 movff TABLAT,var_a+1 | |
770 TBLRDPOSTINC | |
771 movff TABLAT,var_a | |
772 TBLRDPOSTINC | |
773 movff TABLAT,var_a+3 | |
774 TBLRD | |
775 movff TABLAT,var_a+2 | |
776 addlw 0x80 | |
777 movwf TBLPTRL,0 | |
778 incf TBLPTRH,1,0 | |
779 TBLRDPOSTINC | |
780 movff TABLAT,var_b+1 | |
781 TBLRDPOSTINC | |
782 movff TABLAT,var_b | |
783 TBLRDPOSTINC | |
784 movff TABLAT,var_b+3 | |
785 TBLRD | |
786 movff TABLAT,var_b+2 | |
787 _endasm | |
788 | 763 |
789 pres_tissue_limit[ci] = (pres_tissue[ci] - var_a) * var_b ; | 764 var_a = ((rom float*)a_N2)[ci]; |
790 // now update the guiding tissue | 765 var_b = ((rom float*)b_N2)[ci]; |
791 if (pres_tissue_limit[ci] < 0) | 766 p = (p - var_a) * var_b ; |
792 pres_tissue_limit[ci] = 0; | 767 if( p < 0.0 ) |
768 p = 0.0; | |
769 pres_tissue_limit[ci] = p; | |
770 | |
771 // cycle through the 16 b"uhlmann tissues for Helium | |
772 pres_tissue[ci+16] = 0.0; | |
793 } // for 0 to 16 | 773 } // for 0 to 16 |
794 | |
795 for (ci=16;ci<32;ci++) // cycle through the 16 b"uhlmann tissues for Helium | |
796 { | |
797 pres_tissue[ci] = 0.0; | |
798 } // for | |
799 | 774 |
800 clear_decoarray(); | 775 clear_decoarray(); |
801 char_O_deco_status = 0; | 776 char_O_deco_status = 0; |
802 char_O_nullzeit = 0; | 777 char_O_nullzeit = 0; |
803 char_O_ascenttime = 0; | 778 char_O_ascenttime = 0; |
1228 for (ci=0;ci<16;ci++) | 1203 for (ci=0;ci<16;ci++) |
1229 { | 1204 { |
1230 _asm | 1205 _asm |
1231 movlw 0x02 | 1206 movlw 0x02 |
1232 movwf TBLPTRH,0 | 1207 movwf TBLPTRH,0 |
1233 movlb 4 // fuer ci | 1208 movlb 5 // fuer ci |
1234 movf ci,0,1 | 1209 movf ci,0,1 |
1235 addwf ci,0,1 | 1210 addwf ci,0,1 |
1236 addwf ci,0,1 | 1211 addwf ci,0,1 |
1237 addwf ci,0,1 | 1212 addwf ci,0,1 |
1238 movwf TBLPTRL,0 | 1213 movwf TBLPTRL,0 |
1239 TBLRDPOSTINC | 1214 TBLRDPOSTINC |
1488 for (ci=0;ci<16;ci++) | 1463 for (ci=0;ci<16;ci++) |
1489 { | 1464 { |
1490 _asm | 1465 _asm |
1491 movlw 0x02 | 1466 movlw 0x02 |
1492 movwf TBLPTRH,0 | 1467 movwf TBLPTRH,0 |
1493 movlb 4 // fuer ci | 1468 movlb 5 // fuer ci |
1494 movf ci,0,1 | 1469 movf ci,0,1 |
1495 addwf ci,0,1 | 1470 addwf ci,0,1 |
1496 addwf ci,0,1 | 1471 addwf ci,0,1 |
1497 addwf ci,0,1 | 1472 addwf ci,0,1 |
1498 addlw 0x80 | 1473 addlw 0x80 |
1499 movwf TBLPTRL,0 | 1474 movwf TBLPTRL,0 |
1609 for (ci=0;ci<16;ci++) | 1584 for (ci=0;ci<16;ci++) |
1610 { | 1585 { |
1611 _asm | 1586 _asm |
1612 movlw 0x02 | 1587 movlw 0x02 |
1613 movwf TBLPTRH,0 | 1588 movwf TBLPTRH,0 |
1614 movlb 4 // fuer ci | 1589 movlb 5 // fuer ci |
1615 movf ci,0,1 | 1590 movf ci,0,1 |
1616 addwf ci,0,1 | 1591 addwf ci,0,1 |
1617 addwf ci,0,1 | 1592 addwf ci,0,1 |
1618 addwf ci,0,1 | 1593 addwf ci,0,1 |
1619 addlw 0x80 | 1594 addlw 0x80 |
1620 movwf TBLPTRL,0 | 1595 movwf TBLPTRL,0 |
1861 for (ci=0;ci<16;ci++) | 1836 for (ci=0;ci<16;ci++) |
1862 { | 1837 { |
1863 _asm | 1838 _asm |
1864 movlw 0x04 | 1839 movlw 0x04 |
1865 movwf TBLPTRH,0 | 1840 movwf TBLPTRH,0 |
1866 movlb 4 // fuer ci | 1841 movlb 5 // fuer ci |
1867 movf ci,0,1 | 1842 movf ci,0,1 |
1868 addwf ci,0,1 | 1843 addwf ci,0,1 |
1869 addwf ci,0,1 | 1844 addwf ci,0,1 |
1870 addwf ci,0,1 | 1845 addwf ci,0,1 |
1871 addlw 0x80 | 1846 addlw 0x80 |
1872 movwf TBLPTRL,0 | 1847 movwf TBLPTRL,0 |
2017 for (ci=0;ci<16;ci++) | 1992 for (ci=0;ci<16;ci++) |
2018 { | 1993 { |
2019 _asm | 1994 _asm |
2020 movlw 0x02 | 1995 movlw 0x02 |
2021 movwf TBLPTRH,0 | 1996 movwf TBLPTRH,0 |
2022 movlb 4 // fuer ci | 1997 movlb 5 // fuer ci |
2023 movf ci,0,1 | 1998 movf ci,0,1 |
2024 addwf ci,0,1 | 1999 addwf ci,0,1 |
2025 addwf ci,0,1 | 2000 addwf ci,0,1 |
2026 addwf ci,0,1 | 2001 addwf ci,0,1 |
2027 addlw 0x80 | 2002 addlw 0x80 |
2028 movwf TBLPTRL,0 | 2003 movwf TBLPTRL,0 |
2118 void deco_hash(void) | 2093 void deco_hash(void) |
2119 { | 2094 { |
2120 RESET_C_STACK | 2095 RESET_C_STACK |
2121 | 2096 |
2122 // init | 2097 // init |
2123 for (md_i=0;md_i<16;md_i++) | 2098 for(md_i=0;md_i<16;md_i++) |
2124 { | 2099 { |
2125 md_state[md_i] = 0; | 2100 md_state[md_i] = 0; |
2126 md_cksum[md_i] = 0; | 2101 char_O_hash[md_i] = 0; |
2127 } // for md_i 16 | 2102 } // for md_i 16 |
2128 | 2103 |
2129 _asm | 2104 _asm |
2130 movlw 0x01 | 2105 movlw 0x01 |
2131 movwf TBLPTRU,0 | 2106 movwf TBLPTRU,0 |
2132 movlw 0x06 | 2107 movlw 0x06 |
2133 movwf TBLPTRH,0 | 2108 movwf TBLPTRH,0 |
2134 movlw 0x00 | 2109 movlw 0x00 |
2135 movwf TBLPTRL,0 | 2110 movwf TBLPTRL,0 |
2136 _endasm; | 2111 _endasm; |
2137 for (md_i=0;md_i<127;md_i++) | 2112 for(md_i=0;md_i<=255;md_i++) |
2138 { | 2113 { |
2139 _asm | 2114 _asm |
2140 TBLRDPOSTINC | 2115 TBLRDPOSTINC |
2141 movff TABLAT,md_temp | 2116 movff TABLAT,md_temp |
2142 _endasm | 2117 _endasm |
2143 md_pi_subst[md_i] = md_temp; | 2118 md_pi_subst[md_i] = md_temp; |
2144 } // for md_i 256 | 2119 } // for md_i 256 |
2145 _asm | |
2146 TBLRDPOSTINC | |
2147 movff TABLAT,md_temp | |
2148 _endasm; | |
2149 md_pi_subst[127] = md_temp; | |
2150 for (md_i=0;md_i<127;md_i++) | |
2151 { | |
2152 _asm | |
2153 TBLRDPOSTINC | |
2154 movff TABLAT,md_temp | |
2155 _endasm | |
2156 md_pi_subst[md_i+128] = md_temp; | |
2157 } // for md_i 256 | |
2158 _asm | |
2159 TBLRD | |
2160 movff TABLAT,md_temp | |
2161 _endasm | |
2162 md_pi_subst[255] = md_temp; | |
2163 | 2120 |
2164 _asm | 2121 _asm |
2165 movlw 0x00 | 2122 movlw 0x00 |
2166 movwf TBLPTRU,0 | 2123 movwf TBLPTRU,0 |
2167 movlw 0x00 | 2124 movlw 0x00 |
2174 { | 2131 { |
2175 md_t = 0; | 2132 md_t = 0; |
2176 for (md_i=0;md_i<16;md_i++) | 2133 for (md_i=0;md_i<16;md_i++) |
2177 { | 2134 { |
2178 if(md_pointer == 9) | 2135 if(md_pointer == 9) |
2179 md_temp = md_cksum[md_i]; | 2136 md_temp = char_O_hash[md_i]; |
2180 else | 2137 else |
2181 { | 2138 { |
2182 _asm | 2139 _asm |
2183 TBLRDPOSTINC | 2140 TBLRDPOSTINC |
2184 movff TABLAT,md_temp | 2141 movff TABLAT,md_temp |
2196 md_state[md_j] = (unsigned char)(md_state[md_j] ^ md_pi_subst[md_t]); | 2153 md_state[md_j] = (unsigned char)(md_state[md_j] ^ md_pi_subst[md_t]); |
2197 md_t = md_state[md_j]; | 2154 md_t = md_state[md_j]; |
2198 } // for md_j 48 | 2155 } // for md_j 48 |
2199 md_t = (unsigned char)(md_t+1); | 2156 md_t = (unsigned char)(md_t+1); |
2200 } // for md_i 18 | 2157 } // for md_i 18 |
2201 md_t = md_cksum[15]; | 2158 md_t = char_O_hash[15]; |
2202 | 2159 |
2203 for (md_i=0;md_i<16;md_i++) | 2160 for (md_i=0;md_i<16;md_i++) |
2204 { | 2161 { |
2205 md_cksum[md_i] = (unsigned char)(md_cksum[md_i] ^ md_pi_subst[(md_buffer[md_i] ^ md_t)]); | 2162 char_O_hash[md_i] = (unsigned char)(char_O_hash[md_i] ^ md_pi_subst[(md_buffer[md_i] ^ md_t)]); |
2206 md_t = md_cksum[md_i]; | 2163 md_t = char_O_hash[md_i]; |
2207 } // for md_i 16 | 2164 } // for md_i 16 |
2208 } // for md_pointer | 2165 } // for md_pointer |
2209 } // void deco_hash(void) | 2166 } // void deco_hash(void) |
2210 | 2167 |
2211 // --------------------- | 2168 // --------------------- |
2330 CNS_fraction = cns_vault; | 2287 CNS_fraction = cns_vault; |
2331 for (ci=0;ci<32;ci++) | 2288 for (ci=0;ci<32;ci++) |
2332 pres_tissue[ci] = pres_tissue_vault[ci]; | 2289 pres_tissue[ci] = pres_tissue_vault[ci]; |
2333 } | 2290 } |
2334 | 2291 |
2292 void main() {} |