comparison src/start.asm @ 604:ca4556fb60b9

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