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