📄 clr_alg.asm
字号:
;--------------------------------------------------------------------------------------------------
; Filename : CLR_ALG.ASM
; Last Modified : 25 May 2001.
; Version : 1.0
; Originator : Texas Instruments, DSP Digital Control Systems Group.
;--------------------------------------------------------------------------------------------------
; Description:
;
; This file contains the implementation of the core algorithm for clearing the LF240x Flash. This
; algorithm is generic to any sector, and performs the pre-erase conditioning for the flash module
; on these parts.
;--------------------------------------------------------------------------------------------------
;--------------------------------------------------------------------------------------------------
; Revision History
;
; Ver 1.0 (25 May 2001)
;
; Comments: Derived from previous source code. Several modifications in place for
; enhanced embeddability.
;--------------------------------------------------------------------------------------------------
;--------------------------------------------------------------------------------------------------
.def CLEAR_FLASH
;--------------------------------------------------------------------------------------------------
; Symbols imported by this file
;--------------------------------------------------------------------------------------------------
.include "..\include\var.h"
.include "..\include\rundefs.h"
;--------------------------------------------------------------------------------------------------
; Program sections generated by this file:
; All code in this algorithm implementation is assembled into the named section 'ALG_Text".
; Any relocation sensitive code is placed in the named
; section 'CSPL_text'.
;--------------------------------------------------------------------------------------------------
.sect "CLR_text"
;--------------------------------------------------------------------------------------------------
; Define macros to set the Flash Mode.
; ACCESS_REGS gives access to the Flash Registers in the Pgm Mem Space and ACCESS_ARRAY gives
; access to the Flash ARRAY in Pgm Mem Space.
;--------------------------------------------------------------------------------------------------
ACCESS_REGS .macro
OUT 07fh,0ff0fh
.endm
ACCESS_ARRAY .macro
IN 07fh,0ff0fh
.endm
;--------------------------------------------------------------------------------------------------
; Define Short DELAY loop macro.
; This will be used to generate a short delay upto 256 cycles.
;--------------------------------------------------------------------------------------------------
SDELAY .macro COUNT
RPT COUNT
NOP
.endm
;--------------------------------------------------------------------------------------------------
; CLEAR_FLASH:
;
; This function is the user level interface to the implementation of the clear algorithm for
; pre-erase conditioning of the TMS320LF2407 flash array.
; This function is desginated as a LEVEL_1 subroutine.
;--------------------------------------------------------------------------------------------------
CLEAR_FLASH: ;Call label for asm client applications.
_clearFlash: ;Call label for C client applications.
.label ClearAlgoStartMain
LDP #flashAlgoVars.ADDR ;Set the DP to the flash algo vars.
SECTOR_0:
LACC flashAlgoVars.SECTOR_CMD ;Get the sector processing command.
AND #000Fh ;Mask out unwanted bits.
BCND NO_SECTORS,EQ ;If no sectors are set, then goto
;error reporting routine.
SFR ;Get Bit 0.
SACL flashAlgoVars.SECTOR_CMD ;Store the rest of the command back.
;--------------------------------------------------------------------------------------------------
BCND SECTOR_1,NC ;If bit 0 is set, clear sector 0.
SPLK #0000h,flashAlgoVars.FL_SECST ;Set up first addr of sector 0.
SPLK #0FFFh,flashAlgoVars.FL_SECEND ;Set up last addr of sector 0.
SPLK #0001h,flashAlgoVars.SECTOR_KEY ;Pass the sector enable key.
CALL CLEAR_SECTOR ;Call clear_sector to clear sector 0.
;--------------------------------------------------------------------------------------------------
SECTOR_1:
LACC flashAlgoVars.SECTOR_CMD ;Get the sector processing command.
SFR ;Mask out unwanted bits.
SACL flashAlgoVars.SECTOR_CMD ;Store the rest of the command back.
BCND SECTOR_2,NC ;If bit 1 is set, clear sector 1.
SPLK #1000h,flashAlgoVars.FL_SECST ;Set up first addr of sector 1.
SPLK #3FFFh,flashAlgoVars.FL_SECEND ;Set up last addr of sector 1.
SPLK #0002h,flashAlgoVars.SECTOR_KEY ;Pass the sector enable key.
CALL CLEAR_SECTOR ;Call clear_sector to clear
; Sector 1 if requested
;--------------------------------------------------------------------------------------------------
SECTOR_2:
LACC flashAlgoVars.SECTOR_CMD ;Get the sector processing command.
SFR ;Mask out unwanted bits.
SACL flashAlgoVars.SECTOR_CMD ;Store the rest of the command back.
BCND SECTOR_3,NC ;If bit 2 is set, clear sector 2.
SPLK #4000h,flashAlgoVars.FL_SECST ;Set up first address of sector 2.
SPLK #6FFFh,flashAlgoVars.FL_SECEND ;Set up last address of sector 2.
SPLK #0004h,flashAlgoVars.SECTOR_KEY ;Pass the sector enable key.
CALL CLEAR_SECTOR ;Call clear_sector to clear sector 2.
SECTOR_3:
LACC flashAlgoVars.SECTOR_CMD ;Get the sector processing command.
SFR ;Mask out unwanted bits.
SACL flashAlgoVars.SECTOR_CMD ;Store the rest of the command back.
BCND SECTORS_DONE,NC ;If bit 3 is set, clear sector 3.
SPLK #7000h,flashAlgoVars.FL_SECST ;Set up first address of sector 3.
SPLK #7FFFh,flashAlgoVars.FL_SECEND ;Set up last address of sector 3.
SPLK #0008h,flashAlgoVars.SECTOR_KEY ;Pass the sector enable key.
CALL CLEAR_SECTOR ;Call clear_sector to clear sector 3.
SECTORS_DONE:
SPLK #0,flashAlgoVars.ALGO_STATUS ;No errors encountered.
RET
NO_SECTORS:
SPLK #10,flashAlgoVars.ALGO_STATUS ;No sectors specified for clear.
RET
ERROR1:
;--------------------------------------------------------------------------------------------------
; IMPORTANT NOTE:
;
; This code is executed in LEVEL_3, during a call to CLR_LOOP (which is a LEVEL_3 routine).
; This routine is returning control to the LEVEL_0 (Caller's level). So it is performing the
; function of a LEVEL_1 routine.
; So, It is EXTREMELY important that this routine adjust the stack depth by the proper amount.
; This routine must therefore remove two (2) words from the stack.
;--------------------------------------------------------------------------------------------------
POPD flashAlgoVars.PAD ;Adjust stack depth 1.
POPD flashAlgoVars.PAD ;Adjust stack depth 2.
SPLK #1,flashAlgoVars.ALGO_STATUS ;Error encountered in CLEAR.
RET
;--------------------------------------------------------------------------------------------------
; CLEAR_SECTOR:
;
; This function is the implementation of the clear algorithm for the pre-erase preconditioning of
; the flash array. This function is desginated as a LEVEL_2 subroutine.
;--------------------------------------------------------------------------------------------------
CLEAR_SECTOR:
;--------------------------------------------------------------------------------------------------
; Enable the flash for programming:
; To accept programming commands the following must happen:
; 1. Place the flash in the register mode.
; 2. Copy the sector key to the SECT register.
; 3. Enable the core by setting Bit 0 of the ENAB Register
;--------------------------------------------------------------------------------------------------
ENABLE: ACCESS_REGS ;Put the flash in register mode.
LACC #SECT ;Enable sector.
BLDD #flashAlgoVars.SECTOR_KEY,flashAlgoVars.PAD
TBLW flashAlgoVars.PAD
LACC #ENAB ;Enable core.
SPLK #0001h,flashAlgoVars.PAD ;
TBLW flashAlgoVars.PAD ;
;--------------------------------------------------------------------------------------------------
; Next, the following steps are performed
; 1. DATA is set to 0000h for use in the compare stage, since in clear the flash is set to all
; words = 0000h.
; 2. Calls the Level 2 routine CLR_LOOP to clear the sector user space.
; 3. Calls the Level 2 routine CLR_LOOP to clear the sector base space.
; This clears out any bits in the base sector space that were not mapped into the user space.
; 4. It then calls the Level2 routine CLR_LOOP to clear the redundant
; row bits, that were not mapped into the user space.
;--------------------------------------------------------------------------------------------------
SPLK #0000h,flashAlgoVars.DATA ;Load 0000h for compare.
SPLK #0000h,flashAlgoVars.FL_CMD ;Setup the routine to address the base space.
SPLK #0001H,flashAlgoVars.FAIL_CMD ;Setup the routine to fail if any bits in
;the user space fail to clear.
CALL CLR_LOOP ;Call the CLR_Loop routine to clear
;the user space.
LACC flashAlgoVars.SECTOR_KEY ;Get the sector key.
AND #0006H ;Mask out bits for sectors 0 and 3.
BCND NO_RED_CLEAR,EQ ;Perform NOROWRED and PRECON steps only
;for sectors 1 and 2.
SPLK #0080h,flashAlgoVars.FL_CMD ;Setup the NOROWRED mode.
SPLK #0000H,flashAlgoVars.FAIL_CMD ;Set up the routine to ingnore failure of
;bits to program on MX_PCNT pulses.
CALL CLR_LOOP ;Clear the base sector space (NOROWRED)
SPLK #0100h,flashAlgoVars.FL_CMD ;Setup the redundancy precondition mode.
SPLK #0000H,flashAlgoVars.FAIL_CMD ;Set up the routine to ingnore failure of
;bits to program on MX_PCNT pulses.
CALL CLR_LOOP ;Call the CLR_Loop routine to clear
;the redundant bits.
NO_RED_CLEAR:
CALL END1
RET
;--------------------------------------------------------------------------------------------------
; CLR_LOOP:
;--------------------------------------------------------------------------------------------------
; This function is desginated as a LEVEL_3 subroutine.
;--------------------------------------------------------------------------------------------------
; This function is the implementation for the clear loop. It reads the flash one word at a
; time in PROGVER mode. It then compares this word to the word in DATA. In case of the this
; algo, it is always 0000h. If then goes processes the next word if it is already zero,
; else it enters BITMASK to form the bitmask for applying programming pulses to the Flash array.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -