From 1feb11642ab3f8d1cdc350ff3027bacf9434a4d7 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Thu, 8 Apr 2021 14:11:50 +0100 Subject: [PATCH] remove cruft, add comments --- small_jtag_test/main.cpp | 76 +++++----------------------------------- 1 file changed, 8 insertions(+), 68 deletions(-) diff --git a/small_jtag_test/main.cpp b/small_jtag_test/main.cpp index 5931804..e153d76 100644 --- a/small_jtag_test/main.cpp +++ b/small_jtag_test/main.cpp @@ -3,7 +3,7 @@ #include #include #include -#include /* See NOTES */ +#include #include #include #include @@ -68,77 +68,17 @@ int get_connection() connfd = accept(listenfd, (struct sockaddr*)NULL, NULL); close(listenfd); - setsockopt(connfd, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int)); + setsockopt(connfd, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int)); return connfd; } -/* - -static void accept_conn_cb(struct evconnlistener *listener, evutil_socket_t fd, struct sockaddr *address, int socklen, void *ctx) -{ - struct session_s *s = (struct session_s*)ctx; - struct timeval tv = {1, 0}; - - s->fd = fd; - s->ev = event_new(base, fd, EV_READ | EV_PERSIST , event_handler, s); - event_add(s->ev, &tv); -} - -static int jtagremote_new(void **sess, char *args) -{ - int ret = RC_OK; - struct session_s *s = NULL; - char *cport = NULL; - int port; - struct evconnlistener *listener; - struct sockaddr_in sin; - - if(!sess) { - ret = RC_INVARG; - goto out; - } - - ret = litex_sim_module_get_args(args, "port", &cport); - if(RC_OK != ret) - goto out; - - printf("Found port %s\n", cport); - sscanf(cport, "%d", &port); - free(cport); - if(!port) { - ret = RC_ERROR; - fprintf(stderr, "Invalid port selected!\n"); - goto out; - } - - s=(struct session_s*)malloc(sizeof(struct session_s)); - if(!s) { - ret = RC_NOENMEM; - goto out; - } - memset(s, 0, sizeof(struct session_s)); - - memset(&sin, 0, sizeof(sin)); - sin.sin_family = AF_INET; - sin.sin_addr.s_addr = htonl(0); - sin.sin_port = htons(port); - listener = evconnlistener_new_bind(base, accept_conn_cb, s, LEV_OPT_CLOSE_ON_FREE|LEV_OPT_REUSEABLE, -1, (struct sockaddr*)&sin, sizeof(sin)); - if (!listener) { - ret=RC_ERROR; - eprintf("Can't bind port %d\n!\n", port); - goto out; - } - evconnlistener_set_error_cb(listener, accept_error_cb); - -out: - *sess=(void*)s; - return ret; -} - -*/ - } // extern "C" +/* main function which polls the socket and talks openocd jtagremote protocol. + dead simple: incoming number 0-7 sets TCK, TMS and TDK. request "R" + indicates that receiver wants to know the status of TDO. + "Q" means "quit socket". +*/ void read_openocd_jtagremote(cxxrtl_design::p_add &top, int sock) { char c; @@ -184,7 +124,7 @@ int main() /* read and process incoming jtag */ read_openocd_jtagremote(top, sock); - // check that the output is correct + // quick check that the output is correct (it's an adder: go figure) /* top.p_a.set(5); top.p_b.set(3); -- 2.30.2