20 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
21 #include <machine/sysarch.h>
22 #include <machine/cpufunc.h>
23 #define ioperm(startport, length, enable) \
24 i386_set_ioperm((startport), (length), (enable))
27 #if PARPORT_USE_PPDEV == 1
28 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
29 #include <dev/ppbus/ppi.h>
30 #include <dev/ppbus/ppbconf.h>
31 #define PPRSTATUS PPIGSTATUS
32 #define PPWDATA PPISDATA
34 #include <linux/parport.h>
35 #include <linux/ppdev.h>
37 #include <sys/ioctl.h>
44 #if PARPORT_USE_GIVEIO == 1 && IS_CYGWIN == 1
58 #if PARPORT_USE_PPDEV == 1
59 static int device_handle;
77 #define OUTPUT_BITMASK(gpio_index) BIT((adapter_gpio_config[(gpio_index)].gpio_num - 2))
83 #if PARPORT_USE_PPDEV == 1
84 ioctl(device_handle, PPRSTATUS, &data);
99 #if PARPORT_USE_PPDEV == 1
100 ioctl(device_handle, PPWDATA, &
output);
102 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
139 LOG_DEBUG(
"trst: %i, srst: %i", trst, srst);
172 LOG_ERROR(
"RCLK is not supported by the adapter");
185 *khz = (499999 + denominator) / denominator;
190 #if PARPORT_USE_GIVEIO == 1
191 static bool parport_get_giveio_access(
void)
193 OSVERSIONINFO version;
195 version.dwOSVersionInfoSize =
sizeof(version);
196 if (!GetVersionEx(&version)) {
201 if (version.dwPlatformId != VER_PLATFORM_WIN32_NT)
204 HANDLE h = CreateFile(
"\\\\.\\giveio", GENERIC_READ, 0,
NULL, OPEN_EXISTING,
205 FILE_ATTRIBUTE_NORMAL,
NULL);
207 if (h == INVALID_HANDLE_VALUE) {
224 static const struct {
249 LOG_ERROR(
"The signal '%s' is required and must be configured",
259 LOG_ERROR(
"The '%s' signal pin must be 10, 11, 12, 13, or 15",
265 LOG_ERROR(
"The '%s' signal pin must be 2, 3, 4, 5, 6, 7, 8, or 9",
292 #if PARPORT_USE_PPDEV == 1
293 if (device_handle > 0) {
294 LOG_ERROR(
"Parallel port is already open");
298 char device_path[256];
300 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
301 snprintf(device_path,
sizeof(device_path),
"/dev/ppi%d",
parport_port);
303 snprintf(device_path,
sizeof(device_path),
"/dev/parport%d",
parport_port);
306 LOG_DEBUG(
"Using parallel port %s", device_path);
308 device_handle = open(device_path, O_WRONLY);
310 if (device_handle < 0) {
312 LOG_ERROR(
"Failed to open parallel port %s (errno = %d)", device_path,
314 LOG_ERROR(
"Check whether the device exists and if you have the required access rights");
318 #if !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__)
319 int retval = ioctl(device_handle, PPCLAIM);
322 LOG_ERROR(
"Failed to claim parallel port %s", device_path);
326 int value = PARPORT_MODE_COMPAT;
327 retval = ioctl(device_handle, PPSETMODE, &value);
330 LOG_ERROR(
"Cannot set compatible mode to device");
334 value = IEEE1284_MODE_COMPAT;
335 retval = ioctl(device_handle, PPNEGOT, &value);
338 LOG_ERROR(
"Cannot set compatible 1284 mode to device");
346 LOG_WARNING(
"No parallel port specified, using default 0x378 (LPT1)");
354 #if PARPORT_USE_GIVEIO == 1
355 if (!parport_get_giveio_access()) {
359 LOG_ERROR(
"Missing privileges for direct I/O");
364 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
448 LOG_WARNING(
"DEPRECATED: 'parport write_on_exit' will be removed in the future, use the 'adapter gpio' command to configure the exit state for pins");
460 uint32_t toggling_time;
464 if (!toggling_time) {
478 LOG_INFO(
"No parallel port speed set, using zero wait states");
488 .handler = parport_handle_port_command,
490 .help =
"Configure the address of the I/O port (e.g. 0x378) "
491 "or the number of the '/dev/parport' (Linux) or '/dev/ppi' (FreeBSD) device used",
492 .usage =
"port_number",
496 .handler = parport_handle_cable_command,
498 .help =
"Set the layout of the parallel port cable "
499 "used to connect to the target",
503 .name =
"write_on_exit",
504 .handler = parport_handle_write_on_exit_command,
506 .help =
"Configure the driver to write a value to the parallel port on shutdown",
507 .usage =
"('on'|'off')",
510 .name =
"toggling_time",
511 .handler = parport_handle_toggling_time_command,
513 .help =
"Configure how many nanoseconds it takes for the hardware to toggle TCK",
523 .help =
"perform parport management",
const struct adapter_gpio_config * adapter_gpio_get_config(void)
Retrieves gpio configuration set with command "adapter gpio <signal_name>".
int adapter_get_speed(int *speed)
const char * adapter_gpio_get_name(enum adapter_gpio_config_index idx)
Retrieves gpio name.
@ ADAPTER_GPIO_INIT_STATE_ACTIVE
@ ADAPTER_GPIO_INIT_STATE_INACTIVE
@ ADAPTER_GPIO_EXIT_STATE_ACTIVE
@ ADAPTER_GPIO_EXIT_STATE_INACTIVE
adapter_gpio_config_index
Adapter GPIO.
#define ADAPTER_GPIO_NOT_SET
int bitbang_execute_queue(struct jtag_command *cmd_queue)
void command_print(struct command_invocation *cmd, const char *format,...)
int command_run_linef(struct command_context *context, 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 COMMAND_PARSE_ON_OFF(in, out)
parses an on/off command argument
#define ERROR_COMMAND_SYNTAX_ERROR
#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 CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
#define ERROR_COMMAND_ARGUMENT_INVALID
#define DEBUG_CAP_TMS_SEQ
#define ERROR_JTAG_INIT_FAILED
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
static int parport_reset(int trst, int srst)
static int parport_speed(int speed)
static const struct command_registration parport_command_handlers[]
static uint32_t parport_toggling_time_ns
static int parport_write(int tck, int tms, int tdi)
#define OUTPUT_BITMASK(gpio_index)
static void set_pin_state(enum adapter_gpio_config_index gpio_index, bool state)
static unsigned long dataport
static uint16_t parport_port
static const struct bitbang_interface parport_bitbang
static int parport_quit(void)
static bool parport_write_exit_state
static void parport_write_data(void)
static struct jtag_interface parport_interface
static int parport_speed_div(int speed, int *khz)
enum adapter_gpio_config_index gpio_index
static const struct adapter_gpio_config * adapter_gpio_config
static const struct command_registration parport_subcommand_handlers[]
static unsigned long statusport
static bool is_gpio_configured(enum adapter_gpio_config_index gpio_index)
static int parport_khz(int khz, int *jtag_speed)
static struct @31 input_pin_bitmask_map[]
static uint8_t dataport_value
static const struct @32 all_signals[]
static int parport_init(void)
static enum bb_value parport_read(void)
COMMAND_HANDLER(parport_handle_port_command)
struct adapter_driver parport_adapter_driver
static int parport_led(bool on)
Represents a driver for a debugging interface.
const char *const name
The name of the interface driver.
Configuration options for a single GPIO.
enum adapter_gpio_exit_state exit_state
enum adapter_gpio_init_state init_state
Low level callbacks (for bitbang).
enum bb_value(* read)(void)
Sample TDO and return the value.
const char * usage
a string listing the options and arguments, required or optional
Represents a driver for a debugging interface.
unsigned int supported
Bit vector listing capabilities exposed by this driver.
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.