source: rtems/bsps/arm/xilinx-zynqmp/console/console-config.c @ b296708

Last change on this file since b296708 was b296708, checked in by Joel Sherrill <joel@…>, on 06/06/23 at 22:33:08

xilinx-zynqmp: Include <rtems/libio.h> for rtems_termios_initialize()

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (C) 2013, 2017 embedded brains GmbH & Co. KG
5 *
6 * Copyright (C) 2019 DornerWorks
7 *
8 * Written by Jeff Kubascik <jeff.kubascik@dornerworks.com>
9 *        and Josh Whitehead <josh.whitehead@dornerworks.com>
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 *    notice, this list of conditions and the following disclaimer in the
18 *    documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#include <rtems/console.h>
34#include <rtems/bspIo.h>
35#include <rtems/sysinit.h>
36#include <rtems/libio.h>   /* for rtems_termios_initialize */
37
38#include <bsp/irq.h>
39#include <dev/serial/zynq-uart.h>
40
41#include <bspopts.h>
42
43static zynq_uart_context zynqmp_uart_instances[2] = {
44  {
45    .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER( "Zynq UART 0" ),
46    .regs = (volatile struct zynq_uart *) 0xff000000,
47    .irq = ZYNQMP_IRQ_UART_0
48  }, {
49    .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER( "Zynq UART 1" ),
50    .regs = (volatile struct zynq_uart *) 0xff010000,
51    .irq = ZYNQMP_IRQ_UART_1
52  }
53};
54
55rtems_status_code console_initialize(
56  rtems_device_major_number major,
57  rtems_device_minor_number minor,
58  void *arg
59)
60{
61  size_t i;
62
63  rtems_termios_initialize();
64
65  for (i = 0; i < RTEMS_ARRAY_SIZE(zynqmp_uart_instances); ++i) {
66    char uart[] = "/dev/ttySX";
67
68    uart[sizeof(uart) - 2] = (char) ('0' + i);
69    rtems_termios_device_install(
70      &uart[0],
71      &zynq_uart_handler,
72      NULL,
73      &zynqmp_uart_instances[i].base
74    );
75
76    if (i == BSP_CONSOLE_MINOR) {
77      link(&uart[0], CONSOLE_DEVICE_NAME);
78    }
79  }
80
81  return RTEMS_SUCCESSFUL;
82}
83
84void zynqmp_debug_console_flush(void)
85{
86  zynq_uart_reset_tx_flush(&zynqmp_uart_instances[BSP_CONSOLE_MINOR]);
87}
88
89static void zynqmp_debug_console_out(char c)
90{
91  rtems_termios_device_context *base =
92    &zynqmp_uart_instances[BSP_CONSOLE_MINOR].base;
93
94  zynq_uart_write_polled(base, c);
95}
96
97static void zynqmp_debug_console_init(void)
98{
99  rtems_termios_device_context *base =
100    &zynqmp_uart_instances[BSP_CONSOLE_MINOR].base;
101
102  zynq_uart_initialize(base);
103  BSP_output_char = zynqmp_debug_console_out;
104}
105
106static void zynqmp_debug_console_early_init(char c)
107{
108  rtems_termios_device_context *base =
109    &zynqmp_uart_instances[BSP_CONSOLE_MINOR].base;
110
111  zynq_uart_initialize(base);
112  zynqmp_debug_console_out(c);
113}
114
115static int zynqmp_debug_console_in(void)
116{
117  rtems_termios_device_context *base =
118    &zynqmp_uart_instances[BSP_CONSOLE_MINOR].base;
119
120  return zynq_uart_read_polled(base);
121}
122
123BSP_output_char_function_type BSP_output_char = zynqmp_debug_console_early_init;
124
125BSP_polling_getchar_function_type BSP_poll_char = zynqmp_debug_console_in;
126
127RTEMS_SYSINIT_ITEM(
128  zynqmp_debug_console_init,
129  RTEMS_SYSINIT_BSP_START,
130  RTEMS_SYSINIT_ORDER_LAST_BUT_5
131);
Note: See TracBrowser for help on using the repository browser.