1 // SPDX-License-Identifier: GPL-2.0+
4 * Murray Jensen <Murray.Jensen@csiro.au>
13 #if defined(__sun__) || \
14 defined(__OpenBSD__) || \
15 defined(__FreeBSD__) || \
16 defined(__NetBSD__) || \
18 static struct termios tios = { BRKINT, 0, B115200|CS8|CREAD, 0, { 0 } };
20 static struct termios tios = { BRKINT, 0, B115200|CS8|CREAD, 0, 0 };
23 static struct speedmap {
27 { "50", B50 }, { "75", B75 }, { "110", B110 },
28 { "134", B134 }, { "150", B150 }, { "200", B200 },
29 { "300", B300 }, { "600", B600 }, { "1200", B1200 },
30 { "1800", B1800 }, { "2400", B2400 }, { "4800", B4800 },
31 { "9600", B9600 }, { "19200", B19200 }, { "38400", B38400 },
36 { "115200", B115200 },
38 { "153600", B153600 },
40 { "230400", B230400 },
42 { "307200", B307200 },
48 static int nspeeds = sizeof speedmap / sizeof speedmap[0];
53 struct speedmap *smp = speedmap, *esmp = &speedmap[nspeeds];
56 if (strcmp(str, smp->str) == 0)
64 serialopen(char *device, speed_t speed)
68 if (cfsetospeed(&tios, speed) < 0)
71 if ((fd = open(device, O_RDWR)) < 0)
74 if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
83 serialreadchar(int fd, int timeout)
96 /* this is a fucking horrible quick hack - fix this */
98 if ((n = select(fd + 1, &fds, 0, 0, &tv)) < 0)
102 return SERIAL_TIMEOUT;
104 if ((n = read(fd, &ch, 1)) < 0)
114 serialwrite(int fd, char *buf, int len)
119 n = write(fd, buf, len);