1 |
27 |
unneback |
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
NEC uPD985xx USB Device Driver
|
42 |
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
NEC uPD985xx USB Device Driver
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
NEC uPD985xx USB Support
|
49 |
|
|
Device driver for the on-chip NEC uPD985xx USB device
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
NEC uPD985xx USB Hardware
|
53 |
|
|
|
54 |
|
|
The NEC uPD985xx family of processors is supplied with an on-chip USB
|
55 |
|
|
slave device, the UDC (USB Device Controller). This supports seven
|
56 |
|
|
endpoints. Endpoint 0 can only be used for control messages. Endpoints
|
57 |
|
|
1 and 2 are for isochronous transmits and receives respectively.
|
58 |
|
|
Endpoints 3 and 4 support bulk transmits and receives. Endpoints 5 and
|
59 |
|
|
6 normally support interrupt transmits and receives, but endpoint 5 can
|
60 |
|
|
also be configured to support bulk transmits. At this time only the
|
61 |
|
|
control endpoint 0, the bulk endpoints 3 and 4, and the interrupt
|
62 |
|
|
endpoint 5 are supported.
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
Endpoint Data Structures
|
67 |
|
|
|
68 |
|
|
The uPD985xx USB device driver can provide up to four data structures
|
69 |
|
|
corresponding to the four supported endpoints: a
|
70 |
|
|
usbs_control_endpoint structure
|
71 |
|
|
usbs_upd985xx_ep0;
|
72 |
|
|
usbs_tx_endpoint structures
|
73 |
|
|
usbs_upd985xx_ep3 and
|
74 |
|
|
usbs_upd985xx_ep5; and a
|
75 |
|
|
usbs_rx_endpoint
|
76 |
|
|
usbs_upd985xx_ep4. The header file
|
77 |
|
|
|
78 |
|
|
provides declarations for these.
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
Not all applications will require support for all the endpoints. For
|
82 |
|
|
example, if the intended use of the UDC only involves peripheral to
|
83 |
|
|
host transfers then usbs_upd985xx_ep4 is redundant.
|
84 |
|
|
The device driver provides configuration options to control the
|
85 |
|
|
presence of each endpoint:
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
Endpoint 0 is controlled by
|
91 |
|
|
CYGFUN_DEVS_USB_UPD985XX_EP0. This defaults to
|
92 |
|
|
enabled if there are any higher-level packages that require USB
|
93 |
|
|
hardware or if the global preference
|
94 |
|
|
CYGGLO_IO_USB_SLAVE_APPLICATION is enabled,
|
95 |
|
|
otherwise it is disabled. Usually this has the desired effect. It may
|
96 |
|
|
be necessary to override this in special circumstances, for example if
|
97 |
|
|
the target board uses an external USB chip in preference to the UDC
|
98 |
|
|
and it is that external chip's device driver that should be used
|
99 |
|
|
rather than the on-chip UDC. It is not possible to disable endpoint 0
|
100 |
|
|
and at the same time enable one or both of the other endpoints, since
|
101 |
|
|
a USB device is only usable if it can process the standard control
|
102 |
|
|
messages.
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
Endpoint 3 is controlled by
|
108 |
|
|
CYGPKG_DEVS_USB_UPD985XX_EP3. By default this
|
109 |
|
|
endpoint is disabled: according to NEC erratum U3 there may be
|
110 |
|
|
problems when attempting bulk transfers of 192 bytes or greater. As an
|
111 |
|
|
alternative the device driver provides support for endpoint 5,
|
112 |
|
|
configured to allow bulk transfers. Endpoint 3 can be enabled if the
|
113 |
|
|
application only requires bulk transfers of less than 192 bytes, or if
|
114 |
|
|
this erratum is not applicable to the system being developed for other
|
115 |
|
|
reasons.
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
|
|
Endpoint 4 is controlled by
|
121 |
|
|
CYGPKG_DEVS_USB_UPD985XX_EP4. This is enabled by
|
122 |
|
|
default whenever endpoint 0 is enabled, but it can be disabled
|
123 |
|
|
manually.
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
|
127 |
|
|
|
128 |
|
|
Endpoint 5 is controlled by
|
129 |
|
|
CYGPKG_DEVS_USB_UPD985XX_EP5. This is enabled by
|
130 |
|
|
default whenever endpoint 0 is enabled, but it can be disabled
|
131 |
|
|
manually. There is also a configuration option
|
132 |
|
|
CYGIMP_DEVS_USB_UPD985XX_EP5_BULK, enabled by
|
133 |
|
|
default. This option allows the endpoint to be used for bulk
|
134 |
|
|
transfers rather than interrupt transfers.
|
135 |
|
|
|
136 |
|
|
|
137 |
|
|
|
138 |
|
|
|
139 |
|
|
The uPD985xx USB device driver implements the interface specified by the
|
140 |
|
|
common eCos USB Slave Support package. The documentation for that
|
141 |
|
|
package should be consulted for further details.
|
142 |
|
|
|
143 |
|
|
|
144 |
|
|
The device driver assumes a bulk packet size of 64 bytes, so this
|
145 |
|
|
value should be used in the endpoint descriptors in the enumeration
|
146 |
|
|
data provided by application code. The device driver also assumes
|
147 |
|
|
a control packet size of eight bytes, and again this should be
|
148 |
|
|
reflected in the enumeration data. If endpoint 5 is configured for
|
149 |
|
|
interrupt rather than bulk transfers then the maximum packet size is
|
150 |
|
|
limited to 64 bytes by the USB standard.
|
151 |
|
|
|
152 |
|
|
|
153 |
|
|
|
154 |
|
|
Devtab Entries
|
155 |
|
|
|
156 |
|
|
In addition to the endpoint data structures the uPD985xx USB device
|
157 |
|
|
driver can also provide devtab entries for each endpoint. This allows
|
158 |
|
|
higher-level code to use traditional I/O operations such as
|
159 |
|
|
open/read/write
|
160 |
|
|
rather than the USB-specific non-blocking functions like
|
161 |
|
|
usbs_start_rx_buffer. These devtab entries are
|
162 |
|
|
optional since they are not always required. The relevant
|
163 |
|
|
configuration options are
|
164 |
|
|
CYGVAR_DEVS_USB_UPD985XX_EP0_DEVTAB_ENTRY,
|
165 |
|
|
CYGVAR_DEVS_USB_UPD985XX_EP3_DEVTAB_ENTRY,
|
166 |
|
|
CYGVAR_DEVS_USB_UPD985XX_EP4_DEVTAB_ENTRY, and
|
167 |
|
|
CYGVAR_DEVS_USB_UPD985XX_EP5_DEVTAB_ENTRY. By
|
168 |
|
|
default these devtab entries are provided if the global preference
|
169 |
|
|
CYGGLO_USB_SLAVE_PROVIDE_DEVTAB_ENTRIES is enabled,
|
170 |
|
|
which is usually the case. Obviously a devtab entry for a given
|
171 |
|
|
endpoint will only be provided if the underlying endpoint is enabled.
|
172 |
|
|
For example, there will not be a devtab entry for endpoint 4 if
|
173 |
|
|
CYGPKG_DEVS_USB_UPD985XX_EP4 is disabled.
|
174 |
|
|
|
175 |
|
|
|
176 |
|
|
The names for the devtab entries are determined by using a
|
177 |
|
|
configurable base name and appending 0c,
|
178 |
|
|
3w, 4r or 5w.
|
179 |
|
|
The base name is determined by the configuration option
|
180 |
|
|
CYGDAT_DEVS_USB_UPD985XX_DEVTAB_BASENAME and has a
|
181 |
|
|
default value of /dev/usbs, so the devtab entry for
|
182 |
|
|
endpoint 4 would default to /dev/usbs4r. If the
|
183 |
|
|
target hardware involves multiple USB devices then application
|
184 |
|
|
developers may have to change the base name to prevent a name clash
|
185 |
|
|
with other USB device drivers.
|
186 |
|
|
|
187 |
|
|
|
188 |
|
|
|
189 |
|
|
Restrictions
|
190 |
|
|
|
191 |
|
|
The current device driver imposes a restriction on certain bulk
|
192 |
|
|
receives on endpoint 4. If the protocol being used involves
|
193 |
|
|
variable-length transfers, in other words if the host is allowed to
|
194 |
|
|
send less data than a maximum-sized transfer, then the buffer passed
|
195 |
|
|
to the device driver for receives must be aligned to a 16-byte
|
196 |
|
|
cacheline boundary and it must be a multiple of this 16-byte cacheline
|
197 |
|
|
size. This restriction does not apply if the protocol only involves
|
198 |
|
|
fixed-size transfers.
|
199 |
|
|
|
200 |
|
|
|
201 |
|
|
|
202 |
|
|
Optional Hardware Workarounds
|
203 |
|
|
|
204 |
|
|
The NEC errata list a number of other problems that affect the USB
|
205 |
|
|
device driver. The device driver contains workarounds for these, which
|
206 |
|
|
are enabled by default but can be disabled if the application
|
207 |
|
|
developer knows that the errata are not relevant to the system being
|
208 |
|
|
developed.
|
209 |
|
|
|
210 |
|
|
|
211 |
|
|
Erratum S1 lists a possible problem if the device driver attempts
|
212 |
|
|
multiple writes to the USB hardware. This is circumvented by a
|
213 |
|
|
dummy read operation after every write. If the workaround is not
|
214 |
|
|
required then the configuration option
|
215 |
|
|
CYGIMP_DEVS_USB_UPD985XX_IBUS_WRITE_LIMIT can be disabled.
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
Errata U3 and U4 describe various problems related to concurrent
|
219 |
|
|
transmissions on different endpoints. By default the device driver
|
220 |
|
|
works around this by serializing all transmit operations. For example
|
221 |
|
|
if the device driver needs to send a response to a control message on
|
222 |
|
|
endpoint 0 while there is an ongoing bulk transfer on endpoint 5, the
|
223 |
|
|
response is delayed until the bulk transfer has completed. Under
|
224 |
|
|
typical operating conditions this does not cause any problems:
|
225 |
|
|
endpoint 0 traffic usually happens only during initialization, when
|
226 |
|
|
the target is connected to the host, while endpoint 5 traffic only
|
227 |
|
|
happens after initialization. However if transmit serialization is
|
228 |
|
|
inappropriate for the system being developed then it can be disabled
|
229 |
|
|
using the configuration option
|
230 |
|
|
CYGIMP_DEVS_USB_UPD985XX_SERIALIZE_TRANSMITS.
|
231 |
|
|
|
232 |
|
|
|
233 |
|
|
|
234 |
|
|
Platform Dependencies
|
235 |
|
|
|
236 |
|
|
On some platforms it is necessary for the low-level USB device driver
|
237 |
|
|
to perform some additional operations during start-up. For example it
|
238 |
|
|
may be necessary to manipulate one of the processor's GPIO lines
|
239 |
|
|
before the host can detect a new USB peripheral and attempt to
|
240 |
|
|
communicate with it. This avoids problems if the target involves a
|
241 |
|
|
significant amount of work prior to device driver initialization, for
|
242 |
|
|
example a power-on self-test sequence. If the USB host attempted to
|
243 |
|
|
contact the target before the USB device driver had been initialized,
|
244 |
|
|
it would fail to get the expected responses and conclude that the
|
245 |
|
|
target was not a functional USB peripheral.
|
246 |
|
|
|
247 |
|
|
|
248 |
|
|
Platform-specific initialization code can be provided via a macro
|
249 |
|
|
UPD985XX_USB_PLATFORM_INIT. Typically this macro
|
250 |
|
|
would be defined in the platform HAL's header file
|
251 |
|
|
. If the
|
252 |
|
|
current platform defines such a macro, the USB device driver will
|
253 |
|
|
invoke it during the endpoint 0 start-up operation.
|
254 |
|
|
|
255 |
|
|
|
256 |
|
|
|
257 |
|
|
|
258 |
|
|
|
259 |
|
|
|