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

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

LEON3: console use register pointers instead of UART indexes

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

  • Property mode set to 100644
File size: 3.2 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#include <stdio.h>
25
26/*
27 * Number of uarts on AMBA bus
28 */
29extern int uarts;
30
31static int isinit = 0;
32
33/* Let user override which on-chip APBUART will be debug UART
34 * 0 = Default APBUART. On MP system CPU0=APBUART0, CPU1=APBUART1...
35 * 1 = APBUART[0]
36 * 2 = APBUART[1]
37 * 3 = APBUART[2]
38 * ...
39 */
40int debug_uart_index __attribute__((weak)) = 0;
41ambapp_apb_uart *dbg_uart = NULL;
42
43/*
44 *  Scan for UARTS in configuration
45 */
46int scan_uarts(void)
47{
48  int i;
49  amba_apb_device apbuarts[LEON3_APBUARTS];
50
51  if (isinit == 0) {
52    i = 0;
53    uarts = 0;
54
55    uarts = amba_find_apbslvs(
56      &amba_conf, VENDOR_GAISLER, GAISLER_APBUART, apbuarts, LEON3_APBUARTS);
57    for(i=0; i<uarts; i++) {
58      LEON3_Console_Uart[i] = (volatile LEON3_UART_Regs_Map *)apbuarts[i].start;
59    }
60
61    /* Update debug_uart_index to index used as debug console.
62     * Let user select Debug console by setting debug_uart_index. If the
63     * BSP is to provide the default UART (debug_uart_index==0):
64     *   non-MP: APBUART[0] is debug console
65     *   MP: LEON CPU index select UART
66     */
67    if (debug_uart_index == 0) {
68#if defined(RTEMS_MULTIPROCESSING)
69      debug_uart_index = LEON3_Cpu_Index;
70#else
71      debug_uart_index = 0;
72#endif
73    } else {
74      debug_uart_index = debug_uart_index - 1; /* User selected dbg-console */
75    }
76
77    /* initialize debug uart if present for printk */
78    if (debug_uart_index < uarts) {
79      dbg_uart = (ambapp_apb_uart *)LEON3_Console_Uart[debug_uart_index];
80      dbg_uart->ctrl |= LEON_REG_UART_CTRL_RE | LEON_REG_UART_CTRL_TE;
81      dbg_uart->status = 0;
82    }
83    isinit = 1;
84  }
85
86  return uarts;
87}
88
89/*
90 *  apbuart_outbyte_polled
91 *
92 *  This routine transmits a character using polling.
93 */
94void apbuart_outbyte_polled(
95  ambapp_apb_uart *regs,
96  unsigned char ch
97)
98{
99  while ( (regs->status & LEON_REG_UART_STATUS_THE) == 0 );
100  regs->data = (unsigned int) ch;
101}
102
103/*
104 *  apbuart_inbyte_nonblocking
105 *
106 *  This routine polls for a character.
107 */
108int apbuart_inbyte_nonblocking(ambapp_apb_uart *regs)
109{
110  /* Clear errors */
111  if (regs->status & LEON_REG_UART_STATUS_ERR)
112    regs->status = ~LEON_REG_UART_STATUS_ERR;
113
114  if ((regs->status & LEON_REG_UART_STATUS_DR) == 0)
115    return EOF;
116  else
117    return (int) regs->data;
118}
119
120/* putchar/getchar for printk */
121static void bsp_out_char(char c)
122{
123  if (dbg_uart == NULL)
124    return;
125
126  apbuart_outbyte_polled(dbg_uart, c);
127}
128
129/*
130 *  To support printk
131 */
132
133#include <rtems/bspIo.h>
134
135BSP_output_char_function_type BSP_output_char = bsp_out_char;
136
137static int bsp_in_char(void)
138{
139  int tmp;
140
141  if (dbg_uart == NULL)
142    return EOF;
143
144  while ((tmp = apbuart_inbyte_nonblocking(dbg_uart)) < 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.