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

📄 spl78k0_kx2.asm

📁 NEC upd78f0300的自编程序样例
💻 ASM
📖 第 1 页 / 共 3 页
字号:
;=============================================================================
; FILE      = spl78k0_kx2.asm
; PROJECT   = selfprogramming application note, MF2 single voltage flash
; DEVICE    = 78k0/Kx2
; VERSION   = 1v06
; DATE      = 12.09.2006 09:29   (c)2004-2006 by NEC Electronics (Europe) GmbH
;=============================================================================
; Purpose:      implementation of the low-level access flash memory access
;=============================================================================
; Enviroment:   IAR for 78K0 and 78K0S (version V3.xx and V4.xx)
;=============================================================================

 NAME           spl78k0_kx2             ; module name

                                        ;======================================
                                        ; INCLUDE LIST
                                        ;======================================
#include  "spl78k0_kx2_config.h"        ; NEC-EE
#include  "spl78k0_kx2_const.h"         ; NEC-EE

                                        ;======================================
                                        ; EXPORT LIST
                                        ;======================================
                                        ; Constants:
 PUBLIC   SPL_INFO                      ;  PUBLIC for device and version control
                                        ; Variables:
 PUBLIC   entry_ram                     ;  PUBLIC for EEPROM emulation purpose only
                                        ; Flags:
                                        ; Labels:
 PUBLIC   SelfLib_Init                  ; u08 SelfLib_Init(u08* data_buffer_pu08);
 PUBLIC   SelfLib_ModeCheck             ; u08 SelfLib_ModeCheck(void);
 PUBLIC   SelfLib_BlankCheck            ; u08 SelfLib_BlankCheck(u08 block_u08);
 PUBLIC   SelfLib_Erase                 ; u08 SelfLib_Erase(u08 block_u08);
 PUBLIC   SelfLib_Verify                ; u08 SelfLib_Verify(u08 block_u08);
 PUBLIC   SelfLib_Write                 ; u08 SelfLib_Write(u32 s_address_u32, u08 wordcount_u08);
 PUBLIC   SelfLib_EepWrite              ; u08 SelfLib_EepWrite(u32 s_address_u32, u08 wordcount_u08);
 PUBLIC   ASM_execute                   ; PUBLIC for EEPROM emulation purpose only
                                        ;======================================


                                        ;======================================
                                        ; IMPORT LIST
                                        ;======================================
                                        ; Constants:
                                        ; Variables:
                                        ; Flags:
                                        ; Labels:


; temporary abbreviation for conditional assembly
#define   GI_S    (GetInfo_Security==spl78k0_function_included)
#define   GI_BC   (GetInfo_BootCluster==spl78k0_function_included)
#define   GI_BEA  (GetInfo_BlockEndAddr==spl78k0_function_included)
#define   SI_SBC  (SetInfo_SwapBootCluster==spl78k0_function_included)
#define   SI_CEP  (SetInfo_ChipEraseProtection==spl78k0_function_included)
#define   SI_BEP  (SetInfo_BlockEraseProtection==spl78k0_function_included)
#define   SI_WP   (SetInfo_WriteProtection==spl78k0_function_included)
#define   SI_BCP  (SetInfo_BootClusterProtection==spl78k0_function_included)



;=============================================================================
; Segment name:  DS_ERAM
; Segment type:  self-lib data-segment
; Address area:  location corresponds with XCL-File
;=============================================================================
; The Enrty-RAM can be located in high-speed RAM as well as in short-address RAM.
; When located in saddr area the real-time behavior of selfprogramming improves.
;=============================================================================
 RSEG           DS_ERAM (1)
;=============================================================================
entry_ram      DS       ENTRY_RAM_SIZE



;=============================================================================
; Segment name:  BCLUST0
; Segment type:  self-lib code segment inside the boot-claster 0 (block 0..3)
; Address area:  internal ROM area 0082H-0FFFH
;=============================================================================
; The code of the selfprogramming library have to be located in the active
; boot-cluster area 0x0000...0x0FFF. Before swapping the boot-cluster the
; application should take care for valid boot-loader inside the activated .
;=============================================================================
 RSEG          BCLUST0 (1)
;=============================================================================


;-----------------------------------------------------------------------------
; Block type:   selflib command function
; C prototype:  void SelfLib_Init(u08* data_buffer_pu08);
; C example:    SelfLib_Init((u08*)&my_data_buffer[0]);
;-----------------------------------------------------------------------------
; Purpose:      initialization of internal selfprogramming environment.
;               After initialization the pointer to the data-buffer is stored
;               in the EntryRAM and the block-erase retry-counter is downsized
;               from 255 (firmware default value) to ERASE_RETRY_COUNTER
;               defined in spl78k0_kx2_const.h. If other value required, the
;               user can reconfigure this constant.
; Input:        AX, data_buffer_pu08 - pointer to a data buffer N...256 bytes
;               (used for data exchange between firmware and application)
; Output:       -
; Return:       -
;-----------------------------------------------------------------------------
SelfLib_Init:
    PUSH    HL                                      ; save used register
    PUSH    AX                                      ; keep data_buffer_pu08 "in mind"
    MOV     A,#CMD_INIT                             ; select the command
    CALL    ASM_execute                             ; execute the command
    MOVW    HL,AX                                   ; keep FW status "in mind"
    POP     AX                                      ; get data_buffer_pu08
    MOVW    (entry_ram+IDX_DATA_BUF_H),AX           ; set address of data_buffer
    MOV     A,#ERASE_RETRY_COUNTER                  ;
    MOV     (entry_ram+IDX_ERASE_RETRY_COUNTER),A   ; reduce the erase retry counter 255->N
    MOVW    AX,HL                                   ; restore FW status
    POP     HL                                      ; restore used register
    RET                                             ;



