Beispiel #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()));
}
Beispiel #2
0
static void ftdi_execute_statemove(struct jtag_command *cmd)
{
    DEBUG_JTAG_IO("statemove end in %s",
                  tap_state_name(cmd->cmd.statemove->end_state));

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

    /* shortest-path move to desired end state */
    if (tap_get_state() != tap_get_end_state() || tap_get_end_state() == TAP_RESET)
        move_to_state(tap_get_end_state());
}
Beispiel #3
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()));
}
Beispiel #4
0
void update()
{
  if(quit)
    return;
  
  if(game_state != INSTRUCTION)
    if(keydown == SDLK_ESCAPE)
    {
      move_to_main_menu();
      return;
    }

  if(keydown == SDLK_h)
  {
    move_to_instruction_state();
    return;
  }

  switch(game_state)
  {
    case MAIN_MENU:
      update_main_menu();
    break;

    case PLAY:
    {
        if(striker.state == RELEASED)
        {
          update_striker(&striker);

          int i;
          for(i = 0; CHIPS[i]; i++)
            if(CHIPS[i]->mov.state != OUT_OF_GAME)
              integrate(&CHIPS[i]->mov);

          for(i = 0; CHIPS[i]; i++)
            if(CHIPS[i]->mov.state != OUT_OF_GAME)
              resolve_collision(&striker.mov, &CHIPS[i]->mov);

          int j;
          for(i = 0; CHIPS[i]; i++)
          {
            if(CHIPS[i]->mov.state != OUT_OF_GAME)
            {
              for(j = i + 1; CHIPS[j]; j++)
              {
                if(CHIPS[j]->mov.state != OUT_OF_GAME)
                  resolve_collision(&CHIPS[i]->mov, &CHIPS[j]->mov);
              }
            }
          }

          for(i = 0; CHIPS[i]; i++)
          {
            if(CHIPS[i]->mov.state != OUT_OF_GAME)
            {
              resolve_collision_with_hole(&CHIPS[i]->mov, &board);
              resolve_collision_with_board(&CHIPS[i]->mov, &board);
            }
          }
          
          resolve_collision_with_hole(&striker.mov, &board);
          resolve_collision_with_board(&striker.mov, &board);

          if(!chips_on_board)
          {
            move_to_game_over_state();
            return;
          }

          int all_stopped = 1;
          for(i = 0; CHIPS[i]; i++)
          {
            if(CHIPS[i]->mov.state == MOVING)
            {
              all_stopped = 0;
              break;
            }
          }

          if(striker.mov.state == MOVING)
            all_stopped = 0;

          if(all_stopped)
          {
            // calculate score
            // assign striker to square
            if(striker.mov.in_hole)
            {
              second_chance = 0;
            }
            increment_current_player();
            move_to_with_player(&striker, current_player);
          }
        } else {
          update_striker(&striker);
        }
    }
    break;

    case INSTRUCTION:
      if(keydown || left_mouse_button_down)
        move_to_state(back_state);
    break;
  }
}
Beispiel #5
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;

}