device_drive.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #ifndef __DEVICE_DRIVE_H__
  2. #define __DEVICE_DRIVE_H__
  3. #include "typedef.h"
  4. #include "errno-base.h"
  5. #include "ioctl.h"
  6. #ifndef __UBOOT
  7. #ifndef _MANGO_OS_
  8. #define _MANGO_OS_
  9. #endif
  10. #endif
  11. #ifdef _MANGO_OS_
  12. #include "os/os_api.h"
  13. #else
  14. #ifndef __UBOOT
  15. #ifndef _WIN_DEBUG_
  16. #define _WIN_DEBUG_
  17. #endif
  18. #endif
  19. #ifdef _WIN_DEBUG_
  20. #include <pthread.h>
  21. typedef pthread_mutex_t OS_MUTEX;
  22. typedef u32 OS_ERR;
  23. #define OS_ERR_NONE 0
  24. #else
  25. typedef u32 OS_MUTEX, OS_ERR;
  26. #define OS_ERR_NONE 0
  27. #endif
  28. #endif
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. struct dev_mutex {
  33. OS_MUTEX *write_mutex;
  34. OS_MUTEX *read_mutex;
  35. };
  36. typedef enum _dev_type {
  37. DEV_SDCRAD_0 = 0X10,
  38. DEV_SDCRAD_1,
  39. DEV_SDCRAD_2,
  40. DEV_UDISK_H0,
  41. DEV_UDISK_H1,
  42. DEV_UDISK_F0,
  43. DEV_NOR_FLASH,
  44. DEV_NAND_FLASH,
  45. DEV_STORAGE = 0x100,
  46. DEV_LOGIC_DISK = 0x101,
  47. DEV_USB_SLAVE,
  48. DEV_USB_HOST,
  49. DEV_HID = 0x200,
  50. DEV_NET,
  51. DEV_AUDIO,
  52. DEV_ISP,
  53. } dev_type;
  54. // struct partition_table
  55. // {
  56. // int partition_addr;
  57. // int partition_size;
  58. // };
  59. typedef struct DEV_IO {
  60. const char name[8];
  61. s32(*mount)(void *volatile parm);
  62. s32(*unmount)();
  63. s32(*read)(u8 *volatile buf, u32 addr, u32 len);
  64. s32(*write)(u8 *volatile buf, u32 addr, u32 len);
  65. s32(*ioctrl)(void *volatile parm, u32 cmd);
  66. s32(*power)(u32 mod);
  67. s32(*detect)(); //设备状态检测
  68. struct dev_mutex *mutex;
  69. dev_type device_type;
  70. void *private_data;//设备私有属性,用来提供额外接口或者存储一些设备的特性
  71. } dev_io_t;
  72. //设备状态:
  73. typedef enum dev_sta {
  74. DEV_OFFLINE = 0, //--0 设备从在线切换到离线。
  75. DEV_ONLINE = 1, //---1 设备从离线切换到在线。
  76. DEV_HOLD = 2, //---2 其他值表示设备状态未改变。
  77. DEV_POWER_ON = 0x10, // 0x10 – 开机
  78. DEV_POWER_OFF, // 0x11 -关机
  79. DEV_POWER_STANDBY, // 0x12 -待机
  80. DEV_POWER_WAKEUP, // 0x13- 唤醒
  81. } DEV_STA;
  82. //设备错误代码:
  83. typedef enum dev_err {
  84. DEV_ERR_NONE = 0,
  85. DEV_ERR_NOT_MOUNT,
  86. DEV_ERR_OVER_CAPACITY,
  87. DEV_ERR_UNKNOW_CLASS,
  88. DEV_ERR_NOT_READY,//设备已经在线,但是没初始化完成
  89. DEV_ERR_LUN,
  90. DEV_ERR_TIMEOUT,
  91. DEV_ERR_CMD_TIMEOUT,
  92. DEV_ERR_READ_TIMEOUT,//0x08
  93. DEV_ERR_WRITE_TIMEOUT,
  94. DEV_ERR_OFFLINE,//0x0a
  95. DEV_ERR_CRC,
  96. DEV_ERR_CMD_CRC,
  97. DEV_ERR_READ_CRC,
  98. DEV_ERR_WRITE_CRC,
  99. DEV_ERR_CONTROL_STALL,
  100. DEV_ERR_RXSTALL,//0x10
  101. DEV_ERR_TXSTALL,
  102. DEV_ERR_CONTROL,
  103. DEV_ERR_NOT_STORAGE,
  104. DEV_ERR_INVALID_PATH,
  105. DEV_ERR_INVALID_DATA,
  106. DEV_ERR_OUTOFMEMORY,
  107. DEV_ERR_HANDLE_FREE,
  108. DEV_ERR_INVALID_HANDLE,//24
  109. DEV_ERR_INVALID_BUF,
  110. DEV_ERR_INUSE,
  111. DEV_ERR_NO_READ,
  112. DEV_ERR_NO_WRITE,
  113. DEV_ERR_NO_IOCTL,
  114. DEV_ERR_NO_POWER,
  115. DEV_ERR_NOT_EXIST,
  116. DEV_ERR_UNKNOW,
  117. } DEV_ERR;
  118. #define DEV_GENERAL_MAGIC 0xe0
  119. //每个设备必须支持的命令
  120. #define DEV_GET_STATUS _IOR(DEV_GENERAL_MAGIC,0xe0,u32) //获取设备状态,在线、离线、power_on、power_off、standby、……
  121. //设备不支持下面命令时返回 -ENOTTY
  122. #define DEV_GET_BLOCK_SIZE _IOR(DEV_GENERAL_MAGIC,0xe1,u32) //获取存储设备的块大小
  123. #define DEV_GET_BLOCK_NUM _IOR(DEV_GENERAL_MAGIC,0xe2,u32) //获取存储设备的块总数
  124. #define DEV_GET_DEV_ID _IOR(DEV_GENERAL_MAGIC,0xe3,u32) //获取设备的ID。SD/TF 卡返回“sdtf”(0x73647466)
  125. #define DEV_SECTOR_ERASE _IOW(DEV_GENERAL_MAGIC,0xe4,u32) //设备页擦除
  126. #define DEV_BLOCK_ERASE _IOW(DEV_GENERAL_MAGIC,0xe5,u32) //设备块擦除
  127. #define DEV_CHIP_ERASE _IOW(DEV_GENERAL_MAGIC,0xe6,u32) //设备擦除
  128. #define DEV_GET_TYPE _IOR(DEV_GENERAL_MAGIC,0xe7,u32) //返回设备的dev_type
  129. #define DEV_CHECK_WPSTA _IOR(DEV_GENERAL_MAGIC,0xe8,u32) //检测设备写保护状态,当参数为-1的时候返回设备的写包含状态,0的时候解除写保护,1的时候加上写保护
  130. #define typecheck(type,x) \
  131. ({ type __dummy; \
  132. typeof(x) __dummy2; \
  133. (void)(&__dummy == &__dummy2); \
  134. 1; \
  135. })
  136. #ifndef time_after
  137. #define time_after(a,b) (typecheck(u32, a) && \
  138. typecheck(u32, b) && \
  139. ((s32)(b) - (s32)(a) < 0))
  140. #endif
  141. #ifndef time_before
  142. #define time_before(a,b) time_after(b,a)
  143. #endif
  144. #ifdef __cplusplus
  145. }
  146. #endif
  147. #endif