⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bootload.a51

📁 at89c51cc03RS232引导程序
💻 A51
📖 第 1 页 / 共 2 页
字号:
hex_write_function_error:
    ajmp    wait_hex_line


;*F***************************************************************************
; NAME:     hex_display_function        Type= 04h
;-----------------------------------------------------------------------------
; PARAMS:   hex_buffer[1:0]: start address
;           hex_buffer[3:2]: end address
;           hex_buffer[4]:   00h: display data sub-function
;                            01h: blank check sub-function
;                            02h: display eeprom sub-function
;
; RETURN:
;
;-----------------------------------------------------------------------------
; PURPOSE:  display data eeprom or blank check
;
;*****************************************************************************
hex_display_function:
    mov     A,hex_buffer+4                  ; get function parameter
    cjne    A,#01,hex_display
    
hex_blanck_check:
    mov     DPH,hex_buffer                  ; MSB of start address
    mov     DPL,hex_buffer+1                ; LSB of start address
    mov     FCON,#SEL_USER_MOVC             ; map USER in code space

hex_blanck_check_loop:
    mov     A,#00h
    movc    A,@A+DPTR
    cjne    A,#0FFh,hex_blank_check_ko
    mov     A,DPH
    cjne    A,hex_buffer+2,hex_blanck_check_next
    mov     A,DPL
    cjne    A,hex_buffer+3,hex_blanck_check_next

hex_blank_check_end:
    mov     FCON,#DESELECT_CL               ; reset FCON
    acall   send_point
    ajmp    wait_hex_line

hex_blanck_check_next:
    inc     DPTR                            ; check next address
    ajmp    hex_blanck_check_loop

hex_blank_check_ko:
    mov     R7,DPH
    acall   send_data_byte                  ; send MSB address
    mov     R7,DPL
    acall   send_data_byte                  ; send LSB address 
    acall   send_cr_lf
hex_display_function_error:
    ajmp    wait_hex_line

hex_display:
$if EEPROM_ON_CHIP
    cjne    A,#02,hex_display_flash_init

hex_display_eeprom_init: 
    mov     R1,#01h
    clr     A
    ajmp    hex_display_data
$endif ;EEPROM_ON_CHIP
hex_display_flash_init:
    mov     R1, #00h

hex_display_data:
    jnz     hex_display_function_error   
    mov     A,security_state
    cjne    A,#SEC_LEVEL_2,hex_display_data_ok

hex_security_locked:
    mov     A,#'L'
    acall   send_char
    acall   send_cr_lf
    ajmp    wait_hex_line

hex_display_data_ok:
    mov     DPH,hex_buffer                    ; MSB of start address
    mov     DPL,hex_buffer+1                  ; LSB of start address
    mov     A,R1                              ; Decode the memory area to display
    jz      hex_display_flash                 ; Target=FM0
    cjne    R1, #01, hex_display_common_init  ; Target=Custom       
    mov     EECON,#SEL_EEPROM_CL              ; map EEPROM in xram space
hex_display_common_init:
    ajmp    hex_display_data_line

hex_display_flash:
    mov     FCON,#SEL_USER_MOVC             ; map USER in code space

hex_display_data_line:
    acall   send_cr_lf
    mov     R7,DPH   
    acall   send_data_byte                   ; send MSB of current address 
    mov     R7,DPL       
    acall   send_data_byte                   ; send LSB of current address
    mov     A,#'=' 
    acall   send_char
    mov     R0,#DISPLAY_SIZE                ; number of data to display per line

hex_display_data_loop:
    mov     A,R1
    jz      hex_display_flash_loop
    cjne    R1, #01, hex_display_custom_loop ; custom area display 
    mov     A,#00h
    movx    A,@DPTR
    ajmp    hex_display_loop  

hex_display_custom_loop:
$if CUSTOM_ON_CHIP
using 0
    push    DPH
    push    DPL
    push    AR7
    push    AR6
    push    AR5
    push    AR4
    push    AR3
    push    AR2
    push    AR1
    push    AR0
    mov     R6, DPH
    mov     R7, DPL
    mov     R3, #1              ; Get 1byte @R6,R7 adr
    mov     R5, #hex_buffer+5
    lcall   READ_MEM_ENTRY
    mov     R0, #hex_buffer+5
    mov     A, @R0
    pop     AR0
    pop     AR1
    pop     AR2
    pop     AR3
    pop     AR4
    pop     AR5
    pop     AR6
    pop     AR7
    pop     DPL
    pop     DPH
    ajmp    hex_display_loop  
$endif ;CUSTOM_ON_CHIP

hex_display_flash_loop:     
    mov     A,#00h
    movc    A,@A+DPTR

