Mercurial > public > mk2
comparison code_part1/OSTC_code_c_part2/p2_deco.c @ 122:3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
author | JeanDo |
---|---|
date | Tue, 28 Dec 2010 15:28:55 +0100 |
parents | 14a074e1a375 |
children | ed275788a291 |
comparison
equal
deleted
inserted
replaced
121:e0f29e20bd24 | 122:3003a8040b78 |
---|---|
253 static float sim_pres_tissue[32]; | 253 static float sim_pres_tissue[32]; |
254 static float sim_pres_tissue_backup[32]; | 254 static float sim_pres_tissue_backup[32]; |
255 | 255 |
256 #pragma udata bank8=0x800 | 256 #pragma udata bank8=0x800 |
257 static char md_pi_subst[256]; | 257 static char md_pi_subst[256]; |
258 #define C_STACK md_pi_subst // Overlay C-code data stack here, too. | |
258 | 259 |
259 #pragma udata bank9a=0x900 | 260 #pragma udata bank9a=0x900 |
260 // output: | 261 // output: |
261 static char md_state[48]; // DONT MOVE !! // has to be at the beginning of bank 9 for the asm code!!! | 262 static char md_state[48]; // DONT MOVE !! // has to be at the beginning of bank 9 for the asm code!!! |
262 | 263 |
465 } | 466 } |
466 | 467 |
467 // ------------------------------- | 468 // ------------------------------- |
468 // DBG - multi main during dive // | 469 // DBG - multi main during dive // |
469 // ------------------------------- | 470 // ------------------------------- |
470 void check_dbg(char is_post_check) | 471 void check_dbg(static char is_post_check) |
471 { | 472 { |
472 temp_DBS = 0; | 473 temp_DBS = 0; |
473 if( (DBG_N2_ratio != N2_ratio) || (DBG_He_ratio != He_ratio) ) | 474 if( (DBG_N2_ratio != N2_ratio) || (DBG_He_ratio != He_ratio) ) |
474 temp_DBS |= DBG_c_gas; | 475 temp_DBS |= DBG_c_gas; |
475 if(DBG_const_ppO2 != const_ppO2) | 476 if(DBG_const_ppO2 != const_ppO2) |
744 // ********************** | 745 // ********************** |
745 // ** THE JUMP-IN CODE ** | 746 // ** THE JUMP-IN CODE ** |
746 // ** for the asm code ** | 747 // ** for the asm code ** |
747 // ********************** | 748 // ********************** |
748 // ********************** | 749 // ********************** |
750 | |
751 void fillDataStack(void) | |
752 { | |
753 _asm | |
754 LFSR 1,C_STACK | |
755 MOVLW 0xCC | |
756 loop: MOVWF POSTINC1,0 | |
757 TSTFSZ FSR1L,0 | |
758 BRA loop | |
759 | |
760 LFSR 1,C_STACK | |
761 LFSR 2,C_STACK | |
762 MOVLW 1 | |
763 MOVWF TBLPTRU,0 | |
764 _endasm | |
765 } | |
766 | |
767 // When calling C code from ASM context, the data stack pointer and | |
768 // frames should be reset. Bank3 is dedicated to the stack (see the | |
769 // .lkr script). | |
770 #ifdef __DEBUG | |
771 # define RESET_C_STACK fillDataStack(); | |
772 #else | |
773 # define RESET_C_STACK \ | |
774 _asm \ | |
775 LFSR 1, C_STACK \ | |
776 LFSR 2, C_STACK \ | |
777 MOVLW 1 \ | |
778 MOVWF TBLPTRU,0 \ | |
779 _endasm | |
780 #endif | |
781 | |
782 | |
749 void deco_calc_hauptroutine(void) | 783 void deco_calc_hauptroutine(void) |
750 { | 784 { |
785 RESET_C_STACK | |
751 calc_hauptroutine(); | 786 calc_hauptroutine(); |
752 int_O_desaturation_time = 65535; | 787 int_O_desaturation_time = 65535; |
753 } | 788 } |
754 | 789 |
755 void deco_calc_without_deco(void) | 790 void deco_calc_without_deco(void) |
756 { | 791 { |
792 RESET_C_STACK | |
757 calc_without_deco(); | 793 calc_without_deco(); |
758 deco_calc_desaturation_time(); | 794 deco_calc_desaturation_time(); |
759 } | 795 } |
760 | 796 |
761 void deco_clear_tissue(void) | 797 void deco_clear_tissue(void) |
762 { | 798 { |
799 RESET_C_STACK | |
763 clear_tissue(); | 800 clear_tissue(); |
764 char_I_depth_last_deco = 0; // for compatibility with v.101pre_no_last_deco | 801 char_I_depth_last_deco = 0; // for compatibility with v.101pre_no_last_deco |
765 } | 802 } |
766 | 803 |
767 void deco_calc_wo_deco_step_1_min(void) | 804 void deco_calc_wo_deco_step_1_min(void) |
768 { | 805 { |
806 RESET_C_STACK | |
769 calc_wo_deco_step_1_min(); | 807 calc_wo_deco_step_1_min(); |
770 char_O_deco_status = 3; // surface new in v.102 overwrites value of calc_wo_deco_step_1_min | 808 char_O_deco_status = 3; // surface new in v.102 overwrites value of calc_wo_deco_step_1_min |
771 deco_calc_desaturation_time(); | 809 deco_calc_desaturation_time(); |
772 } | 810 } |
773 | 811 |
774 void deco_debug(void) | 812 void deco_debug(void) |
775 { | 813 { |
776 //debug(); | 814 RESET_C_STACK |
815 // debug(); | |
777 } | 816 } |
778 | 817 |
779 // --------------- | 818 // --------------- |
780 // CLEAR tissue // | 819 // CLEAR tissue // |
781 // --------------- | 820 // --------------- |
790 int_O_DBS_bitfield = 0; | 829 int_O_DBS_bitfield = 0; |
791 int_O_DBS2_bitfield = 0; | 830 int_O_DBS2_bitfield = 0; |
792 int_O_DBG_pre_bitfield = 0; | 831 int_O_DBG_pre_bitfield = 0; |
793 int_O_DBG_post_bitfield = 0; | 832 int_O_DBG_post_bitfield = 0; |
794 char_O_NDL_at_20mtr = 255; | 833 char_O_NDL_at_20mtr = 255; |
795 | |
796 _asm | |
797 lfsr 1, 0x300 // C math routines shall use this variable bank | |
798 movlw 0x01 | |
799 movwf TBLPTRU,0 | |
800 _endasm | |
801 | 834 |
802 // N2_ratio = (float)char_I_N2_ratio; // the 0.0002 of 0.7902 are missing with standard air | 835 // N2_ratio = (float)char_I_N2_ratio; // the 0.0002 of 0.7902 are missing with standard air |
803 N2_ratio = 0.7902; // N2_ratio / 100.0; | 836 N2_ratio = 0.7902; // N2_ratio / 100.0; |
804 pres_respiration = (float)int_I_pres_respiration / 1000.0; | 837 pres_respiration = (float)int_I_pres_respiration / 1000.0; |
805 for (ci=0;ci<16;ci++) // cycle through the 16 b"uhlmann tissues | 838 for (ci=0;ci<16;ci++) // cycle through the 16 b"uhlmann tissues |
862 // -------------------- | 895 // -------------------- |
863 // optimized in v.101 (float_..saturation_multiplier) | 896 // optimized in v.101 (float_..saturation_multiplier) |
864 | 897 |
865 void calc_without_deco(void) | 898 void calc_without_deco(void) |
866 { | 899 { |
867 _asm | |
868 lfsr 1, 0x300 | |
869 _endasm | |
870 N2_ratio = 0.7902; // FIXED RATIO !! sum as stated in b"uhlmann | 900 N2_ratio = 0.7902; // FIXED RATIO !! sum as stated in b"uhlmann |
871 pres_respiration = (float)int_I_pres_respiration / 1000.0; // assembler code uses different digit system | 901 pres_respiration = (float)int_I_pres_respiration / 1000.0; // assembler code uses different digit system |
872 pres_surface = (float)int_I_pres_surface / 1000.0; | 902 pres_surface = (float)int_I_pres_surface / 1000.0; |
873 temp_atem = N2_ratio * (pres_respiration - 0.0627); // 0.0627 is the extra pressure in the body | 903 temp_atem = N2_ratio * (pres_respiration - 0.0627); // 0.0627 is the extra pressure in the body |
874 temp2_atem = 0.0; | 904 temp2_atem = 0.0; |
1279 // -------------- | 1309 // -------------- |
1280 // optimized in v.101 | 1310 // optimized in v.101 |
1281 | 1311 |
1282 void calc_tissue(void) | 1312 void calc_tissue(void) |
1283 { | 1313 { |
1284 _asm | |
1285 lfsr 1, 0x300 | |
1286 movlw 0x01 | |
1287 movwf TBLPTRU,0 | |
1288 _endasm | |
1289 | |
1290 char_O_gtissue_no = 255; | 1314 char_O_gtissue_no = 255; |
1291 pres_gtissue_limit = 0.0; | 1315 pres_gtissue_limit = 0.0; |
1292 | 1316 |
1293 for (ci=0;ci<16;ci++) | 1317 for (ci=0;ci<16;ci++) |
1294 { | 1318 { |
1547 void sim_tissue_1min(void) | 1571 void sim_tissue_1min(void) |
1548 { | 1572 { |
1549 temp_pres_gtissue_limit = 0.0; | 1573 temp_pres_gtissue_limit = 0.0; |
1550 temp_gtissue_no = 255; | 1574 temp_gtissue_no = 255; |
1551 | 1575 |
1552 _asm | |
1553 lfsr 1, 0x300 | |
1554 movlw 0x01 | |
1555 movwf TBLPTRU,0 | |
1556 _endasm | |
1557 | |
1558 | |
1559 for (ci=0;ci<16;ci++) | 1576 for (ci=0;ci<16;ci++) |
1560 { | 1577 { |
1561 _asm | 1578 _asm |
1562 movlw 0x02 | 1579 movlw 0x02 |
1563 movwf TBLPTRH,0 | 1580 movwf TBLPTRH,0 |
1670 | 1687 |
1671 void sim_tissue_10min(void) | 1688 void sim_tissue_10min(void) |
1672 { | 1689 { |
1673 temp_pres_gtissue_limit = 0.0; | 1690 temp_pres_gtissue_limit = 0.0; |
1674 temp_gtissue_no = 255; | 1691 temp_gtissue_no = 255; |
1675 | |
1676 _asm | |
1677 lfsr 1, 0x300 | |
1678 movlw 0x01 | |
1679 movwf TBLPTRU,0 | |
1680 _endasm | |
1681 | 1692 |
1682 for (ci=0;ci<16;ci++) | 1693 for (ci=0;ci<16;ci++) |
1683 { | 1694 { |
1684 _asm | 1695 _asm |
1685 movlw 0x02 | 1696 movlw 0x02 |
1918 // optimized in v.101 (var_a) | 1929 // optimized in v.101 (var_a) |
1919 // new code in v.102 | 1930 // new code in v.102 |
1920 | 1931 |
1921 void deco_gradient_array() | 1932 void deco_gradient_array() |
1922 { | 1933 { |
1934 RESET_C_STACK | |
1923 pres_respiration = (float)int_I_pres_respiration / 1000.0; // assembler code uses different digit system | 1935 pres_respiration = (float)int_I_pres_respiration / 1000.0; // assembler code uses different digit system |
1924 for (ci=0;ci<16;ci++) | 1936 for (ci=0;ci<16;ci++) |
1925 { | 1937 { |
1926 temp_tissue = pres_tissue[ci] + pres_tissue[ci+16]; | 1938 temp_tissue = pres_tissue[ci] + pres_tissue[ci+16]; |
1927 temp1 = temp_tissue - pres_respiration; | 1939 temp1 = temp_tissue - pres_respiration; |
1946 // FIXED N2_ratio | 1958 // FIXED N2_ratio |
1947 // unchanged in v.101 | 1959 // unchanged in v.101 |
1948 | 1960 |
1949 void deco_calc_desaturation_time(void) | 1961 void deco_calc_desaturation_time(void) |
1950 { | 1962 { |
1951 _asm | 1963 RESET_C_STACK |
1952 lfsr 1, 0x300 | 1964 |
1953 movlw 0x01 | |
1954 movwf TBLPTRU,0 | |
1955 _endasm | |
1956 N2_ratio = 0.7902; // FIXED sum as stated in b"uhlmann | 1965 N2_ratio = 0.7902; // FIXED sum as stated in b"uhlmann |
1957 pres_surface = (float)int_I_pres_surface / 1000.0; | 1966 pres_surface = (float)int_I_pres_surface / 1000.0; |
1958 temp_atem = N2_ratio * (pres_surface - 0.0627); | 1967 temp_atem = N2_ratio * (pres_surface - 0.0627); |
1959 int_O_desaturation_time = 0; | 1968 int_O_desaturation_time = 0; |
1960 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142) | 1969 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142) |
2083 if(flag_in_divemode) | 2092 if(flag_in_divemode) |
2084 { | 2093 { |
2085 flag_in_divemode = 0; | 2094 flag_in_divemode = 0; |
2086 set_dbg_end_of_dive(); | 2095 set_dbg_end_of_dive(); |
2087 } | 2096 } |
2088 _asm | 2097 |
2089 lfsr 1, 0x300 | |
2090 _endasm | |
2091 N2_ratio = 0.7902; // FIXED, sum lt. buehlmann | 2098 N2_ratio = 0.7902; // FIXED, sum lt. buehlmann |
2092 pres_respiration = (float)int_I_pres_respiration / 1000.0; // assembler code uses different digit system | 2099 pres_respiration = (float)int_I_pres_respiration / 1000.0; // assembler code uses different digit system |
2093 pres_surface = (float)int_I_pres_surface / 1000.0; | 2100 pres_surface = (float)int_I_pres_surface / 1000.0; |
2094 temp_atem = N2_ratio * (pres_respiration - 0.0627); // 0.0627 is the extra pressure in the body | 2101 temp_atem = N2_ratio * (pres_respiration - 0.0627); // 0.0627 is the extra pressure in the body |
2095 temp2_atem = 0.0; | 2102 temp2_atem = 0.0; |
2112 // ------------------------- | 2119 // ------------------------- |
2113 // optimized in v.101 | 2120 // optimized in v.101 |
2114 | 2121 |
2115 void calc_tissue_step_1_min(void) | 2122 void calc_tissue_step_1_min(void) |
2116 { | 2123 { |
2117 _asm | |
2118 lfsr 1, 0x300 | |
2119 movlw 0x01 | |
2120 movwf TBLPTRU,0 | |
2121 _endasm | |
2122 | |
2123 char_O_gtissue_no = 255; | 2124 char_O_gtissue_no = 255; |
2124 pres_gtissue_limit = 0.0; | 2125 pres_gtissue_limit = 0.0; |
2125 | 2126 |
2126 for (ci=0;ci<16;ci++) | 2127 for (ci=0;ci<16;ci++) |
2127 { | 2128 { |
2248 // ---------- | 2249 // ---------- |
2249 // deco_hash // | 2250 // deco_hash // |
2250 // ---------- | 2251 // ---------- |
2251 void deco_hash(void) | 2252 void deco_hash(void) |
2252 { | 2253 { |
2254 RESET_C_STACK | |
2253 // init | 2255 // init |
2254 for (md_i=0;md_i<16;md_i++) | 2256 for (md_i=0;md_i<16;md_i++) |
2255 { | 2257 { |
2256 md_state[md_i] = 0; | 2258 md_state[md_i] = 0; |
2257 md_cksum[md_i] = 0; | 2259 md_cksum[md_i] = 0; |
2344 // --------------------- | 2346 // --------------------- |
2345 // new in v.101 | 2347 // new in v.101 |
2346 | 2348 |
2347 void deco_clear_CNS_fraction(void) | 2349 void deco_clear_CNS_fraction(void) |
2348 { | 2350 { |
2351 RESET_C_STACK | |
2349 CNS_fraction = 0.0; | 2352 CNS_fraction = 0.0; |
2350 char_O_CNS_fraction = 0; | 2353 char_O_CNS_fraction = 0; |
2351 } // void deco_clear_CNS_fraction(void) | 2354 } // void deco_clear_CNS_fraction(void) |
2352 | 2355 |
2353 | 2356 |
2362 // Uses and Updates: CNS_fraction | 2365 // Uses and Updates: CNS_fraction |
2363 // Uses: acutal_ppO2 | 2366 // Uses: acutal_ppO2 |
2364 | 2367 |
2365 void deco_calc_CNS_fraction(void) | 2368 void deco_calc_CNS_fraction(void) |
2366 { | 2369 { |
2370 RESET_C_STACK | |
2367 actual_ppO2 = (float)char_I_actual_ppO2 / 100.0; | 2371 actual_ppO2 = (float)char_I_actual_ppO2 / 100.0; |
2368 | 2372 |
2369 if (char_I_actual_ppO2 < 50) | 2373 if (char_I_actual_ppO2 < 50) |
2370 CNS_fraction = CNS_fraction;// no changes | 2374 CNS_fraction = CNS_fraction;// no changes |
2371 else if (char_I_actual_ppO2 < 60) | 2375 else if (char_I_actual_ppO2 < 60) |
2420 // Output: char_O_CNS_fraction | 2424 // Output: char_O_CNS_fraction |
2421 // Uses and Updates: CNS_fraction | 2425 // Uses and Updates: CNS_fraction |
2422 | 2426 |
2423 void deco_calc_CNS_decrease_15min(void) | 2427 void deco_calc_CNS_decrease_15min(void) |
2424 { | 2428 { |
2429 RESET_C_STACK | |
2425 CNS_fraction = 0.890899 * CNS_fraction; | 2430 CNS_fraction = 0.890899 * CNS_fraction; |
2426 char_O_CNS_fraction = (char)((CNS_fraction + 0.005)* 100.0); | 2431 char_O_CNS_fraction = (char)((CNS_fraction + 0.005)* 100.0); |
2427 }// deco_calc_CNS_decrease_15min(void) | 2432 }// deco_calc_CNS_decrease_15min(void) |
2428 | 2433 |
2429 | 2434 |
2435 // calculates int_I_temp * char_I_temp / 100 | 2440 // calculates int_I_temp * char_I_temp / 100 |
2436 // output is int_I_temp | 2441 // output is int_I_temp |
2437 | 2442 |
2438 void deco_calc_percentage(void) | 2443 void deco_calc_percentage(void) |
2439 { | 2444 { |
2445 RESET_C_STACK | |
2440 temp1 = (float)int_I_temp; | 2446 temp1 = (float)int_I_temp; |
2441 temp2 = (float)char_I_temp / 100.0; | 2447 temp2 = (float)char_I_temp / 100.0; |
2442 temp3 = temp1 * temp2; | 2448 temp3 = temp1 * temp2; |
2443 int_I_temp = (int)temp3; | 2449 int_I_temp = (int)temp3; |
2444 } | 2450 } |
2445 | 2451 |
2446 void deco_push_tissues_to_vault(void) | 2452 void deco_push_tissues_to_vault(void) |
2447 { | 2453 { |
2454 RESET_C_STACK | |
2448 cns_vault = CNS_fraction; | 2455 cns_vault = CNS_fraction; |
2449 for (ci=0;ci<32;ci++) | 2456 for (ci=0;ci<32;ci++) |
2450 pres_tissue_vault[ci] = pres_tissue[ci]; | 2457 pres_tissue_vault[ci] = pres_tissue[ci]; |
2451 } | 2458 } |
2452 void deco_pull_tissues_from_vault(void) | 2459 void deco_pull_tissues_from_vault(void) |
2453 { | 2460 { |
2461 RESET_C_STACK | |
2454 CNS_fraction = cns_vault; | 2462 CNS_fraction = cns_vault; |
2455 for (ci=0;ci<32;ci++) | 2463 for (ci=0;ci<32;ci++) |
2456 pres_tissue[ci] = pres_tissue_vault[ci]; | 2464 pres_tissue[ci] = pres_tissue_vault[ci]; |
2457 } | 2465 } |
2458 | 2466 |