swd: Remove DAP from parameter list
[openocd.git] / src / jtag / drivers / ftdi.c
index 9d3444738930fb5065cdeddd2bbad935e1fdfddc..d8c7d64229af7880affcb5d6e4b8166ef61f855e 100644 (file)
@@ -127,10 +127,8 @@ static uint16_t output;
 static uint16_t direction;
 static uint16_t jtag_output_init;
 static uint16_t jtag_direction_init;
-static uint16_t swd_output_init;
-static uint16_t swd_direction_init;
 
-static int ftdi_swd_switch_seq(struct adiv5_dap *dap, enum swd_special_seq seq);
+static int ftdi_swd_switch_seq(enum swd_special_seq seq);
 
 static struct signal *find_signal_by_name(const char *name)
 {
@@ -503,7 +501,8 @@ static void ftdi_execute_reset(struct jtag_command *cmd)
                        ftdi_set_signal(trst, '0');
                else
                        LOG_ERROR("Can't assert TRST: nTRST signal is not defined");
-       } else if (trst && cmd->cmd.reset->trst == 0) {
+       } else if (trst && jtag_get_reset_config() & RESET_HAS_TRST &&
+                       cmd->cmd.reset->trst == 0) {
                if (jtag_get_reset_config() & RESET_TRST_OPEN_DRAIN)
                        ftdi_set_signal(trst, 'z');
                else
@@ -516,7 +515,8 @@ static void ftdi_execute_reset(struct jtag_command *cmd)
                        ftdi_set_signal(srst, '0');
                else
                        LOG_ERROR("Can't assert SRST: nSRST signal is not defined");
-       } else if (srst && cmd->cmd.reset->srst == 0) {
+       } else if (srst && jtag_get_reset_config() & RESET_HAS_SRST &&
+                       cmd->cmd.reset->srst == 0) {
                if (jtag_get_reset_config() & RESET_SRST_PUSH_PULL)
                        ftdi_set_signal(srst, '1');
                else
@@ -634,21 +634,26 @@ static int ftdi_initialize(void)
        if (!mpsse_ctx)
                return ERROR_JTAG_INIT_FAILED;
 
-       output = swd_mode ? swd_output_init : jtag_output_init;
-       direction = swd_mode ? swd_direction_init : jtag_direction_init;
+       output = jtag_output_init;
+       direction = jtag_direction_init;
+
+       if (swd_mode) {
+               struct signal *sig = find_signal_by_name("SWD_EN");
+               if (!sig) {
+                       LOG_ERROR("SWD mode is active but SWD_EN signal is not defined");
+                       return ERROR_JTAG_INIT_FAILED;
+               }
+               /* A dummy SWD_EN would have zero mask */
+               if (sig->data_mask)
+                       ftdi_set_signal(sig, '1');
+       }
 
        mpsse_set_data_bits_low_byte(mpsse_ctx, output & 0xff, direction & 0xff);
        mpsse_set_data_bits_high_byte(mpsse_ctx, output >> 8, direction >> 8);
 
        mpsse_loopback_config(mpsse_ctx, false);
 
-       /* Set a low default */
-       freq = mpsse_set_frequency(mpsse_ctx, 1000);
-
-       if (swd_mode)
-               ftdi_swd_switch_seq(NULL, JTAG_TO_SWD);
-       else
-               ftdi_swd_switch_seq(NULL, SWD_TO_JTAG);
+       freq = mpsse_set_frequency(mpsse_ctx, jtag_get_speed_khz() * 1000);
 
        return mpsse_flush(mpsse_ctx);
 }
@@ -657,6 +662,8 @@ static int ftdi_quit(void)
 {
        mpsse_close(mpsse_ctx);
 
+       free(swd_cmd_queue);
+
        return ERROR_OK;
 }
 
@@ -707,17 +714,6 @@ COMMAND_HANDLER(ftdi_handle_layout_init_command)
        return ERROR_OK;
 }
 
