source: rtems/c/src/lib/libbsp/no_cpu/no_bsp/console/console.c @ 03f2154e

4.104.114.84.95
Last change on this file since 03f2154e was 03f2154e, checked in by Joel Sherrill <joel.sherrill@…>, on Apr 22, 1997 at 5:20:27 PM

headers updated to reflect new style copyright notice as part
of switching to the modified GNU GPL.

  • 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      buffer[ count ]  = 0;
173      break;
174    }
175  }
176
177  rw_args->bytes_moved = count;
178  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
179}
180
181/*
182 * write bytes to the serial port. Stdout and stderr are the same.
183 */
184
185rtems_device_driver console_write(
186  rtems_device_major_number major,
187  rtems_device_minor_number minor,
188  void                    * arg
189)
190{
191  int count;
192  int maximum;
193  rtems_libio_rw_args_t *rw_args;
194  char *buffer;
195
196  rw_args = (rtems_libio_rw_args_t *) arg;
197
198  buffer = rw_args->buffer;
199  maximum = rw_args->count;
200
201  for (count = 0; count < maximum; count++) {
202    if ( buffer[ count ] == '\n') {
203      outbyte('\r');
204    }
205    outbyte( buffer[ count ] );
206  }
207
208  rw_args->bytes_moved = maximum;
209  return 0;
210}
211
212/*
213 *  IO Control entry point
214 */
215
216rtems_device_driver console_control(
217  rtems_device_major_number major,
218  rtems_device_minor_number minor,
219  void                    * arg
220)
221{
222  return RTEMS_SUCCESSFUL;
223}
Note: See TracBrowser for help on using the repository browser.