OpenOCD
usb.c File Reference

Defines USB descriptors, interrupt routines and helper functions. More...

Include dependency graph for usb.c:

Go to the source code of this file.

Macros

#define NUM_ENDPOINTS   2
 

Functions

void ep0in_isr (void)
 
void ep0out_isr (void)
 
void ep1in_isr (void)
 
void ep1out_isr (void)
 
void ep2in_isr (void)
 EP2 IN: called after the transfer from uC->Host has finished: we sent data. More...
 
void ep2out_isr (void)
 EP2 OUT: called after the transfer from Host->uC has finished: we got data. More...
 
void ep3in_isr (void)
 
void ep3out_isr (void)
 
void ep4in_isr (void)
 
void ep4out_isr (void)
 
void ep5in_isr (void)
 
void ep5out_isr (void)
 
void ep6in_isr (void)
 
void ep6out_isr (void)
 
void ep7in_isr (void)
 
void ep7out_isr (void)
 
void ibn_isr (void)
 
void sof_isr (void)
 
void sudav_isr (void)
 
void suspend_isr (void)
 
void sutok_isr (void)
 
__xdata uint8_t * usb_get_endpoint_cs_reg (uint8_t ep)
 Return the control/status register for an endpoint. More...
 
bool usb_handle_clear_feature (void)
 Handle CLEAR_FEATURE request. More...
 
bool usb_handle_get_descriptor (void)
 Handle GET_DESCRIPTOR request. More...
 
bool usb_handle_get_status (void)
 Handle GET_STATUS request. More...
 
bool usb_handle_set_feature (void)
 Handle SET_FEATURE request. More...
 
void usb_handle_set_interface (void)
 Handle SET_INTERFACE request. More...
 
void usb_handle_setup_data (void)
 Handle the arrival of a USB Control Setup Packet. More...
 
void usb_init (void)
 USB initialization. More...
 
void usb_reset_data_toggle (uint8_t ep)
 
void usbreset_isr (void)
 

Variables

__code struct usb_endpoint_descriptor Bulk_EP2_IN_Endpoint_Descriptor
 
__code struct usb_endpoint_descriptor Bulk_EP2_OUT_Endpoint_Descriptor
 
__code struct usb_config_descriptor config_descriptor
 
__code struct usb_device_descriptor device_descriptor
 
__code struct usb_string_descriptor *__code en_string_descriptors [4]
 
volatile bool EP2_in
 
volatile bool EP2_out
 
__code struct usb_interface_descriptor interface_descriptor00
 
__code struct usb_language_descriptor language_descriptor
 
volatile __xdata __at struct setup_data setup_data
 
__code struct usb_string_descriptor strConfigDescr
 
__code struct usb_string_descriptor strManufacturer
 
__code struct usb_string_descriptor strProduct
 
__code struct usb_string_descriptor strSerialNumber
 

Detailed Description

Defines USB descriptors, interrupt routines and helper functions.

To minimize code size, we make the following assumptions:

  • The OpenULINK has exactly one configuration
  • and exactly one alternate setting

Therefore, we do not have to support the Set Configuration USB request.

Definition in file usb.c.

Macro Definition Documentation

◆ NUM_ENDPOINTS

#define NUM_ENDPOINTS   2

Definition at line 31 of file usb.c.

Function Documentation

◆ ep0in_isr()

void ep0in_isr ( void  )

Definition at line 147 of file usb.c.

◆ ep0out_isr()

void ep0out_isr ( void  )

Definition at line 150 of file usb.c.

◆ ep1in_isr()

void ep1in_isr ( void  )

Definition at line 153 of file usb.c.

◆ ep1out_isr()

void ep1out_isr ( void  )

Definition at line 156 of file usb.c.

◆ ep2in_isr()

void ep2in_isr ( void  )

EP2 IN: called after the transfer from uC->Host has finished: we sent data.

Definition at line 163 of file usb.c.

References CLEAR_IRQ, EP2_in, and IN2IR.

