jtag: declare local symbols as static
[fw/openocd] / src / jtag / drivers / usb_blaster / usb_blaster.c
index 8ccf871724c7b636ad7d246278ea26a7683b2e9a..de3b5d58bc32098138672bc7356489a1bbb03f0c 100644 (file)
@@ -174,7 +174,7 @@ static int ublast_buf_read(uint8_t *buf, unsigned size, uint32_t *bytes_read)
        int ret = info.drv->read(info.drv, buf, size, bytes_read);
        char *str = hexdump(buf, *bytes_read);
 
-       DEBUG_JTAG_IO("(size=%d, buf=[%s]) -> %u", size, str,
+       LOG_DEBUG_IO("(size=%d, buf=[%s]) -> %" PRIu32, size, str,
                      *bytes_read);
        free(str);
        return ret;
@@ -185,7 +185,7 @@ static int ublast_buf_write(uint8_t *buf, int size, uint32_t *bytes_written)
        int ret = info.drv->write(info.drv, buf, size, bytes_written);
        char *str = hexdump(buf, *bytes_written);
 
-       DEBUG_JTAG_IO("(size=%d, buf=[%s]) -> %u", size, str,
+       LOG_DEBUG_IO("(size=%d, buf=[%s]) -> %" PRIu32, size, str,
                      *bytes_written);
        free(str);
        return ret;
@@ -198,7 +198,7 @@ static int nb_buf_remaining(void)
 
 static void ublast_flush_buffer(void)
 {
-       unsigned int retlen;
+       uint32_t retlen;
        int nb = info.bufidx, ret = ERROR_OK;
 
        while (ret == ERROR_OK && nb > 0) {
@@ -266,7 +266,7 @@ static void ublast_queue_byte(uint8_t abyte)
        info.buf[info.bufidx++] = abyte;
        if (nb_buf_remaining() == 0)
                ublast_flush_buffer();
-       DEBUG_JTAG_IO("(byte=0x%02x)", abyte);
+       LOG_DEBUG_IO("(byte=0x%02x)", abyte);
 }
 
 /**
@@ -275,7 +275,7 @@ static void ublast_queue_byte(uint8_t abyte)
  *
  * Returns pin value (1 means driven high, 0 mean driven low)
  */
-bool ublast_compute_pin(enum gpio_steer steer)
+static bool ublast_compute_pin(enum gpio_steer steer)
 {
        switch (steer) {
        case FIXED_0:
@@ -337,7 +337,7 @@ static void ublast_clock_tms(int tms)
 {
        uint8_t out;
 
-       DEBUG_JTAG_IO("(tms=%d)", !!tms);
+       LOG_DEBUG_IO("(tms=%d)", !!tms);
        info.tms = !!tms;
        info.tdi = 0;
        out = ublast_build_out(SCAN_OUT);
@@ -354,7 +354,7 @@ static void ublast_idle_clock(void)
 {
        uint8_t out = ublast_build_out(SCAN_OUT);
 
-       DEBUG_JTAG_IO(".");
+       LOG_DEBUG_IO(".");
        ublast_queue_byte(out);
 }
 
@@ -366,16 +366,16 @@ static void ublast_idle_clock(void)
  * Output a TDI bit and assert clock to push it into the JTAG device :
  *  - writing out TCK=0, TMS=<old_state>=0, TDI=<tdi>
  * - writing out TCK=1, TMS=<new_state>, TDI=<tdi> which triggers the JTAG
- *    device aquiring the data.
+ *    device acquiring the data.
  *
  * If a TDO is to be read back, the required read is requested (bitbang mode),
- * and the USB Blaster will send back a byte with bit0 reprensenting the TDO.
+ * and the USB Blaster will send back a byte with bit0 representing the TDO.
  */
 static void ublast_clock_tdi(int tdi, enum scan_type type)
 {
        uint8_t out;
 
-       DEBUG_JTAG_IO("(tdi=%d)",  !!tdi);
+       LOG_DEBUG_IO("(tdi=%d)",  !!tdi);
        info.tdi = !!tdi;
 
        out = ublast_build_out(SCAN_OUT);
@@ -391,7 +391,7 @@ static void ublast_clock_tdi(int tdi, enum scan_type type)
  * @type: scan type (ie. does a readback of TDO is required)
  *
  * This function is the same as ublast_clock_tdi(), but it changes also the TMS
- * while outputing the TDI. This should be the last TDI output of a TDI
+ * while output the TDI. This should be the last TDI output of a TDI
  * sequence, which will change state from :
  *   - IRSHIFT -> IREXIT1
  *   - or DRSHIFT -> DREXIT1
@@ -400,7 +400,7 @@ static void ublast_clock_tdi_flip_tms(int tdi, enum scan_type type)
 {
        uint8_t out;
 
-       DEBUG_JTAG_IO("(tdi=%d)", !!tdi);
+       LOG_DEBUG_IO("(tdi=%d)", !!tdi);
        info.tdi = !!tdi;
        info.tms = !info.tms;
 
@@ -430,7 +430,7 @@ static void ublast_queue_bytes(uint8_t *bytes, int nb_bytes)
                          info.bufidx + nb_bytes);
                exit(-1);
        }
-       DEBUG_JTAG_IO("(nb_bytes=%d, bytes=[0x%02x, ...])", nb_bytes,
+       LOG_DEBUG_IO("(nb_bytes=%d, bytes=[0x%02x, ...])", nb_bytes,
                      bytes ? bytes[0] : 0);
        if (bytes)
                memcpy(&info.buf[info.bufidx], bytes, nb_bytes);
@@ -447,7 +447,7 @@ static void ublast_queue_bytes(uint8_t *bytes, int nb_bytes)
  * @nb_bits: number of TMS bits (between 1 and 8)
  * @skip: number of TMS bits to skip at the beginning of the series
  *
- * Write a serie of TMS transitions, where each transition consists in :
+ * Write a series of TMS transitions, where each transition consists in :
  *  - writing out TCK=0, TMS=<new_state>, TDI=<???>
  *  - writing out TCK=1, TMS=<new_state>, TDI=<???> which triggers the transition
  * The function ensures that at the end of the sequence, the clock (TCK) is put
@@ -457,7 +457,7 @@ static void ublast_tms_seq(const uint8_t *bits, int nb_bits, int skip)
 {
        int i;
 
-       DEBUG_JTAG_IO("(bits=%02x..., nb_bits=%d)", bits[0], nb_bits);
+       LOG_DEBUG_IO("(bits=%02x..., nb_bits=%d)", bits[0], nb_bits);
        for (i = skip; i < nb_bits; i++)
                ublast_clock_tms((bits[i / 8] >> (i % 8)) & 0x01);
        ublast_idle_clock();
@@ -469,7 +469,7 @@ static void ublast_tms_seq(const uint8_t *bits, int nb_bits, int skip)
  */
 static void ublast_tms(struct tms_command *cmd)
 {
-       DEBUG_JTAG_IO("(num_bits=%d)", cmd->num_bits);
+       LOG_DEBUG_IO("(num_bits=%d)", cmd->num_bits);
        ublast_tms_seq(cmd->bits, cmd->num_bits, 0);
 }
 
@@ -477,7 +477,7 @@ static void ublast_tms(struct tms_command *cmd)
  * ublast_path_move - write a TMS sequence transition to JTAG
  * @cmd: path transition
  *
- * Write a serie of TMS transitions, where each transition consists in :
+ * Write a series of TMS transitions, where each transition consists in :
  *  - writing out TCK=0, TMS=<new_state>, TDI=<???>
  *  - writing out TCK=1, TMS=<new_state>, TDI=<???> which triggers the transition
  * The function ensures that at the end of the sequence, the clock (TCK) is put
@@ -487,7 +487,7 @@ static void ublast_path_move(struct pathmove_command *cmd)
 {
        int i;
 
-       DEBUG_JTAG_IO("(num_states=%d, last_state=%d)",
+       LOG_DEBUG_IO("(num_states=%d, last_state=%d)",
                  cmd->num_states, cmd->path[cmd->num_states - 1]);
        for (i = 0; i < cmd->num_states; i++) {
                if (tap_state_transition(tap_get_state(), false) == cmd->path[i])
@@ -512,7 +512,7 @@ static void ublast_state_move(tap_state_t state, int skip)
        uint8_t tms_scan;
        int tms_len;
 
-       DEBUG_JTAG_IO("(from %s to %s)", tap_state_name(tap_get_state()),
+       LOG_DEBUG_IO("(from %s to %s)", tap_state_name(tap_get_state()),
                  tap_state_name(state));
        if (tap_get_state() == state)
                return;
@@ -534,14 +534,14 @@ static void ublast_state_move(tap_state_t state, int skip)
  * bit0), second bit in (byte0, bit1), ...), which is what we want to return,
  * simply read bytes from USB interface and store them.
  *
- * Returns ERROR_OK if OK, ERROR_xxx if a read error occured
+ * Returns ERROR_OK if OK, ERROR_xxx if a read error occurred
  */
 static int ublast_read_byteshifted_tdos(uint8_t *buf, int nb_bytes)
 {
-       unsigned int retlen;
+       uint32_t retlen;
        int ret = ERROR_OK;
 
-       DEBUG_JTAG_IO("%s(buf=%p, num_bits=%d)", __func__, buf, nb_bytes * 8);
+       LOG_DEBUG_IO("%s(buf=%p, num_bits=%d)", __func__, buf, nb_bytes * 8);
        ublast_flush_buffer();
        while (ret == ERROR_OK && nb_bytes > 0) {
                ret = ublast_buf_read(buf, nb_bytes, &retlen);
@@ -564,16 +564,16 @@ static int ublast_read_byteshifted_tdos(uint8_t *buf, int nb_bytes)
  *  - ninth bit is sotred in byte1, bit 0
  *  - etc ...
  *
- * Returns ERROR_OK if OK, ERROR_xxx if a read error occured
+ * Returns ERROR_OK if OK, ERROR_xxx if a read error occurred
  */
 static int ublast_read_bitbang_tdos(uint8_t *buf, int nb_bits)
 {
        int nb1 = nb_bits;
        int i, ret = ERROR_OK;
-       unsigned int retlen;
+       uint32_t retlen;
        uint8_t tmp[8];
 
-       DEBUG_JTAG_IO("%s(buf=%p, num_bits=%d)", __func__, buf, nb_bits);
+       LOG_DEBUG_IO("%s(buf=%p, num_bits=%d)", __func__, buf, nb_bits);
 
        /*
         * Ensure all previous bitbang writes were issued to the dongle, so that
@@ -596,7 +596,7 @@ static int ublast_read_bitbang_tdos(uint8_t *buf, int nb_bits)
  * @nb_bits: number of bits
  * @scan: scan type (ie. if TDO read back is required or not)
  *
- * Outputs a serie of TDI bits on TDI.
+ * Outputs a series of TDI bits on TDI.
  * As a side effect, the last TDI bit is sent along a TMS=1, and triggers a JTAG
  * TAP state shift if input bits were non NULL.
  *
@@ -688,7 +688,7 @@ static void ublast_queue_tdi(uint8_t *bits, int nb_bits, enum scan_type scan)
 
 static void ublast_runtest(int cycles, tap_state_t state)
 {
-       DEBUG_JTAG_IO("%s(cycles=%i, end_state=%d)", __func__, cycles, state);
+       LOG_DEBUG_IO("%s(cycles=%i, end_state=%d)", __func__, cycles, state);
 
        ublast_state_move(TAP_IDLE, 0);
        ublast_queue_tdi(NULL, cycles, SCAN_OUT);
@@ -697,7 +697,7 @@ static void ublast_runtest(int cycles, tap_state_t state)
 
 static void ublast_stableclocks(int cycles)
 {
-       DEBUG_JTAG_IO("%s(cycles=%i)", __func__, cycles);
+       LOG_DEBUG_IO("%s(cycles=%i)", __func__, cycles);
        ublast_queue_tdi(NULL, cycles, SCAN_OUT);
 }
 
@@ -707,7 +707,7 @@ static void ublast_stableclocks(int cycles)
  *
  * Launch a JTAG IR-scan or DR-scan
  *
- * Returns ERROR_OK if OK, ERROR_xxx if a read/write error occured.
+ * Returns ERROR_OK if OK, ERROR_xxx if a read/write error occurred.
  */
 static int ublast_scan(struct scan_command *cmd)
 {
@@ -727,7 +727,7 @@ static int ublast_scan(struct scan_command *cmd)
                ublast_state_move(TAP_DRSHIFT, 0);
 
        log_buf = hexdump(buf, DIV_ROUND_UP(scan_bits, 8));
-       DEBUG_JTAG_IO("%s(scan=%s, type=%s, bits=%d, buf=[%s], end_state=%d)", __func__,
+       LOG_DEBUG_IO("%s(scan=%s, type=%s, bits=%d, buf=[%s], end_state=%d)", __func__,
                  cmd->ir_scan ? "IRSCAN" : "DRSCAN",
                  type2str[type],
                  scan_bits, log_buf, cmd->end_state);
@@ -736,8 +736,7 @@ static int ublast_scan(struct scan_command *cmd)
        ublast_queue_tdi(buf, scan_bits, type);
 
        ret = jtag_read_buffer(buf, cmd);
-       if (buf)
-               free(buf);
+       free(buf);
        /*
         * ublast_queue_tdi sends the last bit with TMS=1. We are therefore
         * already in Exit1-DR/IR and have to skip the first step on our way
@@ -749,7 +748,7 @@ static int ublast_scan(struct scan_command *cmd)
 
 static void ublast_usleep(int us)
 {
-       DEBUG_JTAG_IO("%s(us=%d)",  __func__, us);
+       LOG_DEBUG_IO("%s(us=%d)",  __func__, us);
        jtag_sleep(us);
 }
 
@@ -816,6 +815,11 @@ static int ublast_execute_queue(void)
                case JTAG_SCAN:
                        ret = ublast_scan(cmd->cmd.scan);
                        break;
+               default:
+                       LOG_ERROR("BUG: unknown JTAG command type 0x%X",
+                                 cmd->type);
+                       ret = ERROR_FAIL;
+                       break;
                }
        }
 
@@ -897,7 +901,7 @@ static int ublast_init(void)
 static int ublast_quit(void)
 {
        uint8_t byte0 = 0;
-       unsigned int retlen;
+       uint32_t retlen;
 
        ublast_buf_write(&byte0, 1, &retlen);
        return info.drv->close(info.drv);
@@ -1037,8 +1041,8 @@ static const struct command_registration ublast_command_handlers[] = {
                .name = "usb_blaster_vid_pid",
                .handler = ublast_handle_vid_pid_command,
                .mode = COMMAND_CONFIG,
-               .help = "the vendor ID and product ID of the USB-Blaster and " \
-                       "vendor ID and product ID of the uninitialized device " \
+               .help = "the vendor ID and product ID of the USB-Blaster and "
+                       "vendor ID and product ID of the uninitialized device "
                        "for USB-Blaster II",
                .usage = "vid pid vid_uninit pid_uninit",
        },
@@ -1066,12 +1070,18 @@ static const struct command_registration ublast_command_handlers[] = {
        COMMAND_REGISTRATION_DONE
 };
 
-struct jtag_interface usb_blaster_interface = {
+static struct jtag_interface usb_blaster_interface = {
+       .supported = DEBUG_CAP_TMS_SEQ,
+       .execute_queue = ublast_execute_queue,
+};
+
+struct adapter_driver usb_blaster_adapter_driver = {
        .name = "usb_blaster",
+       .transports = jtag_only,
        .commands = ublast_command_handlers,
-       .supported = DEBUG_CAP_TMS_SEQ,
 
-       .execute_queue = ublast_execute_queue,
        .init = ublast_init,
        .quit = ublast_quit,
+
+       .jtag_ops = &usb_blaster_interface,
 };