source: rtems/c/src/lib/libbsp/i386/pc386/console/console_select.c @ 441b90e

4.115
Last change on this file since 441b90e was 441b90e, checked in by Jennifer Averett <Jennifer.Averett@…>, on 02/01/12 at 20:32:28

Correct run-time selection of console port.

This was broken by conversion of console driver to libchip style.

  • Property mode set to 100644
File size: 4.3 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup Console
5 *
6 * @brief Generic libchip console select
7 */
8
9/*
10 *  This file contains a routine to select the
11 *  console based upon a number of criteria.
12 *
13 *  COPYRIGHT (c) 2011.
14 *  On-Line Applications Research Corporation (OAR).
15 *
16 *  The license and distribution terms for this file may be
17 *  found in the file LICENSE in this distribution or at
18 *  http://www.rtems.com/license/LICENSE.
19 *
20 *  $Id: console_select.c,v 1.1 2012/02/01 16:03:14 jennifer Exp $
21 */
22
23#include <bsp.h>
24#include <rtems/libio.h>
25#include <stdlib.h>
26#include <assert.h>
27#include <termios.h>
28
29#include <rtems/termiostypes.h>
30#include <libchip/serial.h>
31#include "../../../shared/console_private.h"
32#ifdef RTEMS_RUNTIME_CONSOLE_SELECT
33  #include <crt.h>
34#endif
35
36/*
37 * Method to return true if the device associated with the
38 * minor number probs available.
39 */
40static bool bsp_Is_Available( rtems_device_minor_number minor )
41{
42  console_tbl  *cptr = Console_Port_Tbl[minor];
43
44  /*
45   * First perform the configuration dependent probe, then the
46   * device dependent probe
47   */
48  if ((!cptr->deviceProbe || cptr->deviceProbe(minor)) &&
49       cptr->pDeviceFns->deviceProbe(minor)) {
50    return true;
51  }
52  return false;
53}
54
55/*
56 * Method to return the first available device.
57 */
58static rtems_device_minor_number bsp_First_Available_Device( void )
59{
60  rtems_device_minor_number minor;
61
62  for (minor=0; minor < Console_Port_Count ; minor++) {
63    console_tbl  *cptr = Console_Port_Tbl[minor];
64
65    /*
66     * First perform the configuration dependent probe, then the
67     * device dependent probe
68     */
69
70    if ((!cptr->deviceProbe || cptr->deviceProbe(minor)) &&
71         cptr->pDeviceFns->deviceProbe(minor)) {
72      return minor;
73    }
74  }
75
76  /*
77   *  Error No devices were found.  We will want to bail here.
78   */
79  rtems_fatal_error_occurred(RTEMS_IO_ERROR);
80}
81
82void bsp_console_select(void)
83{
84  static const char* opt;
85
86  /*
87   * Check the command line for the type of mode the console is.
88   */
89  opt = bsp_cmdline_arg ("--console=");
90
91  if (opt) {
92    const char* comma;
93
94    opt += sizeof ("--console=") - 1;
95    if (strncmp (opt, "console", sizeof ("console") - 1) == 0) {
96      Console_Port_Minor = BSP_CONSOLE_VGA;
97      BSPPrintkPort      = BSP_CONSOLE_VGA;
98    } else if (strncmp (opt, "com1", sizeof ("com1") - 1) == 0) {
99      Console_Port_Minor = BSP_CONSOLE_COM1;
100      BSPPrintkPort      = BSP_CONSOLE_COM1;
101    } else if (strncmp (opt, "com2", sizeof ("com2") - 1) == 0) {
102      Console_Port_Minor = BSP_CONSOLE_COM2;
103      BSPPrintkPort      = BSP_CONSOLE_COM2;
104    }
105
106    comma = strchr (opt, ',');
107
108    if (comma) {
109      console_tbl *conscfg;
110
111      comma += 1;
112      conscfg = &Console_Configuration_Ports[Console_Port_Minor];
113      if (strncmp (opt, "115200", sizeof ("115200") - 1) == 0)
114        conscfg->pDeviceParams = (void *)115200;
115      else if (strncmp (opt, "57600", sizeof ("57600") - 1) == 0)
116        conscfg->pDeviceParams = (void *)57600;
117      else if (strncmp (opt, "38400", sizeof ("38400") - 1) == 0)
118        conscfg->pDeviceParams = (void *)38400;
119      else if (strncmp (opt, "19200", sizeof ("19200") - 1) == 0)
120        conscfg->pDeviceParams = (void *)19200;
121      else if (strncmp (opt, "9600", sizeof ("9600") - 1) == 0)
122        conscfg->pDeviceParams = (void *)9600;
123      else if (strncmp (opt, "4800", sizeof ("4800") - 1) == 0)
124        conscfg->pDeviceParams = (void *)4800;
125    }
126  }
127
128  #ifdef RTEMS_RUNTIME_CONSOLE_SELECT
129    if ( BSP_runtime_console_select )
130      BSP_runtime_console_select(&BSPPrintkPort, &Console_Port_Minor);
131
132    /*
133     * If no video card, fall back to serial port console
134     */
135    if((Console_Port_Minor == BSP_CONSOLE_VGA)
136     && (*(unsigned char*) NB_MAX_ROW_ADDR == 0)
137     && (*(unsigned short*)NB_MAX_COL_ADDR == 0)) {
138      Console_Port_Minor = BSP_CONSOLE_COM2;
139      BSPPrintkPort      = BSP_CONSOLE_COM1;
140    }
141  #endif
142
143  /*
144   * If the device that was selected isn't available then
145   * let the user know and select the first available device.
146   */
147  if ( !bsp_Is_Available( Console_Port_Minor ) ) {
148    printk(
149      "Error finding %s setting console to first available\n",
150      Console_Port_Tbl[Console_Port_Minor]->sDeviceName
151    );
152    Console_Port_Minor = bsp_First_Available_Device();
153  }
154
155  if (opt != NULL)
156    printk("cmdline==>%s<<==\n", opt);
157}
Note: See TracBrowser for help on using the repository browser.