1 /* vi: set sw=4 ts=4: */
3 * compact speed_t <-> speed functions for busybox
5 * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org>
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
13 #if defined __FreeBSD__
14 /* On FreeBSD, B<num> constants don't fit into a short */
22 static const struct speed_map speeds[] = {
43 {B38400, 38400/256 + 0x8000U},
45 {EXTB, 38400/256 + 0x8000U},
48 {B57600, 57600/256 + 0x8000U},
51 {B115200, 115200/256 + 0x8000U},
54 {B230400, 230400/256 + 0x8000U},
57 {B460800, 460800/256 + 0x8000U},
60 {B921600, 921600/256 + 0x8000U},
64 enum { NUM_SPEEDS = ARRAY_SIZE(speeds) };
66 unsigned FAST_FUNC tty_baud_to_value(speed_t speed)
71 if (speed == speeds[i].speed) {
72 if (speeds[i].value & 0x8000U) {
73 return ((unsigned long) (speeds[i].value) & 0x7fffU) * 256;
75 return speeds[i].value;
77 } while (++i < NUM_SPEEDS);
82 speed_t FAST_FUNC tty_value_to_baud(unsigned int value)
87 if (value == tty_baud_to_value(speeds[i].speed)) {
88 return speeds[i].speed;
90 } while (++i < NUM_SPEEDS);
104 for (v = 0 ; v < 1000000; v++) {
105 s = tty_value_to_baud(v);
106 if (s == (speed_t) -1) {
109 printf("v = %lu -- s = %0lo\n", v, (unsigned long) s);
112 printf("-------------------------------\n");
114 for (s = 0 ; s < 010017+1; s++) {
115 v = tty_baud_to_value(s);
119 printf("v = %lu -- s = %0lo\n", v, (unsigned long) s);