annotate libserial-posix/openport.c @ 737:6d97866bad79

first round of documentation for DUART28C boot control addition
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 16 Sep 2020 06:10:39 +0000
parents fd7b447b99e3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
248
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements the basic serial port opening operation.
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/file.h>
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/ioctl.h>
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <unistd.h>
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 int target_fd;
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 open_serial_port(ttyport)
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 char *ttyport;
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 {
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 target_fd = open(ttyport, O_RDWR|O_NONBLOCK);
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 if (target_fd < 0) {
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 perror(ttyport);
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 exit(1);
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 }
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 ioctl(target_fd, TIOCEXCL);
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 return 0;
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 }