source: rtems/c/src/lib/libbsp/mips/rbtx4938/console/console-io.c @ 16db6ad1

5
Last change on this file since 16db6ad1 was 16db6ad1, checked in by Joel Sherrill <joel@…>, on 03/29/16 at 18:10:52

mips/rbtx4938: Remove include of <rtems/console.h> from <bsp.h> and fix warnings

  • Property mode set to 100644
File size: 4.5 KB
Line 
1/*
2 *  This file contains the RBTX4938 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#include "yamon_api.h"
38
39/* PMON entry points */
40int mon_read(int fd, char *buf, int cnt);    /* stdin is fd=0 */
41int mon_write(int fd, char *buf, int cnt);    /* stdout is fd=1 */
42
43
44/*  console_initialize
45 *
46 *  This routine initializes the console IO driver.
47 */
48rtems_device_driver console_initialize(
49  rtems_device_major_number  major,
50  rtems_device_minor_number  minor,
51  void                      *arg
52)
53{
54  rtems_status_code status;
55
56  status = rtems_io_register_name(
57    "/dev/console",
58    major,
59    (rtems_device_minor_number) 0
60  );
61
62  if (status != RTEMS_SUCCESSFUL)
63    rtems_fatal_error_occurred(status);
64
65  return RTEMS_SUCCESSFUL;
66}
67
68/*  inbyte
69 *
70 *  This routine reads a character from the SOURCE.
71 */
72static char inbyte( void )
73{
74  char buf[10];
75
76  /*
77   *  If polling, wait until a character is available.
78   */
79  while (YAMON_FUNC_GETCHAR(buf) == YAMON_FALSE);
80
81  return (buf[0]);
82}
83
84/*  outbyte
85 *
86 *  This routine transmits a character out the SOURCE.  It may support
87 *  XON/XOFF flow control.
88 */
89static void outbyte(
90  char ch
91)
92{
93  char buf[10];
94
95  /*
96   *  If polling, wait for the transmitter to be ready.
97   *  Check for flow control requests and process.
98   *  Then output the character.
99   */
100  buf[0] = ch;
101
102  YAMON_FUNC_PRINT_COUNT(buf,1);
103}
104
105/*
106 *  Open entry point
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  return RTEMS_SUCCESSFUL;
116}
117
118/*
119 *  Close entry point
120 */
121rtems_device_driver console_close(
122  rtems_device_major_number major,
123  rtems_device_minor_number minor,
124  void                    * arg
125)
126{
127  return RTEMS_SUCCESSFUL;
128}
129
130/*
131 * read bytes from the serial port. We only have stdin.
132 */
133rtems_device_driver console_read(
134  rtems_device_major_number major,
135  rtems_device_minor_number minor,
136  void                    * arg
137)
138{
139  rtems_libio_rw_args_t *rw_args;
140  char *buffer;
141  int maximum;
142  int count = 0;
143
144  rw_args = (rtems_libio_rw_args_t *) arg;
145
146  buffer = rw_args->buffer;
147  maximum = rw_args->count;
148
149  for (count = 0; count < maximum; count++) {
150    buffer[ count ] = inbyte();
151    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
152      buffer[ count++ ]  = '\n';
153      break;
154    }
155  }
156
157  rw_args->bytes_moved = count;
158  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
159}
160
161/*
162 * write bytes to the serial port. Stdout and stderr are the same.
163 */
164rtems_device_driver console_write(
165  rtems_device_major_number major,
166  rtems_device_minor_number minor,
167  void                    * arg
168)
169{
170  int count;
171  int maximum;
172  rtems_libio_rw_args_t *rw_args;
173  char *buffer;
174
175  rw_args = (rtems_libio_rw_args_t *) arg;
176
177  buffer = rw_args->buffer;
178  maximum = rw_args->count;
179
180  for (count = 0; count < maximum; count++) {
181    if ( buffer[ count ] == '\n') {
182      outbyte('\r');
183    }
184    outbyte( buffer[ count ] );
185  }
186
187  rw_args->bytes_moved = maximum;
188  return 0;
189}
190
191/*
192 *  IO Control entry point
193 */
194rtems_device_driver console_control(
195  rtems_device_major_number major,
196  rtems_device_minor_number minor,
197  void                    * arg
198)
199{
200  return RTEMS_SUCCESSFUL;
201}
202
203#include <rtems/bspIo.h>
204
205static void RBTX4938_output_char(char c) { outbyte( c ); }
206
207BSP_output_char_function_type           BSP_output_char = RBTX4938_output_char;
208BSP_polling_getchar_function_type       BSP_poll_char = NULL;
209
Note: See TracBrowser for help on using the repository browser.