Пример #1
0
static void ftdi_execute_runtest(struct jtag_command *cmd)
{
    int i;
    uint8_t zero = 0;

    DEBUG_JTAG_IO("runtest %i cycles, end in %s",
                  cmd->cmd.runtest->num_cycles,
                  tap_state_name(cmd->cmd.runtest->end_state));

    if (tap_get_state() != TAP_IDLE)
        move_to_state(TAP_IDLE);

    /* TODO: Reuse ftdi_execute_stableclocks */
    i = cmd->cmd.runtest->num_cycles;
    while (i > 0) {
        /* there are no state transitions in this code, so omit state tracking */
        unsigned this_len = i > 7 ? 7 : i;
        mpsse_clock_tms_cs_out(mpsse_ctx, &zero, 0, this_len, false, JTAG_MODE);
        i -= this_len;
    }

    ftdi_end_state(cmd->cmd.runtest->end_state);

    if (tap_get_state() != tap_get_end_state())
        move_to_state(tap_get_end_state());

    DEBUG_JTAG_IO("runtest: %i, end in %s",
                  cmd->cmd.runtest->num_cycles,
                  tap_state_name(tap_get_end_state()));
}
Пример #2
0
/**
 * Function move_to_state
 * moves the TAP controller from the current state to a
 * \a goal_state through a path given by tap_get_tms_path().  State transition
 * logging is performed by delegation to clock_tms().
 *
 * @param goal_state is the destination state for the move.
 */
static void move_to_state(tap_state_t goal_state)
{
    tap_state_t start_state = tap_get_state();

    /*	goal_state is 1/2 of a tuple/pair of states which allow convenient
    	lookup of the required TMS pattern to move to this state from the
    	start state.
    */

    /* do the 2 lookups */
    int tms_bits  = tap_get_tms_path(start_state, goal_state);
    int tms_count = tap_get_tms_path_len(start_state, goal_state);

    DEBUG_JTAG_IO("start=%s goal=%s", tap_state_name(start_state), tap_state_name(goal_state));

    /* Track state transitions step by step */
    for (int i = 0; i < tms_count; i++)
        tap_set_state(tap_state_transition(tap_get_state(), (tms_bits >> i) & 1));

    mpsse_clock_tms_cs_out(mpsse_ctx,
                           (uint8_t *)&tms_bits,
                           0,
                           tms_count,
                           false,
                           JTAG_MODE);
}
Пример #3
0
static int ftdi_execute_stableclocks(struct jtag_command *cmd)
{
	int retval = ERROR_OK;

	/* this is only allowed while in a stable state.  A check for a stable
	 * state was done in jtag_add_clocks()
	 */
	int num_cycles = cmd->cmd.stableclocks->num_cycles;

	/* 7 bits of either ones or zeros. */
	uint8_t tms = tap_get_state() == TAP_RESET ? 0x7f : 0x00;

	/* TODO: Use mpsse_clock_data with in=out=0 for this, if TMS can be set to
	 * the correct level and remain there during the scan */
	while (num_cycles > 0 && retval == ERROR_OK) {
		/* there are no state transitions in this code, so omit state tracking */
		unsigned this_len = num_cycles > 7 ? 7 : num_cycles;
		retval = mpsse_clock_tms_cs_out(mpsse_ctx, &tms, 0, this_len, false, JTAG_MODE);
		num_cycles -= this_len;
	}

	DEBUG_JTAG_IO("clocks %i while in %s",
		cmd->cmd.stableclocks->num_cycles,
		tap_state_name(tap_get_state()));
	return retval;
}
Пример #4
0
static int ftdi_execute_pathmove(struct jtag_command *cmd)
{
	int retval = ERROR_OK;

	tap_state_t *path = cmd->cmd.pathmove->path;
	int num_states  = cmd->cmd.pathmove->num_states;

	DEBUG_JTAG_IO("pathmove: %i states, current: %s  end: %s", num_states,
		tap_state_name(tap_get_state()),
		tap_state_name(path[num_states-1]));

	int state_count = 0;
	unsigned bit_count = 0;
	uint8_t tms_byte = 0;

	DEBUG_JTAG_IO("-");

	/* this loop verifies that the path is legal and logs each state in the path */
	while (num_states-- && retval == ERROR_OK) {

		/* either TMS=0 or TMS=1 must work ... */
		if (tap_state_transition(tap_get_state(), false)
		    == path[state_count])
			buf_set_u32(&tms_byte, bit_count++, 1, 0x0);
		else if (tap_state_transition(tap_get_state(), true)
			 == path[state_count]) {
			buf_set_u32(&tms_byte, bit_count++, 1, 0x1);

			/* ... or else the caller goofed BADLY */
		} else {
			LOG_ERROR("BUG: %s -> %s isn't a valid "
				"TAP state transition",
				tap_state_name(tap_get_state()),
				tap_state_name(path[state_count]));
			exit(-1);
		}

		tap_set_state(path[state_count]);
		state_count++;

		if (bit_count == 7 || num_states == 0) {
			retval = mpsse_clock_tms_cs_out(mpsse_ctx,
					&tms_byte,
					0,
					bit_count,
					false,
					JTAG_MODE);
			bit_count = 0;
		}
	}
	tap_set_end_state(tap_get_state());

	return retval;
}
Пример #5
0
/**
 * Clock a bunch of TMS (or SWDIO) transitions, to change the JTAG
 * (or SWD) state machine. REVISIT: Not the best method, perhaps.
 */
