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