summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>2022-09-07 11:25:41 +0200
committerUwe Kleine-König <u.kleine-koenig@pengutronix.de>2022-09-07 11:25:41 +0200
commit50e868981dbe58a472bb79638f849262f0f432ef (patch)
tree6ee17cea8b425cf6fb1280d662044b9a6a94efc9
parenta1cdfde42c91b0c5bd2426fcb6f3fc442a5334fc (diff)
downloadmicrocom-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.c86
-rw-r--r--microcom.h3
-rw-r--r--serial.c74
3 files changed, 74 insertions, 89 deletions
diff --git a/microcom.c b/microcom.c
index 5bda7b4..2b3d484 100644
--- a/microcom.c
+++ b/microcom.c
@@ -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)
{
diff --git a/microcom.h b/microcom.h
index 0956e7d..54aea56 100644
--- a/microcom.h
+++ b/microcom.h
@@ -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;
diff --git a/serial.c b/serial.c
index 07be8ed..e4dc39c 100644
--- a/serial.c
+++ b/serial.c
@@ -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 */