source: rtems/bsps/lm32/shared/console/console.c @ d7d66d7

5
Last change on this file since d7d66d7 was d7d66d7, checked in by Sebastian Huber <sebastian.huber@…>, on 04/19/18 at 04:28:01

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.5 KB
Line 
1/*
2 *  Console driver for Lattice Mico32 (lm32).
3 */
4
5/*
6 *  COPYRIGHT (c) 1989-1999.
7 *  On-Line Applications Research Corporation (OAR).
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.rtems.org/license/LICENSE.
12 *
13 *  Jukka Pietarinen <jukka.pietarinen@mrf.fi>, 2008,
14 *  Micro-Research Finland Oy
15 */
16
17#define NO_BSP_INIT
18
19#include <bsp.h>
20#include <rtems/bspIo.h>
21#include <rtems/libio.h>
22#include <rtems/console.h>
23
24/*  console_initialize
25 *
26 *  This routine initializes the console IO driver.
27 */
28rtems_device_driver console_initialize(
29  rtems_device_major_number  major,
30  rtems_device_minor_number  minor,
31  void                      *arg
32)
33{
34  rtems_status_code status;
35
36  printk("console_initialize\n");
37
38  status = rtems_io_register_name(
39    "/dev/console",
40    major,
41    (rtems_device_minor_number) 0
42  );
43
44  if (status != RTEMS_SUCCESSFUL)
45    rtems_fatal_error_occurred(status);
46
47  return RTEMS_SUCCESSFUL;
48}
49
50/*  inbyte
51 *
52 *  This routine reads a character from the SOURCE.
53 */
54static int inbyte( void )
55{
56  /*
57   *  If polling, wait until a character is available.
58   */
59  return BSP_uart_polled_read();
60}
61
62/*  outbyte
63 *
64 *  This routine transmits a character out the SOURCE.  It may support
65 *  XON/XOFF flow control.
66 */
67static void outbyte(
68  char ch
69)
70{
71  /*
72   *  If polling, wait for the transmitter to be ready.
73   *  Check for flow control requests and process.
74   *  Then output the character.
75   */
76
77  BSP_uart_polled_write(ch);
78}
79
80/*
81 *  Open entry point
82 */
83rtems_device_driver console_open(
84  rtems_device_major_number major,
85  rtems_device_minor_number minor,
86  void                    * arg
87)
88{
89  return RTEMS_SUCCESSFUL;
90}
91
92/*
93 *  Close entry point
94 */
95rtems_device_driver console_close(
96  rtems_device_major_number major,
97  rtems_device_minor_number minor,
98  void                    * arg
99)
100{
101  return RTEMS_SUCCESSFUL;
102}
103
104/*
105 * read bytes from the serial port. We only have stdin.
106 */
107rtems_device_driver console_read(
108  rtems_device_major_number major,
109  rtems_device_minor_number minor,
110  void                    * arg
111)
112{
113  rtems_libio_rw_args_t *rw_args;
114  char *buffer;
115  int maximum;
116  int count = 0;
117
118  rw_args = (rtems_libio_rw_args_t *) arg;
119
120  buffer = rw_args->buffer;
121  maximum = rw_args->count;
122
123  for (count = 0; count < maximum; count++) {
124    buffer[ count ] = inbyte();
125    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
126      buffer[ count++ ]  = '\n';
127      break;
128    }
129  }
130
131  rw_args->bytes_moved = count;
132  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
133}
134
135/*
136 * write bytes to the serial port. Stdout and stderr are the same.
137 */
138rtems_device_driver console_write(
139  rtems_device_major_number major,
140  rtems_device_minor_number minor,
141  void                    * arg
142)
143{
144  int count;
145  int maximum;
146  rtems_libio_rw_args_t *rw_args;
147  char *buffer;
148
149  rw_args = (rtems_libio_rw_args_t *) arg;
150
151  buffer = rw_args->buffer;
152  maximum = rw_args->count;
153
154  for (count = 0; count < maximum; count++) {
155    if ( buffer[ count ] == '\n') {
156      outbyte('\r');
157    }
158    outbyte( buffer[ count ] );
159  }
160
161  rw_args->bytes_moved = maximum;
162  return 0;
163}
164
165/*
166 *  IO Control entry point
167 */
168rtems_device_driver console_control(
169  rtems_device_major_number major,
170  rtems_device_minor_number minor,
171  void                    * arg
172)
173{
174  return RTEMS_SUCCESSFUL;
175}
176
177BSP_output_char_function_type BSP_output_char = BSP_uart_polled_write;
178BSP_polling_getchar_function_type BSP_poll_char = BSP_uart_polled_read;
Note: See TracBrowser for help on using the repository browser.