[PATCH 4/9] Adding RTEMS termios FREEBSD support

Kevin Kirspel kevin-kirspel at idexx.com
Thu Feb 9 03:21:35 UTC 2017


---
 rtemsbsd/include/machine/rtems-bsd-termios.h |  68 +++++++++
 rtemsbsd/rtems/rtems-bsd-termios.c           | 213 +++++++++++++++++++++++++++
 2 files changed, 281 insertions(+)
 create mode 100755 rtemsbsd/include/machine/rtems-bsd-termios.h
 create mode 100755 rtemsbsd/rtems/rtems-bsd-termios.c

diff --git a/rtemsbsd/include/machine/rtems-bsd-termios.h b/rtemsbsd/include/machine/rtems-bsd-termios.h
new file mode 100755
index 0000000..0acb23f
--- /dev/null
+++ b/rtemsbsd/include/machine/rtems-bsd-termios.h
@@ -0,0 +1,68 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_bsd_machine
+ *
+ * @brief TODO.
+ */
+
+/*
+ * Copyright (c) 2013 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Dornierstr. 4
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems at embedded-brains.de>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _RTEMS_BSD_MACHINE_RTEMS_BSD_TERMIOS_H_
+#define _RTEMS_BSD_MACHINE_RTEMS_BSD_TERMIOS_H_
+
+#include <sys/cdefs.h>
+#include <sys/_termios.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+__BEGIN_DECLS
+
+u_long
+rtems_bsd_ioctl_cmd_to_bsd(struct termios *t, u_long cmd, caddr_t data, int* flush_flags);
+
+speed_t
+rtems_bsd_rtems_speed_to_bsd_speed(speed_t spd);
+
+speed_t
+rtems_bsd_bsd_speed_to_rtems_speed(speed_t spd);
+
+speed_t
+rtems_bsd_get_input_speed(struct termios *t);
+
+speed_t
+rtems_bsd_get_output_speed(struct termios *t);
+
+__END_DECLS
+
+#endif /* _RTEMS_BSD_MACHINE_RTEMS_BSD_TERMIOS_H_ */
diff --git a/rtemsbsd/rtems/rtems-bsd-termios.c b/rtemsbsd/rtems/rtems-bsd-termios.c
new file mode 100755
index 0000000..cd86581
--- /dev/null
+++ b/rtemsbsd/rtems/rtems-bsd-termios.c
@@ -0,0 +1,213 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_bsd_rtems
+ *
+ * @brief TODO.
+ */
+
+/*
+ * Copyright (c) 2009, 2010 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Obere Lagerstr. 30
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems at embedded-brains.de>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <machine/rtems-bsd-kernel-space.h>
+
+#include <sys/types.h>
+#include <sys/fcntl.h>
+#include <sys/tty.h>
+#include <sys/ttycom.h>
+#define TTYDEFCHARS
+#include <sys/ttydefaults.h>
+#undef TTYDEFCHARS
+#include <sys/ioccom.h>
+
+typedef struct
+{
+  speed_t rtems_speed;
+  speed_t bsd_speed;
+}rtems_bsd_termios_speed_entry;
+
+static rtems_bsd_termios_speed_entry rtems_bsd_speed_table[] = {
+  { B0,      0      },
+  { B50,     50     },
+  { B75,     75     },
+  { B110,    110    },
+  { B134,    134    },
+  { B150,    150    },
+  { B200,    200    },
+  { B300,    300    },
+  { B600,    600    },
+  { B1200,   1200   },
+  { B1800,   1800   },
+  { B2400,   2400   },
+  { B4800,   4800   },
+  { B9600,   9600   },
+  { B19200,  19200  },
+  { B38400,  38400  },
+  { B57600,  57600  },
+  { B115200, 115200 },
+  { B230400, 230400 },
+  { B460800, 460800 },
+};
+#define rtems_bsd_speed_table_size (( int )( sizeof( rtems_bsd_speed_table ) / sizeof( rtems_bsd_speed_table[0] )))
+
+/*
+ *********************************************************************
+ *            RTEMS ioctl cmd translation for BSD                    *
+ *********************************************************************
+ */
+u_long
+rtems_bsd_ioctl_cmd_to_bsd(struct termios *t, u_long cmd, caddr_t data, int* flush_flags)
+{
+	uint32_t c_ispeed;
+	uint32_t c_ospeed;
+
+  switch (cmd) {
+
+  case RTEMS_IO_GET_ATTRIBUTES:
+    cmd = TIOCGETA;
+		break;
+
+  case RTEMS_IO_SET_ATTRIBUTES:
+    cmd = TIOCSETA;
+		c_ispeed = cfgetispeed(t);
+		c_ospeed = cfgetospeed(t);
+		if (c_ispeed && (c_ispeed != c_ospeed)) {
+			cfsetospeed(t, c_ispeed);
+		}
+    break;
+
+  case RTEMS_IO_TCDRAIN:
+    cmd = TIOCSETAW;
+    break;
+
+  case RTEMS_IO_RCVWAKEUP:
+    break;
+
+  case RTEMS_IO_SNDWAKEUP:
+    break;
+
+  case RTEMS_IO_TCFLUSH:
+    cmd = TIOCFLUSH;
+    switch ((intptr_t)data) {
+    case TCIFLUSH:
+      *flush_flags = FREAD;
+      break;
+    case TCOFLUSH:
+      *flush_flags = FWRITE;
+      break;
+    case TCIOFLUSH:
+      *flush_flags = FREAD | FWRITE;
+      break;
+		default:
+			*flush_flags = 0;
+    }
+    break;
+	}
+  return (cmd);
+}
+
+/*
+ *********************************************************************
+ *            RTEMS speed translation for BSD speed                  *
+ *********************************************************************
+ */
+speed_t
+rtems_bsd_rtems_speed_to_bsd_speed(speed_t spd)
+{
+  rtems_bsd_termios_speed_entry* entry = &rtems_bsd_speed_table[0];
+  rtems_bsd_termios_speed_entry* entry_end = &rtems_bsd_speed_table[rtems_bsd_speed_table_size];
+
+  while( entry != entry_end ) {
+    if(entry->rtems_speed == spd) {
+      return entry->bsd_speed;
+    }
+    entry++;
+  }
+  return 0;
+}
+
+/*
+ *********************************************************************
+ *            BSD speed translation for RTEMS speed                  *
+ *********************************************************************
+ */
+speed_t
+rtems_bsd_bsd_speed_to_rtems_speed(speed_t spd)
+{
+  rtems_bsd_termios_speed_entry* entry = &rtems_bsd_speed_table[0];
+  rtems_bsd_termios_speed_entry* entry_end = &rtems_bsd_speed_table[rtems_bsd_speed_table_size];
+
+  while( entry != entry_end ) {
+    if(entry->bsd_speed == spd) {
+      return entry->rtems_speed;
+    }
+    entry++;
+  }
+  return 0;
+}
+
+/*
+ *********************************************************************
+ *            RTEMS get input baud rate from termios                 *
+ *********************************************************************
+ */
+speed_t
+rtems_bsd_get_input_speed(struct termios *t)
+{
+  return rtems_bsd_rtems_speed_to_bsd_speed(cfgetispeed(t));
+}
+
+/*
+ *********************************************************************
+ *            RTEMS get output baud rate from termios                *
+ *********************************************************************
+ */
+speed_t
+rtems_bsd_get_output_speed(struct termios *t)
+{
+  return rtems_bsd_rtems_speed_to_bsd_speed(cfgetospeed(t));
+}
+
+/*
+ * Obtain a termios structure which is similar to the one provided by
+ * the kernel.
+ */
+void
+cfmakesane(struct termios *t)
+{
+  t->c_cflag = TTYDEF_CFLAG;
+  t->c_iflag = TTYDEF_IFLAG;
+  t->c_lflag = TTYDEF_LFLAG;
+  t->c_oflag = TTYDEF_OFLAG;
+  cfsetispeed(t, TTYDEF_SPEED);
+  cfsetospeed(t, TTYDEF_SPEED);
+  memcpy(&t->c_cc, ttydefchars, sizeof ttydefchars);
+}
-- 
1.9.1



More information about the devel mailing list