# HG changeset patch # User Mychaela Falconia # Date 1728762139 0 # Node ID a10657f8024ec966479fb0884051f3b3d622ec83 # Parent 3ae4a6ca56390ae43c235928b6782818d5f317f8 sw: move initflush.c module into libserial diff -r 3ae4a6ca5639 -r a10657f8024e sw/libserial/Makefile --- a/sw/libserial/Makefile Sat Oct 12 03:11:17 2024 +0000 +++ b/sw/libserial/Makefile Sat Oct 12 19:42:19 2024 +0000 @@ -1,6 +1,6 @@ CC= gcc CFLAGS= -O2 -OBJS= nonblock.o openport.o setbaud.o +OBJS= initflush.o nonblock.o openport.o setbaud.o LIB= libserial.a all: ${LIB} diff -r 3ae4a6ca5639 -r a10657f8024e sw/libserial/initflush.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sw/libserial/initflush.c Sat Oct 12 19:42:19 2024 +0000 @@ -0,0 +1,41 @@ +/* + * FTDI chip+driver combo (specifically the combination of FTDI chips and + * ftdi_sio driver in Linux, not sure who is the actual culprit) exhibits + * this unpleasant behaviour: even though we request "please flush all + * previous input" when we set our termios params, old accumulated serial + * Rx bytes still remain in some buffer somewhere, and a newly started + * serial application receives this stale garbage. As a workaround, + * we do an additional flush of our own: we put the fd in non-blocking mode + * and keep reading and discarding data until we get EAGAIN or EWOULDBLOCK. + */ + +#include +#include +#include +#include +#include + +extern int target_fd; + +void +init_serial_flush() +{ + u_char buf[512]; + int cc; + + set_serial_nonblock(1); + for (;;) { + cc = read(target_fd, buf, sizeof buf); + if (cc <= 0) + break; + } + if (cc == 0) { + fprintf(stderr, + "read EOF from serial port during initial flush\n"); + exit(1); + } + if (errno == EAGAIN || errno == EWOULDBLOCK) + return; /* success */ + perror("serial port read"); + exit(1); +} diff -r 3ae4a6ca5639 -r a10657f8024e sw/mcsi-rx/Makefile --- a/sw/mcsi-rx/Makefile Sat Oct 12 03:11:17 2024 +0000 +++ b/sw/mcsi-rx/Makefile Sat Oct 12 19:42:19 2024 +0000 @@ -1,7 +1,7 @@ CC= gcc CFLAGS= -O2 PROG= fc-mcsi-rx -OBJS= initflush.o main.o mainloop.o robe_out.o +OBJS= main.o mainloop.o robe_out.o LIBS= ../libserial/libserial.a INSTALL_PREFIX= /opt/freecalypso diff -r 3ae4a6ca5639 -r a10657f8024e sw/mcsi-rx/initflush.c --- a/sw/mcsi-rx/initflush.c Sat Oct 12 03:11:17 2024 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -/* - * FTDI chip+driver combo (specifically the combination of FTDI chips and - * ftdi_sio driver in Linux, not sure who is the actual culprit) exhibits - * this unpleasant behaviour: even though we request "please flush all - * previous input" when we set our termios params, old accumulated serial - * Rx bytes still remain in some buffer somewhere, and a newly started - * serial application receives this stale garbage. As a workaround, - * we do an additional flush of our own: we put the fd in non-blocking mode - * and keep reading and discarding data until we get EAGAIN or EWOULDBLOCK. - */ - -#include -#include -#include -#include -#include - -extern int target_fd; - -void -init_serial_flush() -{ - u_char buf[512]; - int cc; - - set_serial_nonblock(1); - for (;;) { - cc = read(target_fd, buf, sizeof buf); - if (cc <= 0) - break; - } - if (cc == 0) { - fprintf(stderr, - "read EOF from serial port during initial flush\n"); - exit(1); - } - if (errno == EAGAIN || errno == EWOULDBLOCK) - return; /* success */ - perror("serial port read"); - exit(1); -}