Skip to content

Commit 2b6d63a

Browse files
zapb-0borneoa
authored andcommitted
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 <[email protected]> Reviewed-on: https://review.openocd.org/c/openocd/+/8414 Tested-by: jenkins Reviewed-by: Antonio Borneo <[email protected]>
1 parent 7d56407 commit 2b6d63a

File tree

6 files changed

+60
-62
lines changed

6 files changed

+60
-62
lines changed

src/jtag/commands.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ enum scan_type jtag_scan_type(const struct scan_command *cmd)
178178
return type;
179179
}
180180

181-
int jtag_scan_size(const struct scan_command *cmd)
181+
unsigned int jtag_scan_size(const struct scan_command *cmd)
182182
{
183-
int bit_count = 0;
183+
unsigned int bit_count = 0;
184184

185185
/* count bits in scan command */
186186
for (unsigned int i = 0; i < cmd->num_fields; i++)
@@ -191,9 +191,7 @@ int jtag_scan_size(const struct scan_command *cmd)
191191

192192
int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer)
193193
{
194-
int bit_count = 0;
195-
196-
bit_count = jtag_scan_size(cmd);
194+
unsigned int bit_count = jtag_scan_size(cmd);
197195
*buffer = calloc(1, DIV_ROUND_UP(bit_count, 8));
198196

199197
bit_count = 0;

src/jtag/commands.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ struct jtag_command *jtag_command_queue_get(void);
157157

158158
void jtag_scan_field_clone(struct scan_field *dst, const struct scan_field *src);
159159
enum scan_type jtag_scan_type(const struct scan_command *cmd);
160-
int jtag_scan_size(const struct scan_command *cmd);
160+
unsigned int jtag_scan_size(const struct scan_command *cmd);
161161
int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd);
162162
int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer);
163163

src/jtag/core.c

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#include "server/ipdbg.h"
4040

4141
/** The number of JTAG queue flushes (for profiling and debugging purposes). */
42-
static int jtag_flush_queue_count;
42+
static unsigned int jtag_flush_queue_count;
4343

4444
/* Sleep this # of ms after flushing the queue */
4545
static int jtag_flush_queue_sleep;
@@ -92,10 +92,10 @@ static bool jtag_verify = true;
9292

9393
/* how long the OpenOCD should wait before attempting JTAG communication after reset lines
9494
*deasserted (in ms) */
95-
static int adapter_nsrst_delay; /* default to no nSRST delay */
96-
static int jtag_ntrst_delay;/* default to no nTRST delay */
97-
static int adapter_nsrst_assert_width; /* width of assertion */
98-
static int jtag_ntrst_assert_width; /* width of assertion */
95+
static unsigned int adapter_nsrst_delay; /* default to no nSRST delay */
96+
static unsigned int jtag_ntrst_delay;/* default to no nTRST delay */
97+
static unsigned int adapter_nsrst_assert_width; /* width of assertion */
98+
static unsigned int jtag_ntrst_assert_width; /* width of assertion */
9999

