#include <windows.h>
#endif
-/* parallel port cable description
- */
+// Parallel port cable description.
struct cable {
const char *name;
- uint8_t TDO_MASK; /* status port bit containing current TDO value */
- uint8_t TRST_MASK; /* data port bit for TRST */
- uint8_t TMS_MASK; /* data port bit for TMS */
- uint8_t TCK_MASK; /* data port bit for TCK */
- uint8_t TDI_MASK; /* data port bit for TDI */
- uint8_t SRST_MASK; /* data port bit for SRST */
- uint8_t OUTPUT_INVERT; /* data port bits that should be inverted */
- uint8_t INPUT_INVERT; /* status port that should be inverted */
- uint8_t PORT_INIT; /* initialize data port with this value */
- uint8_t PORT_EXIT; /* de-initialize data port with this value */
- uint8_t LED_MASK; /* data port bit for LED */
+ // Status port bit containing current TDO value.
+ uint8_t tdo_mask;
+ // Data port bit for TRST.
+ uint8_t trst_mask;
+ // Data port bit for TMD.
+ uint8_t tms_mask;
+ // Data port bit for TCK.
+ uint8_t tck_mask;
+ // Data port bit for TDI.
+ uint8_t tdi_mask;
+ // Data port bit for SRST.
+ uint8_t srst_mask;
+ // Data port bits that should be inverted.
+ uint8_t output_invert;
+ // Status port that should be inverted.
+ uint8_t input_invert;
+ // Initialize data port with this value.
+ uint8_t port_init;
+ // De-initialize data port with this value.
+ uint8_t port_exit;
+ // Data port bit for LED.
+ uint8_t led_mask;
};
static const struct cable cables[] = {
{ NULL, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
};
-/* configuration */
+// Configuration variables.
static char *parport_cable;
static uint16_t parport_port;
static bool parport_exit;
static uint32_t parport_toggling_time_ns = 1000;
static int wait_states;
-/* interface variables
- */
+// Interface variables.
static const struct cable *cable;
static uint8_t dataport_value;
data = inb(statusport);
#endif
- if ((data ^ cable->INPUT_INVERT) & cable->TDO_MASK)
+ if ((data ^ cable->input_invert) & cable->tdo_mask)
return BB_HIGH;
else
return BB_LOW;
static inline void parport_write_data(void)
{
uint8_t output;
- output = dataport_value ^ cable->OUTPUT_INVERT;
+ output = dataport_value ^ cable->output_invert;
#if PARPORT_USE_PPDEV == 1
ioctl(device_handle, PPWDATA, &output);
int i = wait_states + 1;
if (tck)
- dataport_value |= cable->TCK_MASK;
+ dataport_value |= cable->tck_mask;
else
- dataport_value &= ~cable->TCK_MASK;
+ dataport_value &= ~cable->tck_mask;
if (tms)
- dataport_value |= cable->TMS_MASK;
+ dataport_value |= cable->tms_mask;
else
- dataport_value &= ~cable->TMS_MASK;
+ dataport_value &= ~cable->tms_mask;
if (tdi)
- dataport_value |= cable->TDI_MASK;
+ dataport_value |= cable->tdi_mask;
else
- dataport_value &= ~cable->TDI_MASK;
+ dataport_value &= ~cable->tdi_mask;
while (i-- > 0)
parport_write_data();
return ERROR_OK;
}
-/* (1) assert or (0) deassert reset lines */
+// (1) assert or (0) deassert reset lines.
static int parport_reset(int trst, int srst)
{
LOG_DEBUG("trst: %i, srst: %i", trst, srst);
if (trst == 0)
- dataport_value |= cable->TRST_MASK;
+ dataport_value |= cable->trst_mask;
else if (trst == 1)
- dataport_value &= ~cable->TRST_MASK;
+ dataport_value &= ~cable->trst_mask;
if (srst == 0)
- dataport_value |= cable->SRST_MASK;
+ dataport_value |= cable->srst_mask;
else if (srst == 1)
- dataport_value &= ~cable->SRST_MASK;
+ dataport_value &= ~cable->srst_mask;
parport_write_data();
return ERROR_OK;
}
-/* turn LED on parport adapter on (true) or off (true) */
static int parport_led(bool on)
{
if (on)
- dataport_value |= cable->LED_MASK;
+ dataport_value |= cable->led_mask;
else
- dataport_value &= ~cable->LED_MASK;
+ dataport_value &= ~cable->led_mask;
parport_write_data();
static int parport_khz(int khz, int *jtag_speed)
{
- if (khz == 0) {
+ if (!khz) {
LOG_DEBUG("RCLK not supported");
return ERROR_FAIL;
}
#endif
static struct bitbang_interface parport_bitbang = {
- .read = &parport_read,
- .write = &parport_write,
- .blink = &parport_led,
- };
+ .read = &parport_read,
+ .write = &parport_write,
+ .blink = &parport_led,
+};
static int parport_init(void)
{
}
while (cur_cable->name) {
- if (strcmp(cur_cable->name, parport_cable) == 0) {
+ if (!strcmp(cur_cable->name, parport_cable)) {
cable = cur_cable;
break;
}
return ERROR_JTAG_INIT_FAILED;
}
- dataport_value = cable->PORT_INIT;
+ dataport_value = cable->port_init;
#if PARPORT_USE_PPDEV == 1
if (device_handle > 0) {
#endif /* not __FreeBSD__, __FreeBSD_kernel__ */
#else /* not PARPORT_USE_PPDEV */
- if (parport_port == 0) {
+ if (!parport_port) {
parport_port = 0x378;
LOG_WARNING("No parport port specified, using default '0x378' (LPT1)");
}
}
LOG_DEBUG("...privileges granted");
- /* make sure parallel port is in right mode (clear tristate and interrupt */
+ // Make sure parallel port is in right mode (clear tristate and interrupt.
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
outb(parport_port + 2, 0x0);
#else
return ERROR_FAIL;
if (parport_exit) {
- dataport_value = cable->PORT_EXIT;
+ dataport_value = cable->port_exit;
parport_write_data();
}
return ERROR_OK;
}
-COMMAND_HANDLER(parport_handle_parport_port_command)
+COMMAND_HANDLER(parport_handle_port_command)
{
if (CMD_ARGC == 1) {
- /* only if the port wasn't overwritten by cmdline */
- if (parport_port == 0)
+ // Only if the port wasn't overwritten by cmdline.
+ if (!parport_port) {
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], parport_port);
- else {
+ } else {
LOG_ERROR("The parport port was already configured!");
return ERROR_FAIL;
}
return ERROR_OK;
}
-COMMAND_HANDLER(parport_handle_parport_cable_command)
+COMMAND_HANDLER(parport_handle_cable_command)
{
- if (CMD_ARGC == 0)
+ if (!CMD_ARGC)
return ERROR_OK;
- /* only if the cable name wasn't overwritten by cmdline */
+ // Only if the cable name wasn't overwritten by cmdline.
if (!parport_cable) {
- /* REVISIT first verify that it's listed in cables[] ... */
+ // TODO: REVISIT first verify that it's listed in cables[].
parport_cable = malloc(strlen(CMD_ARGV[0]) + sizeof(char));
if (!parport_cable) {
LOG_ERROR("Out of memory");
strcpy(parport_cable, CMD_ARGV[0]);
}
- /* REVISIT it's probably worth returning the current value ... */
+ // TODO: REVISIT it's probably worth returning the current value.
return ERROR_OK;
}
return ERROR_OK;
}
-COMMAND_HANDLER(parport_handle_parport_toggling_time_command)
+COMMAND_HANDLER(parport_handle_toggling_time_command)
{
if (CMD_ARGC == 1) {
uint32_t ns;
if (retval != ERROR_OK)
return retval;
- if (ns == 0) {
+ if (!ns) {
LOG_ERROR("0 ns is not a valid parport toggling time");
return ERROR_FAIL;
}
parport_toggling_time_ns = ns;
retval = adapter_get_speed(&wait_states);
if (retval != ERROR_OK) {
- /* if adapter_get_speed fails then the clock_mode
- * has not been configured, this happens if parport_toggling_time is
- * called before the adapter speed is set */
+ /*
+ * If adapter_get_speed fails then the clock_mode has
+ * not been configured, this happens if toggling_time is
+ * called before the adapter speed is set.
+ */
LOG_INFO("no parport speed set - defaulting to zero wait states");
wait_states = 0;
}
static const struct command_registration parport_subcommand_handlers[] = {
{
.name = "port",
- .handler = parport_handle_parport_port_command,
+ .handler = parport_handle_port_command,
.mode = COMMAND_CONFIG,
.help = "Display the address of the I/O port (e.g. 0x378) "
"or the number of the '/dev/parport' device used. "
},
{
.name = "cable",
- .handler = parport_handle_parport_cable_command,
+ .handler = parport_handle_cable_command,
.mode = COMMAND_CONFIG,
.help = "Set the layout of the parallel port cable "
"used to connect to the target.",
- /* REVISIT there's no way to list layouts we know ... */
+ // TODO: REVISIT there's no way to list layouts we know.
.usage = "[layout]",
},
{
},
{
.name = "toggling_time",
- .handler = parport_handle_parport_toggling_time_command,
+ .handler = parport_handle_toggling_time_command,
.mode = COMMAND_CONFIG,
.help = "Displays or assigns how many nanoseconds it "
"takes for the hardware to toggle TCK.",