| NUC472_NUC442_BSP V3.04.000 The Board Support Package for NUC472/NUC442

usbh_hub.h
Go to the documentation of this file.
1#ifndef _USB_HUB_H
2#define _USB_HUB_H
3
5
6/*
7 * Hub request types
8 */
9
10#define USB_RT_HUB (USB_TYPE_CLASS | USB_RECIP_DEVICE) /* 0x20 */
11#define USB_RT_PORT (USB_TYPE_CLASS | USB_RECIP_OTHER) /* 0x23 */
12
13/*
14 * Hub Class feature numbers
15 * See USB 2.0 spec Table 11-17
16 */
17#define C_HUB_LOCAL_POWER 0
18#define C_HUB_OVER_CURRENT 1
19
20/*
21 * Port feature numbers
22 * See USB 2.0 spec Table 11-17
23 */
24#define USB_PORT_FEAT_CONNECTION 0
25#define USB_PORT_FEAT_ENABLE 1
26#define USB_PORT_FEAT_SUSPEND 2
27#define USB_PORT_FEAT_OVER_CURRENT 3
28#define USB_PORT_FEAT_RESET 4
29#define USB_PORT_FEAT_POWER 8
30#define USB_PORT_FEAT_LOWSPEED 9
31#define USB_PORT_FEAT_HIGHSPEED 10
32#define USB_PORT_FEAT_C_CONNECTION 16 /* connection change */
33#define USB_PORT_FEAT_C_ENABLE 17
34#define USB_PORT_FEAT_C_SUSPEND 18
35#define USB_PORT_FEAT_C_OVER_CURRENT 19
36#define USB_PORT_FEAT_C_RESET 20
37#define USB_PORT_FEAT_TEST 21 /* USB 2.0 only */
38#define USB_PORT_FEAT_INDICATOR 22 /* USB 2.0 only */
39
40/*
41 * Hub Status and Hub Change results
42 * See USB 2.0 spec Table 11-19 and Table 11-20
43 */
44typedef struct usb_port_status
45{
46 uint16_t wPortStatus;
47 uint16_t wPortChange;
48} USB_PORT_STATUS_T;
49
50/*
51 * wPortStatus bit field
52 * See USB 2.0 spec Table 11-21
53 */
54#define USB_PORT_STAT_CONNECTION 0x0001
55#define USB_PORT_STAT_ENABLE 0x0002
56#define USB_PORT_STAT_SUSPEND 0x0004
57#define USB_PORT_STAT_OVERCURRENT 0x0008
58#define USB_PORT_STAT_RESET 0x0010
59/* bits 5 for 7 are reserved */
60#define USB_PORT_STAT_POWER 0x0100
61#define USB_PORT_STAT_LOW_SPEED 0x0200
62#define USB_PORT_STAT_HIGH_SPEED 0x0400
63#define USB_PORT_STAT_TEST 0x0800
64#define USB_PORT_STAT_INDICATOR 0x1000
65/* bits 13 to 15 are reserved */
66
67/*
68 * wPortChange bit field
69 * See USB 2.0 spec Table 11-22
70 * Bits 0 to 4 shown, bits 5 to 15 are reserved
71 */
72#define USB_PORT_STAT_C_CONNECTION 0x0001
73#define USB_PORT_STAT_C_ENABLE 0x0002
74#define USB_PORT_STAT_C_SUSPEND 0x0004
75#define USB_PORT_STAT_C_OVERCURRENT 0x0008
76#define USB_PORT_STAT_C_RESET 0x0010
77
78/*
79 * wHubCharacteristics (masks)
80 * See USB 2.0 spec Table 11-13, offset 3
81 */
82#define HUB_CHAR_LPSM 0x0003 /* D1 .. D0 */
83#define HUB_CHAR_COMPOUND 0x0004 /* D2 */
84#define HUB_CHAR_OCPM 0x0018 /* D4 .. D3 */
85#define HUB_CHAR_TTTT 0x0060 /* D6 .. D5 */
86#define HUB_CHAR_PORTIND 0x0080 /* D7 */
87
88#ifdef __ICCARM__
89typedef struct usb_hub_status
90{
91 __packed uint16_t wHubStatus;
92 __packed uint16_t wHubChange;
93} USB_HUB_STATUS_T;
94#else
95typedef struct __attribute__((__packed__)) usb_hub_status
96{
97 uint16_t wHubStatus;
98 uint16_t wHubChange;
99} USB_HUB_STATUS_T;
100#endif
101
102/*
103 * Hub Status & Hub Change bit masks
104 * See USB 2.0 spec Table 11-19 and Table 11-20
105 * Bits 0 and 1 for wHubStatus and wHubChange
106 * Bits 2 to 15 are reserved for both
107 */
108#define HUB_STATUS_LOCAL_POWER 0x0001
109#define HUB_STATUS_OVERCURRENT 0x0002
110#define HUB_CHANGE_LOCAL_POWER 0x0001
111#define HUB_CHANGE_OVERCURRENT 0x0002
112
113
114/*
115 * This is a bit arbitrary.
116 * From USB 2.0 spec Table 11-13, offset 7, a hub
117 * can have up to 255 ports. The most ever reported
118 * is 10. So we round it up to the next multiple of
119 * eight. If increasing this, do so to a multiple
120 * of eight to be safe
121 */
122#define MAX_PORTS_PER_HUB 8
123
124/*
125 * Hub descriptor
126 * See USB 2.0 spec Table 11-13
127 */
128#ifdef __ICCARM__
129typedef struct usb_hub_descriptor
130{
131 __packed uint8_t bDescLength;
132 __packed uint8_t bDescriptorType;
133 __packed uint8_t bNbrPorts;
134 __packed uint16_t wHubCharacteristics;
135 __packed uint8_t bPwrOn2PwrGood;
136 __packed uint8_t bHubContrCurrent;
137 __packed uint8_t DeviceRemovable[MAX_PORTS_PER_HUB/8];
138 __packed uint8_t PortPwrCtrlMask[MAX_PORTS_PER_HUB/8];
139} USB_HUB_DESC_T;
140#else
141typedef struct __attribute__((__packed__)) usb_hub_descriptor
142{
143 uint8_t bDescLength;
144 uint8_t bDescriptorType;
145 uint8_t bNbrPorts;
146 uint16_t wHubCharacteristics;
147 uint8_t bPwrOn2PwrGood;
148 uint8_t bHubContrCurrent;
149 uint8_t DeviceRemovable[MAX_PORTS_PER_HUB/8];
150 uint8_t PortPwrCtrlMask[MAX_PORTS_PER_HUB/8];
151} USB_HUB_DESC_T;
152#endif
153
154
155typedef struct usb_hub
156{
157 USB_DEV_T *dev;
158 URB_T *urb; /* Interrupt polling pipe */
159 short error;
160 short nerrors;
161 USB_LIST_T event_list;
162 USB_HUB_DESC_T descriptor;
163 char buffer[(USB_MAXCHILDREN + 1 + 7) / 8];
164 /* add 1 bit for hub status change */
165 /* and add 7 bits to round up to byte boundary */
166} USB_HUB_T;
167
168
169extern USB_HUB_T * usbh_alloc_hubdev(void);
170extern void usbh_free_hubdev(USB_HUB_T *hub);
171
173
174#endif /* _USB_HUB_H */
__attribute__
void *__dso_handle __attribute__((weak))
Definition: _syscalls.c:35
USB_DEV_T
HIDDEN_SYMBOLS struct usb_device USB_DEV_T
urb_t
Definition: usbh_core.h:537