static void ftdi_execute_tms(struct jtag_command *cmd)
{
    DEBUG_JTAG_IO("TMS: %d bits", cmd->cmd.tms->num_bits);

    /* TODO: Missing tap state tracking, also missing from ft2232.c! */
    mpsse_clock_tms_cs_out(mpsse_ctx,
                           cmd->cmd.tms->bits,
                           0,
                           cmd->cmd.tms->num_bits,
                           false,
                           JTAG_MODE);
}
Пример #6
0
static void ftdi_execute_scan(struct jtag_command *cmd)
{
    DEBUG_JTAG_IO("%s type:%d", cmd->cmd.scan->ir_scan ? "IRSCAN" : "DRSCAN",
                  jtag_scan_type(cmd->cmd.scan));

    /* Make sure there are no trailing fields with num_bits == 0, or the logic below will fail. */
    while (cmd->cmd.scan->num_fields > 0
            && cmd->cmd.scan->fields[cmd->cmd.scan->num_fields - 1].num_bits == 0) {
        cmd->cmd.scan->num_fields--;
        LOG_DEBUG("discarding trailing empty field");
    }

    if (cmd->cmd.scan->num_fields == 0) {
        LOG_DEBUG("empty scan, doing nothing");
        return;
    }

    if (cmd->cmd.scan->ir_scan) {
        if (tap_get_state() != TAP_IRSHIFT)
            move_to_state(TAP_IRSHIFT);
    } else {
        if (tap_get_state() != TAP_DRSHIFT)
            move_to_state(TAP_DRSHIFT);
    }

    ftdi_end_state(cmd->cmd.scan->end_state);

    struct scan_field *field = cmd->cmd.scan->fields;
    unsigned scan_size = 0;

    for (int i = 0; i < cmd->cmd.scan->num_fields; i++, field++) {
        scan_size += field->num_bits;
        DEBUG_JTAG_IO("%s%s field %d/%d %d bits",
                      field->in_value ? "in" : "",
                      field->out_value ? "out" : "",
                      i,
                      cmd->cmd.scan->num_fields,
                      field->num_bits);

        if (i == cmd->cmd.scan->num_fields - 1 && tap_get_state() != tap_get_end_state()) {
            /* Last field, and we're leaving IRSHIFT/DRSHIFT. Clock last bit during tap
             * movement. This last field can't have length zero, it was checked above. */
            mpsse_clock_data(mpsse_ctx,
                             field->out_value,
                             0,
                             field->in_value,
                             0,
                             field->num_bits - 1,
                             JTAG_MODE);
            uint8_t last_bit = 0;
            if (field->out_value)
                bit_copy(&last_bit, 0, field->out_value, field->num_bits - 1, 1);
            uint8_t tms_bits = 0x01;
            mpsse_clock_tms_cs(mpsse_ctx,
                               &tms_bits,
                               0,
                               field->in_value,
                               field->num_bits - 1,
                               1,
                               last_bit,
                               JTAG_MODE);
            tap_set_state(tap_state_transition(tap_get_state(), 1));
            mpsse_clock_tms_cs_out(mpsse_ctx,
                                   &tms_bits,
                                   1,
                                   1,
                                   last_bit,
                                   JTAG_MODE);
            tap_set_state(tap_state_transition(tap_get_state(), 0));
        } else
            mpsse_clock_data(mpsse_ctx,
                             field->out_value,
                             0,
                             field->in_value,
                             0,
                             field->num_bits,
                             JTAG_MODE);
    }

    if (tap_get_state() != tap_get_end_state())
        move_to_state(tap_get_end_state());

    DEBUG_JTAG_IO("%s scan, %i bits, end in %s",
                  (cmd->cmd.scan->ir_scan) ? "IR" : "DR", scan_size,
                  tap_state_name(tap_get_end_state()));
}
Пример #7
0
static int ftdi_execute_scan(struct jtag_command *cmd)
{
	int retval = ERROR_OK;

	DEBUG_JTAG_IO("%s type:%d", cmd->cmd.scan->ir_scan ? "IRSCAN" : "DRSCAN",
		jtag_scan_type(cmd->cmd.scan));

	if (cmd->cmd.scan->ir_scan) {
		if (tap_get_state() != TAP_IRSHIFT)
			move_to_state(TAP_IRSHIFT);
	} else {
		if (tap_get_state() != TAP_DRSHIFT)
			move_to_state(TAP_DRSHIFT);
	}

	ftdi_end_state(cmd->cmd.scan->end_state);

	struct scan_field *field = cmd->cmd.scan->fields;
	unsigned scan_size = 0;

	for (int i = 0; i < cmd->cmd.scan->num_fields; i++, field++) {
		scan_size += field->num_bits;
		DEBUG_JTAG_IO("%s%s field %d/%d %d bits",
			field->in_value ? "in" : "",
			field->out_value ? "out" : "",
			i,
			cmd->cmd.scan->num_fields,
			field->num_bits);

		if (i == cmd->cmd.scan->num_fields - 1 && tap_get_state() != tap_get_end_state()) {
			/* Last field, and we're leaving IRSHIFT/DRSHIFT. Clock last bit during tap
			 *movement */
			mpsse_clock_data(mpsse_ctx,
				field->out_value,
				0,
				field->in_value,
				0,
				field->num_bits - 1,
				JTAG_MODE);
			uint8_t last_bit = 0;
			if (field->out_value)
				bit_copy(&last_bit, 0, field->out_value, field->num_bits - 1, 1);
			uint8_t tms_bits = 0x01;
			retval = mpsse_clock_tms_cs(mpsse_ctx,
					&tms_bits,
					0,
					field->in_value,
					field->num_bits - 1,
					1,
					last_bit,
					JTAG_MODE);
			tap_set_state(tap_state_transition(tap_get_state(), 1));
			retval = mpsse_clock_tms_cs_out(mpsse_ctx,
					&tms_bits,
					1,
					1,
					last_bit,
					JTAG_MODE);
			tap_set_state(tap_state_transition(tap_get_state(), 0));
		} else
			mpsse_clock_data(mpsse_ctx,
				field->out_value,
				0,
				field->in_value,
				0,
				field->num_bits,
				JTAG_MODE);
		if (retval != ERROR_OK) {
			LOG_ERROR("failed to add field %d in scan", i);
			return retval;
		}
	}

	if (tap_get_state() != tap_get_end_state())
		move_to_state(tap_get_end_state());

	DEBUG_JTAG_IO("%s scan, %i bits, end in %s",
		(cmd->cmd.scan->ir_scan) ? "IR" : "DR", scan_size,
		tap_state_name(tap_get_end_state()));
	return retval;

}