驱动设备管理

来源:互联网 发布:淘宝最低价最新规则 编辑:程序博客网 时间:2024/06/08 09:31
  • 设备管理作用
  • 设备管理接口使用
  • 设备管理实现

设备管理作用

一个操作系统往往集成很多设备的驱动,比如led灯,按键,PWM,ADC,SD等等设备。如何管理
这些设备,使得应用层可以使用统一的方式去操作这些设备,类似linux操作所有设备当做操作
文件的方式,FOS也是这种方式,用户可以在驱动层去定义open,read,write,iocontrol,close
等接口,在应用层去做对应的设备操作。

设备管理接口使用

驱动层
定义设备操作接口,初始化operation结构体
用户层
调用接口

int device_open(DEVICE * device, char * name, U8 flag);int device_read(DEVICE * device, char * buff, U8 size);int device_write(DEVICE * device, char * buff, U8 size);int device_ioctrl(DEVICE * device, U8 cmd, void *arg);int device_close(DEVICE * device);

设备管理实现

typedef struct OPERATIONS_STR {    int (*open) (char *arg, U8 flag);    int (*read) (char * buff, U8 size);    int (*write) (char * buff, U8 size);    int (*ioctrl) (U8 cmd, void *arg);    int (*close) ();} OPERATIONS;typedef struct DEVICE_STR {    LIST list;    BOOL enable;    const char *name;    OPERATIONS *ops;    U8 open_count;    U8 flag;} DEVICE;

这两个结构体是整个设备管理的核心, OPERATIONS_STR 是设备操作的方式, DEVICE_STR是具体的设备,
每个设备都会被加入设备链表,在链表里面实现设备的增删查改。

device code