#include <string.h>
#include <unistd.h>
#include <sys/select.h>
+#include <sys/types.h> /* See NOTES */
+#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <sys/fcntl.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
#include <iostream>
#include "add.cpp"
switch (status)
{
case -1:
+ printf("Error reading on socket\n");
exit(status); // error
return 0;
case 0:
int get_connection()
{
int listenfd = 0, connfd = 0;
+ int flag = 1;
struct sockaddr_in serv_addr;
listenfd = socket(AF_INET, SOCK_STREAM, 0);
connfd = accept(listenfd, (struct sockaddr*)NULL, NULL);
close(listenfd);
+ setsockopt(connfd, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int));
return connfd;
}
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<bool>(((c - '0') >> 2) & 1);
+ top.p_tms.set<bool>(((c - '0') >> 1) & 1);
+ top.p_tdi.set<bool>((c - '0') & 1);
+ }
+ if (c == 'R')
+ {
+ uint8_t val = top.p_tdo.get<uint8_t>() + '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;
int sock = get_connection();
top.step();
- for(int cycle=0;cycle<1000;++cycle){
+ while (true) {
top.p_clk.set<bool>(false);
top.step();
top.p_clk.set<bool>(true);
top.step();
+ /* read and process incoming jtag */
+ read_openocd_jtagremote(top, sock);
+
// check that the output is correct
/*
top.p_a.set<uint8_t>(5);