Skip to content

Commit 3b261fb

Browse files
zapb-0borneoa
authored andcommitted
adapter/parport: Coding style changes
Apply some coding style changes according to the C style guide. The patch is tested for regression with the 'wiggler' parallel port cable. Change-Id: I43774f596831d8c46f90f18893418178041a930b Signed-off-by: Marc Schink <[email protected]> Reviewed-on: https://review.openocd.org/c/openocd/+/8516 Reviewed-by: Antonio Borneo <[email protected]> Tested-by: jenkins
1 parent 337db32 commit 3b261fb

File tree

1 file changed

+70
-60
lines changed

1 file changed

+70
-60
lines changed

src/jtag/drivers/parport.c

Lines changed: 70 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,31 @@
4545
#include <windows.h>
4646
#endif
4747

48-
/* parallel port cable description
49-
*/
48+
// Parallel port cable description.
5049
struct cable {
5150
const char *name;
52-
uint8_t TDO_MASK; /* status port bit containing current TDO value */
53-
uint8_t TRST_MASK; /* data port bit for TRST */
54-
uint8_t TMS_MASK; /* data port bit for TMS */
55-
uint8_t TCK_MASK; /* data port bit for TCK */
56-
uint8_t TDI_MASK; /* data port bit for TDI */
57-
uint8_t SRST_MASK; /* data port bit for SRST */
58-
uint8_t OUTPUT_INVERT; /* data port bits that should be inverted */
59-
uint8_t INPUT_INVERT; /* status port that should be inverted */
60-
uint8_t PORT_INIT; /* initialize data port with this value */
61-
uint8_t PORT_EXIT; /* de-initialize data port with this value */
62-
uint8_t LED_MASK; /* data port bit for LED */
51+
// Status port bit containing current TDO value.
52+
uint8_t tdo_mask;
53+
// Data port bit for TRST.
54+
uint8_t trst_mask;
55+
// Data port bit for TMD.
56+
uint8_t tms_mask;
57+
// Data port bit for TCK.
58+
uint8_t tck_mask;
59+
// Data port bit for TDI.
60+
uint8_t tdi_mask;
61+
// Data port bit for SRST.
62+
uint8_t srst_mask;
63+
// Data port bits that should be inverted.
64+
uint8_t output_invert;
65+
// Status port that should be inverted.
66+
uint8_t input_invert;
67+
// Initialize data port with this value.
68+
uint8_t port_init;
69+
// De-initialize data port with this value.
70+
uint8_t port_exit;
71+
// Data port bit for LED.
72+
uint8_t led_mask;
6373
};
6474

