source: rtems/bsps/aarch64/xilinx-zynqmp/console/console.c @ a92d4ae

Last change on this file since a92d4ae was a92d4ae, checked in by Kinsey Moore <kinsey.moore@…>, on 11/16/20 at 19:36:51

Add AArch64 ZynpMP BSP

This adds a BSP family that runs on the Xilinx Ultrascale+ MPSOC
(ZynqMP) family of chips. It is configured to be usable on the Qemu
ZCU102 machine definition and should be almost trivially portable to
ZynqMP development boards and custom hardware. It is also configured to
be usable with libbsd.

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