-COMMAND_HANDLER(ftdi_handle_layout_init_swd_command)
-{
-       if (CMD_ARGC != 2)
-               return ERROR_COMMAND_SYNTAX_ERROR;
-
-       COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], swd_output_init);
-       COMMAND_PARSE_NUMBER(u16, CMD_ARGV[1], swd_direction_init);
-
-       return ERROR_OK;
-}
-
 COMMAND_HANDLER(ftdi_handle_layout_signal_command)
 {
        if (CMD_ARGC < 1)
@@ -863,17 +859,7 @@ static const struct command_registration ftdi_command_handlers[] = {
                .handler = &ftdi_handle_layout_init_command,
                .mode = COMMAND_CONFIG,
                .help = "initialize the FTDI GPIO signals used "
-                       "to control output-enables and reset signals"
-                       "when JTAG mode is selected",
-               .usage = "data direction",
-       },
-       {
-               .name = "ftdi_layout_init_swd",
-               .handler = &ftdi_handle_layout_init_swd_command,
-               .mode = COMMAND_CONFIG,
-               .help = "initialize the FTDI GPIO signals used "
-                       "to control output-enables and reset signals"
-                       "when SWD mode is selected",
+                       "to control output-enables and reset signals",
                .usage = "data direction",
        },
        {
@@ -901,11 +887,42 @@ static const struct command_registration ftdi_command_handlers[] = {
        COMMAND_REGISTRATION_DONE
 };
 
+static int create_default_signal(const char *name, uint16_t data_mask)
+{
+       struct signal *sig = create_signal(name);
+       if (!sig) {
+               LOG_ERROR("failed to create signal %s", name);
+               return ERROR_FAIL;
+       }
+       sig->invert_data = false;
+       sig->data_mask = data_mask;
+       sig->invert_oe = false;
+       sig->oe_mask = 0;
+
+       return ERROR_OK;
+}
+
+static int create_signals(void)
+{
+       if (create_default_signal("TCK", 0x01) != ERROR_OK)
+               return ERROR_FAIL;
+       if (create_default_signal("TDI", 0x02) != ERROR_OK)
+               return ERROR_FAIL;
+       if (create_default_signal("TDO", 0x04) != ERROR_OK)
+               return ERROR_FAIL;
+       if (create_default_signal("TMS", 0x08) != ERROR_OK)
+               return ERROR_FAIL;
+       return ERROR_OK;
+}
+
 static int ftdi_swd_init(void)
 {
        LOG_INFO("FTDI SWD mode enabled");
        swd_mode = true;
 
+       if (create_signals() != ERROR_OK)
+               return ERROR_FAIL;
+
        swd_cmd_queue_alloced = 10;
        swd_cmd_queue = malloc(swd_cmd_queue_alloced * sizeof(*swd_cmd_queue));
 
@@ -924,7 +941,7 @@ static void ftdi_swd_swdio_en(bool enable)
  * @param dap
  * @return
  */
-static int ftdi_swd_run_queue(struct adiv5_dap *dap)
+static int ftdi_swd_run_queue(void)
 {
        LOG_DEBUG("Executing %zu queued transactions", swd_cmd_queue_length);
        int retval;
@@ -950,7 +967,7 @@ static int ftdi_swd_run_queue(struct adiv5_dap *dap)
        }
 
        for (size_t i = 0; i < swd_cmd_queue_length; i++) {
-               int ack = buf_get_u32(&swd_cmd_queue[i].trn_ack_data_parity_trn, 1, 3);
+               int ack = buf_get_u32(swd_cmd_queue[i].trn_ack_data_parity_trn, 1, 3);
 
                LOG_DEBUG("%s %s %s reg %X = %08"PRIx32,
                                ack == SWD_ACK_OK ? "OK" : ack == SWD_ACK_WAIT ? "WAIT" : ack == SWD_ACK_FAULT ? "FAULT" : "JUNK",
@@ -961,7 +978,7 @@ static int ftdi_swd_run_queue(struct adiv5_dap *dap)
                                                1 + 3 + (swd_cmd_queue[i].cmd & SWD_CMD_RnW ? 0 : 1), 32));
 
                if (ack != SWD_ACK_OK) {
-                       queued_retval = ack;
+                       queued_retval = ack == SWD_ACK_WAIT ? ERROR_WAIT : ERROR_FAIL;
                        goto skip;
 
                } else if (swd_cmd_queue[i].cmd & SWD_CMD_RnW) {
@@ -991,13 +1008,13 @@ skip:
        return retval;
 }
 
-static void ftdi_swd_queue_cmd(struct adiv5_dap *dap, uint8_t cmd, uint32_t *dst, uint32_t data)
+static void ftdi_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint32_t ap_delay_clk)
 {
        if (swd_cmd_queue_length >= swd_cmd_queue_alloced) {
                /* Not enough room in the queue. Run the queue and increase its size for next time.
                 * Note that it's not possible to avoid running the queue here, because mpsse contains
                 * pointers into the queue which may be invalid after the realloc. */
-               queued_retval = ftdi_swd_run_queue(dap);
+               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) {
                        swd_cmd_queue = q;
@@ -1040,23 +1057,23 @@ static void ftdi_swd_queue_cmd(struct adiv5_dap *dap, uint8_t cmd, uint32_t *dst
 
        /* Insert idle cycles after AP accesses to avoid WAIT */
        if (cmd & SWD_CMD_APnDP)
-               mpsse_clock_data_out(mpsse_ctx, NULL, 0, dap->memaccess_tck, SWD_MODE);
+               mpsse_clock_data_out(mpsse_ctx, NULL, 0, ap_delay_clk, SWD_MODE);
 
 }
 
-static void ftdi_swd_read_reg(struct adiv5_dap *dap, uint8_t cmd, uint32_t *value)
+static void ftdi_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
 {
        assert(cmd & SWD_CMD_RnW);
-       ftdi_swd_queue_cmd(dap, cmd, value, 0);
+       ftdi_swd_queue_cmd(cmd, value, 0, ap_delay_clk);
 }
 
-static void ftdi_swd_write_reg(struct adiv5_dap *dap, uint8_t cmd, uint32_t value)
+static void ftdi_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
 {
        assert(!(cmd & SWD_CMD_RnW));
-       ftdi_swd_queue_cmd(dap, cmd, NULL, value);
+       ftdi_swd_queue_cmd(cmd, NULL, value, ap_delay_clk);
 }
 
-static int_least32_t ftdi_swd_frequency(struct adiv5_dap *dap, int_least32_t hz)
+static int_least32_t ftdi_swd_frequency(int_least32_t hz)
 {
        if (hz > 0)
                freq = mpsse_set_frequency(mpsse_ctx, hz);
@@ -1064,7 +1081,7 @@ static int_least32_t ftdi_swd_frequency(struct adiv5_dap *dap, int_least32_t hz)
        return freq;
 }
 
-static int ftdi_swd_switch_seq(struct adiv5_dap *dap, enum swd_special_seq seq)
+static int ftdi_swd_switch_seq(enum swd_special_seq seq)
 {
        switch (seq) {
        case LINE_RESET:

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)