Software Drivers 49LF008A 8 Mbit Firmware Hub with Top Boot-Block March 2003 ABOUT THE SOFTWARE This application note provides software driver examples for 49LF008A, 8 Mbit Firmware Hub with Top Boot-Block. This device is designed to interface with host controllers (chipsets) that supports a low-pin-count(LPC) interface for BIOS applications. Software driver examples used in this document utilize two programming languages: (a) high -level "C" for broad platform support and (b) optimized x86 assembly language. In many cases, software driver routines can be inserted "as is" into the main body of code being developed by the system software developers. Extensive comments are included in each routine to describe the function of each routine. The driver in "C" language can be used with many microprocessors and microcontrollers, while the x86 assembly language provides an optimized solution for x86 microprocessors. There are two hardware pins, WP# and TBL#, are provided for hardware write protection of device memory in FWH mode. The TBL# is used for the top boot block and needs to set to high (unprotected state) before programming. The WP# is used for the rest of memory and needs to set to high (unprotected state) before programming. ABOUT THE 49LF008A Companion product datasheets for the 49LF008A should be reviewed in conjunction with this application note for a complete understanding of the device. Both the C and x86 assembly code in the document contain the following routines, in this order: Name Function ------------------------------------------------------------------ Check_SST_49LF008A Check manufacturer and device ID Check_SST49LF008A_JedecIDs Check manufacturer and device ID by reading JEDEC ID registers Erase_Entire_Chip Erase the contents of the entire chip Erase_One_Sector Erase a sector of 4096 bytes Erase_One_Block Erase a block of 64 Kbytes Read_T_MINUS15_LK_Register Read status byte of T_MINUS15_LK_Register Block Locking Register Write_T_MINUS15_LK_Register Write status byte to T_MINUS15_LK_Register Block Locking Register Erase_Block_T_MINUS15 Erase the block of T_MINUS05 Program_One_Byte Alter data in one byte Program_One_Sector Alter data in 4096 bytes sector Program_One_Block Alter data in 64 Kbytes block Check_Toggle_Ready End of internal program or erase detection using Toggle bit Check_Data_Polling End of internal program or erase detection using Data# polling Read_SST49LF008A_GPI_Register Fetch the content of GPI Register */ //"C" LANGUAGE DRIVERS /***********************************************************************/ /* Copyright Silicon Storage Technology, Inc. (SST), 1994-2003 */ /* Example "C" Language Drivers of 49LF008A, 8 Mbit Firmware Hub Flash */ /* Read-Compatible Flash */ /* Nelson Wang, Silicon Storage Technology, Inc. */ /* */ /* Revision 1.1, March 31, 2003 */ /* */ /* This file requires these external "timing" routines: */ /* */ /* 1.) Delay_150_Nano_Seconds */ /* 2.) Delay_25_Milli_Seconds */ /* 3.) Delay_100_Milli_Seconds */ /***********************************************************************/ #define FALSE 0 #define TRUE 1 #define SECTOR_SIZE 4096 /* Must be 4 Kbytes for 49LF008A */ #define BLOCK_SIZE 65536 /* Must be 64 Kbytes for 49LF008A */ #define SST_ID 0xBF /* SST Manufacturer's ID code */ #define SST_49LF008A 0x5A /* 49LF008A device code */ #define SST_49LF008A_M_ID 0xFFBC0000 /* 49LF008A Manufacturer's ID */ /* register address for boot device, FWH mode*/ /*should be modified by user for other strapping*/ #define SST_49LF008A_D_ID 0xFFBC0001 /* 49LF008A Device ID */ /* register address for boot device, FWH mode */ /*should be modified by user for other strapping*/ #define SST_49LF008A_GPI 0xFFBC0100 /* 49LF008A GPI register address */ /* for boot device, FWH mode */ #define SST_49LF008A_T_MINUS15_LKReg 0xFFB00002 /*49LF008A Locking Register*/ /*for block15 of the boot device should be*/ /*modified by user for other strapping or other block*/ typedef unsigned char BYTE; typedef unsigned long int Uint32; Uint32 system_base = 0xFFF00000; /* 4GB System Memory Address for boot device*/ /* in FWH mode. It should be modified by user for other memory strapping*/ #define sysAddress(offset) (*(volatile BYTE *)(system_base + offset)) /* -------------------------------------------------------------------- */ /* EXTERNAL ROUTINES */ /* -------------------------------------------------------------------- */ extern void Delay_150_Nano_Seconds(); extern void Delay_25_Milli_Seconds(); extern void Delay_100_Milli_Seconds(); int Check_Toggle_Ready (Uint32 Dst); /************************************************************************/ /* PROCEDURE: Check_SST_49LF008A (PP/FWH mode) */ /* */ /* This procedure decides whether a physical hardware device has a */ /* SST 49LF008A 8 Mbit Firmware Hub Flash installed or not. */ /* Input: */ /* None */ /* */ /* Output: */ /* return TRUE: indicates a SST 49LF008A */ /* return FALSE: indicates not a SST 49LF008A */ /************************************************************************/ int Check_SST_49LF008A() { BYTE SST_id1; BYTE SST_id2; int ReturnStatus; /* Issue the Software Product ID code to 49LF008A */ sysAddress(0x5555) = 0xAA; /* write data 0xAA to device addr 0x5555*/ sysAddress(0x2AAA) = 0x55; /* write data 0x55 to device addr 0x2AAA*/ sysAddress(0x5555) = 0x90; /* write data 0x90 to device addr 0x5555*/ Delay_150_Nano_Seconds(); /* Tida Max 150ns for 49LF008A*/ /* Read the product ID from 49LF008A */ SST_id1 = sysAddress(0x0000); /* get first ID byte */ SST_id2 = sysAddress(0x0001); /* get second ID byte */ /* Determine whether there is a SST 49LF008A installed or not */ if ((SST_id1 == SST_ID) && (SST_id2 ==SST_49LF008A)) ReturnStatus = TRUE; else ReturnStatus = FALSE; /* Issue the Soffware Product ID Exit code thus returning the */ /* 49LF008A to the normal operation */ sysAddress(0x5555) = 0xAA; /* write data 0xAA to device addr 0x5555*/ sysAddress(0x2AAA) = 0x55; /* write data 0x55 to device addr 0x2AAA*/ sysAddress(0x5555) = 0xF0; /* write data 0xF0 to device addr 0x5555*/ Delay_150_Nano_Seconds(); /* Tida Max 150ns for 49LF008A*/ return (ReturnStatus); } /************************************************************************/ /* PROCEDURE: Check_SST49LF008A_JedecIDs (FWH mode) */ /* */ /* This procedure decides whether a physical hardware device has a */ /* SST 49LF008A 8 Mbit FWH Flash installed or not by reading JEDEC */ /* ID registers of Boot Device (Device #0). */ /* */ /* For Boot Configuration from Top of the 4 Gbytes System Memory, the */ /* address of Manufacturer ID Register(M-ID) = FFBC0000H, and the */ /* address of Device ID Register(D-ID) = FFBC0001H. */ /* */ /* Input: */ /* None */ /* */ /* Output: */ /* return TRUE: indicates a SST49LF008A */ /* return FALSE: indicates not a SST49LF008A */ /************************************************************************/ int Check_SST49LF008A_JedecIDs() { BYTE SST_id1; BYTE SST_id2; int ReturnStatus; SST_id1 = *(volatile BYTE *)(SST_49LF008A_M_ID); /*get first ID byte */ SST_id2 = *(volatile BYTE *)(SST_49LF008A_D_ID); /*get second ID byte*/ /* Determine whether there is a SST 49LF008A installed or not */ if ((SST_id1 == SST_ID) && (SST_id2 ==SST_49LF008A)) ReturnStatus = TRUE; else ReturnStatus = FALSE; return (ReturnStatus); } /************************************************************************/ /* PROCEDURE: Erase_Entire_Chip (PP Mode only) */ /* */ /* This procedure can be used to erase the entire chip. Chip-Erase is */ /* only available in PP mode. */ /* */ /* Input: */ /* NONE */ /* */ /* Output: */ /* NONE */ /************************************************************************/ void Erase_Entire_Chip() { /* Issue the Sector Erase command to 49LF008A */ sysAddress(0x5555) = 0xAA; /* write data 0xAA to device addr 0x5555*/ sysAddress(0x2AAA) = 0x55; /* write data 0x55 to device addr 0x2AAA*/ sysAddress(0x5555) = 0x80; /* write data 0x80 to device addr 0x5555*/ sysAddress(0x5555) = 0xAA; /* write data 0xAA to device addr 0x5555*/ sysAddress(0x2AAA) = 0x55; /* write data 0x55 to device addr 0x2AAA*/ sysAddress(0x5555) = 0x10; /* write data 0x10 to device addr 0x5555*/ Delay_100_Milli_Seconds(); /* 70ms typical for chip erase */ } /************************************************************************/ /* PROCEDURE: Erase_One_Sector (FWH/PP Mode) */ /* */ /* This procedure can be used to erase a total of 4096 bytes. */ /* */ /* In FWH mode, the block containning the sector to be erased needs to */ /* be unlocked first. Please refers the sample routine */ /* Erase_Block_T_MINUS15() for a detail of usage. */ /* */ /* Input: */ /* Dst device address at which the sector erase */ /* operations will start. */ /* */ /* Output: */ /* NONE */ /************************************************************************/ void Erase_One_Sector(Uint32 Dst) { /* Issue the Sector Erase command to 49LF008A */ sysAddress(0x5555) = 0xAA; /* write data 0xAA to device addr 0x5555*/ sysAddress(0x2AAA) = 0x55; /* write data 0x55 to device addr 0x2AAA*/ sysAddress(0x5555) = 0x80; /* write data 0x80 to device addr 0x5555*/ sysAddress(0x5555) = 0xAA; /* write data 0xAA to device addr 0x5555*/ sysAddress(0x2AAA) = 0x55; /* write data 0x55 to device addr 0x2AAA*/ sysAddress(Dst) = 0x30; /* write data 0x30 to device sector addr*/ Delay_25_Milli_Seconds(); /* Max Tse 25 ms */ } /************************************************************************/ /* PROCEDURE: Erase_One_Block (FWH/PP Mode) */ /* */ /* This procedure can be used to erase a total of 64 Kbytes. */ /* */ /* In FWH mode, the block to be erased needs to be unlocked first. */ /* Please refers the sample routine */ /* Erase_Block_T_MINUS15() for a detail of usage. */ /* */ /* For FWH mode, please refer to subroutine Erase_Block_T_MINUS15() */ /* for a detailed description. */ /* */ /* Input: */ /* Dst device address at which the block erase */ /* operation will start. */ /* */ /* Output: */ /* NONE */ /************************************************************************/ void Erase_One_Block(Uint32 Dst) { /* Issue the Block Erase command to 49LF008A */ sysAddress(0x5555) = 0xAA; /* write data 0xAA to device addr 0x5555*/ sysAddress(0x2AAA) = 0x55; /* write data 0x55 to device addr 0x2AAA*/ sysAddress(0x5555) = 0x80; /* write data 0x80 to device addr 0x5555*/ sysAddress(0x5555) = 0xAA; /* write data 0xAA to device addr 0x5555*/ sysAddress(0x2AAA) = 0x55; /* write data 0x55 to device addr 0x2AAA*/ sysAddress(Dst) = 0x50; /* write data 0x50 to device block addr */ Delay_25_Milli_Seconds(); /* Max Tbe 25 ms */ } /************************************************************************/ /* PROCEDURE: Read_T_MINUS15_LK_Register (FWH mode) */ /* */ /* This sample subroutine reads the status byte of block register */ /* T_MINUS15_LK_Register from the Boot Device(Device #0) of SST49LF008A */ /* */ /* The address of T_MINUS15_LK_Register = FFB00002H */ /* */ /* Input: */ /* None */ /* */ /* Output: */ /* return status byte */ /************************************************************************/ BYTE Read_T_MINUS15_LK_Register() { return (*(volatile BYTE *)(SST_49LF008A_T_MINUS15_LKReg)); } /************************************************************************/ /* PROCEDURE: Write_T_MINUS15_LK_Register (FWH mode) */ /* */ /* This sample subroutine writes new status byte to block locking reg. */ /* T_MINUS15_LK_Register of Boot Device(Device #0) of SST49LF008A */ /* */ /* The address of T_MINUS15_LK_Register = FFB00002H */ /* */ /* Input: */ /* Status the new status byte to be written */ /* */ /* Output: */ /* None */ /************************************************************************/ void Write_T_MINUS15_LK_Register(BYTE Status) { *(volatile BYTE *)(SST_49LF008A_T_MINUS15_LKReg) = Status; } /************************************************************************/ /* PROCEDURE: Erase_Block_T_MINUS15 (FWH Mode) */ /* */ /* This sample subroutine can be used to erase the block of T_MINUS15 */ /* in Boot Device (Devoce #0) of SST49LF008A in FWH mode. */ /* */ /* SST49LF008A has 16 uniform, 64 KByte blocks: T_BLOCK, T_MINUS01 -- */ /* T_MINUS15. */ /* */ /* The block of T_MINUS15 has an address range from FFF0FFFFH -- */ /* FFF00000H in the System of 4Gbytes Memory Map and its block locking */ /* register: T_MINUS15_LK_Register = FFB00002H. */ /* */ /* Before erasing the block, the user needs to unlock the block first. */ /* To unlock the block, the user needs to refer two sample subroutines */ /* Read_T_MINUS15_LK_Register() and Write_T_MINUS15_LK_Register(). */ /* */ /* Input: */ /* Dst DESTINATION address at which the erase operation will */ /* start. */ /* Output: */ /* return TRUE: indicate the erase of T_MINUS15 block is success */ /* return FALSE: indicate the block erase is failed */ /************************************************************************/ int Erase_Block_T_MINUS15() { BYTE data1; /* read the status byte from T_MINUS15_LK_Register */ data1 = Read_T_MINUS15_LK_Register(); data1 &= 0x03; /* mask D[7:2] of status byte */ if (data1 == 0x03) { /* 0x03: the Write Lock Bit is lock-down */ return (FALSE); /* return FALSE to indicate Block-erase is failed */ } if (data1 == 0x01) /* 0x01: the Write Lock Bit is set */ { /* To unlock the block, write 0x00 to block locking register */ Write_T_MINUS15_LK_Register( 0x00 ); data1 = Read_T_MINUS15_LK_Register(); /* read the status byte */ data1 &= 0x03; /* mask D[7:2] of status */ if (data1 != 0x00) { /* unlock the block is failed */ return (FALSE); } } /* point to a valid address of block T_MINUS15 which is range */ /* from FFF0FFFFH -- FFF00000H */ Erase_One_Block(0xFFF00000); /* Issue the Block Erase command to 49LF008A */ return (TRUE); } /************************************************************************/ /* PROCEDURE: Program_One_Byte (FWH/PP Mode) */ /* */ /* This procedure can be used to program ONE byte of data to the */ /* 49LF008A. */ /* */ /* In FWH mode, the block containning the byte to be programmed needs */ /* to be unlocked first. Please refer the sample routine */ /* Erase_Block_T_MINUS15() for a detail of usage. */ /* */ /* NOTE: It is mandatory that the sector containing the byte to be */ /* programmed was ERASED first. */ /* */ /* Input: */ /* Src The BYTE which will be written to the 49LF008A. */ /* Dst device address which will be written */ /* with the data passed in from SrcByte */ /* */ /* Output: */ /* None */ /************************************************************************/ void Program_One_Byte (BYTE *Src, Uint32 Dst) { Uint32 DestBuf = Dst; BYTE *SourceBuf = Src; sysAddress(0x5555) = 0xAA; /* write data 0xAA to device addr 0x5555*/ sysAddress(0x2AAA) = 0x55; /* write data 0x55 to device addr 0x2AAA*/ sysAddress(0x5555) = 0xA0; /* write data 0x80 to device addr 0x5555*/ sysAddress(DestBuf) = *SourceBuf;/* transfer the byte to destination*/ Check_Toggle_Ready(DestBuf);/* wait for TOGGLE bit to get ready */ } /************************************************************************/ /* PROCEDURE: Program_One_Sector (FWH/PP Mode) */ /* */ /* This procedure can be used to program a total of 4096 bytes of data */ /* to the SST's 49LF008A. */ /* */ /* In FWH mode, the block to be programmed needs to be unlocked first. */ /* Please refers the sample routine */ /* Erase_Block_T_MINUS15() for a detail of usage. */ /* */ /* Input: */ /* Src source buffer containing the data which will be */ /* written to the 49LF008A. */ /* Dst device address which will be written with the */ /* data passed in from Src */ /* */ /* Output: */ /* None */ /************************************************************************/ void Program_One_Sector ( BYTE *Src, Uint32 Dst) { BYTE *SourceBuf; Uint32 DestBuf; int Index; SourceBuf = Src; DestBuf = Dst; Erase_One_Sector(DestBuf); /* erase the sector first */ for (Index = 0; Index < SECTOR_SIZE; Index++) { sysAddress(0x5555) = 0xAA; /* write data 0xAA to device addr 0x5555*/ sysAddress(0x2AAA) = 0x55; /* write data 0x55 to device addr 0x2AAA*/ sysAddress(0x5555) = 0xA0; /* write data 0x80 to device addr 0x5555*/ sysAddress(DestBuf) = *SourceBuf++;/*transfer the byte to destination*/ DestBuf++; Check_Toggle_Ready(DestBuf);/* wait for TOGGLE bit to get ready */ } } /************************************************************************/ /* PROCEDURE: Program_One_Block (FWH/PP Mode) */ /* */ /* This procedure can be used to program a total of 64 Kbytes of data */ /* to the SST's 49LF008A. */ /* */ /* Input: */ /* Src SOURCE address containing the data which will be */ /* written to the 49LF008A. */ /* Dst DESTINATION device address which will be written */ /* with the data passed in from Src */ /* */ /* Output: */ /* None */ /************************************************************************/ void Program_One_Block (BYTE *Src, Uint32 Dst) { BYTE *SourceBuf; int DestBuf; long Index; SourceBuf = Src; DestBuf = Dst; Erase_One_Block(Dst); /* erase the block first */ for (Index = 0L; Index < BLOCK_SIZE; Index++) { sysAddress(0x5555) = 0xAA; /* write data 0xAA to device addr 0x5555*/ sysAddress(0x2AAA) = 0x55; /* write data 0x55 to device addr 0x2AAA*/ sysAddress(0x5555) = 0xA0; /* write data 0x80 to device addr 0x5555*/ sysAddress(DestBuf) = *SourceBuf++;/* transfer the byte to destination*/ DestBuf++; Check_Toggle_Ready(DestBuf); /* wait for TOGGLE bit to get ready */ } } /************************************************************************/ /* PROCEDURE: Check_Toggle_Ready (FWH/PP Mode) */ /* */ /* During the internal program cycle, any consecutive read operation */ /* on DQ6 will produce alternating 0's and 1's i.e. toggling between */ /* 0 and 1. When the program cycle is completed, DQ6 of the data will */ /* stop toggling. After the DQ6 data bit stops toggling, the device is */ /* ready for next operation. */ /* */ /* Input: */ /* Dst must already be set-up by the caller */ /* */ /* Output: TRUE Data toggling success */ /* FALSE Time out */ /************************************************************************/ int Check_Toggle_Ready (Uint32 Dst) { BYTE PreData; BYTE CurrData; unsigned long TimeOut = 0; PreData = sysAddress(Dst); PreData = PreData & 0x40; /*read DQ6*/ while (TimeOut< 0x07FFFFFF) { CurrData = sysAddress(Dst); CurrData = CurrData & 0x40; /*read DQ6 again*/ if (PreData == CurrData) return TRUE; PreData = CurrData; TimeOut++; } return FALSE; } /************************************************************************/ /* PROCEDURE: Check_Data_Polling (FWH/PP Mode) */ /* */ /* 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: */ /* Dst must already be set-up by the caller */ /* TrueData this is the original (true) data */ /* */ /* Output: */ /* TRUE Data polling success */ /* FALSE Time out */ /************************************************************************/ int Check_Data_Polling (Uint32 Dst, BYTE TrueData) { BYTE CurrData; unsigned long int TimeOut = 0; TrueData = TrueData & 0x80; /*read D7*/ while (TimeOut< 0x07FFFFFF) { CurrData = sysAddress(Dst); CurrData = CurrData & 0x80; /*read DQ7*/ if (TrueData == CurrData) return TRUE; TimeOut++; } return FALSE; } /************************************************************************/ /* PROCEDURE: Read_SST49LF008A_GPI_Rigister (FWH Mode) */ /* */ /* This procedure fetches the content of GPI Reigster of the device, */ /* which is in the address 0xFFBC0100 for boot device. It's recommended */ /* that the GPI[4:0] pins be in the desired state before LFRAME# is */ /* brought low for the beginning of the next bus cycle, and remain in */ /* that state until the end of the cycle. */ /* */ /* Input: */ /* None */ /* Output: */ /* GPI register value */ /************************************************************************/ BYTE Read_SST49LF008_GPI_Rigister() { return ((*(volatile BYTE *)(SST_49LF008A_GPI)) & 0x1F);/*mask data[7:5]*/ } ; ====================================================================== ; Copyright Silicon Storage Technology, Inc. (SST), 1994-2003 ; EXAMPLE x86 Assembly Language Drivers for 49LF008A, 8 Mbit ; Firmware Hub Flash with Top Boot-Block ; Frank Cirimele, Silicon Storage Technology, Inc. ; ; Revision 1.1, March 31, 2003 ; ; 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 4 Kbytes for 49LF008A BLOCK_SIZE EQU 65536 ; Must be 64 Kbytes for 49LF008A SST_ID EQU 0BFh ; SST Manufacturer's ID code SST_49LF008A EQU 05Ah ; SST 49LF008A device code SST_49LF008A_GPI EQU 0FFBC0100h ; SST 49LF008A GPI address SST_49LF008A_M_ID EQU 0FFBC0000h ; SST 49LF008A Manufacturer's ID(for boot device) SST_49LF008A_D_ID EQU 0FFBC0001h ; SST 49LF008A Device ID(for boot device) SST_49LF008A_T_MINUS15_LKReg EQU 0FFB00002h ; SST 49LF008A Block15 Locking Register(boot device) CHIP_ERASE_COMMAND EQU 010h SECTOR_ERASE_COMMAND EQU 030h BLOCK_ERASE_COMMAND EQU 050h extrn ABS_SEGMENT ;system address of the device extrn Delay_150_Nano_Seconds:near extrn Delay_25_Milli_Seconds:near extrn Delay_100_Milli_Seconds:near ;======================================================================= ; PROCEDURE: Check_SST_49LF008A (FWH/PP mode) ; ; This procedure decides whether a physical hardware device has a SST's ; 49LF008A 8 Mbit Firmware Hub Flash installed or not. ; ; Input: ; None ; ; Output: ; carry bit: CLEARED means a SST 49LF008A is installed ; carry bit: SET means a SST 49LF008A is NOT installed ; ;======================================================================= Check_SST_49LF008A 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 ; 32bit address mov ds, ax mov ds:byte ptr [5555h], 0AAh ; issue the 3-byte product ID mov ds:byte ptr [2AAAh], 055h ; command to the 49LF008A 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_49LF008A ; Is it a 49LF008A? 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 49LF008A ; 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 49LF008A call Delay_150_Nano_Seconds ; insert delay = Tida popf ; restore flags pop ds ; restore registers pop ax ret Check_SST_49LF008A endp ;======================================================================= ; PROCEDURE: Check_SST49LF008A_JedecIDs (FWH mode) ; ; This procedure decides whether a physical hardware device has a SST's ; 49LF008A 8 Mbit Firmware Hub Flash installed or not. ; ; Input: ; None ; ; Output: ; carry bit: CLEARED means a SST 49LF008A is installed ; carry bit: SET means a SST 49LF008A is NOT installed ; ;======================================================================= Check_SST49LF008A_JedecIDs proc near push ax ; preserve registers’ value push ds pushf ; save interrupt state ; It is mandatory to maintain pushf as the last push instruction. mov al, byte ptr[SST_49LF008A_M_ID] ; 32bit address cmp al, SST_ID ; is this a SST part? jne CSJ2 ; NO, then return Carry set mov al,byte ptr[SST_49LF008A_D_ID] ; 32bit address cmp al, SST_49LF008A ; Is it a 49LF008A? jne CSJ2 ; NO, then Non-SST part and ; set carry flag CSJ1: pop ax ; get flags from stack and ax, 0FFFEh ; and clear carry flag jmp short CSJ3 CSJ2: pop ax ; get flags from stack or ax, 0001h ; and set carry flag CSJ3: push ax ; return flags to stack popf ; restore flags pop ds ; restore registers pop ax ret Check_SST49LF008A_JedecIDs endp ; ===================================================================== ; PROCEDURE: Erase_Entire_Chip (PP Mode ONLY) ; ; This procedure can be used to erase the entire contents of ; SST's 49LF008A. Chip-Erase is only available in PP mode. ; ; Input: ; es:di points to the beginning address of the 49LF008A 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 (FWH/PP Mode) ; ; This procedure can be used to erase a sector, or total of 4096 bytes, ; in the SST49LF008A. ; ; In FWH mode, the block containning the sector to be erased needs to be ; unlocked first. Please refers the subroutine: ; Erase_Block_T_Minus15 for a detail of usage. ; ; Input: ; es:di points to the beginning address of the "Destination" address ; which will be erased. ; 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: Erase_One_Block (FWH/PP Mode) ; ; This procedure can be used to erase a block, or total of 64 Kbytes, ; in the SST49LF008A. ; ; In FWH mode, the block to be erased needs to be unlocked first. ; Please refers the subroutine: ; Erase_Block_T_Minus15 for a detail of usage. ; ; Input: ; es:di points to the beginning address of the "Destination" block ; which will be erased. ; ; Output: ; None ; ===================================================================== Erase_One_Block 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, BLOCK_ERASE_COMMAND mov byte ptr es:[di], al call Delay_25_Milli_Seconds ; insert delay = Tbe pop ax ; restore register ret Erase_One_Block endp ; ===================================================================== ; PROCEDURE: Read_T_MINUS15_LK_Register (FWH mode) ; ; This sample subroutine reads the status byte of block register ; T_MINUS15_LK_Register from the Boot Device(Device #0) of SST49LF008A ; ; The address of T_MINUS15_LK_Register = FFB00002H ; ; Input: ; None ; ; Output: ; register value will be in AL ; ===================================================================== Read_T_MINUS15_LK_Register proc near mov al,byte ptr[SST_49LF008A_T_MINUS15_LKReg] ;store block register value to AL ret Read_T_MINUS15_LK_Register endp ; ===================================================================== ; PROCEDURE: Write_T_MINUS15_LK_Register (FWH mode) ; ; This sample subroutine writes new status byte to block locking reg. ; T_MINUS15_LK_Register of Boot Device(Device #0) of SST49LF008A ; ; The address of T_MINUS15_LK_Register = FFB00002H ; ; Input: ; AL the new status byte to be written ; ; Output: ; None ; ===================================================================== Write_T_MINUS15_LK_Register proc near mov byte ptr[SST_49LF008A_T_MINUS15_LKReg], al ;store AL value to block register ret Write_T_MINUS15_LK_Register endp ; ===================================================================== ; PROCEDURE: Erase_Block_T_MINUS15 (FWH Mode) ; ; This sample subroutine can be used to erase the block of T_MINUS15 ; in Boot Device (Devoce #0) of SST49LF008A in FWH mode. ; ; SST49LF008A has 16 uniform, 64 KByte blocks: T_BLOCK, T_MINUS01 -- ; T_MINUS15. ; ; The block of T_MINUS15 has an address range from FFF0FFFFH -- ; FFF00000H in the System of 4 Gbytes Memory Map and its block locking ; register: T_MINUS15_LK_Register = FFB00002H. ; ; Before erasing the block, the user needs to unlock the block first. ; To unlock the block, the user needs to refer two sample subroutines ; Read_T_MINUS15_LK_Register() and Write_T_MINUS15_LK_Register(). ; ; Input: ; es:di DESTINATION address at which the erase operation will ; start. ; Output: ; carry bit: CLEARED means the block T_MINUS15 is erased ; carry bit: SET means the block T_MINUS15 cannot be erased ;===================================================================== Erase_Block_T_MINUS15 proc near push ax ; preserve registers’ value push es pushf ; save interrupt state cli call Read_T_MINUS15_LK_Register ;read register value and al, 3 cmp al, 3 je EBT2 ;locked down cmp al, 1 jne EBT1 ;write protect mov al, 0 call Write_T_MINUS15_LK_Register ;unlock the write protect call Read_T_MINUS15_LK_Register cmp al, 0 jne EBT2 ;unlock failed EBT1: mov es, FFF00000h ;point to a valid address of block T_MINUS15 call Erase_One_Block pop ax and ax, 0FFFEh ;block erased jmp EBT3 EBT2: pop ax or ax, 1 ;block not erased EBT3: push ax popf pop es pop ax ret Erase_Block_T_MINUS15 endp ; ===================================================================== ; PROCEDURE: Program_One_Byte (FWH/PP Mode) ; ; This procedure can be used to program ONE byte of data to the 49LF008A. ; ; In FWH mode, the block containning the byte to be programmed needs to be ; unlocked first. Please refers the subroutine: ; Erase_Block_T_Minus15 for a detail of usage. ; ; NOTE: It is necessary to first erase the sector containing the byte ; to be programmed. ; ; ; Input: ; al BYTE which will be written into the 49LF008A. ; 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 (FWH/PP Mode) ; ; This procedure can be used to program a memory sector, or total of ; 4096 bytes, of the 49LF008A. ; ; In FWH mode, the block containning the sector to be programmed needs to be ; unlocked first. Please refers the subroutine: ; Erase_Block_T_Minus15 for a detail of usage. ; ; Input: ; ds:si SOURCE address containing the data which will be ; written into the 49LF008A. ; 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 bx push cx 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 49LF008A ; call Erase_One_Sector ; ; The following loop will program a total of 4096 bytes to the SST49LF008A ; mov cx, SECTOR_SIZE 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 bx, di ; preserve original DI temporarily stosb ; program the byte push di ; preserve incremented DI temporarily mov di, bx ; restore original DI call check_Toggle_Ready ; wait for TOGGLE bit to get ready pop di ; retrieve the updated DI loopw DRP1 ; continue program more bytes until done popf ; restore original direction flag pop si ; restore registers pop di pop cx pop bx pop ax ret Program_One_Sector endp ; ===================================================================== ; PROCEDURE: Program_One_Block (FWH/PP Mode) ; ; This procedure can be used to program a memory block, or a total of ; 64 Kbytes, of the SST49LF008A. ; ; In FWH mode, the block to be programmed needs to be unlocked first. ; Please refers the subroutine: ; Erase_Block_T_Minus15 for a detail of usage. ; ; Input: ; ds:si SOURCE address containing the data which will be ; written into the SST49LF008A. ; es:di DESTINATION address which will be written with the ; data passed in for ds:si ; ; Output: ; None ; SI, DI: Contains the original values ; ===================================================================== Program_One_Block proc near push ax ; save registers push bx push di push si pushf ; preserve the "Direction" flag in the FLAG ; register cld ; clear "Direction" flag in the FLAG register to ; auto-increment SI and DI ; ; Erase the block before programming. Each erase command will erase a total ; of 64K bytes of the SST49LF008A. ; call Erase_One_Block ; ; The following loop will program a total of 64 Kbytes to SST's SST49LF008A ; mov cx, BLOCK_SIZE POB1: push ds mov ax, ABS_SEGMENT mov ds, ax mov ds:byte ptr [5555h], 0AAh ; send 3-byte SDP sequence mov ds:byte ptr [2AAAh], 055h mov ds:byte ptr [5555h], 0A0h pop ds lodsb ; get the byte to be programmed mov bx, di ; preserve DI temporarily stosb ; program the byte push di ; preserve the updated DI temporarily mov di, bx call check_Toggle_Ready ; wait for TOGGLE bit to get ready pop di ; retrieve the updated DI loopw POB1 ; continue program more bytes until done popf ; restore original direction flag pop si ; restore registers pop di pop bx pop ax ret Program_One_Block endp ;====================================================================== ; PROCEDURE: Check_Toggle_Ready (FWH/PP Mode) ; ; During the internal program cycle, any consecutive read operation ; on DQ6 will produce alternating 0’s and 1’s, 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 be set-up by the caller ; ; Output: ; None ;====================================================================== Check_Toggle_Ready proc near push ax ; save register mov al, es:[di] ; read a byte from 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 (FWH/PP Mode) ; ; 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 ;======================================================================= ; PROCEDURE: Read_SST49LF008A_GPI_Rigister (FWH Mode) ; ; This procedure fetches the content of GPI Reigster of the device, ; which is in the address 0xFFBC0100. It's recommended that the ; GPI[4:0] pins be in the desired state before LFRAME# is brought low ; for the beginning of the next bus cycle, and remain in that state ; until the end of the cycle. ; ; Input: ; None ; Output: ; GPI register value will be in AL ;======================================================================= Read_SST49LF008A_GPI_Rigister proc near mov al,byte ptr[SST_49LF008A_GPI] ;store GPI value to AL ret Read_SST49LF008A_GPI_Rigister endp