diff options
author | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2022-09-07 11:25:41 +0200 |
---|---|---|
committer | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2022-09-07 11:25:41 +0200 |
commit | 50e868981dbe58a472bb79638f849262f0f432ef (patch) | |
tree | 6ee17cea8b425cf6fb1280d662044b9a6a94efc9 | |
parent | a1cdfde42c91b0c5bd2426fcb6f3fc442a5334fc (diff) | |
download | microcom-50e868981dbe58a472bb79638f849262f0f432ef.tar.gz microcom-50e868981dbe58a472bb79638f849262f0f432ef.tar.xz |
Move baudrate_to_flag() to serial.c, drop flag_to_baudrate()
serial.c is the only user of baudrate_to_flag(), so move the function (and
the needed table) into that file. flag_to_baudrate() is unused and so can
be dropped.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
-rw-r--r-- | microcom.c | 86 | ||||
-rw-r--r-- | microcom.h | 3 | ||||
-rw-r--r-- | serial.c | 74 |
3 files changed, 74 insertions, 89 deletions
@@ -61,92 +61,6 @@ void restore_terminal(void) tcsetattr(STDIN_FILENO, TCSANOW, &sots); } -static const struct { - int speed; - speed_t flag; -} bd_to_flg[] = { - { 50, B50 }, - { 75, B75 }, - { 110, B110 }, - { 134, B134 }, - { 150, B150 }, - { 200, B200 }, - { 300, B300 }, - { 600, B600 }, - { 1200, B1200}, - { 1800, B1800}, - { 2400, B2400}, - { 4800, B4800}, - { 9600, B9600}, - { 19200, B19200}, - { 38400, B38400}, - { 57600, B57600}, - { 115200, B115200}, - { 230400, B230400}, -#ifdef B460800 - { 460800, B460800}, -#endif -#ifdef B500000 - { 500000, B500000}, -#endif -#ifdef B576000 - { 576000, B576000}, -#endif -#ifdef B921600 - { 921600, B921600}, -#endif -#ifdef B1000000 - { 1000000, B1000000}, -#endif -#ifdef B1152000 - { 1152000, B1152000}, -#endif -#ifdef B1500000 - { 1500000, B1500000}, -#endif -#ifdef B2000000 - { 2000000, B2000000}, -#endif -#ifdef B2500000 - { 2500000, B2500000}, -#endif -#ifdef B3000000 - { 3000000, B3000000}, -#endif -#ifdef B3500000 - { 3500000, B3500000}, -#endif -#ifdef B4000000 - { 4000000, B4000000}, -#endif -}; - -int baudrate_to_flag(int speed, speed_t *flag) -{ - size_t i; - - /* possible optimisation: binary search for speed */ - for (i = 0; i < ARRAY_SIZE(bd_to_flg); ++i) - if (bd_to_flg[i].speed == speed) { - *flag = bd_to_flg[i].flag; - return 0; - } - - printf("unknown speed: %d\n", speed); - return -1; -} - -int flag_to_baudrate(speed_t speed) -{ - size_t i; - - for (i = 0; i < ARRAY_SIZE(bd_to_flg); ++i) - if (bd_to_flg[i].flag == speed) - return bd_to_flg[i].speed; - - printf("unknown speed flag: 0x%x\n", (unsigned)speed); - return -1; -} void microcom_exit(int signal) { @@ -69,9 +69,6 @@ void microcom_cmd_usage(char *str); void main_usage(int exitcode, char *str, char *dev); -int flag_to_baudrate(speed_t speed); -int baudrate_to_flag(int speed, speed_t *flag); - extern struct ios_ops *ios; extern int debug; extern int opt_force; @@ -80,6 +80,80 @@ static int serial_set_handshake_line(struct ios_ops *ios, int pin, int enable) return ret; } +static const struct { + int speed; + speed_t flag; +} bd_to_flg[] = { + { 50, B50 }, + { 75, B75 }, + { 110, B110 }, + { 134, B134 }, + { 150, B150 }, + { 200, B200 }, + { 300, B300 }, + { 600, B600 }, + { 1200, B1200}, + { 1800, B1800}, + { 2400, B2400}, + { 4800, B4800}, + { 9600, B9600}, + { 19200, B19200}, + { 38400, B38400}, + { 57600, B57600}, + { 115200, B115200}, + { 230400, B230400}, +#ifdef B460800 + { 460800, B460800}, +#endif +#ifdef B500000 + { 500000, B500000}, +#endif +#ifdef B576000 + { 576000, B576000}, +#endif +#ifdef B921600 + { 921600, B921600}, +#endif +#ifdef B1000000 + { 1000000, B1000000}, +#endif +#ifdef B1152000 + { 1152000, B1152000}, +#endif +#ifdef B1500000 + { 1500000, B1500000}, +#endif +#ifdef B2000000 + { 2000000, B2000000}, +#endif +#ifdef B2500000 + { 2500000, B2500000}, +#endif +#ifdef B3000000 + { 3000000, B3000000}, +#endif +#ifdef B3500000 + { 3500000, B3500000}, +#endif +#ifdef B4000000 + { 4000000, B4000000}, +#endif +}; + +static int baudrate_to_flag(int speed, speed_t *flag) +{ + size_t i; + + /* possible optimisation: binary search for speed */ + for (i = 0; i < ARRAY_SIZE(bd_to_flg); ++i) + if (bd_to_flg[i].speed == speed) { + *flag = bd_to_flg[i].flag; + return 0; + } + + return -1; +} + static int serial_set_speed(struct ios_ops *ios, unsigned long speed) { struct termios pts; /* termios settings on port */ |