# HG changeset patch # User Mychaela Falconia # Date 1506038977 0 # Node ID 6984b76f3deff30d064d35acf10496533c287e75 # Parent 6f078c4a5506668caf7562676bea0f75ad337bf8 beginning of libserial-newlnx: copy of libserial-orig diff -r 6f078c4a5506 -r 6984b76f3def libserial-newlnx/baudrate.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libserial-newlnx/baudrate.h Fri Sep 22 00:09:37 2017 +0000 @@ -0,0 +1,7 @@ +/* this header file defines the data structure for baud rate machinations */ + +struct baudrate { + char *name; + int termios_code; + int bootrom_code; +}; diff -r 6f078c4a5506 -r 6984b76f3def libserial-newlnx/baudtab.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libserial-newlnx/baudtab.c Fri Sep 22 00:09:37 2017 +0000 @@ -0,0 +1,47 @@ +/* + * This module contains the table of baud rates supported + * by this implementation of FreeCalypso libserial. + */ + +#include +#include +#include +#include +#include +#include "baudrate.h" + +struct baudrate baud_rate_table[] = { + /* the first listed rate will be our default */ + {"115200", B115200, 0}, + {"57600", B57600, 1}, + {"38400", B38400, 2}, + {"19200", B19200, 4}, + /* + * 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}, + {"406250", B460800, -1}, + {"203125", B230400, -1}, + /* 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); + } +} diff -r 6f078c4a5506 -r 6984b76f3def libserial-newlnx/nonblock.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libserial-newlnx/nonblock.c Fri Sep 22 00:09:37 2017 +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 6f078c4a5506 -r 6984b76f3def libserial-newlnx/openport.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libserial-newlnx/openport.c Fri Sep 22 00:09:37 2017 +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 6f078c4a5506 -r 6984b76f3def libserial-newlnx/setbaud.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libserial-newlnx/setbaud.c Fri Sep 22 00:09:37 2017 +0000 @@ -0,0 +1,36 @@ +/* + * This module implements the termios/ioctl setting of the baud rate. + */ + +#include +#include +#include +#include +#include +#include +#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; +} diff -r 6f078c4a5506 -r 6984b76f3def libserial-newlnx/setbyname.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libserial-newlnx/setbyname.c Fri Sep 22 00:09:37 2017 +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 +#include +#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); +}