Mercurial > public > mk2
comparison 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 |
comparison
equal
deleted
inserted
replaced
257:f8f869bafd92 | 258:abbf9a2c2c48 |
---|---|
107 | 107 |
108 static void calc_hauptroutine(void); | 108 static void calc_hauptroutine(void); |
109 static void calc_nullzeit(void); | 109 static void calc_nullzeit(void); |
110 | 110 |
111 static void calc_tissue(PARAMETER unsigned char period); | 111 static void calc_tissue(PARAMETER unsigned char period); |
112 static void calc_limit(PARAMETER float GF_current); | 112 static void calc_limit(void); |
113 | 113 |
114 static void clear_tissue(void); | 114 static void clear_tissue(void); |
115 static void calc_ascenttime(void); | 115 static void calc_ascenttime(void); |
116 static void update_startvalues(void); | 116 static void update_startvalues(void); |
117 static void clear_deco_table(void); | 117 static void clear_deco_table(void); |
199 | 199 |
200 //---- Bank 6 parameters ----------------------------------------------------- | 200 //---- Bank 6 parameters ----------------------------------------------------- |
201 #pragma udata bank6=0x600 | 201 #pragma udata bank6=0x600 |
202 | 202 |
203 float pres_tissue[32]; | 203 float pres_tissue[32]; |
204 float pres_tissue_limit[16]; | |
205 float sim_pres_tissue_limit[16]; | |
206 | 204 |
207 //---- Bank 7 parameters ----------------------------------------------------- | 205 //---- Bank 7 parameters ----------------------------------------------------- |
208 #pragma udata bank7=0x700 | 206 #pragma udata bank7=0x700 |
209 | 207 |
210 float sim_pres_tissue[32]; // 32 floats = 128 bytes. | 208 float sim_pres_tissue[32]; // 32 floats = 128 bytes. |
542 movff 0xfb3,PRODH // TMR3H | 540 movff 0xfb3,PRODH // TMR3H |
543 _endasm // result in PRODH:PRODL. | 541 _endasm // result in PRODH:PRODL. |
544 } | 542 } |
545 | 543 |
546 ////////////////////////////////////////////////////////////////////////////// | 544 ////////////////////////////////////////////////////////////////////////////// |
545 // read buhlmann tables A and B for compatriment ci | |
546 // | |
547 static void read_buhlmann_coefficients(void) | |
548 { | |
549 #ifndef CROSS_COMPILE | |
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 | |
558 #endif | |
559 | |
560 assert( 0 <= ci && ci < 16 ); | |
561 var_N2_a = buhlmann_a[ci]; | |
562 var_N2_b = buhlmann_b[ci]; | |
563 var_He_a = (buhlmann_a+16)[ci]; | |
564 var_He_b = (buhlmann_b+16)[ci]; | |
565 | |
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 ) | |
576 int_O_DBG_pre_bitfield |= DBG_ZH16ERR; | |
577 } | |
578 | |
579 ////////////////////////////////////////////////////////////////////////////// | |
547 // read buhlmann tables for compatriment ci | 580 // read buhlmann tables for compatriment ci |
548 // If period == 0 : 2sec interval | 581 // If period == 0 : 2sec interval |
549 // 1 : 1 min interval | 582 // 1 : 1 min interval |
550 // 2 : 10 min interval. | 583 // 2 : 10 min interval. |
551 static void read_buhlmann_coefficients(PARAMETER char period) | 584 static void read_buhlmann_times(PARAMETER char period) |
552 { | 585 { |
553 #ifndef CROSS_COMPILE | 586 #ifndef CROSS_COMPILE |
554 // Note: we don't use far rom pointer, because the | 587 // Note: we don't use far rom pointer, because the |
555 // 24 bits is to complex, hence we have to set | 588 // 24 bits is to complex, hence we have to set |
556 // the UPPER page ourself... | 589 // the UPPER page ourself... |
560 movwf TBLPTRU,0 | 593 movwf TBLPTRU,0 |
561 _endasm | 594 _endasm |
562 #endif | 595 #endif |
563 assert( 0 <= ci && ci < 16 ); | 596 assert( 0 <= ci && ci < 16 ); |
564 | 597 |
565 var_N2_a = buhlmann_a[ci]; | |
566 var_N2_b = buhlmann_b[ci]; | |
567 var_He_a = (buhlmann_a+16)[ci]; | |
568 var_He_b = (buhlmann_b+16)[ci]; | |
569 | |
570 // Check reading consistency: | |
571 if( (var_N2_a < 0.231) | |
572 || (var_N2_a > 1.27) | |
573 || (var_N2_b < 0.504) | |
574 || (var_N2_b > 0.966) | |
575 || (var_He_a < 0.510) | |
576 || (var_He_a > 1.75) | |
577 || (var_He_b < 0.423) | |
578 || (var_He_b > 0.927) | |
579 ) | |
580 int_O_DBG_pre_bitfield |= DBG_ZH16ERR; | |
581 | |
582 // Integration intervals. | 598 // Integration intervals. |
583 switch(period) | 599 switch(period) |
584 { | 600 { |
585 case -1://---- no interval ----------------------------------------------- | |
586 var_N2_e = 0.0; | |
587 var_He_e = 0.0; | |
588 break; | |
589 | |
590 case 0: //---- 2 sec ----------------------------------------------------- | 601 case 0: //---- 2 sec ----------------------------------------------------- |
591 var_N2_e = e2secs[ci]; | 602 var_N2_e = e2secs[ci]; |
592 var_He_e = (e2secs+16)[ci]; | 603 var_He_e = (e2secs+16)[ci]; |
593 | 604 |
594 // Check reading consistency: | 605 // Check reading consistency: |
1129 { | 1140 { |
1130 // cycle through the 16 Bühlmann tissues | 1141 // cycle through the 16 Bühlmann tissues |
1131 overlay float p = N2_ratio * (pres_respiration - ppWVapour); | 1142 overlay float p = N2_ratio * (pres_respiration - ppWVapour); |
1132 pres_tissue[ci] = p; | 1143 pres_tissue[ci] = p; |
1133 | 1144 |
1134 read_buhlmann_coefficients(-1); | |
1135 | |
1136 p = (p - var_N2_a) * var_N2_b ; | |
1137 if( p < 0.0 ) | |
1138 p = 0.0; | |
1139 pres_tissue_limit[ci] = p; | |
1140 | |
1141 // cycle through the 16 Bühlmann tissues for Helium | 1145 // cycle through the 16 Bühlmann tissues for Helium |
1142 (pres_tissue+16)[ci] = 0.0; | 1146 (pres_tissue+16)[ci] = 0.0; |
1143 } // for 0 to 16 | 1147 } // for 0 to 16 |
1144 | 1148 |
1145 clear_deco_table(); | 1149 clear_deco_table(); |
1147 char_O_nullzeit = 0; | 1151 char_O_nullzeit = 0; |
1148 int_O_ascenttime = 0; | 1152 int_O_ascenttime = 0; |
1149 char_O_gradient_factor = 0; | 1153 char_O_gradient_factor = 0; |
1150 char_O_relative_gradient_GF = 0; | 1154 char_O_relative_gradient_GF = 0; |
1151 char_I_depth_last_deco = 0; // for compatibility with v.101pre_no_last_deco | 1155 char_I_depth_last_deco = 0; // for compatibility with v.101pre_no_last_deco |
1156 | |
1157 calc_lead_tissue_limit = 0.0; | |
1158 char_O_gtissue_no = 0; | |
1152 } | 1159 } |
1153 | 1160 |
1154 ////////////////////////////////////////////////////////////////////////////// | 1161 ////////////////////////////////////////////////////////////////////////////// |
1155 // calc_hauptroutine | 1162 // calc_hauptroutine |
1156 // | 1163 // |
1354 calc_tissue(0); | 1361 calc_tissue(0); |
1355 else | 1362 else |
1356 calc_tissue(1); | 1363 calc_tissue(1); |
1357 | 1364 |
1358 // Calc limit for surface, ie. GF_high. | 1365 // Calc limit for surface, ie. GF_high. |
1359 calc_limit(GF_high); | 1366 calc_limit(); |
1360 | 1367 |
1361 int_O_gtissue_limit = (short)(calc_lead_tissue_limit * 1000); | 1368 int_O_gtissue_limit = (short)(calc_lead_tissue_limit * 1000); |
1362 int_O_gtissue_press = (short)((pres_tissue[char_O_gtissue_no] + (pres_tissue+16)[char_O_gtissue_no]) * 1000); | 1369 int_O_gtissue_press = (short)((pres_tissue[char_O_gtissue_no] + (pres_tissue+16)[char_O_gtissue_no]) * 1000); |
1363 | 1370 |
1364 // if guiding tissue can not be exposed to surface pressure immediately | 1371 // if guiding tissue can not be exposed to surface pressure immediately |
1498 assert( 0.00 <= ppN2 && ppN2 < 11.2 ); // 80% N2 at 130m | 1505 assert( 0.00 <= ppN2 && ppN2 < 11.2 ); // 80% N2 at 130m |
1499 assert( 0.00 <= ppHe && ppHe < 12.6 ); // 90% He at 130m | 1506 assert( 0.00 <= ppHe && ppHe < 12.6 ); // 90% He at 130m |
1500 | 1507 |
1501 for (ci=0;ci<16;ci++) | 1508 for (ci=0;ci<16;ci++) |
1502 { | 1509 { |
1503 read_buhlmann_coefficients(period); // 2 sec or 1 min period. | 1510 read_buhlmann_times(period); // 2 sec or 1 min period. |
1504 | 1511 |
1505 // N2 | 1512 // N2 |
1506 temp_tissue = (ppN2 - pres_tissue[ci]) * var_N2_e; | 1513 temp_tissue = (ppN2 - pres_tissue[ci]) * var_N2_e; |
1507 temp_tissue_safety(); | 1514 temp_tissue_safety(); |
1508 pres_tissue[ci] += temp_tissue; | 1515 pres_tissue[ci] += temp_tissue; |
1517 ////////////////////////////////////////////////////////////////////////////// | 1524 ////////////////////////////////////////////////////////////////////////////// |
1518 // calc_limit | 1525 // calc_limit |
1519 // | 1526 // |
1520 // New in v.111 : separated from calc_tissue(), and depends on GF value. | 1527 // New in v.111 : separated from calc_tissue(), and depends on GF value. |
1521 // | 1528 // |
1522 static void calc_limit(PARAMETER float GF_current) | 1529 static void calc_limit(void) |
1523 { | 1530 { |
1524 char_O_gtissue_no = 255; | 1531 char_O_gtissue_no = 255; |
1525 calc_lead_tissue_limit = 0.0; | 1532 calc_lead_tissue_limit = 0.0; |
1526 | 1533 |
1527 for (ci=0;ci<16;ci++) | 1534 for (ci=0;ci<16;ci++) |
1528 { | 1535 { |
1529 overlay float p = pres_tissue[ci] + (pres_tissue+16)[ci]; | 1536 overlay float p = pres_tissue[ci] + (pres_tissue+16)[ci]; |
1530 | 1537 |
1531 read_buhlmann_coefficients(-1); // 2 sec or 1 min period. | 1538 read_buhlmann_coefficients(); |
1532 var_N2_a = (var_N2_a * pres_tissue[ci] + var_He_a * (pres_tissue+16)[ci]) / p; | 1539 var_N2_a = (var_N2_a * pres_tissue[ci] + var_He_a * (pres_tissue+16)[ci]) / p; |
1533 var_N2_b = (var_N2_b * pres_tissue[ci] + var_He_b * (pres_tissue+16)[ci]) / p; | 1540 var_N2_b = (var_N2_b * pres_tissue[ci] + var_He_b * (pres_tissue+16)[ci]) / p; |
1534 | 1541 |
1535 // Apply the Eric Baker's varying gradient factor correction. | 1542 // Apply the Eric Baker's varying gradient factor correction. |
1536 // Note: the correction factor depends both on GF and b, | 1543 // Note: the correction factor depends both on GF and b, |
1540 // GF_low, current GF, or GF_high... | 1547 // GF_low, current GF, or GF_high... |
1541 // *BUT* calc_tissue() is used to compute bottom time, | 1548 // *BUT* calc_tissue() is used to compute bottom time, |
1542 // hence what would happend at surface, | 1549 // hence what would happend at surface, |
1543 // hence at GF_high. | 1550 // hence at GF_high. |
1544 if( char_I_deco_model == 1 ) | 1551 if( char_I_deco_model == 1 ) |
1545 p = ( p - var_N2_a * GF_current) * var_N2_b | 1552 p = ( p - var_N2_a * GF_high) * var_N2_b |
1546 / (GF_current + var_N2_b * (1.0 - GF_current)); | 1553 / (GF_high + var_N2_b * (1.0 - GF_high)); |
1547 else | 1554 else |
1548 p = (p - var_N2_a) * var_N2_b; | 1555 p = (p - var_N2_a) * var_N2_b; |
1549 if( p < 0 ) p = 0; | 1556 if( p < 0.0 ) p = 0.0; |
1550 | 1557 |
1551 pres_tissue_limit[ci] = p; | |
1552 if( p > calc_lead_tissue_limit ) | 1558 if( p > calc_lead_tissue_limit ) |
1553 { | 1559 { |
1554 char_O_gtissue_no = ci; | 1560 char_O_gtissue_no = ci; |
1555 calc_lead_tissue_limit = p; | 1561 calc_lead_tissue_limit = p; |
1556 } | 1562 } |
1680 assert( 0.00 <= ppN2 && ppN2 < 11.2 ); // 80% N2 at 130m | 1686 assert( 0.00 <= ppN2 && ppN2 < 11.2 ); // 80% N2 at 130m |
1681 assert( 0.00 <= ppHe && ppHe < 12.6 ); // 90% He at 130m | 1687 assert( 0.00 <= ppHe && ppHe < 12.6 ); // 90% He at 130m |
1682 | 1688 |
1683 for(ci=0; ci<16; ci++) | 1689 for(ci=0; ci<16; ci++) |
1684 { | 1690 { |
1685 read_buhlmann_coefficients(period); // 1 or 10 minute(s) interval | 1691 read_buhlmann_times(period); // 1 or 10 minute(s) interval |
1686 | 1692 |
1687 // N2 | 1693 // N2 |
1688 temp_tissue = (ppN2 - sim_pres_tissue[ci]) * var_N2_e; | 1694 temp_tissue = (ppN2 - sim_pres_tissue[ci]) * var_N2_e; |
1689 temp_tissue_safety(); | 1695 temp_tissue_safety(); |
1690 sim_pres_tissue[ci] += temp_tissue; | 1696 sim_pres_tissue[ci] += temp_tissue; |
1715 { | 1721 { |
1716 overlay float N2 = sim_pres_tissue[ci]; | 1722 overlay float N2 = sim_pres_tissue[ci]; |
1717 overlay float He = (sim_pres_tissue+16)[ci]; | 1723 overlay float He = (sim_pres_tissue+16)[ci]; |
1718 overlay float p = N2 + He; | 1724 overlay float p = N2 + He; |
1719 | 1725 |
1720 read_buhlmann_coefficients(-1); | 1726 read_buhlmann_coefficients(); |
1721 var_N2_a = (var_N2_a * N2 + var_He_a * He) / p; | 1727 var_N2_a = (var_N2_a * N2 + var_He_a * He) / p; |
1722 var_N2_b = (var_N2_b * N2 + var_He_b * He) / p; | 1728 var_N2_b = (var_N2_b * N2 + var_He_b * He) / p; |
1723 | 1729 |
1724 // Apply the Eric Baker's varying gradient factor correction. | 1730 // Apply the Eric Baker's varying gradient factor correction. |
1725 // Note: the correction factor depends both on GF and b, | 1731 // Note: the correction factor depends both on GF and b, |
1731 / (GF_current + var_N2_b * (1.0 - GF_current)); | 1737 / (GF_current + var_N2_b * (1.0 - GF_current)); |
1732 else | 1738 else |
1733 p = (p - var_N2_a) * var_N2_b; | 1739 p = (p - var_N2_a) * var_N2_b; |
1734 if( p < 0.0 ) p = 0.0; | 1740 if( p < 0.0 ) p = 0.0; |
1735 | 1741 |
1736 assert( p <= 14.0 ); | |
1737 | |
1738 sim_pres_tissue_limit[ci] = p; | |
1739 if( p > sim_lead_tissue_limit ) | 1742 if( p > sim_lead_tissue_limit ) |
1740 { | 1743 { |
1741 sim_lead_tissue_no = ci; | 1744 sim_lead_tissue_no = ci; |
1742 sim_lead_tissue_limit = p; | 1745 sim_lead_tissue_limit = p; |
1743 } | 1746 } |
1830 if( temp_tissue < pres_respiration ) | 1833 if( temp_tissue < pres_respiration ) |
1831 gf = 0.0; | 1834 gf = 0.0; |
1832 else | 1835 else |
1833 { | 1836 { |
1834 gf = (temp_tissue - pres_respiration) | 1837 gf = (temp_tissue - pres_respiration) |
1835 / (temp_tissue - pres_tissue_limit[char_O_gtissue_no]) | 1838 / (temp_tissue - calc_lead_tissue_limit) |
1836 * 100.0; | 1839 * 100.0; |
1837 if( gf > 255.0 ) gf = 255.0; | 1840 if( gf > 255.0 ) gf = 255.0; |
1838 if( gf < 0.0 ) gf = 0.0; | 1841 if( gf < 0.0 ) gf = 0.0; |
1839 } | 1842 } |
1840 char_O_gradient_factor = (unsigned char)gf; | 1843 char_O_gradient_factor = (unsigned char)gf; |