Mercurial > public > hwos_code
annotate src/start.asm @ 472:4fdf6886004b
CHANGE: Show warnings either in Customview (If active) _or_ next to warning sign
NEW: Show battery type in information menu (T0:1.5V AA, T1:3.6V AA, T2:3.6V/0.8A LiIon, T3:Internal 18650, T4:Internal 16650)
author | heinrichsweikamp |
---|---|
date | Sun, 18 Dec 2016 18:20:39 +0100 |
parents | 0491a84fd0b8 |
children | 2880aa1264f5 |
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 | |
275 | 12 #include "hwos.inc" ; Mandatory header |
0 | 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 |
275 | 29 extern init_ostc |
0 | 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 | |
275 | 53 call init_ostc |
0 | 54 |
449 | 55 ; Get button type from Bootloader-Info |
56 bsf analog_switches | |
57 movlw 0x7C | |
58 movwf TBLPTRL | |
59 movlw 0xF7 | |
60 movwf TBLPTRH | |
61 movlw 0x01 | |
62 movwf TBLPTRU | |
63 TBLRD*+ ; Reads 0x07 for analog buttons | |
64 movlw 0x07 | |
65 cpfseq TABLAT | |
66 bcf analog_switches | |
67 | |
0 | 68 ; Air pressure compensation after reset |
69 call get_calibration_data ; Get calibration data from pressure sensor | |
70 banksel common ; get_calibration_data uses isr_backup | |
71 | |
463 | 72 call TFT_DisplayOff ; display off |
73 bsf LEDr ; Status LED | |
74 bcf pressure_refresh | |
0 | 75 ; First pass will not have valid temperature! |
76 btfss pressure_refresh ; Air pressure compensation | |
77 bra $-2 | |
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
429
diff
changeset
|
78 ; Second pass |
0 | 79 bcf pressure_refresh |
80 btfss pressure_refresh ; Air pressure compensation | |
81 bra $-2 | |
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
429
diff
changeset
|
82 bcf LEDr |
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
429
diff
changeset
|
83 |
0 | 84 clrf rel_pressure+0 |
85 clrf rel_pressure+1 | |
86 clrf surface_interval+0 | |
87 clrf surface_interval+1 | |
88 | |
89 SAFE_2BYTE_COPY amb_pressure, last_surfpressure | |
90 | |
91 movlw LOW max_surfpressure | |
92 movff WREG,sub_a+0 ; max. "allowed" airpressure in mbar | |
93 movlw HIGH max_surfpressure | |
94 movff WREG,sub_a+1 ; max. "allowed" airpressure in mbar | |
95 movff last_surfpressure+0,sub_b+0 | |
96 movff last_surfpressure+1,sub_b+1 | |
97 call subU16 ; sub_c = sub_a - sub_b | |
98 btfss neg_flag ; Is 1080mbar < amb_pressure ? | |
99 bra start_copy_pressure ; NO: current airpressure is lower then "allowed" airpressure, ok! | |
100 | |
101 ; not ok! Overwrite with max. "allowed" airpressure | |
102 movlw LOW max_surfpressure | |
103 movff WREG,last_surfpressure+0 ; max. "allowed" airpressure in mbar | |
104 movlw HIGH max_surfpressure | |
105 movff WREG,last_surfpressure+1 ; max. "allowed" airpressure in mbar | |
106 | |
107 start_copy_pressure: | |
108 movff last_surfpressure+0,last_surfpressure_15min+0 | |
109 movff last_surfpressure+1,last_surfpressure_15min+1 | |
110 movff last_surfpressure+0,last_surfpressure_30min+0 | |
111 movff last_surfpressure+1,last_surfpressure_30min+1 ; Rests all airpressure registers | |
112 | |
113 ; reset deco data for surface mode | |
114 movlw d'79' | |
115 movff WREG,char_I_N2_ratio ; 79% N2 | |
116 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; copy for deco routine | |
117 movff int_I_pres_respiration+0,int_I_pres_surface+0 ; copy for desat routine | |
118 movff int_I_pres_respiration+1,int_I_pres_surface+1 | |
119 | |
120 extern deco_reset | |
121 call deco_reset | |
133
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 call rtc_init ; init clock |
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 movlw HIGH .512 ; =2 |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
126 movwf EEADRH |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
127 read_int_eeprom .0 |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
128 clrf EEADRH |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
129 movlw 0xAA |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
130 cpfseq EEDATA ; =0xAA |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
131 bra no_deco_restore ; No |
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 extern restore_decodata_from_eeprom |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
134 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
|
135 |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
136 no_deco_restore: |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
137 call deco_calc_desaturation_time ; calculate desaturation time |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
138 banksel common |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
139 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
|
140 banksel common |
0 | 141 bcf menubit ; clear menu flag |
215 | 142 |
0 | 143 ; Check for Power-on reset here |
464
0491a84fd0b8
CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents:
463
diff
changeset
|
144 extern use_old_prior_209 |
215 | 145 ; ***************************************************************************** |
146 ; "new_battery_menu" and "use_old_batteries" 'goto' back to "power_on_return" | |
147 ; ***************************************************************************** | |
0 | 148 |
457 | 149 ; Try to migrate the old battery status from firmware 2.09 or earlier.. |
150 btfsc RCON,POR ; Was this a power-on reset? | |
472
4fdf6886004b
CHANGE: Show warnings either in Customview (If active) _or_ next to warning sign
heinrichsweikamp
parents:
464
diff
changeset
|
151 call use_old_prior_209 ; No |
464
0491a84fd0b8
CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents:
463
diff
changeset
|
152 |
0491a84fd0b8
CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents:
463
diff
changeset
|
153 bcf use_old_batt_flag |
416
4389fe9673b2
NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents:
410
diff
changeset
|
154 btfsc RCON,POR ; Was this a power-on reset? |
464
0491a84fd0b8
CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents:
463
diff
changeset
|
155 bsf use_old_batt_flag ; No |
0491a84fd0b8
CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents:
463
diff
changeset
|
156 |
215 | 157 call lt2942_get_status ; Check for gauge IC |
449 | 158 btfss battery_gauge_available ; cR or 2 hardware? |
416
4389fe9673b2
NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents:
410
diff
changeset
|
159 bra power_on_return2 ; no |
215 | 160 |
375
a9e35c1327aa
1.88 release, BUGFIX: Start with Sensor use from sleep (cR only), CHANGE: Apply button settings when button menu is closed, NEW: Reset button settings on a magnet reset (cR and OSTC 2)
heinrichsweikamp
parents:
359
diff
changeset
|
161 movlw .30 |
a9e35c1327aa
1.88 release, BUGFIX: Start with Sensor use from sleep (cR only), CHANGE: Apply button settings when button menu is closed, NEW: Reset button settings on a magnet reset (cR and OSTC 2)
heinrichsweikamp
parents:
359
diff
changeset
|
162 movff WREG,opt_cR_button_right |
a9e35c1327aa
1.88 release, BUGFIX: Start with Sensor use from sleep (cR only), CHANGE: Apply button settings when button menu is closed, NEW: Reset button settings on a magnet reset (cR and OSTC 2)
heinrichsweikamp
parents:
359
diff
changeset
|
163 movff WREG,opt_cR_button_left ; Reset on power-on reset |
a9e35c1327aa
1.88 release, BUGFIX: Start with Sensor use from sleep (cR only), CHANGE: Apply button settings when button menu is closed, NEW: Reset button settings on a magnet reset (cR and OSTC 2)
heinrichsweikamp
parents:
359
diff
changeset
|
164 call piezo_config ; Yes, configure buttons |
416
4389fe9673b2
NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents:
410
diff
changeset
|
165 call piezo_config ; Yes, configure buttons (2 times) |
0 | 166 |
416
4389fe9673b2
NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents:
410
diff
changeset
|
167 power_on_return2: |
0 | 168 ; check firmware and reset Custom Functions after an update |
169 movlw d'1' | |
281
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
276
diff
changeset
|
170 movwf EEADR ; =1 |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
276
diff
changeset
|
171 movwf EEADRH ; =1 |
0 | 172 call read_eeprom ; read current version x |
173 movff EEDATA,temp1 | |
174 incf EEADR,F ; set to 0x102 | |
175 call read_eeprom ; read current version y | |
176 movff EEDATA,temp2 | |
177 clrf EEADRH ; Reset EEADRH | |
178 | |
443 | 179 movlw softwareversion_x |
180 cpfseq temp1 ; compare version x | |
0 | 181 bra check_firmware_new ; is not equal -> reset CF and store new version in EEPROM |
182 | |
183 movlw softwareversion_y | |
184 cpfseq temp2 ; compare version y | |
185 bra check_firmware_new ; is not equal -> reset CF and store new version in EEPROM | |
186 bra restart ; x and y are equal -> do not reset cf | |
187 | |
188 check_firmware_new: | |
189 call TFT_boot ; Initialize TFT (includes clear screen) | |
190 clrf CCPR1L ; Backlight off | |
191 WIN_TOP .50 | |
192 WIN_LEFT .10 | |
193 movlw LOW 0x1E000 | |
194 movwf TBLPTRL | |
195 movlw HIGH 0x1E000 | |
196 movwf TBLPTRH | |
197 movlw UPPER 0x1E000 | |
198 movwf TBLPTRU | |
199 extern color_image | |
200 call color_image ; Show logo | |
201 call TFT_standard_color | |
202 WIN_SMALL .10,.100 | |
427 | 203 STRCPY_PRINT "Update successful!" ; Hard coded since language switch does not work here |
0 | 204 WIN_SMALL .10,.140 |
427 | 205 STRCPY "New Firmware: " |
0 | 206 movlw softwareversion_x |
207 movwf lo | |
208 bsf leftbind | |
209 output_8 | |
210 PUTC "." | |
211 movlw softwareversion_y | |
212 movwf lo | |
45 | 213 output_99x |
0 | 214 bcf leftbind |
215 STRCAT_PRINT "" ; Print second row | |
216 call TFT_Display_FadeIn ; Display resulting surface screen. | |
217 | |
218 ; place "after-update reset" here... | |
93
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
219 |
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
220 extern oPressureAdjust, option_reset, option_save |
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
221 lfsr FSR0,oPressureAdjust |
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
222 call option_reset ; Reset FSR0 option to factory default. |
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
223 lfsr FSR0,oPressureAdjust |
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
224 call option_save ; Save in EEPROM |
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
225 |
281
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
276
diff
changeset
|
226 call fix_180_dives ; fix dives made with the 1.80 |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
276
diff
changeset
|
227 |
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
228 rcall backup_flash_page ; backup the first 128bytes from flash to EEPROM |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
229 |
0 | 230 movlw d'1' ; store current version in EEPROM |
281
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
276
diff
changeset
|
231 movwf EEADR ; =1 |
eb758a5b44eb
BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents:
276
diff
changeset
|
232 movwf EEADRH ; =1 |
0 | 233 movlw softwareversion_x |
234 movwf EEDATA | |
235 call write_eeprom ; write version x | |
236 incf EEADR,F ; set to 0x102 | |
237 movlw softwareversion_y | |
238 movwf EEDATA | |
239 call write_eeprom ; write version y | |
240 clrf EEADRH ; Reset EEADRH | |
241 | |
242 movlw .7 | |
243 movwf lo | |
244 check_firmware_new2: | |
245 ; Wait 1 second | |
246 bcf onesecupdate | |
247 btfss onesecupdate | |
248 bra $-2 | |
249 decfsz lo,F ; Wait 10 seconds... | |
250 bra check_firmware_new2 | |
251 | |
252 global restart | |
253 restart: | |
254 clrf STKPTR ; Never return from here | |
276
e4cb495aed3d
Increase byte timeout in PC download mode, faster response to "Exit" in main menu
heinrichsweikamp
parents:
275
diff
changeset
|
255 clrf CCP1CON ; stop PWM |
e4cb495aed3d
Increase byte timeout in PC download mode, faster response to "Exit" in main menu
heinrichsweikamp
parents:
275
diff
changeset
|
256 bcf PORTC,2 ; Pull PWM out to GND |
e4cb495aed3d
Increase byte timeout in PC download mode, faster response to "Exit" in main menu
heinrichsweikamp
parents:
275
diff
changeset
|
257 |
21
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
16
diff
changeset
|
258 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
|
259 |
0 | 260 btfsc menubit ; Return from Menu/COMM mode or timeout? |
261 call option_save_all ; Yes, save all settings into EEPROM | |
262 | |
429 | 263 call option_restore_all ; Restore everything from EEPROM into RAM |
23
e402813343b6
new option to switch samplingrate between 10s and 2s
heinrichsweikamp
parents:
21
diff
changeset
|
264 call option_check_all ; Check all options (and reset if not within their min/max boundaries) |
429 | 265 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
|
266 |
429 | 267 clrf flag1 ; clear all flags |
268 clrf flag2 | |
269 clrf flag3 | |
270 clrf flag4 | |
271 clrf flag5 | |
272 clrf flag6 | |
0 | 273 clrf flag7 |
274 clrf flag8 | |
429 | 275 clrf flag9 |
276 clrf flag10 | |
267
f64afa14ef07
BUGFIX: Analog sensors were ignored in 1.76
heinrichsweikamp
parents:
255
diff
changeset
|
277 ; Do not clear flag11 (Sensor calibration and charger status) |
255 | 278 clrf flag12 |
449 | 279 ; ; Do not clear flag13 (Important hardware flags) |
235
23311219dacc
under construction: new hardware_flag to configure different hardware versions
heinrichsweikamp
parents:
224
diff
changeset
|
280 clrf hardware_flag ; hardware descriptor flag |
449 | 281 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
|
282 |
236 | 283 ; configure hardware_flag byte |
284 | |
429 | 285 bsf ambient_sensor ; Set flag |
286 bsf optical_input ; Set flag | |
236 | 287 |
113 | 288 call lt2942_get_status ; Check for gauge IC |
449 | 289 btfss battery_gauge_available ; cR/2 hardware? |
236 | 290 bra restart2 ; No |
291 | |
113 | 292 call lt2942_init ; Yes, init battery gauge IC |
429 | 293 bcf optical_input ; Clear flag |
294 | |
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
429
diff
changeset
|
295 banksel 0xF16 |
429 | 296 bcf ANCON0,7 ; AN7 Digital input |
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
429
diff
changeset
|
297 banksel common |
429 | 298 bcf lightsen_power ; Power-down ambient light sensor |
236 | 299 bcf ambient_sensor ; Clear flag |
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
429
diff
changeset
|
300 nop |
429 | 301 btfss PORTF,2 ; Light sensor available? |
302 bsf ambient_sensor ; Yes. | |
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
429
diff
changeset
|
303 banksel 0xF16 |
429 | 304 bsf ANCON0,7 ; AN7 Analog again |
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
429
diff
changeset
|
305 banksel common |
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
429
diff
changeset
|
306 bsf lightsen_power ; Power-up ambient light sensor again |
429 | 307 |
243 | 308 restart2: |
309 btfsc vusb_in | |
310 bra restart3 ; USB (and powered on) | |
311 bcf PORTE,0 ; Start comms | |
312 WAITMS d'1' | |
313 btfss vusb_in | |
314 bra restart3 ; USB (and powered off) | |
315 bsf ble_available ; ble available | |
316 restart3: | |
317 bsf PORTE,0 ; Stop comms | |
248
afe73e1a0181
support hardware_flag for all possible hardware combinations
heinrichsweikamp
parents:
243
diff
changeset
|
318 btfsc ble_available ; ble available? |
afe73e1a0181
support hardware_flag for all possible hardware combinations
heinrichsweikamp
parents:
243
diff
changeset
|
319 bra restart4 ; Yes, can't be a cR |
449 | 320 btfss battery_gauge_available ; Rechargeable |
248
afe73e1a0181
support hardware_flag for all possible hardware combinations
heinrichsweikamp
parents:
243
diff
changeset
|
321 bra restart4 ; No, can't be a cR |
afe73e1a0181
support hardware_flag for all possible hardware combinations
heinrichsweikamp
parents:
243
diff
changeset
|
322 bsf analog_o2_input ; Set flag for analog |
249 | 323 restart4: |
324 ; The hardware_flag is now: | |
325 ; 3: 0x0A | |
326 ; cR: 0x05 | |
327 ; 2 with BLE: 0x11 | |
328 ; 3 with BLE: 0x1A | |
429 | 329 ; 2 with ambient: 0x13 |
113 | 330 |
0 | 331 ; Select high altitude (Fly) mode? |
332 movff last_surfpressure_30min+0,sub_b+0 | |
333 movff last_surfpressure_30min+1,sub_b+1 | |
334 movlw HIGH high_altitude_threshold | |
335 movwf sub_a+1 | |
336 movlw LOW high_altitude_threshold ; Hard-wired 880mbar | |
337 movwf sub_a+0 | |
338 call subU16 ; sub_c = sub_a - sub_b | |
339 btfss neg_flag ; Result negative (Ambient>880mbar)? | |
340 bsf high_altitude_mode ; No, Set Flag! | |
341 | |
236 | 342 btfss analog_o2_input |
165 | 343 bsf TRISB,3 |
449 | 344 btfss battery_gauge_available |
165 | 345 bsf TRISG,0 |
0 | 346 call ext_flash_disable_protection ; Disable write protection for external flash |
347 | |
155
5f71e31bd5b3
CHANGE: Re-arranged Settings Menu, add 180? rotate to menu
heinrichsweikamp
parents:
154
diff
changeset
|
348 bsf flip_screen ; Flip 180° |
5f71e31bd5b3
CHANGE: Re-arranged Settings Menu, add 180? rotate to menu
heinrichsweikamp
parents:
154
diff
changeset
|
349 TSTOSS opt_flip_screen ; =1: Flip the screen |
5f71e31bd5b3
CHANGE: Re-arranged Settings Menu, add 180? rotate to menu
heinrichsweikamp
parents:
154
diff
changeset
|
350 bcf flip_screen ; Normal orientation |
151 | 351 |
464
0491a84fd0b8
CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents:
463
diff
changeset
|
352 btfsc use_old_batt_flag ; =1: load old battery information after power-on reset |
0491a84fd0b8
CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents:
463
diff
changeset
|
353 goto use_old_batteries ; Returns to "surfloop"! |
0491a84fd0b8
CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents:
463
diff
changeset
|
354 |
0491a84fd0b8
CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents:
463
diff
changeset
|
355 btfsc RCON,POR ; Was this a power-on reset? |
0491a84fd0b8
CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents:
463
diff
changeset
|
356 goto surfloop ; Jump to Surfaceloop! |
0491a84fd0b8
CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents:
463
diff
changeset
|
357 bsf RCON,POR ; Set bit for next detection |
0491a84fd0b8
CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents:
463
diff
changeset
|
358 ; Things to do after a power-on reset |
0491a84fd0b8
CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents:
463
diff
changeset
|
359 extern new_battery_menu,use_old_batteries |
0491a84fd0b8
CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents:
463
diff
changeset
|
360 goto new_battery_menu ; Returns to "surfloop"! |
0 | 361 |
362 ;============================================================================= | |
363 ; Setup all flags and parameters for divemode and simulator computations. | |
364 ; | |
365 global restart_set_modes_and_flags | |
366 restart_set_modes_and_flags: ; "Call"ed from divemode, as well! | |
367 call option_restore_all ; Restore everything from EEPROM | |
24 | 368 |
369 ; Setup sampling rate | |
370 movlw .2 | |
371 movwf samplingrate | |
372 TSTOSS opt_sampling_rate ; =1: 10s, =0: 2s | |
373 bra restart_set_modes_and_flags1 | |
374 movlw .10 | |
375 movwf samplingrate | |
376 restart_set_modes_and_flags1: | |
0 | 377 movff opt_dive_mode,lo ; 0=OC, 1=CC, 2=Gauge, 3=Apnea |
378 | |
379 bcf FLAG_apnoe_mode | |
380 bcf FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active | |
381 bcf FLAG_gauge_mode ; =1: In Gauge mode | |
224
5a4801918be9
temporally disable "Copy disable flags from digital input" routine
heinrichsweikamp
parents:
220
diff
changeset
|
382 call disable_ir_s8 ; IR off |
0 | 383 |
384 tstfsz lo | |
385 bra restart_set_modes_and_flags2 | |
386 ; OC Mode | |
387 return | |
388 | |
389 restart_set_modes_and_flags2: | |
390 decfsz lo,F | |
391 bra restart_set_modes_and_flags3 | |
392 ; CC Mode | |
359 | 393 btfsc analog_o2_input ; cR? |
394 bra restart_set_modes_and_flags2b ; Yes, skip mode check | |
395 btfsc optical_input ; 3 | |
396 bra restart_set_modes_and_flags2b ; Yes, skip mode check | |
397 ; Make sure Sensor is not selected | |
398 ; opt_ccr_mode must be <> 1 (=0: Fixed SP, =1: Sensor, =2: Auto SP) | |
399 banksel opt_ccr_mode | |
400 movlw .1 | |
401 cpfseq opt_ccr_mode ; = Sensor? | |
402 bra restart_set_modes_and_flags2b ; No | |
403 clrf opt_ccr_mode ; Yes, reset to Fixed SP | |
404 restart_set_modes_and_flags2b: | |
405 banksel common | |
338
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
319
diff
changeset
|
406 bsf FLAG_ccr_mode ; =1: CCR mode (Fixed SP, Auto SP or Sensor) active |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
165
diff
changeset
|
407 call enable_ir_s8 ; Enable IR/S8-Port |
0 | 408 return |
409 | |
410 restart_set_modes_and_flags3: | |
411 decfsz lo,F | |
412 bra restart_set_modes_and_flags4 | |
413 ; Gauge Mode | |
414 bsf FLAG_gauge_mode ; =1: In Gauge mode | |
415 return | |
416 | |
417 restart_set_modes_and_flags4: | |
418 ; Apnea Mode | |
419 bsf FLAG_apnoe_mode | |
420 return ; start in Surfacemode | |
421 | |
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
422 backup_flash_page: ; backup the first 128bytes from flash to EEPROM |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
423 ; Start address in internal flash |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
424 movlw 0x00 |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
425 movwf TBLPTRL |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
426 movwf TBLPTRH |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
427 movwf TBLPTRU |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
428 |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
429 movlw .128 |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
430 movwf lo ; Byte counter |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
431 clrf EEADR |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
432 movlw .3 |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
433 movwf EEADRH ; Setup backup address |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
434 |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
435 TBLRD*- ; Dummy read to be in 128 byte block |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
436 backup_flash_loop: |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
437 tblrd+* ; Table Read with Pre-Increment |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
438 movff TABLAT,EEDATA ; put 1 byte |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
439 call write_eeprom ; save it in EEPROM |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
440 incf EEADR,F |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
441 decfsz lo,F ; 128byte done? |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
442 bra backup_flash_loop ; No |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
443 clrf EEADRH ; Reset EEADRH |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
444 return ; Done. |
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
445 |
0 | 446 END |