#include <machine/sysarch.h>
#include <machine/cpufunc.h>
#define ioperm(startport,length,enable)\
#include <machine/sysarch.h>
#include <machine/cpufunc.h>
#define ioperm(startport,length,enable)\
-int gw16012_execute_queue(void);
-int gw16012_register_commands(struct command_context_s *cmd_ctx);
-int gw16012_speed(int speed);
-int gw16012_init(void);
-int gw16012_quit(void);
+static int gw16012_execute_queue(void);
+static int gw16012_register_commands(struct command_context_s *cmd_ctx);
+static int gw16012_speed(int speed);
+static int gw16012_init(void);
+static int gw16012_quit(void);
-int gw16012_handle_parport_port_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
+static int gw16012_handle_parport_port_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
{
register_command(cmd_ctx, NULL, "parport_port", gw16012_handle_parport_port_command,
COMMAND_CONFIG, NULL);
{
register_command(cmd_ctx, NULL, "parport_port", gw16012_handle_parport_port_command,
COMMAND_CONFIG, NULL);
{
value = (value & 0x7f) | gw16012_msb;
gw16012_msb ^= 0x80; /* toggle MSB */
#ifdef _DEBUG_GW16012_IO_
{
value = (value & 0x7f) | gw16012_msb;
gw16012_msb ^= 0x80; /* toggle MSB */
#ifdef _DEBUG_GW16012_IO_
#if PARPORT_USE_PPDEV == 1
ioctl(device_handle, PPWDATA, &value);
#else
#if PARPORT_USE_PPDEV == 1
ioctl(device_handle, PPWDATA, &value);
#else
{
if (value != gw16012_control_value)
{
gw16012_control_value = value;
#ifdef _DEBUG_GW16012_IO_
{
if (value != gw16012_control_value)
{
gw16012_control_value = value;
#ifdef _DEBUG_GW16012_IO_
{
#if PARPORT_USE_PPDEV == 1
ioctl(device_handle, PPRSTATUS, value);
{
#if PARPORT_USE_PPDEV == 1
ioctl(device_handle, PPRSTATUS, value);
- DEBUG("trst: %i, srst: %i", trst, srst);
+ LOG_DEBUG("trst: %i, srst: %i", trst, srst);
- int i=0, tms=0;
- u8 tms_scan = TAP_MOVE(cur_state, end_state);
-
+ int i = 0, tms = 0;
+ uint8_t tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state());
+ int tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
+
- ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_strings[cur_state], tap_state_strings[cmd->path[state_count]]);
+ LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_name(tap_get_state()), tap_state_name(cmd->path[state_count]));
for (i = 0; i < num_cycles; i++)
{
gw16012_control(0x0); /* single-bit mode */
gw16012_data(0x0); /* TMS cycle with TMS low */
}
for (i = 0; i < num_cycles; i++)
{
gw16012_control(0x0); /* single-bit mode */
gw16012_data(0x0); /* TMS cycle with TMS low */
}
-void gw16012_scan(int ir_scan, enum scan_type type, u8 *buffer, int scan_size)
+static void gw16012_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size)
{
gw16012_input(&scan_in);
buf_set_u32(buffer, bit_count, 1, ((scan_in & 0x08) >> 3));
{
gw16012_input(&scan_in);
buf_set_u32(buffer, bit_count, 1, ((scan_in & 0x08) >> 3));
/* return ERROR_OK, unless a jtag_read_buffer returns a failed check
* that wasn't handled by a caller-provided error handler
/* return ERROR_OK, unless a jtag_read_buffer returns a failed check
* that wasn't handled by a caller-provided error handler
- DEBUG("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, cmd->cmd.runtest->end_state);
+ LOG_DEBUG("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, cmd->cmd.runtest->end_state);
- DEBUG("pathmove: %i states, end in %i", cmd->cmd.pathmove->num_states, cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]);
+ LOG_DEBUG("pathmove: %i states, end in %i", cmd->cmd.pathmove->num_states, cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]);
scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer);
type = jtag_scan_type(cmd->cmd.scan);
#ifdef _DEBUG_JTAG_IO_
scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer);
type = jtag_scan_type(cmd->cmd.scan);
#ifdef _DEBUG_JTAG_IO_
type, scan_size, cmd->cmd.scan->end_state);
#endif
gw16012_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size);
type, scan_size, cmd->cmd.scan->end_state);
#endif
gw16012_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size);
- HANDLE h;
- OSVERSIONINFO version;
-
- version.dwOSVersionInfoSize = sizeof version;
- if (!GetVersionEx( &version )) {
- errno = EINVAL;
- return -1;
- }
- if (version.dwPlatformId != VER_PLATFORM_WIN32_NT)
- return 0;
-
- h = CreateFile( "\\\\.\\giveio", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
- if (h == INVALID_HANDLE_VALUE) {
- errno = ENODEV;
- return -1;
- }
-
- CloseHandle( h );
-
- return 0;
+ HANDLE h;
+ OSVERSIONINFO version;
+
+ version.dwOSVersionInfoSize = sizeof version;
+ if (!GetVersionEx( &version )) {
+ errno = EINVAL;
+ return -1;
+ }
+ if (version.dwPlatformId != VER_PLATFORM_WIN32_NT)
+ return 0;
+
+ h = CreateFile( "\\\\.\\giveio", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
+ if (h == INVALID_HANDLE_VALUE) {
+ errno = ENODEV;
+ return -1;
+ }
+
+ CloseHandle( h );
+
+ return 0;
- snprintf(buffer, 256, "/dev/ppi%d", gw16012_port);
- device_handle = open(buffer, O_WRONLY);
-#else
- DEBUG("opening /dev/parport%d...", gw16012_port);
+#define GW16012_PPDEV_NAME "ppi"
- snprintf(buffer, 256, "/dev/parport%d", gw16012_port);
- device_handle = open(buffer, O_WRONLY);
-#endif
- if (device_handle<0)
+static int gw16012_init_ioctls(void)
+{
+ int temp = 0;
+ temp = ioctl(device_handle, PPCLAIM);
+ if (temp < 0)
+ temp = PARPORT_MODE_COMPAT;
+ temp = ioctl(device_handle, PPSETMODE, &temp);
+ if (temp < 0)
+ {
+ LOG_ERROR(" cannot set compatible mode to device");
+ return ERROR_JTAG_INIT_FAILED;
+ }
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
- i=ioctl(device_handle, PPCLAIM);
- if (i<0)
+ temp = IEEE1284_MODE_COMPAT;
+ temp = ioctl(device_handle, PPNEGOT, &temp);
+ if (temp < 0)
+ return ERROR_OK;
+}
+#else
+
+#define GW16012_PPDEV_NAME "parport"
+
+static int gw16012_init_ioctls(void)
+{
+ return ERROR_OK;
+}
+
+#endif // defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+
+static int gw16012_init_device(void)
+{
+ const char *device_name = GW16012_PPDEV_NAME;
+ char buffer[256];
- i = IEEE1284_MODE_COMPAT;
- i = ioctl(device_handle, PPNEGOT, & i);
- if (i<0)
+ snprintf(buffer, 256, "/dev/%s%d", device_name, gw16012_port);
+ LOG_DEBUG("opening %s...", buffer);
+
+ device_handle = open(buffer, O_WRONLY);
+ if (device_handle<0)
#if PARPORT_USE_GIVEIO == 1
if (gw16012_get_giveio_access() != 0)
#else /* PARPORT_USE_GIVEIO */
if (ioperm(gw16012_port, 3, 1) != 0)
#endif /* PARPORT_USE_GIVEIO */
{
#if PARPORT_USE_GIVEIO == 1
if (gw16012_get_giveio_access() != 0)
#else /* PARPORT_USE_GIVEIO */
if (ioperm(gw16012_port, 3, 1) != 0)
#endif /* PARPORT_USE_GIVEIO */
{
/* make sure parallel port is in right mode (clear tristate and interrupt */
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
/* make sure parallel port is in right mode (clear tristate and interrupt */
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
-#endif /* PARPORT_USE_PPDEV */
-
+ return ERROR_OK;
+}
+
+#endif // PARPORT_USE_PPDEV
+
+static int gw16012_init(void)
+{
+ uint8_t status_port;
+
+ if (gw16012_init_device() != ERROR_OK)
+ return ERROR_JTAG_INIT_FAILED;
+
-int gw16012_handle_parport_port_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+static int gw16012_handle_parport_port_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
- if (argc == 0)
- return ERROR_OK;
+ if (argc == 1)
+ {
+ /* only if the port wasn't overwritten by cmdline */
+ if (gw16012_port == 0)
+ {
+ int retval = parse_u16(args[0], &gw16012_port);
+ if (ERROR_OK != retval)
+ return retval;
+ }
+ else
+ {
+ LOG_ERROR("The parport port was already configured!");
+ return ERROR_FAIL;
+ }
+ }
- /* only if the port wasn't overwritten by cmdline */
- if (gw16012_port == 0)
- gw16012_port = strtoul(args[0], NULL, 0);
+ command_print(cmd_ctx, "parport port = %u", gw16012_port);