source: rtems/bsps/powerpc/mpc55xxevb/console/console-generic.c @ d7d66d7

5
Last change on this file since d7d66d7 was d7d66d7, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 19, 2018 at 4:28:01 AM

bsps: Move console drivers to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/**
2 * @file
3 *
4 * @brief Generic console driver implementation.
5 */
6
7/*
8 * Copyright (c) 2011 embedded brains GmbH.  All rights reserved.
9 *
10 *  embedded brains GmbH
11 *  Obere Lagerstr. 30
12 *  82178 Puchheim
13 *  Germany
14 *  <rtems@embedded-brains.de>
15 *
16 * The license and distribution terms for this file may be
17 * found in the file LICENSE in this distribution or at
18 * http://www.rtems.org/license/LICENSE.
19 */
20
21#include <sys/cdefs.h>
22
23#include <bsp.h>
24#include <bsp/console-generic.h>
25#include <bsp/fatal.h>
26
27#include <rtems/bspIo.h>
28#include <rtems/console.h>
29
30static const struct termios console_generic_termios = {
31  .c_cflag = CS8 | CREAD | CLOCAL | __CONCAT(B, BSP_DEFAULT_BAUD_RATE)
32};
33
34static void console_generic_char_out(char c)
35{
36  int minor = (int) console_generic_minor;
37  const console_generic_callbacks *cb =
38    console_generic_info_table [minor].callbacks;
39
40  (*cb->poll_write)(minor, c);
41}
42
43static int console_generic_char_in(void)
44{
45  int minor = (int) console_generic_minor;
46  const console_generic_callbacks *cb =
47    console_generic_info_table [minor].callbacks;
48
49  return (*cb->poll_read)(minor);
50}
51
52static void console_generic_char_out_do_init(void)
53{
54  int minor = (int) console_generic_minor;
55  const console_generic_callbacks *cb =
56    console_generic_info_table [minor].callbacks;
57  const struct termios *term = &console_generic_termios;
58
59  BSP_output_char = console_generic_char_out;
60  (*cb->termios_callbacks.setAttributes)(minor, term);
61}
62
63static void console_generic_char_out_init(char c)
64{
65  console_generic_char_out_do_init();
66  console_generic_char_out(c);
67}
68
69rtems_device_driver console_initialize(
70  rtems_device_major_number major,
71  rtems_device_minor_number minor,
72  void *arg
73)
74{
75  rtems_status_code sc = RTEMS_SUCCESSFUL;
76  const console_generic_info *info_table = console_generic_info_table;
77  rtems_device_minor_number count = console_generic_info_count;
78  rtems_device_minor_number console = console_generic_minor;
79
80  if (count <= 0) {
81    bsp_fatal(MPC55XX_FATAL_CONSOLE_GENERIC_COUNT);
82  }
83
84  rtems_termios_initialize();
85
86  for (minor = 0; minor < count; ++minor) {
87    const console_generic_info *info = info_table + minor;
88
89    sc = rtems_io_register_name(info->device_path, major, minor);
90    if (sc != RTEMS_SUCCESSFUL) {
91      bsp_fatal(MPC55XX_FATAL_CONSOLE_GENERIC_REGISTER);
92    }
93  }
94
95  sc = rtems_io_register_name(CONSOLE_DEVICE_NAME, major, console);
96  if (sc != RTEMS_SUCCESSFUL) {
97    bsp_fatal(MPC55XX_FATAL_CONSOLE_GENERIC_REGISTER_CONSOLE);
98  }
99
100  console_generic_char_out_do_init();
101
102  return sc;
103}
104
105rtems_device_driver console_open(
106  rtems_device_major_number major,
107  rtems_device_minor_number minor,
108  void *arg
109)
110{
111  rtems_status_code sc = RTEMS_SUCCESSFUL;
112  rtems_device_minor_number count = console_generic_info_count;
113
114  if (minor < count) {
115    const console_generic_info *info = &console_generic_info_table [minor];
116
117    sc = rtems_termios_open(
118      major,
119      minor,
120      arg,
121      &info->callbacks->termios_callbacks
122    );
123  } else {
124    sc = RTEMS_INVALID_ID;
125  }
126
127  return sc;
128}
129
130rtems_device_driver console_close(
131  rtems_device_major_number major,
132  rtems_device_minor_number minor,
133  void *arg
134)
135{
136  return rtems_termios_close(arg);
137}
138
139rtems_device_driver console_read(
140  rtems_device_major_number major,
141  rtems_device_minor_number minor,
142  void *arg
143)
144{
145  return rtems_termios_read(arg);
146}
147
148rtems_device_driver console_write(
149  rtems_device_major_number major,
150  rtems_device_minor_number minor,
151  void *arg
152)
153{
154  return rtems_termios_write(arg);
155}
156
157rtems_device_driver console_control(
158  rtems_device_major_number major,
159  rtems_device_minor_number minor,
160  void *arg
161)
162{
163  return rtems_termios_ioctl(arg);
164}
165
166BSP_output_char_function_type BSP_output_char = console_generic_char_out_init;
167
168BSP_polling_getchar_function_type BSP_poll_char = console_generic_char_in;
Note: See TracBrowser for help on using the repository browser.