hex_display_loop:
    mov     R7,A
    acall   send_data_byte                   ; display 1 byte
    mov     A,DPH
    cjne    A,hex_buffer+2,hex_display_data_next
    mov     A,DPL
    cjne    A,hex_buffer+3,hex_display_data_next

hex_display_data_end:
    mov     A,R1
    jz      hex_display_flash_end
    mov     EECON,#DESE_EEPROM_CL
    ajmp    hex_display_end

hex_display_flash_end:
    mov     FCON,#DESELECT_CL               ; reset FCON

hex_display_end:
    acall   send_cr_lf
    ajmp    wait_hex_line

hex_display_data_next:
    inc     DPTR
    djnz    R0,hex_display_data_loop
    ajmp    hex_display_data_line


;*F***************************************************************************
; NAME:     hex_read_function           Type= 05h
;-----------------------------------------------------------------------------
; PARAMS:   hex_buffer[0]: 00h: read id
;                               hex_buffer[1]: 00h: manufacturer id
;                                              01h: id 1
;                                              02h: id 2
;                                              03h: id 3
;                          07h: read bytes
;                               hex_buffer[1]: 00h: read SSB
;                                              01h: read BSB
;                                              02h: read SBV
;                          0Bh: read hard byte (fuse + hard security bits)
;                          0Eh: read boot id
;                               hex_buffer[1]: 00h: id 1
;                                              01h: id 2
;                          0Fh: read boot loader version
;
; RETURN:
;
;-----------------------------------------------------------------------------
; PURPOSE:  read function
;
;*****************************************************************************
hex_read_function:
    mov     A,hex_buffer                        ; get function parameter
    mov     DPL,#00h

hex_read_id:
    cjne    A,#00h,hex_read_bytes
        mov     A,hex_buffer+1                  ; get read_id parameter
    hex_read_id_manufacturer:
        cjne    A,#00h,hex_read_id_1   
        mov     DPL,#MANUF_ID_ADDRESS
        ajmp    hex_read_fuction_xrow
    hex_read_id_1:
        cjne    A,#01h,hex_read_id_2   
        mov     DPL,#DEVICE_ID1_ADDRESS
        ajmp    hex_read_fuction_xrow
    hex_read_id_2:
        cjne    A,#02h,hex_read_id_3   
        mov     DPL,#DEVICE_ID2_ADDRESS
        ajmp    hex_read_fuction_xrow
    hex_read_id_3:
        cjne    A,#03h,hex_read_function_error   
        mov     DPL,#DEVICE_ID3_ADDRESS
        ajmp    hex_read_fuction_xrow

hex_read_bytes:
    cjne    A,#07h,hex_read_hardware_byte
        mov     A,hex_buffer+1                  ; get read_bytes parameter
    hex_read_bytes_ssb:
        cjne    A,#00h,hex_read_bytes_security
        mov     DPL,#SSB_ADDRESS
        ajmp    hex_read_fuction_xrow
    hex_read_bytes_security:
        mov     A,security_state                ; level 2 = read protected
        cjne    A,#SEC_LEVEL_2,hex_read_bytes_bsb_ok
        ajmp    hex_security_locked

    hex_read_bytes_bsb_ok:
        mov     A,hex_buffer+1                  ; reload sub-function parameter
        cjne    A,#01h,hex_read_bytes_sbv_ok    ; 01h -> read BSB
        mov     DPL,#BSB_ADDRESS
        ajmp    hex_read_fuction_xrow
    hex_read_bytes_sbv_ok:
        cjne    A,#02h,hex_read_bytes_eb_ok     ; 02h -> read SBV
        mov     DPL,#SBV_ADDRESS
        ajmp    hex_read_fuction_xrow
    hex_read_bytes_eb_ok:
        cjne    A,#06h,hex_read_function_error  ; 06h -> read SBV
        mov     DPL,#EB_ADDRESS
        ajmp    hex_read_fuction_xrow

hex_read_hardware_byte:
    cjne    A,#0Bh,hex_read_boot_ids
        mov     A,security_state                ; level 2 = read protected
        cjne    A,#SEC_LEVEL_2,hex_read_hardware_byte_ok
        ajmp    hex_security_locked

    hex_read_hardware_byte_ok:
        acall   fm_read_hardware_byte
        ajmp    hex_read_function_end

hex_read_boot_ids:
    cjne    A,#0Eh,hex_read_boot_version 
        mov     A,hex_buffer+1                  ; get read_boot_ids parameter
        jnz     hex_read_boot_id_2
    hex_read_boot_id_1:
        mov     A,#BOOT_ID1_VALUE
        ajmp    hex_read_function_end

    hex_read_boot_id_2:
        cjne    A,#01h,hex_read_function_error 
        mov     A,#BOOT_ID2_VALUE
        ajmp    hex_read_function_end


