source: rtems/c/src/lib/libbsp/sparc/leon3/console/printk_support.c @ 920a43e

4.115
Last change on this file since 920a43e was 1d5d6de, checked in by Sebastian Huber <sebastian.huber@…>, on 11/26/13 at 08:11:57

bsp/leon3: Console driver changes

Move declaration of global variables and functions to <leon.h> header
file. Make several global variables and functions static.

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