RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
usb_host.h
浏览该文件的文档.
1/*
2 * Copyright (c) 2006-2023, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2011-3-12 Yi Qiu first version
9 * 2021-02-23 Leslie Lee provide possibility for multi usb host
10 */
11
12#ifndef __RT_USB_HOST_H__
13#define __RT_USB_HOST_H__
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19#include <rtthread.h>
20#include "usb_common.h"
21
22#define USB_MAX_DEVICE 0x20
23#define USB_MAX_INTERFACE 0x08
24#define USB_HUB_PORT_NUM 0x04
25#define SIZEOF_USB_REQUEST 0x08
26
27#define DEV_STATUS_IDLE 0x00
28#define DEV_STATUS_BUSY 0x01
29#define DEV_STATUS_ERROR 0x02
30
31#define UPIPE_STATUS_OK 0x00
32#define UPIPE_STATUS_STALL 0x01
33#define UPIPE_STATUS_ERROR 0x02
34
35#define USBH_PID_SETUP 0x00
36#define USBH_PID_DATA 0x01
37
38struct uhcd;
39struct uhintf;
40struct uhub;
41struct upipe;
42
44{
48
49 rt_err_t (*enable)(void* arg);
50 rt_err_t (*disable)(void* arg);
51
52 void* user_data;
53};
54typedef struct uclass_driver* ucd_t;
55
57{
59 int pro_id;
60
61 rt_err_t (*init)(void* arg);
62 rt_err_t (*callback)(void* arg);
63};
64typedef struct uprotocal* uprotocal_t;
65
89typedef struct uinstance* uinst_t;
90
99
110typedef struct upipe* upipe_t;
111
125typedef struct uhub* uhub_t;
126
128{
130 int (*pipe_xfer) (upipe_t pipe, rt_uint8_t token, void* buffer, int nbytes, int timeout);
133};
134typedef struct uhcd_ops* uhcd_ops_t;
143typedef struct uhcd* uhcd_t;
144
151
153{
155 union
156 {
157 struct uhub* hub;
158 struct
159 {
161 void *context;
164};
165typedef struct uhost_msg* uhost_msg_t;
166
167/* usb host system interface */
168rt_err_t rt_usb_host_init(const char *name);
169void rt_usbh_hub_init(struct uhcd *hcd);
170
171/* usb host core interface */
175rt_err_t rt_usbh_get_descriptor(struct uinstance* device, rt_uint8_t type, void* buffer, int nbytes);
176rt_err_t rt_usbh_set_configure(struct uinstance* device, int config);
179rt_err_t rt_usbh_clear_feature(struct uinstance* device, int endpoint, int feature);
182
183/* usb class driver interface */
189ucd_t rt_usbh_class_driver_find(int class_code, int subclass_code);
190
191/* usb class driver implement */
194
195
196
197/* usb hub interface */
199 rt_size_t size);
202 rt_uint32_t* buffer);
204 rt_uint16_t feature);
206 rt_uint16_t feature);
209
210
213
214/* usb host controller driver interface */
216{
217 RT_ASSERT(inst != RT_NULL);
219 rt_list_insert_before(&inst->pipe, &pipe->list);
220 return RT_EOK;
221}
223{
224 rt_list_t * l;
225 for(l = inst->pipe.next;l != &inst->pipe;l = l->next)
226 {
227 if(rt_list_entry(l,struct upipe,list)->ep.bEndpointAddress == ep_address)
228 {
229 return rt_list_entry(l,struct upipe,list);
230 }
231 }
232 return RT_NULL;
233}
235{
236 *pipe = (upipe_t)rt_malloc(sizeof(struct upipe));
237 if(*pipe == RT_NULL)
238 {
239 return -RT_ERROR;
240 }
241 rt_memset(*pipe,0,sizeof(struct upipe));
242 (*pipe)->inst = inst;
243 rt_memcpy(&(*pipe)->ep,ep,sizeof(struct uendpoint_descriptor));
244 return hcd->ops->open_pipe(*pipe);
245}
247{
248 pipe->callback = callback;
249}
250
252{
255 rt_free(pipe);
256 return RT_EOK;
257}
258
259int rt_usb_hcd_pipe_xfer(uhcd_t hcd, upipe_t pipe, void* buffer, int nbytes, int timeout);
260rt_inline int rt_usb_hcd_setup_xfer(uhcd_t hcd, upipe_t pipe, ureq_t setup, int timeout)
261{
262 return hcd->ops->pipe_xfer(pipe, USBH_PID_SETUP, (void *)setup, 8, timeout);
263}
264
265#ifdef __cplusplus
266}
267#endif
268
269#endif
rt_inline void rt_list_insert_before(rt_list_t *l, rt_list_t *n)
insert a node before a list
#define rt_list_entry(node, type, member)
get the struct for this entry
#define RT_ASSERT(EX)
rt_weak void rt_free(void *ptr)
This function will release the previously allocated memory block by rt_malloc. The released memory bl...
rt_weak void * rt_malloc(rt_size_t size)
Allocate a block of memory with a minimum of 'size' bytes.
int rt_bool_t
rt_base_t rt_err_t
unsigned char rt_uint8_t
unsigned short rt_uint16_t
rt_ubase_t rt_size_t
struct rt_list_node rt_list_t
unsigned int rt_uint32_t
#define RT_NULL
struct rt_list_node * next
rt_err_t(* disable)(void *arg)
rt_err_t(* enable)(void *arg)
rt_err_t(* close_pipe)(upipe_t pipe)
rt_err_t(* open_pipe)(upipe_t pipe)
rt_err_t(* reset_port)(rt_uint8_t port)
int(* pipe_xfer)(upipe_t pipe, rt_uint8_t token, void *buffer, int nbytes, int timeout)
struct rt_messagequeue * usb_mq
struct rt_device parent
uhcd_ops_t ops
uhub_t roothub
rt_uint8_t num_ports
uintf_desc_t intf_desc
void * user_data
struct uinstance * device
ucd_t drv
func_callback function
struct uhost_msg::@020305060061050274016071270013030133242316335024::@107347266142322172023002154023040246357005133104 cb
union uhost_msg::@020305060061050274016071270013030133242316335024 content
struct uhub * hub
uhost_msg_type type
rt_uint8_t num_ports
struct uhub_descriptor hub_desc
struct uhcd * hcd
rt_uint32_t port_status[USB_HUB_PORT_NUM]
struct uinstance * self
rt_bool_t is_roothub
rt_uint8_t buffer[8]
struct uinstance * child[USB_HUB_PORT_NUM]
ucfg_desc_t cfg_desc
struct uhintf * intf[USB_MAX_INTERFACE]
struct upipe * pipe_ep0_in
rt_uint8_t speed
rt_uint8_t type
struct uhcd * hcd
rt_uint8_t max_packet_size
rt_uint8_t address
rt_list_t pipe
rt_uint8_t status
rt_uint8_t port
struct rt_device parent
struct uhub * parent_hub
rt_uint8_t index
struct upipe * pipe_ep0_out
struct udevice_descriptor dev_desc
uinst_t inst
rt_list_t list
rt_uint32_t status
void * user_data
func_callback callback
struct uendpoint_descriptor ep
rt_uint8_t pipe_index
rt_err_t(* init)(void *arg)
rt_list_t list
rt_err_t(* callback)(void *arg)
struct uinterface_descriptor * uintf_desc_t
void(* func_callback)(void *context)
struct uendpoint_descriptor * uep_desc_t
struct urequest * ureq_t
struct uconfig_descriptor * ucfg_desc_t
rt_err_t rt_usbh_hub_get_status(struct uinstance *device, rt_uint32_t *buffer)
struct uhcd_ops * uhcd_ops_t
rt_err_t rt_usbh_class_driver_unregister(ucd_t drv)
rt_err_t rt_usbh_hub_reset_port(uhub_t uhub, rt_uint16_t port)
rt_err_t rt_usbh_class_driver_register(ucd_t drv)
struct uhub * uhub_t
rt_err_t rt_usbh_set_configure(struct uinstance *device, int config)
void rt_usbh_root_hub_connect_handler(struct uhcd *hcd, rt_uint8_t port, rt_bool_t isHS)
rt_inline void rt_usb_pipe_add_callback(upipe_t pipe, func_callback callback)
struct uhcd * uhcd_t
rt_err_t rt_usbh_hub_get_port_status(uhub_t uhub, rt_uint16_t port, rt_uint32_t *buffer)
uhost_msg_type
@ USB_MSG_CONNECT_CHANGE
@ USB_MSG_CALLBACK
struct upipe * upipe_t
rt_inline int rt_usb_hcd_setup_xfer(uhcd_t hcd, upipe_t pipe, ureq_t setup, int timeout)
rt_err_t rt_usbh_set_address(struct uinstance *device)
rt_err_t rt_usb_host_init(const char *name)
rt_err_t rt_usbh_hub_set_port_feature(uhub_t uhub, rt_uint16_t port, rt_uint16_t feature)
void rt_usbh_hub_init(struct uhcd *hcd)
rt_err_t rt_usbh_class_driver_disable(ucd_t drv, void *args)
rt_err_t rt_usbh_get_endpoint_descriptor(uintf_desc_t intf_desc, int num, uep_desc_t *ep_desc)
rt_inline rt_err_t rt_usb_hcd_free_pipe(uhcd_t hcd, upipe_t pipe)
struct uinstance * uinst_t
rt_err_t rt_usbh_hub_get_descriptor(struct uinstance *device, rt_uint8_t *buffer, rt_size_t size)
struct uinstance * rt_usbh_alloc_instance(uhcd_t uhcd)
rt_err_t rt_usbh_attatch_instance(struct uinstance *device)
struct uhost_msg * uhost_msg_t
#define USB_MAX_INTERFACE
rt_err_t rt_usbh_get_interface_descriptor(ucfg_desc_t cfg_desc, int num, uintf_desc_t *intf_desc)
#define USB_HUB_PORT_NUM
#define USBH_PID_SETUP
rt_err_t rt_usbh_clear_feature(struct uinstance *device, int endpoint, int feature)
rt_err_t rt_usbh_set_interface(struct uinstance *device, int intf)
rt_err_t rt_usbh_detach_instance(struct uinstance *device)
struct uprotocal * uprotocal_t
rt_err_t rt_usbh_class_driver_enable(ucd_t drv, void *args)
ucd_t rt_usbh_class_driver_hub(void)
rt_inline upipe_t rt_usb_instance_find_pipe(uinst_t inst, rt_uint8_t ep_address)
int rt_usb_hcd_pipe_xfer(uhcd_t hcd, upipe_t pipe, void *buffer, int nbytes, int timeout)
struct uclass_driver * ucd_t
ucd_t rt_usbh_class_driver_find(int class_code, int subclass_code)
rt_err_t rt_usbh_class_driver_init(void)
rt_err_t rt_usbh_hub_clear_port_feature(uhub_t uhub, rt_uint16_t port, rt_uint16_t feature)
rt_inline rt_err_t rt_usb_hcd_alloc_pipe(uhcd_t hcd, upipe_t *pipe, uinst_t inst, uep_desc_t ep)
void rt_usbh_root_hub_disconnect_handler(struct uhcd *hcd, rt_uint8_t port)
ucd_t rt_usbh_class_driver_storage(void)
rt_inline rt_err_t rt_usb_instance_add_pipe(uinst_t inst, upipe_t pipe)
rt_err_t rt_usbh_event_signal(uhcd_t uhcd, struct uhost_msg *msg)
rt_err_t rt_usbh_get_descriptor(struct uinstance *device, rt_uint8_t type, void *buffer, int nbytes)