comparison src/start.asm @ 560:b7eb98dbd800

bump to 2.96beta (REFACTORED VERSION)
author heinrichsweikamp
date Wed, 31 Jan 2018 19:39:37 +0100
parents 7e6df19264b6
children 9c54849b8d3b
comparison
equal deleted inserted replaced
559:9cb967d844f0 560:b7eb98dbd800
1 ;============================================================================= 1 ;=============================================================================
2 ; 2 ;
3 ; File start.asm 3 ; File start.asm REFACTORED VERSION V2.95a1
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 ;=============================================================================
32 ;============================================================================= 32 ;=============================================================================
33 ; Reset vector: What to do on device wake-up and hard reset. 33 ; Reset vector: What to do on device wake-up and hard reset.
34 ; 34 ;
35 reset_v code 0x00000 35 reset_v code 0x00000
36 ; goto start 36 ; goto start
37 goto 0x1FF00 ; Bootloader 37 goto 0x1FF00 ; Bootloader
38 38
39 ORG 0x00004 ; Needed for second-level bootloader 39 ORG 0x00004 ; Needed for second-level bootloader
40 goto start 40 goto start
41 ;============================================================================= 41 ;=============================================================================
42 boot CODE 42 boot CODE
51 bra clear_rambank ; clear... 51 bra clear_rambank ; clear...
52 52
53 call init_ostc 53 call init_ostc
54 54
55 ; Get button type from Bootloader-Info 55 ; Get button type from Bootloader-Info
56 movlw .16 56 movlw .16
57 movff WREG,analog_counter ; init averaging 57 movff WREG,analog_counter ; init averaging
58 bsf analog_switches 58 bsf analog_switches
59 movlw 0x7C 59 movlw 0x7C
60 movwf TBLPTRL 60 movwf TBLPTRL
61 movlw 0xF7 61 movlw 0xF7
62 movwf TBLPTRH 62 movwf TBLPTRH
63 movlw 0x01 63 movlw 0x01
64 movwf TBLPTRU 64 movwf TBLPTRU
65 TBLRD*+ ; Reads 0x07 for analog buttons 65 TBLRD*+ ; Reads 0x07 for analog buttons
66 movlw 0x07 66 movlw 0x07
67 cpfseq TABLAT 67 cpfseq TABLAT
68 bcf analog_switches 68 bcf analog_switches
69 69
70 ; read button polarity 70 ; read button polarity
71 movlw LOW .897 71 movlw LOW .897
72 movwf EEADR 72 movwf EEADR
73 movlw HIGH .897 73 movlw HIGH .897
74 movwf EEADRH 74 movwf EEADRH
75 call read_eeprom ; EEDATA into EEPROM@EEADR 75 call read_eeprom ; EEDATA into EEPROM@EEADR
76 clrf EEADRH ; Reset EEADRH 76 clrf EEADRH ; Reset EEADRH
77 movff EEDATA,button_polarity ; 0xFF (Both normal), 0x00 (Both inverted), 0x01 (Left inverted only), 0x02 (Right inverted only) 77 movff EEDATA,button_polarity ; 0xFF (Both normal), 0x00 (Both inverted), 0x01 (Left inverted only), 0x02 (Right inverted only)
78 78
79 ; Air pressure compensation after reset 79 ; Air pressure compensation after reset
80 call get_calibration_data ; Get calibration data from pressure sensor 80 call get_calibration_data ; Get calibration data from pressure sensor
81 banksel common ; get_calibration_data uses isr_backup 81 banksel common ; get_calibration_data uses isr_backup
82 82
83 call TFT_DisplayOff ; display off 83 call TFT_DisplayOff ; display off
84 bsf LEDr ; Status LED 84 bsf LEDr ; Status LED
85 bcf pressure_refresh 85 bcf pressure_refresh
86 ; First pass will not have valid temperature! 86 ; First pass will not have valid temperature!
87 btfss pressure_refresh ; Air pressure compensation 87 btfss pressure_refresh ; Air pressure compensation
88 bra $-2 88 bra $-2
89 ; Second pass 89 ; Second pass
103 movff WREG,sub_a+0 ; max. "allowed" airpressure in mbar 103 movff WREG,sub_a+0 ; max. "allowed" airpressure in mbar
104 movlw HIGH max_surfpressure 104 movlw HIGH max_surfpressure
105 movff WREG,sub_a+1 ; max. "allowed" airpressure in mbar 105 movff WREG,sub_a+1 ; max. "allowed" airpressure in mbar
106 movff last_surfpressure+0,sub_b+0 106 movff last_surfpressure+0,sub_b+0
107 movff last_surfpressure+1,sub_b+1 107 movff last_surfpressure+1,sub_b+1
108 call subU16 ; sub_c = sub_a - sub_b 108 call subU16 ; sub_c = sub_a - sub_b
109 btfss neg_flag ; Is 1080mbar < amb_pressure ? 109 btfss neg_flag ; Is 1080mbar < amb_pressure ?
110 bra start_copy_pressure ; NO: current airpressure is lower then "allowed" airpressure, ok! 110 bra start_copy_pressure ; NO: current airpressure is lower then "allowed" airpressure, ok!
111 111
112 ; not ok! Overwrite with max. "allowed" airpressure 112 ; not ok! Overwrite with max. "allowed" airpressure
113 movlw LOW max_surfpressure 113 movlw LOW max_surfpressure
114 movff WREG,last_surfpressure+0 ; max. "allowed" airpressure in mbar 114 movff WREG,last_surfpressure+0 ; max. "allowed" airpressure in mbar
115 movlw HIGH max_surfpressure 115 movlw HIGH max_surfpressure
117 117
118 start_copy_pressure: 118 start_copy_pressure:
119 movff last_surfpressure+0,last_surfpressure_15min+0 119 movff last_surfpressure+0,last_surfpressure_15min+0
120 movff last_surfpressure+1,last_surfpressure_15min+1 120 movff last_surfpressure+1,last_surfpressure_15min+1
121 movff last_surfpressure+0,last_surfpressure_30min+0 121 movff last_surfpressure+0,last_surfpressure_30min+0
122 movff last_surfpressure+1,last_surfpressure_30min+1 ; Rests all airpressure registers 122 movff last_surfpressure+1,last_surfpressure_30min+1 ; resets all airpressure registers
123 123
124 ; reset deco data for surface mode 124 ; reset deco data for surface mode
125 movlw d'79' 125 movlw .21 ; 21%
126 movff WREG,char_I_N2_ratio ; 79% N2 126 movff WREG,char_I_O2_ratio ; ... oxygen
127 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; copy for deco routine 127 movlw .0 ; 0%
128 movff int_I_pres_respiration+0,int_I_pres_surface+0 ; copy for desat routine 128 movff WREG,char_I_He_ratio ; ... helium
129
130 ; initialize GF high (needed by deco engine for color-coding the GF value)
131 movff opt_GF_high,char_I_GF_High_percentage
132
133 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
129 movff int_I_pres_respiration+1,int_I_pres_surface+1 135 movff int_I_pres_respiration+1,int_I_pres_surface+1
130 136
131 extern deco_reset 137 extern deco_setup
132 call deco_reset 138 call deco_setup ; set up all model parameters.
139 call deco_clear_tissue ; Set all tissues to Pamb * N2_ratio (C-Code)
140 banksel common ; back to bank 1, needed after every return from C code
133 141
134 call rtc_init ; init clock 142 call rtc_init ; init clock
135 143
136 movlw HIGH .512 ; =2 144 movlw HIGH .512 ; =2
137 movwf EEADRH 145 movwf EEADRH
138 read_int_eeprom .0 146 read_int_eeprom .0
139 clrf EEADRH 147 clrf EEADRH
140 movlw 0xAA 148 movlw 0xAA
141 cpfseq EEDATA ; =0xAA 149 cpfseq EEDATA ; =0xAA
142 bra no_deco_restore ; No 150 bra no_deco_restore ; No
143 151
144 extern restore_decodata_from_eeprom 152 extern restore_decodata_from_eeprom
145 call restore_decodata_from_eeprom ; Reload deco data and date/time from eeprom 153 call restore_decodata_from_eeprom ; Reload deco data and date/time from eeprom
146 154
147 no_deco_restore: 155 no_deco_restore:
148 call deco_calc_desaturation_time ; calculate desaturation time 156 call deco_calc_wo_deco_step_1_min ; calculate deco in surface mode
157 call deco_calc_desaturation_time ; calculate desaturation and no-fly time
149 banksel common 158 banksel common
150 call deco_calc_wo_deco_step_1_min ; calculate deco in surface mode 159
151 banksel common
152 bcf menubit ; clear menu flag 160 bcf menubit ; clear menu flag
153 161
154 ; Check for Power-on reset here 162 ; Check for Power-on reset here
155 extern use_old_prior_209 163 extern use_old_prior_209
156 ; ***************************************************************************** 164 ; *****************************************************************************
157 ; "new_battery_menu" and "use_old_batteries" 'goto' back to "power_on_return" 165 ; "new_battery_menu" and "use_old_batteries" 'goto' back to "power_on_return"
158 ; ***************************************************************************** 166 ; *****************************************************************************
159 167
160 ; Try to migrate the old battery status from firmware 2.09 or earlier.. 168 ; Try to migrate the old battery status from firmware 2.09 or earlier..
161 btfsc RCON,POR ; Was this a power-on reset? 169 btfsc RCON,POR ; Was this a power-on reset?
162 call use_old_prior_209 ; No 170 call use_old_prior_209 ; No
163 171
164 bcf use_old_batt_flag 172 bcf use_old_batt_flag
165 btfsc RCON,POR ; Was this a power-on reset? 173 btfsc RCON,POR ; Was this a power-on reset?
166 bsf use_old_batt_flag ; No 174 bsf use_old_batt_flag ; No
167 175
168 call lt2942_get_status ; Check for gauge IC 176 call lt2942_get_status ; Check for gauge IC
169 btfss battery_gauge_available ; cR or 2 hardware? 177 btfss battery_gauge_available ; cR or 2 hardware?
170 bra power_on_return2 ; no 178 bra power_on_return2 ; no
171 179
172 movlw .30 180 movlw .30
173 movff WREG,opt_cR_button_right 181 movff WREG,opt_cR_button_right
174 movff WREG,opt_cR_button_left ; Reset on power-on reset 182 movff WREG,opt_cR_button_left ; Reset on power-on reset
175 call piezo_config ; Yes, configure buttons 183 call piezo_config ; Yes, configure buttons
221 PUTC "." 229 PUTC "."
222 movlw softwareversion_y 230 movlw softwareversion_y
223 movwf lo 231 movwf lo
224 output_99x 232 output_99x
225 bcf leftbind 233 bcf leftbind
226 STRCAT_PRINT "" ; Print second row 234 STRCAT_PRINT "" ; Print second row
227 call TFT_Display_FadeIn ; Display resulting surface screen. 235 call TFT_Display_FadeIn ; Display resulting surface screen.
228 236
229 ; place "after-update reset" here... 237 ; place "after-update reset" here...
230 238
231 extern oPressureAdjust, option_reset, option_save 239 extern oPressureAdjust, option_reset, option_save
232 lfsr FSR0,oPressureAdjust 240 lfsr FSR0,oPressureAdjust
271 btfsc menubit ; Return from Menu/COMM mode or timeout? 279 btfsc menubit ; Return from Menu/COMM mode or timeout?
272 call option_save_all ; Yes, save all settings into EEPROM 280 call option_save_all ; Yes, save all settings into EEPROM
273 281
274 call option_restore_all ; Restore everything from EEPROM into RAM 282 call option_restore_all ; Restore everything from EEPROM into RAM
275 call option_check_all ; Check all options (and reset if not within their min/max boundaries) 283 call option_check_all ; Check all options (and reset if not within their min/max boundaries)
276 call option_save_all ; Save all settings into EEPROM after they have been checked 284 call option_save_all ; Save all settings into EEPROM after they have been checked
277 285
278 clrf flag1 ; clear all flags 286 clrf flag1 ; clear all flags
279 clrf flag2 287 clrf flag2
280 clrf flag3 288 clrf flag3
281 clrf flag4 289 clrf flag4
285 clrf flag8 293 clrf flag8
286 clrf flag9 294 clrf flag9
287 clrf flag10 295 clrf flag10
288 ; Do not clear flag11 (Sensor calibration and charger status) 296 ; Do not clear flag11 (Sensor calibration and charger status)
289 clrf flag12 297 clrf flag12
290 ; ; Do not clear flag13 (Important hardware flags) 298 ; Do not clear flag13 (Important hardware flags)
291 clrf flag14 299 clrf flag14
292 clrf hardware_flag ; hardware descriptor flag 300 clrf hardware_flag ; hardware descriptor flag
293 bsf tft_is_dimming ; TFT is dimming up (soon), ignore ambient sensor! 301 bsf tft_is_dimming ; TFT is dimming up (soon), ignore ambient sensor!
294 302
295 ; configure hardware_flag byte 303 ; configure hardware_flag byte
296 304
297 bsf ambient_sensor ; Set flag 305 bsf ambient_sensor ; Set flag
298 bsf optical_input ; Set flag 306 bsf optical_input ; Set flag
299 307
300 call lt2942_get_status ; Check for gauge IC 308 call lt2942_get_status ; Check for gauge IC
301 btfss battery_gauge_available ; cR/2 hardware? 309 btfss battery_gauge_available ; cR/2 hardware?
302 bra restart2 ; No 310 bra restart2 ; No
303 311
304 call lt2942_init ; Yes, init battery gauge IC 312 call lt2942_init ; Yes, init battery gauge IC
305 bcf optical_input ; Clear flag 313 bcf optical_input ; Clear flag
306 314
307 banksel 0xF16 315 banksel 0xF16
308 bcf ANCON0,7 ; AN7 Digital input 316 bcf ANCON0,7 ; AN7 Digital input
309 banksel common 317 banksel common
310 bcf lightsen_power ; Power-down ambient light sensor 318 bcf lightsen_power ; Power-down ambient light sensor
311 bcf ambient_sensor ; Clear flag 319 bcf ambient_sensor ; Clear flag
312 nop 320 nop
313 btfss PORTF,2 ; Light sensor available? 321 btfss PORTF,2 ; Light sensor available?
314 bsf ambient_sensor ; Yes. 322 bsf ambient_sensor ; Yes.
315 banksel 0xF16 323 banksel 0xF16
316 bsf ANCON0,7 ; AN7 Analog again 324 bsf ANCON0,7 ; AN7 Analog again
317 banksel common 325 banksel common
318 bsf lightsen_power ; Power-up ambient light sensor again 326 bsf lightsen_power ; Power-up ambient light sensor again
319 327
320 restart2: 328 restart2:
321 btfsc vusb_in 329 btfsc vusb_in
322 bra restart3 ; USB (and powered on) 330 bra restart3 ; USB (and powered on)
323 bcf PORTE,0 ; Start comms 331 bcf PORTE,0 ; Start comms
359 367
360 bsf flip_screen ; Flip 180° 368 bsf flip_screen ; Flip 180°
361 TSTOSS opt_flip_screen ; =1: Flip the screen 369 TSTOSS opt_flip_screen ; =1: Flip the screen
362 bcf flip_screen ; Normal orientation 370 bcf flip_screen ; Normal orientation
363 371
364 btfsc use_old_batt_flag ; =1: load old battery information after power-on reset 372 btfsc use_old_batt_flag ; =1: load old battery information after power-on reset
365 goto use_old_batteries ; Returns to "surfloop"! 373 goto use_old_batteries ; Returns to "surfloop"!
366 374
367 btfsc RCON,POR ; Was this a power-on reset? 375 btfsc RCON,POR ; Was this a power-on reset?
368 goto surfloop ; Jump to Surfaceloop! 376 goto surfloop ; Jump to Surfaceloop!
369 bsf RCON,POR ; Set bit for next detection 377 bsf RCON,POR ; Set bit for next detection
370 ; Things to do after a power-on reset 378 ; Things to do after a power-on reset
371 extern new_battery_menu,use_old_batteries 379 extern new_battery_menu,use_old_batteries
372 goto new_battery_menu ; Returns to "surfloop"! 380 goto new_battery_menu ; Returns to "surfloop"!
373 381
374 ;============================================================================= 382 ;=============================================================================
375 ; Setup all flags and parameters for divemode and simulator computations. 383 ; Setup all flags and parameters for divemode and simulator computations.
376 ; 384 ;
377 global restart_set_modes_and_flags 385 global restart_set_modes_and_flags
384 TSTOSS opt_sampling_rate ; =1: 10s, =0: 2s 392 TSTOSS opt_sampling_rate ; =1: 10s, =0: 2s
385 bra restart_set_modes_and_flags1 393 bra restart_set_modes_and_flags1
386 movlw .10 394 movlw .10
387 movwf samplingrate 395 movwf samplingrate
388 restart_set_modes_and_flags1: 396 restart_set_modes_and_flags1:
389 bcf twosecupdate ; to have divemode routines in sync 397 bcf twosecupdate ; to have divemode routines in sync
390 movlw .3 398
391 movff WREG,char_O_deco_status ; will init the deco_calc_hauptroutine on first invocation
392 bcf FLAG_apnoe_mode 399 bcf FLAG_apnoe_mode
393 bcf FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active 400 bcf FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active
394 bcf FLAG_gauge_mode ; =1: In Gauge mode 401 bcf FLAG_gauge_mode ; =1: In Gauge mode
395 bcf FLAG_pscr_mode 402 bcf FLAG_pscr_mode
396 call disable_ir_s8 ; IR off 403 call disable_ir_s8 ; IR off
397 404
398 movff opt_dive_mode,lo ; 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=PSCR 405 movff opt_dive_mode,lo ; 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=PSCR
399 406
400 tstfsz lo 407 tstfsz lo
401 bra restart_set_modes_and_flags2 408 bra restart_set_modes_and_flags2
402 ; OC Mode 409 ; OC Mode
410
403 return 411 return
404 412
405 restart_set_modes_and_flags2: 413 restart_set_modes_and_flags2:
406 decfsz lo,F 414 decfsz lo,F
407 bra restart_set_modes_and_flags3 415 bra restart_set_modes_and_flags3
417 cpfseq opt_ccr_mode ; = Sensor? 425 cpfseq opt_ccr_mode ; = Sensor?
418 bra restart_set_modes_and_flags2b ; No 426 bra restart_set_modes_and_flags2b ; No
419 clrf opt_ccr_mode ; Yes, reset to Fixed SP 427 clrf opt_ccr_mode ; Yes, reset to Fixed SP
420 restart_set_modes_and_flags2b: 428 restart_set_modes_and_flags2b:
421 banksel common 429 banksel common
422 bsf FLAG_ccr_mode ; =1: CCR mode (Fixed SP, Auto SP or Sensor) active 430 bsf FLAG_ccr_mode ; =1: CCR mode (Fixed SP, Auto SP or Sensor) active
423 call enable_ir_s8 ; Enable IR/S8-Port 431 call enable_ir_s8 ; Enable IR/S8-Port
424 return 432 return
425 433
426 restart_set_modes_and_flags3: 434 restart_set_modes_and_flags3:
427 decfsz lo,F 435 decfsz lo,F
428 bra restart_set_modes_and_flags4 436 bra restart_set_modes_and_flags4
429 ; Gauge Mode 437 ; Gauge Mode
430 bsf FLAG_gauge_mode ; =1: In Gauge mode 438 bsf FLAG_gauge_mode ; =1: In Gauge mode
431 return 439 return
432 440
433 restart_set_modes_and_flags4: 441 restart_set_modes_and_flags4:
434 decfsz lo,F 442 decfsz lo,F
435 bra restart_set_modes_and_flags5 443 bra restart_set_modes_and_flags5
436 ; Apnea Mode 444 ; Apnea Mode
437 bsf FLAG_apnoe_mode 445 bsf FLAG_apnoe_mode
438 return ; start in Surfacemode 446 return ; start in Surfacemode
439 447
440 restart_set_modes_and_flags5: 448 restart_set_modes_and_flags5:
441 ; PSCR Mode 449 ; PSCR Mode
442 bsf FLAG_pscr_mode 450 btfsc analog_o2_input ; cR?
443 return ; start in Surfacemode 451 bra restart_set_modes_and_flags5b ; Yes, skip mode check
444 452 btfsc optical_input ; 3
453 bra restart_set_modes_and_flags5b ; Yes, skip mode check
454
455 ; Make sure Sensor is not selected
456 ; opt_ccr_mode must be <> 1 (=0: calculated ppO2, =1: Sensor, =2: Auto SP - not valid in pSCR, too)
457 banksel opt_ccr_mode
458 movlw .1
459 cpfseq opt_ccr_mode ; = Sensor?
460 bra restart_set_modes_and_flags5b ; No
461 clrf opt_ccr_mode ; Yes, reset to calculated ppO2
462
463 restart_set_modes_and_flags5b:
464 banksel opt_ccr_mode
465 bcf opt_ccr_mode,1 ; in pSCR mode only calculated or Sensor, not 2 = Auto SP allowed
466 banksel common
467 bsf FLAG_pscr_mode
468 return ; start in Surfacemode
469
445 470
446 backup_flash_page: ; backup the first 128bytes from flash to EEPROM 471 backup_flash_page: ; backup the first 128bytes from flash to EEPROM
447 ; Start address in internal flash 472 ; Start address in internal flash
448 movlw 0x00 473 movlw 0x00
449 movwf TBLPTRL 474 movwf TBLPTRL
450 movwf TBLPTRH 475 movwf TBLPTRH
451 movwf TBLPTRU 476 movwf TBLPTRU
452 477
453 movlw .128 478 movlw .128
454 movwf lo ; Byte counter 479 movwf lo ; Byte counter
455 clrf EEADR 480 clrf EEADR
456 movlw .3 481 movlw .3
457 movwf EEADRH ; Setup backup address 482 movwf EEADRH ; Setup backup address
458 483
459 TBLRD*- ; Dummy read to be in 128 byte block 484 TBLRD*- ; Dummy read to be in 128 byte block
460 backup_flash_loop: 485 backup_flash_loop:
461 tblrd+* ; Table Read with Pre-Increment 486 tblrd+* ; Table Read with Pre-Increment
462 movff TABLAT,EEDATA ; put 1 byte 487 movff TABLAT,EEDATA ; put 1 byte
463 call write_eeprom ; save it in EEPROM 488 call write_eeprom ; save it in EEPROM
464 incf EEADR,F 489 incf EEADR,F
465 decfsz lo,F ; 128byte done? 490 decfsz lo,F ; 128byte done?
466 bra backup_flash_loop ; No 491 bra backup_flash_loop ; No
467 clrf EEADRH ; Reset EEADRH 492 clrf EEADRH ; Reset EEADRH
468 return ; Done. 493 return ; Done.
469 494
470 END 495 END