📄 spl78k0_kx2.asm
字号:
;-----------------------------------------------------------------------------
; Block type: selflib command function
; C prototype: u08 SelfLib_Write (u32 s_address_u32, u08 word_count_u08)
; u08 SelfLib_EepWrite(u32 s_address_u32, u08 word_count_u08)
;-----------------------------------------------------------------------------
; Purpose: writes N words to a specified flash address (multiple of 4)
; Parameter: see function prototype description in spl78k0_kx2.h
;-----------------------------------------------------------------------------
; Parameter passing:
; IAR 3.xx: s_address_u32 in AX/BC, word_count_u08 in Stack[SP+4]
; IAR 4.xx: s_address_u32 in AX/BC, word_count_u08 in D
;-----------------------------------------------------------------------------
SelfLib_Write: ; CAUTION !!!!
MOV B,#CMD_WRITE_WORD ; register B not PUSH'ed here
BR SelfLib_Wr_Common ; because real flash addr 24 bit.
; Consequently B=MSB(addr) remains unused
SelfLib_EepWrite:
MOV B,#CMD_EEP_WRITE_WORD ;
SelfLib_Wr_Common:
MOV (entry_ram+IDX_START_ADDR_M),A ; entry_ram[IDX_START_ADDR_M] <- middle byte
XCH A,X ;
MOV (entry_ram+IDX_START_ADDR_L),A ; entry_ram[IDX_START_ADDR_L] <- low byte
XCH A,C ;
MOV (entry_ram+IDX_START_ADDR_H),A ; entry_ram[IDX_START_ADDR_H] <- high byte
#if __VER__ >= 400
; IAR 4.xx: fetch "word_count_u08"
; from register D
MOV A,D ;
MOV (entry_ram+IDX_WORD_COUNT),A ; entry_ram[IDX_WORD_COUNT] <- word count
#else
; IAR 3.xx: fetch "word_count_u08"
;from the stack
PUSH HL ; save used register
MOVW AX,SP ;
XCHW AX,HL ;
MOV A,[HL+4] ; A <- word_count_u08
MOV (entry_ram+IDX_WORD_COUNT),A ; entry_ram[IDX_WORD_COUNT] <- word count
#endif
; entry-ram prepared ->> execute the command
MOV A,B ; RB(user).A <- command code
CALL ASM_execute ; execute the command
#if __VER__ >= 400
; IAR 4.xx: firmware status already in register A
RET ;
#else
; IAR 3.xx: reconstruct the stack and SP before RET
; shift the write RET-addr. iside the stack
; AX overwritten here, but it will be recovered directly from RB3 later
MOV A,[HL+2] ; 1v04, A <- PC(7...0)
MOV [HL+4],A ; 1v04, SP[6] <- SP[4]
MOV A,[HL+3] ; 1v04, A <- PC(15...8)
MOV [HL+5],A ; 1v04, SP[7] <- SP[5]
POP HL ; 1v04, restore used register
POP AX ; 1v04, stack-pointer correction (-2) (caused at caller side)
MOV A,0FEE3H ; 1v04, recover the status, RB(user).A <- status code (RB3.B)
RET ;
#endif
#if (GI_S)
PUBLIC SelfLib_GetInfo_Security
;-----------------------------------------------------------------------------
; Block type: selflib command function
; C prototype: u08 SelfLib_GetInfo_Security(u08 *destination_pu08)
; C example: my_status_u08 = SelfLib_GetInfo_Security(my_destination_pu08);
;-----------------------------------------------------------------------------
; Purpose: reads the security information (write-/erase-protection)
; Input: AX, destination_pu08 - destination address of the security info
; The format of the security info is: "unsigned char"
; Output: -
; Changed: X, content of the data_buffer
; Returned: A, status code
; = 0x00(STS_NO_ERROR), normal
; = 0x05(STS_PARAMETER_ERROR), parameter error
;-----------------------------------------------------------------------------
SelfLib_GetInfo_Security:
PUSH BC ; save used register
PUSH AX ; stack <- destination address
MOV A,#OPT_SECURITY_INFO ; A <- option byte value
MOV C,#1 ; C <- length of the info
BR SelfLib_GI_Execute
#endif
#if (GI_BC)
PUBLIC SelfLib_GetInfo_BootCluster
;-----------------------------------------------------------------------------
; Block type: selflib command function
; C prototype: u08 SelfLib_GetInfo_BootCluster(u08 *destination_pu08)
; C example: my_status_u08 = SelfLib_GetInfo_BootCluster((u08*)&my_destination_u08);
;-----------------------------------------------------------------------------
; Purpose: read the current value of the boot flag in extra area
; Input: AX, destination_pu08 - destination address of the bootflag info
; The format of the boot-flag info is: "unsigned char"
; The value of the boot info is 0x00 for cluster 0 and 0x01 for cluster 1.
; Output: -
; Changed: X, content of the data_buffer
; Returned: A, status code
; = 0x00(STS_NO_ERROR), normal
; = 0x05(STS_PARAMETER_ERROR), parameter error
;-----------------------------------------------------------------------------
SelfLib_GetInfo_BootCluster:
PUSH BC ; save used register
PUSH AX ; stack <- destination address
MOV A,#OPT_BOOTCLUSTER_INFO ; A <- option byte value
MOV C,#1 ; C <- length of the info
BR SelfLib_GI_Execute
#endif
#if (GI_BEA)
PUBLIC SelfLib_GetInfo_BlockEndAddr
;-----------------------------------------------------------------------------
; Block type: selflib command function
; C prototype: u08 SelfLib_GetInfo_BlockEndAddr((u32*) destination_pu32, u08 block_u08)
; C example: my_status_u08 = SelfLib_GetInfo_BlockEndAddr((u32*)&my_destination_u32, my_block_u08);
;-----------------------------------------------------------------------------
; Purpose: puts the last address of the specified block into *destination_pu32
; Input: AX - addr where the block end-address should be stored
; The type is u32 in spite of the fact, that the real flash address is 24 bit.
; B - block number the end-address is asked for.
; Output: -
; Changed: -
; Returned: A, status code
; = 0x00(STS_NO_ERROR), normal
; = 0x05(STS_PARAMETER_ERROR), parameter error
;-----------------------------------------------------------------------------
SelfLib_GetInfo_BlockEndAddr:
PUSH BC ; save used register
PUSH AX ; stack <- destination address
PUSH HL ; save used register
MOV A,B ;
MOV (entry_ram+IDX_BLOCK_NO_INFO),A ; entry_ram[IDX_BLOCK_NO_INFO] <- my_block_u08
MOVW AX,(entry_ram+IDX_DATA_BUF_H) ; AX <- address of data_buffer
MOVW HL,AX ;
MOV A,#00H ;
MOV [HL+3],A ; clear address bits 31...24 in advance
POP HL ; restore used register
MOV A,#OPT_LASTADDRESS_INFO ; A <- option byte value
MOV C,#4 ; C <- length of the info
#endif
#if (GI_S OR GI_BC OR GI_BEA)
;============================================================================
; Common part of all GetInfo functions
;============================================================================
SelfLib_GI_Execute:
MOV (entry_ram+IDX_OPTION_BYTE),A ; entry_ram[IDX_OPTION_BYTE] <- act. option byte
MOV A,#CMD_GET_INFO ;
CALL ASM_execute ; execute the "get info" command
POP HL ; HL <- destination address
CMP A,#STS_NO_ERROR ;
BNZ SelfLib_GI_Neg_Exit ; if(error) goto error_exit;
;
SelfLib_GI_Pos_Exit: ; else {
; --------------------------------------------
; copy information data_buffer[]->&destination
; --------------------------------------------
; HL = destination
; C = number of bytes
; --------------------------------------------
PUSH AX ; save the status
PUSH DE ; save used registers
MOVW AX,(entry_ram+IDX_DATA_BUF_H) ;
MOVW DE,AX ; DE <- &(data buffer)
SelfLib_GI_copy: ;
MOV A,[DE] ; A <- info byte
MOV [HL],A ; destination <- info byte
INCW HL ; HL++
INCW DE ; DE++
DBNZ C,SelfLib_GI_copy ;
POP DE ; restore used register
POP AX ; restore used register
; --------------------------------------------
SelfLib_GI_Neg_Exit: ; }
POP BC ; restore used register
RET ;
#endif
#if (SI_SBC)
PUBLIC SelfLib_SetInfo_SwapBootCluster
;-----------------------------------------------------------------------------
; Block type: selflib command function
; C prototype: u08 SelfLib_SetInfo_SwapBootCluster(void);
; C example: my_status_u08 = SelfLib_SetInfo_SwapBootCluster();
;-----------------------------------------------------------------------------
; Purpose: inverts the current value of the boot flag in the extra area
; Input: -
; Output: -
; Returned: u08 - status code
; = 0x00(STS_NO_ERROR), normal
; = 0x05(STS_PARAMETER_ERROR), parameter error
; = 0x10(STS_PROTECTION_ERROR), protection error
; = 0x1A(STS_MRG10_ERROR), erase error
; = 0x1B(STS_MRG11_ERROR), internal verify error
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -