annotate sw/libserial/openport.c @ 2:a4918a161d2e

sw: starting with libserial, copied from fc-sim-sniff
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 11 Oct 2024 22:37:11 +0000
parents
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 }