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

📄 f_amd_arm.s

📁 realview22.rar
💻 S
📖 第 1 页 / 共 2 页
字号:
; ============================================================================
; F_AMD_ARM - Flash programming algorithm for AMD Flash 
;
; Library Name: Included into container .s file.
;
; Module Name:  F_AMD_ARM.S
; Module Descr: Flash programming for AMD Flash
; Creation Date:2003
; Author:       Nick Milner
;
; THIS INFORMATION IS PROPRIETARY TO
; ARM
; 110 Fulbourn Road
; Cambridge
; CB1 9NJ
; UK
;
; Revisions of F_AMD_ARM.S: (latest revision on top)
; #.#  Name  Date      Description
; ---  ----- --------  -----------------------------------------------------
;
; Implementation notes:
;
; GENERAL
; -------
;
; This file is to be included into another asm file which has the
; board/chip specific knowledge needed for initialization and the like.
; That is, this is the algorithm only.
;
; This file is based on information on AMD flash 
; of various forms. It is generalized to handle x8 and x16 accesses.
; It does not need to know the block sizes or positions as that is all
; passed in. 
;
; This uses the standard RVDEBUG implementation for an API. That
; means that registers are used for passing arguments and returning
; status. The registers used are based on the save/restore list. The
; first registers are assumed to be the ones to use for passing args.
; In the case of ARM, this is R0, R1, R2, R3, etc.
;
; REGISTER MODEL
; --------------
;
;       The register model for this routine is as follows:
;       R0:     Input: page of Flash (not used on ARM)
;               Output:status return to host
;       R1:     Input: base address of Flash block to operate on
;       R2/R3/R4/R5/R8/R9: Input: arguments
;               Typical meanings: R2=Counter
;       R6/R7:Scratch
;
; -----------------------------------------------------------------------------
; Description:
; ----------------------------------------------------------------------------
;                               NOTICE
;
; This code is proprietary and secret; the use of this source is
; restricted, and all rights are reserved.
;
; If reading for interest, enjoy.
;
; If maintaining, read comments carefully! There are some inter-depen-
; dencies and connectivities. Areas with particular connection are marked.
; There are some variable protocols that are not self evident: check all uses
; of variables before making big changes.
; ============================================================================
;

;************************************************************************/
;* DEFINE ENTRY POINTS                                                  */
;************************************************************************/

;       EXPORT          FLASH_init      // provided by asm that includes us
;       EXPORT          FLASH_erase_all // not available
        EXPORT          FLASH_erase
        EXPORT          FLASH_write_erase
        EXPORT          FLASH_write
        EXPORT          FLASH_validate
        EXPORT          FLASH_break
;       EXPORT          FLASH_term      // we do not need one

;************************************************************************/
;* DEFINE MACROS AND EQUATES                                            */
;************************************************************************/

        IF              WIDTH=1
          MACRO
           STORE        $p1,$p2,$p3
            IF "$p3" = ""
             strb       $p1,$p2
            ELSE
             strb       $p1,$p2,$p3
            ENDIF
          MEND
          MACRO
           LOAD         $p1,$p2,$p3
            IF "$p3" = ""
             ldrb       $p1,$p2
            ELSE
             ldrb       $p1,$p2,$p3
            ENDIF
          MEND
        ENDIF

        IF              WIDTH=2
          MACRO
           STORE        $p1,$p2,$p3=0
            IF "$p3" = ""
             strh       $p1,$p2
            ELSE
             strh       $p1,$p2,$p3
            ENDIF
          MEND
          MACRO
           LOAD         $p1,$p2,$p3=0
            IF "$p3" = ""
             ldrh       $p1,$p2
            ELSE
             ldrh       $p1,$p2,$p3
            ENDIF
          MEND
        ENDIF

        IF              WIDTH=4
          MACRO
           STORE        $p1,$p2,$p3=0
            IF "$p3" = ""
             str        $p1,$p2
            ELSE
             str        $p1,$p2,$p3
            ENDIF
          MEND
          MACRO
           LOAD         $p1,$p2,$p3=0
            IF "$p3" = ""
             ldr        $p1,$p2
            ELSE
             ldr        $p1,$p2,$p3
            ENDIF
          MEND
        ENDIF

        IF :DEF: P_WIDTH
          IF P_WIDTH > 1
            MACRO
              EXPAND    $p1
                add $p1, $p1, $p1, lsl #16
                IF P_WIDTH=4
                  add $p1, $p1, $p1, lsl #8
                ENDIF
            MEND
          ENDIF
        ELSE
          MACRO
            EXPAND      $p1
          MEND
        ENDIF

