annotate libserial-newlnx/openport.c @ 608:9d9c241f2c84

libserial-newlnx experimental change to set ASYNC_LOW_LATENCY
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 12 Feb 2020 06:23:22 +0000
parents 6984b76f3def
children f82551c77e58
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
254
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements the basic serial port opening operation.
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/file.h>
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/ioctl.h>
608
9d9c241f2c84 libserial-newlnx experimental change to set ASYNC_LOW_LATENCY
Mychaela Falconia <falcon@freecalypso.org>
parents: 254
diff changeset
8 #include <linux/serial.h>
254
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdio.h>
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdlib.h>
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <unistd.h>
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 int target_fd;
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 open_serial_port(ttyport)
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 char *ttyport;
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 {
608
9d9c241f2c84 libserial-newlnx experimental change to set ASYNC_LOW_LATENCY
Mychaela Falconia <falcon@freecalypso.org>
parents: 254
diff changeset
18 struct serial_struct kernel_serial_settings;
9d9c241f2c84 libserial-newlnx experimental change to set ASYNC_LOW_LATENCY
Mychaela Falconia <falcon@freecalypso.org>
parents: 254
diff changeset
19
254
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 target_fd = open(ttyport, O_RDWR|O_NONBLOCK);
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 if (target_fd < 0) {
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 perror(ttyport);
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 exit(1);
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 }
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 ioctl(target_fd, TIOCEXCL);
608
9d9c241f2c84 libserial-newlnx experimental change to set ASYNC_LOW_LATENCY
Mychaela Falconia <falcon@freecalypso.org>
parents: 254
diff changeset
26 /*
9d9c241f2c84 libserial-newlnx experimental change to set ASYNC_LOW_LATENCY
Mychaela Falconia <falcon@freecalypso.org>
parents: 254
diff changeset
27 * It appears that some miscreants have modified recent Linux kernel
9d9c241f2c84 libserial-newlnx experimental change to set ASYNC_LOW_LATENCY
Mychaela Falconia <falcon@freecalypso.org>
parents: 254
diff changeset
28 * versions (newer than linux-4.4.14 of Slackware 14.2) to insert
9d9c241f2c84 libserial-newlnx experimental change to set ASYNC_LOW_LATENCY
Mychaela Falconia <falcon@freecalypso.org>
parents: 254
diff changeset
29 * a delay of 10 ms before select system call returns when serial
9d9c241f2c84 libserial-newlnx experimental change to set ASYNC_LOW_LATENCY
Mychaela Falconia <falcon@freecalypso.org>
parents: 254
diff changeset
30 * input is ready; this Linux kernel misbehaviour majorly slows down
9d9c241f2c84 libserial-newlnx experimental change to set ASYNC_LOW_LATENCY
Mychaela Falconia <falcon@freecalypso.org>
parents: 254
diff changeset
31 * many of our operations. It appears that we need to set the
9d9c241f2c84 libserial-newlnx experimental change to set ASYNC_LOW_LATENCY
Mychaela Falconia <falcon@freecalypso.org>
parents: 254
diff changeset
32 * ASYNC_LOW_LATENCY flag in TIOCSSERIAL in order to get the old
9d9c241f2c84 libserial-newlnx experimental change to set ASYNC_LOW_LATENCY
Mychaela Falconia <falcon@freecalypso.org>
parents: 254
diff changeset
33 * sane behaviour back.
9d9c241f2c84 libserial-newlnx experimental change to set ASYNC_LOW_LATENCY
Mychaela Falconia <falcon@freecalypso.org>
parents: 254
diff changeset
34 */
9d9c241f2c84 libserial-newlnx experimental change to set ASYNC_LOW_LATENCY
Mychaela Falconia <falcon@freecalypso.org>
parents: 254
diff changeset
35 ioctl(target_fd, TIOCGSERIAL, &kernel_serial_settings);
9d9c241f2c84 libserial-newlnx experimental change to set ASYNC_LOW_LATENCY
Mychaela Falconia <falcon@freecalypso.org>
parents: 254
diff changeset
36 kernel_serial_settings.flags |= ASYNC_LOW_LATENCY;
9d9c241f2c84 libserial-newlnx experimental change to set ASYNC_LOW_LATENCY
Mychaela Falconia <falcon@freecalypso.org>
parents: 254
diff changeset
37 ioctl(target_fd, TIOCSSERIAL, &kernel_serial_settings);
254
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 return 0;
6984b76f3def beginning of libserial-newlnx: copy of libserial-orig
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 }