source: rtems/c/src/lib/libbsp/sparc/leon3/console/debugputs.c @ da416d4f

Last change on this file since da416d4f was da416d4f, checked in by Daniel Hellstrom <daniel@…>, on 04/05/12 at 15:23:18

LEON3: cleanup console UART indexing handling

The UART indexing was rather a mess when MP was enabled. The changes
introduces two weak variables syscon_uart_index and debug_uart_index
so that the user can override the default system debug console (printk)
and system console UART (/dev/console).

The two weak variables is updated on boot to reflect the "real" UART
index.

MINOR DEVICE-FS-NAME UART
0 /dev/console Default /dev/console_a, user selectable
1 /dev/console_a APBUART[0] (missing by default)
2 /dev/console_b APBUART[1]
...

/dev/console_a is by default renamed /dev/console and assigned minor=0,
but user can select /dev/console_['a'+N] to be renamed to /dev/console
by setting syscon_uart_index=N.

On a MP system the console renamed to /dev/console is selected by CPU
index (LEON3_Cpu_Index). /dev/console_+ LEON3_Cpu_Index? is
renamed unless overrided. Resource sharing is performed by the user,
one should not open/access a console that another OS instance uses.

This patch also moves the initialization of the UART to the open()
call, note that before APBUART[0] was always enabled as debug uart
even on MP systems. The debug UART is initialized at boot time.

Signed-off-by: Daniel Hellstrom <daniel@…>

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 *  This file contains the TTY driver for the serial ports on the LEON.
3 *
4 *  This driver uses the termios pseudo driver.
5 *
6 *  COPYRIGHT (c) 1989-1999.
7 *  On-Line Applications Research Corporation (OAR).
8 *
9 *  Modified for LEON3 BSP.
10 *  COPYRIGHT (c) 2011.
11 *  Aeroflex Gaisler.
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.com/license/LICENSE.
16 *
17 *  $Id$
18 */
19
20#include <bsp.h>
21#include <rtems/libio.h>
22#include <stdlib.h>
23#include <assert.h>
24
25/*
26 * Number of uarts on AMBA bus
27 */
28extern int uarts;
29
30static int isinit = 0;
31
32/* Let user override which on-chip APBUART will be debug UART
33 * 0 = Default APBUART. On MP system CPU0=APBUART0, CPU1=APBUART1...
34 * 1 = APBUART[0]
35 * 2 = APBUART[1]
36 * 3 = APBUART[2]
37 * ...
38 */
39int debug_uart_index __attribute__((weak)) = 0;
40
41/*
42 *  Scan for UARTS in configuration
43 */
44int scan_uarts(void)
45{
46  int i;
47  amba_apb_device apbuarts[LEON3_APBUARTS];
48
49  if (isinit == 0) {
50    i = 0;
51    uarts = 0;
52
53    uarts = amba_find_apbslvs(
54      &amba_conf, VENDOR_GAISLER, GAISLER_APBUART, apbuarts, LEON3_APBUARTS);
55    for(i=0; i<uarts; i++) {
56      LEON3_Console_Uart[i] = (volatile LEON3_UART_Regs_Map *)apbuarts[i].start;
57    }
58
59    /* Update debug_uart_index to index used as debug console.
60     * Let user select Debug console by setting debug_uart_index. If the
61     * BSP is to provide the default UART (debug_uart_index==0):
62     *   non-MP: APBUART[0] is debug console
63     *   MP: LEON CPU index select UART
64     */
65    if (debug_uart_index == 0) {
66#if defined(RTEMS_MULTIPROCESSING)
67      debug_uart_index = LEON3_Cpu_Index;
68#else
69      debug_uart_index = 0;
70#endif
71    } else {
72      debug_uart_index = debug_uart_index - 1; /* User selected dbg-console */
73    }
74
75    /* initialize debug uart if present for printk */
76    if (debug_uart_index < uarts) {
77      LEON3_Console_Uart[debug_uart_index]->ctrl |= LEON_REG_UART_CTRL_RE |
78                                                    LEON_REG_UART_CTRL_TE;
79      LEON3_Console_Uart[debug_uart_index]->status = 0;
80    }
81    isinit = 1;
82  }
83
84  return uarts;
85}
86
87/*
88 *  console_outbyte_polled
89 *
90 *  This routine transmits a character using polling.
91 */
92void console_outbyte_polled(
93  int           port,
94  unsigned char ch
95)
96{
97  if ((port >= 0) && (port < uarts)) {
98    return;
99
100  while ( (LEON3_Console_Uart[port]->status & LEON_REG_UART_STATUS_THE) == 0 );
101  LEON3_Console_Uart[port]->data = (unsigned int) ch;
102}
103
104/*
105 *  console_inbyte_nonblocking
106 *
107 *  This routine polls for a character.
108 */
109int apbuart_inbyte_nonblocking(int port)
110{
111  if ((port >= 0) && (port < uarts)) {
112    assert( 0 );
113    return -1;
114  }
115
116  /* Clear errors */
117  if (LEON3_Console_Uart[port]->status & LEON_REG_UART_STATUS_ERR)
118    LEON3_Console_Uart[port]->status = ~LEON_REG_UART_STATUS_ERR;
119
120  if ((LEON3_Console_Uart[port]->status & LEON_REG_UART_STATUS_DR) == 0)
121    return -1;
122  else
123    return (int) LEON3_Console_Uart[port]->data;
124}
125
126/* putchar/getchar for printk */
127static void bsp_out_char(char c)
128{
129  console_outbyte_polled(debug_uart_index, c);
130}
131
132/*
133 *  To support printk
134 */
135
136#include <rtems/bspIo.h>
137
138BSP_output_char_function_type BSP_output_char = bsp_out_char;
139
140static int bsp_in_char(void)
141{
142  int tmp;
143
144  while ((tmp = apbuart_inbyte_nonblocking(debug_uart_index)) < 0)
145    ;
146  return tmp;
147}
148
149BSP_polling_getchar_function_type BSP_poll_char = bsp_in_char;
Note: See TracBrowser for help on using the repository browser.