diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-09-01 11:44:13 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-09-01 11:44:13 +0200 |
commit | 76787a7e025fb4a8b83e29b2fbfdca8d5bd492b9 (patch) | |
tree | 9930441ae330aeebb4800b85cad88dc55ffcbebc | |
parent | ef15970d7ec904eb33ab572abc5de1f51b7e1cfa (diff) | |
download | busybox-w32-76787a7e025fb4a8b83e29b2fbfdca8d5bd492b9.tar.gz busybox-w32-76787a7e025fb4a8b83e29b2fbfdca8d5bd492b9.tar.bz2 busybox-w32-76787a7e025fb4a8b83e29b2fbfdca8d5bd492b9.zip |
libbb/speed_table.c: survive B115200 and B230400 not fitting into 16 bits
Seen on OSX.
While at it, expand baud table with B500000..B4000000
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | libbb/speed_table.c | 66 |
1 files changed, 55 insertions, 11 deletions
diff --git a/libbb/speed_table.c b/libbb/speed_table.c index 174d531b2..3870d4f93 100644 --- a/libbb/speed_table.c +++ b/libbb/speed_table.c | |||
@@ -10,7 +10,16 @@ | |||
10 | #include "libbb.h" | 10 | #include "libbb.h" |
11 | 11 | ||
12 | struct speed_map { | 12 | struct speed_map { |
13 | #if defined __FreeBSD__ | 13 | #if defined __FreeBSD__ \ |
14 | || (defined B115200 && B115200 > 0xffff) \ | ||
15 | || (defined B230400 && B230400 > 0xffff) \ | ||
16 | || (defined B460800 && B460800 > 0xffff) \ | ||
17 | || (defined B921600 && B921600 > 0xffff) \ | ||
18 | || (defined B1152000 && B1152000 > 0xffff) \ | ||
19 | || (defined B1000000 && B1000000 > 0xffff) \ | ||
20 | || (defined B2000000 && B2000000 > 0xffff) \ | ||
21 | || (defined B3000000 && B3000000 > 0xffff) \ | ||
22 | || (defined B4000000 && B4000000 > 0xffff) | ||
14 | /* On FreeBSD, B<num> constants don't fit into a short */ | 23 | /* On FreeBSD, B<num> constants don't fit into a short */ |
15 | unsigned speed; | 24 | unsigned speed; |
16 | #else | 25 | #else |
@@ -19,6 +28,7 @@ struct speed_map { | |||
19 | unsigned short value; | 28 | unsigned short value; |
20 | }; | 29 | }; |
21 | 30 | ||
31 | /* On Linux, Bxx constants are 0..15 (up to B38400) and 0x1001..0x100f */ | ||
22 | static const struct speed_map speeds[] = { | 32 | static const struct speed_map speeds[] = { |
23 | {B0, 0}, | 33 | {B0, 0}, |
24 | {B50, 50}, | 34 | {B50, 50}, |
@@ -37,28 +47,62 @@ static const struct speed_map speeds[] = { | |||
37 | #ifdef B19200 | 47 | #ifdef B19200 |
38 | {B19200, 19200}, | 48 | {B19200, 19200}, |
39 | #elif defined(EXTA) | 49 | #elif defined(EXTA) |
40 | {EXTA, 19200}, | 50 | {EXTA, 19200}, |
41 | #endif | 51 | #endif |
52 | /* 19200 = 0x4b00 */ | ||
53 | /* 38400 = 0x9600, this value would use bit#15 is not "/200" encoded: */ | ||
42 | #ifdef B38400 | 54 | #ifdef B38400 |
43 | {B38400, 38400/256 + 0x8000U}, | 55 | {B38400, 38400/200 + 0x8000u}, |
44 | #elif defined(EXTB) | 56 | #elif defined(EXTB) |
45 | {EXTB, 38400/256 + 0x8000U}, | 57 | {EXTB, 38400/200 + 0x8000u}, |
46 | #endif | 58 | #endif |
47 | #ifdef B57600 | 59 | #ifdef B57600 |
48 | {B57600, 57600/256 + 0x8000U}, | 60 | {B57600, 57600/200 + 0x8000u}, |
49 | #endif | 61 | #endif |
50 | #ifdef B115200 | 62 | #ifdef B115200 |
51 | {B115200, 115200/256 + 0x8000U}, | 63 | {B115200, 115200/200 + 0x8000u}, |
52 | #endif | 64 | #endif |
53 | #ifdef B230400 | 65 | #ifdef B230400 |
54 | {B230400, 230400/256 + 0x8000U}, | 66 | {B230400, 230400/200 + 0x8000u}, |
55 | #endif | 67 | #endif |
56 | #ifdef B460800 | 68 | #ifdef B460800 |
57 | {B460800, 460800/256 + 0x8000U}, | 69 | {B460800, 460800/200 + 0x8000u}, |
70 | #endif | ||
71 | #ifdef B576000 | ||
72 | {B576000, 576000/200 + 0x8000u}, | ||
58 | #endif | 73 | #endif |
59 | #ifdef B921600 | 74 | #ifdef B921600 |
60 | {B921600, 921600/256 + 0x8000U}, | 75 | {B921600, 921600/200 + 0x8000u}, |
76 | #endif | ||
77 | #ifdef B1152000 | ||
78 | {B1152000, 1152000/200 + 0x8000u}, | ||
79 | #endif | ||
80 | |||
81 | #ifdef B500000 | ||
82 | {B500000, 500000/200 + 0x8000u}, | ||
83 | #endif | ||
84 | #ifdef B1000000 | ||
85 | {B1000000, 1000000/200 + 0x8000u}, | ||
86 | #endif | ||
87 | #ifdef B1500000 | ||
88 | {B1500000, 1500000/200 + 0x8000u}, | ||
89 | #endif | ||
90 | #ifdef B2000000 | ||
91 | {B2000000, 2000000/200 + 0x8000u}, | ||
92 | #endif | ||
93 | #ifdef B2500000 | ||
94 | {B2500000, 2500000/200 + 0x8000u}, | ||
95 | #endif | ||
96 | #ifdef B3000000 | ||
97 | {B3000000, 3000000/200 + 0x8000u}, | ||
98 | #endif | ||
99 | #ifdef B3500000 | ||
100 | {B3500000, 3500000/200 + 0x8000u}, | ||
101 | #endif | ||
102 | #ifdef B4000000 | ||
103 | {B4000000, 4000000/200 + 0x8000u}, | ||
61 | #endif | 104 | #endif |
105 | /* 4000000/200 = 0x4e20, bit#15 still does not interfere with the value */ | ||
62 | }; | 106 | }; |
63 | 107 | ||
64 | enum { NUM_SPEEDS = ARRAY_SIZE(speeds) }; | 108 | enum { NUM_SPEEDS = ARRAY_SIZE(speeds) }; |
@@ -69,8 +113,8 @@ unsigned FAST_FUNC tty_baud_to_value(speed_t speed) | |||
69 | 113 | ||
70 | do { | 114 | do { |
71 | if (speed == speeds[i].speed) { | 115 | if (speed == speeds[i].speed) { |
72 | if (speeds[i].value & 0x8000U) { | 116 | if (speeds[i].value & 0x8000u) { |
73 | return ((unsigned long) (speeds[i].value) & 0x7fffU) * 256; | 117 | return ((unsigned long) (speeds[i].value) & 0x7fffU) * 200; |
74 | } | 118 | } |
75 | return speeds[i].value; | 119 | return speeds[i].value; |
76 | } | 120 | } |