comparison src/sleepmode.asm @ 604:ca4556fb60b9

bump to 2.99beta, work on 3.00 stable
author heinrichsweikamp
date Thu, 22 Nov 2018 19:47:26 +0100
parents b455b31ce022
children c40025d8e750 be8787f2034d
comparison
equal deleted inserted replaced
603:00b24fb4324d 604:ca4556fb60b9
1 ;============================================================================= 1 ;=============================================================================
2 ; 2 ;
3 ; File sleepmode.asm Version 2.98 3 ; File sleepmode.asm Version 2.99e
4 ; 4 ;
5 ; Sleepmode 5 ; Sleepmode
6 ; 6 ;
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
8 ;============================================================================== 8 ;==============================================================================
38 sm_timer2 ; timer for 10 minutes tasks (updating of tissues) 38 sm_timer2 ; timer for 10 minutes tasks (updating of tissues)
39 sm_timer3 ; timer for 15 minutes tasks (updating of surface pressure) 39 sm_timer3 ; timer for 15 minutes tasks (updating of surface pressure)
40 ENDC ; used: 5 byte, remaining: 11 byte 40 ENDC ; used: 5 byte, remaining: 11 byte
41 41
42 42
43 gui CODE 43 slmode CODE
44 44
45 ;============================================================================== 45 ;==============================================================================
46 46
47 global sleeploop 47 global sleeploop
48 sleeploop: ; enter sleepmode! 48 sleeploop: ; enter sleep mode
49 call disable_ir_s8 ; IR/S8 off 49 call disable_ir_s8 ; IR/S8 off
50 call mcp_sleep 50 call mcp_sleep
51 bcf LEDg 51 bcf LEDg
52 bcf LEDr 52 bcf LEDr
53 call TFT_Display_FadeOut 53 call TFT_Display_FadeOut
54 call TFT_DisplayOff ; display off 54 call TFT_DisplayOff ; display off
55 bcf enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) 55
56 IFDEF _screendump
57 bcf enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (screen dump)
58 ENDIF
59
56 call disable_rs232 ; USB off 60 call disable_rs232 ; USB off
57 call vault_decodata_into_eeprom ; store deco data 61 call vault_decodata_into_eeprom ; store deco data
58 call ext_flash_enable_protection ; enable write protection for external flash 62 call ext_flash_enable_protection ; enable write protection for external flash
59 call update_battery_registers ; update battery registers into EEPROM 63 call update_battery_registers ; update battery registers into EEPROM
60 clrf sm_temp1 64 clrf sm_temp1
61 clrf sm_temp2 65 clrf sm_temp2
62 clrf sm_timer1 66 clrf sm_timer1
63 clrf sm_timer2 67 clrf sm_timer2
64 clrf sm_timer3 68 clrf sm_timer3
65 call speed_normal 69 call speed_normal
66 bsf no_sensor_int ; No sensor interrupt 70 bsf no_sensor_int ; inhibit sensor interrupts
67 clrf ADCON0 ; Power-Down ADC Module 71 clrf ADCON0 ; power-down ADC module
68 72
69 sleeploop_pre: 73 sleeploop_pre:
70 bcf deep_sleep ; Normal sleepmode 74 bcf deep_sleep ; normal sleep mode
71 call I2C_sleep_accelerometer 75 call I2C_sleep_accelerometer
72 call I2C_sleep_compass 76 call I2C_sleep_compass
73 btfss analog_switches 77 btfss analog_switches ; OSTC with analog switches?
74 bra sleeploop_loop ; no analog switches 78 bra sleeploop_loop ; NO - no analog switches
75 79
76 bsf power_sw1 80 bsf power_sw1
77 btfss power_sw1 81 btfss power_sw1
78 bra $-4 82 bra $-4
79 bsf power_sw2 83 bsf power_sw2
80 btfss power_sw2 84 btfss power_sw2
81 bra $-4 85 bra $-4
82 movlw .4 ; Wait for button circuity 86 movlw .4 ; wait for button circuity
83 movwf sm_temp1 ; Used as temp 87 movwf sm_temp1 ; used as temp
84 bcf onesecupdate 88 bcf onesecupdate
85 89
86 sleeploop_pre1: 90 sleeploop_pre1:
87 rcall sleepmode_sleep 91 rcall sleepmode_sleep
88 btfss onesecupdate ; Wait 1 second 92 btfss onesecupdate ; wait 1 second
89 bra sleeploop_pre1 93 bra sleeploop_pre1
90 bcf onesecupdate 94 bcf onesecupdate
91 decfsz sm_temp1,F 95 decfsz sm_temp1,F
92 bra sleeploop_pre1 96 bra sleeploop_pre1
93 movlw .32 ; Wait for button circuity 97 movlw .32 ; wait for button circuity
94 movwf sm_temp1 ; Used as temp 98 movwf sm_temp1 ; used as temp
95 99
96 sleeploop_pre2: 100 sleeploop_pre2:
97 call get_analog_switches 101 call get_analog_switches
98 decfsz sm_temp1,F 102 decfsz sm_temp1,F
99 bra sleeploop_pre2 103 bra sleeploop_pre2
104 bcf PIR5,TMR7IF 108 bcf PIR5,TMR7IF
105 bcf switch_left 109 bcf switch_left
106 bcf switch_right 110 bcf switch_right
107 bcf analog_sw2_pressed 111 bcf analog_sw2_pressed
108 bcf analog_sw1_pressed 112 bcf analog_sw1_pressed
109 bsf PIE1,0 ; (Re)Start Timer 1 Interrupt 113 bsf PIE1,0 ; (re)start timer 1 interrupt
110 bsf PIE2,1 ; (Re)Start Timer 2 Interrupt 114 bsf PIE2,1 ; (re)start timer 2 interrupt
111 bsf PIE5,3 ; (Re)Start Timer 7 Interrupt 115 bsf PIE5,3 ; (re)start timer 7 interrupt
112 bsf INTCON,4 ; (Re)Start INT0 Interrupt 116 bsf INTCON,4 ; (re)start INT0 interrupt
113 bsf INTCON3,3 ; (Re)Start INT1 Interrupt 117 bsf INTCON3,3 ; (re)start INT1 interrupt
114 118
115 sleeploop_loop: 119 sleeploop_loop:
116 btfsc onesecupdate ; one second in sleep? 120 btfsc onesecupdate ; one second in sleep?
117 rcall onesec_sleep ; check switches, check pressure sensor, etc. 121 rcall onesec_sleep ; check switches, check pressure sensor, etc.
118 122
119 btfss sleepmode ; wake up? (This bit will be set in other routines) 123 btfss sleepmode ; wake up? (This bit will be set in other routines)
120 goto restart ; yes 124 goto restart ; YES
121 125
122 btfsc deep_sleep ; Enter deep sleep? 126 btfsc deep_sleep ; enter deep sleep?
123 bra deepsleep ; Yes 127 bra deepsleep ; YES
124 128
125 no_deepsleep: 129 no_deepsleep:
126 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) 130 rcall sleepmode_sleep ; wait at least 35 ms (every 62.5ms timer7 wakeup)
127 131
128 ; Any button pressed in sleep? 132 ; Any button pressed in sleep?
129 ; btfsc switch_left 133 ; btfsc switch_left
130 ; rcall onesec_sleep1a 134 ; rcall onesec_sleep1a
131 ; btfsc switch_right 135 ; btfsc switch_right
132 ; rcall onesec_sleep1a 136 ; rcall onesec_sleep1a
133 ; 137 ;
134 ; btfss sleepmode ; wake up? (This bit will be set in other routines) 138 ; btfss sleepmode ; wake up? (this bit will be set in other routines)
135 ; goto restart ; yes 139 ; goto restart ; YES
136 140
137 bra sleeploop_loop ; do loop until something happens 141 bra sleeploop_loop ; do loop until something happens
138 142
139 deepsleep: 143 deepsleep:
140 btfss analog_switches 144 btfss analog_switches
141 bra no_deepsleep ; no analog switches, no deep sleep required 145 bra no_deepsleep ; no analog switches, no deep sleep required
142 146
143 bcf PIE1,0 ; Stop Timer 1 Interrupt 147 bcf PIE1,0 ; stop timer 1 interrupt
144 bcf PIE2,1 ; Stop Timer 2 Interrupt 148 bcf PIE2,1 ; stop timer 2 interrupt
145 bcf PIE5,3 ; Stop Timer 7 Interrupt 149 bcf PIE5,3 ; stop timer 7 interrupt
146 bcf INTCON,4 ; Stop INT0 Interrupt 150 bcf INTCON,4 ; stop INT0 interrupt
147 bcf INTCON3,3 ; Stop INT1 Interrupt 151 bcf INTCON3,3 ; stop INT1 interrupt
148 bcf power_sw1 152 bcf power_sw1
149 bcf power_sw2 153 bcf power_sw2
150 rcall deepsleep_get_accel ; Read accelerometer into WREG 154 rcall deepsleep_get_accel ; read accelerometer into WREG
151 movwf sm_temp1 ; Store init value 155 movwf sm_temp1 ; store init value
152 156
153 deepsleep_loop: 157 deepsleep_loop:
154 btfsc onesecupdate ; one second in sleep? 158 btfsc onesecupdate ; one second in sleep?
155 rcall onesec_deepsleep ; check accelerometer 159 rcall onesec_deepsleep ; YES - check accelerometer
156 160
157 btfsc onesecupdate ; one second in sleep? 161 btfsc onesecupdate ; one second in sleep?
158 rcall onesec_sleep ; check switches, check pressure sensor, etc. 162 rcall onesec_sleep ; YES - check switches, check pressure sensor, etc.
159 163
160 rcall sleepmode_sleep 164 rcall sleepmode_sleep
161 165
162 btfss deep_sleep ; Enter normal sleepmode? 166 btfss deep_sleep ; enter normal sleep mode?
163 bra sleeploop_pre ; Yes 167 bra sleeploop_pre ; Yes
164 168
165 bra deepsleep_loop ; do loop until something happens 169 bra deepsleep_loop ; do loop until something happens
166 170
167 onesec_deepsleep: 171 onesec_deepsleep:
168 rcall deepsleep_get_accel ; Read accelerometer into WREG 172 rcall deepsleep_get_accel ; read accelerometer into WREG
169 subwf sm_temp1,W ; sm_temp1 - accel_DZ+0 -> WREG 173 subwf sm_temp1,W ; sm_temp1 - accel_DZ+0 -> WREG
170 btfsc STATUS,N ; Result negative? 174 btfsc STATUS,N ; result negative?
171 negf WREG ; Yes, negate it 175 negf WREG ; YES - negate it
172 movwf sm_temp2 ; change of acceleration in Z-axis 176 movwf sm_temp2 ; change of acceleration in Z-axis
173 movlw .50 ; Threshold (mg) 177 movlw .50 ; threshold (mg)
174 cpfslt sm_temp2 ; bigger then the threshold? 178 cpfslt sm_temp2 ; bigger then the threshold?
175 bcf deep_sleep ; Yes! 179 bcf deep_sleep ; YES
176 180
177 ; extern piezo_config_tx 181 ; extern piezo_config_tx
178 ; movff sm_temp1,WREG 182 ; movff sm_temp1,WREG
179 ; call piezo_config_tx 183 ; call piezo_config_tx
180 ; movff accel_DZ+0,WREG 184 ; movff accel_DZ+0,WREG
185 return 189 return
186 190
187 deepsleep_get_accel: 191 deepsleep_get_accel:
188 call I2C_init_compass ; required for compass1 192 call I2C_init_compass ; required for compass1
189 call I2C_init_accelerometer ; required for compass2 193 call I2C_init_accelerometer ; required for compass2
190 call I2C_RX_accelerometer ; read Accelerometer 194 call I2C_RX_accelerometer ; read accelerometer
191 call I2C_sleep_compass ; required for compass1 195 call I2C_sleep_compass ; required for compass1
192 call I2C_sleep_accelerometer ; required for compass2 196 call I2C_sleep_accelerometer ; required for compass2
193 movff accel_DZ+0,WREG 197 movff accel_DZ+0,WREG
194 return 198 return
195 199
199 bcf onehourupdate ; all done 203 bcf onehourupdate ; all done
200 return 204 return
201 205
202 onemin_sleep: 206 onemin_sleep:
203 btfsc onehourupdate ; one hour in sleep? 207 btfsc onehourupdate ; one hour in sleep?
204 rcall onehour_sleep ; Yes 208 rcall onehour_sleep ; YES
205 209
206 btfsc battery_gauge_available 210 btfsc battery_gauge_available
207 call get_battery_voltage ; Check for charger 211 call get_battery_voltage ; check for charger
208 212
209 ;---- update tissues and CNS every 10 minutes when gradient factor is 0 (no supersaturation in any tissue any more) 213 ;---- update tissues and CNS every 10 minutes when gradient factor is 0 (no supersaturation in any tissue any more)
210 movff int_O_gradient_factor+0,WREG ; get gradient factor, only the lower byte is used for the value 214 movff int_O_gradient_factor+0,WREG ; get gradient factor, only the lower byte is used for the value
211 tstfsz WREG ; gradient factor = 0? 215 tstfsz WREG ; gradient factor = 0?
212 bra onemin_sleep1 ; NO - continue with air pressure compensation 216 bra onemin_sleep1 ; NO - continue with air pressure compensation
267 bcf oneminupdate ; all done 271 bcf oneminupdate ; all done
268 return 272 return
269 273
270 onesec_sleep: 274 onesec_sleep:
271 btfsc oneminupdate ; one minute in sleep? 275 btfsc oneminupdate ; one minute in sleep?
272 rcall onemin_sleep ; do one-minute tasks, e.g. calculate desaturation 276 rcall onemin_sleep ; YES - do one-minute tasks, e.g. calculate desaturation
273 277
274 btfsc battery_gauge_available 278 btfsc battery_gauge_available
275 call get_battery_voltage ; Check for charger 279 call get_battery_voltage ; check for charger
276 280
277 incf sm_timer1,F ; counts to #test_pressure_in_sleep (10) 281 incf sm_timer1,F ; counts to #test_pressure_in_sleep (10)
278 movlw d'10' 282 movlw d'10'
279 cpfsgt sm_timer1 ; here: temp variable 283 cpfsgt sm_timer1 ; here: temp variable
280 bra onesec_sleep1 ; #test_pressure_in_sleep not done yet 284 bra onesec_sleep1 ; #test_pressure_in_sleep not done yet
285 movlw LOW wake_up_from_sleep 289 movlw LOW wake_up_from_sleep
286 movwf sub_a+0 ; power on if ambient pressure is greater threshold 290 movwf sub_a+0 ; power on if ambient pressure is greater threshold
287 movlw HIGH wake_up_from_sleep 291 movlw HIGH wake_up_from_sleep
288 movwf sub_a+1 ; power on if ambient pressure is greater threshold 292 movwf sub_a+1 ; power on if ambient pressure is greater threshold
289 SAFE_2BYTE_COPY amb_pressure, sub_b 293 SAFE_2BYTE_COPY amb_pressure, sub_b
290 call subU16 ; Is (1160mbar - averaged(amb_pressure)) < 0 ? 294 call subU16 ; is (1160mbar - averaged(amb_pressure)) < 0 ?
291 btfsc neg_flag ; Wake up from Sleep? 295 btfsc neg_flag ; wake up from sleep?
292 bra onesec_sleep1a ; Yes, skip button checks, wake up! 296 bra onesec_sleep1a ; YES - skip button checks, wake up!
293 297
294 btfsc battery_gauge_available 298 btfsc battery_gauge_available
295 bra onesec_sleep1 ; No wake-up with cR hardware 299 bra onesec_sleep1 ; no wake-up with cR hardware
296 btfsc vusb_in ; USB plugged in? 300 btfsc vusb_in ; USB plugged in?
297 bra onesec_sleep1a ; Yes, skip button checks, wake up! 301 bra onesec_sleep1a ; YES - skip button checks, wake up
298 302
299 onesec_sleep1: 303 onesec_sleep1:
300 bcf onesecupdate ; all done. 304 bcf onesecupdate ; clear flag
301 ; Check switches 305 btfsc switch_left ; left switch pressed?
302 btfsc switch_left 306 bra onesec_sleep1a ; YES
303 bra onesec_sleep1a 307 btfsc switch_right ; right switch pressed?
304 btfsc switch_right 308 bra onesec_sleep1a ; YES
305 bra onesec_sleep1a 309 return ; NO to both - done
306 310
307 ; No button pressed 311 onesec_sleep1a: ; at least one button pressed or amb_pressure -> wake_up_from_sleep
308 ; bcf INTCON,INT0IF ; Clear flag 312 bcf sleepmode ; wake up
309 ; bcf INTCON3,INT1IF ; Clear flag
310
311 return
312
313 onesec_sleep1a: ; At least one button pressed or amb_pressure > wake_up_from_sleep
314 ; bcf INTCON,INT0IF ; Clear flag
315 ; bcf INTCON3,INT1IF ; Clear flag
316 bcf sleepmode ; wake up!
317 SAFE_2BYTE_COPY last_surfpressure_30min, amb_pressure ; copy for compatibility 313 SAFE_2BYTE_COPY last_surfpressure_30min, amb_pressure ; copy for compatibility
318 movlw .0 314 movlw .0
319 movff WREG,sensor_state_counter ; Reset sensor state counter 315 movff WREG,sensor_state_counter ; reset sensor state counter
320 bcf no_sensor_int ; normal sensor interrupt mode 316 bcf no_sensor_int ; normal sensor interrupt mode
321 return 317 return
322 318
323 pressuretest_sleep_fast: ; Get pressure without averaging (Faster to save some power in sleep mode) 319 pressuretest_sleep_fast: ; get pressure without averaging (faster to save some power in sleep mode)
324 banksel isr_backup ; Back to Bank0 ISR data 320 banksel isr_backup ; back to Bank0 ISR data
325 clrf amb_pressure_avg+0 ; pressure average registers 321 clrf amb_pressure_avg+0 ; clear pressure average registers
326 clrf amb_pressure_avg+1 322 clrf amb_pressure_avg+1
327 clrf temperature_avg+0 323 clrf temperature_avg+0 ; clear temperature average registers
328 clrf temperature_avg+1 324 clrf temperature_avg+1
329 call get_temperature_start ; and start temperature integration (73,5us) 325 call get_temperature_start ; start temperature integration (73.5 us)
330 banksel common 326 banksel common
331 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) 327 rcall sleepmode_sleep ; wait at least 35 ms (every 62.5 ms timer7 wakeup)
332 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) 328 rcall sleepmode_sleep ; wait at least 35 ms (every 62.5 ms timer7 wakeup)
333 banksel isr_backup ; Back to Bank0 ISR data 329 banksel isr_backup ; back to Bank0 ISR data
334 call get_temperature_value ; State 1: Get temperature 330 call get_temperature_value ; state 1: get temperature
335 call get_pressure_start ; Start pressure integration. 331 call get_pressure_start ; start pressure integration
336 banksel common 332 banksel common
337 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) 333 rcall sleepmode_sleep ; wait at least 35 ms (every 62.5 ms timer7 wakeup)
338 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) 334 rcall sleepmode_sleep ; wait at least 35 ms (every 62.5 ms timer7 wakeup)
339 banksel isr_backup ; Back to Bank0 ISR data 335 banksel isr_backup ; back to bank0 ISR data
340 call get_pressure_value ; State2: Get pressure (51us) 336 call get_pressure_value ; state2: get pressure (51 us)
341 call calculate_compensation ; calculate temperature compensated pressure (27us) 337 call calculate_compensation ; calculate temperature compensated pressure (27 us)
342 banksel common 338 banksel common
343 SAFE_2BYTE_COPY amb_pressure_avg, amb_pressure ; copy for compatibility 339 SAFE_2BYTE_COPY amb_pressure_avg, amb_pressure ; copy for compatibility
344 return 340 return
345 341
346 sleepmode_sleep: 342 sleepmode_sleep:
347 banksel 0xF16 ; Addresses, F16h through F5Fh, are also used by SFRs, but are not part of the Access RAM. 343 banksel 0xF16 ; addresses F16h through F5Fh are also used by SFRs, but are not part of the access RAM
348 clrf T7GCON ; Reset Timer7 Gate Control register 344 clrf T7GCON ; reset timer7 gate control register
349 movlw b'10001101' ; 1:1 Prescaler -> 2seconds@32768Hz, not synced 345 movlw b'10001101' ; 1:1 prescaler -> 2 seconds @ 32768 Hz, not synced
350 movwf T7CON 346 movwf T7CON
351 sleep 347 sleep
352 sleep 348 sleep
353 clrf T7GCON ; Reset Timer7 Gate Control register 349 clrf T7GCON ; reset timer7 gate control register
354 movlw b'10001001' ; 1:1 Prescaler -> 2seconds@32768Hz, synced 350 movlw b'10001001' ; 1:1 prescaler -> 2 seconds @ 32768Hz, synced
355 movwf T7CON 351 movwf T7CON
356 banksel common ; Bank1 352 banksel common ; back to bank1
357 return 353 return
358 354
359 END 355 END