summaryrefslogtreecommitdiff
path: root/src/jtag
diff options
context:
space:
mode:
authorzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2009-06-07 05:23:13 +0000
committerzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2009-06-07 05:23:13 +0000
commitc318068839e39ac0c2186c6af9e469eda4eff9fc (patch)
tree68c76f3901aa5e978558959ecdaf550f2d0bf182 /src/jtag
parent90dbfcea7d49a96c0449012a7996281c08b34604 (diff)
downloadopenocd+libswd-c318068839e39ac0c2186c6af9e469eda4eff9fc.tar.gz
openocd+libswd-c318068839e39ac0c2186c6af9e469eda4eff9fc.tar.bz2
openocd+libswd-c318068839e39ac0c2186c6af9e469eda4eff9fc.tar.xz
openocd+libswd-c318068839e39ac0c2186c6af9e469eda4eff9fc.zip
Factoring of jtag_examine_chain for maintainability:
- Factor initial chain examination check into new static helper. git-svn-id: svn://svn.berlios.de/openocd/trunk@2084 b42882b7-edfa-0310-969c-e2dbd0fdcd60
Diffstat (limited to 'src/jtag')
-rw-r--r--src/jtag/jtag.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/jtag/jtag.c b/src/jtag/jtag.c
index a3d86ade..03462d6b 100644
--- a/src/jtag/jtag.c
+++ b/src/jtag/jtag.c
@@ -963,32 +963,41 @@ static int jtag_examine_chain_execute(u8 *idcode_buffer, unsigned num_idcode)
return jtag_execute_queue();
}
+static bool jtag_examine_chain_check(u8 *idcodes, unsigned count)
+{
+ u8 zero_check = 0x0;
+ u8 one_check = 0xff;
+
+ for (unsigned i = 0; i < count * 4; i++)
+ {
+ zero_check |= idcodes[i];
+ one_check &= idcodes[i];
+ }
+
+ /* if there wasn't a single non-zero bit or if all bits were one,
+ * the scan is not valid */
+ if (zero_check == 0x00 || one_check == 0xff)
+ {
+ LOG_ERROR("JTAG communication failure: check connection, "
+ "JTAG interface, target power etc.");
+ return false;
+ }
+ return true;
+}
+
/* Try to examine chain layout according to IEEE 1149.1 §12
*/
static int jtag_examine_chain(void)
{
jtag_tap_t *tap;
u8 idcode_buffer[JTAG_MAX_CHAIN_SIZE * 4];
- int i;
int bit_count;
int device_count = 0;
- u8 zero_check = 0x0;
- u8 one_check = 0xff;
jtag_examine_chain_execute(idcode_buffer, JTAG_MAX_CHAIN_SIZE);
- for (i = 0; i < JTAG_MAX_CHAIN_SIZE * 4; i++)
- {
- zero_check |= idcode_buffer[i];
- one_check &= idcode_buffer[i];
- }
-
- /* if there wasn't a single non-zero bit or if all bits were one, the scan isn't valid */
- if ((zero_check == 0x00) || (one_check == 0xff))
- {
- LOG_ERROR("JTAG communication failure, check connection, JTAG interface, target power etc.");
+ if (!jtag_examine_chain_check(idcode_buffer, JTAG_MAX_CHAIN_SIZE))
return ERROR_JTAG_INIT_FAILED;
- }
/* point at the 1st tap */
tap = jtag_tap_next_enabled(NULL);