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>
This commit is contained in:
parent
ef15970d7e
commit
76787a7e02
@ -10,7 +10,16 @@
|
|||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
|
|
||||||
struct speed_map {
|
struct speed_map {
|
||||||
#if defined __FreeBSD__
|
#if defined __FreeBSD__ \
|
||||||
|
|| (defined B115200 && B115200 > 0xffff) \
|
||||||
|
|| (defined B230400 && B230400 > 0xffff) \
|
||||||
|
|| (defined B460800 && B460800 > 0xffff) \
|
||||||
|
|| (defined B921600 && B921600 > 0xffff) \
|
||||||
|
|| (defined B1152000 && B1152000 > 0xffff) \
|
||||||
|
|| (defined B1000000 && B1000000 > 0xffff) \
|
||||||
|
|| (defined B2000000 && B2000000 > 0xffff) \
|
||||||
|
|| (defined B3000000 && B3000000 > 0xffff) \
|
||||||
|
|| (defined B4000000 && B4000000 > 0xffff)
|
||||||
/* On FreeBSD, B<num> constants don't fit into a short */
|
/* On FreeBSD, B<num> constants don't fit into a short */
|
||||||
unsigned speed;
|
unsigned speed;
|
||||||
#else
|
#else
|
||||||
@ -19,6 +28,7 @@ struct speed_map {
|
|||||||
unsigned short value;
|
unsigned short value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* On Linux, Bxx constants are 0..15 (up to B38400) and 0x1001..0x100f */
|
||||||
static const struct speed_map speeds[] = {
|
static const struct speed_map speeds[] = {
|
||||||
{B0, 0},
|
{B0, 0},
|
||||||
{B50, 50},
|
{B50, 50},
|
||||||
@ -37,28 +47,62 @@ static const struct speed_map speeds[] = {
|
|||||||
#ifdef B19200
|
#ifdef B19200
|
||||||
{B19200, 19200},
|
{B19200, 19200},
|
||||||
#elif defined(EXTA)
|
#elif defined(EXTA)
|
||||||
{EXTA, 19200},
|
{EXTA, 19200},
|
||||||
#endif
|
#endif
|
||||||
|
/* 19200 = 0x4b00 */
|
||||||
|
/* 38400 = 0x9600, this value would use bit#15 is not "/200" encoded: */
|
||||||
#ifdef B38400
|
#ifdef B38400
|
||||||
{B38400, 38400/256 + 0x8000U},
|
{B38400, 38400/200 + 0x8000u},
|
||||||
#elif defined(EXTB)
|
#elif defined(EXTB)
|
||||||
{EXTB, 38400/256 + 0x8000U},
|
{EXTB, 38400/200 + 0x8000u},
|
||||||
#endif
|
#endif
|
||||||
#ifdef B57600
|
#ifdef B57600
|
||||||
{B57600, 57600/256 + 0x8000U},
|
{B57600, 57600/200 + 0x8000u},
|
||||||
#endif
|
#endif
|
||||||
#ifdef B115200
|
#ifdef B115200
|
||||||
{B115200, 115200/256 + 0x8000U},
|
{B115200, 115200/200 + 0x8000u},
|
||||||
#endif
|
#endif
|
||||||
#ifdef B230400
|
#ifdef B230400
|
||||||
{B230400, 230400/256 + 0x8000U},
|
{B230400, 230400/200 + 0x8000u},
|
||||||
#endif
|
#endif
|
||||||
#ifdef B460800
|
#ifdef B460800
|
||||||
{B460800, 460800/256 + 0x8000U},
|
{B460800, 460800/200 + 0x8000u},
|
||||||
|
#endif
|
||||||
|
#ifdef B576000
|
||||||
|
{B576000, 576000/200 + 0x8000u},
|
||||||
#endif
|
#endif
|
||||||
#ifdef B921600
|
#ifdef B921600
|
||||||
{B921600, 921600/256 + 0x8000U},
|
{B921600, 921600/200 + 0x8000u},
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef B1152000
|
||||||
|
{B1152000, 1152000/200 + 0x8000u},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef B500000
|
||||||
|
{B500000, 500000/200 + 0x8000u},
|
||||||
|
#endif
|
||||||
|
#ifdef B1000000
|
||||||
|
{B1000000, 1000000/200 + 0x8000u},
|
||||||
|
#endif
|
||||||
|
#ifdef B1500000
|
||||||
|
{B1500000, 1500000/200 + 0x8000u},
|
||||||
|
#endif
|
||||||
|
#ifdef B2000000
|
||||||
|
{B2000000, 2000000/200 + 0x8000u},
|
||||||
|
#endif
|
||||||
|
#ifdef B2500000
|
||||||
|
{B2500000, 2500000/200 + 0x8000u},
|
||||||
|
#endif
|
||||||
|
#ifdef B3000000
|
||||||
|
{B3000000, 3000000/200 + 0x8000u},
|
||||||
|
#endif
|
||||||
|
#ifdef B3500000
|
||||||
|
{B3500000, 3500000/200 + 0x8000u},
|
||||||
|
#endif
|
||||||
|
#ifdef B4000000
|
||||||
|
{B4000000, 4000000/200 + 0x8000u},
|
||||||
|
#endif
|
||||||
|
/* 4000000/200 = 0x4e20, bit#15 still does not interfere with the value */
|
||||||
};
|
};
|
||||||
|
|
||||||
enum { NUM_SPEEDS = ARRAY_SIZE(speeds) };
|
enum { NUM_SPEEDS = ARRAY_SIZE(speeds) };
|
||||||
@ -69,8 +113,8 @@ unsigned FAST_FUNC tty_baud_to_value(speed_t speed)
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
if (speed == speeds[i].speed) {
|
if (speed == speeds[i].speed) {
|
||||||
if (speeds[i].value & 0x8000U) {
|
if (speeds[i].value & 0x8000u) {
|
||||||
return ((unsigned long) (speeds[i].value) & 0x7fffU) * 256;
|
return ((unsigned long) (speeds[i].value) & 0x7fffU) * 200;
|
||||||
}
|
}
|
||||||
return speeds[i].value;
|
return speeds[i].value;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user