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

4.115
Last change on this file since 6273201 was a762dc2, checked in by Sebastian Huber <sebastian.huber@…>, on 01/23/12 at 10:19:22

Support for MPC5643L.

Rework of the start sequence to reduce the amount assembler code and to
support configuration tables which may be provided by the application.

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