[rtems commit] bsp/t32mppc: Convert to Termios device

Sebastian Huber sebh at rtems.org
Fri Nov 27 10:35:33 UTC 2015


Module:    rtems
Branch:    master
Commit:    0a3110158fa8b8b25fec947a99f0a9c889fcb5f8
Changeset: http://git.rtems.org/rtems/commit/?id=0a3110158fa8b8b25fec947a99f0a9c889fcb5f8

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Nov 27 10:39:33 2015 +0100

bsp/t32mppc: Convert to Termios device

---

 c/src/lib/libbsp/powerpc/t32mppc/Makefile.am       |   8 +-
 .../powerpc/t32mppc/console/console-config.c       | 149 ---------------------
 c/src/lib/libbsp/powerpc/t32mppc/console/console.c | 139 +++++++++++++++++++
 3 files changed, 141 insertions(+), 155 deletions(-)

diff --git a/c/src/lib/libbsp/powerpc/t32mppc/Makefile.am b/c/src/lib/libbsp/powerpc/t32mppc/Makefile.am
index e251ade..76a6212 100644
--- a/c/src/lib/libbsp/powerpc/t32mppc/Makefile.am
+++ b/c/src/lib/libbsp/powerpc/t32mppc/Makefile.am
@@ -72,12 +72,8 @@ libbsp_a_SOURCES += ../../shared/src/irq-shell.c
 libbsp_a_SOURCES += irq/irq.c
 
 # Console
-libbsp_a_SOURCES += ../../shared/console.c \
-        ../../shared/console_select.c \
-	console/console-config.c \
-        ../../shared/console_read.c \
-        ../../shared/console_write.c \
-        ../../shared/console_control.c
+libbsp_a_SOURCES += ../../shared/console-termios.c
+libbsp_a_SOURCES += console/console.c
 
 libbsp_a_LIBADD = ../../../libcpu/@RTEMS_CPU@/shared/cpuIdent.rel \
 	../../../libcpu/@RTEMS_CPU@/shared/cache.rel \
