comparison src/start.asm @ 582:b455b31ce022

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