jtag: align adapter speed code to new structure
[openocd.git] / src / jtag / drivers / ftdi.c
index 1a6ba590b8e00763baf7c72b25411654658b6fcd..6e2e18450bf08d162c8106ede3cb3ebf4e6b6d0e 100644 (file)
@@ -69,7 +69,7 @@
 #endif
 
 /* project specific includes */
-#include <jtag/drivers/jtag_usb_common.h>
+#include <jtag/adapter.h>
 #include <jtag/interface.h>
 #include <jtag/swd.h>
 #include <transport/transport.h>
@@ -150,11 +150,11 @@ static struct signal *create_signal(const char *name)
                psig = &(*psig)->next;
 
        *psig = calloc(1, sizeof(**psig));
-       if (*psig == NULL)
+       if (!*psig)
                return NULL;
 
        (*psig)->name = strdup(name);
-       if ((*psig)->name == NULL) {
+       if (!(*psig)->name) {
                free(*psig);
                *psig = NULL;
        }
@@ -289,7 +289,7 @@ static int ftdi_speed(int speed)
 
        if (!swd_mode && speed >= 10000000 && ftdi_jtag_mode != JTAG_MODE_ALT)
                LOG_INFO("ftdi: if you experience problems at higher adapter clocks, try "
-                        "the command \"ftdi_tdo_sample_edge falling\"");
+                        "the command \"ftdi tdo_sample_edge falling\"");
        return ERROR_OK;
 }
 
@@ -666,13 +666,13 @@ static int ftdi_initialize(void)
                LOG_DEBUG("ftdi interface using shortest path jtag state transitions");
 
        if (!ftdi_vid[0] && !ftdi_pid[0]) {
-               LOG_ERROR("Please specify ftdi_vid_pid");
+               LOG_ERROR("Please specify ftdi vid_pid");
                return ERROR_JTAG_INIT_FAILED;
        }
 
        for (int i = 0; ftdi_vid[i] || ftdi_pid[i]; i++) {
                mpsse_ctx = mpsse_open(&ftdi_vid[i], &ftdi_pid[i], ftdi_device_desc,
-                               ftdi_serial, jtag_usb_get_location(), ftdi_channel);
+                               ftdi_serial, adapter_usb_get_location(), ftdi_channel);
                if (mpsse_ctx)
                        break;
        }
@@ -699,7 +699,7 @@ static int ftdi_initialize(void)
 
        mpsse_loopback_config(mpsse_ctx, false);
 
-       freq = mpsse_set_frequency(mpsse_ctx, jtag_get_speed_khz() * 1000);
+       freq = mpsse_set_frequency(mpsse_ctx, adapter_get_speed_khz() * 1000);
 
        return mpsse_flush(mpsse_ctx);
 }
@@ -730,7 +730,7 @@ COMMAND_HANDLER(ftdi_handle_device_desc_command)
                free(ftdi_device_desc);
                ftdi_device_desc = strdup(CMD_ARGV[0]);
        } else {
-               LOG_ERROR("expected exactly one argument to ftdi_device_desc <description>");
+               LOG_ERROR("expected exactly one argument to ftdi device_desc <description>");
        }
 
        return ERROR_OK;