hex_read_boot_version:
    cjne    A,#0Fh,hex_read_function_error 
        mov     A,#BL_VERSION
        ajmp    hex_read_function_end

hex_read_fuction_xrow:
    acall   fm_read_xrow

hex_read_function_end:
    mov     R7,A
    acall   send_data_byte
    acall   send_point
hex_read_function_error:
    ajmp    wait_hex_line


;*F***************************************************************************
; NAME:     hex_program_custom        Type= 08h
;-----------------------------------------------------------------------------
; PARAMS:
;
; RETURN:
;
;-----------------------------------------------------------------------------
; PURPOSE:  program up to one page of custom area
;
;*****************************************************************************

$if CUSTOM_ON_CHIP
using 0
hex_program_custom:
    mov     A,security_state
    cjne    A,#SEC_LEVEL_0,hex_program_custom_security_ko
    sjmp    hex_program_custom_security_ok

hex_program_custom_security_ko:
    ljmp    hex_security_protected

hex_program_custom_security_ok:
    push    AR7
    push    AR6
    push    AR5
    push    AR4
    push    AR3
    push    AR2
    push    AR1
    push    AR0
    mov     R4,hex_address      ;destination pointer
    mov     R5,hex_address+1
    mov     R7,#hex_buffer       ; buffer adr
    mov     R3,hex_data_size    ; number of byte to write
    lcall   WRITE_MEM_ENTRY     ;custom write function
    pop     AR0
    pop     AR1
    pop     AR2
    pop     AR3
    pop     AR4
    pop     AR5
    pop     AR6
    pop     AR7
    jc      hex_program_custom_end
    ajmp    hex_program_data    ;User function does not know how to program -> Go to flash FM0
hex_program_custom_end:   
    acall   send_point
    ajmp    wait_hex_line
$endif ; CUSTOM_ON_CHIP



;*F***************************************************************************
; NAME:     erase_full_chip
;-----------------------------------------------------------------------------
; PARAMS:
;
; RETURN:
;
;-----------------------------------------------------------------------------
; PURPOSE:  - erase the USER memory
;           - erase the Boot Status Byte
;           - initialize the Software Boot Vector
;           - initialize the Sofware Security Byte to level 0
; 
;*****************************************************************************
erase_full_chip:

    mov     DPTR,#BLOCK0_BASE_ADDRESS
    mov     R2, #HIGH(FLASH_NB_PAGE)
    mov     R1, #LOW(FLASH_NB_PAGE)    
    cjne    R2, #02h, erase_loop_bloc_1_time ; erase in one time for flash less than 32kb

erase_loop_bloc:
    acall   erase_loop              ; erase USER
    mov     R1,#LOW(FLASH_NB_PAGE)    

erase_loop_bloc_1_time:
    acall   erase_loop              ; erase USER


    mov     DPH,#00h
    mov     FCON,#SEL_XROW_CL       ; map XROW column latch in XRAM space

    mov     DPL,#BSB_ADDRESS
    mov     A,#0FFh
    movx    @DPTR,A                 ; erase BSB

    mov     DPL,#SBV_ADDRESS
    mov     A,#BOOT_BASE_ADDRESS
    movx    @DPTR,A                 ; reset BSB

    mov     DPL,#SSB_ADDRESS
    mov     A,#SEC_LEVEL_0
    movx    @DPTR,A                 ; set SSB to level 0

    acall   fm_program_xrow         ; launch programming
    ret

    
erase_block_8k:
    mov     R1,#BLOCK_8K_NB_PAGE    ; number of page to erase
    ajmp    erase_loop

erase_block_16k:
    mov     R1,#BLOCK_16K_NB_PAGE   ; number of page to erase

erase_loop:
    mov     R0,#PAGE_SIZE           ; load column latch size
    mov     A,#0FFh                 ; init value
    mov     FCON,#SEL_USER_CL       ; map USER column latch in XRAM space

erase_fill_cl:
    movx    @DPTR,A                 ; write FFh in all CL positions
    inc     DPTR
    djnz    R0,erase_fill_cl        ; loop until column latch filled

    mov     FCON,#(FPL_S0 OR FMOD_USER_MSK)  ; launch USER programming
    mov     FCON,#(FPL_S1 OR FMOD_USER_MSK)
    nop   ; 1.1 Rev after first Si: Busy flag too slow!

erase_user_busy:
    mov     A,FCON
    jb      ACC.0,erase_user_busy
    djnz    R1,erase_loop
    ret



END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -