#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);
#ifdef _DEBUG_GW16012_IO_
LOG_DEBUG("%2.2x", value);
#endif
#ifdef _DEBUG_GW16012_IO_
LOG_DEBUG("%2.2x", value);
#endif
#if PARPORT_USE_PPDEV == 1
ioctl(device_handle, PPWDATA, &value);
#else
#if PARPORT_USE_PPDEV == 1
ioctl(device_handle, PPWDATA, &value);
#else
{
#if PARPORT_USE_PPDEV == 1
ioctl(device_handle, PPRSTATUS, value);
{
#if PARPORT_USE_PPDEV == 1
ioctl(device_handle, PPRSTATUS, value);
{
LOG_DEBUG("trst: %i, srst: %i", trst, srst);
{
LOG_DEBUG("trst: %i, srst: %i", trst, srst);
- u8 tms_scan = TAP_MOVE(cur_state, end_state);
-
+ u8 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());
+
- LOG_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, u8 *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
case JTAG_RESET:
#ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst);
#endif
if (cmd->cmd.reset->trst == 1)
{
case JTAG_RESET:
#ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst);
#endif
if (cmd->cmd.reset->trst == 1)
{
#ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, cmd->cmd.runtest->end_state);
#endif
#ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, cmd->cmd.runtest->end_state);
#endif
gw16012_runtest(cmd->cmd.runtest->num_cycles);
break;
case JTAG_STATEMOVE:
#ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("statemove end in %i", cmd->cmd.statemove->end_state);
#endif
gw16012_runtest(cmd->cmd.runtest->num_cycles);
break;
case JTAG_STATEMOVE:
#ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("statemove end in %i", cmd->cmd.statemove->end_state);
#endif
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
- LOG_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)
- i = PARPORT_MODE_COMPAT;
- i= ioctl(device_handle, PPSETMODE, & i);
- if (i<0)
+#endif // defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+
+static int gw16012_init_device(void)
+{
+ const char *device_name = GW16012_PPDEV_NAME;
+ char buffer[256];
+
+ if (device_handle > 0)
- 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)
LOG_DEBUG("requesting privileges for parallel port 0x%lx...", (long unsigned)(gw16012_port) );
#if PARPORT_USE_GIVEIO == 1
if (gw16012_get_giveio_access() != 0)
LOG_DEBUG("requesting privileges for parallel port 0x%lx...", (long unsigned)(gw16012_port) );
#if PARPORT_USE_GIVEIO == 1
if (gw16012_get_giveio_access() != 0)
-#endif /* PARPORT_USE_PPDEV */
-
+ return ERROR_OK;
+}
+
+#endif // PARPORT_USE_PPDEV
+
+static int gw16012_init(void)
+{
+ u8 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)