...
A single RAM disk is opened as shown in Listing - Opening a RAM disk volume. The file system initialization (FS_Init()
) function must have previously been called.
ROM/RAM characteristics and performance benchmarks of the RAM disk driver can be found in Driver Characterization. For more information about the FS_DEV_RAM_CFG
structure, see section FS_DEV_RAM_CFG. FS_DEV_RAM_CFG.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
#define APP_CFG_FS_RAM_SEC_SIZE 512 (1)
#define APP_CFG_FS_RAM_NBR_SECS (48 * 1024)
static CPU_INT32U App_FS_RAM_Disk[APP_CFG_FS_RAM_SEC_SIZE * APP_CFG_FS_RAM_NBR_SECS / 4];
CPU_BOOLEAN App_FS_AddRAM (void)
{
FS_ERR err;
FS_DEV_RAM_CFG cfg;
FS_DevDrvAdd((FS_DEV_API *)&FSDev_RAM, (2)
(FS_ERR *)&err);
if ((err != FS_ERR_NONE) && (err != FS_ERR_DEV_DRV_ALREADY_ADDED)) {
return (DEF_FAIL);
}
ram_cfg.SecSize = APP_CFG_FS_RAM_SEC_SIZE; (3)
ram_cfg.Size = APP_CFG_FS_RAM_NBR_SECS;
ram_cfg.DiskPtr = (void *)&App_FS_RAM_Disk[0];
(4)
FSDev_Open((CPU_CHAR *)"ram:0:", (a)
(void *)&ram_cfg, (b)
(FS_ERR *)&err);
if (err != FS_ERR_NONE) {
return (DEF_FAIL);
}
(5)
FSVol_Open((CPU_CHAR *)"ram:0:", (a)
(CPU_CHAR *)"ram:0:", (b)
(FS_PARTITION_NBR ) 0, (c)
(FS_ERR *)&err);
switch (err) {
case FS_ERR_NONE:
APP_TRACE_DBG((" ...opened volume (mounted).\r\n"));
break;
case FS_ERR_PARTITION_NOT_FOUND: /* Volume error. */
APP_TRACE_DBG((" ...opened device (not formatted).\r\n"));
FSVol_Fmt("ram:0:", (void *)0, &err); (6)
if (err != FS_ERR_NONE) {
APP_TRACE_DBG((" ...format failed.\r\n"));
return (DEF_FAIL);
}
break;
default: /* Device error. */
APP_TRACE_DBG((" ...opening volume failed w/err = %d.\r\n\r\n", err));
return (DEF_FAIL);
}
return (DEF_OK);
} |
Panel |
---|
(1) The sector size and number of sectors in the RAM disk must be defined. The sector size should be 512, 1024, 2048 or 4096; the number of sectors will be determined by your application requirements. This defines a 24-MB RAM disk (49152 512-B sectors). On most CPUs, it is beneficial to 32-bit align the RAM disk, since this will speed up access. (2) Register the RAM disk driver (3) The RAM disk parameters—sector size, size (in sectors) and pointer to the disk—should be assigned to a (4) (5) (6) |
If the RAM disk initialization succeeds, the file system will produce the trace output as shown in Figure - RAM disk initialization trace output (if a sufficiently high trace level is configured). See section Trace Configuration about configuring the trace level.
Panel | ||||
---|---|---|---|---|
| ||||