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

4.115
Last change on this file since ddf0d60 was ddf0d60, checked in by Daniel Hellstrom <daniel@…>, on 04/17/12 at 14:25:40

LEON3: updated console driver for new AMBAPP layer

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#include <stdio.h>
25
26static int isinit = 0;
27
28/* Let user override which on-chip APBUART will be debug UART
29 * 0 = Default APBUART. On MP system CPU0=APBUART0, CPU1=APBUART1...
30 * 1 = APBUART[0]
31 * 2 = APBUART[1]
32 * 3 = APBUART[2]
33 * ...
34 */
35int debug_uart_index __attribute__((weak)) = 0;
36ambapp_apb_uart *dbg_uart = NULL;
37
38/* Initialize the BSP system debug console layer. It will scan AMBA Plu&Play
39 * for a debug APBUART and enable RX/TX for that UART.
40 */
41int bsp_debug_uart_init(void)
42{
43  int i;
44  struct ambapp_dev *adev;
45  struct ambapp_apb_info *apb;
46
47  if (isinit == 0) {
48    /* Update debug_uart_index to index used as debug console.
49     * Let user select Debug console by setting debug_uart_index. If the
50     * BSP is to provide the default UART (debug_uart_index==0):
51     *   non-MP: APBUART[0] is debug console
52     *   MP: LEON CPU index select UART
53     */
54    if (debug_uart_index == 0) {
55#if defined(RTEMS_MULTIPROCESSING)
56      debug_uart_index = LEON3_Cpu_Index;
57#else
58      debug_uart_index = 0;
59#endif
60    } else {
61      debug_uart_index = debug_uart_index - 1; /* User selected dbg-console */
62    }
63
64    /* Find APBUART core for System Debug Console */
65    i = debug_uart_index;
66    adev = (void *)ambapp_for_each(&ambapp_plb, (OPTIONS_ALL|OPTIONS_APB_SLVS),
67                                   VENDOR_GAISLER, GAISLER_APBUART,
68                                   ambapp_find_by_idx, (void *)&i);
69    if (adev) {
70      /* Found a matching debug console, initialize debug uart if present
71       * for printk
72       */
73      apb = (struct ambapp_apb_info *)adev->devinfo;
74      dbg_uart = (ambapp_apb_uart *)apb->start;
75      dbg_uart->ctrl |= LEON_REG_UART_CTRL_RE | LEON_REG_UART_CTRL_TE;
76      dbg_uart->status = 0;
77    }
78    isinit = 1;
79  }
80
81  if (dbg_uart == NULL)
82    return 0;
83  else
84    return 1;
85}
86
87/*
88 *  apbuart_outbyte_polled
89 *
90 *  This routine transmits a character using polling.
91 */
92void apbuart_outbyte_polled(
93  ambapp_apb_uart *regs,
94  unsigned char ch
95)
96{
97  while ( (regs->status & LEON_REG_UART_STATUS_THE) == 0 );
98  regs->data = (unsigned int) ch;
99}
100
101/*
102 *  apbuart_inbyte_nonblocking
103 *
104 *  This routine polls for a character.
105 */
106int apbuart_inbyte_nonblocking(ambapp_apb_uart *regs)
107{
108  /* Clear errors */
109  if (regs->status & LEON_REG_UART_STATUS_ERR)
110    regs->status = ~LEON_REG_UART_STATUS_ERR;
111
112  if ((regs->status & LEON_REG_UART_STATUS_DR) == 0)
113    return EOF;
114  else
115    return (int) regs->data;
116}
117
118/* putchar/getchar for printk */
119static void bsp_out_char(char c)
120{
121  if (dbg_uart == NULL)
122    return;
123
124  apbuart_outbyte_polled(dbg_uart, c);
125}
126
127/*
128 *  To support printk
129 */
130
131#include <rtems/bspIo.h>
132
133BSP_output_char_function_type BSP_output_char = bsp_out_char;
134
135static int bsp_in_char(void)
136{
137  int tmp;
138
139  if (dbg_uart == NULL)
140    return EOF;
141
142  while ((tmp = apbuart_inbyte_nonblocking(dbg_uart)) < 0)
143    ;
144  return tmp;
145}
146
147BSP_polling_getchar_function_type BSP_poll_char = bsp_in_char;
Note: See TracBrowser for help on using the repository browser.