Mercurial > public > hwos_code
comparison src/sleepmode.asm @ 0:11d4fc797f74
init
author | heinrichsweikamp |
---|---|
date | Wed, 24 Apr 2013 19:22:45 +0200 |
parents | |
children | fcaf94b913db |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:11d4fc797f74 |
---|---|
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" | |
26 | |
27 gui CODE | |
28 | |
29 global sleeploop | |
30 sleeploop: ; enter sleepmode! | |
31 call disable_ir ; IR off | |
32 bcf mcp_power ; RX off | |
33 btfsc mcp_power | |
34 bra $-4 | |
35 bcf LEDg | |
36 bcf LEDr | |
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: | |
119 incf divemins+0,F ; counts to #test_pressure_in_sleep (5) | |
120 movlw d'5' | |
121 cpfsgt divemins+0 ; here: temp variable | |
122 bra onesec_sleep1 ; #test_pressure_in_sleep not done yet | |
123 | |
124 clrf divemins+0 ; clear counter | |
125 rcall pressuretest_sleep_fast ; Gets pressure without averaging (faster!) | |
126 ; compare current ambient pressure with wake_up_from_sleep | |
127 movlw LOW wake_up_from_sleep | |
128 movwf sub_a+0 ; power on if ambient pressure is greater threshold | |
129 movlw HIGH wake_up_from_sleep | |
130 movwf sub_a+1 ; power on if ambient pressure is greater threshold | |
131 SAFE_2BYTE_COPY amb_pressure, sub_b | |
132 call subU16 ; Is (1160mbar - averaged(amb_pressure)) < 0 ? | |
133 btfsc neg_flag ; Wake up from Sleep? | |
134 bra onesec_sleep1a ; Yes, skip button checks, wake up! | |
135 | |
136 btfsc vusb_in ; USB plugged in? | |
137 bra onesec_sleep1a ; Yes, skip button checks, wake up! | |
138 | |
139 onesec_sleep1: | |
140 bcf onesecupdate ; all done. | |
141 ; Check switches | |
142 btfsc switch_left | |
143 bra onesec_sleep1a | |
144 btfsc switch_right | |
145 bra onesec_sleep1a | |
146 ; No button pressed | |
147 bcf INTCON,INT0IF ; Clear flag | |
148 bcf INTCON3,INT1IF ; Clear flag | |
149 return | |
150 | |
151 onesec_sleep1a: ; At least one button pressed or amb_pressure > wake_up_from_sleep | |
152 bcf INTCON,INT0IF ; Clear flag | |
153 bcf INTCON3,INT1IF ; Clear flag | |
154 bcf switch_right | |
155 bcf switch_left | |
156 bcf sleepmode ; wake up! | |
157 SAFE_2BYTE_COPY last_surfpressure_30min, amb_pressure ; copy for compatibility | |
158 movlw .0 | |
159 movff WREG,sensor_state_counter ; Reset sensor state counter | |
160 bcf no_sensor_int ; normal sensor interrupt mode | |
161 return | |
162 | |
163 pressuretest_sleep_fast: ; Get pressure without averaging (Faster to save some power in sleep mode) | |
164 banksel isr_backup ; Back to Bank0 ISR data | |
165 clrf amb_pressure_avg+0 ; pressure average registers | |
166 clrf amb_pressure_avg+1 | |
167 clrf temperature_avg+0 | |
168 clrf temperature_avg+1 | |
169 call get_temperature_start ; and start temperature integration (73,5us) | |
170 banksel common | |
171 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | |
172 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | |
173 banksel isr_backup ; Back to Bank0 ISR data | |
174 call get_temperature_value ; State 1: Get temperature | |
175 call get_pressure_start ; Start pressure integration. | |
176 banksel common | |
177 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | |
178 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | |
179 banksel isr_backup ; Back to Bank0 ISR data | |
180 call get_pressure_value ; State2: Get pressure (51us) | |
181 call calculate_compensation ; calculate temperature compensated pressure (27us) | |
182 banksel common | |
183 SAFE_2BYTE_COPY amb_pressure_avg, amb_pressure ; copy for compatibility | |
184 return | |
185 | |
186 sleepmode_sleep: | |
187 banksel 0xF16 ; Addresses, F16h through F5Fh, are also used by SFRs, but are not part of the Access RAM. | |
188 clrf T7GCON ; Reset Timer7 Gate Control register | |
189 movlw b'10001101' ; 1:1 Prescaler -> 2seconds@32768Hz, not synced | |
190 movwf T7CON | |
191 banksel common ; Bank1 | |
192 sleep | |
193 nop | |
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'10001001' ; 1:1 Prescaler -> 2seconds@32768Hz, synced | |
197 movwf T7CON | |
198 banksel common ; Bank1 | |
199 return | |
200 | |
201 END |