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