Mercurial > public > hwos_code
annotate src/start.asm @ 626:be8787f2034d
compass3 support for 3.01 branch
author | heinrichsweikamp |
---|---|
date | Sun, 23 Jun 2019 15:21:16 +0200 |
parents | b87f23fae743 |
children | c40025d8e750 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
614 | 3 ; File start.asm REFACTORED VERSION V2.99g |
0 | 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 | |
604 | 12 #include "hwos.inc" ; mandatory header |
582 | 13 #include "ms5541.inc" |
14 #include "isr.inc" | |
604 | 15 #include "shared_definitions.h" ; mailbox from/to p2_deco.c |
582 | 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" | |
26 #include "adc_lightsensor.inc" | |
27 #include "i2c.inc" | |
0 | 28 |
582 | 29 extern init_ostc |
30 extern option_restore_all | |
31 extern restore_decodata_from_eeprom | |
32 extern oPressureAdjust | |
33 extern option_reset | |
34 extern option_save | |
35 extern option_save_all | |
36 extern option_check_all | |
37 extern do_new_battery_select | |
38 extern use_old_batteries | |
39 extern use_old_prior_209 | |
604 | 40 extern get_first_gas_to_WREG |
41 extern get_first_dil_to_WREG | |
42 extern option_cleanup_oCCRMode_pSCR | |
43 extern option_cleanup_oCCRMode_CCR | |
44 | |
45 IFDEF _rx_functions | |
46 extern option_cleanup_oTrMode_CCR | |
47 extern option_cleanup_oTrMode_no_CCR | |
48 ENDIF | |
49 | |
0 | 50 |
51 ;============================================================================= | |
604 | 52 ; Reset Vector: entry point on device wake-up and hard reset |
0 | 53 ; |
582 | 54 reset_v code 0x00000 |
0 | 55 |
582 | 56 ; goto start |
604 | 57 goto 0x1FF00 ; bootloader |
582 | 58 |
604 | 59 ORG 0x00004 ; needed for second-level bootloader |
0 | 60 goto start |
582 | 61 |
0 | 62 ;============================================================================= |
582 | 63 |
604 | 64 boot CODE |
65 | |
66 ;============================================================================= | |
0 | 67 |
582 | 68 global start |
0 | 69 start: |
604 | 70 lfsr FSR0,0x000 ; clear ram-banks 0-14 |
0 | 71 clear_rambank: |
72 clrf POSTINC0 | |
73 movlw 0x0F | |
604 | 74 cpfseq FSR0H ; bank 14 done? |
75 bra clear_rambank ; NO - loop | |
0 | 76 |
604 | 77 call init_ostc ; initialize hardware (ports, timers, etc.) |
0 | 78 |
604 | 79 ; get button type from Bootloader-Info |
582 | 80 movlw .16 |
604 | 81 movff WREG,analog_counter ; initialize averaging |
582 | 82 bsf analog_switches |
83 movlw 0x7C | |
84 movwf TBLPTRL | |
85 movlw 0xF7 | |
86 movwf TBLPTRH | |
87 movlw 0x01 | |
88 movwf TBLPTRU | |
604 | 89 TBLRD*+ ; reads 0x07 for analog buttons |
449 | 90 movlw 0x07 |
91 cpfseq TABLAT | |
582 | 92 bcf analog_switches |
475 | 93 |
608 | 94 ; get screen type (2) from Bootloader-Info |
95 bsf screen_type2 | |
614 | 96 movlw 0x80 |
97 movwf TBLPTRL ; only adjust low byte, high and upper are still 0x01F7... | |
98 TBLRD*+ ; reads 0x83 if OSTC has screen type 2 | |
608 | 99 movlw 0x83 |
100 cpfseq TABLAT | |
614 | 101 bcf screen_type2 |
608 | 102 |
475 | 103 ; read button polarity |
582 | 104 movlw LOW .897 |
475 | 105 movwf EEADR |
582 | 106 movlw HIGH .897 |
475 | 107 movwf EEADRH |
604 | 108 call read_eeprom ; EEDATA into EEPROM @ EEADR |
109 clrf EEADRH ; reset EEADRH | |
110 movff EEDATA,button_polarity ; 0xFF (both normal), 0x00 (both inverted), 0x01 (left inverted only), 0x02 (right inverted only) | |
475 | 111 |
604 | 112 ; air pressure compensation after reset |
582 | 113 call get_calibration_data ; get calibration data from pressure sensor |
114 banksel common ; get_calibration_data uses isr_backup | |
0 | 115 |
582 | 116 call TFT_DisplayOff ; turn off display |
117 bsf LEDr ; turn on red LED | |
118 bcf pressure_refresh | |
604 | 119 ; first pass will not have valid temperature |
120 btfss pressure_refresh ; air pressure compensation | |
0 | 121 bra $-2 |
604 | 122 ; second pass |
0 | 123 bcf pressure_refresh |
604 | 124 btfss pressure_refresh ; air pressure compensation |
0 | 125 bra $-2 |
582 | 126 bcf LEDr |
127 | |
0 | 128 clrf rel_pressure+0 |
129 clrf rel_pressure+1 | |
130 clrf surface_interval+0 | |
131 clrf surface_interval+1 | |
132 | |
582 | 133 SAFE_2BYTE_COPY amb_pressure, last_surfpressure |
0 | 134 |
582 | 135 movlw LOW max_surfpressure |
136 movff WREG,sub_a+0 ; max. "allowed" air pressure in mbar | |
137 movlw HIGH max_surfpressure | |
138 movff WREG,sub_a+1 ; max. "allowed" air pressure in mbar | |
0 | 139 movff last_surfpressure+0,sub_b+0 |
140 movff last_surfpressure+1,sub_b+1 | |
582 | 141 call subU16 ; sub_c = sub_a - sub_b |
604 | 142 btfss neg_flag ; is 1080 mbar < amb_pressure ? |
143 bra start_copy_pressure ; NO - current air pressure is lower then "allowed" air pressure, ok | |
0 | 144 |
604 | 145 ; not ok - overwrite with max. "allowed" air pressure |
582 | 146 movlw LOW max_surfpressure |
147 movff WREG,last_surfpressure+0 ; max. "allowed" air pressure in mbar | |
148 movlw HIGH max_surfpressure | |
149 movff WREG,last_surfpressure+1 ; max. "allowed" air pressure in mbar | |
0 | 150 |
151 start_copy_pressure: | |
152 movff last_surfpressure+0,last_surfpressure_15min+0 | |
153 movff last_surfpressure+1,last_surfpressure_15min+1 | |
154 movff last_surfpressure+0,last_surfpressure_30min+0 | |
582 | 155 movff last_surfpressure+1,last_surfpressure_30min+1 ; resets all air pressure registers |
560 | 156 |
157 ; initialize GF high (needed by deco engine for color-coding the GF value) | |
158 movff opt_GF_high,char_I_GF_High_percentage | |
159 | |
582 | 160 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; breathing at surface |
161 movff int_I_pres_respiration+0,int_I_pres_surface+0 ; surface pressure | |
162 movff int_I_pres_respiration+1,int_I_pres_surface+1 | |
0 | 163 |
604 | 164 call deco_clear_tissue ; set all tissues to Pamb * N2_ratio (code located in p2_deco.c) |
582 | 165 banksel common ; back to bank 1, needed after every return from C code |
133
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
166 |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
167 call rtc_init ; init clock |
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
168 |
582 | 169 movlw HIGH .512 ; =2 |
170 movwf EEADRH | |
171 read_int_eeprom .0 | |
172 clrf EEADRH | |
173 movlw 0xAA | |
174 cpfseq EEDATA ; =0xAA | |
604 | 175 bra no_deco_restore ; NO |
176 call restore_decodata_from_eeprom ; reload deco data and date/time from eeprom | |
582 | 177 no_deco_restore: |
178 call deco_calc_dive_interval_1min ; calculate deco in surface mode | |
179 call deco_calc_desaturation_time ; calculate desaturation and no-fly time | |
180 banksel common | |
133
939f1e83c4c2
BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents:
113
diff
changeset
|
181 |
0 | 182 bcf menubit ; clear menu flag |
215 | 183 |
604 | 184 ; check for power-on reset here |
582 | 185 |
186 ; ***************************************************************************** | |
615 | 187 ; "do_new_battery_menu" and "use_old_batteries" 'goto' back to "power_on_return" |
582 | 188 ; ***************************************************************************** |
0 | 189 |
582 | 190 ; Try to migrate the old battery status from firmware 2.09 or earlier.. |
604 | 191 btfsc RCON,POR ; was this a power-on reset? |
192 call use_old_prior_209 ; NO | |
464
0491a84fd0b8
CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents:
463
diff
changeset
|
193 |
582 | 194 bcf use_old_batt_flag |
604 | 195 btfsc RCON,POR ; was this a power-on reset? |
196 bsf use_old_batt_flag ; NO | |
582 | 197 |
604 | 198 call lt2942_get_status ; check for gauge IC |
582 | 199 btfss battery_gauge_available ; cR or 2 hardware? |
604 | 200 bra check_firmware_new ; NO - skip next |
201 movlw .30 ; YES - reset button sensitivity | |
202 movff WREG,opt_cR_button_right | |
203 movff WREG,opt_cR_button_left ; reset on power-on reset | |
204 call piezo_config ; configure buttons | |
205 call piezo_config ; configure buttons (2 times) | |
206 | |
207 check_firmware_new: | |
208 call TFT_boot ; initialize TFT (includes clear screen) | |
209 clrf CCPR1L ; backlight off | |
210 | |
211 WIN_TOP .40 | |
212 WIN_LEFT .10 | |
213 TFT_WRITE_PROM_IMAGE_BY_ADDR hw_logo_block ; show heinrichsweikamp logo | |
215 | 214 |
604 | 215 call TFT_standard_color |
216 | |
217 WIN_SMALL .20,.100 | |
218 STRCPY_PRINT "Update successful!" ; hard coded since language switch does not work here | |
0 | 219 |
604 | 220 WIN_SMALL .20,.140 |
221 STRCPY "New Firmware: " | |
222 call TFT_cat_firmware ; show firmware version x.y and color-code if outdated | |
223 STRCAT_PRINT "" ; finalize output | |
224 bcf win_invert ; reset inverted output if firmware is outdated | |
225 call TFT_standard_color ; reset color if firmware is outdated | |
226 | |
227 WIN_SMALL .60,.180 | |
228 call TFT_cat_beta_release ; if it is a beta version, show "BETA" + issue, else "Release" | |
229 STRCAT_PRINT "" ; finalize output | |
230 call TFT_standard_color ; reset color | |
231 | |
232 call TFT_Display_FadeIn ; display resulting surface screen | |
233 | |
234 ; check if a new firmware was loaded, if yes reset Custom Function oPressureAdjust | |
0 | 235 movlw d'1' |
582 | 236 movwf EEADR ; =1 |
237 movwf EEADRH ; =1 | |
238 call read_eeprom ; read current version x | |
239 movff EEDATA,lo | |
240 incf EEADR,F ; set to 0x102 | |
241 call read_eeprom ; read current version y | |
242 movff EEDATA,hi | |
604 | 243 clrf EEADRH ; reset EEADRH |
0 | 244 |
443 | 245 movlw softwareversion_x |
604 | 246 cpfseq lo ; compare version x |
247 bra check_firmware_new4 ; is not equal -> reset CF and store new version in EEPROM | |
0 | 248 |
249 movlw softwareversion_y | |
604 | 250 cpfseq hi ; compare version y |
251 bra check_firmware_new4 ; is not equal -> reset CF and store new version in EEPROM | |
252 bra check_firmware_new5 ; x and y are equal -> do not reset CF | |
582 | 253 |
604 | 254 check_firmware_new4: |
582 | 255 ; place "after-update reset" here... |
256 lfsr FSR0,oPressureAdjust | |
604 | 257 call option_reset ; reset oPressureAdjust to factory default |
582 | 258 lfsr FSR0,oPressureAdjust |
604 | 259 call option_save ; save new value of oPressureAdjust in EEPROM |
582 | 260 |
604 | 261 check_firmware_new5: |
582 | 262 rcall backup_flash_page ; backup the first 128 bytes from flash to EEPROM |
93
5e1ef9bf32ec
clear pressure sensor compensation upon update
heinrichsweikamp
parents:
52
diff
changeset
|
263 |
582 | 264 movlw d'1' ; store current version in EEPROM |
265 movwf EEADR ; =1 | |
266 movwf EEADRH ; =1 | |
0 | 267 movlw softwareversion_x |
582 | 268 movwf EEDATA |
604 | 269 call write_eeprom ; write version, major number |
582 | 270 incf EEADR,F ; set to 0x102 |
0 | 271 movlw softwareversion_y |
582 | 272 movwf EEDATA |
604 | 273 call write_eeprom ; write version, minor number |
274 clrf EEADRH ; reset EEADRH | |
0 | 275 |
604 | 276 ; wait 10 seconds |
277 movlw .10 ; load loop counter | |
278 check_firmware_new6: | |
279 call wait_1s ; wait (about) 1 second | |
280 decfsz WREG,W ; YES - decrement loop counter, did it became zero? | |
281 bra check_firmware_new6 ; NO - loop | |
282 ;bra restart ; YES - proceed with restart | |
283 | |
0 | 284 |
582 | 285 global restart |
0 | 286 restart: |
604 | 287 clrf STKPTR ; never return from here |
582 | 288 clrf CCP1CON ; stop PWM |
604 | 289 bcf PORTC,2 ; pull PWM out to GND |
276
e4cb495aed3d
Increase byte timeout in PC download mode, faster response to "Exit" in main menu
heinrichsweikamp
parents:
275
diff
changeset
|
290 |
604 | 291 btfsc menubit ; return from Menu/COMM mode or timeout? |
292 call option_save_all ; YES - save all settings into EEPROM | |
21
79b2084fd75a
Reset options to default if they are not within the allowed min/max values
heinrichsweikamp
parents:
16
diff
changeset
|
293 |
604 | 294 call option_restore_all ; restore everything from EEPROM into RAM |
295 call option_check_all ; check all options (and reset if not within their min/max boundaries) | |
296 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
|
297 |
582 | 298 clrf flag1 ; clear all flags |
299 clrf flag2 | |
300 clrf flag3 | |
301 clrf flag4 | |
302 clrf flag5 | |
303 clrf flag6 | |
304 clrf flag7 | |
305 clrf flag8 | |
306 clrf flag9 | |
612 | 307 clrf flag10 ; Clears flag "enable_screen_dumps" - making screen dumps impossible... TODO |
604 | 308 ; do not clear flag11 (sensor calibration and charger status) |
582 | 309 clrf flag12 |
604 | 310 ; do not clear flag13 (important hardware flags) |
582 | 311 clrf flag14 |
604 | 312 clrf flag15 |
313 clrf flag16 | |
314 clrf flag17 | |
615 | 315 ; do not clear flag18 (important hardware flags) |
316 | |
604 | 317 clrf cvt_flags |
318 | |
319 clrf tft_update_flags+0 | |
320 clrf tft_update_flags+1 | |
321 clrf tft_update_flags+2 | |
322 | |
323 clrf hardware_flag1 ; hardware descriptor 1 | |
324 ; hardware_flag2 ; hardware descriptor 2 - do not clear here! | |
23
e402813343b6
new option to switch samplingrate between 10s and 2s
heinrichsweikamp
parents:
21
diff
changeset
|
325 |
582 | 326 bsf tft_is_dimming ; TFT is dimming up (soon), ignore ambient sensor! |
236 | 327 |
604 | 328 ; configure hardware descriptor 1 |
329 bcf tft_power ; inverted, here needed for I2C_probe_OSTC_rx, to wake-up RX circuity | |
330 bsf ambient_sensor ; set flag | |
331 bsf optical_input ; set flag | |
582 | 332 |
604 | 333 call lt2942_get_status ; check for gauge IC |
582 | 334 btfss battery_gauge_available ; cR/2 hardware? |
604 | 335 bra restart2 ; NO |
336 call lt2942_init ; YES - initialize battery gauge IC | |
337 bcf optical_input ; clear flag | |
236 | 338 |
582 | 339 banksel 0xF16 |
604 | 340 bcf ANCON0,7 ; AN7 digital input |
341 banksel common | |
342 bcf lightsen_power ; power-down ambient light sensor | |
343 bcf ambient_sensor ; clear flag | |
582 | 344 nop |
604 | 345 btfss PORTF,2 ; light sensor available? |
346 bsf ambient_sensor ; YES | |
582 | 347 banksel 0xF16 |
604 | 348 bsf ANCON0,7 ; AN7 analog again |
582 | 349 banksel common |
604 | 350 bsf lightsen_power ; power-up ambient light sensor again |
582 | 351 |
243 | 352 restart2: |
582 | 353 btfsc vusb_in |
354 bra restart3 ; USB (and powered on) | |
604 | 355 bcf PORTE,0 ; start comms |
615 | 356 WAITMS d'5' |
582 | 357 btfss vusb_in |
358 bra restart3 ; USB (and powered off) | |
604 | 359 bsf ble_available ; BLE available |
582 | 360 |
361 restart3: | |
604 | 362 bsf PORTE,0 ; stop comms |
363 btfsc ble_available ; BLE available? | |
364 bra restart4 ; YES - can't be a cR | |
365 btfss battery_gauge_available ; rechargeable? | |
366 bra restart4 ; NO - can't be a cR | |
367 bsf analog_o2_input ; set flag for analog | |
582 | 368 |
604 | 369 restart4: |
370 IFDEF _rx_functions | |
371 WAITMS d'200' | |
372 call I2C_probe_OSTC_rx ; set ostc_rx_present flag if this is an OSTC TR model | |
373 | |
374 ; The hardware descriptor is now: | |
582 | 375 ; 0x11: 2 with BLE |
614 | 376 ; 0x12; Sport |
377 ; 0x13: +/2 with BLE & ambient ; PLUS ??? OSTC 3 (2016) ??? | |
582 | 378 ; 0x05: cR |
379 ; 0x0A: 3 | |
380 ; 0x1A: 3 with BLE | |
604 | 381 ; 0x33: 2 TR |
582 | 382 |
604 | 383 btfss ostc_rx_present ; OSTC TR detected? |
384 bra restart5 ; NO | |
385 movff opt_TR_mode,WREG ; YES - get user-selected TR mode | |
386 tstfsz WREG ; TR functions switched on? | |
387 bsf FLAG_tr_enabled ; YES - switch on displays and calculation functions | |
388 ENDIF | |
389 | |
390 ; configure hardware descriptor 2 | |
391 ; flag screen_type will be configured on each call of TFT_boot | |
392 ; flags compass_type & compass_type2 will be configured on each call of I2C_init_compass | |
393 ; flag analog_switches will be configured directly after hard start (in start:) | |
394 | |
395 restart5: | |
396 ; Select high altitude (fly) mode? | |
0 | 397 movff last_surfpressure_30min+0,sub_b+0 |
398 movff last_surfpressure_30min+1,sub_b+1 | |
582 | 399 movlw HIGH high_altitude_threshold |
0 | 400 movwf sub_a+1 |
604 | 401 movlw LOW high_altitude_threshold ; hard-wired 880 hPa |
0 | 402 movwf sub_a+0 |
582 | 403 call subU16 ; sub_c = sub_a - sub_b |
604 | 404 btfss neg_flag ; result negative (ambient > 880 hPa)? |
405 bsf high_altitude_mode ; NO - set flag | |
0 | 406 |
582 | 407 btfss analog_o2_input |
408 bsf TRISB,3 | |
409 btfss battery_gauge_available | |
410 bsf TRISG,0 | |
411 call ext_flash_disable_protection ; disable write protection for external flash | |
464
0491a84fd0b8
CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents:
463
diff
changeset
|
412 |
604 | 413 bsf flip_screen ; select screen flip 180° |
414 TSTOSS opt_flip_screen ; shall actually flip? (=1: flip the screen) | |
415 bcf flip_screen ; NO - revert to normal orientation | |
582 | 416 |
417 btfsc use_old_batt_flag ; =1: load old battery information after power-on reset | |
604 | 418 goto use_old_batteries ; returns to surface loop |
582 | 419 |
420 btfsc RCON,POR ; was this a power-on reset? | |
614 | 421 goto surfloop ; NO - jump to surface loop |
582 | 422 bsf RCON,POR ; set bit for next detection |
423 ; Things to do after a power-on reset | |
604 | 424 goto do_new_battery_select ; returns to surface loop |
0 | 425 |
426 ;============================================================================= | |
427 ; Setup all flags and parameters for divemode and simulator computations. | |
428 ; | |
429 global restart_set_modes_and_flags | |
604 | 430 restart_set_modes_and_flags: ; "Call"ed from dive mode as well |
431 call option_restore_all ; restore everything from EEPROM | |
24 | 432 |
582 | 433 ; Setup sampling rate |
434 movlw .2 | |
435 movwf samplingrate | |
436 TSTOSS opt_sampling_rate ; =1: 10s, =0: 2s | |
437 bra restart_set_modes_and_flags1 | |
438 movlw .10 | |
439 movwf samplingrate | |
440 | |
24 | 441 restart_set_modes_and_flags1: |
604 | 442 bcf FLAG_gauge_mode |
582 | 443 bcf FLAG_apnoe_mode |
604 | 444 bcf FLAG_oc_mode |
445 bcf FLAG_ccr_mode | |
582 | 446 bcf FLAG_pscr_mode |
604 | 447 bcf FLAG_bailout_mode |
582 | 448 call disable_ir_s8 ; IR off |
0 | 449 |
604 | 450 IFDEF _cave_mode |
451 bsf FLAG_cave_mode ; enable cave mode by default | |
452 movff opt_calc_asc_gasvolume,WREG ; get gas needs calculation mode (0=off, 1=on, 2=cave mode) | |
453 xorlw .2 ; coding for cave mode | |
454 tstfsz WREG ; cave mode enabled? | |
455 bcf FLAG_cave_mode ; NO - disable cave mode again | |
456 bcf FLAG_cave_mode_shutdown ; clear flag for cave mode shutdown | |
457 bcf FLAG_dive_turned ; clear flag for dive turned | |
458 bcf gas_needs_mode_last ; set last gas calculation results as direct ascent needs | |
459 ENDIF | |
460 | |
461 ; Initialize active_gas and active_dil for surface mode pressure display | |
462 call get_first_gas_to_WREG | |
463 movwf active_gas | |
464 call get_first_dil_to_WREG | |
465 movwf active_dil | |
466 | |
582 | 467 ; Setup char_I_saturation_multiplier and char_I_desaturation_multiplier |
468 movff opt_sat_multiplier_gf,char_I_saturation_multiplier | |
469 movff opt_desat_multiplier_gf,char_I_desaturation_multiplier | |
470 movff char_I_deco_model,lo ; 0 = ZH-L16, 1 = ZH-L16-GF | |
471 tstfsz lo | |
472 bra restart_set_modes_and_flags1b | |
473 movff opt_sat_multiplier_non_gf,char_I_saturation_multiplier | |
474 movff opt_desat_multiplier_non_gf,char_I_desaturation_multiplier | |
475 | |
476 restart_set_modes_and_flags1b: | |
477 movff opt_dive_mode,lo ; 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=PSCR | |
478 tstfsz lo | |
479 bra restart_set_modes_and_flags2 | |
480 | |
481 ; OC Mode | |
604 | 482 bsf FLAG_oc_mode ; =1: OC mode active |
483 IFDEF _rx_functions | |
484 call option_cleanup_oTrMode_no_CCR ; revert TR mode from 'CCR Dil+O2' to 'on' | |
485 ENDIF | |
582 | 486 return |
0 | 487 |
488 restart_set_modes_and_flags2: | |
582 | 489 decfsz lo,F |
490 bra restart_set_modes_and_flags3 | |
491 | |
604 | 492 ; CCR Mode |
582 | 493 bsf FLAG_ccr_mode ; =1: CCR mode (Fixed SP, Auto SP or Sensor) active |
604 | 494 call option_cleanup_oCCRMode_CCR ; revert CCR mode 'Sensor' to 'fixed SP' if no sensor interface available |
495 IFDEF _rx_functions | |
496 call option_cleanup_oTrMode_CCR ; revert TR mode from 'ind.double' to 'on' | |
497 ENDIF | |
498 call enable_ir_s8 ; enable IR/S8 port | |
582 | 499 return |
0 | 500 |
501 restart_set_modes_and_flags3: | |
582 | 502 decfsz lo,F |
503 bra restart_set_modes_and_flags4 | |
504 | |
505 ; Gauge Mode | |
604 | 506 bsf FLAG_gauge_mode ; =1: in gauge mode |
507 IFDEF _rx_functions | |
508 call option_cleanup_oTrMode_no_CCR ; revert TR mode from 'CCR Dil+O2' to 'on' | |
509 ENDIF | |
582 | 510 return |
0 | 511 |
512 restart_set_modes_and_flags4: | |
582 | 513 decfsz lo,F |
514 bra restart_set_modes_and_flags5 | |
604 | 515 |
582 | 516 ; Apnea Mode |
604 | 517 bsf FLAG_apnoe_mode ; =1: in Apnea mode |
518 IFDEF _rx_functions | |
519 call option_cleanup_oTrMode_no_CCR ; revert TR mode from 'CCR Dil+O2' to 'on' | |
520 ENDIF | |
521 return ; start in surface mode | |
0 | 522 |
480
ad8acade5567
NEW: PSCR mode (Passive semi-closed rebreather)
heinrichsweikamp
parents:
475
diff
changeset
|
523 restart_set_modes_and_flags5: |
604 | 524 ; pSCR Mode |
525 bsf FLAG_pscr_mode ; set pSCR mode flag | |
526 call option_cleanup_oCCRMode_pSCR ; in pSCR mode, revert AutoSP (2) to calculated SP (0), additionally revert Sensor to fixed SP if no sensor interface available | |
527 IFDEF _rx_functions | |
528 call option_cleanup_oTrMode_no_CCR ; revert TR mode from 'CCR Dil+O2' to 'on' | |
529 ENDIF | |
530 call enable_ir_s8 ; enable IR/S8 port | |
531 return ; start in surface mode | |
560 | 532 |
582 | 533 |
604 | 534 ; backup the first 128 bytes from flash to EEPROM |
582 | 535 backup_flash_page: |
536 ; Start address in internal flash | |
537 movlw 0x00 | |
538 movwf TBLPTRL | |
539 movwf TBLPTRH | |
540 movwf TBLPTRU | |
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
541 |
582 | 542 movlw .128 |
604 | 543 movwf lo ; byte counter |
582 | 544 clrf EEADR |
545 movlw .3 | |
604 | 546 movwf EEADRH ; setup backup address |
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
547 |
604 | 548 TBLRD*- ; dummy read to be in 128 byte block |
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
549 backup_flash_loop: |
604 | 550 tblrd+* ; table read with pre-increment |
582 | 551 movff TABLAT,EEDATA ; put 1 byte |
552 call write_eeprom ; save it in EEPROM | |
553 incf EEADR,F | |
604 | 554 decfsz lo,F ; 128 byte done? |
555 bra backup_flash_loop ; NO - loop | |
556 clrf EEADRH ; reset EEADRH | |
557 return ; done | |
410
d3087a8ed7e1
BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents:
375
diff
changeset
|
558 |
0 | 559 END |