Line No. | Rev | Author | Line |
---|---|---|---|
1 | 32 | kaklik | /****************************************************************************** |
2 | |||
3 | USB Host Driver Local Header |
||
4 | |||
5 | This file provides local definitions used by the hardware interface for a USB |
||
6 | Host application. |
||
7 | |||
8 | File Name: usb_host_local.h |
||
9 | Dependencies: None |
||
10 | Processor: PIC24F/PIC32MX |
||
11 | Compiler: C30/C32 |
||
12 | Company: Microchip Technology, Inc. |
||
13 | |||
14 | Software License Agreement |
||
15 | |||
16 | The software supplied herewith by Microchip Technology Incorporated |
||
17 | (the Company) for its PICmicro® Microcontroller is intended and |
||
18 | supplied to you, the Companys customer, for use solely and |
||
19 | exclusively on Microchip PICmicro Microcontroller products. The |
||
20 | software is owned by the Company and/or its supplier, and is |
||
21 | protected under applicable copyright laws. All rights are reserved. |
||
22 | Any use in violation of the foregoing restrictions may subject the |
||
23 | user to criminal sanctions under applicable laws, as well as to |
||
24 | civil liability for the breach of the terms and conditions of this |
||
25 | license. |
||
26 | |||
27 | THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES, |
||
28 | WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED |
||
29 | TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
||
30 | PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, |
||
31 | IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
||
32 | CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
||
33 | |||
34 | Change History: |
||
35 | Rev Description |
||
36 | ---------- ---------------------------------------------------------- |
||
37 | 2.6a Removed extraneous definition |
||
38 | 2.7 No change |
||
39 | 2.7a Removed freez() macro |
||
40 | *******************************************************************************/ |
||
41 | |||
42 | #ifndef _USB_HOST_LOCAL_ |
||
43 | #define _USB_HOST_LOCAL_ |
||
44 | |||
45 | #include "usb_hal_local.h" |
||
46 | |||
47 | |||
48 | // ***************************************************************************** |
||
49 | // ***************************************************************************** |
||
50 | // Section: Constants |
||
51 | // |
||
52 | // These constants are internal to the stack. All constants required by the |
||
53 | // API are in the header file(s). |
||
54 | // ***************************************************************************** |
||
55 | // ***************************************************************************** |
||
56 | |||
57 | // ***************************************************************************** |
||
58 | // Section: State Machine Constants |
||
59 | // ***************************************************************************** |
||
60 | |||
61 | #define STATE_MASK 0x0F00 // |
||
62 | #define SUBSTATE_MASK 0x00F0 // |
||
63 | #define SUBSUBSTATE_MASK 0x000F // |
||
64 | |||
65 | #define NEXT_STATE 0x0100 // |
||
66 | #define NEXT_SUBSTATE 0x0010 // |
||
67 | #define NEXT_SUBSUBSTATE 0x0001 // |
||
68 | |||
69 | #define SUBSUBSTATE_ERROR 0x000F // |
||
70 | |||
71 | #define NO_STATE 0xFFFF // |
||
72 | |||
73 | /* |
||
74 | ******************************************************************************* |
||
75 | DETACHED state machine values |
||
76 | |||
77 | This state machine handles the condition when no device is attached. |
||
78 | */ |
||
79 | |||
80 | #define STATE_DETACHED 0x0000 // |
||
81 | #define SUBSTATE_INITIALIZE 0x0000 // |
||
82 | #define SUBSTATE_WAIT_FOR_POWER 0x0010 // |
||
83 | #define SUBSTATE_TURN_ON_POWER 0x0020 // |
||
84 | #define SUBSTATE_WAIT_FOR_DEVICE 0x0030 // |
||
85 | |||
86 | /* |
||
87 | ******************************************************************************* |
||
88 | ATTACHED state machine values |
||
89 | |||
90 | This state machine gets the device descriptor of the remote device. We get the |
||
91 | size of the device descriptor, and use that size to get the entire device |
||
92 | descriptor. Then we check the VID and PID and make sure they appear in the TPL. |
||
93 | */ |
||
94 | |||
95 | #define STATE_ATTACHED 0x0100 // |
||
96 | |||
97 | #define SUBSTATE_SETTLE 0x0000 // |
||
98 | #define SUBSUBSTATE_START_SETTLING_DELAY 0x0000 // |
||
99 | #define SUBSUBSTATE_WAIT_FOR_SETTLING 0x0001 // |
||
100 | #define SUBSUBSTATE_SETTLING_DONE 0x0002 // |
||
101 | |||
102 | #define SUBSTATE_RESET_DEVICE 0x0010 // |
||
103 | #define SUBSUBSTATE_SET_RESET 0x0000 // |
||
104 | #define SUBSUBSTATE_RESET_WAIT 0x0001 // |
||
105 | #define SUBSUBSTATE_RESET_RECOVERY 0x0002 // |
||
106 | #define SUBSUBSTATE_RECOVERY_WAIT 0x0003 // |
||
107 | #define SUBSUBSTATE_RESET_COMPLETE 0x0004 // |
||
108 | |||
109 | #define SUBSTATE_GET_DEVICE_DESCRIPTOR_SIZE 0x0020 // |
||
110 | #define SUBSUBSTATE_SEND_GET_DEVICE_DESCRIPTOR_SIZE 0x0000 // |
||
111 | #define SUBSUBSTATE_WAIT_FOR_GET_DEVICE_DESCRIPTOR_SIZE 0x0001 // |
||
112 | #define SUBSUBSTATE_GET_DEVICE_DESCRIPTOR_SIZE_COMPLETE 0x0002 // |
||
113 | |||
114 | #define SUBSTATE_GET_DEVICE_DESCRIPTOR 0x0030 // |
||
115 | #define SUBSUBSTATE_SEND_GET_DEVICE_DESCRIPTOR 0x0000 // |
||
116 | #define SUBSUBSTATE_WAIT_FOR_GET_DEVICE_DESCRIPTOR 0x0001 // |
||
117 | #define SUBSUBSTATE_GET_DEVICE_DESCRIPTOR_COMPLETE 0x0002 // |
||
118 | |||
119 | #define SUBSTATE_VALIDATE_VID_PID 0x0040 // |
||
120 | |||
121 | /* |
||
122 | ******************************************************************************* |
||
123 | ADDRESSING state machine values |
||
124 | |||
125 | This state machine sets the address of the remote device. |
||
126 | */ |
||
127 | |||
128 | #define STATE_ADDRESSING 0x0200 // |
||
129 | |||
130 | #define SUBSTATE_SET_DEVICE_ADDRESS 0x0000 // |
||
131 | #define SUBSUBSTATE_SEND_SET_DEVICE_ADDRESS 0x0000 // |
||
132 | #define SUBSUBSTATE_WAIT_FOR_SET_DEVICE_ADDRESS 0x0001 // |
||
133 | #define SUBSUBSTATE_SET_DEVICE_ADDRESS_COMPLETE 0x0002 // |
||
134 | |||
135 | /* |
||
136 | ******************************************************************************* |
||
137 | CONFIGURING state machine values |
||
138 | |||
139 | This state machine sets the configuration of the remote device, and sets up |
||
140 | internal variables to support the device. |
||
141 | */ |
||
142 | #define STATE_CONFIGURING 0x0300 // |
||
143 | |||
144 | #define SUBSTATE_INIT_CONFIGURATION 0x0000 // |
||
145 | |||
146 | #define SUBSTATE_GET_CONFIG_DESCRIPTOR_SIZE 0x0010 // |
||
147 | #define SUBSUBSTATE_SEND_GET_CONFIG_DESCRIPTOR_SIZE 0x0000 // |
||
148 | #define SUBSUBSTATE_WAIT_FOR_GET_CONFIG_DESCRIPTOR_SIZE 0x0001 // |
||
149 | #define SUBSUBSTATE_GET_CONFIG_DESCRIPTOR_SIZECOMPLETE 0x0002 // |
||
150 | |||
151 | #define SUBSTATE_GET_CONFIG_DESCRIPTOR 0x0020 // |
||
152 | #define SUBSUBSTATE_SEND_GET_CONFIG_DESCRIPTOR 0x0000 // |
||
153 | #define SUBSUBSTATE_WAIT_FOR_GET_CONFIG_DESCRIPTOR 0x0001 // |
||
154 | #define SUBSUBSTATE_GET_CONFIG_DESCRIPTOR_COMPLETE 0x0002 // |
||
155 | |||
156 | #define SUBSTATE_SELECT_CONFIGURATION 0x0030 // |
||
157 | #define SUBSUBSTATE_SELECT_CONFIGURATION 0x0000 // |
||
158 | #define SUBSUBSTATE_SEND_SET_OTG 0x0001 // |
||
159 | #define SUBSUBSTATE_WAIT_FOR_SET_OTG_DONE 0x0002 // |
||
160 | #define SUBSUBSTATE_SET_OTG_COMPLETE 0x0003 // |
||
161 | |||
162 | #define SUBSTATE_SET_CONFIGURATION 0x0040 // |
||
163 | #define SUBSUBSTATE_SEND_SET_CONFIGURATION 0x0000 // |
||
164 | #define SUBSUBSTATE_WAIT_FOR_SET_CONFIGURATION 0x0001 // |
||
165 | #define SUBSUBSTATE_SET_CONFIGURATION_COMPLETE 0x0002 // |
||
166 | #define SUBSUBSTATE_INIT_CLIENT_DRIVERS 0x0003 // |
||
167 | |||
168 | /* |
||
169 | ******************************************************************************* |
||
170 | RUNNING state machine values |
||
171 | |||
172 | */ |
||
173 | |||
174 | #define STATE_RUNNING 0x0400 // |
||
175 | #define SUBSTATE_NORMAL_RUN 0x0000 // |
||
176 | #define SUBSTATE_SUSPEND_AND_RESUME 0x0010 // |
||
177 | #define SUBSUBSTATE_SUSPEND 0x0000 // |
||
178 | #define SUBSUBSTATE_RESUME 0x0001 // |
||
179 | #define SUBSUBSTATE_RESUME_WAIT 0x0002 // |
||
180 | #define SUBSUBSTATE_RESUME_RECOVERY 0x0003 // |
||
181 | #define SUBSUBSTATE_RESUME_RECOVERY_WAIT 0x0004 // |
||
182 | #define SUBSUBSTATE_RESUME_COMPLETE 0x0005 // |
||
183 | |||
184 | |||
185 | /* |
||
186 | ******************************************************************************* |
||
187 | HOLDING state machine values |
||
188 | |||
189 | */ |
||
190 | |||
191 | #define STATE_HOLDING 0x0500 // |
||
192 | #define SUBSTATE_HOLD_INIT 0x0000 // |
||
193 | #define SUBSTATE_HOLD 0x0001 // |
||
194 | |||
195 | |||
196 | // ***************************************************************************** |
||
197 | // Section: Token State Machine Constants |
||
198 | // ***************************************************************************** |
||
199 | |||
200 | #define TSTATE_MASK 0x00F0 // |
||
201 | #define TSUBSTATE_MASK 0x000F // |
||
202 | |||
203 | #define TSUBSTATE_ERROR 0x000F // |
||
204 | |||
205 | #define TSTATE_IDLE 0x0000 // |
||
206 | |||
207 | #define TSTATE_CONTROL_NO_DATA 0x0010 // |
||
208 | #define TSUBSTATE_CONTROL_NO_DATA_SETUP 0x0000 // |
||
209 | #define TSUBSTATE_CONTROL_NO_DATA_ACK 0x0001 // |
||
210 | #define TSUBSTATE_CONTROL_NO_DATA_COMPLETE 0x0002 // |
||
211 | |||
212 | #define TSTATE_CONTROL_READ 0x0020 // |
||
213 | #define TSUBSTATE_CONTROL_READ_SETUP 0x0000 // |
||
214 | #define TSUBSTATE_CONTROL_READ_DATA 0x0001 // |
||
215 | #define TSUBSTATE_CONTROL_READ_ACK 0x0002 // |
||
216 | #define TSUBSTATE_CONTROL_READ_COMPLETE 0x0003 // |
||
217 | |||
218 | #define TSTATE_CONTROL_WRITE 0x0030 // |
||
219 | #define TSUBSTATE_CONTROL_WRITE_SETUP 0x0000 // |
||
220 | #define TSUBSTATE_CONTROL_WRITE_DATA 0x0001 // |
||
221 | #define TSUBSTATE_CONTROL_WRITE_ACK 0x0002 // |
||
222 | #define TSUBSTATE_CONTROL_WRITE_COMPLETE 0x0003 // |
||
223 | |||
224 | #define TSTATE_INTERRUPT_READ 0x0040 // |
||
225 | #define TSUBSTATE_INTERRUPT_READ_DATA 0x0000 // |
||
226 | #define TSUBSTATE_INTERRUPT_READ_COMPLETE 0x0001 // |
||
227 | |||
228 | #define TSTATE_INTERRUPT_WRITE 0x0050 // |
||
229 | #define TSUBSTATE_INTERRUPT_WRITE_DATA 0x0000 // |
||
230 | #define TSUBSTATE_INTERRUPT_WRITE_COMPLETE 0x0001 // |
||
231 | |||
232 | #define TSTATE_ISOCHRONOUS_READ 0x0060 // |
||
233 | #define TSUBSTATE_ISOCHRONOUS_READ_DATA 0x0000 // |
||
234 | #define TSUBSTATE_ISOCHRONOUS_READ_COMPLETE 0x0001 // |
||
235 | |||
236 | #define TSTATE_ISOCHRONOUS_WRITE 0x0070 // |
||
237 | #define TSUBSTATE_ISOCHRONOUS_WRITE_DATA 0x0000 // |
||
238 | #define TSUBSTATE_ISOCHRONOUS_WRITE_COMPLETE 0x0001 // |
||
239 | |||
240 | #define TSTATE_BULK_READ 0x0080 // |
||
241 | #define TSUBSTATE_BULK_READ_DATA 0x0000 // |
||
242 | #define TSUBSTATE_BULK_READ_COMPLETE 0x0001 // |
||
243 | |||
244 | #define TSTATE_BULK_WRITE 0x0090 // |
||
245 | #define TSUBSTATE_BULK_WRITE_DATA 0x0000 // |
||
246 | #define TSUBSTATE_BULK_WRITE_COMPLETE 0x0001 // |
||
247 | |||
248 | //****************************************************************************** |
||
249 | // Section: USB Peripheral Constants |
||
250 | //****************************************************************************** |
||
251 | |||
252 | // Section: USB Control Register Constants |
||
253 | |||
254 | // Section: U1PWRC |
||
255 | |||
256 | #define USB_SUSPEND_MODE 0x02 // U1PWRC - Put the module in suspend mode. |
||
257 | #define USB_NORMAL_OPERATION 0x00 // U1PWRC - Normal USB operation |
||
258 | #define USB_ENABLED 0x01 // U1PWRC - Enable the USB module. |
||
259 | #define USB_DISABLED 0x00 // U1PWRC - Disable the USB module. |
||
260 | |||
261 | // Section: U1OTGCON |
||
262 | |||
263 | #define USB_DPLUS_PULLUP_ENABLE 0x80 // U1OTGCON - Enable D+ pull-up |
||
264 | #define USB_DMINUS_PULLUP_ENABLE 0x40 // U1OTGCON - Enable D- pull-up |
||
265 | #define USB_DPLUS_PULLDOWN_ENABLE 0x20 // U1OTGCON - Enable D+ pull-down |
||
266 | #define USB_DMINUS_PULLDOWN_ENABLE 0x10 // U1OTGCON - Enable D- pull-down |
||
267 | #define USB_VBUS_ON 0x08 // U1OTGCON - Enable Vbus |
||
268 | #define USB_OTG_ENABLE 0x04 // U1OTGCON - Enable OTG |
||
269 | #define USB_VBUS_CHARGE_ENABLE 0x02 // U1OTGCON - Vbus charge line set to 5V |
||
270 | #define USB_VBUS_DISCHARGE_ENABLE 0x01 // U1OTGCON - Discharge Vbus |
||
271 | |||
272 | // Section: U1OTGIE/U1OTGIR |
||
273 | |||
274 | #define USB_INTERRUPT_IDIF 0x80 // U1OTGIR - ID state change flag |
||
275 | #define USB_INTERRUPT_T1MSECIF 0x40 // U1OTGIR - 1ms timer interrupt flag |
||
276 | #define USB_INTERRUPT_LSTATEIF 0x20 // U1OTGIR - line state stable flag |
||
277 | #define USB_INTERRUPT_ACTIVIF 0x10 // U1OTGIR - bus activity flag |
||
278 | #define USB_INTERRUPT_SESVDIF 0x08 // U1OTGIR - session valid change flag |
||
279 | #define USB_INTERRUPT_SESENDIF 0x04 // U1OTGIR - B-device Vbus change flag |
||
280 | #define USB_INTERRUPT_VBUSVDIF 0x01 // U1OTGIR - A-device Vbus change flag |
||
281 | |||
282 | // Section: U1CON |
||
283 | |||
284 | #define USB_JSTATE_DETECTED 0x80 // U1CON - J state |
||
285 | #define USB_SE0_DETECTED 0x40 // U1CON - Single ended 0 detected |
||
286 | #define USB_TOKEN_BUSY 0x20 // U1CON - Token currently being processed |
||
287 | #define USB_ASSERT_RESET 0x10 // U1CON - RESET signalling |
||
288 | #define USB_HOST_MODE_ENABLE 0x08 // U1CON - Enable host mode |
||
289 | #define USB_RESUME_ACTIVATED 0x04 // U1CON - RESUME signalling |
||
290 | #define USB_PINGPONG_RESET 0x02 // U1CON - Reset ping-pong buffer pointer |
||
291 | #define USB_SOF_ENABLE 0x01 // U1CON - Enable SOF generation |
||
292 | #define USB_SOF_DISABLE 0x00 // U1CON - Disable SOF generation |
||
293 | |||
294 | // Section: U1CNFG1 |
||
295 | |||
296 | #define USB_EYE_PATTERN_TEST 0x80 // U1CFG1 - Enable eye pattern test |
||
297 | #define USB_MONITOR_OE 0x40 // U1CFG1 - nOE signal active |
||
298 | #define USB_FREEZE_IN_DEBUG_MODE 0x20 // U1CFG1 - Freeze on halt when in debug mode |
||
299 | #define USB_STOP_IN_IDLE_MODE 0x10 // U1CFG1 - Stop module in idle mode |
||
300 | #define USB_PING_PONG__ALL_BUT_EP0 0x03 // U1CFG1 - Ping-pong on all endpoints except EP0 |
||
301 | #define USB_PING_PONG__FULL_PING_PONG 0x02 // U1CFG1 - Ping-pong on all endpoints |
||
302 | #define USB_PING_PONG__EP0_OUT_ONLY 0x01 // U1CFG1 - Ping-pong on EP 0 out only |
||
303 | #define USB_PING_PONG__NO_PING_PONG 0x00 // U1CFG1 - No ping-pong |
||
304 | |||
305 | // Section: U1CNFG2 |
||
306 | |||
307 | #define USB_VBUS_PULLUP_ENABLE 0x01 // U1CNFG2 - Enable Vbus pull-up |
||
308 | #define USB_EXTERNAL_IIC 0x08 // U1CNFG2 - External module controlled by I2C |
||
309 | #define USB_VBUS_BOOST_DISABLE 0x04 // U1CNFG2 - Disable Vbus boost |
||
310 | #define USB_VBUS_BOOST_ENABLE 0x00 // U1CNFG2 - Enable Vbus boost |
||
311 | #define USB_VBUS_COMPARE_DISABLE 0x02 // U1CNFG2 - Vbus comparator disabled |
||
312 | #define USB_VBUS_COMPARE_ENABLE 0x00 // U1CNFG2 - Vbus comparator enabled |
||
313 | #define USB_ONCHIP_DISABLE 0x01 // U1CNFG2 - On-chip transceiver disabled |
||
314 | #define USB_ONCHIP_ENABLE 0x00 // U1CNFG2 - On-chip transceiver enabled |
||
315 | |||
316 | // Section: U1IE/U1IR |
||
317 | |||
318 | #define USB_INTERRUPT_STALL 0x80 // U1IE - Stall interrupt enable |
||
319 | #define USB_INTERRUPT_ATTACH 0x40 // U1IE - Attach interrupt enable |
||
320 | #define USB_INTERRUPT_RESUME 0x20 // U1IE - Resume interrupt enable |
||
321 | #define USB_INTERRUPT_IDLE 0x10 // U1IE - Idle interrupt enable |
||
322 | #define USB_INTERRUPT_TRANSFER 0x08 // U1IE - Transfer Done interrupt enable |
||
323 | #define USB_INTERRUPT_SOF 0x04 // U1IE - Start of Frame Threshold interrupt enable |
||
324 | #define USB_INTERRUPT_ERROR 0x02 // U1IE - USB Error interrupt enable |
||
325 | #define USB_INTERRUPT_DETACH 0x01 // U1IE - Detach interrupt enable |
||
326 | |||
327 | |||
328 | //****************************************************************************** |
||
329 | // Section: Other Constants |
||
330 | //****************************************************************************** |
||
331 | |||
332 | #define CLIENT_DRIVER_HOST 0xFF // Client driver index for indicating the host driver. |
||
333 | |||
334 | #define DTS_DATA0 0 // DTS bit - DATA0 PID |
||
335 | #define DTS_DATA1 1 // DTS bit - DATA1 PID |
||
336 | |||
337 | #define UEP_DIRECT_LOW_SPEED 0x80 // UEP0 - Direct connect to low speed device enabled |
||
338 | #define UEP_NO_DIRECT_LOW_SPEED 0x00 // UEP0 - Direct connect to low speed device disabled |
||
339 | #define UEP_RETRY_NAKS 0x40 // UEP0 - No automatic retry of NAK'd transactions |
||
340 | #define UEP_NO_RETRY_NAKS 0x00 // UEP0 - Automatic retry of NAK'd transactions |
||
341 | #define UEP_NO_SETUP_TRANSFERS 0x10 // UEP0 - SETUP transfers not allowed |
||
342 | #define UEP_ALLOW_SETUP_TRANSFERS 0x00 // UEP0 - SETUP transfers allowed |
||
343 | #define UEP_RX_ENABLE 0x08 // UEP0 - Endpoint can receive data |
||
344 | #define UEP_RX_DISABLE 0x00 // UEP0 - Endpoint cannot receive data |
||
345 | #define UEP_TX_ENABLE 0x04 // UEP0 - Endpoint can transmit data |
||
346 | #define UEP_TX_DISABLE 0x00 // UEP0 - Endpoint cannot transmit data |
||
347 | #define UEP_HANDSHAKE_ENABLE 0x01 // UEP0 - Endpoint handshake enabled |
||
348 | #define UEP_HANDSHAKE_DISABLE 0x00 // UEP0 - Endpoint handshake disabled (isochronous endpoints) |
||
349 | |||
350 | #define USB_ENDPOINT_CONTROL_BULK (UEP_NO_SETUP_TRANSFERS | UEP_RX_ENABLE | UEP_TX_ENABLE | UEP_HANDSHAKE_ENABLE) // |
||
351 | #define USB_ENDPOINT_CONTROL_ISOCHRONOUS (UEP_NO_SETUP_TRANSFERS | UEP_RX_ENABLE | UEP_TX_ENABLE ) // |
||
352 | #define USB_ENDPOINT_CONTROL_INTERRUPT (UEP_NO_SETUP_TRANSFERS | UEP_RX_ENABLE | UEP_TX_ENABLE | UEP_HANDSHAKE_ENABLE) // |
||
353 | #define USB_ENDPOINT_CONTROL_SETUP (UEP_RX_ENABLE | UEP_TX_ENABLE | UEP_HANDSHAKE_ENABLE) // |
||
354 | |||
355 | #define USB_DISABLE_ENDPOINT 0x00 // Value to disable an endpoint. |
||
356 | |||
357 | #define USB_SOF_THRESHOLD_08 0x12 // U1SOF - Threshold for a max packet size of 8 |
||
358 | #define USB_SOF_THRESHOLD_16 0x1A // U1SOF - Threshold for a max packet size of 16 |
||
359 | #define USB_SOF_THRESHOLD_32 0x2A // U1SOF - Threshold for a max packet size of 32 |
||
360 | #define USB_SOF_THRESHOLD_64 0x4A // U1SOF - Threshold for a max packet size of 64 |
||
361 | |||
362 | #define USB_1MS_TIMER_FLAG 0x40 |
||
363 | #ifndef USB_INSERT_TIME |
||
364 | #define USB_INSERT_TIME (250+1) // Insertion delay time (spec minimum is 100 ms) |
||
365 | #endif |
||
366 | #define USB_RESET_TIME (50+1) // RESET signaling time - 50ms |
||
367 | #if defined( __C30__ ) |
||
368 | #define USB_RESET_RECOVERY_TIME (10+1) // RESET recovery time. |
||
369 | #elif defined( __PIC32MX__ ) |
||
370 | #define USB_RESET_RECOVERY_TIME (100+1) // RESET recovery time - Changed to 100 ms from 10ms. Some devices take longer. |
||
371 | #else |
||
372 | #error Unknown USB_RESET_RECOVERY_TIME |
||
373 | #endif |
||
374 | #define USB_RESUME_TIME (20+1) // RESUME signaling time - 20 ms |
||
375 | #define USB_RESUME_RECOVERY_TIME (10+1) // RESUME recovery time - 10 ms |
||
376 | |||
377 | |||
378 | //****************************************************************************** |
||
379 | //****************************************************************************** |
||
380 | // Section: Data Structures |
||
381 | // |
||
382 | // These data structures are all internal to the stack. |
||
383 | //****************************************************************************** |
||
384 | //****************************************************************************** |
||
385 | |||
386 | // ***************************************************************************** |
||
387 | /* USB Bus Information |
||
388 | |||
389 | This structure is used to hold information about the USB bus status. |
||
390 | */ |
||
391 | typedef struct _USB_BUS_INFO |
||
392 | { |
||
393 | volatile union |
||
394 | { |
||
395 | struct |
||
396 | { |
||
397 | BYTE bfControlTransfersDone : 1; // All control transfers in the current frame are complete. |
||
398 | BYTE bfInterruptTransfersDone : 1; // All interrupt transfers in the current frame are complete. |
||
399 | BYTE bfIsochronousTransfersDone : 1; // All isochronous transfers in the current frame are complete. |
||
400 | BYTE bfBulkTransfersDone : 1; // All bulk transfers in the current frame are complete. |
||
401 | BYTE bfTokenAlreadyWritten : 1; // A token has already been written to the USB module |
||
402 | }; |
||
403 | WORD val; // |
||
404 | } flags; // |
||
405 | // volatile DWORD dBytesSentInFrame; // The number of bytes sent during the current frame. Isochronous use only. |
||
406 | volatile BYTE lastBulkTransaction; // The last bulk transaction sent. |
||
407 | volatile BYTE countBulkTransactions; // The number of active bulk transactions. |
||
408 | } USB_BUS_INFO; |
||
409 | |||
410 | |||
411 | // ***************************************************************************** |
||
412 | /* USB Configuration Node |
||
413 | |||
414 | This structure is used to make a linked list of all the configuration |
||
415 | descriptors of an attached device. |
||
416 | */ |
||
417 | typedef struct _USB_CONFIGURATION |
||
418 | { |
||
419 | BYTE *descriptor; // Complete Configuration Descriptor. |
||
420 | struct _USB_CONFIGURATION *next; // Pointer to next node. |
||
421 | BYTE configNumber; // Number of this Configuration. |
||
422 | } USB_CONFIGURATION; |
||
423 | |||
424 | |||
425 | // ***************************************************************************** |
||
426 | /* Endpoint Information Node |
||
427 | |||
428 | This structure contains all the needed information about an endpoint. Multiple |
||
429 | endpoints form a linked list. |
||
430 | */ |
||
431 | typedef struct _USB_ENDPOINT_INFO |
||
432 | { |
||
433 | struct _USB_ENDPOINT_INFO *next; // Pointer to the next node in the list. |
||
434 | |||
435 | volatile union |
||
436 | { |
||
437 | struct |
||
438 | { |
||
439 | BYTE bfErrorCount : 5; // Not used for isochronous. |
||
440 | BYTE bfStalled : 1; // Received a STALL. Requires host interaction to clear. |
||
441 | BYTE bfError : 1; // Error count excessive. Must be cleared by the application. |
||
442 | BYTE bfUserAbort : 1; // User terminated transfer. |
||
443 | BYTE bfTransferSuccessful : 1; // Received an ACK. |
||
444 | BYTE bfTransferComplete : 1; // Transfer done, status obtained. |
||
445 | BYTE bfUseDTS : 1; // Use DTS error checking. |
||
446 | BYTE bfNextDATA01 : 1; // The value of DTS for the next transfer. |
||
447 | BYTE bfLastTransferNAKd : 1; // The last transfer attempted NAK'd. |
||
448 | BYTE bfNAKTimeoutEnabled : 1; // Endpoint will time out if too many NAKs are received. |
||
449 | }; |
||
450 | WORD val; |
||
451 | } status; |
||
452 | WORD wInterval; // Polling interval for interrupt and isochronous endpoints. |
||
453 | volatile WORD wIntervalCount; // Current interval count. |
||
454 | WORD wMaxPacketSize; // Endpoint packet size. |
||
455 | DWORD dataCountMax; // Amount of data to transfer during the transfer. Not used for isochronous transfers. |
||
456 | WORD dataCountMaxSETUP; // Amount of data in the SETUP packet (if applicable). |
||
457 | volatile DWORD dataCount; // Count of bytes transferred. |
||
458 | BYTE *pUserDataSETUP; // Pointer to data for the SETUP packet (if applicable). |
||
459 | BYTE *pUserData; // Pointer to data for the transfer. |
||
460 | volatile BYTE transferState; // State of endpoint tranfer. |
||
461 | BYTE clientDriver; // Client driver index for events |
||
462 | BYTE bEndpointAddress; // Endpoint address |
||
463 | TRANSFER_ATTRIBUTES bmAttributes; // Endpoint attributes, including transfer type. |
||
464 | volatile BYTE bErrorCode; // If bfError is set, this indicates the reason |
||
465 | volatile WORD countNAKs; // Count of NAK's of current transaction. |
||
466 | WORD timeoutNAKs; // Count of NAK's for a timeout, if bfNAKTimeoutEnabled. |
||
467 | |||
468 | } USB_ENDPOINT_INFO; |
||
469 | |||
470 | |||
471 | // ***************************************************************************** |
||
472 | /* Interface Setting Information Structure |
||
473 | |||
474 | This structure contains information about one interface. |
||
475 | */ |
||
476 | typedef struct _USB_INTERFACE_SETTING_INFO |
||
477 | { |
||
478 | struct _USB_INTERFACE_SETTING_INFO *next; // Pointer to the next node in the list. |
||
479 | |||
480 | BYTE interfaceAltSetting; // Alternate Interface setting |
||
481 | USB_ENDPOINT_INFO *pEndpointList; // List of endpoints associated with this interface setting |
||
482 | |||
483 | } USB_INTERFACE_SETTING_INFO; |
||
484 | |||
485 | |||
486 | // ***************************************************************************** |
||
487 | /* Interface Information Structure |
||
488 | |||
489 | This structure contains information about one interface. |
||
490 | */ |
||
491 | typedef struct _USB_INTERFACE_INFO |
||
492 | { |
||
493 | struct _USB_INTERFACE_INFO *next; // Pointer to the next node in the list. |
||
494 | |||
495 | USB_INTERFACE_SETTING_INFO *pInterfaceSettings; // Pointer to the list of alternate settings. |
||
496 | USB_INTERFACE_SETTING_INFO *pCurrentSetting; // Current Alternate Interface setting |
||
497 | BYTE interface; // Interface number |
||
498 | BYTE clientDriver; // Index into client driver table for this Interface |
||
499 | |||
500 | } USB_INTERFACE_INFO; |
||
501 | |||
502 | |||
503 | // ***************************************************************************** |
||
504 | /* USB Device Information |
||
505 | |||
506 | This structure is used to hold all the information about an attached device. |
||
507 | */ |
||
508 | typedef struct _USB_DEVICE_INFO |
||
509 | { |
||
510 | USB_CONFIGURATION *currentConfigurationDescriptor; // Descriptor of the current Configuration. |
||
511 | BYTE currentConfiguration; // Value of current Configuration. |
||
512 | BYTE attributesOTG; // OTG attributes. |
||
513 | BYTE deviceAddressAndSpeed; // Device address and low/full speed indication. |
||
514 | BYTE deviceAddress; // Device address. |
||
515 | BYTE errorCode; // Error code of last operation. |
||
516 | BYTE deviceClientDriver; // Index of client driver for this device if bfUseDeviceClientDriver=1. |
||
517 | WORD currentConfigurationPower; // Max power in milli-amps. |
||
518 | |||
519 | USB_CONFIGURATION *pConfigurationDescriptorList; // Pointer to the list of Cnfiguration Descriptors of the attached device. |
||
520 | USB_INTERFACE_INFO *pInterfaceList; // List of interfaces on the attached device. |
||
521 | USB_ENDPOINT_INFO *pEndpoint0; // Pointer to a structure that describes EP0. |
||
522 | |||
523 | volatile union |
||
524 | { |
||
525 | struct |
||
526 | { |
||
527 | BYTE bfIsLowSpeed : 1; // If the device is low speed (default = 0). |
||
528 | BYTE bfSupportsOTG : 1; // If the device supports OTG (default = 0). |
||
529 | BYTE bfConfiguredOTG : 1; // If OTG on the device has been configured (default = 0). |
||
530 | BYTE bfAllowHNP : 1; // If Host Negotiation Protocol is allowed (default = 0). |
||
531 | BYTE bfPingPongIn : 1; // Ping-pong status of IN buffers (default = 0). |
||
532 | BYTE bfPingPongOut : 1; // Ping-pong status of OUT buffers (default = 0). |
||
533 | BYTE bfUseDeviceClientDriver : 1; // Indicates driver should use a single client driver (deviceClientDriver) |
||
534 | }; |
||
535 | WORD val; |
||
536 | } flags; |
||
537 | } USB_DEVICE_INFO; |
||
538 | |||
539 | |||
540 | // ***************************************************************************** |
||
541 | /* USB Root Hub Information |
||
542 | |||
543 | This structure contains information about the USB root hub. |
||
544 | */ |
||
545 | |||
546 | typedef struct _USB_ROOT_HUB_INFO |
||
547 | { |
||
548 | union |
||
549 | { |
||
550 | struct |
||
551 | { |
||
552 | BYTE bPowerGoodPort0 : 1; // Power can turned on |
||
553 | }; |
||
554 | BYTE val; |
||
555 | } flags; |
||
556 | } USB_ROOT_HUB_INFO; |
||
557 | |||
558 | |||
559 | // ***************************************************************************** |
||
560 | /* Event Data |
||
561 | |||
562 | This structure defines the data associated with any USB events (see USB_EVENT) |
||
563 | that can be generated by the USB ISR (see _USB1Interrupt). These events and |
||
564 | their associated data are placed in an event queue used to synchronize between |
||
565 | the main host-tasks loop (see USBHostTasks) and the ISR. This queue is required |
||
566 | only if transfer events are being used. All other events are send directly to |
||
567 | the client drivers. |
||
568 | */ |
||
569 | #if defined( USB_ENABLE_TRANSFER_EVENT ) |
||
570 | typedef struct |
||
571 | { |
||
572 | USB_EVENT event; // Event that occured. |
||
573 | union |
||
574 | { |
||
575 | HOST_TRANSFER_DATA TransferData; // Event: EVENT_TRANSFER, |
||
576 | // EVENT_BUS_ERROR |
||
577 | |||
578 | // Additional items needed for new events can be added here. |
||
579 | }; |
||
580 | } USB_EVENT_DATA; |
||
581 | #endif |
||
582 | |||
583 | |||
584 | |||
585 | // ***************************************************************************** |
||
586 | /* Event Queue |
||
587 | |||
588 | This structure defines the queue of USB events that can be generated by the |
||
589 | ISR that need to be synchronized to the USB event tasks loop (see |
||
590 | USB_EVENT_DATA, above). See "struct_queue.h" for usage and operations. |
||
591 | */ |
||
592 | #if defined( USB_ENABLE_TRANSFER_EVENT ) |
||
593 | #ifndef USB_EVENT_QUEUE_DEPTH |
||
594 | #define USB_EVENT_QUEUE_DEPTH 4 // Default depth of 4 events |
||
595 | #endif |
||
596 | |||
597 | typedef struct _usb_event_queue |
||
598 | { |
||
599 | int head; |
||
600 | int tail; |
||
601 | int count; |
||
602 | USB_EVENT_DATA buffer[USB_EVENT_QUEUE_DEPTH]; |
||
603 | |||
604 | } USB_EVENT_QUEUE; |
||
605 | #endif |
||
606 | |||
607 | |||
608 | /******************************************************************** |
||
609 | * USB Endpoint Control Registers |
||
610 | *******************************************************************/ |
||
611 | |||
612 | // See _UEP data type for EP Control Register definitions in the |
||
613 | // processor-specific header files. |
||
614 | |||
615 | #define UEPList (*((_UEP*)&U1EP0)) |
||
616 | |||
617 | |||
618 | //****************************************************************************** |
||
619 | //****************************************************************************** |
||
620 | // Section: Macros |
||
621 | // |
||
622 | // These macros are all internal to the host layer. |
||
623 | //****************************************************************************** |
||
624 | //****************************************************************************** |
||
625 | |||
626 | #define _USB_InitErrorCounters() { numCommandTries = USB_NUM_COMMAND_TRIES; } |
||
627 | #define _USB_SetDATA01(x) { pCurrentEndpoint->status.bfNextDATA01 = x; } |
||
628 | #define _USB_SetErrorCode(x) { usbDeviceInfo.errorCode = x; } |
||
629 | #define _USB_SetHoldState() { usbHostState = STATE_HOLDING; } |
||
630 | #define _USB_SetNextState() { usbHostState = (usbHostState & STATE_MASK) + NEXT_STATE; } |
||
631 | #define _USB_SetNextSubState() { usbHostState = (usbHostState & (STATE_MASK | SUBSTATE_MASK)) + NEXT_SUBSTATE; } |
||
632 | #define _USB_SetNextSubSubState() { usbHostState = usbHostState + NEXT_SUBSUBSTATE; } |
||
633 | #define _USB_SetNextTransferState() { pCurrentEndpoint->transferState ++; } |
||
634 | #define _USB_SetPreviousSubSubState() { usbHostState = usbHostState - NEXT_SUBSUBSTATE; } |
||
635 | #define _USB_SetTransferErrorState(x) { x->transferState = (x->transferState & TSTATE_MASK) | TSUBSTATE_ERROR; } |
||
636 | |||
637 | |||
638 | //****************************************************************************** |
||
639 | //****************************************************************************** |
||
640 | // Section: Local Prototypes |
||
641 | //****************************************************************************** |
||
642 | //****************************************************************************** |
||
643 | |||
644 | void _USB_CheckCommandAndEnumerationAttempts( void ); |
||
645 | BOOL _USB_FindClassDriver( BYTE bClass, BYTE bSubClass, BYTE bProtocol, BYTE *pbClientDrv ); |
||
646 | BOOL _USB_FindDeviceLevelClientDriver( void ); |
||
647 | USB_ENDPOINT_INFO * _USB_FindEndpoint( BYTE endpoint ); |
||
648 | USB_INTERFACE_INFO * _USB_FindInterface ( BYTE bInterface, BYTE bAltSetting ); |
||
649 | void _USB_FindNextToken( void ); |
||
650 | BOOL _USB_FindServiceEndpoint( BYTE transferType ); |
||
651 | void _USB_FreeConfigMemory( void ); |
||
652 | void _USB_FreeMemory( void ); |
||
653 | void _USB_InitControlRead( USB_ENDPOINT_INFO *pEndpoint, BYTE *pControlData, WORD controlSize, |
||
654 | BYTE *pData, WORD size ); |
||
655 | void _USB_InitControlWrite( USB_ENDPOINT_INFO *pEndpoint, BYTE *pControlData, WORD controlSize, |
||
656 | BYTE *pData, WORD size ); |
||
657 | void _USB_InitRead( USB_ENDPOINT_INFO *pEndpoint, BYTE *pData, WORD size ); |
||
658 | void _USB_InitWrite( USB_ENDPOINT_INFO *pEndpoint, BYTE *pData, WORD size ); |
||
659 | void _USB_NotifyClients( BYTE DevAddress, USB_EVENT event, void *data, unsigned int size ); |
||
660 | BOOL _USB_ParseConfigurationDescriptor( void ); |
||
661 | void _USB_ResetDATA0( BYTE endpoint ); |
||
662 | void _USB_SendToken( BYTE endpoint, BYTE tokenType ); |
||
663 | void _USB_SetBDT( BYTE direction ); |
||
664 | BOOL _USB_TransferInProgress( void ); |
||
665 | |||
666 | |||
667 | #endif // _USB_HOST_LOCAL_ |
||
668 | |||
669 |
Powered by WebSVN v2.8.3