source: rtems/c/src/lib/libbsp/sparc/leon3/console/console.c @ 7fd5e89

4.115
Last change on this file since 7fd5e89 was 7fd5e89, checked in by Sebastian Huber <sebastian.huber@…>, on Oct 7, 2014 at 2:28:04 PM

termios: Partially hide rtems_termios_tty

Move interrupt lock to device context and expose only this structure to
the read, write and set attributes device handler. This makes these
device handler independent of the general Termios infrastructure
suitable for direct use in printk() support.

  • Property mode set to 100644
File size: 4.4 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-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
15 *  http://www.rtems.org/license/LICENSE.
16 */
17
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
29#include <bsp.h>
30#include <bsp/fatal.h>
31#include <apbuart_termios.h>
32
33int syscon_uart_index __attribute__((weak)) = 0;
34
35/* body is in debugputs.c */
36static struct apbuart_context apbuarts[BSP_NUMBER_OF_TERMIOS_PORTS];
37static int uarts = 0;
38
39static rtems_termios_device_context *leon3_console_get_context(int minor)
40{
41  struct apbuart_context *uart;
42
43  if (minor == 0)
44    uart = &apbuarts[syscon_uart_index];
45  else
46    uart = &apbuarts[minor - 1];
47
48  rtems_termios_device_context_initialize(&uart->base, "APBUART");
49
50  return &uart->base;
51}
52
53/* AMBA PP find routine. Extract AMBA PnP information into data structure. */
54static int find_matching_apbuart(struct ambapp_dev *dev, int index, void *arg)
55{
56  struct ambapp_apb_info *apb = (struct ambapp_apb_info *)dev->devinfo;
57
58  /* Extract needed information of one APBUART */
59  apbuarts[uarts].regs = (struct apbuart_regs *)apb->start;
60  apbuarts[uarts].irq = apb->irq;
61  /* Get APBUART core frequency, it is assumed that it is the same
62   * as Bus frequency where the UART is situated
63   */
64  apbuarts[uarts].freq_hz = ambapp_freq_get(&ambapp_plb, dev);
65  uarts++;
66
67  if (uarts >= BSP_NUMBER_OF_TERMIOS_PORTS)
68    return 1; /* Satisfied number of UARTs, stop search */
69  else
70    return 0; /* Continue searching for more UARTs */
71}
72
73/* Find all UARTs */
74static void leon3_console_scan_uarts(void)
75{
76  memset(apbuarts, 0, sizeof(apbuarts));
77
78  /* Find APBUART cores */
79  ambapp_for_each(&ambapp_plb, (OPTIONS_ALL|OPTIONS_APB_SLVS), VENDOR_GAISLER,
80                  GAISLER_APBUART, find_matching_apbuart, NULL);
81}
82
83rtems_device_driver console_initialize(
84  rtems_device_major_number  major,
85  rtems_device_minor_number  minor,
86  void                      *arg
87)
88{
89  const rtems_termios_device_handler *handler =
90#if CONSOLE_USE_INTERRUPTS
91    &apbuart_handler_interrupt;
92#else
93    &apbuart_handler_polled;
94#endif
95  rtems_status_code status;
96  int i;
97  char console_name[16];
98
99  rtems_termios_initialize();
100
101  /* Find UARTs */
102  leon3_console_scan_uarts();
103
104  /* Update syscon_uart_index to index used as /dev/console
105   * Let user select System console by setting syscon_uart_index. If the
106   * BSP is to provide the default UART (syscon_uart_index==0):
107   *   non-MP: APBUART[0] is system console
108   *   MP: LEON CPU index select UART
109   */
110  if (syscon_uart_index == 0) {
111#if defined(RTEMS_MULTIPROCESSING)
112    syscon_uart_index = LEON3_Cpu_Index;
113#else
114    syscon_uart_index = 0;
115#endif
116  } else {
117    syscon_uart_index = syscon_uart_index - 1; /* User selected sys-console */
118  }
119
120  /*  Register Device Names
121   *
122   *  0 /dev/console   - APBUART[USER-SELECTED, DEFAULT=APBUART[0]]
123   *  1 /dev/console_a - APBUART[0] (by default not present because is console)
124   *  2 /dev/console_b - APBUART[1]
125   *  ...
126   *
127   * On a MP system one should not open UARTs that other OS instances use.
128   */
129  if (syscon_uart_index < uarts) {
130    minor = 0;
131    status = rtems_termios_device_install(
132      CONSOLE_DEVICE_NAME,
133      major,
134      minor,
135      handler,
136      NULL,
137      leon3_console_get_context(syscon_uart_index)
138    );
139    if (status != RTEMS_SUCCESSFUL)
140      bsp_fatal(LEON3_FATAL_CONSOLE_REGISTER_DEV);
141  }
142  strcpy(console_name,"/dev/console_a");
143  for (i = 0; i < uarts; i++) {
144    if (i == syscon_uart_index)
145      continue; /* skip UART that is registered as /dev/console */
146    console_name[13] = 'a' + i;
147    minor = i + 1;
148    rtems_termios_device_install(
149      console_name,
150      major,
151      minor,
152      handler,
153      NULL,
154      leon3_console_get_context(syscon_uart_index)
155    );
156  }
157
158  return RTEMS_SUCCESSFUL;
159}
Note: See TracBrowser for help on using the repository browser.