Mercurial > public > hwos_code
diff 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 |
line wrap: on
line diff
--- a/src/start.asm Sun Feb 25 18:25:38 2018 +0100 +++ b/src/start.asm Mon Feb 26 16:40:28 2018 +0100 @@ -1,6 +1,6 @@ ;============================================================================= ; -; File start.asm REFACTORED VERSION V2.95a1 +; File start.asm REFACTORED VERSION V2.98 ; ; Startup subroutines ; @@ -9,219 +9,223 @@ ; HISTORY ; 2011-08-06 : [mH] moving from OSTC code -#include "hwos.inc" ; Mandatory header -#include "ms5541.inc" -#include "isr.inc" -#include "shared_definitions.h" ; Mailbox from/to p2_deco.c -#include "eeprom_rs232.inc" -#include "math.inc" -#include "tft.inc" -#include "surfmode.inc" -#include "wait.inc" -#include "rtc.inc" -#include "external_flash.inc" -#include "convert.inc" -#include "strings.inc" -#include "tft_outputs.inc" -#include "adc_lightsensor.inc" -#include "i2c.inc" +#include "hwos.inc" ; Mandatory header +#include "ms5541.inc" +#include "isr.inc" +#include "shared_definitions.h" ; Mailbox from/to p2_deco.c +#include "eeprom_rs232.inc" +#include "math.inc" +#include "tft.inc" +#include "surfmode.inc" +#include "wait.inc" +#include "rtc.inc" +#include "external_flash.inc" +#include "convert.inc" +#include "strings.inc" +#include "tft_outputs.inc" +#include "adc_lightsensor.inc" +#include "i2c.inc" - extern init_ostc - extern option_restore_all + extern init_ostc + extern option_restore_all + extern deco_setup + extern restore_decodata_from_eeprom + extern color_image + extern oPressureAdjust + extern option_reset + extern option_save + extern option_save_all + extern option_check_all + extern do_new_battery_select + extern use_old_batteries + extern use_old_prior_209 ;============================================================================= ; Reset vector: What to do on device wake-up and hard reset. ; -reset_v code 0x00000 -; goto start - goto 0x1FF00 ; Bootloader +reset_v code 0x00000 - ORG 0x00004 ; Needed for second-level bootloader +; goto start + goto 0x1FF00 ; Bootloader + + ORG 0x00004 ; Needed for second-level bootloader goto start + ;============================================================================= -boot CODE - global start + +boot CODE + global start start: - lfsr FSR0,0x000 ; Clear rambank 0-14 + lfsr FSR0,0x000 ; Clear rambank 0-14 clear_rambank: clrf POSTINC0 movlw 0x0F - cpfseq FSR0H ; Bank 14 done? - bra clear_rambank ; clear... + cpfseq FSR0H ; Bank 14 done? + bra clear_rambank ; clear... - call init_ostc + call init_ostc - ; Get button type from Bootloader-Info - movlw .16 - movff WREG,analog_counter ; init averaging - bsf analog_switches - movlw 0x7C - movwf TBLPTRL - movlw 0xF7 - movwf TBLPTRH - movlw 0x01 - movwf TBLPTRU - TBLRD*+ ; Reads 0x07 for analog buttons + ; Get button type from Bootloader-Info + movlw .16 + movff WREG,analog_counter ; init averaging + bsf analog_switches + movlw 0x7C + movwf TBLPTRL + movlw 0xF7 + movwf TBLPTRH + movlw 0x01 + movwf TBLPTRU + TBLRD*+ ; Reads 0x07 for analog buttons movlw 0x07 cpfseq TABLAT - bcf analog_switches + bcf analog_switches ; read button polarity - movlw LOW .897 + movlw LOW .897 movwf EEADR - movlw HIGH .897 + movlw HIGH .897 movwf EEADRH - call read_eeprom ; EEDATA into EEPROM@EEADR - clrf EEADRH ; Reset EEADRH - movff EEDATA,button_polarity ; 0xFF (Both normal), 0x00 (Both inverted), 0x01 (Left inverted only), 0x02 (Right inverted only) + call read_eeprom ; EEDATA into EEPROM@EEADR + clrf EEADRH ; Reset EEADRH + movff EEDATA,button_polarity ; 0xFF (Both normal), 0x00 (Both inverted), 0x01 (Left inverted only), 0x02 (Right inverted only) -; Air pressure compensation after reset - call get_calibration_data ; Get calibration data from pressure sensor - banksel common ; get_calibration_data uses isr_backup + ; Air pressure compensation after reset + call get_calibration_data ; get calibration data from pressure sensor + banksel common ; get_calibration_data uses isr_backup - call TFT_DisplayOff ; display off - bsf LEDr ; Status LED - bcf pressure_refresh -; First pass will not have valid temperature! - btfss pressure_refresh ; Air pressure compensation + call TFT_DisplayOff ; turn off display + bsf LEDr ; turn on red LED + bcf pressure_refresh + ; First pass will not have valid temperature! + btfss pressure_refresh ; Air pressure compensation bra $-2 - ; Second pass + ; Second pass bcf pressure_refresh - btfss pressure_refresh ; Air pressure compensation + btfss pressure_refresh ; Air pressure compensation bra $-2 - bcf LEDr - + bcf LEDr + clrf rel_pressure+0 clrf rel_pressure+1 clrf surface_interval+0 clrf surface_interval+1 - SAFE_2BYTE_COPY amb_pressure, last_surfpressure + SAFE_2BYTE_COPY amb_pressure, last_surfpressure - movlw LOW max_surfpressure - movff WREG,sub_a+0 ; max. "allowed" airpressure in mbar - movlw HIGH max_surfpressure - movff WREG,sub_a+1 ; max. "allowed" airpressure in mbar + movlw LOW max_surfpressure + movff WREG,sub_a+0 ; max. "allowed" air pressure in mbar + movlw HIGH max_surfpressure + movff WREG,sub_a+1 ; max. "allowed" air pressure in mbar movff last_surfpressure+0,sub_b+0 movff last_surfpressure+1,sub_b+1 - call subU16 ; sub_c = sub_a - sub_b - btfss neg_flag ; Is 1080mbar < amb_pressure ? - bra start_copy_pressure ; NO: current airpressure is lower then "allowed" airpressure, ok! + call subU16 ; sub_c = sub_a - sub_b + btfss neg_flag ; Is 1080mbar < amb_pressure ? + bra start_copy_pressure ; NO: current air pressure is lower then "allowed" air pressure, ok! - ; not ok! Overwrite with max. "allowed" airpressure - movlw LOW max_surfpressure - movff WREG,last_surfpressure+0 ; max. "allowed" airpressure in mbar - movlw HIGH max_surfpressure - movff WREG,last_surfpressure+1 ; max. "allowed" airpressure in mbar + ; not ok! Overwrite with max. "allowed" air pressure + movlw LOW max_surfpressure + movff WREG,last_surfpressure+0 ; max. "allowed" air pressure in mbar + movlw HIGH max_surfpressure + movff WREG,last_surfpressure+1 ; max. "allowed" air pressure in mbar start_copy_pressure: movff last_surfpressure+0,last_surfpressure_15min+0 movff last_surfpressure+1,last_surfpressure_15min+1 movff last_surfpressure+0,last_surfpressure_30min+0 - movff last_surfpressure+1,last_surfpressure_30min+1 ; resets all airpressure registers - -; reset deco data for surface mode - movlw .21 ; 21% - movff WREG,char_I_O2_ratio ; ... oxygen - movlw .0 ; 0% - movff WREG,char_I_He_ratio ; ... helium + movff last_surfpressure+1,last_surfpressure_30min+1 ; resets all air pressure registers ; initialize GF high (needed by deco engine for color-coding the GF value) movff opt_GF_high,char_I_GF_High_percentage - SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; breathing at surface - movff int_I_pres_respiration+0,int_I_pres_surface+0 ; surface pressue - movff int_I_pres_respiration+1,int_I_pres_surface+1 + SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; breathing at surface + movff int_I_pres_respiration+0,int_I_pres_surface+0 ; surface pressure + movff int_I_pres_respiration+1,int_I_pres_surface+1 - extern deco_setup - call deco_setup ; set up all model parameters. - call deco_clear_tissue ; Set all tissues to Pamb * N2_ratio (C-Code) - banksel common ; back to bank 1, needed after every return from C code + call deco_setup ; set up all model parameters (code located in simulator.asm) + + call deco_clear_tissue ; Set all tissues to Pamb * N2_ratio (code located in p2_deco.c) + banksel common ; back to bank 1, needed after every return from C code call rtc_init ; init clock - movlw HIGH .512 ; =2 - movwf EEADRH - read_int_eeprom .0 - clrf EEADRH - movlw 0xAA - cpfseq EEDATA ; =0xAA - bra no_deco_restore ; No + movlw HIGH .512 ; =2 + movwf EEADRH + read_int_eeprom .0 + clrf EEADRH + movlw 0xAA + cpfseq EEDATA ; =0xAA + bra no_deco_restore ; No + call restore_decodata_from_eeprom ; Reload deco data and date/time from eeprom +no_deco_restore: + call deco_calc_dive_interval_1min ; calculate deco in surface mode + call deco_calc_desaturation_time ; calculate desaturation and no-fly time + banksel common - extern restore_decodata_from_eeprom - call restore_decodata_from_eeprom ; Reload deco data and date/time from eeprom - -no_deco_restore: - call deco_calc_wo_deco_step_1_min ; calculate deco in surface mode - call deco_calc_desaturation_time ; calculate desaturation and no-fly time - banksel common - bcf menubit ; clear menu flag -; Check for Power-on reset here - extern use_old_prior_209 - ; ***************************************************************************** + ; Check for Power-on reset here + + ; ***************************************************************************** ; "new_battery_menu" and "use_old_batteries" 'goto' back to "power_on_return" - ; ***************************************************************************** + ; ***************************************************************************** - ; Try to migrate the old battery status from firmware 2.09 or earlier.. - btfsc RCON,POR ; Was this a power-on reset? - call use_old_prior_209 ; No + ; Try to migrate the old battery status from firmware 2.09 or earlier.. + btfsc RCON,POR ; Was this a power-on reset? + call use_old_prior_209 ; No - bcf use_old_batt_flag - btfsc RCON,POR ; Was this a power-on reset? - bsf use_old_batt_flag ; No - - call lt2942_get_status ; Check for gauge IC - btfss battery_gauge_available ; cR or 2 hardware? - bra power_on_return2 ; no + bcf use_old_batt_flag + btfsc RCON,POR ; Was this a power-on reset? + bsf use_old_batt_flag ; No + + call lt2942_get_status ; Check for gauge IC + btfss battery_gauge_available ; cR or 2 hardware? + bra power_on_return2 ; no - movlw .30 - movff WREG,opt_cR_button_right - movff WREG,opt_cR_button_left ; Reset on power-on reset - call piezo_config ; Yes, configure buttons - call piezo_config ; Yes, configure buttons (2 times) + movlw .30 + movff WREG,opt_cR_button_right + movff WREG,opt_cR_button_left ; Reset on power-on reset + call piezo_config ; Yes, configure buttons + call piezo_config ; Yes, configure buttons (2 times) power_on_return2: ; check firmware and reset Custom Functions after an update movlw d'1' - movwf EEADR ; =1 - movwf EEADRH ; =1 - call read_eeprom ; read current version x - movff EEDATA,temp1 - incf EEADR,F ; set to 0x102 - call read_eeprom ; read current version y - movff EEDATA,temp2 - clrf EEADRH ; Reset EEADRH + movwf EEADR ; =1 + movwf EEADRH ; =1 + call read_eeprom ; read current version x + movff EEDATA,lo + incf EEADR,F ; set to 0x102 + call read_eeprom ; read current version y + movff EEDATA,hi + clrf EEADRH ; Reset EEADRH movlw softwareversion_x - cpfseq temp1 ; compare version x - bra check_firmware_new ; is not equal -> reset CF and store new version in EEPROM + cpfseq lo ; compare version x + bra check_firmware_new ; is not equal -> reset CF and store new version in EEPROM movlw softwareversion_y - cpfseq temp2 ; compare version y - bra check_firmware_new ; is not equal -> reset CF and store new version in EEPROM - bra restart ; x and y are equal -> do not reset cf - + cpfseq hi ; compare version y + bra check_firmware_new ; is not equal -> reset CF and store new version in EEPROM + bra restart ; x and y are equal -> do not reset cf + check_firmware_new: - call TFT_boot ; Initialize TFT (includes clear screen) - clrf CCPR1L ; Backlight off - WIN_TOP .50 - WIN_LEFT .10 - movlw LOW 0x1E000 - movwf TBLPTRL - movlw HIGH 0x1E000 - movwf TBLPTRH - movlw UPPER 0x1E000 - movwf TBLPTRU - extern color_image - call color_image ; Show logo + call TFT_boot ; Initialize TFT (includes clear screen) + clrf CCPR1L ; Backlight off + WIN_TOP .50 + WIN_LEFT .10 + movlw LOW 0x1E000 + movwf TBLPTRL + movlw HIGH 0x1E000 + movwf TBLPTRH + movlw UPPER 0x1E000 + movwf TBLPTRU + call color_image ; Show logo call TFT_standard_color - WIN_SMALL .10,.100 - STRCPY_PRINT "Update successful!" ; Hard coded since language switch does not work here - WIN_SMALL .10,.140 - STRCPY "New Firmware: " + WIN_SMALL .10,.100 + STRCPY_PRINT "Update successful!" ; Hard coded since language switch does not work here + WIN_SMALL .10,.140 + STRCPY "New Firmware: " movlw softwareversion_x movwf lo bsf leftbind @@ -231,30 +235,29 @@ movwf lo output_99x bcf leftbind - STRCAT_PRINT "" ; Print second row - call TFT_Display_FadeIn ; Display resulting surface screen. + STRCAT_PRINT "" ; Print second row + call TFT_Display_FadeIn ; Display resulting surface screen. -; place "after-update reset" here... - extern oPressureAdjust, option_reset, option_save - lfsr FSR0,oPressureAdjust - call option_reset ; Reset FSR0 option to factory default. - lfsr FSR0,oPressureAdjust - call option_save ; Save in EEPROM + ; place "after-update reset" here... + lfsr FSR0,oPressureAdjust + call option_reset ; Reset FSR0 option to factory default. + lfsr FSR0,oPressureAdjust + call option_save ; Save in EEPROM + + rcall backup_flash_page ; backup the first 128 bytes from flash to EEPROM - rcall backup_flash_page ; backup the first 128bytes from flash to EEPROM - - movlw d'1' ; store current version in EEPROM - movwf EEADR ; =1 - movwf EEADRH ; =1 + movlw d'1' ; store current version in EEPROM + movwf EEADR ; =1 + movwf EEADRH ; =1 movlw softwareversion_x - movwf EEDATA - call write_eeprom ; write version x - incf EEADR,F ; set to 0x102 + movwf EEDATA + call write_eeprom ; write version x + incf EEADR,F ; set to 0x102 movlw softwareversion_y - movwf EEDATA - call write_eeprom ; write version y - clrf EEADRH ; Reset EEADRH + movwf EEDATA + call write_eeprom ; write version y + clrf EEADRH ; Reset EEADRH movlw .7 movwf lo @@ -263,194 +266,197 @@ bcf onesecupdate btfss onesecupdate bra $-2 - decfsz lo,F ; Wait 10 seconds... + decfsz lo,F ; Wait 10 seconds... bra check_firmware_new2 - global restart + global restart restart: - clrf STKPTR ; Never return from here - clrf CCP1CON ; stop PWM - bcf PORTC,2 ; Pull PWM out to GND + clrf STKPTR ; Never return from here + clrf CCP1CON ; stop PWM + bcf PORTC,2 ; Pull PWM out to GND - extern option_save_all, option_check_all + btfsc menubit ; Return from Menu/COMM mode or timeout? + call option_save_all ; Yes, save all settings into EEPROM - btfsc menubit ; Return from Menu/COMM mode or timeout? - call option_save_all ; Yes, save all settings into EEPROM - - call option_restore_all ; Restore everything from EEPROM into RAM - call option_check_all ; Check all options (and reset if not within their min/max boundaries) - call option_save_all ; Save all settings into EEPROM after they have been checked + call option_restore_all ; Restore everything from EEPROM into RAM + call option_check_all ; Check all options (and reset if not within their min/max boundaries) + call option_save_all ; Save all settings into EEPROM after they have been checked - clrf flag1 ; clear all flags - clrf flag2 - clrf flag3 - clrf flag4 - clrf flag5 - clrf flag6 - clrf flag7 - clrf flag8 - clrf flag9 - clrf flag10 - ; Do not clear flag11 (Sensor calibration and charger status) - clrf flag12 - ; Do not clear flag13 (Important hardware flags) - clrf flag14 - clrf hardware_flag ; hardware descriptor flag - bsf tft_is_dimming ; TFT is dimming up (soon), ignore ambient sensor! + clrf flag1 ; clear all flags + clrf flag2 + clrf flag3 + clrf flag4 + clrf flag5 + clrf flag6 + clrf flag7 + clrf flag8 + clrf flag9 + clrf flag10 + ; Do not clear flag11 (Sensor calibration and charger status) + clrf flag12 + ; Do not clear flag13 (Important hardware flags) + clrf flag14 + clrf hardware_flag ; hardware descriptor flag - ; configure hardware_flag byte + bsf tft_is_dimming ; TFT is dimming up (soon), ignore ambient sensor! - bsf ambient_sensor ; Set flag - bsf optical_input ; Set flag + ; configure hardware_flag byte + bsf ambient_sensor ; Set flag + bsf optical_input ; Set flag + + call lt2942_get_status ; Check for gauge IC + btfss battery_gauge_available ; cR/2 hardware? + bra restart2 ; No - call lt2942_get_status ; Check for gauge IC - btfss battery_gauge_available ; cR/2 hardware? - bra restart2 ; No + call lt2942_init ; Yes, init battery gauge IC + bcf optical_input ; Clear flag - call lt2942_init ; Yes, init battery gauge IC - bcf optical_input ; Clear flag - - banksel 0xF16 - bcf ANCON0,7 ; AN7 Digital input - banksel common - bcf lightsen_power ; Power-down ambient light sensor - bcf ambient_sensor ; Clear flag - nop - btfss PORTF,2 ; Light sensor available? - bsf ambient_sensor ; Yes. - banksel 0xF16 - bsf ANCON0,7 ; AN7 Analog again - banksel common - bsf lightsen_power ; Power-up ambient light sensor again - + banksel 0xF16 + bcf ANCON0,7 ; AN7 Digital input + banksel common + bcf lightsen_power ; Power-down ambient light sensor + bcf ambient_sensor ; Clear flag + nop + btfss PORTF,2 ; Light sensor available? + bsf ambient_sensor ; Yes. + banksel 0xF16 + bsf ANCON0,7 ; AN7 Analog again + banksel common + bsf lightsen_power ; Power-up ambient light sensor again + restart2: - btfsc vusb_in - bra restart3 ; USB (and powered on) - bcf PORTE,0 ; Start comms - WAITMS d'1' - btfss vusb_in - bra restart3 ; USB (and powered off) - bsf ble_available ; ble available -restart3: - bsf PORTE,0 ; Stop comms - btfsc ble_available ; ble available? - bra restart4 ; Yes, can't be a cR - btfss battery_gauge_available ; Rechargeable - bra restart4 ; No, can't be a cR - bsf analog_o2_input ; Set flag for analog + btfsc vusb_in + bra restart3 ; USB (and powered on) + bcf PORTE,0 ; Start comms + WAITMS d'1' + btfss vusb_in + bra restart3 ; USB (and powered off) + bsf ble_available ; ble available + +restart3: + bsf PORTE,0 ; Stop comms + btfsc ble_available ; ble available? + bra restart4 ; Yes, can't be a cR + btfss battery_gauge_available ; Rechargeable + bra restart4 ; No, can't be a cR + bsf analog_o2_input ; Set flag for analog + + ; The hardware_flag is now: + ; 0x11: 2 with BLE + ; 0x13: 2 with BLE & ambient + ; 0x05: cR + ; 0x0A: 3 + ; 0x1A: 3 with BLE + restart4: - ; The hardware_flag is now: - ; 3: 0x0A - ; cR: 0x05 - ; 2 with BLE: 0x11 - ; 3 with BLE: 0x1A - ; 2 with ambient: 0x13 - ; Select high altitude (Fly) mode? movff last_surfpressure_30min+0,sub_b+0 movff last_surfpressure_30min+1,sub_b+1 - movlw HIGH high_altitude_threshold + movlw HIGH high_altitude_threshold movwf sub_a+1 - movlw LOW high_altitude_threshold ; Hard-wired 880mbar + movlw LOW high_altitude_threshold ; hard-wired 880mbar movwf sub_a+0 - call subU16 ; sub_c = sub_a - sub_b - btfss neg_flag ; Result negative (Ambient>880mbar)? - bsf high_altitude_mode ; No, Set Flag! - - btfss analog_o2_input - bsf TRISB,3 - btfss battery_gauge_available - bsf TRISG,0 - call ext_flash_disable_protection ; Disable write protection for external flash + call subU16 ; sub_c = sub_a - sub_b + btfss neg_flag ; result negative (ambient > 880mbar)? + bsf high_altitude_mode ; NO - set flag! - bsf flip_screen ; Flip 180° - TSTOSS opt_flip_screen ; =1: Flip the screen - bcf flip_screen ; Normal orientation - - btfsc use_old_batt_flag ; =1: load old battery information after power-on reset - goto use_old_batteries ; Returns to "surfloop"! + btfss analog_o2_input + bsf TRISB,3 + btfss battery_gauge_available + bsf TRISG,0 + call ext_flash_disable_protection ; disable write protection for external flash - btfsc RCON,POR ; Was this a power-on reset? - goto surfloop ; Jump to Surfaceloop! - bsf RCON,POR ; Set bit for next detection - ; Things to do after a power-on reset - extern new_battery_menu,use_old_batteries - goto new_battery_menu ; Returns to "surfloop"! + bsf flip_screen ; flip 180° + TSTOSS opt_flip_screen ; =1: Flip the screen + bcf flip_screen ; normal orientation + + btfsc use_old_batt_flag ; =1: load old battery information after power-on reset + goto use_old_batteries ; returns to "surfloop"! + + btfsc RCON,POR ; was this a power-on reset? + goto surfloop ; jump to surface loop! + bsf RCON,POR ; set bit for next detection + ; Things to do after a power-on reset + goto do_new_battery_select ; returns to "surfloop"! ;============================================================================= ; Setup all flags and parameters for divemode and simulator computations. ; global restart_set_modes_and_flags -restart_set_modes_and_flags: ; "Call"ed from divemode, as well! - call option_restore_all ; Restore everything from EEPROM +restart_set_modes_and_flags: ; "Call"ed from divemode, as well! + call option_restore_all ; Restore everything from EEPROM - ; Setup sampling rate - movlw .2 - movwf samplingrate - TSTOSS opt_sampling_rate ; =1: 10s, =0: 2s - bra restart_set_modes_and_flags1 - movlw .10 - movwf samplingrate + ; Setup sampling rate + movlw .2 + movwf samplingrate + TSTOSS opt_sampling_rate ; =1: 10s, =0: 2s + bra restart_set_modes_and_flags1 + movlw .10 + movwf samplingrate + restart_set_modes_and_flags1: - bcf twosecupdate ; to have divemode routines in sync - - bcf FLAG_apnoe_mode - bcf FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active - bcf FLAG_gauge_mode ; =1: In Gauge mode - bcf FLAG_pscr_mode - call disable_ir_s8 ; IR off + bcf twosecupdate ; to have divemode routines in sync + bcf FLAG_apnoe_mode + bcf FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active + bcf FLAG_gauge_mode ; =1: In Gauge mode + bcf FLAG_pscr_mode + call disable_ir_s8 ; IR off - ; Setup char_I_saturation_multiplier and char_I_desaturation_multiplier - movff opt_sat_multiplier_gf,char_I_saturation_multiplier - movff opt_desat_multiplier_gf,char_I_desaturation_multiplier - movff char_I_deco_model,lo ; 0 = ZH-L16, 1 = ZH-L16-GF - tstfsz lo - bra restart_set_modes_and_flags1b - movff opt_sat_multiplier_non_gf,char_I_saturation_multiplier - movff opt_desat_multiplier_non_gf,char_I_desaturation_multiplier - -restart_set_modes_and_flags1b: - movff opt_dive_mode,lo ; 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=PSCR - tstfsz lo - bra restart_set_modes_and_flags2 - ; OC Mode - - return + ; Setup char_I_saturation_multiplier and char_I_desaturation_multiplier + movff opt_sat_multiplier_gf,char_I_saturation_multiplier + movff opt_desat_multiplier_gf,char_I_desaturation_multiplier + movff char_I_deco_model,lo ; 0 = ZH-L16, 1 = ZH-L16-GF + tstfsz lo + bra restart_set_modes_and_flags1b + movff opt_sat_multiplier_non_gf,char_I_saturation_multiplier + movff opt_desat_multiplier_non_gf,char_I_desaturation_multiplier + +restart_set_modes_and_flags1b: + movff opt_dive_mode,lo ; 0=OC, 1=CC, 2=Gauge, 3=Apnea, 4=PSCR + tstfsz lo + bra restart_set_modes_and_flags2 + + ; OC Mode + return restart_set_modes_and_flags2: - decfsz lo,F - bra restart_set_modes_and_flags3 - ; CC Mode - btfsc analog_o2_input ; cR? - bra restart_set_modes_and_flags2b ; Yes, skip mode check - btfsc optical_input ; 3 - bra restart_set_modes_and_flags2b ; Yes, skip mode check - ; Make sure Sensor is not selected - ; opt_ccr_mode must be <> 1 (=0: Fixed SP, =1: Sensor, =2: Auto SP) - banksel opt_ccr_mode - movlw .1 - cpfseq opt_ccr_mode ; = Sensor? - bra restart_set_modes_and_flags2b ; No - clrf opt_ccr_mode ; Yes, reset to Fixed SP + decfsz lo,F + bra restart_set_modes_and_flags3 + + ; CC Mode + btfsc analog_o2_input ; cR? + bra restart_set_modes_and_flags2b ; Yes, skip mode check + btfsc optical_input ; 3 + bra restart_set_modes_and_flags2b ; Yes, skip mode check + + ; Make sure Sensor is not selected + ; opt_ccr_mode must be <> 1 (=0: Fixed SP, =1: Sensor, =2: Auto SP (CCR only)) + banksel opt_ccr_mode + movlw .1 + cpfseq opt_ccr_mode ; = Sensor? + bra restart_set_modes_and_flags2b ; No + clrf opt_ccr_mode ; Yes, reset to Fixed SP + restart_set_modes_and_flags2b: - banksel common - bsf FLAG_ccr_mode ; =1: CCR mode (Fixed SP, Auto SP or Sensor) active - call enable_ir_s8 ; Enable IR/S8-Port - return + banksel common + bsf FLAG_ccr_mode ; =1: CCR mode (Fixed SP, Auto SP or Sensor) active + call enable_ir_s8 ; Enable IR/S8-Port + return restart_set_modes_and_flags3: - decfsz lo,F - bra restart_set_modes_and_flags4 - ; Gauge Mode - bsf FLAG_gauge_mode ; =1: In Gauge mode - return + decfsz lo,F + bra restart_set_modes_and_flags4 + + ; Gauge Mode + bsf FLAG_gauge_mode ; =1: In Gauge mode + return restart_set_modes_and_flags4: - decfsz lo,F - bra restart_set_modes_and_flags5 - ; Apnea Mode - bsf FLAG_apnoe_mode - return ; start in Surfacemode + decfsz lo,F + bra restart_set_modes_and_flags5 + ; Apnea Mode + bsf FLAG_apnoe_mode + return ; start in Surfacemode restart_set_modes_and_flags5: ; PSCR Mode @@ -474,29 +480,30 @@ bsf FLAG_pscr_mode return ; start in Surfacemode - -backup_flash_page: ; backup the first 128bytes from flash to EEPROM - ; Start address in internal flash - movlw 0x00 - movwf TBLPTRL - movwf TBLPTRH - movwf TBLPTRU + +; backup the first 128bytes from flash to EEPROM +backup_flash_page: + ; Start address in internal flash + movlw 0x00 + movwf TBLPTRL + movwf TBLPTRH + movwf TBLPTRU - movlw .128 - movwf lo ; Byte counter - clrf EEADR - movlw .3 - movwf EEADRH ; Setup backup address + movlw .128 + movwf lo ; Byte counter + clrf EEADR + movlw .3 + movwf EEADRH ; Setup backup address - TBLRD*- ; Dummy read to be in 128 byte block + TBLRD*- ; Dummy read to be in 128 byte block backup_flash_loop: - tblrd+* ; Table Read with Pre-Increment - movff TABLAT,EEDATA ; put 1 byte - call write_eeprom ; save it in EEPROM - incf EEADR,F - decfsz lo,F ; 128byte done? - bra backup_flash_loop ; No - clrf EEADRH ; Reset EEADRH - return ; Done. + tblrd+* ; Table Read with Pre-Increment + movff TABLAT,EEDATA ; put 1 byte + call write_eeprom ; save it in EEPROM + incf EEADR,F + decfsz lo,F ; 128byte done? + bra backup_flash_loop ; No + clrf EEADRH ; Reset EEADRH + return ; Done. END \ No newline at end of file