Mercurial > public > mk2
annotate code_part1/OSTC_code_asm_part1/sleepmode.asm @ 830:e8f5eed0eccf
BUGFIX: Minor layout fix (Battery warning in divemode)
author | heinrichsweikamp |
---|---|
date | Mon, 09 Nov 2015 14:04:17 +0100 |
parents | 2a0e5d884fc3 |
children |
rev | line source |
---|---|
815 | 1 ; OSTC Mk.2, 2N and 2C - diving computer code |
807
c50296c3059e
BUGFIX: Divetime had unwanted "." behind the minutes
heinrichsweikamp
parents:
774
diff
changeset
|
2 ; Copyright (C) 2015 HeinrichsWeikamp GbR |
0 | 3 ; This program is free software: you can redistribute it and/or modify |
4 ; it under the terms of the GNU General Public License as published by | |
5 ; the Free Software Foundation, either version 3 of the License, or | |
6 ; (at your option) any later version. | |
7 ; This program is distributed in the hope that it will be useful, | |
8 ; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
9 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10 ; GNU General Public License for more details. | |
11 ; You should have received a copy of the GNU General Public License | |
12 ; along with this program. If not, see <http://www.gnu.org/licenses/>. | |
13 ; Routines for sleepmode | |
14 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com | |
15 ; written: 050520 | |
16 ; last updated: 090507 | |
17 ; known bugs: | |
18 ; ToDo: | |
19 sleeploop: ; enter sleepmode! | |
20 ; first check if the 16 hash char are=0 | |
21 lfsr FSR2, char_O_hash | |
22 movlw d'16' | |
23 movwf temp1 | |
24 sleeploop1: | |
25 tstfsz POSTINC2 ; Test hash values | |
26 bra sleeploop2 ; At least one char is not zero -> Do not build hash | |
27 decfsz temp1,F | |
28 bra sleeploop1 | |
29 ; build hash (about 90sek @ 16MHz) | |
681 | 30 call DISP_ClearScreen ; clear |
0 | 31 DISPLAYTEXT .1 ; "Building MD2 hash" |
32 DISPLAYTEXT .2 ; "Please wait..." | |
116 | 33 call deco_hash ; calculate MD2 hash |
0 | 34 movlb b'00000001' ; Back to Bank1 |
35 sleeploop2: | |
681 | 36 call DISP_DisplayOff ; display off |
0 | 37 call disable_rs232 ; disable UART module |
626
bab5a9fc1b10
restore last used customview in dive- and surface-mode
heinrichsweikamp
parents:
497
diff
changeset
|
38 |
bab5a9fc1b10
restore last used customview in dive- and surface-mode
heinrichsweikamp
parents:
497
diff
changeset
|
39 ; Save surface mode custom view |
bab5a9fc1b10
restore last used customview in dive- and surface-mode
heinrichsweikamp
parents:
497
diff
changeset
|
40 movff menupos3,EEDATA ; Copy to EEDATA |
bab5a9fc1b10
restore last used customview in dive- and surface-mode
heinrichsweikamp
parents:
497
diff
changeset
|
41 write_int_eeprom d'93' ; Write last selected customview surface mode into EEPROM |
bab5a9fc1b10
restore last used customview in dive- and surface-mode
heinrichsweikamp
parents:
497
diff
changeset
|
42 |
0 | 43 clrf divemins+0 |
44 clrf divemins+1 | |
45 bcf TRISB,6 | |
46 bcf TRISB,7 | |
47 bcf PORTB,6 | |
48 bcf PORTB,7 ; Disable UART | |
49 sleeploop_loop: | |
50 btfsc oneminupdate ; one minute in sleep? | |
51 rcall onemin_sleep ; do oneminute tasks, e.g. calculate desaturation | |
52 | |
53 btfsc onesecupdate ; one second in sleep? | |
54 rcall onesec_sleep ; check switches, check pressure sensor, etc. | |
55 | |
56 btfss sleepmode ; wake up? (This bit will be set in other routines) | |
57 goto restart ; yes | |
58 nop | |
59 sleep ; Sleep until Timer1 will wake up the device | |
60 nop | |
61 bra sleeploop_loop ; do loop until someting happens | |
62 | |
63 | |
64 onemin_sleep: | |
65 call get_battery_voltage ; get battery voltage | |
66 btfsc enter_error_sleep ; Enter Fatal Error Routine? | |
813
c87b9f2fb2f6
wakeup from deep sleep mode automatically upon USB connect
heinrichsweikamp
parents:
807
diff
changeset
|
67 goto fatal_error_sleep ; Yes (In Sleepmode_vxx.asm!) |
0 | 68 |
354 | 69 ;---- adjust airpressure compensation any 15 minutes |
0 | 70 incf divemins+1,F ; counts to 14... |
71 movlw d'14' | |
72 cpfsgt divemins+1 | |
73 bra onemin_sleep2 ; 15 minutes not done! | |
354 | 74 clrf divemins+1 ; reset counter |
0 | 75 |
76 rcall pressuretest_sleep_fast ; Gets pressure without averaging (faster!) | |
77 | |
357
562f1bc79f3c
Bugfix: Wake-up into divemode with 1.91alpha
Heinrichsweikamp
parents:
341
diff
changeset
|
78 SAFE_2BYTE_COPY amb_pressure_avg, amb_pressure ; copy for compatibility |
562f1bc79f3c
Bugfix: Wake-up into divemode with 1.91alpha
Heinrichsweikamp
parents:
341
diff
changeset
|
79 |
0 | 80 call check_temp_extrema ; Check for temperature extremas |
81 | |
116 | 82 call deco_calc_CNS_decrease_15min ; compute CNS decay in sleep only |
0 | 83 movlb b'00000001' |
354 | 84 |
0 | 85 movff last_surfpressure_15min+0,last_surfpressure_30min+0 ; save older airpressure |
86 movff last_surfpressure_15min+1,last_surfpressure_30min+1 ; save older airpressure | |
341
2144f19fa1eb
BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents:
297
diff
changeset
|
87 SAFE_2BYTE_COPY amb_pressure, last_surfpressure_15min ; save new airpressure |
0 | 88 |
89 GETCUSTOM15 d'7' ; loads max_sufpressure into lo, hi | |
398
ab962c4b19d6
Fixing issue 50, correct "Bar" to "bar" in texts and comments
heinrichsweikamp
parents:
361
diff
changeset
|
90 movff lo,sub_a+0 ; max. "allowed" airpressure in mbar |
0 | 91 movff hi,sub_a+1 |
92 movff last_surfpressure_15min+0,sub_b+0 | |
93 movff last_surfpressure_15min+1,sub_b+1 | |
94 call sub16 ; sub_c = sub_a - sub_b | |
354 | 95 btfss neg_flag ; Is 1080mbar < amb_pressure ? |
96 bra onemin_sleep2 ; NO: current airpressure is lower then "allowed" airpressure, ok! | |
97 | |
98 ; not ok! Overwrite with max. "allowed" airpressure | |
0 | 99 GETCUSTOM15 d'7' ; loads max_sufpressure into lo, hi |
398
ab962c4b19d6
Fixing issue 50, correct "Bar" to "bar" in texts and comments
heinrichsweikamp
parents:
361
diff
changeset
|
100 movff lo,last_surfpressure_15min+0 ; max. "allowed" airpressure in mbar |
ab962c4b19d6
Fixing issue 50, correct "Bar" to "bar" in texts and comments
heinrichsweikamp
parents:
361
diff
changeset
|
101 movff hi,last_surfpressure_15min+1 ; max. "allowed" airpressure in mbar |
0 | 102 |
103 onemin_sleep2: | |
341
2144f19fa1eb
BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents:
297
diff
changeset
|
104 SAFE_2BYTE_COPY amb_pressure, int_I_pres_respiration ; LOW copy pressure to deco routine |
0 | 105 GETCUSTOM8 d'11' ; Saturation multiplier % |
251 | 106 movff WREG,char_I_saturation_multiplier |
0 | 107 GETCUSTOM8 d'12' ; Desaturation multiplier % |
251 | 108 movff WREG,char_I_desaturation_multiplier |
116 | 109 call deco_calc_wo_deco_step_1_min ; "calc_tissue_sleep" |
0 | 110 movlb b'00000001' ; RAM Bank1 selected |
111 | |
112 bcf oneminupdate ; all done | |
113 return | |
114 | |
115 onesec_sleep: | |
116 call test_charger ; charger on? | |
117 | |
118 btfss nofly_active | |
119 bra onesec_sleep_nonofly | |
120 | |
21 | 121 bsf LED_blue ; Set nofly LED |
0 | 122 |
123 nop | |
124 sleep | |
125 nop | |
126 | |
127 onesec_sleep_nonofly: | |
21 | 128 bcf LED_blue ; Clear nofly LED |
0 | 129 incf divemins+0,F ; counts to #test_pressure_in_sleep (5) |
130 movlw d'5' | |
131 cpfsgt divemins+0 ; here: temp variable | |
132 bra onesec_sleep1 ; #test_pressure_in_sleep not done yet | |
354 | 133 clrf divemins+0 |
134 | |
0 | 135 rcall pressuretest_sleep_fast ; Gets pressure without averaging (faster!) |
421
af2894e5cda4
copy from amb_pressure_avg to amb_pressure for compatibility
heinrichsweikamp
parents:
398
diff
changeset
|
136 SAFE_2BYTE_COPY amb_pressure_avg, amb_pressure ; copy for compatibility |
0 | 137 |
361 | 138 ; compare current ambient pressure with threshold CF6==1160mbar. |
0 | 139 GETCUSTOM15 d'6' ; loads pressure threshold into lo,hi |
140 movff lo,sub_a+0 ; power on if ambient pressure is greater threshold | |
141 movff hi,sub_a+1 | |
361 | 142 SAFE_2BYTE_COPY amb_pressure_avg, sub_b |
143 call sub16 ; Is (1160mbar - averaged(amb_pressure)) < 0 ? | |
0 | 144 bsf sleepmode |
145 btfsc neg_flag ; Wake up from Sleep? | |
146 bcf sleepmode ; amb_pressure>pressure_offset_divemode: wake up! | |
354 | 147 |
0 | 148 onesec_sleep1: |
149 bcf onesecupdate ; all done. | |
150 btfsc switch_left | |
151 bra onesec_sleep1a | |
152 btfsc switch_right | |
153 bra onesec_sleep1a | |
154 ; No button pressed | |
155 bcf INTCON,INT0IF ; Clear flag | |
156 bcf INTCON3,INT1IF ; Clear flag | |
157 bcf switch_right | |
158 bcf switch_left | |
159 bcf T0CON,TMR0ON ; Stop Timer 0 | |
160 return | |
161 onesec_sleep1a: ; At least one button pressed.... | |
162 bcf INTCON,INT0IF ; Clear flag | |
163 bcf INTCON3,INT1IF ; Clear flag | |
164 bcf switch_right | |
165 bcf switch_left | |
166 bcf T0CON,TMR0ON ; Stop Timer 0 | |
354 | 167 bcf sleepmode ; wake up! |
125 | 168 |
213
d19445e0cb2f
BUGFIX Altimeter reset when exiting sleep mode (bug#&6).
JeanDo
parents:
153
diff
changeset
|
169 ; Restart altimeter averaging, so next averaging starts right over... |
d19445e0cb2f
BUGFIX Altimeter reset when exiting sleep mode (bug#&6).
JeanDo
parents:
153
diff
changeset
|
170 call altimeter_restart |
125 | 171 |
0 | 172 return |
173 | |
174 pressuretest_sleep_fast: ; Get pressure without averaging (Faster to save some power in sleep mode) | |
175 call get_temperature_start ; and start temperature integration (73,5us) | |
176 sleep | |
177 nop | |
178 sleep | |
179 nop | |
180 sleep ; Wait at least 35ms (every 16.5ms Timer1 wakeup) | |
181 call get_temperature_value ; State 1: Get temperature | |
182 call get_pressure_start ; Start pressure integration. | |
183 sleep | |
184 nop | |
185 sleep | |
186 nop | |
187 sleep ; Wait at least 35ms (every 16.5ms Timer1 wakeup) | |
188 call get_pressure_value ; State2: Get pressure (51us) | |
703 | 189 clrf temperature_avg+0 |
190 clrf temperature_avg+1 | |
357
562f1bc79f3c
Bugfix: Wake-up into divemode with 1.91alpha
Heinrichsweikamp
parents:
341
diff
changeset
|
191 clrf amb_pressure_avg+0 |
562f1bc79f3c
Bugfix: Wake-up into divemode with 1.91alpha
Heinrichsweikamp
parents:
341
diff
changeset
|
192 clrf amb_pressure_avg+1 ; clear for sleep routine |
0 | 193 call calculate_compensation ; calculate temperature compensated pressure (233us) |
194 return | |
195 | |
196 fatal_error_sleep: | |
774 | 197 call DISP_DisplayOff ; display off |
198 call disable_rs232 ; disable UART module | |
199 | |
200 bcf TRISB,6 | |
201 bcf TRISB,7 | |
202 bcf PORTB,6 | |
203 bcf PORTB,7 ; Disable UART | |
204 fatal_error_sleep_loop: | |
0 | 205 movff fatal_error_code,temp4 |
206 movlw d'15' | |
207 movwf temp1 | |
208 fatal_error_sleep_loop1: | |
209 sleep | |
210 nop | |
211 decfsz temp1,F | |
212 bra fatal_error_sleep_loop1 | |
213 fatal_error_sleep_loop2: | |
774 | 214 call get_battery_voltage ; get battery voltage |
215 btfss enter_error_sleep ; REALLY enter Fatal Error Routine? | |
216 goto restart ; No | |
813
c87b9f2fb2f6
wakeup from deep sleep mode automatically upon USB connect
heinrichsweikamp
parents:
807
diff
changeset
|
217 |
c87b9f2fb2f6
wakeup from deep sleep mode automatically upon USB connect
heinrichsweikamp
parents:
807
diff
changeset
|
218 btfss CHRG_IN ; If CHRG_IN=0 -> CC active |
c87b9f2fb2f6
wakeup from deep sleep mode automatically upon USB connect
heinrichsweikamp
parents:
807
diff
changeset
|
219 goto restart ; wake up |
c87b9f2fb2f6
wakeup from deep sleep mode automatically upon USB connect
heinrichsweikamp
parents:
807
diff
changeset
|
220 |
21 | 221 bsf LED_red |
0 | 222 clrwdt |
223 WAIT10US d'5' | |
21 | 224 bcf LED_red |
0 | 225 sleep |
226 nop | |
227 decfsz temp4,F | |
228 bra fatal_error_sleep_loop2 | |
229 bra fatal_error_sleep_loop |