hub.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /**************************************************************************//**
  2. * @file hub.h
  3. * @version V1.00
  4. * @brief USB Host hub class driver header file.
  5. *
  6. * SPDX-License-Identifier: Apache-2.0
  7. *
  8. * @copyright (C) 2017 Nuvoton Technology Corp. All rights reserved.
  9. *****************************************************************************/
  10. #ifndef _USBH_HUB_H_
  11. #define _USBH_HUB_H_
  12. /// @cond HIDDEN_SYMBOLS
  13. /*--------------------------------------------------------------------------*/
  14. /* Hub class feature selectors (Table 11-17) */
  15. /*--------------------------------------------------------------------------*/
  16. #define FS_C_HUB_LOCAL_POWER 0
  17. #define FS_C_HUB_OVER_CURRENT 1
  18. #define FS_PORT_CONNECTION 0
  19. #define FS_PORT_ENABLE 1
  20. #define FS_PORT_SUSPEND 2
  21. #define FS_PORT_OVER_CURRENT 3
  22. #define FS_PORT_RESET 4
  23. #define FS_PORT_POWER 8
  24. #define FS_C_PORT_CONNECTION 16
  25. #define FS_C_PORT_ENABLE 17
  26. #define FS_C_PORT_SUSPEND 18
  27. #define FS_C_PORT_OVER_CURRENT 19
  28. #define FS_C_PORT_RESET 20
  29. /*--------------------------------------------------------------------------*/
  30. /* Hub/Port staus and change bits */
  31. /*--------------------------------------------------------------------------*/
  32. #define HUB_S_LOCAL_POWER (1UL << 0)
  33. #define HUB_S_OVERCURRENT (1UL << 1)
  34. #define HUB_C_LOCAL_POWER (1UL << 0)
  35. #define HUB_C_OVERCURRENT (1UL << 1)
  36. #define PORT_S_CONNECTION (1UL << 0)
  37. #define PORT_S_ENABLE (1UL << 1)
  38. #define PORT_S_SUSPEND (1UL << 2)
  39. #define PORT_S_OVERCURRENT (1UL << 3)
  40. #define PORT_S_RESET (1UL << 4)
  41. #define PORT_S_PORT_POWER (1UL << 8)
  42. #define PORT_S_LOW_SPEED (1UL << 9)
  43. #define PORT_S_HIGH_SPEED (1UL << 10)
  44. #define PORT_S_TEST (1UL << 11)
  45. #define PORT_S_INDICATOR (1UL << 12)
  46. #define PORT_C_CONNECTION (1UL << 0)
  47. #define PORT_C_ENABLE (1UL << 1)
  48. #define PORT_C_SUSPEND (1UL << 2)
  49. #define PORT_C_OVERCURRENT (1UL << 3)
  50. #define PORT_C_RESET (1UL << 4)
  51. /*--------------------------------------------------------------------------*/
  52. /* Hub descriptor */
  53. /*--------------------------------------------------------------------------*/
  54. #ifdef __ICCARM__
  55. typedef struct
  56. {
  57. __packed uint8_t bDescLength;
  58. __packed uint8_t bDescriptorType;
  59. __packed uint8_t bNbrPorts;
  60. __packed uint16_t wHubCharacteristics;
  61. __packed uint8_t bPwrOn2PwrGood;
  62. __packed uint8_t bHubContrCurrent;
  63. __packed uint8_t bDeviceRemovble;
  64. __packed uint8_t PortPwrCtrlMask[16];
  65. } DESC_HUB_T;
  66. #else
  67. typedef struct __attribute__((__packed__))
  68. {
  69. uint8_t bDescLength;
  70. uint8_t bDescriptorType;
  71. uint8_t bNbrPorts;
  72. uint16_t wHubCharacteristics;
  73. uint8_t bPwrOn2PwrGood;
  74. uint8_t bHubContrCurrent;
  75. uint8_t bDeviceRemovble;
  76. uint8_t PortPwrCtrlMask[16];
  77. }
  78. DESC_HUB_T;
  79. #endif
  80. /*
  81. * wHubCharacteristics bit field mask
  82. */
  83. #define HUB_CHAR_LPSM 0x0003 /* 00b: global port power, 01b: per port power, 1x: reserved */
  84. #define HUB_CHAR_COMPOUND 0x0004 /* 1: is part of a compond device, 0: is not. */
  85. #define HUB_CHAR_OCPM 0x0018 /* 00b: global over-current protection, 01b: per port, 1x: reserved */
  86. #define HUB_CHAR_TTTT 0x0060 /* TT think time. 00b: 8FS, 01b: 16FS, 10b: 24FS, 11b: 32FS */
  87. #define HUB_CHAR_PORTIND 0x0080 /* 1: port indicator (LED) supported, 0: not */
  88. /* port indicator status selectors */
  89. #define HUB_LED_AUTO 0
  90. #define HUB_LED_AMBER 1
  91. #define HUB_LED_GREEN 2
  92. #define HUB_LED_OFF 3
  93. /*--------------------------------------------------------------------------*/
  94. /* Port reset retry and time-out settings */
  95. /*--------------------------------------------------------------------------*/
  96. #define HUB_DEBOUNCE_TIME 500 /* Hub connect/disconnect de-bounce time in ms */
  97. #define PORT_RESET_RETRY 3 /* port reset retry times */
  98. #define PORT_RESET_TIME_MS 50 /* port reset time (ms) */
  99. #define PORT_RESET_RETRY_INC_MS 250 /* increased reset time (ms) after reset failed */
  100. #define HUB_STATUS_MAX_BYTE 2 /* maximum number of interrupt-in status bytes */
  101. /* 2 can support up to 16 port hubs */
  102. /* 4 can support up to 32 port hubs */
  103. /* Note!! If modeifed to 4, "uint16_t sc_bitmap" */
  104. /* MUST be changed as "uint32_t sc_bitmap" */
  105. typedef struct hub_dev_t
  106. {
  107. IFACE_T *iface; /*!< Interface device of this hub \hideinitializer */
  108. UTR_T *utr; /*!< Interrupt in UTR of this hub \hideinitializer */
  109. uint8_t buff[HUB_STATUS_MAX_BYTE]; /*!< Interrupt in buffer \hideinitializer */
  110. uint16_t sc_bitmap; /*!< Hub and Port Status Change Bitmap \hideinitializer */
  111. uint8_t bNbrPorts; /*!< Number of ports \hideinitializer */
  112. uint8_t bPwrOn2PwrGood; /*!< Hub power on to power good time \hideinitializer */
  113. char pos_id[MAX_HUB_DEVICE+1]; /*!< Hub position identifier \hideinitializer */
  114. int (*port_reset)(struct hub_dev_t *hub, int port);/*!< Port reset function \hideinitializer */
  115. UDEV_T *children; /*!< Child device list. \hideinitializer */
  116. } HUB_DEV_T;
  117. /// @endcond
  118. #endif /* _USBH_HUB_H_ */