Mercurial > public > mk2
comparison 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 |
comparison
equal
deleted
inserted
replaced
256:d8dfbc7041b0 | 257:f8f869bafd92 |
---|---|
69 // 2011/01/25: [jDG] Fusion deco array for both models. | 69 // 2011/01/25: [jDG] Fusion deco array for both models. |
70 // 2011/01/25: [jDG] Use CF(54) to reverse deco order. | 70 // 2011/01/25: [jDG] Use CF(54) to reverse deco order. |
71 // 2011/02/11: [jDG] Reworked gradient-factor implementation. | 71 // 2011/02/11: [jDG] Reworked gradient-factor implementation. |
72 // 2011/02/13: [jDG] CF55 for additional gas switch delay in decoplan. | 72 // 2011/02/13: [jDG] CF55 for additional gas switch delay in decoplan. |
73 // 2011/02/24: [jDG] Fixed inconsistencies introduced by gas switch delays. | 73 // 2011/02/24: [jDG] Fixed inconsistencies introduced by gas switch delays. |
74 // 2011/04/10: [jDG] Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco() | |
74 // | 75 // |
75 // TODO: | 76 // TODO: |
76 // + Allow to abort MD2 calculation (have to restart next time). | 77 // + Allow to abort MD2 calculation (have to restart next time). |
77 // | 78 // |
78 // Literature: | 79 // Literature: |
466 /////////////////////// U T I L I T I E S ///////////////////////////////// | 467 /////////////////////// U T I L I T I E S ///////////////////////////////// |
467 ////////////////////////////////////////////////////////////////////////////// | 468 ////////////////////////////////////////////////////////////////////////////// |
468 ////////////////////////////////////////////////////////////////////////////// | 469 ////////////////////////////////////////////////////////////////////////////// |
469 | 470 |
470 ////////////////////////////////////////////////////////////////////////////// | 471 ////////////////////////////////////////////////////////////////////////////// |
472 // Bump to blue-screen when an assert is wrong | |
471 #ifdef __DEBUG | 473 #ifdef __DEBUG |
472 void assert_failed(PARAMETER short int line) | 474 void assert_failed(PARAMETER short int line) |
473 { | 475 { |
474 extern void PLED_resetdebugger(void); | 476 extern void PLED_resetdebugger(void); |
475 extern unsigned short temp10; | 477 extern unsigned short temp10; |
476 | 478 |
477 temp10 = line; | 479 temp10 = line; // Show source line number as stack depth. |
478 PLED_resetdebugger(); | 480 PLED_resetdebugger(); |
479 } | 481 } |
480 #endif | 482 #endif |
483 | |
481 ////////////////////////////////////////////////////////////////////////////// | 484 ////////////////////////////////////////////////////////////////////////////// |
482 // When calling C code from ASM context, the data stack pointer and | 485 // When calling C code from ASM context, the data stack pointer and |
483 // frames should be reset. Bank8 is used by stack, when not doing hashing. | 486 // frames should be reset. Bank8 is used by stack, when not doing hashing. |
484 | 487 |
485 #ifdef CROSS_COMPILE | 488 #ifdef CROSS_COMPILE |
508 _endasm | 511 _endasm |
509 # endif | 512 # endif |
510 #endif | 513 #endif |
511 | 514 |
512 ////////////////////////////////////////////////////////////////////////////// | 515 ////////////////////////////////////////////////////////////////////////////// |
516 // Read CF values from the C code. | |
513 | 517 |
514 static short read_custom_function(PARAMETER unsigned char cf) | 518 static short read_custom_function(PARAMETER unsigned char cf) |
515 { | 519 { |
516 #ifdef CROSS_COMPILE | 520 #ifdef CROSS_COMPILE |
517 extern unsigned short custom_functions[]; | 521 extern unsigned short custom_functions[]; |
524 call getcustom15,0 | 528 call getcustom15,0 |
525 movff lo,PRODL | 529 movff lo,PRODL |
526 movff hi,PRODH | 530 movff hi,PRODH |
527 _endasm | 531 _endasm |
528 #endif | 532 #endif |
533 } | |
534 | |
535 ////////////////////////////////////////////////////////////////////////////// | |
536 // Fast subroutine to read RTC timer 3. | |
537 // Note: result is in 1/32 of msecs. | |
538 static unsigned short tmr3(void) | |
539 { | |
540 _asm | |
541 movff 0xfb2,PRODL // TMR3L | |
542 movff 0xfb3,PRODH // TMR3H | |
543 _endasm // result in PRODH:PRODL. | |
529 } | 544 } |
530 | 545 |
531 ////////////////////////////////////////////////////////////////////////////// | 546 ////////////////////////////////////////////////////////////////////////////// |
532 // read buhlmann tables for compatriment ci | 547 // read buhlmann tables for compatriment ci |
533 // If period == 0 : 2sec interval | 548 // If period == 0 : 2sec interval |
566 | 581 |
567 // Integration intervals. | 582 // Integration intervals. |
568 switch(period) | 583 switch(period) |
569 { | 584 { |
570 case -1://---- no interval ----------------------------------------------- | 585 case -1://---- no interval ----------------------------------------------- |
571 var_N2_e = var_He_e = 0.0; | 586 var_N2_e = 0.0; |
587 var_He_e = 0.0; | |
572 break; | 588 break; |
573 | 589 |
574 case 0: //---- 2 sec ----------------------------------------------------- | 590 case 0: //---- 2 sec ----------------------------------------------------- |
575 var_N2_e = e2secs[ci]; | 591 var_N2_e = e2secs[ci]; |
576 var_He_e = (e2secs+16)[ci]; | 592 var_He_e = (e2secs+16)[ci]; |
1357 ////////////////////////////////////////////////////////////////////////////// | 1373 ////////////////////////////////////////////////////////////////////////////// |
1358 // Compute stops. | 1374 // Compute stops. |
1359 // | 1375 // |
1360 // Note: because this can be very long, break on 16 iterations, and set state | 1376 // Note: because this can be very long, break on 16 iterations, and set state |
1361 // to 0 when finished, or to 1 when needing to continue. | 1377 // to 0 when finished, or to 1 when needing to continue. |
1378 // Note: because this might be very long (~ 66 ms by iteration in 1.84beta), | |
1379 // break the loop when total time > 512msec. | |
1362 // | 1380 // |
1363 void calc_hauptroutine_calc_deco(void) | 1381 void calc_hauptroutine_calc_deco(void) |
1364 { | 1382 { |
1365 overlay unsigned char loop; | 1383 overlay unsigned char loop; |
1366 | 1384 |
1367 for(loop = 0; loop < 16; ++loop) | 1385 for(loop = 0; loop < 16; ++loop) |
1368 { | 1386 { |
1387 // Limit loops to 512ms, using the RTC timer 3: | |
1388 if( tmr3() & (512*32) ) | |
1389 break; | |
1390 | |
1369 // Do not ascent while doing a gas switch ? | 1391 // Do not ascent while doing a gas switch ? |
1370 if( sim_gas_delay <= sim_dive_mins ) | 1392 if( sim_gas_delay <= sim_dive_mins ) |
1371 { | 1393 { |
1372 if( calc_nextdecodepth() ) | 1394 if( calc_nextdecodepth() ) |
1373 { | 1395 { |
1709 / (GF_current + var_N2_b * (1.0 - GF_current)); | 1731 / (GF_current + var_N2_b * (1.0 - GF_current)); |
1710 else | 1732 else |
1711 p = (p - var_N2_a) * var_N2_b; | 1733 p = (p - var_N2_a) * var_N2_b; |
1712 if( p < 0.0 ) p = 0.0; | 1734 if( p < 0.0 ) p = 0.0; |
1713 | 1735 |
1714 assert( 0.0 <= p && p <= 14.0 ); | 1736 assert( p <= 14.0 ); |
1715 | 1737 |
1716 sim_pres_tissue_limit[ci] = p; | 1738 sim_pres_tissue_limit[ci] = p; |
1717 if( p > sim_lead_tissue_limit ) | 1739 if( p > sim_lead_tissue_limit ) |
1718 { | 1740 { |
1719 sim_lead_tissue_no = ci; | 1741 sim_lead_tissue_no = ci; |