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

4.115
Last change on this file since b802353 was b802353, checked in by Sebastian Huber <sebastian.huber@…>, on 09/05/14 at 07:27:56

bsp/leon3: Include missing header file

  • Property mode set to 100644
File size: 3.0 KB
RevLine 
[41c9282]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.
[4b557617]10 *  COPYRIGHT (c) 2011.
11 *  Aeroflex Gaisler.
[41c9282]12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
[c499856]15 *  http://www.rtems.org/license/LICENSE.
[41c9282]16 */
17
18#include <bsp.h>
[1d5d6de]19#include <leon.h>
[41c9282]20#include <rtems/libio.h>
21#include <stdlib.h>
22#include <assert.h>
[e60e862]23#include <stdio.h>
[516a60a]24#include <apbuart.h>
[b802353]25#include <apbuart_termios.h>
[41c9282]26
[4b557617]27int debug_uart_index __attribute__((weak)) = 0;
[1d5d6de]28static struct apbuart_regs *dbg_uart = NULL;
[4b557617]29
[5903484]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 */
[1d5d6de]35static char pre_printk_dbgbuf[32] = {0};
36static int pre_printk_pos = 0;
[5903484]37
[ddf0d60]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.
[d17733c]40 */
[224b888]41void bsp_debug_uart_init(void)
[d17733c]42{
43  int i;
[ddf0d60]44  struct ambapp_dev *adev;
45  struct ambapp_apb_info *apb;
[d17733c]46
[605b4b64]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) {
[4b557617]54#if defined(RTEMS_MULTIPROCESSING)
[605b4b64]55    debug_uart_index = LEON3_Cpu_Index;
[4b557617]56#else
[605b4b64]57    debug_uart_index = 0;
[4b557617]58#endif
[605b4b64]59  } else {
60    debug_uart_index = debug_uart_index - 1; /* User selected dbg-console */
[d17733c]61  }
62
[605b4b64]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;
[226d48d8]73    dbg_uart = (struct apbuart_regs *)apb->start;
[516a60a]74    dbg_uart->ctrl |= APBUART_CTRL_RE | APBUART_CTRL_TE;
[605b4b64]75    dbg_uart->status = 0;
[224b888]76  }
[d17733c]77}
78
[344ba65a]79/* putchar/getchar for printk */
80static void bsp_out_char(char c)
81{
[5903484]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);
[e60e862]86    return;
[5903484]87  }
[e60e862]88
[5d48037]89  apbuart_outbyte_polled(dbg_uart, c, 1, 1);
[344ba65a]90}
91
[f752c24]92/*
93 *  To support printk
94 */
95
96#include <rtems/bspIo.h>
97
[344ba65a]98BSP_output_char_function_type BSP_output_char = bsp_out_char;
99
[56035ca3]100static int bsp_in_char(void)
[344ba65a]101{
102  int tmp;
103
[e60e862]104  if (dbg_uart == NULL)
105    return EOF;
106
107  while ((tmp = apbuart_inbyte_nonblocking(dbg_uart)) < 0)
[4b557617]108    ;
[56035ca3]109  return tmp;
[344ba65a]110}
111
112BSP_polling_getchar_function_type BSP_poll_char = bsp_in_char;
Note: See TracBrowser for help on using the repository browser.