+ if (srst == 1)
+ {
+ high_output |= nSRST;
+ }
+ else if (srst == 0)
+ {
+ high_output &= ~nSRST;
+ }
+
+ /* command "set data bits high byte" */
+ BUFFER_ADD = 0x82;
+ BUFFER_ADD = high_output;
+ BUFFER_ADD = high_direction;
+ LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst, srst, high_output,
+ high_direction);
+}
+
+
+static void axm0432_jtag_reset(int trst, int srst)
+{
+ if (trst == 1)
+ {
+ tap_set_state(TAP_RESET);
+ high_output &= ~nTRST;
+ }
+ else if (trst == 0)
+ {
+ high_output |= nTRST;
+ }
+
+ if (srst == 1)
+ {
+ high_output &= ~nSRST;
+ }
+ else if (srst == 0)
+ {
+ high_output |= nSRST;
+ }
+
+ /* command "set data bits low byte" */
+ BUFFER_ADD = 0x82;
+ BUFFER_ADD = high_output;
+ BUFFER_ADD = high_direction;
+ LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst, srst, high_output,
+ high_direction);
+}
+
+
+static void flyswatter_reset(int trst, int srst)
+{
+ if (trst == 1)
+ {
+ low_output &= ~nTRST;
+ }
+ else if (trst == 0)
+ {
+ low_output |= nTRST;
+ }
+
+ if (srst == 1)
+ {
+ low_output |= nSRST;
+ }
+ else if (srst == 0)
+ {
+ low_output &= ~nSRST;
+ }
+
+ /* command "set data bits low byte" */
+ BUFFER_ADD = 0x80;
+ BUFFER_ADD = low_output;
+ BUFFER_ADD = low_direction;
+ LOG_DEBUG("trst: %i, srst: %i, low_output: 0x%2.2x, low_direction: 0x%2.2x", trst, srst, low_output, low_direction);
+}
+
+
+static void turtle_reset(int trst, int srst)
+{
+ trst = trst;
+
+ if (srst == 1)
+ {
+ low_output |= nSRST;
+ }
+ else if (srst == 0)
+ {
+ low_output &= ~nSRST;
+ }
+
+ /* command "set data bits low byte" */
+ BUFFER_ADD = 0x80;
+ BUFFER_ADD = low_output;
+ BUFFER_ADD = low_direction;
+ LOG_DEBUG("srst: %i, low_output: 0x%2.2x, low_direction: 0x%2.2x", srst, low_output, low_direction);
+}
+
+
+static void comstick_reset(int trst, int srst)
+{
+ if (trst == 1)
+ {
+ high_output &= ~nTRST;
+ }
+ else if (trst == 0)
+ {
+ high_output |= nTRST;
+ }
+
+ if (srst == 1)
+ {
+ high_output &= ~nSRST;
+ }
+ else if (srst == 0)
+ {
+ high_output |= nSRST;
+ }
+
+ /* command "set data bits high byte" */
+ BUFFER_ADD = 0x82;
+ BUFFER_ADD = high_output;
+ BUFFER_ADD = high_direction;
+ LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst, srst, high_output,
+ high_direction);
+}
+
+
+static void stm32stick_reset(int trst, int srst)
+{
+ if (trst == 1)
+ {
+ high_output &= ~nTRST;
+ }
+ else if (trst == 0)
+ {
+ high_output |= nTRST;
+ }
+
+ if (srst == 1)
+ {
+ low_output &= ~nSRST;
+ }
+ else if (srst == 0)
+ {
+ low_output |= nSRST;
+ }
+
+ /* command "set data bits low byte" */
+ BUFFER_ADD = 0x80;
+ BUFFER_ADD = low_output;
+ BUFFER_ADD = low_direction;
+
+ /* command "set data bits high byte" */
+ BUFFER_ADD = 0x82;
+ BUFFER_ADD = high_output;
+ BUFFER_ADD = high_direction;
+ LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst, srst, high_output,
+ high_direction);
+}
+
+
+
+static void sheevaplug_reset(int trst, int srst)
+{
+ if (trst == 1)
+ high_output &= ~nTRST;
+ else if (trst == 0)
+ high_output |= nTRST;
+
+ if (srst == 1)
+ high_output &= ~nSRSTnOE;
+ else if (srst == 0)
+ high_output |= nSRSTnOE;
+
+ /* command "set data bits high byte" */
+ BUFFER_ADD = 0x82;
+ BUFFER_ADD = high_output;
+ BUFFER_ADD = high_direction;
+ LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst, srst, high_output, high_direction);
+}
+
+static int ft2232_execute_end_state(jtag_command_t *cmd)
+{
+ int retval;
+ retval = ERROR_OK;
+
+ DEBUG_JTAG_IO("end_state: %i", cmd->cmd.end_state->end_state);
+
+ if (cmd->cmd.end_state->end_state != TAP_INVALID)
+ ft2232_end_state(cmd->cmd.end_state->end_state);
+
+ return retval;
+}
+
+
+static int ft2232_execute_runtest(jtag_command_t *cmd)
+{
+ int retval;
+ int i;
+ int predicted_size = 0;
+ retval = ERROR_OK;
+
+ DEBUG_JTAG_IO("runtest %i cycles, end in %i",
+ cmd->cmd.runtest->num_cycles,
+ cmd->cmd.runtest->end_state);
+ /* only send the maximum buffer size that FT2232C can handle */
+ predicted_size = 0;
+ if (tap_get_state() != TAP_IDLE)
+ predicted_size += 3;
+ predicted_size += 3 * CEIL(cmd->cmd.runtest->num_cycles, 7);
+ if ( (cmd->cmd.runtest->end_state != TAP_INVALID) && (cmd->cmd.runtest->end_state != TAP_IDLE) )
+ predicted_size += 3;
+ if ( (cmd->cmd.runtest->end_state == TAP_INVALID) && (tap_get_end_state() != TAP_IDLE) )
+ predicted_size += 3;
+ if (ft2232_buffer_size + predicted_size + 1 > FT2232_BUFFER_SIZE)
+ {
+ if (ft2232_send_and_recv(first_unsent, cmd) != ERROR_OK)
+ retval = ERROR_JTAG_QUEUE_FAILED;
+ require_send = 0;
+ first_unsent = cmd;
+ }
+ if (tap_get_state() != TAP_IDLE)
+ {
+ /* command "Clock Data to TMS/CS Pin (no Read)" */
+ BUFFER_ADD = 0x4b;
+ BUFFER_ADD = 0x6; /* scan 7 bits */
+
+ /* TMS data bits */
+ BUFFER_ADD = tap_get_tms_path(tap_get_state(), TAP_IDLE);
+ tap_set_state(TAP_IDLE);
+ require_send = 1;
+ }
+ i = cmd->cmd.runtest->num_cycles;
+ while (i > 0)
+ {
+ /* command "Clock Data to TMS/CS Pin (no Read)" */
+ BUFFER_ADD = 0x4b;
+
+ /* scan 7 bits */
+ BUFFER_ADD = (i > 7) ? 6 : (i - 1);
+
+ /* TMS data bits */
+ BUFFER_ADD = 0x0;
+ tap_set_state(TAP_IDLE);
+ i -= (i > 7) ? 7 : i;
+ /* LOG_DEBUG("added TMS scan (no read)"); */
+ }
+
+ if (cmd->cmd.runtest->end_state != TAP_INVALID)
+ ft2232_end_state(cmd->cmd.runtest->end_state);
+
+ if ( tap_get_state() != tap_get_end_state() )
+ {
+ /* command "Clock Data to TMS/CS Pin (no Read)" */
+ BUFFER_ADD = 0x4b;
+ /* scan 7 bit */
+ BUFFER_ADD = 0x6;
+ /* TMS data bits */
+ BUFFER_ADD = tap_get_tms_path( tap_get_state(), tap_get_end_state() );
+ tap_set_state( tap_get_end_state() );
+ /* LOG_DEBUG("added TMS scan (no read)"); */
+ }
+ require_send = 1;
+#ifdef _DEBUG_JTAG_IO_
+ LOG_DEBUG( "runtest: %i, end in %s", cmd->cmd.runtest->num_cycles, tap_state_name( tap_get_end_state() ) );
+#endif
+
+ return retval;
+}
+
+static int ft2232_execute_statemove(jtag_command_t *cmd)
+{
+ int retval;
+ int predicted_size = 0;
+ retval = ERROR_OK;
+
+ DEBUG_JTAG_IO("statemove end in %i", cmd->cmd.statemove->end_state);
+
+ /* only send the maximum buffer size that FT2232C can handle */
+ predicted_size = 3;
+ if (ft2232_buffer_size + predicted_size + 1 > FT2232_BUFFER_SIZE)
+ {
+ if (ft2232_send_and_recv(first_unsent, cmd) != ERROR_OK)
+ retval = ERROR_JTAG_QUEUE_FAILED;
+ require_send = 0;
+ first_unsent = cmd;
+ }
+ if (cmd->cmd.statemove->end_state != TAP_INVALID)
+ ft2232_end_state(cmd->cmd.statemove->end_state);
+
+ /* command "Clock Data to TMS/CS Pin (no Read)" */
+ BUFFER_ADD = 0x4b;
+
+ BUFFER_ADD = 0x6; /* scan 7 bits */
+
+ /* TMS data bits */
+ BUFFER_ADD = tap_get_tms_path( tap_get_state(), tap_get_end_state() );
+ /* LOG_DEBUG("added TMS scan (no read)"); */
+ tap_set_state( tap_get_end_state() );
+ require_send = 1;
+#ifdef _DEBUG_JTAG_IO_
+ LOG_DEBUG( "statemove: %s", tap_state_name( tap_get_end_state() ) );
+#endif
+
+ return retval;
+}
+
+static int ft2232_execute_pathmove(jtag_command_t *cmd)
+{
+ int retval;
+ int predicted_size = 0;
+ retval = ERROR_OK;
+
+ DEBUG_JTAG_IO("pathmove: %i states, end in %i",
+ cmd->cmd.pathmove->num_states,
+ cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]);
+ /* only send the maximum buffer size that FT2232C can handle */
+ predicted_size = 3 * CEIL(cmd->cmd.pathmove->num_states, 7);
+ if (ft2232_buffer_size + predicted_size + 1 > FT2232_BUFFER_SIZE)
+ {
+ if (ft2232_send_and_recv(first_unsent, cmd) != ERROR_OK)
+ retval = ERROR_JTAG_QUEUE_FAILED;
+ require_send = 0;
+ first_unsent = cmd;
+ }
+ ft2232_add_pathmove(cmd->cmd.pathmove);
+ require_send = 1;
+#ifdef _DEBUG_JTAG_IO_
+ LOG_DEBUG( "pathmove: %i states, end in %s", cmd->cmd.pathmove->num_states,
+ tap_state_name(cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]) );
+#endif
+ return retval;
+}
+
+static int ft2232_execute_scan(jtag_command_t *cmd)
+{
+ int retval;
+ u8* buffer;
+ int scan_size; /* size of IR or DR scan */
+ enum scan_type type;
+ int predicted_size = 0;
+ retval = ERROR_OK;
+
+ scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer);
+ type = jtag_scan_type(cmd->cmd.scan);
+ predicted_size = ft2232_predict_scan_out(scan_size, type);
+ if ( (predicted_size + 1) > FT2232_BUFFER_SIZE )
+ {
+ LOG_DEBUG("oversized ft2232 scan (predicted_size > FT2232_BUFFER_SIZE)");
+ /* unsent commands before this */
+ if (first_unsent != cmd)
+ if (ft2232_send_and_recv(first_unsent, cmd) != ERROR_OK)
+ retval = ERROR_JTAG_QUEUE_FAILED;
+
+ /* current command */
+ if (cmd->cmd.scan->end_state != TAP_INVALID)
+ ft2232_end_state(cmd->cmd.scan->end_state);
+ ft2232_large_scan(cmd->cmd.scan, type, buffer, scan_size);
+ require_send = 0;
+ first_unsent = cmd->next;
+ if (buffer)
+ free(buffer);
+ return retval;
+ }
+ else if (ft2232_buffer_size + predicted_size + 1 > FT2232_BUFFER_SIZE)
+ {
+ LOG_DEBUG("ft2232 buffer size reached, sending queued commands (first_unsent: %p, cmd: %p)",
+ first_unsent,
+ cmd);
+ if (ft2232_send_and_recv(first_unsent, cmd) != ERROR_OK)
+ retval = ERROR_JTAG_QUEUE_FAILED;
+ require_send = 0;
+ first_unsent = cmd;
+ }
+ ft2232_expect_read += ft2232_predict_scan_in(scan_size, type);
+ /* LOG_DEBUG("new read size: %i", ft2232_expect_read); */
+ if (cmd->cmd.scan->end_state != TAP_INVALID)
+ ft2232_end_state(cmd->cmd.scan->end_state);
+ ft2232_add_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size);
+ require_send = 1;
+ if (buffer)
+ free(buffer);
+#ifdef _DEBUG_JTAG_IO_
+ LOG_DEBUG( "%s scan, %i bits, end in %s", (cmd->cmd.scan->ir_scan) ? "IR" : "DR", scan_size,
+ tap_state_name( tap_get_end_state() ) );
+#endif
+ return retval;
+