Use parse_uint helper to replace strtoul call in jtag_tap_by_string.
[openocd.git] / src / jtag / core.c
index 4d4d278347ffc0963b40633d362545f3d3ad9176..4c91abeeed7c8c40d653a60c1e48863b45c72e46 100644 (file)
@@ -103,7 +103,7 @@ static int speed_khz = 0;
 static bool hasKHz = false;
 static int jtag_speed = 0;
 
-struct jtag_interface_s *jtag = NULL;
+static struct jtag_interface_s *jtag = NULL;
 
 /* configuration */
 jtag_interface_t *jtag_interface = NULL;
@@ -172,9 +172,8 @@ jtag_tap_t *jtag_tap_by_string(const char *s)
        }
 
        /* no tap found by name, so try to parse the name as a number */
-       char *cp;
-       unsigned n = strtoul(s, &cp, 0);
-       if ((s == cp) || (*cp != 0))
+       unsigned n;
+       if (parse_uint(s, &n) != ERROR_OK)
                return NULL;
 
        return jtag_tap_by_position(n);
@@ -202,6 +201,18 @@ jtag_tap_t *jtag_tap_by_position(unsigned n)
        return t;
 }
 
+jtag_tap_t* jtag_tap_next_enabled(jtag_tap_t* p)
+{
+       p = p ? p->next_tap : jtag_all_taps();
+       while (p)
+       {
+               if (p->enabled)
+                       return p;
+               p = p->next_tap;
+       }
+       return NULL;
+}
+
 const char *jtag_tap_name(const jtag_tap_t *tap)
 {
        return (tap == NULL) ? "(unknown)" : tap->dotted_name;
@@ -476,6 +487,50 @@ void jtag_add_pathmove(int num_states, const tap_state_t *path)
        cmd_queue_cur_state = path[num_states - 1];
 }
 
+int jtag_add_statemove(tap_state_t goal_state)
+{
+       tap_state_t cur_state = cmd_queue_cur_state;
+
+       LOG_DEBUG( "cur_state=%s goal_state=%s",
+               tap_state_name(cur_state),
+               tap_state_name(goal_state) );
+
+
+       if (goal_state==cur_state )
+               ;       /* nothing to do */
+       else if( goal_state==TAP_RESET )
+       {
+               jtag_add_tlr();
+       }
+       else if( tap_is_state_stable(cur_state) && tap_is_state_stable(goal_state) )
+       {
+               unsigned tms_bits  = tap_get_tms_path(cur_state, goal_state);
+               unsigned tms_count = tap_get_tms_path_len(cur_state, goal_state);
+               tap_state_t moves[8];
+               assert(tms_count < DIM(moves));
+
+               for (unsigned i = 0; i < tms_count; i++, tms_bits >>= 1)
+               {
+                       bool bit = tms_bits & 1;
+
+                       cur_state = tap_state_transition(cur_state, bit);
+                       moves[i] = cur_state;
+               }
+
+               jtag_add_pathmove(tms_count, moves);
+       }
+       else if( tap_state_transition(cur_state, true)  == goal_state
+               ||   tap_state_transition(cur_state, false) == goal_state )
+       {
+               jtag_add_pathmove(1, &goal_state);
+       }
+
+       else
+               return ERROR_FAIL;
+
+       return ERROR_OK;
+}
+
 void jtag_add_runtest(int num_cycles, tap_state_t state)
 {
        jtag_prelude(state);
@@ -1178,6 +1233,27 @@ unsigned jtag_get_speed_khz(void)
 {
        return speed_khz;
 }
+int jtag_config_khz(unsigned khz)
+{
+       LOG_DEBUG("handle jtag khz");
+       jtag_set_speed_khz(khz);
+
+       int cur_speed = 0;
+       if (jtag != NULL)
+       {
+               LOG_DEBUG("have interface set up");
+               int speed_div1;
+               int retval = jtag->khz(jtag_get_speed_khz(), &speed_div1);
+               if (ERROR_OK != retval)
+               {
+                       jtag_set_speed_khz(0);
+                       return retval;
+               }
+               cur_speed = speed_div1;
+       }
+       return jtag_set_speed(cur_speed);
+}
+
 int jtag_get_speed(void)
 {
        return jtag_speed;
@@ -1192,6 +1268,12 @@ int jtag_set_speed(int speed)
        return jtag ? jtag->speed(speed) : ERROR_OK;
 }
 
+int jtag_get_speed_readable(int *speed)
+{
+       return jtag ? jtag->speed_div(jtag_get_speed(), speed) : ERROR_OK;
+}
+
+
 void jtag_set_verify(bool enable)
 {
        jtag_verify = enable;
@@ -1222,50 +1304,6 @@ int jtag_srst_asserted(int *srst_asserted)
        return jtag->srst_asserted(srst_asserted);
 }
 
-int jtag_add_statemove(tap_state_t goal_state)
-{
-       tap_state_t cur_state = cmd_queue_cur_state;
-
-       LOG_DEBUG( "cur_state=%s goal_state=%s",
-               tap_state_name(cur_state),
-               tap_state_name(goal_state) );
-
-
-       if (goal_state==cur_state )
-               ;       /* nothing to do */
-       else if( goal_state==TAP_RESET )
-       {
-               jtag_add_tlr();
-       }
-       else if( tap_is_state_stable(cur_state) && tap_is_state_stable(goal_state) )
-       {
-               unsigned tms_bits  = tap_get_tms_path(cur_state, goal_state);
-               unsigned tms_count = tap_get_tms_path_len(cur_state, goal_state);
-               tap_state_t moves[8];
-               assert(tms_count < DIM(moves));
-
-               for (unsigned i = 0; i < tms_count; i++, tms_bits >>= 1)
-               {
-                       bool bit = tms_bits & 1;
-
-                       cur_state = tap_state_transition(cur_state, bit);
-                       moves[i] = cur_state;
-               }
-
-               jtag_add_pathmove(tms_count, moves);
-       }
-       else if( tap_state_transition(cur_state, true)  == goal_state
-               ||   tap_state_transition(cur_state, false) == goal_state )
-       {
-               jtag_add_pathmove(1, &goal_state);
-       }
-
-       else
-               return ERROR_FAIL;
-
-       return ERROR_OK;
-}
-
 enum reset_types jtag_get_reset_config(void)
 {
        return jtag_reset_config;

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)