for (jtag_tap_t * tap = jtag_NextEnabledTap(NULL); tap != NULL; tap = jtag_NextEnabledTap(tap))
{
- int found = 0;
+ /* search the input field list for fields for the current TAP */
- size_t scan_size = tap->ir_length;
+ bool found = false;
- /* search the list */
for (int j = 0; j < in_num_fields; j++)
{
- if (tap == in_fields[j].tap)
- {
- found = 1;
+ if (tap != in_fields[j].tap)
+ continue;
- tap->bypass = 0;
-
- assert(in_fields[j].num_bits == tap->ir_length); /* input fields must have the same length as the TAP's IR */
+ /* if TAP is listed in input fields, copy the value */
- cmd_queue_scan_field_clone(field, in_fields + j);
+ found = true;
- break;
- }
+ tap->bypass = 0;
+
+ assert(in_fields[j].num_bits == tap->ir_length); /* input fields must have the same length as the TAP's IR */
+
+ cmd_queue_scan_field_clone(field, in_fields + j);
+
+ break;
}
if (!found)
{
/* if a TAP isn't listed in input fields, set it to BYPASS */
+
tap->bypass = 1;
field->tap = tap;
- field->num_bits = scan_size;
- field->out_value = buf_set_ones(cmd_queue_alloc(CEIL(scan_size, 8)), scan_size);
+ field->num_bits = tap->ir_length;
+ field->out_value = buf_set_ones(cmd_queue_alloc(CEIL(tap->ir_length, 8)), tap->ir_length);
field->in_value = NULL; /* do not collect input for tap's in bypass */
}
/* update device information */
- buf_cpy(field->out_value, tap->cur_instr, scan_size);
+ buf_cpy(field->out_value, tap->cur_instr, tap->ir_length);
field++;
}
*/
int MINIDRIVER(interface_jtag_add_dr_scan)(int in_num_fields, const scan_field_t *in_fields, tap_state_t state)
{
- int j;
- int field_count = 0;
-
/* count devices in bypass */
size_t bypass_devices = 0;
scan->fields = out_fields;
scan->end_state = state;
+
+ scan_field_t * field = out_fields; /* keep track where we insert data */
+
+ /* loop over all enabled TAPs */
+
for (jtag_tap_t * tap = jtag_NextEnabledTap(NULL); tap != NULL; tap = jtag_NextEnabledTap(tap))
{
- int found = 0;
+ /* if TAP is not bypassed insert matching input fields */
- for (j = 0; j < in_num_fields; j++)
+ if (!tap->bypass)
{
- if (tap == in_fields[j].tap)
- {
- found = 1;
-
- cmd_queue_scan_field_clone(scan->fields + field_count, in_fields + j);
+ scan_field_t * start_field = field; /* keep initial position for assert() */
- field_count++;
- }
- }
- if (!found)
- {
-#ifdef _DEBUG_JTAG_IO_
- /* if a device isn't listed, the BYPASS register should be selected */
- if (! tap->bypass)
+ for (int j = 0; j < in_num_fields; j++)
{
- LOG_ERROR("BUG: no scan data for a device not in BYPASS");
- exit(-1);
+ if (tap != in_fields[j].tap)
+ continue;
+
+ cmd_queue_scan_field_clone(field, in_fields + j);
+
+ field++;
}
-#endif
- /* program the scan field to 1 bit length, and ignore it's value */
- scan->fields[field_count].tap = tap;
- scan->fields[field_count].num_bits = 1;
- scan->fields[field_count].out_value = NULL;
- scan->fields[field_count].in_value = NULL;
- field_count++;
+
+ assert(field > start_field); /* must have at least one input field per not bypassed TAP */
}
+
+ /* if a TAP is bypassed, generated a dummy bit*/
else
{
-#ifdef _DEBUG_JTAG_IO_
- /* if a device is listed, the BYPASS register must not be selected */
- if (tap->bypass)
- {
- LOG_ERROR("BUG: scan data for a device in BYPASS");
- exit(-1);
- }
-#endif
+ field->tap = tap;
+ field->num_bits = 1;
+ field->out_value = NULL;
+ field->in_value = NULL;
+
+ field++;
}
}
- /* field_count represents the true number of fields setup*/
- scan->num_fields = field_count;
+ assert(field == out_fields + scan->num_fields); /* no superfluous input fields permitted */
+
return ERROR_OK;
}
const u32 *value,
tap_state_t end_state)
{
- int field_count = 0;
-
/* count devices in bypass */
size_t bypass_devices = 0;
scan->fields = out_fields;
scan->end_state = end_state;
+
+ bool target_tap_match = false;
+
+ scan_field_t * field = out_fields; /* keep track where we insert data */
+
+ /* loop over all enabled TAPs */
+
for (jtag_tap_t * tap = jtag_NextEnabledTap(NULL); tap != NULL; tap = jtag_NextEnabledTap(tap))
{
- scan->fields[field_count].tap = tap;
+ /* if TAP is not bypassed insert matching input fields */
- if (tap == target_tap)
+ if (!tap->bypass)
{
-#ifdef _DEBUG_JTAG_IO_
- /* if a device is listed, the BYPASS register must not be selected */
- if (tap->bypass)
- {
- LOG_ERROR("BUG: scan data for a device in BYPASS");
- exit(-1);
- }
-#endif
+ assert(tap == target_tap); /* target_tap must match the one not bypassed TAP */
+
+ target_tap_match = true;
+
for (int j = 0; j < in_num_fields; j++)
{
u8 out_value[4];
size_t scan_size = num_bits[j];
buf_set_u32(out_value, 0, scan_size, value[j]);
- scan->fields[field_count].num_bits = scan_size;
- scan->fields[field_count].out_value = buf_cpy(out_value, cmd_queue_alloc(CEIL(scan_size, 8)), scan_size);
- scan->fields[field_count].in_value = NULL;
- field_count++;
+
+ field->tap = tap;
+ field->num_bits = scan_size;
+ field->out_value = buf_cpy(out_value, cmd_queue_alloc(CEIL(scan_size, 8)), scan_size);
+ field->in_value = NULL;
+
+ field++;
}
- } else
+ }
+
+ /* if a TAP is bypassed, generated a dummy bit*/
+ else
{
-#ifdef _DEBUG_JTAG_IO_
- /* if a device isn't listed, the BYPASS register should be selected */
- if (! tap->bypass)
- {
- LOG_ERROR("BUG: no scan data for a device not in BYPASS");
- exit(-1);
- }
-#endif
- /* program the scan field to 1 bit length, and ignore it's value */
- scan->fields[field_count].num_bits = 1;
- scan->fields[field_count].out_value = NULL;
- scan->fields[field_count].in_value = NULL;
- field_count++;
+
+ field->tap = tap;
+ field->num_bits = 1;
+ field->out_value = NULL;
+ field->in_value = NULL;
+
+ field++;
}
}
+
+ assert(target_tap_match); /* target_tap should be enabled and not bypassed */
}
jtag_error=retval;
return;
}
+ jtag_execute_queue();
if (jtag_srst)
{
* and inform possible listeners about this
*/
LOG_DEBUG("TRST line asserted");
- cmd_queue_cur_state = TAP_RESET;
+ tap_set_state(TAP_RESET);
jtag_call_event_callbacks(JTAG_TRST_ASSERTED);
}
else
register_command(cmd_ctx, NULL, "interface", handle_interface_command,
COMMAND_CONFIG, "try to configure interface");
register_command(cmd_ctx, NULL, "jtag_speed", handle_jtag_speed_command,
- COMMAND_ANY, "set jtag speed (if supported)");
+ COMMAND_ANY, "(DEPRECATED) set jtag speed (if supported)");
register_command(cmd_ctx, NULL, "jtag_khz", handle_jtag_khz_command,
- COMMAND_ANY, "same as jtag_speed, except it takes maximum khz as arguments. 0 KHz = RTCK.");
+ COMMAND_ANY, "set maximum jtag speed (if supported); "
+ "parameter is maximum khz, or 0 for adaptive clocking (RTCK).");
register_command(cmd_ctx, NULL, "jtag_device", handle_jtag_device_command,
COMMAND_CONFIG, "jtag_device <ir_length> <ir_expected> <ir_mask>");
register_command(cmd_ctx, NULL, "reset_config", handle_reset_config_command,