Mercurial > public > hwos_code
comparison src/isr.asm @ 640:8c1f1f334275
3.13 release
| author | heinrichsweikamp |
|---|---|
| date | Thu, 29 Oct 2020 09:29:15 +0100 |
| parents | 2737ddc643bb |
| children | 7d8a4c60ec1a 5b7fe7777425 |
comparison
equal
deleted
inserted
replaced
| 639:0ff82370991d | 640:8c1f1f334275 |
|---|---|
| 1 ;============================================================================= | 1 ;============================================================================= |
| 2 ; | 2 ; |
| 3 ; File isr.asm * combined next generation V3.09.5 | 3 ; File isr.asm * combined next generation V3.11.1 |
| 4 ; | 4 ; |
| 5 ; INTERUPT subroutines | 5 ; INTERUPT subroutines |
| 6 ; | 6 ; |
| 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. |
| 8 ;============================================================================= | 8 ;============================================================================= |
| 38 movff PRODL,PROD_backup+0 ; back-up PRODL | 38 movff PRODL,PROD_backup+0 ; back-up PRODL |
| 39 movff PRODH,PROD_backup+1 ; back-up PRODH | 39 movff PRODH,PROD_backup+1 ; back-up PRODH |
| 40 ; serve buttons | 40 ; serve buttons |
| 41 btfsc PIR1,TMR1IF ; timer 1 interrupt (button hold-down timer)? | 41 btfsc PIR1,TMR1IF ; timer 1 interrupt (button hold-down timer)? |
| 42 rcall timer1int ; YES - reset timer | 42 rcall timer1int ; YES - reset timer |
| 43 btfsc PIR5,TMR4IF ; timer 4 interrupt (button debounce) | |
| 44 rcall timer4int ; YES, serve the interrupt | |
| 43 btfsc INTCON,INT0IF ; right button activity? | 45 btfsc INTCON,INT0IF ; right button activity? |
| 44 rcall isr_switch_right ; YES - check right switch | 46 rcall isr_switch_right ; YES - check right switch |
| 45 btfsc INTCON3,INT1IF ; left button activity? | 47 btfsc INTCON3,INT1IF ; left button activity? |
| 46 rcall isr_switch_left ; YES - check left switch | 48 rcall isr_switch_left ; YES - check left switch |
| 47 | 49 |
| 105 btfsc lv_core ; on OSTC with low voltage core? | 107 btfsc lv_core ; on OSTC with low voltage core? |
| 106 movlw b'01100010' ; YES - reduce to 8 MHz | 108 movlw b'01100010' ; YES - reduce to 8 MHz |
| 107 movwf OSCCON ; set prescaler | 109 movwf OSCCON ; set prescaler |
| 108 bsf OSCTUNE,6 ; switch on x4 PLL -> 64 MHz on high voltage core, 32 MHz on low voltage core | 110 bsf OSCTUNE,6 ; switch on x4 PLL -> 64 MHz on high voltage core, 32 MHz on low voltage core |
| 109 movlw T2CON_FASTEST ; PWM1 dimming factor for speed 'fastest' | 111 movlw T2CON_FASTEST ; PWM1 dimming factor for speed 'fastest' |
| 110 ;bra isr_adjust_speed_exit | 112 bra isr_adjust_speed_exit |
| 113 | |
| 114 ; Attention: fill-up the gap between the end of this section | |
| 115 ; and the next section which starts at 0x00080 !! | |
| 116 nop | |
| 117 | |
| 118 block_0_code_end: ; marker to find end of code in block 0 in linker report file | |
| 119 | |
| 120 | |
| 121 ;============================================================================= | |
| 122 ; Code to be placed at a fixed Position: Jump-Vector for the Bootloader | |
| 123 ; | |
| 124 restore CODE 0x00080 ; restore first flash page from EEPROM | |
| 125 | |
| 126 restore_flash_0x00080: | |
| 127 goto restore_flash | |
| 128 ; | |
| 129 ;============================================================================= | |
| 130 | |
| 131 | |
| 132 ;============================================================================= | |
| 133 isr_handler CODE 0x00084 | |
| 134 ;============================================================================= | |
| 111 | 135 |
| 112 isr_adjust_speed_exit: | 136 isr_adjust_speed_exit: |
| 113 movwf T2CON ; adjust PWM1 for LED dimming | 137 movwf T2CON ; adjust PWM1 for LED dimming |
| 114 btfss OSCCON,HFIOFS ; PLL stabilized? | 138 btfss OSCCON,HFIOFS ; PLL stabilized? |
| 115 bra isr_adjust_speed_exit ; NO - loop to give it some more time | 139 bra isr_adjust_speed_exit ; NO - loop to give it some more time |
| 116 return ; YES - done | 140 return ; YES - done |
| 117 | 141 |
| 118 ; Attention: fill-up the gap between the end of this section | |
| 119 ; and the next section which starts at 0x00080 !! | |
| 120 ;nop | |
| 121 | |
| 122 block_0_code_end: ; marker to find end of code in block 0 in linker report file | |
| 123 | |
| 124 | |
| 125 ;============================================================================= | |
| 126 ; Code to be placed at a fixed Position: Jump-Vector for the Bootloader | |
| 127 ; | |
| 128 restore CODE 0x00080 ; restore first flash page from EEPROM | |
| 129 | |
| 130 restore_flash_0x00080: | |
| 131 goto restore_flash | |
| 132 ; | |
| 133 ;============================================================================= | |
| 134 | |
| 135 | |
| 136 ;============================================================================= | |
| 137 isr_handler CODE 0x00084 | |
| 138 ;============================================================================= | |
| 139 | |
| 140 ;----------------------------------------------------------------------------- | 142 ;----------------------------------------------------------------------------- |
| 141 ; Handle digitally-attached external Sensors | 143 ; Handle digitally-attached external Sensors |
| 142 ; | 144 ; |
| 143 ; take a byte received on IR/S8 link and slot it into the RX buffer | 145 ; take a byte received on IR/S8 link and slot it into the RX buffer |
| 144 ; | 146 ; |
| 275 MOVII FSR0_backup,FSR0L ; - restore FSR0 | 277 MOVII FSR0_backup,FSR0L ; - restore FSR0 |
| 276 return ; - done | 278 return ; - done |
| 277 | 279 |
| 278 ENDIF ; _external_sensor | 280 ENDIF ; _external_sensor |
| 279 | 281 |
| 282 | |
| 283 ;----------------------------------------------------------------------------- | |
| 284 ; Timer 4 - Button debounce (For new digital piezo circuit) | |
| 285 | |
| 286 timer4int: | |
| 287 bcf PIR5,TMR4IF | |
| 288 decfsz debounce_counter,F | |
| 289 return | |
| 290 bcf T4CON,TMR4ON ; Stop timer 4 | |
| 291 clrf TMR4 ; reset | |
| 292 | |
| 293 movff opt_cR_button_right,WREG ; 20-100; mH: opt_cR_button_right will also affect left button | |
| 294 bcf STATUS,C ; clear carry bit | |
| 295 rrcf WREG ; /2 -> 10-50 | |
| 296 bcf STATUS,C ; clear carry bit | |
| 297 rrcf WREG ; /2 -> 5-25 | |
| 298 decf WREG,W ; -1 | |
| 299 decf WREG,W ; -1 | |
| 300 decf WREG,W ; -1 -> 2-22 | |
| 301 | |
| 302 ; movlw .5 ; initial delay | |
| 303 movwf debounce_counter ; multiples of 16ms | |
| 304 return | |
| 305 | |
| 306 timer4_restart: | |
| 307 movlw .5 ; extra delay | |
| 308 movwf debounce_counter | |
| 309 clrf TMR4 ; reset | |
| 310 bcf INTCON3,INT1IF ; clear ext. int 1 request | |
| 311 bcf INTCON,INT0IF ; clear ext. int 0 request | |
| 312 bsf INTCON,INT0IE ; enable INT0 IRQ | |
| 313 bsf INTCON3,INT1IE ; enable INT1 IRQ | |
| 314 return | |
| 280 | 315 |
| 281 ;----------------------------------------------------------------------------- | 316 ;----------------------------------------------------------------------------- |
| 282 ; Tasks every 62.5 ms: Buttons, Dimming, Pressure/Temperature Sensor and CPU Speed | 317 ; Tasks every 62.5 ms: Buttons, Dimming, Pressure/Temperature Sensor and CPU Speed |
| 283 ; | 318 ; |
| 284 isr_tmr7: | 319 isr_tmr7: |
| 286 | 321 |
| 287 banksel 0xF16 ; TMR7H/L are not part of the access RAM | 322 banksel 0xF16 ; TMR7H/L are not part of the access RAM |
| 288 movlw .248 ; reload timer 7, high byte (8x256 ticks -> 62.5 ms) | 323 movlw .248 ; reload timer 7, high byte (8x256 ticks -> 62.5 ms) |
| 289 movwf TMR7H ; ... (keep low byte running ) | 324 movwf TMR7H ; ... (keep low byte running ) |
| 290 | 325 |
| 291 btfss update_surface_pressure ; shall update the surface pressure? | 326 btfss update_surface_pressure ; shall update the surface pressure? |
| 292 bra isr_tmr7_0 ; NO - skip | 327 bra isr_tmr7_1 ; NO - skip |
| 293 bcf update_surface_pressure ; YES - clear request flag | 328 bcf update_surface_pressure ; YES - clear request flag |
| 294 MOVII pressure_abs_ref,pressure_surf ; - update surface pressure | 329 MOVII pressure_abs_ref,pressure_surf ; - update surface pressure |
| 295 | 330 |
| 296 isr_tmr7_0: | 331 isr_tmr7_1: |
| 297 call get_analog_switches ; get analog readings - bank-safe, but CAUTION: returns in bank common | 332 call get_analog_switches ; get analog readings - bank-safe, but CAUTION: returns in bank common |
| 298 banksel isr_backup ; back to ISR default bank | 333 banksel isr_backup ; back to ISR default bank |
| 299 | 334 |
| 300 btfss INTCON3,INT1IE ; external IRQ 1 enabled? | 335 btfss INTCON3,INT1IE ; external IRQ 1 enabled? |
| 301 bra isr_tmr7_a ; NO - skip next | 336 bra isr_tmr7_2 ; NO - skip next |
| 302 btfsc analog_sw2_pressed ; YES - analog switch 2 pressed? | 337 btfsc analog_sw2_pressed ; YES - analog switch 2 pressed? |
| 303 rcall isr_switch_left ; NO - get digital readings of left switch | 338 rcall isr_switch_left ; NO - get digital readings of left switch |
| 304 isr_tmr7_a: | 339 |
| 340 isr_tmr7_2: | |
| 305 btfss INTCON,INT0IE ; external IRQ 0 enabled? | 341 btfss INTCON,INT0IE ; external IRQ 0 enabled? |
| 306 bra isr_tmr7_b ; NO - skip next | 342 bra isr_tmr7_3 ; NO - skip next |
| 307 btfsc analog_sw1_pressed ; YES - analog switch 1 pressed? | 343 btfsc analog_sw1_pressed ; YES - analog switch 1 pressed? |
| 308 rcall isr_switch_right ; NO - get digital readings of right switch | 344 rcall isr_switch_right ; NO - get digital readings of right switch |
| 309 isr_tmr7_b: | 345 |
| 310 btfss block_sensor_interrupt ; sensor interrupts disabled? | 346 isr_tmr7_3: |
| 311 bra isr_tmr7_c ; NO - continue | 347 btfsc block_sensor_interrupt ; sensor interrupts disabled? |
| 312 bra sensor_int_state_exit ; YES - goto exit | 348 bra sensor_int_state_exit ; YES - goto exit |
| 313 isr_tmr7_c: | 349 ;bra isr_tmr7_4 ; NO - continue |
| 350 | |
| 351 isr_tmr7_4: | |
| 314 movf max_CCPR1L,W ; dim value | 352 movf max_CCPR1L,W ; dim value |
| 315 cpfseq CCPR1L ; = current PWM value? | 353 cpfseq CCPR1L ; = current PWM value? |
| 316 rcall isr_dimm_tft ; NO - adjust until max_CCPR1L = CCPR1L | 354 rcall isr_dimm_tft ; NO - adjust until max_CCPR1L = CCPR1L |
| 317 | 355 |
| 318 IFDEF _external_sensor | 356 IFDEF _external_sensor |
| 357 | |
| 319 decfsz ir_s8_timeout,F ; decrement IR/S8 timeout counter, became zero? | 358 decfsz ir_s8_timeout,F ; decrement IR/S8 timeout counter, became zero? |
| 320 bra isr_tmr7_2 ; NO - continue | 359 bra isr_sensor_state2 ; NO - continue with sensor |
| 321 movlw ir_timeout_value ; YES - get timeout value (in multiples of 62.5 ms) | 360 movlw ir_timeout_value ; YES - get timeout value (in multiples of 62.5 ms) |
| 322 movwf ir_s8_timeout ; - reload timeout timer | 361 movwf ir_s8_timeout ; - reload timeout timer |
| 323 btfsc ext_input_optical ; - optical input in use? | 362 btfsc ext_input_optical ; - optical input in use? |
| 324 bra isr_tmr7_1a ; YES - clear data | 363 bra isr_tmr7_5 ; YES - clear data |
| 325 TSTOSS opt_s8_mode ; NO - S8 input in use? | 364 TSTOSS opt_s8_mode ; NO - S8 input in use? |
| 326 bra isr_tmr7_2 ; NO - must be analog interface in use, keep data | 365 bra isr_sensor_state2 ; NO - must be analog interface in use, keep data |
| 327 ;bra isr_tmr7_1a ; YES - clear data | 366 ;bra isr_tmr7_5 ; YES - clear data |
| 328 | 367 |
| 329 isr_tmr7_1a: | 368 isr_tmr7_5: |
| 330 clrf hud_status_byte ; S8/IR timeout clears all analog input readings to zero -> fallback will be triggered when in sensor mode | 369 clrf hud_status_byte ; S8/IR timeout clears all analog input readings to zero -> fallback will be triggered when in sensor mode |
| 331 CLRI hud_battery_mv ; clear battery voltage | 370 CLRI hud_battery_mv ; clear battery voltage |
| 332 | 371 |
| 333 banksel sensor1_mv ; select bank where sensor data are stored | 372 banksel sensor1_mv ; select bank where sensor data are stored |
| 334 CLRI sensor1_mv ; clear all sensor data | 373 CLRI sensor1_mv ; clear all sensor data |
| 345 CLRI s8_rawdata_sensor3 ; clear all sensor data (raw data) | 384 CLRI s8_rawdata_sensor3 ; clear all sensor data (raw data) |
| 346 clrf s8_rawdata_sensor3+2 | 385 clrf s8_rawdata_sensor3+2 |
| 347 banksel isr_backup ; back to ISR default bank | 386 banksel isr_backup ; back to ISR default bank |
| 348 | 387 |
| 349 bsf trigger_S8_data_update ; signal a data update | 388 bsf trigger_S8_data_update ; signal a data update |
| 350 ENDIF | 389 |
| 351 | 390 ENDIF ; _external_sensor |
| 352 isr_tmr7_2: | 391 |
| 353 | 392 isr_sensor_state2: |
| 354 ;isr_sensor_state2: | |
| 355 btfss sensor_state_counter,0 ; every 1/4 second | 393 btfss sensor_state_counter,0 ; every 1/4 second |
| 356 bsf trigger_quarter_second ; set flag | 394 bsf trigger_quarter_second ; set flag |
| 357 | 395 |
| 358 btfss speed_is_normal ; CPU running on normal speed? | 396 btfss speed_is_normal ; CPU running on normal speed? |
| 359 rcall isr_set_speed_to_normal ; NO - set CPU speed to normal | 397 rcall isr_set_speed_to_normal ; NO - set CPU speed to normal |
| 849 | 887 |
| 850 ;----------------------------------------------------------------------------- | 888 ;----------------------------------------------------------------------------- |
| 851 ; Check Buttons | 889 ; Check Buttons |
| 852 ; | 890 ; |
| 853 isr_switch_right: | 891 isr_switch_right: |
| 854 bcf INTCON,INT0IE ; clear external interrupt 0 | 892 bcf INTCON,INT0IE ; disable external interrupt 0 |
| 893 | |
| 894 btfsc button_hold_down_allowed,A ; ignore for mechanical push buttons | |
| 895 bra isr_switch_right2 | |
| 896 btfsc T4CON,TMR4ON ; Timer4 running? | |
| 897 bra timer4_restart ; Yes, restart | |
| 898 isr_switch_right2: | |
| 899 | |
| 855 btfss flip_screen ; 180° flipped? | 900 btfss flip_screen ; 180° flipped? |
| 856 bsf switch_right ; NO - set flag for right button | 901 bsf switch_right ; NO - set flag for right button |
| 857 btfsc flip_screen ; 180° flipped? | 902 btfsc flip_screen ; 180° flipped? |
| 858 bsf switch_left ; YES - set flag for left button | 903 bsf switch_left ; YES - set flag for left button |
| 859 bra isr_switch_common ; continue with common part | 904 bra isr_switch_common ; continue with common part |
| 860 | 905 |
| 861 isr_switch_left: | 906 isr_switch_left: |
| 862 bcf INTCON3,INT1IE ; clear external interrupt 1 | 907 bcf INTCON3,INT1IE ; disable external interrupt 1 |
| 908 | |
| 909 btfsc button_hold_down_allowed,A ; ignore for mechanical push buttons | |
| 910 bra isr_switch_left2 | |
| 911 btfsc T4CON,TMR4ON ; Timer4 running? | |
| 912 bra timer4_restart ; Yes, restart | |
| 913 isr_switch_left2: | |
| 914 | |
| 863 btfss flip_screen ; 180° flipped? | 915 btfss flip_screen ; 180° flipped? |
| 864 bsf switch_left ; NO - set flag for left button | 916 bsf switch_left ; NO - set flag for left button |
| 865 btfsc flip_screen ; 180° flipped? | 917 btfsc flip_screen ; 180° flipped? |
| 866 bsf switch_right ; YES - set flag for right button | 918 bsf switch_right ; YES - set flag for right button |
| 867 ;bra isr_switch_common ; continue with common part | 919 ;bra isr_switch_common ; continue with common part |
| 868 | 920 |
| 869 isr_switch_common: | 921 isr_switch_common: |
| 922 btfss button_hold_down_allowed,A ; ignore for mechanical push buttons | |
| 923 bsf T4CON,TMR4ON ; Start timer 4 | |
| 924 | |
| 870 btfsc tmr5_preemtion_allowed ; timer 5 preemption allowed? | 925 btfsc tmr5_preemtion_allowed ; timer 5 preemption allowed? |
| 871 bsf PIR5,TMR5IF ; YES - preempt timer 5 | 926 bsf PIR5,TMR5IF ; YES - preempt timer 5 |
| 872 movlw TMR1H_VALUE_FIRST ; load timer 1 (in steps of 7.8125 ms) | 927 movlw TMR1H_VALUE_FIRST ; load timer 1 (in steps of 7.8125 ms) |
| 873 movwf TMR1H ; ... | 928 movwf TMR1H ; ... |
| 874 clrf TMR1L ; ... | 929 clrf TMR1L ; ... |
| 875 bsf T1CON,TMR1ON ; start timer 1 | 930 bsf T1CON,TMR1ON ; start timer 1 |
| 876 bcf INTCON3,INT1IF ; clear timer 1 IRQ request | 931 bcf INTCON3,INT1IF ; clear ext. int 1 request |
| 877 bcf INTCON,INT0IF ; clear timer 0 IRQ request | 932 bcf INTCON,INT0IF ; clear ext. int 0 request |
| 878 return ; done | 933 return ; done |
| 879 | 934 |
| 880 | 935 |
| 881 ;----------------------------------------------------------------------------- | 936 ;----------------------------------------------------------------------------- |
| 882 ; Button hold-down Interrupt | 937 ; Button hold-down Interrupt |
| 883 ; | 938 ; |
| 884 timer1int: | 939 timer1int: |
| 885 bcf PIR1,TMR1IF ; clear timer 1 IRQ request | 940 bcf PIR1,TMR1IF ; clear timer 1 IRQ request |
| 886 bcf INTCON,INT0IF ; clear timer 0 IRQ request | 941 bcf INTCON,INT0IF ; clear ext. int 0 request |
| 887 bcf INTCON3,INT1IF ; clear timer 1 IRQ request | 942 bcf INTCON3,INT1IF ; clear ext. int 1 request |
| 888 | 943 |
| 889 ; digital | 944 ; digital |
| 890 btfss switch_left1 ; left button hold-down? | 945 btfss switch_left1 ; left button hold-down? |
| 891 bra timer1int_left ; YES | 946 bra timer1int_left ; YES |
| 892 btfss switch_right2 ; right button hold-down? | 947 btfss switch_right2 ; right button hold-down? |
