source: rtems/bsps/mips/rbtx4925/console/console-io.c @ 762fa62

5
Last change on this file since 762fa62 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: 4.5 KB
Line 
1/*
2 *  This file contains the RBTX4925 console IO package.
3 */
4
5/*
6 *  Author:     Craig Lebakken <craigl@transition.com>
7 *
8 *  COPYRIGHT (c) 1996 by Transition Networks Inc.
9 *
10 *  To anyone who acknowledges that this file is provided "AS IS"
11 *  without any express or implied warranty:
12 *      permission to use, copy, modify, and distribute this file
13 *      for any purpose is hereby granted without fee, provided that
14 *      the above copyright notice and this notice appears in all
15 *      copies, and that the name of Transition Networks not be used in
16 *      advertising or publicity pertaining to distribution of the
17 *      software without specific, written prior permission.
18 *      Transition Networks makes no representations about the suitability
19 *      of this software for any purpose.
20 *
21 *  Derived from c/src/lib/libbsp/no_cpu/no_bsp/console/console.c:
22 *
23 *  COPYRIGHT (c) 1989-1999.
24 *  On-Line Applications Research Corporation (OAR).
25 *
26 *  The license and distribution terms for this file may be
27 *  found in the file LICENSE in this distribution or at
28 *  http://www.rtems.org/license/LICENSE.
29 */
30
31#include <ctype.h>
32
33#include <rtems/console.h>
34#include <rtems/libio.h>
35#include <bsp.h>
36
37/* PMON entry points */
38int mon_read(int fd, char *buf, int cnt);    /* stdin is fd=0 */
39int mon_write(int fd, char *buf, int cnt);    /* stdout is fd=1 */
40
41/*  console_initialize
42 *
43 *  This routine initializes the console IO driver.
44 */
45rtems_device_driver console_initialize(
46  rtems_device_major_number  major,
47  rtems_device_minor_number  minor,
48  void                      *arg
49)
50{
51  rtems_status_code status;
52
53  status = rtems_io_register_name(
54    "/dev/console",
55    major,
56    (rtems_device_minor_number) 0
57  );
58
59  if (status != RTEMS_SUCCESSFUL)
60    rtems_fatal_error_occurred(status);
61
62  return RTEMS_SUCCESSFUL;
63}
64
65/*  inbyte
66 *
67 *  This routine reads a character from the SOURCE.
68 */
69static char inbyte( void )
70{
71  char buf[10];
72
73  /*
74   *  If polling, wait until a character is available.
75   */
76
77  mon_read(0, buf, 1);    /* stdin is fd=0, read 1 byte */
78
79  return (buf[0]);
80}
81
82/*  outbyte
83 *
84 *  This routine transmits a character out the SOURCE.  It may support
85 *  XON/XOFF flow control.
86 */
87static void outbyte(
88  char ch
89)
90{
91  char buf[10];
92
93  /*
94   *  If polling, wait for the transmitter to be ready.
95   *  Check for flow control requests and process.
96   *  Then output the character.
97   */
98  buf[0] = ch;
99
100  mon_write( 1, buf, 1 );    /* stdout is fd=1, write 1 byte */
101}
102
103/*
104 *  Open entry point
105 */
106rtems_device_driver console_open(
107  rtems_device_major_number major,
108  rtems_device_minor_number minor,
109  void                    * arg
110)
111{
112  return RTEMS_SUCCESSFUL;
113}
114
115/*
116 *  Close entry point
117 */
118rtems_device_driver console_close(
119  rtems_device_major_number major,
120  rtems_device_minor_number minor,
121  void                    * arg
122)
123{
124  return RTEMS_SUCCESSFUL;
125}
126
127/*
128 * read bytes from the serial port. We only have stdin.
129 */
130rtems_device_driver console_read(
131  rtems_device_major_number major,
132  rtems_device_minor_number minor,
133  void                    * arg
134)
135{
136  rtems_libio_rw_args_t *rw_args;
137  char *buffer;
138  int maximum;
139  int count = 0;
140
141  rw_args = (rtems_libio_rw_args_t *) arg;
142
143  buffer = rw_args->buffer;
144  maximum = rw_args->count;
145
146  for (count = 0; count < maximum; count++) {
147    buffer[ count ] = inbyte();
148    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
149      buffer[ count++ ]  = '\n';
150      break;
151    }
152  }
153
154  rw_args->bytes_moved = count;
155  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
156}
157
158/*
159 * write bytes to the serial port. Stdout and stderr are the same.
160 */
161rtems_device_driver console_write(
162  rtems_device_major_number major,
163  rtems_device_minor_number minor,
164  void                    * arg
165)
166{
167  int count;
168  int maximum;
169  rtems_libio_rw_args_t *rw_args;
170  char *buffer;
171
172  rw_args = (rtems_libio_rw_args_t *) arg;
173
174  buffer = rw_args->buffer;
175  maximum = rw_args->count;
176
177  for (count = 0; count < maximum; count++) {
178    if ( buffer[ count ] == '\n') {
179      outbyte('\r');
180    }
181    outbyte( buffer[ count ] );
182  }
183
184  rw_args->bytes_moved = maximum;
185  return 0;
186}
187
188/*
189 *  IO Control entry point
190 */
191rtems_device_driver console_control(
192  rtems_device_major_number major,
193  rtems_device_minor_number minor,
194  void                    * arg
195)
196{
197  return RTEMS_SUCCESSFUL;
198}
199
200#include <rtems/bspIo.h>
201
202static void RBTX4925_output_char(char c) { outbyte( c ); }
203
204BSP_output_char_function_type           BSP_output_char = RBTX4925_output_char;
205BSP_polling_getchar_function_type       BSP_poll_char = NULL;
206
Note: See TracBrowser for help on using the repository browser.