summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/shared/console_select.c
diff options
context:
space:
mode:
authorJennifer Averett <Jennifer.Averett@OARcorp.com>2011-10-18 18:23:51 +0000
committerJennifer Averett <Jennifer.Averett@OARcorp.com>2011-10-18 18:23:51 +0000
commitba692232fa53278801b9f17318b8f6692bd3d92c (patch)
tree33ddd615cd8e42bda34b77db13ae19b2d2066610 /c/src/lib/libbsp/shared/console_select.c
parent2011-10-18 Jennifer Averett <Jennifer.Averett@OARcorp.com (diff)
downloadrtems-ba692232fa53278801b9f17318b8f6692bd3d92c.tar.bz2
2011-10-18 Jennifer Averett <Jennifer.Averett@OARcorp.com>
PR 1917/bsps * console.c: Modifications to add dynamic tables for libchip serial drivers. * console_control.c, console_private.h, console_read.c, console_select.c, console_write.c: New files.
Diffstat (limited to 'c/src/lib/libbsp/shared/console_select.c')
-rw-r--r--c/src/lib/libbsp/shared/console_select.c102
1 files changed, 102 insertions, 0 deletions
diff --git a/c/src/lib/libbsp/shared/console_select.c b/c/src/lib/libbsp/shared/console_select.c
new file mode 100644
index 0000000000..caab940c2d
--- /dev/null
+++ b/c/src/lib/libbsp/shared/console_select.c
@@ -0,0 +1,102 @@
+/**
+ * @file
+ *
+ * @ingroup Console
+ *
+ * @brief Generic libchip console select
+ */
+
+/*
+ * This file contains a routine to select the
+ * console based upon a number of criteria.
+ *
+ * COPYRIGHT (c) 2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <bsp.h>
+#include <rtems/libio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <termios.h>
+
+#include <rtems/termiostypes.h>
+#include <libchip/serial.h>
+#include "console_private.h"
+
+/*
+ * Method to return true if the device associated with the
+ * minor number probs available.
+ */
+static bool bsp_Is_Available( rtems_device_minor_number minor )
+{
+ console_tbl *cptr = Console_Port_Tbl[minor];
+
+ /*
+ * First perform the configuration dependent probe, then the
+ * device dependent probe
+ */
+ if ((!cptr->deviceProbe || cptr->deviceProbe(minor)) &&
+ cptr->pDeviceFns->deviceProbe(minor)) {
+ return true;
+ }
+ return false;
+}
+
+/*
+ * Method to return the first available device.
+ */
+static rtems_device_minor_number bsp_First_Available_Device( void )
+{
+ rtems_device_minor_number minor;
+
+ for (minor=0; minor < Console_Port_Count ; minor++) {
+ console_tbl *cptr = Console_Port_Tbl[minor];
+
+ /*
+ * First perform the configuration dependent probe, then the
+ * device dependent probe
+ */
+
+ if ((!cptr->deviceProbe || cptr->deviceProbe(minor)) &&
+ cptr->pDeviceFns->deviceProbe(minor)) {
+ return minor;
+ }
+ }
+
+ /*
+ * Error No devices were found. We will want to bail here.
+ */
+ rtems_fatal_error_occurred(RTEMS_IO_ERROR);
+}
+
+void bsp_console_select(void)
+{
+
+ /*
+ * Reset Console_Port_Minor and
+ * BSPPrintkPort here if desired.
+ *
+ * This default version allows the bsp to set these
+ * values at creation and will not touch them again
+ * unless the selected port number is not available.
+ */
+
+ /*
+ * If the device that was selected isn't available then
+ * let the user know and select the first available device.
+ */
+ if ( !bsp_Is_Available( Console_Port_Minor ) ) {
+ printk(
+ "Error finding %s setting console to first available\n",
+ Console_Port_Tbl[Console_Port_Minor]->sDeviceName
+ );
+ Console_Port_Minor = bsp_First_Available_Device();
+ }
+}