Commits

wump committed 2fb8772

provide much faster raw buffer interface

Comments (0)

Files changed (3)

 libusb based bit banging implementation
+
+   Very simple C library using the USB SX as jtag interface 
+   Bit banging is very slow through USB. To get any speed at all,
+   use jtag_inout with custom-built buffers.
 /* 
-   Very simple C library using the USB SX as jtag interface 
-   Uses only a small part of the interface, and uses bit banging only, so 
-   is pretty slow.
+C-interface to JTAG for USBee SX
+Wladimir van der Laan 2010 
 */
 #include <stdio.h>
 #include <string.h>
     return rv;
 }
 
+int jtag_close(struct usb_dev_handle *dev)
+{
+    /* TODO */
+    return 0;
+}
+
+int jtag_inout(struct usb_dev_handle *dev, const uint8_t *data_in, size_t data_in_ptr, uint8_t *data_out, size_t data_out_size)
+{
+    int i;
+    /*
+    printf("<< %i >> %i\n", data_in_ptr, data_out_size);
+    for(i=0; i<data_in_ptr; ++i)
+        printf("%08x\n", data_in[i]);
+    */
+    if(jtag_send(dev, data_in, data_in_ptr) != data_in_ptr)
+    {
+        fprintf(stderr, "Error writing to interface\n");
+        return -1;
+    }
+    if(data_out_size > 0)
+    {
+        if(jtag_recv(dev, data_out, data_out_size) != data_out_size)
+        {
+            fprintf(stderr, "Error reading from interface\n");
+            return -1;
+        }
+        for(i=0; i<data_out_size; ++i)
+            data_out[i] &= 1;
+    }
+    return 0;
+}
 struct usb_dev_handle *jtag_init(void);
 int jtag_reset_tap(struct usb_dev_handle *dev);
 int jtag_clockio(struct usb_dev_handle *dev, uint8_t data_in);
+int jtag_close(struct usb_dev_handle *dev);
 
+/**
+ * Manually built buffer API. This is much more efficient than bit-banging,
+ * but you need to be careful. See the command bits above which can be used.
+ * Make sure that data_in_ptr and data_out_size exactly match.
+ */
+int jtag_inout(struct usb_dev_handle *dev, const uint8_t *data_in, size_t data_in_ptr, uint8_t *data_out, size_t data_out_size);
 
 #endif