1 /***************************************************************************
2 * Copyright (C) 2005 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
5 * Copyright (C) 2008 by Spencer Oliver *
6 * spen@spen-soft.co.uk *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22 ***************************************************************************/
30 /* -ino: 060521-1036 */
31 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
32 #include <machine/sysarch.h>
33 #include <machine/cpufunc.h>
34 #define ioperm(startport,length,enable)\
35 i386_set_ioperm((startport), (length), (enable))
36 #endif /* __FreeBSD__ */
38 #if PARPORT_USE_PPDEV == 1
39 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
40 #include <dev/ppbus/ppi.h>
41 #include <dev/ppbus/ppbconf.h>
42 #define PPRSTATUS PPIGSTATUS
43 #define PPWDATA PPISDATA
45 #include <linux/parport.h>
46 #include <linux/ppdev.h>
48 #include <sys/ioctl.h>
49 #else /* not PARPORT_USE_PPDEV */
55 #if PARPORT_USE_GIVEIO == 1 && IS_CYGWIN == 1
60 /* parallel port cable description
62 typedef struct cable_s
65 u8 TDO_MASK
; /* status port bit containing current TDO value */
66 u8 TRST_MASK
; /* data port bit for TRST */
67 u8 TMS_MASK
; /* data port bit for TMS */
68 u8 TCK_MASK
; /* data port bit for TCK */
69 u8 TDI_MASK
; /* data port bit for TDI */
70 u8 SRST_MASK
; /* data port bit for SRST */
71 u8 OUTPUT_INVERT
; /* data port bits that should be inverted */
72 u8 INPUT_INVERT
; /* status port that should be inverted */
73 u8 PORT_INIT
; /* initialize data port with this value */
74 u8 PORT_EXIT
; /* de-initialize data port with this value */
75 u8 LED_MASK
; /* data port bit for LED */
78 static cable_t cables
[] =
80 /* name tdo trst tms tck tdi srst o_inv i_inv init exit led */
81 { "wiggler", 0x80, 0x10, 0x02, 0x04, 0x08, 0x01, 0x01, 0x80, 0x80, 0x80, 0x00 },
82 { "wiggler2", 0x80, 0x10, 0x02, 0x04, 0x08, 0x01, 0x01, 0x80, 0x80, 0x00, 0x20 },
83 { "wiggler_ntrst_inverted",
84 0x80, 0x10, 0x02, 0x04, 0x08, 0x01, 0x11, 0x80, 0x80, 0x80, 0x00 },
85 { "old_amt_wiggler", 0x80, 0x01, 0x02, 0x04, 0x08, 0x10, 0x11, 0x80, 0x80, 0x80, 0x00 },
86 { "arm-jtag", 0x80, 0x01, 0x02, 0x04, 0x08, 0x10, 0x01, 0x80, 0x80, 0x80, 0x00 },
87 { "chameleon", 0x80, 0x00, 0x04, 0x01, 0x02, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00 },
88 { "dlc5", 0x10, 0x00, 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00 },
89 { "triton", 0x80, 0x08, 0x04, 0x01, 0x02, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00 },
90 { "lattice", 0x40, 0x10, 0x04, 0x02, 0x01, 0x08, 0x00, 0x00, 0x18, 0x18, 0x00 },
91 { "flashlink", 0x20, 0x10, 0x02, 0x01, 0x04, 0x20, 0x30, 0x20, 0x00, 0x00, 0x00 },
92 /* Altium Universal JTAG cable. Set the cable to Xilinx Mode and wire to target as follows:
97 SOFT TCK - Target TRST
98 SOFT TDI - Target SRST
100 { "altium", 0x10, 0x20, 0x04, 0x02, 0x01, 0x80, 0x00, 0x00, 0x10, 0x00, 0x08 },
101 { NULL
, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
105 static char* parport_cable
= NULL
;
106 static u16 parport_port
;
107 static int parport_exit
= 0;
109 /* interface variables
111 static cable_t
* cable
;
112 static u8 dataport_value
= 0x0;
114 #if PARPORT_USE_PPDEV == 1
115 static int device_handle
;
117 static unsigned long dataport
;
118 static unsigned long statusport
;
121 /* low level command set
123 static int parport_read(void);
124 static void parport_write(int tck
, int tms
, int tdi
);
125 static void parport_reset(int trst
, int srst
);
126 static void parport_led(int on
);
128 static int parport_speed(int speed
);
129 static int parport_register_commands(struct command_context_s
*cmd_ctx
);
130 static int parport_init(void);
131 static int parport_quit(void);
133 /* interface commands */
134 static int parport_handle_parport_port_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
135 static int parport_handle_parport_cable_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
136 static int parport_handle_write_on_exit_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
138 jtag_interface_t parport_interface
=
142 .execute_queue
= bitbang_execute_queue
,
144 .speed
= parport_speed
,
145 .register_commands
= parport_register_commands
,
146 .init
= parport_init
,
147 .quit
= parport_quit
,
150 static bitbang_interface_t parport_bitbang
=
152 .read
= parport_read
,
153 .write
= parport_write
,
154 .reset
= parport_reset
,
158 static int parport_read(void)
162 #if PARPORT_USE_PPDEV == 1
163 ioctl(device_handle
, PPRSTATUS
, & data
);
165 data
= inb(statusport
);
168 if ((data
^ cable
->INPUT_INVERT
) & cable
->TDO_MASK
)
174 static __inline__
void parport_write_data(void)
177 output
= dataport_value
^ cable
->OUTPUT_INVERT
;
179 #if PARPORT_USE_PPDEV == 1
180 ioctl(device_handle
, PPWDATA
, &output
);
182 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
183 outb(dataport
, output
);
185 outb(output
, dataport
);
190 static void parport_write(int tck
, int tms
, int tdi
)
192 int i
= jtag_speed
+ 1;
195 dataport_value
|= cable
->TCK_MASK
;
197 dataport_value
&= ~cable
->TCK_MASK
;
200 dataport_value
|= cable
->TMS_MASK
;
202 dataport_value
&= ~cable
->TMS_MASK
;
205 dataport_value
|= cable
->TDI_MASK
;
207 dataport_value
&= ~cable
->TDI_MASK
;
210 parport_write_data();
213 /* (1) assert or (0) deassert reset lines */
214 static void parport_reset(int trst
, int srst
)
216 LOG_DEBUG("trst: %i, srst: %i", trst
, srst
);
219 dataport_value
|= cable
->TRST_MASK
;
221 dataport_value
&= ~cable
->TRST_MASK
;
224 dataport_value
|= cable
->SRST_MASK
;
226 dataport_value
&= ~cable
->SRST_MASK
;
228 parport_write_data();
231 /* turn LED on parport adapter on (1) or off (0) */
232 static void parport_led(int on
)
235 dataport_value
|= cable
->LED_MASK
;
237 dataport_value
&= ~cable
->LED_MASK
;
239 parport_write_data();
242 static int parport_speed(int speed
)
247 static int parport_register_commands(struct command_context_s
*cmd_ctx
)
249 register_command(cmd_ctx
, NULL
, "parport_port", parport_handle_parport_port_command
,
250 COMMAND_CONFIG
, "either the address of the I/O port or the number of the \91/dev/parport\92 device");
251 register_command(cmd_ctx
, NULL
, "parport_cable", parport_handle_parport_cable_command
,
252 COMMAND_CONFIG
, "the layout of the parallel port cable used to connect to the target");
253 register_command(cmd_ctx
, NULL
, "parport_write_on_exit", parport_handle_write_on_exit_command
,
254 COMMAND_CONFIG
, "configure the parallel driver to write a known value to the parallel interface");
259 #if PARPORT_USE_GIVEIO == 1
260 static int parport_get_giveio_access(void)
263 OSVERSIONINFO version
;
265 version
.dwOSVersionInfoSize
= sizeof version
;
266 if (!GetVersionEx( &version
)) {
270 if (version
.dwPlatformId
!= VER_PLATFORM_WIN32_NT
)
273 h
= CreateFile( "\\\\.\\giveio", GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
274 if (h
== INVALID_HANDLE_VALUE
) {
285 static int parport_init(void)
288 #if PARPORT_USE_PPDEV == 1
295 if ((parport_cable
== NULL
) || (parport_cable
[0] == 0))
297 parport_cable
= "wiggler";
298 LOG_WARNING("No parport cable specified, using default 'wiggler'");
301 while (cur_cable
->name
)
303 if (strcmp(cur_cable
->name
, parport_cable
) == 0)
313 LOG_ERROR("No matching cable found for %s", parport_cable
);
314 return ERROR_JTAG_INIT_FAILED
;
317 dataport_value
= cable
->PORT_INIT
;
319 #if PARPORT_USE_PPDEV == 1
320 if (device_handle
> 0)
322 LOG_ERROR("device is already opened");
323 return ERROR_JTAG_INIT_FAILED
;
326 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
327 LOG_DEBUG("opening /dev/ppi%d...", parport_port
);
329 snprintf(buffer
, 256, "/dev/ppi%d", parport_port
);
330 device_handle
= open(buffer
, O_WRONLY
);
331 #else /* not __FreeBSD__, __FreeBSD_kernel__ */
332 LOG_DEBUG("opening /dev/parport%d...", parport_port
);
334 snprintf(buffer
, 256, "/dev/parport%d", parport_port
);
335 device_handle
= open(buffer
, O_WRONLY
);
336 #endif /* __FreeBSD__, __FreeBSD_kernel__ */
338 if (device_handle
< 0)
340 LOG_ERROR("cannot open device. check it exists and that user read and write rights are set");
341 return ERROR_JTAG_INIT_FAILED
;
344 LOG_DEBUG("...open");
346 #if !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__)
347 i
=ioctl(device_handle
, PPCLAIM
);
350 LOG_ERROR("cannot claim device");
351 return ERROR_JTAG_INIT_FAILED
;
354 i
= PARPORT_MODE_COMPAT
;
355 i
= ioctl(device_handle
, PPSETMODE
, & i
);
358 LOG_ERROR(" cannot set compatible mode to device");
359 return ERROR_JTAG_INIT_FAILED
;
362 i
= IEEE1284_MODE_COMPAT
;
363 i
= ioctl(device_handle
, PPNEGOT
, & i
);
366 LOG_ERROR("cannot set compatible 1284 mode to device");
367 return ERROR_JTAG_INIT_FAILED
;
369 #endif /* not __FreeBSD__, __FreeBSD_kernel__ */
371 #else /* not PARPORT_USE_PPDEV */
372 if (parport_port
== 0)
374 parport_port
= 0x378;
375 LOG_WARNING("No parport port specified, using default '0x378' (LPT1)");
378 dataport
= parport_port
;
379 statusport
= parport_port
+ 1;
381 LOG_DEBUG("requesting privileges for parallel port 0x%lx...", dataport
);
382 #if PARPORT_USE_GIVEIO == 1
383 if (parport_get_giveio_access() != 0)
384 #else /* PARPORT_USE_GIVEIO */
385 if (ioperm(dataport
, 3, 1) != 0)
386 #endif /* PARPORT_USE_GIVEIO */
388 LOG_ERROR("missing privileges for direct i/o");
389 return ERROR_JTAG_INIT_FAILED
;
391 LOG_DEBUG("...privileges granted");
393 /* make sure parallel port is in right mode (clear tristate and interrupt */
394 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
395 outb(parport_port
+ 2, 0x0);
397 outb(0x0, parport_port
+ 2);
400 #endif /* PARPORT_USE_PPDEV */
403 parport_write(0, 0, 0);
406 bitbang_interface
= &parport_bitbang
;
411 static int parport_quit(void)
417 dataport_value
= cable
->PORT_EXIT
;
418 parport_write_data();
424 parport_cable
= NULL
;
430 static int parport_handle_parport_port_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
435 /* only if the port wasn't overwritten by cmdline */
436 if (parport_port
== 0)
437 parport_port
= strtoul(args
[0], NULL
, 0);
442 static int parport_handle_parport_cable_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
447 /* only if the cable name wasn't overwritten by cmdline */
448 if (parport_cable
== 0)
450 parport_cable
= malloc(strlen(args
[0]) + sizeof(char));
451 strcpy(parport_cable
, args
[0]);
457 static int parport_handle_write_on_exit_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
461 command_print(cmd_ctx
, "usage: parport_write_on_exit <on|off>");
465 if (strcmp(args
[0], "on") == 0)
467 else if (strcmp(args
[0], "off") == 0)
Linking to existing account procedure
If you already have an account and want to add another login method
you
MUST first sign in with your existing account and
then change URL to read
https://review.openocd.org/login/?link
to get to this page again but this time it'll work for linking. Thank you.
SSH host keys fingerprints
1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=.. |
|+o.. . |
|*.o . . |
|+B . . . |
|Bo. = o S |
|Oo.+ + = |
|oB=.* = . o |
| =+=.+ + E |
|. .=o . o |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)