ftdi: Remove unnecessary cast
[openocd.git] / src / jtag / drivers / ftdi.c
index f04b390c1717b1c541c2e3e81fa9daa1cbda8ff3..a6070b1120dbafc76892b8cafafd6f1f9d07a468 100644 (file)
@@ -15,7 +15,7 @@
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
-*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+*   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
 ***************************************************************************/
 
 /**
@@ -127,8 +127,10 @@ static struct signal *create_signal(const char *name)
                psig = &(*psig)->next;
 
        *psig = calloc(1, sizeof(**psig));
-       if (*psig)
-               (*psig)->name = strdup(name);
+       if (*psig == NULL)
+               return NULL;
+
+       (*psig)->name = strdup(name);
        if ((*psig)->name == NULL) {
                free(*psig);
                *psig = NULL;
@@ -138,7 +140,6 @@ static struct signal *create_signal(const char *name)
 
 static int ftdi_set_signal(const struct signal *s, char value)
 {
-       int retval;
        bool data;
        bool oe;
 
@@ -179,13 +180,8 @@ static int ftdi_set_signal(const struct signal *s, char value)
        else
                output = oe ? output | s->oe_mask : output & ~s->oe_mask;
 
-       retval = mpsse_set_data_bits_low_byte(mpsse_ctx, output & 0xff, direction & 0xff);
-       if (retval == ERROR_OK)
-               retval = mpsse_set_data_bits_high_byte(mpsse_ctx, output >> 8, direction >> 8);
-       if (retval != ERROR_OK) {
-               LOG_ERROR("couldn't initialize FTDI GPIO");
-               return ERROR_JTAG_INIT_FAILED;
-       }
+       mpsse_set_data_bits_low_byte(mpsse_ctx, output & 0xff, direction & 0xff);
+       mpsse_set_data_bits_high_byte(mpsse_ctx, output >> 8, direction >> 8);
 
        return ERROR_OK;
 }
@@ -199,7 +195,7 @@ static int ftdi_set_signal(const struct signal *s, char value)
  *
  * @param goal_state is the destination state for the move.
  */
