source: mainline/uspace/lib/usb/hcd.h@ 23cb44b

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

Update of libusb/HC methods

  • Property mode set to 100644
File size: 6.4 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 /* IPC_M_USB_HCD_ */
159} usb_hcd_method_t;
160
161/** IPC methods for callbacks from HCD. */
162typedef enum {
163 /** Confimation after data sent.
164 *
165 * Arguments of the call:
166 * - transaction handle
167 * - transaction outcome
168 */
169 IPC_M_USB_HCD_DATA_SENT = IPC_FIRST_USER_METHOD,
170
171 /** Notification of data received.
172 * This call initiates sending a data buffer from HCD to the client.
173 * See IPC_M_USB_HCD_SEND_DATA for details for buffer transfer is
174 * done.
175 *
176 * Arguments of the call:
177 * - transaction handle
178 * - transaction outcome
179 * - actual data length
180 */
181 IPC_M_USB_HCD_DATA_RECEIVED,
182
183 /** Notification about a serious trouble with HC.
184 */
185 IPC_M_USB_HCD_CONTROLLER_FAILURE,
186
187 /* IPC_M_USB_HCD_ */
188} usb_hcd_callback_method_t;
189
190
191int usb_hcd_create_phones(const char *, async_client_conn_t);
192int usb_hcd_send_data_to_function(int, usb_target_t, usb_transfer_type_t,
193 void *, size_t, usb_transaction_handle_t *);
194int usb_hcd_prepare_data_reception(int, usb_target_t, usb_transfer_type_t,
195 size_t, usb_transaction_handle_t *);
196
197
198int usb_hcd_transfer_interrupt_out(int, usb_target_t,
199 void *, size_t, usb_transaction_handle_t *);
200int usb_hcd_transfer_interrupt_in(int, usb_target_t,
201 size_t, usb_transaction_handle_t *);
202
203int usb_hcd_transfer_control_write_setup(int, usb_target_t,
204 void *, size_t, usb_transaction_handle_t *);
205int usb_hcd_transfer_control_write_data(int, usb_target_t,
206 void *, size_t, usb_transaction_handle_t *);
207int usb_hcd_transfer_control_write_status(int, usb_target_t,
208 usb_transaction_handle_t *);
209
210int usb_hcd_transfer_control_read_setup(int, usb_target_t,
211 void *, size_t, usb_transaction_handle_t *);
212int usb_hcd_transfer_control_read_data(int, usb_target_t,
213 size_t, usb_transaction_handle_t *);
214int usb_hcd_transfer_control_read_status(int, usb_target_t,
215 usb_transaction_handle_t *);
216
217#endif
218/**
219 * @}
220 */
Note: See TracBrowser for help on using the repository browser.