µC/FS RAM Disk Driver
You are here : Micrium
: Products : µC/FS :
RAM Disk Driver
µC/FS comes with a simple RAM disk driver that makes it possible to use a portion of your system RAM as drive for data storage. This can be very helpful to examine your system performance and may also be used as a in-system test procedure.
Supported hardware
The RAM driver can be used with every target with enough RAM. The size of the disk is defined as the number of sectors reserved for the drive.
Theory of operation
A RAM disk is a portion of memory that you allocate to use as a partition. The RAM disk driver takes some of your memory and pretends that it is a hard drive that you can format, mount, save files to, etc. Remember that every bit of RAM is important for the well being of your system and the bigger your RAM disk is, the less memory there is available for your system.
Fail-safe operation
When power is lost, the data of the RAM drive is typically lost as well except for systems with Battery backup for the RAM used as storage device. For this reason, fail safety is relevant only for systems which provide such battery backup.
Unexpected Reset
The data will be preserved. However, if the Power failure / unexpected Reset interrupts a write operation, the data of the sector may contain partially invalid data.
Power failure
Power failure causes an unexpected Reset and has the same effects.
Wear leveling
The RAM disk driver does not require wear leveling.
Configuring the driver
FS_RAMDISK_Configure()
Description
Configures a single RAM disk instance. This function has to be called from within FS_X_AddDevices() after adding an instance of the RAMDisk driver.
Prototype
void FS_RAMDISK_Configure(U8 Unit,
void * pData,
U16 BytesPerSector,
U32 NumSectors);
| Parameter |
Description |
| Unit |
Number of media (0–n). |
| pData |
Pointer to a data buffer. |
| BytesPerSector |
Number of bytes per sector. |
| NumSectors |
Number of sectors. |
Additional information
The size of the disk is defined as the number of sectors reserved for the drive. Each sector consists of 512 bytes. The minimum value for NumSectors is 7. BytesperSector defines the size of each sector on the RAM disk. A FAT file system needs a minimum sector size of 512 bytes.
Example
/*********************************************************************
*
* FS_X_AddDevices
*
* Function description
* This function is called by the FS during FS_Init().
* It is supposed to add all devices, using primarily FS_AddDevice().
*
* Note
* (1) Other API functions
* Other API functions may NOT be called, since this function is called
* during initialisation. The devices are not yet ready at this point.
*/
void FS_X_AddDevices(void) {
void * pRamDisk;
//
// Allocate memory for the RAM disk
//
pRamDisk = FS_Alloc(RAMDISK_NUM_SECTORS * RAMDISK_BYTES_PER_SECTOR);
//
// Add driver
//
FS_AddDevice(&FS_RAMDISK_Driver);
//
// Configure driver
//
FS_RAMDISK_Configure(0, pRamDisk, RAMDISK_BYTES_PER_SECTOR, RAMDISK_NUM_SECTORS);
}
Adding the driver to µC/FS
To add the driver use FS_AddDevice() with the driver label FS_RAMDISK_Driver. This function has to be called from within FS_X_AddDevices().
Example
FS_AddDevice(&FS_RAMDISK_Driver);
Hardware functions
The RAM disk driver does not need any hardware function.
Addition information
Formatting
A RAM disk is unformatted after each startup. Exceptions from this rule are RAM disks which are memory backed up with a battery.
You have to format every unformatted RAM disk with the FS_Format() function, before you can store data on it. If you use only one RAM disk in your application FS_FORMAT() can be called with an empty string as device name. For example, FS_Format("", NULL);
If you use more then one RAM disk, you have to specify the device name. For example, FS_FORMAT("ram:0:", NULL); for the first device and FS_FORMAT("ram:1:",NULL); for the second.
|