source: rtems/c/src/lib/libbsp/sparc/leon3/console/printk_support.c @ 5ba49066

4.115
Last change on this file since 5ba49066 was 5ba49066, checked in by Daniel Hellstrom <daniel@…>, on Feb 5, 2015 at 7:06:26 AM

LEON3: export debug uart to console uart driver

  • Property mode set to 100644
File size: 3.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.org/license/LICENSE.
16 */
17
18#include <bsp.h>
19#include <leon.h>
20#include <rtems/libio.h>
21#include <stdlib.h>
22#include <assert.h>
23#include <stdio.h>
24#include <apbuart.h>
25#include <apbuart_termios.h>
26
27int debug_uart_index __attribute__((weak)) = 0;
28struct apbuart_regs *dbg_uart = NULL;
29
30/* Before UART driver has registered (or when no UART is available), calls to
31 * printk that gets to bsp_out_char() will be filling data into the
32 * pre_printk_dbgbuf[] buffer, hopefully the buffer can help debugging the
33 * early BSP boot.. At least the last printk() will be caught.
34 */
35static char pre_printk_dbgbuf[32] = {0};
36static int pre_printk_pos = 0;
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 */
41void bsp_debug_uart_init(void)
42{
43  int i;
44  struct ambapp_dev *adev;
45  struct ambapp_apb_info *apb;
46
47  /* Update debug_uart_index to index used as debug console.
48   * Let user select Debug console by setting debug_uart_index. If the
49   * BSP is to provide the default UART (debug_uart_index==0):
50   *   non-MP: APBUART[0] is debug console
51   *   MP: LEON CPU index select UART
52   */
53  if (debug_uart_index == 0) {
54#if defined(RTEMS_MULTIPROCESSING)
55    debug_uart_index = LEON3_Cpu_Index;
56#else
57    debug_uart_index = 0;
58#endif
59  } else {
60    debug_uart_index = debug_uart_index - 1; /* User selected dbg-console */
61  }
62
63  /* Find APBUART core for System Debug Console */
64  i = debug_uart_index;
65  adev = (void *)ambapp_for_each(&ambapp_plb, (OPTIONS_ALL|OPTIONS_APB_SLVS),
66                                 VENDOR_GAISLER, GAISLER_APBUART,
67                                 ambapp_find_by_idx, (void *)&i);
68  if (adev) {
69    /* Found a matching debug console, initialize debug uart if present
70     * for printk
71     */
72    apb = (struct ambapp_apb_info *)adev->devinfo;
73    dbg_uart = (struct apbuart_regs *)apb->start;
74    dbg_uart->ctrl |= APBUART_CTRL_RE | APBUART_CTRL_TE;
75    dbg_uart->status = 0;
76  }
77}
78
79/* putchar/getchar for printk */
80static void bsp_out_char(char c)
81{
82  if (dbg_uart == NULL) {
83    /* Local debug buffer when UART driver has not registered */
84    pre_printk_dbgbuf[pre_printk_pos++] = c;
85    pre_printk_pos = pre_printk_pos & (sizeof(pre_printk_dbgbuf)-1);
86    return;
87  }
88
89  apbuart_outbyte_polled(dbg_uart, c, 1, 1);
90}
91
92/*
93 *  To support printk
94 */
95
96#include <rtems/bspIo.h>
97
98BSP_output_char_function_type BSP_output_char = bsp_out_char;
99
100static int bsp_in_char(void)
101{
102  int tmp;
103
104  if (dbg_uart == NULL)
105    return EOF;
106
107  while ((tmp = apbuart_inbyte_nonblocking(dbg_uart)) < 0)
108    ;
109  return tmp;
110}
111
112BSP_polling_getchar_function_type BSP_poll_char = bsp_in_char;
Note: See TracBrowser for help on using the repository browser.