Break ft2232_execute_quie into smaller functions, follows restructure of jlink.c
git-svn-id: svn://svn.berlios.de/openocd/trunk@1526 b42882b7-edfa-0310-969c-e2dbd0fdcd60__archive__
parent
479a65e946
commit
4b9f6fcdb7
|
@ -423,8 +423,8 @@ static int ft2232_send_and_recv(jtag_command_t* first, jtag_command_t* last)
|
|||
int scan_size;
|
||||
enum scan_type type;
|
||||
int retval;
|
||||
u32 bytes_written;
|
||||
u32 bytes_read;
|
||||
u32 bytes_written=0;
|
||||
u32 bytes_read=0;
|
||||
|
||||
#ifdef _DEBUG_USB_IO_
|
||||
struct timeval start, inter, inter2, end;
|
||||
|
@ -1267,64 +1267,30 @@ static void sheevaplug_reset(int trst, int srst)
|
|||
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_queue()
|
||||
static int ft2232_execute_end_state(jtag_command_t *cmd)
|
||||
{
|
||||
jtag_command_t* cmd = jtag_command_queue; /* currently processed command */
|
||||
u8* buffer;
|
||||
int scan_size; /* size of IR or DR scan */
|
||||
enum scan_type type;
|
||||
int i;
|
||||
int predicted_size = 0;
|
||||
int retval;
|
||||
|
||||
first_unsent = cmd; /* next command that has to be sent */
|
||||
require_send = 0;
|
||||
|
||||
/* return ERROR_OK, unless ft2232_send_and_recv reports a failed check
|
||||
* that wasn't handled by a caller-provided error handler
|
||||
*/
|
||||
retval = ERROR_OK;
|
||||
|
||||
ft2232_buffer_size = 0;
|
||||
ft2232_expect_read = 0;
|
||||
DEBUG_JTAG_IO("end_state: %i", cmd->cmd.end_state->end_state);
|
||||
|
||||
/* blink, if the current layout has that feature */
|
||||
if (layout->blink)
|
||||
layout->blink();
|
||||
|
||||
while (cmd)
|
||||
{
|
||||
switch (cmd->type)
|
||||
{
|
||||
case JTAG_END_STATE:
|
||||
if (cmd->cmd.end_state->end_state != TAP_INVALID)
|
||||
ft2232_end_state(cmd->cmd.end_state->end_state);
|
||||
break;
|
||||
|
||||
case JTAG_RESET:
|
||||
/* 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;
|
||||
return retval;
|
||||
}
|
||||
|
||||
if ( (cmd->cmd.reset->trst == 1) || ( cmd->cmd.reset->srst && (jtag_reset_config & RESET_SRST_PULLS_TRST) ) )
|
||||
|
||||
static int ft2232_execute_runtest(jtag_command_t *cmd)
|
||||
{
|
||||
tap_set_state(TAP_RESET);
|
||||
}
|
||||
layout->reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
|
||||
require_send = 1;
|
||||
int retval;
|
||||
int i;
|
||||
int predicted_size = 0;
|
||||
retval = ERROR_OK;
|
||||
|
||||
#ifdef _DEBUG_JTAG_IO_
|
||||
LOG_DEBUG("trst: %i, srst: %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case JTAG_RUNTEST:
|
||||
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)
|
||||
|
@ -1386,9 +1352,18 @@ static int ft2232_execute_queue()
|
|||
#ifdef _DEBUG_JTAG_IO_
|
||||
LOG_DEBUG( "runtest: %i, end in %s", cmd->cmd.runtest->num_cycles, tap_state_name( tap_get_end_state() ) );
|
||||
#endif
|
||||
break;
|
||||
|
||||
case JTAG_STATEMOVE:
|
||||
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)
|
||||
|
@ -1414,9 +1389,19 @@ static int ft2232_execute_queue()
|
|||
#ifdef _DEBUG_JTAG_IO_
|
||||
LOG_DEBUG( "statemove: %s", tap_state_name( tap_get_end_state() ) );
|
||||
#endif
|
||||
break;
|
||||
|
||||
case JTAG_PATHMOVE:
|
||||
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)
|
||||
|
@ -1432,9 +1417,18 @@ static int ft2232_execute_queue()
|
|||
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
|
||||
break;
|
||||
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;
|
||||
|
||||
case JTAG_SCAN:
|
||||
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);
|
||||
|
@ -1454,7 +1448,7 @@ static int ft2232_execute_queue()
|
|||
first_unsent = cmd->next;
|
||||
if (buffer)
|
||||
free(buffer);
|
||||
break;
|
||||
return retval;
|
||||
}
|
||||
else if (ft2232_buffer_size + predicted_size + 1 > FT2232_BUFFER_SIZE)
|
||||
{
|
||||
|
@ -1478,9 +1472,49 @@ static int ft2232_execute_queue()
|
|||
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
|
||||
break;
|
||||
return retval;
|
||||
|
||||
}
|
||||
|
||||
static int ft2232_execute_reset(jtag_command_t *cmd)
|
||||
{
|
||||
int retval;
|
||||
int predicted_size = 0;
|
||||
retval = ERROR_OK;
|
||||
|
||||
DEBUG_JTAG_IO("reset trst: %i srst %i",
|
||||
cmd->cmd.reset->trst, cmd->cmd.reset->srst);
|
||||
|
||||
/* 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.reset->trst == 1) || ( cmd->cmd.reset->srst && (jtag_reset_config & RESET_SRST_PULLS_TRST) ) )
|
||||
{
|
||||
tap_set_state(TAP_RESET);
|
||||
}
|
||||
layout->reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
|
||||
require_send = 1;
|
||||
|
||||
#ifdef _DEBUG_JTAG_IO_
|
||||
LOG_DEBUG("trst: %i, srst: %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst);
|
||||
#endif
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int ft2232_execute_sleep(jtag_command_t *cmd)
|
||||
{
|
||||
int retval;
|
||||
retval = ERROR_OK;
|
||||
|
||||
DEBUG_JTAG_IO("sleep %i", cmd->cmd.sleep->us);
|
||||
|
||||
case JTAG_SLEEP:
|
||||
if (ft2232_send_and_recv(first_unsent, cmd) != ERROR_OK)
|
||||
retval = ERROR_JTAG_QUEUE_FAILED;
|
||||
first_unsent = cmd->next;
|
||||
|
@ -1488,9 +1522,14 @@ static int ft2232_execute_queue()
|
|||
#ifdef _DEBUG_JTAG_IO_
|
||||
LOG_DEBUG( "sleep %i usec while in %s", cmd->cmd.sleep->us, tap_state_name( tap_get_state() ) );
|
||||
#endif
|
||||
break;
|
||||
|
||||
case JTAG_STABLECLOCKS:
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int ft2232_execute_stableclocks(jtag_command_t *cmd)
|
||||
{
|
||||
int retval;
|
||||
retval = ERROR_OK;
|
||||
|
||||
/* this is only allowed while in a stable state. A check for a stable
|
||||
* state was done in jtag_add_clocks()
|
||||
|
@ -1500,13 +1539,56 @@ static int ft2232_execute_queue()
|
|||
#ifdef _DEBUG_JTAG_IO_
|
||||
LOG_DEBUG( "clocks %i while in %s", cmd->cmd.stableclocks->num_cycles, tap_state_name( tap_get_state() ) );
|
||||
#endif
|
||||
break;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int ft2232_execute_command(jtag_command_t *cmd)
|
||||
{
|
||||
int retval;
|
||||
retval = ERROR_OK;
|
||||
|
||||
switch (cmd->type)
|
||||
{
|
||||
case JTAG_END_STATE: retval = ft2232_execute_end_state(cmd); break;
|
||||
case JTAG_RESET: retval = ft2232_execute_reset(cmd); break;
|
||||
case JTAG_RUNTEST: retval = ft2232_execute_runtest(cmd); break;
|
||||
case JTAG_STATEMOVE: retval = ft2232_execute_statemove(cmd); break;
|
||||
case JTAG_PATHMOVE: retval = ft2232_execute_pathmove(cmd); break;
|
||||
case JTAG_SCAN: retval = ft2232_execute_scan(cmd); break;
|
||||
case JTAG_SLEEP: retval = ft2232_execute_sleep(cmd); break;
|
||||
case JTAG_STABLECLOCKS: retval = ft2232_execute_stableclocks(cmd); break;
|
||||
default:
|
||||
LOG_ERROR("BUG: unknown JTAG command type encountered");
|
||||
exit(-1);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int ft2232_execute_queue()
|
||||
{
|
||||
jtag_command_t* cmd = jtag_command_queue; /* currently processed command */
|
||||
int retval;
|
||||
|
||||
first_unsent = cmd; /* next command that has to be sent */
|
||||
require_send = 0;
|
||||
|
||||
/* return ERROR_OK, unless ft2232_send_and_recv reports a failed check
|
||||
* that wasn't handled by a caller-provided error handler
|
||||
*/
|
||||
retval = ERROR_OK;
|
||||
|
||||
ft2232_buffer_size = 0;
|
||||
ft2232_expect_read = 0;
|
||||
|
||||
/* blink, if the current layout has that feature */
|
||||
if (layout->blink)
|
||||
layout->blink();
|
||||
|
||||
while (cmd)
|
||||
{
|
||||
if (ft2232_execute_command(cmd) != ERROR_OK)
|
||||
retval = ERROR_JTAG_QUEUE_FAILED;
|
||||
cmd = cmd->next;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue