jtag: Use 'unsigned int' data type

This patch modifies as little code as possible in order to simplify the
review. Data types that are affected by these changes will be addresses
in following patches.

While at it, apply coding style fixes if these are not too extensive.

Change-Id: I364467b88f193f8387623a19e6994ef77899d117
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/8414
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
Marc Schink 2024-07-22 09:30:42 +02:00 committed by Antonio Borneo
parent 7d56407ba7
commit 2b6d63a44d
6 changed files with 60 additions and 62 deletions

View File

@ -178,9 +178,9 @@ enum scan_type jtag_scan_type(const struct scan_command *cmd)
return type;
}
int jtag_scan_size(const struct scan_command *cmd)
unsigned int jtag_scan_size(const struct scan_command *cmd)
{
int bit_count = 0;
unsigned int bit_count = 0;
/* count bits in scan command */
for (unsigned int i = 0; i < cmd->num_fields; i++)
@ -191,9 +191,7 @@ int jtag_scan_size(const struct scan_command *cmd)
int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer)
{
int bit_count = 0;
bit_count = jtag_scan_size(cmd);
unsigned int bit_count = jtag_scan_size(cmd);
*buffer = calloc(1, DIV_ROUND_UP(bit_count, 8));
bit_count = 0;

View File

@ -157,7 +157,7 @@ struct jtag_command *jtag_command_queue_get(void);
void jtag_scan_field_clone(struct scan_field *dst, const struct scan_field *src);
enum scan_type jtag_scan_type(const struct scan_command *cmd);
int jtag_scan_size(const struct scan_command *cmd);
unsigned 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);

View File

