source: rtems/c/src/lib/libbsp/sparc/leon3/console/printk_support.c @ 224b888

4.115
Last change on this file since 224b888 was 224b888, checked in by Sebastian Huber <sebastian.huber@…>, on Feb 6, 2014 at 7:39:51 AM

bsp/leon3: Declare bsp_debug_uart_init() in header

Do not return a status.

  • Property mode set to 100644
File size: 4.1 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 */
39void 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  }
75}
76
77/*
78 *  apbuart_outbyte_polled
79 *
80 *  This routine transmits a character using polling.
81 */
82void apbuart_outbyte_polled(
83  struct apbuart_regs *regs,
84  unsigned char ch,
85  int do_cr_on_newline,
86  int wait_sent
87)
88{
89send:
90  while ( (regs->status & LEON_REG_UART_STATUS_THE) == 0 ) {
91    /* Lower bus utilization while waiting for UART */
92    asm volatile ("nop"::); asm volatile ("nop"::);
93    asm volatile ("nop"::); asm volatile ("nop"::);
94    asm volatile ("nop"::); asm volatile ("nop"::);
95    asm volatile ("nop"::); asm volatile ("nop"::);
96  }
97  regs->data = (unsigned int) ch;
98
99  if ((ch == '\n') && do_cr_on_newline) {
100    ch = '\r';
101    goto send;
102  }
103
104  /* Wait until the character has been sent? */
105  if (wait_sent) {
106    while ((regs->status & LEON_REG_UART_STATUS_THE) == 0)
107      ;
108  }
109}
110
111/*
112 *  apbuart_inbyte_nonblocking
113 *
114 *  This routine polls for a character.
115 */
116int apbuart_inbyte_nonblocking(struct apbuart_regs *regs)
117{
118  /* Clear errors */
119  if (regs->status & LEON_REG_UART_STATUS_ERR)
120    regs->status = ~LEON_REG_UART_STATUS_ERR;
121
122  if ((regs->status & LEON_REG_UART_STATUS_DR) == 0)
123    return EOF;
124  else
125    return (int) regs->data;
126}
127
128/* putchar/getchar for printk */
129static void bsp_out_char(char c)
130{
131  if (dbg_uart == NULL) {
132    /* Local debug buffer when UART driver has not registered */
133    pre_printk_dbgbuf[pre_printk_pos++] = c;
134    pre_printk_pos = pre_printk_pos & (sizeof(pre_printk_dbgbuf)-1);
135    return;
136  }
137
138  apbuart_outbyte_polled(dbg_uart, c, 1, 1);
139}
140
141/*
142 *  To support printk
143 */
144
145#include <rtems/bspIo.h>
146
147BSP_output_char_function_type BSP_output_char = bsp_out_char;
148
149static int bsp_in_char(void)
150{
151  int tmp;
152
153  if (dbg_uart == NULL)
154    return EOF;
155
156  while ((tmp = apbuart_inbyte_nonblocking(dbg_uart)) < 0)
157    ;
158  return tmp;
159}
160
161BSP_polling_getchar_function_type BSP_poll_char = bsp_in_char;
Note: See TracBrowser for help on using the repository browser.