Mercurial > public > hwos_code
annotate src/sleepmode.asm @ 130:c935f7fbd39c
no safety stop during menu display
author | heinrichsweikamp |
---|---|
date | Thu, 03 Jul 2014 19:34:41 +0200 |
parents | d076e9c02438 |
children | 939f1e83c4c2 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
3 ; File sleepmode.asm | |
4 ; | |
5 ; Sleepmode | |
6 ; | |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
10 ; 2011-08-12 : [mH] moving from OSTC code | |
11 | |
12 #include "ostc3.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" | |
28 | 26 #include "mcp.inc" |
0 | 27 |
28 gui CODE | |
29 | |
30 global sleeploop | |
31 sleeploop: ; enter sleepmode! | |
32 call disable_ir ; IR off | |
28 | 33 call mcp_sleep |
0 | 34 bcf LEDg |
35 bcf LEDr | |
39
e4e91fe8b09d
remember last customview in dive and surface mode
mh@mh-THINK.fritz.box
parents:
28
diff
changeset
|
36 movff menupos3,customview_surfmode; save last customview |
0 | 37 call TFT_Display_FadeOut |
38 call TFT_DisplayOff ; display off | |
39 call disable_rs232 ; USB off | |
40 call I2C_sleep_accelerometer | |
41 call I2C_sleep_compass | |
42 call ext_flash_enable_protection ; enable write protection for external flash | |
43 call update_battery_registers ; update battery registers into EEPROM | |
44 clrf divemins+0 | |
45 clrf divemins+1 | |
46 call speed_normal | |
47 bsf no_sensor_int ; No sensor interrupt | |
48 bcf enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) | |
49 clrf ADCON0 ; Power-Down ADC Module | |
50 sleeploop_loop: | |
51 btfsc onehourupdate ; one hour in sleep? | |
52 call update_battery_registers;update battery registers into EEPROM | |
53 | |
54 btfsc oneminupdate ; one minute in sleep? | |
55 rcall onemin_sleep ; do oneminute tasks, e.g. calculate desaturation | |
56 | |
57 btfsc onesecupdate ; one second in sleep? | |
58 rcall onesec_sleep ; check switches, check pressure sensor, etc. | |
59 | |
60 btfss sleepmode ; wake up? (This bit will be set in other routines) | |
61 goto restart ; yes | |
62 | |
63 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | |
64 | |
65 ; Any button pressed in sleep? | |
66 btfsc switch_left | |
67 rcall onesec_sleep1a | |
68 btfsc switch_right | |
69 rcall onesec_sleep1a | |
70 | |
71 btfss sleepmode ; wake up? (This bit will be set in other routines) | |
72 goto restart ; yes | |
73 | |
74 bra sleeploop_loop ; do loop until someting happens | |
75 | |
76 | |
77 onemin_sleep: | |
78 ;---- adjust airpressure compensation any 15 minutes | |
79 incf divemins+1,F ; counts to 14... | |
80 movlw d'14' | |
81 cpfsgt divemins+1 | |
82 bra onemin_sleep2 ; 15 minutes not done! | |
83 | |
84 ; Tasks every 15 minutes in sleep | |
85 clrf divemins+1 ; reset counter | |
86 | |
87 call deco_calc_CNS_decrease_15min ; compute CNS decay in sleep only | |
88 banksel common | |
89 | |
90 SAFE_2BYTE_COPY last_surfpressure_15min, last_surfpressure_30min ; save older airpressure | |
91 SAFE_2BYTE_COPY amb_pressure, last_surfpressure_15min ; save new airpressure | |
92 | |
93 movlw LOW max_surfpressure | |
94 movff WREG,sub_a+0 ; max. "allowed" airpressure in mbar | |
95 movlw HIGH max_surfpressure | |
96 movff WREG,sub_a+1 ; max. "allowed" airpressure in mbar | |
97 movff last_surfpressure_15min+0,sub_b+0 | |
98 movff last_surfpressure_15min+1,sub_b+1 | |
99 call subU16 ; sub_c = sub_a - sub_b | |
100 btfss neg_flag ; Is 1080mbar < amb_pressure ? | |
101 bra onemin_sleep2 ; NO: current airpressure is lower then "allowed" airpressure, ok! | |
102 | |
103 ; not ok! Overwrite with max. "allowed" airpressure | |
104 movlw LOW max_surfpressure | |
105 movff WREG,last_surfpressure_15min+0 ; max. "allowed" airpressure in mbar | |
106 movlw HIGH max_surfpressure | |
107 movff WREG,last_surfpressure_15min+1 ; max. "allowed" airpressure in mbar | |
108 | |
109 onemin_sleep2: | |
110 ; Tasks every minute in sleep | |
111 SAFE_2BYTE_COPY amb_pressure, int_I_pres_respiration ; LOW copy pressure to deco routine | |
112 call deco_calc_wo_deco_step_1_min ; "calc_tissue_sleep" | |
113 banksel common | |
114 | |
115 bcf oneminupdate ; all done | |
116 return | |
117 | |
118 onesec_sleep: | |
121 | 119 btfsc c3_hardware |
120 | 120 call get_battery_voltage ; Check for charger |
121 | |
0 | 122 incf divemins+0,F ; counts to #test_pressure_in_sleep (5) |
123 movlw d'5' | |
124 cpfsgt divemins+0 ; here: temp variable | |
125 bra onesec_sleep1 ; #test_pressure_in_sleep not done yet | |
126 | |
127 clrf divemins+0 ; clear counter | |
128 rcall pressuretest_sleep_fast ; Gets pressure without averaging (faster!) | |
129 ; compare current ambient pressure with wake_up_from_sleep | |
130 movlw LOW wake_up_from_sleep | |
131 movwf sub_a+0 ; power on if ambient pressure is greater threshold | |
132 movlw HIGH wake_up_from_sleep | |
133 movwf sub_a+1 ; power on if ambient pressure is greater threshold | |
134 SAFE_2BYTE_COPY amb_pressure, sub_b | |
135 call subU16 ; Is (1160mbar - averaged(amb_pressure)) < 0 ? | |
136 btfsc neg_flag ; Wake up from Sleep? | |
137 bra onesec_sleep1a ; Yes, skip button checks, wake up! | |
138 | |
123 | 139 btfsc c3_hardware |
140 bra onesec_sleep1 ; No wake-up with c3 hardware | |
0 | 141 btfsc vusb_in ; USB plugged in? |
123 | 142 bra onesec_sleep1a ; Yes, skip button checks, wake up! |
0 | 143 |
144 onesec_sleep1: | |
145 bcf onesecupdate ; all done. | |
146 ; Check switches | |
147 btfsc switch_left | |
148 bra onesec_sleep1a | |
149 btfsc switch_right | |
150 bra onesec_sleep1a | |
151 ; No button pressed | |
152 bcf INTCON,INT0IF ; Clear flag | |
153 bcf INTCON3,INT1IF ; Clear flag | |
154 return | |
155 | |
156 onesec_sleep1a: ; At least one button pressed or amb_pressure > wake_up_from_sleep | |
157 bcf INTCON,INT0IF ; Clear flag | |
158 bcf INTCON3,INT1IF ; Clear flag | |
159 bcf switch_right | |
160 bcf switch_left | |
161 bcf sleepmode ; wake up! | |
162 SAFE_2BYTE_COPY last_surfpressure_30min, amb_pressure ; copy for compatibility | |
163 movlw .0 | |
164 movff WREG,sensor_state_counter ; Reset sensor state counter | |
165 bcf no_sensor_int ; normal sensor interrupt mode | |
166 return | |
167 | |
168 pressuretest_sleep_fast: ; Get pressure without averaging (Faster to save some power in sleep mode) | |
169 banksel isr_backup ; Back to Bank0 ISR data | |
170 clrf amb_pressure_avg+0 ; pressure average registers | |
171 clrf amb_pressure_avg+1 | |
172 clrf temperature_avg+0 | |
173 clrf temperature_avg+1 | |
174 call get_temperature_start ; and start temperature integration (73,5us) | |
175 banksel common | |
176 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | |
177 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | |
178 banksel isr_backup ; Back to Bank0 ISR data | |
179 call get_temperature_value ; State 1: Get temperature | |
180 call get_pressure_start ; Start pressure integration. | |
181 banksel common | |
182 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | |
183 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | |
50 | 184 bsf LEDg ; Show some activity |
0 | 185 banksel isr_backup ; Back to Bank0 ISR data |
186 call get_pressure_value ; State2: Get pressure (51us) | |
187 call calculate_compensation ; calculate temperature compensated pressure (27us) | |
188 banksel common | |
189 SAFE_2BYTE_COPY amb_pressure_avg, amb_pressure ; copy for compatibility | |
50 | 190 bcf LEDg |
0 | 191 return |
192 | |
193 sleepmode_sleep: | |
194 banksel 0xF16 ; Addresses, F16h through F5Fh, are also used by SFRs, but are not part of the Access RAM. | |
195 clrf T7GCON ; Reset Timer7 Gate Control register | |
196 movlw b'10001101' ; 1:1 Prescaler -> 2seconds@32768Hz, not synced | |
197 movwf T7CON | |
198 banksel common ; Bank1 | |
199 sleep | |
200 nop | |
201 banksel 0xF16 ; Addresses, F16h through F5Fh, are also used by SFRs, but are not part of the Access RAM. | |
202 clrf T7GCON ; Reset Timer7 Gate Control register | |
203 movlw b'10001001' ; 1:1 Prescaler -> 2seconds@32768Hz, synced | |
204 movwf T7CON | |
205 banksel common ; Bank1 | |
206 return | |
207 | |
208 END |