1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /****************************************************************************
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 *****************************************************************************/
15 #include "reg_ezusb.h"
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)
23 /* Convenience functions */
24 #define STALL_EP0() (EP0CS |= EPSTALL)
25 #define CLEAR_IRQ() (USBINT = 0)
27 /*********** USB descriptors. See USB 2.0 Spec **********/
29 /* USB Descriptor Types. See USB 2.0 Spec */
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 #define DESCRIPTOR_TYPE_INTERFACE_ASSOCIATION 0x0B
37 #define STR_DESCR(len, ...) { (len) * 2 + 2, DESCRIPTOR_TYPE_STRING, { __VA_ARGS__ } }
39 /** USB Device Descriptor. See USB 2.0 Spec */
40 struct usb_device_descriptor
{
41 uint8_t blength
; /**< Size of this descriptor in bytes. */
42 uint8_t bdescriptortype
; /**< DEVICE Descriptor Type. */
43 uint16_t bcdusb
; /**< USB specification release number (BCD). */
44 uint8_t bdeviceclass
; /**< Class code. */
45 uint8_t bdevicesubclass
; /**< Subclass code. */
46 uint8_t bdeviceprotocol
; /**< Protocol code. */
47 uint8_t bmaxpacketsize0
; /**< Maximum packet size for EP0 (8, 16, 32, 64). */
48 uint16_t idvendor
; /**< USB Vendor ID. */
49 uint16_t idproduct
; /**< USB Product ID. */
50 uint16_t bcddevice
; /**< Device Release Number (BCD). */
51 uint8_t imanufacturer
; /**< Index of manufacturer string descriptor. */
52 uint8_t iproduct
; /**< Index of product string descriptor. */
53 uint8_t iserialnumber
; /**< Index of string descriptor containing serial #. */
54 uint8_t bnumconfigurations
; /**< Number of possible configurations. */
57 /** USB Configuration Descriptor. See USB 2.0 Spec */
58 struct usb_config_descriptor
{
59 uint8_t blength
; /**< Size of this descriptor in bytes. */
60 uint8_t bdescriptortype
; /**< CONFIGURATION descriptor type. */
61 uint16_t wtotallength
; /**< Combined total length of all descriptors. */
62 uint8_t bnuminterfaces
; /**< Number of interfaces in this configuration. */
63 uint8_t bconfigurationvalue
; /**< Value used to select this configuration. */
64 uint8_t iconfiguration
; /**< Index of configuration string descriptor. */
65 uint8_t bmattributes
; /**< Configuration characteristics. */
66 uint8_t maxpower
; /**< Maximum power consumption in 2 mA units. */
69 /** USB Interface association Descriptor. See USB 2.0 Spec */
70 struct usb_interface_association_descriptor
{
72 uint8_t bdescriptortype
;
73 uint8_t bfirstinterface
;
74 uint8_t binterfacecount
;
75 uint8_t bfunctionclass
;
76 uint8_t bfunctionsubclass
;
77 uint8_t bfunctionprotocol
;
81 /** USB Interface Descriptor. See USB 2.0 Spec */
82 struct usb_interface_descriptor
{
83 uint8_t blength
; /**< Size of this descriptor in bytes. */
84 uint8_t bdescriptortype
; /**< INTERFACE descriptor type. */
85 uint8_t binterfacenumber
; /**< Interface number. */
86 uint8_t balternatesetting
; /**< Value used to select alternate setting. */
87 uint8_t bnumendpoints
; /**< Number of endpoints used by this interface. */
88 uint8_t binterfaceclass
; /**< Class code. */
89 uint8_t binterfacesubclass
; /**< Subclass code. */
90 uint8_t binterfaceprotocol
; /**< Protocol code. */
91 uint8_t iinterface
; /**< Index of interface string descriptor. */
94 /** USB Endpoint Descriptor. See USB 2.0 Spec */
95 struct usb_endpoint_descriptor
{
96 uint8_t blength
; /**< Size of this descriptor in bytes. */
97 uint8_t bdescriptortype
; /**< ENDPOINT descriptor type. */
98 uint8_t bendpointaddress
; /**< Endpoint Address: IN/OUT + EP number. */
99 uint8_t bmattributes
; /**< Endpoint Attributes: BULK/INTR/ISO/CTRL. */
100 uint16_t wmaxpacketsize
; /**< Maximum packet size for this endpoint. */
101 uint8_t binterval
; /**< Polling interval (in ms) for this endpoint. */
104 /** USB Language Descriptor. See USB 2.0 Spec */
105 struct usb_language_descriptor
{
106 uint8_t blength
; /**< Size of this descriptor in bytes. */
107 uint8_t bdescriptortype
; /**< STRING descriptor type. */
108 uint16_t wlangid
[]; /**< LANGID codes. */
111 /** USB String Descriptor. See USB 2.0 Spec */
112 struct usb_string_descriptor
{
113 uint8_t blength
; /**< Size of this descriptor in bytes. */
114 uint8_t bdescriptortype
; /**< STRING descriptor type. */
115 uint16_t bstring
[]; /**< UNICODE encoded string. */
118 /********************** USB Control Endpoint 0 related *********************/
120 /** USB Control Setup Data. See USB 2.0 Spec */
122 uint8_t bmrequesttype
; /**< Characteristics of a request. */
123 uint8_t brequest
; /**< Specific request. */
124 uint16_t wvalue
; /**< Field that varies according to request. */
125 uint16_t windex
; /**< Field that varies according to request. */
126 uint16_t wlength
; /**< Number of bytes to transfer in data stage. */
129 /* External declarations for variables that need to be accessed outside of
131 extern volatile bool ep1_out
;
132 extern volatile bool ep1_in
;
134 extern volatile __xdata __at
0xE6B8 struct setup_data setup_data
;
137 * USB Request Types (bmRequestType): See USB 2.0 Spec
139 * Bit 7: Data transfer direction
147 * Bit 4...0: Recipient
155 #define USB_DIR_OUT 0x00
156 #define USB_DIR_IN 0x80
158 #define USB_REQ_TYPE_STANDARD (0x00 << 5)
159 #define USB_REQ_TYPE_CLASS (0x01 << 5)
160 #define USB_REQ_TYPE_VENDOR (0x02 << 5)
161 #define USB_REQ_TYPE_RESERVED (0x03 << 5)
163 #define USB_RECIP_DEVICE 0x00
164 #define USB_RECIP_INTERFACE 0x01
165 #define USB_RECIP_ENDPOINT 0x02
166 #define USB_RECIP_OTHER 0x03
168 /* Clear Interface Request */
169 #define CF_DEVICE (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_DEVICE)
170 #define CF_INTERFACE (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_INTERFACE)
171 #define CF_ENDPOINT (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_ENDPOINT)
173 /* Get Configuration Request */
174 #define GC_DEVICE (USB_DIR_IN | USB_REQ_TYPE_STANDARD | USB_RECIP_DEVICE)
176 /* Get Descriptor Request */
177 #define GD_DEVICE (USB_DIR_IN | USB_REQ_TYPE_STANDARD | USB_RECIP_DEVICE)
179 /* Get Interface Request */
180 #define GI_INTERFACE (USB_DIR_IN | USB_REQ_TYPE_STANDARD | USB_RECIP_INTERFACE)
182 /* Get Status Request: See USB 1.1 spec, page 190 */
183 #define GS_DEVICE (USB_DIR_IN | USB_REQ_TYPE_STANDARD | USB_RECIP_DEVICE)
184 #define GS_INTERFACE (USB_DIR_IN | USB_REQ_TYPE_STANDARD | USB_RECIP_INTERFACE)
185 #define GS_ENDPOINT (USB_DIR_IN | USB_REQ_TYPE_STANDARD | USB_RECIP_ENDPOINT)
187 /* Set Address Request is handled by EZ-USB core */
189 /* Set Configuration Request */
190 #define SC_DEVICE (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_DEVICE)
192 /* Set Descriptor Request */
193 #define SD_DEVICE (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_DEVICE)
195 /* Set Feature Request */
196 #define SF_DEVICE (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_DEVICE)
197 #define SF_INTERFACE (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_INTERFACE)
198 #define SF_ENDPOINT (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_ENDPOINT)
200 /* Set Interface Request */
201 #define SI_INTERFACE (USB_DIR_OUT | USB_REQ_TYPE_STANDARD | USB_RECIP_INTERFACE)
203 /* Synch Frame Request */
204 #define SY_ENDPOINT (USB_DIR_IN | USB_REQ_TYPE_STANDARD | USB_RECIP_ENDPOINT)
206 /* USB Requests (bRequest): See USB 2.0 Spec */
208 #define CLEAR_FEATURE 1
209 /* Value '2' is reserved for future use */
210 #define SET_FEATURE 3
211 /* Value '4' is reserved for future use */
212 #define SET_ADDRESS 5
213 #define GET_DESCRIPTOR 6
214 #define SET_DESCRIPTOR 7
215 #define GET_CONFIGURATION 8
216 #define SET_CONFIGURATION 9
217 #define GET_INTERFACE 10
218 #define SET_INTERFACE 11
219 #define SYNCH_FRAME 12
221 /* Standard Feature Selectors: See USB 2.0 Spec */
222 #define DEVICE_REMOTE_WAKEUP 1
223 #define ENDPOINT_HALT 0
225 /************************** EZ-USB specific stuff **************************/
226 /** USB Interrupts. See EZ-USB FX2-TRM, for details */
272 /*************************** Function Prototypes ***************************/
273 __xdata
uint8_t *usb_get_endpoint_cs_reg(uint8_t ep
);
274 void usb_reset_data_toggle(uint8_t ep
);
275 bool usb_handle_get_status(void);
276 bool usb_handle_clear_feature(void);
277 bool usb_handle_set_feature(void);
278 bool usb_handle_get_descriptor(void);
279 void usb_handle_set_interface(void);
280 void usb_handle_setup_data(void);
281 void usb_handle_i2c_in(void);
282 void usb_handle_i2c_out(void);
284 void i2c_recieve(void);
286 void interrupt_init(void);
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)