source: rtems/c/src/lib/libbsp/powerpc/mpc55xxevb/console/console-generic.c @ 1c77a36

5
Last change on this file since 1c77a36 was 1c77a36, checked in by Sebastian Huber <sebastian.huber@…>, on 06/24/16 at 12:31:29

bsps: Include missing <rtems/bspIo.h>

  • 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  if (c == '\n') {
41    (*cb->poll_write)(minor, '\r');
42  }
43
44  (*cb->poll_write)(minor, c);
45}
46
47static int console_generic_char_in(void)
48{
49  int minor = (int) console_generic_minor;
50  const console_generic_callbacks *cb =
51    console_generic_info_table [minor].callbacks;
52
53  return (*cb->poll_read)(minor);
54}
55
56static void console_generic_char_out_do_init(void)
57{
58  int minor = (int) console_generic_minor;
59  const console_generic_callbacks *cb =
60    console_generic_info_table [minor].callbacks;
61  const struct termios *term = &console_generic_termios;
62
63  BSP_output_char = console_generic_char_out;
64  (*cb->termios_callbacks.setAttributes)(minor, term);
65}
66
67static void console_generic_char_out_init(char c)
68{
69  console_generic_char_out_do_init();
70  console_generic_char_out(c);
71}
72
73rtems_device_driver console_initialize(
74  rtems_device_major_number major,
75  rtems_device_minor_number minor,
76  void *arg
77)
78{
79  rtems_status_code sc = RTEMS_SUCCESSFUL;
80  const console_generic_info *info_table = console_generic_info_table;
81  rtems_device_minor_number count = console_generic_info_count;
82  rtems_device_minor_number console = console_generic_minor;
83
84  if (count <= 0) {
85    bsp_fatal(MPC55XX_FATAL_CONSOLE_GENERIC_COUNT);
86  }
87
88  rtems_termios_initialize();
89
90  for (minor = 0; minor < count; ++minor) {
91    const console_generic_info *info = info_table + minor;
92
93    sc = rtems_io_register_name(info->device_path, major, minor);
94    if (sc != RTEMS_SUCCESSFUL) {
95      bsp_fatal(MPC55XX_FATAL_CONSOLE_GENERIC_REGISTER);
96    }
97  }
98
99  sc = rtems_io_register_name(CONSOLE_DEVICE_NAME, major, console);
100  if (sc != RTEMS_SUCCESSFUL) {
101    bsp_fatal(MPC55XX_FATAL_CONSOLE_GENERIC_REGISTER_CONSOLE);
102  }
103
104  console_generic_char_out_do_init();
105
106  return sc;
107}
108
109rtems_device_driver console_open(
110  rtems_device_major_number major,
111  rtems_device_minor_number minor,
112  void *arg
113)
114{
115  rtems_status_code sc = RTEMS_SUCCESSFUL;
116  rtems_device_minor_number count = console_generic_info_count;
117
118  if (minor < count) {
119    const console_generic_info *info = &console_generic_info_table [minor];
120
121    sc = rtems_termios_open(
122      major,
123      minor,
124      arg,
125      &info->callbacks->termios_callbacks
126    );
127  } else {
128    sc = RTEMS_INVALID_ID;
129  }
130
131  return sc;
132}
133
134rtems_device_driver console_close(
135  rtems_device_major_number major,
136  rtems_device_minor_number minor,
137  void *arg
138)
139{
140  return rtems_termios_close(arg);
141}
142
143rtems_device_driver console_read(
144  rtems_device_major_number major,
145  rtems_device_minor_number minor,
146  void *arg
147)
148{
149  return rtems_termios_read(arg);
150}
151
152rtems_device_driver console_write(
153  rtems_device_major_number major,
154  rtems_device_minor_number minor,
155  void *arg
156)
157{
158  return rtems_termios_write(arg);
159}
160
161rtems_device_driver console_control(
162  rtems_device_major_number major,
163  rtems_device_minor_number minor,
164  void *arg
165)
166{
167  return rtems_termios_ioctl(arg);
168}
169
170BSP_output_char_function_type BSP_output_char = console_generic_char_out_init;
171
172BSP_polling_getchar_function_type BSP_poll_char = console_generic_char_in;
Note: See TracBrowser for help on using the repository browser.