Each FreeRTOS-Plus-FAT media driver requires a function that reads sectors
from the media on which the embedded file system is stored. How the read
functions actually work is dependent on the media type. For example, if
the media is a RAM disk then data can be read from the RAM using memcpy(),
but if the media is an SD card then the card's command interface will
have to be used via an MMC or SPI peripheral driver.
The Read Function
The read function can have any name, but must have the following prototype:
int32_t prvFFRead( uint8_t *pucDestination,
uint32_t ulSectorNumber,
uint32_t ulSectorCount,
FF_Disk_t *pxDisk );
The prototype of a function used to read sectors from the media holding the embedded file system
As an example, below is the outline of the read function used by the
FreeRTOS-Plus-FAT RAM disk driver. The full version contains input parameter
checking, and can be found in
/FreeRTOS-Plus/Source/FreeRTOS-Plus-FAT/portable/common/ff_ramdisk.c.
#define ramSECTOR_SIZE 512
static int32_t prvReadRAM( uint8_t *pucDestination,
uint32_t ulSectorNumber,
uint32_t ulSectorCount,
FF_Disk_t *pxDisk )
{
uint8_t *pucSource;
pucSource = ( uint8_t * ) pxDisk->pvTag;
pucSource += ( ramSECTOR_SIZE * ulSectorNumber );
memcpy( ( void * ) pucDestination,
( void * ) pucSource,
( size_t ) ( ulSectorCount * ramSECTOR_SIZE ) );
return FF_ERR_NONE;
}
The read function used by the RAM disk driver - for clarity input parameter checking is not shown
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.