Mercurial > public > hwos_code
comparison src/isr.asm @ 634:4050675965ea
3.10 stable release
author | heinrichsweikamp |
---|---|
date | Tue, 28 Apr 2020 17:34:31 +0200 |
parents | 185ba2f91f59 |
children | 2737ddc643bb |
comparison
equal
deleted
inserted
replaced
633:690c48db7b5b | 634:4050675965ea |
---|---|
1 ;============================================================================= | 1 ;============================================================================= |
2 ; | 2 ; |
3 ; File isr.asm combined next generation V3.08.8 | 3 ; File isr.asm * combined next generation V3.09.5 |
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 ;============================================================================= |
14 #include "ms5541.inc" | 14 #include "ms5541.inc" |
15 #include "adc_lightsensor.inc" | 15 #include "adc_lightsensor.inc" |
16 | 16 |
17 extern restore_flash | 17 extern restore_flash |
18 | 18 |
19 | |
19 ;============================================================================= | 20 ;============================================================================= |
20 ; Code to be placed at fixed position | 21 ; Code to be placed at a fixed Position |
21 ; | 22 ; |
22 isr_high CODE 0x0008 ; high priority interrupts | 23 isr_high CODE 0x0008 ; high priority interrupts |
23 bra HighInt | 24 bra HighInt ; jump to ISR |
24 nop | 25 |
25 nop | 26 isr_low CODE 0x00018 ; low priority interrupts *** not used *** |
26 nop | 27 retfie FAST ; do an immediate return from IRQ |
27 nop | 28 ; |
28 nop | |
29 nop | |
30 bra HighInt | |
31 ; *** low priority interrupts are not used *** | |
32 isr_low CODE 0x00018 ; low priority interrupts | |
33 retfie FAST ; do an immediate return with restore of BSR, STATUS and WREG | |
34 | |
35 | |
36 ;============================================================================= | 29 ;============================================================================= |
37 ; Interrupt Dispatcher | 30 |
31 | |
32 ;----------------------------------------------------------------------------- | |
33 ; Interrupt Dispatcher Entry Point | |
38 ; | 34 ; |
39 HighInt: | 35 HighInt: |
40 ; initialize interrupt code | 36 ; initialize interrupt code |
41 banksel isr_backup ; default bank for all ISR code is bank ISR data | 37 banksel isr_backup ; default bank for all ISR code is bank ISR data |
42 movff PRODL,PROD_backup+0 ; back-up PRODL | 38 movff PRODL,PROD_backup+0 ; back-up PRODL |
76 movff PROD_backup+1,PRODH ; restore PRODH | 72 movff PROD_backup+1,PRODH ; restore PRODH |
77 bsf trigger_isr_updates ; signal that the ISR had kicked in | 73 bsf trigger_isr_updates ; signal that the ISR had kicked in |
78 retfie FAST ; return from interrupt restoring BSR, STATUS and WREG | 74 retfie FAST ; return from interrupt restoring BSR, STATUS and WREG |
79 | 75 |
80 | 76 |
81 ;============================================================================= | 77 ;----------------------------------------------------------------------------- |
82 ; CPU speed adjustment | 78 ; CPU Speed Adjustment |
83 ; | 79 ; |
84 isr_adjust_speed: | 80 isr_adjust_speed: |
85 movff cpu_speed_request,cpu_speed_state ; acknowledge CPU speed request | 81 movff cpu_speed_request,cpu_speed_state ; acknowledge CPU speed request |
86 | 82 |
87 btfsc speed_is_eco ; speed 'eco' requested? | 83 btfsc speed_is_eco ; speed 'eco' requested? |
123 ; and the next section which starts at 0x00080 !! | 119 ; and the next section which starts at 0x00080 !! |
124 ;nop | 120 ;nop |
125 | 121 |
126 block_0_code_end: ; marker to find end of code in block 0 in linker report file | 122 block_0_code_end: ; marker to find end of code in block 0 in linker report file |
127 | 123 |
124 | |
128 ;============================================================================= | 125 ;============================================================================= |
129 ; jump vector for the bootloader, placed at an appointed position here | 126 ; Code to be placed at a fixed Position: Jump-Vector for the Bootloader |
130 ; | 127 ; |
131 isr_restore CODE 0x00080 ; restore first flash page from EEPROM | 128 restore CODE 0x00080 ; restore first flash page from EEPROM |
129 | |
132 restore_flash_0x00080: | 130 restore_flash_0x00080: |
133 goto restore_flash | 131 goto restore_flash |
134 | 132 ; |
135 ;============================================================================= | 133 ;============================================================================= |
136 ; routines for handling digital-attached external sensors | 134 |
135 | |
136 ;============================================================================= | |
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 | |
137 ; | 144 ; |
138 IFDEF _external_sensor | 145 IFDEF _external_sensor |
139 | 146 |
140 ; Take a byte received on IR/S8 link and slot it into the RX buffer | |
141 ; | |
142 isr_uart2: | 147 isr_uart2: |
143 bcf PIR3,RC2IF ; Clear UART 2 interrupt flag | 148 bcf PIR3,RC2IF ; clear UART 2 interrupt flag |
144 banksel RCREG2 ; RC*2 is outside access RAM | 149 banksel RCREG2 ; RC*2 is outside access RAM |
145 movff RCREG2,isr_lo ; copy received byte to isr_lo | 150 movff RCREG2,isr_lo ; copy received byte to isr_lo |
146 bcf RCSTA2,CREN ; clear receiver status | 151 bcf RCSTA2,CREN ; clear receiver status |
147 bsf RCSTA2,CREN ; ... | 152 bsf RCSTA2,CREN ; ... |
148 banksel isr_backup ; back to default ISR bank | 153 banksel isr_backup ; back to default ISR bank |
154 lfsr FSR0,ir_s8_buffer ; - load base address of buffer | 159 lfsr FSR0,ir_s8_buffer ; - load base address of buffer |
155 movff isr_lo,PLUSW0 ; - store received byte | 160 movff isr_lo,PLUSW0 ; - store received byte |
156 MOVII FSR0_backup,FSR0L ; - restore FSR0 | 161 MOVII FSR0_backup,FSR0L ; - restore FSR0 |
157 incf ir_s8_counter,F ; - increment number of received bytes by 1 | 162 incf ir_s8_counter,F ; - increment number of received bytes by 1 |
158 isr_uart2_1: | 163 isr_uart2_1: |
159 clrf TMR3L ; reload timer 3 | 164 movlw .253 ; reload timer 3, high byte |
160 movlw .253 ; ... | |
161 movwf TMR3H ; ... | 165 movwf TMR3H ; ... |
162 bsf T3CON,TMR3ON ; (re)start timeout timer 3 | 166 clrf TMR3L ; reload timer 3, low byte |
163 return | 167 bsf T3CON,TMR3ON ; restart timer |
164 | 168 return ; done |
165 | 169 |
166 ; Timeout on IR/S8 link: check the checksum and gather the received data | 170 |
171 ;----------------------------------------------------------------------------- | |
172 ; Timeout on IR/S8 Link: check the Checksum and gather the received Data | |
167 ; | 173 ; |
168 isr_timer3: | 174 isr_timer3: |
169 bcf T3CON,TMR3ON ; stop timer 3 | 175 bcf T3CON,TMR3ON ; stop timer 3 |
170 movlw .15 | 176 movlw .15 ; a IR telegram has 15 bytes |
171 cpfseq ir_s8_counter ; got exactly 15 bytes? | 177 cpfseq ir_s8_counter ; got exactly 15 bytes? |
172 bra isr_timer3_1 ; NO - test for 16 bytes | 178 bra isr_timer3_1 ; NO - test for 16 bytes |
173 bra isr_timer3_ir ; YES - got 15 bytes, compute local checksum | 179 bra isr_timer3_ir ; YES - got 15 bytes, compute local checksum |
174 isr_timer3_1: | 180 isr_timer3_1: |
175 movlw .16 | 181 movlw .16 ; a IR telegram may also have 16 bytes, with last byte 0x00 |
176 cpfseq ir_s8_counter ; got exactly 16 bytes? | 182 cpfseq ir_s8_counter ; got exactly 16 bytes? |
177 bra isr_timer3_2 ; NO - test for 17 bytes | 183 bra isr_timer3_2 ; NO - test for 17 bytes |
178 tstfsz ir_s8_buffer+.15 ; YES - last byte = 0x00 ? | 184 tstfsz ir_s8_buffer+.15 ; YES - last byte = 0x00 ? |
179 bra isr_timer3_exit ; No - exit | 185 bra isr_timer3_exit ; NO - exit |
180 bra isr_timer3_ir ; YES - got 16 bytes, compute local checksum | 186 bra isr_timer3_ir ; YES - got 16 bytes, compute local checksum |
181 isr_timer3_2: | 187 isr_timer3_2: |
182 movlw .17 | 188 movlw .17 ; a S8 telegram has 17 bytes |
183 cpfseq ir_s8_counter ; got exactly 17 bytes? | 189 cpfseq ir_s8_counter ; got exactly 17 bytes? |
184 bra isr_timer3_exit ; NO - exit | 190 bra isr_timer3_exit ; NO - exit |
185 bra isr_timer3_s8 ; YES - S8 data | 191 bra isr_timer3_s8 ; YES - S8 data |
186 | 192 |
187 ; Process telegram received on IR link | 193 ; process telegram received on IR link |
188 isr_timer3_ir: | 194 isr_timer3_ir: |
189 movlw .12 ; checksum shall be computed for 1st and next 12 bytes | 195 movlw .12 ; compute checksum over 1st and next 12 bytes |
190 rcall compute_IR_S8_checksum ; compute checksum | 196 rcall compute_IR_S8_checksum ; compute checksum |
191 movf ir_s8_buffer+.13,W ; get low byte of the received checksum | 197 tstfsz ir_s8_counter ; checksum ok? |
192 cpfseq isr_mpr+0 ; = low byte of the calculated local checksum? | 198 bra isr_timer3_exit ; NO - discard data |
193 bra isr_timer3_exit ; NO - exit | 199 |
194 movf ir_s8_buffer+.14,W ; get high byte of the received checksum | 200 ; copy received data to respective variables |
195 cpfseq isr_mpr+1 ; = high byte of the calculated local checksum? | |
196 bra isr_timer3_exit ; NO - exit | |
197 ; YES to both - received telegram valid, copy data | |
198 | |
199 movff ir_s8_buffer+.1, hud_status_byte | 201 movff ir_s8_buffer+.1, hud_status_byte |
200 movff ir_s8_buffer+.2, sensor1_mv+0 | 202 movff ir_s8_buffer+.2, sensor1_mv+0 |
201 movff ir_s8_buffer+.3, sensor1_mv+1 | 203 movff ir_s8_buffer+.3, sensor1_mv+1 |
202 movff ir_s8_buffer+.4, sensor2_mv+0 | 204 movff ir_s8_buffer+.4, sensor2_mv+0 |
203 movff ir_s8_buffer+.5, sensor2_mv+1 | 205 movff ir_s8_buffer+.5, sensor2_mv+1 |
210 movff ir_s8_buffer+.12,hud_battery_mv+1 | 212 movff ir_s8_buffer+.12,hud_battery_mv+1 |
211 | 213 |
212 bsf hud_connection_ok ; set manually for hwHUD w/o the HUD module | 214 bsf hud_connection_ok ; set manually for hwHUD w/o the HUD module |
213 bra isr_timer3_reload ; reload timer and exit | 215 bra isr_timer3_reload ; reload timer and exit |
214 | 216 |
215 ; Process telegram received on S8 link | 217 ; process telegram received on S8 link |
216 isr_timer3_s8: | 218 isr_timer3_s8: |
217 movlw .14 ; checksum shall be computed for 1st and next 14 bytes | 219 movlw .14 ; compute checksum over 1st and next 14 bytes |
218 rcall compute_IR_S8_checksum ; compute checksum | 220 rcall compute_IR_S8_checksum ; compute checksum |
219 | 221 tstfsz ir_s8_counter ; checksum ok? |
220 movf ir_s8_buffer+.15,W ; get low byte of the received checksum | 222 bra isr_timer3_exit ; NO - discard data |
221 cpfseq isr_mpr+0 ; = low byte of the calculated local checksum? | 223 |
222 bra isr_timer3_exit ; NO - exit | 224 ; copy received data to respective variables |
223 movf ir_s8_buffer+.16,W ; get high byte of the received checksum | 225 movff ir_s8_buffer+.3, hud_status_byte ; also sets hud_connection_ok flag |
224 cpfseq isr_mpr+1 ; = high byte of the calculated local checksum? | |
225 bra isr_timer3_exit ; NO - exit | |
226 ; YES to both - received telegram valid, copy data | |
227 movff ir_s8_buffer+.3, hud_status_byte | |
228 movff ir_s8_buffer+.13,hud_battery_mv+0 | 226 movff ir_s8_buffer+.13,hud_battery_mv+0 |
229 movff ir_s8_buffer+.14,hud_battery_mv+1 | 227 movff ir_s8_buffer+.14,hud_battery_mv+1 |
230 | 228 |
231 btfsc trigger_S8_data_update ; last data already processed? | 229 ; btfsc trigger_S8_data_update ; last data already processed? |
232 bra isr_timer3_exit ; NO - skip copying new results (And not reload the timeout) | 230 ; bra isr_timer3_exit ; NO - skip copying new data (and not reload the timeout) |
233 bsf trigger_S8_data_update ; YES - set flag for new data available | 231 bsf trigger_S8_data_update ; YES - set flag for new data available |
234 | 232 |
235 ; - copy more data | 233 ; copy more received data to respective variables |
236 movff ir_s8_buffer+.4, s8_rawdata_sensor1+0 | 234 movff ir_s8_buffer+.4, s8_rawdata_sensor1+0 |
237 movff ir_s8_buffer+.5, s8_rawdata_sensor1+1 | 235 movff ir_s8_buffer+.5, s8_rawdata_sensor1+1 |
238 movff ir_s8_buffer+.6, s8_rawdata_sensor1+2 | 236 movff ir_s8_buffer+.6, s8_rawdata_sensor1+2 |
239 movff ir_s8_buffer+.7, s8_rawdata_sensor2+0 | 237 movff ir_s8_buffer+.7, s8_rawdata_sensor2+0 |
240 movff ir_s8_buffer+.8, s8_rawdata_sensor2+1 | 238 movff ir_s8_buffer+.8, s8_rawdata_sensor2+1 |
242 movff ir_s8_buffer+.10,s8_rawdata_sensor3+0 | 240 movff ir_s8_buffer+.10,s8_rawdata_sensor3+0 |
243 movff ir_s8_buffer+.11,s8_rawdata_sensor3+1 | 241 movff ir_s8_buffer+.11,s8_rawdata_sensor3+1 |
244 movff ir_s8_buffer+.12,s8_rawdata_sensor3+2 | 242 movff ir_s8_buffer+.12,s8_rawdata_sensor3+2 |
245 | 243 |
246 isr_timer3_reload: | 244 isr_timer3_reload: |
247 movlw ir_timeout_value ; in multiples of 62.5 ms | 245 movlw ir_timeout_value ; get timeout value (in multiples of 62.5 ms) |
248 movwf ir_s8_timeout ; reload timeout | 246 movwf ir_s8_timeout ; reload timeout counter |
249 isr_timer3_exit: | 247 isr_timer3_exit: |
250 clrf ir_s8_counter ; clear pointer | 248 clrf ir_s8_counter ; clear number of received bytes |
251 bcf PIR2,TMR3IF ; clear flag | 249 bcf PIR2,TMR3IF ; clear IRQ flag |
252 return | 250 return ; done |
253 | 251 |
254 | 252 |
255 ; compute checksum on data in RX buffer | 253 ;----------------------------------------------------------------------------- |
254 ; Helper Function - Compute Checksum on Data in RX Buffer | |
256 ; | 255 ; |
257 compute_IR_S8_checksum: | 256 compute_IR_S8_checksum: |
258 movwf ir_s8_counter ; initialize loop counter from WREG | 257 movwf ir_s8_counter ; initialize loop counter from WREG |
259 movff ir_s8_buffer+0,isr_mpr+0 ; initialize low byte of the local checksum with first byte in buffer | 258 MOVII FSR0L,FSR0_backup ; back-up FSR0 |
260 clrf isr_mpr+1 ; clear the high byte of the local checksum | 259 lfsr FSR0,ir_s8_buffer ; load base address of the receive buffer |
261 lfsr FSR0,ir_s8_buffer ; load base address of the 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 | |
262 compute_IR_S8_checksum_loop: | 262 compute_IR_S8_checksum_loop: |
263 movf PREINC0,W ; get next byte | 263 movf POSTINC0,W ; read next byte |
264 addwf isr_mpr+0,F ; add it to the to checksum, low byte | 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... | 265 movlw .0 ; no explicit data to add to the high byte... |
266 addwfc isr_mpr+1,F ; ... besides the carry | 266 addwfc isr_mpr+1,F ; ... besides the carry |
267 decfsz ir_s8_counter ; decrement number of bytes yet to do, all done? | 267 decfsz ir_s8_counter,F ; decrement number of bytes yet to do, all done? |
268 bra compute_IR_S8_checksum_loop ; NO - loop | 268 bra compute_IR_S8_checksum_loop ; NO - loop |
269 return ; YES - done | 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 | |
270 | 277 |
271 ENDIF ; _external_sensor | 278 ENDIF ; _external_sensor |
272 | 279 |
273 ;============================================================================= | 280 |
274 | 281 ;----------------------------------------------------------------------------- |
275 ;============================================================================= | 282 ; Tasks every 62.5 ms: Buttons, Dimming, Pressure/Temperature Sensor and CPU Speed |
276 ; Tasks every 62.5 ms: buttons, dimming, pressure/temp sensor and CPU speed | |
277 ; | 283 ; |
278 isr_tmr7: | 284 isr_tmr7: |
279 bcf PIR5,TMR7IF ; clear flag | 285 bcf PIE5,TMR7IE ; disable IRQs by TMR7 |
280 movlw .248 ; rollover after 248 cycles -> 62.5 ms | 286 |
281 movff WREG,TMR7H ; timer 7 is outside access RAM | 287 banksel 0xF16 ; TMR7H/L are not part of the access RAM |
282 | 288 movlw .248 ; reload timer 7, high byte (8x256 ticks -> 62.5 ms) |
283 call get_analog_switches ; get analog readings, CAUTION: returns in bank common | 289 movwf TMR7H ; ... (keep low byte running ) |
284 banksel isr_backup ;back to ISR default bank | 290 |
285 | 291 call get_analog_switches ; get analog readings - bank-safe, but CAUTION: returns in bank common |
286 btfss INTCON3,INT1IE | 292 banksel isr_backup ; back to ISR default bank |
287 bra isr_tmr7_a | 293 |
288 btfsc analog_sw2_pressed | 294 btfss INTCON3,INT1IE ; external IRQ 1 enabled? |
289 rcall isr_switch_left ; get digital readings of left switch | 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 | |
290 isr_tmr7_a: | 298 isr_tmr7_a: |
291 btfss INTCON,INT0IE | 299 btfss INTCON,INT0IE ; external IRQ 0 enabled? |
292 bra isr_tmr7_b | 300 bra isr_tmr7_b ; NO - skip next |
293 btfsc analog_sw1_pressed | 301 btfsc analog_sw1_pressed ; YES - analog switch 1 pressed? |
294 rcall isr_switch_right ; get digital readings of right switch | 302 rcall isr_switch_right ; NO - get digital readings of right switch |
295 isr_tmr7_b: | 303 isr_tmr7_b: |
296 btfss block_sensor_interrupt ; sensor interrupts disabled? | 304 btfss block_sensor_interrupt ; sensor interrupts disabled? |
297 bra isr_tmr7_c ; NO - continue | 305 bra isr_tmr7_c ; NO - continue |
298 return ; YES - done | 306 bra sensor_int_state_exit ; YES - goto exit |
299 isr_tmr7_c: | 307 isr_tmr7_c: |
300 movf max_CCPR1L,W ; dim value | 308 movf max_CCPR1L,W ; dim value |
301 cpfseq CCPR1L ; = current PWM value? | 309 cpfseq CCPR1L ; = current PWM value? |
302 rcall isr_dimm_tft ; NO - adjust until max_CCPR1L = CCPR1L | 310 rcall isr_dimm_tft ; NO - adjust until max_CCPR1L = CCPR1L |
303 | 311 |
304 IFDEF _external_sensor | 312 IFDEF _external_sensor |
305 decfsz ir_s8_timeout,F ; IR / S8 digital data still valid? | 313 decfsz ir_s8_timeout,F ; decrement IR/S8 timeout counter, became zero? |
306 bra isr_tmr7_2 ; YES - continue | 314 bra isr_tmr7_2 ; NO - continue |
307 movlw ir_timeout_value ; NO - get timer reload in multiples of 62.5 ms | 315 movlw ir_timeout_value ; YES - get timeout value (in multiples of 62.5 ms) |
308 movwf ir_s8_timeout ; - reload the timer | 316 movwf ir_s8_timeout ; - reload timeout timer |
309 btfss analog_o2_input ; - analog input available? | 317 btfsc ext_input_optical ; - optical input in use? |
310 bra isr_tmr7_1a ; NO - clear data | 318 bra isr_tmr7_1a ; YES - clear data |
311 btfss s8_digital_avail ; YES - S8 digital interface available? | 319 TSTOSS opt_s8_mode ; NO - S8 input in use? |
312 bra isr_tmr7_2 ; NO - must be analog interface in use, keep data | 320 bra isr_tmr7_2 ; NO - must be analog interface in use, keep data |
321 ;bra isr_tmr7_1a ; YES - clear data | |
322 | |
313 isr_tmr7_1a: | 323 isr_tmr7_1a: |
314 clrf hud_status_byte ; S8/IR timeout clears all analog input readings to zero -> fallback will be triggered when in sensor mode | 324 clrf hud_status_byte ; S8/IR timeout clears all analog input readings to zero -> fallback will be triggered when in sensor mode |
315 CLRI hud_battery_mv ; clear battery voltage | 325 CLRI hud_battery_mv ; clear battery voltage |
316 | 326 |
317 banksel sensor1_mv ; select bank where sensor data are stored | 327 banksel sensor1_mv ; select bank where sensor data are stored |
333 bsf trigger_S8_data_update ; signal a data update | 343 bsf trigger_S8_data_update ; signal a data update |
334 ENDIF | 344 ENDIF |
335 | 345 |
336 isr_tmr7_2: | 346 isr_tmr7_2: |
337 btfsc block_sensor_interrupt ; sensor interrupts disabled? | 347 btfsc block_sensor_interrupt ; sensor interrupts disabled? |
338 return ; YES - abort | 348 bra sensor_int_state_exit ; YES - goto exit |
339 | 349 |
340 isr_sensor_state2: | 350 isr_sensor_state2: |
341 btfss sensor_state_counter,0 ; every 1/4 second | 351 btfss sensor_state_counter,0 ; every 1/4 second |
342 bsf trigger_quarter_second ; set flag | 352 bsf trigger_quarter_second ; set flag |
343 | 353 |
381 ; first, do state 2: | 391 ; first, do state 2: |
382 call get_pressure_value ; state 2: get pressure (51 us) | 392 call get_pressure_value ; state 2: get pressure (51 us) |
383 call get_temperature_start ; and start temperature integration (73.5 us) | 393 call get_temperature_start ; and start temperature integration (73.5 us) |
384 call calculate_compensation ; calculate temperature compensated pressure (27 us) | 394 call calculate_compensation ; calculate temperature compensated pressure (27 us) |
385 | 395 |
386 ; build average for pressure | 396 ; build average for pressure |
387 bcf STATUS,C ; clear carry bit | 397 bcf STATUS,C ; clear carry bit |
388 rrcf pressure_abs_avg+1 ; divide by 2 | 398 rrcf pressure_abs_avg+1 ; divide by 2 |
389 rrcf pressure_abs_avg+0 | 399 rrcf pressure_abs_avg+0 ; ... |
390 bcf STATUS,C ; clear carry bit | 400 bcf STATUS,C ; clear carry bit |
391 rrcf pressure_abs_avg+1 ; divide by 2, again | 401 rrcf pressure_abs_avg+1 ; divide by 2, again |
392 rrcf pressure_abs_avg+0 | 402 rrcf pressure_abs_avg+0 ; ... |
393 | 403 |
394 ; copy into result register and set update flag | 404 ; export averaged pressure |
395 MOVII pressure_abs_avg,pressure_abs | 405 MOVII pressure_abs_avg,pressure_abs ; export result |
396 ; bsf trigger_pres_update ; signal a pressure update | 406 |
397 | 407 ; build average for temperature |
398 ; build average for temperature | |
399 bcf STATUS,C ; clear carry bit by default | 408 bcf STATUS,C ; clear carry bit by default |
400 btfsc temperature_avg+1,7 ; sign bit set? | 409 btfsc temperature_avg+1,7 ; sign bit set? |
401 bsf STATUS,C ; YES - copy sign bit to carry bit | 410 bsf STATUS,C ; YES - copy sign bit to carry bit |
402 rrcf temperature_avg+1 ; divide signed temperature by 2 | 411 rrcf temperature_avg+1 ; divide signed temperature by 2 |
403 rrcf temperature_avg+0 ; ... | 412 rrcf temperature_avg+0 ; ... |
406 bsf STATUS,C ; YES - copy sign bit to carry bit | 415 bsf STATUS,C ; YES - copy sign bit to carry bit |
407 rrcf temperature_avg+1 ; divide signed temperature by 2 again (by 4 in total now) | 416 rrcf temperature_avg+1 ; divide signed temperature by 2 again (by 4 in total now) |
408 rrcf temperature_avg+0 ; ... | 417 rrcf temperature_avg+0 ; ... |
409 MOVII temperature_avg,temperature_cur ; store final result | 418 MOVII temperature_avg,temperature_cur ; store final result |
410 | 419 |
411 ; check for temperature change | 420 ; check for temperature change |
412 movf temperature_cur+0,W ; get current temperature, low byte | 421 movf temperature_cur+0,W ; get current temperature, low byte |
413 cpfseq temperature_last+0 ; compare with last temperature, equal? | 422 cpfseq temperature_last+0 ; compare with last temperature, equal? |
414 bra isr_sensor_state2_2 ; NO - temperature has changed | 423 bra isr_sensor_state2_2 ; NO - temperature has changed |
415 movf temperature_cur+1,W ; get current temperature, high byte | 424 movf temperature_cur+1,W ; get current temperature, high byte |
416 cpfseq temperature_last+1 ; compare with last temperature, equal? | 425 cpfseq temperature_last+1 ; compare with last temperature, equal? |
494 bra sensor_int_state_exit ; NO - done | 503 bra sensor_int_state_exit ; NO - done |
495 MOVII pressure_rel_cur,pressure_rel_min_trip ; YES - set new min rel pressure | 504 MOVII pressure_rel_cur,pressure_rel_min_trip ; YES - set new min rel pressure |
496 ENDIF ; _min_depth_option | 505 ENDIF ; _min_depth_option |
497 bra sensor_int_state_exit ; done | 506 bra sensor_int_state_exit ; done |
498 | 507 |
499 | |
500 sensor_int_state1_plus_restart: | 508 sensor_int_state1_plus_restart: |
501 ; clear average registers | 509 CLRI pressure_abs_avg ; clear average register for pressure |
502 CLRI pressure_abs_avg | 510 CLRI temperature_avg ; clear average register for temperature |
503 CLRI temperature_avg | |
504 | 511 |
505 sensor_int_state1: | 512 sensor_int_state1: |
506 call get_temperature_value ; state 1: get temperature... | 513 call get_temperature_value ; state 1: get temperature... |
507 call get_pressure_start ; ...and start pressure integration | 514 call get_pressure_start ; ...and start pressure integration |
508 bra sensor_int_state_exit | 515 bra sensor_int_state_exit |
511 call get_pressure_value ; state 2: get pressure (51 us)... | 518 call get_pressure_value ; state 2: get pressure (51 us)... |
512 call get_temperature_start ; ...and start temperature integration (73.5 us) | 519 call get_temperature_start ; ...and start temperature integration (73.5 us) |
513 call calculate_compensation ; .. and calculate temperature compensated pressure (233 us) | 520 call calculate_compensation ; .. and calculate temperature compensated pressure (233 us) |
514 | 521 |
515 sensor_int_state_exit: | 522 sensor_int_state_exit: |
523 bcf PIR5,TMR7IF ; clear IRQ flag | |
524 bsf PIE5,TMR7IE ; re-enable IRQs by TMR7 | |
516 bra isr_adjust_speed ; set/restore CPU speed and return | 525 bra isr_adjust_speed ; set/restore CPU speed and return |
517 | 526 |
518 | 527 |
528 ;----------------------------------------------------------------------------- | |
529 ; Helper Function for Display Dimming | |
530 ; | |
519 isr_dimm_tft: ; adjust until max_CCPR1L = CCPR1L | 531 isr_dimm_tft: ; adjust until max_CCPR1L = CCPR1L |
520 btfsc screen_type3 ; screen type 3 ? | 532 btfsc screen_type3 ; screen type 3 ? |
521 return ; YES - ignore, no dimming function with screen type 3 | 533 return ; YES - ignore, no dimming function with screen type 3 |
522 btfsc tft_is_dimming ; is the display dimming? | 534 btfsc tft_is_dimming ; is the display dimming? |
523 return ; YES - ignore | 535 return ; YES - ignore |
536 isr_dimm_tft3: | 548 isr_dimm_tft3: |
537 incf CCPR1L,F ; - dim up (+1) | 549 incf CCPR1L,F ; - dim up (+1) |
538 return ; - done | 550 return ; - done |
539 | 551 |
540 | 552 |
541 ;============================================================================= | 553 ;----------------------------------------------------------------------------- |
542 ; RTC interrupt on every 1/2 second | 554 ; RTC Interrupt (invoked every 0.5 Seconds) |
543 ; | 555 ; |
544 isr_rtcc: | 556 isr_rtcc: |
545 bcf PIR3,RTCCIF ; clear flag | 557 bcf PIR3,RTCCIF ; clear flag |
546 bsf trigger_half_second ; set flag for a new 1/2 second has begun | 558 bsf trigger_half_second ; set flag for a new 1/2 second has begun |
547 btfsc reset_timebase ; shall reset the timebase? | 559 btfsc reset_timebase ; shall reset the timebase? |
569 movff RTCVALL,rtc_hour ; read hour in BCD | 581 movff RTCVALL,rtc_hour ; read hour in BCD |
570 movff RTCVALH,rtc_secs ; dummy read | 582 movff RTCVALH,rtc_secs ; dummy read |
571 movff RTCVALL,rtc_secs ; read seconds in BCD | 583 movff RTCVALL,rtc_secs ; read seconds in BCD |
572 movff RTCVALH,rtc_mins ; read minutes in BCD | 584 movff RTCVALH,rtc_mins ; read minutes in BCD |
573 | 585 |
574 ; Convert BCD to DEC and set registers | 586 ; convert BCD to DEC and set registers |
575 movf rtc_mins,W | 587 movf rtc_mins,W |
576 rcall isr_rtcc_convert_BCD_DEC ; convert to decimal with result in WREG | 588 rcall isr_rtcc_convert_BCD_DEC ; convert to decimal with result in WREG |
577 movwf rtc_mins | 589 movwf rtc_mins |
578 movf rtc_secs,W | 590 movf rtc_secs,W |
579 rcall isr_rtcc_convert_BCD_DEC ; convert to decimal with result in WREG | 591 rcall isr_rtcc_convert_BCD_DEC ; convert to decimal with result in WREG |
608 btfsc simulatormode ; YES - in simulator mode? | 620 btfsc simulatormode ; YES - in simulator mode? |
609 rcall inc_surface_interval_secs ; NO - YES - increment the surface interval (seconds timer) | 621 rcall inc_surface_interval_secs ; NO - YES - increment the surface interval (seconds timer) |
610 | 622 |
611 ; reset the surface interval timers if requested | 623 ; reset the surface interval timers if requested |
612 btfsc reset_surface_interval ; shall reset both surface interval timers? | 624 btfsc reset_surface_interval ; shall reset both surface interval timers? |
613 call rst_surface_interval ; YES | 625 rcall rst_surface_interval ; YES |
614 | 626 |
615 ; reset the timebase if requested | 627 ; reset the timebase if requested |
616 btfss reset_timebase ; shall reset the timebase? | 628 btfss reset_timebase ; shall reset the timebase? |
617 bra isr_rtcc_3 ; NO | 629 bra isr_rtcc_3 ; NO |
618 bcf reset_timebase ; YES - clear request flag | 630 bcf reset_timebase ; YES - clear request flag |
660 ; new full hour | 672 ; new full hour |
661 clrf timebase_mins ; YES - reset timer | 673 clrf timebase_mins ; YES - reset timer |
662 bsf trigger_full_hour ; - set flag for a new hour has begun | 674 bsf trigger_full_hour ; - set flag for a new hour has begun |
663 return ; - done | 675 return ; - done |
664 | 676 |
665 | |
666 ; increment overall OSTC uptime | 677 ; increment overall OSTC uptime |
667 isr_update_uptime: | 678 isr_update_uptime: |
668 incf uptime+0,F | 679 incf uptime+0,F ; uptime++ |
669 clrf WREG | 680 clrf WREG ; ... |
670 addwfc uptime+1,F | 681 addwfc uptime+1,F ; ... |
671 addwfc uptime+2,F | 682 addwfc uptime+2,F ; ... |
672 addwfc uptime+3,F | 683 addwfc uptime+3,F ; ... |
673 return | 684 return ; done |
674 | |
675 | 685 |
676 ; process the timeout timer | 686 ; process the timeout timer |
677 isr_update_timeout: | 687 isr_update_timeout: |
678 btfsc reset_timeout ; shall reset the timeout? | 688 btfsc restart_timeout ; shall restart the timeout? |
679 bra isr_update_timeout_1 ; YES | 689 bra isr_update_timeout_1 ; YES |
680 tstfsz isr_timeout_timer ; NO - timeout timer already at zero? | 690 tstfsz isr_timeout_timer ; NO - timeout timer already at zero? |
681 decfsz isr_timeout_timer ; NO - decrement timer, reached zero now? | 691 decfsz isr_timeout_timer,F ; NO - decrement timer, reached zero now? |
682 return ; YES / NO - nothing further to do | 692 return ; YES / NO - nothing further to do |
683 bsf trigger_timeout ; YES - set timeout flag | 693 bsf trigger_timeout ; YES - set timeout flag |
684 return ; - done | 694 return ; - done |
685 isr_update_timeout_1: | 695 isr_update_timeout_1: |
686 bcf reset_timeout ; clear request flag | 696 bcf restart_timeout ; clear request flag |
687 bcf trigger_timeout ; clear pending timeout trigger, if any | 697 bcf trigger_timeout ; clear pending timeout trigger, if any |
688 movff isr_timeout_reload,isr_timeout_timer ; reload timer | 698 movff isr_timeout_reload,isr_timeout_timer ; reload timer |
689 return ; done | 699 return ; done |
690 | 700 |
691 ;============================================================================= | 701 |
692 ; Calculate charge drawn from the battery | 702 ;----------------------------------------------------------------------------- |
703 ; Calculate Charge drawn from the Battery | |
693 ; | 704 ; |
694 isr_battery_gauge: | 705 isr_battery_gauge: |
695 btfsc block_battery_gauge ; access to battery gauge suspended? | 706 btfsc block_battery_gauge ; access to battery gauge suspended? |
696 return ; YES - done | 707 return ; YES - done |
697 MOVLI current_sleepmode,isr_mpr ; NO - default to sleep mode with 100ľA/3600 -> nAs | 708 MOVLI current_sleepmode,isr_mpr ; NO - default to sleep mode with 100ľA/3600 -> nAs |
698 btfss sleepmode ; - in sleep mode? | 709 btfss sleepmode ; - in sleep mode? |
699 rcall isr_battery_gauge2 ; NO - compute current consumption value into isr_lo and isr_hi | 710 rcall isr_battery_gauge2 ; NO - compute current consumption into isr_lo and isr_hi |
700 movf isr_mpr+0,W ; - 48 bit add of isr_mpr:2 with battery_gauge:6 | 711 movf isr_mpr+0,W ; - 48 bit add of isr_mpr:2 to battery_gauge:6 |
701 addwf battery_gauge+0,F | 712 addwf battery_gauge+0,F ; - ... |
702 movf isr_mpr+1,W | 713 movf isr_mpr+1,W ; - ... |
703 addwfc battery_gauge+1,F | 714 addwfc battery_gauge+1,F ; - ... |
704 clrf WREG | 715 clrf WREG ; - ... |
705 addwfc battery_gauge+2,F | 716 addwfc battery_gauge+2,F ; - ... |
706 addwfc battery_gauge+3,F | 717 addwfc battery_gauge+3,F ; - ... |
707 addwfc battery_gauge+4,F | 718 addwfc battery_gauge+4,F ; - ... |
708 addwfc battery_gauge+5,F | 719 addwfc battery_gauge+5,F ; - ... |
709 return | 720 return ; - done |
710 | 721 |
722 | |
723 ;----------------------------------------------------------------------------- | |
724 ; Helper Function - compute current Consumption | |
725 ; | |
711 isr_battery_gauge2: | 726 isr_battery_gauge2: |
712 ; set consumption rate in nAs - nano Ampere per second | 727 ; Set consumption rate in nAs (nano Ampere x seconds) |
713 ; Example: | 728 ; Example: |
714 ; MOVLI .55556,isr_mpr ; 0.2 Ah / 3600 seconds per hour * 1e9s = nAs | 729 ; MOVLI .55556,isr_mpr ; 0.2 Ah / 3600 seconds per hour * 1e9s = nAs |
715 ; | 730 ; |
716 ; Remark: although all the constants are named current_xxxx, in reality they mean charge! | 731 ; Remark: although all the constants are named current_xxxx, in reality they mean charge! |
717 | 732 |
721 movf CCPR1L,W ; NO - for screen types 0, 1 and 2 get the slope from CCPR1L | 736 movf CCPR1L,W ; NO - for screen types 0, 1 and 2 get the slope from CCPR1L |
722 mullw current_backlight_multi ; multiply with backlight factor current_backlight_multi | 737 mullw current_backlight_multi ; multiply with backlight factor current_backlight_multi |
723 ADDLI current_backlight_offset,PRODL ; add backlight offset current_backlight_offset | 738 ADDLI current_backlight_offset,PRODL ; add backlight offset current_backlight_offset |
724 MOVII PRODL,isr_mpr ; copy result to isr_mpr | 739 MOVII PRODL,isr_mpr ; copy result to isr_mpr |
725 | 740 |
726 ; Add current for CPU and GPU | 741 ; add current for CPU and GPU |
727 ; cpu_speed_state = ECO 3.10 mA -> 861 nAs | 742 ; cpu_speed_state = ECO 3.10 mA -> 861 nAs |
728 ; = NORMAL 5.50 mA -> 1528 nAs | 743 ; = NORMAL 5.50 mA -> 1528 nAs |
729 ; = FASTEST 8.04 mA -> 2233 nAs | 744 ; = FASTEST 8.04 mA -> 2233 nAs |
730 btfss speed_is_eco ; speed = eco ? | 745 btfss speed_is_eco ; speed = eco ? |
731 bra isr_battery_gauge3 ; NO | 746 bra isr_battery_gauge3 ; NO |
745 isr_battery_gauge6: | 760 isr_battery_gauge6: |
746 btfss compass_enabled ; compass active? | 761 btfss compass_enabled ; compass active? |
747 bra isr_battery_gauge7 ; NO | 762 bra isr_battery_gauge7 ; NO |
748 ADDLI current_compass,isr_mpr ; YES - add current_compass to isr_mpr | 763 ADDLI current_compass,isr_mpr ; YES - add current_compass to isr_mpr |
749 isr_battery_gauge7: | 764 isr_battery_gauge7: |
750 return | 765 return ; done |
751 | 766 |
752 | 767 |
753 ;============================================================================= | 768 ;----------------------------------------------------------------------------- |
754 ; Every second tasks while in dive mode | 769 ; Every Second Tasks while in Dive Mode |
755 ; | 770 ; |
756 isr_divemode_1sec: | 771 isr_divemode_1sec: |
757 decfsz sampling_timer,F ; decrement sampling timer, became zero? | 772 decfsz sampling_timer,F ; decrement sampling timer, became zero? |
758 bra isr_divemode_1sec_1 ; NO | 773 bra isr_divemode_1sec_1 ; NO |
759 bsf trigger_sample_divedata ; YES - set trigger flag for sampling dive data | 774 bsf trigger_sample_divedata ; YES - set trigger flag for sampling dive data |
816 clrf apnoe_surface_secs ; YES - reset seconds to 0 | 831 clrf apnoe_surface_secs ; YES - reset seconds to 0 |
817 incf apnoe_surface_mins,F ; - increment surface time, minutes | 832 incf apnoe_surface_mins,F ; - increment surface time, minutes |
818 return ; - done | 833 return ; - done |
819 | 834 |
820 | 835 |
821 ;============================================================================= | 836 ;----------------------------------------------------------------------------- |
822 ; BCD to Binary conversion | 837 ; Helper Function - BCD to Binary conversion |
838 ; | |
823 ; Input WREG = value in BCD | 839 ; Input WREG = value in BCD |
824 ; Output WREG = value in binary | 840 ; Output WREG = value in binary |
825 ; | 841 ; |
826 isr_rtcc_convert_BCD_DEC: | 842 isr_rtcc_convert_BCD_DEC: |
827 movwf isr_lo | 843 movwf isr_lo ; copy BCD to isr_lo |
828 swapf isr_lo, W | 844 swapf isr_lo, W ; create swapped copy in WREG |
829 andlw 0x0F ; W = tens | 845 andlw 0x0F ; keep only the tens |
830 rlncf WREG, W ; W = 2 * tens | 846 rlncf WREG, W ; WREG = 2 * tens |
831 subwf isr_lo, F ; 16 * tens + ones - 2*tens | 847 subwf isr_lo, F ; 16 * tens + ones - 2*tens |
832 subwf isr_lo, F ; 14 * tens + ones - 2*tens | 848 subwf isr_lo, F ; 14 * tens + ones - 2*tens |
833 subwf isr_lo, W ; 12 * tens + ones - 2*tens | 849 subwf isr_lo, W ; 12 * tens + ones - 2*tens |
834 return | 850 return ; done |
835 | 851 |
836 | 852 |
837 ;============================================================================= | 853 ;----------------------------------------------------------------------------- |
838 ; Check buttons | 854 ; Check Buttons |
839 ; | 855 ; |
840 isr_switch_right: | 856 isr_switch_right: |
841 bcf INTCON,INT0IE ; disable INT0 | 857 bcf INTCON,INT0IE ; clear external interrupt 0 |
842 btfss flip_screen ; 180° flipped? | 858 btfss flip_screen ; 180° flipped? |
843 bsf switch_right ; set flag | 859 bsf switch_right ; NO - set flag for right button |
844 btfsc flip_screen ; 180° flipped? | 860 btfsc flip_screen ; 180° flipped? |
845 bsf switch_left ; set flag | 861 bsf switch_left ; YES - set flag for left button |
846 bra isr_switch_common ; continue... | 862 bra isr_switch_common ; continue with common part |
847 | 863 |
848 isr_switch_left: | 864 isr_switch_left: |
849 bcf INTCON3,INT1IE ; disable INT1 | 865 bcf INTCON3,INT1IE ; clear external interrupt 1 |
850 btfss flip_screen ; 180° flipped? | 866 btfss flip_screen ; 180° flipped? |
851 bsf switch_left ; set flag | 867 bsf switch_left ; NO - set flag for left button |
852 btfsc flip_screen ; 180° flipped? | 868 btfsc flip_screen ; 180° flipped? |
853 bsf switch_right ; set flag | 869 bsf switch_right ; YES - set flag for right button |
854 ;bra isr_switch_common ; continue... | 870 ;bra isr_switch_common ; continue with common part |
855 | 871 |
856 isr_switch_common: | 872 isr_switch_common: |
857 clrf TMR1L ; load timer1 for first press | 873 btfsc tmr5_preemtion_allowed ; timer 5 preemption allowed? |
858 movlw TMR1H_VALUE_FIRST ; in steps of 7.8125 ms | 874 bsf PIR5,TMR5IF ; YES - preempt timer 5 |
875 movlw TMR1H_VALUE_FIRST ; load timer 1 (in steps of 7.8125 ms) | |
859 movwf TMR1H ; ... | 876 movwf TMR1H ; ... |
877 clrf TMR1L ; ... | |
860 bsf T1CON,TMR1ON ; start timer 1 | 878 bsf T1CON,TMR1ON ; start timer 1 |
861 bcf INTCON3,INT1IF ; clear flag | 879 bcf INTCON3,INT1IF ; clear timer 1 IRQ request |
862 bcf INTCON,INT0IF ; clear flag | 880 bcf INTCON,INT0IF ; clear timer 0 IRQ request |
863 return | 881 return ; done |
864 | 882 |
865 | 883 |
866 ;============================================================================= | 884 ;----------------------------------------------------------------------------- |
867 ; Button hold-down interrupt | 885 ; Button hold-down Interrupt |
868 ; | 886 ; |
869 timer1int: | 887 timer1int: |
870 bcf PIR1,TMR1IF ; clear flag | 888 bcf PIR1,TMR1IF ; clear timer 1 IRQ request |
871 bcf INTCON,INT0IF ; clear flag | 889 bcf INTCON,INT0IF ; clear timer 0 IRQ request |
872 bcf INTCON3,INT1IF ; clear flag | 890 bcf INTCON3,INT1IF ; clear timer 1 IRQ request |
891 | |
873 ; digital | 892 ; digital |
874 btfss switch_left1 ; left button hold-down? | 893 btfss switch_left1 ; left button hold-down? |
875 bra timer1int_left ; YES | 894 bra timer1int_left ; YES |
876 btfss switch_right2 ; right button hold-down? | 895 btfss switch_right2 ; right button hold-down? |
877 bra timer1int_right ; YES | 896 bra timer1int_right ; YES |
880 btfsc analog_sw2_pressed ; left button hold-down? | 899 btfsc analog_sw2_pressed ; left button hold-down? |
881 bra timer1int_left ; YES | 900 bra timer1int_left ; YES |
882 btfsc analog_sw1_pressed ; right button hold-down? | 901 btfsc analog_sw1_pressed ; right button hold-down? |
883 bra timer1int_right ; YES | 902 bra timer1int_right ; YES |
884 | 903 |
885 ; no button hold-down, stop Timer 1 | 904 ; no button hold-down, stop timer 1 |
886 bcf T1CON,TMR1ON ; stop timer 1 | 905 bcf T1CON,TMR1ON ; stop timer 1 |
887 bsf INTCON,INT0IE ; enable INT0 | 906 bsf INTCON,INT0IE ; enable INT0 IRQ |
888 bsf INTCON3,INT1IE ; enable INT1 | 907 bsf INTCON3,INT1IE ; enable INT1 IRQ |
889 return | 908 return |
890 | 909 |
891 timer1int_left: | 910 timer1int_left: |
892 btfss flip_screen ; 180° flipped? | 911 btfss flip_screen ; 180° flipped? |
893 bsf switch_left ; (re-)set flag | 912 bsf switch_left ; set flag for left button |
894 btfsc flip_screen ; 180° flipped? | 913 btfsc flip_screen ; 180° flipped? |
895 bsf switch_right ; (re-)set flag | 914 bsf switch_right ; set flag for right button |
896 bra timer1int_common ; continue | 915 bra timer1int_common ; continue |
897 | 916 |
898 timer1int_right: | 917 timer1int_right: |
899 btfss flip_screen ; 180° flipped? | 918 btfss flip_screen ; 180° flipped? |
900 bsf switch_right ; set flag | 919 bsf switch_right ; set flag for right button |
901 btfsc flip_screen ; 180° flipped? | 920 btfsc flip_screen ; 180° flipped? |
902 bsf switch_left ; (re-)set flag | 921 bsf switch_left ; set flag for left button |
903 ;bra timer1int_common ; continue | 922 ;bra timer1int_common ; continue |
904 | 923 |
905 timer1int_common: ; load timer1 for next pressure | 924 timer1int_common: ; load timer 1 for next button press |
906 clrf TMR1L ; clear timer, low byte | |
907 movlw TMR1H_VALUE_CONT ; default to surface mode value | 925 movlw TMR1H_VALUE_CONT ; default to surface mode value |
908 btfsc divemode ; in dive mode? | 926 btfsc divemode ; in dive mode? |
909 movlw TMR1H_VALUE_CONT_DIVE ; YES - overwrite with dive mode value | 927 movlw TMR1H_VALUE_CONT_DIVE ; YES - overwrite with dive mode value |
910 movwf TMR1H ; write value to timer, high byte | 928 movwf TMR1H ; write value to timer, high byte |
911 return ; return from timer1int with timer1 kept running | 929 clrf TMR1L ; write value to timer, low byte (zero) |
912 | 930 return ; done (timer1 kept running) |
913 | 931 |
914 ;============================================================================= | 932 |
915 ; Increment surface interval (counted in minutes and in seconds) | 933 ;----------------------------------------------------------------------------- |
934 ; Increment Surface Interval (counted in minutes and in seconds) | |
916 ; | 935 ; |
917 ; int_O_desaturation_time is only computed while in start, surface mode, | 936 ; int_O_desaturation_time is only computed while in start, surface mode, |
918 ; menue_tree or ghostwriter. So the ISR may clock surface_interval_mins | 937 ; menue_tree or ghostwriter. So the ISR may clock surface_interval_mins |
919 ; past the actual surface interval time. But TFT_surface_lastdive will | 938 ; past the actual surface interval time. But TFT_surf_cv_lastdive will |
920 ; check int_O_desaturation_time and in case int_O_desaturation_time is | 939 ; check int_O_desaturation_time and in case int_O_desaturation_time is |
921 ; zero it will not show surface_interval_mins but surface_interval_secs instead. | 940 ; zero it will not show surface_interval_mins but surface_interval_secs instead. |
922 ; Thus the glitch will remain invisible. | 941 ; Thus the glitch will remain invisible. |
923 ; | 942 ; |
924 | 943 inc_surface_interval_secs: ; called every second when not in dive mode |
925 inc_surface_interval_secs: ; called every second when not in dive mode | 944 incf surface_interval_secs+0,F ; increment the lowest byte |
926 incf surface_interval_secs+0,F ; increment the lowest byte | 945 clrf WREG ; clear WREG |
927 clrf WREG ; clear WREG | 946 addwfc surface_interval_secs+1,F ; add carry from byte before, if it did wrap-around |
928 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 |
929 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 |
930 addwfc surface_interval_secs+3,F ; add carry from byte before, if it did wrap-around | 949 return ; done |
931 return ; done | 950 |
932 | 951 inc_surface_interval_mins: ; called every minute when not in dive mode |
933 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 |
934 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 |
935 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 ? |
936 iorwf isr_lo,W ; inclusive-or low & high byte, desaturation time = 0 ? | 955 bz clr_surface_interval_mins ; YES - reset surface interval minutes counter |
937 bz clr_surface_interval_mins ; YES - reset surface interval minutes counter | 956 INCI surface_interval_mins ; NO - increment surface interval |
938 INCI surface_interval_mins ; NO - increment surface interval | 957 return ; - done |
939 return ; - done | |
940 | 958 |
941 rst_surface_interval: | 959 rst_surface_interval: |
942 bcf reset_surface_interval ; reset request flag | 960 bcf reset_surface_interval ; reset request flag |
943 ; reset the surface interval counted in seconds | 961 ; reset the surface interval counted in seconds |
944 clrf surface_interval_secs+0 ; reset surface interval (seconds), lowest byte | 962 clrf surface_interval_secs+0 ; reset surface interval (seconds), lowest byte |
953 clr_surface_interval_mins: | 971 clr_surface_interval_mins: |
954 clrf surface_interval_mins+0 ; reset surface interval (minutes), low byte | 972 clrf surface_interval_mins+0 ; reset surface interval (minutes), low byte |
955 clrf surface_interval_mins+1 ; reset surface interval (minutes), high byte | 973 clrf surface_interval_mins+1 ; reset surface interval (minutes), high byte |
956 return ; done | 974 return ; done |
957 | 975 |
958 | 976 ;----------------------------------------------------------------------------- |
959 ;============================================================================= | |
960 | 977 |
961 END | 978 END |