OpenOCD
libusb_helper.h File Reference
Include dependency graph for libusb_helper.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define LIBUSB_TIMEOUT_MS   (6000)
 

Typedefs

typedef char *(* adapter_get_alternate_serial_fn) (struct libusb_device_handle *device, struct libusb_device_descriptor *dev_desc)
 

Functions

int jtag_libusb_bulk_read (struct libusb_device_handle *dev, int ep, char *bytes, int size, int timeout, int *transferred)
 
int jtag_libusb_bulk_write (struct libusb_device_handle *dev, int ep, char *bytes, int size, int timeout, int *transferred)
 
int jtag_libusb_choose_interface (struct libusb_device_handle *devh, unsigned int *usb_read_ep, unsigned int *usb_write_ep, int bclass, int subclass, int protocol, int trans_type)
 Find the first interface optionally matching class, subclass and protocol and claim it. More...
 
void jtag_libusb_close (struct libusb_device_handle *dev)
 
int jtag_libusb_control_transfer (struct libusb_device_handle *dev, uint8_t request_type, uint8_t request, uint16_t value, uint16_t index, char *bytes, uint16_t size, unsigned int timeout, int *transferred)
 
int jtag_libusb_get_pid (struct libusb_device *dev, uint16_t *pid)
 
int jtag_libusb_handle_events_completed (int *completed)
 
bool jtag_libusb_match_ids (struct libusb_device_descriptor *dev_desc, const uint16_t vids[], const uint16_t pids[])
 
int jtag_libusb_open (const uint16_t vids[], const uint16_t pids[], const char *product, struct libusb_device_handle **out, adapter_get_alternate_serial_fn adapter_get_alternate_serial)
 
int jtag_libusb_set_configuration (struct libusb_device_handle *devh, int configuration)
 
uint8_t * oocd_libusb_dev_mem_alloc (libusb_device_handle *devh, size_t length)
 Attempts to allocate a block of persistent DMA memory suitable for transfers against the USB device. More...
 
int oocd_libusb_dev_mem_free (libusb_device_handle *devh, uint8_t *buffer, size_t length)
 Free device memory allocated with oocd_libusb_dev_mem_alloc(). More...
 

Macro Definition Documentation

◆ LIBUSB_TIMEOUT_MS

#define LIBUSB_TIMEOUT_MS   (6000)

Definition at line 26 of file libusb_helper.h.

Typedef Documentation

◆ adapter_get_alternate_serial_fn

typedef char*(* adapter_get_alternate_serial_fn) (struct libusb_device_handle *device, struct libusb_device_descriptor *dev_desc)

Definition at line 30 of file libusb_helper.h.

Function Documentation

◆ jtag_libusb_bulk_read()

◆ jtag_libusb_bulk_write()

◆ jtag_libusb_choose_interface()

int jtag_libusb_choose_interface ( struct libusb_device_handle *  devh,
unsigned int *  usb_read_ep,
unsigned int *  usb_write_ep,
int  bclass,
int  subclass,
int  protocol,
int  trans_type 
)

Find the first interface optionally matching class, subclass and protocol and claim it.

Parameters
devhlibusb device handle.
usb_read_epA pointer to a variable where the IN endpoint number will be stored.
usb_write_epA pointer to a variable where the OUT endpoint number will be stored.
bclassbInterfaceClass to match, or -1 to ignore this field.
subclassbInterfaceSubClass to match, or -1 to ignore this field.
protocolbInterfaceProtocol to match, or -1 to ignore this field.
trans_typebmAttributes Bits 0..1 Transfer type to match, or -1 to ignore this field.
Returns
Returns ERROR_OK on success, ERROR_FAIL otherwise.

Definition at line 311 of file libusb_helper.c.

References config, devh, ERROR_FAIL, ERROR_OK, and LOG_DEBUG.

Referenced by angie_init(), esp_usb_jtag_init(), openjtag_init_cy7c65215(), and ulink_init().

◆ jtag_libusb_close()

◆ jtag_libusb_control_transfer()

◆ jtag_libusb_get_pid()

int jtag_libusb_get_pid ( struct libusb_device *  dev,
uint16_t *  pid 
)

Definition at line 363 of file libusb_helper.c.

References ERROR_FAIL, and ERROR_OK.

Referenced by stlink_usb_usb_open().

◆ jtag_libusb_handle_events_completed()

int jtag_libusb_handle_events_completed ( int *  completed)

Definition at line 376 of file libusb_helper.c.

References jtag_libusb_context.

◆ jtag_libusb_match_ids()

bool jtag_libusb_match_ids ( struct libusb_device_descriptor *  dev_desc,
const uint16_t  vids[],
const uint16_t  pids[] 
)

Definition at line 53 of file libusb_helper.c.

Referenced by jtag_libusb_open(), and open_matching_device().

◆ jtag_libusb_open()

◆ jtag_libusb_set_configuration()

int jtag_libusb_set_configuration ( struct libusb_device_handle *  devh,
int  configuration 
)

Definition at line 283 of file libusb_helper.c.

References config, devh, and NULL.

Referenced by esp_usb_jtag_init(), opendous_usb_open(), and stlink_usb_usb_open().

◆ oocd_libusb_dev_mem_alloc()

uint8_t* oocd_libusb_dev_mem_alloc ( libusb_device_handle *  devh,
size_t  length 
)

Attempts to allocate a block of persistent DMA memory suitable for transfers against the USB device.

Fall-back to the ordinary heap malloc() if the first libusb_dev_mem_alloc() call fails.

Parameters
devhlibusb device handle.
lengthsize of desired data buffer
Returns
a pointer to the newly allocated memory, or NULL on failure

Definition at line 401 of file libusb_helper.c.

References buffer, dev_mem_allocation, DEV_MEM_AVAILABLE, DEV_MEM_FALLBACK_MALLOC, DEV_MEM_NOT_YET_DECIDED, devh, length, libusb_dev_mem_alloc(), and NULL.

Referenced by cmsis_dap_usb_alloc().

◆ oocd_libusb_dev_mem_free()

int oocd_libusb_dev_mem_free ( libusb_device_handle *  devh,
uint8_t *  buffer,
size_t  length 
)

Free device memory allocated with oocd_libusb_dev_mem_alloc().

Uses either libusb_dev_mem_free() or free() consistently with the used method of allocation.

Parameters
devhlibusb device handle.
bufferpointer to the previously allocated memory
lengthsize of desired data buffer
Returns
Returns ERROR_OK on success, ERROR_FAIL otherwise.

Definition at line 417 of file libusb_helper.c.

References buffer, dev_mem_allocation, DEV_MEM_AVAILABLE, DEV_MEM_FALLBACK_MALLOC, DEV_MEM_NOT_YET_DECIDED, devh, ERROR_FAIL, ERROR_OK, jtag_libusb_error(), length, and libusb_dev_mem_free().

Referenced by cmsis_dap_usb_free().