device.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #ifndef CHRDEV_H
  2. #define CHRDEV_H
  3. #include "generic/typedef.h"
  4. #include "generic/list.h"
  5. //#include "generic/ioctl.h"
  6. #include "generic/atomic.h"
  7. //#include "sys/task.h"
  8. #include "device/ioctl_cmds.h"
  9. struct dev_node;
  10. struct device;
  11. /**@struct device_operations
  12. * @brief device_operations结构体 \n
  13. * otg设备执行哪种类型的操作
  14. */
  15. struct device_operations {
  16. bool (*online)(const struct dev_node *node); ///<设备在线状态查询
  17. int (*init)(const struct dev_node *node, void *); ///<设备初始化
  18. int (*open)(const char *name, struct device **device, void *arg); ///<设备开启
  19. int (*read)(struct device *device, void *buf, u32 len, u32); ///<读操作
  20. int (*write)(struct device *device, void *buf, u32 len, u32); ///<写操作
  21. int (*seek)(struct device *device, u32 offset, int orig); ///<设备搜索
  22. int (*ioctl)(struct device *device, u32 cmd, u32 arg); ///<I/O控制
  23. int (*close)(struct device *device); ///<设备关闭
  24. };
  25. struct dev_node {
  26. const char *name;
  27. const struct device_operations *ops;
  28. void *priv_data;
  29. };
  30. struct device {
  31. atomic_t ref;
  32. void *private_data;
  33. const struct device_operations *ops;
  34. void *platform_data;
  35. void *driver_data;
  36. };
  37. #define REGISTER_DEVICE(node) \
  38. const struct dev_node node sec(.device)
  39. #define REGISTER_DEVICES(node) \
  40. const struct dev_node node[] sec(.device)
  41. int devices_init();
  42. bool dev_online(const char *name);
  43. void *dev_open(const char *name, void *arg);
  44. int dev_read(void *device, void *buf, u32 len);
  45. int dev_write(void *device, void *buf, u32 len);
  46. int dev_seek(void *device, u32 offset, int orig);
  47. int dev_ioctl(void *device, int cmd, u32 arg);
  48. int dev_close(void *device);
  49. int dev_bulk_read(void *_device, void *buf, u32 offset, u32 len);
  50. int dev_bulk_write(void *_device, void *buf, u32 offset, u32 len);
  51. #endif