FreeCalypso > hg > freecalypso-tools
comparison libserial-newlnx/setbaud.c @ 254:6984b76f3def
beginning of libserial-newlnx: copy of libserial-orig
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Fri, 22 Sep 2017 00:09:37 +0000 |
| parents | |
| children | ab8410d06ca7 |
comparison
equal
deleted
inserted
replaced
| 253:6f078c4a5506 | 254:6984b76f3def |
|---|---|
| 1 /* | |
| 2 * This module implements the termios/ioctl setting of the baud rate. | |
| 3 */ | |
| 4 | |
| 5 #include <sys/types.h> | |
| 6 #include <sys/ioctl.h> | |
| 7 #include <termios.h> | |
| 8 #include <stdio.h> | |
| 9 #include <stdlib.h> | |
| 10 #include <unistd.h> | |
| 11 #include "baudrate.h" | |
| 12 | |
| 13 extern int target_fd; | |
| 14 | |
| 15 struct baudrate *current_baud_rate; | |
| 16 | |
| 17 set_serial_baudrate(br) | |
| 18 struct baudrate *br; | |
| 19 { | |
| 20 struct termios target_termios; | |
| 21 | |
| 22 target_termios.c_iflag = IGNBRK; | |
| 23 target_termios.c_oflag = 0; | |
| 24 target_termios.c_cflag = CLOCAL|HUPCL|CREAD|CS8; | |
| 25 target_termios.c_lflag = 0; | |
| 26 target_termios.c_cc[VMIN] = 1; | |
| 27 target_termios.c_cc[VTIME] = 0; | |
| 28 cfsetispeed(&target_termios, br->termios_code); | |
| 29 cfsetospeed(&target_termios, br->termios_code); | |
| 30 if (tcsetattr(target_fd, TCSAFLUSH, &target_termios) < 0) { | |
| 31 perror("tcsetattr"); | |
| 32 exit(1); | |
| 33 } | |
| 34 current_baud_rate = br; | |
| 35 return 0; | |
| 36 } |
