lib/sw_services/xilffs/examples/xilffs_polled_example.c
int FfsSdPolledExample(void)
{
	FRESULT Res;
	UINT NumBytesRead;
	UINT NumBytesWritten;
	u32 BuffCnt;
	BYTE work[FF_MAX_SS];
	u32 FileSize = (8*1024);

	/*
	 * To test logical drive 0, Path should be "0:/"
	 * For logical drive 1, Path should be "1:/"
	 */
	TCHAR *Path = "0:/";

	for(BuffCnt = 0; BuffCnt < FileSize; BuffCnt++){
		SourceAddress[BuffCnt] = TEST + BuffCnt;
	}

	/*
	 * Register volume work area, initialize device
	 */
	Res = f_mount(&fatfs, Path, 0);

	if (Res != FR_OK) {
		return XST_FAILURE;
	}

	/*
	 * Path - Path to logical driver, 0 - FDISK format.
	 * 0 - Cluster size is automatically determined based on Vol size.
	 */
	Res = f_mkfs(Path, FM_FAT32, 0, work, sizeof work);
	if (Res != FR_OK) {
		return XST_FAILURE;
	}

	/*
	 * Open file with required permissions.
	 * Here - Creating new file with read/write permissions. .
	 * To open file with write permissions, file system should not
	 * be in Read Only mode.
	 */
	SD_File = (char *)FileName;

	Res = f_open(&fil, SD_File, FA_CREATE_ALWAYS | FA_WRITE | FA_READ);
	if (Res) {
		return XST_FAILURE;
	}

	/*
	 * Pointer to beginning of file .
	 */
	Res = f_lseek(&fil, 0);
	if (Res) {
		return XST_FAILURE;
	}

	/*
	 * Write data to file.
	 */
	Res = f_write(&fil, (const void*)SourceAddress, FileSize,
			&NumBytesWritten);
	if (Res) {
		return XST_FAILURE;
	}

	/*
	 * Pointer to beginning of file .
	 */
	Res = f_lseek(&fil, 0);
	if (Res) {
		return XST_FAILURE;
	}

	/*
	 * Read data from file.
	 */
	Res = f_read(&fil, (void*)DestinationAddress, FileSize,
			&NumBytesRead);
	if (Res) {
		return XST_FAILURE;
	}

	/*
	 * Data verification
	 */
	for(BuffCnt = 0; BuffCnt < FileSize; BuffCnt++){
		if(SourceAddress[BuffCnt] != DestinationAddress[BuffCnt]){
			return XST_FAILURE;
		}
	}

	/*
	 * Close file.
	 */
	Res = f_close(&fil);
	if (Res) {
		return XST_FAILURE;
	}

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
*
* File system example using SD driver to write to and read from an SD card
* in polled mode. This example creates a new file on an
* SD card (which is previously formatted with FATFS), write data to the file
* and reads the same data back to verify.
*
* @param	None
*
* @return	XST_SUCCESS if successful, otherwise XST_FAILURE.
*
* @note		None
*
******************************************************************************/
File system example using SD driver to write to and read from an SD card
in polled mode. This example creates a new file on an
SD card (which is previously formatted with FATFS), write data to the file
and reads the same data back to verify.
File system example using SD driver to write to and read from an SD card in polled mode . This example creates a new file on an SD card ( which is previously formatted with FATFS ) write data to the file and reads the same data back to verify .
int FfsSdPolledExample(void)
{
	FRESULT Res;
	UINT NumBytesRead;
	UINT NumBytesWritten;
	u32 BuffCnt;
	BYTE work[FF_MAX_SS];
	u32 FileSize = (8*1024);
	TCHAR *Path = "0:/";
	for(BuffCnt = 0; BuffCnt < FileSize; BuffCnt++){
		SourceAddress[BuffCnt] = TEST + BuffCnt;
	}
	Res = f_mount(&fatfs, Path, 0);
	if (Res != FR_OK) {
		return XST_FAILURE;
	}
	Res = f_mkfs(Path, FM_FAT32, 0, work, sizeof work);
	if (Res != FR_OK) {
		return XST_FAILURE;
	}
	SD_File = (char *)FileName;
	Res = f_open(&fil, SD_File, FA_CREATE_ALWAYS | FA_WRITE | FA_READ);
	if (Res) {
		return XST_FAILURE;
	}
	Res = f_lseek(&fil, 0);
	if (Res) {
		return XST_FAILURE;
	}
	Res = f_write(&fil, (const void*)SourceAddress, FileSize,
			&NumBytesWritten);
	if (Res) {
		return XST_FAILURE;
	}
	Res = f_lseek(&fil, 0);
	if (Res) {
		return XST_FAILURE;
	}
	Res = f_read(&fil, (void*)DestinationAddress, FileSize,
			&NumBytesRead);
	if (Res) {
		return XST_FAILURE;
	}
	for(BuffCnt = 0; BuffCnt < FileSize; BuffCnt++){
		if(SourceAddress[BuffCnt] != DestinationAddress[BuffCnt]){
			return XST_FAILURE;
		}
	}
	Res = f_close(&fil);
	if (Res) {
		return XST_FAILURE;
	}
	return XST_SUCCESS;
}
int FfsSdPolledExample ( void ) { FRESULT Res ; UINT NumBytesRead ; UINT NumBytesWritten ; u32 BuffCnt ; BYTE work [ FF_MAX_SS ] ; u32 FileSize = ( 8 * 1024 ) ; TCHAR * Path = " " ; for ( BuffCnt = 0 ; BuffCnt < FileSize ; BuffCnt ++ ) { SourceAddress [ BuffCnt ] = TEST + BuffCnt ; } Res = f_mount ( & fatfs , Path , 0 ) ; if ( Res != FR_OK ) { return XST_FAILURE ; } Res = f_mkfs ( Path , FM_FAT32 , 0 , work , sizeof work ) ; if ( Res != FR_OK ) { return XST_FAILURE ; } SD_File = ( char * ) FileName ; Res = f_open ( & fil , SD_File , FA_CREATE_ALWAYS | FA_WRITE | FA_READ ) ; if ( Res ) { return XST_FAILURE ; } Res = f_lseek ( & fil , 0 ) ; if ( Res ) { return XST_FAILURE ; } Res = f_write ( & fil , ( const void * ) SourceAddress , FileSize , & NumBytesWritten ) ; if ( Res ) { return XST_FAILURE ; } Res = f_lseek ( & fil , 0 ) ; if ( Res ) { return XST_FAILURE ; } Res = f_read ( & fil , ( void * ) DestinationAddress , FileSize , & NumBytesRead ) ; if ( Res ) { return XST_FAILURE ; } for ( BuffCnt = 0 ; BuffCnt < FileSize ; BuffCnt ++ ) { if ( SourceAddress [ BuffCnt ] != DestinationAddress [ BuffCnt ] ) { return XST_FAILURE ; } } Res = f_close ( & fil ) ; if ( Res ) { return XST_FAILURE ; } return XST_SUCCESS ; }
File system example using SD driver to write to and read from an SD card
in polled mode.
File system example using SD driver to write to and read from an SD card in polled mode .
/*
	 * To test logical drive 0, Path should be "0:/"
	 * For logical drive 1, Path should be "1:/"
	 */ /*
	 * Register volume work area, initialize device
	 */ /*
	 * Path - Path to logical driver, 0 - FDISK format.
	 * 0 - Cluster size is automatically determined based on Vol size.
	 */ /*
	 * Open file with required permissions.
	 * Here - Creating new file with read/write permissions. .
	 * To open file with write permissions, file system should not
	 * be in Read Only mode.
	 */ /*
	 * Pointer to beginning of file .
	 */ /*
	 * Write data to file.
	 */ /*
	 * Pointer to beginning of file .
	 */ /*
	 * Read data from file.
	 */ /*
	 * Data verification
	 */ /*
	 * Close file.
	 */