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

4.115
Last change on this file since a830cb8 was a830cb8, checked in by Sebastian Huber <sebastian.huber@…>, on 10/07/14 at 14:27:51

termios: Separate flow control from normal handler

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