contrib/firmware: add new adapter ANGIE's firmware/bitstream code
[openocd.git] / contrib / firmware / angie / c / include / usb.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /****************************************************************************
3 File : usb.h *
4 Contents : usb communication handling header file for NanoXplore *
5 USB-JTAG ANGIE adapter hardware. *
6 Based on openULINK project code by: Martin Schmoelzer. *
7 Copyright 2023, Ahmed Errached BOUDJELIDA, NanoXplore SAS. *
8 <aboudjelida@nanoxplore.com> *
9 <ahmederrachedbjld@gmail.com> *
10 *****************************************************************************/
11
12 #ifndef __USB_H
13 #define __USB_H
14
15 #include "reg_ezusb.h"
16 #include <stdint.h>
17 #include <stdbool.h>
18
19 /* High and Low byte of a word (uint16_t) */
20 #define HI8(word) (uint8_t)(((uint16_t)(word) >> 8) & 0xff)
21 #define LO8(word) (uint8_t)((uint16_t)(word) & 0xff)
22
23 /* Convenience functions */
24 #define STALL_EP0() (EP0CS |= EPSTALL)
25 #define CLEAR_IRQ() (USBINT = 0)
26
27 /*********** USB descriptors. See section 9.5 of the USB 1.1 spec **********/
28
29 /* USB Descriptor Types. See USB 1.1 spec, page 187, table 9-5 */
30 #define DESCRIPTOR_TYPE_DEVICE 0x01
31 #define DESCRIPTOR_TYPE_CONFIGURATION 0x02
32 #define DESCRIPTOR_TYPE_STRING 0x03
33 #define DESCRIPTOR_TYPE_INTERFACE 0x04
34 #define DESCRIPTOR_TYPE_ENDPOINT 0x05
35
36 #define STR_DESCR(len, ...) { (len) * 2 + 2, DESCRIPTOR_TYPE_STRING, { __VA_ARGS__ } }
37
38 /** USB Device Descriptor. See USB 1.1 spec, pp. 196 - 198 */
39 struct usb_device_descriptor {
40 uint8_t blength; /**< Size of this descriptor in bytes. */
41 uint8_t bdescriptortype; /**< DEVICE Descriptor Type. */
42 uint16_t bcdusb; /**< USB specification release number (BCD). */
43 uint8_t bdeviceclass; /**< Class code. */
44 uint8_t bdevicesubclass; /**< Subclass code. */
45 uint8_t bdeviceprotocol; /**< Protocol code. */
46 uint8_t bmaxpacketsize0; /**< Maximum packet size for EP0 (8, 16, 32, 64). */
47 uint16_t idvendor; /**< USB Vendor ID. */
48 uint16_t idproduct; /**< USB Product ID. */
49 uint16_t bcddevice; /**< Device Release Number (BCD). */
50 uint8_t imanufacturer; /**< Index of manufacturer string descriptor. */
51 uint8_t iproduct; /**< Index of product string descriptor. */
52 uint8_t iserialnumber; /**< Index of string descriptor containing serial #. */
53 uint8_t bnumconfigurations; /**< Number of possible configurations. */
54 };
55
56 /** USB Configuration Descriptor. See USB 1.1 spec, pp. 199 - 200 */
57 struct usb_config_descriptor {
58 uint8_t blength; /**< Size of this descriptor in bytes. */
59 uint8_t bdescriptortype; /**< CONFIGURATION descriptor type. */
60 uint16_t wtotallength; /**< Combined total length of all descriptors. */
61 uint8_t bnuminterfaces; /**< Number of interfaces in this configuration. */
62 uint8_t bconfigurationvalue; /**< Value used to select this configuration. */
63 uint8_t iconfiguration; /**< Index of configuration string descriptor. */
64 uint8_t bmattributes; /**< Configuration characteristics. */
65 uint8_t maxpower; /**< Maximum power consumption in 2 mA units. */
66 };
67
68 /** USB Interface Descriptor. See USB 1.1 spec, pp. 201 - 203 */
69 struct usb_interface_descriptor {
70 uint8_t blength; /**< Size of this descriptor in bytes. */
71 uint8_t bdescriptortype; /**< INTERFACE descriptor type. */
72 uint8_t binterfacenumber; /**< Interface number. */
73 uint8_t balternatesetting; /**< Value used to select alternate setting. */
74 uint8_t bnumendpoints; /**< Number of endpoints used by this interface. */
75 uint8_t binterfaceclass; /**< Class code. */
76 uint8_t binterfacesubclass; /**< Subclass code. */
77 uint8_t binterfaceprotocol; /**< Protocol code. */
78 uint8_t iinterface; /**< Index of interface string descriptor. */
79 };
80
81 /** USB Endpoint Descriptor. See USB 1.1 spec, pp. 203 - 204 */
82 struct usb_endpoint_descriptor {
83 uint8_t blength; /**< Size of this descriptor in bytes. */
84 uint8_t bdescriptortype; /**< ENDPOINT descriptor type. */
85 uint8_t bendpointaddress; /**< Endpoint Address: IN/OUT + EP number. */
86 uint8_t bmattributes; /**< Endpoint Attributes: BULK/INTR/ISO/CTRL. */
87 uint16_t wmaxpacketsize; /**< Maximum packet size for this endpoint. */
88 uint8_t binterval; /**< Polling interval (in ms) for this endpoint. */
89 };
90
91 /** USB Language Descriptor. See USB 1.1 spec, pp. 204 - 205 */
92 struct usb_language_descriptor {
93 uint8_t blength; /**< Size of this descriptor in bytes. */
94 uint8_t bdescriptortype; /**< STRING descriptor type. */
95 uint16_t wlangid[]; /**< LANGID codes. */
96 };
97
98 /** USB String Descriptor. See USB 1.1 spec, pp. 204 - 205 */
99 struct usb_string_descriptor {
100 uint8_t blength; /**< Size of this descriptor in bytes. */
101 uint8_t bdescriptortype; /**< STRING descriptor type. */
102 uint16_t bstring[]; /**< UNICODE encoded string. */
103 };
104
105 /********************** USB Control Endpoint 0 related *********************/
106
107 /** USB Control Setup Data. See USB 1.1 spec, pp. 183 - 185 */
108 struct setup_data {
109 uint8_t bmrequesttype; /**< Characteristics of a request. */
110 uint8_t brequest; /**< Specific request. */
111 uint16_t wvalue; /**< Field that varies according to request. */
112 uint16_t windex; /**< Field that varies according to request. */
113 uint16_t wlength; /**< Number of bytes to transfer in data stage. */
114 };
115
116 /* External declarations for variables that need to be accessed outside of
117 * the USB module */
118 extern volatile bool ep1_out;
119 extern volatile bool ep1_in;
120
121 extern volatile __xdata __at 0xE6B8 struct setup_data setup_data;
122
123 /*
124 * USB Request Types (bmRequestType): See USB 1.1 spec, page 183, table 9-2
125 *
126 * Bit 7: Data transfer direction
127 * 0 = Host-to-device
128 * 1 = Device-to-host
129 * Bit 6...5: Type
130 * 0 = Standard
131 * 1 = Class
132 * 2 = Vendor
133 * 3 = Reserved
134 * Bit 4...0: Recipient
135 * 0 = Device
136 * 1 = Interface
137 * 2 = Endpoint
138 * 3 = Other
139 * 4...31 = Reserved
140 */
141
142 #define USB_DIR_OUT 0x00
143 #define USB_DIR_IN 0x80
144
145 #define USB_REQ_TYPE_STANDARD (0x00 << 5)
146 #define USB_REQ_TYPE_CLASS (0x01 << 5)
147 #define USB_REQ_TYPE_VENDOR (0x02 << 5)
148 #define USB_REQ_TYPE_RESERVED (0x03 << 5)
149
150 #define USB_RECIP_DEVICE 0x00
151 #define USB_RECIP_INTERFACE 0x01
152 #define USB_RECIP_ENDPOINT 0x02
153 #define USB_RECIP_OTHER 0x03
154
155 /* Clear Interface Request */
156 #define CF_DEVICE (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_DEVICE)
157 #define CF_INTERFACE (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_INTERFACE)
158 #define CF_ENDPOINT (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_ENDPOINT)
159
160 /* Get Configuration Request */
161 #define GC_DEVICE (USB_DIR_IN | USB_REQ_TYPE_STANDARD | USB_RECIP_DEVICE)
162
163 /* Get Descriptor Request */
164 #define GD_DEVICE (USB_DIR_IN | USB_REQ_TYPE_STANDARD | USB_RECIP_DEVICE)
165
166 /* Get Interface Request */
167 #define GI_INTERFACE (USB_DIR_IN | USB_REQ_TYPE_STANDARD | USB_RECIP_INTERFACE)
168
169 /* Get Status Request: See USB 1.1 spec, page 190 */
170 #define GS_DEVICE (USB_DIR_IN | USB_REQ_TYPE_STANDARD | USB_RECIP_DEVICE)
171 #define GS_INTERFACE (USB_DIR_IN | USB_REQ_TYPE_STANDARD | USB_RECIP_INTERFACE)
172 #define GS_ENDPOINT (USB_DIR_IN | USB_REQ_TYPE_STANDARD | USB_RECIP_ENDPOINT)
173
174 /* Set Address Request is handled by EZ-USB core */
175
176 /* Set Configuration Request */
177 #define SC_DEVICE (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_DEVICE)
178
179 /* Set Descriptor Request */
180 #define SD_DEVICE (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_DEVICE)
181
182 /* Set Feature Request */
183 #define SF_DEVICE (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_DEVICE)
184 #define SF_INTERFACE (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_INTERFACE)
185 #define SF_ENDPOINT (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_ENDPOINT)
186
187 /* Set Interface Request */
188 #define SI_INTERFACE (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_INTERFACE)
189
190 /* Synch Frame Request */
191 #define SY_ENDPOINT (USB_DIR_IN | USB_REQ_TYPE_STANDARD | USB_RECIP_ENDPOINT)
192
193 /* USB Requests (bRequest): See USB 1.1 spec, table 9-4 on page 187 */
194 #define GET_STATUS 0
195 #define CLEAR_FEATURE 1
196 /* Value '2' is reserved for future use */
197 #define SET_FEATURE 3
198 /* Value '4' is reserved for future use */
199 #define SET_ADDRESS 5
200 #define GET_DESCRIPTOR 6
201 #define SET_DESCRIPTOR 7
202 #define GET_CONFIGURATION 8
203 #define SET_CONFIGURATION 9
204 #define GET_INTERFACE 10
205 #define SET_INTERFACE 11
206 #define SYNCH_FRAME 12
207
208 /* Standard Feature Selectors: See USB 1.1 spec, table 9-6 on page 188 */
209 #define DEVICE_REMOTE_WAKEUP 1
210 #define ENDPOINT_HALT 0
211
212 /************************** EZ-USB specific stuff **************************/
213 /** USB Interrupts. See AN2131-TRM, page 9-4 for details */
214 enum usb_isr {
215 SUDAV_ISR = 13,
216 SOF_ISR,
217 SUTOK_ISR,
218 SUSPEND_ISR,
219 USBRESET_ISR,
220 HIGHSPEED_ISR,
221 EP0ACK_ISR,
222 STUB_ISR,
223 EP0IN_ISR,
224 EP0OUT_ISR,
225 EP1IN_ISR,
226 EP1OUT_ISR,
227 EP2_ISR,
228 EP4_ISR,
229 EP6_ISR,
230 EP8_ISR,
231 IBN_ISR,
232 EP0PINGNAK_ISR,
233 EP1PINGNAK_ISR,
234 EP2PINGNAK_ISR,
235 EP4PINGNAK_ISR,
236 EP6PINGNAK_ISR,
237 EP8PINGNAK_ISR,
238 ERRORLIMIT_ISR,
239 EP2PIDERROR_ISR,
240 EP4PIDERROR_ISR,
241 EP6PIDERROR_ISR,
242 EP8PIDERROR_ISR,
243 EP2PFLAG_ISR,
244 EP4PFLAG_ISR,
245 EP6PFLAG_ISR,
246 EP8PFLAG_ISR,
247 EP2EFLAG_ISR,
248 EP4EFLAG_ISR,
249 EP6EFLAG_ISR,
250 EP8EFLAG_ISR,
251 EP2FFLAG_ISR,
252 EP4FFLAG_ISR,
253 EP6FFLAG_ISR,
254 EP8FFLAG_ISR,
255 GPIFCOMPLETE_ISR,
256 GPIFWAVEFORM_ISR
257 };
258
259 /*************************** Function Prototypes ***************************/
260 __xdata uint8_t *usb_get_endpoint_cs_reg(uint8_t ep);
261 void usb_reset_data_toggle(uint8_t ep);
262 bool usb_handle_get_status(void);
263 bool usb_handle_clear_feature(void);
264 bool usb_handle_set_feature(void);
265 bool usb_handle_get_descriptor(void);
266 void usb_handle_set_interface(void);
267 void usb_handle_setup_data(void);
268
269 void ep_init(void);
270 void interrupt_init(void);
271 void io_init(void);
272
273 #endif

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)