[rtems commit] Add simple console driver

Sebastian Huber sebh at rtems.org
Mon Nov 6 06:29:18 UTC 2017


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Nov  3 08:33:16 2017 +0100

Add simple console driver

Update #3170.
Update #3199.

---

 cpukit/include/rtems/console.h         |  9 ++++
 cpukit/libcsupport/Makefile.am         |  1 +
 cpukit/libcsupport/src/consolesimple.c | 97 ++++++++++++++++++++++++++++++++++
 cpukit/sapi/include/confdefs.h         | 17 ++++++
 4 files changed, 124 insertions(+)

diff --git a/cpukit/include/rtems/console.h b/cpukit/include/rtems/console.h
index dbd749c..f9a7de1 100644
--- a/cpukit/include/rtems/console.h
+++ b/cpukit/include/rtems/console.h
@@ -147,6 +147,15 @@ rtems_device_driver console_control(
   void                      *arg
 );
 
+/**
+ * @brief Initializes a simple console device.
+ *
+ * This device writes via rtems_putc() and reads via getchark().  The Termios
+ * framework is not used.  There is no support to change device settings, e.g.
+ * baud, stop bits, parity, etc.
+ */
+void _Console_simple_Initialize( void );
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/cpukit/libcsupport/Makefile.am b/cpukit/libcsupport/Makefile.am
index 8645ba1..dbba6b1 100644
--- a/cpukit/libcsupport/Makefile.am
+++ b/cpukit/libcsupport/Makefile.am
@@ -138,6 +138,7 @@ libcsupport_a_SOURCES = src/gxx_wrappers.c src/getchark.c src/printk.c \
     src/resource_snapshot.c \
     $(BSD_LIBC_C_FILES) $(BASE_FS_C_FILES) $(MALLOC_C_FILES) \
     $(ERROR_C_FILES) $(ASSOCIATION_C_FILES)
+libcsupport_a_SOURCES += src/consolesimple.c
 libcsupport_a_SOURCES += src/printertask.c
 libcsupport_a_SOURCES += src/printerfprintfputc.c
 
diff --git a/cpukit/libcsupport/src/consolesimple.c b/cpukit/libcsupport/src/consolesimple.c
new file mode 100644
index 0000000..5aa0f98
--- /dev/null
+++ b/cpukit/libcsupport/src/consolesimple.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2017 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.
+ */
+
+#include <rtems/console.h>
+#include <rtems/bspIo.h>
+#include <rtems/imfs.h>
+
+static ssize_t _Console_simple_Read(
+  rtems_libio_t *iop,
+  void          *buffer,
+  size_t         count
+)
+{
+  char    *buf;
+  ssize_t  i;
+  ssize_t  n;
+
+  buf = buffer;
+  n = (ssize_t) count;
+
+  for ( i = 0; i < n; ++i ) {
+    int c;
+
+    do {
+      c = getchark();
+    } while (c == -1);
+
+    buf[ i ] = (char) c;
+  }
+
+  return n;
+}
+
+static ssize_t _Console_simple_Write(
+  rtems_libio_t *iop,
+  const void    *buffer,
+  size_t         count
+)
+{
+  const char *buf;
+  ssize_t     i;
+  ssize_t     n;
+
+  buf = buffer;
+  n = (ssize_t) count;
+
+  for ( i = 0; i < n; ++i ) {
+    rtems_putc( buf[ i ] );
+  }
+
+  return n;
+}
+
+static const rtems_filesystem_file_handlers_r _Console_simple_Handlers = {
+  .open_h = rtems_filesystem_default_open,
+  .close_h = rtems_filesystem_default_close,
+  .read_h = _Console_simple_Read,
+  .write_h = _Console_simple_Write,
+  .ioctl_h = rtems_filesystem_default_ioctl,
+  .lseek_h = rtems_filesystem_default_lseek,
+  .fstat_h = IMFS_stat,
+  .ftruncate_h = rtems_filesystem_default_ftruncate,
+  .fsync_h = rtems_filesystem_default_fsync_or_fdatasync,
+  .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync,
+  .fcntl_h = rtems_filesystem_default_fcntl,
+  .readv_h = rtems_filesystem_default_readv,
+  .writev_h = rtems_filesystem_default_writev,
+  .mmap_h = rtems_filesystem_default_mmap
+};
+
+static const IMFS_node_control
+_Console_simple_Node_control = IMFS_GENERIC_INITIALIZER(
+  &_Console_simple_Handlers,
+  IMFS_node_initialize_default,
+  IMFS_node_destroy_default
+);
+
+void _Console_simple_Initialize( void )
+{
+  IMFS_make_generic_node(
+    CONSOLE_DEVICE_NAME,
+    S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO,
+    &_Console_simple_Node_control,
+    NULL
+  );
+}
diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h
index 47b7d9a..ca4ee47 100755
--- a/cpukit/sapi/include/confdefs.h
+++ b/cpukit/sapi/include/confdefs.h
@@ -1610,10 +1610,27 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
 #define NULL_DRIVER_TABLE_ENTRY \
  { NULL, NULL, NULL, NULL, NULL, NULL }
 
+#if defined(CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER) && \
+  defined(CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER)
+#error "CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER and CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER are mutually exclusive"
+#endif
+
 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
   #include <rtems/console.h>
 #endif
 
+#ifdef CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
+  #include <rtems/console.h>
+
+  #ifdef CONFIGURE_INIT
+    RTEMS_SYSINIT_ITEM(
+      _Console_simple_Initialize,
+      RTEMS_SYSINIT_DEVICE_DRIVERS,
+      RTEMS_SYSINIT_ORDER_SECOND
+    );
+  #endif
+#endif
+
 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
   #include <rtems/clockdrv.h>
 #endif



More information about the vc mailing list