diff --git a/c/src/lib/libbsp/powerpc/t32mppc/console/console-config.c b/c/src/lib/libbsp/powerpc/t32mppc/console/console-config.c
deleted file mode 100644
index d4f85a6..0000000
--- a/c/src/lib/libbsp/powerpc/t32mppc/console/console-config.c
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
- *
- *  embedded brains GmbH
- *  Obere Lagerstr. 30
- *  82178 Puchheim
- *  Germany
- *  <rtems at embedded-brains.de>
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rtems.org/license/LICENSE.
- */
-
-/*
- * Console driver for Lauterbach Trace32 Simulator.  The implementation is
- * based on the example in "demo/powerpc/etc/terminal/terminal_mpc85xx.cmm" in
- * the Trace32 system directory.
- */
-
-#include <rtems/bspIo.h>
-#include <rtems/libio.h>
-#include <rtems/termiostypes.h>
-
-#include <libchip/serial.h>
-#include <libchip/sersupp.h>
-
-#define CONSOLE_COUNT 1
-
-volatile unsigned char messagebufferin [256];
-
-volatile unsigned char messagebufferout [256];
-
-static void initialize(int minor)
-{
-  /* Nothing to do */
-}
-
-static int first_open(int major, int minor, void *arg)
-{
-  rtems_libio_open_close_args_t *oc = (rtems_libio_open_close_args_t *) arg;
-  struct rtems_termios_tty *tty = (struct rtems_termios_tty *) oc->iop->data1;
-  console_data *cd = &Console_Port_Data [minor];
-
-  cd->termios_data = tty;
-  rtems_termios_set_initial_baud(tty, 115200);
-
-  return 0;
-}
-
-static int last_close(int major, int minor, void *arg)
-{
-  return 0;
-}
-
-static int read_polled(int minor)
-{
-  static int bufsize;
-  static int bufindex;
-
-  int c;
-
-  if (bufsize == 0) {
-    int new_bufsize = messagebufferin [0];
-
-    if (new_bufsize != 0) {
-      bufsize = new_bufsize;
-      bufindex = 0;
-    } else {
-      return -1;
-    }
-  }
-
-  c = messagebufferin [4 + bufindex];
-
-  ++bufindex;
-  if (bufindex >= bufsize) {
-    messagebufferin [0] = 0;
-    bufsize = 0;
-  }
-
-  return c;
-}
-
-static void write_polled(int minor, char c)
-{
-  while (messagebufferout[0] != 0) {
-    /* Wait for ready */
-  }
-
-  messagebufferout [4] = (unsigned char) c;
-  messagebufferout [0] = 1;
-}
-
-static ssize_t write_support_polled(
-  int minor,
-  const char *s,
-  size_t n
-)
-{
-  ssize_t i = 0;
-
-  for (i = 0; i < n; ++i) {
-    write_polled(minor, s [i]);
-  }
-
-  return n;
-}
-
-static int set_attribues(int minor, const struct termios *term)
-{
-  return -1;
-}
-
-static const console_fns t32mppc_console_fns = {
-  .deviceProbe = libchip_serial_default_probe,
-  .deviceFirstOpen = first_open,
-  .deviceLastClose = last_close,
-  .deviceRead = read_polled,
-  .deviceWrite = write_support_polled,
-  .deviceInitialize = initialize,
-  .deviceWritePolled = write_polled,
-  .deviceSetAttributes = set_attribues,
-  .deviceOutputUsesInterrupts = false
-};
-
-unsigned long Console_Configuration_Count = CONSOLE_COUNT;
-
-console_tbl Console_Configuration_Ports [CONSOLE_COUNT] = {
-  {
-    .sDeviceName = "/dev/ttyS0",
-    .deviceType = SERIAL_CUSTOM,
-    .pDeviceFns = &t32mppc_console_fns
-  }
-};
-
-static void output_char(char c)
-{
-  const console_fns *con = Console_Port_Tbl [Console_Port_Minor]->pDeviceFns;
-
-  if (c == '\n') {
-    con->deviceWritePolled((int) Console_Port_Minor, '\r');
-  }
-  con->deviceWritePolled((int) Console_Port_Minor, c);
-}
-
-BSP_output_char_function_type BSP_output_char = output_char;
-
-BSP_polling_getchar_function_type BSP_poll_char = NULL;
diff --git a/c/src/lib/libbsp/powerpc/t32mppc/console/console.c b/c/src/lib/libbsp/powerpc/t32mppc/console/console.c
new file mode 100644
index 0000000..0c39bdd
--- /dev/null
+++ b/c/src/lib/libbsp/powerpc/t32mppc/console/console.c
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2012, 2015 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Dornierstr. 4
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems at embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+/*
+ * Console driver for Lauterbach Trace32 Simulator.  The implementation is
+ * based on the example in "demo/powerpc/etc/terminal/terminal_mpc85xx.cmm" in
+ * the Trace32 system directory.
+ */
+
+#include <rtems/bspIo.h>
+#include <rtems/console.h>
+#include <rtems/termiostypes.h>
+
+volatile unsigned char messagebufferin[256];
+
+volatile unsigned char messagebufferout[256];
+
+typedef struct {
+  rtems_termios_device_context base;
+  int input_size;
+  int input_index;
+} t32_console_context;
+
+static t32_console_context t32_console_instance;
+
+static bool t32_console_first_open(
+  rtems_termios_tty *tty,
+  rtems_termios_device_context *base,
+  struct termios *term,
+  rtems_libio_open_close_args_t *args
+)
+{
+  rtems_termios_set_initial_baud(tty, 115200);
+
+  return true;
+}
+
+static int t32_console_read_polled(rtems_termios_device_context *base)
+{
+  t32_console_context *ctx = (t32_console_context *) base;
+  int c;
+
+  if (ctx->input_size == 0) {
+    int new_bufsize = messagebufferin[0];
+
+    if (new_bufsize != 0) {
+      ctx->input_size = new_bufsize;
+      ctx->input_index = 0;
+    } else {
+      return -1;
+    }
+  }
+
+  c = messagebufferin[4 + ctx->input_index];
+
+  ++ctx->input_index;
+  if (ctx->input_index >= ctx->input_size) {
+    messagebufferin[0] = 0;
+    ctx->input_size = 0;
+  }
+
+  return c;
+}
+
+static void t32_console_write_char_polled(char c)
+{
+  while (messagebufferout[0] != 0) {
+    /* Wait for ready */
+  }
+
+  messagebufferout[4] = (unsigned char) c;
+  messagebufferout[0] = 1;
+}
+
+static void t32_console_write_polled(
+  rtems_termios_device_context *base,
+  const char *s,
+  size_t n
+)
+{
+  size_t i;
+
+  for (i = 0; i < n; ++i) {
+    t32_console_write_char_polled(s[i]);
+  }
+}
+
+const rtems_termios_device_handler t32_console_handler = {
+  .first_open = t32_console_first_open,
+  .poll_read = t32_console_read_polled,
+  .write = t32_console_write_polled,
+  .mode = TERMIOS_POLLED
+};
+
+rtems_device_driver console_initialize(
+  rtems_device_major_number major,
+  rtems_device_minor_number minor,
+  void *arg
+)
+{
+  t32_console_context *ctx = &t32_console_instance;
+
+  rtems_termios_initialize();
+  rtems_termios_device_context_initialize(&ctx->base, "T32 Console");
+  rtems_termios_device_install(
+    CONSOLE_DEVICE_NAME,
+    major,
+    0,
+    &t32_console_handler,
+    NULL,
+    &ctx->base
+  );
+
+  return RTEMS_SUCCESSFUL;
+}
+
+static void t32_output_char(char c)
+{
+  if (c == '\n') {
+    t32_console_write_char_polled('\r');
+  }
+
+  t32_console_write_char_polled(c);
+}
+
+BSP_output_char_function_type BSP_output_char = t32_output_char;
+
+BSP_polling_getchar_function_type BSP_poll_char = NULL;




More information about the vc mailing list