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