?? clr_alg.asm
字號:
;--------------------------------------------------------------------------------------------------
; Filename : CLR_ALG.ASM
; Last Modified : 23 Jan 2002.
; Version : 1.3
; 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.
; Ver 1.1 (10 Aug 2001)
; Comments: Added code to save/restore the hardware stack. This excludes the possibility
; of hardware stack overflow.
; Ver 1.2 (16 Oct 2001)
; Comments: No changes to this file. Changed version number only.
; Ver 1.3 (23 Jan 2002)
; Comments:
; * Added support for the LF2401A. See the file ..\include\var.h on how to
; set one of the available configurations.
; * Modified the macros ACCESS_REGS and ACCESS_ARRAY to not use a hard coded data
; mem address. This is to bring these macros in line with the rest of the algo
; which uses allocated addresses. These macros still use a hard coded address
; for the i/o space address 0xff0f (0ff0fh) since that is a special address,
; which will always address the i/o latch which controls the flash memory
; mode.
;--------------------------------------------------------------------------------------------------
;--------------------------------------------------------------------------------------------------
.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 flashAlgoVars.PAD,0ff0fh
.endm
ACCESS_ARRAY .macro
IN flashAlgoVars.PAD,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.
STACK_SAVE:
LAR AR2,#flashAlgoVars.STACK0 ;Use AR2 to save the hardware stack.
MAR *,AR2 ;Make AR2 the current AR
RPT #7 ;Save all the 8 hardware stack locations
POPD *+ ;into RAM block.
SECTOR_0:
LACC flashAlgoVars.SECTOR_CMD ;Get the sector processing command.
;--------------------------------------------------------------------------------------------------
.if(DEV_TYPE = LF2407)
;Since the LF2401A has four sectors,
;allow only four bits.
AND #000Fh ;Mask out unwanted bits.
.elseif (DEV_TYPE = LF2401A)
;Since the LF2401A has only two sectors,
;allow only two bits.
AND #0003h ;Mask out unwanted bits.
.endif
;--------------------------------------------------------------------------------------------------
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.
;--------------------------------------------------------------------------------------------------
.if(DEV_TYPE = LF2407)
; Set up the limits for Sector 0 of LF2407 and call the core clear routine.
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.
.elseif (DEV_TYPE = LF2401A)
; Set up the limits for Sector 0 of LF2401A and call the core clear routine.
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.
.endif
;--------------------------------------------------------------------------------------------------
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.
.if(DEV_TYPE = LF2407)
; Set up the limits for Sector 1 of LF2407 and call the core clear routine.
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
.elseif(DEV_TYPE = LF2401A)
; Set up the limits for Sector 1 of LF2401A and call the core clear routine.
SPLK #1000h,flashAlgoVars.FL_SECST ;Set up first addr of sector 1.
SPLK #1FFFh,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
.endif
;--------------------------------------------------------------------------------------------------
SECTOR_2:
.if(DEV_TYPE = LF2407)
; For the LF2407, check if sector 2 is to be cleared. If it is to be
; cleared then call the core clear routine with the correct limits.
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.
; For the LF2407, check if sector 3 is to be cleared. If it is to be
; cleared then call the core clear routine with the correct limits.
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.
.endif
SECTORS_DONE:
SPLK #0,flashAlgoVars.ALGO_STATUS ;No errors encountered.
B STACK_RESTORE
NO_SECTORS:
SPLK #10,flashAlgoVars.ALGO_STATUS ;No sectors specified for clear.
B STACK_RESTORE
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.
B STACK_RESTORE
;--------------------------------------------------------------------------------------------------
; Restore the hardware stack and exit to caller.
;--------------------------------------------------------------------------------------------------
STACK_RESTORE:
LAR AR2,#flashAlgoVars.STACK7 ;Point AR2 to the last of the stored stack contents
MAR *,AR2 ;Make AR2 the current AR
RPT #7 ;Restore ALL stack locations.
PSHD *-
MAR *,AR1 ;Make AR1 the current AR
RET ;Return to caller
;--------------------------------------------------------------------------------------------------
; 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 ;
;--------------------------------------------------------------------------------------------------
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -