hub.h 5.6 KB

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