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