zy1000: clean up jtag_add_xx_scan fn's
The implementation is now more straightforward as the scan_fields have been greatly simplified over time. Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
This commit is contained in:
parent
03359b1680
commit
7373d1c342
|
@ -492,57 +492,32 @@ static void shiftValueInnerFlip(const tap_state_t state, const tap_state_t endSt
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void gotoEndState(tap_state_t end_state)
|
|
||||||
{
|
|
||||||
setCurrentState(end_state);
|
|
||||||
}
|
|
||||||
|
|
||||||
static __inline void scanFields(int num_fields, const struct scan_field *fields, tap_state_t shiftState, int pause)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
int k;
|
|
||||||
|
|
||||||
for (i = 0; i < num_fields; i++)
|
|
||||||
{
|
|
||||||
cyg_uint32 value;
|
|
||||||
|
|
||||||
uint8_t *inBuffer = NULL;
|
|
||||||
|
|
||||||
|
|
||||||
// figure out where to store the input data
|
|
||||||
int num_bits = fields[i].num_bits;
|
|
||||||
if (fields[i].in_value != NULL)
|
|
||||||
{
|
|
||||||
inBuffer = fields[i].in_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// here we shuffle N bits out/in
|
// here we shuffle N bits out/in
|
||||||
j = 0;
|
static __inline void scanBits(const uint8_t *out_value, uint8_t *in_value, int num_bits, bool pause, tap_state_t shiftState, tap_state_t end_state)
|
||||||
while (j < num_bits)
|
|
||||||
{
|
{
|
||||||
tap_state_t pause_state;
|
tap_state_t pause_state = shiftState;
|
||||||
int l;
|
for (int j = 0; j < num_bits; j += 32)
|
||||||
k = num_bits-j;
|
{
|
||||||
pause_state = (shiftState == TAP_DRSHIFT)?TAP_DRSHIFT:TAP_IRSHIFT;
|
int k = num_bits - j;
|
||||||
if (k > 32)
|
if (k > 32)
|
||||||
{
|
{
|
||||||
k = 32;
|
k = 32;
|
||||||
/* we have more to shift out */
|
/* we have more to shift out */
|
||||||
} else if (pause&&(i == num_fields-1))
|
} else if (pause)
|
||||||
{
|
{
|
||||||
/* this was the last to shift out this time */
|
/* this was the last to shift out this time */
|
||||||
pause_state = (shiftState==TAP_DRSHIFT)?TAP_DRPAUSE:TAP_IRPAUSE;
|
pause_state = end_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
// we have (num_bits + 7)/8 bytes of bits to toggle out.
|
// we have (num_bits + 7)/8 bytes of bits to toggle out.
|
||||||
// bits are pushed out LSB to MSB
|
// bits are pushed out LSB to MSB
|
||||||
|
cyg_uint32 value;
|
||||||
value = 0;
|
value = 0;
|
||||||
if (fields[i].out_value != NULL)
|
if (out_value != NULL)
|
||||||
{
|
{
|
||||||
for (l = 0; l < k; l += 8)
|
for (int l = 0; l < k; l += 8)
|
||||||
{
|
{
|
||||||
value|=fields[i].out_value[(j + l)/8]<<l;
|
value|=out_value[(j + l)/8]<<l;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* mask away unused bits for easier debugging */
|
/* mask away unused bits for easier debugging */
|
||||||
|
@ -557,38 +532,53 @@ static __inline void scanFields(int num_fields, const struct scan_field *fields,
|
||||||
|
|
||||||
shiftValueInner(shiftState, pause_state, k, value);
|
shiftValueInner(shiftState, pause_state, k, value);
|
||||||
|
|
||||||
if (inBuffer != NULL)
|
if (in_value != NULL)
|
||||||
{
|
{
|
||||||
// data in, LSB to MSB
|
// data in, LSB to MSB
|
||||||
value = getShiftValue();
|
value = getShiftValue();
|
||||||
// we're shifting in data to MSB, shift data to be aligned for returning the value
|
// we're shifting in data to MSB, shift data to be aligned for returning the value
|
||||||
value >>= 32-k;
|
value >>= 32-k;
|
||||||
|
|
||||||
for (l = 0; l < k; l += 8)
|
for (int l = 0; l < k; l += 8)
|
||||||
{
|
{
|
||||||
inBuffer[(j + l)/8]=(value >> l)&0xff;
|
in_value[(j + l)/8]=(value >> l)&0xff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
j += k;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static __inline void scanFields(int num_fields, const struct scan_field *fields, tap_state_t shiftState, tap_state_t end_state)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < num_fields; i++)
|
||||||
|
{
|
||||||
|
scanBits(fields[i].out_value,
|
||||||
|
fields[i].in_value,
|
||||||
|
fields[i].num_bits,
|
||||||
|
(i == num_fields-1),
|
||||||
|
shiftState,
|
||||||
|
end_state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int interface_jtag_add_ir_scan(struct jtag_tap *active, const struct scan_field *fields, tap_state_t state)
|
int interface_jtag_add_ir_scan(struct jtag_tap *active, const struct scan_field *fields, tap_state_t state)
|
||||||
{
|
{
|
||||||
int scan_size = 0;
|
int scan_size = 0;
|
||||||
struct jtag_tap *tap, *nextTap;
|
struct jtag_tap *tap, *nextTap;
|
||||||
|
tap_state_t pause_state = TAP_IRSHIFT;
|
||||||
|
|
||||||
for (tap = jtag_tap_next_enabled(NULL); tap!= NULL; tap = nextTap)
|
for (tap = jtag_tap_next_enabled(NULL); tap!= NULL; tap = nextTap)
|
||||||
{
|
{
|
||||||
nextTap = jtag_tap_next_enabled(tap);
|
nextTap = jtag_tap_next_enabled(tap);
|
||||||
bool pause = (nextTap==NULL);
|
if (nextTap==NULL)
|
||||||
|
{
|
||||||
|
pause_state = state;
|
||||||
|
}
|
||||||
scan_size = tap->ir_length;
|
scan_size = tap->ir_length;
|
||||||
|
|
||||||
/* search the list */
|
/* search the list */
|
||||||
if (tap == active)
|
if (tap == active)
|
||||||
{
|
{
|
||||||
scanFields(1, fields, TAP_IRSHIFT, pause);
|
scanFields(1, fields, TAP_IRSHIFT, pause_state);
|
||||||
/* update device information */
|
/* update device information */
|
||||||
buf_cpy(fields[0].out_value, tap->cur_instr, scan_size);
|
buf_cpy(fields[0].out_value, tap->cur_instr, scan_size);
|
||||||
|
|
||||||
|
@ -597,12 +587,11 @@ int interface_jtag_add_ir_scan(struct jtag_tap *active, const struct scan_field
|
||||||
{
|
{
|
||||||
/* if a device isn't listed, set it to BYPASS */
|
/* if a device isn't listed, set it to BYPASS */
|
||||||
assert(scan_size <= 32);
|
assert(scan_size <= 32);
|
||||||
shiftValueInner(TAP_IRSHIFT, pause?TAP_IRPAUSE:TAP_IRSHIFT, scan_size, 0xffffffff);
|
shiftValueInner(TAP_IRSHIFT, pause_state, scan_size, 0xffffffff);
|
||||||
|
|
||||||
tap->bypass = 1;
|
tap->bypass = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gotoEndState(state);
|
|
||||||
|
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
@ -613,51 +602,41 @@ int interface_jtag_add_ir_scan(struct jtag_tap *active, const struct scan_field
|
||||||
|
|
||||||
int interface_jtag_add_plain_ir_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits, tap_state_t state)
|
int interface_jtag_add_plain_ir_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits, tap_state_t state)
|
||||||
{
|
{
|
||||||
struct scan_field field;
|
scanBits(out_bits, in_bits, num_bits, true, TAP_IRSHIFT, state);
|
||||||
field.num_bits = num_bits;
|
|
||||||
field.out_value = out_bits;
|
|
||||||
field.in_value = in_bits;
|
|
||||||
|
|
||||||
scanFields(1, &field, TAP_IRSHIFT, 1);
|
|
||||||
gotoEndState(state);
|
|
||||||
|
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int interface_jtag_add_dr_scan(struct jtag_tap *active, int num_fields, const struct scan_field *fields, tap_state_t state)
|
int interface_jtag_add_dr_scan(struct jtag_tap *active, int num_fields, const struct scan_field *fields, tap_state_t state)
|
||||||
{
|
{
|
||||||
struct jtag_tap *tap, *nextTap;
|
struct jtag_tap *tap, *nextTap;
|
||||||
|
tap_state_t pause_state = TAP_DRSHIFT;
|
||||||
for (tap = jtag_tap_next_enabled(NULL); tap!= NULL; tap = nextTap)
|
for (tap = jtag_tap_next_enabled(NULL); tap!= NULL; tap = nextTap)
|
||||||
{
|
{
|
||||||
nextTap = jtag_tap_next_enabled(tap);
|
nextTap = jtag_tap_next_enabled(tap);
|
||||||
bool pause = (nextTap==NULL);
|
if (nextTap==NULL)
|
||||||
|
{
|
||||||
|
pause_state = state;
|
||||||
|
}
|
||||||
|
|
||||||
/* Find a range of fields to write to this tap */
|
/* Find a range of fields to write to this tap */
|
||||||
if (tap == active)
|
if (tap == active)
|
||||||
{
|
{
|
||||||
assert(!tap->bypass);
|
assert(!tap->bypass);
|
||||||
|
|
||||||
scanFields(num_fields, fields, TAP_DRSHIFT, pause);
|
scanFields(num_fields, fields, TAP_DRSHIFT, pause_state);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
/* Shift out a 0 for disabled tap's */
|
/* Shift out a 0 for disabled tap's */
|
||||||
assert(tap->bypass);
|
assert(tap->bypass);
|
||||||
shiftValueInner(TAP_DRSHIFT, pause?TAP_DRPAUSE:TAP_DRSHIFT, 1, 0);
|
shiftValueInner(TAP_DRSHIFT, pause_state, 1, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gotoEndState(state);
|
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int interface_jtag_add_plain_dr_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits, tap_state_t state)
|
int interface_jtag_add_plain_dr_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits, tap_state_t state)
|
||||||
{
|
{
|
||||||
struct scan_field field;
|
scanBits(out_bits, in_bits, num_bits, true, TAP_DRSHIFT, state);
|
||||||
field.num_bits = num_bits;
|
|
||||||
field.out_value = out_bits;
|
|
||||||
field.in_value = in_bits;
|
|
||||||
|
|
||||||
scanFields(1, &field, TAP_DRSHIFT, 1);
|
|
||||||
gotoEndState(state);
|
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue