FreeCalypso > hg > freecalypso-tools
comparison 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 |
comparison
equal
deleted
inserted
replaced
607:d5abcbbf7432 | 608:9d9c241f2c84 |
---|---|
3 */ | 3 */ |
4 | 4 |
5 #include <sys/types.h> | 5 #include <sys/types.h> |
6 #include <sys/file.h> | 6 #include <sys/file.h> |
7 #include <sys/ioctl.h> | 7 #include <sys/ioctl.h> |
8 #include <linux/serial.h> | |
8 #include <stdio.h> | 9 #include <stdio.h> |
9 #include <stdlib.h> | 10 #include <stdlib.h> |
10 #include <unistd.h> | 11 #include <unistd.h> |
11 | 12 |
12 int target_fd; | 13 int target_fd; |
13 | 14 |
14 open_serial_port(ttyport) | 15 open_serial_port(ttyport) |
15 char *ttyport; | 16 char *ttyport; |
16 { | 17 { |
18 struct serial_struct kernel_serial_settings; | |
19 | |
17 target_fd = open(ttyport, O_RDWR|O_NONBLOCK); | 20 target_fd = open(ttyport, O_RDWR|O_NONBLOCK); |
18 if (target_fd < 0) { | 21 if (target_fd < 0) { |
19 perror(ttyport); | 22 perror(ttyport); |
20 exit(1); | 23 exit(1); |
21 } | 24 } |
22 ioctl(target_fd, TIOCEXCL); | 25 ioctl(target_fd, TIOCEXCL); |
26 /* | |
27 * It appears that some miscreants have modified recent Linux kernel | |
28 * versions (newer than linux-4.4.14 of Slackware 14.2) to insert | |
29 * a delay of 10 ms before select system call returns when serial | |
30 * input is ready; this Linux kernel misbehaviour majorly slows down | |
31 * many of our operations. It appears that we need to set the | |
32 * ASYNC_LOW_LATENCY flag in TIOCSSERIAL in order to get the old | |
33 * sane behaviour back. | |
34 */ | |
35 ioctl(target_fd, TIOCGSERIAL, &kernel_serial_settings); | |
36 kernel_serial_settings.flags |= ASYNC_LOW_LATENCY; | |
37 ioctl(target_fd, TIOCSSERIAL, &kernel_serial_settings); | |
23 return 0; | 38 return 0; |
24 } | 39 } |