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