📄 main.asm
字号:
;-------------------------------------------------------------------------------
; Main.asm:
; This is the client application program that invokes the clear,erase and
; program algorithms.
;-------------------------------------------------------------------------------
;-------------------------------------------------------------------------------
; Define the Vector Table
;-------------------------------------------------------------------------------
.sect "VECTORS"
RESET B START
;-------------------------------------------------------------------------------
; Get the flash algorithm symbols
;-------------------------------------------------------------------------------
.include ..\flashalgos\include\var.h
.include ..\flashalgos\include\rundefs.h
;-------------------------------------------------------------------------------
; Detect the device for which the Flash Programming API is configured for,
; this example assumes that this configuration is for the LF2407. (It uses
; more RAM than physically exists on the Lf2401A, and also uses a sector mask
; which refers to sectors non-existant on the Lf2401A.)
;-------------------------------------------------------------------------------
.if( DEV_TYPE != LF2407)
.emsg "ERROR: This example requires the DEV_TYPE in VAR.H be set to LF2407"
.endif
;-------------------------------------------------------------------------------
; Control shell variables.
;-------------------------------------------------------------------------------
;-------------------------------------------------------------------------------
; Normal application code: This is assembled into the .text segment.
;-------------------------------------------------------------------------------
.text
START: RPT #255
NOP
;-------------------------------------------------------------------------------
;Perform device initialiazation. At a minimum, before calling the flash algos,
;the watchdog must be shut down and the PLL multiplier must be set up correctly.
;-------------------------------------------------------------------------------
CALL DEVICE_INIT
;-------------------------------------------------------------------------------
; Application code goes in here ...
;
;------------------------------------------------------------------------------
;-------------------------------------------------------------------------------
; Flash programming routine.
; To program flash the following information should be available:
; 1. What sectors is the incoming code going into.
; 2. Copy the clear, erase, and program algos into RAM.
; 3. Copy the kernel to RAM.
;
; Steps 2 and 3 are critical, since while the flash is being reprogrammed,
; no code can be executed from the flash at all.
;
; 4. Call the kernel, which will sequence things like clear, erase the flash
; and then call the program routine. All the communications must be handled
; in the kernel, since this is the only executable code while the flash
; is being reprogrammed.
;-------------------------------------------------------------------------------
PGM_FLASH:
;-------------------------------------------------------------------------------
; Initialize the device - at a minimum the PLL and Watchdog must be initialized.
;-------------------------------------------------------------------------------
CALL DEVICE_INIT
CALL DATA_SETUP
;-------------------------------------------------------------------------------
; Copy the routines to execute while the flash is being programmed into the
; SARAM memory. This is needed since *NO* code can be executed from flash while
; programming.
;
; NOTE: Since all the algos are being copied into RAM, this means that
; the NON-overlaid memory map command file must be used.
;-------------------------------------------------------------------------------
CALL COPY_CLEAR_ALGO
CALL COPY_ERASE_ALGO
CALL COPY_PROGRAM_ALGO
CALL COPY_KERNEL
;-------------------------------------------------------------------------------
; Transfer control to the runtime control kernel which will sequence operations
; during flash programming.
;-------------------------------------------------------------------------------
B KERNEL_START
;-------------------------------------------------------------------------------
;
;-------------------------------------------------------------------------------
DEVICE_INIT:
LDP #0E0h
SPLK #0000h,7018h ; Init the PLL
SPLK #0bh,7019h
LDP #0E0h
SPLK #6fh,7029h ; Shutdown the watchdog.
RET
;-------------------------------------------------------------------------------
; Set up a block of memory for the flash programming routine to reference.
;-------------------------------------------------------------------------------
DATA_SETUP:
LDP #6
SPLK #3456h,300h
SPLK #7236h,301h
SPLK #4389h,302h
SPLK #9876h,303h
SPLK #2786h,304h
RET
.sect "KER_text"
KERNEL_START:
;-------------------------------------------------------------------------------
; Set up and call the CLEAR routine for the flash. This preconditions the flash
; to 0s in preparation for erase. This must be called with the same exact sector
; command as erase.
;-------------------------------------------------------------------------------
CLEAR:
LDP #flashAlgoVars.SECTOR_CMD ;Point DP to flash vars.
SPLK #0eh,flashAlgoVars.SECTOR_CMD ;Pass sector command.
CALL CLEAR_FLASH ;Call the clear routine.
LACC flashAlgoVars.ALGO_STATUS ;Check algo status.
BCND ERROR,NEQ ;If non zero indicate error.
;-------------------------------------------------------------------------------
; Set up and call the CLEAR routine for the flash. This preconditions the flash
; to 0s in preparation for erase. This must be called with the same exact sector
; command as erase.
;-------------------------------------------------------------------------------
ERASE:
LDP #flashAlgoVars.SECTOR_CMD ;Point DP to flash vars.
SPLK #0eh,flashAlgoVars.SECTOR_CMD ;Pass sector command.
CALL ERASE_FLASH ;Call the erase routine.
LACC flashAlgoVars.ALGO_STATUS ;Check algo status.
BCND ERROR,NEQ ;If non zero indicate error.
;-------------------------------------------------------------------------------
; Set up and call the PROGRAM routine for the flash. This programs the flash
; with data. This data would in a practical application come over a serial port
; or other interface. Or this may be calibration data, which may be computed
; either on-chip or off-chip.
;-------------------------------------------------------------------------------
PROGRAM:
LDP #flashAlgoVars.DATA_PTR ;Point DP to flash vars.
SPLK #300h,flashAlgoVars.DATA_PTR ;Setup ptr to data buffer.
SPLK #0eh,flashAlgoVars.SECTOR_CMD ;Pass sector command.
SPLK #4,flashAlgoVars.FL_SECEND ;Number of words to program.
SPLK #1023h,flashAlgoVars.ADDR ;Pass sector command.
CALL PROGRAM_FLASH ;Call the program routine.
LACC flashAlgoVars.ALGO_STATUS ;Check algo status.
BCND ERROR,NEQ ;If non zero indicate error.
SUCCESS:
B DONE
ERROR: CLRC XF ;Toggle LED in a fast loop
;
CALL SHORT_DELAY
SETC XF
CALL SHORT_DELAY
B ERROR
DONE: SETC XF ;Toggle LED in a slow loop
CALL LONG_DELAY
CLRC XF
CALL LONG_DELAY
B DONE
LONG_DELAY:
LAR AR2,#60000
MAR *,AR2
LDELAYLP:
RPT #255
NOP
BANZ LDELAYLP
RET
SHORT_DELAY:
LAR AR2,#7000
MAR *,AR2
SDELAYLP:
RPT #255
NOP
BANZ LDELAYLP
RET
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -