lib/sw_services/xilflash/examples/xilflash_readwrite_example.c
int FlashReadWriteExample(void)
{
	int Status = XST_FAILURE;
	u32 Index;

	#ifdef XPAR_XFL_DEVICE_FAMILY_INTEL
		#if XFL_TO_ASYNCMODE
		/*
		 * Set Flash to Async mode.
		 */
		if (FLASH_MEM_WIDTH == 1) {
			WRITE_FLASH_8(FLASH_BASE_ADDRESS + ASYNC_ADDR, 0x60);
			WRITE_FLASH_8(FLASH_BASE_ADDRESS + ASYNC_ADDR, 0x03);
		} else if (FLASH_MEM_WIDTH == 2) {
			WRITE_FLASH_16(FLASH_BASE_ADDRESS + ASYNC_ADDR,
					INTEL_CMD_CONFIG_REG_SETUP);
			WRITE_FLASH_16(FLASH_BASE_ADDRESS + ASYNC_ADDR,
					INTEL_CMD_CONFIG_REG_CONFIRM);
		}
		#endif
	#endif

	/*
	 * Initialize the Flash Library.
	 */
	Status = XFlash_Initialize(&FlashInstance, FLASH_BASE_ADDRESS,
				   FLASH_MEM_WIDTH, 0);
	if(Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Reset the Flash Device. This clears the Status registers and puts
	 * the device in Read mode.
	 */
	Status = XFlash_Reset(&FlashInstance);
	if(Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Perform an unlock operation before the erase operation for the Intel
	 * Flash. The erase operation will result in an error if the block is
	 * locked.
	 */
	if ((FlashInstance.CommandSet == XFL_CMDSET_INTEL_STANDARD) ||
	    (FlashInstance.CommandSet == XFL_CMDSET_INTEL_EXTENDED) ||
            (FlashInstance.CommandSet == XFL_CMDSET_INTEL_G18)) {
		Status = XFlash_Unlock(&FlashInstance, BLOCK_OFFSET_ADDR, 0);
		if(Status != XST_SUCCESS) {
			return XST_FAILURE;
		}
	}

	/*
	 * Perform the Erase operation.
	 */
	Status = XFlash_Erase(&FlashInstance, START_ADDRESS, FLASH_TEST_SIZE);
	if(Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Prepare the write buffer. Fill in the data need to be written into
	 * Flash Device.
	 */
	for(Index = 0; Index < FLASH_TEST_SIZE; Index++) {
		WriteBuffer[Index] = Index + 1;
	}

	/*
	 * Perform the Write operation.
	 */
	Status = XFlash_Write(&FlashInstance, START_ADDRESS, FLASH_TEST_SIZE,
								WriteBuffer);
	if(Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Perform the read operation.
	 */
	Status = XFlash_Read(&FlashInstance, START_ADDRESS, FLASH_TEST_SIZE,
								ReadBuffer);
		if(Status != XST_SUCCESS) {
			return XST_FAILURE;
	}

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

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
*
* This function writes, reads, and verifies the data to the Flash device.
*
* @param	None
*
* @return	XST_SUCCESS if successful else XST_FAILURE.
*
* @note		None.
*
******************************************************************************/
This function writes, reads, and verifies the data to the Flash device.
This function writes reads and verifies the data to the Flash device .
int FlashReadWriteExample(void)
{
	int Status = XST_FAILURE;
	u32 Index;
	#ifdef XPAR_XFL_DEVICE_FAMILY_INTEL
		#if XFL_TO_ASYNCMODE
		if (FLASH_MEM_WIDTH == 1) {
			WRITE_FLASH_8(FLASH_BASE_ADDRESS + ASYNC_ADDR, 0x60);
			WRITE_FLASH_8(FLASH_BASE_ADDRESS + ASYNC_ADDR, 0x03);
		} else if (FLASH_MEM_WIDTH == 2) {
			WRITE_FLASH_16(FLASH_BASE_ADDRESS + ASYNC_ADDR,
					INTEL_CMD_CONFIG_REG_SETUP);
			WRITE_FLASH_16(FLASH_BASE_ADDRESS + ASYNC_ADDR,
					INTEL_CMD_CONFIG_REG_CONFIRM);
		}
		#endif
	#endif
	Status = XFlash_Initialize(&FlashInstance, FLASH_BASE_ADDRESS,
				   FLASH_MEM_WIDTH, 0);
	if(Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status = XFlash_Reset(&FlashInstance);
	if(Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	if ((FlashInstance.CommandSet == XFL_CMDSET_INTEL_STANDARD) ||
	    (FlashInstance.CommandSet == XFL_CMDSET_INTEL_EXTENDED) ||
            (FlashInstance.CommandSet == XFL_CMDSET_INTEL_G18)) {
		Status = XFlash_Unlock(&FlashInstance, BLOCK_OFFSET_ADDR, 0);
		if(Status != XST_SUCCESS) {
			return XST_FAILURE;
		}
	}
	Status = XFlash_Erase(&FlashInstance, START_ADDRESS, FLASH_TEST_SIZE);
	if(Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	for(Index = 0; Index < FLASH_TEST_SIZE; Index++) {
		WriteBuffer[Index] = Index + 1;
	}
	Status = XFlash_Write(&FlashInstance, START_ADDRESS, FLASH_TEST_SIZE,
								WriteBuffer);
	if(Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status = XFlash_Read(&FlashInstance, START_ADDRESS, FLASH_TEST_SIZE,
								ReadBuffer);
		if(Status != XST_SUCCESS) {
			return XST_FAILURE;
	}
	for(Index = 0; Index < FLASH_TEST_SIZE; Index++) {
		if(ReadBuffer[Index] != WriteBuffer[Index]) {
			return XST_FAILURE;
		}
	}
	return XST_SUCCESS;
}
int FlashReadWriteExample ( void ) { int Status = XST_FAILURE ; u32 Index ; #ifdef XPAR_XFL_DEVICE_FAMILY_INTEL #if XFL_TO_ASYNCMODE if ( FLASH_MEM_WIDTH == 1 ) { WRITE_FLASH_8 ( FLASH_BASE_ADDRESS + ASYNC_ADDR , 0x60 ) ; WRITE_FLASH_8 ( FLASH_BASE_ADDRESS + ASYNC_ADDR , 0x03 ) ; } else if ( FLASH_MEM_WIDTH == 2 ) { WRITE_FLASH_16 ( FLASH_BASE_ADDRESS + ASYNC_ADDR , INTEL_CMD_CONFIG_REG_SETUP ) ; WRITE_FLASH_16 ( FLASH_BASE_ADDRESS + ASYNC_ADDR , INTEL_CMD_CONFIG_REG_CONFIRM ) ; } #endif #endif Status = XFlash_Initialize ( & FlashInstance , FLASH_BASE_ADDRESS , FLASH_MEM_WIDTH , 0 ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = XFlash_Reset ( & FlashInstance ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } if ( ( FlashInstance . CommandSet == XFL_CMDSET_INTEL_STANDARD ) || ( FlashInstance . CommandSet == XFL_CMDSET_INTEL_EXTENDED ) || ( FlashInstance . CommandSet == XFL_CMDSET_INTEL_G18 ) ) { Status = XFlash_Unlock ( & FlashInstance , BLOCK_OFFSET_ADDR , 0 ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } } Status = XFlash_Erase ( & FlashInstance , START_ADDRESS , FLASH_TEST_SIZE ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } for ( Index = 0 ; Index < FLASH_TEST_SIZE ; Index ++ ) { WriteBuffer [ Index ] = Index + 1 ; } Status = XFlash_Write ( & FlashInstance , START_ADDRESS , FLASH_TEST_SIZE , WriteBuffer ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = XFlash_Read ( & FlashInstance , START_ADDRESS , FLASH_TEST_SIZE , ReadBuffer ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } for ( Index = 0 ; Index < FLASH_TEST_SIZE ; Index ++ ) { if ( ReadBuffer [ Index ] != WriteBuffer [ Index ] ) { return XST_FAILURE ; } } return XST_SUCCESS ; }
This function writes, reads, and verifies the data to the Flash device.
This function writes reads and verifies the data to the Flash device .
/*
		 * Set Flash to Async mode.
		 */ /*
	 * Initialize the Flash Library.
	 */ /*
	 * Reset the Flash Device. This clears the Status registers and puts
	 * the device in Read mode.
	 */ /*
	 * Perform an unlock operation before the erase operation for the Intel
	 * Flash. The erase operation will result in an error if the block is
	 * locked.
	 */ /*
	 * Perform the Erase operation.
	 */ /*
	 * Prepare the write buffer. Fill in the data need to be written into
	 * Flash Device.
	 */ /*
	 * Perform the Write operation.
	 */ /*
	 * Perform the read operation.
	 */ /*
	 * Compare the data read against the data Written.
	 */