source: rtems/c/src/lib/libbsp/sparc/leon3/console/console.c @ 5823bae8

4.115
Last change on this file since 5823bae8 was 5823bae8, checked in by Daniel Hellstrom <daniel@…>, on 02/27/15 at 13:03:15

LEON: move driver headers to bsp/ directory

  • Property mode set to 100644
File size: 4.6 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-1998.
7 *  On-Line Applications Research Corporation (OAR).
8 *
9 *  Modified for LEON3 BSP.
10 *  COPYRIGHT (c) 2004.
11 *  Gaisler Research.
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
[62694fd]18/* Define CONSOLE_USE_INTERRUPTS to enable APBUART interrupt handling instead
19 * of polling mode.
20 *
21 * Note that it is not possible to use the interrupt mode of the driver
22 * together with the "old" APBUART and -u to GRMON. However the new
23 * APBUART core (from GRLIB 1.0.17-b2710) has the GRMON debug bit and can
24 * handle interrupts.
25 *
26 * NOTE: This can be defined in the make/custom/leon3.cfg file.
27 */
28
[41c9282]29#include <bsp.h>
[46d7fa5]30#include <bsp/fatal.h>
[5823bae8]31#include <bsp/apbuart_termios.h>
[41c9282]32
[e428dc4a]33/* The LEON3 BSP UART driver can rely on the Driver Manager if the
34 * DrvMgr is initialized during startup. Otherwise the classic driver
35 * must be used.
36 *
37 * The DrvMgr APBUART driver is located in the shared/uart directory
38 */
39#ifndef RTEMS_DRVMGR_STARTUP
40
[4b557617]41int syscon_uart_index __attribute__((weak)) = 0;
42
[41c9282]43/* body is in debugputs.c */
[21abc43]44static struct apbuart_context apbuarts[BSP_NUMBER_OF_TERMIOS_PORTS];
[ddf0d60]45static int uarts = 0;
[41c9282]46
[7fd5e89]47static rtems_termios_device_context *leon3_console_get_context(int minor)
[6fe6d017]48{
[21abc43]49  struct apbuart_context *uart;
[6fe6d017]50
51  if (minor == 0)
52    uart = &apbuarts[syscon_uart_index];
53  else
54    uart = &apbuarts[minor - 1];
55
[7fd5e89]56  rtems_termios_device_context_initialize(&uart->base, "APBUART");
57
58  return &uart->base;
[6fe6d017]59}
60
[ddf0d60]61/* AMBA PP find routine. Extract AMBA PnP information into data structure. */
[1d5d6de]62static int find_matching_apbuart(struct ambapp_dev *dev, int index, void *arg)
[ddf0d60]63{
64  struct ambapp_apb_info *apb = (struct ambapp_apb_info *)dev->devinfo;
65
66  /* Extract needed information of one APBUART */
[226d48d8]67  apbuarts[uarts].regs = (struct apbuart_regs *)apb->start;
[62694fd]68  apbuarts[uarts].irq = apb->irq;
[ddf0d60]69  /* Get APBUART core frequency, it is assumed that it is the same
70   * as Bus frequency where the UART is situated
71   */
72  apbuarts[uarts].freq_hz = ambapp_freq_get(&ambapp_plb, dev);
73  uarts++;
74
75  if (uarts >= BSP_NUMBER_OF_TERMIOS_PORTS)
76    return 1; /* Satisfied number of UARTs, stop search */
77  else
78    return 0; /* Continue searching for more UARTs */
79}
80
81/* Find all UARTs */
[1d5d6de]82static void leon3_console_scan_uarts(void)
[ddf0d60]83{
84  memset(apbuarts, 0, sizeof(apbuarts));
85
86  /* Find APBUART cores */
87  ambapp_for_each(&ambapp_plb, (OPTIONS_ALL|OPTIONS_APB_SLVS), VENDOR_GAISLER,
88                  GAISLER_APBUART, find_matching_apbuart, NULL);
[4b557617]89}
[41c9282]90
91rtems_device_driver console_initialize(
92  rtems_device_major_number  major,
93  rtems_device_minor_number  minor,
94  void                      *arg
95)
96{
[21abc43]97  const rtems_termios_device_handler *handler =
98#if CONSOLE_USE_INTERRUPTS
99    &apbuart_handler_interrupt;
100#else
101    &apbuart_handler_polled;
102#endif
[41c9282]103  rtems_status_code status;
[4b557617]104  int i;
[921bb59]105  char console_name[16];
[41c9282]106
107  rtems_termios_initialize();
108
[ddf0d60]109  /* Find UARTs */
[1d5d6de]110  leon3_console_scan_uarts();
[ddf0d60]111
[4b557617]112  /* Update syscon_uart_index to index used as /dev/console
113   * Let user select System console by setting syscon_uart_index. If the
114   * BSP is to provide the default UART (syscon_uart_index==0):
115   *   non-MP: APBUART[0] is system console
116   *   MP: LEON CPU index select UART
117   */
118  if (syscon_uart_index == 0) {
119#if defined(RTEMS_MULTIPROCESSING)
120    syscon_uart_index = LEON3_Cpu_Index;
121#else
122    syscon_uart_index = 0;
123#endif
124  } else {
125    syscon_uart_index = syscon_uart_index - 1; /* User selected sys-console */
126  }
[41c9282]127
[4b557617]128  /*  Register Device Names
129   *
130   *  0 /dev/console   - APBUART[USER-SELECTED, DEFAULT=APBUART[0]]
131   *  1 /dev/console_a - APBUART[0] (by default not present because is console)
132   *  2 /dev/console_b - APBUART[1]
133   *  ...
134   *
135   * On a MP system one should not open UARTs that other OS instances use.
136   */
137  if (syscon_uart_index < uarts) {
[21abc43]138    minor = 0;
139    status = rtems_termios_device_install(
140      CONSOLE_DEVICE_NAME,
141      major,
142      minor,
143      handler,
[a830cb8]144      NULL,
[7fd5e89]145      leon3_console_get_context(syscon_uart_index)
[21abc43]146    );
[41c9282]147    if (status != RTEMS_SUCCESSFUL)
[46d7fa5]148      bsp_fatal(LEON3_FATAL_CONSOLE_REGISTER_DEV);
[41c9282]149  }
[4b557617]150  strcpy(console_name,"/dev/console_a");
151  for (i = 0; i < uarts; i++) {
152    if (i == syscon_uart_index)
153      continue; /* skip UART that is registered as /dev/console */
154    console_name[13] = 'a' + i;
[21abc43]155    minor = i + 1;
156    rtems_termios_device_install(
157      console_name,
158      major,
159      minor,
160      handler,
[a830cb8]161      NULL,
[7fd5e89]162      leon3_console_get_context(syscon_uart_index)
[21abc43]163    );
[41c9282]164  }
165
166  return RTEMS_SUCCESSFUL;
167}
[e428dc4a]168
169#endif
Note: See TracBrowser for help on using the repository browser.