;************************************************************************/
;* THE GLOBAL FUNCTIONS (EXPORTED PUBLICLY)                             */
;************************************************************************/
 
;* -----------------------------------------------------------------------
;  FLASH_erase - erase a Flash sector
;
;  Notes:
;     - this erases a Flash sector on request from host. The host has
;       the information on which end has the boot block and its size,
;       so we do not need to worry about that. 
;     - we may be asked to erase one or a set of blocks, but all will
;       have the same size.
;
;  Input/Output:
;     - In: R1=Base of 1st Flash Block to erase
;           R0=Page of Flash (no meaning for ARM)
;           R2=Count of blocks to do
;           R3=Size of blocks (for iterate)
;     - Out:R0=status code (0=OK, else error)
;     - Scratch: R6,R7
;  ----------------------------------------------------------------------- */

FLASH_erase
        bl      erase_block     ; erase block in R1

        subs    R2,R2,#1        ; count down
        addne   R1,R1,R4        ; setup for next block if more
        bne     FLASH_erase     ; more to do
        b       flash_exit      ; Stop routine on breakpoint

;* -----------------------------------------------------------------------
;  FLASH_write - write to a Flash sector
;  FLASH_write_erase - erase then write
;
;  Notes:
;     - this writes a buffer into a flash sector. The caller is responsible
;       for pre-erasing if needed.
;     - note: this is writing half-words and not bytes
;     - the host knows about block sizes and all, and passes in the needed
;       info.
;     - if we are writing into a later part of the block, this will be
;       handled by the host.
;
;  Input/Output:
;     - In: R1=Base of Flash Block to write
;           R0=Page of Flash (no meaning for ARM)
;           R2=Count of bytes to copy
;           R4=Offset in block to copy into (from base)
;           R5=Address of buffer to copy from
;           R8=Page of buffer (no meaning for ARM)
;           R9=0 if no verify, else same value as R2 (count)
;     - Out:R0=status code (0=OK, else error)
;     - Scratch: R6,R7
;  ----------------------------------------------------------------------- */


FLASH_write_erase
        bl      erase_block                     ; erase block in R1
FLASH_write

        add     R4,R4,R1                        ; compute start address

        mov     r0,r1,LSR#13
        mov     r0,r0,LSL#13                    ; R0 now has sector base with
                                                                                ; use Unlock bypass to shorten program sequence

                
        ldr     R7,=0x555                       ; address msg 1
        add     R7,R0,R7,LSL#2                          
        mov     R6,#0xAA                        ; data msg 1
        EXPAND  R6
        STORE   R6,[R7]                         ; send command
        
        ldr     R7,=0x2AA                       ; address msg 2
        add     R7,R0,R7,LSL#2                          
        mov     R6,#0x55                        ; data msg 2
        EXPAND  R6                                              
        STORE   R6,[R7]                         ; send command

        ldr     R7,=0x555                       ; address msg 3
        add     R7,R0,R7,LSL#2                          
        mov     R6,#0x20                        ; data msg 3
        EXPAND  R6
        STORE   R6,[R7]                         ; send command

write_loop

        LOAD    R7,[R5],#WIDTH                  ; load first value from buffer then inc

        mov     R6,#0xA0                        ; First message for unlock bypass program
        EXPAND  R6
        STORE   R6,[R4]                         ; send command
        
        STORE   R7,[R4],#WIDTH                  ; write value desired then inc

        bl      wait_for_ready_program  ; wait for Flash to finish write
                ;mov     r0,#0x0
        subs    R2,R2,#WIDTH                    ; decrement count, more?

⌨️ 快捷键说明

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