📄 flashdrive.c
字号:
*(u16 *) (BaseAddrs + 0xaaaa) = (u16)0x00AA; // write data 0x00AA to device addr 5555H
*(u16 *) (BaseAddrs + 0x5554) = (u16)0x0055; // write data 0x0055 to device addr 2AAAH
*(u16 *) (BaseAddrs + 0xaaaa) = (u16)0x0080; // write data 0x0080 to device addr 5555H
*(u16 *) (BaseAddrs + 0xaaaa) = (u16)0x00AA; // write data 0x00AA to device addr 5555H
*(u16 *) (BaseAddrs + 0x5554) = (u16)0x0055; // write data 0x0055 to device addr 2AAAH
*(u16 *) (BaseAddrs + 0xaaaa) = (u16)0x0010; // write data 0x0010 to device addr 5555H
ReturnStatus = Check_Toggle_Ready(0, ChipEraseTime); // wait TOGGLE bit stops toggling
// ReturnStatus = Check_Data_Polling(0, 0xFFFF, ChipEraseTime);// wait until DQ7 outputs 1
return ReturnStatus;
}
/************************************************************************/
/* PROCEDURE: Program_One_Word */
/* */
/* This procedure programs one word of data into SST39VF320X. */
/* */
/* NOTE: It is necessary to first erase the sector containing the */
/* word to be programmed. */
/* */
/* Input: */
/* SrcWord data word to be written into SST39VF320X. */
/* Dst DESTINATION address where to be written into. */
/* */
/* Output: */
/* return TRUE: indicates success in word-program */
/* return FALSE: indicates timeout in word-program */
/************************************************************************/
u8 Program_One_Word (u16 SrcWord, u32 Dst)
{
u8 ReturnStatus=TRUE;
*(u16 *) (BaseAddrs + 0xaaaa ) = (u16)0x00AA; // 1st write data 0x00AA to device addr 5555H
*(u16 *) (BaseAddrs + 0x5554 ) = (u16)0x0055; // 2nd write data 0x0055 to device addr 2AAAH
*(u16 *) (BaseAddrs + 0xaaaa ) = (u16)0x00A0; // 3rd write data 0x00A0 to device addr 5555H
*(u16 *) (BaseAddrs + Dst* AddrsShift ) = (u16)SrcWord; // 4th write data word into destination address Dst
ReturnStatus = Check_Toggle_Ready(Dst, WordProgramTime); // wait TOGGLE bit stops toggling
// if(ReturnStatus==FALSE)
//printf("Program wrong");
// else
//printf("Program is ok");
// ReturnStatus = Check_Data_Polling(Dst, SrcWord, WordProgramTime); // wait until DQ7 outputs true data
return ReturnStatus;
}
/************************************************************************/
/* PROCEDURE: Program_One_Sector */
/* */
/* This procedure can be used to program a total of 2048 words of data */
/* to the SST39VF160X. */
/* */
/* NOTES: 1. It is necessary to first erase the sector before the */
/* programming. */
/* 2. This sample code assumes the destination address passed */
/* from the calling function is the starting address of the */
/* sector. */
/* */
/* Input: */
/* Src SOURCE address containing the data which will be */
/* written to the 39VF160X */
/* Dst DESTINATION address which will be written with the */
/* data passed in from Src */
/* */
/* Output: */
/* return TRUE: indicates success in sector-program */
/* return FALSE: indicates failure in sector-program */
/************************************************************************/
int Program_One_Sector (u16 *Src, u32 Dst)
{
u16 *SourceBuf;
u32 DestBuf;
int Index, ReturnStatus;
SourceBuf = Src;
DestBuf = Dst;
ReturnStatus = Erase_One_Sector(DestBuf); // erase the sector first
if (!ReturnStatus)
return ReturnStatus;
for (Index = 0; Index < SECTOR_SIZE; Index++)
{ // transfer data from source to destination
ReturnStatus = Program_One_Word( *SourceBuf, DestBuf);
++DestBuf;
++SourceBuf;
if (!ReturnStatus)
return ReturnStatus;
}
return ReturnStatus;
}
/************************************************************************/
/* PROCEDURE: Program_One_Block */
/* */
/* This procedure can be used to program a total of 32k words of data */
/* to the SST39VF160X. */
/* */
/* NOTES: 1. It is necessary to first erase the block before the */
/* programming. */
/* 2. This sample code assumes the destination address passed */
/* from the calling function is the starting address of the */
/* block. */
/* */
/* Input: */
/* Src SOURCE address containing the data which will be */
/* written to the 39VF160X */
/* Dst DESTINATION address which will be written with the */
/* data passed in from Src */
/* */
/* Output: */
/* return TRUE: indicates success in block-program */
/* return FALSE: indicates failure in block-program */
/************************************************************************/
int Program_One_Block (u16 *Src, u32 Dst)
{
u16 *SourceBuf;
u32 DestBuf;
int Index, ReturnStatus;
SourceBuf = Src;
DestBuf = Dst;
ReturnStatus = Erase_One_Block(DestBuf); // erase the block first
if (!ReturnStatus)
return ReturnStatus;
for (Index = 0; Index < BLOCK_SIZE; Index++)
{ // transfer data from source to destination
ReturnStatus = Program_One_Word( *SourceBuf, DestBuf);
++DestBuf;
++SourceBuf;
if (!ReturnStatus)
return ReturnStatus;
}
return ReturnStatus;
}
//burnflash
void BurnFlash(u8 *data, u16 nBytes)
{
u32 timeout;
u16 c;
volatile u8 *pdata;
Erase_Entire_Chip();
while(nBytes--)
{
*(volatile u16 *)(BaseAddrs+0xaaaa) = (u16)0x00AA;/*change*/
*(volatile u16 *)(BaseAddrs+0x5554) = (u16)0x0055;
*(volatile u16 *)(BaseAddrs+0xaaaa) = (u16)0x00A0;
pdata = (volatile u8 *)((u32)flashnext);
*pdata = *data;
/* Spin here 'til programming completes
*/
c = *data++;
timeout = 0;
do timeout += 1;
while(*pdata != c && timeout < (u16)0xffff);
flashnext++;
}
/* Put the Flash in normal mode */
*(volatile u16 *)BaseAddrs = (u16)0xf0;
}
/*write more*/
int Program_more (u16 *Src, u32 Dst,u32 bytes)
{
u16 *SourceBuf;
u32 DestBuf;
int Index, ReturnStatus;
SourceBuf = Src;
DestBuf = Dst;
for (Index = 0; Index < bytes; Index++)
{ // transfer data from source to destination
ReturnStatus = Program_One_Word( *SourceBuf, DestBuf);
++DestBuf;
++SourceBuf;
if (!ReturnStatus)
return ReturnStatus;
}
return ReturnStatus;
}
/************************************************************************/
/* PROCEDURE: SecID_Lock_Status */
/* */
/* This procedure should be used to check the Lock Status of SecID */
/* */
/* Input: */
/* None */
/* */
/* Output: */
/* return TRUE: indicates SecID is Locked */
/* return FALSE: indicates SecID is not locked */
/************************************************************************/
u8 SecID_Lock_Status(void)
{
u16 SecID_Status;
// Issue the Sec ID Entry code to 39VF320X
*(u16 *) (BaseAddrs + 0x5555 * AddrsShift) = 0x00AA; // 1st write data 0x00AA to device addr 5555H
*(u16 *) (BaseAddrs + 0x2AAA * AddrsShift) = 0x0055; // 2nd write data 0x0055 to device addr 2AAAH
*(u16 *) (BaseAddrs + 0x5555 * AddrsShift) = 0x0088; // 3rd write data 0x0088 to device addr 5555H
Delay_150_Nano_Seconds(); // insert delay time = Tida
// Read Lock Status of SecID segment
SecID_Status = *(u16 *) (BaseAddrs+ 0xFF * AddrsShift ); // Lock Status address at 0000FFh
SecID_Status &= 0x0008; // get data bit DQ3 only
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -