annotate sw/libserial/openport.c @ 22:b112c2df6c43

sw: simtrace3-sniff-rx program written, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 22 Aug 2023 06:16:44 +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 basic serial port opening operation.
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/file.h>
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/ioctl.h>
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <unistd.h>
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 int target_fd;
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 open_serial_port(ttyport)
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 char *ttyport;
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 {
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 target_fd = open(ttyport, O_RDWR|O_NONBLOCK);
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 if (target_fd < 0) {
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 perror(ttyport);
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 exit(1);
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 }
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 ioctl(target_fd, TIOCEXCL);
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 return 0;
c4346cdc9641 sw/libserial: based on FC host tools version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 }