6575
static const struct cable cables[] = {
@@ -87,15 +97,14 @@ static const struct cable cables[] = {
8797
{ NULL, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
8898
};
8999

90-
/* configuration */
100+
// Configuration variables.
91101
static char *parport_cable;
92102
static uint16_t parport_port;
93103
static bool parport_exit;
94104
static uint32_t parport_toggling_time_ns = 1000;
95105
static int wait_states;
96106

97-
/* interface variables
98-
*/
107+
// Interface variables.
99108
static const struct cable *cable;
100109
static uint8_t dataport_value;
101110

@@ -116,7 +125,7 @@ static bb_value_t parport_read(void)
116125
data = inb(statusport);
117126
#endif
118127

119-
if ((data ^ cable->INPUT_INVERT) & cable->TDO_MASK)
128+
if ((data ^ cable->input_invert) & cable->tdo_mask)
120129
return BB_HIGH;
121130
else
122131
return BB_LOW;
@@ -125,7 +134,7 @@ static bb_value_t parport_read(void)
125134
static inline void parport_write_data(void)
126135
{
127136
uint8_t output;
128-
output = dataport_value ^ cable->OUTPUT_INVERT;
137+
output = dataport_value ^ cable->output_invert;
129138

130139
#if PARPORT_USE_PPDEV == 1
131140
ioctl(device_handle, PPWDATA, &output);
@@ -143,53 +152,52 @@ static int parport_write(int tck, int tms, int tdi)
143152
int i = wait_states + 1;
144153

145154
if (tck)
146-
dataport_value |= cable->TCK_MASK;
155+
dataport_value |= cable->tck_mask;
147156
else
148-
dataport_value &= ~cable->TCK_MASK;
157+
dataport_value &= ~cable->tck_mask;
149158

150159
if (tms)
151-
dataport_value |= cable->TMS_MASK;
160+
dataport_value |= cable->tms_mask;
152161
else
153-
dataport_value &= ~cable->TMS_MASK;
162+
dataport_value &= ~cable->tms_mask;
154163

155164
if (tdi)
156-
dataport_value |= cable->TDI_MASK;
165+
dataport_value |= cable->tdi_mask;
157166
else
158-
dataport_value &= ~cable->TDI_MASK;
167+
dataport_value &= ~cable->tdi_mask;
159168

160169
while (i-- > 0)
161170
parport_write_data();
162171

163172
return ERROR_OK;
164173
}
165174

166-
/* (1) assert or (0) deassert reset lines */
175+
// (1) assert or (0) deassert reset lines.
167176
static int parport_reset(int trst, int srst)
168177
{
169178
LOG_DEBUG("trst: %i, srst: %i", trst, srst);
170179

171180
if (trst == 0)
172-
dataport_value |= cable->TRST_MASK;
181+
dataport_value |= cable->trst_mask;
173182
else if (trst == 1)
174-
dataport_value &= ~cable->TRST_MASK;
183+
dataport_value &= ~cable->trst_mask;
175184

176185
if (srst == 0)
177-
dataport_value |= cable->SRST_MASK;
186+
dataport_value |= cable->srst_mask;
178187
else if (srst == 1)
179-
dataport_value &= ~cable->SRST_MASK;
188+
dataport_value &= ~cable->srst_mask;
180189

181190
parport_write_data();
182191

183192
return ERROR_OK;
184193
}
185194

186-
/* turn LED on parport adapter on (true) or off (true) */
187195
static int parport_led(bool on)
188196
{
189197
if (on)
190-
dataport_value |= cable->LED_MASK;
198+
dataport_value |= cable->led_mask;
191199
else
192-
dataport_value &= ~cable->LED_MASK;
200+
dataport_value &= ~cable->led_mask;
193201

194202
parport_write_data();
195203

@@ -204,7 +212,7 @@ static int parport_speed(int speed)
204212

205213
static int parport_khz(int khz, int *jtag_speed)
206214
{
207-
if (khz == 0) {
215+
if (!khz) {
208216
LOG_DEBUG("RCLK not supported");
209217
return ERROR_FAIL;
210218
}
@@ -248,10 +256,10 @@ static int parport_get_giveio_access(void)
248256
#endif
249257

250258
static struct bitbang_interface parport_bitbang = {
251-
.read = &parport_read,
252-
.write = &parport_write,
253-
.blink = &parport_led,
254-
};
259+
.read = &parport_read,
260+
.write = &parport_write,
261+
.blink = &parport_led,
262+
};
255263

256264
static int parport_init(void)
257265
{
@@ -268,7 +276,7 @@ static int parport_init(void)
268276
}
269277

270278
while (cur_cable->name) {
271-
if (strcmp(cur_cable->name, parport_cable) == 0) {
279+
if (!strcmp(cur_cable->name, parport_cable)) {
272280
cable = cur_cable;
273281
break;
274282
}
@@ -280,7 +288,7 @@ static int parport_init(void)
280288
return ERROR_JTAG_INIT_FAILED;
281289
}
282290

283-
dataport_value = cable->PORT_INIT;
291+
dataport_value = cable->port_init;
284292

285293
#if PARPORT_USE_PPDEV == 1
286294
if (device_handle > 0) {
@@ -332,7 +340,7 @@ static int parport_init(void)
332340
#endif /* not __FreeBSD__, __FreeBSD_kernel__ */
333341

334342
#else /* not PARPORT_USE_PPDEV */
335-
if (parport_port == 0) {
343+
if (!parport_port) {
336344
parport_port = 0x378;
337345
LOG_WARNING("No parport port specified, using default '0x378' (LPT1)");
338346
}
@@ -351,7 +359,7 @@ static int parport_init(void)
351359
}
352360
LOG_DEBUG("...privileges granted");
353361

354-
/* make sure parallel port is in right mode (clear tristate and interrupt */
362+
// Make sure parallel port is in right mode (clear tristate and interrupt.
355363
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
356364
outb(parport_port + 2, 0x0);
357365
#else
@@ -378,7 +386,7 @@ static int parport_quit(void)
378386
return ERROR_FAIL;
379387

380388
if (parport_exit) {
381-
dataport_value = cable->PORT_EXIT;
389+
dataport_value = cable->port_exit;
382390
parport_write_data();
383391
}
384392

@@ -388,13 +396,13 @@ static int parport_quit(void)
388396
return ERROR_OK;
389397
}
390398

391-
COMMAND_HANDLER(parport_handle_parport_port_command)
399+
COMMAND_HANDLER(parport_handle_port_command)
392400
{
393401
if (CMD_ARGC == 1) {
394-
/* only if the port wasn't overwritten by cmdline */
395-
if (parport_port == 0)
402+
// Only if the port wasn't overwritten by cmdline.
403+
if (!parport_port) {
396404
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], parport_port);
397-
else {
405+
} else {
398406
LOG_ERROR("The parport port was already configured!");
399407
return ERROR_FAIL;
400408
}
@@ -405,14 +413,14 @@ COMMAND_HANDLER(parport_handle_parport_port_command)
405413
return ERROR_OK;
406414
}
407415

408-
COMMAND_HANDLER(parport_handle_parport_cable_command)
416+
COMMAND_HANDLER(parport_handle_cable_command)
409417
{
410-
if (CMD_ARGC == 0)
418+
if (!CMD_ARGC)
411419
return ERROR_OK;
412420

413-
/* only if the cable name wasn't overwritten by cmdline */
421+
// Only if the cable name wasn't overwritten by cmdline.
414422
if (!parport_cable) {
415-
/* REVISIT first verify that it's listed in cables[] ... */
423+
// TODO: REVISIT first verify that it's listed in cables[].
416424
parport_cable = malloc(strlen(CMD_ARGV[0]) + sizeof(char));
417425
if (!parport_cable) {
418426
LOG_ERROR("Out of memory");
@@ -421,7 +429,7 @@ COMMAND_HANDLER(parport_handle_parport_cable_command)
421429
strcpy(parport_cable, CMD_ARGV[0]);
422430
}
423431

424-
/* REVISIT it's probably worth returning the current value ... */
432+
// TODO: REVISIT it's probably worth returning the current value.
425433

426434
return ERROR_OK;
427435
}
@@ -436,7 +444,7 @@ COMMAND_HANDLER(parport_handle_write_on_exit_command)
436444
return ERROR_OK;
437445
}
438446

439-
COMMAND_HANDLER(parport_handle_parport_toggling_time_command)
447+
COMMAND_HANDLER(parport_handle_toggling_time_command)
440448
{
441449
if (CMD_ARGC == 1) {
442450
uint32_t ns;
@@ -445,17 +453,19 @@ COMMAND_HANDLER(parport_handle_parport_toggling_time_command)
445453
if (retval != ERROR_OK)
446454
return retval;
447455

448-
if (ns == 0) {
456+
if (!ns) {
449457
LOG_ERROR("0 ns is not a valid parport toggling time");
450458
return ERROR_FAIL;
451459
}
452460

453461
parport_toggling_time_ns = ns;
454462
retval = adapter_get_speed(&wait_states);
455463
if (retval != ERROR_OK) {
456-
/* if adapter_get_speed fails then the clock_mode
457-
* has not been configured, this happens if parport_toggling_time is
458-
* called before the adapter speed is set */
464+
/*
465+
* If adapter_get_speed fails then the clock_mode has
466+
* not been configured, this happens if toggling_time is
467+
* called before the adapter speed is set.
468+
*/
459469
LOG_INFO("no parport speed set - defaulting to zero wait states");
460470
wait_states = 0;
461471
}
@@ -470,7 +480,7 @@ COMMAND_HANDLER(parport_handle_parport_toggling_time_command)
470480
static const struct command_registration parport_subcommand_handlers[] = {
471481
{
472482
.name = "port",
473-
.handler = parport_handle_parport_port_command,
483+
.handler = parport_handle_port_command,
474484
.mode = COMMAND_CONFIG,
475485
.help = "Display the address of the I/O port (e.g. 0x378) "
476486
"or the number of the '/dev/parport' device used. "
@@ -479,11 +489,11 @@ static const struct command_registration parport_subcommand_handlers[] = {
479489
},
480490
{
481491
.name = "cable",
482-
.handler = parport_handle_parport_cable_command,
492+
.handler = parport_handle_cable_command,
483493
.mode = COMMAND_CONFIG,
484494
.help = "Set the layout of the parallel port cable "
485495
"used to connect to the target.",
486-
/* REVISIT there's no way to list layouts we know ... */
496+
// TODO: REVISIT there's no way to list layouts we know.
487497
.usage = "[layout]",
488498
},
489499
{
@@ -496,7 +506,7 @@ static const struct command_registration parport_subcommand_handlers[] = {
496506
},
497507
{
498508
.name = "toggling_time",
499-
.handler = parport_handle_parport_toggling_time_command,
509+
.handler = parport_handle_toggling_time_command,
500510
.mode = COMMAND_CONFIG,
501511
.help = "Displays or assigns how many nanoseconds it "
502512
"takes for the hardware to toggle TCK.",

0 commit comments

Comments
 (0)