Download FreeRTOS
 

Quality RTOS & Embedded Software

LIBRARIES
WHAT'S NEW
Simplifying Authenticated Cloud Connectivity for Any Device.
Designing an energy efficient and cloud-connected IoT solution with CoAP.
Introducing FreeRTOS Kernel version 11.0.0:
FreeRTOS Roadmap and Code Contribution process.
OPC-UA over TSN with FreeRTOS.

f_read()

[FreeRTOS Embedded File System API]

header_file.h
long f_read( const void *pvBuffer, long lSize, long lItems, F_FILE *pxFileHandle );
		

Reads data from the current read/write position of an open FAT file. The current file read/write position is incremented by the number of bytes read.

A file can only be read if it was opened with one of the following option strings: "r", "r+", "w+" or "a+" (see f_open()).

Parameters:

pvBuffer   A pointer to the buffer into which the read data will be copied.

lSize   The size in bytes of the item being read from the file.

lItems   The number of items being read from the file (the size of each item being set by the lSize parameter).

pxFileHandle   The handle of the file from which the data is being read. The handle is returned by the call to f_open() used to originally open the file.

Returns:
Any value   The returned value is the number of items that were successfully read from the file.

See also

f_getc()

Example usage:


int vSampleFunction( char *pcFileName, char *pucBuffer, long lBufferSize )
{
F_FILE *pxFile;
long lSize, lRead = 0L;

/* Open the pxFile specified by the pcFileName parameter. */
pxFile = f_open( pcFileName, "r" );

if( pxFile != NULL )
{
/* Determine the size of the file. */
lSize = f_filelength( pcFileName );

if( lSize > lBufferSize )
{
lSize = lBufferSize;
}

/* Read the entire file. */
lRead = f_read( pucBuffer, 1, lSize, pxFile );
if( lRead == lSize )
{
/* The entire file was copied into pucBuffer. */
}

/* Close the file again. */
f_close( pxFile );
}

return lSize;
}

Example use of the f_read() API function
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.