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