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

📄 sst39sf040.txt

📁 很全的flash芯片驱动程序包括:SST28SF040
💻 TXT
📖 第 1 页 / 共 2 页
字号:
                CurrData = *Dst;
                CurrData = CurrData & 0x80;
                if (TrueData == CurrData)
                        Loop = FALSE;   /* ready to exit the while loop  */
                TimeOut++;
        }
}



8086 ASSEMBLY LANGUAGE DRIVERS

; ======================================================================
; Copyright Silicon Storage Technology, Inc. (SST), 1994-2001
; EXAMPLE 8086 Assembly Language Drivers for 39SF040 4 Mbit(512 x 8) 
; Multi-Purpose Flash 
; Frank Cirimele,  Silicon Storage Technology, Inc.
;
; Revision 1.0,  Sept. 12, 2000
;
; This file requires these external "timing" routines:
;
;       1.)  Delay_150_Nano_Seconds
;       2.)  Delay_25_Milli_Seconds
;       3.)  Delay_100_Milli_Seconds
; ======================================================================

SECTOR_SIZE             EQU     4096    ; Must be 4096 bytes for 39SF040

SST_ID                  EQU     0BFh    ; SST Manufacturer's ID code
SST_39SF040             EQU     0B7h    ; SST 39SF040 device code
CHIP_ERASE_COMMAND      EQU     010h
SECTOR_ERASE_COMMAND    EQU     030h

ABS_SEGMENT     EQU     0A000h

extrn   Delay_150_Nano_Seconds:near
extrn   Delay_25_Milli_Seconds:near
extrn   Delay_100_Milli_Seconds:near


;=======================================================================
; PROCEDURE:    Check_SST_39SF040
;
; This procedure decides whether a physical hardware device has a SST's
; 39SF040 4 Mbit(512 x 8) Multi-Purpose Flash installed or not.
;
; Input:
;       None
;
; Output:
;       carry bit:   CLEARED means a SST 39SF040 is installed
;       carry bit:   SET means NOT a SST 39SF040 is NOT installed
;
;=======================================================================

Check_SST_39SF040      proc    near

        push    ax                              ; preserve registers?value
        push    ds
	pushf					; save interrupt state

	; It is mandatory to maintain pushf as the last push instruction.

        cli
        mov     ax, ABS_SEGMENT
        mov     ds, ax

        mov     ds:byte ptr [5555h], 0AAh       ; issue the 3-byte product ID
        mov     ds:byte ptr [2AAAh], 055h       ;  command to the 39SF040
        mov     ds:byte ptr [5555h], 090h

        call    Delay_150_Nano_Seconds          ; insert delay = Tida

        mov     al, ds:[0]
        cmp     al, SST_ID                      ; is this a SST part?
        jne     CSC5                            ; NO, then return Carry set
        mov     al,ds:[1]
        cmp     al, SST_39SF040                 ; Is it a 39SF040?
        jne     CSC5                            ; NO, then Non-SST part and
						; set carry flag
CSC4:
        pop	ax				; get flags from stack
	and	ax, 0FFFEh			; and clear carry flag
        jmp     short CSC6

CSC5:
        pop	ax				; get flags from stack
	or	ax, 0001h			; and set carry flag
   ; save the result on the STACK
       
CSC6:
	push	ax				; return flags to stack

;
; Issue the Software Product ID Exit code thus returning the 39SF040
; to the read operation mode.
;

        mov     ds:byte ptr [5555h], 0AAh       ; issue the 3-byte product ID
        mov     ds:byte ptr [2AAAh], 055h       ;  exit command sequence to
        mov     ds:byte ptr [5555h], 0F0h	;  the 39SF040

        call    Delay_150_Nano_Seconds          ; insert delay = Tida


        popf                                    ; restore flags
        pop     ds                              ; restore registers
        pop     ax

        ret

Check_SST_39SF040 endp


; =====================================================================
; PROCEDURE:    Erase_Entire_Chip
;
; This procedure can be used to erase the entire contents of
; SST's 39SF040.
;
; Input:
;       es:di   points to the beginning address of the 39SF040 chip
;               which will be erased.
;
; Output:
;       None
; =====================================================================

Erase_Entire_Chip       proc    near

        mov     es:byte ptr [5555h], 0AAh	; issue 6-byte chip
        mov     es:byte ptr [2AAAh], 055h	;  erase command sequence
        mov     es:byte ptr [5555h], 080h
        mov     es:byte ptr [5555h], 0AAh
        mov     es:byte ptr [2AAAh], 055h
        mov     es:byte ptr [5555h], CHIP_ERASE_COMMAND

        call    Delay_100_Milli_Seconds         ; insert delay = Tsce

        ret

Erase_Entire_Chip       endp


; =====================================================================
; PROCEDURE:    Erase_One_Sector
;
; This procedure can be used to erase a sector, or total of 4096 bytes,
; in the SST39SF040.
;
; Input:
;       es:di   points to the beginning address of the "Destination" address
;               which will be erased.
;               ==> Note: The address MUST be on a sector boundary, 
;			  that is, a multiple of 4096.
;
; Output:
;       None
; =====================================================================