◆ ep2out_isr()

void ep2out_isr ( void  )

EP2 OUT: called after the transfer from Host->uC has finished: we got data.

Definition at line 174 of file usb.c.

References CLEAR_IRQ, EP2_out, and OUT2IR.

◆ ep3in_isr()

void ep3in_isr ( void  )

Definition at line 182 of file usb.c.

◆ ep3out_isr()

void ep3out_isr ( void  )

Definition at line 185 of file usb.c.

◆ ep4in_isr()

void ep4in_isr ( void  )

Definition at line 188 of file usb.c.

◆ ep4out_isr()

void ep4out_isr ( void  )

Definition at line 191 of file usb.c.

◆ ep5in_isr()

void ep5in_isr ( void  )

Definition at line 194 of file usb.c.

◆ ep5out_isr()

void ep5out_isr ( void  )

Definition at line 197 of file usb.c.

◆ ep6in_isr()

void ep6in_isr ( void  )

Definition at line 200 of file usb.c.

◆ ep6out_isr()

void ep6out_isr ( void  )

Definition at line 203 of file usb.c.

◆ ep7in_isr()

void ep7in_isr ( void  )

Definition at line 206 of file usb.c.

◆ ep7out_isr()

void ep7out_isr ( void  )

Definition at line 209 of file usb.c.

◆ ibn_isr()

void ibn_isr ( void  )

Definition at line 143 of file usb.c.

◆ sof_isr()

void sof_isr ( void  )

Definition at line 131 of file usb.c.

◆ sudav_isr()

void sudav_isr ( void  )

Definition at line 121 of file usb.c.

References CLEAR_IRQ, HSNAK, SUDAVIR, and usb_handle_setup_data().

◆ suspend_isr()

void suspend_isr ( void  )

Definition at line 137 of file usb.c.

◆ sutok_isr()

void sutok_isr ( void  )

Definition at line 134 of file usb.c.

◆ usb_get_endpoint_cs_reg()

__xdata uint8_t* usb_get_endpoint_cs_reg ( uint8_t  ep)

Return the control/status register for an endpoint.

Parameters
ependpoint address
Returns
on success: pointer to Control & Status register for endpoint specified in ep
on failure: NULL

Definition at line 221 of file usb.c.

References NULL.

Referenced by usb_handle_clear_feature(), usb_handle_get_status(), and usb_handle_set_feature().

◆ usb_handle_clear_feature()

bool usb_handle_clear_feature ( void  )

Handle CLEAR_FEATURE request.

Returns
on success: true
on failure: false

Definition at line 334 of file usb.c.

References setup_data::bmRequestType, CF_DEVICE, CF_ENDPOINT, EPSTALL, STALL_EP0, usb_get_endpoint_cs_reg(), setup_data::wIndex, and setup_data::wValue.

Referenced by usb_handle_setup_data().

◆ usb_handle_get_descriptor()

bool usb_handle_get_descriptor ( void  )

Handle GET_DESCRIPTOR request.

Returns
on success: true
on failure: false

Definition at line 403 of file usb.c.

References config_descriptor, DESCRIPTOR_TYPE_CONFIGURATION, DESCRIPTOR_TYPE_DEVICE, DESCRIPTOR_TYPE_STRING, device_descriptor, en_string_descriptors, HI8, language_descriptor, LO8, setup_data::wIndex, and setup_data::wValue.

Referenced by usb_handle_setup_data().

◆ usb_handle_get_status()

bool usb_handle_get_status ( void  )

Handle GET_STATUS request.

Returns
on success: true
on failure: false

Definition at line 283 of file usb.c.

References setup_data::bmRequestType, EPSTALL, GS_DEVICE, GS_ENDPOINT, GS_INTERFACE, usb_get_endpoint_cs_reg(), and setup_data::wIndex.

Referenced by usb_handle_setup_data().

◆ usb_handle_set_feature()

bool usb_handle_set_feature ( void  )

Handle SET_FEATURE request.

