annotate sw/libserial/setbaud.c @ 29:8be0b96b7c8d

fpga: add top Makefile across projects
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 29 Aug 2023 20:35:51 +0000
parents c4346cdc9641
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements the termios/ioctl setting of the baud rate.
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/ioctl.h>
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <asm/ioctls.h>
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <asm/termbits.h>
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdio.h>
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdlib.h>
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <unistd.h>
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 extern int target_fd;
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 set_serial_baudrate(br)
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 unsigned br;
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 {
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 struct termios2 target_termios;
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 target_termios.c_iflag = IGNBRK;
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 target_termios.c_oflag = 0;
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 target_termios.c_cflag = BOTHER|CLOCAL|HUPCL|CREAD|CS8;
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 target_termios.c_lflag = 0;
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 target_termios.c_cc[VMIN] = 1;
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 target_termios.c_cc[VTIME] = 0;
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 target_termios.c_ispeed = br;
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 target_termios.c_ospeed = br;
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 if (ioctl(target_fd, TCSETSF2, &target_termios) < 0) {
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 perror("TCSETSF2");
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 exit(1);
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 return 0;
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 }