source: rtems/bsps/riscv/riscv/console/console-config.c @ 31f90a2

5
Last change on this file since 31f90a2 was 31f90a2, checked in by Sebastian Huber <sebastian.huber@…>, on 07/06/18 at 11:52:22

bsp/riscv: Simplify printk() support

This is a prepartion to add NS16550 driver support to the console
driver.

Update #3433.

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 * Copyright (c) 2018 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <info@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#include <rtems/bspIo.h>
16#include <rtems/console.h>
17#include <rtems/sysinit.h>
18#include <rtems/termiostypes.h>
19
20#include <bsp.h>
21#include <bsp/fdt.h>
22#include <bsp/irq.h>
23
24#include <dev/serial/htif.h>
25
26#include <libfdt.h>
27
28#if RISCV_ENABLE_HTIF_SUPPORT > 0
29static htif_console_context htif_console_instance;
30#endif
31
32static struct {
33  rtems_termios_device_context *context;
34  void (*putchar)(rtems_termios_device_context *base, char c);
35  int (*getchar)(rtems_termios_device_context *base);
36} riscv_console;
37
38static void riscv_output_char(char c)
39{
40  (*riscv_console.putchar)(riscv_console.context, c);
41}
42
43static int riscv_get_console_node(const void *fdt)
44{
45  const char *stdout_path;
46  int node;
47
48  node = fdt_path_offset(fdt, "/chosen");
49
50  stdout_path = fdt_getprop(fdt, node, "stdout-path", NULL);
51  if (stdout_path == NULL) {
52    stdout_path = "";
53  }
54
55  return fdt_path_offset(fdt, stdout_path);
56}
57
58static void riscv_console_probe(void)
59{
60  const void *fdt;
61  int node;
62  int console_node;
63
64  fdt = bsp_fdt_get();
65  console_node = riscv_get_console_node(fdt);
66
67  node = fdt_next_node(fdt, -1, NULL);
68
69  while (node >= 0) {
70#if RISCV_ENABLE_HTIF_SUPPORT
71    if (fdt_node_check_compatible(fdt, node, "ucb,htif0") == 0) {
72      htif_console_context_init(&htif_console_instance.base, node);
73
74      riscv_console.context = &htif_console_instance.base;
75      riscv_console.putchar = htif_console_putchar;
76      riscv_console.getchar = htif_console_getchar;
77    };
78#endif
79
80    node = fdt_next_node(fdt, node, NULL);
81  }
82
83  BSP_output_char = riscv_output_char;
84}
85
86static void riscv_output_char_init(char c)
87{
88  riscv_console_probe();
89  riscv_output_char(c);
90}
91
92BSP_output_char_function_type BSP_output_char = riscv_output_char_init;
93
94BSP_polling_getchar_function_type BSP_poll_char = NULL;
95
96rtems_status_code console_initialize(
97  rtems_device_major_number major,
98  rtems_device_minor_number minor,
99  void *arg
100)
101{
102  rtems_termios_device_context *base;
103  char htif_path[] = "/dev/ttyShtif";
104
105  rtems_termios_initialize();
106
107#if RISCV_ENABLE_HTIF_SUPPORT
108  base = &htif_console_instance.base;
109  rtems_termios_device_install(htif_path, &htif_console_handler, NULL, base);
110
111  if (base == riscv_console.context) {
112    link(htif_path, CONSOLE_DEVICE_NAME);
113  }
114#endif
115
116  return RTEMS_SUCCESSFUL;
117}
118
119RTEMS_SYSINIT_ITEM(
120  riscv_console_probe,
121  RTEMS_SYSINIT_BSP_START,
122  RTEMS_SYSINIT_ORDER_LAST
123);
Note: See TracBrowser for help on using the repository browser.