17 #include <netinet/tcp.h>
107 unsigned int contiguous_available_space =
111 contiguous_available_space);
112 if (first && block ==
BLOCK)
118 }
else if (
count == 0) {
122 if (first && block ==
BLOCK) {
123 LOG_ERROR(
"remote_bitbang: socket closed by remote");
127 }
else if (
count < 0) {
129 if (WSAGetLastError() == WSAEWOULDBLOCK) {
131 if (errno == EAGAIN) {
172 LOG_INFO(
"remote_bitbang interface quit");
185 LOG_ERROR(
"remote_bitbang: invalid read response: %c(%i)", c, c);
213 char c =
'0' + ((tck ? 0x4 : 0x0) | (tms ? 0x2 : 0x0) | (tdi ? 0x1 : 0x0));
219 char c =
'r' + ((trst ? 0x2 : 0x0) | (srst ? 0x1 : 0x0));
233 unsigned int ms = microseconds / 1000;
234 unsigned int us = microseconds % 1000;
236 for (
unsigned int i = 0; i < ms; i++) {
242 for (
unsigned int i = 0; i < us; i++) {
253 char c = on ?
'B' :
'b';
259 char c = is_output ?
'O' :
'o';
261 LOG_ERROR(
"Error setting direction for swdio");
274 char c =
'd' + ((swclk ? 0x2 : 0x0) | (swdio ? 0x1 : 0x0));
293 struct addrinfo hints = { .ai_family = AF_UNSPEC, .ai_socktype = SOCK_STREAM };
294 struct addrinfo *result, *rp;
304 LOG_ERROR(
"getaddrinfo: %s\n", gai_strerror(s));
313 for (rp = result; rp ; rp = rp->ai_next) {
314 fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
318 if (connect(fd, rp->ai_addr, rp->ai_addrlen) != -1)
329 setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (
const char *)&one,
sizeof(one));
331 freeaddrinfo(result);
349 int fd = socket(PF_UNIX, SOCK_STREAM, 0);
355 struct sockaddr_un
addr;
356 addr.sun_family = AF_UNIX;
358 addr.sun_path[
sizeof(
addr.sun_path)-1] =
'\0';
360 if (connect(fd, (
struct sockaddr *)&
addr,
sizeof(
struct sockaddr_un)) < 0) {
375 LOG_INFO(
"Initializing remote_bitbang driver");
386 LOG_INFO(
"remote_bitbang driver initialized");
425 .handler = remote_bitbang_handle_remote_bitbang_port_command,
427 .help =
"Set the port to use to connect to the remote jtag.\n"
428 " if 0 or unset, use unix sockets to connect to the remote jtag.",
429 .usage =
"port_number",
433 .handler = remote_bitbang_handle_remote_bitbang_host_command,
435 .help =
"Set the host to use to connect to the remote jtag.\n"
436 " if port is 0 or unset, this is the name of the unix socket to use.",
437 .usage =
"host_name",
440 .name =
"use_remote_sleep",
441 .handler = remote_bitbang_handle_remote_bitbang_use_remote_sleep_command,
443 .help =
"Rather than executing sleep locally, include delays in the "
444 "instruction stream for the remote host.",
452 .
name =
"remote_bitbang",
454 .help =
"perform remote_bitbang management",
481 .
name =
"remote_bitbang",
int bitbang_execute_queue(struct jtag_command *cmd_queue)
const struct swd_driver bitbang_swd
#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 COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
void jtag_sleep(uint32_t us)
void log_socket_error(const char *socket_desc)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
static int remote_bitbang_swdio_read(void)
static char remote_bitbang_recv_buf[256]
static int remote_bitbang_init_tcp(void)
static int remote_bitbang_sample(void)
static const struct command_registration remote_bitbang_subcommand_handlers[]
static bool remote_bitbang_recv_buf_empty(void)
static int remote_bitbang_execute_queue(struct jtag_command *cmd_queue)
static int remote_bitbang_swd_write(int swclk, int swdio)
static unsigned int remote_bitbang_recv_buf_contiguous_available_space(void)
static uint8_t remote_bitbang_send_buf[512]
static int remote_bitbang_fill_buf(enum block_bool block)
static int remote_bitbang_init(void)
static struct jtag_interface remote_bitbang_interface
static int remote_bitbang_blink(bool on)
static enum bb_value char_to_int(int c)
static void remote_bitbang_swdio_drive(bool is_output)
static int remote_bitbang_queue(int c, enum flush_bool flush)
static unsigned int remote_bitbang_recv_buf_end
static bool remote_bitbang_recv_buf_full(void)
static int remote_bitbang_sleep(unsigned int microseconds)
static int remote_bitbang_init_unix(void)
static int remote_bitbang_reset(int trst, int srst)
static const struct command_registration remote_bitbang_command_handlers[]
static unsigned int remote_bitbang_recv_buf_start
static int remote_bitbang_quit(void)
static int remote_bitbang_write(int tck, int tms, int tdi)
static bool use_remote_sleep
COMMAND_HANDLER(remote_bitbang_handle_remote_bitbang_port_command)
static int remote_bitbang_flush(void)
static const struct bitbang_interface remote_bitbang_bitbang
static char * remote_bitbang_port
static int remote_bitbang_fd
static unsigned int remote_bitbang_send_buf_used
static enum bb_value remote_bitbang_read_sample(void)
static char * remote_bitbang_host
struct adapter_driver remote_bitbang_adapter_driver
static void socket_block(int fd)
static int read_socket(int handle, void *buffer, unsigned int count)
static int close_socket(int sock)
static int write_socket(int handle, const void *buffer, unsigned int count)
static void socket_nonblock(int fd)
target_addr_t addr
Start address to search for the control block.
Represents a driver for a debugging interface.
const char *const name
The name of the interface driver.
Low level callbacks (for bitbang).
int(* sleep)(unsigned int microseconds)
Sleep for some number of microseconds.
int(* swdio_read)(void)
Sample SWDIO and return the value.
int(* swd_write)(int swclk, int swdio)
Set SWCLK and SWDIO to the given value.
int(* sample)(void)
Sample TDO and put the result in a buffer.
enum bb_value(* read_sample)(void)
Return the next unread value from the buffer.
int(* flush)(void)
Force a flush.
int(* write)(int tck, int tms, int tdi)
Set TCK, TMS, and TDI to the given values.
void(* swdio_drive)(bool on)
Set direction of SWDIO.
int(* blink)(bool on)
Blink led (optional).
size_t buf_size
The number of TDO samples that can be buffered up before the caller has to call read_sample.
const char * usage
a string listing the options and arguments, required or optional
Represents a driver for a debugging interface.
int(* execute_queue)(struct jtag_command *cmd_queue)
Execute commands in the supplied queue.
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.