diff options
author | Daniel Hellstrom <daniel@gaisler.com> | 2012-04-05 10:23:18 -0500 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@oarcorp.com> | 2012-04-05 14:33:48 -0500 |
commit | 4b557617fdd3448f1c40798e3a075a5d8ce9a5c6 (patch) | |
tree | 9f7a9021037a20a4438cb47991df8d519d4e7c0d /c/src/lib/libbsp/sparc/leon3/console/debugputs.c | |
parent | Add MIPS/Malta BSP. (diff) | |
download | rtems-4b557617fdd3448f1c40798e3a075a5d8ce9a5c6.tar.bz2 |
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_['a' + 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@gaisler.com>
Diffstat (limited to 'c/src/lib/libbsp/sparc/leon3/console/debugputs.c')
-rw-r--r-- | c/src/lib/libbsp/sparc/leon3/console/debugputs.c | 73 |
1 files changed, 50 insertions, 23 deletions
diff --git a/c/src/lib/libbsp/sparc/leon3/console/debugputs.c b/c/src/lib/libbsp/sparc/leon3/console/debugputs.c index 2cd0d136e1..cf3f280520 100644 --- a/c/src/lib/libbsp/sparc/leon3/console/debugputs.c +++ b/c/src/lib/libbsp/sparc/leon3/console/debugputs.c @@ -7,8 +7,8 @@ * On-Line Applications Research Corporation (OAR). * * Modified for LEON3 BSP. - * COPYRIGHT (c) 2004. - * Gaisler Research. + * COPYRIGHT (c) 2011. + * Aeroflex Gaisler. * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at @@ -29,6 +29,15 @@ extern int uarts; static int isinit = 0; +/* Let user override which on-chip APBUART will be debug UART + * 0 = Default APBUART. On MP system CPU0=APBUART0, CPU1=APBUART1... + * 1 = APBUART[0] + * 2 = APBUART[1] + * 3 = APBUART[2] + * ... + */ +int debug_uart_index __attribute__((weak)) = 0; + /* * Scan for UARTS in configuration */ @@ -47,11 +56,27 @@ int scan_uarts(void) LEON3_Console_Uart[i] = (volatile LEON3_UART_Regs_Map *)apbuarts[i].start; } - /* initialize uart 0 if present for printk */ - if ( uarts ) { - LEON3_Console_Uart[0]->ctrl |= - LEON_REG_UART_CTRL_RE | LEON_REG_UART_CTRL_TE; - LEON3_Console_Uart[0]->status = 0; + /* Update debug_uart_index to index used as debug console. + * Let user select Debug console by setting debug_uart_index. If the + * BSP is to provide the default UART (debug_uart_index==0): + * non-MP: APBUART[0] is debug console + * MP: LEON CPU index select UART + */ + if (debug_uart_index == 0) { +#if defined(RTEMS_MULTIPROCESSING) + debug_uart_index = LEON3_Cpu_Index; +#else + debug_uart_index = 0; +#endif + } else { + debug_uart_index = debug_uart_index - 1; /* User selected dbg-console */ + } + + /* initialize debug uart if present for printk */ + if (debug_uart_index < uarts) { + LEON3_Console_Uart[debug_uart_index]->ctrl |= LEON_REG_UART_CTRL_RE | + LEON_REG_UART_CTRL_TE; + LEON3_Console_Uart[debug_uart_index]->status = 0; } isinit = 1; } @@ -70,10 +95,10 @@ void console_outbyte_polled( ) { if ((port >= 0) && (port < uarts)) { - int u = LEON3_Cpu_Index+port; - while ( (LEON3_Console_Uart[u]->status & LEON_REG_UART_STATUS_THE) == 0 ); - LEON3_Console_Uart[u]->data = (unsigned int) ch; - } + return; + + while ( (LEON3_Console_Uart[port]->status & LEON_REG_UART_STATUS_THE) == 0 ); + LEON3_Console_Uart[port]->data = (unsigned int) ch; } /* @@ -81,26 +106,27 @@ void console_outbyte_polled( * * This routine polls for a character. */ -int console_inbyte_nonblocking( int port ) +int apbuart_inbyte_nonblocking(int port) { if ((port >= 0) && (port < uarts)) { - int u = LEON3_Cpu_Index+port; - if (LEON3_Console_Uart[u]->status & LEON_REG_UART_STATUS_ERR) - LEON3_Console_Uart[u]->status = ~LEON_REG_UART_STATUS_ERR; - - if ((LEON3_Console_Uart[u]->status & LEON_REG_UART_STATUS_DR) == 0) - return -1; - return (int) LEON3_Console_Uart[u]->data; - } else { assert( 0 ); + return -1; } - return -1; + + /* Clear errors */ + if (LEON3_Console_Uart[port]->status & LEON_REG_UART_STATUS_ERR) + LEON3_Console_Uart[port]->status = ~LEON_REG_UART_STATUS_ERR; + + if ((LEON3_Console_Uart[port]->status & LEON_REG_UART_STATUS_DR) == 0) + return -1; + else + return (int) LEON3_Console_Uart[port]->data; } /* putchar/getchar for printk */ static void bsp_out_char(char c) { - console_outbyte_polled(0, c); + console_outbyte_polled(debug_uart_index, c); } /* @@ -115,7 +141,8 @@ static int bsp_in_char(void) { int tmp; - while ((tmp = console_inbyte_nonblocking(0)) < 0); + while ((tmp = apbuart_inbyte_nonblocking(debug_uart_index)) < 0) + ; return tmp; } |