FreeCalypso > hg > freecalypso-tools
changeset 661:fd7b447b99e3
libserial rename
The version that was previously named libserial-newlnx is now libserial-linux,
and the version that was previosly named libserial-orig is now libserial-posix.
This new naming is more in line with the objective reality of the difference,
moving away from naming based on our project history.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 05 Mar 2020 19:54:31 +0000 |
parents | b34384991094 |
children | 0a6184443821 |
files | libserial libserial-linux/Makefile libserial-linux/baudrate.h libserial-linux/baudtab.c libserial-linux/nonblock.c libserial-linux/openport.c libserial-linux/setbaud.c libserial-linux/setbyname.c libserial-newlnx/Makefile libserial-newlnx/baudrate.h libserial-newlnx/baudtab.c libserial-newlnx/nonblock.c libserial-newlnx/openport.c libserial-newlnx/setbaud.c libserial-newlnx/setbyname.c libserial-orig/Makefile libserial-orig/baudrate.h libserial-orig/baudtab.c libserial-orig/nonblock.c libserial-orig/openport.c libserial-orig/setbaud.c libserial-orig/setbyname.c libserial-posix/Makefile libserial-posix/baudrate.h libserial-posix/baudtab.c libserial-posix/nonblock.c libserial-posix/openport.c libserial-posix/setbaud.c libserial-posix/setbyname.c |
diffstat | 29 files changed, 327 insertions(+), 327 deletions(-) [+] |
line wrap: on
line diff
--- a/libserial Wed Mar 04 06:51:52 2020 +0000 +++ b/libserial Thu Mar 05 19:54:31 2020 +0000 @@ -1,1 +1,1 @@ -libserial-newlnx \ No newline at end of file +libserial-linux \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libserial-linux/Makefile Thu Mar 05 19:54:31 2020 +0000 @@ -0,0 +1,13 @@ +CC= gcc +CFLAGS= -O2 +OBJS= baudtab.o nonblock.o openport.o setbaud.o setbyname.o +LIB= libserial.a + +all: ${LIB} + +${LIB}: ${OBJS} + ar rcu $@ ${OBJS} + ranlib $@ + +clean: + rm -f *.[oa] errs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libserial-linux/baudrate.h Thu Mar 05 19:54:31 2020 +0000 @@ -0,0 +1,9 @@ +/* this header file defines the data structure for baud rate machinations */ + +struct baudrate { + char *name; + int termios_code; + int nonstd_speed; + int bootrom_code; + int xram_records; +};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libserial-linux/baudtab.c Thu Mar 05 19:54:31 2020 +0000 @@ -0,0 +1,43 @@ +/* + * This module contains the table of baud rates supported + * by this implementation of FreeCalypso libserial. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include <asm/termbits.h> +#include "baudrate.h" + +struct baudrate baud_rate_table[] = { + /* the first listed rate will be our default */ + {"115200", B115200, 0, 0, 100}, + {"57600", B57600, 0, 1, 100}, + {"38400", B38400, 0, 2, 100}, + {"19200", B19200, 0, 4, 50}, + /* Non-standard high baud rates */ + {"812500", BOTHER, 812500, -1, 1000}, + {"406250", BOTHER, 406250, -1, 500}, + {"203125", BOTHER, 203125, -1, 250}, + /* table search terminator */ + {NULL, B0, 0, -1, 0}, +}; + +struct baudrate * +find_baudrate_by_name(srch_name) + char *srch_name; +{ + struct baudrate *br; + + for (br = baud_rate_table; br->name; br++) + if (!strcmp(br->name, srch_name)) + break; + if (br->name) + return(br); + else { + fprintf(stderr, "error: baud rate \"%s\" not known\n", + srch_name); + return(NULL); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libserial-linux/nonblock.c Thu Mar 05 19:54:31 2020 +0000 @@ -0,0 +1,15 @@ +/* + * This module contains the set_serial_nonblock() function. + */ + +#include <sys/types.h> +#include <sys/ioctl.h> +#include <unistd.h> + +extern int target_fd; + +set_serial_nonblock(state) + int state; +{ + ioctl(target_fd, FIONBIO, &state); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libserial-linux/openport.c Thu Mar 05 19:54:31 2020 +0000 @@ -0,0 +1,24 @@ +/* + * This module implements the basic serial port opening operation. + */ + +#include <sys/types.h> +#include <sys/file.h> +#include <sys/ioctl.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +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; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libserial-linux/setbaud.c Thu Mar 05 19:54:31 2020 +0000 @@ -0,0 +1,37 @@ +/* + * This module implements the termios/ioctl setting of the baud rate. + */ + +#include <sys/types.h> +#include <sys/ioctl.h> +#include <asm/ioctls.h> +#include <asm/termbits.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include "baudrate.h" + +extern int target_fd; + +struct baudrate *current_baud_rate; + +set_serial_baudrate(br) + struct baudrate *br; +{ + struct termios2 target_termios; + + target_termios.c_iflag = IGNBRK; + target_termios.c_oflag = 0; + target_termios.c_cflag = br->termios_code | 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->nonstd_speed; + target_termios.c_ospeed = br->nonstd_speed; + if (ioctl(target_fd, TCSETSF2, &target_termios) < 0) { + perror("TCSETSF2"); + exit(1); + } + current_baud_rate = br; + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libserial-linux/setbyname.c Thu Mar 05 19:54:31 2020 +0000 @@ -0,0 +1,21 @@ +/* + * This module contains the wrapper function (used by loadtools) + * that looks up a baud rate by name and calls set_serial_baud(). + */ + +#include <stdio.h> +#include <stdlib.h> +#include "baudrate.h" + +extern struct baudrate *find_baudrate_by_name(); + +set_fixed_baudrate(baudname) + char *baudname; +{ + struct baudrate *br; + + br = find_baudrate_by_name(baudname); + if (!br) + exit(1); /* error msg already printed */ + set_serial_baudrate(br); +}
--- a/libserial-newlnx/Makefile Wed Mar 04 06:51:52 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -CC= gcc -CFLAGS= -O2 -OBJS= baudtab.o nonblock.o openport.o setbaud.o setbyname.o -LIB= libserial.a - -all: ${LIB} - -${LIB}: ${OBJS} - ar rcu $@ ${OBJS} - ranlib $@ - -clean: - rm -f *.[oa] errs
--- a/libserial-newlnx/baudrate.h Wed Mar 04 06:51:52 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -/* this header file defines the data structure for baud rate machinations */ - -struct baudrate { - char *name; - int termios_code; - int nonstd_speed; - int bootrom_code; - int xram_records; -};
--- a/libserial-newlnx/baudtab.c Wed Mar 04 06:51:52 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/* - * This module contains the table of baud rates supported - * by this implementation of FreeCalypso libserial. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <strings.h> -#include <asm/termbits.h> -#include "baudrate.h" - -struct baudrate baud_rate_table[] = { - /* the first listed rate will be our default */ - {"115200", B115200, 0, 0, 100}, - {"57600", B57600, 0, 1, 100}, - {"38400", B38400, 0, 2, 100}, - {"19200", B19200, 0, 4, 50}, - /* Non-standard high baud rates */ - {"812500", BOTHER, 812500, -1, 1000}, - {"406250", BOTHER, 406250, -1, 500}, - {"203125", BOTHER, 203125, -1, 250}, - /* table search terminator */ - {NULL, B0, 0, -1, 0}, -}; - -struct baudrate * -find_baudrate_by_name(srch_name) - char *srch_name; -{ - struct baudrate *br; - - for (br = baud_rate_table; br->name; br++) - if (!strcmp(br->name, srch_name)) - break; - if (br->name) - return(br); - else { - fprintf(stderr, "error: baud rate \"%s\" not known\n", - srch_name); - return(NULL); - } -}
--- a/libserial-newlnx/nonblock.c Wed Mar 04 06:51:52 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -/* - * This module contains the set_serial_nonblock() function. - */ - -#include <sys/types.h> -#include <sys/ioctl.h> -#include <unistd.h> - -extern int target_fd; - -set_serial_nonblock(state) - int state; -{ - ioctl(target_fd, FIONBIO, &state); -}
--- a/libserial-newlnx/openport.c Wed Mar 04 06:51:52 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -/* - * This module implements the basic serial port opening operation. - */ - -#include <sys/types.h> -#include <sys/file.h> -#include <sys/ioctl.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -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; -}
--- a/libserial-newlnx/setbaud.c Wed Mar 04 06:51:52 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -/* - * This module implements the termios/ioctl setting of the baud rate. - */ - -#include <sys/types.h> -#include <sys/ioctl.h> -#include <asm/ioctls.h> -#include <asm/termbits.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include "baudrate.h" - -extern int target_fd; - -struct baudrate *current_baud_rate; - -set_serial_baudrate(br) - struct baudrate *br; -{ - struct termios2 target_termios; - - target_termios.c_iflag = IGNBRK; - target_termios.c_oflag = 0; - target_termios.c_cflag = br->termios_code | 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->nonstd_speed; - target_termios.c_ospeed = br->nonstd_speed; - if (ioctl(target_fd, TCSETSF2, &target_termios) < 0) { - perror("TCSETSF2"); - exit(1); - } - current_baud_rate = br; - return 0; -}
--- a/libserial-newlnx/setbyname.c Wed Mar 04 06:51:52 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -/* - * This module contains the wrapper function (used by loadtools) - * that looks up a baud rate by name and calls set_serial_baud(). - */ - -#include <stdio.h> -#include <stdlib.h> -#include "baudrate.h" - -extern struct baudrate *find_baudrate_by_name(); - -set_fixed_baudrate(baudname) - char *baudname; -{ - struct baudrate *br; - - br = find_baudrate_by_name(baudname); - if (!br) - exit(1); /* error msg already printed */ - set_serial_baudrate(br); -}
--- a/libserial-orig/Makefile Wed Mar 04 06:51:52 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -CC= gcc -CFLAGS= -O2 -OBJS= baudtab.o nonblock.o openport.o setbaud.o setbyname.o -LIB= libserial.a - -all: ${LIB} - -${LIB}: ${OBJS} - ar rcu $@ ${OBJS} - ranlib $@ - -clean: - rm -f *.[oa] errs
--- a/libserial-orig/baudrate.h Wed Mar 04 06:51:52 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -/* this header file defines the data structure for baud rate machinations */ - -struct baudrate { - char *name; - int termios_code; - int bootrom_code; - int xram_records; -};
--- a/libserial-orig/baudtab.c Wed Mar 04 06:51:52 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -/* - * This module contains the table of baud rates supported - * by this implementation of FreeCalypso libserial. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <strings.h> -#include <termios.h> -#include "baudrate.h" - -struct baudrate baud_rate_table[] = { - /* the first listed rate will be our default */ - {"115200", B115200, 0, 100}, - {"57600", B57600, 1, 100}, - {"38400", B38400, 2, 100}, - {"19200", B19200, 4, 50}, - /* - * Non-standard high baud rates remapped by CP2102 EEPROM programming - * or by a hacky patch to the ftdi_sio Linux kernel driver to work - * with FTDI adapters. - */ - {"812500", B921600, -1, 1000}, - {"406250", B460800, -1, 500}, - {"203125", B230400, -1, 250}, - /* table search terminator */ - {NULL, B0, -1}, -}; - -struct baudrate * -find_baudrate_by_name(srch_name) - char *srch_name; -{ - struct baudrate *br; - - for (br = baud_rate_table; br->name; br++) - if (!strcmp(br->name, srch_name)) - break; - if (br->name) - return(br); - else { - fprintf(stderr, "error: baud rate \"%s\" not known\n", - srch_name); - return(NULL); - } -}
--- a/libserial-orig/nonblock.c Wed Mar 04 06:51:52 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -/* - * This module contains the set_serial_nonblock() function. - */ - -#include <sys/types.h> -#include <sys/ioctl.h> -#include <unistd.h> - -extern int target_fd; - -set_serial_nonblock(state) - int state; -{ - ioctl(target_fd, FIONBIO, &state); -}
--- a/libserial-orig/openport.c Wed Mar 04 06:51:52 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -/* - * This module implements the basic serial port opening operation. - */ - -#include <sys/types.h> -#include <sys/file.h> -#include <sys/ioctl.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -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; -}
--- a/libserial-orig/setbaud.c Wed Mar 04 06:51:52 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -/* - * This module implements the termios/ioctl setting of the baud rate. - */ - -#include <sys/types.h> -#include <sys/ioctl.h> -#include <termios.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include "baudrate.h" - -extern int target_fd; - -struct baudrate *current_baud_rate; - -set_serial_baudrate(br) - struct baudrate *br; -{ - struct termios target_termios; - - target_termios.c_iflag = IGNBRK; - target_termios.c_oflag = 0; - target_termios.c_cflag = CLOCAL|HUPCL|CREAD|CS8; - target_termios.c_lflag = 0; - target_termios.c_cc[VMIN] = 1; - target_termios.c_cc[VTIME] = 0; - cfsetispeed(&target_termios, br->termios_code); - cfsetospeed(&target_termios, br->termios_code); - if (tcsetattr(target_fd, TCSAFLUSH, &target_termios) < 0) { - perror("tcsetattr"); - exit(1); - } - current_baud_rate = br; - return 0; -}
--- a/libserial-orig/setbyname.c Wed Mar 04 06:51:52 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -/* - * This module contains the wrapper function (used by loadtools) - * that looks up a baud rate by name and calls set_serial_baud(). - */ - -#include <stdio.h> -#include <stdlib.h> -#include "baudrate.h" - -extern struct baudrate *find_baudrate_by_name(); - -set_fixed_baudrate(baudname) - char *baudname; -{ - struct baudrate *br; - - br = find_baudrate_by_name(baudname); - if (!br) - exit(1); /* error msg already printed */ - set_serial_baudrate(br); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libserial-posix/Makefile Thu Mar 05 19:54:31 2020 +0000 @@ -0,0 +1,13 @@ +CC= gcc +CFLAGS= -O2 +OBJS= baudtab.o nonblock.o openport.o setbaud.o setbyname.o +LIB= libserial.a + +all: ${LIB} + +${LIB}: ${OBJS} + ar rcu $@ ${OBJS} + ranlib $@ + +clean: + rm -f *.[oa] errs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libserial-posix/baudrate.h Thu Mar 05 19:54:31 2020 +0000 @@ -0,0 +1,8 @@ +/* this header file defines the data structure for baud rate machinations */ + +struct baudrate { + char *name; + int termios_code; + int bootrom_code; + int xram_records; +};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libserial-posix/baudtab.c Thu Mar 05 19:54:31 2020 +0000 @@ -0,0 +1,47 @@ +/* + * This module contains the table of baud rates supported + * by this implementation of FreeCalypso libserial. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include <termios.h> +#include "baudrate.h" + +struct baudrate baud_rate_table[] = { + /* the first listed rate will be our default */ + {"115200", B115200, 0, 100}, + {"57600", B57600, 1, 100}, + {"38400", B38400, 2, 100}, + {"19200", B19200, 4, 50}, + /* + * Non-standard high baud rates remapped by CP2102 EEPROM programming + * or by a hacky patch to the ftdi_sio Linux kernel driver to work + * with FTDI adapters. + */ + {"812500", B921600, -1, 1000}, + {"406250", B460800, -1, 500}, + {"203125", B230400, -1, 250}, + /* table search terminator */ + {NULL, B0, -1}, +}; + +struct baudrate * +find_baudrate_by_name(srch_name) + char *srch_name; +{ + struct baudrate *br; + + for (br = baud_rate_table; br->name; br++) + if (!strcmp(br->name, srch_name)) + break; + if (br->name) + return(br); + else { + fprintf(stderr, "error: baud rate \"%s\" not known\n", + srch_name); + return(NULL); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libserial-posix/nonblock.c Thu Mar 05 19:54:31 2020 +0000 @@ -0,0 +1,15 @@ +/* + * This module contains the set_serial_nonblock() function. + */ + +#include <sys/types.h> +#include <sys/ioctl.h> +#include <unistd.h> + +extern int target_fd; + +set_serial_nonblock(state) + int state; +{ + ioctl(target_fd, FIONBIO, &state); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libserial-posix/openport.c Thu Mar 05 19:54:31 2020 +0000 @@ -0,0 +1,24 @@ +/* + * This module implements the basic serial port opening operation. + */ + +#include <sys/types.h> +#include <sys/file.h> +#include <sys/ioctl.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +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; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libserial-posix/setbaud.c Thu Mar 05 19:54:31 2020 +0000 @@ -0,0 +1,36 @@ +/* + * This module implements the termios/ioctl setting of the baud rate. + */ + +#include <sys/types.h> +#include <sys/ioctl.h> +#include <termios.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include "baudrate.h" + +extern int target_fd; + +struct baudrate *current_baud_rate; + +set_serial_baudrate(br) + struct baudrate *br; +{ + struct termios target_termios; + + target_termios.c_iflag = IGNBRK; + target_termios.c_oflag = 0; + target_termios.c_cflag = CLOCAL|HUPCL|CREAD|CS8; + target_termios.c_lflag = 0; + target_termios.c_cc[VMIN] = 1; + target_termios.c_cc[VTIME] = 0; + cfsetispeed(&target_termios, br->termios_code); + cfsetospeed(&target_termios, br->termios_code); + if (tcsetattr(target_fd, TCSAFLUSH, &target_termios) < 0) { + perror("tcsetattr"); + exit(1); + } + current_baud_rate = br; + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libserial-posix/setbyname.c Thu Mar 05 19:54:31 2020 +0000 @@ -0,0 +1,21 @@ +/* + * This module contains the wrapper function (used by loadtools) + * that looks up a baud rate by name and calls set_serial_baud(). + */ + +#include <stdio.h> +#include <stdlib.h> +#include "baudrate.h" + +extern struct baudrate *find_baudrate_by_name(); + +set_fixed_baudrate(baudname) + char *baudname; +{ + struct baudrate *br; + + br = find_baudrate_by_name(baudname); + if (!br) + exit(1); /* error msg already printed */ + set_serial_baudrate(br); +}