source: mainline/uspace/lib/usb/hcd.h@ 63b4f90

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

Old code removal

Completely removed old methods for communicating with HCD (the ones
that used callback phones). Now only methods using the async framework
are available.

  • Property mode set to 100644
File size: 8.1 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.
88 *
89 * Notes for async methods:
90 *
91 * Methods for sending data to device (OUT transactions)
92 * - e.g. IPC_M_USB_HCD_INTERRUPT_OUT_ASYNC -
93 * always use the same semantics:
94 * - first, IPC call with given method is made
95 * - argument #1 is target address
96 * - argument #2 is target endpoint
97 * - argument #3 is buffer size
98 * - this call is immediately followed by IPC data write (from caller)
99 * - the initial call (and the whole transaction) is answer after the
100 * transaction is scheduled by the HC and acknowledged by the device
101 * or immediatelly after error is detected
102 * - the answer carries only the error code
103 *
104 * Methods for retrieving data from device (IN transactions)
105 * - e.g. IPC_M_USB_HCD_INTERRUPT_IN_ASYNC -
106 * also use the same semantics:
107 * - first, IPC call with given method is made
108 * - argument #1 is target address
109 * - argument #2 is target endpoint
110 * - argument #3 is buffer size
111 * - the call is not answered until the device returns some data (or until
112 * error occurs)
113 * - if the call is answered with EOK, first argument of the answer is buffer
114 * hash that could be used to retrieve the actual data
115 *
116 * Some special methods (NO-DATA transactions) do not send any data. These
117 * might behave as both OUT or IN transactions because communication parts
118 * where actual buffers are exchanged are ommitted.
119 *
120 * The mentioned data retrieval can be done any time after receiving EOK
121 * answer to IN method.
122 * This retrieval is done using the IPC_M_USB_HCD_GET_BUFFER_ASYNC where
123 * the first argument is buffer hash from call answer.
124 * This call must be immediatelly followed by data read-in and after the
125 * data are transferred, the initial call (IPC_M_USB_HCD_GET_BUFFER_ASYNC)
126 * is answered. Each buffer can be retrieved only once.
127 *
128 * For all these methods, wrap functions exists. Important rule: functions
129 * for IN transactions have (as parameters) buffers where retrieved data
130 * will be stored. These buffers must be already allocated and shall not be
131 * touch until the transaction is completed
132 * (e.g. not before calling usb_hcd_async_wait_for() with appropriate handle).
133 * OUT transactions buffers can be freed immediatelly after call is dispatched
134 * (i.e. after return from wrapping function).
135 *
136 */
137typedef enum {
138 /** Tell maximum size of the transaction buffer (payload).
139 *
140 * Arguments of the call:
141 * (none)
142 *
143 * Answer:
144 * - EOK - always
145 *
146 * Arguments of the answer:
147 * - buffer size (in bytes):
148 */
149 IPC_M_USB_HCD_TRANSACTION_SIZE = IPC_FIRST_USER_METHOD,
150
151 /** Asks for data buffer.
152 * See explanation at usb_hcd_method_t.
153 */
154 IPC_M_USB_HCD_GET_BUFFER_ASYNC,
155
156
157
158 /** Send interrupt data to device.
159 * See explanation at usb_hcd_method_t (OUT transaction).
160 */
161 IPC_M_USB_HCD_INTERRUPT_OUT_ASYNC,
162
163 /** Get interrupt data from device.
164 * See explanation at usb_hcd_method_t (IN transaction).
165 */
166 IPC_M_USB_HCD_INTERRUPT_IN_ASYNC,
167
168
169 /** Start WRITE control transfer.
170 * See explanation at usb_hcd_method_t (OUT transaction).
171 */
172 IPC_M_USB_HCD_CONTROL_WRITE_SETUP_ASYNC,
173
174 /** Send control-transfer data to device.
175 * See explanation at usb_hcd_method_t (OUT transaction).
176 */
177 IPC_M_USB_HCD_CONTROL_WRITE_DATA_ASYNC,
178
179 /** Terminate WRITE control transfer.
180 * See explanation at usb_hcd_method_t (NO-DATA transaction).
181 */
182 IPC_M_USB_HCD_CONTROL_WRITE_STATUS_ASYNC,
183
184
185
186 /** Start READ control transfer.
187 * See explanation at usb_hcd_method_t (OUT transaction).
188 */
189 IPC_M_USB_HCD_CONTROL_READ_SETUP_ASYNC,
190
191 /** Get control-transfer data from device.
192 * See explanation at usb_hcd_method_t (IN transaction).
193 */
194 IPC_M_USB_HCD_CONTROL_READ_DATA_ASYNC,
195
196 /** Terminate READ control transfer.
197 * See explanation at usb_hcd_method_t (NO-DATA transaction).
198 */
199 IPC_M_USB_HCD_CONTROL_READ_STATUS_ASYNC,
200
201
202 /* IPC_M_USB_HCD_ */
203} usb_hcd_method_t;
204
205/** IPC methods for callbacks from HCD. */
206typedef enum {
207 /** Confimation after data sent.
208 *
209 * Arguments of the call:
210 * - transaction handle
211 * - transaction outcome
212 */
213 IPC_M_USB_HCD_DATA_SENT = IPC_FIRST_USER_METHOD,
214
215 /** Notification of data received.
216 * This call initiates sending a data buffer from HCD to the client.
217 * See IPC_M_USB_HCD_SEND_DATA for details for buffer transfer is
218 * done.
219 *
220 * Arguments of the call:
221 * - transaction handle
222 * - transaction outcome
223 * - actual data length
224 */
225 IPC_M_USB_HCD_DATA_RECEIVED,
226
227 /** Notification about a serious trouble with HC.
228 */
229 IPC_M_USB_HCD_CONTROLLER_FAILURE,
230
231 /* IPC_M_USB_HCD_ */
232} usb_hcd_callback_method_t;
233
234
235int usb_hcd_connect(const char *);
236
237int usb_hcd_async_transfer_interrupt_out(int, usb_target_t,
238 void *, size_t, usb_handle_t *);
239int usb_hcd_async_transfer_interrupt_in(int, usb_target_t,
240 void *, size_t, size_t *, usb_handle_t *);
241
242int usb_hcd_async_transfer_control_write_setup(int, usb_target_t,
243 void *, size_t, usb_handle_t *);
244int usb_hcd_async_transfer_control_write_data(int, usb_target_t,
245 void *, size_t, usb_handle_t *);
246int usb_hcd_async_transfer_control_write_status(int, usb_target_t,
247 usb_handle_t *);
248
249int usb_hcd_async_transfer_control_read_setup(int, usb_target_t,
250 void *, size_t, usb_handle_t *);
251int usb_hcd_async_transfer_control_read_data(int, usb_target_t,
252 void *, size_t, size_t *, usb_handle_t *);
253int usb_hcd_async_transfer_control_read_status(int, usb_target_t,
254 usb_handle_t *);
255
256int usb_hcd_async_wait_for(usb_handle_t);
257
258#endif
259/**
260 * @}
261 */
Note: See TracBrowser for help on using the repository browser.