Using Devices
A device is opened with FSDev_Open()
:
FSDev_Open((CPU_CHAR *)“ide:0:”, /* <-- (a) device name */ (void *) 0, /* <-- (b) pointer to configuration */ (FS_ERR *)&err); /* <-- (c) return error */
The parameters are the device name (a) and a pointer to a device driver-specific configuration structure (b). If a device driver requires no configuration structure (as the SD driver does not), the configuration structure (b) should be passed a NULL
pointer. For other devices, like RAM disks, this must point to a valid structure.
Figure - Device state transition
Prior to FSDev_Open()
being called (a), software is ignorant of the presence, state or characteristics of the particular device. After all references to the device are released (b), this ignorance again prevails, and any buffers or structures are freed for later use.
The return error code from this functions provides important information about the device state:
- If the return error code is
FS_ERR_NONE
, then the device is present, responsive and low-level formatted; basically, it is ready to use. - If the return error code is
FS_ERR_DEV_INVALID_LOW_FMT
, then the device is present and responsive, but must be low-level formatted. The application should next callFSDev_NOR_LowFmt()
for the NOR flash. - If the return error code is
FS_ERR_DEV_NOT_PRESENT
,FS_ERR_DEV_IO
orFS_ERR_DEV_TIMEOUT
, the device is either not present or did not respond. This is an important consideration for removable devices. It is still registered with the file system suite, and the file system will attempt to re-open the device each time the application accesses it. - If any other error code is returned, the device is not registered with the file system. The developer should examine the error code to determine the source of the error.