📄 flash.c
字号:
#include "flash.h"
/************************************************************************/
/* 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: */
/* Dst must already be set-up by the caller */
/* True Data is the original (true) data */
/* */
/* Output: */
/* None */
/************************************************************************/
void Check_Data_Polling (INT8U *Dst, INT8U TrueData)
{
INT8U Loop = TRUE;
INT8U CurrData;
unsigned long TimeOut = 0;
TrueData = TrueData & 0x80;
while ((TimeOut< 0x07FFFFFF) && (Loop))
{
CurrData = *Dst;
CurrData = CurrData & 0x80;
if (TrueData == CurrData)
Loop = FALSE; /* ready to exit the while loop */
TimeOut++;
}
}
/************************************************************************/
/* 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: */
/* Dst must already be set-up by the caller */
/* */
/* Output: */
/* None */
/************************************************************************/
void Check_Toggle_Ready (INT8U *Dst)
{
INT8U Loop = TRUE;
INT8U PreData;
INT8U CurrData;
unsigned long TimeOut = 0;
PreData = *Dst;
PreData = PreData & 0x40;
while ((TimeOut< 0x07FFFFFF) && (Loop))
{
CurrData = *Dst;
CurrData = CurrData & 0x40;
if (PreData == CurrData)
Loop = FALSE; /* ready to exit the while loop */
PreData = CurrData;
TimeOut++;
}
}
/************************************************************************/
/* PROCEDURE: Check_SST_39VF080 */
/* */
/* This procedure decides whether a physical hardware device has a */
/* SST39VF080 1M X 8 Multi-Purpose Flash installed or not. */
/* */
/* Input: */
/* None */
/* */
/* Output: */
/* return TRUE: indicates a SST39VF080 */
/* return FALSE: indicates not a SST39VF080 */
/************************************************************************/
#ifdef ___SST_39VF080
int Check_SST_39VF080()
{
char *Temp;
char SST_id1;
char SST_id2;
// char mm1, mm2;
int ReturnStatus;
/* Issue the Software Product ID code to 39VF080 */
Temp = (char *)FLASH_ADR1; /* set up address to be C000:5555h */
*Temp = FLASH_KEY1; /* write data 0xAA to the address */
Temp = (char *)FLASH_ADR2; /* set up address to be C000:2AAAh */
*Temp = FLASH_KEY2; /* write data 0x55 to the address */
Temp = (char *)FLASH_ADR1; /* set up address to be C000:5555h */
*Temp = FLASH_SID_ENTER; /* write data 0x90 to the address */
Delay_150_Nano_Seconds(); /* check DATABOOK for the most */
/* accurate value -- Tida */
/* Read the product ID from 39VF080 */
Temp = (char *)FLASH_START;
SST_id1 = *Temp; /* get first ID byte */
Temp = (char *)FLASH_START+1;
SST_id2 = *Temp; /* get first ID byte */
/* Determine whether there is a SST 39VF080 installed or not */
if ((SST_id1 == (char)SST_ID) && (SST_id2 == (char)SST_39VF080))
ReturnStatus = TRUE;
else
ReturnStatus = FALSE;
/* Issue the Soffware Product ID Exit code thus returning the 39VF080*/
/* to the read operating mode */
Temp = (char *)FLASH_ADR1; /* set up address to be C000:5555h */
*Temp = FLASH_KEY1; /* write data 0xAA to the address */
Temp = (char *)FLASH_ADR2; /* set up address to be C000:2AAAh */
*Temp = FLASH_KEY2; /* write data 0x55 to the address */
Temp = (char *)FLASH_ADR1; /* set up address to be C000:5555h */
*Temp = FLASH_SID_EXIT; /* write data 0xF0 to the address */
Delay_150_Nano_Seconds(); /* check DATABOOK for the most */
/* accurate value -- Tida */
return(ReturnStatus);
}
void Erase_Entire_Chip()
{
/* Issue the Chip Erase command to 39VF080 */
*(char *)FLASH_ADR1 = FLASH_KEY1;
*(char *)FLASH_ADR2 = FLASH_KEY2;
*(char *)FLASH_ADR1 = FLASH_ERASE_KEY;
*(char *)FLASH_ADR1 = FLASH_KEY1;
*(char *)FLASH_ADR2 = FLASH_KEY2;
*(char *)FLASH_ADR1 = FLASH_ERASE_CHIP;
Delay_100_Milli_Seconds(); /* Delay Tsce time */
}
/************************************************************************/
/* PROCEDURE: Erase_One_Sector */
/* */
/* This procedure can be used to erase a total of 4096 bytes. */
/* */
/* Input: */
/* Dst DESTINATION address where the erase operation starts */
/* */
/* Output: */
/* NONE */
/************************************************************************/
void Erase_One_Sector (INT8U *Dst)
{
/* Issue the Chip Erase command to 39VF080 */
*(char *)FLASH_ADR1 = FLASH_KEY1;
*(char *)FLASH_ADR2 = FLASH_KEY2;
*(char *)FLASH_ADR1 = FLASH_ERASE_KEY;
*(char *)FLASH_ADR1 = FLASH_KEY1;
*(char *)FLASH_ADR2 = FLASH_KEY2;
*Dst = FLASH_ERASE_SECTOR;
Delay_25_Milli_Seconds(); /* Delay time = Tse */
}
/************************************************************************/
/* PROCEDURE: Program_One_Sector */
/* */
/* This procedure can be used to program a total of 4096 bytes of data */
/* to the SST39VF080. */
/* */
/* Input: */
/* Src SOURCE address containing the data which will be */
/* written to the 39VF080 */
/* Dst DESTINATION address which will be written with the */
/* data passed in from Src */
/* */
/* Output: */
/* None */
/************************************************************************/
void Program_One_Sector (INT8U *Src, INT8U *Dst)
{
INT8U *SourceBuf;
INT8U *DestBuf;
int Index;
SourceBuf = Src;
DestBuf = Dst;
Erase_One_Sector(Dst); /* erase the sector first */
for (Index = 0; Index < SECTOR_SIZE; Index++)
{
Program_One_Byte(*SourceBuf, DestBuf++);
SourceBuf++;
}
}
/************************************************************************/
/* PROCEDURE: Program_One_Byte */
/* */
/* This procedure can be used to program ONE byte of data to the */
/* 39VF080. */
/* */
/* NOTE: It is necessary to first erase the sector containing the */
/* byte to be programmed. */
/* */
/* Input: */
/* Src The BYTE which will be written to the 39VF080 */
/* Dst DESTINATION address which will be written with the */
/* data passed in from Src */
/* */
/* Output: */
/* None */
/************************************************************************/
void Program_One_Byte (INT8U SrcByte, INT8U *Dst)
{
INT8U *Temp;
INT8U *DestBuf;
DestBuf = Dst;
Temp = (INT8U *)FLASH_ADR1; /* set up address to be C000:555h */
*Temp = 0xAA; /* write data 0xAA to the address */
Temp = (INT8U *)FLASH_ADR2; /* set up address to be C000:2AAAh */
*Temp = 0x55; /* write data 0x55 to the address */
Temp = (INT8U *)FLASH_ADR1; /* set up address to be C000:5555h */
*Temp = 0xA0; /* write data 0xA0 to the address */
*DestBuf = SrcByte; /* transfer the byte to destination*/
Check_Toggle_Ready(DestBuf); /* wait for TOGGLE bit to get ready*/
}
#endif
/************************************************************************/
/* PROCEDURE: Check_SST_29LE010 */
/* */
/* This procedure decides whether a physical hardware device has a */
/* SST29LE010 1 Mbit Multi-Purpose Flash installed or not. */
/* */
/* Input: */
/* None */
/* */
/* Output: */
/* return TRUE: indicates a SST29LE010 */
/* return FALSE: indicates not a SST29LE010 */
/************************************************************************/
#ifdef ___SST_29LE010
int Check_SST_29LE010() /* same device code as SST29LE010 */
{
char *Temp;
char SST_id1;
char SST_id2;
int ReturnStatus;
/* Issue the Software Product ID code to SST29LE010 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -