diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2010-07-24 16:12:49 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2010-07-24 16:12:49 +0000 |
commit | a5bbb06141592892d13e294d67dc7295accd1c3a (patch) | |
tree | 6381eab26969206f6c0996cbbac5064b22b44a41 /cpukit/libcsupport | |
parent | 2010-07-23 Vinu Rajashekhar <vinutheraj@gmail.com> (diff) | |
download | rtems-a5bbb06141592892d13e294d67dc7295accd1c3a.tar.bz2 |
2010-07-24 Joel Sherrill <joel.sherrill@oarcorp.com>
* libcsupport/Makefile.am, libcsupport/src/termios_baud2num.c,
libcsupport/src/termios_num2baud.c: Use RTEMS associations to
simplify code and make easier for coverage.
* libcsupport/src/termios_baudtable.c: New file.
Diffstat (limited to 'cpukit/libcsupport')
-rw-r--r-- | cpukit/libcsupport/Makefile.am | 2 | ||||
-rw-r--r-- | cpukit/libcsupport/src/termios_baud2num.c | 31 | ||||
-rw-r--r-- | cpukit/libcsupport/src/termios_baudtable.c | 42 | ||||
-rw-r--r-- | cpukit/libcsupport/src/termios_num2baud.c | 30 |
4 files changed, 56 insertions, 49 deletions
diff --git a/cpukit/libcsupport/Makefile.am b/cpukit/libcsupport/Makefile.am index c3150e7fa6..9eb4df5c24 100644 --- a/cpukit/libcsupport/Makefile.am +++ b/cpukit/libcsupport/Makefile.am @@ -57,7 +57,7 @@ TERMIOS_C_FILES = src/cfgetispeed.c src/cfgetospeed.c src/cfsetispeed.c \ src/tcflow.c src/tcflush.c src/tcgetpgrp.c src/tcsendbreak.c \ src/tcsetpgrp.c src/termios.c src/termiosinitialize.c \ src/termios_baud2index.c src/termios_baud2num.c src/termios_num2baud.c \ - src/termios_setinitialbaud.c + src/termios_setinitialbaud.c src/termios_baudtable.c SYSTEM_CALL_C_FILES = src/open.c src/close.c src/read.c src/write.c \ src/write_r.c \ diff --git a/cpukit/libcsupport/src/termios_baud2num.c b/cpukit/libcsupport/src/termios_baud2num.c index 67a5831b06..57b908ebee 100644 --- a/cpukit/libcsupport/src/termios_baud2num.c +++ b/cpukit/libcsupport/src/termios_baud2num.c @@ -15,36 +15,19 @@ #include <sys/termios.h> #include <rtems/termiostypes.h> +#include <rtems/assoc.h> + +extern rtems_assoc_t termios_assoc_table[]; int32_t rtems_termios_baud_to_number( int termios_baud ) { - int32_t baud; + int baud; - switch (termios_baud) { - case B0: baud = 0; break; - case B50: baud = 50; break; - case B75: baud = 75; break; - case B110: baud = 110; break; - case B134: baud = 134; break; - case B150: baud = 150; break; - case B200: baud = 200; break; - case B300: baud = 300; break; - case B600: baud = 600; break; - case B1200: baud = 1200; break; - case B1800: baud = 1800; break; - case B2400: baud = 2400; break; - case B4800: baud = 4800; break; - case B9600: baud = 9600; break; - case B19200: baud = 19200; break; - case B38400: baud = 38400; break; - case B57600: baud = 57600; break; - case B115200: baud = 115200; break; - case B230400: baud = 230400; break; - case B460800: baud = 460800; break; - default: baud = -1; break; - } + baud = rtems_assoc_local_by_remote( termios_assoc_table, termios_baud ); + if ( baud == 0 && termios_baud != 0 ) + return -1; return baud; } diff --git a/cpukit/libcsupport/src/termios_baudtable.c b/cpukit/libcsupport/src/termios_baudtable.c new file mode 100644 index 0000000000..92d1c6b809 --- /dev/null +++ b/cpukit/libcsupport/src/termios_baudtable.c @@ -0,0 +1,42 @@ +/* + * COPYRIGHT (c) 1989-2010. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <sys/termios.h> +#include <rtems/termiostypes.h> +#include <rtems/assoc.h> + +rtems_assoc_t termios_assoc_table[] = { + { "B0", 0, B0 }, + { "B50", 50, B50 }, + { "B75", 75, B75 }, + { "B110", 110, B110 }, + { "B134", 134, B134 }, + { "B150", 150, B150 }, + { "B200", 200, B200 }, + { "B300", 300, B300 }, + { "B600", 600, B600 }, + { "B1200", 1200, B1200 }, + { "B1800", 1800, B1800 }, + { "B2400", 2400, B2400 }, + { "B4800", 4800, B4800 }, + { "B9600", 9600, B9600 }, + { "B19200", 19200, B19200 }, + { "B38400", 38400, B38400 }, + { "B57600", 57600, B57600 }, + { "B115200", 115200, B115200 }, + { "B230400", 230400, B230400 }, + { "B460800", 460800, B460800 }, + { NULL, 0, 0 } +}; diff --git a/cpukit/libcsupport/src/termios_num2baud.c b/cpukit/libcsupport/src/termios_num2baud.c index 465a79794d..3725609135 100644 --- a/cpukit/libcsupport/src/termios_num2baud.c +++ b/cpukit/libcsupport/src/termios_num2baud.c @@ -15,6 +15,9 @@ #include <sys/termios.h> #include <rtems/termiostypes.h> +#include <rtems/assoc.h> + +extern rtems_assoc_t termios_assoc_table[]; int rtems_termios_number_to_baud( int32_t baud @@ -22,29 +25,8 @@ int rtems_termios_number_to_baud( { int termios_baud; - switch (baud) { - case 0: termios_baud = B0; break; - case 50: termios_baud = B50; break; - case 75: termios_baud = B75; break; - case 110: termios_baud = B110; break; - case 134: termios_baud = B134; break; - case 150: termios_baud = B150; break; - case 200: termios_baud = B200; break; - case 300: termios_baud = B300; break; - case 600: termios_baud = B600; break; - case 1200: termios_baud = B1200; break; - case 1800: termios_baud = B1800; break; - case 2400: termios_baud = B2400; break; - case 4800: termios_baud = B4800; break; - case 9600: termios_baud = B9600; break; - case 19200: termios_baud = B19200; break; - case 38400: termios_baud = B38400; break; - case 57600: termios_baud = B57600; break; - case 115200: termios_baud = B115200; break; - case 230400: termios_baud = B230400; break; - case 460800: termios_baud = B460800; break; - default: termios_baud = -1; break; - } - + termios_baud = rtems_assoc_remote_by_local( termios_assoc_table, baud ); + if ( termios_baud == 0 && baud != 0 ) + return -1; return termios_baud; } |