Mercurial > public > hwos_code
annotate src/sleepmode.asm @ 122:3e84e2a64188
Show %'s for non-GF deco model in surface mode
author | heinrichsweikamp |
---|---|
date | Fri, 27 Jun 2014 16:55:49 +0200 |
parents | d519e24ef990 |
children | d076e9c02438 |
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 | |
139 btfsc vusb_in ; USB plugged in? | |
140 bra onesec_sleep1a ; Yes, skip button checks, wake up! | |
141 | |
142 onesec_sleep1: | |
143 bcf onesecupdate ; all done. | |
144 ; Check switches | |
145 btfsc switch_left | |
146 bra onesec_sleep1a | |
147 btfsc switch_right | |
148 bra onesec_sleep1a | |
149 ; No button pressed | |
150 bcf INTCON,INT0IF ; Clear flag | |
151 bcf INTCON3,INT1IF ; Clear flag | |
152 return | |
153 | |
154 onesec_sleep1a: ; At least one button pressed or amb_pressure > wake_up_from_sleep | |
155 bcf INTCON,INT0IF ; Clear flag | |
156 bcf INTCON3,INT1IF ; Clear flag | |
157 bcf switch_right | |
158 bcf switch_left | |
159 bcf sleepmode ; wake up! | |
160 SAFE_2BYTE_COPY last_surfpressure_30min, amb_pressure ; copy for compatibility | |
161 movlw .0 | |
162 movff WREG,sensor_state_counter ; Reset sensor state counter | |
163 bcf no_sensor_int ; normal sensor interrupt mode | |
164 return | |
165 | |
166 pressuretest_sleep_fast: ; Get pressure without averaging (Faster to save some power in sleep mode) | |
167 banksel isr_backup ; Back to Bank0 ISR data | |
168 clrf amb_pressure_avg+0 ; pressure average registers | |
169 clrf amb_pressure_avg+1 | |
170 clrf temperature_avg+0 | |
171 clrf temperature_avg+1 | |
172 call get_temperature_start ; and start temperature integration (73,5us) | |
173 banksel common | |
174 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | |
175 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | |
176 banksel isr_backup ; Back to Bank0 ISR data | |
177 call get_temperature_value ; State 1: Get temperature | |
178 call get_pressure_start ; Start pressure integration. | |
179 banksel common | |
180 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | |
181 rcall sleepmode_sleep ; Wait at least 35ms (every 62,5ms Timer7 wakeup) | |
50 | 182 bsf LEDg ; Show some activity |
0 | 183 banksel isr_backup ; Back to Bank0 ISR data |
184 call get_pressure_value ; State2: Get pressure (51us) | |
185 call calculate_compensation ; calculate temperature compensated pressure (27us) | |
186 banksel common | |
187 SAFE_2BYTE_COPY amb_pressure_avg, amb_pressure ; copy for compatibility | |
50 | 188 bcf LEDg |
0 | 189 return |
190 | |
191 sleepmode_sleep: | |
192 banksel 0xF16 ; Addresses, F16h through F5Fh, are also used by SFRs, but are not part of the Access RAM. | |
193 clrf T7GCON ; Reset Timer7 Gate Control register | |
194 movlw b'10001101' ; 1:1 Prescaler -> 2seconds@32768Hz, not synced | |
195 movwf T7CON | |
196 banksel common ; Bank1 | |
197 sleep | |
198 nop | |
199 banksel 0xF16 ; Addresses, F16h through F5Fh, are also used by SFRs, but are not part of the Access RAM. | |
200 clrf T7GCON ; Reset Timer7 Gate Control register | |
201 movlw b'10001001' ; 1:1 Prescaler -> 2seconds@32768Hz, synced | |
202 movwf T7CON | |
203 banksel common ; Bank1 | |
204 return | |
205 | |
206 END |