16 #define _DEBUG_GW16012_IO_
21 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
23 #include <machine/sysarch.h>
24 #include <machine/cpufunc.h>
25 #define ioperm(startport, length, enable) \
26 386_set_ioperm((startport), (length), (enable))
32 #if PARPORT_USE_PPDEV == 1
33 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
34 #include <dev/ppbus/ppi.h>
35 #include <dev/ppbus/ppbconf.h>
36 #define PPRSTATUS PPIGSTATUS
37 #define PPWDATA PPISDATA
39 #include <linux/parport.h>
40 #include <linux/ppdev.h>
43 #include <sys/ioctl.h>
50 #if PARPORT_USE_GIVEIO == 1 && IS_CYGWIN == 1
62 #if PARPORT_USE_PPDEV == 1
63 static int device_handle;
71 #ifdef _DEBUG_GW16012_IO_
75 #if PARPORT_USE_PPDEV == 1
76 ioctl(device_handle, PPWDATA, &value);
78 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
91 #ifdef _DEBUG_GW16012_IO_
95 #if PARPORT_USE_PPDEV == 1
98 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
109 #if PARPORT_USE_PPDEV == 1
110 ioctl(device_handle, PPRSTATUS, value);
115 #ifdef _DEBUG_GW16012_IO_
123 LOG_DEBUG(
"trst: %i, srst: %i", trst, srst);
154 for (i = 0; i < tms_count; i++) {
155 tms = (tms_scan >> i) & 1;
164 int num_states =
cmd->num_states;
175 LOG_ERROR(
"BUG: %s -> %s isn't a valid TAP transition",
198 for (
unsigned int i = 0; i < num_cycles; i++) {
210 int bits_left = scan_size;
213 uint8_t scan_out, scan_in;
236 while (bits_left-- > 0) {
241 if (bits_left == 0) {
289 if (
cmd->cmd.reset->trst == 1)
294 LOG_DEBUG_IO(
"runtest %u cycles, end in %i",
cmd->cmd.runtest->num_cycles,
295 cmd->cmd.runtest->end_state);
305 LOG_DEBUG_IO(
"pathmove: %i states, end in %i",
cmd->cmd.pathmove->num_states,
306 cmd->cmd.pathmove->path[
cmd->cmd.pathmove->num_states - 1]);
313 LOG_DEBUG_IO(
"%s scan (%i) %i bit end in %i", (
cmd->cmd.scan->ir_scan) ?
"ir" :
"dr",
314 type, scan_size,
cmd->cmd.scan->end_state);
325 LOG_ERROR(
"BUG: unknown JTAG command type encountered");
334 #if PARPORT_USE_GIVEIO == 1
335 static int gw16012_get_giveio_access(
void)
338 OSVERSIONINFO version;
340 version.dwOSVersionInfoSize =
sizeof(version);
341 if (!GetVersionEx(&version)) {
345 if (version.dwPlatformId != VER_PLATFORM_WIN32_NT)
348 h = CreateFile(
"\\\\.\\giveio", GENERIC_READ, 0,
NULL, OPEN_EXISTING,
349 FILE_ATTRIBUTE_NORMAL,
NULL);
350 if (h == INVALID_HANDLE_VALUE) {
361 #if PARPORT_USE_PPDEV == 1
363 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
365 #define GW16012_PPDEV_NAME "ppi"
367 static int gw16012_init_ioctls(
void)
370 temp = ioctl(device_handle, PPCLAIM);
376 temp = PARPORT_MODE_COMPAT;
377 temp = ioctl(device_handle, PPSETMODE, &temp);
379 LOG_ERROR(
" cannot set compatible mode to device");
383 temp = IEEE1284_MODE_COMPAT;
384 temp = ioctl(device_handle, PPNEGOT, &temp);
386 LOG_ERROR(
"cannot set compatible 1284 mode to device");
393 #define GW16012_PPDEV_NAME "parport"
395 static int gw16012_init_ioctls(
void)
404 const char *device_name = GW16012_PPDEV_NAME;
407 if (device_handle > 0) {
415 device_handle = open(
buffer, O_WRONLY);
416 if (device_handle < 0) {
417 LOG_ERROR(
"cannot open device. check it exists and that user read and write rights are set");
423 if (gw16012_init_ioctls() !=
ERROR_OK)
435 LOG_WARNING(
"No gw16012 port specified, using default '0x378' (LPT1)");
439 #if PARPORT_USE_GIVEIO == 1
440 if (gw16012_get_giveio_access() != 0) {
444 LOG_ERROR(
"missing privileges for direct i/o");
450 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
488 LOG_ERROR(
"The parport port was already configured!");
500 .
name =
"parport_port",
501 .handler = gw16012_handle_parport_port_command,
503 .help =
"Display the address of the I/O port (e.g. 0x378) "
504 "or the number of the '/dev/parport' device used. "
505 "If a parameter is provided, first change that port.",
506 .usage =
"[port_number]",
const char *const jtag_only[]
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
static void buf_set_u32(uint8_t *_buffer, unsigned int first, unsigned int num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
void command_print(struct command_invocation *cmd, const char *format,...)
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer)
enum scan_type jtag_scan_type(const struct scan_command *cmd)
int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd)
scan_type
The inferred type of a scan_command structure, indicating whether the command has the host scan in fr...
@ SCAN_OUT
From host to device,.
static int gw16012_init(void)
static void gw16012_runtest(unsigned int num_cycles)
static void gw16012_data(uint8_t value)
static void gw16012_control(uint8_t value)
static uint8_t gw16012_msb
static const struct command_registration gw16012_command_handlers[]
static void gw16012_reset(int trst, int srst)
static void gw16012_end_state(tap_state_t state)
static void gw16012_input(uint8_t *value)
static int gw16012_quit(void)
COMMAND_HANDLER(gw16012_handle_parport_port_command)
static int gw16012_execute_queue(struct jtag_command *cmd_queue)
static uint16_t gw16012_port
struct adapter_driver gw16012_adapter_driver
static int gw16012_init_device(void)
static struct jtag_interface gw16012_interface
static void gw16012_path_move(struct pathmove_command *cmd)
static void gw16012_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size)
static void gw16012_state_move(void)
static uint8_t gw16012_control_value
bool tap_is_state_stable(tap_state_t astate)
Function tap_is_state_stable returns true if the astate is stable.
tap_state_t tap_state_transition(tap_state_t cur_state, bool tms)
Function tap_state_transition takes a current TAP state and returns the next state according to the t...
const char * tap_state_name(tap_state_t state)
Function tap_state_name Returns a string suitable for display representing the JTAG tap_state.
void tap_set_end_state(tap_state_t new_end_state)
This function sets the state of an "end state follower" which tracks the state that any cable driver ...
tap_state_t tap_get_end_state(void)
For more information,.
int tap_get_tms_path(tap_state_t from, tap_state_t to)
This function provides a "bit sequence" indicating what has to be done with TMS during a sequence of ...
int tap_get_tms_path_len(tap_state_t from, tap_state_t to)
Function int tap_get_tms_path_len returns the total number of bits that represents a TMS path transit...
tap_state_t tap_get_state(void)
This function gets the state of the "state follower" which tracks the state of the TAPs connected to ...
#define tap_set_state(new_state)
This function sets the state of a "state follower" which tracks the state of the TAPs connected to th...
void jtag_sleep(uint32_t us)
#define ERROR_JTAG_QUEUE_FAILED
#define ERROR_JTAG_INIT_FAILED
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
#define LOG_DEBUG_IO(expr ...)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_DEBUG(expr ...)
Represents a driver for a debugging interface.
const char *const name
The name of the interface driver.
Represents a driver for a debugging interface.
int(* execute_queue)(struct jtag_command *cmd_queue)
Execute commands in the supplied queue.