RAM Disk Driver

The Embedded SDK includes a RAM disk driver that provides the ability to store file system data within a simple array of RAM memory. The RAM disk driver is useful for validation and debugging since it is such a simple implementation.

The code snippet below illustrates how to create and initialize a RAM disk.

#include "FS/Disk/disk_ram.h"
#include <assert.h>

static RAMDISK disk;                                    /* Allocate a RAM disk */

void APP_Function(void)
{
    ALIGNED(8) static BYTE diskmem[8192];               /* Allocate memory for the RAM disk */
    STATUS status;


    status = RAMDISK_Create(&disk,                      /* Create and initialize the RAM disk */
                            diskmem,                    /* Pointer to the memory used by the disk */
                            512,                        /* Block size, 512 for FAT file systems */
                            sizeof(diskmem) / 512);     /* Number of blocks */

    assert(status == SUCCESS);
}

API Reference

STATUS RAMDISK_Create(RAMDISK* disk, void* mem, UINT32 blksize, UINT32 blkcnt)
Creates and initializes a disk driver that uses RAM memory for data storage.
PARAMETERS
disk A pointer to a caller allocated RAM disk to be initialized.
mem A pointer to the RAM memory that represents the disk image. The specified memory area must be at least (sectorSize * sectorCount) in size.
blksize The size, in bytes, of each of the blocks within the disk.
blkcnt The total number of blocks contained within the disk.
RETURNS
SUCCESS The disk has been initialized.
ERR_NULLREFERENCE The argument 'disk' or 'mem' was found to be NULL.