]> git.sur5r.net Git - openocd/commitdiff
libusb: Add transfer type filter to get correct ep
authorHellosun Wu <wujiheng.tw@gmail.com>
Tue, 26 Jan 2016 05:36:49 +0000 (13:36 +0800)
committerFreddie Chopin <freddie.chopin@gmail.com>
Mon, 24 Apr 2017 21:31:41 +0000 (22:31 +0100)
The need for this due to AICE having 3 interfaces
(EP1 IN-Interrupt, EP2 OUT-Bulk, EP6 IN-Bulk).
Without it, the function will choose first two endpoint as
read_ep/write_ep. This filter will check transfer types
when get endpoint-id. Without this patch, AICE will not
get correct endpoint.

Change-Id: I4da93c7de41cd19e5095b4bfb42078b21f40b678
Signed-off-by: Hellosun Wu <wujiheng.tw@gmail.com>
Reviewed-on: http://openocd.zylin.com/3218
Tested-by: jenkins
Reviewed-by: Hsiangkai Wang <hsiangkai@gmail.com>
Reviewed-by: Freddie Chopin <freddie.chopin@gmail.com>
src/jtag/aice/aice_usb.c
src/jtag/drivers/libusb0_common.c
src/jtag/drivers/libusb0_common.h
src/jtag/drivers/libusb1_common.c
src/jtag/drivers/libusb1_common.h
src/jtag/drivers/openjtag.c

index b36e3900cb7fe77a14c7c1e2301b153ea6f8fa7b..50468f375aea977003abe6dca26a4d009d77035f 100644 (file)
@@ -2135,10 +2135,16 @@ static int aice_usb_open(struct aice_port_param_s *param)
 
        /* usb_set_configuration required under win32 */
        jtag_libusb_set_configuration(devh, 0);
+       jtag_libusb_claim_interface(devh, 0);
 
        unsigned int aice_read_ep;
        unsigned int aice_write_ep;
-       jtag_libusb_choose_interface(devh, &aice_read_ep, &aice_write_ep, -1, -1, -1);
+#ifdef HAVE_LIBUSB1
+       jtag_libusb_choose_interface(devh, &aice_read_ep, &aice_write_ep, -1, -1, -1, LIBUSB_TRANSFER_TYPE_BULK);
+#else
+       jtag_libusb_choose_interface(devh, &aice_read_ep, &aice_write_ep, -1, -1, -1, USB_ENDPOINT_TYPE_BULK);
+#endif
+       LOG_DEBUG("aice_read_ep=0x%x, aice_write_ep=0x%x", aice_read_ep, aice_write_ep);
 
        aice_handler.usb_read_ep = aice_read_ep;
        aice_handler.usb_write_ep = aice_write_ep;
