Slightly less braindead TCP interactions for openocd JTAG bitbang testbench, much more interactive now
This commit is contained in:
parent
f4952ab66d
commit
9643a57ba9
|
@ -0,0 +1,5 @@
|
||||||
|
set arch riscv:rv32
|
||||||
|
set confirm off
|
||||||
|
set disassemble-next-line on
|
||||||
|
targ rem localhost:3333
|
||||||
|
monitor reset halt
|
|
@ -23,6 +23,8 @@ enum {
|
||||||
IO_EXIT = 8
|
IO_EXIT = 8
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const int TCP_BUF_SIZE = 256;
|
||||||
|
|
||||||
const char *help_str =
|
const char *help_str =
|
||||||
"Usage: tb binfile [vcdfile] [--dump start end] [--cycles n] [--port n]\n"
|
"Usage: tb binfile [vcdfile] [--dump start end] [--cycles n] [--port n]\n"
|
||||||
" binfile : Binary to load into start of memory\n"
|
" binfile : Binary to load into start of memory\n"
|
||||||
|
@ -88,6 +90,8 @@ int main(int argc, char **argv) {
|
||||||
struct sockaddr_in sock_addr;
|
struct sockaddr_in sock_addr;
|
||||||
int sock_opt = 1;
|
int sock_opt = 1;
|
||||||
socklen_t sock_addr_len = sizeof(sock_addr);
|
socklen_t sock_addr_len = sizeof(sock_addr);
|
||||||
|
char txbuf[TCP_BUF_SIZE], rxbuf[TCP_BUF_SIZE];
|
||||||
|
int rx_ptr = 0, rx_remaining = 0, tx_ptr = 0;
|
||||||
|
|
||||||
server_fd = socket(AF_INET, SOCK_STREAM, 0);
|
server_fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if (server_fd == 0) {
|
if (server_fd == 0) {
|
||||||
|
@ -183,9 +187,11 @@ int main(int argc, char **argv) {
|
||||||
// writes) but reads take 0 cycles, step=false.
|
// writes) but reads take 0 cycles, step=false.
|
||||||
bool got_exit_cmd = false;
|
bool got_exit_cmd = false;
|
||||||
bool step = false;
|
bool step = false;
|
||||||
char c;
|
|
||||||
while (!step) {
|
while (!step) {
|
||||||
if (read(sock_fd, &c, 1) > 0) {
|
if (rx_remaining > 0) {
|
||||||
|
char c = rxbuf[rx_ptr++];
|
||||||
|
--rx_remaining;
|
||||||
|
|
||||||
if (c == 'r' || c == 's') {
|
if (c == 'r' || c == 's') {
|
||||||
top.p_trst__n.set<bool>(true);
|
top.p_trst__n.set<bool>(true);
|
||||||
step = true;
|
step = true;
|
||||||
|
@ -201,14 +207,29 @@ int main(int argc, char **argv) {
|
||||||
step = true;
|
step = true;
|
||||||
}
|
}
|
||||||
else if (c == 'R') {
|
else if (c == 'R') {
|
||||||
char d = top.p_tdo.get<bool>() ? '1' : '0';
|
txbuf[tx_ptr++] = top.p_tdo.get<bool>() ? '1' : '0';
|
||||||
send(sock_fd, &d, 1, 0);
|
if (tx_ptr >= TCP_BUF_SIZE || rx_remaining == 0) {
|
||||||
|
send(sock_fd, txbuf, tx_ptr, 0);
|
||||||
|
tx_ptr = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (c == 'Q') {
|
else if (c == 'Q') {
|
||||||
got_exit_cmd = true;
|
got_exit_cmd = true;
|
||||||
step = true;
|
step = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
// Potentially the last command was not a read command, but
|
||||||
|
// OpenOCD is still waiting for a last response from its
|
||||||
|
// last command packet before it sends us any more, so now is
|
||||||
|
// the time to flush TX.
|
||||||
|
if (tx_ptr > 0) {
|
||||||
|
send(sock_fd, txbuf, tx_ptr, 0);
|
||||||
|
tx_ptr = 0;
|
||||||
|
}
|
||||||
|
rx_ptr = 0;
|
||||||
|
rx_remaining = read(sock_fd, &rxbuf, TCP_BUF_SIZE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle current data phase, then move current address phase to data phase
|
// Handle current data phase, then move current address phase to data phase
|
||||||
|
|
Loading…
Reference in New Issue