Mercurial > public > hwos_code
annotate src/sleepmode.asm @ 177:67db1f6d3787
Merge
author | heinrichsweikamp |
---|---|
date | Tue, 07 Oct 2014 08:42:38 +0200 |
parents | 4574aed5cd4c |
children | c511dc403d7e |
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 btfsc oneminupdate ; one minute in sleep? | |
59 rcall onemin_sleep ; do oneminute tasks, e.g. calculate desaturation | |
60 | |
134
4574aed5cd4c
Show clock in Apnea mode, minor layout changes in Apnea mode
heinrichsweikamp
parents:
133
diff
changeset
|
61 btfsc onehourupdate ; one hour in sleep? |
4574aed5cd4c
Show clock in Apnea mode, minor layout changes in Apnea mode
heinrichsweikamp
parents:
133
diff
changeset
|
62 rcall onehour_sleep ; Yes |
0 | 63 |
64 btfss sleepmode ; wake up? (This bit will be set in other routines) | |
65 goto restart ; yes | |
66 | |
67 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | |
68 | |
69 ; Any button pressed in sleep? | |
70 btfsc switch_left | |
71 rcall onesec_sleep1a | |
72 btfsc switch_right | |
73 rcall onesec_sleep1a | |
74 | |
75 btfss sleepmode ; wake up? (This bit will be set in other routines) | |
76 goto restart ; yes | |
77 | |
78 bra sleeploop_loop ; do loop until someting happens | |
79 | |
134
4574aed5cd4c
Show clock in Apnea mode, minor layout changes in Apnea mode
heinrichsweikamp
parents:
133
diff
changeset
|
80 onehour_sleep: |
4574aed5cd4c
Show clock in Apnea mode, minor layout changes in Apnea mode
heinrichsweikamp
parents:
133
diff
changeset
|
81 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
|
82 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
|
83 bcf onehourupdate ; all done |
4574aed5cd4c
Show clock in Apnea mode, minor layout changes in Apnea mode
heinrichsweikamp
parents:
133
diff
changeset
|
84 return |
0 | 85 |
86 onemin_sleep: | |
87 ;---- adjust airpressure compensation any 15 minutes | |
88 incf divemins+1,F ; counts to 14... | |
89 movlw d'14' | |
90 cpfsgt divemins+1 | |
91 bra onemin_sleep2 ; 15 minutes not done! | |
92 | |
93 ; Tasks every 15 minutes in sleep | |
94 clrf divemins+1 ; reset counter | |
95 | |
96 call deco_calc_CNS_decrease_15min ; compute CNS decay in sleep only | |
97 banksel common | |
98 | |
99 SAFE_2BYTE_COPY last_surfpressure_15min, last_surfpressure_30min ; save older airpressure | |
100 SAFE_2BYTE_COPY amb_pressure, last_surfpressure_15min ; save new airpressure | |
101 | |
102 movlw LOW max_surfpressure | |
103 movff WREG,sub_a+0 ; max. "allowed" airpressure in mbar | |
104 movlw HIGH max_surfpressure | |
105 movff WREG,sub_a+1 ; max. "allowed" airpressure in mbar | |
106 movff last_surfpressure_15min+0,sub_b+0 | |
107 movff last_surfpressure_15min+1,sub_b+1 | |
108 call subU16 ; sub_c = sub_a - sub_b | |
109 btfss neg_flag ; Is 1080mbar < amb_pressure ? | |
110 bra onemin_sleep2 ; NO: current airpressure is lower then "allowed" airpressure, ok! | |
111 | |
112 ; not ok! Overwrite with max. "allowed" airpressure | |
113 movlw LOW max_surfpressure | |
114 movff WREG,last_surfpressure_15min+0 ; max. "allowed" airpressure in mbar | |
115 movlw HIGH max_surfpressure | |
116 movff WREG,last_surfpressure_15min+1 ; max. "allowed" airpressure in mbar | |
117 | |
118 onemin_sleep2: | |
119 ; Tasks every minute in sleep | |
120 SAFE_2BYTE_COPY amb_pressure, int_I_pres_respiration ; LOW copy pressure to deco routine | |
121 call deco_calc_wo_deco_step_1_min ; "calc_tissue_sleep" | |
122 banksel common | |
123 | |
124 bcf oneminupdate ; all done | |
125 return | |
126 | |
127 onesec_sleep: | |
121 | 128 btfsc c3_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 | |
123 | 148 btfsc c3_hardware |
149 bra onesec_sleep1 ; No wake-up with c3 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 switch_right | |
169 bcf switch_left | |
170 bcf sleepmode ; wake up! | |
171 SAFE_2BYTE_COPY last_surfpressure_30min, amb_pressure ; copy for compatibility | |
172 movlw .0 | |
173 movff WREG,sensor_state_counter ; Reset sensor state counter | |
174 bcf no_sensor_int ; normal sensor interrupt mode | |
175 return | |
176 | |
177 pressuretest_sleep_fast: ; Get pressure without averaging (Faster to save some power in sleep mode) | |
178 banksel isr_backup ; Back to Bank0 ISR data | |
179 clrf amb_pressure_avg+0 ; pressure average registers | |
180 clrf amb_pressure_avg+1 | |
181 clrf temperature_avg+0 | |
182 clrf temperature_avg+1 | |
183 call get_temperature_start ; and start temperature integration (73,5us) | |
184 banksel common | |
185 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | |
186 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | |
187 banksel isr_backup ; Back to Bank0 ISR data | |
188 call get_temperature_value ; State 1: Get temperature | |
189 call get_pressure_start ; Start pressure integration. | |
190 banksel common | |
191 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | |
192 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | |
50 | 193 bsf LEDg ; Show some activity |
0 | 194 banksel isr_backup ; Back to Bank0 ISR data |
195 call get_pressure_value ; State2: Get pressure (51us) | |
196 call calculate_compensation ; calculate temperature compensated pressure (27us) | |
197 banksel common | |
198 SAFE_2BYTE_COPY amb_pressure_avg, amb_pressure ; copy for compatibility | |
50 | 199 bcf LEDg |
0 | 200 return |
201 | |
202 sleepmode_sleep: | |
203 banksel 0xF16 ; Addresses, F16h through F5Fh, are also used by SFRs, but are not part of the Access RAM. | |
204 clrf T7GCON ; Reset Timer7 Gate Control register | |
205 movlw b'10001101' ; 1:1 Prescaler -> 2seconds@32768Hz, not synced | |
206 movwf T7CON | |
207 banksel common ; Bank1 | |
208 sleep | |
209 nop | |
210 banksel 0xF16 ; Addresses, F16h through F5Fh, are also used by SFRs, but are not part of the Access RAM. | |
211 clrf T7GCON ; Reset Timer7 Gate Control register | |
212 movlw b'10001001' ; 1:1 Prescaler -> 2seconds@32768Hz, synced | |
213 movwf T7CON | |
214 banksel common ; Bank1 | |
215 return | |
216 | |
217 END |