[ ]
 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Homepage FreeRTOS Labs FreeRTOS+TCP FreeRTOS+FAT Contact / Enquiries


FreeRTOS+FAT is still in the lab
FreeRTOS+FAT is already in use in commercial products and we encourage you to try it yourself. Be aware however that FreeRTOS+FAT was acquired by Real Time Engineers Ltd., and is still being documented and updated to ensure it meets our strict quality standards. Please use the forum for support, or contact us directly if you have a specific business interest.

Creating a Media Driver: Reading Sectors
[Creating a FreeRTOS+FAT Media Driver]

Each FreeRTOS+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, /* Destination for data being read. */
                   uint32_t ulSectorNumber, /* Sector from which to start reading data. */
                   uint32_t ulSectorCount,  /* Number of sectors to read. */
                   FF_Disk_t *pxDisk );     /* Describes the disk being read from. */
						
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+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.


/* Each sector is 512 bytes. */
#define ramSECTOR_SIZE    512

static int32_t prvReadRAM( uint8_t *pucDestination,
                           uint32_t ulSectorNumber,
                           uint32_t ulSectorCount,
                           FF_Disk_t *pxDisk )
{
uint8_t *pucSource;

    /* The FF_Disk_t structure describes the media being accessed.  Attributes that
    are common to all media types are stored in the structure directly.  The pvTag
    member of the structure is used to add attributes that are specific to the media
    actually being accessed.  In the case of the RAM disk the pvTag member is just
    used to point to the RAM buffer being used as the disk. */
    pucSource = ( uint8_t * ) pxDisk->pvTag;

    /* Move to the start of the sector being read. */
    pucSource += ( ramSECTOR_SIZE * ulSectorNumber );

    /* Copy the data from the disk.  As this is a RAM disk data can be copied
    using memcpy(). */
    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




[ Back to the top ]    [ About FreeRTOS ]    [ FreeRTOS Labs Sitemap ]    [ Main FreeRTOS Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.