1 |
786 |
skrzyp |
#ifndef CYGONCE_USBS_H
|
2 |
|
|
# define CYGONCE_USBS_H
|
3 |
|
|
//==========================================================================
|
4 |
|
|
//
|
5 |
|
|
// include/usbs.h
|
6 |
|
|
//
|
7 |
|
|
// The generic USB slave-side support
|
8 |
|
|
//
|
9 |
|
|
//==========================================================================
|
10 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
11 |
|
|
// -------------------------------------------
|
12 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
13 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2010 Free Software Foundation, Inc.
|
14 |
|
|
//
|
15 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
16 |
|
|
// the terms of the GNU General Public License as published by the Free
|
17 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
18 |
|
|
// version.
|
19 |
|
|
//
|
20 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
21 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
22 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
23 |
|
|
// for more details.
|
24 |
|
|
//
|
25 |
|
|
// You should have received a copy of the GNU General Public License
|
26 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
27 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
28 |
|
|
//
|
29 |
|
|
// As a special exception, if other files instantiate templates or use
|
30 |
|
|
// macros or inline functions from this file, or you compile this file
|
31 |
|
|
// and link it with other works to produce a work based on this file,
|
32 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
33 |
|
|
// the GNU General Public License. However the source code for this file
|
34 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
35 |
|
|
// General Public License v2.
|
36 |
|
|
//
|
37 |
|
|
// This exception does not invalidate any other reasons why a work based
|
38 |
|
|
// on this file might be covered by the GNU General Public License.
|
39 |
|
|
// -------------------------------------------
|
40 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
41 |
|
|
//==========================================================================
|
42 |
|
|
//#####DESCRIPTIONBEGIN####
|
43 |
|
|
//
|
44 |
|
|
// Author(s): bartv
|
45 |
|
|
// Contributors: bartv
|
46 |
|
|
// Date: 2000-10-04
|
47 |
|
|
// Purpose:
|
48 |
|
|
// Description: USB slave-side support
|
49 |
|
|
//
|
50 |
|
|
//
|
51 |
|
|
//####DESCRIPTIONEND####
|
52 |
|
|
//==========================================================================
|
53 |
|
|
|
54 |
|
|
# include <pkgconf/system.h>
|
55 |
|
|
# include <cyg/infra/cyg_type.h>
|
56 |
|
|
# include <cyg/io/usb/usb.h>
|
57 |
|
|
|
58 |
|
|
#ifdef __cplusplus
|
59 |
|
|
extern "C" {
|
60 |
|
|
#endif
|
61 |
|
|
|
62 |
|
|
// The USB slave-side eCos support involves a number of different
|
63 |
|
|
// components:
|
64 |
|
|
//
|
65 |
|
|
// 1) a hardware-specific package to drive a specific chip implementation.
|
66 |
|
|
// This provides access to the endpoints. All the hardware-specific
|
67 |
|
|
// packages implement a common interface.
|
68 |
|
|
//
|
69 |
|
|
// 2) a common package (this one). This defines the interface implemented
|
70 |
|
|
// by the hardware-specific packages. It also provides support for
|
71 |
|
|
// the various generic control messages, using information provided
|
72 |
|
|
// by higher-level code and invoking callbacks as appropriate.
|
73 |
|
|
//
|
74 |
|
|
// 3) some number of support packages for particular types of
|
75 |
|
|
// application, for example ethernet or mass-storage.
|
76 |
|
|
//
|
77 |
|
|
// Typically there will only be one USB slave device, although the design
|
78 |
|
|
// does allow for multiple devices. Each device should provide a
|
79 |
|
|
// usbs_control_endpoint structure and zero or more usbs_data_endpoint
|
80 |
|
|
// structures. Each usbs_data_endpoint structure supports uni-directional
|
81 |
|
|
// transfers on a single endpoint. If an endpoint can support multiple
|
82 |
|
|
// types of transfer then there will be some control operation to switch
|
83 |
|
|
// between bulk, interrupt and isochronous.
|
84 |
|
|
//
|
85 |
|
|
// Access to the USB endpoints can go either via usbs_ calls which
|
86 |
|
|
// take a usbs_endpoint structure, or via open/read/write calls. The
|
87 |
|
|
// latter is more likely to be used in application code since it
|
88 |
|
|
// involves a familiar interface. The former is more appropriate for
|
89 |
|
|
// eCos packages layered on top of the USB code. The difference is
|
90 |
|
|
// synchronous vs. asynchronous: the open/read/write model involves
|
91 |
|
|
// blocking operations, implying a need for extra threads; the usbs_
|
92 |
|
|
// calls involve start operations and a completion callback. In
|
93 |
|
|
// practice the read and write calls are implemented using the
|
94 |
|
|
// lower-level code.
|
95 |
|
|
|
96 |
|
|
// Enumeration data. This requires information about the hardware,
|
97 |
|
|
// specifically what endpoints are available and what they get used
|
98 |
|
|
// for. It also requires information about the application class
|
99 |
|
|
// packages that are in the configuration, and quite possibly about
|
100 |
|
|
// things in application space. Some of the enumeration info such as
|
101 |
|
|
// the vendor id is inherently application-specific. Hence there is no
|
102 |
|
|
// way of generating part or all of the the enumeration information
|
103 |
|
|
// automatically, instead it is up to application code to supply this.
|
104 |
|
|
//
|
105 |
|
|
// The intention is that application provides all the data via const
|
106 |
|
|
// static objects, allowing the data to live in ROM. Alternatively the
|
107 |
|
|
// data structures can go into the .data section as normal, allowing
|
108 |
|
|
// them to be edited at run-time.
|
109 |
|
|
//
|
110 |
|
|
// There can be only one device descriptor, so that is part of the
|
111 |
|
|
// main enumeration data structure. There can be an unknown number of
|
112 |
|
|
// configurations so application code has to initialize an array of
|
113 |
|
|
// these. Ditto for interfaces and endpoints. The first x interfaces
|
114 |
|
|
// in the array correspond to the first configuration, the next y
|
115 |
|
|
// interfaces to the second configuration, etc. The endpoints array
|
116 |
|
|
// works in the same way.
|
117 |
|
|
//
|
118 |
|
|
// In the initial implementation multiple languages are not supported
|
119 |
|
|
// so a simple array of strings suffices. The first entry of these
|
120 |
|
|
// is still special in that it should define a single supported
|
121 |
|
|
// LANGID. All strings should be encoded as per the USB standard:
|
122 |
|
|
// a length field, a type code of USB_STRING_DESCRIPTOR_TYPE,
|
123 |
|
|
// and data in unicode format. In future multiple language support
|
124 |
|
|
// may be supported via configury with the default case remaining
|
125 |
|
|
// a single language, thus avoiding incompatibility problems.
|
126 |
|
|
|
127 |
|
|
typedef struct usbs_enumeration_data {
|
128 |
|
|
usb_device_descriptor device;
|
129 |
|
|
int total_number_interfaces;
|
130 |
|
|
int total_number_endpoints;
|
131 |
|
|
int total_number_strings;
|
132 |
|
|
const usb_configuration_descriptor* configurations;
|
133 |
|
|
const usb_interface_descriptor* interfaces;
|
134 |
|
|
const usb_endpoint_descriptor* endpoints;
|
135 |
|
|
const unsigned char** strings;
|
136 |
|
|
} usbs_enumeration_data;
|
137 |
|
|
|
138 |
|
|
// The current state of a USB device. This involves a bit to mark
|
139 |
|
|
// whether or not the device has been suspended, plus a state machine.
|
140 |
|
|
// On some hardware it may not be possible to distinguish between the
|
141 |
|
|
// detached, attached and powered states. If so then the initial state
|
142 |
|
|
// will be POWERED.
|
143 |
|
|
|
144 |
|
|
#define USBS_STATE_DETACHED 0x01
|
145 |
|
|
#define USBS_STATE_ATTACHED 0x02
|
146 |
|
|
#define USBS_STATE_POWERED 0x03
|
147 |
|
|
#define USBS_STATE_DEFAULT 0x04
|
148 |
|
|
#define USBS_STATE_ADDRESSED 0x05
|
149 |
|
|
#define USBS_STATE_CONFIGURED 0x06
|
150 |
|
|
#define USBS_STATE_MASK 0x7F
|
151 |
|
|
#define USBS_STATE_SUSPENDED (1 << 7)
|
152 |
|
|
|
153 |
|
|
// State changes. Application code or higher-level packages should
|
154 |
|
|
// install an appropriate state change function which will get
|
155 |
|
|
// invoked with details of the state change.
|
156 |
|
|
typedef enum {
|
157 |
|
|
USBS_STATE_CHANGE_DETACHED = 1,
|
158 |
|
|
USBS_STATE_CHANGE_ATTACHED = 2,
|
159 |
|
|
USBS_STATE_CHANGE_POWERED = 3,
|
160 |
|
|
USBS_STATE_CHANGE_RESET = 4,
|
161 |
|
|
USBS_STATE_CHANGE_ADDRESSED = 5,
|
162 |
|
|
USBS_STATE_CHANGE_CONFIGURED = 6,
|
163 |
|
|
USBS_STATE_CHANGE_DECONFIGURED = 7,
|
164 |
|
|
USBS_STATE_CHANGE_SUSPENDED = 8,
|
165 |
|
|
USBS_STATE_CHANGE_RESUMED = 9
|
166 |
|
|
} usbs_state_change;
|
167 |
|
|
|
168 |
|
|
typedef enum {
|
169 |
|
|
USBS_CONTROL_RETURN_HANDLED = 0,
|
170 |
|
|
USBS_CONTROL_RETURN_UNKNOWN = 1,
|
171 |
|
|
USBS_CONTROL_RETURN_STALL = 2
|
172 |
|
|
} usbs_control_return;
|
173 |
|
|
|
174 |
|
|
// Forward type definitions - see below for structure detail.
|
175 |
|
|
struct usbs_rx_endpoint;
|
176 |
|
|
struct usbs_tx_endpoint;
|
177 |
|
|
|
178 |
|
|
typedef struct usbs_control_endpoint {
|
179 |
|
|
// The state is maintained by the USB code and should not be
|
180 |
|
|
// modified by anything higher up.
|
181 |
|
|
int state;
|
182 |
|
|
|
183 |
|
|
// The enumeration data should be supplied by higher level code,
|
184 |
|
|
// usually the application. Often this data will be constant.
|
185 |
|
|
const usbs_enumeration_data* enumeration_data;
|
186 |
|
|
|
187 |
|
|
// This function pointer is supplied by the USB device driver.
|
188 |
|
|
// Application code should invoke it directly or via the
|
189 |
|
|
// usbs_start() function when the system is ready. Typically it
|
190 |
|
|
// will cause the USB lines to switch from tristate to active,
|
191 |
|
|
// and the USB host/hub should detect this.
|
192 |
|
|
void (*start_fn)(struct usbs_control_endpoint*);
|
193 |
|
|
|
194 |
|
|
// This function is used for polled operation when interrupts
|
195 |
|
|
// are disabled. This can happen in some debugging contexts.
|
196 |
|
|
// Higher-level code may also need to know about the interrupt
|
197 |
|
|
// number(s) used.
|
198 |
|
|
void (*poll_fn)(struct usbs_control_endpoint*);
|
199 |
|
|
int interrupt_vector;
|
200 |
|
|
|
201 |
|
|
// When a new control message arrives it will be in this buffer
|
202 |
|
|
// where the appropriate callback functions can examine it. The
|
203 |
|
|
// USB code will not modify the buffer unless a new control
|
204 |
|
|
// message arrives. The control_buffer can also be re-used
|
205 |
|
|
// by handlers to maintain some state information, e.g.
|
206 |
|
|
// for coping with complicated IN requests, but this is only
|
207 |
|
|
// allowed if they actually handle the request.
|
208 |
|
|
unsigned char control_buffer[8];
|
209 |
|
|
|
210 |
|
|
// This callback will be invoked by the USB code following a
|
211 |
|
|
// change in USB state, e.g. to SUSPENDED mode. Higher-level code
|
212 |
|
|
// should install a suitable function. There is some callback data
|
213 |
|
|
// as well. This gets passed explicitly to the callback function,
|
214 |
|
|
// in addition to the control endpoint structure. The reason is
|
215 |
|
|
// that the actual state change callback may be some sort of
|
216 |
|
|
// multiplexer inside a multifunction peripheral, and this
|
217 |
|
|
// multiplexer wants to invoke device-specific state change
|
218 |
|
|
// functions. However in simple devices those device-specific
|
219 |
|
|
// state change functions could be invoked directly.
|
220 |
|
|
void (*state_change_fn)(struct usbs_control_endpoint*, void*, usbs_state_change, int /* old state */);
|
221 |
|
|
void* state_change_data;
|
222 |
|
|
// When a standard control message arrives, the device driver will
|
223 |
|
|
// detect some requests such as SET_ADDRESS and handle it
|
224 |
|
|
// internally. Otherwise if higher-level code has installed a
|
225 |
|
|
// callback then that will be invoked. If the callback returns
|
226 |
|
|
// UNKNOWN then the default handler usbs_handle_standard_control()
|
227 |
|
|
// is used to process the request.
|
228 |
|
|
usbs_control_return (*standard_control_fn)(struct usbs_control_endpoint*, void*);
|
229 |
|
|
void* standard_control_data;
|
230 |
|
|
|
231 |
|
|
// These three callbacks are used for other types of control
|
232 |
|
|
// messages. The generic USB code has no way of knowing what
|
233 |
|
|
// such control messages are about.
|
234 |
|
|
usbs_control_return (*class_control_fn)(struct usbs_control_endpoint*, void*);
|
235 |
|
|
void* class_control_data;
|
236 |
|
|
usbs_control_return (*vendor_control_fn)(struct usbs_control_endpoint*, void*);
|
237 |
|
|
void* vendor_control_data;
|
238 |
|
|
usbs_control_return (*reserved_control_fn)(struct usbs_control_endpoint*, void*);
|
239 |
|
|
void* reserved_control_data;
|
240 |
|
|
|
241 |
|
|
// If a control operation involves transferring more data than
|
242 |
|
|
// just the initial eight-byte packet, the following fields are
|
243 |
|
|
// used to keep track of the current operation. The original
|
244 |
|
|
// control request indicates the direction of the transfer (IN or
|
245 |
|
|
// OUT) and a length field. For OUT this length is exact, for IN
|
246 |
|
|
// it is an upper bound. The transfer operates mostly as per the
|
247 |
|
|
// bulk protocol, but if the length requested is an exact multiple
|
248 |
|
|
// of the control fifo size (typically eight bytes) then there
|
249 |
|
|
// is no need for an empty packet at the end.
|
250 |
|
|
//
|
251 |
|
|
// For an OUT operation the control message handler should supply
|
252 |
|
|
// a suitable buffer via the "buffer" field below. The only other
|
253 |
|
|
// field of interest is the complete_fn which must be provided and
|
254 |
|
|
// will be invoked once all the data has arrived. Alternatively
|
255 |
|
|
// the OUT operation may get aborted if a new control message
|
256 |
|
|
// arrives. The second argument is an error code -EPIPE or -EIO,
|
257 |
|
|
// or zero to indicate success. The return code is used by the
|
258 |
|
|
// device driver during the status phase.
|
259 |
|
|
//
|
260 |
|
|
// IN is more complicated and the defined interface makes it
|
261 |
|
|
// possible to gather data from multiple locations, eliminating
|
262 |
|
|
// the need for copying into large buffers in some circumstances.
|
263 |
|
|
// Basically when an IN request arrives the device driver will
|
264 |
|
|
// look at the buffer and buffer_size fields, extracting data from
|
265 |
|
|
// there if possible. If the current buffer has been exhausted
|
266 |
|
|
// then the the refill function will be invoked, and this can
|
267 |
|
|
// reset the buffer and size fields to point somewhere else.
|
268 |
|
|
// This continues until such time that there is no longer
|
269 |
|
|
// a refill function and the current buffer is empty. The
|
270 |
|
|
// refill function can use the refill_data and refill_index
|
271 |
|
|
// to keep track of the current state. The control_buffer
|
272 |
|
|
// fields are available as well. At the end of the transfer,
|
273 |
|
|
// if a completion function has been supplied then it will
|
274 |
|
|
// be invoked. The return code will be ignored.
|
275 |
|
|
unsigned char* buffer;
|
276 |
|
|
int buffer_size;
|
277 |
|
|
void (*fill_buffer_fn)(struct usbs_control_endpoint*);
|
278 |
|
|
void* fill_data;
|
279 |
|
|
int fill_index;
|
280 |
|
|
usbs_control_return (*complete_fn)(struct usbs_control_endpoint*, int);
|
281 |
|
|
|
282 |
|
|
// The following two functions provide a common API for accessing
|
283 |
|
|
// USB data endpoints. This avoids class drivers needing to know
|
284 |
|
|
// about the physical configuration of endpoints for each underlying
|
285 |
|
|
// USB slave device driver. The functions are used to map the
|
286 |
|
|
// logical endpoint ID (as specified in the USB class descriptors) to
|
287 |
|
|
// the appropriate endpoint data structure (as used by the eCos USB
|
288 |
|
|
// slave API calls). Individual USB slave drivers are free to implement
|
289 |
|
|
// this mapping in the most appropriate manner for the underlying
|
290 |
|
|
// hardware. This may be via CDL compile time options or preferably
|
291 |
|
|
// by scanning the supplied class driver descriptors at runtime.
|
292 |
|
|
// The latter method allows eCos to support multiple USB configurations
|
293 |
|
|
// in a single USB device. For this reason, these functions will only
|
294 |
|
|
// yield a valid endpoint mapping while the USB device is in its
|
295 |
|
|
// configured state. In all other states they will return a null
|
296 |
|
|
// pointer. These functions should also return a null pointer if the
|
297 |
|
|
// requested endpoint ID is not valid for the currently selected
|
298 |
|
|
// configuration.
|
299 |
|
|
struct usbs_rx_endpoint* (*get_rxep_fn)(struct usbs_control_endpoint*, cyg_uint8);
|
300 |
|
|
struct usbs_tx_endpoint* (*get_txep_fn)(struct usbs_control_endpoint*, cyg_uint8);
|
301 |
|
|
|
302 |
|
|
} usbs_control_endpoint;
|
303 |
|
|
|
304 |
|
|
// Data endpoints are a little bit simpler, but not much. From the
|
305 |
|
|
// perspective of a device driver things a single buffer is most
|
306 |
|
|
// convenient, but that is quite likely to require a max-size buffer
|
307 |
|
|
// at a higher level and an additional copy operation. Supplying
|
308 |
|
|
// a vector of buffers is a bit more general, but in a layered
|
309 |
|
|
// system it may be desirable to prepend to this vector...
|
310 |
|
|
// A combination of a current buffer and a refill/empty function
|
311 |
|
|
// offers flexibility, at the cost of additional function calls
|
312 |
|
|
// from inside the device driver.
|
313 |
|
|
//
|
314 |
|
|
// FIXME: implement support for fill/empty functions.
|
315 |
|
|
//
|
316 |
|
|
// Some USB devices may prefer buffers of particular alignment,
|
317 |
|
|
// e.g. for DMA purposes. This is hard to reconcile with the
|
318 |
|
|
// current interface. However pushing such alignment restrictions
|
319 |
|
|
// etc. up into the higher levels is difficult, e.g. it does
|
320 |
|
|
// not map at all onto a conventional read/write interface.
|
321 |
|
|
// The device driver will just have to do the best it can.
|
322 |
|
|
//
|
323 |
|
|
// The completion function will be invoked at the end of the transfer.
|
324 |
|
|
// The second argument indicates per-transfer completion data. The
|
325 |
|
|
// third argument indicates the total amount received, or an error
|
326 |
|
|
// code: typically -EPIPE to indicate a broken conenction; -EAGAIN to
|
327 |
|
|
// indicate a stall condition; -EMSGSIZE if the host is sending more
|
328 |
|
|
// data than the target is expecting; or -EIO to indicate some other
|
329 |
|
|
// error. Individual device drivers should avoid generating other
|
330 |
|
|
// errors.
|
331 |
|
|
typedef struct usbs_rx_endpoint {
|
332 |
|
|
void (*start_rx_fn)(struct usbs_rx_endpoint*);
|
333 |
|
|
void (*set_halted_fn)(struct usbs_rx_endpoint*, cyg_bool);
|
334 |
|
|
void (*complete_fn)(void*, int);
|
335 |
|
|
void* complete_data;
|
336 |
|
|
unsigned char* buffer;
|
337 |
|
|
int buffer_size;
|
338 |
|
|
cyg_bool halted;
|
339 |
|
|
} usbs_rx_endpoint;
|
340 |
|
|
|
341 |
|
|
typedef struct usbs_tx_endpoint {
|
342 |
|
|
void (*start_tx_fn)(struct usbs_tx_endpoint*);
|
343 |
|
|
void (*set_halted_fn)(struct usbs_tx_endpoint*, cyg_bool);
|
344 |
|
|
void (*complete_fn)(void*, int);
|
345 |
|
|
void* complete_data;
|
346 |
|
|
const unsigned char*buffer;
|
347 |
|
|
int buffer_size;
|
348 |
|
|
cyg_bool halted;
|
349 |
|
|
} usbs_tx_endpoint;
|
350 |
|
|
|
351 |
|
|
// Functions called by device drivers.
|
352 |
|
|
extern usbs_control_return usbs_handle_standard_control(struct usbs_control_endpoint*);
|
353 |
|
|
|
354 |
|
|
// Utility functions. These just invoke the corresponding function
|
355 |
|
|
// pointers in the endpoint structures. It is assumed that the
|
356 |
|
|
// necessary fields in the endpoint structures will have been
|
357 |
|
|
// filled in already.
|
358 |
|
|
extern void usbs_start(usbs_control_endpoint*);
|
359 |
|
|
extern void usbs_start_rx(usbs_rx_endpoint*);
|
360 |
|
|
extern void usbs_start_tx(usbs_tx_endpoint*);
|
361 |
|
|
extern void usbs_start_rx_buffer(usbs_rx_endpoint*, unsigned char*, int, void (*)(void*, int), void*);
|
362 |
|
|
extern void usbs_start_tx_buffer(usbs_tx_endpoint*, const unsigned char*, int, void (*)(void*, int), void*);
|
363 |
|
|
extern cyg_bool usbs_rx_endpoint_halted(usbs_rx_endpoint*);
|
364 |
|
|
extern cyg_bool usbs_tx_endpoint_halted(usbs_tx_endpoint*);
|
365 |
|
|
extern void usbs_set_rx_endpoint_halted(usbs_rx_endpoint*, cyg_bool);
|
366 |
|
|
extern void usbs_set_tx_endpoint_halted(usbs_tx_endpoint*, cyg_bool);
|
367 |
|
|
extern void usbs_start_rx_endpoint_wait(usbs_rx_endpoint*, void (*)(void*, int), void*);
|
368 |
|
|
extern void usbs_start_tx_endpoint_wait(usbs_tx_endpoint*, void (*)(void*, int), void*);
|
369 |
|
|
|
370 |
|
|
// Utility function to access USB data endpoints by logical endpoint ID.
|
371 |
|
|
extern usbs_rx_endpoint* usbs_get_rx_endpoint(usbs_control_endpoint*, cyg_uint8);
|
372 |
|
|
extern usbs_tx_endpoint* usbs_get_tx_endpoint(usbs_control_endpoint*, cyg_uint8);
|
373 |
|
|
|
374 |
|
|
// Functions that can go into devtab entries. These should not be
|
375 |
|
|
// called directly, they are intended only for use by USB device
|
376 |
|
|
// drivers.
|
377 |
|
|
#if defined(CYGPKG_IO) && defined(CYGPKG_ERROR)
|
378 |
|
|
#include <cyg/io/io.h>
|
379 |
|
|
extern Cyg_ErrNo usbs_devtab_cwrite(cyg_io_handle_t, const void*, cyg_uint32*);
|
380 |
|
|
extern Cyg_ErrNo usbs_devtab_cread(cyg_io_handle_t, void*, cyg_uint32*);
|
381 |
|
|
extern Cyg_ErrNo usbs_devtab_get_config(cyg_io_handle_t, cyg_uint32, void*, cyg_uint32*);
|
382 |
|
|
extern Cyg_ErrNo usbs_devtab_set_config(cyg_io_handle_t, cyg_uint32, const void*, cyg_uint32*);
|
383 |
|
|
#endif
|
384 |
|
|
|
385 |
|
|
// Additional support for testing.
|
386 |
|
|
// Test cases need to have some way of finding out about what support is
|
387 |
|
|
// actually provided by the USB device driver, for example what endpoints
|
388 |
|
|
// are available. There is no perfect way of achieving this. One approach
|
389 |
|
|
// would be to scan through the devtab table looking for devices of the
|
390 |
|
|
// form /dev/usbs1r. That is not reliable: the devtab entries may have been
|
391 |
|
|
// configured out if higher-level code uses the usb-specific API; or the
|
392 |
|
|
// devtab entries may have been renamed. Also having a devtab entry does not
|
393 |
|
|
// really give the kind of information a general-purpose testcase needs,
|
394 |
|
|
// for example upper bounds on transfer size.
|
395 |
|
|
//
|
396 |
|
|
// An alternative approach is to have a data structure that somehow
|
397 |
|
|
// defines the USB hardware, and the USB device driver then creates an
|
398 |
|
|
// instance of this. This is the approach actually taken. The problem
|
399 |
|
|
// now is how the test code can access this instance. Accessing by
|
400 |
|
|
// unique name is simple, as long as there is only one USB device in
|
401 |
|
|
// the system (which of course will usually be the case on the USB
|
402 |
|
|
// slave side). Alternative approaches such as creating a table at
|
403 |
|
|
// link time or a list during static construction time are vulnerable
|
404 |
|
|
// either to selective linking or to having these structures present
|
405 |
|
|
// in applications other than the test cases. In future it might be
|
406 |
|
|
// possible to address the latter issue by extending the build system
|
407 |
|
|
// support, e.g. a new library libtesting.a and a new object file
|
408 |
|
|
// testing.o.
|
409 |
|
|
//
|
410 |
|
|
// Note that a given endpoint could be used for bulk transfers some
|
411 |
|
|
// of the time, then for isochronous transfers, etc. It is the
|
412 |
|
|
// responsibility of the host to only perform one type of IN operation
|
413 |
|
|
// for a given endpoint number, and ditto for OUT.
|
414 |
|
|
|
415 |
|
|
typedef struct usbs_testing_endpoint {
|
416 |
|
|
int endpoint_type; // One of ATTR_CONTROL, ATTR_BULK, ...
|
417 |
|
|
int endpoint_number; // Between 0 and 15
|
418 |
|
|
int endpoint_direction; // ENDPOINT_IN or ENDPOINT_OUT
|
419 |
|
|
void* endpoint; // pointer to the usbs_control_endpoint, usbs_rx_endpoint, ...
|
420 |
|
|
const char* devtab_entry; // e.g. "/dev/usbs1r", or 0 if inaccessible via devtab
|
421 |
|
|
int min_size; // Minimum transfer size
|
422 |
|
|
int max_size; // -1 indicates no specific upper bound
|
423 |
|
|
int max_in_padding; // extra bytes that the target may send, usually 0.
|
424 |
|
|
// Primarily for SA11x0 hardware. It is assumed
|
425 |
|
|
// for now that no other hardware will exhibit
|
426 |
|
|
// comparable problems.
|
427 |
|
|
int alignment; // Buffer should be aligned to a suitable boundary
|
428 |
|
|
} usbs_testing_endpoint;
|
429 |
|
|
|
430 |
|
|
// A specific instance provided by the device driver. The end of
|
431 |
|
|
// the table is indicated by a NULL endpoint field.
|
432 |
|
|
extern usbs_testing_endpoint usbs_testing_endpoints[];
|
433 |
|
|
|
434 |
|
|
#define USBS_TESTING_ENDPOINTS_TERMINATOR \
|
435 |
|
|
{ \
|
436 |
|
|
endpoint_type : USB_ENDPOINT_DESCRIPTOR_ATTR_CONTROL, \
|
437 |
|
|
endpoint_number : 0, \
|
438 |
|
|
endpoint_direction : USB_ENDPOINT_DESCRIPTOR_ENDPOINT_IN, \
|
439 |
|
|
endpoint : (void*) 0, \
|
440 |
|
|
devtab_entry : (const char*) 0, \
|
441 |
|
|
min_size : 0, \
|
442 |
|
|
max_size : 0, \
|
443 |
|
|
max_in_padding : 0, \
|
444 |
|
|
alignment : 0 \
|
445 |
|
|
}
|
446 |
|
|
|
447 |
|
|
#define USBS_TESTING_ENDPOINTS_IS_TERMINATOR(_endpoint_) ((void*)0 == (_endpoint_).endpoint)
|
448 |
|
|
|
449 |
|
|
#ifdef __cplusplus
|
450 |
|
|
} // extern "C" {
|
451 |
|
|
#endif
|
452 |
|
|
|
453 |
|
|
#endif // CYGONCE_USBS_H
|
454 |
|
|
|