core.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * File : core.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2011, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2011-12-12 Yi Qiu first version
  13. */
  14. #ifndef __CORE_H__
  15. #define __CORE_H__
  16. #include <rtthread.h>
  17. #include "usbspec.h"
  18. #include "usbhost.h"
  19. #define USB_MAX_DEVICE 32
  20. #define USB_MAX_INTERFACE 8
  21. #define PORT_NUM 4
  22. #define SIZEOF_USB_REQUEST 8
  23. struct uhcd;
  24. struct uifinst;
  25. struct uhubinst;
  26. typedef void (*func_callback)(void *context);
  27. enum umsg_type
  28. {
  29. USB_MSG_CONNECT_CHANGE,
  30. USB_MSG_CALLBACK,
  31. };
  32. typedef enum umsg_type umsg_type;
  33. #define UINST_STATUS_IDLE 0
  34. #define UINST_STATUS_BUSY 1
  35. #define UINST_STATUS_ERROR 2
  36. struct uinstance
  37. {
  38. struct udevice_descriptor dev_desc;
  39. ucfg_desc_t cfg_desc;
  40. struct uhcd *hcd;
  41. rt_uint8_t status;
  42. rt_uint8_t type;
  43. rt_uint8_t index;
  44. rt_uint8_t address;
  45. rt_uint8_t speed;
  46. rt_uint8_t max_packet_size;
  47. rt_uint8_t port;
  48. struct uhubinst* parent;
  49. struct uifinst* ifinst[USB_MAX_INTERFACE];
  50. };
  51. typedef struct uinstance* uinst_t;
  52. struct uifinst
  53. {
  54. uinst_t uinst;
  55. uintf_desc_t intf_desc;
  56. ucd_t drv;
  57. void *user_data;
  58. };
  59. typedef struct uifinst* uifinst_t;
  60. #define UPIPE_STATUS_OK 0
  61. #define UPIPE_STATUS_STALL 1
  62. #define UPIPE_STATUS_ERROR 2
  63. struct upipe
  64. {
  65. rt_uint32_t status;
  66. struct uendpoint_descriptor ep;
  67. uifinst_t ifinst;
  68. func_callback callback;
  69. void* user_data;
  70. };
  71. typedef struct upipe* upipe_t;
  72. struct umsg
  73. {
  74. umsg_type type;
  75. union
  76. {
  77. struct uhubinst* uhub;
  78. struct
  79. {
  80. func_callback function;
  81. void *context;
  82. }cb;
  83. }content;
  84. };
  85. typedef struct umsg* umsg_t;
  86. uinst_t rt_usb_alloc_instance(void);
  87. rt_err_t rt_usb_attatch_instance(uinst_t uinst);
  88. rt_err_t rt_usb_detach_instance(uinst_t uinst);
  89. rt_err_t rt_usb_get_descriptor(uinst_t uinst, rt_uint8_t type, void* buffer,
  90. int nbytes);
  91. rt_err_t rt_usb_set_configure(uinst_t uinst, int config);
  92. rt_err_t rt_usb_set_address(uinst_t uinst);
  93. rt_err_t rt_usb_set_interface(uinst_t uinst, int intf);
  94. rt_err_t rt_usb_clear_feature(uinst_t uinst, int endpoint, int feature);
  95. rt_err_t rt_usb_get_interface_descriptor(ucfg_desc_t cfg_desc, int num,
  96. uintf_desc_t* intf_desc);
  97. rt_err_t rt_usb_get_endpoint_descriptor(uintf_desc_t intf_desc, int num,
  98. uep_desc_t* ep_desc);
  99. #endif