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

📄 clr_alg.asm

📁 DSP F2407 烧写软件
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;--------------------------------------------------------------------------------------------------
CLR_LOOP:
        SPLK    #MX_PCNT,flashAlgoVars.PLS_CNT  ;Initialize the program pulse count. 
        BLDD    #flashAlgoVars.FL_SECST,flashAlgoVars.ADDR        
                                                ;Initialize the address counter.

PGVERON:
        LACC    #WADDR                          ;Load the WADDR Register with the address of
        CALL    SETWADDR                        ;the word to be programmed.

        LACC    flashAlgoVars.FL_CMD            
        XOR     #0004h                          ;(PROGVER Command)Program Verification Command.
        SACL    flashAlgoVars.PAD                        

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

        LACC    #PMPC                
        SPLK    #0005h,flashAlgoVars.PAD
        TBLW    flashAlgoVars.PAD               ;Activate the PGVER Mode by writing to 
                                                ;PMPC.
        SDELAY   #T_pva_e                       ;Wait T_pva(E) 
        CALL     READWORD
    
PGVEROFF:
        SPLK    #0000h,flashAlgoVars.PAD1       ;Clear out PMPC.
        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:
        LACC    flashAlgoVars.READ              ;Get the value of the word read out during
                                                ;Program Verify.
        OR      #0000h                          ;OR this value with 0000h
        BCND    NEXTWORD,EQ                     ;If == 0000h then this word (*ADDR) is
                                                ;programmed, process the next word.
;--------------------------------------------------------------------------------------------------
; BITMASK:
;       This section forms the bitmask to write to the WDATA register.
;       READ contains the value read during program verify above,
;       and this is used to build the mask.
;       Once the mask is built, the sub-routine PROG is called.
;--------------------------------------------------------------------------------------------------
; Notes on building the mask:
;
; ** IMPORTANT: This mask building assumes processing is always to clear the 
; **             flash, i.e. the end value in the flash is assumed to be 0000h.
; **
; 
; This works as follows:
;       1.  Get the value read out during program verify.
;        2. Any bits that are 0s should not get any more pulses.  While any bits that are 1s 
;           should get pulses.
;        3. To apply pulses bits in the WDATA register should be 0s.
;        4. XOR the read value with 0ffffh. This inverts all bits in the read value. So bits that
;           are 0s send 1s in the corresponding bits in WDATA and bits that are 1s send 0s in the
;           corresponding bits in WDATA.
;        5. This ensures that prog applied pulses to those bits read out as 1s.
;--------------------------------------------------------------------------------------------------
        LACC    flashAlgoVars.READ              ;Get the value read during program verify
        XOR     #0ffffh                         ;Acc has the bits now to be written to WDATA.
        SACL    flashAlgoVars.DATA,0            ;Store acc in flashAlgoVars.DATA
        CALL    PROG                            ;Call the PROGRAM routine, that applies the
                                                ;pulses.
;--------------------------------------------------------------------------------------------------
; PGCNT: Program Pulse Count Advance / Check:
;        1. Advance the pulse counter.
;        2. Check the pulse counter to see if this has exceeded limits.          
;        3. Error handling if (2) is true.
;--------------------------------------------------------------------------------------------------
PGCNT:  LACC    flashAlgoVars.PLS_CNT           ;Decrement the pulse counter
        SUB     #1                              ;
        SACL    flashAlgoVars.PLS_CNT           ;Pulse counter now has remaining 
                                                ;pulses allowable.
                                    
        BCND    CHK_IF_FAIL,EQ                  ;If zero then the pulse count is exceeded,
                                                ;enter error handling,
        B        PGVERON                        ;verify word programmed
;--------------------------------------------------------------------------------------------------
CHK_IF_FAIL:                                    ; If here then MAX_PCNT pulses have been 
                                                ; applied. So, check the fail command.
        LACL    flashAlgoVars.FAIL_CMD          ; Get the FAIL_CMD passed from caller.
        BCND    ERROR,NEQ                       ; If non-zero begin error handling.
        B       NEXTWORD                        ; If fail command is zero, then the 
                                                ; caller intended to allow programming
                                                ; failures. So continue the flow.
ERROR:  CALL    END1
        B       ERROR1

;--------------------------------------------------------------------------------------------------
; NEXTWORD
; This block does the following things:
;   1.  Checks if the ADDR is at the last address in the sector.
;   2.  If not, increments ADDR.
;   3.  Sets up program pulse count for programming the next word.
;--------------------------------------------------------------------------------------------------
NEXTWORD:

        LACL    flashAlgoVars.ADDR              ;ACC = (address of previous word programmed).
        SUB     flashAlgoVars.FL_SECEND         ;ACC = (prev word addr) - (last address of sector)
        BCND    NW,NEQ                          ;If there is a match end the routine,
        RET                                     ;otherwise continue with the next word.

