build: cleanup src/jtag directory

Change-Id: I7caf57ca3d9dfbe152504472a6bb26c2a28b92e8
Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk>
Reviewed-on: http://openocd.zylin.com/423
Tested-by: jenkins
__archive__
Spencer Oliver 2012-02-02 15:13:13 +00:00
parent 3da783f628
commit 38f8e5eefa
14 changed files with 903 additions and 971 deletions

View File

@ -27,6 +27,7 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -49,8 +50,7 @@
extern struct jtag_interface *jtag_interface;
const char *jtag_only[] = { "jtag", NULL };
static int
jim_adapter_name(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
static int jim_adapter_name(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
{
Jim_GetOptInfo goi;
Jim_GetOpt_Setup(&goi, interp, argc-1, argv + 1);
@ -67,7 +67,6 @@ jim_adapter_name(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
return JIM_OK;
}
static int default_khz(int khz, int *jtag_speed)
{
LOG_ERROR("Translation from khz to jtag_speed not implemented");
@ -98,9 +97,8 @@ COMMAND_HANDLER(interface_transport_command)
int retval;
retval = CALL_COMMAND_HANDLER(transport_list_parse, &transports);
if (retval != ERROR_OK) {
if (retval != ERROR_OK)
return retval;
}
retval = allow_transports(CMD_CTX, (const char **)transports);
@ -118,8 +116,7 @@ COMMAND_HANDLER(handle_interface_list_command)
return ERROR_COMMAND_SYNTAX_ERROR;
command_print(CMD_CTX, "The following debug interfaces are available:");
for (unsigned i = 0; NULL != jtag_interfaces[i]; i++)
{
for (unsigned i = 0; NULL != jtag_interfaces[i]; i++) {
const char *name = jtag_interfaces[i]->name;
command_print(CMD_CTX, "%u: %s", i + 1, name);
}
@ -132,8 +129,7 @@ COMMAND_HANDLER(handle_interface_command)
int retval;
/* check whether the interface is already configured */
if (jtag_interface)
{
if (jtag_interface) {
LOG_WARNING("Interface already configured, ignoring");
return ERROR_OK;
}
@ -142,13 +138,11 @@ COMMAND_HANDLER(handle_interface_command)
if (CMD_ARGC != 1 || CMD_ARGV[0][0] == '\0')
return ERROR_COMMAND_SYNTAX_ERROR;
for (unsigned i = 0; NULL != jtag_interfaces[i]; i++)
{
for (unsigned i = 0; NULL != jtag_interfaces[i]; i++) {
if (strcmp(CMD_ARGV[0], jtag_interfaces[i]->name) != 0)
continue;
if (NULL != jtag_interfaces[i]->commands)
{
if (NULL != jtag_interfaces[i]->commands) {
retval = register_commands(CMD_CTX, NULL,
jtag_interfaces[i]->commands);
if (ERROR_OK != retval)
@ -391,8 +385,7 @@ COMMAND_HANDLER(handle_adapter_nsrst_delay_command)
{
if (CMD_ARGC > 1)
return ERROR_COMMAND_SYNTAX_ERROR;
if (CMD_ARGC == 1)
{
if (CMD_ARGC == 1) {
unsigned delay;
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], delay);
@ -406,8 +399,7 @@ COMMAND_HANDLER(handle_adapter_nsrst_assert_width_command)
{
if (CMD_ARGC > 1)
return ERROR_COMMAND_SYNTAX_ERROR;
if (CMD_ARGC == 1)
{
if (CMD_ARGC == 1) {
unsigned width;
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], width);
@ -425,8 +417,7 @@ COMMAND_HANDLER(handle_adapter_khz_command)
return ERROR_COMMAND_SYNTAX_ERROR;
int retval = ERROR_OK;
if (CMD_ARGC == 1)
{
if (CMD_ARGC == 1) {
unsigned khz = 0;
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], khz);

View File

@ -27,6 +27,7 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -41,14 +42,14 @@ struct cmd_queue_page {
};
#define CMD_QUEUE_PAGE_SIZE (1024 * 1024)
static struct cmd_queue_page *cmd_queue_pages = NULL;
static struct cmd_queue_page *cmd_queue_pages;
struct jtag_command *jtag_command_queue = NULL;
struct jtag_command *jtag_command_queue;
static struct jtag_command **next_command_pointer = &jtag_command_queue;
void jtag_queue_command(struct jtag_command *cmd)
{
// this command goes on the end, so ensure the queue terminates
/* this command goes on the end, so ensure the queue terminates */
cmd->next = NULL;
struct jtag_command **last_cmd = next_command_pointer;
@ -56,7 +57,7 @@ void jtag_queue_command(struct jtag_command * cmd)
assert(NULL == *last_cmd);
*last_cmd = cmd;
// store location where the next command pointer will be stored
/* store location where the next command pointer will be stored */
next_command_pointer = &cmd->next;
}
@ -98,16 +99,14 @@ void* cmd_queue_alloc(size_t size)
size = (size + ALIGN_SIZE - 1) & (~(ALIGN_SIZE - 1));
/* Done... */
if (*p_page)
{
if (*p_page) {
while ((*p_page)->next)
p_page = &((*p_page)->next);
if (CMD_QUEUE_PAGE_SIZE - (*p_page)->used < size)
p_page = &((*p_page)->next);
}
if (!*p_page)
{
if (!*p_page) {
*p_page = malloc(sizeof(struct cmd_queue_page));
(*p_page)->used = 0;
(*p_page)->address = malloc(CMD_QUEUE_PAGE_SIZE);
@ -125,8 +124,7 @@ static void cmd_queue_free(void)
{
struct cmd_queue_page *page = cmd_queue_pages;
while (page)
{
while (page) {
struct cmd_queue_page *last = page;
free(page->address);
page = page->next;
@ -149,8 +147,7 @@ enum scan_type jtag_scan_type(const struct scan_command *cmd)
int i;
int type = 0;
for (i = 0; i < cmd->num_fields; i++)
{
for (i = 0; i < cmd->num_fields; i++) {
if (cmd->fields[i].in_value)
type |= SCAN_IN;
if (cmd->fields[i].out_value)
@ -167,9 +164,7 @@ int jtag_scan_size(const struct scan_command *cmd)
/* count bits in scan command */
for (i = 0; i < cmd->num_fields; i++)
{
bit_count += cmd->fields[i].num_bits;
}
return bit_count;
}
@ -188,10 +183,8 @@ int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer)
cmd->ir_scan ? "IRSCAN" : "DRSCAN",
cmd->num_fields);
for (i = 0; i < cmd->num_fields; i++)
{
if (cmd->fields[i].out_value)
{
for (i = 0; i < cmd->num_fields; i++) {
if (cmd->fields[i].out_value) {
#ifdef _DEBUG_JTAG_IO_
char *char_buf = buf_to_str(cmd->fields[i].out_value,
(cmd->fields[i].num_bits > DEBUG_JTAG_IOZ)
@ -204,9 +197,7 @@ int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer)
#endif
buf_set_buf(cmd->fields[i].out_value, 0, *buffer,
bit_count, cmd->fields[i].num_bits);
}
else
{
} else {
DEBUG_JTAG_IO("fields[%i].out_value[%i]: NULL",
i, cmd->fields[i].num_bits);
}
@ -214,7 +205,7 @@ int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer)
bit_count += cmd->fields[i].num_bits;
}
//DEBUG_JTAG_IO("bit_count totalling: %i", bit_count);
/*DEBUG_JTAG_IO("bit_count totalling: %i", bit_count); */
return bit_count;
}
@ -228,15 +219,14 @@ int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd)
/* we return ERROR_OK, unless a check fails, or a handler reports a problem */
retval = ERROR_OK;
for (i = 0; i < cmd->num_fields; i++)
{
for (i = 0; i < cmd->num_fields; i++) {
/* if neither in_value nor in_handler
* are specified we don't have to examine this field
*/
if (cmd->fields[i].in_value)
{
if (cmd->fields[i].in_value) {
int num_bits = cmd->fields[i].num_bits;
uint8_t *captured = buf_set_buf(buffer, bit_count, malloc(DIV_ROUND_UP(num_bits, 8)), 0, num_bits);
uint8_t *captured = buf_set_buf(buffer, bit_count,
malloc(DIV_ROUND_UP(num_bits, 8)), 0, num_bits);
#ifdef _DEBUG_JTAG_IO_
char *char_buf = buf_to_str(captured,
@ -250,9 +240,7 @@ int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd)
#endif
if (cmd->fields[i].in_value)
{
buf_cpy(captured, cmd->fields[i].in_value, num_bits);
}
free(captured);
}
@ -261,5 +249,3 @@ int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd)
return retval;
}

View File

@ -23,6 +23,7 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef JTAG_COMMANDS_H
#define JTAG_COMMANDS_H
@ -32,11 +33,11 @@
* to the device, or both.
*/
enum scan_type {
/// From device to host,
/** From device to host, */
SCAN_IN = 1,
/// From host to device,
/** From host to device, */
SCAN_OUT = 2,
/// Full-duplex scan.
/** Full-duplex scan. */
SCAN_IO = 3
};
@ -45,56 +46,56 @@ enum scan_type {
* structures that should be scanned in/out to the device.
*/
struct scan_command {
/// instruction/not data scan
/** instruction/not data scan */
bool ir_scan;
/// number of fields in *fields array
/** number of fields in *fields array */
int num_fields;
/// pointer to an array of data scan fields
/** pointer to an array of data scan fields */
struct scan_field *fields;
/// state in which JTAG commands should finish
/** state in which JTAG commands should finish */
tap_state_t end_state;
};
struct statemove_command {
/// state in which JTAG commands should finish
/** state in which JTAG commands should finish */
tap_state_t end_state;
};
struct pathmove_command {
/// number of states in *path
/** number of states in *path */
int num_states;
/// states that have to be passed
/** states that have to be passed */
tap_state_t *path;
};
struct runtest_command {
/// number of cycles to spend in Run-Test/Idle state
/** number of cycles to spend in Run-Test/Idle state */
int num_cycles;
/// state in which JTAG commands should finish
/** state in which JTAG commands should finish */
tap_state_t end_state;
};
struct stableclocks_command {
/// number of clock cycles that should be sent
/** number of clock cycles that should be sent */
int num_cycles;
};
struct reset_command {
/// Set TRST output: 0 = deassert, 1 = assert, -1 = no change
/** Set TRST output: 0 = deassert, 1 = assert, -1 = no change */
int trst;
/// Set SRST output: 0 = deassert, 1 = assert, -1 = no change
/** Set SRST output: 0 = deassert, 1 = assert, -1 = no change */
int srst;
};
struct end_state_command {
/// state in which JTAG commands should finish
/** state in which JTAG commands should finish */
tap_state_t end_state;
};
struct sleep_command {
/// number of microseconds to sleep
/** number of microseconds to sleep */
uint32_t us;
};
@ -161,7 +162,7 @@ struct jtag_command {
struct jtag_command *next;
};
/// The current queue of jtag_command_s structures.
/** The current queue of jtag_command_s structures. */
extern struct jtag_command *jtag_command_queue;
void *cmd_queue_alloc(size_t size);
@ -174,4 +175,4 @@ int jtag_scan_size(const struct scan_command* cmd);
int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd);
int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer);
#endif // JTAG_COMMANDS_H
#endif /* JTAG_COMMANDS_H */

View File

@ -27,6 +27,7 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -43,14 +44,17 @@
#include "svf/svf.h"
#include "xsvf/xsvf.h"
/// The number of JTAG queue flushes (for profiling and debugging purposes).
/** The number of JTAG queue flushes (for profiling and debugging purposes). */
static int jtag_flush_queue_count;
// Sleep this # of ms after flushing the queue
static int jtag_flush_queue_sleep = 0;
/* Sleep this # of ms after flushing the queue */
static int jtag_flush_queue_sleep;
static void jtag_add_scan_check(struct jtag_tap *active,
void (*jtag_add_scan)(struct jtag_tap *active, int in_num_fields, const struct scan_field *in_fields, tap_state_t state),
void (*jtag_add_scan)(struct jtag_tap *active,
int in_num_fields,
const struct scan_field *in_fields,
tap_state_t state),
int in_num_fields, struct scan_field *in_fields, tap_state_t state);
/**
@ -65,8 +69,7 @@ static void jtag_add_scan_check(struct jtag_tap *active,
*/
static int jtag_error = ERROR_OK;
static const char *jtag_event_strings[] =
{
static const char *jtag_event_strings[] = {
[JTAG_TRST_ASSERTED] = "TAP reset",
[JTAG_TAP_EVENT_SETUP] = "TAP setup",
[JTAG_TAP_EVENT_ENABLE] = "TAP enabled",
@ -85,12 +88,12 @@ static int jtag_srst = -1;
/**
* List all TAPs that have been created.
*/
static struct jtag_tap *__jtag_all_taps = NULL;
static struct jtag_tap *__jtag_all_taps;
/**
* The number of TAPs in the __jtag_all_taps list, used to track the
* assigned chain position to new TAPs
*/
static unsigned jtag_num_taps = 0;
static unsigned jtag_num_taps;
static enum reset_types jtag_reset_config = RESET_NONE;
tap_state_t cmd_queue_cur_state = TAP_RESET;
@ -98,22 +101,23 @@ tap_state_t cmd_queue_cur_state = TAP_RESET;
static bool jtag_verify_capture_ir = true;
static int jtag_verify = 1;
/* how long the OpenOCD should wait before attempting JTAG communication after reset lines deasserted (in ms) */
static int adapter_nsrst_delay = 0; /* default to no nSRST delay */
static int jtag_ntrst_delay = 0; /* default to no nTRST delay */
static int adapter_nsrst_assert_width = 0; /* width of assertion */
static int jtag_ntrst_assert_width = 0; /* width of assertion */
/* how long the OpenOCD should wait before attempting JTAG communication after reset lines
*deasserted (in ms) */
static int adapter_nsrst_delay; /* default to no nSRST delay */
static int jtag_ntrst_delay;/* default to no nTRST delay */
static int adapter_nsrst_assert_width; /* width of assertion */
static int jtag_ntrst_assert_width; /* width of assertion */
/**
* Contains a single callback along with a pointer that will be passed
* when an event occurs.
*/
struct jtag_event_callback {
/// a event callback
/* / a event callback */
jtag_event_handler_t callback;
/// the private data to pass to the callback
/* / the private data to pass to the callback */
void *priv;
/// the next callback
/* / the next callback */
struct jtag_event_callback *next;
};
@ -121,19 +125,18 @@ struct jtag_event_callback {
static struct jtag_event_callback *jtag_event_callbacks;
/* speed in kHz*/
static int speed_khz = 0;
static int speed_khz;
/* speed to fallback to when RCLK is requested but not supported */
static int rclk_fallback_speed_khz = 0;
static int rclk_fallback_speed_khz;
static enum {CLOCK_MODE_UNSELECTED, CLOCK_MODE_KHZ, CLOCK_MODE_RCLK} clock_mode;
static int jtag_speed = 0;
static int jtag_speed;
static struct jtag_interface *jtag = NULL;
static struct jtag_interface *jtag;
const struct swd_driver *swd = NULL;
const struct swd_driver *swd;
/* configuration */
struct jtag_interface *jtag_interface = NULL;
struct jtag_interface *jtag_interface;
void jtag_set_flush_queue_sleep(int ms)
{
@ -195,8 +198,7 @@ unsigned jtag_tap_count_enabled(void)
{
struct jtag_tap *t = jtag_all_taps();
unsigned n = 0;
while (t)
{
while (t) {
if (t->enabled)
n++;
t = t->next_tap;
@ -204,7 +206,7 @@ unsigned jtag_tap_count_enabled(void)
return n;
}
/// Append a new TAP to the chain of all taps.
/* / Append a new TAP to the chain of all taps. */
void jtag_tap_add(struct jtag_tap *t)
{
t->abs_chain_position = jtag_num_taps++;
@ -231,8 +233,7 @@ struct jtag_tap *jtag_tap_by_string(const char *s)
/* try by name first */
struct jtag_tap *t = jtag_all_taps();
while (t)
{
while (t) {
if (0 == strcmp(t->dotted_name, s))
return t;
t = t->next_tap;
@ -258,8 +259,7 @@ struct jtag_tap *jtag_tap_by_string(const char *s)
struct jtag_tap *jtag_tap_next_enabled(struct jtag_tap *p)
{
p = p ? p->next_tap : jtag_all_taps();
while (p)
{
while (p) {
if (p->enabled)
return p;
p = p->next_tap;
@ -278,12 +278,9 @@ int jtag_register_event_callback(jtag_event_handler_t callback, void *priv)
struct jtag_event_callback **callbacks_p = &jtag_event_callbacks;
if (callback == NULL)
{
return ERROR_COMMAND_SYNTAX_ERROR;
}
if (*callbacks_p)
{
if (*callbacks_p) {
while ((*callbacks_p)->next)
callbacks_p = &((*callbacks_p)->next);
callbacks_p = &((*callbacks_p)->next);
@ -302,14 +299,10 @@ int jtag_unregister_event_callback(jtag_event_handler_t callback, void *priv)
struct jtag_event_callback **p = &jtag_event_callbacks, *temp;
if (callback == NULL)
{
return ERROR_COMMAND_SYNTAX_ERROR;
}
while (*p)
{
if (((*p)->priv != priv) || ((*p)->callback != callback))
{
while (*p) {
if (((*p)->priv != priv) || ((*p)->callback != callback)) {
p = &(*p)->next;
continue;
}
@ -328,8 +321,7 @@ int jtag_call_event_callbacks(enum jtag_event event)
LOG_DEBUG("jtag event: %s", jtag_event_strings[event]);
while (callback)
{
while (callback) {
struct jtag_event_callback *next;
/* callback may remove itself */
@ -364,7 +356,9 @@ void jtag_add_ir_scan_noverify(struct jtag_tap *active, const struct scan_field
jtag_set_error(retval);
}
static void jtag_add_ir_scan_noverify_callback(struct jtag_tap *active, int dummy, const struct scan_field *in_fields,
static void jtag_add_ir_scan_noverify_callback(struct jtag_tap *active,
int dummy,
const struct scan_field *in_fields,
tap_state_t state)
{
jtag_add_ir_scan_noverify(active, in_fields, state);
@ -375,8 +369,7 @@ void jtag_add_ir_scan(struct jtag_tap *active, struct scan_field *in_fields, tap
{
assert(state != TAP_RESET);
if (jtag_verify && jtag_verify_capture_ir)
{
if (jtag_verify && jtag_verify_capture_ir) {
/* 8 x 32 bit id's is enough for all invocations */
/* if we are to run a verification of the ir scan, we need to get the input back.
@ -384,12 +377,11 @@ void jtag_add_ir_scan(struct jtag_tap *active, struct scan_field *in_fields, tap
*/
in_fields->check_value = active->expected;
in_fields->check_mask = active->expected_mask;
jtag_add_scan_check(active, jtag_add_ir_scan_noverify_callback, 1, in_fields, state);
jtag_add_scan_check(active, jtag_add_ir_scan_noverify_callback, 1, in_fields,
state);
} else
{
jtag_add_ir_scan_noverify(active, in_fields, state);
}
}
void jtag_add_plain_ir_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits,
tap_state_t state)
@ -407,22 +399,31 @@ void jtag_add_plain_ir_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_b
static int jtag_check_value_inner(uint8_t *captured, uint8_t *in_check_value,
uint8_t *in_check_mask, int num_bits);
static int jtag_check_value_mask_callback(jtag_callback_data_t data0, jtag_callback_data_t data1, jtag_callback_data_t data2, jtag_callback_data_t data3)
static int jtag_check_value_mask_callback(jtag_callback_data_t data0,
jtag_callback_data_t data1,
jtag_callback_data_t data2,
jtag_callback_data_t data3)
{
return jtag_check_value_inner((uint8_t *)data0, (uint8_t *)data1, (uint8_t *)data2, (int)data3);
return jtag_check_value_inner((uint8_t *)data0,
(uint8_t *)data1,
(uint8_t *)data2,
(int)data3);
}
static void jtag_add_scan_check(struct jtag_tap *active, void (*jtag_add_scan)(struct jtag_tap *active, int in_num_fields, const struct scan_field *in_fields, tap_state_t state),
static void jtag_add_scan_check(struct jtag_tap *active, void (*jtag_add_scan)(
struct jtag_tap *active,
int in_num_fields,
const struct scan_field *in_fields,
tap_state_t state),
int in_num_fields, struct scan_field *in_fields, tap_state_t state)
{
jtag_add_scan(active, in_num_fields, in_fields, state);
for (int i = 0; i < in_num_fields; i++)
{
if ((in_fields[i].check_value != NULL) && (in_fields[i].in_value != NULL))
{
for (int i = 0; i < in_num_fields; i++) {
if ((in_fields[i].check_value != NULL) && (in_fields[i].in_value != NULL)) {
/* this is synchronous for a minidriver */
jtag_add_callback4(jtag_check_value_mask_callback, (jtag_callback_data_t)in_fields[i].in_value,
jtag_add_callback4(jtag_check_value_mask_callback,
(jtag_callback_data_t)in_fields[i].in_value,
(jtag_callback_data_t)in_fields[i].check_value,
(jtag_callback_data_t)in_fields[i].check_mask,
(jtag_callback_data_t)in_fields[i].num_bits);
@ -430,19 +431,21 @@ static void jtag_add_scan_check(struct jtag_tap *active, void (*jtag_add_scan)(s
}
}
void jtag_add_dr_scan_check(struct jtag_tap *active, int in_num_fields, struct scan_field *in_fields, tap_state_t state)
void jtag_add_dr_scan_check(struct jtag_tap *active,
int in_num_fields,
struct scan_field *in_fields,
tap_state_t state)
{
if (jtag_verify)
{
jtag_add_scan_check(active, jtag_add_dr_scan, in_num_fields, in_fields, state);
} else
{
else
jtag_add_dr_scan(active, in_num_fields, in_fields, state);
}
}
void jtag_add_dr_scan(struct jtag_tap *active, int in_num_fields, const struct scan_field *in_fields,
void jtag_add_dr_scan(struct jtag_tap *active,
int in_num_fields,
const struct scan_field *in_fields,
tap_state_t state)
{
assert(state != TAP_RESET);
@ -511,25 +514,21 @@ void jtag_add_pathmove(int num_states, const tap_state_t *path)
tap_state_t cur_state = cmd_queue_cur_state;
/* the last state has to be a stable state */
if (!tap_is_state_stable(path[num_states - 1]))
{
if (!tap_is_state_stable(path[num_states - 1])) {
LOG_ERROR("BUG: TAP path doesn't finish in a stable state");
jtag_set_error(ERROR_JTAG_NOT_STABLE_STATE);
return;
}
for (int i = 0; i < num_states; i++)
{
if (path[i] == TAP_RESET)
{
for (int i = 0; i < num_states; i++) {
if (path[i] == TAP_RESET) {
LOG_ERROR("BUG: TAP_RESET is not a valid state for pathmove sequences");
jtag_set_error(ERROR_JTAG_STATE_INVALID);
return;
}
if (tap_state_transition(cur_state, true) != path[i]
&& tap_state_transition(cur_state, false) != path[i])
{
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]));
jtag_set_error(ERROR_JTAG_TRANSITION_INVALID);
@ -548,8 +547,7 @@ int jtag_add_statemove(tap_state_t goal_state)
{
tap_state_t cur_state = cmd_queue_cur_state;
if (goal_state != cur_state)
{
if (goal_state != cur_state) {
LOG_DEBUG("cur_state=%s goal_state=%s",
tap_state_name(cur_state),
tap_state_name(goal_state));
@ -563,15 +561,13 @@ int jtag_add_statemove(tap_state_t goal_state)
else if (goal_state == cur_state)
/* nothing to do */;
else if (tap_is_state_stable(cur_state) && tap_is_state_stable(goal_state))
{
else if (tap_is_state_stable(cur_state) && tap_is_state_stable(goal_state)) {
unsigned tms_bits = tap_get_tms_path(cur_state, goal_state);
unsigned tms_count = tap_get_tms_path_len(cur_state, goal_state);
tap_state_t moves[8];
assert(tms_count < ARRAY_SIZE(moves));
for (unsigned i = 0; i < tms_count; i++, tms_bits >>= 1)
{
for (unsigned i = 0; i < tms_count; i++, tms_bits >>= 1) {
bool bit = tms_bits & 1;
cur_state = tap_state_transition(cur_state, bit);
@ -579,13 +575,9 @@ int jtag_add_statemove(tap_state_t goal_state)
}
jtag_add_pathmove(tms_count, moves);
}
else if (tap_state_transition(cur_state, true) == goal_state
} else if (tap_state_transition(cur_state, true) == goal_state
|| tap_state_transition(cur_state, false) == goal_state)
{
jtag_add_pathmove(1, &goal_state);
}
else
return ERROR_FAIL;
@ -601,16 +593,14 @@ void jtag_add_runtest(int num_cycles, tap_state_t state)
void jtag_add_clocks(int num_cycles)
{
if (!tap_is_state_stable(cmd_queue_cur_state))
{
if (!tap_is_state_stable(cmd_queue_cur_state)) {
LOG_ERROR("jtag_add_clocks() called with TAP in unstable state \"%s\"",
tap_state_name(cmd_queue_cur_state));
jtag_set_error(ERROR_JTAG_NOT_STABLE_STATE);
return;
}
if (num_cycles > 0)
{
if (num_cycles > 0) {
jtag_checks();
jtag_set_error(interface_jtag_add_clocks(num_cycles));
}
@ -680,13 +670,11 @@ void jtag_add_reset(int req_tlr_or_trst, int req_srst)
/* SRST resets everything hooked up to that signal */
if (jtag_srst != new_srst) {
jtag_srst = new_srst;
if (jtag_srst)
{
if (jtag_srst) {
LOG_DEBUG("SRST line asserted");
if (adapter_nsrst_assert_width)
jtag_add_sleep(adapter_nsrst_assert_width * 1000);
}
else {
} else {
LOG_DEBUG("SRST line released");
if (adapter_nsrst_delay)
jtag_add_sleep(adapter_nsrst_delay * 1000);
@ -728,7 +716,7 @@ void jtag_add_reset(int req_tlr_or_trst, int req_srst)
void jtag_add_sleep(uint32_t us)
{
/// @todo Here, keep_alive() appears to be a layering violation!!!
/* / @todo Here, keep_alive() appears to be a layering violation!!! */
keep_alive();
jtag_set_error(interface_jtag_add_sleep(us));
}
@ -746,9 +734,7 @@ static int jtag_check_value_inner(uint8_t *captured, uint8_t *in_check_value,
if (compare_failed) {
char *captured_str, *in_check_value_str;
int bits = (num_bits > DEBUG_JTAG_IOZ)
? DEBUG_JTAG_IOZ
: num_bits;
int bits = (num_bits > DEBUG_JTAG_IOZ) ? DEBUG_JTAG_IOZ : num_bits;
/* NOTE: we've lost diagnostic context here -- 'which tap' */
@ -779,8 +765,7 @@ void jtag_check_value_mask(struct scan_field *field, uint8_t *value, uint8_t *ma
{
assert(field->in_value != NULL);
if (value == NULL)
{
if (value == NULL) {
/* no checking to do */
return;
}
@ -791,12 +776,9 @@ void jtag_check_value_mask(struct scan_field *field, uint8_t *value, uint8_t *ma
jtag_set_error(retval);
}
int default_interface_jtag_execute_queue(void)
{
if (NULL == jtag)
{
if (NULL == jtag) {
LOG_ERROR("No JTAG interface configured yet. "
"Issue 'init' command in startup scripts "
"before communicating with targets.");
@ -811,8 +793,7 @@ void jtag_execute_queue_noclear(void)
jtag_flush_queue_count++;
jtag_set_error(interface_jtag_execute_queue());
if (jtag_flush_queue_sleep > 0)
{
if (jtag_flush_queue_sleep > 0) {
/* For debug purposes it can be useful to test performance
* or behavior when delaying after flushing the queue,
* e.g. to simulate long roundtrip times.
@ -836,8 +817,7 @@ static int jtag_reset_callback(enum jtag_event event, void *priv)
{
struct jtag_tap *tap = priv;
if (event == JTAG_TRST_ASSERTED)
{
if (event == JTAG_TRST_ASSERTED) {
tap->enabled = !tap->disabled_after_reset;
/* current instruction is either BYPASS or IDCODE */
@ -886,7 +866,7 @@ static int jtag_examine_chain_execute(uint8_t *idcode_buffer, unsigned num_idcod
.in_value = idcode_buffer,
};
// initialize to the end of chain ID value
/* initialize to the end of chain ID value */
for (unsigned i = 0; i < JTAG_MAX_CHAIN_SIZE; i++)
buf_set_u32(idcode_buffer, i * 32, 32, END_OF_CHAIN_FLAG);
@ -900,8 +880,7 @@ static bool jtag_examine_chain_check(uint8_t *idcodes, unsigned count)
uint8_t zero_check = 0x0;
uint8_t one_check = 0xff;
for (unsigned i = 0; i < count * 4; i++)
{
for (unsigned i = 0; i < count * 4; i++) {
zero_check |= idcodes[i];
one_check &= idcodes[i];
}
@ -916,8 +895,7 @@ static bool jtag_examine_chain_check(uint8_t *idcodes, unsigned count)
* + there are several hundreds of TAPs in bypass, or
* + at least a few dozen TAPs all have an all-ones IDCODE
*/
if (zero_check == 0x00 || one_check == 0xff)
{
if (zero_check == 0x00 || one_check == 0xff) {
LOG_ERROR("JTAG scan chain interrogation failed: all %s",
(zero_check == 0x00) ? "zeroes" : "ones");
LOG_ERROR("Check JTAG interface, timings, target power, etc.");
@ -929,7 +907,7 @@ static bool jtag_examine_chain_check(uint8_t *idcodes, unsigned count)
static void jtag_examine_chain_display(enum log_levels level, const char *msg,
const char *name, uint32_t idcode)
{
log_printf_lf(level, __FILE__, __LINE__, __FUNCTION__,
log_printf_lf(level, __FILE__, __LINE__, __func__,
"JTAG tap: %s %16.16s: 0x%08x "
"(mfg: 0x%3.3x, part: 0x%4.4x, ver: 0x%1.1x)",
name, msg,
@ -959,8 +937,7 @@ static bool jtag_idcode_is_final(uint32_t idcode)
static bool jtag_examine_chain_end(uint8_t *idcodes, unsigned count, unsigned max)
{
bool triggered = false;
for (; count < max - 31; count += 32)
{
for (; count < max - 31; count += 32) {
uint32_t idcode = buf_get_u32(idcodes, count, 32);
/* do not trigger the warning if the data looks good */
@ -989,8 +966,7 @@ static bool jtag_examine_chain_match_tap(const struct jtag_tap *tap)
/* Loop over the expected identification codes and test for a match */
unsigned ii, limit = tap->expected_ids_cnt;
for (ii = 0; ii < limit; ii++)
{
for (ii = 0; ii < limit; ii++) {
uint32_t expected = tap->expected_ids[ii] & mask;
if (idcode == expected)
@ -1004,8 +980,7 @@ static bool jtag_examine_chain_match_tap(const struct jtag_tap *tap)
/* If none of the expected ids matched, warn */
jtag_examine_chain_display(LOG_LVL_WARNING, "UNEXPECTED",
tap->dotted_name, tap->idcode);
for (ii = 0; ii < limit; ii++)
{
for (ii = 0; ii < limit; ii++) {
char msg[32];
snprintf(msg, sizeof(msg), "expected %u of %u", ii + 1, limit);
@ -1044,12 +1019,10 @@ static int jtag_examine_chain(void)
for (bit_count = 0;
tap && bit_count < (JTAG_MAX_CHAIN_SIZE * 32) - 31;
tap = jtag_tap_next_enabled(tap))
{
tap = jtag_tap_next_enabled(tap)) {
uint32_t idcode = buf_get_u32(idcode_buffer, bit_count, 32);
if ((idcode & 1) == 0)
{
if ((idcode & 1) == 0) {
/* Zero for LSB indicates a device in bypass */
LOG_INFO("TAP %s does not have IDCODE",
tap->dotted_name);
@ -1057,9 +1030,7 @@ static int jtag_examine_chain(void)
tap->hasidcode = false;
bit_count += 1;
}
else
{
} else {
/* Friendly devices support IDCODE */
tap->hasidcode = true;
jtag_examine_chain_display(LOG_LVL_INFO,
@ -1203,9 +1174,8 @@ static int jtag_validate_ircapture(void)
for (;; ) {
tap = jtag_tap_next_enabled(tap);
if (tap == NULL) {
if (tap == NULL)
break;
}
/* If we're autoprobing, guess IR lengths. They must be at
* least two bits. Guessing will fail if (a) any TAP does
@ -1225,8 +1195,7 @@ static int jtag_validate_ircapture(void)
*/
if (tap->ir_length == 0) {
tap->ir_length = 2;
while ((val = buf_get_u32(ir_test, chain_pos,
tap->ir_length + 1)) == 1
while ((val = buf_get_u32(ir_test, chain_pos, tap->ir_length + 1)) == 1
&& tap->ir_length <= 32) {
tap->ir_length++;
}
@ -1260,8 +1229,7 @@ static int jtag_validate_ircapture(void)
/* verify the '11' sentinel we wrote is returned at the end */
val = buf_get_u32(ir_test, chain_pos, 2);
if (val != 0x3)
{
if (val != 0x3) {
char *cbuf = buf_to_str(ir_test, total_ir_length, 16);
LOG_ERROR("IR capture error at bit %d, saw 0x%s not 0x...3",
@ -1279,7 +1247,6 @@ done:
return retval;
}
void jtag_tap_init(struct jtag_tap *tap)
{
unsigned ir_len_bits;
@ -1293,18 +1260,18 @@ void jtag_tap_init(struct jtag_tap *tap)
tap->expected_mask = calloc(1, ir_len_bytes);
tap->cur_instr = malloc(ir_len_bytes);
/// @todo cope better with ir_length bigger than 32 bits
/* / @todo cope better with ir_length bigger than 32 bits */
if (ir_len_bits > 32)
ir_len_bits = 32;
buf_set_u32(tap->expected, 0, ir_len_bits, tap->ir_capture_value);
buf_set_u32(tap->expected_mask, 0, ir_len_bits, tap->ir_capture_mask);
// TAP will be in bypass mode after jtag_validate_ircapture()
/* TAP will be in bypass mode after jtag_validate_ircapture() */
tap->bypass = 1;
buf_set_ones(tap->cur_instr, tap->ir_length);
// register the reset callback for the TAP
/* register the reset callback for the TAP */
jtag_register_event_callback(&jtag_reset_callback, tap);
LOG_DEBUG("Created Tap: %s @ abs position %d, "
@ -1319,7 +1286,7 @@ void jtag_tap_free(struct jtag_tap *tap)
{
jtag_unregister_event_callback(&jtag_reset_callback, tap);
/// @todo is anything missing? no memory leaks please
/* / @todo is anything missing? no memory leaks please */
free((void *)tap->expected);
free((void *)tap->expected_ids);
free((void *)tap->chip);
@ -1337,8 +1304,7 @@ int adapter_init(struct command_context *cmd_ctx)
if (jtag)
return ERROR_OK;
if (!jtag_interface)
{
if (!jtag_interface) {
/* nothing was previously specified by "interface" command */
LOG_ERROR("Debug Adapter has to be specified, "
"see \"interface\" command");
@ -1348,9 +1314,7 @@ int adapter_init(struct command_context *cmd_ctx)
int retval;
retval = jtag_interface->init();
if (retval != ERROR_OK)
{
return retval;
}
jtag = jtag_interface;
/* LEGACY SUPPORT ... adapter drivers must declare what
@ -1366,8 +1330,7 @@ int adapter_init(struct command_context *cmd_ctx)
return retval;
}
if (CLOCK_MODE_UNSELECTED == clock_mode)
{
if (CLOCK_MODE_UNSELECTED == clock_mode) {
LOG_ERROR("An adapter speed is not selected in the init script."
" Insert a call to adapter_khz or jtag_rclk to proceed.");
return ERROR_JTAG_INIT_FAILED;
@ -1385,19 +1348,15 @@ int adapter_init(struct command_context *cmd_ctx)
retval = jtag_get_speed_readable(&actual_khz);
if (ERROR_OK != retval)
LOG_INFO("adapter-specific clock speed value %d", jtag_speed_var);
else if (actual_khz)
{
else if (actual_khz) {
/* Adaptive clocking -- JTAG-specific */
if ((CLOCK_MODE_RCLK == clock_mode)
|| ((CLOCK_MODE_KHZ == clock_mode) && !requested_khz))
{
|| ((CLOCK_MODE_KHZ == clock_mode) && !requested_khz)) {
LOG_INFO("RCLK (adaptive clock speed) not supported - fallback to %d kHz"
, actual_khz);
}
else
} else
LOG_INFO("clock speed %d kHz", actual_khz);
}
else
} else
LOG_INFO("RCLK (adaptive clock speed)");
return ERROR_OK;
@ -1431,7 +1390,8 @@ int jtag_init_inner(struct command_context *cmd_ctx)
}
jtag_add_tlr();
if ((retval = jtag_execute_queue()) != ERROR_OK)
retval = jtag_execute_queue();
if (retval != ERROR_OK)
return retval;
/* Examine DR values first. This discovers problems which will
@ -1465,8 +1425,7 @@ int jtag_init_inner(struct command_context *cmd_ctx)
* ircapture/irmask values during TAP setup.)
*/
retval = jtag_validate_ircapture();
if (retval != ERROR_OK)
{
if (retval != ERROR_OK) {
/* The target might be powered down. The user
* can power it up and reset it after firing
* up OpenOCD.
@ -1488,7 +1447,7 @@ int adapter_quit(void)
if (!jtag || !jtag->quit)
return ERROR_OK;
// close the JTAG interface
/* close the JTAG interface */
int result = jtag->quit();
if (ERROR_OK != result)
LOG_ERROR("failed: %d", result);
@ -1499,9 +1458,8 @@ int adapter_quit(void)
int jtag_init_reset(struct command_context *cmd_ctx)
{
int retval;
if ((retval = adapter_init(cmd_ctx)) != ERROR_OK)
int retval = adapter_init(cmd_ctx);
if (retval != ERROR_OK)
return retval;
LOG_DEBUG("Initializing with hard TRST+SRST reset");
@ -1531,14 +1489,14 @@ int jtag_init_reset(struct command_context *cmd_ctx)
* need to be a C routine at all...
*/
jtag_add_reset(1, 0); /* TAP_RESET, using TMS+TCK or TRST */
if (jtag_reset_config & RESET_HAS_SRST)
{
if (jtag_reset_config & RESET_HAS_SRST) {
jtag_add_reset(1, 1);
if ((jtag_reset_config & RESET_SRST_PULLS_TRST) == 0)
jtag_add_reset(0, 1);
}
jtag_add_reset(0, 0);
if ((retval = jtag_execute_queue()) != ERROR_OK)
retval = jtag_execute_queue();
if (retval != ERROR_OK)
return retval;
/* Check that we can communication on the JTAG chain + eventually we want to
@ -1553,14 +1511,14 @@ int jtag_init_reset(struct command_context *cmd_ctx)
int jtag_init(struct command_context *cmd_ctx)
{
int retval;
if ((retval = adapter_init(cmd_ctx)) != ERROR_OK)
int retval = adapter_init(cmd_ctx);
if (retval != ERROR_OK)
return retval;
/* guard against oddball hardware: force resets to be inactive */
jtag_add_reset(0, 0);
if ((retval = jtag_execute_queue()) != ERROR_OK)
retval = jtag_execute_queue();
if (retval != ERROR_OK)
return retval;
if (Jim_Eval_Named(cmd_ctx->interp, "jtag_init", __FILE__, __LINE__) != JIM_OK)
@ -1578,15 +1536,12 @@ static int adapter_khz_to_speed(unsigned khz, int* speed)
{
LOG_DEBUG("convert khz to interface specific speed value");
speed_khz = khz;
if (jtag != NULL)
{
if (jtag != NULL) {
LOG_DEBUG("have interface set up");
int speed_div1;
int retval = jtag->khz(jtag_get_speed_khz(), &speed_div1);
if (ERROR_OK != retval)
{
return retval;
}
*speed = speed_div1;
}
return ERROR_OK;
@ -1595,8 +1550,7 @@ static int adapter_khz_to_speed(unsigned khz, int* speed)
static int jtag_rclk_to_speed(unsigned fallback_speed_khz, int *speed)
{
int retval = adapter_khz_to_speed(0, speed);
if ((ERROR_OK != retval) && fallback_speed_khz)
{
if ((ERROR_OK != retval) && fallback_speed_khz) {
LOG_DEBUG("trying fallback speed...");
retval = adapter_khz_to_speed(fallback_speed_khz, speed);
}
@ -1632,8 +1586,7 @@ int jtag_config_rclk(unsigned fallback_speed_khz)
int jtag_get_speed(int *speed)
{
switch(clock_mode)
{
switch (clock_mode) {
case CLOCK_MODE_KHZ:
adapter_khz_to_speed(jtag_get_speed_khz(), speed);
break;
@ -1678,8 +1631,7 @@ bool jtag_will_verify_capture_ir()
int jtag_power_dropout(int *dropout)
{
if (jtag == NULL)
{
if (jtag == NULL) {
/* TODO: as the jtag interface is not valid all
* we can do at the moment is exit OpenOCD */
LOG_ERROR("No Valid JTAG Interface Configured.");

View File

@ -1,4 +1,28 @@
/***************************************************************************
* Copyright (C) 2005 by Dominic Rath *
* Dominic.Rath@gmx.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef JTAG_DRIVER_H
#define JTAG_DRIVER_H
struct command_context;
int interface_register_commands(struct command_context *ctx);
#endif /* JTAG_DRIVER_H */

View File

@ -27,6 +27,7 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -60,7 +61,7 @@ static tap_state_t end_state_follower = TAP_RESET;
void tap_set_end_state(tap_state_t new_end_state)
{
/* this is the state we think the TAPs will be in at completion of the
current TAP operation, was end_state
* current TAP operation, was end_state
*/
end_state_follower = new_end_state;
}
@ -70,7 +71,6 @@ tap_state_t tap_get_end_state()
return end_state_follower;
}
int tap_move_ndx(tap_state_t astate)
{
/* given a stable state, return the index into the tms_seqs[]
@ -79,14 +79,25 @@ int tap_move_ndx(tap_state_t astate)
int ndx;
switch (astate)
{
case TAP_RESET: ndx = 0; break;
case TAP_IDLE: ndx = 1; break;
case TAP_DRSHIFT: ndx = 2; break;
case TAP_DRPAUSE: ndx = 3; break;
case TAP_IRSHIFT: ndx = 4; break;
case TAP_IRPAUSE: ndx = 5; break;
switch (astate) {
case TAP_RESET:
ndx = 0;
break;
case TAP_IDLE:
ndx = 1;
break;
case TAP_DRSHIFT:
ndx = 2;
break;
case TAP_DRPAUSE:
ndx = 3;
break;
case TAP_IRSHIFT:
ndx = 4;
break;
case TAP_IRPAUSE:
ndx = 5;
break;
default:
LOG_ERROR("FATAL: unstable state \"%s\" in tap_move_ndx()",
tap_state_name(astate));
@ -96,14 +107,12 @@ int tap_move_ndx(tap_state_t astate)
return ndx;
}
/* tap_move[i][j]: tap movement command to go from state i to state j
* encodings of i and j are what tap_move_ndx() reports.
*
* DRSHIFT->DRSHIFT and IRSHIFT->IRSHIFT have to be caught in interface specific code
*/
struct tms_sequences
{
struct tms_sequences {
uint8_t bits;
uint8_t bit_count;
};
@ -115,19 +124,18 @@ struct tms_sequences
#define HEX__(n) 0x##n##LU
#define B8__(x) \
(((x) & 0x0000000FLU)?(1 << 0):0) \
((((x) & 0x0000000FLU) ? (1 << 0) : 0) \
+(((x) & 0x000000F0LU) ? (1 << 1) : 0) \
+(((x) & 0x00000F00LU) ? (1 << 2) : 0) \
+(((x) & 0x0000F000LU) ? (1 << 3) : 0) \
+(((x) & 0x000F0000LU) ? (1 << 4) : 0) \
+(((x) & 0x00F00000LU) ? (1 << 5) : 0) \
+(((x) & 0x0F000000LU) ? (1 << 6) : 0) \
+(((x) & 0xF0000000LU)?(1 << 7):0)
+(((x) & 0xF0000000LU) ? (1 << 7) : 0))
#define B8(bits, count) {((uint8_t)B8__(HEX__(bits))), (count)}
static const struct tms_sequences old_tms_seqs[6][6] = /* [from_state_ndx][to_state_ndx] */
{
static const struct tms_sequences old_tms_seqs[6][6] = { /* [from_state_ndx][to_state_ndx] */
/* value clocked to TMS to move from one of six stable states to another.
* N.B. OOCD clocks TMS from LSB first, so read these right-to-left.
* N.B. Reset only needs to be 0b11111, but in JLink an even byte of 1's is more stable.
@ -144,10 +152,7 @@ static const struct tms_sequences old_tms_seqs[6][6] = /* [from_state_ndx][to_
{B8(1111111, 7), B8(0110000, 7), B8(0011100, 7), B8(0010111, 7), B8(0011110, 7), B8(0101111, 7)},/* IRPAUSE */
};
static const struct tms_sequences short_tms_seqs[6][6] = /* [from_state_ndx][to_state_ndx] */
{
static const struct tms_sequences short_tms_seqs[6][6] = { /* [from_state_ndx][to_state_ndx] */
/* this is the table submitted by Jeff Williams on 3/30/2009 with this comment:
OK, I added Peter's version of the state table, and it works OK for
@ -189,7 +194,6 @@ static const struct tms_sequences short_tms_seqs[6][6] = /* [from_state_ndx][t
{B8(1111111, 7), B8(011, 3), B8(01, 2), B8(0, 1), B8(001111, 6), B8(0101111, 7)}, /* DRPAUSE */
{B8(1111111, 7), B8(011, 3), B8(00111, 5), B8(010111, 6), B8(001111, 6), B8(01, 2)}, /* IRSHIFT */
{B8(1111111, 7), B8(011, 3), B8(00111, 5), B8(010111, 6), B8(01, 2), B8(0, 1)} /* IRPAUSE */
};
typedef const struct tms_sequences tms_table[6][6];
@ -201,22 +205,19 @@ int tap_get_tms_path(tap_state_t from, tap_state_t to)
return (*tms_seqs)[tap_move_ndx(from)][tap_move_ndx(to)].bits;
}
int tap_get_tms_path_len(tap_state_t from, tap_state_t to)
{
return (*tms_seqs)[tap_move_ndx(from)][tap_move_ndx(to)].bit_count;
}
bool tap_is_state_stable(tap_state_t astate)
{
bool is_stable;
/* A switch () is used because it is symbol dependent
(not value dependent like an array), and can also check bounds.
* (not value dependent like an array), and can also check bounds.
*/
switch (astate)
{
switch (astate) {
case TAP_RESET:
case TAP_IDLE:
case TAP_DRSHIFT:
@ -237,13 +238,11 @@ tap_state_t tap_state_transition(tap_state_t cur_state, bool tms)
tap_state_t new_state;
/* A switch is used because it is symbol dependent and not value dependent
like an array. Also it can check for out of range conditions.
* like an array. Also it can check for out of range conditions.
*/
if (tms)
{
switch (cur_state)
{
if (tms) {
switch (cur_state) {
case TAP_RESET:
new_state = cur_state;
break;
@ -285,11 +284,8 @@ tap_state_t tap_state_transition(tap_state_t cur_state, bool tms)
exit(1);
break;
}
}
else
{
switch (cur_state)
{
} else {
switch (cur_state) {
case TAP_RESET:
case TAP_IDLE:
case TAP_DRUPDATE:
@ -330,7 +326,6 @@ tap_state_t tap_state_transition(tap_state_t cur_state, bool tms)
return new_state;
}
/* NOTE: do not change these state names. They're documented,
* and we rely on them to match SVF input (except for "RUN/IDLE").
*/
@ -406,7 +401,7 @@ tap_state_t jtag_debug_state_machine(const void *tms_buf, const void *tdi_buf,
tap_state_t last_state;
// set startstate (and possibly last, if tap_bits == 0)
/* set startstate (and possibly last, if tap_bits == 0) */
last_state = next_state;
DEBUG_JTAG_IO("TAP/SM: START state: %s", tap_state_name(next_state));
@ -417,47 +412,44 @@ tap_state_t jtag_debug_state_machine(const void *tms_buf, const void *tdi_buf,
DEBUG_JTAG_IO("TAP/SM: TMS bits: %u (bytes: %u)", tap_bits, tap_bytes);
tap_out_bits = 0;
for (cur_byte = 0; cur_byte < tap_bytes; cur_byte++)
{
for (cur_bit = 0; cur_bit < 8; cur_bit++)
{
// make sure we do not run off the end of the buffers
for (cur_byte = 0; cur_byte < tap_bytes; cur_byte++) {
for (cur_bit = 0; cur_bit < 8; cur_bit++) {
/* make sure we do not run off the end of the buffers */
unsigned tap_bit = cur_byte * 8 + cur_bit;
if (tap_bit == tap_bits)
break;
// check and save TMS bit
/* check and save TMS bit */
tap_bit = !!(tms_buffer[cur_byte] & (1 << cur_bit));
JTAG_DEBUG_STATE_APPEND(tms_str, tap_out_bits, tap_bit);
// use TMS bit to find the next TAP state
/* use TMS bit to find the next TAP state */
next_state = tap_state_transition(last_state, tap_bit);
// check and store TDI bit
/* check and store TDI bit */
tap_bit = !!(tdi_buffer[cur_byte] & (1 << cur_bit));
JTAG_DEBUG_STATE_APPEND(tdi_str, tap_out_bits, tap_bit);
// increment TAP bits
/* increment TAP bits */
tap_out_bits++;
// Only show TDO bits on state transitions, or
// after some number of bits in the same state.
/* Only show TDO bits on state transitions, or */
/* after some number of bits in the same state. */
if ((next_state == last_state) && (tap_out_bits < 32))
continue;
// terminate strings and display state transition
/* terminate strings and display state transition */
tms_str[tap_out_bits] = tdi_str[tap_out_bits] = 0;
JTAG_DEBUG_STATE_PRINT(last_state, next_state, tms_str, tdi_str);
// reset state
/* reset state */
last_state = next_state;
tap_out_bits = 0;
}
}
if (tap_out_bits)
{
// terminate strings and display state transition
if (tap_out_bits) {
/* terminate strings and display state transition */
tms_str[tap_out_bits] = tdi_str[tap_out_bits] = 0;
JTAG_DEBUG_STATE_PRINT(last_state, next_state, tms_str, tdi_str);
}
@ -466,7 +458,7 @@ tap_state_t jtag_debug_state_machine(const void *tms_buf, const void *tdi_buf,
return next_state;
}
#endif // _DEBUG_JTAG_IO_
#endif /* _DEBUG_JTAG_IO_ */
void tap_use_new_tms_table(bool use_new)
{
@ -476,4 +468,3 @@ bool tap_uses_new_tms_table(void)
{
return tms_seqs == &short_tms_seqs;
}

View File

@ -23,6 +23,7 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef OPENOCD_JTAG_INTERFACE_H
#define OPENOCD_JTAG_INTERFACE_H
@ -110,7 +111,6 @@ tap_state_t tap_get_end_state(void);
*/
int tap_get_tms_path(tap_state_t from, tap_state_t to);
/**
* Function int tap_get_tms_path_len
* returns the total number of bits that represents a TMS path
@ -160,9 +160,9 @@ bool tap_is_state_stable(tap_state_t astate);
*/
tap_state_t tap_state_transition(tap_state_t current_state, bool tms);
/// Allow switching between old and new TMS tables. @see tap_get_tms_path
/** Allow switching between old and new TMS tables. @see tap_get_tms_path */
void tap_use_new_tms_table(bool use_new);
/// @returns True if new TMS table is active; false otherwise.
/** @returns True if new TMS table is active; false otherwise. */
bool tap_uses_new_tms_table(void);
#ifdef _DEBUG_JTAG_IO_
@ -182,7 +182,7 @@ static inline tap_state_t jtag_debug_state_machine(const void *tms_buf,
{
return start_tap_state;
}
#endif // _DEBUG_JTAG_IO_
#endif /* _DEBUG_JTAG_IO_ */
/**
* Represents a driver for a debugging interface.
@ -197,7 +197,7 @@ static inline tap_state_t jtag_debug_state_machine(const void *tms_buf,
* debugging interface.
*/
struct jtag_interface {
/// The name of the JTAG interface driver.
/** The name of the JTAG interface driver. */
char *name;
/**
@ -300,9 +300,8 @@ struct jtag_interface {
int (*srst_asserted)(int *srst_asserted);
};
extern const char *jtag_only[];
extern const struct swd_driver *swd;
#endif // OPENOCD_JTAG_INTERFACE_H
#endif /* OPENOCD_JTAG_INTERFACE_H */

View File

@ -27,6 +27,7 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -45,7 +46,7 @@
extern struct jtag_interface zy1000_interface;
#elif defined(BUILD_MINIDRIVER_DUMMY)
extern struct jtag_interface minidummy_interface;
#else // standard drivers
#else /* standard drivers */
#if BUILD_PARPORT == 1
extern struct jtag_interface parport_interface;
#endif
@ -103,7 +104,7 @@ extern struct jtag_interface remote_bitbang_interface;
#if BUILD_STLINK == 1
extern struct jtag_interface stlink_interface;
#endif
#endif // standard drivers
#endif /* standard drivers */
/**
* The list of built-in JTAG interfaces, containing entries for those
@ -117,7 +118,7 @@ struct jtag_interface *jtag_interfaces[] = {
&zy1000_interface,
#elif defined(BUILD_MINIDRIVER_DUMMY)
&minidummy_interface,
#else // standard drivers
#else /* standard drivers */
#if BUILD_PARPORT == 1
&parport_interface,
#endif
@ -175,11 +176,11 @@ struct jtag_interface *jtag_interfaces[] = {
#if BUILD_STLINK == 1
&stlink_interface,
#endif
#endif // standard drivers
#endif /* standard drivers */
NULL,
};
void jtag_interface_modules_load(const char *path)
{
// @todo: implement dynamic module loading for JTAG interface drivers
/* @todo: implement dynamic module loading for JTAG interface drivers */
}

View File

@ -27,6 +27,7 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef OPENOCD_JTAG_INTERFACES_H
#define OPENOCD_JTAG_INTERFACES_H
@ -37,9 +38,9 @@
#include <jtag/interface.h>
/// Dynamically load all JTAG interface modules from specified directory.
/** Dynamically load all JTAG interface modules from specified directory. */
void jtag_interface_modules_load(const char *path);
extern struct jtag_interface *jtag_interfaces[];
#endif // OPENOCD_JTAG_INTERFACES_H
#endif /* OPENOCD_JTAG_INTERFACES_H */

View File

@ -20,6 +20,7 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef JTAG_H
#define JTAG_H
@ -52,8 +53,7 @@
* Fix those drivers to map as appropriate ... then pick some
* sane set of numbers here (where 0/uninitialized == INVALID).
*/
typedef enum tap_state
{
typedef enum tap_state {
TAP_INVALID = -1,
#if BUILD_ZY1000
@ -92,10 +92,10 @@ typedef enum tap_state
*/
const char *tap_state_name(tap_state_t state);
/// Provides user-friendly name lookup of TAP states.
/** Provides user-friendly name lookup of TAP states. */
tap_state_t tap_state_by_name(const char *name);
/// The current TAP state of the pending JTAG command queue.
/** The current TAP state of the pending JTAG command queue. */
extern tap_state_t cmd_queue_cur_state;
/**
@ -107,16 +107,16 @@ extern tap_state_t cmd_queue_cur_state;
* jtag_add_dr_scan_check() to validate the value that was scanned out.
*/
struct scan_field {
/// The number of bits this field specifies (up to 32)
/** The number of bits this field specifies (up to 32) */
int num_bits;
/// A pointer to value to be scanned into the device
/** A pointer to value to be scanned into the device */
const uint8_t *out_value;
/// A pointer to a 32-bit memory location for data scanned out
/** A pointer to a 32-bit memory location for data scanned out */
uint8_t *in_value;
/// The value used to check the data scanned out.
/** The value used to check the data scanned out. */
uint8_t *check_value;
/// The mask to go with check_value
/** The mask to go with check_value */
uint8_t *check_mask;
};
@ -125,9 +125,9 @@ struct jtag_tap {
const char *tapname;
const char *dotted_name;
int abs_chain_position;
/// Is this TAP disabled after JTAG reset?
/** Is this TAP disabled after JTAG reset? */
bool disabled_after_reset;
/// Is this TAP currently enabled?
/** Is this TAP currently enabled? */
bool enabled;
int ir_length; /**< size of instruction register */
uint32_t ir_capture_value;
@ -139,17 +139,17 @@ struct jtag_tap {
* we'll discover this during chain examination */
bool hasidcode;
/// Array of expected identification codes */
/** Array of expected identification codes */
uint32_t *expected_ids;
/// Number of expected identification codes
/** Number of expected identification codes */
uint8_t expected_ids_cnt;
/// Flag saying whether to ignore version field in expected_ids[]
/** Flag saying whether to ignore version field in expected_ids[] */
bool ignore_version;
/// current instruction
/** current instruction */
uint8_t *cur_instr;
/// Bypass register selected
/** Bypass register selected */
int bypass;
struct jtag_tap_event_action *event_action;
@ -173,7 +173,6 @@ struct jtag_tap* jtag_tap_next_enabled(struct jtag_tap* p);
unsigned jtag_tap_count_enabled(void);
unsigned jtag_tap_count(void);
/*
* - TRST_ASSERTED triggers two sets of callbacks, after operations to
* reset the scan chain -- via TMS+TCK signaling, or deasserting the
@ -203,15 +202,14 @@ enum jtag_event {
JTAG_TAP_EVENT_DISABLE,
};
struct jtag_tap_event_action
{
/// The event for which this action will be triggered.
struct jtag_tap_event_action {
/** The event for which this action will be triggered. */
enum jtag_event event;
/// The interpreter to use for evaluating the @c body.
/** The interpreter to use for evaluating the @c body. */
Jim_Interp *interp;
/// Contains a script to 'eval' when the @c event is triggered.
/** Contains a script to 'eval' when the @c event is triggered. */
Jim_Obj *body;
// next action in linked list
/* next action in linked list */
struct jtag_tap_event_action *next;
};
@ -234,7 +232,7 @@ int jtag_unregister_event_callback(jtag_event_handler_t f, void *x);
int jtag_call_event_callbacks(enum jtag_event event);
/// @returns The current JTAG speed setting.
/** @returns The current JTAG speed setting. */
int jtag_get_speed(int *speed);
/**
@ -246,7 +244,7 @@ int jtag_get_speed(int *speed);
*/
int jtag_get_speed_readable(int *speed);
/// Attempt to configure the interface for the specified KHz.
/** Attempt to configure the interface for the specified KHz. */
int jtag_config_khz(unsigned khz);
/**
@ -255,10 +253,9 @@ int jtag_config_khz(unsigned khz);
*/
int jtag_config_rclk(unsigned fallback_speed_khz);
/// Retreives the clock speed of the JTAG interface in KHz.
/** Retreives the clock speed of the JTAG interface in KHz. */
unsigned jtag_get_speed_khz(void);
enum reset_types {
RESET_NONE = 0x0,
RESET_HAS_TRST = 0x1,
@ -286,29 +283,28 @@ unsigned jtag_get_nsrst_assert_width(void);
void jtag_set_ntrst_assert_width(unsigned delay);
unsigned jtag_get_ntrst_assert_width(void);
/// @returns The current state of TRST.
/** @returns The current state of TRST. */
int jtag_get_trst(void);
/// @returns The current state of SRST.
/** @returns The current state of SRST. */
int jtag_get_srst(void);
/// Enable or disable data scan verification checking.
/** Enable or disable data scan verification checking. */
void jtag_set_verify(bool enable);
/// @returns True if data scan verification will be performed.
/** @returns True if data scan verification will be performed. */
bool jtag_will_verify(void);
/// Enable or disable verification of IR scan checking.
/** Enable or disable verification of IR scan checking. */
void jtag_set_verify_capture_ir(bool enable);
/// @returns True if IR scan verification will be performed.
/** @returns True if IR scan verification will be performed. */
bool jtag_will_verify_capture_ir(void);
/** Initialize debug adapter upon startup. */
int adapter_init(struct command_context *cmd_ctx);
/// Shutdown the debug adapter upon program exit.
/** Shutdown the debug adapter upon program exit. */
int adapter_quit(void);
/// Set ms to sleep after jtag_execute_queue() flushes queue. Debug
/// purposes.
/** Set ms to sleep after jtag_execute_queue() flushes queue. Debug purposes. */
void jtag_set_flush_queue_sleep(int ms);
/**
@ -317,7 +313,7 @@ void jtag_set_flush_queue_sleep(int ms);
*/
int jtag_init(struct command_context *cmd_ctx);
/// reset, then initialize JTAG chain
/** reset, then initialize JTAG chain */
int jtag_init_reset(struct command_context *cmd_ctx);
int jtag_register_commands(struct command_context *cmd_ctx);
int jtag_init_inner(struct command_context *cmd_ctx);
@ -363,7 +359,6 @@ void jtag_add_ir_scan_noverify(struct jtag_tap* tap,
void jtag_add_plain_ir_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits,
tap_state_t endstate);
/**
* Generate a DR SCAN using the fields passed to the function.
* For connected TAPs, the function checks in_fields and uses fields
@ -372,7 +367,7 @@ void jtag_add_plain_ir_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_b
*/
void jtag_add_dr_scan(struct jtag_tap *tap, int num_fields,
const struct scan_field *fields, tap_state_t endstate);
/// A version of jtag_add_dr_scan() that uses the check_value/mask fields
/** A version of jtag_add_dr_scan() that uses the check_value/mask fields */
void jtag_add_dr_scan_check(struct jtag_tap *tap, int num_fields,
struct scan_field *fields, tap_state_t endstate);
/**
@ -399,7 +394,7 @@ typedef intptr_t jtag_callback_data_t;
*/
typedef void (*jtag_callback1_t)(jtag_callback_data_t data0);
/// A simpler version of jtag_add_callback4().
/** A simpler version of jtag_add_callback4(). */
void jtag_add_callback(jtag_callback1_t, jtag_callback_data_t data0);
@ -550,7 +545,6 @@ int jtag_add_tms_seq(unsigned nbits, const uint8_t *seq, enum tap_state t);
*/
void jtag_add_clocks(int num_cycles);
/**
* For software FIFO implementations, the queued commands can be executed
* during this call or earlier. A sw queue might decide to push out
@ -573,16 +567,15 @@ void jtag_add_clocks(int num_cycles);
*/
int jtag_execute_queue(void);
/// same as jtag_execute_queue() but does not clear the error flag
/** same as jtag_execute_queue() but does not clear the error flag */
void jtag_execute_queue_noclear(void);
/// @returns the number of times the scan queue has been flushed
/** @returns the number of times the scan queue has been flushed */
int jtag_get_flush_queue_count(void);
/// Report Tcl event to all TAPs
/** Report Tcl event to all TAPs */
void jtag_notify_event(enum jtag_event);
/* can be implemented by hw + sw */
int jtag_power_dropout(int *dropout);
int jtag_srst_asserted(int *srst_asserted);
@ -642,7 +635,6 @@ void jtag_sleep(uint32_t us);
* clocking data back in. Patches gladly accepted!
*/
/**
* Set the current JTAG core execution error, unless one was set
* by a previous call previously. Driver or application code must

View File

@ -23,6 +23,7 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef MINIDRIVER_H
#define MINIDRIVER_H
@ -45,8 +46,8 @@
* - default_interface_jtag_execute_queue()
*/
// this header will be provided by the minidriver implementation,
// and it may provide additional declarations that must be defined.
/* this header will be provided by the minidriver implementation, */
/* and it may provide additional declarations that must be defined. */
#include <jtag/minidriver_imp.h>
int interface_jtag_add_ir_scan(struct jtag_tap *active,
@ -89,4 +90,4 @@ int interface_jtag_execute_queue(void);
*/
int default_interface_jtag_execute_queue(void);
#endif // MINIDRIVER_H
#endif /* MINIDRIVER_H */

View File

@ -1,4 +1,21 @@
//
/***************************************************************************
* Copyright (C) 2009-2010 by David Brownell *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
/* Bits in SWD command packets, written from host to target
* first bit on the wire is START
@ -33,7 +50,7 @@ static inline uint8_t swd_cmd(bool is_read, bool is_ap, uint8_t regnum)
| (is_read ? SWD_CMD_RnW : 0)
| ((regnum & 0xc) << 1);
//8 cmd bits 4:1 may be set
/* 8 cmd bits 4:1 may be set */
if (nibble_parity(cmd >> 1))
cmd |= SWD_CMD_PARITY;

View File

@ -27,6 +27,7 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -72,8 +73,7 @@ struct jtag_tap *jtag_tap_by_jim_obj(Jim_Interp *interp, Jim_Obj *o)
static bool scan_is_safe(tap_state_t state)
{
switch (state)
{
switch (state) {
case TAP_RESET:
case TAP_IDLE:
case TAP_DRPAUSE:
@ -103,8 +103,7 @@ static int Jim_Command_drscan(Jim_Interp *interp, int argc, Jim_Obj *const *args
* args[N-2] = "-endstate"
* args[N-1] = statename
*/
if ((argc < 4) || ((argc % 2) != 0))
{
if ((argc < 4) || ((argc % 2) != 0)) {
Jim_WrongNumArgs(interp, 1, args, "wrong arguments");
return JIM_ERR;
}
@ -115,16 +114,14 @@ static int Jim_Command_drscan(Jim_Interp *interp, int argc, Jim_Obj *const *args
/* validate arguments as numbers */
e = JIM_OK;
for (i = 2; i < argc; i += 2)
{
for (i = 2; i < argc; i += 2) {
long bits;
const char *cp;
e = Jim_GetLong(interp, args[i], &bits);
/* If valid - try next arg */
if (e == JIM_OK) {
if (e == JIM_OK)
continue;
}
/* Not valid.. are we at the end? */
if (((i + 2) != argc)) {
@ -162,23 +159,20 @@ static int Jim_Command_drscan(Jim_Interp *interp, int argc, Jim_Obj *const *args
}
/* Still an error? */
if (e != JIM_OK) {
if (e != JIM_OK)
return e; /* too bad */
}
} /* validate args */
assert(e == JIM_OK);
tap = jtag_tap_by_jim_obj(interp, args[1]);
if (tap == NULL) {
if (tap == NULL)
return JIM_ERR;
}
num_fields = (argc-2)/2;
assert(num_fields > 0);
fields = malloc(sizeof(struct scan_field) * num_fields);
for (i = 2; i < argc; i += 2)
{
for (i = 2; i < argc; i += 2) {
long bits;
int len;
const char *str;
@ -197,16 +191,14 @@ static int Jim_Command_drscan(Jim_Interp *interp, int argc, Jim_Obj *const *args
jtag_add_dr_scan(tap, num_fields, fields, endstate);
retval = jtag_execute_queue();
if (retval != ERROR_OK)
{
if (retval != ERROR_OK) {
Jim_SetResultString(interp, "drscan: jtag execute failed", -1);
return JIM_ERR;
}
field_count = 0;
Jim_Obj *list = Jim_NewListObj(interp, NULL, 0);
for (i = 2; i < argc; i += 2)
{
for (i = 2; i < argc; i += 2) {
long bits;
char *str;
@ -231,8 +223,7 @@ static int Jim_Command_pathmove(Jim_Interp *interp, int argc, Jim_Obj *const *ar
{
tap_state_t states[8];
if ((argc < 2) || ((size_t)argc > (ARRAY_SIZE(states) + 1)))
{
if ((argc < 2) || ((size_t)argc > (ARRAY_SIZE(states) + 1))) {
Jim_WrongNumArgs(interp, 1, args, "wrong arguments");
return JIM_ERR;
}
@ -240,29 +231,25 @@ static int Jim_Command_pathmove(Jim_Interp *interp, int argc, Jim_Obj *const *ar
script_debug(interp, "pathmove", argc, args);
int i;
for (i = 0; i < argc-1; i++)
{
for (i = 0; i < argc-1; i++) {
const char *cp;
cp = Jim_GetString(args[i + 1], NULL);
states[i] = tap_state_by_name(cp);
if (states[i] < 0)
{
if (states[i] < 0) {
/* update the error message */
Jim_SetResultFormatted(interp, "endstate: %s invalid", cp);
return JIM_ERR;
}
}
if ((jtag_add_statemove(states[0]) != ERROR_OK) || (jtag_execute_queue()!= ERROR_OK))
{
if ((jtag_add_statemove(states[0]) != ERROR_OK) || (jtag_execute_queue() != ERROR_OK)) {
Jim_SetResultString(interp, "pathmove: jtag execute failed", -1);
return JIM_ERR;
}
jtag_add_pathmove(argc - 2, states + 1);
if (jtag_execute_queue()!= ERROR_OK)
{
if (jtag_execute_queue() != ERROR_OK) {
Jim_SetResultString(interp, "pathmove: failed", -1);
return JIM_ERR;
}
@ -330,23 +317,24 @@ static Jim_Nvp nvp_config_opts[] = {
static int jtag_tap_configure_event(Jim_GetOptInfo *goi, struct jtag_tap *tap)
{
if (goi->argc == 0)
{
if (goi->argc == 0) {
Jim_WrongNumArgs(goi->interp, goi->argc, goi->argv, "-event <event-name> ...");
return JIM_ERR;
}
Jim_Nvp *n;
int e = Jim_GetOpt_Nvp(goi, nvp_jtag_tap_event, &n);
if (e != JIM_OK)
{
if (e != JIM_OK) {
Jim_GetOpt_NvpUnknown(goi, nvp_jtag_tap_event, 1);
return e;
}
if (goi->isconfigure) {
if (goi->argc != 1) {
Jim_WrongNumArgs(goi->interp, goi->argc, goi->argv, "-event <event-name> <event-body>");
Jim_WrongNumArgs(goi->interp,
goi->argc,
goi->argv,
"-event <event-name> <event-body>");
return JIM_ERR;
}
} else {
@ -359,10 +347,8 @@ static int jtag_tap_configure_event(Jim_GetOptInfo *goi, struct jtag_tap * tap)
struct jtag_tap_event_action *jteap = tap->event_action;
/* replace existing event body */
bool found = false;
while (jteap)
{
if (jteap->event == (enum jtag_event)n->value)
{
while (jteap) {
if (jteap->event == (enum jtag_event)n->value) {
found = true;
break;
}
@ -371,8 +357,7 @@ static int jtag_tap_configure_event(Jim_GetOptInfo *goi, struct jtag_tap * tap)
Jim_SetEmptyResult(goi->interp);
if (goi->isconfigure)
{
if (goi->isconfigure) {
if (!found)
jteap = calloc(1, sizeof(*jteap));
else if (NULL != jteap->body)
@ -386,15 +371,12 @@ static int jtag_tap_configure_event(Jim_GetOptInfo *goi, struct jtag_tap * tap)
jteap->body = Jim_DuplicateObj(goi->interp, o);
Jim_IncrRefCount(jteap->body);
if (!found)
{
if (!found) {
/* add to head of event list */
jteap->next = tap->event_action;
tap->event_action = jteap;
}
}
else if (found)
{
} else if (found) {
jteap->interp = goi->interp;
Jim_SetResult(goi->interp,
Jim_DuplicateObj(goi->interp, jteap->body));
@ -405,20 +387,17 @@ static int jtag_tap_configure_event(Jim_GetOptInfo *goi, struct jtag_tap * tap)
static int jtag_tap_configure_cmd(Jim_GetOptInfo *goi, struct jtag_tap *tap)
{
/* parse config or cget options */
while (goi->argc > 0)
{
while (goi->argc > 0) {
Jim_SetEmptyResult(goi->interp);
Jim_Nvp *n;
int e = Jim_GetOpt_Nvp(goi, nvp_config_opts, &n);
if (e != JIM_OK)
{
if (e != JIM_OK) {
Jim_GetOpt_NvpUnknown(goi, nvp_config_opts, 0);
return e;
}
switch (n->value)
{
switch (n->value) {
case JCFG_EVENT:
e = jtag_tap_configure_event(goi, tap);
if (e != JIM_OK)
@ -455,8 +434,7 @@ static int jim_newtap_expected_id(Jim_Nvp *n, Jim_GetOptInfo *goi,
unsigned expected_len = sizeof(uint32_t) * pTap->expected_ids_cnt;
uint32_t *new_expected_ids = malloc(expected_len + sizeof(uint32_t));
if (new_expected_ids == NULL)
{
if (new_expected_ids == NULL) {
Jim_SetResultFormatted(goi->interp, "no memory");
return JIM_ERR;
}
@ -485,8 +463,7 @@ static int jim_newtap_ir_param(Jim_Nvp *n, Jim_GetOptInfo *goi,
{
jim_wide w;
int e = Jim_GetOpt_Wide(goi, &w);
if (e != JIM_OK)
{
if (e != JIM_OK) {
Jim_SetResultFormatted(goi->interp,
"option: %s bad parameter", n->name);
free((void *)pTap->dotted_name);
@ -494,16 +471,14 @@ static int jim_newtap_ir_param(Jim_Nvp *n, Jim_GetOptInfo *goi,
}
switch (n->value) {
case NTAP_OPT_IRLEN:
if (w > (jim_wide) (8 * sizeof(pTap->ir_capture_value)))
{
if (w > (jim_wide) (8 * sizeof(pTap->ir_capture_value))) {
LOG_WARNING("%s: huge IR length %d",
pTap->dotted_name, (int) w);
}
pTap->ir_length = w;
break;
case NTAP_OPT_IRMASK:
if (is_bad_irval(pTap->ir_length, w))
{
if (is_bad_irval(pTap->ir_length, w)) {
LOG_ERROR("%s: IR mask %x too big",
pTap->dotted_name,
(int) w);
@ -514,8 +489,7 @@ static int jim_newtap_ir_param(Jim_Nvp *n, Jim_GetOptInfo *goi,
pTap->ir_capture_mask = w;
break;
case NTAP_OPT_IRCAPTURE:
if (is_bad_irval(pTap->ir_length, w))
{
if (is_bad_irval(pTap->ir_length, w)) {
LOG_ERROR("%s: IR capture %x too big",
pTap->dotted_name, (int) w);
return JIM_ERR;
@ -603,8 +577,7 @@ static int jim_newtap_cmd(Jim_GetOptInfo *goi)
break;
case NTAP_OPT_EXPECTED_ID:
e = jim_newtap_expected_id(n, goi, pTap);
if (JIM_OK != e)
{
if (JIM_OK != e) {
free((void *)pTap->dotted_name);
free(pTap);
return e;
@ -614,8 +587,7 @@ static int jim_newtap_cmd(Jim_GetOptInfo *goi)
case NTAP_OPT_IRMASK:
case NTAP_OPT_IRCAPTURE:
e = jim_newtap_ir_param(n, goi, pTap);
if (JIM_OK != e)
{
if (JIM_OK != e) {
free((void *)pTap->dotted_name);
free(pTap);
return e;
@ -631,8 +603,7 @@ static int jim_newtap_cmd(Jim_GetOptInfo *goi)
pTap->enabled = !pTap->disabled_after_reset;
/* Did all the required option bits get cleared? */
if (pTap->ir_length != 0)
{
if (pTap->ir_length != 0) {
jtag_tap_init(pTap);
return JIM_OK;
}
@ -648,8 +619,7 @@ static void jtag_tap_handle_event(struct jtag_tap *tap, enum jtag_event e)
{
struct jtag_tap_event_action *jteap;
for (jteap = tap->event_action; jteap != NULL; jteap = jteap->next)
{
for (jteap = tap->event_action; jteap != NULL; jteap = jteap->next) {
if (jteap->event != e)
continue;
@ -658,15 +628,13 @@ static void jtag_tap_handle_event(struct jtag_tap *tap, enum jtag_event e)
tap->dotted_name, e, nvp->name,
Jim_GetString(jteap->body, NULL));
if (Jim_EvalObj(jteap->interp, jteap->body) != JIM_OK)
{
if (Jim_EvalObj(jteap->interp, jteap->body) != JIM_OK) {
Jim_MakeErrorMessage(jteap->interp);
LOG_USER("%s", Jim_GetString(Jim_GetResult(jteap->interp), NULL));
continue;
}
switch (e)
{
switch (e) {
case JTAG_TAP_EVENT_ENABLE:
case JTAG_TAP_EVENT_DISABLE:
/* NOTE: we currently assume the handlers
@ -776,7 +744,7 @@ int jim_jtag_tap_enabler(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
return JIM_ERR;
if (strcasecmp(cmd_name, "tapisenabled") == 0) {
// do nothing, just return the value
/* do nothing, just return the value */
} else if (strcasecmp(cmd_name, "tapenable") == 0) {
if (!jtag_tap_enable(t)) {
LOG_WARNING("failed to enable tap %s", t->dotted_name);
@ -813,9 +781,8 @@ int jim_jtag_configure(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
Jim_Obj *o;
Jim_GetOpt_Obj(&goi, &o);
t = jtag_tap_by_jim_obj(goi.interp, o);
if (t == NULL) {
if (t == NULL)
return JIM_ERR;
}
return jtag_tap_configure_cmd(&goi, t);
}
@ -845,9 +812,8 @@ COMMAND_HANDLER(handle_jtag_init_command)
if (CMD_ARGC != 0)
return ERROR_COMMAND_SYNTAX_ERROR;
static bool jtag_initialized = false;
if (jtag_initialized)
{
static bool jtag_initialized;
if (jtag_initialized) {
LOG_INFO("'jtag init' has already been called");
return ERROR_OK;
}
@ -1010,8 +976,7 @@ COMMAND_HANDLER(handle_jtag_ntrst_delay_command)
{
if (CMD_ARGC > 1)
return ERROR_COMMAND_SYNTAX_ERROR;
if (CMD_ARGC == 1)
{
if (CMD_ARGC == 1) {
unsigned delay;
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], delay);
@ -1025,8 +990,7 @@ COMMAND_HANDLER(handle_jtag_ntrst_assert_width_command)
{
if (CMD_ARGC > 1)
return ERROR_COMMAND_SYNTAX_ERROR;
if (CMD_ARGC == 1)
{
if (CMD_ARGC == 1) {
unsigned delay;
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], delay);
@ -1042,8 +1006,7 @@ COMMAND_HANDLER(handle_jtag_rclk_command)
return ERROR_COMMAND_SYNTAX_ERROR;
int retval = ERROR_OK;
if (CMD_ARGC == 1)
{
if (CMD_ARGC == 1) {
unsigned khz = 0;
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], khz);
@ -1121,9 +1084,7 @@ COMMAND_HANDLER(handle_irscan_command)
tap_state_t endstate;
if ((CMD_ARGC < 2) || (CMD_ARGC % 2))
{
return ERROR_COMMAND_SYNTAX_ERROR;
}
/* optional "-endstate" "statename" at the end of the arguments,
* so that e.g. IRPAUSE can let us load the data register before
@ -1132,8 +1093,8 @@ COMMAND_HANDLER(handle_irscan_command)
endstate = TAP_IDLE;
if (CMD_ARGC >= 4) {
/* have at least one pair of numbers. */
/* is last pair the magic text? */
/* have at least one pair of numbers.
* is last pair the magic text? */
if (strcmp("-endstate", CMD_ARGV[CMD_ARGC - 2]) == 0) {
endstate = tap_state_by_name(CMD_ARGV[CMD_ARGC - 1]);
if (endstate == TAP_INVALID)
@ -1146,8 +1107,7 @@ COMMAND_HANDLER(handle_irscan_command)
}
int num_fields = CMD_ARGC / 2;
if (num_fields > 1)
{
if (num_fields > 1) {
/* we really should be looking at plain_ir_scan if we want
* anything more fancy.
*/
@ -1160,11 +1120,9 @@ COMMAND_HANDLER(handle_irscan_command)
memset(fields, 0, fields_len);
int retval;
for (i = 0; i < num_fields; i++)
{
for (i = 0; i < num_fields; i++) {
tap = jtag_tap_by_string(CMD_ARGV[i*2]);
if (tap == NULL)
{
if (tap == NULL) {
int j;
for (j = 0; j < i; j++)
free((void *)fields[j].out_value);
@ -1192,8 +1150,7 @@ void *v = (void *)fields[i].out_value;
retval = jtag_execute_queue();
error_return:
for (i = 0; i < num_fields; i++)
{
for (i = 0; i < num_fields; i++) {
if (NULL != fields[i].out_value)
free((void *)fields[i].out_value);
}
@ -1203,14 +1160,12 @@ error_return:
return retval;
}
COMMAND_HANDLER(handle_verify_ircapture_command)
{
if (CMD_ARGC > 1)
return ERROR_COMMAND_SYNTAX_ERROR;
if (CMD_ARGC == 1)
{
if (CMD_ARGC == 1) {
bool enable;
COMMAND_PARSE_ENABLE(CMD_ARGV[0], enable);
jtag_set_verify_capture_ir(enable);
@ -1227,8 +1182,7 @@ COMMAND_HANDLER(handle_verify_jtag_command)
if (CMD_ARGC > 1)
return ERROR_COMMAND_SYNTAX_ERROR;
if (CMD_ARGC == 1)
{
if (CMD_ARGC == 1) {
bool enable;
COMMAND_PARSE_ENABLE(CMD_ARGV[0], enable);
jtag_set_verify(enable);
@ -1245,8 +1199,7 @@ COMMAND_HANDLER(handle_tms_sequence_command)
if (CMD_ARGC > 1)
return ERROR_COMMAND_SYNTAX_ERROR;
if (CMD_ARGC == 1)
{
if (CMD_ARGC == 1) {
bool use_new_table;
if (strcmp(CMD_ARGV[0], "short") == 0)
use_new_table = true;
@ -1284,8 +1237,7 @@ COMMAND_HANDLER(handle_wait_srst_deassert)
int timeout_ms;
COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], timeout_ms);
if ((timeout_ms <= 0) || (timeout_ms > 100000))
{
if ((timeout_ms <= 0) || (timeout_ms > 100000)) {
LOG_ERROR("Timeout must be an integer between 0 and 100000");
return ERROR_FAIL;
}
@ -1293,20 +1245,16 @@ COMMAND_HANDLER(handle_wait_srst_deassert)
LOG_USER("Waiting for srst assert + deassert for at most %dms", timeout_ms);
int asserted_yet;
long long then = timeval_ms();
while (jtag_srst_asserted(&asserted_yet) == ERROR_OK)
{
if ((timeval_ms() - then) > timeout_ms)
{
while (jtag_srst_asserted(&asserted_yet) == ERROR_OK) {
if ((timeval_ms() - then) > timeout_ms) {
LOG_ERROR("Timed out");
return ERROR_FAIL;
}
if (asserted_yet)
break;
}
while (jtag_srst_asserted(&asserted_yet) == ERROR_OK)
{
if ((timeval_ms() - then) > timeout_ms)
{
while (jtag_srst_asserted(&asserted_yet) == ERROR_OK) {
if ((timeval_ms() - then) > timeout_ms) {
LOG_ERROR("Timed out");
return ERROR_FAIL;
}
@ -1317,8 +1265,6 @@ COMMAND_HANDLER(handle_wait_srst_deassert)
return ERROR_OK;
}
static const struct command_registration jtag_command_handlers[] = {
{

View File

@ -1,3 +1,33 @@
/***************************************************************************
* Copyright (C) 2005 by Dominic Rath *
* Dominic.Rath@gmx.de *
* *
* Copyright (C) 2007-2010 Øyvind Harboe *
* oyvind.harboe@zylin.com *
* *
* Copyright (C) 2009 SoftPLC Corporation *
* http://softplc.com *
* dick@softplc.com *
* *
* Copyright (C) 2009 Zachary T Welch *
* zw@superlucidity.net *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef _JTAG_TCL_H_
#define _JTAG_TCL_H_