NUC472_NUC442_BSP V3.03.004
The Board Support Package for NUC472/NUC442
usb.h
Go to the documentation of this file.
1
2#ifndef _USBH_H_
3#define _USBH_H_
4
6
7enum OCHI_CC_CODE
8{
9/* mapping of the OHCI CC status to error codes */
10 CC_NOERROR, /* No Error */
11 CC_CRC, /* CRC Error */
12 CC_BITSTUFF, /* Bit Stuff */
13 CC_DATA_TOGGLE, /* Data Toggle*/
14 CC_STALL, /* Stall */
15 CC_NOTRESPONSE, /* DevNotResp */
16 CC_PID_CHECK, /* PIDCheck */
17 CC_UNEXPECTED_PID, /* UnExpPID */
18 CC_DATA_OVERRUN, /* DataOver */
19 CC_DATA_UNDERRUN, /* DataUnder */
20 CC_RESERVED1, /* reserved */
21 CC_RESERVED2, /* reserved */
22 CC_BUFFER_OVERRUN, /* BufferOver */
23 CC_BUFFER_UNDERRUN, /* BuffUnder */
24 CC_NOT_ACCESS /* Not Access */
25};
26
27
28/* ED States */
29#define ED_NEW 0x00
30#define ED_UNLINK 0x01
31#define ED_OPER 0x02
32#define ED_DEL 0x04
33#define ED_URB_DEL 0x08
34
35/* usb_ohci_ed */
36typedef struct ed
37{
38 uint32_t hwINFO;
39 uint32_t hwTailP;
40 uint32_t hwHeadP;
41 uint32_t hwNextED;
42} ED_T;
43
44
45/* TD info field */
46#define TD_CC 0xF0000000
47#define TD_CC_GET(td_p) ((td_p >>28) & 0x0F)
48#define TD_CC_SET(td_p, cc) (td_p) = ((td_p) & 0x0FFFFFFF) | (((cc) & 0x0F) << 28)
49#define TD_EC 0x0C000000
50#define TD_T_DATA0 0x02000000
51#define TD_T_DATA1 0x03000000
52#define TD_T_TOGGLE 0x00000000
53#define TD_R 0x00040000
54#define TD_DI 0x00E00000
55#define TD_DI_SET(X) (((X) & 0x07)<< 21)
56#define TD_DP 0x00180000
57#define TD_DP_SETUP 0x00000000
58#define TD_DP_IN 0x00100000
59#define TD_DP_OUT 0x00080000
60
61#define TD_ISO 0x00010000
62#define TD_DEL 0x00020000
63
64#define MAXPSW 8
65
66typedef struct td
67{
68 uint32_t hwINFO;
69 uint32_t hwCBP; /* Current Buffer Pointer */
70 uint32_t hwNextTD; /* Next TD Pointer */
71 uint32_t hwBE; /* Memory Buffer End Pointer */
72} TD_T;
73
74
75/*
76 * The HCCA (Host Controller Communications Area) is a 256 byte
77 * structure defined in the OHCI spec. that the host controller is
78 * told the base address of. It must be 256-byte aligned.
79 */
80
81#define NUM_INTS 32 /* part of the OHCI standard */
82
83typedef struct ohci_hcca
84{
85 uint32_t int_table[NUM_INTS]; /* Interrupt ED table */
86#ifdef __BIG_ENDIAN
87 uint16_t pad1; /* set to 0 on each frame_no change */
88 uint16_t frame_no; /* current frame number */
89#else
90 uint16_t frame_no; /* current frame number */
91 uint16_t pad1; /* set to 0 on each frame_no change */
92#endif
93 uint32_t done_head; /* info returned for an interrupt */
94 uint8_t reserved_for_hc[116];
95} OHCI_HCCA_T;
96
97
98/* OHCI CONTROL AND STATUS REGISTER MASKS */
99
100
101/* pre-shifted values for HCFS */
102#define OHCI_USB_RESET (0 << 6)
103#define OHCI_USB_RESUME (1 << 6)
104#define OHCI_USB_OPER (2 << 6)
105#define OHCI_USB_SUSPEND (3 << 6)
106
107/*
108 * HcCommandStatus (cmdstatus) register masks
109 */
110#define OHCI_HCR (1 << 0) /* host controller reset */
111#define OHCI_CLF (1 << 1) /* control list filled */
112#define OHCI_BLF (1 << 2) /* bulk list filled */
113#define OHCI_OCR (1 << 3) /* ownership change request */
114#define OHCI_SOC (3 << 16) /* scheduling overrun count */
115
116#define OHCI_INTR_MIE 0x80000000 /* master interrupt enable */
117
118/*
119 * USB directions
120 */
121#define USB_DIR_OUT 0
122#define USB_DIR_IN 0x80
123
124/*
125 * Descriptor types
126 */
127#define USB_DT_DEVICE 0x01
128#define USB_DT_CONFIG 0x02
129#define USB_DT_STRING 0x03
130#define USB_DT_INTERFACE 0x04
131#define USB_DT_ENDPOINT 0x05
132
133/*
134 * Standard requests
135 */
136#define USB_REQ_GET_STATUS 0x00
137#define USB_REQ_CLEAR_FEATURE 0x01
138#define USB_REQ_SET_FEATURE 0x03
139#define USB_REQ_SET_ADDRESS 0x05
140#define USB_REQ_GET_DESCRIPTOR 0x06
141#define USB_REQ_SET_CONFIGURATION 0x09
142#define USB_REQ_SET_INTERFACE 0x0B
143
144#ifdef __ICCARM__
145typedef struct
146{
147 __packed uint8_t requesttype;
148 __packed uint8_t request;
149 __packed uint16_t value;
150 __packed uint16_t index;
151 __packed uint16_t length;
152} DEV_REQ_T;
153#else
154typedef struct __attribute__((__packed__))
155{
156 uint8_t requesttype;
157 uint8_t request;
158 uint16_t value;
159 uint16_t index;
160 uint16_t length;
161}
163#endif
164
165
166/*-----------------------------------------------------------------------------------
167 * USB device descriptor
168 */
169#ifdef __ICCARM__
170typedef struct usb_device_descriptor
171{
172 __packed uint8_t bLength;
173 __packed uint8_t bDescriptorType;
174 __packed uint16_t bcdUSB;
175 __packed uint8_t bDeviceClass;
176 __packed uint8_t bDeviceSubClass;
177 __packed uint8_t bDeviceProtocol;
178 __packed uint8_t bMaxPacketSize0;
179 __packed uint16_t idVendor;
180 __packed uint16_t idProduct;
181 __packed uint16_t bcdDevice;
182 __packed uint8_t iManufacturer;
183 __packed uint8_t iProduct;
184 __packed uint8_t iSerialNumber;
185 __packed uint8_t bNumConfigurations;
187#else
188typedef struct __attribute__((__packed__)) usb_device_descriptor
189{
190 uint8_t bLength;
191 uint8_t bDescriptorType;
192 uint16_t bcdUSB;
193 uint8_t bDeviceClass;
194 uint8_t bDeviceSubClass;
195 uint8_t bDeviceProtocol;
196 uint8_t bMaxPacketSize0;
197 uint16_t idVendor;
198 uint16_t idProduct;
199 uint16_t bcdDevice;
200 uint8_t iManufacturer;
201 uint8_t iProduct;
202 uint8_t iSerialNumber;
203 uint8_t bNumConfigurations;
205#endif
206
207/*-----------------------------------------------------------------------------------
208 * Configuration descriptor
209 */
210#ifdef __ICCARM__
211typedef struct usb_config_descriptor
212{
213 __packed uint8_t bLength;
214 __packed uint8_t bDescriptorType;
215 __packed uint16_t wTotalLength;
216 __packed uint8_t bNumInterfaces;
217 __packed uint8_t bConfigurationValue;
218 __packed uint8_t iConfiguration;
219 __packed uint8_t bmAttributes;
220 __packed uint8_t MaxPower;
222#else
223typedef struct __attribute__((__packed__)) usb_config_descriptor
224{
225 uint8_t bLength;
226 uint8_t bDescriptorType;
227 uint16_t wTotalLength;
228 uint8_t bNumInterfaces;
229 uint8_t bConfigurationValue;
230 uint8_t iConfiguration;
231 uint8_t bmAttributes;
232 uint8_t MaxPower;
234#endif
235
236/*-----------------------------------------------------------------------------------
237 * USB interface descriptor
238 */
239#ifdef __ICCARM__
240typedef struct usb_interface_descriptor
241{
242 __packed uint8_t bLength;
243 __packed uint8_t bDescriptorType;
244 __packed uint8_t bInterfaceNumber;
245 __packed uint8_t bAlternateSetting;
246 __packed uint8_t bNumEndpoints;
247 __packed uint8_t bInterfaceClass;
248 __packed uint8_t bInterfaceSubClass;
249 __packed uint8_t bInterfaceProtocol;
250 __packed uint8_t iInterface;
252#else
253typedef struct __attribute__((__packed__)) usb_interface_descriptor
254{
255 uint8_t bLength;
256 uint8_t bDescriptorType;
257 uint8_t bInterfaceNumber;
258 uint8_t bAlternateSetting;
259 uint8_t bNumEndpoints;
260 uint8_t bInterfaceClass;
261 uint8_t bInterfaceSubClass;
262 uint8_t bInterfaceProtocol;
263 uint8_t iInterface;
265#endif
266
267
268/*-----------------------------------------------------------------------------------
269 * USB endpoint descriptor
270 */
271#ifdef __ICCARM__
272typedef struct usb_endpoint_descriptor
273{
274 __packed uint8_t bLength;
275 __packed uint8_t bDescriptorType;
276 __packed uint8_t bEndpointAddress;
277 __packed uint8_t bmAttributes;
278 __packed uint16_t wMaxPacketSize;
279 __packed uint8_t bInterval;
280 __packed uint8_t bRefresh;
281 __packed uint8_t bSynchAddress;
283#else
284typedef struct __attribute__((__packed__)) usb_endpoint_descriptor
285{
286 uint8_t bLength;
287 uint8_t bDescriptorType;
288 uint8_t bEndpointAddress;
289 uint8_t bmAttributes;
290 uint16_t wMaxPacketSize;
291 uint8_t bInterval;
292 uint8_t bRefresh;
293 uint8_t bSynchAddress;
295#endif
296
297
298#define MINISEC_1 84000
299#define MINISEC_10 840000
300#define MINISEC_100 8400000
301
303
304#endif /* _USBH_H_ */
void *__dso_handle __attribute__((weak))
Definition: _syscalls.c:35
USB_IF_DESC_T
Definition: usbh_core.h:335
DEV_REQ_T
Definition: usbh_core.h:190
USB_CONFIG_DESC_T
Definition: usbh_core.h:366
USB_DEV_DESC_T
Definition: usbh_core.h:270
USB_EP_DESC_T
Definition: usbh_core.h:300
return value
Definition: semihosting.h:98