source: mainline/uspace/lib/usb/hcd.h@ 2185776

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 2185776 was 2185776, checked in by Vojtech Horky <vojtechhorky@…>, 15 years ago

Async communication with HCD

Added asynchronous versions of functions for sending/retrieving
data to/from HCD. These work pretty the same as functions for
sending messages in the async framework.

  • Property mode set to 100644
File size: 7.6 KB
Line 
1/*
2 * Copyright (c) 2010 Vojtech Horky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libusb usb
30 * @{
31 */
32/** @file
33 * @brief USB Host Controller Driver.
34 */
35#ifndef LIBUSB_HCD_H_
36#define LIBUSB_HCD_H_
37
38#include "usb.h"
39
40#include <ipc/ipc.h>
41#include <async.h>
42
43/** Maximum size of transaction payload. */
44#define USB_MAX_PAYLOAD_SIZE 1020
45
46/** Opaque handle of active USB transaction.
47 * This handle is when informing about transaction outcome (or status).
48 */
49typedef ipcarg_t usb_transaction_handle_t;
50
51/** USB transaction outcome. */
52typedef enum {
53 USB_OUTCOME_OK,
54 USB_OUTCOME_CRCERROR,
55 USB_OUTCOME_BABBLE
56} usb_transaction_outcome_t;
57
58/** USB packet identifier. */
59typedef enum {
60#define _MAKE_PID_NIBBLE(tag, type) \
61 ((uint8_t)(((tag) << 2) | (type)))
62#define _MAKE_PID(tag, type) \
63 ( \
64 _MAKE_PID_NIBBLE(tag, type) \
65 | ((~_MAKE_PID_NIBBLE(tag, type)) << 4) \
66 )
67 USB_PID_OUT = _MAKE_PID(0, 1),
68 USB_PID_IN = _MAKE_PID(2, 1),
69 USB_PID_SOF = _MAKE_PID(1, 1),
70 USB_PID_SETUP = _MAKE_PID(3, 1),
71
72 USB_PID_DATA0 = _MAKE_PID(0 ,3),
73 USB_PID_DATA1 = _MAKE_PID(2 ,3),
74
75 USB_PID_ACK = _MAKE_PID(0 ,2),
76 USB_PID_NAK = _MAKE_PID(2 ,2),
77 USB_PID_STALL = _MAKE_PID(3 ,2),
78
79 USB_PID_PRE = _MAKE_PID(3 ,0),
80 /* USB_PID_ = _MAKE_PID( ,), */
81#undef _MAKE_PID
82#undef _MAKE_PID_NIBBLE
83} usb_packet_id;
84
85const char * usb_str_transaction_outcome(usb_transaction_outcome_t o);
86
87/** IPC methods for HCD. */
88typedef enum {
89 /** Send data over USB to a function.
90 * This method initializes large data transfer that must follow
91 * immediatelly.
92 * The recipient of this method must issue immediately data reception
93 * and answer this call after data buffer was transfered.
94 *
95 * Arguments of the call:
96 * - USB address of the function
97 * - endpoint of the function
98 * - transfer type
99 * - flags (not used)
100 *
101 * Answer:
102 * - EOK - ready to accept the data buffer
103 * - ELIMIT - too many transactions for current connection
104 * - ENOENT - callback connection does not exist
105 * - EINVAL - other kind of error
106 *
107 * Arguments of the answer:
108 * - opaque transaction handle (used in callbacks)
109 */
110 IPC_M_USB_HCD_SEND_DATA = IPC_FIRST_USER_METHOD,
111
112 /** Initiate data receive from a function.
113 * This method announces the HCD that some data will come.
114 * When this data arrives, the HCD will call back with
115 * IPC_M_USB_HCD_DATA_RECEIVED.
116 *
117 * Arguments of the call:
118 * - USB address of the function
119 * - endpoint of the function
120 * - transfer type
121 * - buffer size
122 * - flags (not used)
123 *
124 * Answer:
125 * - EOK - HCD accepted the request
126 * - ELIMIT - too many transactions for current connection
127 * - ENOENT - callback connection does not exist
128 *
129 * Arguments of the answer:
130 * - opaque transaction handle (used in callbacks)
131 */
132 IPC_M_USB_HCD_RECEIVE_DATA,
133
134 /** Tell maximum size of the transaction buffer (payload).
135 *
136 * Arguments of the call:
137 * (none)
138 *
139 * Answer:
140 * - EOK - always
141 *
142 * Arguments of the answer:
143 * - buffer size (in bytes):
144 */
145 IPC_M_USB_HCD_TRANSACTION_SIZE,
146
147
148 IPC_M_USB_HCD_INTERRUPT_OUT,
149 IPC_M_USB_HCD_INTERRUPT_IN,
150
151 IPC_M_USB_HCD_CONTROL_WRITE_SETUP,
152 IPC_M_USB_HCD_CONTROL_WRITE_DATA,
153 IPC_M_USB_HCD_CONTROL_WRITE_STATUS,
154
155 IPC_M_USB_HCD_CONTROL_READ_SETUP,
156 IPC_M_USB_HCD_CONTROL_READ_DATA,
157 IPC_M_USB_HCD_CONTROL_READ_STATUS,
158
159 IPC_M_USB_HCD_GET_BUFFER_ASYNC,
160
161 IPC_M_USB_HCD_INTERRUPT_OUT_ASYNC,
162 IPC_M_USB_HCD_INTERRUPT_IN_ASYNC,
163
164 IPC_M_USB_HCD_CONTROL_WRITE_SETUP_ASYNC,
165 IPC_M_USB_HCD_CONTROL_WRITE_DATA_ASYNC,
166 IPC_M_USB_HCD_CONTROL_WRITE_STATUS_ASYNC,
167
168 IPC_M_USB_HCD_CONTROL_READ_SETUP_ASYNC,
169 IPC_M_USB_HCD_CONTROL_READ_DATA_ASYNC,
170 IPC_M_USB_HCD_CONTROL_READ_STATUS_ASYNC,
171 /* IPC_M_USB_HCD_ */
172} usb_hcd_method_t;
173
174/** IPC methods for callbacks from HCD. */
175typedef enum {
176 /** Confimation after data sent.
177 *
178 * Arguments of the call:
179 * - transaction handle
180 * - transaction outcome
181 */
182 IPC_M_USB_HCD_DATA_SENT = IPC_FIRST_USER_METHOD,
183
184 /** Notification of data received.
185 * This call initiates sending a data buffer from HCD to the client.
186 * See IPC_M_USB_HCD_SEND_DATA for details for buffer transfer is
187 * done.
188 *
189 * Arguments of the call:
190 * - transaction handle
191 * - transaction outcome
192 * - actual data length
193 */
194 IPC_M_USB_HCD_DATA_RECEIVED,
195
196 /** Notification about a serious trouble with HC.
197 */
198 IPC_M_USB_HCD_CONTROLLER_FAILURE,
199
200 /* IPC_M_USB_HCD_ */
201} usb_hcd_callback_method_t;
202
203
204int usb_hcd_create_phones(const char *, async_client_conn_t);
205int usb_hcd_send_data_to_function(int, usb_target_t, usb_transfer_type_t,
206 void *, size_t, usb_transaction_handle_t *);
207int usb_hcd_prepare_data_reception(int, usb_target_t, usb_transfer_type_t,
208 size_t, usb_transaction_handle_t *);
209
210
211int usb_hcd_transfer_interrupt_out(int, usb_target_t,
212 void *, size_t, usb_transaction_handle_t *);
213int usb_hcd_transfer_interrupt_in(int, usb_target_t,
214 size_t, usb_transaction_handle_t *);
215
216int usb_hcd_transfer_control_write_setup(int, usb_target_t,
217 void *, size_t, usb_transaction_handle_t *);
218int usb_hcd_transfer_control_write_data(int, usb_target_t,
219 void *, size_t, usb_transaction_handle_t *);
220int usb_hcd_transfer_control_write_status(int, usb_target_t,
221 usb_transaction_handle_t *);
222
223int usb_hcd_transfer_control_read_setup(int, usb_target_t,
224 void *, size_t, usb_transaction_handle_t *);
225int usb_hcd_transfer_control_read_data(int, usb_target_t,
226 size_t, usb_transaction_handle_t *);
227int usb_hcd_transfer_control_read_status(int, usb_target_t,
228 usb_transaction_handle_t *);
229
230int usb_hcd_async_transfer_interrupt_out(int, usb_target_t,
231 void *, size_t, usb_handle_t *);
232int usb_hcd_async_transfer_interrupt_in(int, usb_target_t,
233 void *, size_t, size_t *, usb_handle_t *);
234
235int usb_hcd_async_transfer_control_write_setup(int, usb_target_t,
236 void *, size_t, usb_handle_t *);
237int usb_hcd_async_transfer_control_write_data(int, usb_target_t,
238 void *, size_t, usb_handle_t *);
239int usb_hcd_async_transfer_control_write_status(int, usb_target_t,
240 usb_handle_t *);
241
242int usb_hcd_async_transfer_control_read_setup(int, usb_target_t,
243 void *, size_t, usb_handle_t *);
244int usb_hcd_async_transfer_control_read_data(int, usb_target_t,
245 void *, size_t, size_t *, usb_handle_t *);
246int usb_hcd_async_transfer_control_read_status(int, usb_target_t,
247 usb_handle_t *);
248
249int usb_hcd_async_wait_for(usb_handle_t);
250
251#endif
252/**
253 * @}
254 */
Note: See TracBrowser for help on using the repository browser.