Factoring of jtag_examine_chain for maintainability:
authorzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Sun, 7 Jun 2009 05:23:40 +0000 (05:23 +0000)
committerzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Sun, 7 Jun 2009 05:23:40 +0000 (05:23 +0000)
- Factor end-of-chain verfication into new helper routine.
- Change 'unexpected' local variable name to 'triggered' and type to bool.

git-svn-id: svn://svn.berlios.de/openocd/trunk@2086 b42882b7-edfa-0310-969c-e2dbd0fdcd60

src/jtag/jtag.c

index 8774bbba09f9564dd0dafc8833ab83e26a22bfaa..0bc1c4ffbe3dafad2befcb3b45d3ee341f3ec1c0 100644 (file)
@@ -995,6 +995,27 @@ static void jtag_examine_chain_display(enum log_levels level, const char *msg,
                EXTRACT_MFG(idcode), EXTRACT_PART(idcode), EXTRACT_VER(idcode) );
 }
 
+/**
+ * This helper checks that remaining bits in the examined chain data are
+ * all as expected, but a single JTAG device requires only 64 bits to be
+ * read back correctly.  This can help identify and diagnose problems
+ * with the JTAG chain earlier, gives more helpful/explicit error messages.
+ */
+static void jtag_examine_chain_end(u8 *idcodes, unsigned count, unsigned max)
+{
+       bool triggered = false;
+       for ( ; count < max - 31; count += 32)
+       {
+               u32 idcode = buf_get_u32(idcodes, count, 32);
+               // do not trigger the warning if the data looks good
+               if (!triggered && (idcode == 0x000000FF || idcode == 0xFFFFFFFF))
+                       continue;
+               LOG_WARNING("Unexpected idcode after end of chain: %d 0x%08x",
+                               count, idcode);
+               triggered = true;
+       }
+}
+
 /* Try to examine chain layout according to IEEE 1149.1 ยง12
  */
 static int jtag_examine_chain(void)
@@ -1029,32 +1050,15 @@ static int jtag_examine_chain(void)
                }
                else
                {
-                       /* some devices, such as AVR will output all 1's instead of TDI
-                       input value at end of chain. */
+                       /*
+                        * End of chain (invalid manufacturer ID) some devices, such
+                        * as AVR will output all 1's instead of TDI input value at
+                        * end of chain.
+                        */
                        if ((idcode == 0x000000FF)||(idcode == 0xFFFFFFFF))
                        {
-                               int unexpected=0;
-                               /* End of chain (invalid manufacturer ID)
-                                *
-                                * The JTAG examine is the very first thing that happens
-                                *
-                                * A single JTAG device requires only 64 bits to be read back correctly.
-                                *
-                                * The code below adds a check that the rest of the data scanned (640 bits)
-                                * are all as expected. This helps diagnose/catch problems with the JTAG chain
-                                *
-                                * earlier and gives more helpful/explicit error messages.
-                                */
-                               for (bit_count += 32; bit_count < (JTAG_MAX_CHAIN_SIZE * 32) - 31;bit_count += 32)
-                               {
-                                       idcode = buf_get_u32(idcode_buffer, bit_count, 32);
-                                       if (unexpected||((idcode != 0x000000FF)&&(idcode != 0xFFFFFFFF)))
-                                       {
-                                               LOG_WARNING("Unexpected idcode after end of chain! %d 0x%08x", bit_count, idcode);
-                                               unexpected = 1;
-                                       }
-                               }
-
+                               jtag_examine_chain_end(idcode_buffer,
+                                               bit_count + 32, JTAG_MAX_CHAIN_SIZE * 32);
                                break;
                        }
 

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)