#include "config.h"
#endif
-#include "log.h"
+#include "replacements.h"
+
#include "jtag.h"
/* system includes */
-#include <sys/io.h>
+
+#ifdef _WIN32
+#include "errno.h"
+#endif /* _WIN32 */
+
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
+#else /* not PARPORT_USE_PPDEV */
+#ifndef _WIN32
+#include <sys/io.h>
+#endif
#endif
+#if PARPORT_USE_GIVEIO == 1
+#if IS_CYGWIN == 1
+#include <windows.h>
+#include <errno.h>
+#undef ERROR
+#endif
+#endif
+
+#include "log.h"
+
/* configuration */
unsigned long amt_jtagaccel_port;
.execute_queue = amt_jtagaccel_execute_queue,
- .support_statemove = 0,
-
.speed = amt_jtagaccel_speed,
.register_commands = amt_jtagaccel_register_commands,
.init = amt_jtagaccel_init,
if (ar_status & 0x80)
{
- ERROR("amt_jtagaccel timed out while waiting for end of scan, rtck was %s", (rtck_enabled) ? "enabled" : "disabled");
+ ERROR("amt_jtagaccel timed out while waiting for end of scan, rtck was %s, last AR_STATUS: 0x%2.2x", (rtck_enabled) ? "enabled" : "disabled", ar_status);
exit(-1);
}
}
int scan_size;
enum scan_type type;
u8 *buffer;
+ int retval;
+
+ /* return ERROR_OK, unless a jtag_read_buffer returns a failed check
+ * that wasn't handled by a caller-provided error handler
+ */
+ retval = ERROR_OK;
while (cmd)
{
type = jtag_scan_type(cmd->cmd.scan);
amt_jtagaccel_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size);
if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK)
- return ERROR_JTAG_QUEUE_FAILED;
+ retval = ERROR_JTAG_QUEUE_FAILED;
if (buffer)
free(buffer);
break;
case JTAG_SLEEP:
#ifdef _DEBUG_JTAG_IO_
- DEBUG("sleep", cmd->cmd.sleep->us);
+ DEBUG("sleep %i", cmd->cmd.sleep->us);
#endif
jtag_sleep(cmd->cmd.sleep->us);
break;
cmd = cmd->next;
}
- return ERROR_OK;
+ return retval;
}
+#if PARPORT_USE_GIVEIO == 1
+int amt_jtagaccel_get_giveio_access()
+{
+ 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;
+}
+#endif
+
int amt_jtagaccel_init(void)
{
#if PARPORT_USE_PPDEV == 1
#else
u8 status_port;
#endif
-
+ u8 ar_status;
+
#if PARPORT_USE_PPDEV == 1
if (device_handle > 0)
{
amt_jtagaccel_port = 0x378;
WARNING("No parport port specified, using default '0x378' (LPT1)");
}
-
+
+#if PARPORT_USE_GIVEIO == 1
+ if (amt_jtagaccel_get_giveio_access() != 0) {
+#else /* PARPORT_USE_GIVEIO */
if (ioperm(amt_jtagaccel_port, 5, 1) != 0) {
+#endif /* PARPORT_USE_GIVEIO */
ERROR("missing privileges for direct i/o");
return ERROR_JTAG_INIT_FAILED;
}
outb(0x04, amt_jtagaccel_port + 2);
#endif
+ if (rtck_enabled)
+ {
+ /* set RTCK enable bit */
+ aw_control_fsm |= 0x02;
+ }
+
/* enable JTAG port */
aw_control_fsm |= 0x04;
AMT_AW(aw_control_fsm);
amt_jtagaccel_reset(0, 0);
+ /* read status register */
+ AMT_AR(ar_status);
+ DEBUG("AR_STATUS: 0x%2.2x", ar_status);
+
return ERROR_OK;
}
if (strcmp(args[0], "enabled") == 0)
{
rtck_enabled = 1;
-
- /* set RTCK enable bit */
- aw_control_fsm |= 0x02;
- AMT_AW(aw_control_fsm);
+ }
+ else
+ {
+ rtck_enabled = 0;
}
}