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

📄 era_alg.asm

📁 DSP F2407 烧写软件
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;--------------------------------------------------------------------------------------------------
; Filename         : ERA_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 ERASING the TMS320LF240x 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.
;--------------------------------------------------------------------------------------------------
;--------------------------------------------------------------------------------------------------

;--------------------------------------------------------------------------------------------------
; Symbols exported from this file
;--------------------------------------------------------------------------------------------------
            .globl  ERASE_FLASH

;--------------------------------------------------------------------------------------------------
; Import symbols (and other information) from VAR.H 
;--------------------------------------------------------------------------------------------------
            .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 'ESPL_text'.
;--------------------------------------------------------------------------------------------------
            .sect     "ERA_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
;--------------------------------------------------------------------------------------------------
; ERASE_FLASH: Implementation of the user call for the flash erase routine. Call this with a valid
; sector mask in flashAlgoVars.SECTOR_MASK to erase any sector combination in the flash.
;--------------------------------------------------------------------------------------------------

        .label  EraseAlgoStartMain

ERASE_FLASH:                        ; Call label for assembly-language client applications.
_eraseFlash:                        ; Call label for C-language client applications.

        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    ERASE_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    ERASE_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    ERASE_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    ERASE_SECTOR                    ;Call clear_sector to clear sector 3.

SECTORS_DONE:
        SPLK    #0,flashAlgoVars.ALGO_STATUS    ;No errors encountered.
        RET

NO_SECTORS:
        SPLK    #11,flashAlgoVars.ALGO_STATUS   ;No sectors specified for erase.
        RET

ERROR1: POPD    flashAlgoVars.PAD               ;Adjust stack depth.
        SPLK    #2,flashAlgoVars.ALGO_STATUS    ;Error encountered in ERASE.
        RET

;--------------------------------------------------------------------------------------------------    
; ERASE_SECTOR:
;--------------------------------------------------------------------------------------------------    
; This function is the implementation of the erase algorithm for the pre-program
; conditioning of the flash array. This function is desginated as a LEVEL_1 
; subroutine.
;--------------------------------------------------------------------------------------------------
ERASE_SECTOR:
        SPLK    #MX_ECNT,flashAlgoVars.PLS_CNT              ;Initialize the program pulse count. 
        SPLK    #0ffffh,flashAlgoVars.DATA                  ;Load 0ffffh for compare.
    
        BLDD    #flashAlgoVars.FL_SECST,flashAlgoVars.ADDR  ;Point address to the start of sector.
        SPLK    #0000,flashAlgoVars.LASTVER                 ;Initialize LASTVERIFY Flag 
;--------------------------------------------------------------------------------------------------
;   ENABLE
;--------------------------------------------------------------------------------------------------
; Enable the flash for erase:
; To accept 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 ;Copy the sector key
        TBLW    flashAlgoVars.PAD                           ;
                                                            ;
        LACC    #ENAB                                       ;Enable core.
        SPLK    #0001h,flashAlgoVars.PAD                    ;
        TBLW    flashAlgoVars.PAD                           ;

        B    ERVER                                          ;Enter erase loop from the erase verify.

;--------------------------------------------------------------------------------------------------
;   PERASE:
;--------------------------------------------------------------------------------------------------
;   This loop erases the sector, based on the address passed by the caller in
;   flashAlgoVars.FL_SECST.
;--------------------------------------------------------------------------------------------------
PERASE:
        LACC    flashAlgoVars.PLS_CNT                       ;Get the pulse counter value.
        BCND    ERROR,EQ                                    ;If remaining pulses == 0 then
                                                            ;commence the error handling.
;--------------------------------------------------------------------------------------------------
        LACC    #WADDR                                      ;The sector is selected by writing
                                                            ;WADDR with the first address of 
                                                            ;the sector
        CALL    SETWADDR                                    ;Execute the write to WADDR.

        LACC    #WDATA                                      ;Load the WDATA register with 0xffff.
        TBLW    flashAlgoVars.DATA