index e319751a34a3ed9790ddefd12002e619e9023710..1825543e2b7dda5a5d9cc8dca8358cc4509b4479 100644 (file)
@@ -146,7 +146,7 @@ int jtag_libusb_set_configuration(jtag_libusb_device_handle *devh,
 int jtag_libusb_choose_interface(struct jtag_libusb_device_handle *devh,
                unsigned int *usb_read_ep,
                unsigned int *usb_write_ep,
-               int bclass, int subclass, int protocol)
+               int bclass, int subclass, int protocol, int trans_type)
 {
        struct jtag_libusb_device *udev = jtag_libusb_get_device(devh);
        struct usb_interface *iface = udev->config->interface;
@@ -157,7 +157,8 @@ int jtag_libusb_choose_interface(struct jtag_libusb_device_handle *devh,
        for (int i = 0; i < desc->bNumEndpoints; i++) {
                if ((bclass > 0 && desc->bInterfaceClass != bclass) ||
                    (subclass > 0 && desc->bInterfaceSubClass != subclass) ||
-                   (protocol > 0 && desc->bInterfaceProtocol != protocol))
+                   (protocol > 0 && desc->bInterfaceProtocol != protocol) ||
+                   (trans_type > 0 && (desc->endpoint[i].bmAttributes & 0x3) != trans_type))
                        continue;
 
                uint8_t epnum = desc->endpoint[i].bEndpointAddress;
index 7163b4314a16e7e92c051d77643b5e0344e573a8..baa9e3c5a91e3e103be127451e1a418ee7157160 100644 (file)
@@ -67,7 +67,7 @@ int jtag_libusb_set_configuration(jtag_libusb_device_handle *devh,
 int jtag_libusb_choose_interface(struct jtag_libusb_device_handle *devh,
                unsigned int *usb_read_ep,
                unsigned int *usb_write_ep,
-               int bclass, int subclass, int protocol);
+               int bclass, int subclass, int protocol, int trans_type);
 int jtag_libusb_get_pid(struct jtag_libusb_device *dev, uint16_t *pid);
 
 #endif /* OPENOCD_JTAG_DRIVERS_LIBUSB0_COMMON_H */
index f8b7c754c0eabd1f9f33fb801df1ff0651e56e3f..89f8092719241e780465c90702a9b20aca5a676b 100644 (file)
@@ -187,7 +187,7 @@ int jtag_libusb_set_configuration(jtag_libusb_device_handle *devh,
 int jtag_libusb_choose_interface(struct jtag_libusb_device_handle *devh,
                unsigned int *usb_read_ep,
                unsigned int *usb_write_ep,
-               int bclass, int subclass, int protocol)
+               int bclass, int subclass, int protocol, int trans_type)
 {
        struct jtag_libusb_device *udev = jtag_libusb_get_device(devh);
        const struct libusb_interface *inter;
@@ -210,6 +210,8 @@ int jtag_libusb_choose_interface(struct jtag_libusb_device_handle *devh,
                                continue;
 
                        epdesc = &interdesc->endpoint[k];
+                       if (trans_type > 0 && (epdesc->bmAttributes & 0x3) != trans_type)
+                               continue;
 
                        uint8_t epnum = epdesc->bEndpointAddress;
                        bool is_input = epnum & 0x80;
index fc6526a3091454eae66a2490797ed12ec6d9cba8..7c73d29a417309af2deb7ef7fe561e7ee28a1c23 100644 (file)
@@ -69,12 +69,13 @@ int jtag_libusb_set_configuration(jtag_libusb_device_handle *devh,
  * @param bclass `bInterfaceClass` to match, or -1 to ignore this field.
  * @param subclass `bInterfaceSubClass` to match, or -1 to ignore this field.
  * @param protocol `bInterfaceProtocol` to match, or -1 to ignore this field.
+ * @param trans_type `bmAttributes Bits 0..1 Transfer type` to match, or -1 to ignore this field.
  * @returns Returns ERROR_OK on success, ERROR_FAIL otherwise.
  */
 int jtag_libusb_choose_interface(struct jtag_libusb_device_handle *devh,
                unsigned int *usb_read_ep,
                unsigned int *usb_write_ep,
-               int bclass, int subclass, int protocol);
+               int bclass, int subclass, int protocol, int trans_type);
 int jtag_libusb_get_pid(struct jtag_libusb_device *dev, uint16_t *pid);
 
 #endif /* OPENOCD_JTAG_DRIVERS_LIBUSB1_COMMON_H */
index bb0ff74db77ce27c4ebecd2d5aab652b51307bfd..8f11b4ba1e02fb243cd2b0857953d9b61de83fe1 100644 (file)
@@ -459,7 +459,7 @@ static int openjtag_init_cy7c65215(void)
 
        ret = jtag_libusb_choose_interface(usbh, &ep_in, &ep_out,
                                                                           CY7C65215_JTAG_CLASS,
-                                                                          CY7C65215_JTAG_SUBCLASS, -1);
+                                                                          CY7C65215_JTAG_SUBCLASS, -1, LIBUSB_TRANSFER_TYPE_BULK);
        if (ret != ERROR_OK) {
                LOG_ERROR("unable to claim JTAG interface");
                goto err;