22 #ifdef HAVE_ARPA_INET_H
23 #include <arpa/inet.h>
27 #include <netinet/tcp.h>
30 #define SERVER_ADDRESS "127.0.0.1"
31 #define SERVER_PORT 5555
44 LOG_ERROR(
"%s: NULL 'buf' argument, file %s, line %d",
45 __func__, __FILE__, __LINE__);
48 if (write(
sockfd, buf, len) != (ssize_t)len) {
49 LOG_ERROR(
"%s: %s, file %s, line %d", __func__,
50 strerror(errno), __FILE__, __LINE__);
59 LOG_ERROR(
"%s: NULL 'buf' argument, file %s, line %d",
60 __func__, __FILE__, __LINE__);
63 if (read(
sockfd, buf, len) != (ssize_t)len) {
64 LOG_ERROR(
"%s: %s, file %s, line %d", __func__,
65 strerror(errno), __FILE__, __LINE__);
78 char *buf =
"reset\n";
81 LOG_DEBUG_IO(
"JTAG DRIVER DEBUG: reset trst: %i srst %i", trst, srst);
87 LOG_ERROR(
"write_sock() fail, file %s, line %d",
118 LOG_ERROR(
"jtag_build_buffer call failed, data_buf == NULL, "
119 "file %s, line %d", __FILE__, __LINE__);
126 last_ir_buf = (uint8_t *)malloc(bytes *
sizeof(uint8_t));
128 LOG_ERROR(
"%s: malloc fail, file %s, line %d",
129 __func__, __FILE__, __LINE__);
136 snprintf(buf,
sizeof(buf),
"%s %d\n",
cmd->ir_scan ?
"ib" :
"db", num_bits);
139 LOG_ERROR(
"write_sock() fail, file %s, line %d",
145 LOG_ERROR(
"write_sock() fail, file %s, line %d",
149 ret =
read_sock((
char *)data_buf, bytes);
151 LOG_ERROR(
"read_sock() fail, file %s, line %d",
158 LOG_ERROR(
"jtag_read_buffer() fail, file %s, line %d",
176 LOG_ERROR(
"%s: NULL 'data_buf' argument, file %s, line %d",
177 __func__, __FILE__, __LINE__);
181 LOG_ERROR(
"%s: 'num_bits' invalid value, file %s, line %d",
182 __func__, __FILE__, __LINE__);
187 read_scan = (uint8_t *)malloc(bytes *
sizeof(uint8_t));
189 LOG_ERROR(
"%s: malloc fail, file %s, line %d",
190 __func__, __FILE__, __LINE__);
193 snprintf(buf,
sizeof(buf),
"ib %d\n", num_bits);
194 for (
unsigned int cycle = 0; cycle < num_cycles; cycle += num_bits + 6) {
197 LOG_ERROR(
"write_sock() fail, file %s, line %d",
203 LOG_ERROR(
"write_sock() fail, file %s, line %d",
207 ret =
read_sock((
char *)read_scan, bytes);
209 LOG_ERROR(
"read_sock() fail, file %s, line %d",
257 LOG_ERROR(
"BUG: unknown JTAG command type 0x%X",
272 LOG_ERROR(
"%s: strdup fail, file %s, line %d",
273 __func__, __FILE__, __LINE__);
278 const struct addrinfo hints = {
279 .ai_family = AF_UNSPEC,
280 .ai_socktype = SOCK_STREAM
283 char port_str[5 + 1];
284 snprintf(port_str,
sizeof(port_str),
"%" PRIu16,
server_port);
286 struct addrinfo *result;
290 LOG_ERROR(
"getaddrinfo: %s", gai_strerror(ret));
295 for (rp = result; rp ; rp = rp->ai_next) {
296 sockfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
300 if (connect(
sockfd, rp->ai_addr, rp->ai_addrlen) != -1)
309 freeaddrinfo(result);
313 bool is_loopback =
false;
314 if (rp->ai_family == AF_INET) {
315 struct sockaddr_in sa;
316 memcpy(&sa, rp->ai_addr,
sizeof(sa));
317 is_loopback = (sa.sin_addr.s_addr == htonl(INADDR_LOOPBACK));
318 }
else if (rp->ai_family == AF_INET6) {
319 struct sockaddr_in6 sa;
320 memcpy(&sa, rp->ai_addr,
sizeof(sa));
321 is_loopback = IN6_IS_ADDR_LOOPBACK(&sa.sin6_addr);
325 LOG_DEBUG(
"Enabling TCP_NODELAY to enhance the speed of local connections");
331 setsockopt(
sockfd, IPPROTO_TCP, TCP_NODELAY, (
char *)&
flag,
335 freeaddrinfo(result);
372 LOG_ERROR(
"%s: strdup fail, file %s, line %d",
373 __func__, __FILE__, __LINE__);
382 LOG_ERROR(
"%s: strdup fail, file %s, line %d",
383 __func__, __FILE__, __LINE__);
395 .handler = &jtag_dpi_set_port,
397 .help =
"set the port of the DPI server",
401 .name =
"set_address",
402 .handler = &jtag_dpi_set_address,
404 .help =
"set the hostname or IP address of the DPI server",
405 .usage =
"[address]",
414 .help =
"perform jtag_dpi management",
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#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.
int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer)
int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd)
#define DEBUG_CAP_TMS_SEQ
void jtag_sleep(uint32_t us)
static struct jtag_interface jtag_dpi_interface
static int jtag_dpi_runtest(unsigned int num_cycles)
static int jtag_dpi_reset(int trst, int srst)
jtag_dpi_reset - ask to reset the JTAG device
static int last_ir_num_bits
static const struct command_registration jtag_dpi_command_handlers[]
static int jtag_dpi_stableclocks(unsigned int num_cycles)
static int jtag_dpi_execute_queue(struct jtag_command *cmd_queue)
static const struct command_registration jtag_dpi_subcommand_handlers[]
static uint8_t * last_ir_buf
static int write_sock(char *buf, size_t len)
static uint16_t server_port
COMMAND_HANDLER(jtag_dpi_set_port)
static int read_sock(char *buf, size_t len)
static int jtag_dpi_quit(void)
static int jtag_dpi_scan(struct scan_command *cmd)
jtag_dpi_scan - launches a DR-scan or IR-scan
static int jtag_dpi_init(void)
static char * server_address
struct adapter_driver jtag_dpi_adapter_driver
#define LOG_DEBUG_IO(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
Represents a driver for a debugging interface.
const char *const name
The name of the interface driver.
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.
The scan_command provide a means of encapsulating a set of scan_field structures that should be scann...
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.