rlink: remove redundant text from log messages
[openocd.git] / src / jtag / drivers / usb_blaster.c
index 59c5715bdf401ee281ff01deaba0bfaaa9a768d0..382240f52114f53539b929be05f7fbda1b7fc8ec 100644 (file)
@@ -4,6 +4,10 @@
  *     (http://www.ixo.de/info/usb_jtag/).                                 *
  *   Some updates by Anthony Liu (2006).                                   *
  *   Minor updates and cleanup by Catalin Patulea (2009).                  *
+ *   Speed updates by Ali Lown (2011).                                     *
+ *                                                                         *
+ *   Copyright (C) 2011 Ali Lown                                           *
+ *   ali@lown.me.uk                                                        *
  *                                                                         *
  *   Copyright (C) 2009 Catalin Patulea                                    *
  *   cat@vv.carleton.ca                                                    *
@@ -104,8 +108,12 @@ static char *usb_blaster_device_desc;
 static uint16_t usb_blaster_vid = 0x09fb; /* Altera */
 static uint16_t usb_blaster_pid = 0x6001; /* USB-Blaster */
 
-/* last output byte in simple bit banging mode */
+/* last output byte in simple bit banging (legacy) mode */
 static uint8_t out_value;
+/* global output buffer for bit banging */
+#define BUF_LEN 64 //Size of EP1
+static uint8_t out_buffer[BUF_LEN];
+static uint16_t out_count = 0;
 
 #if BUILD_USB_BLASTER_FTD2XX == 1
 static FT_HANDLE ftdih;
@@ -121,13 +129,13 @@ static int usb_blaster_buf_write(
        DWORD dw_bytes_written;
 
 #ifdef _DEBUG_JTAG_IO_
-       LOG_DEBUG("usb_blaster_buf_write %02X (%d)\n", buf[0], size);
+       LOG_DEBUG("usb_blaster_buf_write %02X (%d)", buf[0], size);
 #endif
        status = FT_Write(ftdih, buf, size, &dw_bytes_written);
        if (status != FT_OK)
        {
                *bytes_written = dw_bytes_written;
-               LOG_ERROR("FT_Write returned: %lu", status);
+               LOG_ERROR("FT_Write returned: %" PRIu32, status);
                return ERROR_JTAG_DEVICE_ERROR;
        }
        *bytes_written = dw_bytes_written;
@@ -135,7 +143,7 @@ static int usb_blaster_buf_write(
 #elif BUILD_USB_BLASTER_LIBFTDI == 1
        int retval;
 #ifdef _DEBUG_JTAG_IO_
-       LOG_DEBUG("usb_blaster_buf_write %02X (%d)\n", buf[0], size);
+       LOG_DEBUG("usb_blaster_buf_write %02X (%d)", buf[0], size);
 #endif
        retval = ftdi_write_data(&ftdic, buf, size);
        if (retval < 0)
@@ -160,11 +168,11 @@ usb_blaster_buf_read(uint8_t *buf, unsigned size, uint32_t *bytes_read)
        if (status != FT_OK)
        {
                *bytes_read = dw_bytes_read;
-               LOG_ERROR("FT_Read returned: %lu", status);
+               LOG_ERROR("FT_Read returned: %" PRIu32, status);
                return ERROR_JTAG_DEVICE_ERROR;
        }
 #ifdef _DEBUG_JTAG_IO_
-       LOG_DEBUG("usb_blaster_buf_read %02X (%lu)\n", buf[0], dw_bytes_read);
+       LOG_DEBUG("usb_blaster_buf_read %02X (%" PRIu32 ")", buf[0], dw_bytes_read);
 #endif
        *bytes_read = dw_bytes_read;
        return ERROR_OK;
@@ -188,15 +196,14 @@ usb_blaster_buf_read(uint8_t *buf, unsigned size, uint32_t *bytes_read)
                *bytes_read += retval;
        }
 #ifdef _DEBUG_JTAG_IO_
-       LOG_DEBUG("usb_blaster_buf_read %02X (%d)\n", buf[0], *bytes_read);
+       LOG_DEBUG("usb_blaster_buf_read %02X (%d)", buf[0], *bytes_read);
 #endif
        return ERROR_OK;
 #endif
 }
 
 /* The following code doesn't fully utilize the possibilities of the
- * USB-Blaster. It writes one byte per JTAG pin state change at a time; it
- * doesn't even try to buffer data up to the maximum packet size of 64 bytes.
+ * USB-Blaster. It only buffers data up to the maximum packet size of 64 bytes.
  *
  * Actually, the USB-Blaster offers a byte-shift mode to transmit up to 504 data
  * bits (bidirectional) in a single USB packet. A header byte has to be sent as
@@ -225,8 +232,8 @@ usb_blaster_buf_read(uint8_t *buf, unsigned size, uint32_t *bytes_read)
  *   Bit 0 (0x01): TCK Output.
  *
  * For transmitting a single data bit, you need to write two bytes. Up to 64
- * bytes can be combined in a single USB packet (but this is not done in the
- * code below). It isn't possible to read a data without transmitting data.
+ * bytes can be combined in a single USB packet.
+ * It isn't possible to read a data without transmitting data.
  */
 
 #define TCK                    (1 << 0)
@@ -241,10 +248,22 @@ usb_blaster_buf_read(uint8_t *buf, unsigned size, uint32_t *bytes_read)
 
 #define READ_TDO       (1 << 0)
 
-static void usb_blaster_write_data(void)
+static void usb_blaster_write_databuffer(uint8_t* buf, uint16_t len)
 {
        uint32_t bytes_written;
-       usb_blaster_buf_write(&out_value, 1, &bytes_written);
+       usb_blaster_buf_write(buf, len, &bytes_written);
+       out_count = 0;
+#ifdef _DEBUG_JTAG_IO_
+       LOG_DEBUG("---- WROTE %d",bytes_written);
+#endif
+}
+
+static void usb_blaster_addtowritebuffer(uint8_t value, bool forcewrite)
+{
+       out_buffer[out_count] = value;
+       out_count += 1;
+       if(out_count == BUF_LEN || forcewrite)
+               usb_blaster_write_databuffer(out_buffer, out_count);
 }
 
 static int usb_blaster_read_data(void)
@@ -253,8 +272,11 @@ static int usb_blaster_read_data(void)
        uint8_t buf[1];
        uint32_t bytes_read;
 
+       if(out_count > 0)
+               usb_blaster_write_databuffer(out_buffer, out_count);
+
        out_value |= READ;
-       usb_blaster_write_data();
+       usb_blaster_addtowritebuffer(out_value, true);
        out_value &= ~READ;
 
        status = usb_blaster_buf_read(buf, 1, &bytes_read);
@@ -267,7 +289,7 @@ static int usb_blaster_read_data(void)
 static void usb_blaster_write(int tck, int tms, int tdi)
 {
 #ifdef _DEBUG_JTAG_IO_
-       LOG_DEBUG("---- usb_blaster_write(%d,%d,%d)\n", tck, tms, tdi);
+       LOG_DEBUG("---- usb_blaster_write(%d,%d,%d)", tck, tms, tdi);
 #endif
        out_value &= ~(TCK | TMS | TDI);
        if (tck)
@@ -277,7 +299,7 @@ static void usb_blaster_write(int tck, int tms, int tdi)
        if (tdi)
                out_value |= TDI;
 
-       usb_blaster_write_data();
+       usb_blaster_addtowritebuffer(out_value, false);
 }
 
 static int usb_blaster_speed(int speed)
@@ -307,10 +329,20 @@ static void usb_blaster_reset(int trst, int srst)
                        trst, srst);
 }
 
