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

📄 era_alg.asm

📁 TMS320C2000Flash操作
💻 ASM
📖 第 1 页 / 共 3 页
字号:
;--------------------------------------------------------------------------------------------------
; Filename         : ERA_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 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.
; 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 (10 Aug 2001)
;           Comments: Modified the timing delay routines to use AR2 instead of AR7. AR7 is used
;                     by the C-compiler in some cases, and cannot be used without first saving
;                     it. AR2 can be used directly.
; 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.
;--------------------------------------------------------------------------------------------------
;--------------------------------------------------------------------------------------------------

;--------------------------------------------------------------------------------------------------
; 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    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
;--------------------------------------------------------------------------------------------------
; 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.

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 erase 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    ERASE_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 erase 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    ERASE_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 erase 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    ERASE_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 erase 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    ERASE_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 erased. If it is to be
        ; erased then call the core erase 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    ERASE_SECTOR                    ;Call clear_sector to clear sector 2.

        ; For the LF2407, check if sector 2 is to be erased. If it is to be
        ; erased then call the core erase 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    ERASE_SECTOR                    ;Call clear_sector to clear sector 3.

        .endif

⌨️ 快捷键说明

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