]> git.sur5r.net Git - openocd/blobdiff - src/jtag/core.c
1.54 snapshot
[openocd] / src / jtag / core.c
index 58c8e3415d347a47fc813a92490d22552ed00c47..c721b91b038efeca372167aa4b02a0b308e24800 100644 (file)
@@ -162,10 +162,22 @@ void jtag_tap_add(struct jtag_tap_s *t)
        *tap = t;
 }
 
+/* returns a pointer to the n-th device in the scan chain */
+static inline jtag_tap_t *jtag_tap_by_position(unsigned n)
+{
+       jtag_tap_t *t = jtag_all_taps();
+
+       while (t && n-- > 0)
+               t = t->next_tap;
+
+       return t;
+}
+
 jtag_tap_t *jtag_tap_by_string(const char *s)
 {
        /* try by name first */
        jtag_tap_t *t = jtag_all_taps();
+
        while (t)
        {
                if (0 == strcmp(t->dotted_name, s))
@@ -178,7 +190,16 @@ jtag_tap_t *jtag_tap_by_string(const char *s)
        if (parse_uint(s, &n) != ERROR_OK)
                return NULL;
 
-       return jtag_tap_by_position(n);
+       /* FIXME remove this numeric fallback code late June 2010, along
+        * with all info in the User's Guide that TAPs have numeric IDs.
+        * Also update "scan_chain" output to not display the numbers.
+        */
+       t = jtag_tap_by_position(n);
+       if (t)
+               LOG_WARNING("Specify TAP '%s' by name, not number %u",
+                       t->dotted_name, n);
+
+       return t;
 }
 
 jtag_tap_t *jtag_tap_by_jim_obj(Jim_Interp *interp, Jim_Obj *o)
@@ -192,17 +213,6 @@ jtag_tap_t *jtag_tap_by_jim_obj(Jim_Interp *interp, Jim_Obj *o)
        return t;
 }
 
-/* returns a pointer to the n-th device in the scan chain */
-jtag_tap_t *jtag_tap_by_position(unsigned n)
-{
-       jtag_tap_t *t = jtag_all_taps();
-
-       while (t && n-- > 0)
-               t = t->next_tap;
-
-       return t;
-}
-
 jtag_tap_t* jtag_tap_next_enabled(jtag_tap_t* p)
 {
        p = p ? p->next_tap : jtag_all_taps();
@@ -505,16 +515,16 @@ int jtag_add_statemove(tap_state_t goal_state)
 
        LOG_DEBUG("cur_state=%s goal_state=%s",
                tap_state_name(cur_state),
-               tap_state_name(goal_state) );
+               tap_state_name(goal_state));
 
 
-       if (goal_state == cur_state )
+       if (goal_state == cur_state)
                ;       /* nothing to do */
-       else if (goal_state == TAP_RESET )
+       else if (goal_state == TAP_RESET)
        {
                jtag_add_tlr();
        }
-       else if (tap_is_state_stable(cur_state) && tap_is_state_stable(goal_state) )
+       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);
@@ -532,7 +542,7 @@ int jtag_add_statemove(tap_state_t goal_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 )
+               ||   tap_state_transition(cur_state, false) == goal_state)
        {
                jtag_add_pathmove(1, &goal_state);
        }
@@ -704,7 +714,7 @@ int jtag_check_value_inner(uint8_t *captured, uint8_t *in_check_value, uint8_t *
        else
                compare_failed = buf_cmp(captured, in_check_value, num_bits);
 
-       if (compare_failed){
+       if (compare_failed) {
                /* An error handler could have caught the failing check
                 * only report a problem when there wasn't a handler, or if the handler
                 * acknowledged the error
@@ -864,11 +874,11 @@ static void jtag_examine_chain_display(enum log_levels level, const char *msg,
        log_printf_lf(level, __FILE__, __LINE__, __FUNCTION__,
                                  "JTAG tap: %s %16.16s: 0x%08x "
                                  "(mfg: 0x%3.3x, part: 0x%4.4x, ver: 0x%1.1x)",
-                                 name, msg, 
+                                 name, msg,
                                  (unsigned int)idcode,
-                                 (unsigned int)EXTRACT_MFG(idcode), 
-                                 (unsigned int)EXTRACT_PART(idcode), 
-                                 (unsigned int)EXTRACT_VER(idcode) );
+                                 (unsigned int)EXTRACT_MFG(idcode),
+                                 (unsigned int)EXTRACT_PART(idcode),
+                                 (unsigned int)EXTRACT_VER(idcode));
 }
 
 static bool jtag_idcode_is_final(uint32_t idcode)
@@ -1024,9 +1034,9 @@ int jtag_validate_chain(void)
 
        tap = NULL;
        total_ir_length = 0;
-       for (;;){
+       for (;;) {
                tap = jtag_tap_next_enabled(tap);
-               if (tap == NULL ){
+               if (tap == NULL{
                        break;
                }
                total_ir_length += tap->ir_length;
@@ -1048,9 +1058,9 @@ int jtag_validate_chain(void)
        tap = NULL;
        chain_pos = 0;
        int val;
-       for (;;){
+       for (;;) {
                tap = jtag_tap_next_enabled(tap);
-               if (tap == NULL ){
+               if (tap == NULL{
                        break;
                }
 
@@ -1111,7 +1121,7 @@ void jtag_tap_free(jtag_tap_t *tap)
 {
        jtag_unregister_event_callback(&jtag_reset_callback, tap);
 
-       /// @todo is anything missing? no memory leaks please 
+       /// @todo is anything missing? no memory leaks please
        free((void *)tap->expected_ids);
        free((void *)tap->chip);
        free((void *)tap->tapname);
@@ -1151,7 +1161,7 @@ static int jtag_init_inner(struct command_context_s *cmd_ctx)
        LOG_DEBUG("Init JTAG chain");
 
        tap = jtag_tap_next_enabled(NULL);
-       if (tap == NULL ){
+       if (tap == NULL{
                LOG_ERROR("There are no enabled taps?");
                return ERROR_JTAG_INIT_FAILED;
        }