Commit 254c359b authored by Alessandro Rubini's avatar Alessandro Rubini

userspace: clean up lm32-vuart

lm32-vuart was destroying the tty it was run into. And ctrl-C was
not working (the initial message "press ctrl-A" was not really
visible).

This removes part of the cruft of the program. It also adds a little
delay when no bytes are there to read from FPGA to releaf a little
the load on the ARM CPU.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent c32915cd
...@@ -38,18 +38,13 @@ int vuart_rx(char *buf, int size) ...@@ -38,18 +38,13 @@ int vuart_rx(char *buf, int size)
return n_rx; return n_rx;
} }
static int transfer_byte(int from, int is_control) { static int transfer_byte(int from) {
char c; char c;
int ret; int ret;
do { do {
ret = read(from, &c, 1); ret = read(from, &c, 1);
} while (ret < 0 && errno == EINTR); } while (ret < 0 && errno == EINTR);
if(ret == 1) { if(ret == 1) {
if(is_control) {
if(c == '\x01') { // C-a
return -1;
}
}
vuart_tx(&c, 1); vuart_tx(&c, 1);
} else { } else {
fprintf(stderr, "nothing to read. Port disconnected?\n"); fprintf(stderr, "nothing to read. Port disconnected?\n");
...@@ -59,25 +54,11 @@ static int transfer_byte(int from, int is_control) { ...@@ -59,25 +54,11 @@ static int transfer_byte(int from, int is_control) {
} }
void term_main(int keep_term) void term_main(void)
{ {
struct termios oldkey, newkey; struct termios oldkey, newkey;
int need_exit = 0;
while(1) {
fprintf(stderr, "[press C-a to exit]\n");
if(!keep_term) {
tcgetattr(STDIN_FILENO,&oldkey);
newkey.c_cflag = B9600 | CS8 | CLOCAL | CREAD;
newkey.c_iflag = IGNPAR;
newkey.c_oflag = 0;
newkey.c_lflag = 0;
newkey.c_cc[VMIN]=1;
newkey.c_cc[VTIME]=0;
tcflush(STDIN_FILENO, TCIFLUSH);
tcsetattr(STDIN_FILENO,TCSANOW,&newkey);
}
while(!need_exit) {
fd_set fds; fd_set fds;
int ret; int ret;
char rx; char rx;
...@@ -91,23 +72,22 @@ void term_main(int keep_term) ...@@ -91,23 +72,22 @@ void term_main(int keep_term)
perror("select"); perror("select");
} else if (ret > 0) { } else if (ret > 0) {
if(FD_ISSET(STDIN_FILENO, &fds)) { if(FD_ISSET(STDIN_FILENO, &fds)) {
need_exit = transfer_byte(STDIN_FILENO, 1); transfer_byte(STDIN_FILENO);
} }
} }
while((vuart_rx(&rx, 1)) == 1) while((vuart_rx(&rx, 1)) == 1)
fprintf(stderr,"%c", rx); fprintf(stderr,"%c", rx);
usleep(1000); /* relief the CPU */
} }
if(!keep_term)
tcsetattr(STDIN_FILENO,TCSANOW,&oldkey);
} }
int main(void) int main(void)
{ {
shw_fpga_mmap_init(); shw_fpga_mmap_init();
term_main(0); term_main();
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment