![]() |
|
|||
File indexing completed on 2025-05-11 08:24:08
0001 /* SPDX-License-Identifier: BSD-2-Clause */ 0002 0003 /* 0004 * This file contains the TTY driver for the serial ports on the LEON. 0005 * 0006 * This driver uses the termios pseudo driver. 0007 * 0008 * COPYRIGHT (c) 1989-1998. 0009 * On-Line Applications Research Corporation (OAR). 0010 * 0011 * Modified for LEON3 BSP. 0012 * COPYRIGHT (c) 2004. 0013 * Gaisler Research. 0014 * 0015 * Redistribution and use in source and binary forms, with or without 0016 * modification, are permitted provided that the following conditions 0017 * are met: 0018 * 1. Redistributions of source code must retain the above copyright 0019 * notice, this list of conditions and the following disclaimer. 0020 * 2. Redistributions in binary form must reproduce the above copyright 0021 * notice, this list of conditions and the following disclaimer in the 0022 * documentation and/or other materials provided with the distribution. 0023 * 0024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 0025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 0027 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 0028 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 0029 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 0030 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 0031 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 0032 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 0033 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 0034 * POSSIBILITY OF SUCH DAMAGE. 0035 */ 0036 0037 /* Define CONSOLE_USE_INTERRUPTS to enable APBUART interrupt handling instead 0038 * of polling mode. 0039 * 0040 * Note that it is not possible to use the interrupt mode of the driver 0041 * together with the "old" APBUART and -u to GRMON. However the new 0042 * APBUART core (from GRLIB 1.0.17-b2710) has the GRMON debug bit and can 0043 * handle interrupts. 0044 * 0045 * NOTE: This can be defined in the make/custom/leon3.cfg file. 0046 */ 0047 0048 #include <bsp.h> 0049 #include <bsp/fatal.h> 0050 #include <leon.h> 0051 #include <grlib/apbuart_termios.h> 0052 #include <rtems/console.h> 0053 #include <string.h> 0054 0055 /* The LEON3 BSP UART driver can rely on the Driver Manager if the 0056 * DrvMgr is initialized during startup. Otherwise the classic driver 0057 * must be used. 0058 * 0059 * The DrvMgr APBUART driver is located in the shared/uart directory 0060 */ 0061 #ifndef RTEMS_DRVMGR_STARTUP 0062 0063 int syscon_uart_index __attribute__((weak)) = 0; 0064 0065 /* body is in debugputs.c */ 0066 static struct apbuart_context apbuarts[BSP_NUMBER_OF_TERMIOS_PORTS]; 0067 static int uarts = 0; 0068 0069 static rtems_termios_device_context *leon3_console_get_context(int index) 0070 { 0071 struct apbuart_context *uart = &apbuarts[index]; 0072 0073 rtems_termios_device_context_initialize(&uart->base, "APBUART"); 0074 0075 return &uart->base; 0076 } 0077 0078 /* AMBA PP find routine. Extract AMBA PnP information into data structure. */ 0079 static int find_matching_apbuart(struct ambapp_dev *dev, int index, void *arg) 0080 { 0081 struct ambapp_apb_info *apb = (struct ambapp_apb_info *)dev->devinfo; 0082 0083 /* Extract needed information of one APBUART */ 0084 apbuarts[uarts].regs = (apbuart *)apb->start; 0085 apbuarts[uarts].irq = apb->common.irq; 0086 /* Get APBUART core frequency, it is assumed that it is the same 0087 * as Bus frequency where the UART is situated 0088 */ 0089 apbuarts[uarts].freq_hz = ambapp_freq_get(ambapp_plb(), dev); 0090 uarts++; 0091 0092 if (uarts >= BSP_NUMBER_OF_TERMIOS_PORTS) 0093 return 1; /* Satisfied number of UARTs, stop search */ 0094 else 0095 return 0; /* Continue searching for more UARTs */ 0096 } 0097 0098 /* Find all UARTs */ 0099 static void leon3_console_scan_uarts(void) 0100 { 0101 memset(apbuarts, 0, sizeof(apbuarts)); 0102 0103 /* Find APBUART cores */ 0104 ambapp_for_each(ambapp_plb(), (OPTIONS_ALL|OPTIONS_APB_SLVS), VENDOR_GAISLER, 0105 GAISLER_APBUART, find_matching_apbuart, NULL); 0106 } 0107 0108 rtems_device_driver console_initialize( 0109 rtems_device_major_number major, 0110 rtems_device_minor_number minor, 0111 void *arg 0112 ) 0113 { 0114 const rtems_termios_device_handler *handler = 0115 #if CONSOLE_USE_INTERRUPTS 0116 &apbuart_handler_interrupt; 0117 #else 0118 &apbuart_handler_polled; 0119 #endif 0120 rtems_status_code status; 0121 int i; 0122 char console_name[16]; 0123 0124 rtems_termios_initialize(); 0125 0126 /* Find UARTs */ 0127 leon3_console_scan_uarts(); 0128 0129 /* Update syscon_uart_index to index used as /dev/console 0130 * Let user select System console by setting syscon_uart_index. If the 0131 * BSP is to provide the default UART (syscon_uart_index==0): 0132 * non-MP: APBUART[0] is system console 0133 * MP: LEON CPU index select UART 0134 */ 0135 if (syscon_uart_index == 0) { 0136 #if defined(RTEMS_MULTIPROCESSING) 0137 syscon_uart_index = LEON3_Cpu_Index; 0138 #else 0139 syscon_uart_index = 0; 0140 #endif 0141 } else { 0142 syscon_uart_index = syscon_uart_index - 1; /* User selected sys-console */ 0143 } 0144 0145 /* Register Device Names 0146 * 0147 * 0 /dev/console - APBUART[USER-SELECTED, DEFAULT=APBUART[0]] 0148 * 1 /dev/console_a - APBUART[0] (by default not present because is console) 0149 * 2 /dev/console_b - APBUART[1] 0150 * ... 0151 * 0152 * On a MP system one should not open UARTs that other OS instances use. 0153 */ 0154 if (syscon_uart_index < uarts) { 0155 status = rtems_termios_device_install( 0156 CONSOLE_DEVICE_NAME, 0157 handler, 0158 NULL, 0159 leon3_console_get_context(syscon_uart_index) 0160 ); 0161 if (status != RTEMS_SUCCESSFUL) 0162 bsp_fatal(LEON3_FATAL_CONSOLE_REGISTER_DEV); 0163 } 0164 strcpy(console_name,"/dev/console_a"); 0165 for (i = 0; i < uarts; i++) { 0166 if (i == syscon_uart_index) 0167 continue; /* skip UART that is registered as /dev/console */ 0168 console_name[13] = 'a' + i; 0169 rtems_termios_device_install( 0170 console_name, 0171 handler, 0172 NULL, 0173 leon3_console_get_context(i) 0174 ); 0175 } 0176 0177 return RTEMS_SUCCESSFUL; 0178 } 0179 0180 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |