source: rtems/c/src/lib/libbsp/sparc/leon3/console/printk_support.c @ 4c927c79

5
Last change on this file since 4c927c79 was 4c927c79, checked in by Sebastian Huber <sebastian.huber@…>, on 06/21/16 at 07:10:28

bsp/leon3: Fix LEON3_Cpu_Index initialization

  • 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.org/license/LICENSE.
16 */
17
18#include <bsp.h>
19#include <leon.h>
20#include <rtems/libio.h>
21#include <rtems/sysinit.h>
22#include <stdlib.h>
23#include <assert.h>
24#include <stdio.h>
25#include <bsp/apbuart.h>
26#include <bsp/apbuart_termios.h>
27
28int debug_uart_index __attribute__((weak)) = 0;
29struct apbuart_regs *dbg_uart = NULL;
30
31/* Before UART driver has registered (or when no UART is available), calls to
32 * printk that gets to bsp_out_char() will be filling data into the
33 * pre_printk_dbgbuf[] buffer, hopefully the buffer can help debugging the
34 * early BSP boot.. At least the last printk() will be caught.
35 */
36static char pre_printk_dbgbuf[32] = {0};
37static int pre_printk_pos = 0;
38
39/* Initialize the BSP system debug console layer. It will scan AMBA Plu&Play
40 * for a debug APBUART and enable RX/TX for that UART.
41 */
42static void bsp_debug_uart_init(void)
43{
44  int i;
45  struct ambapp_dev *adev;
46  struct ambapp_apb_info *apb;
47
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 = (struct apbuart_regs *)apb->start;
75    dbg_uart->ctrl |= APBUART_CTRL_RE | APBUART_CTRL_TE;
76    dbg_uart->status = 0;
77  }
78}
79
80RTEMS_SYSINIT_ITEM(
81  bsp_debug_uart_init,
82  RTEMS_SYSINIT_BSP_START,
83  RTEMS_SYSINIT_ORDER_FOURTH
84);
85
86/* putchar/getchar for printk */
87static void bsp_out_char(char c)
88{
89  if (dbg_uart == NULL) {
90    /* Local debug buffer when UART driver has not registered */
91    pre_printk_dbgbuf[pre_printk_pos++] = c;
92    pre_printk_pos = pre_printk_pos & (sizeof(pre_printk_dbgbuf)-1);
93    return;
94  }
95
96  apbuart_outbyte_polled(dbg_uart, c, 1, 1);
97}
98
99/*
100 *  To support printk
101 */
102
103#include <rtems/bspIo.h>
104
105BSP_output_char_function_type BSP_output_char = bsp_out_char;
106
107static int bsp_in_char(void)
108{
109  int tmp;
110
111  if (dbg_uart == NULL)
112    return EOF;
113
114  while ((tmp = apbuart_inbyte_nonblocking(dbg_uart)) < 0)
115    ;
116  return tmp;
117}
118
119BSP_polling_getchar_function_type BSP_poll_char = bsp_in_char;
Note: See TracBrowser for help on using the repository browser.