Mercurial > public > hwos_code
comparison src/sleepmode.asm @ 582:b455b31ce022
work on 2.97 stable
author | heinrichsweikamp |
---|---|
date | Mon, 26 Feb 2018 16:40:28 +0100 |
parents | b7eb98dbd800 |
children | ca4556fb60b9 |
comparison
equal
deleted
inserted
replaced
581:f5de1ff88814 | 582:b455b31ce022 |
---|---|
1 ;============================================================================= | 1 ;============================================================================= |
2 ; | 2 ; |
3 ; File sleepmode.asm | 3 ; File sleepmode.asm Version 2.98 |
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 ;============================================================================== |
9 ; HISTORY | 9 ; HISTORY |
10 ; 2011-08-12 : [mH] moving from OSTC code | 10 ; 2011-08-12 : [mH] moving from OSTC code |
11 | 11 |
12 #include "hwos.inc" ; Mandatory header | 12 #include "hwos.inc" ; Mandatory header |
13 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c | 13 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c |
14 #include "surfmode.inc" | 14 #include "surfmode.inc" |
15 #include "tft.inc" | 15 #include "tft.inc" |
16 #include "isr.inc" | 16 #include "isr.inc" |
17 #include "start.inc" | 17 #include "start.inc" |
18 #include "adc_lightsensor.inc" | 18 #include "adc_lightsensor.inc" |
19 #include "math.inc" | 19 #include "math.inc" |
20 #include "ms5541.inc" | 20 #include "ms5541.inc" |
21 #include "wait.inc" | 21 #include "wait.inc" |
22 #include "eeprom_rs232.inc" | 22 #include "eeprom_rs232.inc" |
23 #include "external_flash.inc" | 23 #include "external_flash.inc" |
24 #include "ghostwriter.inc" | 24 #include "ghostwriter.inc" |
25 #include "i2c.inc" | 25 #include "i2c.inc" |
26 #include "mcp.inc" | 26 #include "mcp.inc" |
27 | 27 |
28 | 28 |
29 extern vault_decodata_into_eeprom | 29 extern vault_decodata_into_eeprom |
30 | 30 |
31 gui CODE | 31 |
32 ;---- Private local variables ------------------------------------------------- | |
33 | |
34 CBLOCK local1 ; max size is 16 Byte !!! | |
35 sm_temp1 ; sleepmode temporary 1 | |
36 sm_temp2 ; sleepmode temporary 2 | |
37 sm_timer1 ; timer for pressure check every 10 seconds | |
38 sm_timer2 ; timer for 10 minutes tasks (updating of tissues) | |
39 sm_timer3 ; timer for 15 minutes tasks (updating of surface pressure) | |
40 ENDC ; used: 5 byte, remaining: 11 byte | |
41 | |
42 | |
43 gui CODE | |
44 | |
45 ;============================================================================== | |
32 | 46 |
33 global sleeploop | 47 global sleeploop |
34 sleeploop: ; enter sleepmode! | 48 sleeploop: ; enter sleepmode! |
35 call disable_ir_s8 ; IR/S8 off | 49 call disable_ir_s8 ; IR/S8 off |
36 call mcp_sleep | 50 call mcp_sleep |
37 bcf LEDg | 51 bcf LEDg |
38 bcf LEDr | 52 bcf LEDr |
39 movff menupos3,customview_surfmode; save last customview | |
40 call TFT_Display_FadeOut | 53 call TFT_Display_FadeOut |
41 call TFT_DisplayOff ; display off | 54 call TFT_DisplayOff ; display off |
42 bcf enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) | 55 bcf enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) |
43 call disable_rs232 ; USB off | 56 call disable_rs232 ; USB off |
44 call vault_decodata_into_eeprom ; store deco data | 57 call vault_decodata_into_eeprom ; store deco data |
45 call ext_flash_enable_protection ; enable write protection for external flash | 58 call ext_flash_enable_protection ; enable write protection for external flash |
46 call update_battery_registers ; update battery registers into EEPROM | 59 call update_battery_registers ; update battery registers into EEPROM |
47 clrf divemins+0 | 60 clrf sm_temp1 |
48 clrf divemins+1 | 61 clrf sm_temp2 |
49 clrf apnoe_max_pressure+0 | 62 clrf sm_timer1 |
50 clrf apnoe_max_pressure+1 | 63 clrf sm_timer2 |
64 clrf sm_timer3 | |
51 call speed_normal | 65 call speed_normal |
52 bsf no_sensor_int ; No sensor interrupt | 66 bsf no_sensor_int ; No sensor interrupt |
53 clrf ADCON0 ; Power-Down ADC Module | 67 clrf ADCON0 ; Power-Down ADC Module |
68 | |
54 sleeploop_pre: | 69 sleeploop_pre: |
55 bcf deep_sleep ; Normal sleepmode | 70 bcf deep_sleep ; Normal sleepmode |
56 call I2C_sleep_accelerometer | 71 call I2C_sleep_accelerometer |
57 call I2C_sleep_compass | 72 call I2C_sleep_compass |
58 btfss analog_switches | 73 btfss analog_switches |
59 bra sleeploop_loop ; no analog switches | 74 bra sleeploop_loop ; no analog switches |
60 | 75 |
61 bsf power_sw1 | 76 bsf power_sw1 |
62 btfss power_sw1 | 77 btfss power_sw1 |
63 bra $-4 | 78 bra $-4 |
64 bsf power_sw2 | 79 bsf power_sw2 |
65 btfss power_sw2 | 80 btfss power_sw2 |
66 bra $-4 | 81 bra $-4 |
67 movlw .4 ; Wait for button circuity | 82 movlw .4 ; Wait for button circuity |
68 movwf apnoe_max_pressure+0 ; Used as temp | 83 movwf sm_temp1 ; Used as temp |
69 bcf onesecupdate | 84 bcf onesecupdate |
85 | |
70 sleeploop_pre1: | 86 sleeploop_pre1: |
71 rcall sleepmode_sleep | 87 rcall sleepmode_sleep |
72 btfss onesecupdate ; Wait 1 second | 88 btfss onesecupdate ; Wait 1 second |
73 bra sleeploop_pre1 | 89 bra sleeploop_pre1 |
74 bcf onesecupdate | 90 bcf onesecupdate |
75 decfsz apnoe_max_pressure+0,F | 91 decfsz sm_temp1,F |
76 bra sleeploop_pre1 | 92 bra sleeploop_pre1 |
77 | 93 movlw .32 ; Wait for button circuity |
78 movlw .32 ; Wait for button circuity | 94 movwf sm_temp1 ; Used as temp |
79 movwf apnoe_max_pressure+0 ; Used as temp | 95 |
80 sleeploop_pre2: | 96 sleeploop_pre2: |
81 call get_analog_switches | 97 call get_analog_switches |
82 decfsz apnoe_max_pressure+0,F | 98 decfsz sm_temp1,F |
83 bra sleeploop_pre2 | 99 bra sleeploop_pre2 |
84 | 100 |
85 bcf PIR1,TMR1IF | 101 bcf PIR1,TMR1IF |
86 bcf INTCON,INT0IF | 102 bcf INTCON,INT0IF |
87 bcf INTCON3,INT1IF | 103 bcf INTCON3,INT1IF |
88 bcf PIR5,TMR7IF | 104 bcf PIR5,TMR7IF |
89 bcf switch_left | 105 bcf switch_left |
90 bcf switch_right | 106 bcf switch_right |
91 bcf analog_sw2_pressed | 107 bcf analog_sw2_pressed |
92 bcf analog_sw1_pressed | 108 bcf analog_sw1_pressed |
93 bsf PIE1,0 ; (Re)Start Timer 1 Interrupt | 109 bsf PIE1,0 ; (Re)Start Timer 1 Interrupt |
94 bsf PIE2,1 ; (Re)Start Timer 2 Interrupt | 110 bsf PIE2,1 ; (Re)Start Timer 2 Interrupt |
95 bsf PIE5,3 ; (Re)Start Timer 7 Interrupt | 111 bsf PIE5,3 ; (Re)Start Timer 7 Interrupt |
96 bsf INTCON,4 ; (Re)Start INT0 Interrupt | 112 bsf INTCON,4 ; (Re)Start INT0 Interrupt |
97 bsf INTCON3,3 ; (Re)Start INT1 Interrupt | 113 bsf INTCON3,3 ; (Re)Start INT1 Interrupt |
98 | 114 |
99 sleeploop_loop: | 115 sleeploop_loop: |
100 btfsc onesecupdate ; one second in sleep? | 116 btfsc onesecupdate ; one second in sleep? |
101 rcall onesec_sleep ; check switches, check pressure sensor, etc. | 117 rcall onesec_sleep ; check switches, check pressure sensor, etc. |
102 | 118 |
103 btfss sleepmode ; wake up? (This bit will be set in other routines) | 119 btfss sleepmode ; wake up? (This bit will be set in other routines) |
104 goto restart ; yes | 120 goto restart ; yes |
105 | 121 |
106 btfsc deep_sleep ; Enter deep sleep? | 122 btfsc deep_sleep ; Enter deep sleep? |
107 bra deepsleep ; Yes | 123 bra deepsleep ; Yes |
124 | |
108 no_deepsleep: | 125 no_deepsleep: |
109 | 126 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) |
110 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | |
111 | 127 |
112 ; Any button pressed in sleep? | 128 ; Any button pressed in sleep? |
113 ; btfsc switch_left | 129 ; btfsc switch_left |
114 ; rcall onesec_sleep1a | 130 ; rcall onesec_sleep1a |
115 ; btfsc switch_right | 131 ; btfsc switch_right |
116 ; rcall onesec_sleep1a | 132 ; rcall onesec_sleep1a |
117 ; | 133 ; |
118 ; btfss sleepmode ; wake up? (This bit will be set in other routines) | 134 ; btfss sleepmode ; wake up? (This bit will be set in other routines) |
119 ; goto restart ; yes | 135 ; goto restart ; yes |
120 | 136 |
121 bra sleeploop_loop ; do loop until someting happens | 137 bra sleeploop_loop ; do loop until something happens |
122 | 138 |
123 deepsleep: | 139 deepsleep: |
124 btfss analog_switches | 140 btfss analog_switches |
125 bra no_deepsleep ; no analog switches, no deep sleep required | 141 bra no_deepsleep ; no analog switches, no deep sleep required |
126 | 142 |
127 bcf PIE1,0 ; Stop Timer 1 Interrupt | 143 bcf PIE1,0 ; Stop Timer 1 Interrupt |
128 bcf PIE2,1 ; Stop Timer 2 Interrupt | 144 bcf PIE2,1 ; Stop Timer 2 Interrupt |
129 bcf PIE5,3 ; Stop Timer 7 Interrupt | 145 bcf PIE5,3 ; Stop Timer 7 Interrupt |
130 bcf INTCON,4 ; Stop INT0 Interrupt | 146 bcf INTCON,4 ; Stop INT0 Interrupt |
131 bcf INTCON3,3 ; Stop INT1 Interrupt | 147 bcf INTCON3,3 ; Stop INT1 Interrupt |
132 bcf power_sw1 | 148 bcf power_sw1 |
133 bcf power_sw2 | 149 bcf power_sw2 |
134 rcall deepsleep_get_accel ; Read accelerometer into WREG | 150 rcall deepsleep_get_accel ; Read accelerometer into WREG |
135 movwf apnoe_max_pressure+0 ; Store init value | 151 movwf sm_temp1 ; Store init value |
136 | 152 |
137 deepsleep_loop: | 153 deepsleep_loop: |
138 btfsc onesecupdate ; one second in sleep? | 154 btfsc onesecupdate ; one second in sleep? |
139 rcall onesec_deepsleep ; check accelerometer | 155 rcall onesec_deepsleep ; check accelerometer |
140 | 156 |
141 btfsc onesecupdate ; one second in sleep? | 157 btfsc onesecupdate ; one second in sleep? |
142 rcall onesec_sleep ; check switches, check pressure sensor, etc. | 158 rcall onesec_sleep ; check switches, check pressure sensor, etc. |
143 | 159 |
144 rcall sleepmode_sleep | 160 rcall sleepmode_sleep |
145 | 161 |
146 btfss deep_sleep ; Enter normal sleepmode? | 162 btfss deep_sleep ; Enter normal sleepmode? |
147 bra sleeploop_pre ; Yes | 163 bra sleeploop_pre ; Yes |
148 | 164 |
149 bra deepsleep_loop ; do loop until someting happens | 165 bra deepsleep_loop ; do loop until something happens |
150 | 166 |
151 onesec_deepsleep: | 167 onesec_deepsleep: |
152 rcall deepsleep_get_accel ; Read accelerometer into WREG | 168 rcall deepsleep_get_accel ; Read accelerometer into WREG |
153 subwf apnoe_max_pressure+0,W ; apnoe_max_pressure+0 - accel_DZ+0 -> WREG | 169 subwf sm_temp1,W ; sm_temp1 - accel_DZ+0 -> WREG |
154 btfsc STATUS,N ; Result negative? | 170 btfsc STATUS,N ; Result negative? |
155 negf WREG ; Yes, negate it | 171 negf WREG ; Yes, negate it |
156 movwf apnoe_max_pressure+1 ; change of acceleration in Z-axis | 172 movwf sm_temp2 ; change of acceleration in Z-axis |
157 movlw .50 ; Threshold (mg) | 173 movlw .50 ; Threshold (mg) |
158 cpfslt apnoe_max_pressure+1 ; bigger then the threshold? | 174 cpfslt sm_temp2 ; bigger then the threshold? |
159 bcf deep_sleep ; Yes! | 175 bcf deep_sleep ; Yes! |
160 | 176 |
161 ; extern piezo_config_tx | 177 ; extern piezo_config_tx |
162 ; movff apnoe_max_pressure+0,WREG | 178 ; movff sm_temp1,WREG |
163 ; call piezo_config_tx | 179 ; call piezo_config_tx |
164 ; movff accel_DZ+0,WREG | 180 ; movff accel_DZ+0,WREG |
165 ; call piezo_config_tx | 181 ; call piezo_config_tx |
166 ; movff apnoe_max_pressure+1,WREG | 182 ; movff sm_temp2,WREG |
167 ; call piezo_config_tx | 183 ; call piezo_config_tx |
168 return | 184 |
169 | 185 return |
186 | |
170 deepsleep_get_accel: | 187 deepsleep_get_accel: |
171 call I2C_init_compass ; required for compass1 | 188 call I2C_init_compass ; required for compass1 |
172 call I2C_init_accelerometer ; required for compass2 | 189 call I2C_init_accelerometer ; required for compass2 |
173 call I2C_RX_accelerometer ; read Accelerometer | 190 call I2C_RX_accelerometer ; read Accelerometer |
174 call I2C_sleep_compass ; required for compass1 | 191 call I2C_sleep_compass ; required for compass1 |
175 call I2C_sleep_accelerometer ; required for compass2 | 192 call I2C_sleep_accelerometer ; required for compass2 |
176 movff accel_DZ+0,WREG | 193 movff accel_DZ+0,WREG |
177 return | 194 return |
178 | 195 |
179 onehour_sleep: | 196 onehour_sleep: |
180 call update_battery_registers ; update battery registers into EEPROM | 197 call update_battery_registers ; update battery registers into EEPROM |
181 call vault_decodata_into_eeprom ; update deco data | 198 call vault_decodata_into_eeprom ; update deco data |
182 bcf onehourupdate ; all done | 199 bcf onehourupdate ; all done |
183 return | 200 return |
184 | 201 |
185 onemin_sleep: | 202 onemin_sleep: |
186 btfsc onehourupdate ; one hour in sleep? | 203 btfsc onehourupdate ; one hour in sleep? |
187 rcall onehour_sleep ; Yes | 204 rcall onehour_sleep ; Yes |
188 | 205 |
189 btfsc battery_gauge_available | 206 btfsc battery_gauge_available |
190 call get_battery_voltage ; Check for charger | 207 call get_battery_voltage ; Check for charger |
191 | 208 |
192 ;---- adjust airpressure compensation any 15 minutes | 209 ;---- update tissues and CNS every 10 minutes when gradient factor is 0 (no supersaturation in any tissue any more) |
193 incf divemins+1,F ; counts to 14... | 210 movff int_O_gradient_factor+0,WREG ; get gradient factor, only the lower byte is used for the value |
194 movlw d'14' | 211 tstfsz WREG ; gradient factor = 0? |
195 cpfsgt divemins+1 | 212 bra onemin_sleep1 ; NO - continue with air pressure compensation |
196 bra onemin_sleep2 ; 15 minutes not done! | 213 incf sm_timer2,F ; count-up... |
197 | 214 movlw d'9' ; ...to 9 |
198 ; Tasks every 15 minutes in sleep | 215 cpfsgt sm_timer2 ; 10 minutes over? |
199 bsf deep_sleep ; enter deep-sleep mode | 216 bra onemin_sleep1 ; NO - continue with air pressure compensation |
200 | 217 clrf sm_timer2 ; reset counter |
201 clrf divemins+1 ; reset counter | 218 SAFE_2BYTE_COPY amb_pressure, int_I_pres_respiration ; copy pressure to deco routine |
202 | 219 call deco_calc_dive_interval_10min ; calculate 10 minutes under surface conditions |
203 call deco_calc_CNS_decrease_15min ; compute CNS decay in sleep only | 220 banksel common |
204 banksel common | 221 |
205 | 222 onemin_sleep1: |
206 SAFE_2BYTE_COPY last_surfpressure_15min, last_surfpressure_30min ; save older airpressure | 223 ;---- adjust air pressure compensation any 15 minutes |
207 SAFE_2BYTE_COPY amb_pressure, last_surfpressure_15min ; save new airpressure | 224 incf sm_timer3,F ; count-up... |
208 | 225 movlw d'14' ; ...to 14 |
209 movlw LOW max_surfpressure | 226 cpfsgt sm_timer3 ; 15 minutes over? |
210 movff WREG,sub_a+0 ; max. "allowed" airpressure in mbar | 227 bra onemin_sleep2 ; NO - continue with every-minute-tasks |
211 movlw HIGH max_surfpressure | 228 |
212 movff WREG,sub_a+1 ; max. "allowed" airpressure in mbar | 229 ; Tasks every 15 minutes in sleep |
230 bsf deep_sleep ; enter deep-sleep mode | |
231 clrf sm_timer3 ; reset counter | |
232 | |
233 SAFE_2BYTE_COPY last_surfpressure_15min, last_surfpressure_30min ; save older air pressure | |
234 SAFE_2BYTE_COPY amb_pressure, last_surfpressure_15min ; save new air pressure | |
235 | |
236 movlw LOW max_surfpressure | |
237 movff WREG,sub_a+0 ; max. "allowed" air pressure in mbar | |
238 movlw HIGH max_surfpressure | |
239 movff WREG,sub_a+1 ; max. "allowed" air pressure in mbar | |
213 movff last_surfpressure_15min+0,sub_b+0 | 240 movff last_surfpressure_15min+0,sub_b+0 |
214 movff last_surfpressure_15min+1,sub_b+1 | 241 movff last_surfpressure_15min+1,sub_b+1 |
215 call subU16 ; sub_c = sub_a - sub_b | 242 call subU16 ; sub_c = sub_a - sub_b |
216 btfss neg_flag ; Is 1080mbar < amb_pressure ? | 243 btfss neg_flag ; Is 1080mbar < amb_pressure ? |
217 bra onemin_sleep2 ; NO: current airpressure is lower then "allowed" airpressure, ok! | 244 bra onemin_sleep2 ; NO: current air pressure is lower then "allowed" air pressure, ok! |
218 | 245 |
219 ; not ok! Overwrite with max. "allowed" airpressure | 246 ; not ok! Overwrite with max. "allowed" air pressure |
220 movlw LOW max_surfpressure | 247 movlw LOW max_surfpressure |
221 movff WREG,last_surfpressure_15min+0 ; max. "allowed" airpressure in mbar | 248 movff WREG,last_surfpressure_15min+0 ; max. "allowed" air pressure in mbar |
222 movlw HIGH max_surfpressure | 249 movlw HIGH max_surfpressure |
223 movff WREG,last_surfpressure_15min+1 ; max. "allowed" airpressure in mbar | 250 movff WREG,last_surfpressure_15min+1 ; max. "allowed" air pressure in mbar |
224 | 251 |
225 onemin_sleep2: | 252 onemin_sleep2: |
226 ; Tasks every minute in sleep | 253 ; Tasks every minute in sleep |
227 SAFE_2BYTE_COPY amb_pressure, int_I_pres_respiration ; LOW copy pressure to deco routine | 254 |
228 call deco_calc_wo_deco_step_1_min ; "calc_tissue_sleep" | 255 ;---- update tissues and CNS every minute when gradient factor is >0 (supersaturation in at least one tissue) |
229 banksel common | 256 movff int_O_gradient_factor+0,WREG ; get gradient factor, only the lower byte is used for the value |
230 | 257 tstfsz WREG ; gradient factor = 0? |
231 bcf oneminupdate ; all done | 258 bra onemin_sleep3 ; NO - do tissue update on 1 minute schedule |
259 bra onemin_sleep4 ; YES - tissue update is done on 10 minutes schedule | |
260 | |
261 onemin_sleep3: | |
262 SAFE_2BYTE_COPY amb_pressure, int_I_pres_respiration ; copy pressure to deco routine | |
263 call deco_calc_dive_interval_1min ; calculate 1 minute under surface conditions | |
264 banksel common | |
265 | |
266 onemin_sleep4: | |
267 bcf oneminupdate ; all done | |
232 return | 268 return |
233 | 269 |
234 onesec_sleep: | 270 onesec_sleep: |
235 btfsc oneminupdate ; one minute in sleep? | 271 btfsc oneminupdate ; one minute in sleep? |
236 rcall onemin_sleep ; do oneminute tasks, e.g. calculate desaturation | 272 rcall onemin_sleep ; do one-minute tasks, e.g. calculate desaturation |
237 | 273 |
238 btfsc battery_gauge_available | 274 btfsc battery_gauge_available |
239 call get_battery_voltage ; Check for charger | 275 call get_battery_voltage ; Check for charger |
240 | 276 |
241 incf divemins+0,F ; counts to #test_pressure_in_sleep (10) | 277 incf sm_timer1,F ; counts to #test_pressure_in_sleep (10) |
242 movlw d'10' | 278 movlw d'10' |
243 cpfsgt divemins+0 ; here: temp variable | 279 cpfsgt sm_timer1 ; here: temp variable |
244 bra onesec_sleep1 ; #test_pressure_in_sleep not done yet | 280 bra onesec_sleep1 ; #test_pressure_in_sleep not done yet |
245 | 281 |
246 clrf divemins+0 ; clear counter | 282 clrf sm_timer1 ; clear counter |
247 rcall pressuretest_sleep_fast ; Gets pressure without averaging (faster!) | 283 rcall pressuretest_sleep_fast ; Gets pressure without averaging (faster!) |
248 ; compare current ambient pressure with wake_up_from_sleep | 284 ; compare current ambient pressure with wake_up_from_sleep |
249 movlw LOW wake_up_from_sleep | 285 movlw LOW wake_up_from_sleep |
250 movwf sub_a+0 ; power on if ambient pressure is greater threshold | 286 movwf sub_a+0 ; power on if ambient pressure is greater threshold |
251 movlw HIGH wake_up_from_sleep | 287 movlw HIGH wake_up_from_sleep |
252 movwf sub_a+1 ; power on if ambient pressure is greater threshold | 288 movwf sub_a+1 ; power on if ambient pressure is greater threshold |
253 SAFE_2BYTE_COPY amb_pressure, sub_b | 289 SAFE_2BYTE_COPY amb_pressure, sub_b |
254 call subU16 ; Is (1160mbar - averaged(amb_pressure)) < 0 ? | 290 call subU16 ; Is (1160mbar - averaged(amb_pressure)) < 0 ? |
255 btfsc neg_flag ; Wake up from Sleep? | 291 btfsc neg_flag ; Wake up from Sleep? |
256 bra onesec_sleep1a ; Yes, skip button checks, wake up! | 292 bra onesec_sleep1a ; Yes, skip button checks, wake up! |
257 | 293 |
258 btfsc battery_gauge_available | 294 btfsc battery_gauge_available |
259 bra onesec_sleep1 ; No wake-up with cR hardware | 295 bra onesec_sleep1 ; No wake-up with cR hardware |
260 btfsc vusb_in ; USB plugged in? | 296 btfsc vusb_in ; USB plugged in? |
261 bra onesec_sleep1a ; Yes, skip button checks, wake up! | 297 bra onesec_sleep1a ; Yes, skip button checks, wake up! |
262 | 298 |
263 onesec_sleep1: | 299 onesec_sleep1: |
264 bcf onesecupdate ; all done. | 300 bcf onesecupdate ; all done. |
265 ; Check switches | 301 ; Check switches |
266 btfsc switch_left | 302 btfsc switch_left |
267 bra onesec_sleep1a | 303 bra onesec_sleep1a |
268 btfsc switch_right | 304 btfsc switch_right |
269 bra onesec_sleep1a | 305 bra onesec_sleep1a |
306 | |
270 ; No button pressed | 307 ; No button pressed |
271 ; bcf INTCON,INT0IF ; Clear flag | 308 ; bcf INTCON,INT0IF ; Clear flag |
272 ; bcf INTCON3,INT1IF ; Clear flag | 309 ; bcf INTCON3,INT1IF ; Clear flag |
273 return | 310 |
274 | 311 return |
275 onesec_sleep1a: ; At least one button pressed or amb_pressure > wake_up_from_sleep | 312 |
276 ; bcf INTCON,INT0IF ; Clear flag | 313 onesec_sleep1a: ; At least one button pressed or amb_pressure > wake_up_from_sleep |
277 ; bcf INTCON3,INT1IF ; Clear flag | 314 ; bcf INTCON,INT0IF ; Clear flag |
278 bcf sleepmode ; wake up! | 315 ; bcf INTCON3,INT1IF ; Clear flag |
316 bcf sleepmode ; wake up! | |
279 SAFE_2BYTE_COPY last_surfpressure_30min, amb_pressure ; copy for compatibility | 317 SAFE_2BYTE_COPY last_surfpressure_30min, amb_pressure ; copy for compatibility |
280 movlw .0 | 318 movlw .0 |
281 movff WREG,sensor_state_counter ; Reset sensor state counter | 319 movff WREG,sensor_state_counter ; Reset sensor state counter |
282 bcf no_sensor_int ; normal sensor interrupt mode | 320 bcf no_sensor_int ; normal sensor interrupt mode |
283 return | 321 return |
284 | 322 |
285 pressuretest_sleep_fast: ; Get pressure without averaging (Faster to save some power in sleep mode) | 323 pressuretest_sleep_fast: ; Get pressure without averaging (Faster to save some power in sleep mode) |
286 banksel isr_backup ; Back to Bank0 ISR data | 324 banksel isr_backup ; Back to Bank0 ISR data |
287 clrf amb_pressure_avg+0 ; pressure average registers | 325 clrf amb_pressure_avg+0 ; pressure average registers |
288 clrf amb_pressure_avg+1 | 326 clrf amb_pressure_avg+1 |
289 clrf temperature_avg+0 | 327 clrf temperature_avg+0 |
290 clrf temperature_avg+1 | 328 clrf temperature_avg+1 |
291 call get_temperature_start ; and start temperature integration (73,5us) | 329 call get_temperature_start ; and start temperature integration (73,5us) |
292 banksel common | 330 banksel common |
293 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | 331 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) |
294 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | 332 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) |
295 banksel isr_backup ; Back to Bank0 ISR data | 333 banksel isr_backup ; Back to Bank0 ISR data |
296 call get_temperature_value ; State 1: Get temperature | 334 call get_temperature_value ; State 1: Get temperature |
297 call get_pressure_start ; Start pressure integration. | 335 call get_pressure_start ; Start pressure integration. |
298 banksel common | 336 banksel common |
299 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | 337 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) |
300 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | 338 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) |
301 banksel isr_backup ; Back to Bank0 ISR data | 339 banksel isr_backup ; Back to Bank0 ISR data |
302 call get_pressure_value ; State2: Get pressure (51us) | 340 call get_pressure_value ; State2: Get pressure (51us) |
303 call calculate_compensation ; calculate temperature compensated pressure (27us) | 341 call calculate_compensation ; calculate temperature compensated pressure (27us) |
304 banksel common | 342 banksel common |
305 SAFE_2BYTE_COPY amb_pressure_avg, amb_pressure ; copy for compatibility | 343 SAFE_2BYTE_COPY amb_pressure_avg, amb_pressure ; copy for compatibility |
306 return | 344 return |
307 | 345 |
308 sleepmode_sleep: | 346 sleepmode_sleep: |
309 banksel 0xF16 ; Addresses, F16h through F5Fh, are also used by SFRs, but are not part of the Access RAM. | 347 banksel 0xF16 ; Addresses, F16h through F5Fh, are also used by SFRs, but are not part of the Access RAM. |
310 clrf T7GCON ; Reset Timer7 Gate Control register | 348 clrf T7GCON ; Reset Timer7 Gate Control register |
311 movlw b'10001101' ; 1:1 Prescaler -> 2seconds@32768Hz, not synced | 349 movlw b'10001101' ; 1:1 Prescaler -> 2seconds@32768Hz, not synced |
312 movwf T7CON | 350 movwf T7CON |
313 sleep | 351 sleep |
314 sleep | 352 sleep |
315 clrf T7GCON ; Reset Timer7 Gate Control register | 353 clrf T7GCON ; Reset Timer7 Gate Control register |
316 movlw b'10001001' ; 1:1 Prescaler -> 2seconds@32768Hz, synced | 354 movlw b'10001001' ; 1:1 Prescaler -> 2seconds@32768Hz, synced |
317 movwf T7CON | 355 movwf T7CON |
318 banksel common ; Bank1 | 356 banksel common ; Bank1 |
319 return | 357 return |
320 | 358 |
321 END | 359 END |