Duane Ellis: fix warnings
[fw/openocd] / src / jtag / jtag.c
index cbf52f09306b088d96df25a5da2f2f22420a7431..d34cec5a257b3187221eadb7b9870408ff3f2d87 100644 (file)
@@ -2,6 +2,9 @@
  *   Copyright (C) 2005 by Dominic Rath                                    *
  *   Dominic.Rath@gmx.de                                                   *
  *                                                                         *
+ *   Copyright (C) 2007,2008 Ã˜yvind Harboe                                      *
+ *   oyvind.harboe@zylin.com                                               *
+ *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
  *   the Free Software Foundation; either version 2 of the License, or     *
@@ -398,7 +401,7 @@ void* cmd_queue_alloc(size_t size)
        return t + offset;
 }
 
-void cmd_queue_free()
+void cmd_queue_free(void)
 {
        cmd_queue_page_t *page = cmd_queue_pages;
 
@@ -413,7 +416,7 @@ void cmd_queue_free()
        cmd_queue_pages = NULL;
 }
 
-static void jtag_prelude1()
+static void jtag_prelude1(void)
 {
        if (jtag_trst == 1)
        {
@@ -851,6 +854,11 @@ void jtag_add_pathmove(int num_states, enum tap_state *path)
 
        for (i=0; i<num_states; i++)
        {
+               if (path[i] == TAP_TLR)
+               {
+                       LOG_ERROR("BUG: TAP_TLR is not a valid state for pathmove sequences");
+                       exit(-1);
+               }
                if ((tap_transitions[cur_state].low != path[i])&&
                                (tap_transitions[cur_state].high != path[i]))
                {
@@ -1358,6 +1366,8 @@ int jtag_examine_chain()
                        /* LSB must not be 0, this indicates a device in bypass */
                        device_count++;
                        
+                       LOG_WARNING("Device was in bypass after TRST/TMS reset");
+                       
                        bit_count += 1;
                }
                else
@@ -1368,7 +1378,28 @@ int jtag_examine_chain()
                        
                        if (idcode == 0x000000FF)
                        {
-                               /* End of chain (invalid manufacturer ID) */
+                               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))
+                                       {
+                                               LOG_WARNING("Unexpected idcode after end of chain! %d 0x%08x", bit_count, idcode);
+                                               unexpected = 1;
+                                       }
+                               }
+                               
                                break;
                        }
                        
@@ -1402,7 +1433,7 @@ int jtag_examine_chain()
        return ERROR_OK;
 }
 
-int jtag_validate_chain()
+int jtag_validate_chain(void)
 {
        jtag_device_t *device = jtag_devices;
        int total_ir_length = 0;