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

4.115
Last change on this file since 605b4b64 was 605b4b64, checked in by Daniel Hellstrom <daniel@…>, on 04/19/12 at 13:21:24

LEON3: debugputs removed pointless isinit code, invoked only once

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

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