1:
9:
10:
14:
#ifndef __USBC_HUB_H__
15:
#define __USBC_HUB_H__
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
#define HUB_MAJOR_VERSION (0x01)
28:
29:
#define HUB_MINOR_VERSION (0x00)
30:
31:
32:
36:
#define HUB_OVRCUR_CALLBACK (1)
37:
38:
48:
#define C_HUB_LOCAL_POWER (0)
49:
50:
#define C_HUB_OVER_CURRENT (1)
51:
52:
53:
54:
#define PORT_CONNECTION (0)
55:
56:
#define PORT_ENABLE (1)
57:
58:
#define PORT_SUSPEND (2)
59:
60:
#define PORT_OVER_CURRENT (3)
61:
62:
#define PORT_RESET (4)
63:
64:
#define PORT_POWER (8)
65:
66:
#define PORT_LOW_SPEED (9)
67:
68:
#define C_PORT_CONNECTION (16)
69:
70:
#define C_PORT_ENABLE (17)
71:
72:
#define C_PORT_SUSPEND (18)
73:
74:
#define C_PORT_OVERCURRENT (19)
75:
76:
#define C_PORT_RESET (20)
77:
78:
#define PORT_TEST (21)
79:
80:
#define PORT_INDICATOR (22)
81:
82:
83:
#define HUB_TASK_STKSZ USB_CL_HUB_TASK_STKSZ
84:
#define HUB_TASK_PRI USB_CL_HUB_TASK_PRI
85:
86:
87:
#define USB_HUB_CLASSID (9)
88:
89:
90:
#define USB_HUB_DEVPROTO_SINGLE (1)
91:
#define USB_HUB_DEVPROTO_MULTI (2)
92:
93:
94:
#define HUB_GET_STATUS_REQ USB_DEVICE_REQUEST_GET_STATUS
95:
#define HUB_CLEAR_FEATURE_REQ USB_DEVICE_REQUEST_CLEAR_FEATURE
96:
#define HUB_SET_FEATURE_REQ USB_DEVICE_REQUEST_SET_FEATURE
97:
#define HUB_GET_DESCRIPTOR_REQ (6)
98:
#define HUB_SET_DESCRIPTOR_REQ (7)
99:
100:
101:
#define GET_HUB_DESCRIPTOR_REQTYPE (0xA0)
102:
#define GET_HUB_DESCRIPTOR_REQ USB_DEVICE_REQUEST_GET_DESCRIPTOR
103:
#define GET_HUB_DESCRIPTOR_VALUE (HUB_DESCRIPTOR_TYPE << 8)
104:
#define GET_HUB_DESCRIPTOR_INDEX (0)
105:
106:
107:
108:
#define CLEAR_HUB_FEATURE (0x20)
109:
#define CLEAR_PORT_FEATURE (0x23)
110:
111:
112:
#define SET_HUB_FEATURE (0x20)
113:
#define SET_PORT_FEATURE (0x23)
114:
115:
116:
#define GET_HUB_STATUS (0xA0)
117:
#define GET_PORT_STATUS (0xA3)
118:
119:
120:
#define CLEAR_TT_BUFFER_BMREQ (0x23)
121:
#define CLEAR_TT_BUFFER_BREQ (8)
122:
123:
124:
#define RESET_TT_BMREQ (0x23)
125:
#define RESET_TT_BREQ (9)
126:
127:
128:
#define GET_TT_STATE_BMREQ (0xA3)
129:
#define GET_TT_STATE_BREQ (10)
130:
131:
132:
#define STOP_TT_BMREQ (0x23)
133:
#define STOP_TT_BREQ (11)
134:
135:
136:
137:
#define USB_HUB_WVALUE_DIR_MSK (0x8000)
138:
139:
#define USB_HUB_WVALUE_EPKIND_MSK (0x1800)
140:
141:
#define USB_HUB_WVALUE_DEVADDR_MSK (0x07F0)
142:
143:
#define USB_HUB_WVALUE_EPNUM_MSK (0x000F)
144:
145:
146:
147:
#define HUB_CHANGE_DETECT (0x01)
148:
#define PORT_CHANGE_OFFSET (0x02)
149:
150:
151:
#define INTERRUPT_BUF_SIZE (1)
152:
#define GET_STATUS_LENGTH (4)
153:
#define DESC_LENGTH (8)
154:
155:
156:
157:
#define USB_PORT_RESET_WAIT (20)
158:
159:
#define USB_DEVICE_CONNECT_WAIT (100)
160:
161:
#define BUS_RESET_TIMEOUT (10)
162:
#define USB_HUB_ENDTASK_TIMEOUT (20000)
163:
166:
#define USB_HUB_GETDESC_RETRY_CNT (3)
167:
168:
169:
#define ON (1)
170:
#define OFF (0)
171:
#define BYTE_MSB (0x80)
172:
#define BYTE_LSB (0x01)
173:
174:
175:
176: 177:
178:
#define HUB_CONN_MAXCNT (USBH_MAX_CLS_ROOTHUB_NUM + USBH_MAX_CLS_HUB_NUM)
179:
180:
181:
#define USB_HUB_MSGKIND_EXITTHREAD ((
void *)0)
182:
183:
#define USB_HUB_MSGKIND_DETECTOVERCURR ((
void *)1)
184:
185:
186:
187:
188:
189:
#define USBH_HUB_MESID_NOTIFY_THREAD_EXIT (USBH_MSGID_KIND_HUB_THREAD | 0x00000000)
190:
191:
#define USBH_HUB_MESID_NOTIFY_INTERRUPT_IN (USBH_MSGID_KIND_HUB_THREAD | 0x00000001)
192:
193:
#define USBH_HUB_MESID_REQ_SUSPEND (USBH_MSGID_KIND_HUB_THREAD | 0x00000002)
194:
195:
#define USBH_HUB_MESID_REQ_RESUME (USBH_MSGID_KIND_HUB_THREAD | 0x00000003)
196:
197:
#define USBH_HUB_MESID_REQ_RE_ATTDET (USBH_MSGID_KIND_HUB_THREAD | 0x00000004)
198:
199:
#define USBH_HUB_MESID_REQ_PORT_SUSPEND (USBH_MSGID_KIND_HUB_THREAD | 0x00000005)
200:
201:
#define USBH_HUB_MESID_REQ_PORT_RESUME (USBH_MSGID_KIND_HUB_THREAD | 0x00000006)
202:
203:
#define USBH_HUB_MESID_REQ_DIS_ATTDET (USBH_MSGID_KIND_HUB_THREAD | 0x00000007)
204:
205:
206:
207:
208:
209:
#define USBH_HUB_MESID_ANS_SUSPEND (USBH_MSGID_KIND_RESPONSE | USBH_HUB_MESID_REQ_SUSPEND)
210:
211:
#define USBH_HUB_MESID_ANS_RESUME (USBH_MSGID_KIND_RESPONSE | USBH_HUB_MESID_REQ_RESUME)
212:
213:
#define USBH_HUB_MESID_ANS_RE_ATTDET (USBH_MSGID_KIND_RESPONSE | USBH_HUB_MESID_REQ_RE_ATTDET)
214:
215:
#define USBH_HUB_MESID_ANS_PORT_SUSPEND (USBH_MSGID_KIND_RESPONSE | USBH_HUB_MESID_REQ_PORT_SUSPEND)
216:
217:
#define USBH_HUB_MESID_ANS_PORT_RESUME (USBH_MSGID_KIND_RESPONSE | USBH_HUB_MESID_REQ_PORT_RESUME)
218:
219:
#define USBH_HUB_MESID_ANS_DIS_ATTDET (USBH_MSGID_KIND_RESPONSE | USBH_HUB_MESID_REQ_DIS_ATTDET)
220:
221:
222:
223:
224:
#define USBH_HUB_RTEY_DLY_GET_PORT_STATUS (100)
225:
226:
227:
228:
229:
#define USBH_HUB_CHKMAX_LOOP_GET_PORT_STATUS (10)
230:
231:
232:
233:
234:
235:
typedef enum _USB_HUB_STATUS {
236: USB_HUB_NON_INIT, 237: USB_HUB_IDLE, 238: USB_HUB_RUN, 239: USB_HUB_EXIT, 240: USB_HUB_ERROR 241: }
USB_HUB_STATUS;
242:
243:
244:
245:
246:
247:
248: 249:
250:
struct usbh_hub_status{
251: uhs_ubit16_t hub_status;
252:
#define HS_HUB_STATUS_LOCAL_POWER ((uhs_ubit16_t)1 << 0)
253:
#define HS_HUB_STATUS_OVER_CURRENT ((uhs_ubit16_t)1 << 1)
254:
255: uhs_ubit16_t hub_change_status;
256:
#define HS_C_HUB_LOCAL_POWER ((uhs_ubit16_t)1 << 0)
257:
#define HS_C_HUB_OVER_CURRENT ((uhs_ubit16_t)1 << 1)
258: };
259:
260:
261:
262: 263:
264:
struct usbh_port_status{
265: uhs_ubit16_t port_status;
266:
267:
#define PS_PORT_CONNECTION ((uhs_ubit16_t)1 << 0)
268:
269:
#define PS_PORT_ENABLE ((uhs_ubit16_t)1 << 1)
270:
271:
#define PS_PORT_SUSPEND ((uhs_ubit16_t)1 << 2)
272:
273:
#define PS_PORT_OVER_CURRENT ((uhs_ubit16_t)1 << 3)
274:
275:
#define PS_PORT_RESET ((uhs_ubit16_t)1 << 4)
276:
277:
#define PS_PORT_POWER ((uhs_ubit16_t)1 << 8)
278:
279:
#define PS_PORT_LOW_SPEED ((uhs_ubit16_t)1 << 9)
280:
281:
#define PS_PORT_HIGH_SPEED ((uhs_ubit16_t)1 << 10)
282:
283:
#define PS_PORT_TEST ((uhs_ubit16_t)1 << 11)
284:
285:
#define PS_PORT_INDICATOR ((uhs_ubit16_t)1 << 12)
286:
287: uhs_ubit16_t port_change_status;
288:
289:
#define PS_C_PORT_CONNECTION ((uhs_ubit16_t)1 << 0)
290:
291:
#define PS_C_PORT_ENABLE ((uhs_ubit16_t)1 << 1)
292:
293:
#define PS_C_PORT_SUSPEND ((uhs_ubit16_t)1 << 2)
294:
295:
#define PS_C_PORT_OVERCURRENT ((uhs_ubit16_t)1 << 3)
296:
297:
#define PS_C_PORT_RESET ((uhs_ubit16_t)1 << 4)
298: };
299:
300:
301:
302: 303:
304:
struct hub_descriptor{
305: uhs_ubit8_t bDescLength;
306: uhs_ubit8_t bDescriptorType;
307:
#define HUB_DESCRIPTOR_TYPE (0x29)
308: uhs_ubit8_t bNbrPorts;
309: uhs_ubit16_t wHubCharacteristics;
310:
#define HUB_POWERSWITCH_MASK (0x03 << 0)
311:
#define GANGED_POWER_SWITCH (0x00 << 0)
312:
#define INDIVIDUAL_POWER_SWITCH (0x01 << 0)
313:
314:
#define HUB_COMPDEVICE_MASK (1 << 2)
315:
#define NOT_COMPOUND_DEVICE (0x00 << 2)
316:
#define COMPOUND_DEVICE (0x01 << 2)
317:
318:
#define HUB_OVERCURRENT_MASK (0x03 << 3)
319:
#define GLOBAL_OVERCURRENT_PROTECTION (0x00 << 3)
320:
#define INDIVIDUAL_OVERCURRENT_PROTECTION (0x01 << 3)
321:
#define NOT_OVERCURRENT_PROTECTION (0x10 << 3)
322:
323:
#define HUB_TTTHINKTIME_MASK (0x03 << 5)
324:
#define TTTHINKTIME_8FS (0x00 << 5)
325:
#define TTTHINKTIME_16FS (0x01 << 5)
326:
#define TTTHINKTIME_24FS (0x10 << 5)
327:
#define TTTHINKTIME_32FS (0x11 << 5)
328:
329:
#define HUB_INDICATORSUPPORT_MASK (0x01 << 7)
330:
#define INDICATORSUPPORT_OFF (0x00 << 7)
331:
#define INDICATORSUPPORT_ON (0x01 << 7)
332:
333: uhs_ubit8_t bPwrOn2PwrGood;
334: uhs_ubit8_t bHubContrCurrent;
335: uhs_ubit8_t DeviceRemovable;
336: uhs_ubit8_t PortPwrCtlMask;
337: };
338:
339:
340:
344:
struct usb_hub_info{
345:
346:
struct usbd_usb_deviceinfo *usbdev;
347:
348:
struct hub_descriptor *hub_desc;
349:
350:
351: uhs_ubit8_t port_num;
352: uhs_ubit16_t PwrOnWait;
353: uhs_ubit8_t current;
354: uhs_ubit8_t power_switch;
355: uhs_ubit8_t compound_device;
356: uhs_ubit8_t current_protect;
357: uhs_ubit8_t tt_thinktime;
358: uhs_ubit8_t indicator_support;
359: uhs_ubit8_t dev_removal;
360:
361:
362: uhs_ubit8_t intr_epnum;
363: uhs_ubit8_t intr_interval;
364: uhs_ubit8_t hub_intr_buf_size;
365:
void *hub_intr_buf;
366:
367:
368:
struct usb_control_block* control_ucb;
369:
struct usb_control_block* intr_ucb;
370:
371: kernel_context_t hub_info_sem;
372: };
373:
374:
375:
376:
377:
378:
struct usb_hub_driver {
379: kernel_context_t mbx_osc;
380: kernel_context_t evt_osc; 381: kernel_context_t thread_info;
382: };
383:
384:
385:
386:
387:
typedef struct {
388:
389: UHS_MSG_COMMON msg_common;
390:
391: } UHS_MSG_HUB_NOTIFY_EXIT_FMT;
392:
393:
394:
395:
396:
typedef struct {
397:
398: UHS_MSG_COMMON msg_common;
399:
struct usb_hub_info *hub_info;
400:
401: } UHS_MSG_HUB_NOTIFY_INTR_IN_FMT;
402:
403:
404: 405: 406: 407: 408:
409:
typedef struct {
410:
411: UHS_MSG_COMMON msg_common;
412:
void *mbox_context;
413:
414: } UHS_MSG_HUB_REQ_SUSPEND_FMT , UHS_MSG_HUB_REQ_RESUME_FMT , UHS_MSG_HUB_REQ_RE_ATTDET_FMT, UHS_MSG_HUB_REQ_DIS_ATTDET_FMT;
415:
416:
417: 418: 419:
420:
typedef struct {
421:
422: UHS_MSG_COMMON msg_common;
423:
void *mbox_context;
424:
struct usb_hub_info *hub_info;
425: uhs_ubit32_t hub_port;
426:
427: } UHS_MSG_HUB_REQ_PORT_SUSPEND , UHS_MSG_HUB_REQ_PORT_RESUME;
428:
429:
430: 431: 432: 433: 434: 435:
436:
typedef struct {
437:
438: UHS_MSG_COMMON msg_common;
439: uhs_status_t result;
440:
441: } UHS_MSG_HUB_ANS_SUSPEND_FMT ,UHS_MSG_HUB_ANS_RESUME_FMT ,UHS_MSG_HUB_ANS_RE_ATTDET_FMT ,UHS_MSG_HUB_ANS_PORT_SUSPEND ,UHS_MSG_HUB_ANS_PORT_RESUME;
442:
443:
444:
445:
446:
#define USBH_HUB_EXCLUSIVE
447:
448:
449:
450:
451:
452:
extern uhs_status_t Usb_HubApi_Init(
void );
453:
extern void Usb_HubApi_Exit(
void );
454:
extern uhs_status_t
Usb_HubApi_PortDevDetach(
struct usbd_usb_deviceinfo* usbdev );
455:
extern uhs_status_t
Usb_HubApi_ClearFeature(
struct usb_hub_info* hub_info, uhs_ubit8_t feature, uhs_ubit16_t port_num );
456:
extern uhs_status_t
Usb_HubApi_SetFeature(
struct usb_hub_info* hub_info, uhs_ubit8_t feature, uhs_ubit16_t port_num );
457:
extern uhs_status_t
Usb_HubApi_GetStatus(
struct usb_hub_info* hub_info,
void* buf, uhs_ubit16_t port_num );
458:
extern uhs_status_t
Usb_HubApi_ClearTTBuffer(
struct usb_hub_info* hub_info, uhs_ubit16_t tt_port,
struct usbd_usb_spliterrinfo *split_err_info);
459:
extern uhs_status_t
Usb_HubApi_RESET_TT(
struct usb_hub_info* hub_info, uhs_ubit16_t tt_port );
460:
extern uhs_status_t Usb_Hub_SendPortReset(
struct usb_hub_info* hub_info, uhs_ubit8_t port_num );
461:
extern void Usb_Hub_ReportStatus(
const char* pFileName, uhs_ubit32_t nLine,
usb_msglevel level, uhs_ubit16_t msgdata, uhs_ubit8_t port_num , uhs_ubit8_t hub_adr );
462:
extern uhs_status_t Usb_Hub_AddHubInfo_List(
struct usb_hub_info* hub_info );
463:
extern uhs_status_t Usb_Hub_DelHubInfo_List(
struct usb_hub_info* hub_info );
464:
extern uhs_status_t Usb_Hub_ChkHubInfo_List(
struct usb_hub_info* hub_info , uhs_ubit8_t *chk_result );
465:
extern uhs_status_t Usb_Hub_SendMsg_exit(
void );
466:
extern uhs_status_t Usb_Hub_SendMsg_intr_in(
struct usb_hub_info *hub_info );
467:
extern uhs_status_t Usb_Hub_SendMsg_with_mbx(
void *resp_mbox_context , uhs_ubit32_t mess_id );
468:
extern uhs_status_t Usb_Hub_SendMsg_with_hubinfo_mbx(
void *resp_mbox_context , uhs_ubit32_t mess_id ,
struct usb_hub_info *hub_info , uhs_ubit32_t hub_port );
469:
extern uhs_status_t Usb_Hub_SendMsg_result(
void *mbox_context , uhs_ubit32_t mess_id , uhs_status_t result );
470:
extern uhs_ubit32_t Usb_Hub_get_suspend_flg(
void );
471:
472:
#endif