Mercurial > public > hwos_code
annotate src/start.asm @ 165:9b82239fa062
testing consumption
author | heinrichsweikamp |
---|---|
date | Thu, 11 Sep 2014 15:41:48 +0200 |
parents | 5f71e31bd5b3 |
children | 669b5d00706d |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
3 ; File start.asm | |
4 ; | |
5 ; Startup subroutines | |
6 ; | |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
10 ; 2011-08-06 : [mH] moving from OSTC code | |
11 | |
12 #include "ostc3.inc" ; Mandatory header | |
13 #include "ms5541.inc" | |
14 #include "isr.inc" | |
15 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c | |
16 #include "eeprom_rs232.inc" | |
17 #include "math.inc" | |
18 #include "tft.inc" | |
19 #include "surfmode.inc" | |
20 #include "wait.inc" | |
21 #include "rtc.inc" | |
22 #include "external_flash.inc" | |
23 #include "convert.inc" | |
24 #include "strings.inc" | |
25 #include "tft_outputs.inc" | |
113 | 26 #include "adc_lightsensor.inc" |
27 #include "i2c.inc" | |
0 | 28 |
29 extern init_ostc3 | |
30 extern option_restore_all | |
31 | |
32 ;============================================================================= | |
33 ; Reset vector: What to do on device wake-up and hard reset. | |
34 ; | |
35 reset_v code 0x00000 | |
36 ; goto start | |
37 goto 0x1FF00 ; Bootloader | |
38 | |
39 ORG 0x00004 ; Needed for second-level bootloader | |
40 goto start | |
41 ;============================================================================= | |
42 boot CODE | |
43 global start | |
44 | |
45 start: | |
46 lfsr FSR0,0x000 ; Clear rambank 0-14 | |
47 clear_rambank: | |
48 clrf POSTINC0 | |
49 movlw 0x0F | |
50 cpfseq FSR0H ; Bank 14 done? | |
51 bra clear_rambank ; clear... | |
52 | |
53 call init_ostc3 | |
54 call speed_normal | |
55 | |
56 bsf no_sensor_int ; disable sensor interrupt | |
57 | |
58 call disable_rs232 ; disable UART module | |
59 ; Air pressure compensation after reset | |
60 call get_calibration_data ; Get calibration data from pressure sensor | |
61 banksel common ; get_calibration_data uses isr_backup | |
62 bcf no_sensor_int ; normal sensor interrupt mode | |
63 | |
113 | 64 call piezo_config |
10 | 65 call TFT_DisplayOff ; display off |
66 bsf LEDr ; Status LED | |
0 | 67 bcf pressure_refresh |
68 ; First pass will not have valid temperature! | |
69 btfss pressure_refresh ; Air pressure compensation | |
70 bra $-2 | |
50 | 71 bcf LEDr |
0 | 72 ; Second pass |
73 bcf pressure_refresh | |
74 btfss pressure_refresh ; Air pressure compensation | |
75 bra $-2 | |
76 | |
77 clrf rel_pressure+0 | |
78 clrf rel_pressure+1 | |
79 clrf surface_interval+0 | |
80 clrf surface_interval+1 | |
81 | |
82 SAFE_2BYTE_COPY amb_pressure, last_surfpressure | |
83 | |
84 movlw LOW max_surfpressure | |
85 movff WREG,sub_a+0 ; max. "allowed" airpressure in mbar | |
86 movlw HIGH max_surfpressure | |
87 movff WREG,sub_a+1 ; max. "allowed" airpressure in mbar | |
88 movff last_surfpressure+0,sub_b+0 | |
89 movff last_surfpressure+1,sub_b+1 | |
90 call subU16 ; sub_c = sub_a - sub_b | |
91 btfss neg_flag ; Is 1080mbar < amb_pressure ? | |
92 bra start_copy_pressure ; NO: current airpressure is lower then "allowed" airpressure, ok! | |
93 | |
94 ; not ok! Overwrite with max. "allowed" airpressure | |
95 movlw LOW max_surfpressure | |
96 movff WREG,last_surfpressure+0 ; max. "allowed" airpressure in mbar | |
97 movlw HIGH max_surfpressure | |
98 movff WREG,last_surfpressure+1 ; max. "allowed" airpressure in mbar | |
99 | |
100 start_copy_pressure: | |
101 movff last_surfpressure+0,last_surfpressure_15min+0 | |
102 movff last_surfpressure+1,last_surfpressure_15min+1 | |
103 movff last_surfpressure+0,last_surfpressure_30min+0 | |
104 movff last_surfpressure+1,last_surfpressure_30min+1 ; Rests all airpressure registers | |
105 | |
106 ; reset deco data for surface mode | |
107 movlw d'79' | |
108 movff WREG,char_I_N2_ratio ; 79% N2 | |
109 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; copy for deco routine | |
110 movff int_I_pres_respiration+0,int_I_pres_surface+0 ; copy for desat routine | |
111 movff int_I_pres_respiration+1,int_I_pres_surface+1 | |
112 | |
113 extern deco_reset | |
114 call deco_reset | |
115 clrf nofly_time+0 ; Reset NoFly | |
116 clrf nofly_time+1 | |
117 clrf desaturation_time+0 ; Reset Desat | |
118 clrf desaturation_time+1 | |
133
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
119 |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
120 call rtc_init ; init clock |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
121 |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
122 movlw HIGH .512 ; =2 |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
123 movwf EEADRH |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
124 read_int_eeprom .0 |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
125 clrf EEADRH |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
126 movlw 0xAA |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
127 cpfseq EEDATA ; =0xAA |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
128 bra no_deco_restore ; No |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
129 |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
130 extern restore_decodata_from_eeprom |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
131 call restore_decodata_from_eeprom ; Reload deco data and date/time from eeprom |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
132 |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
133 no_deco_restore: |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
134 call deco_calc_desaturation_time ; calculate desaturation time |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
135 banksel common |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
136 call deco_calc_wo_deco_step_1_min ; calculate deco in surface mode |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
137 banksel common |
0 | 138 bcf menubit ; clear menu flag |
139 ; Check for Power-on reset here | |
140 extern new_battery_menu | |
141 extern use_old_batteries | |
142 | |
143 btfsc RCON,POR ; Was this a power-on reset? | |
144 goto use_old_batteries ; No, load last stored battery values | |
145 ; "new_battery_menu" and "use_old_batteries" 'goto' back to "power_on_return" | |
146 | |
147 ; Yes | |
148 goto new_battery_menu ; show "New battery dialog" | |
149 ; "new_battery_menu" and "use_old_batteries" 'goto' back to "power_on_return" | |
150 | |
151 global power_on_return | |
152 power_on_return: | |
153 bsf RCON,POR ; Set bit for next detection | |
154 | |
155 ; check firmware and reset Custom Functions after an update | |
156 movlw d'1' | |
157 movwf EEADR | |
158 movlw d'1' | |
159 movwf EEADRH | |
160 call read_eeprom ; read current version x | |
161 movff EEDATA,temp1 | |
162 incf EEADR,F ; set to 0x102 | |
163 call read_eeprom ; read current version y | |
164 movff EEDATA,temp2 | |
165 clrf EEADRH ; Reset EEADRH | |
166 | |
167 movlw softwareversion_x | |
168 cpfseq temp1 ; compare version x | |
169 bra check_firmware_new ; is not equal -> reset CF and store new version in EEPROM | |
170 | |
171 movlw softwareversion_y | |
172 cpfseq temp2 ; compare version y | |
173 bra check_firmware_new ; is not equal -> reset CF and store new version in EEPROM | |
174 bra restart ; x and y are equal -> do not reset cf | |
175 | |
176 check_firmware_new: | |
177 call speed_normal | |
178 call TFT_boot ; Initialize TFT (includes clear screen) | |
179 clrf CCPR1L ; Backlight off | |
180 WIN_TOP .50 | |
181 WIN_LEFT .10 | |
182 movlw LOW 0x1E000 | |
183 movwf TBLPTRL | |
184 movlw HIGH 0x1E000 | |
185 movwf TBLPTRH | |
186 movlw UPPER 0x1E000 | |
187 movwf TBLPTRU | |
188 extern color_image | |
189 call color_image ; Show logo | |
190 call TFT_standard_color | |
191 WIN_SMALL .10,.100 | |
52 | 192 STRCPY_TEXT_PRINT tNewFirmware1 ; "Update successfull!" |
0 | 193 WIN_SMALL .10,.140 |
194 STRCPY_TEXT tNewFirmware2 ; "New Firmware: " | |
195 movlw softwareversion_x | |
196 movwf lo | |
197 bsf leftbind | |
198 output_8 | |
199 PUTC "." | |
200 movlw softwareversion_y | |
201 movwf lo | |
45 | 202 output_99x |
0 | 203 bcf leftbind |
204 STRCAT_PRINT "" ; Print second row | |
205 call TFT_Display_FadeIn ; Display resulting surface screen. | |
206 | |
207 ; place "after-update reset" here... | |
93
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
208 |
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
209 extern oPressureAdjust, option_reset, option_save |
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
210 lfsr FSR0,oPressureAdjust |
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
211 call option_reset ; Reset FSR0 option to factory default. |
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
212 lfsr FSR0,oPressureAdjust |
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
213 call option_save ; Save in EEPROM |
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
214 |
0 | 215 movlw d'1' ; store current version in EEPROM |
216 movwf EEADR | |
217 movlw d'1' | |
218 movwf EEADRH | |
219 movlw softwareversion_x | |
220 movwf EEDATA | |
221 call write_eeprom ; write version x | |
222 incf EEADR,F ; set to 0x102 | |
223 movlw softwareversion_y | |
224 movwf EEDATA | |
225 call write_eeprom ; write version y | |
226 clrf EEADRH ; Reset EEADRH | |
227 | |
228 movlw .7 | |
229 movwf lo | |
230 check_firmware_new2: | |
231 ; Wait 1 second | |
232 bcf onesecupdate | |
233 btfss onesecupdate | |
234 bra $-2 | |
235 decfsz lo,F ; Wait 10 seconds... | |
236 bra check_firmware_new2 | |
237 | |
238 global restart | |
239 restart: | |
240 clrf STKPTR ; Never return from here | |
21
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
16
diff
changeset
|
241 extern option_save_all, option_check_all |
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
16
diff
changeset
|
242 |
0 | 243 btfsc menubit ; Return from Menu/COMM mode or timeout? |
244 call option_save_all ; Yes, save all settings into EEPROM | |
245 | |
23
e402813343b6
new option to switch samplingrate between 10s and 2s
heinrichsweikamp
parents:
21
diff
changeset
|
246 call option_check_all ; Check all options (and reset if not within their min/max boundaries) |
e402813343b6
new option to switch samplingrate between 10s and 2s
heinrichsweikamp
parents:
21
diff
changeset
|
247 |
0 | 248 clrf flag1 ; clear all flags |
249 clrf flag2 | |
250 clrf flag3 | |
251 clrf flag4 | |
252 clrf flag5 | |
253 clrf flag6 | |
254 clrf flag7 | |
255 clrf flag8 | |
16
7b06f20881be
calm compass reading for minor heading changes
heinrichsweikamp
parents:
10
diff
changeset
|
256 clrf flag9 |
113 | 257 clrf flag10 |
0 | 258 bsf tft_is_dimming ; TFT is dimming up (soon), ignore ambient sensor! |
23
e402813343b6
new option to switch samplingrate between 10s and 2s
heinrichsweikamp
parents:
21
diff
changeset
|
259 |
113 | 260 call lt2942_get_status ; Check for gauge IC |
261 btfsc c3_hardware ; C3 hardware? | |
262 call lt2942_init ; Yes, init battery gauge IC | |
263 | |
0 | 264 ; Select high altitude (Fly) mode? |
265 movff last_surfpressure_30min+0,sub_b+0 | |
266 movff last_surfpressure_30min+1,sub_b+1 | |
267 movlw HIGH high_altitude_threshold | |
268 movwf sub_a+1 | |
269 movlw LOW high_altitude_threshold ; Hard-wired 880mbar | |
270 movwf sub_a+0 | |
271 call subU16 ; sub_c = sub_a - sub_b | |
272 btfss neg_flag ; Result negative (Ambient>880mbar)? | |
273 bsf high_altitude_mode ; No, Set Flag! | |
274 | |
165 | 275 btfss c3_hardware |
276 bsf TRISB,3 | |
277 btfss c3_hardware | |
278 bsf TRISG,0 | |
0 | 279 call ext_flash_disable_protection ; Disable write protection for external flash |
280 | |
155
5f71e31bd5b3
CHANGE: Re-arranged Settings Menu, add 180? rotate to menu
heinrichsweikamp
parents:
154
diff
changeset
|
281 bsf flip_screen ; Flip 180° |
5f71e31bd5b3
CHANGE: Re-arranged Settings Menu, add 180? rotate to menu
heinrichsweikamp
parents:
154
diff
changeset
|
282 TSTOSS opt_flip_screen ; =1: Flip the screen |
5f71e31bd5b3
CHANGE: Re-arranged Settings Menu, add 180? rotate to menu
heinrichsweikamp
parents:
154
diff
changeset
|
283 bcf flip_screen ; Normal orientation |
151 | 284 |
0 | 285 goto surfloop ; Jump to Surfaceloop! |
286 | |
287 ;============================================================================= | |
288 ; Setup all flags and parameters for divemode and simulator computations. | |
289 ; | |
290 global restart_set_modes_and_flags | |
291 restart_set_modes_and_flags: ; "Call"ed from divemode, as well! | |
292 call option_restore_all ; Restore everything from EEPROM | |
24 | 293 |
294 ; Setup sampling rate | |
295 movlw .2 | |
296 movwf samplingrate | |
297 TSTOSS opt_sampling_rate ; =1: 10s, =0: 2s | |
298 bra restart_set_modes_and_flags1 | |
299 movlw .10 | |
300 movwf samplingrate | |
301 restart_set_modes_and_flags1: | |
0 | 302 movff opt_dive_mode,lo ; 0=OC, 1=CC, 2=Gauge, 3=Apnea |
303 | |
304 bcf FLAG_apnoe_mode | |
305 bcf FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active | |
306 bcf FLAG_gauge_mode ; =1: In Gauge mode | |
307 call disable_ir ; IR off | |
308 | |
309 tstfsz lo | |
310 bra restart_set_modes_and_flags2 | |
311 ; OC Mode | |
312 return | |
313 | |
314 restart_set_modes_and_flags2: | |
315 decfsz lo,F | |
316 bra restart_set_modes_and_flags3 | |
317 ; CC Mode | |
318 bsf FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active | |
319 call enable_ir ; Enable IR-Port | |
320 return | |
321 | |
322 restart_set_modes_and_flags3: | |
323 decfsz lo,F | |
324 bra restart_set_modes_and_flags4 | |
325 ; Gauge Mode | |
326 bsf FLAG_gauge_mode ; =1: In Gauge mode | |
327 return | |
328 | |
329 restart_set_modes_and_flags4: | |
330 ; Apnea Mode | |
331 bsf FLAG_apnoe_mode | |
332 return ; start in Surfacemode | |
333 | |
334 END |