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

📄 pgm_alg.asm

📁 TMS320C2000Flash操作
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;
; 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 
;          happens with WDATA = 1 for this bit.
;
;--------------------------------------------------------------------------------------------------
GET_DATA:
        LAR     AR2,flashAlgoVars.DATA_PTR              ;Load AR2 with the address of the data.
        BLDD    *,#flashAlgoVars.DATA                   ;Load DATA with the intended contents.
;--------------------------------------------------------------------------------------------------
; Zero Bit Error Check:
; A zero bit error is defined as occurring when a bit in flash is a zero, when its intended value
; as defined by the RAM buffer is a one. 
; The function used to detect this is err= (!READ).(DATA)
; If non zero, a zero bit error is defined as having occurred.
; This needs to be checked once per word. This avoids application of MAX_PCNT pulses to a cell
; that is a zero, but is a one in the RAM buffer.
;--------------------------------------------------------------------------------------------------
ZERO_BIT_ERROR_CHK:
        LACL    flashAlgoVars.READ                      ;Get the value read out during the verify.
        XOR     #0ffffh                                 ;Invert read out from flash.
        AND     flashAlgoVars.DATA                      ;ACC= (!READ).(DATA)

        BCND    ZERO_BIT_ERROR,NEQ                      ;Branch to the corresponding error handler
                                                        ;when this error happens.
;--------------------------------------------------------------------------------------------------
COMPARE:
        LACL    flashAlgoVars.READ                      ;Get the value read out during the verify.
        XOR     flashAlgoVars.DATA                      ;XOR the read out value with the desired
                                                        ;data.

        BCND    NEXTWORD,EQ                             ;If ==0 then this word is done pgm-ing,
                                                        ;if not start building the mask.

        LACC    flashAlgoVars.READ                      ;Get the contents READ from flash.
        XOR     #0ffffh                                 ;ACC = !Flash.
        OR      flashAlgoVars.DATA                      ;ACC = !FLASH + Data. i.e. ACC = MASK.
        SACL    flashAlgoVars.DATA                      ;Store mask in DATA, since PROG expects
                                                        ;the mask there.
        CALL    PROG              
;--------------------------------------------------------------------------------------------------
; PGCNT:
;--------------------------------------------------------------------------------------------------
;   This routine keeps track of the number of pulses applied to the flash memory location. If 
;   number of pulses allowed reaches zero, error handling is commenced. Otherwise the program 
;   pulse counter is decremented and one more cycle is commenced.
;--------------------------------------------------------------------------------------------------
PGCNT:  LACC    flashAlgoVars.PLS_CNT                   ;Get the number of pulses remaining.
        SUB     #1                                      ;Decrement the pulse counter
        SACL    flashAlgoVars.PLS_CNT                   ;and store it back.
        BCND    PULSE_LIMIT_ERROR,EQ                    ;If zero, then branch to error handling.
        B       PGVERON                                 ;else, verify the word programmed.

;--------------------------------------------------------------------------------------------------
; NEXTWORD
;--------------------------------------------------------------------------------------------------
; This section checks if the last address in the block is done.
; If not increments the address and loops back to program the next word.
;--------------------------------------------------------------------------------------------------
NEXTWORD:
        LACC    flashAlgoVars.FL_SECEND                 ;Get the counter.
        SUB     #1                                      ;and advance it.
        SACL    flashAlgoVars.FL_SECEND

        BCND    NW,NEQ                                  ;If the counter is non-zero, more words in
                                                        ;this block remain to be programmed. So
                                                        ;proceed to program the next word.

        B       END1                                    ;Other wise exit the programming routine.
;--------------------------------------------------------------------------------------------------
NW      LACC    flashAlgoVars.ADDR                      ;Get the address variable and increment
        ADD     #1                                      ;the address counter and store it back.
        SACL    flashAlgoVars.ADDR                      ;

        SPLK    #MX_PCNT,flashAlgoVars.PLS_CNT          ;Initialize the Program Pulse Counter.

        LACC    flashAlgoVars.DATA_PTR                  ;Increment the pointer into the buffer
        ADD     #1                                      ;containing the programming data.
        SACL    flashAlgoVars.DATA_PTR
    
        B       PGVERON                                 ;begin prog of next word
;--------------------------------------------------------------------------------------------------
; Program:
;--------------------------------------------------------------------------------------------------
;       This subroutine applies a single program pulse to the flash word at 
;       the address ADDR.
;       DATA contains the bitmask for the pulses. 
;--------------------------------------------------------------------------------------------------
PROG    LACC    #WDATA                                  ;Load data to be prog
        TBLW    flashAlgoVars.DATA

        LACC    flashAlgoVars.FL_CMD
        XOR     #0003h                                  ;PROG CMND
        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 CNTL
        CALL    CLRCMD


        SDELAY  #Tph_A                                  ;Wait in normal read mode.


        RET
;--------------------------------------------------------------------------------------------------
; Handles the error code generation for the case when bit(s) cannot be programmed even after
; the application of the maximum allowed pulses.
;--------------------------------------------------------------------------------------------------
PULSE_LIMIT_ERROR:
        SPLK    #0005h,flashAlgoVars.PAD1
        CALL    CLRCMD

        SPLK    #3,flashAlgoVars.ALGO_STATUS    
        ACCESS_ARRAY
        MAR     *,AR1
        B       STACK_RESTORE
;--------------------------------------------------------------------------------------------------
; Handles the error code generation for the case when a zero bit error has occurred.
; A zero bit error is defined as occurring when a bit in flash is a zero, when its intended value
; as defined by the RAM buffer is a one. 
;--------------------------------------------------------------------------------------------------
ZERO_BIT_ERROR:
        SPLK    #0005h,flashAlgoVars.PAD1
        CALL    CLRCMD

        SPLK    #4,flashAlgoVars.ALGO_STATUS    
        ACCESS_ARRAY
        MAR     *,AR1
        B       STACK_RESTORE

;--------------------------------------------------------------------------------------------------
; READWORD
;--------------------------------------------------------------------------------------------------
; This routine performs the following operations
;    1.    Reads the word at the location pointed to by ADDR.
;    2.  Stores the word in the variable READ.
;    3.  Returns to the caller in Register Mode.
;--------------------------------------------------------------------------------------------------
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:   LACC    flashAlgoVars.ADDR                      ;Get the address variable and increment
        ADD     #1                                      ;the address counter and store it back.
        SACL    flashAlgoVars.ADDR                      ;

        SPLK    #0006h,flashAlgoVars.PAD1               ;Clear 6 regs.
        CALL    CLRCMD
        
        SPLK    #0,flashAlgoVars.ALGO_STATUS            ;Zero error code, since programming
                                                        ;completed successfully.
        ACCESS_ARRAY                                    
        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








;--------------------------------------------------------------------------------------------------
; CLRCMD
;--------------------------------------------------------------------------------------------------
;     This routine performs the following operations
;   1.     Places the flash in normal read mode by writing 0000 to two control 
;        registers PMPC,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  ProgramAlgoEndMain

        .sect   "PSPL_text"
SETWADDR:
        .label  ProgramAlgoStartSpl
        TBLW    flashAlgoVars.ADDR        
        RET
        .label  ProgramAlgoEndSpl

⌨️ 快捷键说明

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