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 <ipc/ipc.h>
|
---|
39 | #include <async.h>
|
---|
40 |
|
---|
41 | /** Maximum size of transaction payload. */
|
---|
42 | #define USB_MAX_PAYLOAD_SIZE 1020
|
---|
43 |
|
---|
44 | /** USB transfer type. */
|
---|
45 | typedef enum {
|
---|
46 | USB_TRANSFER_CONTROL = 0,
|
---|
47 | USB_TRANSFER_ISOCHRONOUS = 1,
|
---|
48 | USB_TRANSFER_BULK = 2,
|
---|
49 | USB_TRANSFER_INTERRUPT = 3
|
---|
50 | } usb_transfer_type_t;
|
---|
51 |
|
---|
52 | const char * usb_str_transfer_type(usb_transfer_type_t t);
|
---|
53 |
|
---|
54 | /** USB data transfer direction. */
|
---|
55 | typedef enum {
|
---|
56 | USB_DIRECTION_IN,
|
---|
57 | USB_DIRECTION_OUT
|
---|
58 | } usb_direction_t;
|
---|
59 |
|
---|
60 | /** USB address type.
|
---|
61 | * Negative values could be used to indicate error.
|
---|
62 | */
|
---|
63 | typedef int usb_address_t;
|
---|
64 |
|
---|
65 | /** USB endpoint number type.
|
---|
66 | * Negative values could be used to indicate error.
|
---|
67 | */
|
---|
68 | typedef int usb_endpoint_t;
|
---|
69 |
|
---|
70 | /** USB complete address type.
|
---|
71 | * Pair address + endpoint is identification of transaction recipient.
|
---|
72 | */
|
---|
73 | typedef struct {
|
---|
74 | usb_address_t address;
|
---|
75 | usb_endpoint_t endpoint;
|
---|
76 | } usb_target_t;
|
---|
77 |
|
---|
78 | static inline int usb_target_same(usb_target_t a, usb_target_t b)
|
---|
79 | {
|
---|
80 | return (a.address == b.address)
|
---|
81 | && (a.endpoint == b.endpoint);
|
---|
82 | }
|
---|
83 |
|
---|
84 | /** Opaque handle of active USB transaction.
|
---|
85 | * This handle is when informing about transaction outcome (or status).
|
---|
86 | */
|
---|
87 | typedef ipcarg_t usb_transaction_handle_t;
|
---|
88 |
|
---|
89 | /** USB transaction outcome. */
|
---|
90 | typedef enum {
|
---|
91 | USB_OUTCOME_OK,
|
---|
92 | USB_OUTCOME_CRCERROR,
|
---|
93 | USB_OUTCOME_BABBLE
|
---|
94 | } usb_transaction_outcome_t;
|
---|
95 |
|
---|
96 | const char * usb_str_transaction_outcome(usb_transaction_outcome_t o);
|
---|
97 |
|
---|
98 | /** IPC methods for HCD. */
|
---|
99 | typedef enum {
|
---|
100 | /** Send data over USB to a function.
|
---|
101 | * This method initializes large data transfer that must follow
|
---|
102 | * immediatelly.
|
---|
103 | * The recipient of this method must issue immediately data reception
|
---|
104 | * and answer this call after data buffer was transfered.
|
---|
105 | *
|
---|
106 | * Arguments of the call:
|
---|
107 | * - USB address of the function
|
---|
108 | * - endpoint of the function
|
---|
109 | * - transfer type
|
---|
110 | * - flags (not used)
|
---|
111 | *
|
---|
112 | * Answer:
|
---|
113 | * - EOK - ready to accept the data buffer
|
---|
114 | * - ELIMIT - too many transactions for current connection
|
---|
115 | * - ENOENT - callback connection does not exist
|
---|
116 | * - EINVAL - other kind of error
|
---|
117 | *
|
---|
118 | * Arguments of the answer:
|
---|
119 | * - opaque transaction handle (used in callbacks)
|
---|
120 | */
|
---|
121 | IPC_M_USB_HCD_SEND_DATA = IPC_FIRST_USER_METHOD,
|
---|
122 |
|
---|
123 | /** Initiate data receive from a function.
|
---|
124 | * This method announces the HCD that some data will come.
|
---|
125 | * When this data arrives, the HCD will call back with
|
---|
126 | * IPC_M_USB_HCD_DATA_RECEIVED.
|
---|
127 | *
|
---|
128 | * Arguments of the call:
|
---|
129 | * - USB address of the function
|
---|
130 | * - endpoint of the function
|
---|
131 | * - transfer type
|
---|
132 | * - buffer size
|
---|
133 | * - flags (not used)
|
---|
134 | *
|
---|
135 | * Answer:
|
---|
136 | * - EOK - HCD accepted the request
|
---|
137 | * - ELIMIT - too many transactions for current connection
|
---|
138 | * - ENOENT - callback connection does not exist
|
---|
139 | *
|
---|
140 | * Arguments of the answer:
|
---|
141 | * - opaque transaction handle (used in callbacks)
|
---|
142 | */
|
---|
143 | IPC_M_USB_HCD_RECEIVE_DATA,
|
---|
144 |
|
---|
145 | /** Tell maximum size of the transaction buffer (payload).
|
---|
146 | *
|
---|
147 | * Arguments of the call:
|
---|
148 | * (none)
|
---|
149 | *
|
---|
150 | * Answer:
|
---|
151 | * - EOK - always
|
---|
152 | *
|
---|
153 | * Arguments of the answer:
|
---|
154 | * - buffer size (in bytes):
|
---|
155 | */
|
---|
156 | IPC_M_USB_HCD_TRANSACTION_SIZE
|
---|
157 | } usb_hcd_method_t;
|
---|
158 |
|
---|
159 | /** IPC methods for callbacks from HCD. */
|
---|
160 | typedef enum {
|
---|
161 | /** Confimation after data sent.
|
---|
162 | *
|
---|
163 | * Arguments of the call:
|
---|
164 | * - transaction handle
|
---|
165 | * - transaction outcome
|
---|
166 | */
|
---|
167 | IPC_M_USB_HCD_DATA_SENT = IPC_FIRST_USER_METHOD,
|
---|
168 |
|
---|
169 | /** Notification of data received.
|
---|
170 | * This call initiates sending a data buffer from HCD to the client.
|
---|
171 | * See IPC_M_USB_HCD_SEND_DATA for details for buffer transfer is
|
---|
172 | * done.
|
---|
173 | *
|
---|
174 | * Arguments of the call:
|
---|
175 | * - transaction handle
|
---|
176 | * - transaction outcome
|
---|
177 | * - actual data length
|
---|
178 | */
|
---|
179 | IPC_M_USB_HCD_DATA_RECEIVED,
|
---|
180 |
|
---|
181 | /** Notification about a serious trouble with HC.
|
---|
182 | */
|
---|
183 | IPC_M_USB_HCD_CONTROLLER_FAILURE
|
---|
184 | } usb_hcd_callback_method_t;
|
---|
185 |
|
---|
186 |
|
---|
187 | int usb_hcd_create_phones(const char *, async_client_conn_t);
|
---|
188 | int usb_hcd_send_data_to_function(int, usb_target_t, usb_transfer_type_t,
|
---|
189 | void *, size_t, usb_transaction_handle_t *);
|
---|
190 | int usb_hcd_prepare_data_reception(int, usb_target_t, usb_transfer_type_t,
|
---|
191 | size_t, usb_transaction_handle_t *);
|
---|
192 |
|
---|
193 | #endif
|
---|
194 | /**
|
---|
195 | * @}
|
---|
196 | */
|
---|