NW      LACL    flashAlgoVars.ADDR              ;ACC = (address of previous word programmed).
        ADD     #1                              ;INCREMENT ADDR
        SACL    flashAlgoVars.ADDR              ;STORE ADDR OF NEXT WORD

        SPLK    #MX_PCNT,flashAlgoVars.PLS_CNT  ;Initialize PROGRAM PULSE COUNT 
        B       PGVERON                         ;begin prog of next word


;--------------------------------------------------------------------------------------------------
; PROG: Program subroutine.
;--------------------------------------------------------------------------------------------------
; This is a LEVEL4 subroutine.
;--------------------------------------------------------------------------------------------------
;       
;    1.     This subroutine applies programming pulses to the flash word based on
;        the bitmask built by the caller and placed in flashAlgoVars.DATA.
;
;    2.  The pulses are applied to the main array or the redundant rows depending  
;          on the status of flashAlgoVars.FL_CMD.
;        FL_CMD = 0080h (NOROWRED) programs the bits in the main array.
;        FL_CMD = 0100h (PRECON).
;--------------------------------------------------------------------------------------------------
PROG    LACC    #WDATA                          ;Load data to be prog
        TBLW    flashAlgoVars.DATA              ;Write data to the WDATA register.

        LACC    flashAlgoVars.FL_CMD            ;Get the flash command.
        XOR     #0003h                          ;Add in the bits for the PROG mode.
        SACL    flashAlgoVars.PAD

        LACC    #CTRL                           ;Init prog mode 
        TBLW    flashAlgoVars.PAD            
        SDELAY  #T_psu_p                        ;Wait T_psu(P)

        LACC    #PMPC                           ;Turn on prog voltages
        SPLK    #0005h,flashAlgoVars.PAD    
        TBLW    flashAlgoVars.PAD

PPW     SDELAY  #T_prog_e1                      ;PROG pulse width part 1
        SDELAY  #T_prog_e2                      ;PROG pulse width part 2

        SPLK    #0000h,flashAlgoVars.PAD        ;Turn off PROG Voltages.
        TBLW    flashAlgoVars.PAD

        SDELAY  #Tph_P                          ;Wait T_ph(P)     (HOLD TIME).

        SPLK    #0001h,flashAlgoVars.PAD1       ;Clear PMPC and CTRL.
        CALL    CLRCMD                          ;Since PMPC is 0s already from above,
                                                ;really the only thing affected is CTRL

        SDELAY  #Tph_A                          ;Wait in normal read mode.


        RET                                     





;--------------------------------------------------------------------------------------------------
; READWORD
; This routine performs the following operations
;    1. Reads the word at the location pointed to by flashAlgoVars.ADDR.
;    2. Stores the word in the variable READ.
;    3. Returns to the caller in Register Mode.
;    This is a LEVEL4 subroutine.
;--------------------------------------------------------------------------------------------------
READWORD:
        ACCESS_ARRAY
        LACC    flashAlgoVars.ADDR              ;Read word flash 
        TBLR    flashAlgoVars.READ              ;store word in READ (data space)
        ACCESS_REGS
        RET
;--------------------------------------------------------------------------------------------------
;    END1:                                       
;     This routine performs the following operations
;   1.  Clears the control registers PMPC,CNTL,WADDR,WDATA,ENABLE AND SECTOR)
;   2.  Returns to the caller in ARRAY Mode.
;--------------------------------------------------------------------------------------------------
END1:   SPLK    #0006h,flashAlgoVars.PAD1       ;CLEAR ALL SIX 
        CALL    CLRCMD
        ACCESS_ARRAY
        RET

;--------------------------------------------------------------------------------------------------
; CLRCMD
;--------------------------------------------------------------------------------------------------
;     This routine performs the following operations
;   1.  Places the flash in normal read mode by writing 0000 to two control 
;       registers PMPC=0000,CNTL=0000.
;   2.  Returns to the caller in Register Mode.
;--------------------------------------------------------------------------------------------------
CLRCMD: ACCESS_REGS
        SPLK    #0,flashAlgoVars.PAD
        LACC    #0
        RPT     flashAlgoVars.PAD1
        TBLW    flashAlgoVars.PAD
        RET

        .label  ClearAlgoEndMain

        .sect    "CSPL_text"
SETWADDR:
        .label  ClearAlgoStartSpl
        TBLW    flashAlgoVars.ADDR              ;Perform the write to the address register.
        RET
        .label  ClearAlgoEndSpl


⌨️ 快捷键说明

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