+static void usb_blaster_blink(int state)
+{
+       out_value = 0x00;
+       if(state)
+               out_value |= LED;
+
+       usb_blaster_addtowritebuffer(out_value, true);
+}
+
 static struct bitbang_interface usb_blaster_bitbang = {
        .read = usb_blaster_read_data,
        .write = usb_blaster_write,
        .reset = usb_blaster_reset,
+       .blink = usb_blaster_blink,
 };
 
 static int usb_blaster_init(void)
@@ -352,7 +384,7 @@ static int usb_blaster_init(void)
        {
                DWORD num_devices;
 
-               LOG_ERROR("unable to open ftdi device: %lu", status);
+               LOG_ERROR("unable to open ftdi device: %" PRIu32, status);
                status = FT_ListDevices(&num_devices, NULL,
                                FT_LIST_NUMBER_ONLY);
                if (status == FT_OK)
@@ -370,7 +402,7 @@ static int usb_blaster_init(void)
 
                        if (status == FT_OK)
                        {
-                               LOG_ERROR("ListDevices: %lu\n", num_devices);
+                               LOG_ERROR("ListDevices: %" PRIu32, num_devices);
                                for (i = 0; i < num_devices; i++)
                                        LOG_ERROR("%i: %s", i, desc_array[i]);
                        }
@@ -389,14 +421,14 @@ static int usb_blaster_init(void)
        status = FT_SetLatencyTimer(ftdih, 2);
        if (status != FT_OK)
        {
-               LOG_ERROR("unable to set latency timer: %lu", status);
+               LOG_ERROR("unable to set latency timer: %" PRIu32, status);
                return ERROR_JTAG_INIT_FAILED;
        }
 
        status = FT_GetLatencyTimer(ftdih, &latency_timer);
        if (status != FT_OK)
        {
-               LOG_ERROR("unable to get latency timer: %lu", status);
+               LOG_ERROR("unable to get latency timer: %" PRIu32, status);
                return ERROR_JTAG_INIT_FAILED;
        }
        LOG_DEBUG("current latency timer: %i", latency_timer);
@@ -404,7 +436,7 @@ static int usb_blaster_init(void)
        status = FT_SetBitMode(ftdih, 0x00, 0);
        if (status != FT_OK)
        {
-               LOG_ERROR("unable to disable bit i/o mode: %lu", status);
+               LOG_ERROR("unable to disable bit i/o mode: %" PRIu32, status);
                return ERROR_JTAG_INIT_FAILED;
        }
 #elif BUILD_USB_BLASTER_LIBFTDI == 1
@@ -442,8 +474,6 @@ static int usb_blaster_init(void)
 
        bitbang_interface = &usb_blaster_bitbang;
 
-       usb_blaster_speed(jtag_get_speed());
-
 #if 0
 #if BUILD_USB_BLASTER_FTD2XX == 1
        if ((status = FT_Purge(ftdih, FT_PURGE_RX | FT_PURGE_TX)) != FT_OK)
@@ -465,6 +495,9 @@ static int usb_blaster_init(void)
 
 static int usb_blaster_quit(void)
 {
+       if(out_count > 0)
+               usb_blaster_write_databuffer(out_buffer, out_count);
+
 #if BUILD_USB_BLASTER_FTD2XX == 1
        FT_STATUS status;
 
@@ -492,7 +525,7 @@ COMMAND_HANDLER(usb_blaster_handle_vid_pid_command)
 {
        if (CMD_ARGC > 2)
        {
-               LOG_WARNING("ignoring extra IDs in ft2232_vid_pid "
+               LOG_WARNING("ignoring extra IDs in usb_blaster_vid_pid "
                                        "(maximum is 1 pair)");
                CMD_ARGC = 2;
        }
@@ -530,12 +563,12 @@ COMMAND_HANDLER(usb_blaster_handle_pin_command)
                if (state == 0)
                {
                        out_value &= ~mask;
-                       usb_blaster_write_data();
+                       usb_blaster_addtowritebuffer(out_value, true);
                }
                else if (state == 1)
                {
                        out_value |= mask;
-                       usb_blaster_write_data();
+                       usb_blaster_addtowritebuffer(out_value, true);
                }
                else
                {

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)