;--------------------------------------------------------------------------------------------------
        LACC    #CTRL                                       ;Setup the erase mode.
        SPLK    #0001,flashAlgoVars.PAD
        TBLW    flashAlgoVars.PAD
;--------------------------------------------------------------------------------------------------
        SDELAY    #T_esu_er                                 ;T_esu(ER) Delay.
;--------------------------------------------------------------------------------------------------
        LACC    #PMPC                                       ;Activate the erase mode.
        SPLK    #0005h,flashAlgoVars.PAD    
        TBLW    flashAlgoVars.PAD    
;--------------------------------------------------------------------------------------------------
EPW:    LAR     AR7,#ERASE_PULSE                            ;Call the delay routine to define the
        CALL    DELAY,AR7                                   ;erase pulse width to T_erase(E)
;--------------------------------------------------------------------------------------------------
        SPLK    #0000h,flashAlgoVars.PAD1                   ;De-activate the erase mode.
        CALL    CLRCMD
;--------------------------------------------------------------------------------------------------
        SDELAY  #T_eh_er    ;T_eh(ER)                       ;Algo delay.
;--------------------------------------------------------------------------------------------------
        LACC    #CTRL                                       ;Exit the Erase mode.
        SPLK    #0000,flashAlgoVars.PAD
        TBLW    flashAlgoVars.PAD
;--------------------------------------------------------------------------------------------------
        SDELAY  #Teh_C                                     ;Wait in normal mode.
;--------------------------------------------------------------------------------------------------
        LACC    flashAlgoVars.PLS_CNT                       ;Advance the erase pulse counter.
        SUB     #1h
        SACL    flashAlgoVars.PLS_CNT
;--------------------------------------------------------------------------------------------------
; ERVER: ERASE Verify
;--------------------------------------------------------------------------------------------------
; This subroutine checks the flash to see if the flash is erased.
; To do this it does the followign steps:
;   1.  Reads the flash array in erase verify mode.
;   2.  Branches to the Erase routine if a word is non-FFFFh
;   3.  If all the words in the sector are ffffh then it transfers control
;       to PASSERVER.
;--------------------------------------------------------------------------------------------------
ERVER:  BLDD    #flashAlgoVars.FL_SECST,flashAlgoVars.ADDR  ;Init ADDR to first location in sector.
    
B0      LACC    #CTRL                                       ;Init the Erase verify mode.
        SPLK    #0002,flashAlgoVars.PAD
        TBLW    flashAlgoVars.PAD
        SDELAY  #T_eva_e                                    ;T_eva(E) ; Algo Delay.

B1

        CALL    READWORD                                    ;Read out the word in erase ver mode.

COMPARE:
        LACL    flashAlgoVars.READ                          ;Check to see if the word read out is
        XOR     #0FFFFh                                     ;0ffffh.
        BCND    PROCEED_TO_ERASE,NEQ                                  ;If not, then proceed to apply an erase 
                                                            ;pulse to the sector.
    
        LACC    flashAlgoVars.ADDR                          ;See if the current address is 
        SUB     flashAlgoVars.FL_SECEND                     ;end-of-sector. If so, transfer control
        BCND    PASSERVER,EQ                                ;to PASSERVER.

        ADD     flashAlgoVars.FL_SECEND                     ;Increment the ADDR counter variable.
        ADD     #1                                          ;to next address
        SACL    flashAlgoVars.ADDR                          ;Store back incremented variable.

        B       B1                                          ;Proceed to check the next word.

PROCEED_TO_ERASE:

        LACC    #CTRL                                       ;Exit the Erase verify mode.
        SPLK    #0000,flashAlgoVars.PAD
        TBLW    flashAlgoVars.PAD

        SDELAY  #Tevh_C                                     ;Wait in normal mode.

        B       PERASE

⌨️ 快捷键说明

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