@ -39,7 +39,7 @@
#include "server/ipdbg.h"
/** The number of JTAG queue flushes (for profiling and debugging purposes). */
static int jtag_flush_queue_count;
static unsigned int jtag_flush_queue_count;
/* Sleep this # of ms after flushing the queue */
static int jtag_flush_queue_sleep;
@ -92,10 +92,10 @@ static bool jtag_verify = true;
/* 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 */
static unsigned int adapter_nsrst_delay; /* default to no nSRST delay */
static unsigned int jtag_ntrst_delay;/* default to no nTRST delay */
static unsigned int adapter_nsrst_assert_width; /* width of assertion */
static unsigned int jtag_ntrst_assert_width; /* width of assertion */
/**
* Contains a single callback along with a pointer that will be passed
@ -186,10 +186,10 @@ struct jtag_tap *jtag_all_taps(void)
return __jtag_all_taps;
};
unsigned jtag_tap_count(void)
unsigned int jtag_tap_count(void)
{
struct jtag_tap *t = jtag_all_taps();
unsigned n = 0;
unsigned int n = 0;
while (t) {
n++;
t = t->next_tap;
@ -197,10 +197,10 @@ unsigned jtag_tap_count(void)
return n;
}
unsigned jtag_tap_count_enabled(void)
unsigned int jtag_tap_count_enabled(void)
{
struct jtag_tap *t = jtag_all_taps();
unsigned n = 0;
unsigned int n = 0;
while (t) {
if (t->enabled)
n++;
@ -499,7 +499,7 @@ void jtag_add_tlr(void)
*
* @todo Update naming conventions to stop assuming everything is JTAG.
*/
int jtag_add_tms_seq(unsigned nbits, const uint8_t *seq, enum tap_state state)
int jtag_add_tms_seq(unsigned int nbits, const uint8_t *seq, enum tap_state state)
{
int retval;
@ -567,12 +567,12 @@ int jtag_add_statemove(tap_state_t goal_state)
/* nothing to do */;
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);
unsigned int tms_bits = tap_get_tms_path(cur_state, goal_state);
unsigned int 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 int i = 0; i < tms_count; i++, tms_bits >>= 1) {
bool bit = tms_bits & 1;
cur_state = tap_state_transition(cur_state, bit);
@ -1029,7 +1029,7 @@ void jtag_execute_queue_noclear(void)
}
}
int jtag_get_flush_queue_count(void)
unsigned int jtag_get_flush_queue_count(void)
{
return jtag_flush_queue_count;
}
@ -1081,7 +1081,7 @@ void jtag_sleep(uint32_t us)
/* a larger IR length than we ever expect to autoprobe */
#define JTAG_IRLEN_MAX 60
static int jtag_examine_chain_execute(uint8_t *idcode_buffer, unsigned num_idcode)
static int jtag_examine_chain_execute(uint8_t *idcode_buffer, unsigned int num_idcode)
{
struct scan_field field = {
.num_bits = num_idcode * 32,
@ -1090,7 +1090,7 @@ static int jtag_examine_chain_execute(uint8_t *idcode_buffer, unsigned num_idcod
};
/* initialize to the end of chain ID value */
for (unsigned i = 0; i < num_idcode; i++)
for (unsigned int i = 0; i < num_idcode; i++)
buf_set_u32(idcode_buffer, i * 32, 32, END_OF_CHAIN_FLAG);
jtag_add_plain_dr_scan(field.num_bits, field.out_value, field.in_value, TAP_DRPAUSE);
@ -1098,12 +1098,12 @@ static int jtag_examine_chain_execute(uint8_t *idcode_buffer, unsigned num_idcod
return jtag_execute_queue();
}
static bool jtag_examine_chain_check(uint8_t *idcodes, unsigned count)
static bool jtag_examine_chain_check(uint8_t *idcodes, unsigned int count)
{
uint8_t zero_check = 0x0;
uint8_t one_check = 0xff;
for (unsigned i = 0; i < count * 4; i++) {
for (unsigned int i = 0; i < count * 4; i++) {
zero_check |= idcodes[i];
one_check &= idcodes[i];
}
@ -1158,7 +1158,8 @@ static bool jtag_idcode_is_final(uint32_t idcode)
* with the JTAG chain earlier, gives more helpful/explicit error messages.
* Returns TRUE iff garbage was found.
*/
static bool jtag_examine_chain_end(uint8_t *idcodes, unsigned count, unsigned max)
static bool jtag_examine_chain_end(uint8_t *idcodes, unsigned int count,
unsigned int max)
{
bool triggered = false;
for (; count < max - 31; count += 32) {
@ -1185,26 +1186,26 @@ static bool jtag_examine_chain_match_tap(const struct jtag_tap *tap)
uint32_t idcode = tap->idcode & mask;
/* Loop over the expected identification codes and test for a match */
for (unsigned ii = 0; ii < tap->expected_ids_cnt; ii++) {
uint32_t expected = tap->expected_ids[ii] & mask;
for (unsigned int i = 0; i < tap->expected_ids_cnt; i++) {
uint32_t expected = tap->expected_ids[i] & mask;
if (idcode == expected)
return true;
/* treat "-expected-id 0" as a "don't-warn" wildcard */
if (tap->expected_ids[ii] == 0)
if (tap->expected_ids[i] == 0)
return true;
}
/* If none of the expected ids matched, warn */
jtag_examine_chain_display(LOG_LVL_WARNING, "UNEXPECTED",
tap->dotted_name, tap->idcode);
for (unsigned ii = 0; ii < tap->expected_ids_cnt; ii++) {
for (unsigned int i = 0; i < tap->expected_ids_cnt; i++) {
char msg[32];
snprintf(msg, sizeof(msg), "expected %u of %u", ii + 1, tap->expected_ids_cnt);
snprintf(msg, sizeof(msg), "expected %u of %u", i + 1, tap->expected_ids_cnt);
jtag_examine_chain_display(LOG_LVL_ERROR, msg,
tap->dotted_name, tap->expected_ids[ii]);
tap->dotted_name, tap->expected_ids[i]);
}
return false;
}
@ -1215,7 +1216,7 @@ static bool jtag_examine_chain_match_tap(const struct jtag_tap *tap)
static int jtag_examine_chain(void)
{
int retval;
unsigned max_taps = jtag_tap_count();
unsigned int max_taps = jtag_tap_count();
/* Autoprobe up to this many. */
if (max_taps < JTAG_MAX_AUTO_TAPS)
@ -1243,9 +1244,9 @@ static int jtag_examine_chain(void)
/* Point at the 1st predefined tap, if any */
struct jtag_tap *tap = jtag_tap_next_enabled(NULL);
unsigned bit_count = 0;
unsigned autocount = 0;
for (unsigned i = 0; i < max_taps; i++) {
unsigned int bit_count = 0;
unsigned int autocount = 0;
for (unsigned int i = 0; i < max_taps; i++) {
assert(bit_count < max_taps * 32);
uint32_t idcode = buf_get_u32(idcode_buffer, bit_count, 32);
@ -1445,8 +1446,8 @@ done:
void jtag_tap_init(struct jtag_tap *tap)
{
unsigned ir_len_bits;
unsigned ir_len_bytes;
unsigned int ir_len_bits;
unsigned int ir_len_bytes;
/* if we're autoprobing, cope with potentially huge ir_length */
ir_len_bits = tap->ir_length ? tap->ir_length : JTAG_IRLEN_MAX;
@ -1749,37 +1750,36 @@ int jtag_get_srst(void)
return jtag_srst == 1;
}
void jtag_set_nsrst_delay(unsigned delay)
void jtag_set_nsrst_delay(unsigned int delay)
{
adapter_nsrst_delay = delay;
}
unsigned jtag_get_nsrst_delay(void)
unsigned int jtag_get_nsrst_delay(void)
{
return adapter_nsrst_delay;
}
void jtag_set_ntrst_delay(unsigned delay)
void jtag_set_ntrst_delay(unsigned int delay)
{
jtag_ntrst_delay = delay;
}
unsigned jtag_get_ntrst_delay(void)
unsigned int jtag_get_ntrst_delay(void)
{
return jtag_ntrst_delay;
}
void jtag_set_nsrst_assert_width(unsigned delay)
void jtag_set_nsrst_assert_width(unsigned int delay)
{
adapter_nsrst_assert_width = delay;
}
unsigned jtag_get_nsrst_assert_width(void)
unsigned int jtag_get_nsrst_assert_width(void)
{
return adapter_nsrst_assert_width;
}
void jtag_set_ntrst_assert_width(unsigned delay)
void jtag_set_ntrst_assert_width(unsigned int delay)
{
jtag_ntrst_assert_width = delay;
}
unsigned jtag_get_ntrst_assert_width(void)
unsigned int jtag_get_ntrst_assert_width(void)
{
return jtag_ntrst_assert_width;
}

View File

@ -970,8 +970,8 @@ static int vdebug_jtag_scan(struct scan_command *cmd, uint8_t f_flush)
uint8_t num_pre = tap_get_tms_path_len(cur, state);
uint8_t tms_post = tap_get_tms_path(state, cmd->end_state);
uint8_t num_post = tap_get_tms_path_len(state, cmd->end_state);
int num_bits = jtag_scan_size(cmd);
LOG_DEBUG_IO("scan len:%d fields:%u ir/!dr:%d state cur:%x end:%x",
const unsigned int num_bits = jtag_scan_size(cmd);
LOG_DEBUG_IO("scan len:%u fields:%u ir/!dr:%d state cur:%x end:%x",
num_bits, cmd->num_fields, cmd->ir_scan, cur, cmd->end_state);
for (unsigned int i = 0; i < cmd->num_fields; i++) {
uint8_t cur_num_pre = i == 0 ? num_pre : 0;

View File

@ -152,8 +152,8 @@ struct jtag_tap *jtag_tap_by_string(const char *dotted_name);
struct jtag_tap *jtag_tap_by_jim_obj(Jim_Interp *interp, Jim_Obj *obj);
struct jtag_tap *jtag_tap_by_position(unsigned int abs_position);
struct jtag_tap *jtag_tap_next_enabled(struct jtag_tap *p);
unsigned jtag_tap_count_enabled(void);
unsigned jtag_tap_count(void);
unsigned int jtag_tap_count_enabled(void);
unsigned int jtag_tap_count(void);
/*
* - TRST_ASSERTED triggers two sets of callbacks, after operations to
@ -229,17 +229,17 @@ enum reset_types {
enum reset_types jtag_get_reset_config(void);
void jtag_set_reset_config(enum reset_types type);
void jtag_set_nsrst_delay(unsigned delay);
unsigned jtag_get_nsrst_delay(void);
void jtag_set_nsrst_delay(unsigned int delay);
unsigned int jtag_get_nsrst_delay(void);
void jtag_set_ntrst_delay(unsigned delay);
unsigned jtag_get_ntrst_delay(void);
void jtag_set_ntrst_delay(unsigned int delay);
unsigned int jtag_get_ntrst_delay(void);
void jtag_set_nsrst_assert_width(unsigned delay);
unsigned jtag_get_nsrst_assert_width(void);
void jtag_set_nsrst_assert_width(unsigned int delay);
unsigned int jtag_get_nsrst_assert_width(void);
void jtag_set_ntrst_assert_width(unsigned delay);
unsigned jtag_get_ntrst_assert_width(void);
void jtag_set_ntrst_assert_width(unsigned int delay);
unsigned int jtag_get_ntrst_assert_width(void);
/** @returns The current state of TRST. */
int jtag_get_trst(void);
@ -488,7 +488,7 @@ void jtag_add_reset(int req_tlr_or_trst, int srst);
void jtag_add_sleep(uint32_t us);
int jtag_add_tms_seq(unsigned nbits, const uint8_t *seq, enum tap_state t);
int jtag_add_tms_seq(unsigned int nbits, const uint8_t *seq, enum tap_state t);
/**
* Function jtag_add_clocks
@ -523,7 +523,7 @@ int jtag_execute_queue(void);
void jtag_execute_queue_noclear(void);
/** @returns the number of times the scan queue has been flushed */
int jtag_get_flush_queue_count(void);
unsigned int jtag_get_flush_queue_count(void);
/** Report Tcl event to all TAPs */
void jtag_notify_event(enum jtag_event);

View File

@ -212,8 +212,8 @@ COMMAND_HANDLER(handle_jtag_flush_count)
if (CMD_ARGC != 0)
return ERROR_COMMAND_SYNTAX_ERROR;
int count = jtag_get_flush_queue_count();
command_print_sameline(CMD, "%d", count);
const unsigned int count = jtag_get_flush_queue_count();
command_print_sameline(CMD, "%u", count);
return ERROR_OK;
}