comparison libserial-orig/setbaud.c @ 248:cb1ba53a1106

beginning of factored-out libserial
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 21 Sep 2017 21:43:34 +0000
parents
children
comparison
equal deleted inserted replaced
247:b5b148ef63da 248:cb1ba53a1106
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 }