hub.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * File : hub.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 __HUB_H__
  15. #define __HUB_H__
  16. #include <rtthread.h>
  17. typedef struct uhubinst* uhubinst_t;
  18. struct uhubinst
  19. {
  20. struct uhub_descriptor hub_desc;
  21. rt_uint8_t num_ports;
  22. rt_uint32_t port_status[PORT_NUM];
  23. struct uinstance* child[PORT_NUM];
  24. rt_bool_t is_roothub;
  25. upipe_t pipe_in;
  26. rt_uint8_t buffer[8];
  27. struct uinstance* self;
  28. struct uhcd *hcd;
  29. };
  30. #define RH_GET_PORT_STATUS 0
  31. #define RH_SET_PORT_STATUS 1
  32. #define RH_CLEAR_PORT_FEATURE 2
  33. #define RH_SET_PORT_FEATURE 3
  34. /*
  35. * Port feature numbers
  36. */
  37. #define PORT_FEAT_CONNECTION 0
  38. #define PORT_FEAT_ENABLE 1
  39. #define PORT_FEAT_SUSPEND 2
  40. #define PORT_FEAT_OVER_CURRENT 3
  41. #define PORT_FEAT_RESET 4
  42. #define PORT_FEAT_POWER 8
  43. #define PORT_FEAT_LOWSPEED 9
  44. #define PORT_FEAT_HIGHSPEED 10
  45. #define PORT_FEAT_C_CONNECTION 16
  46. #define PORT_FEAT_C_ENABLE 17
  47. #define PORT_FEAT_C_SUSPEND 18
  48. #define PORT_FEAT_C_OVER_CURRENT 19
  49. #define PORT_FEAT_C_RESET 20
  50. /*
  51. The HcRhPortStatus[1:NDP] register is used to control and report port events on a per-port
  52. basis. NumberDownstreamPorts represents the number of HcRhPortStatus registers that are
  53. implemented in hardware. The lower word is used to reflect the port status, whereas the upper
  54. word reflects the status change bits. Some status bits are implemented with special write behavior
  55. (see below). If a transaction (token through handshake) is in progress when a write to change
  56. port status occurs, the resulting port status change must be postponed until the transaction
  57. completes. Reserved bits should always be written '0'.
  58. */
  59. #define PORT_CCS 0x00000001UL /* R:CurrentConnectStatus - W:ClearPortEnable */
  60. #define PORT_PES 0x00000002UL /* R:PortEnableStatus - W:SetPortEnable */
  61. #define PORT_PSS 0x00000004UL /* R:PortSuspendStatus - W:SetPortSuspend */
  62. #define PORT_POCI 0x00000008UL /* R:PortOverCurrentIndicator - W:ClearSuspendStatus */
  63. #define PORT_PRS 0x00000010UL /* R:PortResetStatus - W: SetPortReset */
  64. #define PORT_PPS 0x00000100UL /* R:PortPowerStatus - W: SetPortPower */
  65. #define PORT_LSDA 0x00000200UL /* R:LowSpeedDeviceAttached - W:ClearPortPower */
  66. #define PORT_CCSC 0x00010000UL
  67. #define PORT_PESC 0x00020000UL
  68. #define PORT_PSSC 0x00040000UL
  69. #define PORT_POCIC 0x00080000UL
  70. #define PORT_PRSC 0x00100000UL
  71. /*
  72. *Hub Status & Hub Change bit masks
  73. */
  74. #define HUB_STATUS_LOCAL_POWER 0x0001
  75. #define HUB_STATUS_OVERCURRENT 0x0002
  76. #define HUB_CHANGE_LOCAL_POWER 0x0001
  77. #define HUB_CHANGE_OVERCURRENT 0x0002
  78. rt_err_t rt_usb_hub_get_descriptor(uinst_t uinst, rt_uint8_t *buffer,
  79. rt_size_t size);
  80. rt_err_t rt_usb_hub_get_status(uinst_t uinst, rt_uint8_t* buffer);
  81. rt_err_t rt_usb_hub_get_port_status(uhubinst_t uhub, rt_uint16_t port,
  82. rt_uint8_t* buffer);
  83. rt_err_t rt_usb_hub_clear_port_feature(uhubinst_t uhub, rt_uint16_t port,
  84. rt_uint16_t feature);
  85. rt_err_t rt_usb_hub_set_port_feature(uhubinst_t uhub, rt_uint16_t port,
  86. rt_uint16_t feature);
  87. rt_err_t rt_usb_hub_reset_port(uhubinst_t uhub, rt_uint16_t port);
  88. rt_err_t rt_usb_post_event(struct umsg* msg, rt_size_t size);
  89. #endif