;-----------------------------------------------------------------------------
; Block type:   selflib command function
; C prototype:  u08 SelfLib_ModeCheck(void);
; C example:    my_status_u08 = SelfLib_ModeCheck();
;-----------------------------------------------------------------------------
; Purpose:      checks the voltage level at FLMD0 pin.
; Input:        -
; Output:       -
; Returned:     A, status code
;                  = 0x00(STS_NO_ERROR), normal and means FLMD0=HIGH
;                  = 0x01(STS_ERROR), error, FLMD0=LOW
;-----------------------------------------------------------------------------
SelfLib_ModeCheck:
    MOV     A,#CMD_CHECK_FLMD                 ; select the command
    CALL    ASM_execute                       ; execute the command
    RET                                       ; and return the status to the caller



;-----------------------------------------------------------------------------
; Block type:   selflib command function
; C prototype:  u08 SelfLib_BlankCheck(u08 block_u08);
; C example:    my_status_u08 = SelfLib_BlankCheck(my_block_u08);
;-----------------------------------------------------------------------------
; Purpose:      checks if specified block is blank
; Input:        A, block_u08 - block number has to be checked
; Output:       -
; Returned:     A, status code
;                  = 0x00(STS_NO_ERROR), normal and means "block is blank"
;                  = 0x05(STS_PARAMETER_ERROR), parameter error (wrong block nr)
;                  = 0x1B(STS_MRG11_ERROR), blank-check error means "block not blank"
;                  = 0x1F(STS_INTERRUPTED), blank-check interrupted by user interrupt
;-----------------------------------------------------------------------------
SelfLib_BlankCheck:
    MOV     (entry_ram+IDX_BLOCK_NO),A        ; entry_ram[IDX_BLOCK_NO] <- my_block_u08
    MOV     A,#CMD_BLANKCHECK_BLOCK           ; RB(user).A <- command code
    CALL    ASM_execute                       ; execute the command
    RET                                       ;



;-----------------------------------------------------------------------------
; Block type:   selflib command function
; C prototype:  u08 SelfLib_Erase(u08 block_u08);
; C example:    my_status_u08 = SelfLib_Erase(my_block_u08);
;-----------------------------------------------------------------------------
; Purpose:      erase specified block
; Input:        A, block_u08 - block number has to be erase
; Output:       -
; Returned:     A, status_code
;                  = 0x00(STS_NO_ERROR), normal and means "block erased successfully"
;                  = 0x05(STS_PARAMETER_ERROR), parameter error
;                  = 0x10(STS_PROTECTION_ERROR), tried to erase protected boot-cluster
;                  = 0x1A(STS_MRG10_ERROR), erase error, retry up to max. 255 times
;                  = 0x1F(STS_INTERRUPTED), erasing interrupted by user interrupt
;-----------------------------------------------------------------------------
SelfLib_Erase:
    MOV     (entry_ram+IDX_BLOCK_NO),A        ; entry_ram[IDX_BLOCK_NO] <- my_block_u08
    MOV     A,#CMD_ERASE_BLOCK                ; RB(user).A <- command code
    CALL    ASM_execute                       ; execute the command
    RET                                       ;



;-----------------------------------------------------------------------------
; Block type:   selflib command function
; C prototype:  u08 SelfLib_Verify(u08 block_u08);
; C example:    my_status_u08 = SelfLib_Verify(my_block_u08);
;-----------------------------------------------------------------------------
; Purpose:      performs internal verify of specified block
; Input:        A, block_u08 - block number has to be verified
; Output:       -
; Returned:     A, status_code
;                  = 0x00(STS_NO_ERROR), normal and means "block is verified"
;                  = 0x05(STS_PARAMETER_ERROR), parameter error
;                  = 0x1B(STS_MRG11_ERROR), internal verify error
;                  = 0x1F(STS_INTERRUPTED), verify interrupted by user interrupt
;-----------------------------------------------------------------------------
SelfLib_Verify:
    MOV     (entry_ram+IDX_BLOCK_NO),A        ; entry_ram[IDX_BLOCK_NO] <- my_block_u08
    MOV     A,#CMD_VERIFY_BLOCK               ; RB(user).A <- command code
    CALL    ASM_execute                       ; execute the command
    RET                                       ;


⌨️ 快捷键说明

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