Mercurial > public > mk2
diff code_part1/OSTC_code_c_part2/p2_deco.c @ 257:f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
author | JeanDo |
---|---|
date | Sun, 10 Apr 2011 13:12:38 +0200 |
parents | 8b252ff2eded |
children | abbf9a2c2c48 |
line wrap: on
line diff
--- a/code_part1/OSTC_code_c_part2/p2_deco.c Sun Apr 10 09:54:44 2011 +0200 +++ b/code_part1/OSTC_code_c_part2/p2_deco.c Sun Apr 10 13:12:38 2011 +0200 @@ -71,6 +71,7 @@ // 2011/02/11: [jDG] Reworked gradient-factor implementation. // 2011/02/13: [jDG] CF55 for additional gas switch delay in decoplan. // 2011/02/24: [jDG] Fixed inconsistencies introduced by gas switch delays. +// 2011/04/10: [jDG] Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco() // // TODO: // + Allow to abort MD2 calculation (have to restart next time). @@ -468,16 +469,18 @@ ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// +// Bump to blue-screen when an assert is wrong #ifdef __DEBUG void assert_failed(PARAMETER short int line) { extern void PLED_resetdebugger(void); extern unsigned short temp10; - temp10 = line; + temp10 = line; // Show source line number as stack depth. PLED_resetdebugger(); } #endif + ////////////////////////////////////////////////////////////////////////////// // When calling C code from ASM context, the data stack pointer and // frames should be reset. Bank8 is used by stack, when not doing hashing. @@ -510,6 +513,7 @@ #endif ////////////////////////////////////////////////////////////////////////////// +// Read CF values from the C code. static short read_custom_function(PARAMETER unsigned char cf) { @@ -529,6 +533,17 @@ } ////////////////////////////////////////////////////////////////////////////// +// Fast subroutine to read RTC timer 3. +// Note: result is in 1/32 of msecs. +static unsigned short tmr3(void) +{ + _asm + movff 0xfb2,PRODL // TMR3L + movff 0xfb3,PRODH // TMR3H + _endasm // result in PRODH:PRODL. +} + +////////////////////////////////////////////////////////////////////////////// // read buhlmann tables for compatriment ci // If period == 0 : 2sec interval // 1 : 1 min interval @@ -568,7 +583,8 @@ switch(period) { case -1://---- no interval ----------------------------------------------- - var_N2_e = var_He_e = 0.0; + var_N2_e = 0.0; + var_He_e = 0.0; break; case 0: //---- 2 sec ----------------------------------------------------- @@ -1359,6 +1375,8 @@ // // Note: because this can be very long, break on 16 iterations, and set state // to 0 when finished, or to 1 when needing to continue. +// Note: because this might be very long (~ 66 ms by iteration in 1.84beta), +// break the loop when total time > 512msec. // void calc_hauptroutine_calc_deco(void) { @@ -1366,6 +1384,10 @@ for(loop = 0; loop < 16; ++loop) { + // Limit loops to 512ms, using the RTC timer 3: + if( tmr3() & (512*32) ) + break; + // Do not ascent while doing a gas switch ? if( sim_gas_delay <= sim_dive_mins ) { @@ -1711,7 +1733,7 @@ p = (p - var_N2_a) * var_N2_b; if( p < 0.0 ) p = 0.0; - assert( 0.0 <= p && p <= 14.0 ); + assert( p <= 14.0 ); sim_pres_tissue_limit[ci] = p; if( p > sim_lead_tissue_limit )