Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @brief Console configuration.
0007  */
0008 
0009 /*
0010  * Copyright (C) 2008, 2014 embedded brains GmbH & Co. KG
0011  *
0012  * Redistribution and use in source and binary forms, with or without
0013  * modification, are permitted provided that the following conditions
0014  * are met:
0015  * 1. Redistributions of source code must retain the above copyright
0016  *    notice, this list of conditions and the following disclaimer.
0017  * 2. Redistributions in binary form must reproduce the above copyright
0018  *    notice, this list of conditions and the following disclaimer in the
0019  *    documentation and/or other materials provided with the distribution.
0020  *
0021  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0022  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0024  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0025  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0026  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0027  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0028  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0029  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0030  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0031  * POSSIBILITY OF SUCH DAMAGE.
0032  */
0033 
0034 #include <rtems/bspIo.h>
0035 
0036 #include <libchip/ns16550.h>
0037 
0038 #include <mpc83xx/mpc83xx.h>
0039 
0040 #include <bsp.h>
0041 #include <bsp/irq.h>
0042 #include <bsp/console-termios.h>
0043 
0044 #ifdef BSP_USE_UART_INTERRUPTS
0045   #define DEVICE_FNS &ns16550_handler_interrupt
0046 #else
0047   #define DEVICE_FNS &ns16550_handler_polled
0048 #endif
0049 
0050 static uint8_t gen83xx_console_get_register(uintptr_t addr, uint8_t i)
0051 {
0052   volatile uint8_t *reg = (volatile uint8_t *) addr;
0053 
0054   return reg [i];
0055 }
0056 
0057 static void gen83xx_console_set_register(uintptr_t addr, uint8_t i, uint8_t val)
0058 {
0059   volatile uint8_t *reg = (volatile uint8_t *) addr;
0060 
0061   reg [i] = val;
0062 }
0063 
0064 static ns16550_context gen83xx_uart_context_0 = {
0065   .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 0"),
0066   .get_reg = gen83xx_console_get_register,
0067   .set_reg = gen83xx_console_set_register,
0068   .port = (uintptr_t) &mpc83xx.duart[0],
0069 #if MPC83XX_CHIP_TYPE / 10 == 830
0070    .irq = BSP_IPIC_IRQ_UART,
0071 #else
0072    .irq = BSP_IPIC_IRQ_UART1,
0073 #endif
0074   .initial_baud = BSP_CONSOLE_BAUD
0075 };
0076 
0077 #ifdef BSP_USE_UART2
0078 static ns16550_context gen83xx_uart_context_1 = {
0079   .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 1"),
0080   .get_reg = gen83xx_console_get_register,
0081   .set_reg = gen83xx_console_set_register,
0082   .port = (uintptr_t) &mpc83xx.duart[1],
0083 #if MPC83XX_CHIP_TYPE / 10 == 830
0084   .irq = BSP_IPIC_IRQ_UART,
0085 #else
0086   .irq = BSP_IPIC_IRQ_UART2,
0087 #endif
0088   .initial_baud = BSP_CONSOLE_BAUD
0089 };
0090 #endif
0091 
0092 const console_device console_device_table[] = {
0093   {
0094     .device_file = "/dev/ttyS0",
0095     .probe = ns16550_probe,
0096     .handler = DEVICE_FNS,
0097     .context = &gen83xx_uart_context_0.base
0098   }
0099 #ifdef BSP_USE_UART2
0100   , {
0101     .device_file = "/dev/ttyS1",
0102     .probe = ns16550_probe,
0103     .handler = DEVICE_FNS,
0104     .context = &gen83xx_uart_context_1.base
0105   }
0106 #endif
0107 };
0108 
0109 const size_t console_device_count = RTEMS_ARRAY_SIZE(console_device_table);
0110 
0111 static void gen83xx_output_char(char c)
0112 {
0113   rtems_termios_device_context *ctx = console_device_table[0].context;
0114 
0115   ns16550_polled_putchar(ctx, c);
0116 }
0117 
0118 BSP_output_char_function_type BSP_output_char = gen83xx_output_char;
0119 
0120 BSP_polling_getchar_function_type BSP_poll_char = NULL;