RTEMS
printk_support.c
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/bspIo.h>
21 #include <rtems/sysinit.h>
22 #include <grlib/apbuart.h>
23 
24 int leon3_debug_uart_index __attribute__((weak)) = 0;
25 struct apbuart_regs *leon3_debug_uart = NULL;
26 
27 /* Before UART driver has registered (or when no UART is available), calls to
28  * printk that gets to bsp_out_char() will be filling data into the
29  * pre_printk_dbgbuf[] buffer, hopefully the buffer can help debugging the
30  * early BSP boot.. At least the last printk() will be caught.
31  */
32 static char pre_printk_dbgbuf[32] = {0};
33 static int pre_printk_pos = 0;
34 
35 /* Initialize the BSP system debug console layer. It will scan AMBA Plu&Play
36  * for a debug APBUART and enable RX/TX for that UART.
37  */
38 static void bsp_debug_uart_init(void)
39 {
40  int i;
41  struct ambapp_dev *adev;
42  struct ambapp_apb_info *apb;
43 
44  /* Update leon3_debug_uart_index to index used as debug console. Let user
45  * select Debug console by setting leon3_debug_uart_index. If the BSP is to
46  * provide the default UART (leon3_debug_uart_index==0):
47  * non-MP: APBUART[0] is debug console
48  * MP: LEON CPU index select UART
49  */
50  if (leon3_debug_uart_index == 0) {
51 #if defined(RTEMS_MULTIPROCESSING)
52  leon3_debug_uart_index = LEON3_Cpu_Index;
53 #else
54  leon3_debug_uart_index = 0;
55 #endif
56  } else {
57  leon3_debug_uart_index--; /* User selected dbg-console */
58  }
59 
60  /* Find APBUART core for System Debug Console */
61  i = leon3_debug_uart_index;
62  adev = (void *)ambapp_for_each(&ambapp_plb, (OPTIONS_ALL|OPTIONS_APB_SLVS),
63  VENDOR_GAISLER, GAISLER_APBUART,
64  ambapp_find_by_idx, (void *)&i);
65  if (adev) {
66  /* Found a matching debug console, initialize debug uart if present
67  * for printk
68  */
69  apb = (struct ambapp_apb_info *)adev->devinfo;
70  leon3_debug_uart = (struct apbuart_regs *)apb->start;
71  leon3_debug_uart->ctrl |= APBUART_CTRL_RE | APBUART_CTRL_TE;
72  leon3_debug_uart->status = 0;
73  }
74 }
75 
76 RTEMS_SYSINIT_ITEM(
77  bsp_debug_uart_init,
78  RTEMS_SYSINIT_BSP_START,
79  RTEMS_SYSINIT_ORDER_FOURTH
80 );
81 
82 /* putchar/getchar for printk */
83 static void bsp_out_char(char c)
84 {
85  if (leon3_debug_uart == NULL) {
86  /* Local debug buffer when UART driver has not registered */
87  pre_printk_dbgbuf[pre_printk_pos++] = c;
88  pre_printk_pos = pre_printk_pos & (sizeof(pre_printk_dbgbuf)-1);
89  return;
90  }
91 
92  apbuart_outbyte_polled(leon3_debug_uart, c, 1, 1);
93 }
94 
95 /*
96  * To support printk
97  */
98 
100 
101 static int bsp_in_char(void)
102 {
103  int tmp;
104 
105  if (leon3_debug_uart == NULL)
106  return -1;
107 
108  while ((tmp = apbuart_inbyte_nonblocking(leon3_debug_uart)) < 0)
109  ;
110  return tmp;
111 }
112 
BSP_polling_getchar_function_type BSP_poll_char
LEON3 BSP data types and macros.
Interface to Kernel Print Methods.
BSP_output_char_function_type BSP_output_char
int(* BSP_polling_getchar_function_type)(void)
Definition: bspIo.h:55
void(* BSP_output_char_function_type)(char c)
Definition: bspIo.h:49