📄 c2194.c
字号:
/******************************************************************************
NAND_PageRead
Function: NAND_Ret NAND_PageRead(udword udAddress, dataWidth *Buffer,
udword udlength)
Arguments: udAddress: The address of the page to read.
Buffer: Contains the destination buffer to store the data.
udlength: number of data to read.
Return Value: NAND_FLASH_SIZE_OVERFLOW: The address is not within the flash
NAND_PASS: The operation are successfully executed
NAND_FAIL: The operation are not successfully execute
Description: The PageRead operation issue a PageRead Command as explained in
the datasheet of the 528 byte/264 word page family.
The only value of the pointer are 00h and 01h. That means the Page
Read operation starts in any part of the data area of the page
except the spare area. So, the SpareRead operations must be call
to read a page directly in the spare area.
The Random Read, the serial read and the sequentially row read
operations are possible.
*******************************************************************************/
NAND_Ret NAND_PageRead(udword udAddress, dataWidth *Buffer, udword udlength) {
volatile udword udIndex;
ubyte ubStatus;
uword uwFarToPage;
/* Control if the address is within the flash*/
if ( udAddress >= FLASH_SIZE )
return NAND_FLASH_SIZE_OVERFLOW;
NAND_Open();
/* Set the address pointer*/
if ( (udAddress % PAGE_DATA_SIZE) >= PAGE_DATA_SIZE/2 )/* A8 =1 */
NAND_CommandInput(HALF_PAGE_POINTER); /* 2nd half page*/
else
NAND_CommandInput((ubyte)0x00); /* 1st half page*/
/*send the address*/
InsertAddress(udAddress);
/* Wait for ready */
ubStatus=waitForReady();
/* Leave Read Status Register mode */
NAND_CommandInput((ubyte)0x00);
/* Calculate the distance for the page edge*/
uwFarToPage = (PAGE_SIZE - (udAddress % PAGE_DATA_SIZE));
/*DMA management*/
#ifdef DMA_ENABLE
/* to do DMA */
#else
/* Read data to the internal buffer */
udIndex=0;
while(udIndex<udlength)
if ( uwFarToPage == 0 ) {
/*Wait fo Ready*/
ubStatus=waitForReady();
/* Leave Read Status Register mode */
NAND_CommandInput((ubyte)0x00);
uwFarToPage=PAGE_SIZE;
}
else
{
Buffer[udIndex++] = NAND_DataOutput();
uwFarToPage--;
}
#endif
NAND_Close();
/* Return Pass or Fail */
return (ubStatus&(0x01));
}
/****************************** NAND_PageRead ********************************/
/******************************************************************************
NAND_PageProgram function
Function: NAND_Ret NAND_PageProgram(udword udAddress, dataWidth *Buffer,
udword udlength)
Arguments: udAddress: The address of the page to program.
Buffer: Contains the source buffer with the data to program.
udlength: number of data to program.
Return Value: NAND_FLASH_SIZE_OVERFLOW: The address is not within the flash
NAND_PAGE_OVERFLOW: The size exceedes the page size
NAND_PASS: The operation are successfully executed
NAND_FAIL: The operation are not successfully execute
Description: The PageProgram operation issue a PageProgram Command as
explained in the datasheet of the 528 byte/264 word page family.
The only values of the pointer are 00h and 01h. That means the Page
Program operation starts in any part of the data area of the page
except the spare area. So, the SpareProgram operations must be
call to Program only the spare area.
******************************************************************************/
NAND_Ret NAND_PageProgram(udword udAddress, dataWidth *Buffer, udword udlength) {
register udword udIndex;
ubyte ubStatus;
/* Control if the address is within the flash*/
if ( udAddress >= FLASH_SIZE )
return NAND_FLASH_SIZE_OVERFLOW;
/* Control if the address is the buffer size is within the page */
if ( ( (udAddress % PAGE_DATA_SIZE) + udlength ) > PAGE_SIZE )
return NAND_PAGE_OVERFLOW;
NAND_Open();
/* Check for A8 - Set the address pointer */
/* A8 =1*/
if ( (udAddress % PAGE_DATA_SIZE) >= PAGE_DATA_SIZE/2 )
/* 2nd half page*/
NAND_CommandInput(HALF_PAGE_POINTER);
else
/* 1st half page*/
NAND_CommandInput((ubyte)0x00);
/* Issue Sequential data input command */
NAND_CommandInput((ubyte)0x80);
/*send the address*/
InsertAddress(udAddress);
#ifdef DMA_ENABLE
/* to do DMA */
#else
/* Write the data to the internal buffer */
for (udIndex=0;udIndex<udlength;udIndex++)
NAND_DataInput(Buffer[udIndex]);
#endif
/* Issue the Program Command*/
NAND_CommandInput((ubyte)0x10);
/* Wait for ready */
ubStatus=waitForReady();
NAND_Close();
/* Return Pass or Fail */
return (ubStatus&(0x01));
}
/***************************** NAND_PageProgram *******************************/
/******************************************************************************
NAND_ReadElectronicSignature
Function: void NAND_ReadElectronicSignature(ubyte *Buffer)
Arguments: Buffer:contains the byte returned from ReadElectronicSignature
Return Value: na
Description: The NAND_ReadElectronicSignature operation issue a
ReadElectronicSignature Command as explained in the datasheet
of the 528 byte/264 word page family.
******************************************************************************/
void NAND_ReadElectronicSignature(dataWidth *Buffer) {
ubyte ubIndex;
int i;
NAND_Open();
/* Set the address pointer */
NAND_CommandInput((ubyte)0x90); /* Spare Area*/
/* Issue the address bytes*/
NAND_AddressInput((ubyte)0x00); /* first address byte */
for (ubIndex=0;ubIndex<2;ubIndex++)
Buffer[ubIndex]= NAND_DataOutput();
NAND_Close();
}
/********************** NAND_ReadElectronicSignature *************************/
/******************************************************************************
NAND_ReadStatusRegister
Function: ubyte NAND_ReadStatusRegister()
Arguments: na
Return Value: the status register readed
Description: The PageProgram operation issue a Read Status Register Command
as explained in the datasheet of the 528 byte/264 word page
family.
*******************************************************************************/
ubyte NAND_ReadStatusRegister() {
ubyte ret;
NAND_Open();
/* Issue Read Status Register command */
NAND_CommandInput((ubyte)0x70);
ret = (ubyte)NAND_DataOutput();
NAND_Close();
/* Return the Status Register */
return ret;
}
/************************ NAND_ReadStatusRegister ****************************/
/******************************************************************************
NAND_Reset
Function: void NAND_Reset(void)
Arguments: na
Return Value: na
Description: The Reset operation issue a Reset Command as explained in the
datasheet of the 528 byte/264 word page family.
******************************************************************************/
void NAND_Reset(void) {
NAND_Open();
/* Issue the Reset Command*/
NAND_CommandInput((ubyte)0xFF);
NAND_Close();
}
/****************************** NAND_Reset ***********************************/
/*******************************************************************************
NAND_SpareProgram
Function: NAND_Ret NAND_SpareProgram(udword udAddress, dataWidth *Buffer,
udword udlength)
Arguments: udAddress: The address of the page to program
(Note A0-A4 contains theoffset in the spare area).
Buffer: Contains the source buffer with the data to program.
udlength: Lunghezza del buffer or number of data to read.
Return Value: NAND_FLASH_SIZE_OVERFLOW: The address is not within the flash
NAND_PASS: The operation are successfully executed
NAND_FAIL: The operation are not successfully execute
Description: The Spare Program operation issue a Spare Program Command as
explained in the datasheet of the 528 byte/264 word page family.
The only value of the pointer is 50h. That means the Spare
Program operation is used to Program only the spare area.
*******************************************************************************/
NAND_Ret NAND_SpareProgram(udword udAddress, dataWidth *Buffer, udword udlength){
ubyte ubStatus;
udword ubIndex;
/* Control if the address is within the flash*/
if ( udAddress >= FLASH_SIZE )
return NAND_FLASH_SIZE_OVERFLOW;
/* Control if the address is the buffer size is within the page*/
if ( ( (udAddress % PAGE_SPARE_SIZE) + udlength ) > PAGE_SPARE_SIZE )
return NAND_PAGE_OVERFLOW;
/* Set the address pointer to the Spare Area*/
NAND_CommandInput((ubyte)0x50); /* Spare Area */
/* Issue Sequential data input command */
NAND_CommandInput((ubyte)0x80);
InsertAddress(udAddress);
#ifdef DMA_ENABLE
/* to do DMA */
#endif
#ifndef DMA_ENABLE
/* Write the data to the internal buffer */
for (ubIndex=0;ubIndex<udlength;ubIndex++)
NAND_DataInput(Buffer[ubIndex]);
#endif
/* Issue the Program Command*/
NAND_CommandInput((ubyte)0x10);
/* Wait for ready */
ubStatus=waitForReady();
NAND_Close();
/* Return Pass or Fail */
return (ubStatus&(0x01));
}
/*************************** NAND_SpareProgram *******************************/
/******************************************************************************
NAND_SpareRead
Function: NAND_Ret NAND_SpareRead(udword udAddress, dataWidth *Buffer,
udword udlength)
Arguments: udAddress: The address of the page to read.
Buffer: Contains the destination buffer to store the data.
udLength: Lunghezza del buffer or number of data to read.
Return Value: NAND_FLASH_SIZE_OVERFLOW: The address is not within the flash
NAND_PASS: The operation are successfully executed
NAND_FAIL: The operation are not successfully execute
Description: The Sapre Read operation issue a Spare Read Command as explained
in the datasheet of the 528 byte/264 word page family.
The only value of the pointer is 50h. That means the Spare Read
operation starts to read directly in the spare area.
The Random Read, the serial read and the sequentially row read
operations are possible.
******************************************************************************/
NAND_Ret NAND_SpareRead(udword udAddress, dataWidth *Buffer, udword udlength){
udword udIndex;
ubyte ubStatus;
uword uwFarToPage;
/* Control if the address is within the flash*/
if ( udAddress >= FLASH_SIZE )
return NAND_FLASH_SIZE_OVERFLOW;
/* Set the address pointer */
NAND_CommandInput((ubyte)0x50); /* Spare Area*/
InsertAddress(udAddress);
/* Wait for ready */
ubStatus=waitForReady();
/* Leave Read Status Register mode */
NAND_CommandInput((ubyte)0x50);
#ifdef DMA_ENABLE
/* to do DMA */
#endif
#ifndef DMA_ENABLE
/* Calculate the distance for the page edge*/
uwFarToPage = (PAGE_SPARE_SIZE - (udAddress % PAGE_SPARE_SIZE));
/* Read data to the internal buffer */
udIndex=0;
while(udIndex<udlength)
if ( uwFarToPage == 0 ) {
ubStatus=waitForReady(); /* Wait for ready*/
uwFarToPage = PAGE_SPARE_SIZE;
/* Leave Read Status Register mode */
NAND_CommandInput((ubyte)0x50);
}
else {
Buffer[udIndex++] = NAND_DataOutput();
uwFarToPage--;
}
#endif
NAND_Close();
/* Return Pass or Fail */
return (ubStatus&(0x01));
}
/******************************** NAND_SpareRead *****************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -