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