source: rtems/c/src/lib/libbsp/powerpc/mpc55xxevb/console/console-generic.c @ 0e27119

4.115
Last change on this file since 0e27119 was 52c8df84, checked in by Peter Dufault <dufault@…>, on 10/01/12 at 13:43:22

bsp/mpc55xx: PR2077: Add BSP_DEFAULT_BAUD_RATE

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