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