@@ -897,12 +897,12 @@ COMMAND_HANDLER(ftdi_handle_get_signal_command)
 COMMAND_HANDLER(ftdi_handle_vid_pid_command)
 {
        if (CMD_ARGC > MAX_USB_IDS * 2) {
-               LOG_WARNING("ignoring extra IDs in ftdi_vid_pid "
+               LOG_WARNING("ignoring extra IDs in ftdi vid_pid "
                        "(maximum is %d pairs)", MAX_USB_IDS);
                CMD_ARGC = MAX_USB_IDS * 2;
        }
        if (CMD_ARGC < 2 || (CMD_ARGC & 1)) {
-               LOG_WARNING("incomplete ftdi_vid_pid configuration directive");
+               LOG_WARNING("incomplete ftdi vid_pid configuration directive");
                if (CMD_ARGC < 2)
                        return ERROR_COMMAND_SYNTAX_ERROR;
                /* remove the incomplete trailing id */
@@ -917,7 +917,7 @@ COMMAND_HANDLER(ftdi_handle_vid_pid_command)
 
        /*
         * Explicitly terminate, in case there are multiples instances of
-        * ftdi_vid_pid.
+        * ftdi vid_pid.
         */
        ftdi_vid[i >> 1] = ftdi_pid[i >> 1] = 0;
 
@@ -935,7 +935,7 @@ COMMAND_HANDLER(ftdi_handle_tdo_sample_edge_command)
 
        if (CMD_ARGC > 0) {
                n = jim_nvp_name2value_simple(nvp_ftdi_jtag_modes, CMD_ARGV[0]);
-               if (n->name == NULL)
+               if (!n->name)
                        return ERROR_COMMAND_SYNTAX_ERROR;
                ftdi_jtag_mode = n->value;
 
@@ -947,30 +947,30 @@ COMMAND_HANDLER(ftdi_handle_tdo_sample_edge_command)
        return ERROR_OK;
 }
 
-static const struct command_registration ftdi_command_handlers[] = {
+static const struct command_registration ftdi_subcommand_handlers[] = {
        {
-               .name = "ftdi_device_desc",
+               .name = "device_desc",
                .handler = &ftdi_handle_device_desc_command,
                .mode = COMMAND_CONFIG,
                .help = "set the USB device description of the FTDI device",
                .usage = "description_string",
        },
        {
-               .name = "ftdi_serial",
+               .name = "serial",
                .handler = &ftdi_handle_serial_command,
                .mode = COMMAND_CONFIG,
                .help = "set the serial number of the FTDI device",
                .usage = "serial_string",
        },
        {
-               .name = "ftdi_channel",
+               .name = "channel",
                .handler = &ftdi_handle_channel_command,
                .mode = COMMAND_CONFIG,
                .help = "set the channel of the FTDI device that is used as JTAG",
                .usage = "(0-3)",
        },
        {
-               .name = "ftdi_layout_init",
+               .name = "layout_init",
                .handler = &ftdi_handle_layout_init_command,
                .mode = COMMAND_CONFIG,
                .help = "initialize the FTDI GPIO signals used "
@@ -978,7 +978,7 @@ static const struct command_registration ftdi_command_handlers[] = {
                .usage = "data direction",
        },
        {
-               .name = "ftdi_layout_signal",
+               .name = "layout_signal",
                .handler = &ftdi_handle_layout_signal_command,
                .mode = COMMAND_ANY,
                .help = "define a signal controlled by one or more FTDI GPIO as data "
@@ -986,28 +986,28 @@ static const struct command_registration ftdi_command_handlers[] = {
                .usage = "name [-data mask|-ndata mask] [-oe mask|-noe mask] [-alias|-nalias name]",
        },
        {
-               .name = "ftdi_set_signal",
+               .name = "set_signal",
                .handler = &ftdi_handle_set_signal_command,
                .mode = COMMAND_EXEC,
                .help = "control a layout-specific signal",
                .usage = "name (1|0|z)",
        },
        {
-               .name = "ftdi_get_signal",
+               .name = "get_signal",
                .handler = &ftdi_handle_get_signal_command,
                .mode = COMMAND_EXEC,
                .help = "read the value of a layout-specific signal",
                .usage = "name",
        },
        {
-               .name = "ftdi_vid_pid",
+               .name = "vid_pid",
                .handler = &ftdi_handle_vid_pid_command,
                .mode = COMMAND_CONFIG,
                .help = "the vendor ID and product ID of the FTDI device",
                .usage = "(vid pid)*",
        },
        {
-               .name = "ftdi_tdo_sample_edge",
+               .name = "tdo_sample_edge",
                .handler = &ftdi_handle_tdo_sample_edge_command,
                .mode = COMMAND_ANY,
                .help = "set which TCK clock edge is used for sampling TDO "
@@ -1018,6 +1018,17 @@ static const struct command_registration ftdi_command_handlers[] = {
        COMMAND_REGISTRATION_DONE
 };
 
+static const struct command_registration ftdi_command_handlers[] = {
+       {
+               .name = "ftdi",
+               .mode = COMMAND_ANY,
+               .help = "perform ftdi management",
+               .chain = ftdi_subcommand_handlers,
+               .usage = "",
+       },
+       COMMAND_REGISTRATION_DONE
+};
+
 static int create_default_signal(const char *name, uint16_t data_mask)
 {
        struct signal *sig = create_signal(name);
@@ -1057,7 +1068,7 @@ static int ftdi_swd_init(void)
        swd_cmd_queue_alloced = 10;
        swd_cmd_queue = malloc(swd_cmd_queue_alloced * sizeof(*swd_cmd_queue));
 
-       return swd_cmd_queue != NULL ? ERROR_OK : ERROR_FAIL;
+       return swd_cmd_queue ? ERROR_OK : ERROR_FAIL;
 }
 
 static void ftdi_swd_swdio_en(bool enable)
@@ -1132,7 +1143,7 @@ static int ftdi_swd_run_queue(void)
                                goto skip;
                        }
 
-                       if (swd_cmd_queue[i].dst != NULL)
+                       if (swd_cmd_queue[i].dst)
                                *swd_cmd_queue[i].dst = data;
                }
        }
@@ -1157,7 +1168,7 @@ static void ftdi_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint32
                 * pointers into the queue which may be invalid after the realloc. */
                queued_retval = ftdi_swd_run_queue();
                struct swd_cmd_queue_entry *q = realloc(swd_cmd_queue, swd_cmd_queue_alloced * 2 * sizeof(*swd_cmd_queue));
-               if (q != NULL) {
+               if (q) {
                        swd_cmd_queue = q;
                        swd_cmd_queue_alloced *= 2;
                        LOG_DEBUG("Increased SWD command queue to %zu elements", swd_cmd_queue_alloced);

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)