comparison code_part1/OSTC_code_asm_part1/divemode.asm @ 341:2144f19fa1eb

BUGFIX protect against ISR changing pressure/temperature while reading it.
author JeanDo
date Fri, 20 May 2011 00:48:30 +0200
parents b7940978edc9
children 06299199dfb9
comparison
equal deleted inserted replaced
340:ecbbbd423e86 341:2144f19fa1eb
408 return 408 return
409 409
410 ;----------------------------------------------------------------------------- 410 ;-----------------------------------------------------------------------------
411 ; calculate ppO2 in 0.01Bar (e.g. 150 = 1.50 Bar ppO2) 411 ; calculate ppO2 in 0.01Bar (e.g. 150 = 1.50 Bar ppO2)
412 set_actual_ppo2: 412 set_actual_ppo2:
413 movff amb_pressure+0,xA+0 ; P_amb in milibar (1000 = 1.000 bar). 413 SAFE_2BYTE_COPY amb_pressure, xA ; P_amb in milibar (1000 = 1.000 bar).
414 movff amb_pressure+1,xA+1
415 movlw d'10' 414 movlw d'10'
416 movwf xB+0 415 movwf xB+0
417 clrf xB+1 416 clrf xB+1
418 call div16x16 ; xC=p_amb/10 (100 = 1.00 bar). 417 call div16x16 ; xC=p_amb/10 (100 = 1.00 bar).
419 movff xC+0,xA+0 418 movff xC+0,xA+0
548 bra calc_deko_divemode5 547 bra calc_deko_divemode5
549 548
550 ;----------------------------------------------------------------------------- 549 ;-----------------------------------------------------------------------------
551 550
552 divemode_prepare_flags_for_deco: 551 divemode_prepare_flags_for_deco:
553 movff amb_pressure+0,int_I_pres_respiration+0 ; lo and copy result to deco routine 552 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; copy result to deco routine
554 movff amb_pressure+1,int_I_pres_respiration+1 ; hi 553
555 GETCUSTOM8 d'11' ; Saturation multiplier % 554 GETCUSTOM8 d'11' ; Saturation multiplier %
556 movff WREG,char_I_saturation_multiplier 555 movff WREG,char_I_saturation_multiplier
557 GETCUSTOM8 d'12' ; Desaturation multiplier % 556 GETCUSTOM8 d'12' ; Desaturation multiplier %
558 movff WREG,char_I_desaturation_multiplier 557 movff WREG,char_I_desaturation_multiplier
559 GETCUSTOM8 d'16' ; Deco distance to decostop in 1/10 meter for simulation 558 GETCUSTOM8 d'16' ; Deco distance to decostop in 1/10 meter for simulation
585 ; shift address for header 584 ; shift address for header
586 ; the header will be stored after the dive 585 ; the header will be stored after the dive
587 incf_eeprom_address d'47' ; Macro, that adds 8Bit to eeprom_address:2 with banking at 0x8000 586 incf_eeprom_address d'47' ; Macro, that adds 8Bit to eeprom_address:2 with banking at 0x8000
588 587
589 store_dive_data2: 588 store_dive_data2:
590 movf rel_pressure+0,W ; store depth with every sample 589 SAFE_2BYTE_COPY rel_pressure, lo
591 call write_external_eeprom 590 movf lo,W ; store depth with every sample
592 movf rel_pressure+1,W 591 call write_external_eeprom
592 movf hi,W
593 call write_external_eeprom 593 call write_external_eeprom
594 594
595 ;First, find out how many bytes will append to this sample.... 595 ;First, find out how many bytes will append to this sample....
596 clrf ProfileFlagByte ; clear number of bytes to append 596 clrf ProfileFlagByte ; clear number of bytes to append
597 597
802 GETCUSTOM8 d'22' 802 GETCUSTOM8 d'22'
803 movwf divisor_deco ; Reload divisor from CF 803 movwf divisor_deco ; Reload divisor from CF
804 return 804 return
805 805
806 store_dive_temperature: 806 store_dive_temperature:
807 movf temperature+0,W ; append temperature to current sample! 807 SAFE_2BYTE_COPY temperature,lo
808 call write_external_eeprom 808 movf lo,W ; append temperature to current sample!
809 movf temperature+1,W 809 call write_external_eeprom
810 movf hi,W
810 call write_external_eeprom 811 call write_external_eeprom
811 GETCUSTOM8 d'21' 812 GETCUSTOM8 d'21'
812 movwf divisor_temperature ; Reload divisor from CF 813 movwf divisor_temperature ; Reload divisor from CF
813 return 814 return
814 815
815 calc_velocity: ; called every two seconds 816 calc_velocity: ; called every two seconds
816 btfss divemode 817 btfss divemode
817 bra do_not_display_velocity ; display velocity only in divemode 818 bra do_not_display_velocity ; display velocity only in divemode
818 819
819 calc_velocity2: 820 calc_velocity2:
820 movff amb_pressure+0,sub_a+0 821 SAFE_2BYTE_COPY amb_pressure, sub_a
821 movff amb_pressure+1,sub_a+1
822 movff last_pressure+0,sub_b+0 822 movff last_pressure+0,sub_b+0
823 movff last_pressure+1,sub_b+1 823 movff last_pressure+1,sub_b+1
824 movff amb_pressure+0,last_pressure+0 ; store old value for velocity 824 movff sub_a+0,last_pressure+0 ; store old value for velocity
825 movff amb_pressure+1,last_pressure+1 825 movff sub_a+1,last_pressure+1
826 826
827 call sub16 ; sub_c = amb_pressure - last_pressure 827 call sub16 ; sub_c = amb_pressure - last_pressure
828 828
829 movff sub_c+0,xA+0 829 movff sub_c+0,xA+0
830 movff sub_c+1,xA+1 830 movff sub_c+1,xA+1
867 check_ppO2: ; check current ppO2 and display warning if required 867 check_ppO2: ; check current ppO2 and display warning if required
868 btfsc FLAG_const_ppO2_mode ; ignore in ppO2 mode.... 868 btfsc FLAG_const_ppO2_mode ; ignore in ppO2 mode....
869 return 869 return
870 870
871 check_ppO2_bail: ; In CC mode but bailout active! 871 check_ppO2_bail: ; In CC mode but bailout active!
872 movff amb_pressure+0,xA+0 872 SAFE_2BYTE_COPY amb_pressure, xA
873 movff amb_pressure+1,xA+1
874 movlw d'10' 873 movlw d'10'
875 movwf xB+0 874 movwf xB+0
876 clrf xB+1 875 clrf xB+1
877 call div16x16 ; xC=p_amb/10 876 call div16x16 ; xC=p_amb/10
878 movff xC+0,xA+0 877 movff xC+0,xA+0
956 ; 955 ;
957 ; Output: better_gas_available 956 ; Output: better_gas_available
958 ; 957 ;
959 check_gas_change: ; Checks if a better gas should be selected (by user) 958 check_gas_change: ; Checks if a better gas should be selected (by user)
960 bcf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode 959 bcf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode
961 960
962 movff rel_pressure+0,xA+0 961 SAFE_2BYTE_COPY rel_pressure,xA
963 movff rel_pressure+1,xA+1
964 movlw d'100' 962 movlw d'100'
965 movwf xB+0 963 movwf xB+0
966 clrf xB+1 964 clrf xB+1
967 call div16x16 ; compute depth in full m -> result in xC+0 965 call div16x16 ; compute depth in full m -> result in xC+0
968 966
1437 1435
1438 btfsc divemode 1436 btfsc divemode
1439 call set_min_temp ; store min. temp if required 1437 call set_min_temp ; store min. temp if required
1440 1438
1441 bcf temp_changed ; Display temperature? 1439 bcf temp_changed ; Display temperature?
1442 movf temperature+0,W 1440 SAFE_2BYTE_COPY temperature,lo
1441 movf lo,W
1443 cpfseq last_temperature+0 1442 cpfseq last_temperature+0
1444 bsf temp_changed ; Yes 1443 bsf temp_changed ; Yes
1445 movf temperature+1,W 1444 movf hi,W
1446 cpfseq last_temperature+1 1445 cpfseq last_temperature+1
1447 bsf temp_changed ; Yes 1446 bsf temp_changed ; Yes
1448 btfsc temp_changed 1447 btfsc temp_changed
1449 call PLED_temp_divemode ; Displays temperature 1448 call PLED_temp_divemode ; Displays temperature
1450 1449
1451 bcf pres_changed ; Display new depth? 1450 bcf pres_changed ; Display new depth?
1452 movf amb_pressure+0,W 1451 SAFE_2BYTE_COPY amb_pressure, lo
1452 movf lo,W
1453 cpfseq last_pressure+0 1453 cpfseq last_pressure+0
1454 bsf pres_changed ; Yes 1454 bsf pres_changed ; Yes
1455 movf amb_pressure+1,W 1455 movf hi,W
1456 cpfseq last_pressure+1 1456 cpfseq last_pressure+1
1457 bsf pres_changed ; Yes 1457 bsf pres_changed ; Yes
1458 1458
1459 btfsc simulatormode_active ; always update depth when in simulator mode 1459 btfsc simulatormode_active ; always update depth when in simulator mode
1460 bsf pres_changed 1460 bsf pres_changed
1473 return 1473 return
1474 1474
1475 set_max_depth: 1475 set_max_depth:
1476 movff max_pressure+0,sub_a+0 1476 movff max_pressure+0,sub_a+0
1477 movff max_pressure+1,sub_a+1 1477 movff max_pressure+1,sub_a+1
1478 movff rel_pressure+0,sub_b+0 1478 SAFE_2BYTE_COPY rel_pressure, sub_b
1479 movff rel_pressure+1,sub_b+1 1479 call sub16 ; sub_c = sub_a - sub_b
1480 call sub16 ; sub_c = sub_a - sub_b
1481 ; max_pressure<rel_pressure -> neg_flag=1 1480 ; max_pressure<rel_pressure -> neg_flag=1
1482 ; rel_pressure<=max_pressure -> neg_flag=0 1481 ; rel_pressure<=max_pressure -> neg_flag=0
1483 btfss neg_flag 1482 btfss neg_flag
1484 return 1483 return
1485 ;max_pressure<rel_pressure 1484 ;max_pressure<rel_pressure
1486 movff rel_pressure+0,max_pressure+0 1485 movff sub_b+0,max_pressure+0
1487 movff rel_pressure+1,max_pressure+1 1486 movff sub_b+1,max_pressure+1
1488 call PLED_max_pressure ; No, use normal max. depth 1487 call PLED_max_pressure ; No, use normal max. depth
1489 return 1488 return
1490 1489
1491 set_min_temp: 1490 set_min_temp:
1492 movff mintemp+0,sub_a+0 1491 movff mintemp+0,sub_a+0
1493 movff mintemp+1,sub_a+1 1492 movff mintemp+1,sub_a+1
1494 movff temperature+0,sub_b+0 1493 SAFE_2BYTE_COPY temperature,sub_b
1495 movff temperature+1,sub_b+1 1494 call sub16 ; sub_c = sub_a - sub_b
1496 call sub16 ; sub_c = sub_a - sub_b
1497 ; mintemp<T -> neg_flag=1 1495 ; mintemp<T -> neg_flag=1
1498 ; T<=mintemp -> neg_flag=0 1496 ; T<=mintemp -> neg_flag=0
1499 btfsc neg_flag 1497 btfsc neg_flag
1500 return 1498 return
1501 ;mintemp>=T 1499 ;mintemp>=T
1502 movff temperature+0,mintemp+0 1500 movff sub_b+0,mintemp+0
1503 movff temperature+1,mintemp+1 1501 movff sub_b+1,mintemp+1
1504 return 1502 return
1505 1503
1506 set_dive_modes: 1504 set_dive_modes:
1507 btfsc high_altitude_mode ; In high altitude (Fly) mode? 1505 btfsc high_altitude_mode ; In high altitude (Fly) mode?
1508 bra set_dive_modes3 ; Yes 1506 bra set_dive_modes3 ; Yes
1510 bcf divemode2 ; Stop time 1508 bcf divemode2 ; Stop time
1511 1509
1512 GETCUSTOM8 .0 ; loads dive_threshold in WREG 1510 GETCUSTOM8 .0 ; loads dive_threshold in WREG
1513 movwf sub_a+0 ; dive_treshold is in cm 1511 movwf sub_a+0 ; dive_treshold is in cm
1514 clrf sub_a+1 1512 clrf sub_a+1
1515 movff rel_pressure+0,sub_b+0 1513 SAFE_2BYTE_COPY rel_pressure, sub_b
1516 movff rel_pressure+1,sub_b+1
1517 call sub16 ; sub_c = sub_a - sub_b 1514 call sub16 ; sub_c = sub_a - sub_b
1518 1515
1519 btfss neg_flag 1516 btfss neg_flag
1520 bra set_dive_modes2 ; too shallow (rel_pressure<dive_threshold) 1517 bra set_dive_modes2 ; too shallow (rel_pressure<dive_threshold)
1521 1518
1534 set_dive_modes3: 1531 set_dive_modes3:
1535 movlw HIGH d'1075' ; hard-wired 1075mBar threshold 1532 movlw HIGH d'1075' ; hard-wired 1075mBar threshold
1536 movwf sub_a+1 1533 movwf sub_a+1
1537 movlw LOW d'1075' ; hard-wired 1075mBar threshold 1534 movlw LOW d'1075' ; hard-wired 1075mBar threshold
1538 movwf sub_a+0 1535 movwf sub_a+0
1539 movff rel_pressure+0,sub_b+0 1536 SAFE_2BYTE_COPY rel_pressure, sub_b
1540 movff rel_pressure+1,sub_b+1
1541 call sub16 ; sub_c = sub_a - sub_b 1537 call sub16 ; sub_c = sub_a - sub_b
1542 1538
1543 btfss neg_flag 1539 btfss neg_flag
1544 bra set_dive_modes2 ; too shallow (rel_pressure<dive_threshold) 1540 bra set_dive_modes2 ; too shallow (rel_pressure<dive_threshold)
1545 1541
1573 calc_average_depth: 1569 calc_average_depth:
1574 btfsc reset_average_depth ; Reset the Avewrage depth? 1570 btfsc reset_average_depth ; Reset the Avewrage depth?
1575 rcall reset_average1 ; Reset the resettable average depth 1571 rcall reset_average1 ; Reset the resettable average depth
1576 1572
1577 ; 1. Add new 2xdepth to the Sum of depths registers 1573 ; 1. Add new 2xdepth to the Sum of depths registers
1578 movff rel_pressure+0,b0_lo 1574 SAFE_2BYTE_COPY rel_pressure, b0_lo ; Buffer...
1579 movff rel_pressure+1,b0_hi ; Buffer...
1580 1575
1581 movf b0_lo,w 1576 movf b0_lo,w
1582 addwf average_depth_hold+0,F 1577 addwf average_depth_hold+0,F
1583 movf b0_hi,w 1578 movf b0_hi,w
1584 addwfc average_depth_hold+1,F 1579 addwfc average_depth_hold+1,F
1729 movff WREG,int_I_pres_surface+0 ; LOW copy surfacepressure to deco routine 1724 movff WREG,int_I_pres_surface+0 ; LOW copy surfacepressure to deco routine
1730 movlw HIGH .1000 1725 movlw HIGH .1000
1731 movff WREG,int_I_pres_surface+1 ; HIGH copy surfacepressure to deco routine 1726 movff WREG,int_I_pres_surface+1 ; HIGH copy surfacepressure to deco routine
1732 1727
1733 diveloop_boot_2: 1728 diveloop_boot_2:
1734 movff temperature+0,mintemp+0 ; Reset Min-Temp registers 1729 SAFE_2BYTE_COPY temperature,mintemp ; Reset Min-Temp registers
1735 movff temperature+1,mintemp+1 ; Reset Min-Temp registers
1736 1730
1737 ; Init profile recording parameters 1731 ; Init profile recording parameters
1738 GETCUSTOM8 d'20' ; sample rate 1732 GETCUSTOM8 d'20' ; sample rate
1739 movwf samplesecs_value ; to avoid EEPROM access in the ISR 1733 movwf samplesecs_value ; to avoid EEPROM access in the ISR
1740 GETCUSTOM8 d'21' 1734 GETCUSTOM8 d'21'