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

📄 pgm_alg.asm

📁 DSP F2407 烧写软件
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;--------------------------------------------------------------------------------------------------
; Filename         : PGM_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 clear algorithm for 
; progamming user data into the LF240x Flash.
;--------------------------------------------------------------------------------------------------
;--------------------------------------------------------------------------------------------------
; 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  PROGRAM_FLASH

;--------------------------------------------------------------------------------------------------
; Import register definitions and symbol declarations.
;--------------------------------------------------------------------------------------------------
        .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 'PSPL_text'.
;--------------------------------------------------------------------------------------------------
            .sect     "PGM_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
;--------------------------------------------------------------------------------------------------



;--------------------------------------------------------------------------------------------------
; PROGRAM_FLASH:
;--------------------------------------------------------------------------------------------------
; 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_1 subroutine.
;--------------------------------------------------------------------------------------------------
PROGRAM_FLASH:                          ; Call label for assembly-language client applications.
_programFlash:                          ; Call label for C-language client applications.
        .label  ProgramAlgoStartMain
        LDP     #flashAlgoVars.ADDR
        MAR     *,AR2
        
;--------------------------------------------------------------------------------------------------
; 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_CMD,flashAlgoVars.PAD      ;
        TBLW    flashAlgoVars.PAD       

        LACC    #ENAB                                            ;Enable core.
        SPLK    #0001h,flashAlgoVars.PAD                         ;
        TBLW    flashAlgoVars.PAD                                ;

;--------------------------------------------------------------------------------------------------
        SPLK    #0000,flashAlgoVars.FL_CMD                       ;
;--------------------------------------------------------------------------------------------------
;       BLDD    flashAlgoVars.DATA_PTR,#flashAlgoVars.DATA       ;Point to first data 
                                                                 ;to be programmed.
;--------------------------------------------------------------------------------------------------
; PGM:
;--------------------------------------------------------------------------------------------------
; This is the loop at the core of the program algorithm. This performs the following steps to 
; program the flash with the new contents of the flash
;   1.  Reads the flash.
;   2.  Compares the contents read out to those pointed to by the 
;       variable DATA_PTR.
;   3.  If any bits need to be programmed forms a bitmask and calls the PROG
;       routine to apply the program pulse.
;
;--------------------------------------------------------------------------------------------------
PGM:    SPLK    #MX_PCNT,flashAlgoVars.PLS_CNT  ;Initialise the pulse counter.

PGVERON:
        LACC    #WADDR                          ;Load WADDR with the address of 
                                                ;the word to be programmed.
        CALL    SETWADDR                        ;Call the routine to do so.

        LACC    flashAlgoVars.FL_CMD            ;Compose the flash command to read
                                                ;the user space in PROGVER mode.
        XOR     #0004h              
        SACL    flashAlgoVars.PAD    

        LACC    #CTRL                           ;Set up the PROGVER mode.
        TBLW    flashAlgoVars.PAD
        SDELAY  #T_pvsu                         ;Wait for T_pvsu(P)

        LACC    #PMPC                           ;Activate the PROGVER mode.
        SPLK    #0005h,flashAlgoVars.PAD    
        TBLW    flashAlgoVars.PAD
        SDELAY  #T_pva_e                        ;Wait T_pva(E)

        CALL    READWORD                        ;Read the word pointed to by ADDR.
    
PGVEROFF:
        SPLK    #0000h,flashAlgoVars.PAD1       ;Deactivate the PROGVER mode.
        CALL    CLRCMD

        SDELAY  #Tpv_h_P                        ; Wait for Program verify hold time

        SPLK    #0001h,flashAlgoVars.PAD1       ;Clear out PMPC and CTRL
        CALL    CLRCMD                          ;Since PMPC is cleared already, it is unchanged.

        SDELAY  #Tpv_h_C                        ;Hold the normal read mode.

;--------------------------------------------------------------------------------------------------
; Compare:
;--------------------------------------------------------------------------------------------------
; This section of code compares the data read out from the flash with the data
; intended to be programmed in the flash.
;   1.  Get the data read out during the read.
;   2.  Create a bitmask by XOR-ing the data read out during verify with the 
;       intended data pointed to by DATA_PTR.
;   3.  If not equal, builds the mask and calls the PROG routine.
;--------------------------------------------------------------------------------------------------
; Notes on building the mask:
;
; This implementation uses the Bitmask = DATA + !READ_Flash boolean expression for building the
; bitmask. (The + is the boolean operator OR, and ! is inversion.)
; The mask building works as follows:
;
;   1. Read the flash data. 
;   2. Invert this by XOR-ing this with 0xffff.
;   3. OR this with the reference data from the buffer.
;   4. Store the result as the mask into the DATA (subsequently sent to WDATA).
;
;   For example lets say the flash cells contain the 16 bits:  cccc cccc cccc cccc.
;
;   CCCC        cccc cccc cccc cccc  (flash contents)
;   XOR 
;   FFFF        1111 1111 1111 1111  (all ones mask)
;   ----        ---- ---- ---- ----
;   PPPP        pppp pppp pppp pppp  (intermediate result)
;   OR          
;   DDDD        dddd dddd dddd dddd  (reference data from RAM buffer)
;   ----        ---- ---- ---- ----
;   MMMM        mmmm mmmm mmmm mmmm  (mask for writing in WDATA)
;
;   Now the bits m are the result as p = ((C ^ 1) + y). The truth table for this is:
; 
;   d    c   c^1 or !c       m = p = !c + d  Action caused by m     Comments
;--------------------------------------------------------------------------------------------------
;   0    0    1              1               No pulse applied.      Note 1.
;   0    1    0              0               Pulse applied.         Note 2.
;   1    0    1              1               No pulse applied.      Note 3.
;   1    1    0              1               No pulse applied.      Note 4.
;
; 
; Note 1:  This is the case wheen the reference data is a 0 and the flash cell is a 0.
;          Clearly since Cell = Reference data, no pulse is needed, and this is what 
;          happens with WDATA = 1 for this bit.
;
; Note 2:  Case where the reference data is a 0, but the cell is a 1. So a pulse is 
;          applied, to program the cell to a 0.
;
; Note 3.  Case where the reference data is a 1, but the cell is a 0. This is a case
;          where the program routine is asked to 'program' a cell to a 1, while the
;          cell is already at a 0. This is a VIOLATION of the established flow, and 
;          no pulses are really required. So no pulse is applied. This will lead 
;          (rightly so) to an error condition.
; Note 4:  This is the case wheen the reference data is a 1 and the flash cell is a 1.
;          Clearly since Cell = Reference data, no pulse is needed, and this is what 

⌨️ 快捷键说明

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