From: Luke Kenneth Casson Leighton Date: Thu, 8 Apr 2021 13:05:12 +0000 (+0100) Subject: add jtagremote read/write X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ad2a07fbc3313de5854654beea04d05032f03953;p=soc-cxxrtl-sim.git add jtagremote read/write --- diff --git a/small_jtag_test/main.cpp b/small_jtag_test/main.cpp index d98ae9a..5931804 100644 --- a/small_jtag_test/main.cpp +++ b/small_jtag_test/main.cpp @@ -3,8 +3,13 @@ #include #include #include +#include /* See NOTES */ +#include #include #include +#include +#include +#include #include #include "add.cpp" @@ -31,6 +36,7 @@ int read_handler(int fdread, char *buffer) switch (status) { case -1: + printf("Error reading on socket\n"); exit(status); // error return 0; case 0: @@ -45,6 +51,7 @@ int read_handler(int fdread, char *buffer) int get_connection() { int listenfd = 0, connfd = 0; + int flag = 1; struct sockaddr_in serv_addr; listenfd = socket(AF_INET, SOCK_STREAM, 0); @@ -61,6 +68,7 @@ int get_connection() connfd = accept(listenfd, (struct sockaddr*)NULL, NULL); close(listenfd); + setsockopt(connfd, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int)); return connfd; } @@ -127,33 +135,38 @@ out: return ret; } - if(s->datalen) - { - c = s->databuf[s->data_start]; - - if((c >= '0') && (c <= '7')){ - *s->tck = ((c - '0') >> 2) & 1; - *s->tms = ((c - '0') >> 1) & 1; - *s->tdi = (c - '0') & 1; - } - if(c == 'R'){ - val = *s->tdo + '0'; - if(-1 == write(s->fd, &val, 1)) { - eprintf("Error writing on socket\n"); - ret = RC_ERROR; - goto out; - } - } - s->data_start = (s->data_start + 1) % 2048; - s->datalen--; - } - -out: - return ret; */ } // extern "C" +void read_openocd_jtagremote(cxxrtl_design::p_add &top, int sock) +{ + char c; + if (read_handler(sock, &c) != 1) { + return; + } + printf ("read %c\n", c); + if ((c >= '0') && (c <= '7')) + { + top.p_tck.set(((c - '0') >> 2) & 1); + top.p_tms.set(((c - '0') >> 1) & 1); + top.p_tdi.set((c - '0') & 1); + } + if (c == 'R') + { + uint8_t val = top.p_tdo.get() + '0'; + if(-1 == write(sock, &val, 1)) + { + printf("Error writing on socket\n"); + exit(-1); + } + } + if (c == 'Q') { + printf("disconnect request\n"); + exit(-1); + } +} + int main() { cxxrtl_design::p_add top; @@ -161,13 +174,16 @@ int main() int sock = get_connection(); top.step(); - for(int cycle=0;cycle<1000;++cycle){ + while (true) { top.p_clk.set(false); top.step(); top.p_clk.set(true); top.step(); + /* read and process incoming jtag */ + read_openocd_jtagremote(top, sock); + // check that the output is correct /* top.p_a.set(5);