aboutsummaryrefslogtreecommitdiffstats
path: root/sdk/dev
diff options
context:
space:
mode:
Diffstat (limited to 'sdk/dev')
-rw-r--r--sdk/dev/Makefile.in19
-rw-r--r--sdk/dev/bind.conf0
-rw-r--r--sdk/dev/empty.c15
-rw-r--r--sdk/dev/flowctrl.c47
-rw-r--r--sdk/dev/format.c64
-rw-r--r--sdk/dev/inkey.c76
-rw-r--r--sdk/dev/input.c34
-rw-r--r--sdk/dev/interactive.c35
-rw-r--r--sdk/dev/make.conf5
-rw-r--r--sdk/dev/speed.c75
-rw-r--r--sdk/dev/stty.c29
-rw-r--r--sdk/dev/termcap.h17
-rw-r--r--sdk/dev/tty.h72
-rw-r--r--sdk/dev/waitfor.c39
-rw-r--r--sdk/dev/waitsync.c32
-rw-r--r--sdk/dev/xmit.c31
16 files changed, 590 insertions, 0 deletions
diff --git a/sdk/dev/Makefile.in b/sdk/dev/Makefile.in
new file mode 100644
index 0000000..1375154
--- /dev/null
+++ b/sdk/dev/Makefile.in
@@ -0,0 +1,19 @@
+#
+# Template to build device interface library.
+# $Id$
+# Copyright (c) 1997 by Tycho Softworks.
+#
+
+OBJS = inkey.o empty.o input.o waitfor.o waitsync.o xmit.o \
+ speed.o format.o flowctrl.o interactive.o stty.o
+
+.c.o:
+ $(CC) $(CFLAGS) $(OPTIMIZE) -I.. -o $@ -c $<
+ $(AR) r ../lib/libdev.a $@
+
+all: $(OBJS)
+ ranlib ../lib/libdev.a
+
+clean:
+ rm *.o
+
diff --git a/sdk/dev/bind.conf b/sdk/dev/bind.conf
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/sdk/dev/bind.conf
diff --git a/sdk/dev/empty.c b/sdk/dev/empty.c
new file mode 100644
index 0000000..87114a3
--- /dev/null
+++ b/sdk/dev/empty.c
@@ -0,0 +1,15 @@
+/*
+ * Empty the serial input fifo buffer.
+ * $Id$
+ * Copyright (c) 1997 by Tycho Softworks.
+ * For conditions of distribution and reuse see product license.
+ */
+
+#include <dev/tty.h>
+
+void empty(int fd)
+{
+ while(inkey(fd, 0) > -1)
+ continue;
+}
+
diff --git a/sdk/dev/flowctrl.c b/sdk/dev/flowctrl.c
new file mode 100644
index 0000000..7977b1c
--- /dev/null
+++ b/sdk/dev/flowctrl.c
@@ -0,0 +1,47 @@
+/*
+ * Serial line flow control option settings.
+ * $Id$
+ * Copyright (c) 1997 by Tycho Softworks.
+ * For conditions of distribution and reuse see product license.
+ */
+
+#include <dev/tty.h>
+#ifndef TERMIOS_H_MISSING
+#include <termios.h>
+#endif
+
+#ifndef CRTSCTS
+#ifdef CTSFLOW
+#define CRTSCTS CTSFLOW | CRTSFL
+#endif
+#endif
+
+int setflowctrl(stty_t stty, FLOWCONTROL flow)
+{
+#ifndef TERMIOS_H_MISSING
+
+ struct termios *tios = stty;
+ tios->c_cflag &= ~CRTSCTS;
+ tios->c_iflag &= ~(IXON | IXOFF | IXANY);
+
+ switch(flow)
+ {
+ case FC_HARD:
+ tios->c_cflag |= CRTSCTS;
+ break;
+ case FC_SOFT:
+ tios->c_iflag |= (IXON | IXOFF | IXANY);
+ break;
+ case FC_FULL:
+ tios->c_cflag |= CRTSCTS;
+ tios->c_iflag |= (IXON | IXOFF | IXANY);
+ break;
+ }
+#endif
+ return 0;
+}
+
+
+
+
+
diff --git a/sdk/dev/format.c b/sdk/dev/format.c
new file mode 100644
index 0000000..508ec6c
--- /dev/null
+++ b/sdk/dev/format.c
@@ -0,0 +1,64 @@
+/*
+ * Specify serial port data line format.
+ * $Id$
+ * Copyright (c) 1997 by Tycho Softworks.
+ * For conditions of distribution and reuse see product license.
+ */
+
+#include <dev/tty.h>
+#ifndef TERMIOS_H_MISSING
+#include <termios.h>
+#endif
+
+int setformat(stty_t stty, char *format)
+{
+#ifndef TERMIOS_H_MISSING
+ struct termios *tios = stty;
+
+ tios->c_cflag &= ~CSIZE;
+ if(format[2] == '1')
+ tios->c_cflag &= ~CSTOPB;
+ else
+ tios->c_cflag |= CSTOPB;
+
+ switch(format[0])
+ {
+ case '5':
+ tios->c_cflag |= CS5;
+ break;
+ case '6':
+ tios->c_cflag |= CS6;
+ break;
+ case '7':
+ tios->c_cflag |= CS7;
+ break;
+ case '8':
+ tios->c_cflag |= CS8;
+ break;
+ }
+
+ switch(format[1])
+ {
+ case 'n':
+ case 'N':
+ tios->c_cflag &= ~(PARODD | PARENB);
+ break;
+ case 'e':
+ case 'E':
+ tios->c_cflag |= PARENB;
+ tios->c_cflag &= ~PARODD;
+ break;
+ case 'o':
+ case 'O':
+ tios->c_cflag |= (PARENB | PARODD);
+ break;
+ }
+
+#endif
+ return 0;
+}
+
+
+
+
+
diff --git a/sdk/dev/inkey.c b/sdk/dev/inkey.c
new file mode 100644
index 0000000..1003905
--- /dev/null
+++ b/sdk/dev/inkey.c
@@ -0,0 +1,76 @@
+/*
+ * Wait and read single byte input from device.
+ * $Id$
+ * Copyright (c) 1997 by Tycho Softworks.
+ * For conditions of distribution and reuse see product license.
+ */
+
+#include <dev/tty.h>
+#include <std/select.h>
+#include <std/poll.h>
+
+#ifndef SYS_POLL_H_MISSING
+#define USE_POLL
+#endif
+
+#ifndef POLL_H_MISSING
+#define USE_POLL
+#endif
+
+#ifdef USE_POLL
+
+int inkey(fd_t fd, int timeout)
+{
+ struct pollfd poller;
+ uchar buf;
+
+ poller.fd = fd;
+ poller.revents = 0;
+ poller.events = POLLIN ;
+
+ if(!poll(&poller, 1, timeout))
+ return -1;
+
+ if(poller.revents & (POLLERR | POLLHUP))
+ return -1;
+
+ if(read(fd, &buf, 1) != 1)
+ return -1;
+
+ return buf;
+}
+
+#else
+
+int inkey(fd_t fd, int timeout)
+{
+ fd_set inp,out,exc;
+ struct timeval timer;
+ uchar buf;
+
+ FD_ZERO(&inp);
+ FD_ZERO(&out);
+ FD_ZERO(&exc);
+
+ FD_SET(fd, &inp);
+ FD_SET(fd, &exc);
+
+ timer.tv_sec = timeout / 1000;
+ timer.tv_usec = timeout % 1000;
+
+ if(!select(fd + 1, &inp, &out, &exc, &timer))
+ return -1;
+
+ if(FD_ISSET(fd, &exc))
+ return -1;
+
+ if(FD_ISSET(fd, &inp))
+ {
+ if(read(fd, &buf, 1) != 1)
+ return -1;
+ return buf;
+ }
+ return -1;
+}
+
+#endif
diff --git a/sdk/dev/input.c b/sdk/dev/input.c
new file mode 100644
index 0000000..95494d3
--- /dev/null
+++ b/sdk/dev/input.c
@@ -0,0 +1,34 @@
+/*
+ * Read a line of input from device.
+ * $Id$
+ * Copyright (c) 1997 by Tycho Softworks.
+ * For conditions of distribution and reuse see product license.
+ */
+
+#include <std/string.h>
+#include <dev/tty.h>
+
+int input(int fd, uchar *buf, size_t len, int timeout, const uchar *term)
+{
+ int key;
+ int idx = 0;
+
+ while(idx < len)
+ {
+ key = inkey(fd, timeout);
+ if(key < 0)
+ return idx;
+
+ if(!key)
+ continue;
+
+ buf[idx++] = (uchar)(key & 0xff);
+ if(strchr((char *)term, key))
+ break;
+ }
+ buf[idx] = 0;
+ return idx;
+}
+
+
+
diff --git a/sdk/dev/interactive.c b/sdk/dev/interactive.c
new file mode 100644
index 0000000..be998e6
--- /dev/null
+++ b/sdk/dev/interactive.c
@@ -0,0 +1,35 @@
+/*
+ * Select raw or "interactive" terminal mode for device.
+ * $Id$
+ * Copyright (c) 1997 by Tycho Softworks.
+ * For conditions of distribution and reuse see product license.
+ */
+
+#include <dev/tty.h>
+#ifndef TERMIOS_H_MISSING
+#include <termios.h>
+#endif
+
+bool interactive(stty_t stty, bool mode)
+{
+#ifndef TERMIOS_H_MISSING
+
+ struct termios *tios = stty;
+
+ if(mode)
+ {
+
+ }
+ else
+ {
+ tios->c_oflag = 0;
+ tios->c_lflag = 0;
+ }
+#endif
+ return mode;
+}
+
+
+
+
+
diff --git a/sdk/dev/make.conf b/sdk/dev/make.conf
new file mode 100644
index 0000000..8a396ea
--- /dev/null
+++ b/sdk/dev/make.conf
@@ -0,0 +1,5 @@
+inc=$CONFIG_HOST/include
+fn_find_file TERMIOS_H_MISSING $inc/termios.h
+fn_find_file TERMIO_H_MISSING $inc/termio.h
+fn_find_file TERMCAP_H_MISSING $inc/termcap.h
+
diff --git a/sdk/dev/speed.c b/sdk/dev/speed.c
new file mode 100644
index 0000000..f9fee56
--- /dev/null
+++ b/sdk/dev/speed.c
@@ -0,0 +1,75 @@
+/*
+ * Specify serial communications speed.
+ * $Id$
+ * Copyright (c) 1997 by Tycho Softworks.
+ * For conditions of distribution and reuse see product license.
+ */
+
+#include <dev/tty.h>
+#ifndef TERMIOS_H_MISSING
+#include <termios.h>
+#endif
+
+int setspeed(stty_t tios, ulong speed)
+{
+
+#ifdef B38400
+ int rate = B38400;
+#else
+ int rate = B19200;
+#endif
+
+ switch(speed)
+ {
+ case 110:
+ rate = B110;
+ break;
+ case 300:
+ rate = B300;
+ break;
+ case 600:
+ rate = B600;
+ break;
+ case 1200:
+ rate = B1200;
+ break;
+ case 2400:
+ rate = B2400;
+ break;
+ case 4800:
+ rate = B4800;
+ break;
+ case 9600:
+ rate = B9600;
+ break;
+ case 19200:
+ rate = B19200;
+ break;
+#ifdef B38400
+ case 38400:
+ rate = B38400;
+ break;
+#endif
+#ifdef B57600
+ case 57600:
+ rate = B57600;
+ break;
+#endif
+#ifdef B115200
+ case 115200:
+ rate = B115200;
+ break;
+#endif
+ }
+
+#ifndef TERMIOS_H_MISSING
+ cfsetospeed(tios, rate);
+ cfsetispeed(tios, rate);
+#endif
+ return rate;
+}
+
+
+
+
+
diff --git a/sdk/dev/stty.c b/sdk/dev/stty.c
new file mode 100644
index 0000000..9a465da
--- /dev/null
+++ b/sdk/dev/stty.c
@@ -0,0 +1,29 @@
+/*
+ * Portable routines to get and set serial device attributes.
+ * $Id$
+ * Copyright (c) 1997 by Tycho Softworks.
+ * For conditions of distribution and reuse see product license.
+ */
+
+#include <dev/tty.h>
+
+#ifndef TERMIOS_H_MISSING
+#include <termios.h>
+
+stty_t getstty(fd_t fd)
+{
+ stty_t stty = (stty_t)malloc(sizeof(struct termios));
+ tcgetattr(fd, stty);
+ return stty;
+}
+
+void putstty(fd_t fd, stty_t stty, bool now)
+{
+ if(now)
+ tcsetattr(fd, TCSANOW, stty);
+ else
+ tcsetattr(fd, TCSADRAIN, stty);
+ free(stty);
+}
+#endif
+
diff --git a/sdk/dev/termcap.h b/sdk/dev/termcap.h
new file mode 100644
index 0000000..e2cbb5b
--- /dev/null
+++ b/sdk/dev/termcap.h
@@ -0,0 +1,17 @@
+/*
+ * Portable termcap header.
+ * $Id$
+ * Copyright (c) 1997 by Tycho Softworks.
+ * For conditions on distribution and reuse see product license.
+ */
+
+#ifndef __DEV_TERMCAP_H__
+#define __DEV_TERMCAP_H__
+
+#ifndef TERMCAP_H_MISSING
+#include <termcap.h>
+#else
+#endif
+
+#endif
+
diff --git a/sdk/dev/tty.h b/sdk/dev/tty.h
new file mode 100644
index 0000000..3ff02ca
--- /dev/null
+++ b/sdk/dev/tty.h
@@ -0,0 +1,72 @@
+/*
+ * Portable serial interface control and operation.
+ * $Id$
+ * Copyright (c) 1997 by Tycho Softworks.
+ * For conditions of distribution and reuse see product license.
+ */
+
+#ifndef __DEV_TTY_H__
+#define __DEV_TTY_H__
+
+#ifndef __STD_TYPES_H__
+#include <std/types.h>
+#endif
+
+#ifndef __STD_FILES_H__
+#include <std/files.h>
+#endif
+
+typedef void *stty_t;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define ulock_device(lck) ulock_file(lck)
+
+typedef enum
+{
+ FC_NONE,
+ FC_HARD,
+ FC_SOFT,
+ FC_FULL
+} FLOWCONTROL;
+
+#ifdef __NAMESPACE
+#define lock_device __NAMESPACE(lock_device)
+#define setspeed __NAMESPACE(setspeed)
+#define setformat __NAMESPACE(setformat)
+#define setflowctrl __NAMESPACE(setflowctrl)
+#define waitfor __NAMESPACE(waitfor)
+#define waitsync __NAMESPACE(waitsync)
+#define input __NAMESPACE(input)
+#define dropdtr __NAMESPACE(dropdtr)
+#define inkey __NAMESPACE(inkey)
+#define interactive __NAMESPACE(interactive)
+#define readcrc __NAMESPACE(readcrc)
+#define writecrc __NAMESPACE(writecrc)
+#define readcsum __NAMESPACE(readcsum)
+#define writecsum __NAMESPACE(writecsum)
+#define xmit __NAMESPACE(xmit)
+#define empty __NAMESPACE(empty)
+#endif
+
+stty_t getstty(fd_t fd);
+void putstty(fd_t fd, stty_t stty, bool now);
+int setspeed(stty_t stty, ulong speed);
+int setformat(stty_t stty, char *format);
+int setflowctrl(stty_t stty, FLOWCONTROL flow);
+int waitfor(fd_t fd, uchar *str, size_t len, int timeout, ulong maxbytes);
+int waitsync(fd_t fd, uchar *list, size_t len, int timeout, ulong maxbytes);
+int input(fd_t fd, uchar *buf, size_t len, int timeout, const uchar *term);
+int dropdtr(fd_t fd);
+int inkey(fd_t fd, int timeout);
+bool interactive(stty_t stty, bool mode);
+int xmit(fd_t fd, char *str);
+void empty(fd_t fd);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/sdk/dev/waitfor.c b/sdk/dev/waitfor.c
new file mode 100644
index 0000000..36fabec
--- /dev/null
+++ b/sdk/dev/waitfor.c
@@ -0,0 +1,39 @@
+/*
+ * Wait for specified input from device.
+ * $Id$
+ * Copyright (c) 1997 by Tycho Softworks.
+ * For conditions on redistribution and reuse see product license.
+ */
+
+#include <dev/tty.h>
+#include <std/string.h>
+
+int waitfor(int fd, uchar *list, size_t len, int timeout, ulong max)
+{
+ int key;
+ int idx = 0;
+ uchar *mem = (uchar *)malloc(len);
+
+ while(max--)
+ {
+ key = inkey(fd, timeout);
+ if(key < 0)
+ return key;
+
+ if(idx < len)
+ mem[idx++] = (uchar)(key & 0xff);
+ else
+ {
+ for(idx = 0; idx < len; ++idx)
+ mem[idx] = mem[idx + 1];
+
+ mem[len - 1] = (uchar)(key & 0xff);
+ }
+ if(!memcmp(mem, list, len))
+ return 0;
+ }
+ return -1;
+}
+
+
+
diff --git a/sdk/dev/waitsync.c b/sdk/dev/waitsync.c
new file mode 100644
index 0000000..f4596e1
--- /dev/null
+++ b/sdk/dev/waitsync.c
@@ -0,0 +1,32 @@
+/*
+ * Wait for a sync input value from a device.
+ * $Id$
+ * Copyright (c) 1997 by Tycho Softworks.
+ * For conditions of distribution and reuse see product license.
+ */
+
+#include <dev/tty.h>
+
+int waitsync(int fd, uchar *list, size_t len, int timeout, ulong max)
+{
+ int key;
+ int idx;
+ uchar buf;
+
+ while(max--)
+ {
+ key = inkey(fd, timeout);
+ if(key < 0)
+ return key;
+
+ buf = (uchar)(key & 0xff);
+
+ for(idx = 0; idx < len; ++idx)
+ if(list[idx] == buf)
+ return buf;
+ }
+ return -1;
+}
+
+
+
diff --git a/sdk/dev/xmit.c b/sdk/dev/xmit.c
new file mode 100644
index 0000000..471736d
--- /dev/null
+++ b/sdk/dev/xmit.c
@@ -0,0 +1,31 @@
+/*
+ * Write output to a device and ignore any incoming (echo) data.
+ * $Id$
+ * Copyright (c) 1997 by Tycho Softworks.
+ * For conditions of distribution and reuse see product license.
+ */
+
+#include <dev/tty.h>
+
+int xmit(int fd, char *str)
+{
+ int len = strlen(str);
+ int stat;
+
+ while(inkey(fd, 2) > -1)
+ continue;
+
+ stat = write(fd, str, len);
+ if(stat < 0)
+ return stat;
+
+ len = stat;
+ while(len--)
+ if(inkey(fd, 0) < 0)
+ break;
+
+ return stat;
+}
+
+
+