Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
RT-Thread
rt-thread
提交
9b447346
R
rt-thread
项目概览
RT-Thread
/
rt-thread
大约 1 年 前同步成功
通知
774
Star
8911
Fork
4735
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
9b447346
编写于
1月 26, 2022
作者:
G
guo
提交者:
GitHub
1月 26, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4378 from LeeChunHei/usbh_construct
添加多過一個usb host的可能性
上级
32a56685
55a302cd
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
51 addition
and
31 deletion
+51
-31
components/drivers/include/drivers/usb_host.h
components/drivers/include/drivers/usb_host.h
+4
-4
components/drivers/usb/usbhost/core/driver.c
components/drivers/usb/usbhost/core/driver.c
+13
-6
components/drivers/usb/usbhost/core/hub.c
components/drivers/usb/usbhost/core/hub.c
+19
-16
components/drivers/usb/usbhost/core/usbhost.c
components/drivers/usb/usbhost/core/usbhost.c
+15
-5
未找到文件。
components/drivers/include/drivers/usb_host.h
浏览文件 @
9b447346
...
...
@@ -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
components/drivers/usb/usbhost/core/driver.c
浏览文件 @
9b447346
...
...
@@ -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
;
}
}
\ No newline at end of file
components/drivers/usb/usbhost/core/hub.c
浏览文件 @
9b447346
...
...
@@ -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
);
}
}
}
\ No newline at end of file
components/drivers/usb/usbhost/core/usbhost.c
浏览文件 @
9b447346
...
...
@@ -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
;
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录