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 tarball for details.
18 static const struct speed_map speeds[] = {
39 {B38400, 38400/256 + 0x8000U},
41 {EXTB, 38400/256 + 0x8000U},
44 {B57600, 57600/256 + 0x8000U},
47 {B115200, 115200/256 + 0x8000U},
50 {B230400, 230400/256 + 0x8000U},
53 {B460800, 460800/256 + 0x8000U},
57 enum { NUM_SPEEDS = (sizeof(speeds) / sizeof(struct speed_map)) };
59 unsigned int tty_baud_to_value(speed_t speed)
64 if (speed == speeds[i].speed) {
65 if (speeds[i].value & 0x8000U) {
66 return ((unsigned long) (speeds[i].value) & 0x7fffU) * 256;
68 return speeds[i].value;
70 } while (++i < NUM_SPEEDS);
75 speed_t tty_value_to_baud(unsigned int value)
80 if (value == tty_baud_to_value(speeds[i].speed)) {
81 return speeds[i].speed;
83 } while (++i < NUM_SPEEDS);
97 for (v = 0 ; v < 500000 ; v++) {
98 s = tty_value_to_baud(v);
99 if (s == (speed_t) -1) {
102 printf("v = %lu -- s = %0lo\n", v, (unsigned long) s);
105 printf("-------------------------------\n");
107 for (s = 0 ; s < 010017+1 ; s++) {
108 v = tty_baud_to_value(s);
112 printf("v = %lu -- s = %0lo\n", v, (unsigned long) s);