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 libdrv usb
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file
|
---|
33 | * @brief USB interface definition.
|
---|
34 | */
|
---|
35 |
|
---|
36 | #ifndef LIBDRV_USBHC_IFACE_H_
|
---|
37 | #define LIBDRV_USBHC_IFACE_H_
|
---|
38 |
|
---|
39 | #include "driver.h"
|
---|
40 | #include <usb/usb.h>
|
---|
41 |
|
---|
42 |
|
---|
43 | /** IPC methods for communication with HC through DDF interface.
|
---|
44 | *
|
---|
45 | * Notes for async methods:
|
---|
46 | *
|
---|
47 | * Methods for sending data to device (OUT transactions)
|
---|
48 | * - e.g. IPC_M_USBHC_INTERRUPT_OUT -
|
---|
49 | * always use the same semantics:
|
---|
50 | * - first, IPC call with given method is made
|
---|
51 | * - argument #1 is target address
|
---|
52 | * - argument #2 is target endpoint
|
---|
53 | * - argument #3 is buffer size
|
---|
54 | * - this call is immediately followed by IPC data write (from caller)
|
---|
55 | * - the initial call (and the whole transaction) is answer after the
|
---|
56 | * transaction is scheduled by the HC and acknowledged by the device
|
---|
57 | * or immediately after error is detected
|
---|
58 | * - the answer carries only the error code
|
---|
59 | *
|
---|
60 | * Methods for retrieving data from device (IN transactions)
|
---|
61 | * - e.g. IPC_M_USBHC_INTERRUPT_IN -
|
---|
62 | * also use the same semantics:
|
---|
63 | * - first, IPC call with given method is made
|
---|
64 | * - argument #1 is target address
|
---|
65 | * - argument #2 is target endpoint
|
---|
66 | * - argument #3 is buffer size
|
---|
67 | * - the call is not answered until the device returns some data (or until
|
---|
68 | * error occurs)
|
---|
69 | * - if the call is answered with EOK, first argument of the answer is buffer
|
---|
70 | * hash that could be used to retrieve the actual data
|
---|
71 | *
|
---|
72 | * Some special methods (NO-DATA transactions) do not send any data. These
|
---|
73 | * might behave as both OUT or IN transactions because communication parts
|
---|
74 | * where actual buffers are exchanged are omitted.
|
---|
75 | *
|
---|
76 | * The mentioned data retrieval can be done any time after receiving EOK
|
---|
77 | * answer to IN method.
|
---|
78 | * This retrieval is done using the IPC_M_USBHC_GET_BUFFER where
|
---|
79 | * the first argument is buffer hash from call answer.
|
---|
80 | * This call must be immediately followed by data read-in and after the
|
---|
81 | * data are transferred, the initial call (IPC_M_USBHC_GET_BUFFER)
|
---|
82 | * is answered. Each buffer can be retrieved only once.
|
---|
83 | *
|
---|
84 | * For all these methods, wrap functions exists. Important rule: functions
|
---|
85 | * for IN transactions have (as parameters) buffers where retrieved data
|
---|
86 | * will be stored. These buffers must be already allocated and shall not be
|
---|
87 | * touch until the transaction is completed
|
---|
88 | * (e.g. not before calling usb_wait_for() with appropriate handle).
|
---|
89 | * OUT transactions buffers can be freed immediately after call is dispatched
|
---|
90 | * (i.e. after return from wrapping function).
|
---|
91 | *
|
---|
92 | */
|
---|
93 | typedef enum {
|
---|
94 | /** Asks for data buffer.
|
---|
95 | * See explanation at usb_iface_funcs_t.
|
---|
96 | * This function does not have counter part in functional interface
|
---|
97 | * as it is handled by the remote part itself.
|
---|
98 | */
|
---|
99 | IPC_M_USBHC_GET_BUFFER,
|
---|
100 |
|
---|
101 |
|
---|
102 | /** Send interrupt data to device.
|
---|
103 | * See explanation at usb_iface_funcs_t (OUT transaction).
|
---|
104 | */
|
---|
105 | IPC_M_USBHC_INTERRUPT_OUT,
|
---|
106 |
|
---|
107 | /** Get interrupt data from device.
|
---|
108 | * See explanation at usb_iface_funcs_t (IN transaction).
|
---|
109 | */
|
---|
110 | IPC_M_USBHC_INTERRUPT_IN,
|
---|
111 |
|
---|
112 |
|
---|
113 | /** Start WRITE control transfer.
|
---|
114 | * See explanation at usb_iface_funcs_t (OUT transaction).
|
---|
115 | */
|
---|
116 | IPC_M_USBHC_CONTROL_WRITE_SETUP,
|
---|
117 |
|
---|
118 | /** Send control-transfer data to device.
|
---|
119 | * See explanation at usb_iface_funcs_t (OUT transaction).
|
---|
120 | */
|
---|
121 | IPC_M_USBHC_CONTROL_WRITE_DATA,
|
---|
122 |
|
---|
123 | /** Terminate WRITE control transfer.
|
---|
124 | * See explanation at usb_iface_funcs_t (NO-DATA transaction).
|
---|
125 | */
|
---|
126 | IPC_M_USBHC_CONTROL_WRITE_STATUS,
|
---|
127 |
|
---|
128 |
|
---|
129 |
|
---|
130 | /** Start READ control transfer.
|
---|
131 | * See explanation at usb_iface_funcs_t (OUT transaction).
|
---|
132 | */
|
---|
133 | IPC_M_USBHC_CONTROL_READ_SETUP,
|
---|
134 |
|
---|
135 | /** Get control-transfer data from device.
|
---|
136 | * See explanation at usb_iface_funcs_t (IN transaction).
|
---|
137 | */
|
---|
138 | IPC_M_USBHC_CONTROL_READ_DATA,
|
---|
139 |
|
---|
140 | /** Terminate READ control transfer.
|
---|
141 | * See explanation at usb_iface_funcs_t (NO-DATA transaction).
|
---|
142 | */
|
---|
143 | IPC_M_USBHC_CONTROL_READ_STATUS,
|
---|
144 |
|
---|
145 |
|
---|
146 | /* IPC_M_USB_ */
|
---|
147 | } usbhc_iface_funcs_t;
|
---|
148 |
|
---|
149 | /** Callback for outgoing transfer. */
|
---|
150 | typedef void (*usbhc_iface_transfer_out_callback_t)(device_t *,
|
---|
151 | usb_transaction_outcome_t, void *);
|
---|
152 |
|
---|
153 | /** Callback for incoming transfer. */
|
---|
154 | typedef void (*usbhc_iface_transfer_in_callback_t)(device_t *,
|
---|
155 | usb_transaction_outcome_t, size_t, void *);
|
---|
156 |
|
---|
157 | /** USB devices communication interface. */
|
---|
158 | typedef struct {
|
---|
159 | int (*interrupt_out)(device_t *, usb_target_t,
|
---|
160 | void *, size_t,
|
---|
161 | usbhc_iface_transfer_out_callback_t, void *);
|
---|
162 | int (*interrupt_in)(device_t *, usb_target_t,
|
---|
163 | void *, size_t,
|
---|
164 | usbhc_iface_transfer_in_callback_t, void *);
|
---|
165 | } usbhc_iface_t;
|
---|
166 |
|
---|
167 |
|
---|
168 | #endif
|
---|
169 | /**
|
---|
170 | * @}
|
---|
171 | */
|
---|