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

5
Last change on this file since c07481c7 was c07481c7, checked in by Sebastian Huber <sebastian.huber@…>, on 10/20/15 at 09:16:12

bsp/leon3: Fix Termios context usage

Only the context of the console device was used and this is wrong in
case more than one APBUART device is available.

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