annotate src/start.asm @ 584:d63dec562d50

CNS fix
author heinrichsweikamp
date Wed, 28 Feb 2018 10:24:54 +0100
parents b455b31ce022
children 05053910d668
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
3 ; File start.asm REFACTORED VERSION V2.98
0
heinrichsweikamp
parents:
diff changeset
4 ;
heinrichsweikamp
parents:
diff changeset
5 ; Startup subroutines
heinrichsweikamp
parents:
diff changeset
6 ;
heinrichsweikamp
parents:
diff changeset
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
heinrichsweikamp
parents:
diff changeset
8 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
9 ; HISTORY
heinrichsweikamp
parents:
diff changeset
10 ; 2011-08-06 : [mH] moving from OSTC code
heinrichsweikamp
parents:
diff changeset
11
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
12 #include "hwos.inc" ; Mandatory header
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
13 #include "ms5541.inc"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
14 #include "isr.inc"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
15 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
16 #include "eeprom_rs232.inc"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
17 #include "math.inc"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
18 #include "tft.inc"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
19 #include "surfmode.inc"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
20 #include "wait.inc"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
21 #include "rtc.inc"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
22 #include "external_flash.inc"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
23 #include "convert.inc"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
24 #include "strings.inc"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
25 #include "tft_outputs.inc"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
26 #include "adc_lightsensor.inc"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
27 #include "i2c.inc"
0
heinrichsweikamp
parents:
diff changeset
28
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
29 extern init_ostc
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
30 extern option_restore_all
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
31 extern deco_setup
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
32 extern restore_decodata_from_eeprom
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
33 extern color_image
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
34 extern oPressureAdjust
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
35 extern option_reset
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
36 extern option_save
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
37 extern option_save_all
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
38 extern option_check_all
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
39 extern do_new_battery_select
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
40 extern use_old_batteries
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
41 extern use_old_prior_209
0
heinrichsweikamp
parents:
diff changeset
42
heinrichsweikamp
parents:
diff changeset
43 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
44 ; Reset vector: What to do on device wake-up and hard reset.
heinrichsweikamp
parents:
diff changeset
45 ;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
46 reset_v code 0x00000
0
heinrichsweikamp
parents:
diff changeset
47
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
48 ; goto start
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
49 goto 0x1FF00 ; Bootloader
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
50
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
51 ORG 0x00004 ; Needed for second-level bootloader
0
heinrichsweikamp
parents:
diff changeset
52 goto start
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
53
0
heinrichsweikamp
parents:
diff changeset
54 ;=============================================================================
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
55
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
56 boot CODE
0
heinrichsweikamp
parents:
diff changeset
57
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
58 global start
0
heinrichsweikamp
parents:
diff changeset
59 start:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
60 lfsr FSR0,0x000 ; Clear rambank 0-14
0
heinrichsweikamp
parents:
diff changeset
61 clear_rambank:
heinrichsweikamp
parents:
diff changeset
62 clrf POSTINC0
heinrichsweikamp
parents:
diff changeset
63 movlw 0x0F
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
64 cpfseq FSR0H ; Bank 14 done?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
65 bra clear_rambank ; clear...
0
heinrichsweikamp
parents:
diff changeset
66
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
67 call init_ostc
0
heinrichsweikamp
parents:
diff changeset
68
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
69 ; Get button type from Bootloader-Info
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
70 movlw .16
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
71 movff WREG,analog_counter ; init averaging
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
72 bsf analog_switches
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
73 movlw 0x7C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
74 movwf TBLPTRL
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
75 movlw 0xF7
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
76 movwf TBLPTRH
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
77 movlw 0x01
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
78 movwf TBLPTRU
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
79 TBLRD*+ ; Reads 0x07 for analog buttons
449
heinrichsweikamp
parents: 446
diff changeset
80 movlw 0x07
heinrichsweikamp
parents: 446
diff changeset
81 cpfseq TABLAT
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
82 bcf analog_switches
475
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
83
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
84 ; read button polarity
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
85 movlw LOW .897
475
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
86 movwf EEADR
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
87 movlw HIGH .897
475
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
88 movwf EEADRH
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
89 call read_eeprom ; EEDATA into EEPROM@EEADR
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
90 clrf EEADRH ; Reset EEADRH
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
91 movff EEDATA,button_polarity ; 0xFF (Both normal), 0x00 (Both inverted), 0x01 (Left inverted only), 0x02 (Right inverted only)
475
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
92
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
93 ; Air pressure compensation after reset
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
94 call get_calibration_data ; get calibration data from pressure sensor
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
95 banksel common ; get_calibration_data uses isr_backup
0
heinrichsweikamp
parents:
diff changeset
96
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
97 call TFT_DisplayOff ; turn off display
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
98 bsf LEDr ; turn on red LED
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
99 bcf pressure_refresh
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
100 ; First pass will not have valid temperature!
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
101 btfss pressure_refresh ; Air pressure compensation
0
heinrichsweikamp
parents:
diff changeset
102 bra $-2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
103 ; Second pass
0
heinrichsweikamp
parents:
diff changeset
104 bcf pressure_refresh
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
105 btfss pressure_refresh ; Air pressure compensation
0
heinrichsweikamp
parents:
diff changeset
106 bra $-2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
107 bcf LEDr
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
108
0
heinrichsweikamp
parents:
diff changeset
109 clrf rel_pressure+0
heinrichsweikamp
parents:
diff changeset
110 clrf rel_pressure+1
heinrichsweikamp
parents:
diff changeset
111 clrf surface_interval+0
heinrichsweikamp
parents:
diff changeset
112 clrf surface_interval+1
heinrichsweikamp
parents:
diff changeset
113
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
114 SAFE_2BYTE_COPY amb_pressure, last_surfpressure
0
heinrichsweikamp
parents:
diff changeset
115
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
116 movlw LOW max_surfpressure
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
117 movff WREG,sub_a+0 ; max. "allowed" air pressure in mbar
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
118 movlw HIGH max_surfpressure
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
119 movff WREG,sub_a+1 ; max. "allowed" air pressure in mbar
0
heinrichsweikamp
parents:
diff changeset
120 movff last_surfpressure+0,sub_b+0
heinrichsweikamp
parents:
diff changeset
121 movff last_surfpressure+1,sub_b+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
122 call subU16 ; sub_c = sub_a - sub_b
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
123 btfss neg_flag ; Is 1080mbar < amb_pressure ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
124 bra start_copy_pressure ; NO: current air pressure is lower then "allowed" air pressure, ok!
0
heinrichsweikamp
parents:
diff changeset
125
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
126 ; not ok! Overwrite with max. "allowed" air pressure
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
127 movlw LOW max_surfpressure
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
128 movff WREG,last_surfpressure+0 ; max. "allowed" air pressure in mbar
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
129 movlw HIGH max_surfpressure
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
130 movff WREG,last_surfpressure+1 ; max. "allowed" air pressure in mbar
0
heinrichsweikamp
parents:
diff changeset
131
heinrichsweikamp
parents:
diff changeset
132 start_copy_pressure:
heinrichsweikamp
parents:
diff changeset
133 movff last_surfpressure+0,last_surfpressure_15min+0
heinrichsweikamp
parents:
diff changeset
134 movff last_surfpressure+1,last_surfpressure_15min+1
heinrichsweikamp
parents:
diff changeset
135 movff last_surfpressure+0,last_surfpressure_30min+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
136 movff last_surfpressure+1,last_surfpressure_30min+1 ; resets all air pressure registers
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 545
diff changeset
137
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 545
diff changeset
138 ; initialize GF high (needed by deco engine for color-coding the GF value)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 545
diff changeset
139 movff opt_GF_high,char_I_GF_High_percentage
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 545
diff changeset
140
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
141 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; breathing at surface
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
142 movff int_I_pres_respiration+0,int_I_pres_surface+0 ; surface pressure
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
143 movff int_I_pres_respiration+1,int_I_pres_surface+1
0
heinrichsweikamp
parents:
diff changeset
144
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
145 call deco_setup ; set up all model parameters (code located in simulator.asm)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
146
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
147 call deco_clear_tissue ; Set all tissues to Pamb * N2_ratio (code located in p2_deco.c)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
148 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
149
939f1e83c4c2 BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents: 113
diff changeset
150 call rtc_init ; init clock
939f1e83c4c2 BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents: 113
diff changeset
151
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
152 movlw HIGH .512 ; =2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
153 movwf EEADRH
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
154 read_int_eeprom .0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
155 clrf EEADRH
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
156 movlw 0xAA
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
157 cpfseq EEDATA ; =0xAA
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
158 bra no_deco_restore ; No
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
159 call restore_decodata_from_eeprom ; Reload deco data and date/time from eeprom
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
160 no_deco_restore:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
161 call deco_calc_dive_interval_1min ; calculate deco in surface mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
162 call deco_calc_desaturation_time ; calculate desaturation and no-fly time
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
163 banksel common
133
939f1e83c4c2 BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents: 113
diff changeset
164
0
heinrichsweikamp
parents:
diff changeset
165 bcf menubit ; clear menu flag
215
8636efc5c6c5 ignore battery menu for cr
heinrichsweikamp
parents: 207
diff changeset
166
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
167 ; Check for Power-on reset here
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
168
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
169 ; *****************************************************************************
215
8636efc5c6c5 ignore battery menu for cr
heinrichsweikamp
parents: 207
diff changeset
170 ; "new_battery_menu" and "use_old_batteries" 'goto' back to "power_on_return"
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
171 ; *****************************************************************************
0
heinrichsweikamp
parents:
diff changeset
172
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
173 ; Try to migrate the old battery status from firmware 2.09 or earlier..
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
174 btfsc RCON,POR ; Was this a power-on reset?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
175 call use_old_prior_209 ; No
464
0491a84fd0b8 CHANGE: Easier to understand "New Battery" menu (OSTC model dependent)
heinrichsweikamp
parents: 463
diff changeset
176
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
177 bcf use_old_batt_flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
178 btfsc RCON,POR ; Was this a power-on reset?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
179 bsf use_old_batt_flag ; No
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
180
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
181 call lt2942_get_status ; Check for gauge IC
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
182 btfss battery_gauge_available ; cR or 2 hardware?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
183 bra power_on_return2 ; no
215
8636efc5c6c5 ignore battery menu for cr
heinrichsweikamp
parents: 207
diff changeset
184
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
185 movlw .30
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
186 movff WREG,opt_cR_button_right
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
187 movff WREG,opt_cR_button_left ; Reset on power-on reset
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
188 call piezo_config ; Yes, configure buttons
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
189 call piezo_config ; Yes, configure buttons (2 times)
0
heinrichsweikamp
parents:
diff changeset
190
416
4389fe9673b2 NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents: 410
diff changeset
191 power_on_return2:
0
heinrichsweikamp
parents:
diff changeset
192 ; check firmware and reset Custom Functions after an update
heinrichsweikamp
parents:
diff changeset
193 movlw d'1'
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
194 movwf EEADR ; =1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
195 movwf EEADRH ; =1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
196 call read_eeprom ; read current version x
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
197 movff EEDATA,lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
198 incf EEADR,F ; set to 0x102
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
199 call read_eeprom ; read current version y
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
200 movff EEDATA,hi
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
201 clrf EEADRH ; Reset EEADRH
0
heinrichsweikamp
parents:
diff changeset
202
443
heinrichsweikamp
parents: 441
diff changeset
203 movlw softwareversion_x
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
204 cpfseq lo ; compare version x
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
205 bra check_firmware_new ; is not equal -> reset CF and store new version in EEPROM
0
heinrichsweikamp
parents:
diff changeset
206
heinrichsweikamp
parents:
diff changeset
207 movlw softwareversion_y
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
208 cpfseq hi ; compare version y
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
209 bra check_firmware_new ; is not equal -> reset CF and store new version in EEPROM
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
210 bra restart ; x and y are equal -> do not reset cf
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
211
0
heinrichsweikamp
parents:
diff changeset
212 check_firmware_new:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
213 call TFT_boot ; Initialize TFT (includes clear screen)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
214 clrf CCPR1L ; Backlight off
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
215 WIN_TOP .50
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
216 WIN_LEFT .10
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
217 movlw LOW 0x1E000
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
218 movwf TBLPTRL
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
219 movlw HIGH 0x1E000
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
220 movwf TBLPTRH
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
221 movlw UPPER 0x1E000
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
222 movwf TBLPTRU
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
223 call color_image ; Show logo
0
heinrichsweikamp
parents:
diff changeset
224 call TFT_standard_color
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
225 WIN_SMALL .10,.100
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
226 STRCPY_PRINT "Update successful!" ; Hard coded since language switch does not work here
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
227 WIN_SMALL .10,.140
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
228 STRCPY "New Firmware: "
0
heinrichsweikamp
parents:
diff changeset
229 movlw softwareversion_x
heinrichsweikamp
parents:
diff changeset
230 movwf lo
heinrichsweikamp
parents:
diff changeset
231 bsf leftbind
heinrichsweikamp
parents:
diff changeset
232 output_8
heinrichsweikamp
parents:
diff changeset
233 PUTC "."
heinrichsweikamp
parents:
diff changeset
234 movlw softwareversion_y
heinrichsweikamp
parents:
diff changeset
235 movwf lo
45
76dfe320e6ec 1.01 beta start
heinrichsweikamp
parents: 24
diff changeset
236 output_99x
0
heinrichsweikamp
parents:
diff changeset
237 bcf leftbind
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
238 STRCAT_PRINT "" ; Print second row
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
239 call TFT_Display_FadeIn ; Display resulting surface screen.
0
heinrichsweikamp
parents:
diff changeset
240
93
5e1ef9bf32ec clear pressure sensor compensation upon update
heinrichsweikamp
parents: 52
diff changeset
241
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
242 ; place "after-update reset" here...
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
243 lfsr FSR0,oPressureAdjust
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
244 call option_reset ; Reset FSR0 option to factory default.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
245 lfsr FSR0,oPressureAdjust
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
246 call option_save ; Save in EEPROM
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
247
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
248 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
249
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
250 movlw d'1' ; store current version in EEPROM
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
251 movwf EEADR ; =1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
252 movwf EEADRH ; =1
0
heinrichsweikamp
parents:
diff changeset
253 movlw softwareversion_x
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
254 movwf EEDATA
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
255 call write_eeprom ; write version x
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
256 incf EEADR,F ; set to 0x102
0
heinrichsweikamp
parents:
diff changeset
257 movlw softwareversion_y
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
258 movwf EEDATA
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
259 call write_eeprom ; write version y
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
260 clrf EEADRH ; Reset EEADRH
0
heinrichsweikamp
parents:
diff changeset
261
heinrichsweikamp
parents:
diff changeset
262 movlw .7
heinrichsweikamp
parents:
diff changeset
263 movwf lo
heinrichsweikamp
parents:
diff changeset
264 check_firmware_new2:
heinrichsweikamp
parents:
diff changeset
265 ; Wait 1 second
heinrichsweikamp
parents:
diff changeset
266 bcf onesecupdate
heinrichsweikamp
parents:
diff changeset
267 btfss onesecupdate
heinrichsweikamp
parents:
diff changeset
268 bra $-2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
269 decfsz lo,F ; Wait 10 seconds...
0
heinrichsweikamp
parents:
diff changeset
270 bra check_firmware_new2
heinrichsweikamp
parents:
diff changeset
271
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
272 global restart
0
heinrichsweikamp
parents:
diff changeset
273 restart:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
274 clrf STKPTR ; Never return from here
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
275 clrf CCP1CON ; stop PWM
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
276 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
277
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
278 btfsc menubit ; Return from Menu/COMM mode or timeout?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
279 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
280
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
281 call option_restore_all ; Restore everything from EEPROM into RAM
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
282 call option_check_all ; Check all options (and reset if not within their min/max boundaries)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
283 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
284
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
285 clrf flag1 ; clear all flags
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
286 clrf flag2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
287 clrf flag3
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
288 clrf flag4
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
289 clrf flag5
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
290 clrf flag6
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
291 clrf flag7
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
292 clrf flag8
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
293 clrf flag9
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
294 clrf flag10
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
295 ; Do not clear flag11 (Sensor calibration and charger status)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
296 clrf flag12
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
297 ; Do not clear flag13 (Important hardware flags)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
298 clrf flag14
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
299 clrf hardware_flag ; hardware descriptor flag
23
e402813343b6 new option to switch samplingrate between 10s and 2s
heinrichsweikamp
parents: 21
diff changeset
300
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
301 bsf tft_is_dimming ; TFT is dimming up (soon), ignore ambient sensor!
236
e2ea74646127 configure hardware_flag byte
heinrichsweikamp
parents: 235
diff changeset
302
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
303 ; configure hardware_flag byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
304 bsf ambient_sensor ; Set flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
305 bsf optical_input ; Set flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
306
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
307 call lt2942_get_status ; Check for gauge IC
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
308 btfss battery_gauge_available ; cR/2 hardware?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
309 bra restart2 ; No
236
e2ea74646127 configure hardware_flag byte
heinrichsweikamp
parents: 235
diff changeset
310
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
311 call lt2942_init ; Yes, init battery gauge IC
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
312 bcf optical_input ; Clear flag
236
e2ea74646127 configure hardware_flag byte
heinrichsweikamp
parents: 235
diff changeset
313
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
314 banksel 0xF16
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
315 bcf ANCON0,7 ; AN7 Digital input
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
316 banksel common
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
317 bcf lightsen_power ; Power-down ambient light sensor
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
318 bcf ambient_sensor ; Clear flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
319 nop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
320 btfss PORTF,2 ; Light sensor available?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
321 bsf ambient_sensor ; Yes.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
322 banksel 0xF16
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
323 bsf ANCON0,7 ; AN7 Analog again
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
324 banksel common
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
325 bsf lightsen_power ; Power-up ambient light sensor again
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
326
243
ee81f46714cb auto-select correct settings menu
heinrichsweikamp
parents: 236
diff changeset
327 restart2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
328 btfsc vusb_in
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
329 bra restart3 ; USB (and powered on)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
330 bcf PORTE,0 ; Start comms
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
331 WAITMS d'1'
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
332 btfss vusb_in
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
333 bra restart3 ; USB (and powered off)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
334 bsf ble_available ; ble available
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
335
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
336 restart3:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
337 bsf PORTE,0 ; Stop comms
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
338 btfsc ble_available ; ble available?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
339 bra restart4 ; Yes, can't be a cR
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
340 btfss battery_gauge_available ; Rechargeable
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
341 bra restart4 ; No, can't be a cR
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
342 bsf analog_o2_input ; Set flag for analog
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
343
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
344 ; The hardware_flag is now:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
345 ; 0x11: 2 with BLE
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
346 ; 0x13: 2 with BLE & ambient
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
347 ; 0x05: cR
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
348 ; 0x0A: 3
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
349 ; 0x1A: 3 with BLE
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
350
249
94bf757690cf ignore sensor for non-sensor hardware
heinrichsweikamp
parents: 248
diff changeset
351 restart4:
0
heinrichsweikamp
parents:
diff changeset
352 ; Select high altitude (Fly) mode?
heinrichsweikamp
parents:
diff changeset
353 movff last_surfpressure_30min+0,sub_b+0
heinrichsweikamp
parents:
diff changeset
354 movff last_surfpressure_30min+1,sub_b+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
355 movlw HIGH high_altitude_threshold
0
heinrichsweikamp
parents:
diff changeset
356 movwf sub_a+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
357 movlw LOW high_altitude_threshold ; hard-wired 880mbar
0
heinrichsweikamp
parents:
diff changeset
358 movwf sub_a+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
359 call subU16 ; sub_c = sub_a - sub_b
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
360 btfss neg_flag ; result negative (ambient > 880mbar)?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
361 bsf high_altitude_mode ; NO - set flag!
0
heinrichsweikamp
parents:
diff changeset
362
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
363 btfss analog_o2_input
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
364 bsf TRISB,3
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
365 btfss battery_gauge_available
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
366 bsf TRISG,0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
367 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
368
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
369 bsf flip_screen ; flip 180°
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
370 TSTOSS opt_flip_screen ; =1: Flip the screen
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
371 bcf flip_screen ; normal orientation
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
372
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
373 btfsc use_old_batt_flag ; =1: load old battery information after power-on reset
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
374 goto use_old_batteries ; returns to "surfloop"!
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
375
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
376 btfsc RCON,POR ; was this a power-on reset?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
377 goto surfloop ; jump to surface loop!
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
378 bsf RCON,POR ; set bit for next detection
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
379 ; Things to do after a power-on reset
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
380 goto do_new_battery_select ; returns to "surfloop"!
0
heinrichsweikamp
parents:
diff changeset
381
heinrichsweikamp
parents:
diff changeset
382 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
383 ; Setup all flags and parameters for divemode and simulator computations.
heinrichsweikamp
parents:
diff changeset
384 ;
heinrichsweikamp
parents:
diff changeset
385 global restart_set_modes_and_flags
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
386 restart_set_modes_and_flags: ; "Call"ed from divemode, as well!
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
387 call option_restore_all ; Restore everything from EEPROM
24
f51caad821b4 save logbook recording interval
heinrichsweikamp
parents: 23
diff changeset
388
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
389 ; Setup sampling rate
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
390 movlw .2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
391 movwf samplingrate
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
392 TSTOSS opt_sampling_rate ; =1: 10s, =0: 2s
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
393 bra restart_set_modes_and_flags1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
394 movlw .10
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
395 movwf samplingrate
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
396
24
f51caad821b4 save logbook recording interval
heinrichsweikamp
parents: 23
diff changeset
397 restart_set_modes_and_flags1:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
398 bcf twosecupdate ; to have divemode routines in sync
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
399 bcf FLAG_apnoe_mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
400 bcf FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
401 bcf FLAG_gauge_mode ; =1: In Gauge mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
402 bcf FLAG_pscr_mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
403 call disable_ir_s8 ; IR off
0
heinrichsweikamp
parents:
diff changeset
404
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
405 ; Setup char_I_saturation_multiplier and char_I_desaturation_multiplier
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
406 movff opt_sat_multiplier_gf,char_I_saturation_multiplier
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
407 movff opt_desat_multiplier_gf,char_I_desaturation_multiplier
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
408 movff char_I_deco_model,lo ; 0 = ZH-L16, 1 = ZH-L16-GF
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
409 tstfsz lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
410 bra restart_set_modes_and_flags1b
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
411 movff opt_sat_multiplier_non_gf,char_I_saturation_multiplier
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
412 movff opt_desat_multiplier_non_gf,char_I_desaturation_multiplier
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
413
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
414 restart_set_modes_and_flags1b:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
415 movff opt_dive_mode,lo ; 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=PSCR
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
416 tstfsz lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
417 bra restart_set_modes_and_flags2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
418
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
419 ; OC Mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
420 return
0
heinrichsweikamp
parents:
diff changeset
421
heinrichsweikamp
parents:
diff changeset
422 restart_set_modes_and_flags2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
423 decfsz lo,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
424 bra restart_set_modes_and_flags3
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
425
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
426 ; CC Mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
427 btfsc analog_o2_input ; cR?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
428 bra restart_set_modes_and_flags2b ; Yes, skip mode check
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
429 btfsc optical_input ; 3
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
430 bra restart_set_modes_and_flags2b ; Yes, skip mode check
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
431
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
432 ; Make sure Sensor is not selected
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
433 ; opt_ccr_mode must be <> 1 (=0: Fixed SP, =1: Sensor, =2: Auto SP (CCR only))
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
434 banksel opt_ccr_mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
435 movlw .1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
436 cpfseq opt_ccr_mode ; = Sensor?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
437 bra restart_set_modes_and_flags2b ; No
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
438 clrf opt_ccr_mode ; Yes, reset to Fixed SP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
439
359
2be48ccfa9de make AUTO SP available on OSTC2 hardware
heinrichsweikamp
parents: 338
diff changeset
440 restart_set_modes_and_flags2b:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
441 banksel common
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
442 bsf FLAG_ccr_mode ; =1: CCR mode (Fixed SP, Auto SP or Sensor) active
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
443 call enable_ir_s8 ; Enable IR/S8-Port
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
444 return
0
heinrichsweikamp
parents:
diff changeset
445
heinrichsweikamp
parents:
diff changeset
446 restart_set_modes_and_flags3:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
447 decfsz lo,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
448 bra restart_set_modes_and_flags4
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
449
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
450 ; Gauge Mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
451 bsf FLAG_gauge_mode ; =1: In Gauge mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
452 return
0
heinrichsweikamp
parents:
diff changeset
453
heinrichsweikamp
parents:
diff changeset
454 restart_set_modes_and_flags4:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
455 decfsz lo,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
456 bra restart_set_modes_and_flags5
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
457 ; Apnea Mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
458 bsf FLAG_apnoe_mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
459 return ; start in Surfacemode
0
heinrichsweikamp
parents:
diff changeset
460
480
ad8acade5567 NEW: PSCR mode (Passive semi-closed rebreather)
heinrichsweikamp
parents: 475
diff changeset
461 restart_set_modes_and_flags5:
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 545
diff changeset
462 ; PSCR Mode
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 545
diff changeset
463 btfsc analog_o2_input ; cR?
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 545
diff changeset
464 bra restart_set_modes_and_flags5b ; Yes, skip mode check
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 545
diff changeset
465 btfsc optical_input ; 3
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 545
diff changeset
466 bra restart_set_modes_and_flags5b ; Yes, skip mode check
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 545
diff changeset
467
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 545
diff changeset
468 ; Make sure Sensor is not selected
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 545
diff changeset
469 ; opt_ccr_mode must be <> 1 (=0: calculated ppO2, =1: Sensor, =2: Auto SP - not valid in pSCR, too)
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 545
diff changeset
470 banksel opt_ccr_mode
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 545
diff changeset
471 movlw .1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 545
diff changeset
472 cpfseq opt_ccr_mode ; = Sensor?
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 545
diff changeset
473 bra restart_set_modes_and_flags5b ; No
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 545
diff changeset
474 clrf opt_ccr_mode ; Yes, reset to calculated ppO2
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 545
diff changeset
475
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 545
diff changeset
476 restart_set_modes_and_flags5b:
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 545
diff changeset
477 banksel opt_ccr_mode
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 545
diff changeset
478 bcf opt_ccr_mode,1 ; in pSCR mode only calculated or Sensor, not 2 = Auto SP allowed
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 545
diff changeset
479 banksel common
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 545
diff changeset
480 bsf FLAG_pscr_mode
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 545
diff changeset
481 return ; start in Surfacemode
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 545
diff changeset
482
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
483
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
484 ; backup the first 128bytes from flash to EEPROM
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
485 backup_flash_page:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
486 ; Start address in internal flash
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
487 movlw 0x00
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
488 movwf TBLPTRL
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
489 movwf TBLPTRH
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
490 movwf TBLPTRU
410
d3087a8ed7e1 BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents: 375
diff changeset
491
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
492 movlw .128
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
493 movwf lo ; Byte counter
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
494 clrf EEADR
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
495 movlw .3
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
496 movwf EEADRH ; Setup backup address
410
d3087a8ed7e1 BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents: 375
diff changeset
497
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
498 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
499 backup_flash_loop:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
500 tblrd+* ; Table Read with Pre-Increment
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
501 movff TABLAT,EEDATA ; put 1 byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
502 call write_eeprom ; save it in EEPROM
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
503 incf EEADR,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
504 decfsz lo,F ; 128byte done?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
505 bra backup_flash_loop ; No
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
506 clrf EEADRH ; Reset EEADRH
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 562
diff changeset
507 return ; Done.
410
d3087a8ed7e1 BUGFIX: Fix rare issue after battery change (OSTC3 did not start properly)
heinrichsweikamp
parents: 375
diff changeset
508
0
heinrichsweikamp
parents:
diff changeset
509 END