annotate sw/libserial/openport.c @ 6:a10657f8024e

sw: move initflush.c module into libserial
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 12 Oct 2024 19:42:19 +0000
parents a4918a161d2e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
a4918a161d2e sw: starting with libserial, copied from fc-sim-sniff
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
a4918a161d2e sw: starting with libserial, copied from fc-sim-sniff
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements the basic serial port opening operation.
a4918a161d2e sw: starting with libserial, copied from fc-sim-sniff
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
a4918a161d2e sw: starting with libserial, copied from fc-sim-sniff
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
a4918a161d2e sw: starting with libserial, copied from fc-sim-sniff
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
a4918a161d2e sw: starting with libserial, copied from fc-sim-sniff
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/file.h>
a4918a161d2e sw: starting with libserial, copied from fc-sim-sniff
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/ioctl.h>
a4918a161d2e sw: starting with libserial, copied from fc-sim-sniff
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
a4918a161d2e sw: starting with libserial, copied from fc-sim-sniff
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
a4918a161d2e sw: starting with libserial, copied from fc-sim-sniff
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <unistd.h>
a4918a161d2e sw: starting with libserial, copied from fc-sim-sniff
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
a4918a161d2e sw: starting with libserial, copied from fc-sim-sniff
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 int target_fd;
a4918a161d2e sw: starting with libserial, copied from fc-sim-sniff
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
a4918a161d2e sw: starting with libserial, copied from fc-sim-sniff
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 open_serial_port(ttyport)
a4918a161d2e sw: starting with libserial, copied from fc-sim-sniff
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 char *ttyport;
a4918a161d2e sw: starting with libserial, copied from fc-sim-sniff
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 {
a4918a161d2e sw: starting with libserial, copied from fc-sim-sniff
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 target_fd = open(ttyport, O_RDWR|O_NONBLOCK);
a4918a161d2e sw: starting with libserial, copied from fc-sim-sniff
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 if (target_fd < 0) {
a4918a161d2e sw: starting with libserial, copied from fc-sim-sniff
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 perror(ttyport);
a4918a161d2e sw: starting with libserial, copied from fc-sim-sniff
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 exit(1);
a4918a161d2e sw: starting with libserial, copied from fc-sim-sniff
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 }
a4918a161d2e sw: starting with libserial, copied from fc-sim-sniff
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 ioctl(target_fd, TIOCEXCL);
a4918a161d2e sw: starting with libserial, copied from fc-sim-sniff
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 return 0;
a4918a161d2e sw: starting with libserial, copied from fc-sim-sniff
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 }