USB Pipe
- group USB_Pipe
The module mainly provides common pipe operations for interrupt and bulk endpoint.
This driver supports opening, sending, and receiving data pipes.
How to Use USB Pipes
- Open Pipe
Open data pipe by usb_pipe_open.
- Example
// open in endpoint T_USB_HID_ATTR in_attr = { .zlp = 1, .high_throughput = 0, .congestion_ctrl = USB_PIPE_CONGESTION_CTRL_DROP_CUR, .rsv = 0, .mtu = HID_MAX_TRANSMISSION_UNIT }; void *demo_in_handle = usb_pipe_open(in_desc, in_ep_addr, in_attr, in_pending_req_num, in_cb); // open out endpoint. If you intend to use an output endpoint, you must open that output endpoint // during the initialization phase, prior to USB enumeration, because the alternate setting (alt_set) // function will call \ref usb_pipe_recv. T_USB_HID_ATTR out_attr = { .zlp = 0, .high_throughput = 0, .congestion_ctrl = USB_PIPE_CONGESTION_CTRL_DROP_CUR, .rsv = 0, .mtu = HID_MAX_TRANSMISSION_UNIT }; void *demo_out_handle = usb_pipe_open(out_desc, in_ep_addr, out_attr, out_pending_req_num, out_cb);
- Send Data
Send data by usb_pipe_send.
- Example
usb_hid_data_pipe_send(demo_in_handle, data, length);
Definitions
Defines
-
USB_PIPE_CONGESTION_CTRL_DROP_CUR
Congestion control.
usb_pipe.h
If USB_PIPE_CONGESTION_CTRL_DROP_CUR is set, the current data to be sent will be dropped; otherwise, the first data in the queue will be dropped.
备注
Only effective for in endpoint.
-
USB_PIPE_CONGESTION_CTRL_DROP_FIRST
Congestion control.
usb_pipe.h
If USB_PIPE_CONGESTION_CTRL_DROP_FIRST is set, the first data in the queue will be dropped.
备注
Only effective for in endpoint.
Typedefs
-
typedef struct _usb_pipe_attr T_USB_PIPE_ATTR
USB pipe attribute.
usb_pipe.h
备注
The congestion_control is only effective for input endpoints.
- Param zlp:
Zero length packet.
- Param high_throughput:
If it is set to 1, it can be be executed in the interrupt; otherwise it is excuted in a task.
- Param congestion_ctrl:
If it is set to 0, drop the current data; otherwise drop the first data in the queue.
- Param rsv:
Reserved.
- Param mtu:
The maximum transfer unit.
-
typedef uint32_t (*USB_PIPE_CB)(void *handle, void *buf, uint32_t len, int status)
USB pipe callback.
usb_pipe.h
Functions
-
void *usb_pipe_open(T_USB_ENDPOINT_DESC **desc, uint8_t ep_addr, T_USB_PIPE_ATTR attr, uint8_t pending_req_num, USB_PIPE_CB cb)
Open data pipe.
usb_pipe.h
- 参数:
desc – The descriptor of endpoint.
ep_addr – The address of endpoint.
attr – The pipe attribute of T_USB_PIPE_ATTR.
pending_req_num – The number of supported pending requests.
cb – The application callbacks of USB_PIPE_CB, which will be called after data transmission is completed.
- 返回:
The pipe handle.
-
int usb_pipe_close(void *handle)
Close data pipe.
usb_pipe.h
- 参数:
handle – The return value of usb_pipe_open.
- 返回:
Refer to ‘rtl_errno.h’.
-
int usb_pipe_send(void *handle, void *buf, uint32_t len)
Send data pipe.
usb_pipe.h
The data is sent serially, which means that data will not be actually sent until the previous data transmission is complete.
- 参数:
handle – The return value of usb_pipe_open.
buf – The data to be sent.
len – The length of data.
- 返回:
Refer to ‘rtl_errno.h’.
-
int usb_pipe_recv(void *handle)
Receive data pipe.
usb_pipe.h
- 参数:
handle – The return value of usb_pipe_open.
- 返回:
Refer to ‘rtl_errno.h’.
-
struct _usb_pipe_attr
- #include <usb_pipe.h>
USB pipe attribute.
usb_pipe.h
备注
The congestion_control is only effective for input endpoints.
- Param zlp:
Zero length packet.
- Param high_throughput:
If it is set to 1, it can be be executed in the interrupt; otherwise it is excuted in a task.
- Param congestion_ctrl:
If it is set to 0, drop the current data; otherwise drop the first data in the queue.
- Param rsv:
Reserved.
- Param mtu:
The maximum transfer unit.