comparison src/sleepmode.asm @ 490:8dfb93e80338

NEW: Deep Sleep mode for OSTC Plus and OSTC 2 (2017) (Entered automatically) NEW: Logbook detail page in larger font (And nicer layout) CHANGE: Sleep mode current slightly reduced for all hwOS devices NEW: Logbook now records battery information NEW: Markers in internal logbook drawn as small "m" next to the profile
author heinrichsweikamp
date Wed, 29 Mar 2017 21:35:12 +0200
parents aadfe9f2edaf
children 66b9b8c082a9
comparison
equal deleted inserted replaced
489:22092d14fd8c 490:8dfb93e80338
32 32
33 global sleeploop 33 global sleeploop
34 sleeploop: ; enter sleepmode! 34 sleeploop: ; enter sleepmode!
35 call disable_ir_s8 ; IR/S8 off 35 call disable_ir_s8 ; IR/S8 off
36 call mcp_sleep 36 call mcp_sleep
37 bcf LEDg 37 bcf LEDg
38 bcf LEDr 38 bcf LEDr
39 movff menupos3,customview_surfmode; save last customview 39 movff menupos3,customview_surfmode; save last customview
40 call TFT_Display_FadeOut 40 call TFT_Display_FadeOut
41 call TFT_DisplayOff ; display off 41 call TFT_DisplayOff ; display off
42 bcf enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump)
42 call disable_rs232 ; USB off 43 call disable_rs232 ; USB off
43 call vault_decodata_into_eeprom ; store deco data 44 call vault_decodata_into_eeprom ; store deco data
44 call I2C_sleep_accelerometer
45 call I2C_sleep_compass
46 call ext_flash_enable_protection ; enable write protection for external flash 45 call ext_flash_enable_protection ; enable write protection for external flash
47 call update_battery_registers ; update battery registers into EEPROM 46 call update_battery_registers ; update battery registers into EEPROM
48 clrf divemins+0 47 clrf divemins+0
49 clrf divemins+1 48 clrf divemins+1
49 clrf apnoe_max_pressure+0
50 clrf apnoe_max_pressure+1
50 call speed_normal 51 call speed_normal
51 bsf no_sensor_int ; No sensor interrupt 52 bsf no_sensor_int ; No sensor interrupt
52 bcf enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) 53 clrf ADCON0 ; Power-Down ADC Module
53 clrf ADCON0 ; Power-Down ADC Module 54 sleeploop_pre:
55 bcf deep_sleep ; Normal sleepmode
56 call I2C_sleep_accelerometer
57 call I2C_sleep_compass
58 btfss analog_switches
59 bra sleeploop_loop ; no analog switches
60
61 bsf power_sw1
62 bsf power_sw2
63 movlw .4 ; Wait for button circuity
64 movwf apnoe_max_pressure+0 ; Used as temp
65 bcf onesecupdate
66 sleeploop_pre1:
67 sleep
68 sleep
69 btfss onesecupdate ; Wait 1 second
70 bra sleeploop_pre1
71 bcf onesecupdate
72 decfsz apnoe_max_pressure+0,F
73 bra sleeploop_pre1
74
75 movlw .32 ; Wait for button circuity
76 movwf apnoe_max_pressure+0 ; Used as temp
77 sleeploop_pre2:
78 call get_analog_switches
79 decfsz apnoe_max_pressure+0,F
80 bra sleeploop_pre2
81
82 bcf PIR1,TMR1IF
83 bcf INTCON,INT0IF
84 bcf INTCON3,INT1IF
85 bcf PIR5,TMR7IF
86 bcf switch_left
87 bcf switch_right
88 bcf analog_sw2_pressed
89 bcf analog_sw1_pressed
90 bsf PIE1,0 ; (Re)Start Timer 1 Interrupt
91 bsf PIE2,1 ; (Re)Start Timer 2 Interrupt
92 bsf PIE5,3 ; (Re)Start Timer 7 Interrupt
93 bsf INTCON,4 ; (Re)Start INT0 Interrupt
94 bsf INTCON3,3 ; (Re)Start INT1 Interrupt
95
54 sleeploop_loop: 96 sleeploop_loop:
55 btfsc onesecupdate ; one second in sleep? 97 btfsc onesecupdate ; one second in sleep?
56 rcall onesec_sleep ; check switches, check pressure sensor, etc. 98 rcall onesec_sleep ; check switches, check pressure sensor, etc.
57 99
58 btfss sleepmode ; wake up? (This bit will be set in other routines) 100 btfss sleepmode ; wake up? (This bit will be set in other routines)
59 goto restart ; yes 101 goto restart ; yes
102
103 btfsc deep_sleep ; Enter deep sleep?
104 bra deepsleep ; Yes
60 105
61 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) 106 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup)
62 107
63 ; Any button pressed in sleep? 108 ; Any button pressed in sleep?
64 btfsc switch_left 109 ; btfsc switch_left
65 rcall onesec_sleep1a 110 ; rcall onesec_sleep1a
66 btfsc switch_right 111 ; btfsc switch_right
67 rcall onesec_sleep1a 112 ; rcall onesec_sleep1a
68 113 ;
69 btfss sleepmode ; wake up? (This bit will be set in other routines) 114 ; btfss sleepmode ; wake up? (This bit will be set in other routines)
70 goto restart ; yes 115 ; goto restart ; yes
71 116
72 bra sleeploop_loop ; do loop until someting happens 117 bra sleeploop_loop ; do loop until someting happens
73 118
119 deepsleep:
120 btfss analog_switches
121 return ; no analog switches
122
123 bcf PIE1,0 ; Stop Timer 1 Interrupt
124 bcf PIE2,1 ; Stop Timer 2 Interrupt
125 bcf PIE5,3 ; Stop Timer 7 Interrupt
126 bcf INTCON,4 ; Stop INT0 Interrupt
127 bcf INTCON3,3 ; Stop INT1 Interrupt
128 bcf power_sw1
129 bcf power_sw2
130 rcall deepsleep_get_accel ; Read accelerometer into WREG
131 movwf apnoe_max_pressure+0 ; Store init value
132
133 deepsleep_loop:
134 btfsc onesecupdate ; one second in sleep?
135 rcall onesec_deepsleep ; check accelerometer
136
137 btfsc onesecupdate ; one second in sleep?
138 rcall onesec_sleep ; check switches, check pressure sensor, etc.
139
140 sleep
141
142 btfss deep_sleep ; Enter normal sleepmode?
143 bra sleeploop_pre ; Yes
144
145 bra deepsleep_loop ; do loop until someting happens
146
147 onesec_deepsleep:
148 rcall deepsleep_get_accel ; Read accelerometer into WREG
149 subwf apnoe_max_pressure+0,W ; apnoe_max_pressure+0 - accel_DZ+0 -> WREG
150 btfsc STATUS,N ; Result negative?
151 negf WREG ; Yes, negate it
152 movwf apnoe_max_pressure+1 ; change of acceleration in Z-axis
153 movlw .50 ; Threshold (mg)
154 cpfslt apnoe_max_pressure+1 ; bigger then the threshold?
155 bcf deep_sleep ; Yes!
156
157 ; extern piezo_config_tx
158 ; movff apnoe_max_pressure+0,WREG
159 ; call piezo_config_tx
160 ; movff accel_DZ+0,WREG
161 ; call piezo_config_tx
162 ; movff apnoe_max_pressure+1,WREG
163 ; call piezo_config_tx
164 return
165
166 deepsleep_get_accel:
167 call I2C_init_compass
168 call I2C_RX_accelerometer ; read Accelerometer
169 call I2C_sleep_compass
170 movff accel_DZ+0,WREG
171 return
172
74 onehour_sleep: 173 onehour_sleep:
75 call update_battery_registers ; update battery registers into EEPROM 174 call update_battery_registers ; update battery registers into EEPROM
76 call vault_decodata_into_eeprom ; update deco data 175 call vault_decodata_into_eeprom ; update deco data
77 bcf onehourupdate ; all done 176 bcf onehourupdate ; all done
78 return 177 return
79 178
80 onemin_sleep: 179 onemin_sleep:
81 btfsc onehourupdate ; one hour in sleep? 180 btfsc onehourupdate ; one hour in sleep?
82 rcall onehour_sleep ; Yes 181 rcall onehour_sleep ; Yes
83 182
183 btfsc battery_gauge_available
184 call get_battery_voltage ; Check for charger
185
84 ;---- adjust airpressure compensation any 15 minutes 186 ;---- adjust airpressure compensation any 15 minutes
85 incf divemins+1,F ; counts to 14... 187 incf divemins+1,F ; counts to 14...
86 movlw d'14' 188 movlw d'14'
87 cpfsgt divemins+1 189 cpfsgt divemins+1
88 bra onemin_sleep2 ; 15 minutes not done! 190 bra onemin_sleep2 ; 15 minutes not done!
89 191
90 ; Tasks every 15 minutes in sleep 192 ; Tasks every 15 minutes in sleep
193 bsf deep_sleep ; enter deep-sleep mode
194
91 clrf divemins+1 ; reset counter 195 clrf divemins+1 ; reset counter
92 196
93 call deco_calc_CNS_decrease_15min ; compute CNS decay in sleep only 197 call deco_calc_CNS_decrease_15min ; compute CNS decay in sleep only
94 banksel common 198 banksel common
95 199
123 227
124 onesec_sleep: 228 onesec_sleep:
125 btfsc oneminupdate ; one minute in sleep? 229 btfsc oneminupdate ; one minute in sleep?
126 rcall onemin_sleep ; do oneminute tasks, e.g. calculate desaturation 230 rcall onemin_sleep ; do oneminute tasks, e.g. calculate desaturation
127 231
128 btfsc battery_gauge_available 232 ; btfsc battery_gauge_available
129 call get_battery_voltage ; Check for charger 233 ; call get_battery_voltage ; Check for charger
130 234
131 incf divemins+0,F ; counts to #test_pressure_in_sleep (5) 235 incf divemins+0,F ; counts to #test_pressure_in_sleep (10)
132 movlw d'5' 236 movlw d'10'
133 cpfsgt divemins+0 ; here: temp variable 237 cpfsgt divemins+0 ; here: temp variable
134 bra onesec_sleep1 ; #test_pressure_in_sleep not done yet 238 bra onesec_sleep1 ; #test_pressure_in_sleep not done yet
135 239
136 clrf divemins+0 ; clear counter 240 clrf divemins+0 ; clear counter
137 rcall pressuretest_sleep_fast ; Gets pressure without averaging (faster!) 241 rcall pressuretest_sleep_fast ; Gets pressure without averaging (faster!)
138 ; compare current ambient pressure with wake_up_from_sleep 242 ; compare current ambient pressure with wake_up_from_sleep
139 movlw LOW wake_up_from_sleep 243 movlw LOW wake_up_from_sleep
140 movwf sub_a+0 ; power on if ambient pressure is greater threshold 244 movwf sub_a+0 ; power on if ambient pressure is greater threshold
141 movlw HIGH wake_up_from_sleep 245 movlw HIGH wake_up_from_sleep
142 movwf sub_a+1 ; power on if ambient pressure is greater threshold 246 movwf sub_a+1 ; power on if ambient pressure is greater threshold
143 SAFE_2BYTE_COPY amb_pressure, sub_b 247 SAFE_2BYTE_COPY amb_pressure, sub_b
144 call subU16 ; Is (1160mbar - averaged(amb_pressure)) < 0 ? 248 call subU16 ; Is (1160mbar - averaged(amb_pressure)) < 0 ?
149 bra onesec_sleep1 ; No wake-up with cR hardware 253 bra onesec_sleep1 ; No wake-up with cR hardware
150 btfsc vusb_in ; USB plugged in? 254 btfsc vusb_in ; USB plugged in?
151 bra onesec_sleep1a ; Yes, skip button checks, wake up! 255 bra onesec_sleep1a ; Yes, skip button checks, wake up!
152 256
153 onesec_sleep1: 257 onesec_sleep1:
154 bcf onesecupdate ; all done. 258 bcf onesecupdate ; all done.
155 ; Check switches 259 ; Check switches
156 btfsc switch_left 260 btfsc switch_left
157 bra onesec_sleep1a 261 bra onesec_sleep1a
158 btfsc switch_right 262 btfsc switch_right
159 bra onesec_sleep1a 263 bra onesec_sleep1a
160 ; No button pressed 264 ; No button pressed
161 bcf INTCON,INT0IF ; Clear flag 265 ; bcf INTCON,INT0IF ; Clear flag
162 bcf INTCON3,INT1IF ; Clear flag 266 ; bcf INTCON3,INT1IF ; Clear flag
163 return 267 return
164 268
165 onesec_sleep1a: ; At least one button pressed or amb_pressure > wake_up_from_sleep 269 onesec_sleep1a: ; At least one button pressed or amb_pressure > wake_up_from_sleep
166 bcf INTCON,INT0IF ; Clear flag 270 ; bcf INTCON,INT0IF ; Clear flag
167 bcf INTCON3,INT1IF ; Clear flag 271 ; bcf INTCON3,INT1IF ; Clear flag
168 bcf sleepmode ; wake up! 272 bcf sleepmode ; wake up!
169 SAFE_2BYTE_COPY last_surfpressure_30min, amb_pressure ; copy for compatibility 273 SAFE_2BYTE_COPY last_surfpressure_30min, amb_pressure ; copy for compatibility
170 movlw .0 274 movlw .0
171 movff WREG,sensor_state_counter ; Reset sensor state counter 275 movff WREG,sensor_state_counter ; Reset sensor state counter
172 bcf no_sensor_int ; normal sensor interrupt mode 276 bcf no_sensor_int ; normal sensor interrupt mode