# HG changeset patch # User Mychaela Falconia # Date 1692672263 0 # Node ID c4346cdc964106a5cd97258e35dbf818c17b4d01 # Parent f6579cef76e1df29e1d6ff22b39c4b44732efd04 sw/libserial: based on FC host tools version diff -r f6579cef76e1 -r c4346cdc9641 .hgignore --- a/.hgignore Mon Aug 21 20:14:26 2023 +0000 +++ b/.hgignore Tue Aug 22 02:44:23 2023 +0000 @@ -1,5 +1,7 @@ syntax: regexp +\.[oa]$ + \.csv$ \.txt$ \.unet$ diff -r f6579cef76e1 -r c4346cdc9641 sw/libserial/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sw/libserial/Makefile Tue Aug 22 02:44:23 2023 +0000 @@ -0,0 +1,13 @@ +CC= gcc +CFLAGS= -O2 +OBJS= nonblock.o openport.o setbaud.o +LIB= libserial.a + +all: ${LIB} + +${LIB}: ${OBJS} + ar rcu $@ ${OBJS} + ranlib $@ + +clean: + rm -f *.[oa] errs diff -r f6579cef76e1 -r c4346cdc9641 sw/libserial/nonblock.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sw/libserial/nonblock.c Tue Aug 22 02:44:23 2023 +0000 @@ -0,0 +1,15 @@ +/* + * This module contains the set_serial_nonblock() function. + */ + +#include +#include +#include + +extern int target_fd; + +set_serial_nonblock(state) + int state; +{ + ioctl(target_fd, FIONBIO, &state); +} diff -r f6579cef76e1 -r c4346cdc9641 sw/libserial/openport.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sw/libserial/openport.c Tue Aug 22 02:44:23 2023 +0000 @@ -0,0 +1,24 @@ +/* + * This module implements the basic serial port opening operation. + */ + +#include +#include +#include +#include +#include +#include + +int target_fd; + +open_serial_port(ttyport) + char *ttyport; +{ + target_fd = open(ttyport, O_RDWR|O_NONBLOCK); + if (target_fd < 0) { + perror(ttyport); + exit(1); + } + ioctl(target_fd, TIOCEXCL); + return 0; +} diff -r f6579cef76e1 -r c4346cdc9641 sw/libserial/setbaud.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sw/libserial/setbaud.c Tue Aug 22 02:44:23 2023 +0000 @@ -0,0 +1,33 @@ +/* + * This module implements the termios/ioctl setting of the baud rate. + */ + +#include +#include +#include +#include +#include +#include +#include + +extern int target_fd; + +set_serial_baudrate(br) + unsigned br; +{ + struct termios2 target_termios; + + target_termios.c_iflag = IGNBRK; + target_termios.c_oflag = 0; + target_termios.c_cflag = BOTHER|CLOCAL|HUPCL|CREAD|CS8; + target_termios.c_lflag = 0; + target_termios.c_cc[VMIN] = 1; + target_termios.c_cc[VTIME] = 0; + target_termios.c_ispeed = br; + target_termios.c_ospeed = br; + if (ioctl(target_fd, TCSETSF2, &target_termios) < 0) { + perror("TCSETSF2"); + exit(1); + } + return 0; +}