100100
/**
101101
* Contains a single callback along with a pointer that will be passed
@@ -186,21 +186,21 @@ struct jtag_tap *jtag_all_taps(void)
186186
return __jtag_all_taps;
187187
};
188188

189-
unsigned jtag_tap_count(void)
189+
unsigned int jtag_tap_count(void)
190190
{
191191
struct jtag_tap *t = jtag_all_taps();
192-
unsigned n = 0;
192+
unsigned int n = 0;
193193
while (t) {
194194
n++;
195195
t = t->next_tap;
196196
}
197197
return n;
198198
}
199199

200-
unsigned jtag_tap_count_enabled(void)
200+
unsigned int jtag_tap_count_enabled(void)
201201
{
202202
struct jtag_tap *t = jtag_all_taps();
203-
unsigned n = 0;
203+
unsigned int n = 0;
204204
while (t) {
205205
if (t->enabled)
206206
n++;
@@ -499,7 +499,7 @@ void jtag_add_tlr(void)
499499
*
500500
* @todo Update naming conventions to stop assuming everything is JTAG.
501501
*/
502-
int jtag_add_tms_seq(unsigned nbits, const uint8_t *seq, enum tap_state state)
502+
int jtag_add_tms_seq(unsigned int nbits, const uint8_t *seq, enum tap_state state)
503503
{
504504
int retval;
505505

@@ -567,12 +567,12 @@ int jtag_add_statemove(tap_state_t goal_state)
567567
/* nothing to do */;
568568

569569
else if (tap_is_state_stable(cur_state) && tap_is_state_stable(goal_state)) {
570-
unsigned tms_bits = tap_get_tms_path(cur_state, goal_state);
571-
unsigned tms_count = tap_get_tms_path_len(cur_state, goal_state);
570+
unsigned int tms_bits = tap_get_tms_path(cur_state, goal_state);
571+
unsigned int tms_count = tap_get_tms_path_len(cur_state, goal_state);
572572
tap_state_t moves[8];
573573
assert(tms_count < ARRAY_SIZE(moves));
574574

575-
for (unsigned i = 0; i < tms_count; i++, tms_bits >>= 1) {
575+
for (unsigned int i = 0; i < tms_count; i++, tms_bits >>= 1) {
576576
bool bit = tms_bits & 1;
577577

578578
cur_state = tap_state_transition(cur_state, bit);
@@ -1029,7 +1029,7 @@ void jtag_execute_queue_noclear(void)
10291029
}
10301030
}
10311031

1032-
int jtag_get_flush_queue_count(void)
1032+
unsigned int jtag_get_flush_queue_count(void)
10331033
{
10341034
return jtag_flush_queue_count;
10351035
}
@@ -1081,7 +1081,7 @@ void jtag_sleep(uint32_t us)
10811081
/* a larger IR length than we ever expect to autoprobe */
10821082
#define JTAG_IRLEN_MAX 60
10831083

1084-
static int jtag_examine_chain_execute(uint8_t *idcode_buffer, unsigned num_idcode)
1084+
static int jtag_examine_chain_execute(uint8_t *idcode_buffer, unsigned int num_idcode)
10851085
{
10861086
struct scan_field field = {
10871087
.num_bits = num_idcode * 32,
@@ -1090,20 +1090,20 @@ static int jtag_examine_chain_execute(uint8_t *idcode_buffer, unsigned num_idcod
10901090
};
10911091

10921092
/* initialize to the end of chain ID value */
1093-
for (unsigned i = 0; i < num_idcode; i++)
1093+
for (unsigned int i = 0; i < num_idcode; i++)
10941094
buf_set_u32(idcode_buffer, i * 32, 32, END_OF_CHAIN_FLAG);
10951095

10961096
jtag_add_plain_dr_scan(field.num_bits, field.out_value, field.in_value, TAP_DRPAUSE);
10971097
jtag_add_tlr();
10981098
return jtag_execute_queue();
10991099
}
11001100

1101-
static bool jtag_examine_chain_check(uint8_t *idcodes, unsigned count)
1101+
static bool jtag_examine_chain_check(uint8_t *idcodes, unsigned int count)
11021102
{
11031103
uint8_t zero_check = 0x0;
11041104
uint8_t one_check = 0xff;
11051105

1106-
for (unsigned i = 0; i < count * 4; i++) {
1106+
for (unsigned int i = 0; i < count * 4; i++) {
11071107
zero_check |= idcodes[i];
11081108
one_check &= idcodes[i];
11091109
}
@@ -1158,7 +1158,8 @@ static bool jtag_idcode_is_final(uint32_t idcode)
11581158
* with the JTAG chain earlier, gives more helpful/explicit error messages.
11591159
* Returns TRUE iff garbage was found.
11601160
*/
1161-
static bool jtag_examine_chain_end(uint8_t *idcodes, unsigned count, unsigned max)
1161+
static bool jtag_examine_chain_end(uint8_t *idcodes, unsigned int count,
1162+
unsigned int max)
11621163
{
11631164
bool triggered = false;
11641165
for (; count < max - 31; count += 32) {
@@ -1185,26 +1186,26 @@ static bool jtag_examine_chain_match_tap(const struct jtag_tap *tap)
11851186
uint32_t idcode = tap->idcode & mask;
11861187

11871188
/* Loop over the expected identification codes and test for a match */
1188-
for (unsigned ii = 0; ii < tap->expected_ids_cnt; ii++) {
1189-
uint32_t expected = tap->expected_ids[ii] & mask;
1189+
for (unsigned int i = 0; i < tap->expected_ids_cnt; i++) {
1190+
uint32_t expected = tap->expected_ids[i] & mask;
11901191

11911192
if (idcode == expected)
11921193
return true;
11931194

11941195
/* treat "-expected-id 0" as a "don't-warn" wildcard */
1195-
if (tap->expected_ids[ii] == 0)
1196+
if (tap->expected_ids[i] == 0)
11961197
return true;
11971198
}
11981199

11991200
/* If none of the expected ids matched, warn */
12001201
jtag_examine_chain_display(LOG_LVL_WARNING, "UNEXPECTED",
12011202
tap->dotted_name, tap->idcode);
1202-
for (unsigned ii = 0; ii < tap->expected_ids_cnt; ii++) {
1203+
for (unsigned int i = 0; i < tap->expected_ids_cnt; i++) {
12031204
char msg[32];
12041205

1205-
snprintf(msg, sizeof(msg), "expected %u of %u", ii + 1, tap->expected_ids_cnt);
1206+
snprintf(msg, sizeof(msg), "expected %u of %u", i + 1, tap->expected_ids_cnt);
12061207
jtag_examine_chain_display(LOG_LVL_ERROR, msg,
1207-
tap->dotted_name, tap->expected_ids[ii]);
1208+
tap->dotted_name, tap->expected_ids[i]);
12081209
}
12091210
return false;
12101211
}
@@ -1215,7 +1216,7 @@ static bool jtag_examine_chain_match_tap(const struct jtag_tap *tap)
12151216
static int jtag_examine_chain(void)
12161217
{
12171218
int retval;
1218-
unsigned max_taps = jtag_tap_count();
1219+
unsigned int max_taps = jtag_tap_count();
12191220

12201221
/* Autoprobe up to this many. */
12211222
if (max_taps < JTAG_MAX_AUTO_TAPS)
@@ -1243,9 +1244,9 @@ static int jtag_examine_chain(void)
12431244
/* Point at the 1st predefined tap, if any */
12441245
struct jtag_tap *tap = jtag_tap_next_enabled(NULL);
12451246

1246-
unsigned bit_count = 0;
1247-
unsigned autocount = 0;
1248-
for (unsigned i = 0; i < max_taps; i++) {
1247+
unsigned int bit_count = 0;
1248+
unsigned int autocount = 0;
1249+
for (unsigned int i = 0; i < max_taps; i++) {
12491250
assert(bit_count < max_taps * 32);
12501251
uint32_t idcode = buf_get_u32(idcode_buffer, bit_count, 32);
12511252

@@ -1445,8 +1446,8 @@ static int jtag_validate_ircapture(void)
14451446

14461447
void jtag_tap_init(struct jtag_tap *tap)
14471448
{
1448-
unsigned ir_len_bits;
1449-
unsigned ir_len_bytes;
1449+
unsigned int ir_len_bits;
1450+
unsigned int ir_len_bytes;
14501451

14511452
/* if we're autoprobing, cope with potentially huge ir_length */
14521453
ir_len_bits = tap->ir_length ? tap->ir_length : JTAG_IRLEN_MAX;
@@ -1749,37 +1750,36 @@ int jtag_get_srst(void)
17491750
return jtag_srst == 1;
17501751
}
17511752

1752-
void jtag_set_nsrst_delay(unsigned delay)
1753+
void jtag_set_nsrst_delay(unsigned int delay)
17531754
{
17541755
adapter_nsrst_delay = delay;
17551756
}
1756-
unsigned jtag_get_nsrst_delay(void)
1757+
unsigned int jtag_get_nsrst_delay(void)
17571758
{
17581759
return adapter_nsrst_delay;
17591760
}
1760-
void jtag_set_ntrst_delay(unsigned delay)
1761+
void jtag_set_ntrst_delay(unsigned int delay)
17611762
{
17621763
jtag_ntrst_delay = delay;
17631764
}
1764-
unsigned jtag_get_ntrst_delay(void)
1765+
unsigned int jtag_get_ntrst_delay(void)
17651766
{
17661767
return jtag_ntrst_delay;
17671768
}
17681769

1769-
1770-
void jtag_set_nsrst_assert_width(unsigned delay)
1770+
void jtag_set_nsrst_assert_width(unsigned int delay)
17711771
{
17721772
adapter_nsrst_assert_width = delay;
17731773
}
1774-
unsigned jtag_get_nsrst_assert_width(void)
1774+
unsigned int jtag_get_nsrst_assert_width(void)
17751775
{
17761776
return adapter_nsrst_assert_width;
17771777
}
1778-
void jtag_set_ntrst_assert_width(unsigned delay)
1778+
void jtag_set_ntrst_assert_width(unsigned int delay)
17791779
{
17801780
jtag_ntrst_assert_width = delay;
17811781
}
1782-
unsigned jtag_get_ntrst_assert_width(void)
1782+
unsigned int jtag_get_ntrst_assert_width(void)
17831783
{
17841784
return jtag_ntrst_assert_width;
17851785
}

src/jtag/drivers/vdebug.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -970,8 +970,8 @@ static int vdebug_jtag_scan(struct scan_command *cmd, uint8_t f_flush)
970970
uint8_t num_pre = tap_get_tms_path_len(cur, state);
971971
uint8_t tms_post = tap_get_tms_path(state, cmd->end_state);
972972
uint8_t num_post = tap_get_tms_path_len(state, cmd->end_state);
973-
int num_bits = jtag_scan_size(cmd);
974-
LOG_DEBUG_IO("scan len:%d fields:%u ir/!dr:%d state cur:%x end:%x",
973+
const unsigned int num_bits = jtag_scan_size(cmd);
974+
LOG_DEBUG_IO("scan len:%u fields:%u ir/!dr:%d state cur:%x end:%x",
975975
num_bits, cmd->num_fields, cmd->ir_scan, cur, cmd->end_state);
976976
for (unsigned int i = 0; i < cmd->num_fields; i++) {
977977
uint8_t cur_num_pre = i == 0 ? num_pre : 0;

src/jtag/jtag.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ struct jtag_tap *jtag_tap_by_string(const char *dotted_name);
152152
struct jtag_tap *jtag_tap_by_jim_obj(Jim_Interp *interp, Jim_Obj *obj);
153153
struct jtag_tap *jtag_tap_by_position(unsigned int abs_position);
154154
struct jtag_tap *jtag_tap_next_enabled(struct jtag_tap *p);
155-
unsigned jtag_tap_count_enabled(void);
156-
unsigned jtag_tap_count(void);
155+
unsigned int jtag_tap_count_enabled(void);
156+
unsigned int jtag_tap_count(void);
157157

158158
/*
159159
* - TRST_ASSERTED triggers two sets of callbacks, after operations to
@@ -229,17 +229,17 @@ enum reset_types {
229229
enum reset_types jtag_get_reset_config(void);
230230
void jtag_set_reset_config(enum reset_types type);
231231

232-
void jtag_set_nsrst_delay(unsigned delay);
233-
unsigned jtag_get_nsrst_delay(void);
232+
void jtag_set_nsrst_delay(unsigned int delay);
233+
unsigned int jtag_get_nsrst_delay(void);
234234

235-
void jtag_set_ntrst_delay(unsigned delay);
236-
unsigned jtag_get_ntrst_delay(void);
235+
void jtag_set_ntrst_delay(unsigned int delay);
236+
unsigned int jtag_get_ntrst_delay(void);
237237

238-
void jtag_set_nsrst_assert_width(unsigned delay);
239-
unsigned jtag_get_nsrst_assert_width(void);
238+
void jtag_set_nsrst_assert_width(unsigned int delay);
239+
unsigned int jtag_get_nsrst_assert_width(void);
240240

241-
void jtag_set_ntrst_assert_width(unsigned delay);
242-
unsigned jtag_get_ntrst_assert_width(void);
241+
void jtag_set_ntrst_assert_width(unsigned int delay);
242+
unsigned int jtag_get_ntrst_assert_width(void);
243243

244244
/** @returns The current state of TRST. */
245245
int jtag_get_trst(void);
@@ -488,7 +488,7 @@ void jtag_add_reset(int req_tlr_or_trst, int srst);
488488

489489
void jtag_add_sleep(uint32_t us);
490490

491-
int jtag_add_tms_seq(unsigned nbits, const uint8_t *seq, enum tap_state t);
491+
int jtag_add_tms_seq(unsigned int nbits, const uint8_t *seq, enum tap_state t);
492492

493493
/**
494494
* Function jtag_add_clocks
@@ -523,7 +523,7 @@ int jtag_execute_queue(void);
523523
void jtag_execute_queue_noclear(void);
524524

525525
/** @returns the number of times the scan queue has been flushed */
526-
int jtag_get_flush_queue_count(void);
526+
unsigned int jtag_get_flush_queue_count(void);
527527

528528
/** Report Tcl event to all TAPs */
529529
void jtag_notify_event(enum jtag_event);

src/jtag/tcl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ COMMAND_HANDLER(handle_jtag_flush_count)
212212
if (CMD_ARGC != 0)
213213
return ERROR_COMMAND_SYNTAX_ERROR;
214214

215-
int count = jtag_get_flush_queue_count();
216-
command_print_sameline(CMD, "%d", count);
215+
const unsigned int count = jtag_get_flush_queue_count();
216+
command_print_sameline(CMD, "%u", count);
217217

218218
return ERROR_OK;
219219
}

0 commit comments

Comments
 (0)