Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:03

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RTEMSBSPsARMLPC24XX
0007  *
0008  * @brief Console configuration.
0009  */
0010 
0011 /*
0012  * Copyright (C) 2008, 2014 embedded brains GmbH & Co. KG
0013  *
0014  * Redistribution and use in source and binary forms, with or without
0015  * modification, are permitted provided that the following conditions
0016  * are met:
0017  * 1. Redistributions of source code must retain the above copyright
0018  *    notice, this list of conditions and the following disclaimer.
0019  * 2. Redistributions in binary form must reproduce the above copyright
0020  *    notice, this list of conditions and the following disclaimer in the
0021  *    documentation and/or other materials provided with the distribution.
0022  *
0023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0024  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0026  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0027  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0028  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0029  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0033  * POSSIBILITY OF SUCH DAMAGE.
0034  */
0035 
0036 #include <rtems/console.h>
0037 
0038 #include <libchip/ns16550.h>
0039 
0040 #include <bsp.h>
0041 #include <bsp/lpc24xx.h>
0042 #include <bsp/irq.h>
0043 #include <bsp/io.h>
0044 #include <bsp/console-termios.h>
0045 
0046 static uint8_t lpc24xx_uart_get_register(uintptr_t addr, uint8_t i)
0047 {
0048   volatile uint32_t *reg = (volatile uint32_t *) addr;
0049 
0050   return (uint8_t) reg [i];
0051 }
0052 
0053 static void lpc24xx_uart_set_register(uintptr_t addr, uint8_t i, uint8_t val)
0054 {
0055   volatile uint32_t *reg = (volatile uint32_t *) addr;
0056 
0057   reg [i] = val;
0058 }
0059 
0060 #ifdef LPC24XX_CONFIG_CONSOLE
0061 static ns16550_context lpc24xx_uart_context_0 = {
0062   .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 0"),
0063   .get_reg = lpc24xx_uart_get_register,
0064   .set_reg = lpc24xx_uart_set_register,
0065   .port = UART0_BASE_ADDR,
0066   .irq = LPC24XX_IRQ_UART_0,
0067   .clock = LPC24XX_PCLK,
0068   .initial_baud = LPC24XX_UART_BAUD,
0069   .has_fractional_divider_register = true
0070 };
0071 #endif
0072 
0073 #ifdef LPC24XX_CONFIG_UART_1
0074 static ns16550_context lpc24xx_uart_context_1 = {
0075   .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 1"),
0076   .get_reg = lpc24xx_uart_get_register,
0077   .set_reg = lpc24xx_uart_set_register,
0078   .port = UART1_BASE_ADDR,
0079   .irq = LPC24XX_IRQ_UART_1,
0080   .clock = LPC24XX_PCLK,
0081   .initial_baud = LPC24XX_UART_BAUD,
0082   .has_fractional_divider_register = true
0083 };
0084 #endif
0085 
0086 #ifdef LPC24XX_CONFIG_UART_2
0087 static ns16550_context lpc24xx_uart_context_2 = {
0088   .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 2"),
0089   .get_reg = lpc24xx_uart_get_register,
0090   .set_reg = lpc24xx_uart_set_register,
0091   .port = UART2_BASE_ADDR,
0092   .irq = LPC24XX_IRQ_UART_2,
0093   .clock = LPC24XX_PCLK,
0094   .initial_baud = LPC24XX_UART_BAUD,
0095   .has_fractional_divider_register = true
0096 };
0097 #endif
0098 
0099 #ifdef LPC24XX_CONFIG_UART_3
0100 static ns16550_context lpc24xx_uart_context_3 = {
0101   .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 3"),
0102   .get_reg = lpc24xx_uart_get_register,
0103   .set_reg = lpc24xx_uart_set_register,
0104   .port = UART3_BASE_ADDR,
0105   .irq = LPC24XX_IRQ_UART_3,
0106   .clock = LPC24XX_PCLK,
0107   .initial_baud = LPC24XX_UART_BAUD,
0108   .has_fractional_divider_register = true
0109 };
0110 #endif
0111 
0112 const console_device console_device_table[] = {
0113   #ifdef LPC24XX_CONFIG_CONSOLE
0114     {
0115       .device_file = "/dev/ttyS0",
0116       .probe = console_device_probe_default,
0117       .handler = &ns16550_handler_interrupt,
0118       .context = &lpc24xx_uart_context_0.base
0119     },
0120   #endif
0121   #ifdef LPC24XX_CONFIG_UART_1
0122     {
0123       .device_file = "/dev/ttyS1",
0124       .probe = lpc24xx_uart_probe_1,
0125       .handler = &ns16550_handler_interrupt,
0126       .context = &lpc24xx_uart_context_1.base
0127     },
0128   #endif
0129   #ifdef LPC24XX_CONFIG_UART_2
0130     {
0131       .device_file = "/dev/ttyS2",
0132       .probe = lpc24xx_uart_probe_2,
0133       .handler = &ns16550_handler_interrupt,
0134       .context = &lpc24xx_uart_context_2.base
0135     },
0136   #endif
0137   #ifdef LPC24XX_CONFIG_UART_3
0138     {
0139       .device_file = "/dev/ttyS3",
0140       .probe = lpc24xx_uart_probe_3,
0141       .handler = &ns16550_handler_interrupt,
0142       .context = &lpc24xx_uart_context_3.base
0143     },
0144   #endif
0145 };
0146 
0147 const size_t console_device_count = RTEMS_ARRAY_SIZE(console_device_table);