Returns
on success: true
on failure: false

Definition at line 368 of file usb.c.

References setup_data::bmRequestType, EPSTALL, SF_DEVICE, SF_ENDPOINT, usb_get_endpoint_cs_reg(), setup_data::wIndex, and setup_data::wValue.

Referenced by usb_handle_setup_data().

◆ usb_handle_set_interface()

void usb_handle_set_interface ( void  )

Handle SET_INTERFACE request.

Definition at line 444 of file usb.c.

References EPBSY, USB_DIR_IN, USB_DIR_OUT, and usb_reset_data_toggle().

Referenced by usb_handle_setup_data().

◆ usb_handle_setup_data()

◆ usb_init()

void usb_init ( void  )

USB initialization.

Configures USB interrupts, endpoints and performs ReNumeration.

Definition at line 520 of file usb.c.

References AVEN, delay_ms(), DISCOE, DISCON, IN2IEN, IN2VAL, ISODISAB, OUT2IEN, OUT2VAL, RENUM, and SUDAVIE.

Referenced by main().

◆ usb_reset_data_toggle()

void usb_reset_data_toggle ( uint8_t  ep)

Definition at line 256 of file usb.c.

References TOG_R.

Referenced by usb_handle_set_interface().

◆ usbreset_isr()

void usbreset_isr ( void  )

Definition at line 140 of file usb.c.

Variable Documentation

◆ Bulk_EP2_IN_Endpoint_Descriptor

__code struct usb_endpoint_descriptor Bulk_EP2_IN_Endpoint_Descriptor
Initial value:
= {
.bLength = sizeof(struct usb_endpoint_descriptor),
.bDescriptorType = 0x05,
.bEndpointAddress = (2 | USB_DIR_IN),
.bmAttributes = 0x02,
.bInterval = 0
}
USB Endpoint Descriptor.
Definition: usb.h:81
uint16_t wMaxPacketSize
Maximum packet size for this endpoint.
Definition: usb.h:86
uint8_t bInterval
Polling interval (in ms) for this endpoint.
Definition: usb.h:87
uint8_t bmAttributes
Endpoint Attributes: USB 1.1 spec, table 9-10.
Definition: usb.h:85
uint8_t bDescriptorType
ENDPOINT descriptor type.
Definition: usb.h:83
#define USB_DIR_IN
Definition: usb.h:141

Definition at line 77 of file usb.c.

◆ Bulk_EP2_OUT_Endpoint_Descriptor

__code struct usb_endpoint_descriptor Bulk_EP2_OUT_Endpoint_Descriptor
Initial value:
= {
.bLength = sizeof(struct usb_endpoint_descriptor),
.bDescriptorType = 0x05,
.bEndpointAddress = (2 | USB_DIR_OUT),
.bmAttributes = 0x02,
.bInterval = 0
}
#define USB_DIR_OUT
Definition: usb.h:140

Definition at line 86 of file usb.c.

◆ config_descriptor

__code struct usb_config_descriptor config_descriptor
Initial value:
= {
.bLength = sizeof(struct usb_config_descriptor),
.wTotalLength = sizeof(struct usb_config_descriptor) +
sizeof(struct usb_interface_descriptor) +
.bNumInterfaces = 1,
.bConfigurationValue = 1,
.iConfiguration = 4,
.bmAttributes = 0x80,
.MaxPower = 50
}
USB Configuration Descriptor.
Definition: usb.h:56
uint8_t bDescriptorType
CONFIGURATION descriptor type.
Definition: usb.h:58
USB Interface Descriptor.
Definition: usb.h:68
#define NUM_ENDPOINTS
Definition: usb.c:31
#define DESCRIPTOR_TYPE_CONFIGURATION
Definition: usb.h:30

Definition at line 52 of file usb.c.

Referenced by usb_handle_get_descriptor(), and usb_handle_setup_data().

◆ device_descriptor