-static int move_to_state(tap_state_t goal_state)
+static void move_to_state(tap_state_t goal_state)
 {
        tap_state_t start_state = tap_get_state();
 
@@ -209,8 +205,9 @@ static int move_to_state(tap_state_t goal_state)
        */
 
        /* do the 2 lookups */
-       int tms_bits  = tap_get_tms_path(start_state, goal_state);
+       uint8_t tms_bits  = tap_get_tms_path(start_state, goal_state);
        int tms_count = tap_get_tms_path_len(start_state, goal_state);
+       assert(tms_count <= 8);
 
        DEBUG_JTAG_IO("start=%s goal=%s", tap_state_name(start_state), tap_state_name(goal_state));
 
@@ -218,8 +215,8 @@ static int move_to_state(tap_state_t goal_state)
        for (int i = 0; i < tms_count; i++)
                tap_set_state(tap_state_transition(tap_get_state(), (tms_bits >> i) & 1));
 
-       return mpsse_clock_tms_cs_out(mpsse_ctx,
-               (uint8_t *)&tms_bits,
+       mpsse_clock_tms_cs_out(mpsse_ctx,
+               &tms_bits,
                0,
                tms_count,
                false,
@@ -266,9 +263,8 @@ static void ftdi_end_state(tap_state_t state)
        }
 }
 
-static int ftdi_execute_runtest(struct jtag_command *cmd)
+static void ftdi_execute_runtest(struct jtag_command *cmd)
 {
-       int retval = ERROR_OK;
        int i;
        uint8_t zero = 0;
 
@@ -281,10 +277,10 @@ static int ftdi_execute_runtest(struct jtag_command *cmd)
 
        /* TODO: Reuse ftdi_execute_stableclocks */
        i = cmd->cmd.runtest->num_cycles;
-       while (i > 0 && retval == ERROR_OK) {
+       while (i > 0) {
                /* there are no state transitions in this code, so omit state tracking */
                unsigned this_len = i > 7 ? 7 : i;
-               retval = mpsse_clock_tms_cs_out(mpsse_ctx, &zero, 0, this_len, false, JTAG_MODE);
+               mpsse_clock_tms_cs_out(mpsse_ctx, &zero, 0, this_len, false, JTAG_MODE);
                i -= this_len;
        }
 
@@ -296,13 +292,10 @@ static int ftdi_execute_runtest(struct jtag_command *cmd)
        DEBUG_JTAG_IO("runtest: %i, end in %s",
                cmd->cmd.runtest->num_cycles,
                tap_state_name(tap_get_end_state()));
-       return retval;
 }
 
-static int ftdi_execute_statemove(struct jtag_command *cmd)
+static void ftdi_execute_statemove(struct jtag_command *cmd)
 {
-       int retval = ERROR_OK;
-
        DEBUG_JTAG_IO("statemove end in %s",
                tap_state_name(cmd->cmd.statemove->end_state));
 
@@ -311,20 +304,18 @@ static int ftdi_execute_statemove(struct jtag_command *cmd)
        /* shortest-path move to desired end state */
        if (tap_get_state() != tap_get_end_state() || tap_get_end_state() == TAP_RESET)
                move_to_state(tap_get_end_state());
-
-       return retval;
 }
 
 /**
  * Clock a bunch of TMS (or SWDIO) transitions, to change the JTAG
  * (or SWD) state machine. REVISIT: Not the best method, perhaps.
  */
-static int ftdi_execute_tms(struct jtag_command *cmd)
+static void ftdi_execute_tms(struct jtag_command *cmd)
 {
        DEBUG_JTAG_IO("TMS: %d bits", cmd->cmd.tms->num_bits);
 
        /* TODO: Missing tap state tracking, also missing from ft2232.c! */
-       return mpsse_clock_tms_cs_out(mpsse_ctx,
+       mpsse_clock_tms_cs_out(mpsse_ctx,
                cmd->cmd.tms->bits,
                0,
                cmd->cmd.tms->num_bits,
@@ -332,10 +323,8 @@ static int ftdi_execute_tms(struct jtag_command *cmd)
                JTAG_MODE);
 }
 
-static int ftdi_execute_pathmove(struct jtag_command *cmd)
+static void ftdi_execute_pathmove(struct jtag_command *cmd)
 {
-       int retval = ERROR_OK;
-
        tap_state_t *path = cmd->cmd.pathmove->path;
        int num_states  = cmd->cmd.pathmove->num_states;
 
@@ -350,7 +339,7 @@ static int ftdi_execute_pathmove(struct jtag_command *cmd)
        DEBUG_JTAG_IO("-");
 
        /* this loop verifies that the path is legal and logs each state in the path */
-       while (num_states-- && retval == ERROR_OK) {
+       while (num_states--) {
 
                /* either TMS=0 or TMS=1 must work ... */
                if (tap_state_transition(tap_get_state(), false)
@@ -373,7 +362,7 @@ static int ftdi_execute_pathmove(struct jtag_command *cmd)
                state_count++;
 
                if (bit_count == 7 || num_states == 0) {
-                       retval = mpsse_clock_tms_cs_out(mpsse_ctx,
+                       mpsse_clock_tms_cs_out(mpsse_ctx,
                                        &tms_byte,
                                        0,
                                        bit_count,
@@ -383,14 +372,10 @@ static int ftdi_execute_pathmove(struct jtag_command *cmd)
                }
        }
        tap_set_end_state(tap_get_state());
-
-       return retval;
 }
 
-static int ftdi_execute_scan(struct jtag_command *cmd)
+static void ftdi_execute_scan(struct jtag_command *cmd)
 {
-       int retval = ERROR_OK;
-
        DEBUG_JTAG_IO("%s type:%d", cmd->cmd.scan->ir_scan ? "IRSCAN" : "DRSCAN",
                jtag_scan_type(cmd->cmd.scan));
 
@@ -403,7 +388,7 @@ static int ftdi_execute_scan(struct jtag_command *cmd)
 
        if (cmd->cmd.scan->num_fields == 0) {
                LOG_DEBUG("empty scan, doing nothing");
-               return retval;
+               return;
        }
 
        if (cmd->cmd.scan->ir_scan) {
@@ -442,7 +427,7 @@ static int ftdi_execute_scan(struct jtag_command *cmd)
                        if (field->out_value)
                                bit_copy(&last_bit, 0, field->out_value, field->num_bits - 1, 1);
                        uint8_t tms_bits = 0x01;
-                       retval = mpsse_clock_tms_cs(mpsse_ctx,
+                       mpsse_clock_tms_cs(mpsse_ctx,
                                        &tms_bits,
                                        0,
                                        field->in_value,
@@ -451,7 +436,7 @@ static int ftdi_execute_scan(struct jtag_command *cmd)
                                        last_bit,
                                        JTAG_MODE);
                        tap_set_state(tap_state_transition(tap_get_state(), 1));
-                       retval = mpsse_clock_tms_cs_out(mpsse_ctx,
+                       mpsse_clock_tms_cs_out(mpsse_ctx,
                                        &tms_bits,
                                        1,
                                        1,
@@ -466,10 +451,6 @@ static int ftdi_execute_scan(struct jtag_command *cmd)
                                0,
                                field->num_bits,
                                JTAG_MODE);
-               if (retval != ERROR_OK) {
-                       LOG_ERROR("failed to add field %d in scan", i);
-                       return retval;
-               }
        }
 
        if (tap_get_state() != tap_get_end_state())
@@ -478,11 +459,9 @@ static int ftdi_execute_scan(struct jtag_command *cmd)
        DEBUG_JTAG_IO("%s scan, %i bits, end in %s",
                (cmd->cmd.scan->ir_scan) ? "IR" : "DR", scan_size,
                tap_state_name(tap_get_end_state()));
-       return retval;
-
 }
 
-static int ftdi_execute_reset(struct jtag_command *cmd)
+static void ftdi_execute_reset(struct jtag_command *cmd)
 {
        DEBUG_JTAG_IO("reset trst: %i srst %i",
                cmd->cmd.reset->trst, cmd->cmd.reset->srst);
@@ -514,27 +493,21 @@ static int ftdi_execute_reset(struct jtag_command *cmd)
 
        DEBUG_JTAG_IO("trst: %i, srst: %i",
                cmd->cmd.reset->trst, cmd->cmd.reset->srst);
-       return ERROR_OK;
 }
 
-static int ftdi_execute_sleep(struct jtag_command *cmd)
+static void ftdi_execute_sleep(struct jtag_command *cmd)
 {
-       int retval = ERROR_OK;
-
        DEBUG_JTAG_IO("sleep %" PRIi32, cmd->cmd.sleep->us);
 
-       retval = mpsse_flush(mpsse_ctx);
+       mpsse_flush(mpsse_ctx);
        jtag_sleep(cmd->cmd.sleep->us);
        DEBUG_JTAG_IO("sleep %" PRIi32 " usec while in %s",
                cmd->cmd.sleep->us,
                tap_state_name(tap_get_state()));
-       return retval;
 }
 
-static int ftdi_execute_stableclocks(struct jtag_command *cmd)
+static void ftdi_execute_stableclocks(struct jtag_command *cmd)
 {
-       int retval = ERROR_OK;
-
        /* this is only allowed while in a stable state.  A check for a stable
         * state was done in jtag_add_clocks()
         */
@@ -545,60 +518,53 @@ static int ftdi_execute_stableclocks(struct jtag_command *cmd)
 
        /* TODO: Use mpsse_clock_data with in=out=0 for this, if TMS can be set to
         * the correct level and remain there during the scan */
-       while (num_cycles > 0 && retval == ERROR_OK) {
+       while (num_cycles > 0) {
                /* there are no state transitions in this code, so omit state tracking */
                unsigned this_len = num_cycles > 7 ? 7 : num_cycles;
-               retval = mpsse_clock_tms_cs_out(mpsse_ctx, &tms, 0, this_len, false, JTAG_MODE);
+               mpsse_clock_tms_cs_out(mpsse_ctx, &tms, 0, this_len, false, JTAG_MODE);
                num_cycles -= this_len;
        }
 
        DEBUG_JTAG_IO("clocks %i while in %s",
                cmd->cmd.stableclocks->num_cycles,
                tap_state_name(tap_get_state()));
-       return retval;
 }
 
-static int ftdi_execute_command(struct jtag_command *cmd)
+static void ftdi_execute_command(struct jtag_command *cmd)
 {
-       int retval;
-
        switch (cmd->type) {
                case JTAG_RESET:
-                       retval = ftdi_execute_reset(cmd);
+                       ftdi_execute_reset(cmd);
                        break;
                case JTAG_RUNTEST:
-                       retval = ftdi_execute_runtest(cmd);
+                       ftdi_execute_runtest(cmd);
                        break;
                case JTAG_TLR_RESET:
-                       retval = ftdi_execute_statemove(cmd);
+                       ftdi_execute_statemove(cmd);
                        break;
                case JTAG_PATHMOVE:
-                       retval = ftdi_execute_pathmove(cmd);
+                       ftdi_execute_pathmove(cmd);
                        break;
                case JTAG_SCAN:
-                       retval = ftdi_execute_scan(cmd);
+                       ftdi_execute_scan(cmd);
                        break;
                case JTAG_SLEEP:
-                       retval = ftdi_execute_sleep(cmd);
+                       ftdi_execute_sleep(cmd);
                        break;
                case JTAG_STABLECLOCKS:
-                       retval = ftdi_execute_stableclocks(cmd);
+                       ftdi_execute_stableclocks(cmd);
                        break;
                case JTAG_TMS:
-                       retval = ftdi_execute_tms(cmd);
+                       ftdi_execute_tms(cmd);
                        break;
                default:
                        LOG_ERROR("BUG: unknown JTAG command type encountered: %d", cmd->type);
-                       retval = ERROR_JTAG_QUEUE_FAILED;
                        break;
        }
-       return retval;
 }
 
 static int ftdi_execute_queue(void)
 {
-       int retval = ERROR_OK;
-
        /* blink, if the current layout has that feature */
        struct signal *led = find_signal_by_name("LED");
        if (led)
@@ -606,14 +572,13 @@ static int ftdi_execute_queue(void)
 
        for (struct jtag_command *cmd = jtag_command_queue; cmd; cmd = cmd->next) {
                /* fill the write buffer with the desired command */
-               if (ftdi_execute_command(cmd) != ERROR_OK)
-                       retval = ERROR_JTAG_QUEUE_FAILED;
+               ftdi_execute_command(cmd);
        }
 
        if (led)
                ftdi_set_signal(led, '0');
 
-       retval = mpsse_flush(mpsse_ctx);
+       int retval = mpsse_flush(mpsse_ctx);
        if (retval != ERROR_OK)
                LOG_ERROR("error while flushing MPSSE queue: %d", retval);
 
@@ -622,8 +587,6 @@ static int ftdi_execute_queue(void)
 
 static int ftdi_initialize(void)
 {
-       int retval;
-
        if (tap_get_tms_path_len(TAP_IRPAUSE, TAP_IRPAUSE) == 7)
                LOG_DEBUG("ftdi interface using 7 step jtag state transitions");
        else
@@ -639,19 +602,10 @@ static int ftdi_initialize(void)
        if (!mpsse_ctx)
                return ERROR_JTAG_INIT_FAILED;
 
-       retval = mpsse_set_data_bits_low_byte(mpsse_ctx, output & 0xff, direction & 0xff);
-       if (retval == ERROR_OK)
-               retval = mpsse_set_data_bits_high_byte(mpsse_ctx, output >> 8, direction >> 8);
-       if (retval != ERROR_OK) {
-               LOG_ERROR("couldn't initialize FTDI with configured layout");
-               return ERROR_JTAG_INIT_FAILED;
-       }
+       mpsse_set_data_bits_low_byte(mpsse_ctx, output & 0xff, direction & 0xff);
+       mpsse_set_data_bits_high_byte(mpsse_ctx, output >> 8, direction >> 8);
 
-       retval = mpsse_loopback_config(mpsse_ctx, false);
-       if (retval != ERROR_OK) {
-               LOG_ERROR("couldn't write to FTDI to disable loopback");
-               return ERROR_JTAG_INIT_FAILED;
-       }
+       mpsse_loopback_config(mpsse_ctx, false);
 
        return mpsse_flush(mpsse_ctx);
 }

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)