XilinxProcessorIPLib/drivers/nandps/examples/xnandps_cache_example.c
int NandReadWriteCacheExample(u32 NandDeviceId)
{
	int Status;
	u32 Index;
	u32 BlockIndex;
	XNandPs_Config *ConfigPtr;
	u64 Offset;
	u32 Length;
	u32 StartBlock;
	u32 EndBlock;

	/*
	 * Initialize the flash driver.
	 */
	ConfigPtr = XNandPs_LookupConfig(NandDeviceId);
	if (ConfigPtr == NULL) {
		return XST_FAILURE;
	}

	Status = XNandPs_CfgInitialize(NandInstPtr, ConfigPtr,
			ConfigPtr->SmcBase,ConfigPtr->FlashBase);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	StartBlock = NAND_TEST_START_BLOCK;
	EndBlock = NAND_TEST_START_BLOCK + NAND_TEST_NUM_BLOCKS;
	Length = NAND_TEST_BLOCK_SIZE;
	/*
	 * Prepare the write buffer. Fill in the data need to be written into
	 * Flash Device.
	 */
	for (Index = 0; Index < Length; Index++) {
		WriteBuffer[Index] = Index % 256;
	}

	/*
	 * Erase the blocks in the flash
	 */
	for (BlockIndex = StartBlock; BlockIndex < EndBlock; BlockIndex++) {
		/*
		 * Don't erase bad blocks.
		 */
		if (XNandPs_IsBlockBad(NandInstPtr, BlockIndex) == XST_SUCCESS)
		{
			continue;
		}
		/*
		 * Perform erase operation.
		 */
		Status = XNandPs_EraseBlock(NandInstPtr, BlockIndex);
		if (Status != XST_SUCCESS) {
			return Status;
		}
	}

	/*
	 * Perform the read/write operation
	 */
	for (BlockIndex = StartBlock; BlockIndex < EndBlock; BlockIndex++) {
		/*
		 * Don't program bad blocks.
		 */
		if (XNandPs_IsBlockBad(NandInstPtr, BlockIndex) == XST_SUCCESS)
		{
			continue;
		}
		Offset = BlockIndex * NandInstPtr->Geometry.BlockSize;

		/*
		 * Perform the write operation.
		 */
		Status = XNandPs_WriteCache(NandInstPtr, Offset, Length, WriteBuffer, NULL);
		if (Status != XST_SUCCESS) {
			return Status;
		}

		/*
		 * Perform the read operation.
		 */
		Status = XNandPs_ReadCache(NandInstPtr, Offset, Length, ReadBuffer, NULL);
		if (Status != XST_SUCCESS) {
			return Status;
		}

		/*
		 * Compare the data read against the data Written.
		 */
		for (Index = 0; Index < Length; Index++) {
			if (ReadBuffer[Index] != WriteBuffer[Index]) {
				return XST_FAILURE;
			}
		}

		/*
		 * Clear the Receive buffer for next iteration
		 */
		memset(ReadBuffer, 0, Length);
	}

	return XST_SUCCESS;
}
/****************************************************************************/
/**
*
* This function runs a test on the NAND flash device using the basic driver
* functions.
* The function does the following tasks:
*	- Initialize the driver.
*	- Erase the blocks.
*	- Write in to all the blocks.
*	- Read back the data from the blocks.
*	- Compare the data read against the data Written.
*
* @param	NandDeviceId is is the XPAR_<NAND_instance>_DEVICE_ID value
*		from xparameters.h.
*
* @return
*		- XST_SUCCESS if successful.
*		- XST_FAILURE if failed.
*
* @note		When bad blocks are encountered, they are not erased and
*		programmed.
*
****************************************************************************/
This function runs a test on the NAND flash device using the basic driver
functions.
The function does the following tasks:
Initialize the driver.
Erase the blocks.
Write in to all the blocks.
Read back the data from the blocks.
Compare the data read against the data Written.
This function runs a test on the NAND flash device using the basic driver functions . The function does the following tasks : Initialize the driver . Erase the blocks . Write in to all the blocks . Read back the data from the blocks . Compare the data read against the data Written .
int NandReadWriteCacheExample(u32 NandDeviceId)
{
	int Status;
	u32 Index;
	u32 BlockIndex;
	XNandPs_Config *ConfigPtr;
	u64 Offset;
	u32 Length;
	u32 StartBlock;
	u32 EndBlock;
	ConfigPtr = XNandPs_LookupConfig(NandDeviceId);
	if (ConfigPtr == NULL) {
		return XST_FAILURE;
	}
	Status = XNandPs_CfgInitialize(NandInstPtr, ConfigPtr,
			ConfigPtr->SmcBase,ConfigPtr->FlashBase);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	StartBlock = NAND_TEST_START_BLOCK;
	EndBlock = NAND_TEST_START_BLOCK + NAND_TEST_NUM_BLOCKS;
	Length = NAND_TEST_BLOCK_SIZE;
	for (Index = 0; Index < Length; Index++) {
		WriteBuffer[Index] = Index % 256;
	}
	for (BlockIndex = StartBlock; BlockIndex < EndBlock; BlockIndex++) {
		if (XNandPs_IsBlockBad(NandInstPtr, BlockIndex) == XST_SUCCESS)
		{
			continue;
		}
		Status = XNandPs_EraseBlock(NandInstPtr, BlockIndex);
		if (Status != XST_SUCCESS) {
			return Status;
		}
	}
	for (BlockIndex = StartBlock; BlockIndex < EndBlock; BlockIndex++) {
		if (XNandPs_IsBlockBad(NandInstPtr, BlockIndex) == XST_SUCCESS)
		{
			continue;
		}
		Offset = BlockIndex * NandInstPtr->Geometry.BlockSize;
		Status = XNandPs_WriteCache(NandInstPtr, Offset, Length, WriteBuffer, NULL);
		if (Status != XST_SUCCESS) {
			return Status;
		}
		Status = XNandPs_ReadCache(NandInstPtr, Offset, Length, ReadBuffer, NULL);
		if (Status != XST_SUCCESS) {
			return Status;
		}
		for (Index = 0; Index < Length; Index++) {
			if (ReadBuffer[Index] != WriteBuffer[Index]) {
				return XST_FAILURE;
			}
		}
		memset(ReadBuffer, 0, Length);
	}
	return XST_SUCCESS;
}
int NandReadWriteCacheExample ( u32 NandDeviceId ) { int Status ; u32 Index ; u32 BlockIndex ; XNandPs_Config * ConfigPtr ; u64 Offset ; u32 Length ; u32 StartBlock ; u32 EndBlock ; ConfigPtr = XNandPs_LookupConfig ( NandDeviceId ) ; if ( ConfigPtr == NULL ) { return XST_FAILURE ; } Status = XNandPs_CfgInitialize ( NandInstPtr , ConfigPtr , ConfigPtr -> SmcBase , ConfigPtr -> FlashBase ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } StartBlock = NAND_TEST_START_BLOCK ; EndBlock = NAND_TEST_START_BLOCK + NAND_TEST_NUM_BLOCKS ; Length = NAND_TEST_BLOCK_SIZE ; for ( Index = 0 ; Index < Length ; Index ++ ) { WriteBuffer [ Index ] = Index % 256 ; } for ( BlockIndex = StartBlock ; BlockIndex < EndBlock ; BlockIndex ++ ) { if ( XNandPs_IsBlockBad ( NandInstPtr , BlockIndex ) == XST_SUCCESS ) { continue ; } Status = XNandPs_EraseBlock ( NandInstPtr , BlockIndex ) ; if ( Status != XST_SUCCESS ) { return Status ; } } for ( BlockIndex = StartBlock ; BlockIndex < EndBlock ; BlockIndex ++ ) { if ( XNandPs_IsBlockBad ( NandInstPtr , BlockIndex ) == XST_SUCCESS ) { continue ; } Offset = BlockIndex * NandInstPtr -> Geometry . BlockSize ; Status = XNandPs_WriteCache ( NandInstPtr , Offset , Length , WriteBuffer , NULL ) ; if ( Status != XST_SUCCESS ) { return Status ; } Status = XNandPs_ReadCache ( NandInstPtr , Offset , Length , ReadBuffer , NULL ) ; if ( Status != XST_SUCCESS ) { return Status ; } for ( Index = 0 ; Index < Length ; Index ++ ) { if ( ReadBuffer [ Index ] != WriteBuffer [ Index ] ) { return XST_FAILURE ; } } memset ( ReadBuffer , 0 , Length ) ; } return XST_SUCCESS ; }
This function runs a test on the NAND flash device using the basic driver
functions.
This function runs a test on the NAND flash device using the basic driver functions .
/*
	 * Initialize the flash driver.
	 */ /*
	 * Prepare the write buffer. Fill in the data need to be written into
	 * Flash Device.
	 */ /*
	 * Erase the blocks in the flash
	 */ /*
		 * Don't erase bad blocks.
		 */ /*
		 * Perform erase operation.
		 */ /*
	 * Perform the read/write operation
	 */ /*
		 * Don't program bad blocks.
		 */ /*
		 * Perform the write operation.
		 */ /*
		 * Perform the read operation.
		 */ /*
		 * Compare the data read against the data Written.
		 */ /*
		 * Clear the Receive buffer for next iteration
		 */