63c9cf8947b58cd219a5f9885948c3b9fe418b06
12 #include <sys/select.h>
14 /* reads from a socket if it is ready (a single byte) and returns 1 if success
16 int read_handler(int fdread
, char *buffer
)
22 FD_SET(fdread
, &read_fds
);
28 status
= select(fdread
+1, &read_fds
, NULL
, NULL
, &tv
);
32 exit(status
); // error
35 return 0; // timeout (nothing read)
37 return read(fdread
, buffer
, 1);
42 static void event_handler(int fd, short event, void *arg)
45 read_handler(fd, event, arg);
48 static void accept_conn_cb(struct evconnlistener *listener, evutil_socket_t fd, struct sockaddr *address, int socklen, void *ctx)
50 struct session_s *s = (struct session_s*)ctx;
51 struct timeval tv = {1, 0};
54 s->ev = event_new(base, fd, EV_READ | EV_PERSIST , event_handler, s);
55 event_add(s->ev, &tv);
58 static int jtagremote_new(void **sess, char *args)
61 struct session_s *s = NULL;
64 struct evconnlistener *listener;
65 struct sockaddr_in sin;
72 ret = litex_sim_module_get_args(args, "port", &cport);
76 printf("Found port %s\n", cport);
77 sscanf(cport, "%d", &port);
81 fprintf(stderr, "Invalid port selected!\n");
85 s=(struct session_s*)malloc(sizeof(struct session_s));
90 memset(s, 0, sizeof(struct session_s));
92 memset(&sin, 0, sizeof(sin));
93 sin.sin_family = AF_INET;
94 sin.sin_addr.s_addr = htonl(0);
95 sin.sin_port = htons(port);
96 listener = evconnlistener_new_bind(base, accept_conn_cb, s, LEV_OPT_CLOSE_ON_FREE|LEV_OPT_REUSEABLE, -1, (struct sockaddr*)&sin, sizeof(sin));
99 eprintf("Can't bind port %d\n!\n", port);
102 evconnlistener_set_error_cb(listener, accept_error_cb);
111 c = s->databuf[s->data_start];
113 if((c >= '0') && (c <= '7')){
114 *s->tck = ((c - '0') >> 2) & 1;
115 *s->tms = ((c - '0') >> 1) & 1;
116 *s->tdi = (c - '0') & 1;
120 if(-1 == write(s->fd, &val, 1)) {
121 eprintf("Error writing on socket\n");
126 s->data_start = (s->data_start + 1) % 2048;
138 cxxrtl_design::p_add top
;
143 for(int cycle
=0;cycle
<1000;++cycle
){
145 top
.p_clk
.set
<bool>(false);
147 top
.p_clk
.set
<bool>(true);
150 // check that the output is correct
152 top.p_a.set<uint8_t>(5);
153 top.p_b.set<uint8_t>(3);
154 uint32_t f = top.p_f.get<uint32_t>();
156 cout << "f " << f << endl;