39VF160
16 Mbit Multi-Purpose Flash
September 2001
ABOUT THE SOFTWARE
This application note provides software driver examples for 39VF160,16 Mbit Multi-Purpose Flash, that can be used in any microprocessor based system.Software driver examples used in this document.nbsputilize 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.
ABOUT THE 39VF160
Companion product datasheets for the 39VF160 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.nbspcontain the following routines, in this order:
NameFunction
------------------------------------------------------------------
Check_SST_39VF160Check manufacturer and device ID
CFI_QueryCFI Query Entry/Exit command sequence
Erase_Entire_ChipErase the contents of the entire chip
Erase_One_SectorErase a sector of 2048 word
Erase_One_BlockErase a block of 32K word
Program_One_WordAlter data in one word
Program_One_SectorAlter data in 2048 word sector
Program_One_BlockAlter data in 32K word block
Check_Toggle_ReadyEnd of internal program or erase detection using
Toggle bit
Check_Data_PollingEnd of internal program or erase detection using
Data# polling
"C" LANGUAGE DRIVERS
/***********************************************************************/
/* Copyright Silicon Storage Technology, Inc. (SST), 1994-2001*/
/* Example "C" language Driver of 39VF160 16 Mbit Multi-Purpose Flash*/
/* Nelson Wang, Silicon Storage Technology, Inc.*/
/**/
/* Revision 1.0, Sept. 12, 2001*/
/**/
/* This file requires these external "timing"routines:*/
/**/
/*1.)Delay_150_Nano_Seconds*/
/*2.)Delay_25_Milli_Seconds*/
/*3.)Delay_100_Milli_Seconds*/
/***********************************************************************/
#define FALSE0
#define TRUE1
#define SECTOR_SIZE2048/* Must be 2048 words for 39VF160 */
#define BLOCK_SIZE32768/* Must be 32K words for 39VF160*/
#define SST_ID0xBF/* SST Manufacturer's ID code*/
#define SST_39VF1600x2782/* SST 39VF160 device code*/
typedef unsigned charBYTE;
typedef unsigned intWORD;
/* -------------------------------------------------------------------- */
/*EXTERNAL ROUTINES*/
/* -------------------------------------------------------------------- */
extern voidDelay_150_Nano_Seconds();
extern voidDelay_25_Milli_Seconds();
extern voidDelay_100_Milli_Seconds();
*************************************************************************/
/* PROCEDURE:Check_SST_39VF160*/
/**/
/* This procedure decides whether a physical hardware device has a*/
/* SST39VF160 16 Mbit Multi-Purpose Flash installed or not.*/
/**/
/* Input:*/
/*None*/
/**/
/* Output:*/
/*return TRUE:indicates a SST39VF160*/
/*return FALSE: indicates not a SST39VF160*/
/************************************************************************/
int Check_SST_39VF160()
{
WORD far *Temp;
WORD SST_id1;
WORD far *Temp1;
WORD SST_id2;
intReturnStatus;
/*Issue the Software Product ID code to 39VF160*/
Temp1 = (WORD far *)0xC0005555; /* set up address to be C000:5555h*/
*Temp1= 0xAAAA;/* write data 0xAAAA to the address */
Temp1 = (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh*/
*Temp1= 0x5555;/* write data 0x5555 to the address */
Temp1 = (WORD far *)0xC0005555; /* set up address to be C000:5555h*/
*Temp1= 0x9090;/* write data 0x9090 to the address */
Delay_150_Nano_Seconds();
/* Read the product ID from 39VF160 */
Temp= (WORD far *)0xC0000000; /* set up address to be C000:0000h */
SST_id1=*Temp;/* get first ID word*/
SST_id1=SST_id1 & 0xFF/* mask of higher byte*/
Temp1 = (WORD far *)0xC0000001;/* set up address to be C000:0001h*/
SST_id2=*Temp1;/* get second ID word*/
/* Determine whether there is a SST39VF160 installed or not */
if ((SST_id1 == SST_ID) && (SST_id2 ==SST_39VF160))
ReturnStatus = TRUE;
else
ReturnStatus = FALSE;
/* Issue the Soffware Product ID Exit code thus returning the 39VF160 */
/* to the read operating mode*/
Temp1= (WORD far *)0xC0005555; /* set up address to be C000:5555h*/
*Temp1 = 0xAAAA;/* write data 0xAAAA to the address*/
Temp1= (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh*/
*Temp1 = 0x5555;/* write data 0x5555 to the address*/
Temp1= (WORD far *)0xC0005555; /* set up address to be C000:5555h*/
*Temp1 = 0xF0F0;/* write data 0xF0F0 to the address*/
Delay_150_Nano_Seconds();
return(ReturnStatus);
}
*************************************************************************/
/* PROCEDURE:CFI_Query*/
/**/
/* This procedure should be used to query for CFI information*/
/**/
/* Input:*/
/*None*/
/**/
/* Output:*/
/*None*/
/************************************************************************/
int CFI_Query()
{
WORD far *Temp1;
/*Issue the Software Product ID code to 39VF160*/
Temp1 = (WORD far *)0xC0005555; /* set up address to be C000:5555h*/
*Temp1= 0xAAAA;/* write data 0xAAAA to the address*/
Temp1 = (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh*/
*Temp1= 0x5555;/* write data 0x5555 to the address*/
Temp1 = (WORD far *)0xC0005555; /* set up address to be C000:5555h*/
*Temp1= 0x9898;/* write data 0x9898 to the address*/
Delay_150_Nano_Seconds();
/* --------------------------------- */
/*Perform all CFI operations here*/
/*NOTE:no sample code provided*/
/* --------------------------------- */
/* Issue the CFI Exit code thus returning the 39VF160*/
/* to the read operating mode*/
Temp1= (WORD far *)0xC0005555; /* set up address to be C000:5555h*/
*Temp1 = 0xAAAA;/* write data 0xAAAA to the address*/
Temp1= (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh*/
*Temp1 = 0x5555;/* write data 0x5555 to the address*/
Temp1= (WORD far *)0xC0005555; /* set up address to be C000:5555h*/
*Temp1 = 0xF0F0;/* write data 0xF0F0 to the address*/
Delay_150_Nano_Seconds();
}
*************************************************************************/
/* PROCEDURE:Erase_Entire_Chip*/
/**/
/* This procedure can be used to erase the entire chip.*/
/**/
/* Input:*/
/*NONE*/
/**/
/* Output:*/
/*NONE*/
/************************************************************************/
int Erase_Entire_Chip
{
WORD far *Temp;
/*Issue the Chip Erase command to 39VF160*/
Temp= (WORD far *)0xC0005555; /* set up address to be C000:5555h*/
*Temp = 0xAAAA;/* write data 0xAAAA to the address */
Temp= (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh*/
*Temp = 0x5555;/* write data 0x5555 to the address */
Temp= (WORD far *)0xC0005555; /* set up address to be C000:5555h*/
*Temp = 0x8080;/* write data 0x8080 to the address */
Temp= (WORD far *)0xC0005555; /* set up address to be C000:5555h*/
*Temp = 0xAAAA;/* write data 0xAAAA to the address */
Temp= (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh*/
*Temp = 0x5555;/* write data 0x5555 to the address */
Temp= (WORD far *)0xC0005555; /* set up address to be C000:5555h*/
*Temp = 0x1010;/* write data 0x1010 to the address */
Delay_100_Milli_Seconds();/* Delay Tsce time*/
}
*************************************************************************/
/* PROCEDURE:Erase_One_Sector*/
/**/
/* This procedure can be used to erase a total of 2048 words.*/
/**/
/* Input:*/
/*DstDESTINATION address which the erase operation starts*/
/**/
/* Output:*/
/*NONE*/
/************************************************************************/
int Erase_One_Sector (WORD far *Dst)
{
WORD far *Temp;
/*Issue the Sector Erase command to 39VF160*/
Temp= (WORD far *)0xC0005555; /* set up address to be C000:5555h*/
*Temp = 0xAAAA;/* write data 0xAAAA to the address */
Temp= (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh*/
*Temp = 0x5555;/* write data 0x5555 to the address */
Temp= (WORD far *)0xC0005555; /* set up address to be C000:5555h*/
*Temp = 0x8080;/* write data 0x8080 to the address */
Temp= (WORD far *)0xC0005555; /* set up address to be C000:5555h*/
*Temp = 0xAAAA;/* write data 0xAAAA to the address */
Temp= (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh*/
*Temp = 0x5555;/* write data 0x5555 to the address */
Temp= Dst/* set up starting address to be erased */
*Temp = 0x3030;/* write data 0x3030 to the address */
Delay_25_Milli_Seconds();/* Delay time = Tse*/
}
*************************************************************************/
/* PROCEDURE:Erase_One_Block*/
/**/
/* This procedure can be used to erase a total of 32K words.*/
/**/
/* Input:*/
/*DstDESTINATION address which the erase operation starts*/
/**/
/* Output:*/
/*NONE*/
/************************************************************************/
int Erase_One_Block (WORD far *Dst)
{
WORD far *Temp;
/*Issue the Sector Erase command to 39VF160*/
Temp= (WORD far *)0xC0005555; /* set up address to be C000:5555h*/
*Temp = 0xAAAA;/* write data 0xAAAA to the address */
Temp= (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh*/
*Temp = 0x5555;/* write data 0x5555 to the address */
Temp= (WORD far *)0xC0005555; /* set up address to be C000:5555h*/
*Temp = 0x8080;/* write data 0x8080 to the address */
Temp= (WORD far *)0xC0005555; /* set up address to be C000:5555h*/
*Temp = 0xAAAA;/* write data 0xAAAA to the address */
Temp= (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh*/
*Temp = 0x5555;/* write data 0x5555 to the address */
Temp= Dst/* set up starting address to be erased */
*Temp = 0x5050;/* write data 0x5050 to the address */
Delay_25_Milli_Seconds();/* Delay time = Tbe*/
}
/************************************************************************/
/* PROCEDURE:Program_One_Word*/
/**/
/* This procedure can be used to program ONE word of date to the*/
/* 39VF160.*/
/**/
/* NOTE:It is VERY important the sector containing the word to be*/
/*programmed was ERASED first.*/
/**/
/* Input:*/
/*SrcThe WORD which will be written to the 39VF160*/
/*DstDESTINATION address which will be written with the */
/*data passed in from Src*/
/**/
/* Output:*/
/*None*/
/************************************************************************/
void Program_One_Word (WORD SrcWord,WORD far *Dst)
{
WORD far *SourceBuf;
WORD far *DestBuf;
int Index;
DestBuf = Dst;
Temp =(WORD far *)0xC0005555; /* set up address to be C000:555h*/
*Temp = 0xAAAA;/* write data 0xAAAA to the address */
Temp =(WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh*/
*Temp = 0x5555;/* write data 0x5555 to the address */
Temp =(WORD far *)0xC0005555; /* set up address to be C000:5555h*/
*Temp = 0xA0A0;/* write data 0xA0A0 to the address */
*DestBuf = SrcWord;/* transfer the byte to destination */
Check_Toggle_Ready(DestBuf);/* wait for TOGGLE bit to get ready */
}
/************************************************************************/
/* PROCEDURE:Program_One_Sector*/
/**/
/* This procedure can be used to program a total of 2048 words of data*/
/* to the SST39VF160.*/
/**/
/* Input:*/
/*SrcSOURCE address containing the data which will be*/
/*written to the 39VF160*/
/*DstDESTINATION address which will be written with the */
/*data passed in from Src*/
/**/
/* Output:*/
/*None*/
/************************************************************************/
void Program_One_Sector (WORD far *Src,WORD far *Dst)
{
WORD far *Temp;
WORD far *SourceBuf;
WORD far *DestBuf;
int Index;
SourceBuf = Src;
DestBuf = Dst;
Erase_One_Sector(Dst);/* erase the sector first */
for (Index = 0; Index < SECTOR_SIZE; Index++)
{
Temp =(WORD far *)0xC0005555; /* set up address to be C000:555h*/
*Temp = 0xAAAA;/* write data 0xAAAA to the address*/
Temp =(WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh*/
*Temp = 0x5555;/* write data 0x5555 to the address*/
Temp =(WORD far *)0xC0005555; /* set up address to be C000:5555h*/
*Temp = 0xA0A0;/* write data 0xA0A0 to the address*/
Temp = DestBuf;/* save the original Destination address*/
*DestBuf++ = *SourceBuf++;/* transfer data from source to destination */
Check_Toggle_Ready(Temp);/* wait for TOGGLE bit to get ready*/
}
}
/************************************************************************/
/* PROCEDURE:Program_One_Block*/
/**/
/* This procedure can be used to program a total of 32k words of data*/
/* to the SST39VF160.*/
/**/
/* Input:*/
/*SrcSOURCE address containing the data which will be*/
/*written to the 39VF160*/
/*DstDESTINATION address which will be written with the */
/*data passed in from Src*/
/**/
/* Output:*/
/*None*/
/************************************************************************/
void Program_One_Block (WORD far *Src,WORD far *Dst)
{
WORD far *Temp;
WORD far *SourceBuf;
WORD far *DestBuf;
int Index;
SourceBuf = Src;
DestBuf = Dst;
Erase_One_Block(Dst);/* erase the sector first */
for (Index = 0; Index < BLOCK_SIZE; Index++)
{
Temp =(WORD far *)0xC0005555; /* set up address to be C000:555h*/
*Temp = 0xAAAA;/* write data 0xAAAA to the address*/
Temp =(WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh*/
*Temp = 0x5555;/* write data 0x5555 to the address*/
Temp =(WORD far *)0xC0005555; /* set up address to be C000:5555h*/
*Temp = 0xA0A0;/* write data 0xA0A0 to the address*/
Temp = DestBuf;/* save the original Destination address*/
*DestBuf++ = *SourceBuf++;/* transfer data from source to destination */
Check_Toggle_Ready(Temp);/* wait for TOGGLE bit to get ready*/
}
}
/************************************************************************/
/* PROCEDURE:Check_Toggle_Ready*/
/**/
/* 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:*/
/*Dstmust already set-up by the caller*/
/**/
/* Output:*/
/*None*/
/************************************************************************/
void Check_Toggle_Ready (WORD far*Dst)
{
BYTE Loop = TRUE;
WORD PreData;
WORD CurrData;
unsigned long TimeOut = 0;
PreData = *Dst;
PreData = PreData & 0x4040;
while ((TimeOut< 0x07FFFFFF) && (Loop))
{
CurrData = *Dst;
CurrData = CurrData & 0x4040;
if (PreData == CurrData)
Loop = FALSE;/* ready to exit the while loop */
PreData = CurrData;
TimeOut++;
}
}
/************************************************************************/
/* 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:*/
/*Dstmust already set-up by the caller*/
/*TrueData is the original (true) data*/
/**/
/* Output:*/
/*None*/
/************************************************************************/
void Check_Data_Polling (WORD far*Dst,WORD TrueData)
{
BYTE Loop = TRUE;
WORD CurrData;
unsigned long TimeOut = 0;
TrueData = TrueData &0x8080;
while ((TimeOut< 0x07FFFFFF) && (Loop))
{
CurrData = *Dst;
CurrData = CurrData & 0x8080;
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 Drivers for SST39VF160 16 Mbit MultiPurpose Flash
; Frank Cirimele,Silicon Storage Technology, Inc.
;
; Revision 1.0, Sept. 12, 2001
;
; This file requires these external "timing" routines:
;
;1.)Delay_150_Nano_Seconds
;2.)Delay_25_Milli_Seconds
;3.)Delay_100_Milli_Seconds
; ======================================================================
SECTOR_SIZEEQU2048Must be 4096 bytes for SST39VF160
BLOCK_SIZEEQU32768
SST_IDEQU0BFhSST Manufacturer's ID code
SST_SST39VF160EQU02782hSST SST39VF160 internal code
ABS_SEGMENTEQU0C000h
extrnDelay_150_Nano_Seconds:near
extrnDelay_25_Milli_Seconds:near
extrnDelay_100_Milli_Seconds:near
;=======================================================================
; PROCEDURE:Check_SST_SST39VF160
;
; This procedure decides whether a physical hardware device has a
; SST39VF160 16 Mbit Multi-Purpose Flash installed or not.
;
; Input:
;None
;
; Output:
;carry bit:0 = SST39VF160 installed
;carry bit:1 = SST39VF160 NOT installed
;
;=======================================================================
Check_SST_SST39VF160procnear
pushaxpreserve register values
pushds
pushfsave interrupt state
; It is mandatory to maintain the pushf instruction as the last push
; instruction.
clidisable interrupts
movax, ABS_SEGMENT
movds, ax
movds:word ptr [5555h], 0AAAAhissue the 3-byte product ID
movds:word ptr [2AAAh], 05555hcommand to the SST39VF160
movds:word ptr [5555h], 09090h
callDelay_150_Nano_Seconds
movax, ds:[0]
cmpal, SST_IDis this a SST part?
jneCSC5NO, then return Carry set
movax, ds:[1]
cmpax, SST_SST39VF160is it a SST39VF160?
jneCSC5NO, then Non-SST part
CSC4:
pop axget flags from stack
and ax, 0FFFEhand clear carry flag
jmpshort CSC6
CSC5:
pop axget flags from stack
or ax, 0001hand set carry flag
CSC6:
push axreturn flags to stack
;
; Issue the Software Product ID Exit code thus returning the SST39VF160
; to the read operation mode.
;
movds:word ptr [5555h], 0AAAAhissue the 3-byte product ID
movds:word ptr [2AAAh], 05555hexit command to the SST39VF160
movds:word ptr [5555h], 0F0F0h
callDelay_150_Nano_Secondsinsert delay = Tida
popfrestore flags
popdsrestore register values
popax
ret
Check_SST_SST39VF160 endp
;=======================================================================
; PROCEDURE:CFI_Query
;
; This procedure provides access to the CFI information embedded within
; the SST39VF160 16 Mbit Multi-Purpose Flash device.
;
; Input:
;None
;
; Output:
;None
;
;=======================================================================
CFI_Queryprocnear
pushaxpreserve register values
pushds
pushfsave interrupt state
clidisable interrupts
movax, ABS_SEGMENT
movds, ax
movds:word ptr [5555h], 0AAAAhissue the 3-byte product ID
movds:word ptr [2AAAh], 05555hcommand to the SST39VF160
movds:word ptr [5555h], 09898h
callDelay_150_Nano_Secondsinsert delay = Tida
; -----------------------------------
;Perform all CFI operations here
;NOTE:NO sample code provided
; -----------------------------------
movds:word ptr [5555h], 0AAAAhissue the 3-byte product ID
movds:word ptr [2AAAh], 05555hexit command to the SST39VF160
movds:word ptr [5555h], 0F0F0h
callDelay_150_Nano_Secondsinsert delay = Tida
popfrestore interrupt state
popdsrestore registers
popax
ret
CFI_Queryendp
; =====================================================================
; PROCEDURE:Erase_Entire_Chip
;
; This procedure can be used to erase the entire contents of
; SST's SST39VF160.
;
; Input:
;none
;
; Output:
;None
; =====================================================================
Erase_Entire_Chipprocnear
moves:word ptr [5555h], 0AAAAhsend 6-byte code for
moves:word ptr [2AAAh], 05555hchip erase
moves:word ptr [5555h], 08080h
moves:word ptr [5555h], 0AAAAh
moves:word ptr [2AAAh], 05555h
moves:word ptr [5555h], 01010h
callDelay_100_Milli_Secondsinsert delay = Tsce
ret
Erase_Entire_Chipendp
; =====================================================================
; PROCEDURE:Erase_One_Sector
;
; This procedure can be used to erase a sector, or total of 2048 bytes,
; in the SST39VF160.
;
; Input:
;es:dipoints to the beginning address of the "Destination"
;address which will be erased.
;==> The address MUST be a multiple of 2048
;
; Output:
;None
; =====================================================================
Erase_One_Sectorprocnear
pushax
moves:word ptr [5555h], 0AAAAhsend 6-byte code for
moves:word ptr [2AAAh], 05555hsector erase
moves:word ptr [5555h], 08080h
moves:word ptr [5555h], 0AAAAh
moves:word ptr [2AAAh], 05555h
movax, 03030h
movword ptr es:[di], ax
callDelay_25_Milli_Secondsinsert delay = Tse
popax
ret
Erase_One_Sectorendp
; =====================================================================
; PROCEDURE:Erase_One_Block
;
; This procedure can be used to erase a block, or total of 32K words,
; in the SST39VF160.
;
; Input:
;es:dipoints to the beginning address of the "Destination"
;address which will be erased.
;==> The address MUST be a multiple of 32K
;
; Output:
;None
; =====================================================================
Erase_One_Blockprocnear
pushax
moves:word ptr [5555h], 0AAAAhsend 6-byte code for
moves:word ptr [2AAAh], 05555hblock erase
moves:word ptr [5555h], 08080h
moves:word ptr [5555h], 0AAAAh
moves:word ptr [2AAAh], 05555h
movax, 05050h
movword ptr es:[di], ax
callDelay_25_Milli_Secondsinsert delay = Tbe
popax
ret
Erase_One_Blockendp
; =====================================================================
; PROCEDURE:Program_One_Word
;
; This procedure can be used to program ONE word at one program cycle to
;the SST39VF160.
;
; NOTE:It is necessary to first erase the sector containing the byte
;to be programmed.
;
;
; Input:
;axWORD which will be written into the SST39VF160.
;es:diDESTINATION address which will be written with the
;data input in ax
;
; Output:
;None
;SI, DI:Contains the original values
; =====================================================================
Program_One_Wordprocnear
;
; Save the registers value on the stack before proceeding
;
pushax
;
; The following will program ONE word to SST39VF160
;
pushds
movax, ABS_SEGMENT
movds, ax
movds:word ptr [5555h], 0AAAAh3 bytes of"enable protection"
movds:word ptr [2AAAh], 05555hsequence to the chip
movds:word ptr [5555h], 0A0A0h
popds
popaxrestore the word to be programmed from
stack
movword ptr es:[di], axprogram the byte
callcheck_Toggle_Readywait for TOGGLE bit to get ready
ret
Program_One_Wordendp
; =====================================================================
; PROCEDURE:Program_One_Sector
;
; This procedure can be used to program a memory sector, or total of
; 2048 words, of the SST39VF160.
;
; Input:
;ds:siSOURCE address containing the data which will be
;written into the SST39VF160.
;es:diDESTINATION address which will be written with the
;data passed in for ds:si
;
; Output:
;None
;SI, DI:Contains the original values
; =====================================================================
Program_One_Sectorprocnear
;
; Save the registers value on the stack before proceeding
;
pushax
pushbx
pushdi
pushsi
pushfpreserve the "Direction" flag in the FLAG
register
cldclear "Direction" flag in the FLAG register
and auto-increment SI and DI
; Erase the sector before programming.Each erase command will erase a total
; of 2048 words for the SST39VF160
;
callErase_One_Sector
;
; The following loop will program a total of 2048 words to the SST39VF160
;
movcx, SECTOR_SIZE
POS1:
pushds
movax, ABS_SEGMENT
movds, ax
movds:word ptr [5555h], 0AAAAh3 word enable command sequence
movds:word ptr [2AAAh], 05555hfor word program
movds:word ptr [5555h], 0A0A0h
popds
lodswget the word to be programmed
movbx, dipreserve DI temporarily
stoswprogram the word
pushdipreserve the updated DI temporarily
movdi, bx
callcheck_Toggle_Readywait for TOGGLE bit to get ready
popdiretrieve the updated DI
loopPOS1program more words until done
;
; Restore register values from the stack
;
popf
popsi
popdi
popbx
popax
ret
Program_One_Sectorendp
; =====================================================================
; PROCEDURE:Program_One_Block
;
; This procedure can be used to program a memory block, or a total of
; 32K words, of the SST39VF160.
;
; Input:
;ds:siSOURCE address containing the data which will be
;written into the SST39VF160.
;es:diDESTINATION address which will be written with the
;data passed in for ds:si
;
; Output:
;None
;SI, DI:Contains the original values
; =====================================================================
Program_One_Blockprocnear
;
; Save the registers value on the stack before proceeding
;
pushax
pushbx
pushdi
pushsi
pushfpreserve the "Direction" flag in the FLAG
register
cldclear "Direction" flag in the FLAG register
and auto-increment SI and DI
;
; Erase the block before programming.Each erase command will erase a total
; of 32K words of the SST39VF160.
;
callErase_One_Block
;
; The following loop will program a total of 32K words to SST's SST39VF160
;
movcx, BLOCK_SIZE
POB1:
pushds
movax, ABS_SEGMENT
movds, ax
movds:word ptr [5555h], 0AAAAh3 word enable command sequence
movds:word ptr [2AAAh], 05555hfor word program
movds:word ptr [5555h], 0A0A0h
popds
lodswget the word to be programmed
movbx, dipreserve DI temporarily
stoswprogram the word
pushdipreserve the updated DI temporarily
movdi, bx
callcheck_Toggle_Readywait for TOGGLE bit to get ready
popdiretrieve the updated DI
loopPOB1continue program more words until done
;
; Restore the registers' value from the stack
;
popf
popsi
popdi
popbx
popax
ret
Program_One_Blockendp
;======================================================================
; 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:dimust already set-up by the calller
;
; Output:
;None
;======================================================================
Check_Toggle_Readyprocnear
pushaxsave registers
pushbx
movax, es:[di]read a word form the chip
andax, 4040hmask out the TOGGLE bit (DQ6)
CTR_Tog2:
movbx, es:[di]read the same word from the chip again
andbx, 4040hmask out the TOGGLE bit (DQ6)
cmpax, bxis DQ6 still toggling?
jeCTR_Tog3No, then the write operation is done
xchgax, bxYES, then continue checking...
jmpshort CTR_Tog2
CTR_Tog3:
popbxrestore registers
popax
ret
Check_Toggle_Readyendp
;=======================================================================
; 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:dimust already set-up by the caller
;bxcontains the original (true) data
;
; Output:
;None
;
;=======================================================================
Check_Data_Pollingprocnear
pushax
pushbx
andbx, 8080hmask out the DQ7 bit
CDP_Tog2:
movax, es:[di]read a word from the chip
andax, 8080hmask out the DQ7 bit
cmpax, bxis DQ7 still complementing?
jneCDP_Tog2
popbx
popax
ret
Check_Data_Pollingendp