Merge pull request #4378 from LeeChunHei/usbh_construct
添加多過一個usb host的可能性
This commit is contained in:
commit
9b44734643
|
@ -6,6 +6,7 @@
|
|||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2011-3-12 Yi Qiu first version
|
||||
* 2021-02-23 Leslie Lee provide possibility for multi usb host
|
||||
*/
|
||||
|
||||
#ifndef __RT_USB_HOST_H__
|
||||
|
@ -137,6 +138,7 @@ struct uhcd
|
|||
uhcd_ops_t ops;
|
||||
rt_uint8_t num_ports;
|
||||
uhub_t roothub;
|
||||
struct rt_messagequeue *usb_mq;
|
||||
};
|
||||
typedef struct uhcd* uhcd_t;
|
||||
|
||||
|
@ -163,7 +165,7 @@ struct uhost_msg
|
|||
typedef struct uhost_msg* uhost_msg_t;
|
||||
|
||||
/* usb host system interface */
|
||||
rt_err_t rt_usb_host_init(void);
|
||||
rt_err_t rt_usb_host_init(const char *name);
|
||||
void rt_usbh_hub_init(struct uhcd *hcd);
|
||||
|
||||
/* usb host core interface */
|
||||
|
@ -203,7 +205,7 @@ rt_err_t rt_usbh_hub_clear_port_feature(uhub_t uhub, rt_uint16_t port,
|
|||
rt_err_t rt_usbh_hub_set_port_feature(uhub_t uhub, rt_uint16_t port,
|
||||
rt_uint16_t feature);
|
||||
rt_err_t rt_usbh_hub_reset_port(uhub_t uhub, rt_uint16_t port);
|
||||
rt_err_t rt_usbh_event_signal(struct uhost_msg* msg);
|
||||
rt_err_t rt_usbh_event_signal(uhcd_t uhcd, struct uhost_msg* msg);
|
||||
|
||||
|
||||
void rt_usbh_root_hub_connect_handler(struct uhcd *hcd, rt_uint8_t port, rt_bool_t isHS);
|
||||
|
@ -265,5 +267,3 @@ rt_inline int rt_usb_hcd_setup_xfer(uhcd_t hcd, upipe_t pipe, ureq_t setup, int
|
|||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2011-03-12 Yi Qiu first version
|
||||
* 2021-02-23 Leslie Lee provide possibility for multi usb host
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
|
@ -13,6 +14,7 @@
|
|||
#include <drivers/usb_host.h>
|
||||
|
||||
static rt_list_t _driver_list;
|
||||
static rt_bool_t _driver_list_created = RT_FALSE;
|
||||
|
||||
/**
|
||||
* This function will initilize the usb class driver related data structure,
|
||||
|
@ -22,8 +24,11 @@ static rt_list_t _driver_list;
|
|||
*/
|
||||
rt_err_t rt_usbh_class_driver_init(void)
|
||||
{
|
||||
rt_list_init(&_driver_list);
|
||||
|
||||
if (_driver_list_created == RT_FALSE)
|
||||
{
|
||||
rt_list_init(&_driver_list);
|
||||
_driver_list_created = RT_TRUE;
|
||||
}
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
|
@ -39,8 +44,11 @@ rt_err_t rt_usbh_class_driver_register(ucd_t drv)
|
|||
{
|
||||
if (drv == RT_NULL) return -RT_ERROR;
|
||||
|
||||
/* insert class driver into driver list */
|
||||
rt_list_insert_after(&_driver_list, &(drv->list));
|
||||
if (rt_usbh_class_driver_find(drv->class_code, drv->subclass_code) == RT_NULL)
|
||||
{
|
||||
/* insert class driver into driver list */
|
||||
rt_list_insert_after(&_driver_list, &(drv->list));
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
@ -136,5 +144,4 @@ ucd_t rt_usbh_class_driver_find(int class_code, int subclass_code)
|
|||
|
||||
/* not found */
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
}
|
|
@ -6,6 +6,7 @@
|
|||
* 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>
|
||||
|
@ -13,9 +14,9 @@
|
|||
|
||||
#define USB_THREAD_STACK_SIZE 4096
|
||||
|
||||
static struct rt_messagequeue *usb_mq;
|
||||
// static struct rt_messagequeue *usb_mq;
|
||||
static struct uclass_driver hub_driver;
|
||||
static struct uhub root_hub;
|
||||
// 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)
|
||||
{
|
||||
|
@ -92,7 +93,7 @@ void rt_usbh_root_hub_connect_handler(struct uhcd *hcd, rt_uint8_t port, rt_bool
|
|||
{
|
||||
hcd->roothub->port_status[port - 1] |= PORT_LSDA;
|
||||
}
|
||||
rt_usbh_event_signal(&msg);
|
||||
rt_usbh_event_signal(hcd, &msg);
|
||||
}
|
||||
|
||||
void rt_usbh_root_hub_disconnect_handler(struct uhcd *hcd, rt_uint8_t port)
|
||||
|
@ -102,7 +103,7 @@ void rt_usbh_root_hub_disconnect_handler(struct uhcd *hcd, rt_uint8_t port)
|
|||
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(&msg);
|
||||
rt_usbh_event_signal(hcd, &msg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -647,12 +648,13 @@ ucd_t rt_usbh_class_driver_hub(void)
|
|||
*/
|
||||
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(usb_mq, &msg, sizeof(struct uhost_msg), RT_WAITING_FOREVER)
|
||||
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));
|
||||
|
@ -679,12 +681,12 @@ static void rt_usbh_hub_thread_entry(void* parameter)
|
|||
*
|
||||
* @return the error code, RT_EOK on successfully.
|
||||
*/
|
||||
rt_err_t rt_usbh_event_signal(struct uhost_msg* msg)
|
||||
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(usb_mq, (void*)msg, sizeof(struct uhost_msg));
|
||||
rt_mq_send(hcd->usb_mq, (void*)msg, sizeof(struct uhost_msg));
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
@ -698,21 +700,22 @@ rt_err_t rt_usbh_event_signal(struct uhost_msg* msg)
|
|||
void rt_usbh_hub_init(uhcd_t hcd)
|
||||
{
|
||||
rt_thread_t thread;
|
||||
/* link root hub to hcd */
|
||||
root_hub.is_roothub = RT_TRUE;
|
||||
hcd->roothub = &root_hub;
|
||||
root_hub.hcd = hcd;
|
||||
root_hub.num_ports = hcd->num_ports;
|
||||
/* 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 */
|
||||
usb_mq = rt_mq_create("usbh", 32, 16, RT_IPC_FLAG_FIFO);
|
||||
|
||||
hcd->usb_mq = rt_mq_create(hcd->parent.parent.name, 32, 16, RT_IPC_FLAG_FIFO);
|
||||
|
||||
/* create usb hub thread */
|
||||
thread = rt_thread_create("usbh", rt_usbh_hub_thread_entry, RT_NULL,
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -6,6 +6,7 @@
|
|||
* 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>
|
||||
|
@ -22,15 +23,15 @@
|
|||
*
|
||||
* @return none.
|
||||
*/
|
||||
rt_err_t rt_usb_host_init(void)
|
||||
rt_err_t rt_usb_host_init(const char *name)
|
||||
{
|
||||
ucd_t drv;
|
||||
rt_device_t uhc;
|
||||
|
||||
uhc = rt_device_find(USB_HOST_CONTROLLER_NAME);
|
||||
uhc = rt_device_find(name);
|
||||
if(uhc == RT_NULL)
|
||||
{
|
||||
rt_kprintf("can't find usb host controller %s\n", USB_HOST_CONTROLLER_NAME);
|
||||
rt_kprintf("can't find usb host controller %s\n", name);
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
|
@ -44,6 +45,16 @@ rt_err_t rt_usb_host_init(void)
|
|||
/* register mass storage class driver */
|
||||
drv = rt_usbh_class_driver_storage();
|
||||
rt_usbh_class_driver_register(drv);
|
||||
#endif
|
||||
#ifdef RT_USBH_HID
|
||||
/* register mass storage class driver */
|
||||
drv = rt_usbh_class_driver_hid();
|
||||
rt_usbh_class_driver_register(drv);
|
||||
#ifdef RT_USBH_HID_MOUSE
|
||||
uprotocal_t protocal;
|
||||
protocal = rt_usbh_hid_protocal_mouse();
|
||||
rt_usbh_hid_protocal_register(protocal);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* register hub class driver */
|
||||
|
@ -54,5 +65,4 @@ rt_err_t rt_usb_host_init(void)
|
|||
rt_device_init(uhc);
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue