- for (jtag_tap_t * tap = jtag_NextEnabledTap(NULL); tap != NULL; tap = jtag_NextEnabledTap(tap))
- {
- scan->fields[field_count].tap = tap;
-
- if (tap == target_tap)
- {
-#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
- 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++;
- }
- } 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++;
- }
- }
-}
-
-
-/**
- * Duplicate the scan fields passed into the function into a DR SCAN command
- *
- * This function assumes that the caller handles extra fields for bypassed TAPs
- *
- */
-void jtag_add_plain_dr_scan(int in_num_fields, const scan_field_t *in_fields, tap_state_t state)
-{
- int retval;
-
- jtag_prelude(state);
-
- retval=interface_jtag_add_plain_dr_scan(in_num_fields, in_fields, cmd_queue_end_state);
- if (retval!=ERROR_OK)
- jtag_error=retval;
-}
-
-
-/**
- * see jtag_add_plain_dr_scan()
- *
- */
-int MINIDRIVER(interface_jtag_add_plain_dr_scan)(int in_num_fields, const scan_field_t *in_fields, tap_state_t state)
-{
- jtag_command_t * cmd = cmd_queue_alloc(sizeof(jtag_command_t));
- scan_command_t * scan = cmd_queue_alloc(sizeof(scan_command_t));
- scan_field_t * out_fields = cmd_queue_alloc(in_num_fields * sizeof(scan_field_t));
-
- jtag_queue_command(cmd);
-
- cmd->type = JTAG_SCAN;
- cmd->cmd.scan = scan;
-
- scan->ir_scan = false;
- scan->num_fields = in_num_fields;
- scan->fields = out_fields;
- scan->end_state = state;
-
- for (int i = 0; i < in_num_fields; i++)
- cmd_queue_scan_field_clone(out_fields + i, in_fields + i);
-
- return ERROR_OK;
-}
-
-
-void jtag_add_tlr(void)
-{
- jtag_prelude(TAP_RESET);
-
- int retval;
- retval=interface_jtag_add_tlr();
- if (retval!=ERROR_OK)
- jtag_error=retval;
-}
-
-int MINIDRIVER(interface_jtag_add_tlr)(void)
-{
- tap_state_t state = TAP_RESET;
-
- /* allocate memory for a new list member */
- jtag_command_t * cmd = cmd_queue_alloc(sizeof(jtag_command_t));
-
- jtag_queue_command(cmd);
-
- cmd->type = JTAG_STATEMOVE;
-
- cmd->cmd.statemove = cmd_queue_alloc(sizeof(statemove_command_t));
- cmd->cmd.statemove->end_state = state;
-
- return ERROR_OK;
-}
-
-void jtag_add_pathmove(int num_states, const tap_state_t *path)
-{
- tap_state_t cur_state = cmd_queue_cur_state;
- int i;
- int retval;
-
- /* the last state has to be a stable state */
- if (!tap_is_state_stable(path[num_states - 1]))
- {
- LOG_ERROR("BUG: TAP path doesn't finish in a stable state");
- exit(-1);
- }
-
- for (i=0; i<num_states; i++)
- {
- if (path[i] == TAP_RESET)
- {
- LOG_ERROR("BUG: TAP_RESET is not a valid state for pathmove sequences");
- exit(-1);
- }
-
- if ( tap_state_transition(cur_state, true) != path[i]
- && tap_state_transition(cur_state, false) != path[i])
- {
- LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_name(cur_state), tap_state_name(path[i]));
- exit(-1);
- }
- cur_state = path[i];
- }
-
- jtag_prelude1();
-
- retval = interface_jtag_add_pathmove(num_states, path);
- cmd_queue_cur_state = path[num_states - 1];
- if (retval!=ERROR_OK)
- jtag_error=retval;
-}
-
-int MINIDRIVER(interface_jtag_add_pathmove)(int num_states, const tap_state_t *path)
-{
- /* allocate memory for a new list member */
- jtag_command_t * cmd = cmd_queue_alloc(sizeof(jtag_command_t));
-
- jtag_queue_command(cmd);
-
- cmd->type = JTAG_PATHMOVE;
-
- cmd->cmd.pathmove = cmd_queue_alloc(sizeof(pathmove_command_t));
- cmd->cmd.pathmove->num_states = num_states;
- cmd->cmd.pathmove->path = cmd_queue_alloc(sizeof(tap_state_t) * num_states);
-
- for (int i = 0; i < num_states; i++)
- cmd->cmd.pathmove->path[i] = path[i];
-
- return ERROR_OK;
-}
-
-int MINIDRIVER(interface_jtag_add_runtest)(int num_cycles, tap_state_t state)
-{
- /* allocate memory for a new list member */
- jtag_command_t * cmd = cmd_queue_alloc(sizeof(jtag_command_t));
-
- jtag_queue_command(cmd);
-
- cmd->type = JTAG_RUNTEST;
-
- cmd->cmd.runtest = cmd_queue_alloc(sizeof(runtest_command_t));
- cmd->cmd.runtest->num_cycles = num_cycles;
- cmd->cmd.runtest->end_state = state;
-
- return ERROR_OK;
-}
-
-void jtag_add_runtest(int num_cycles, tap_state_t state)
-{
- int retval;
-
- jtag_prelude(state);
-
- /* executed by sw or hw fifo */
- retval=interface_jtag_add_runtest(num_cycles, cmd_queue_end_state);
- if (retval!=ERROR_OK)
- jtag_error=retval;
-}
-
-
-int MINIDRIVER(interface_jtag_add_clocks)( int num_cycles )
-{
- /* allocate memory for a new list member */
- jtag_command_t * cmd = cmd_queue_alloc(sizeof(jtag_command_t));
-
- jtag_queue_command(cmd);
-
- cmd->type = JTAG_STABLECLOCKS;
-
- cmd->cmd.stableclocks = cmd_queue_alloc(sizeof(stableclocks_command_t));
- cmd->cmd.stableclocks->num_cycles = num_cycles;
-
- return ERROR_OK;
-}
-
-void jtag_add_clocks( int num_cycles )
-{
- int retval;
-
- if( !tap_is_state_stable(cmd_queue_cur_state) )
- {
- LOG_ERROR( "jtag_add_clocks() was called with TAP in non-stable state \"%s\"",
- tap_state_name(cmd_queue_cur_state) );
- jtag_error = ERROR_JTAG_NOT_STABLE_STATE;
- return;
- }
-
- if( num_cycles > 0 )
- {
- jtag_prelude1();
-
- retval = interface_jtag_add_clocks(num_cycles);
- if (retval != ERROR_OK)
- jtag_error=retval;
- }
-}
-
-void jtag_add_reset(int req_tlr_or_trst, int req_srst)
-{
- int trst_with_tlr = 0;
- int retval;
-
- /* FIX!!! there are *many* different cases here. A better
- * approach is needed for legal combinations of transitions...
- */
- if ((jtag_reset_config & RESET_HAS_SRST)&&
- (jtag_reset_config & RESET_HAS_TRST)&&
- ((jtag_reset_config & RESET_SRST_PULLS_TRST)==0))