hub.c
19.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2011-12-12 Yi Qiu first version
* 2021-02-23 Leslie Lee provide possibility for multi usb host
*/
#include <rtthread.h>
#include <drivers/usb_host.h>
#define USB_THREAD_STACK_SIZE 4096
// static struct rt_messagequeue *usb_mq;
static struct uclass_driver hub_driver;
// static struct uhub root_hub;
static rt_err_t root_hub_ctrl(struct uhcd *hcd, rt_uint16_t port, rt_uint8_t cmd, void *args)
{
switch(cmd)
{
case RH_GET_PORT_STATUS:
(*(rt_uint32_t *)args) = hcd->roothub->port_status[port-1];
break;
case RH_SET_PORT_STATUS:
hcd->roothub->port_status[port-1] = (*(rt_uint32_t *)args);
break;
case RH_CLEAR_PORT_FEATURE:
switch(((rt_uint32_t)args))
{
case PORT_FEAT_C_CONNECTION:
hcd->roothub->port_status[port-1] &= ~PORT_CCSC;
break;
case PORT_FEAT_C_ENABLE:
hcd->roothub->port_status[port-1] &= ~PORT_PESC;
break;
case PORT_FEAT_C_SUSPEND:
hcd->roothub->port_status[port-1] &= ~PORT_PSSC;
break;
case PORT_FEAT_C_OVER_CURRENT:
hcd->roothub->port_status[port-1] &= ~PORT_POCIC;
break;
case PORT_FEAT_C_RESET:
hcd->roothub->port_status[port-1] &= ~PORT_PRSC;
break;
}
break;
case RH_SET_PORT_FEATURE:
switch((rt_uint32_t)args)
{
case PORT_FEAT_CONNECTION:
hcd->roothub->port_status[port-1] |= PORT_CCSC;
break;
case PORT_FEAT_ENABLE:
hcd->roothub->port_status[port-1] |= PORT_PESC;
break;
case PORT_FEAT_SUSPEND:
hcd->roothub->port_status[port-1] |= PORT_PSSC;
break;
case PORT_FEAT_OVER_CURRENT:
hcd->roothub->port_status[port-1] |= PORT_POCIC;
break;
case PORT_FEAT_RESET:
hcd->ops->reset_port(port);
break;
case PORT_FEAT_POWER:
break;
case PORT_FEAT_LOWSPEED:
break;
case PORT_FEAT_HIGHSPEED:
break;
}
break;
default:
return RT_ERROR;
}
return RT_EOK;
}
void rt_usbh_root_hub_connect_handler(struct uhcd *hcd, rt_uint8_t port, rt_bool_t isHS)
{
struct uhost_msg msg;
msg.type = USB_MSG_CONNECT_CHANGE;
msg.content.hub = hcd->roothub;
hcd->roothub->port_status[port - 1] |= PORT_CCS | PORT_CCSC;
if(isHS)
{
hcd->roothub->port_status[port - 1] &= ~PORT_LSDA;
}
else
{
hcd->roothub->port_status[port - 1] |= PORT_LSDA;
}
rt_usbh_event_signal(hcd, &msg);
}
void rt_usbh_root_hub_disconnect_handler(struct uhcd *hcd, rt_uint8_t port)
{
struct uhost_msg msg;
msg.type = USB_MSG_CONNECT_CHANGE;
msg.content.hub = hcd->roothub;
hcd->roothub->port_status[port - 1] |= PORT_CCSC;
hcd->roothub->port_status[port - 1] &= ~PORT_CCS;
rt_usbh_event_signal(hcd, &msg);
}
/**
* This function will do USB_REQ_GET_DESCRIPTOR bRequest for the device instance
* to get usb hub descriptor.
*
* @param intf the interface instance.
* @buffer the data buffer to save usb hub descriptor.
* @param nbytes the size of buffer
*
* @return the error code, RT_EOK on successfully.
*/
rt_err_t rt_usbh_hub_get_descriptor(struct uinstance* device, rt_uint8_t *buffer, rt_size_t nbytes)
{
struct urequest setup;
int timeout = USB_TIMEOUT_BASIC;
/* parameter check */
RT_ASSERT(device != RT_NULL);
setup.request_type = USB_REQ_TYPE_DIR_IN | USB_REQ_TYPE_CLASS | USB_REQ_TYPE_DEVICE;
setup.bRequest = USB_REQ_GET_DESCRIPTOR;
setup.wIndex = 0;
setup.wLength = nbytes;
setup.wValue = USB_DESC_TYPE_HUB << 8;
if(rt_usb_hcd_setup_xfer(device->hcd, device->pipe_ep0_out, &setup, timeout) == 8)
{
if(rt_usb_hcd_pipe_xfer(device->hcd, device->pipe_ep0_in, buffer, nbytes, timeout) == nbytes)
{
return RT_EOK;
}
}
return -RT_FALSE;
}
/**
* This function will do USB_REQ_GET_STATUS bRequest for the device instance
* to get usb hub status.
*
* @param intf the interface instance.
* @buffer the data buffer to save usb hub status.
*
* @return the error code, RT_EOK on successfully.
*/
rt_err_t rt_usbh_hub_get_status(struct uinstance* device, rt_uint32_t* buffer)
{
struct urequest setup;
int timeout = USB_TIMEOUT_BASIC;
/* parameter check */
RT_ASSERT(device != RT_NULL);
setup.request_type = USB_REQ_TYPE_DIR_IN | USB_REQ_TYPE_CLASS | USB_REQ_TYPE_DEVICE;
setup.bRequest = USB_REQ_GET_STATUS;
setup.wIndex = 0;
setup.wLength = 4;
setup.wValue = 0;
if(rt_usb_hcd_setup_xfer(device->hcd, device->pipe_ep0_out, &setup, timeout) == 8)
{
if(rt_usb_hcd_pipe_xfer(device->hcd, device->pipe_ep0_in, buffer, 4, timeout) == 4)
{
return RT_EOK;
}
}
return -RT_FALSE;
}
/**
* This function will do USB_REQ_GET_STATUS bRequest for the device instance
* to get hub port status.
*
* @param intf the interface instance.
* @port the hub port to get status.
* @buffer the data buffer to save usb hub status.
*
* @return the error code, RT_EOK on successfully.
*/
rt_err_t rt_usbh_hub_get_port_status(uhub_t hub, rt_uint16_t port, rt_uint32_t* buffer)
{
struct urequest setup;
int timeout = USB_TIMEOUT_BASIC;
/* parameter check */
RT_ASSERT(hub != RT_NULL);
/* get roothub port status */
if(hub->is_roothub)
{
root_hub_ctrl(hub->hcd, port, RH_GET_PORT_STATUS,
(void*)buffer);
return RT_EOK;
}
setup.request_type = USB_REQ_TYPE_DIR_IN | USB_REQ_TYPE_CLASS | USB_REQ_TYPE_OTHER;
setup.bRequest = USB_REQ_GET_STATUS;
setup.wIndex = port;
setup.wLength = 4;
setup.wValue = 0;
if(rt_usb_hcd_setup_xfer(hub->hcd, hub->self->pipe_ep0_out, &setup, timeout) == 8)
{
if(rt_usb_hcd_pipe_xfer(hub->hcd, hub->self->pipe_ep0_in, buffer, 4, timeout) == 4)
{
return RT_EOK;
}
}
return -RT_FALSE;
}
/**
* This function will do USB_REQ_CLEAR_FEATURE bRequest for the device instance
* to clear feature of the hub port.
*
* @param intf the interface instance.
* @port the hub port.
* @feature feature to be cleared.
*
* @return the error code, RT_EOK on successfully.
*/
rt_err_t rt_usbh_hub_clear_port_feature(uhub_t hub, rt_uint16_t port, rt_uint16_t feature)
{
struct urequest setup;
int timeout = USB_TIMEOUT_BASIC;
/* parameter check */
RT_ASSERT(hub != RT_NULL);
/* clear roothub feature */
if(hub->is_roothub)
{
root_hub_ctrl(hub->hcd, port, RH_CLEAR_PORT_FEATURE,
(void*)(rt_uint32_t)feature);
return RT_EOK;
}
setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_CLASS |
USB_REQ_TYPE_OTHER;
setup.bRequest = USB_REQ_CLEAR_FEATURE;
setup.wIndex = port;
setup.wLength = 0;
setup.wValue = feature;
if(rt_usb_hcd_setup_xfer(hub->hcd, hub->self->pipe_ep0_out, &setup, timeout) == 8)
{
return RT_EOK;
}
return -RT_FALSE;
}
/**
* This function will do USB_REQ_SET_FEATURE bRequest for the device instance
* to set feature of the hub port.
*
* @param intf the interface instance.
* @port the hub port.
* @feature feature to be set.
*
* @return the error code, RT_EOK on successfully.
*/
rt_err_t rt_usbh_hub_set_port_feature(uhub_t hub, rt_uint16_t port,
rt_uint16_t feature)
{
struct urequest setup;
int timeout = USB_TIMEOUT_BASIC;
/* parameter check */
RT_ASSERT(hub != RT_NULL);
/* clear roothub feature */
if(hub->is_roothub)
{
root_hub_ctrl(hub->hcd, port, RH_SET_PORT_FEATURE,
(void*)(rt_uint32_t)feature);
return RT_EOK;
}
setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_CLASS |
USB_REQ_TYPE_OTHER;
setup.bRequest = USB_REQ_SET_FEATURE;
setup.wIndex = port;
setup.wLength = 0;
setup.wValue = feature;
if(rt_usb_hcd_setup_xfer(hub->hcd, hub->self->pipe_ep0_out, &setup, timeout) == 8)
{
return RT_EOK;
}
else return -RT_FALSE;
}
/**
* This function will rest hub port, it is invoked when sub device attached to the hub port.
*
* @param intf the interface instance.
* @param port the hub port.
*
* @return the error code, RT_EOK on successfully.
*/
rt_err_t rt_usbh_hub_reset_port(uhub_t hub, rt_uint16_t port)
{
rt_err_t ret;
rt_uint32_t pstatus;
/* parameter check */
RT_ASSERT(hub != RT_NULL);
rt_thread_delay(50);
/* reset hub port */
ret = rt_usbh_hub_set_port_feature(hub, port, PORT_FEAT_RESET);
if(ret != RT_EOK) return ret;
while(1)
{
ret = rt_usbh_hub_get_port_status(hub, port, &pstatus);
if(!(pstatus & PORT_PRS)) break;
}
/* clear port reset feature */
ret = rt_usbh_hub_clear_port_feature(hub, port, PORT_FEAT_C_RESET);
if(ret != RT_EOK) return ret;
rt_thread_delay(50);
return RT_EOK;
}
/**
* This function will do debouce, it is invoked when sub device attached to the hub port.
*
* @param device the usb instance.
* @param port the hub port.
*
* @return the error code, RT_EOK on successfully.
*/
rt_err_t rt_usbh_hub_port_debounce(uhub_t hub, rt_uint16_t port)
{
rt_err_t ret;
int i = 0, times = 20;
rt_uint32_t pstatus;
rt_bool_t connect = RT_TRUE;
int delayticks = USB_DEBOUNCE_TIME / times;
if (delayticks < 1)
delayticks = 1;
/* parameter check */
RT_ASSERT(hub != RT_NULL);
for(i=0; i<times; i++)
{
ret = rt_usbh_hub_get_port_status(hub, port, &pstatus);
if(ret != RT_EOK) return ret;
if(!(pstatus & PORT_CCS))
{
connect = RT_FALSE;
break;
}
rt_thread_delay(delayticks);
}
if(connect) return RT_EOK;
else return -RT_ERROR;
}
/**
* This function will poll all the hub ports to detect port status, especially connect and
* disconnect events.
*
* @param intf the interface instance.
*
* @return the error code, RT_EOK on successfully.
*/
static rt_err_t rt_usbh_hub_port_change(uhub_t hub)
{
int i;
rt_bool_t reconnect;
/* parameter check */
RT_ASSERT(hub != RT_NULL);
/* get usb device instance */
for (i = 0; i < hub->num_ports; i++)
{
rt_err_t ret;
struct uinstance* device;
rt_uint32_t pstatus = 0;
reconnect = RT_FALSE;
/* get hub port status */
ret = rt_usbh_hub_get_port_status(hub, i + 1, &pstatus);
if(ret != RT_EOK) continue;
RT_DEBUG_LOG(RT_DEBUG_USB, ("port %d status 0x%x\n", i + 1, pstatus));
/* check port status change */
if (pstatus & PORT_CCSC)
{
/* clear port status change feature */
rt_usbh_hub_clear_port_feature(hub, i + 1, PORT_FEAT_C_CONNECTION);
reconnect = RT_TRUE;
}
if(pstatus & PORT_PESC)
{
rt_usbh_hub_clear_port_feature(hub, i + 1, PORT_FEAT_C_ENABLE);
reconnect = RT_TRUE;
}
if(reconnect)
{
if(hub->child[i] != RT_NULL && hub->child[i]->status != DEV_STATUS_IDLE)
{
rt_usbh_detach_instance(hub->child[i]);
/* Child device have been detach. Set hub->child[i] to NULL. */
hub->child[i] = RT_NULL;
}
ret = rt_usbh_hub_port_debounce(hub, i + 1);
if(ret != RT_EOK) continue;
/* allocate an usb instance for new connected device */
device = rt_usbh_alloc_instance(hub->hcd);
if(device == RT_NULL) break;
/* set usb device speed */
device->speed = (pstatus & PORT_LSDA) ? 1 : 0;
device->parent_hub = hub;
device->hcd = hub->hcd;
device->port = i + 1;
hub->child[i] = device;
/* reset usb roothub port */
rt_usbh_hub_reset_port(hub, i + 1);
/* attatch the usb instance to the hcd */
rt_usbh_attatch_instance(device);
}
}
return RT_EOK;
}
/**
* This function is the callback function of hub's int endpoint, it is invoked when data comes.
*
* @param context the context of the callback function.
*
* @return none.
*/
static void rt_usbh_hub_irq(void* context)
{
upipe_t pipe;
uhub_t hub;
int timeout = USB_TIMEOUT_BASIC;
RT_ASSERT(context != RT_NULL);
pipe = (upipe_t)context;
hub = (uhub_t)pipe->user_data;
if(pipe->status != UPIPE_STATUS_OK)
{
RT_DEBUG_LOG(RT_DEBUG_USB,("hub irq error\n"));
return;
}
rt_usbh_hub_port_change(hub);
RT_DEBUG_LOG(RT_DEBUG_USB,("hub int xfer...\n"));
/* parameter check */
RT_ASSERT(pipe->inst->hcd != RT_NULL);
rt_usb_hcd_pipe_xfer(hub->self->hcd, pipe, hub->buffer, pipe->ep.wMaxPacketSize, timeout);
}
/**
* This function will run usb hub class driver when usb hub is detected and identified
* as a hub class device, it will continue to do the enumulate process.
*
* @param arg the argument.
*
* @return the error code, RT_EOK on successfully.
*/
static rt_err_t rt_usbh_hub_enable(void *arg)
{
int i = 0;
rt_err_t ret = RT_EOK;
uep_desc_t ep_desc = RT_NULL;
uhub_t hub;
struct uinstance* device;
struct uhintf* intf = (struct uhintf*)arg;
upipe_t pipe_in = RT_NULL;
int timeout = USB_TIMEOUT_LONG;
/* paremeter check */
RT_ASSERT(intf != RT_NULL);
RT_DEBUG_LOG(RT_DEBUG_USB, ("rt_usbh_hub_run\n"));
/* get usb device instance */
device = intf->device;
/* create a hub instance */
hub = rt_malloc(sizeof(struct uhub));
RT_ASSERT(hub != RT_NULL);
rt_memset(hub, 0, sizeof(struct uhub));
/* make interface instance's user data point to hub instance */
intf->user_data = (void*)hub;
/* get hub descriptor head */
ret = rt_usbh_hub_get_descriptor(device, (rt_uint8_t*)&hub->hub_desc, 8);
if(ret != RT_EOK)
{
rt_kprintf("get hub descriptor failed\n");
return -RT_ERROR;
}
/* get full hub descriptor */
ret = rt_usbh_hub_get_descriptor(device, (rt_uint8_t*)&hub->hub_desc,
hub->hub_desc.length);
if(ret != RT_EOK)
{
rt_kprintf("get hub descriptor again failed\n");
return -RT_ERROR;
}
/* get hub ports number */
/* If hub device supported ports over USB_HUB_PORT_NUM(Ex: 8 port hub). Set hub->num_ports to USB_HUB_PORT_NUM */
if(hub->hub_desc.num_ports > USB_HUB_PORT_NUM)
hub->num_ports = USB_HUB_PORT_NUM;
else
hub->num_ports = hub->hub_desc.num_ports;
hub->hcd = device->hcd;
hub->self = device;
/* reset all hub ports */
for (i = 0; i < hub->num_ports; i++)
{
rt_usbh_hub_set_port_feature(hub, i + 1, PORT_FEAT_POWER);
rt_thread_delay(hub->hub_desc.pwron_to_good
* 2 * RT_TICK_PER_SECOND / 1000 );
}
if(intf->intf_desc->bNumEndpoints != 1)
return -RT_ERROR;
/* get endpoint descriptor from interface descriptor */
rt_usbh_get_endpoint_descriptor(intf->intf_desc, 0, &ep_desc);
if(ep_desc == RT_NULL)
{
rt_kprintf("rt_usb_get_endpoint_descriptor error\n");
return -RT_ERROR;
}
/* the endpoint type of hub class should be interrupt */
if( USB_EP_ATTR(ep_desc->bmAttributes) == USB_EP_ATTR_INT)
{
/* the endpoint direction of hub class should be in */
if(ep_desc->bEndpointAddress & USB_DIR_IN)
{
/* allocate a pipe according to the endpoint type */
pipe_in = rt_usb_instance_find_pipe(device,ep_desc->bEndpointAddress);
if(pipe_in == RT_NULL)
{
return RT_ERROR;
}
rt_usb_pipe_add_callback(pipe_in,rt_usbh_hub_irq);
}
else return -RT_ERROR;
}
/* parameter check */
RT_ASSERT(device->hcd != RT_NULL);
pipe_in->user_data = hub;
rt_usb_hcd_pipe_xfer(hub->hcd, pipe_in, hub->buffer,
pipe_in->ep.wMaxPacketSize, timeout);
return RT_EOK;
}
/**
* This function will be invoked when usb hub plug out is detected and it would clean
* and release all hub class related resources.
*
* @param arg the argument.
*
* @return the error code, RT_EOK on successfully.
*/
static rt_err_t rt_usbh_hub_disable(void* arg)
{
int i;
uhub_t hub;
struct uhintf* intf = (struct uhintf*)arg;
/* paremeter check */
RT_ASSERT(intf != RT_NULL);
RT_DEBUG_LOG(RT_DEBUG_USB, ("rt_usbh_hub_stop\n"));
hub = (uhub_t)intf->user_data;
for(i=0; i<hub->num_ports; i++)
{
if(hub->child[i] != RT_NULL)
rt_usbh_detach_instance(hub->child[i]);
}
if(hub != RT_NULL) rt_free(hub);
return RT_EOK;
}
/**
* This function will register hub class driver to the usb class driver manager.
* and it should be invoked in the usb system initialization.
*
* @return the error code, RT_EOK on successfully.
*/
ucd_t rt_usbh_class_driver_hub(void)
{
hub_driver.class_code = USB_CLASS_HUB;
hub_driver.enable = rt_usbh_hub_enable;
hub_driver.disable = rt_usbh_hub_disable;
return &hub_driver;
}
/**
* This function is the main entry of usb hub thread, it is in charge of
* processing all messages received from the usb message buffer.
*
* @param parameter the parameter of the usb host thread.
*
* @return none.
*/
static void rt_usbh_hub_thread_entry(void* parameter)
{
uhcd_t hcd = (uhcd_t)parameter;
while(1)
{
struct uhost_msg msg;
/* receive message */
if(rt_mq_recv(hcd->usb_mq, &msg, sizeof(struct uhost_msg), RT_WAITING_FOREVER)
!= RT_EOK ) continue;
//RT_DEBUG_LOG(RT_DEBUG_USB, ("msg type %d\n", msg.type));
switch (msg.type)
{
case USB_MSG_CONNECT_CHANGE:
rt_usbh_hub_port_change(msg.content.hub);
break;
case USB_MSG_CALLBACK:
/* invoke callback */
msg.content.cb.function(msg.content.cb.context);
break;
default:
break;
}
}
}
/**
* This function will post an message to the usb message queue,
*
* @param msg the message to be posted
*
* @return the error code, RT_EOK on successfully.
*/
rt_err_t rt_usbh_event_signal(uhcd_t hcd, struct uhost_msg* msg)
{
RT_ASSERT(msg != RT_NULL);
/* send message to usb message queue */
rt_mq_send(hcd->usb_mq, (void*)msg, sizeof(struct uhost_msg));
return RT_EOK;
}
/**
* This function will initialize usb hub thread.
*
* @return none.
*
*/
void rt_usbh_hub_init(uhcd_t hcd)
{
rt_thread_t thread;
/* create root hub for hcd */
hcd->roothub = rt_malloc(sizeof(struct uhub));
rt_memset(hcd->roothub, 0, sizeof(struct uhub));
hcd->roothub->is_roothub = RT_TRUE;
hcd->roothub->hcd = hcd;
hcd->roothub->num_ports = hcd->num_ports;
/* create usb message queue */
hcd->usb_mq = rt_mq_create(hcd->parent.parent.name, 32, 16, RT_IPC_FLAG_FIFO);
/* create usb hub thread */
thread = rt_thread_create(hcd->parent.parent.name, rt_usbh_hub_thread_entry, hcd,
USB_THREAD_STACK_SIZE, 8, 20);
if(thread != RT_NULL)
{
/* startup usb host thread */
rt_thread_startup(thread);
}
}