source: rtems/c/src/lib/libbsp/no_cpu/no_bsp/console/console.c @ 8f35817

4.104.114.84.95
Last change on this file since 8f35817 was 8f35817, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 15, 1997 at 6:52:26 PM

eliminated potential for overfilling buffer on read

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 *  This file contains the template for a console IO package.
3 *
4 *  COPYRIGHT (c) 1989-1997.
5 *  On-Line Applications Research Corporation (OAR).
6 *  Copyright assigned to U.S. Government, 1994.
7 *
8 *  The license and distribution terms for this file may in
9 *  the file LICENSE in this distribution or at
10 *  http://www.OARcorp.com/rtems/license.html.
11 *
12 *  $Id$
13 */
14
15#define NO_BSP_INIT
16
17#include <bsp.h>
18#include <rtems/libio.h>
19
20/*  console_initialize
21 *
22 *  This routine initializes the console IO driver.
23 *
24 *  Input parameters: NONE
25 *
26 *  Output parameters:  NONE
27 *
28 *  Return values:
29 */
30
31rtems_device_driver console_initialize(
32  rtems_device_major_number  major,
33  rtems_device_minor_number  minor,
34  void                      *arg
35)
36{
37  rtems_status_code status;
38 
39  status = rtems_io_register_name(
40    "/dev/console",
41    major,
42    (rtems_device_minor_number) 0
43  );
44 
45  if (status != RTEMS_SUCCESSFUL)
46    rtems_fatal_error_occurred(status);
47 
48  return RTEMS_SUCCESSFUL;
49}
50
51
52/*  is_character_ready
53 *
54 *  This routine returns TRUE if a character is available.
55 *
56 *  Input parameters: NONE
57 *
58 *  Output parameters:  NONE
59 *
60 *  Return values:
61 */
62
63rtems_boolean is_character_ready(
64  char *ch
65)
66{
67  *ch = '\0';   /* return NULL for no particular reason */
68  return(TRUE);
69}
70
71/*  inbyte
72 *
73 *  This routine reads a character from the SOURCE.
74 *
75 *  Input parameters: NONE
76 *
77 *  Output parameters:  NONE
78 *
79 *  Return values:
80 *    character read from SOURCE
81 */
82
83char inbyte( void )
84{
85  /*
86   *  If polling, wait until a character is available.
87   */
88
89  return '\0';
90}
91
92/*  outbyte
93 *
94 *  This routine transmits a character out the SOURCE.  It may support
95 *  XON/XOFF flow control.
96 *
97 *  Input parameters:
98 *    ch  - character to be transmitted
99 *
100 *  Output parameters:  NONE
101 */
102
103void outbyte(
104  char ch
105)
106{
107  /*
108   *  If polling, wait for the transmitter to be ready.
109   *  Check for flow control requests and process.
110   *  Then output the character.
111   */
112
113  /*
114   *  Carriage Return/New line translation.
115   */
116
117  if ( ch == '\n' )
118    outbyte( '\r' );
119}
120
121
122/*
123 *  Open entry point
124 */
125
126rtems_device_driver console_open(
127  rtems_device_major_number major,
128  rtems_device_minor_number minor,
129  void                    * arg
130)
131{
132  return RTEMS_SUCCESSFUL;
133}
134 
135/*
136 *  Close entry point
137 */
138
139rtems_device_driver console_close(
140  rtems_device_major_number major,
141  rtems_device_minor_number minor,
142  void                    * arg
143)
144{
145  return RTEMS_SUCCESSFUL;
146}
147
148/*
149 * read bytes from the serial port. We only have stdin.
150 */
151
152rtems_device_driver console_read(
153  rtems_device_major_number major,
154  rtems_device_minor_number minor,
155  void                    * arg
156)
157{
158  rtems_libio_rw_args_t *rw_args;
159  char *buffer;
160  int maximum;
161  int count = 0;
162 
163  rw_args = (rtems_libio_rw_args_t *) arg;
164
165  buffer = rw_args->buffer;
166  maximum = rw_args->count;
167
168  for (count = 0; count < maximum; count++) {
169    buffer[ count ] = inbyte();
170    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
171      buffer[ count++ ]  = '\n';
172      break;
173    }
174  }
175
176  rw_args->bytes_moved = count;
177  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
178}
179
180/*
181 * write bytes to the serial port. Stdout and stderr are the same.
182 */
183
184rtems_device_driver console_write(
185  rtems_device_major_number major,
186  rtems_device_minor_number minor,
187  void                    * arg
188)
189{
190  int count;
191  int maximum;
192  rtems_libio_rw_args_t *rw_args;
193  char *buffer;
194
195  rw_args = (rtems_libio_rw_args_t *) arg;
196
197  buffer = rw_args->buffer;
198  maximum = rw_args->count;
199
200  for (count = 0; count < maximum; count++) {
201    if ( buffer[ count ] == '\n') {
202      outbyte('\r');
203    }
204    outbyte( buffer[ count ] );
205  }
206
207  rw_args->bytes_moved = maximum;
208  return 0;
209}
210
211/*
212 *  IO Control entry point
213 */
214
215rtems_device_driver console_control(
216  rtems_device_major_number major,
217  rtems_device_minor_number minor,
218  void                    * arg
219)
220{
221  return RTEMS_SUCCESSFUL;
222}
Note: See TracBrowser for help on using the repository browser.