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.org/license/LICENSE. |
---|
19 | */ |
---|
20 | |
---|
21 | #include <bsp.h> |
---|
22 | #include <bsp/fatal.h> |
---|
23 | #include <rtems/libio.h> |
---|
24 | #include <stdlib.h> |
---|
25 | #include <assert.h> |
---|
26 | #include <termios.h> |
---|
27 | |
---|
28 | #include <rtems/termiostypes.h> |
---|
29 | #include <libchip/serial.h> |
---|
30 | #include "console_private.h" |
---|
31 | |
---|
32 | /* |
---|
33 | * Method to return true if the device associated with the |
---|
34 | * minor number probs available. |
---|
35 | */ |
---|
36 | static bool bsp_Is_Available( rtems_device_minor_number minor ) |
---|
37 | { |
---|
38 | console_tbl *cptr = Console_Port_Tbl[minor]; |
---|
39 | |
---|
40 | /* |
---|
41 | * First perform the configuration dependent probe, then the |
---|
42 | * device dependent probe |
---|
43 | */ |
---|
44 | if ((!cptr->deviceProbe || cptr->deviceProbe(minor)) && |
---|
45 | cptr->pDeviceFns->deviceProbe(minor)) { |
---|
46 | return true; |
---|
47 | } |
---|
48 | return false; |
---|
49 | } |
---|
50 | |
---|
51 | /* |
---|
52 | * Method to return the first available device. |
---|
53 | */ |
---|
54 | static rtems_device_minor_number bsp_First_Available_Device( void ) |
---|
55 | { |
---|
56 | rtems_device_minor_number minor; |
---|
57 | |
---|
58 | for (minor=0; minor < Console_Port_Count ; minor++) { |
---|
59 | console_tbl *cptr = Console_Port_Tbl[minor]; |
---|
60 | |
---|
61 | /* |
---|
62 | * First perform the configuration dependent probe, then the |
---|
63 | * device dependent probe |
---|
64 | */ |
---|
65 | |
---|
66 | if ((!cptr->deviceProbe || cptr->deviceProbe(minor)) && |
---|
67 | cptr->pDeviceFns->deviceProbe(minor)) { |
---|
68 | return minor; |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | /* |
---|
73 | * Error No devices were found. We will want to bail here. |
---|
74 | */ |
---|
75 | bsp_fatal(BSP_FATAL_CONSOLE_NO_DEV); |
---|
76 | } |
---|
77 | |
---|
78 | void bsp_console_select(void) |
---|
79 | { |
---|
80 | |
---|
81 | /* |
---|
82 | * Reset Console_Port_Minor and |
---|
83 | * BSPPrintkPort here if desired. |
---|
84 | * |
---|
85 | * This default version allows the bsp to set these |
---|
86 | * values at creation and will not touch them again |
---|
87 | * unless the selected port number is not available. |
---|
88 | */ |
---|
89 | |
---|
90 | /* |
---|
91 | * If the device that was selected isn't available then |
---|
92 | * let the user know and select the first available device. |
---|
93 | */ |
---|
94 | if ( !bsp_Is_Available( Console_Port_Minor ) ) { |
---|
95 | Console_Port_Minor = bsp_First_Available_Device(); |
---|
96 | } |
---|
97 | } |
---|