aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-06-20 16:17:24 +0000
committerlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-06-20 16:17:24 +0000
commite1b5acf5d94148d9dba6079344540afa8c1f5cf2 (patch)
treed98ce186c5d5a4f6746f38e637d412aad0b6acdd
parent761d546db9f7fe6006dfba468e5e5ca6666e277b (diff)
downloadbusybox-w32-e1b5acf5d94148d9dba6079344540afa8c1f5cf2.tar.gz
busybox-w32-e1b5acf5d94148d9dba6079344540afa8c1f5cf2.tar.bz2
busybox-w32-e1b5acf5d94148d9dba6079344540afa8c1f5cf2.zip
Revert the last two patches to go back to a state before this file was
controversial. git-svn-id: svn://busybox.net/trunk/busybox@15439 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--libbb/speed_table.c110
1 files changed, 94 insertions, 16 deletions
diff --git a/libbb/speed_table.c b/libbb/speed_table.c
index d6073f12f..d690d55dc 100644
--- a/libbb/speed_table.c
+++ b/libbb/speed_table.c
@@ -7,33 +7,111 @@
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */ 8 */
9 9
10#include <termios.h>
10#include "libbb.h" 11#include "libbb.h"
11 12
12static const unsigned short speeds[] = { 13struct speed_map {
13 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 14 unsigned short speed;
14 19200, 38400, 57600>>8, 115200>>8, 230400>>8, 460800>>8, 500000>>8, 15 unsigned short value;
15 576000>>8, 921600>>8, 1000000>>8, 1152000>>8, 1500000>>8, 2000000>>8,
16 3000000>>8, 3500000>>8, 4000000>>8
17}; 16};
18 17
19unsigned int tty_baud_to_value(speed_t speed) 18static const struct speed_map speeds[] = {
19 {B0, 0},
20 {B50, 50},
21 {B75, 75},
22 {B110, 110},
23 {B134, 134},
24 {B150, 150},
25 {B200, 200},
26 {B300, 300},
27 {B600, 600},
28 {B1200, 1200},
29 {B1800, 1800},
30 {B2400, 2400},
31 {B4800, 4800},
32 {B9600, 9600},
33#ifdef B19200
34 {B19200, 19200},
35#elif defined(EXTA)
36 {EXTA, 19200},
37#endif
38#ifdef B38400
39 {B38400, 38400/256 + 0x8000U},
40#elif defined(EXTB)
41 {EXTB, 38400/256 + 0x8000U},
42#endif
43#ifdef B57600
44 {B57600, 57600/256 + 0x8000U},
45#endif
46#ifdef B115200
47 {B115200, 115200/256 + 0x8000U},
48#endif
49#ifdef B230400
50 {B230400, 230400/256 + 0x8000U},
51#endif
52#ifdef B460800
53 {B460800, 460800/256 + 0x8000U},
54#endif
55};
56
57enum { NUM_SPEEDS = (sizeof(speeds) / sizeof(struct speed_map)) };
58
59unsigned long bb_baud_to_value(speed_t speed)
20{ 60{
21 int i; 61 int i = 0;
22 62
23 for (i=0; i<sizeof(speeds) / sizeof(*speeds); i++) 63 do {
24 if (speed == speeds[i] * (i>15 ? 256 : 1)) 64 if (speed == speeds[i].speed) {
25 return i>15 ? (i+4096-14) : i; 65 if (speeds[i].value & 0x8000U) {
66 return ((unsigned long) (speeds[i].value) & 0x7fffU) * 256;
67 }
68 return speeds[i].value;
69 }
70 } while (++i < NUM_SPEEDS);
26 71
27 return 0; 72 return 0;
28} 73}
29 74
30speed_t tty_value_to_baud(unsigned int value) 75speed_t bb_value_to_baud(unsigned long value)
76{
77 int i = 0;
78
79 do {
80 if (value == bb_baud_to_value(speeds[i].speed)) {
81 return speeds[i].speed;
82 }
83 } while (++i < NUM_SPEEDS);
84
85 return (speed_t) - 1;
86}
87
88#if 0
89/* testing code */
90#include <stdio.h>
91
92int main(void)
31{ 93{
32 int i; 94 unsigned long v;
95 speed_t s;
33 96
34 for (i=0; i<sizeof(speeds) / sizeof(*speeds); i++) 97 for (v = 0 ; v < 500000 ; v++) {
35 if (value == (i>15 ? (i+4096-14) : i)) 98 s = bb_value_to_baud(v);
36 return speeds[i] * (i>15 ? 256 : 1); 99 if (s == (speed_t) -1) {
100 continue;
101 }
102 printf("v = %lu -- s = %0lo\n", v, (unsigned long) s);
103 }
37 104
38 return -1; 105 printf("-------------------------------\n");
106
107 for (s = 0 ; s < 010017+1 ; s++) {
108 v = bb_baud_to_value(s);
109 if (!v) {
110 continue;
111 }
112 printf("v = %lu -- s = %0lo\n", v, (unsigned long) s);
113 }
114
115 return 0;
39} 116}
117#endif