summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarc Pignat <marc.pignat@hevs.ch>2010-06-17 10:07:22 +0200
committerØyvind Harboe <oyvind.harboe@zylin.com>2010-07-01 09:32:56 +0200
commitdd88b461da1cb8642200dd5c96fb1ff384ca9f7b (patch)
treedaec77dd4093ba3394f5ab62bd97d992a974d490 /src
parentcd7f4431036355213f8d3daa12c95be978f9e64a (diff)
downloadopenocd+libswd-dd88b461da1cb8642200dd5c96fb1ff384ca9f7b.tar.gz
openocd+libswd-dd88b461da1cb8642200dd5c96fb1ff384ca9f7b.tar.bz2
openocd+libswd-dd88b461da1cb8642200dd5c96fb1ff384ca9f7b.tar.xz
openocd+libswd-dd88b461da1cb8642200dd5c96fb1ff384ca9f7b.zip
ft2232: simplify ft2232_read_scan
Diffstat (limited to 'src')
-rw-r--r--src/jtag/drivers/ft2232.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/jtag/drivers/ft2232.c b/src/jtag/drivers/ft2232.c
index bc8463e6..9d40b1c0 100644
--- a/src/jtag/drivers/ft2232.c
+++ b/src/jtag/drivers/ft2232.c
@@ -714,23 +714,24 @@ static void ft2232_end_state(tap_state_t state)
static void ft2232_read_scan(enum scan_type type, uint8_t* buffer, int scan_size)
{
- int num_bytes = (scan_size + 7) / 8;
- int bits_left = scan_size;
- int cur_byte = 0;
+ int num_bytes = scan_size / 8;
+ int bits_left = scan_size % 8;
+ int cur_byte;
- while (num_bytes-- > 1)
+ for (cur_byte = 0; cur_byte < num_bytes; cur_byte++)
{
- buffer[cur_byte++] = buffer_read();
- bits_left -= 8;
+ buffer[cur_byte] = buffer_read();
}
- buffer[cur_byte] = 0x0;
-
- /* There is one more partial byte left from the clock data in/out instructions */
+ /* Manage partial byte left from the clock data in/out instructions, if any */
if (bits_left > 1)
{
buffer[cur_byte] = buffer_read() >> 1;
}
+ else
+ {
+ buffer[cur_byte] = 0x0;
+ }
/* This shift depends on the length of the clock data to tms instruction, insterted at end of the scan, now fixed to a two step transition in ft2232_add_scan */
buffer[cur_byte] = (buffer[cur_byte] | (((buffer_read()) << 1) & 0x80)) >> (8 - bits_left);
}