Mercurial > public > hwos_code
annotate src/isr.asm @ 634:4050675965ea
3.10 stable release
author | heinrichsweikamp |
---|---|
date | Tue, 28 Apr 2020 17:34:31 +0200 |
parents | 185ba2f91f59 |
children | 2737ddc643bb |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
634 | 3 ; File isr.asm * combined next generation V3.09.5 |
0 | 4 ; |
5 ; INTERUPT subroutines | |
6 ; | |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
10 ; 2011-05-24 : [jDG] Cleanups from initial Matthias code. | |
11 | |
275 | 12 #include "hwos.inc" |
582 | 13 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c |
0 | 14 #include "ms5541.inc" |
15 #include "adc_lightsensor.inc" | |
623 | 16 |
17 extern restore_flash | |
0 | 18 |
634 | 19 |
0 | 20 ;============================================================================= |
634 | 21 ; Code to be placed at a fixed Position |
623 | 22 ; |
604 | 23 isr_high CODE 0x0008 ; high priority interrupts |
634 | 24 bra HighInt ; jump to ISR |
25 | |
26 isr_low CODE 0x00018 ; low priority interrupts *** not used *** | |
27 retfie FAST ; do an immediate return from IRQ | |
28 ; | |
29 ;============================================================================= | |
623 | 30 |
0 | 31 |
634 | 32 ;----------------------------------------------------------------------------- |
33 ; Interrupt Dispatcher Entry Point | |
623 | 34 ; |
0 | 35 HighInt: |
623 | 36 ; initialize interrupt code |
37 banksel isr_backup ; default bank for all ISR code is bank ISR data | |
629 | 38 movff PRODL,PROD_backup+0 ; back-up PRODL |
39 movff PRODH,PROD_backup+1 ; back-up PRODH | |
623 | 40 ; serve buttons |
41 btfsc PIR1,TMR1IF ; timer 1 interrupt (button hold-down timer)? | |
42 rcall timer1int ; YES - reset timer | |
43 btfsc INTCON,INT0IF ; right button activity? | |
44 rcall isr_switch_right ; YES - check right switch | |
45 btfsc INTCON3,INT1IF ; left button activity? | |
46 rcall isr_switch_left ; YES - check left switch | |
0 | 47 |
623 | 48 IFDEF _external_sensor |
49 ; serve IR/S8 link timer | |
50 btfsc PIR3,RC2IF ; UART 2 interrupt? | |
51 rcall isr_uart2 ; YES - get a byte from the IR/S8 link | |
52 btfsc PIR2,TMR3IF ; timer 3 interrupt? | |
53 rcall isr_timer3 ; YES - check bytes received from IR/S8 link for being a valid telegram | |
629 | 54 ELSE |
55 bcf PIR3,RC2IF ; clear UART 2 interrupt | |
56 bcf PIR2,TMR3IF ; clear timer 3 interrupt | |
57 ; fill-up to keep code size identical to _external_sensor variant, see "Attention" below | |
58 nop | |
59 nop | |
623 | 60 ENDIF |
61 | |
62 ; serve pressure and temperature sensor | |
63 btfsc PIR5,TMR7IF ; timer 7 interrupt? | |
64 rcall isr_tmr7 ; YES - do every 62.5 ms tasks: read sensors, set CPU speed | |
65 | |
66 ; serve real-time clock (RTCC) | |
67 btfsc PIR3,RTCCIF ; real-time-clock interrupt? | |
68 rcall isr_rtcc ; YES - do every 1/2 s tasks: read RTC, trigger timed tasks, adjust CPU speed, gauge battery, etc. | |
113 | 69 |
623 | 70 ; clean up and exit |
629 | 71 movff PROD_backup+0,PRODL ; restore PRODL |
72 movff PROD_backup+1,PRODH ; restore PRODH | |
623 | 73 bsf trigger_isr_updates ; signal that the ISR had kicked in |
74 retfie FAST ; return from interrupt restoring BSR, STATUS and WREG | |
75 | |
113 | 76 |
634 | 77 ;----------------------------------------------------------------------------- |
78 ; CPU Speed Adjustment | |
623 | 79 ; |
80 isr_adjust_speed: | |
81 movff cpu_speed_request,cpu_speed_state ; acknowledge CPU speed request | |
0 | 82 |
623 | 83 btfsc speed_is_eco ; speed 'eco' requested? |
84 bra isr_set_speed_to_eco ; YES - set eco speed | |
85 btfsc speed_is_fastest ; NO - speed 'fastest' requested? | |
86 bra isr_set_speed_to_fastest ; YES - set fastest speed | |
87 ;bra isr_set_speed_to_normal ; NO - default to normal speed | |
0 | 88 |
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
89 isr_set_speed_to_normal: |
629 | 90 clrf OSCTUNE ; switch off x4 PLL |
623 | 91 movlw b'01110010' ; select 16 MHz |
92 movwf OSCCON ; set prescaler | |
93 movlw T2CON_NORMAL ; PWM1 dimming factor for speed 'normal' | |
94 bra isr_adjust_speed_exit | |
95 | |
96 isr_set_speed_to_eco: | |
629 | 97 clrf OSCTUNE ; switch off x4 PLL |
623 | 98 movlw b'00110010' ; select 1 MHz |
99 movwf OSCCON ; set prescaler | |
100 movlw T2CON_ECO ; PWM1 dimming factor for speed 'eco' | |
101 bra isr_adjust_speed_exit | |
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
102 |
623 | 103 isr_set_speed_to_fastest: |
104 movlw b'01110010' ; select 16 MHz by default | |
105 btfsc lv_core ; on OSTC with low voltage core? | |
106 movlw b'01100010' ; YES - reduce to 8 MHz | |
107 movwf OSCCON ; set prescaler | |
629 | 108 bsf OSCTUNE,6 ; switch on x4 PLL -> 64 MHz on high voltage core, 32 MHz on low voltage core |
623 | 109 movlw T2CON_FASTEST ; PWM1 dimming factor for speed 'fastest' |
110 ;bra isr_adjust_speed_exit | |
111 | |
112 isr_adjust_speed_exit: | |
629 | 113 movwf T2CON ; adjust PWM1 for LED dimming |
623 | 114 btfss OSCCON,HFIOFS ; PLL stabilized? |
115 bra isr_adjust_speed_exit ; NO - loop to give it some more time | |
116 return ; YES - done | |
117 | |
118 ; Attention: fill-up the gap between the end of this section | |
119 ; and the next section which starts at 0x00080 !! | |
629 | 120 ;nop |
623 | 121 |
122 block_0_code_end: ; marker to find end of code in block 0 in linker report file | |
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
123 |
634 | 124 |
623 | 125 ;============================================================================= |
634 | 126 ; Code to be placed at a fixed Position: Jump-Vector for the Bootloader |
623 | 127 ; |
634 | 128 restore CODE 0x00080 ; restore first flash page from EEPROM |
129 | |
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
130 restore_flash_0x00080: |
582 | 131 goto restore_flash |
634 | 132 ; |
133 ;============================================================================= | |
134 | |
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
378
diff
changeset
|
135 |
623 | 136 ;============================================================================= |
634 | 137 isr_handler CODE 0x00084 |
138 ;============================================================================= | |
139 | |
140 ;----------------------------------------------------------------------------- | |
141 ; Handle digitally-attached external Sensors | |
142 ; | |
143 ; take a byte received on IR/S8 link and slot it into the RX buffer | |
623 | 144 ; |
145 IFDEF _external_sensor | |
146 | |
147 isr_uart2: | |
634 | 148 bcf PIR3,RC2IF ; clear UART 2 interrupt flag |
623 | 149 banksel RCREG2 ; RC*2 is outside access RAM |
150 movff RCREG2,isr_lo ; copy received byte to isr_lo | |
151 bcf RCSTA2,CREN ; clear receiver status | |
152 bsf RCSTA2,CREN ; ... | |
153 banksel isr_backup ; back to default ISR bank | |
154 movlw .18 ; size of the buffer | |
155 cpfslt ir_s8_counter ; number of received bytes < buffer size? | |
156 bra isr_uart2_1 ; NO - buffer full, do not store the byte | |
157 movf ir_s8_counter,W ; YES - copy number of received bytes to WREG | |
158 MOVII FSR0L,FSR0_backup ; - back-up FSR0 | |
159 lfsr FSR0,ir_s8_buffer ; - load base address of buffer | |
160 movff isr_lo,PLUSW0 ; - store received byte | |
161 MOVII FSR0_backup,FSR0L ; - restore FSR0 | |
162 incf ir_s8_counter,F ; - increment number of received bytes by 1 | |
163 isr_uart2_1: | |
634 | 164 movlw .253 ; reload timer 3, high byte |
623 | 165 movwf TMR3H ; ... |
634 | 166 clrf TMR3L ; reload timer 3, low byte |
167 bsf T3CON,TMR3ON ; restart timer | |
168 return ; done | |
623 | 169 |
170 | |
634 | 171 ;----------------------------------------------------------------------------- |
172 ; Timeout on IR/S8 Link: check the Checksum and gather the received Data | |
623 | 173 ; |
174 isr_timer3: | |
604 | 175 bcf T3CON,TMR3ON ; stop timer 3 |
634 | 176 movlw .15 ; a IR telegram has 15 bytes |
604 | 177 cpfseq ir_s8_counter ; got exactly 15 bytes? |
623 | 178 bra isr_timer3_1 ; NO - test for 16 bytes |
604 | 179 bra isr_timer3_ir ; YES - got 15 bytes, compute local checksum |
0 | 180 isr_timer3_1: |
634 | 181 movlw .16 ; a IR telegram may also have 16 bytes, with last byte 0x00 |
604 | 182 cpfseq ir_s8_counter ; got exactly 16 bytes? |
623 | 183 bra isr_timer3_2 ; NO - test for 17 bytes |
604 | 184 tstfsz ir_s8_buffer+.15 ; YES - last byte = 0x00 ? |
634 | 185 bra isr_timer3_exit ; NO - exit |
604 | 186 bra isr_timer3_ir ; YES - got 16 bytes, compute local checksum |
113 | 187 isr_timer3_2: |
634 | 188 movlw .17 ; a S8 telegram has 17 bytes |
604 | 189 cpfseq ir_s8_counter ; got exactly 17 bytes? |
190 bra isr_timer3_exit ; NO - exit | |
191 bra isr_timer3_s8 ; YES - S8 data | |
0 | 192 |
634 | 193 ; process telegram received on IR link |
623 | 194 isr_timer3_ir: |
634 | 195 movlw .12 ; compute checksum over 1st and next 12 bytes |
623 | 196 rcall compute_IR_S8_checksum ; compute checksum |
634 | 197 tstfsz ir_s8_counter ; checksum ok? |
198 bra isr_timer3_exit ; NO - discard data | |
0 | 199 |
634 | 200 ; copy received data to respective variables |
623 | 201 movff ir_s8_buffer+.1, hud_status_byte |
202 movff ir_s8_buffer+.2, sensor1_mv+0 | |
203 movff ir_s8_buffer+.3, sensor1_mv+1 | |
204 movff ir_s8_buffer+.4, sensor2_mv+0 | |
205 movff ir_s8_buffer+.5, sensor2_mv+1 | |
206 movff ir_s8_buffer+.6, sensor3_mv+0 | |
207 movff ir_s8_buffer+.7, sensor3_mv+1 | |
208 movff ir_s8_buffer+.8, sensor1_ppO2 | |
209 movff ir_s8_buffer+.9, sensor2_ppO2 | |
210 movff ir_s8_buffer+.10,sensor3_ppO2 | |
582 | 211 movff ir_s8_buffer+.11,hud_battery_mv+0 |
212 movff ir_s8_buffer+.12,hud_battery_mv+1 | |
0 | 213 |
623 | 214 bsf hud_connection_ok ; set manually for hwHUD w/o the HUD module |
215 bra isr_timer3_reload ; reload timer and exit | |
216 | |
634 | 217 ; process telegram received on S8 link |
623 | 218 isr_timer3_s8: |
634 | 219 movlw .14 ; compute checksum over 1st and next 14 bytes |
623 | 220 rcall compute_IR_S8_checksum ; compute checksum |
634 | 221 tstfsz ir_s8_counter ; checksum ok? |
222 bra isr_timer3_exit ; NO - discard data | |
623 | 223 |
634 | 224 ; copy received data to respective variables |
225 movff ir_s8_buffer+.3, hud_status_byte ; also sets hud_connection_ok flag | |
623 | 226 movff ir_s8_buffer+.13,hud_battery_mv+0 |
227 movff ir_s8_buffer+.14,hud_battery_mv+1 | |
227
03946aa48fa5
NEW: Support for hwHUD without the LED module
heinrichsweikamp
parents:
204
diff
changeset
|
228 |
634 | 229 ; btfsc trigger_S8_data_update ; last data already processed? |
230 ; bra isr_timer3_exit ; NO - skip copying new data (and not reload the timeout) | |
623 | 231 bsf trigger_S8_data_update ; YES - set flag for new data available |
582 | 232 |
634 | 233 ; copy more received data to respective variables |
623 | 234 movff ir_s8_buffer+.4, s8_rawdata_sensor1+0 |
235 movff ir_s8_buffer+.5, s8_rawdata_sensor1+1 | |
236 movff ir_s8_buffer+.6, s8_rawdata_sensor1+2 | |
237 movff ir_s8_buffer+.7, s8_rawdata_sensor2+0 | |
238 movff ir_s8_buffer+.8, s8_rawdata_sensor2+1 | |
239 movff ir_s8_buffer+.9, s8_rawdata_sensor2+2 | |
240 movff ir_s8_buffer+.10,s8_rawdata_sensor3+0 | |
241 movff ir_s8_buffer+.11,s8_rawdata_sensor3+1 | |
242 movff ir_s8_buffer+.12,s8_rawdata_sensor3+2 | |
243 | |
244 isr_timer3_reload: | |
634 | 245 movlw ir_timeout_value ; get timeout value (in multiples of 62.5 ms) |
246 movwf ir_s8_timeout ; reload timeout counter | |
0 | 247 isr_timer3_exit: |
634 | 248 clrf ir_s8_counter ; clear number of received bytes |
249 bcf PIR2,TMR3IF ; clear IRQ flag | |
250 return ; done | |
0 | 251 |
252 | |
634 | 253 ;----------------------------------------------------------------------------- |
254 ; Helper Function - Compute Checksum on Data in RX Buffer | |
623 | 255 ; |
256 compute_IR_S8_checksum: | |
257 movwf ir_s8_counter ; initialize loop counter from WREG | |
634 | 258 MOVII FSR0L,FSR0_backup ; back-up FSR0 |
259 lfsr FSR0,ir_s8_buffer ; load base address of the receive buffer | |
260 movff POSTINC0,isr_mpr+0 ; initialize low byte of the calculated checksum with first byte in buffer | |
261 clrf isr_mpr+1 ; clear the high byte of the calculated checksum | |
623 | 262 compute_IR_S8_checksum_loop: |
634 | 263 movf POSTINC0,W ; read next byte |
623 | 264 addwf isr_mpr+0,F ; add it to the to checksum, low byte |
265 movlw .0 ; no explicit data to add to the high byte... | |
266 addwfc isr_mpr+1,F ; ... besides the carry | |
634 | 267 decfsz ir_s8_counter,F ; decrement number of bytes yet to do, all done? |
623 | 268 bra compute_IR_S8_checksum_loop ; NO - loop |
634 | 269 movf POSTINC0,W ; YES - read low byte of the received checksum |
270 cpfseq isr_mpr+0 ; - equal to low byte of the calculated checksum? | |
271 incf ir_s8_counter,F ; NO - mark a checksum error | |
272 movf POSTINC0,W ; - read high byte of the received checksum | |
273 cpfseq isr_mpr+1 ; - equal to high byte of the calculated checksum? | |
274 incf ir_s8_counter,F ; NO - mark a checksum error | |
275 MOVII FSR0_backup,FSR0L ; - restore FSR0 | |
276 return ; - done | |
113 | 277 |
623 | 278 ENDIF ; _external_sensor |
113 | 279 |
0 | 280 |
634 | 281 ;----------------------------------------------------------------------------- |
282 ; Tasks every 62.5 ms: Buttons, Dimming, Pressure/Temperature Sensor and CPU Speed | |
623 | 283 ; |
284 isr_tmr7: | |
634 | 285 bcf PIE5,TMR7IE ; disable IRQs by TMR7 |
0 | 286 |
634 | 287 banksel 0xF16 ; TMR7H/L are not part of the access RAM |
288 movlw .248 ; reload timer 7, high byte (8x256 ticks -> 62.5 ms) | |
289 movwf TMR7H ; ... (keep low byte running ) | |
290 | |
291 call get_analog_switches ; get analog readings - bank-safe, but CAUTION: returns in bank common | |
292 banksel isr_backup ; back to ISR default bank | |
623 | 293 |
634 | 294 btfss INTCON3,INT1IE ; external IRQ 1 enabled? |
295 bra isr_tmr7_a ; NO - skip next | |
296 btfsc analog_sw2_pressed ; YES - analog switch 2 pressed? | |
297 rcall isr_switch_left ; NO - get digital readings of left switch | |
448 | 298 isr_tmr7_a: |
634 | 299 btfss INTCON,INT0IE ; external IRQ 0 enabled? |
300 bra isr_tmr7_b ; NO - skip next | |
301 btfsc analog_sw1_pressed ; YES - analog switch 1 pressed? | |
302 rcall isr_switch_right ; NO - get digital readings of right switch | |
448 | 303 isr_tmr7_b: |
623 | 304 btfss block_sensor_interrupt ; sensor interrupts disabled? |
604 | 305 bra isr_tmr7_c ; NO - continue |
634 | 306 bra sensor_int_state_exit ; YES - goto exit |
490
8dfb93e80338
NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically)
heinrichsweikamp
parents:
469
diff
changeset
|
307 isr_tmr7_c: |
623 | 308 movf max_CCPR1L,W ; dim value |
582 | 309 cpfseq CCPR1L ; = current PWM value? |
623 | 310 rcall isr_dimm_tft ; NO - adjust until max_CCPR1L = CCPR1L |
0 | 311 |
623 | 312 IFDEF _external_sensor |
634 | 313 decfsz ir_s8_timeout,F ; decrement IR/S8 timeout counter, became zero? |
314 bra isr_tmr7_2 ; NO - continue | |
315 movlw ir_timeout_value ; YES - get timeout value (in multiples of 62.5 ms) | |
316 movwf ir_s8_timeout ; - reload timeout timer | |
317 btfsc ext_input_optical ; - optical input in use? | |
318 bra isr_tmr7_1a ; YES - clear data | |
319 TSTOSS opt_s8_mode ; NO - S8 input in use? | |
623 | 320 bra isr_tmr7_2 ; NO - must be analog interface in use, keep data |
634 | 321 ;bra isr_tmr7_1a ; YES - clear data |
322 | |
113 | 323 isr_tmr7_1a: |
623 | 324 clrf hud_status_byte ; S8/IR timeout clears all analog input readings to zero -> fallback will be triggered when in sensor mode |
325 CLRI hud_battery_mv ; clear battery voltage | |
582 | 326 |
623 | 327 banksel sensor1_mv ; select bank where sensor data are stored |
328 CLRI sensor1_mv ; clear all sensor data | |
329 CLRI sensor2_mv ; ... | |
330 CLRI sensor3_mv ; ... | |
331 clrf sensor1_ppO2 ; ... | |
332 clrf sensor2_ppO2 ; ... | |
333 clrf sensor3_ppO2 ; ... | |
628 | 334 banksel s8_rawdata_sensor1 |
335 CLRI s8_rawdata_sensor1 ; clear all sensor data (raw data) | |
336 clrf s8_rawdata_sensor1+2 | |
337 CLRI s8_rawdata_sensor2 ; clear all sensor data (raw data) | |
338 clrf s8_rawdata_sensor2+2 | |
339 CLRI s8_rawdata_sensor3 ; clear all sensor data (raw data) | |
340 clrf s8_rawdata_sensor3+2 | |
623 | 341 banksel isr_backup ; back to ISR default bank |
342 | |
343 bsf trigger_S8_data_update ; signal a data update | |
344 ENDIF | |
582 | 345 |
0 | 346 isr_tmr7_2: |
623 | 347 btfsc block_sensor_interrupt ; sensor interrupts disabled? |
634 | 348 bra sensor_int_state_exit ; YES - goto exit |
0 | 349 |
350 isr_sensor_state2: | |
623 | 351 btfss sensor_state_counter,0 ; every 1/4 second |
352 bsf trigger_quarter_second ; set flag | |
353 | |
354 btfss speed_is_normal ; CPU running on normal speed? | |
355 rcall isr_set_speed_to_normal ; NO - set CPU speed to normal | |
582 | 356 |
623 | 357 ; update surface pressure |
358 btfss update_surface_pressure ; shall update the surface pressure? | |
359 bra isr_sensor_state2_1 ; NO | |
360 bcf update_surface_pressure ; YES - clear request flag | |
361 MOVII pressure_abs_ref,pressure_surf ; - update surface pressure | |
362 | |
363 isr_sensor_state2_1: | |
364 incf sensor_state_counter,F ; counts to eight for state machine | |
0 | 365 |
623 | 366 ; State 1: clear flags and average registers, get temperature (51 us) and start pressure integration (73.5 us) |
367 ; State 2: get pressure (51 us), start temperature integration (73.5 us) and calculate temperature compensated pressure (233 us) | |
368 ; State 3: get temperature (51 us) and start pressure integration (73.5 us) | |
369 ; State 4: get pressure (51 us), start temperature integration (73.5 us) and calculate temperature compensated pressure (233 us) | |
370 ; State 5: get temperature (51 us) and start pressure integration (73.5 us) | |
371 ; State 6: get pressure (51 us), start temperature integration (73.5 us) and calculate temperature compensated pressure (233 us) | |
372 ; State 7: get temperature (51 us) and start pressure integration (73.5 us) | |
373 ; State 8: get pressure (51 us), start temperature integration (73.5 us) and calculate temperature compensated pressure (233 us) and build average for half-second update of temperature and pressure | |
582 | 374 |
623 | 375 movff sensor_state_counter,WREG ; WREG used as temp here... |
582 | 376 dcfsnz WREG,F |
623 | 377 bra sensor_int_state1_plus_restart ; do state 1 |
582 | 378 dcfsnz WREG,F |
623 | 379 bra sensor_int_state2 ; do state 2 |
582 | 380 dcfsnz WREG,F |
623 | 381 bra sensor_int_state1 ; do state 3 |
582 | 382 dcfsnz WREG,F |
623 | 383 bra sensor_int_state2 ; do state 4 |
582 | 384 dcfsnz WREG,F |
623 | 385 bra sensor_int_state1 ; do state 5 |
582 | 386 dcfsnz WREG,F |
623 | 387 bra sensor_int_state2 ; do state 6 |
582 | 388 dcfsnz WREG,F |
623 | 389 bra sensor_int_state1 ; do state 7 |
390 | |
391 ; first, do state 2: | |
392 call get_pressure_value ; state 2: get pressure (51 us) | |
393 call get_temperature_start ; and start temperature integration (73.5 us) | |
394 call calculate_compensation ; calculate temperature compensated pressure (27 us) | |
0 | 395 |
634 | 396 ; build average for pressure |
623 | 397 bcf STATUS,C ; clear carry bit |
398 rrcf pressure_abs_avg+1 ; divide by 2 | |
634 | 399 rrcf pressure_abs_avg+0 ; ... |
623 | 400 bcf STATUS,C ; clear carry bit |
401 rrcf pressure_abs_avg+1 ; divide by 2, again | |
634 | 402 rrcf pressure_abs_avg+0 ; ... |
623 | 403 |
634 | 404 ; export averaged pressure |
405 MOVII pressure_abs_avg,pressure_abs ; export result | |
0 | 406 |
634 | 407 ; build average for temperature |
623 | 408 bcf STATUS,C ; clear carry bit by default |
409 btfsc temperature_avg+1,7 ; sign bit set? | |
410 bsf STATUS,C ; YES - copy sign bit to carry bit | |
411 rrcf temperature_avg+1 ; divide signed temperature by 2 | |
412 rrcf temperature_avg+0 ; ... | |
413 bcf STATUS,C ; clear carry bit by default | |
414 btfsc temperature_avg+1,7 ; sign bit set? | |
415 bsf STATUS,C ; YES - copy sign bit to carry bit | |
416 rrcf temperature_avg+1 ; divide signed temperature by 2 again (by 4 in total now) | |
417 rrcf temperature_avg+0 ; ... | |
418 MOVII temperature_avg,temperature_cur ; store final result | |
0 | 419 |
634 | 420 ; check for temperature change |
623 | 421 movf temperature_cur+0,W ; get current temperature, low byte |
422 cpfseq temperature_last+0 ; compare with last temperature, equal? | |
423 bra isr_sensor_state2_2 ; NO - temperature has changed | |
424 movf temperature_cur+1,W ; get current temperature, high byte | |
425 cpfseq temperature_last+1 ; compare with last temperature, equal? | |
426 bra isr_sensor_state2_2 ; NO - temperature has changed | |
427 bra isr_sensor_state2_3 ; YES to both - no change | |
0 | 428 |
429 isr_sensor_state2_2: | |
623 | 430 MOVII temperature_cur,temperature_last ; store current temperature as last temperature for next round |
431 bsf trigger_temp_changed ; set flag for temperature change | |
432 | |
0 | 433 isr_sensor_state2_3: |
629 | 434 ; reset state counter |
623 | 435 clrf sensor_state_counter ; reset state counter |
436 btfss reset_max_pressure ; shall clear the max pressure? | |
437 bra isr_sensor_state2_3a ; NO - continue with checking for pressure change | |
438 bcf reset_max_pressure ; YES - clear request flag | |
439 CLRI pressure_rel_max ; - clear max. pressure | |
0 | 440 |
623 | 441 isr_sensor_state2_3a: |
442 ; check for pressure change | |
443 movf pressure_abs+0,W ; get current pressure, low byte | |
444 cpfseq pressure_abs_last+0 ; compare with last pressure, equal? | |
445 bra isr_sensor_state2_4 ; NO - pressure has changed | |
446 movf pressure_abs+1,W ; YES - get current pressure, high byte | |
447 cpfseq pressure_abs_last+1 ; - compare with last pressure, equal? | |
448 bra isr_sensor_state2_4 ; NO - pressure has changed | |
449 bra isr_sensor_state2_5 ; YES - no change | |
450 | |
451 isr_sensor_state2_4: | |
452 MOVII pressure_abs,pressure_abs_last ; store current pressure as last pressure for next round | |
453 bsf trigger_pres_cur_changed ; signal a pressure change | |
454 | |
455 isr_sensor_state2_5: | |
456 ; compute relative pressure | |
457 movf pressure_surf+0,W ; get surface pressure, low byte | |
458 subwf pressure_abs+0,W ; WREG = pressure_abs - pressure_surf (low byte) | |
459 movwf pressure_rel_cur+0 ; store relative pressure, low byte | |
460 movf pressure_surf+1,W ; get surface pressure, high byte | |
461 subwfb pressure_abs+1,W ; WREG = pressure_abs - pressure_surf (high byte) | |
462 movwf pressure_rel_cur+1 ; store relative pressure, high byte | |
463 btfss STATUS,N ; relative pressure < 0 ? | |
464 bra isr_sensor_state2_6 ; NO - OK, keep result | |
465 CLRI pressure_rel_cur ; YES - set relative pressure to zero | |
0 | 466 |
623 | 467 isr_sensor_state2_6: |
468 ; check for new max relative pressure | |
469 movf pressure_rel_cur+0,W ; get current relative pressure, low byte | |
470 subwf pressure_rel_max+0,W ; WREG = pressure_rel_max - pressure_rel_cur (low byte) | |
471 movf pressure_rel_cur+1,W ; get current relative pressure, high byte | |
472 subwfb pressure_rel_max+1,W ; WREG = pressure_rel_max - pressure_rel_cur (high byte) | |
473 btfss STATUS,N ; result < 0, i.e. new max rel pressure? | |
474 bra isr_sensor_state2_6a ; NO | |
475 MOVII pressure_rel_cur,pressure_rel_max ; YES - set new max rel pressure | |
476 bsf trigger_pres_max_changed ; - signal a pressure max change | |
477 | |
478 isr_sensor_state2_6a: | |
0 | 479 |
623 | 480 IFDEF _min_depth_option |
481 ; check if min/max pressures shall be reset | |
482 btfss reset_trip_pressure ; shall reset the resettable min/max pressures? | |
483 bra isr_sensor_state2_6b ; NO | |
484 bcf reset_trip_pressure ; YES - clear request flag | |
485 CLRI pressure_rel_max_trip ; - set max pressure to zero | |
486 SETI pressure_rel_min_trip ; - set min pressure to biggest value possible | |
487 isr_sensor_state2_6b: | |
488 ; check for new resettable max relative pressure | |
489 movf pressure_rel_cur+0,W ; get current relative pressure, low byte | |
490 subwf pressure_rel_max_trip+0,W ; WREG = pressure_rel_max - pressure_rel_cur (low byte) | |
491 movf pressure_rel_cur+1,W ; get current relative pressure, high byte | |
492 subwfb pressure_rel_max_trip+1,W ; WREG = pressure_rel_max - pressure_rel_cur (high byte) | |
493 btfss STATUS,N ; result < 0, i.e. new max rel pressure? | |
494 bra isr_sensor_state2_6c ; NO - continue checking for min depth | |
495 MOVII pressure_rel_cur,pressure_rel_max_trip ; YES - set new max rel pressure | |
496 isr_sensor_state2_6c: | |
497 ; check for new resettable min relative pressure | |
498 movf pressure_rel_cur+0,W ; get current relative pressure, low byte | |
499 subwf pressure_rel_min_trip+0,W ; WREG = pressure_rel_min - pressure_rel_cur (low byte) | |
500 movf pressure_rel_cur+1,W ; get current relative pressure, high byte | |
501 subwfb pressure_rel_min_trip+1,W ; WREG = pressure_rel_min - pressure_rel_cur (high byte) | |
502 btfss STATUS,C ; result > 0, i.e. new min rel pressure? | |
503 bra sensor_int_state_exit ; NO - done | |
504 MOVII pressure_rel_cur,pressure_rel_min_trip ; YES - set new min rel pressure | |
505 ENDIF ; _min_depth_option | |
506 bra sensor_int_state_exit ; done | |
0 | 507 |
508 sensor_int_state1_plus_restart: | |
634 | 509 CLRI pressure_abs_avg ; clear average register for pressure |
510 CLRI temperature_avg ; clear average register for temperature | |
0 | 511 |
512 sensor_int_state1: | |
604 | 513 call get_temperature_value ; state 1: get temperature... |
514 call get_pressure_start ; ...and start pressure integration | |
582 | 515 bra sensor_int_state_exit |
0 | 516 |
517 sensor_int_state2: | |
604 | 518 call get_pressure_value ; state 2: get pressure (51 us)... |
519 call get_temperature_start ; ...and start temperature integration (73.5 us) | |
520 call calculate_compensation ; .. and calculate temperature compensated pressure (233 us) | |
582 | 521 |
0 | 522 sensor_int_state_exit: |
634 | 523 bcf PIR5,TMR7IF ; clear IRQ flag |
524 bsf PIE5,TMR7IE ; re-enable IRQs by TMR7 | |
623 | 525 bra isr_adjust_speed ; set/restore CPU speed and return |
526 | |
527 | |
634 | 528 ;----------------------------------------------------------------------------- |
529 ; Helper Function for Display Dimming | |
530 ; | |
623 | 531 isr_dimm_tft: ; adjust until max_CCPR1L = CCPR1L |
628 | 532 btfsc screen_type3 ; screen type 3 ? |
533 return ; YES - ignore, no dimming function with screen type 3 | |
623 | 534 btfsc tft_is_dimming ; is the display dimming? |
535 return ; YES - ignore | |
536 movf max_CCPR1L,W ; NO - proceed | |
628 | 537 cpfsgt CCPR1L ; - CCPR1L > max_CCPR1L ? |
538 bra isr_dimm_tft2 ; NO - dim up | |
539 decf CCPR1L,F ; YES - dim down | |
540 return ; - done | |
623 | 541 isr_dimm_tft2: |
628 | 542 movf max_CCPR1L,W ; |
543 sublw ambient_light_min_eco ; | |
623 | 544 cpfsgt CCPR1L ; CCPR1L > max_CCPR1L - ambient_light_min_eco ? |
545 bra isr_dimm_tft3 ; NO - dim up slow | |
628 | 546 movlw .10 ; YES - dim up faster (+10) |
547 addwf CCPR1L,F ; - add to dimming value | |
623 | 548 isr_dimm_tft3: |
628 | 549 incf CCPR1L,F ; - dim up (+1) |
550 return ; - done | |
623 | 551 |
582 | 552 |
634 | 553 ;----------------------------------------------------------------------------- |
554 ; RTC Interrupt (invoked every 0.5 Seconds) | |
623 | 555 ; |
556 isr_rtcc: | |
557 bcf PIR3,RTCCIF ; clear flag | |
558 bsf trigger_half_second ; set flag for a new 1/2 second has begun | |
559 btfsc reset_timebase ; shall reset the timebase? | |
560 bra isr_rtcc_1 ; YES - warp to new full second | |
561 btg timebase_0sec ; NO - toggle the 1/2 second timebase | |
562 btfsc timebase_0sec ; - did it toggled 1 -> 0 ? | |
563 return ; NO - on half second, done | |
0 | 564 |
623 | 565 isr_rtcc_1: |
566 ; new full second | |
567 bsf trigger_full_second ; set flag for a new 1/1 second has begun | |
568 | |
569 btfsc block_rtc_access ; ISR suspended from accessing the RTC? | |
570 bra isr_rtcc_2 ; YES | |
571 | |
572 banksel RTCCFG ; RTC registers are outside access RAM | |
582 | 573 bsf RTCCFG,RTCPTR1 |
623 | 574 bsf RTCCFG,RTCPTR0 |
575 banksel isr_backup ; back to ISR default bank | |
576 | |
577 movff RTCVALL,rtc_year ; read year in BCD | |
578 movff RTCVALH,rtc_day ; dummy read | |
579 movff RTCVALL,rtc_day ; read day in BCD | |
580 movff RTCVALH,rtc_month ; read month in BCD | |
581 movff RTCVALL,rtc_hour ; read hour in BCD | |
582 movff RTCVALH,rtc_secs ; dummy read | |
583 movff RTCVALL,rtc_secs ; read seconds in BCD | |
584 movff RTCVALH,rtc_mins ; read minutes in BCD | |
582 | 585 |
634 | 586 ; convert BCD to DEC and set registers |
623 | 587 movf rtc_mins,W |
588 rcall isr_rtcc_convert_BCD_DEC ; convert to decimal with result in WREG | |
589 movwf rtc_mins | |
590 movf rtc_secs,W | |
591 rcall isr_rtcc_convert_BCD_DEC ; convert to decimal with result in WREG | |
592 movwf rtc_secs | |
593 movf rtc_hour,W | |
594 rcall isr_rtcc_convert_BCD_DEC ; convert to decimal with result in WREG | |
595 movwf rtc_hour | |
596 movf rtc_month,W | |
597 rcall isr_rtcc_convert_BCD_DEC ; convert to decimal with result in WREG | |
598 movwf rtc_month | |
599 movf rtc_day,W | |
600 rcall isr_rtcc_convert_BCD_DEC ; convert to decimal with result in WREG | |
601 movwf rtc_day | |
602 movf rtc_year,W | |
603 rcall isr_rtcc_convert_BCD_DEC ; convert to decimal with result in WREG | |
604 movwf rtc_year | |
605 | |
606 isr_rtcc_2: | |
629 | 607 ; every full second - get ambient light level and set max_CCPR1L |
623 | 608 call get_ambient_level ; get ambient light level and set max_CCPR1L |
609 banksel isr_backup ; back to ISR default bank (for safety only) | |
610 | |
611 rcall isr_battery_gauge ; calculate the current charge consumption and add it to the battery gauge | |
612 rcall isr_update_uptime ; increment overall OSTC uptime | |
613 rcall isr_update_timeout ; process the timeout timer | |
614 | |
615 btfsc divemode ; in dive mode? | |
616 rcall isr_divemode_1sec ; YES - do the every second dive mode tasks | |
617 | |
629 | 618 ; increment surface interval counted in seconds |
623 | 619 btfsc divemode ; in dive mode? |
620 btfsc simulatormode ; YES - in simulator mode? | |
629 | 621 rcall inc_surface_interval_secs ; NO - YES - increment the surface interval (seconds timer) |
622 | |
623 ; reset the surface interval timers if requested | |
624 btfsc reset_surface_interval ; shall reset both surface interval timers? | |
634 | 625 rcall rst_surface_interval ; YES |
0 | 626 |
623 | 627 ; reset the timebase if requested |
628 btfss reset_timebase ; shall reset the timebase? | |
629 bra isr_rtcc_3 ; NO | |
630 bcf reset_timebase ; YES - clear request flag | |
631 clrf eventbase ; - clear all pending events | |
632 clrf timebase ; - clear all timebase flags | |
633 clrf timebase_secs ; - clear seconds timer | |
634 clrf timebase_mins ; - clear minutes timer | |
635 clrf simulator_time ; - clear minutes timer of simulator runtime as well | |
636 bsf trigger_half_second ; - set flag for a new 1/2 second has begun | |
637 bsf trigger_full_second ; - set flag for a new 1/1 second has begun | |
638 return ; - done | |
639 | |
640 isr_rtcc_3: | |
641 ; count-up the 2 seconds timebase timer | |
642 btg timebase_1sec ; toggle the 1 second timer bit | |
643 btfss timebase_1sec ; did it toggled 1 -> 0 ? | |
644 btg timebase_2sec ; YES - toggle the 2 seconds timer bit | |
645 | |
646 ; count-up the seconds timer | |
647 incf timebase_secs,F ; increment seconds timer (may temporary become 60 here) | |
648 movlw .59 ; max. for seconds timer | |
649 cpfsgt timebase_secs ; seconds timer > max.? | |
650 return ; NO - done | |
0 | 651 |
623 | 652 ; new full minute |
629 | 653 clrf timebase_secs ; reset timer |
654 bsf trigger_full_minute ; set flag for a new minute has begun | |
623 | 655 |
629 | 656 ; increment surface interval counted in minutes |
657 btfsc divemode ; in dive mode? | |
658 btfsc simulatormode ; YES - in simulator mode? | |
659 rcall inc_surface_interval_mins ; NO - YES - increment surface interval (minutes timer) | |
623 | 660 |
629 | 661 btfss simulatormode ; in simulator mode? |
662 bra isr_rtcc_4 ; NO | |
663 infsnz simulator_time,F ; YES - increment real runtime of the simulator, did wrap around (became zero)? | |
664 setf simulator_time ; YES - disallow wrap-around, keep at 255 instead | |
0 | 665 |
623 | 666 isr_rtcc_4: |
629 | 667 incf timebase_mins,F ; increment minutes timer |
668 movlw .59 ; max. for minutes timer | |
669 cpfsgt timebase_mins ; minutes timer > max.? | |
670 return ; NO - done | |
623 | 671 |
672 ; new full hour | |
629 | 673 clrf timebase_mins ; YES - reset timer |
674 bsf trigger_full_hour ; - set flag for a new hour has begun | |
675 return ; - done | |
623 | 676 |
677 ; increment overall OSTC uptime | |
678 isr_update_uptime: | |
634 | 679 incf uptime+0,F ; uptime++ |
680 clrf WREG ; ... | |
681 addwfc uptime+1,F ; ... | |
682 addwfc uptime+2,F ; ... | |
683 addwfc uptime+3,F ; ... | |
684 return ; done | |
582 | 685 |
623 | 686 ; process the timeout timer |
687 isr_update_timeout: | |
634 | 688 btfsc restart_timeout ; shall restart the timeout? |
623 | 689 bra isr_update_timeout_1 ; YES |
690 tstfsz isr_timeout_timer ; NO - timeout timer already at zero? | |
634 | 691 decfsz isr_timeout_timer,F ; NO - decrement timer, reached zero now? |
623 | 692 return ; YES / NO - nothing further to do |
693 bsf trigger_timeout ; YES - set timeout flag | |
694 return ; - done | |
695 isr_update_timeout_1: | |
634 | 696 bcf restart_timeout ; clear request flag |
623 | 697 bcf trigger_timeout ; clear pending timeout trigger, if any |
698 movff isr_timeout_reload,isr_timeout_timer ; reload timer | |
699 return ; done | |
0 | 700 |
634 | 701 |
702 ;----------------------------------------------------------------------------- | |
703 ; Calculate Charge drawn from the Battery | |
623 | 704 ; |
705 isr_battery_gauge: | |
706 btfsc block_battery_gauge ; access to battery gauge suspended? | |
707 return ; YES - done | |
708 MOVLI current_sleepmode,isr_mpr ; NO - default to sleep mode with 100µA/3600 -> nAs | |
709 btfss sleepmode ; - in sleep mode? | |
634 | 710 rcall isr_battery_gauge2 ; NO - compute current consumption into isr_lo and isr_hi |
711 movf isr_mpr+0,W ; - 48 bit add of isr_mpr:2 to battery_gauge:6 | |
712 addwf battery_gauge+0,F ; - ... | |
713 movf isr_mpr+1,W ; - ... | |
714 addwfc battery_gauge+1,F ; - ... | |
715 clrf WREG ; - ... | |
716 addwfc battery_gauge+2,F ; - ... | |
717 addwfc battery_gauge+3,F ; - ... | |
718 addwfc battery_gauge+4,F ; - ... | |
719 addwfc battery_gauge+5,F ; - ... | |
720 return ; - done | |
582 | 721 |
634 | 722 |
723 ;----------------------------------------------------------------------------- | |
724 ; Helper Function - compute current Consumption | |
725 ; | |
0 | 726 isr_battery_gauge2: |
634 | 727 ; Set consumption rate in nAs (nano Ampere x seconds) |
0 | 728 ; Example: |
623 | 729 ; MOVLI .55556,isr_mpr ; 0.2 Ah / 3600 seconds per hour * 1e9s = nAs |
730 ; | |
731 ; Remark: although all the constants are named current_xxxx, in reality they mean charge! | |
0 | 732 |
623 | 733 ; Calculate current consumption for LED backlight: 47*CCPR1L+272 (according to values in hwos.inc: 115*CCPR1L+216) |
631 | 734 movlw .70 ; screen type 3 has a fix backlight current slope |
735 btfss screen_type3 ; does the OSTC have a screen type 3 ? | |
736 movf CCPR1L,W ; NO - for screen types 0, 1 and 2 get the slope from CCPR1L | |
737 mullw current_backlight_multi ; multiply with backlight factor current_backlight_multi | |
738 ADDLI current_backlight_offset,PRODL ; add backlight offset current_backlight_offset | |
623 | 739 MOVII PRODL,isr_mpr ; copy result to isr_mpr |
0 | 740 |
634 | 741 ; add current for CPU and GPU |
623 | 742 ; cpu_speed_state = ECO 3.10 mA -> 861 nAs |
743 ; = NORMAL 5.50 mA -> 1528 nAs | |
744 ; = FASTEST 8.04 mA -> 2233 nAs | |
745 btfss speed_is_eco ; speed = eco ? | |
746 bra isr_battery_gauge3 ; NO | |
747 ADDLI current_speed_eco,isr_mpr ; YES - add current_speed_eco to isr_mpr | |
582 | 748 bra isr_battery_gauge5 |
0 | 749 isr_battery_gauge3: |
623 | 750 btfss speed_is_normal ; speed = normal? |
751 bra isr_battery_gauge4 ; NO | |
752 ADDLI current_speed_normal,isr_mpr ; YES - add current_speed_normal to isr_mpr | |
582 | 753 bra isr_battery_gauge5 |
0 | 754 isr_battery_gauge4: |
623 | 755 ADDLI current_speed_fastest,isr_mpr ; speed is fastest, add current_speed_fastest to isr_mpr |
0 | 756 isr_battery_gauge5: |
623 | 757 btfss ir_power ; IR enabled? |
758 bra isr_battery_gauge6 ; NO | |
759 ADDLI current_ir_receiver,isr_mpr ; YES - add current_ir_receiver to isr_mpr | |
0 | 760 isr_battery_gauge6: |
623 | 761 btfss compass_enabled ; compass active? |
762 bra isr_battery_gauge7 ; NO | |
763 ADDLI current_compass,isr_mpr ; YES - add current_compass to isr_mpr | |
0 | 764 isr_battery_gauge7: |
634 | 765 return ; done |
0 | 766 |
623 | 767 |
634 | 768 ;----------------------------------------------------------------------------- |
769 ; Every Second Tasks while in Dive Mode | |
623 | 770 ; |
0 | 771 isr_divemode_1sec: |
623 | 772 decfsz sampling_timer,F ; decrement sampling timer, became zero? |
773 bra isr_divemode_1sec_1 ; NO | |
774 bsf trigger_sample_divedata ; YES - set trigger flag for sampling dive data | |
775 movff sampling_rate,sampling_timer; - reload timer | |
0 | 776 |
623 | 777 isr_divemode_1sec_1: |
778 btfss reset_timebase ; shall reset the timebase? (request flag will be cleared later) | |
779 bra isr_divemode_1sec_2 ; NO | |
780 CLRI total_divetime_secs ; YES - reset total dive time, seconds (2 byte) | |
781 clrf counted_divetime_secs ; - reset counted dive time, seconds (1 byte) | |
782 CLRI counted_divetime_mins ; - reset counted dive time, minutes (2 byte) | |
783 clrf apnoe_dive_secs ; - reset apnoe dive time, seconds (1 byte) | |
784 clrf apnoe_dive_mins ; - reset apnoe dive time, minutes (1 byte) | |
785 bcf apnoe_at_surface ; - apnoe mode starts in submerged state | |
786 return ; - done | |
582 | 787 |
623 | 788 isr_divemode_1sec_2: |
789 INCI total_divetime_secs ; increase total dive time (regardless of start_dive_threshold) | |
790 btfss count_divetime ; shall the dive time be counted (regarding start_dive_threshold)? | |
629 | 791 bra isr_divemode_1sec_4 ; NO - too shallow / apnoe at surface |
623 | 792 incf counted_divetime_secs,F ; YES - increase dive time (displayed dive time) |
793 movlw d'59' ; - 60 seconds make a minute | |
794 cpfsgt counted_divetime_secs ; - next full minute reached? | |
629 | 795 bra isr_divemode_1sec_3 ; NO - continue |
623 | 796 clrf counted_divetime_secs ; YES - reset seconds to 0 |
797 INCI counted_divetime_mins ; - increase dive minutes | |
798 bsf divetime_longer_1min ; - set flag for dive time exceeding 1 minute | |
629 | 799 ;bra isr_divemode_1sec_3 ; - continue |
0 | 800 |
623 | 801 isr_divemode_1sec_3: ; submerged |
802 btfss FLAG_apnoe_mode ; in apnoe mode? | |
803 return ; NO - done | |
804 btfss apnoe_at_surface ; - been at surface before? | |
805 bra isr_divemode_1sec_3a ; NO - increment the dive time | |
806 bcf apnoe_at_surface ; YES - a new dive has begun | |
807 bsf apnoe_new_dive ; - signal a new dive has begun | |
808 clrf apnoe_surface_secs ; - clear surface seconds | |
809 clrf apnoe_surface_mins ; - clear surface minutes | |
810 clrf apnoe_dive_secs ; - clear dive seconds | |
811 clrf apnoe_dive_mins ; - clear dive minutes | |
812 MOVII pressure_rel_cur,pressure_rel_max ; - reset max pressure to current pressure | |
813 bsf trigger_pres_max_changed ; - signal a new maximum pressure | |
814 isr_divemode_1sec_3a: | |
815 incf apnoe_dive_secs,F ; increment dive time, seconds | |
816 movlw d'59' ; 60 seconds make a minute | |
817 cpfsgt apnoe_dive_secs ; next full minute reached? | |
818 return ; NO - done | |
819 clrf apnoe_dive_secs ; YES - reset seconds to 0 | |
820 incf apnoe_dive_mins,F ; - increment dive time, minutes | |
821 return ; - done | |
0 | 822 |
623 | 823 isr_divemode_1sec_4: ; at surface |
824 btfss FLAG_apnoe_mode ; in apnoe mode? | |
825 return ; NO - done | |
826 bsf apnoe_at_surface ; YES - memorize been at the surface | |
827 incf apnoe_surface_secs,F ; - increment surface time, seconds | |
828 movlw d'59' ; - 60 seconds make a minute | |
829 cpfsgt apnoe_surface_secs ; - next full minute reached? | |
830 return ; NO - done | |
831 clrf apnoe_surface_secs ; YES - reset seconds to 0 | |
832 incf apnoe_surface_mins,F ; - increment surface time, minutes | |
833 return ; - done | |
834 | |
835 | |
634 | 836 ;----------------------------------------------------------------------------- |
837 ; Helper Function - BCD to Binary conversion | |
838 ; | |
623 | 839 ; Input WREG = value in BCD |
840 ; Output WREG = value in binary | |
841 ; | |
842 isr_rtcc_convert_BCD_DEC: | |
634 | 843 movwf isr_lo ; copy BCD to isr_lo |
844 swapf isr_lo, W ; create swapped copy in WREG | |
845 andlw 0x0F ; keep only the tens | |
846 rlncf WREG, W ; WREG = 2 * tens | |
623 | 847 subwf isr_lo, F ; 16 * tens + ones - 2*tens |
848 subwf isr_lo, F ; 14 * tens + ones - 2*tens | |
849 subwf isr_lo, W ; 12 * tens + ones - 2*tens | |
634 | 850 return ; done |
0 | 851 |
852 | |
634 | 853 ;----------------------------------------------------------------------------- |
854 ; Check Buttons | |
623 | 855 ; |
582 | 856 isr_switch_right: |
634 | 857 bcf INTCON,INT0IE ; clear external interrupt 0 |
582 | 858 btfss flip_screen ; 180° flipped? |
634 | 859 bsf switch_right ; NO - set flag for right button |
582 | 860 btfsc flip_screen ; 180° flipped? |
634 | 861 bsf switch_left ; YES - set flag for left button |
862 bra isr_switch_common ; continue with common part | |
0 | 863 |
582 | 864 isr_switch_left: |
634 | 865 bcf INTCON3,INT1IE ; clear external interrupt 1 |
582 | 866 btfss flip_screen ; 180° flipped? |
634 | 867 bsf switch_left ; NO - set flag for left button |
582 | 868 btfsc flip_screen ; 180° flipped? |
634 | 869 bsf switch_right ; YES - set flag for right button |
870 ;bra isr_switch_common ; continue with common part | |
623 | 871 |
0 | 872 isr_switch_common: |
634 | 873 btfsc tmr5_preemtion_allowed ; timer 5 preemption allowed? |
874 bsf PIR5,TMR5IF ; YES - preempt timer 5 | |
875 movlw TMR1H_VALUE_FIRST ; load timer 1 (in steps of 7.8125 ms) | |
623 | 876 movwf TMR1H ; ... |
634 | 877 clrf TMR1L ; ... |
604 | 878 bsf T1CON,TMR1ON ; start timer 1 |
634 | 879 bcf INTCON3,INT1IF ; clear timer 1 IRQ request |
880 bcf INTCON,INT0IF ; clear timer 0 IRQ request | |
881 return ; done | |
0 | 882 |
623 | 883 |
634 | 884 ;----------------------------------------------------------------------------- |
885 ; Button hold-down Interrupt | |
623 | 886 ; |
0 | 887 timer1int: |
634 | 888 bcf PIR1,TMR1IF ; clear timer 1 IRQ request |
889 bcf INTCON,INT0IF ; clear timer 0 IRQ request | |
890 bcf INTCON3,INT1IF ; clear timer 1 IRQ request | |
891 | |
451 | 892 ; digital |
604 | 893 btfss switch_left1 ; left button hold-down? |
894 bra timer1int_left ; YES | |
895 btfss switch_right2 ; right button hold-down? | |
896 bra timer1int_right ; YES | |
582 | 897 |
623 | 898 ; analog |
604 | 899 btfsc analog_sw2_pressed ; left button hold-down? |
900 bra timer1int_left ; YES | |
901 btfsc analog_sw1_pressed ; right button hold-down? | |
902 bra timer1int_right ; YES | |
582 | 903 |
634 | 904 ; no button hold-down, stop timer 1 |
604 | 905 bcf T1CON,TMR1ON ; stop timer 1 |
634 | 906 bsf INTCON,INT0IE ; enable INT0 IRQ |
907 bsf INTCON3,INT1IE ; enable INT1 IRQ | |
451 | 908 return |
0 | 909 |
910 timer1int_left: | |
582 | 911 btfss flip_screen ; 180° flipped? |
634 | 912 bsf switch_left ; set flag for left button |
582 | 913 btfsc flip_screen ; 180° flipped? |
634 | 914 bsf switch_right ; set flag for right button |
604 | 915 bra timer1int_common ; continue |
623 | 916 |
0 | 917 timer1int_right: |
582 | 918 btfss flip_screen ; 180° flipped? |
634 | 919 bsf switch_right ; set flag for right button |
582 | 920 btfsc flip_screen ; 180° flipped? |
634 | 921 bsf switch_left ; set flag for left button |
623 | 922 ;bra timer1int_common ; continue |
923 | |
634 | 924 timer1int_common: ; load timer 1 for next button press |
623 | 925 movlw TMR1H_VALUE_CONT ; default to surface mode value |
926 btfsc divemode ; in dive mode? | |
927 movlw TMR1H_VALUE_CONT_DIVE ; YES - overwrite with dive mode value | |
928 movwf TMR1H ; write value to timer, high byte | |
634 | 929 clrf TMR1L ; write value to timer, low byte (zero) |
930 return ; done (timer1 kept running) | |
0 | 931 |
623 | 932 |
634 | 933 ;----------------------------------------------------------------------------- |
934 ; Increment Surface Interval (counted in minutes and in seconds) | |
623 | 935 ; |
936 ; int_O_desaturation_time is only computed while in start, surface mode, | |
629 | 937 ; menue_tree or ghostwriter. So the ISR may clock surface_interval_mins |
634 | 938 ; past the actual surface interval time. But TFT_surf_cv_lastdive will |
629 | 939 ; check int_O_desaturation_time and in case int_O_desaturation_time is |
940 ; zero it will not show surface_interval_mins but surface_interval_secs instead. | |
941 ; Thus the glitch will remain invisible. | |
623 | 942 ; |
634 | 943 inc_surface_interval_secs: ; called every second when not in dive mode |
944 incf surface_interval_secs+0,F ; increment the lowest byte | |
945 clrf WREG ; clear WREG | |
946 addwfc surface_interval_secs+1,F ; add carry from byte before, if it did wrap-around | |
947 addwfc surface_interval_secs+2,F ; add carry from byte before, if it did wrap-around | |
948 addwfc surface_interval_secs+3,F ; add carry from byte before, if it did wrap-around | |
949 return ; done | |
629 | 950 |
634 | 951 inc_surface_interval_mins: ; called every minute when not in dive mode |
952 movff int_O_desaturation_time+0,isr_lo ; get desaturation time, low byte | |
953 movff int_O_desaturation_time+1,WREG ; get desaturation time, high byte | |
954 iorwf isr_lo,W ; inclusive-or low & high byte, desaturation time = 0 ? | |
955 bz clr_surface_interval_mins ; YES - reset surface interval minutes counter | |
956 INCI surface_interval_mins ; NO - increment surface interval | |
957 return ; - done | |
629 | 958 |
631 | 959 rst_surface_interval: |
629 | 960 bcf reset_surface_interval ; reset request flag |
631 | 961 ; reset the surface interval counted in seconds |
629 | 962 clrf surface_interval_secs+0 ; reset surface interval (seconds), lowest byte |
963 clrf surface_interval_secs+1 ; ... | |
964 clrf surface_interval_secs+2 ; ... | |
965 clrf surface_interval_secs+3 ; reset surface interval (seconds), highest byte | |
631 | 966 ; reset the surface interval counted in minutes |
629 | 967 movff opt_diveTimeout,surface_interval_mins+0 ; set surface interval (minutes), low byte, to dive timeout offset |
968 clrf surface_interval_mins+1 ; reset surface interval (minutes), high byte | |
631 | 969 return ; done |
629 | 970 |
631 | 971 clr_surface_interval_mins: |
972 clrf surface_interval_mins+0 ; reset surface interval (minutes), low byte | |
973 clrf surface_interval_mins+1 ; reset surface interval (minutes), high byte | |
629 | 974 return ; done |
975 | |
634 | 976 ;----------------------------------------------------------------------------- |
0 | 977 |
582 | 978 END |