Erase_One_Sector        proc    near

        push    ax				; save register

        mov     es:byte ptr [5555h], 0AAh	; send 6-byte code for
        mov     es:byte ptr [2AAAh], 055h	;  sector erase
        mov     es:byte ptr [5555h], 080h
        mov     es:byte ptr [5555h], 0AAh
        mov     es:byte ptr [2AAAh], 055h
        mov     al, SECTOR_ERASE_COMMAND
        mov     byte ptr es:[di], al

        call    Delay_25_Milli_Seconds          ; insert delay = Tse

        pop     ax				; restore register

        ret

Erase_One_Sector        endp

; =====================================================================
; PROCEDURE:    Program_One_Byte
;
; This procedure can be used to program ONE byte of data to the 39SF040.
;
; NOTE:  It is necessary to first erase the sector containing the byte 
;	 to be programmed..
;
;
; Input:
;       al      BYTE which will be written into the 39SF040.
;       es:di   DESTINATION address which will be written with the
;               data input in al.
;
; Output:
;       None
;       ES, DI:  Contain their original values
; =====================================================================

Program_One_Byte          proc    near

        push    ax				; save registers
        push    ds
        mov     ax, ABS_SEGMENT			; set up ds register
        mov     ds, ax
        mov     ds:byte ptr [5555h], 0AAh       ; send 3 byte data protection
        mov     ds:byte ptr [2AAAh], 055h       ;  sequence to the chip
        mov     ds:byte ptr [5555h], 0A0h
        pop     ds
        pop     ax                      	; restore the byte to be 
						;  programmed from stack
        mov     byte ptr es:[di], al    	; program the byte
        call    check_Toggle_Ready      	; wait for valid TOGGLE bit 

        ret

Program_One_Byte          endp


; =====================================================================
; PROCEDURE:    Program_One_Sector
;
; This procedure can be used to program a memory sector, or total of 
; 4096 bytes, of the SST39SF040.
;
; Input:
;       ds:si   SOURCE address containing the data which will be
;               written into the 39SF040.
;       es:di   DESTINATION address which will be written with the
;               data passed in for ds:si
;
; Output:
;       None
;       SI, DI:  Contains their original values
; =====================================================================

Program_One_Sector        proc    near

        push    ax			; save registers
        push    di
        push    si
        pushf                   	; preserve the "Direction" flag 
        cld                     	; clear "Direction" flag to
                                	;  auto-increment SI and DI
;
; Erase the sector before programming.  Each erase command will erase a total
; of 4096 bytes for the 39SF040
;
        call    Erase_One_Sector
;
; The following loop will program a total of 4096 bytes to the SST39SF040
;
DRP1:
        push    ds
        mov     ax, ABS_SEGMENT
        mov     ds, ax
        mov     ds:byte ptr [5555h], 0AAh       ;3 bytes of  "enable protection"
        mov     ds:byte ptr [2AAAh], 055h       ;  sequence to the chip
        mov     ds:byte ptr [5555h], 0A0h
        pop     ds

        lodsb                           ; get the byte to be programmed
        mov     ax, di                  ; preserve original DI temporarily
        stosb                           ; program the byte
        push    di                      ; preserve incremented DI temporarily
        mov     di, ax			; restore original DI
        call    check_Toggle_Ready      ; wait for TOGGLE bit to get ready
        pop     di                      ; retrieve the updated DI
        loop    DRP1                    ; continue program more bytes until done

        popf				; restore original direction flag
        pop     si			; restore registers
        pop     di
        pop     ax

        ret

Program_One_Sector        endp


;======================================================================
; PROCEDURE:                    Check_Toggle_Ready
;
; During the internal program cycle, any consecutive read operation
; on DQ6 will produce alternating 0抯 and 1抯, i.e. toggling between
; 0 and 1. When the program cycle is completed, the DQ6 data will
; stop toggling. After the DQ6 data stops toggling, the device is ready
; for the next operation.
;
; Input:
;       es:di   must already set-up by the caller
;
; Output:
;       None
;======================================================================

Check_Toggle_Ready      proc    near

        push    ax		; save register

        mov     al, es:[di]     ; read a byte form the chip
        and     al,40h          ; mask out the TOGGLE bit (DQ6)

CTR_Tog2:
        mov     ah, es:[di]     ; read the same byte from the chip again
        and     ah, 40h         ; mask out the TOGGLE bit (DQ6)
        cmp     al, ah          ; is DQ6 still toggling?
        je      CTR_Tog3        ; No, then the write operation is done
        xchg    ah, al          ; YES, then continue checking...
        jmp     short CTR_Tog2

CTR_Tog3:
        pop     ax		; restore register

        ret

Check_Toggle_Ready      endp


;=======================================================================
; PROCEDURE:                    Check_Data_Polling
;
; During the internal program cycle, any attempt to read DQ7 of the last
; byte loaded during the page/byte-load cycle will receive the complement 
; of the true data.  Once the program cycle is completed, DQ7 will show 
; true data.
;
; Input:
;       es:di   must already be set-up by the caller
;       bl      contains the original (true) data
;
; Output:
;       None
;
;=======================================================================

Check_Data_Polling      proc    near

        push    ax		; save registers
        push    bx

        and     bl, 80h         ; mask out the DQ7 bit

CDP_Tog2:
        mov     al, es:[di]     ; read a byte from the chip
        and     al,80h          ; mask out the DQ7 bit
        cmp     al,bl           ; is DQ7 still complementing?
        jne     CDP_Tog2

        pop     bx		; restore registers
        pop     ax

        ret

Check_Data_Polling      endp


⌨️ 快捷键说明

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