Device Driver
Devices drivers for the most popular devices are already available for µC/FS. If you use a particular device for which no driver exist, you should read this section to understand how to build your own driver.
A device driver is registered with the file system by passing a pointer to its API structure as the first parameter of FS_DevDrvAdd()
. The API structure, FS_DEV_API
, includes pointers to eight functions used to control and access the device:
const FS_DEV_API FSDev_#### = { FSDev_####_NameGet, FSDev_####_Init, FSDev_####_Open, FSDev_####_Close, FSDev_####_Rd, #if (FS_CFG_RD_ONLY_EN == DEF_DISABLED) FSDev_####_Wr, #endif FSDev_####_Query, FSDev_####_IO_Ctrl };
The functions which must be implemented are listed and described in the table below.. The first two functions, NameGet()
and Init()
, act upon the driver as a whole; neither should interact with any physical devices. The remaining functions act upon individual devices, and the first argument of each is a pointer to a FS_DEV
structure which holds device information, including the unit number which uniquely identifies the device unit (member UnitNbr
).
Function | Description |
---|---|
NameGet() | Get driver name. |
Init() | Initialize driver. |
Open() | Open a device. |
Close() | Close a device. |
Rd() | Read from a device. |
Wr() | Write to a device. |
Query() | Get information about a device |
IO_Ctrl() | Execute device I/O control operation |