annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
254
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements the termios/ioctl setting of the baud rate.
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/ioctl.h>
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <termios.h>
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <unistd.h>
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "baudrate.h"
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 extern int target_fd;
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 struct baudrate *current_baud_rate;
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 set_serial_baudrate(br)
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 struct baudrate *br;
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 {
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 struct termios target_termios;
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 target_termios.c_iflag = IGNBRK;
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 target_termios.c_oflag = 0;
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 target_termios.c_cflag = CLOCAL|HUPCL|CREAD|CS8;
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 target_termios.c_lflag = 0;
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 target_termios.c_cc[VMIN] = 1;
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 target_termios.c_cc[VTIME] = 0;
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 cfsetispeed(&target_termios, br->termios_code);
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 cfsetospeed(&target_termios, br->termios_code);
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 if (tcsetattr(target_fd, TCSAFLUSH, &target_termios) < 0) {
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 perror("tcsetattr");
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 exit(1);
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 }
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 current_baud_rate = br;
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 return 0;
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 }