__code struct usb_device_descriptor device_descriptor
Initial value:
= {
.bLength = sizeof(struct usb_device_descriptor),
.bcdUSB = 0x0110,
.bDeviceClass = 0xFF,
.bDeviceSubClass = 0xFF,
.bDeviceProtocol = 0xFF,
.bMaxPacketSize0 = 64,
.idVendor = 0xC251,
.idProduct = 0x2710,
.bcdDevice = 0x0100,
.iManufacturer = 1,
.iProduct = 2,
.iSerialNumber = 3,
.bNumConfigurations = 1
}
USB Device Descriptor.
Definition: usb.h:38
uint8_t bDescriptorType
DEVICE Descriptor Type.
Definition: usb.h:40
#define DESCRIPTOR_TYPE_DEVICE
Definition: usb.h:29

Definition at line 33 of file usb.c.

Referenced by usb_handle_get_descriptor().

◆ en_string_descriptors

__code struct usb_string_descriptor* __code en_string_descriptors[4]
Initial value:
= {
}
__code struct usb_string_descriptor strProduct
Definition: usb.c:104
__code struct usb_string_descriptor strManufacturer
Definition: usb.c:101
__code struct usb_string_descriptor strConfigDescr
Definition: usb.c:110
__code struct usb_string_descriptor strSerialNumber
Definition: usb.c:107

Definition at line 114 of file usb.c.

Referenced by usb_handle_get_descriptor().

◆ EP2_in

volatile bool EP2_in

Definition at line 25 of file usb.c.

Referenced by command_loop(), and ep2in_isr().

◆ EP2_out

volatile bool EP2_out

Definition at line 24 of file usb.c.

Referenced by command_loop(), and ep2out_isr().

◆ interface_descriptor00

__code struct usb_interface_descriptor interface_descriptor00
Initial value:
= {
.bLength = sizeof(struct usb_interface_descriptor),
.bInterfaceNumber = 0,
.bAlternateSetting = 0,
.bNumEndpoints = NUM_ENDPOINTS,
.bInterfaceClass = 0xFF,
.bInterfaceSubclass = 0xFF,
.bInterfaceProtocol = 0xFF,
.iInterface = 0
}
uint8_t bDescriptorType
INTERFACE descriptor type.
Definition: usb.h:70
#define DESCRIPTOR_TYPE_INTERFACE
Definition: usb.h:32

Definition at line 65 of file usb.c.

Referenced by usb_handle_setup_data().

◆ language_descriptor

__code struct usb_language_descriptor language_descriptor
Initial value:
= {
.bLength = 4,
.bDescriptorType = DESCRIPTOR_TYPE_STRING,
.wLANGID = {0x0409 }
}
#define DESCRIPTOR_TYPE_STRING
Definition: usb.h:31

Definition at line 95 of file usb.c.

Referenced by usb_handle_get_descriptor().

◆ setup_data

volatile __xdata __at struct setup_data setup_data

Definition at line 27 of file usb.c.

◆ strConfigDescr

__code struct usb_string_descriptor strConfigDescr
Initial value:
=
STR_DESCR(12, 'J', 'T', 'A', 'G', ' ', 'A', 'd', 'a', 'p', 't', 'e', 'r')
#define STR_DESCR(len,...)
Definition: usb.h:35

Definition at line 110 of file usb.c.

◆ strManufacturer

__code struct usb_string_descriptor strManufacturer
Initial value:
=
STR_DESCR(9, 'O', 'p', 'e', 'n', 'U', 'L', 'I', 'N', 'K')

Definition at line 101 of file usb.c.

◆ strProduct

__code struct usb_string_descriptor strProduct
Initial value:
=
STR_DESCR(9, 'O', 'p', 'e', 'n', 'U', 'L', 'I', 'N', 'K')

Definition at line 104 of file usb.c.

◆ strSerialNumber

__code struct usb_string_descriptor strSerialNumber
Initial value:
=
STR_DESCR(6, '0', '0', '0', '0', '0', '1')

Definition at line 107 of file usb.c.