📄 sst39vf1601.c
字号:
/* */
/* 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 (uint16_t *Src, uint32_t Dst)
{
uint16_t *SourceBuf;
uint32_t 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_uint16_t( 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 uint16_ts 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 (uint16_t *Src, uint32_t Dst)
{
uint16_t *SourceBuf;
uint32_t 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_uint16_t( 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 Unlocked */
/************************************************************************/
int SecID_Lock_Status(void)
{
uint16_t SecID_Status;
// Issue the Sec ID Entry code to 39VF160X
*sysAddress(0x5555) = 0x00AA; // write data 0x00AA to device addr 0x5555
*sysAddress(0x2AAA) = 0x0055; // write data 0x0055 to device addr 0x2AAA
*sysAddress(0x5555) = 0x0088; // write data 0x0088 to device addr 0x5555
Delay(1); // insert delay time = Tida
// Read Lock Status of SecID segment
SecID_Status = *sysAddress(0x00FF);
SecID_Status &= 0x0008; // Unlocked: DQ3=1; Locked: DQ3=0
// Issue the Sec ID Exit code thus returning the 39VF160X
// to the read operating mode
*sysAddress(0x5555) = 0x00AA; // write data 0x00AA to device addr 0x5555
*sysAddress(0x2AAA) = 0x0055; // write data 0x0055 to device addr 0x2AAA
*sysAddress(0x5555) = 0x00F0; // write data 0x00F0 to device addr 0x5555
Delay(1); // insert delay time = Tida
if (!SecID_Status)
return TRUE; // SecID segment is Locked
return FALSE; // SecID segment is Unlocked
}
/************************************************************************/
/* PROCEDURE: User_SecID_uint16_t_Program */
/* */
/* This procedure can be used to program data into the User SecID */
/* segment (from 000010H--000017H) in 39VF160X. */
/* */
/* NOTE: 1. It's recommended to lock out the SecID segment after the */
/* completion of program. */
/* 2. There's no way to unlock the SecID segment once it's */
/* locked. */
/* */
/* Input: */
/* Srcuint16_t Source address to fetch data */
/* Dst Destination address to write data */
/* length number of uint16_t needs to be programmed */
/* */
/* Output: */
/* return TRUE: indicates SecID program is successful */
/* return FALSE: indicates SecID program is failed or SecID */
/* is locked. */
/************************************************************************/
int User_SecID_uint16_t_Program (uint16_t *Srcuint16_t, uint16_t *Dst, int length)
{
uint16_t *DestBuf = Dst;
uint16_t *SourceBuf = Srcuint16_t;
int test, index=length;
test = SecID_Lock_Status (); // check whether the SecID is Locked or not
if (test) // TRUE: SecID is Locked
return FALSE;
while (index--)
{
*sysAddress(0x5555) = 0x00AA; // write data 0x00AA to device addr 0x5555
*sysAddress(0x2AAA) = 0x0055; // write data 0x0055 to device addr 0x2AAA
*sysAddress(0x5555) = 0x00A5; // write data 0x00A5 to device addr 0x5555
*sysAddress(*DestBuf) = *SourceBuf; // transfer the uint16_t to destination YJ
++DestBuf;
++SourceBuf;
// Read the toggle bit to detect end-of-write for the Sec ID.
// Do Not use Data# Polling for User_SecID_uint16_t_Program.
test = Check_Toggle_Ready((uint32_t)DestBuf); // wait for TOGGLE bit to get ready
if (!test)
return FALSE; // SecID uint16_t-Program failed!
}
return TRUE;
}
/************************************************************************/
/* PROCEDURE: User_SecID_Lock_Out */
/* */
/* This procedure can be used to Lock Out the User Seccurity ID. */
/* User Security ID segment, from 000010H--000017H, in 39VF160X. */
/* */
/* NOTE: 1. Call SecID_Lock_Status() first to verify the SecID is */
/* unlocked. */
/* 2. SecID segment can't be erased. */
/* 3. SecID segment can't be unlocked once it's locked. */
/* */
/* Input: None */
/* */
/* Output: None */
/************************************************************************/
void User_SecID_Lock_Out (void)
{
*sysAddress(0x5555) = 0x00AA; // write data 0x00AA to device addr 0x5555
*sysAddress(0x2AAA) = 0x0055; // write data 0x0055 to device addr 0x2AAA
*sysAddress(0x5555) = 0x0085; // write data 0x0085 to device addr 0x5555
*sysAddress(0x00FF) = 0x0000; // write data 0x0000 to any addr
Delay(1); // Wait for uint16_t-Program timeout, Tbp=10us
}
/************************************************************************/
/* PROCEDURE: Erase_Suspend */
/* */
/* This procedure can be used to temporarily suspend a Sector/Block- */
/* Erase operation in 39VF160X. */
/* */
/* Input: None */
/* */
/* Output: None */
/************************************************************************/
void Erase_Suspend (void)
{
*sysAddress(0x5555) = 0x00B0; // write data 0x00B0 to any addr, i.e. 0x5555
Delay(1); // The device automatically enters read mode
// typically within 20 us after the Erase-Suspend command issued.
}
/************************************************************************/
/* PROCEDURE: Erase_Resume */
/* */
/* This procedure can be used to resume a Sector-Erase or Block-Erase */
/* operation that had been suspended in 39VF160X. */
/* */
/* Input: None */
/* */
/* Output: None */
/************************************************************************/
void Erase_Resume (void)
{
*sysAddress(0x5555) = 0x0030; // write data 0x0030 to any addr, i.e. 0x5555
}
/************************************************************************/
/* 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: TRUE Data toggling success */
/* FALSE Time out */
/************************************************************************/
int Check_Toggle_Ready (uint32_t Dst)
{
uint16_t PreData;
uint16_t CurrData;
unsigned long TimeOut = 0;
PreData = *sysAddress(Dst);
PreData = PreData & 0x0040; // read DQ6
while (TimeOut < MAX_TIMEOUT) // MAX_TIMEOUT=0x07FFFFFF
{
CurrData = *sysAddress(Dst);
CurrData = CurrData & 0x0040; // read DQ6 again
if (PreData == CurrData)
{
return TRUE;
}
PreData = CurrData;
TimeOut++;
}
return FALSE;
}
/************************************************************************/
/* PROCEDURE: Check_Data_Polling */
/* */
/* During the internal program cycle, any attempt to read DQ7 of the */
/* last uint8_t loaded during the page/uint8_t-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_t Dst, uint16_t TrueData)
{
uint16_t CurrData;
unsigned long int TimeOut = 0;
TrueData = TrueData & 0x0080; // read D7
while (TimeOut < MAX_TIMEOUT) // MAX_TIMEOUT=0x07FFFFFF
{
CurrData = *sysAddress(Dst);
CurrData = CurrData & 0x0080; // read DQ7
if (TrueData == CurrData)
{
return TRUE;
}
TimeOut++;
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -