📄 flash.c
字号:
*(char *)FLASH_ADR1 = FLASH_KEY1;
*(char *)FLASH_ADR2 = FLASH_KEY2;
*(char *)FLASH_ADR1 = FLASH_SID_ENTER;
Delay_10000_Nano_Seconds(); /* insert delay time = Tida */
/* Read the product ID from SST29LE010 */
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_29LE010))
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_10000_Nano_Seconds(); /* insert delay time = Tida */
return(ReturnStatus);
}
/*-------------------------------------------------------------------------*/
/* flash_page_prog() - used to program FLASH SST_29LE010 */
/*-------------------------------------------------------------------------*/
void Program_One_Page(unsigned int src_addr, unsigned int dst_addr)
{
int i;
char *flash_ptr = (char *)dst_addr;
char *src_ptr = (char *)src_addr;
// char temp,temp1;
*(char *)FLASH_ADR1 = FLASH_KEY1;
*(char *)FLASH_ADR2 = FLASH_KEY2;
*(char *)FLASH_ADR1 = FLASH_LOAD;
for (i=0;i<PAGE_SIZE;i++) *flash_ptr++ = *src_ptr++;
/*modefied by SHIYAN on 2002/04/26
//waiting for in internal program proceed is complete,
//Way 1:
temp = *--flash_ptr;
temp1 = *--src_ptr;
while ( temp != temp1)
{
temp = *flash_ptr;
}
modefied by SHIYAN on 2002/04/26*/
/*modefied by SHIYAN on 2002/04/26
//waiting for in internal program proceed is complete,
//Way 2:
--flash_ptr;--src_ptr;
Check_Data_Polling (flash_ptr, *src_ptr);
modefied by SHIYAN on 2002/04/26*/
//modefied by SHIYAN on 2002/04/26
//waiting for in internal program proceed is complete,
//Way 3:
--flash_ptr;
--src_ptr;
Check_Toggle_Ready((INT8U *)flash_ptr);
}
/************************************************************************/
/* PROCEDURE: Erase_Entire_Chip */
/* */
/* This procedure can be used to erase the entire chip. */
/* */
/* Input: */
/* NONE */
/* */
/* Output: */
/* NONE */
/************************************************************************/
void Erase_Entire_Chip()
{
/* Issue the Chip Erase command to SST_29LE010 */
*(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_20_Milli_Seconds(); /* Delay Tsce time */
}
#endif
/************************************************************************/
/* PROCEDURE: Check_INTEL_28F016 */
/* */
/* This procedure decides whether a physical hardware device has a */
/* INTEL28F016 2M X 8 Multi-Purpose Flash installed or not. */
/* */
/* Input: */
/* None */
/* */
/* Output: */
/* return TRUE: indicates a INTEL28F016 */
/* return FALSE: indicates not a INTEL28F016 */
/************************************************************************/
#ifdef ___INTEL_28F016
int Check_INTEL_28F016()
{
char *Temp;
char SST_id1;
char SST_id2;
int ReturnStatus;
/* Issue the Software Product ID code to 28F016 */
Temp = (char *)FLASH_START;
*Temp = FLASH_READ_SID; /* write data 0x90 to the address */
/* Read the product ID from 28F016 */
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 INTEL 28F016 installed or not */
if ((SST_id1 == (char)INTEL_ID) && (SST_id2 == (char)INTEL_28F016))
ReturnStatus = TRUE;
else
ReturnStatus = FALSE;
/* Write FFH after last operation to reset device to ready array mode*/
Temp = (char *)FLASH_START;
*Temp = FLASH_READ_ARRAY; /* write data 0xFF to the address */
return(ReturnStatus);
}
/************************************************************************/
/* PROCEDURE: Erase_One_Block */
/* */
/* This procedure can be used to erase a total of 65536 bytes. */
/* */
/* Input: */
/* Dst DESTINATION address where the erase operation starts */
/* */
/* Output: */
/* NONE */
/************************************************************************/
void Erase_One_Block(INT8U *Dst)
{
char *Temp;
char INTEL_status;
volatile char SR_7 = 0;
/* Issue the Block Erase command to 28F016 */
Temp = (char *)FLASH_START;
*Temp = FLASH_ERASE_SETUP; /* write data 0x20 to the address */
*Dst = FLASH_ERASE_CONFIRM; /* write data 0xD0 to the address */
/* Read the status register to inquery bit7 */
*Temp = FLASH_READ_STATUS; /* write data 0x70 to the address */
while(SR_7 == 0)
{
INTEL_status = *(char *)FLASH_READ_STATUS;
SR_7 = INTEL_status & 0x80;
}
/* Write FFH after last operation to reset device to ready array mode*/
Temp = (char *)FLASH_START;
*Temp = FLASH_READ_ARRAY; /* write data 0xFF to the address */
}
/*************************************************************************/
/* PROCEDURE: Program_One_Block */
/* */
/* This procedure can be used to program a total of 65536 bytes of data */
/* to the INTEL28F016. */
/* */
/* Input: */
/* Src SOURCE address containing the data which will be */
/* written to the 28F016 */
/* Dst DESTINATION address which will be written with the */
/* data passed in from Src */
/* */
/* Output: */
/* None */
/*************************************************************************/
void Program_One_Block(INT8U *Src, INT8U *Dst)
{
INT8U *SourceBuf;
INT8U *DestBuf;
int Index;
char *Temp;
SourceBuf = Src;
DestBuf = Dst;
Erase_One_Block(Dst); /* erase the block first */
for (Index = 0; Index < BLOCK_SIZE; Index++)
{
Program_One_Byte(*SourceBuf, DestBuf++);
SourceBuf++;
}
/* Write FFH after last operation to reset device to ready array mode*/
Temp = (char *)FLASH_START;
*Temp = FLASH_READ_ARRAY; /* write data 0xFF to the address */
}
/************************************************************************/
/* PROCEDURE: Program_One_Byte */
/* */
/* This procedure can be used to program ONE byte of data to the */
/* 28F016. */
/* */
/* 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 28F016 */
/* 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;
char INTEL_status;
volatile char SR_7 = 0;
DestBuf = Dst;
Temp = (INT8U *)FLASH_START;
*Temp = FLASH_LOAD; /* write data 0x40 to the address */
*DestBuf = SrcByte; /* transfer the byte to destination*/
/* Read the status register to inquery bit7 */
*Temp = FLASH_READ_STATUS; /* write data 0x70 to the address */
while(SR_7 == 0)
{
INTEL_status = *(char *)FLASH_READ_STATUS;
SR_7 = INTEL_status & 0x80;
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -