source: rtems/c/src/lib/libbsp/m68k/mvme147/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: 4.8 KB
Line 
1/*
2 *  This file contains the MVME147 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 *  MVME147 port for TNI - Telecom Bretagne
13 *  by Dominique LE CAMPION (Dominique.LECAMPION@enst-bretagne.fr)
14 *  May 1996
15 *
16 *  This file was taken from the DMV152 bsp
17 *
18 *  $Id$
19 */
20
21#define M147_INIT
22
23#include <bsp.h>
24#include <rtems/libio.h>
25#include <zilog/z8530.h>
26
27
28/*  console_initialize
29 *
30 *  This routine initializes the console IO driver.
31 *
32 *  Input parameters: NONE
33 *
34 *  Output parameters:  NONE
35 *
36 *  Return values:
37 */
38 
39rtems_device_driver console_initialize(
40  rtems_device_major_number  major,
41  rtems_device_minor_number  minor,
42  void                      *arg
43)
44{
45  rtems_status_code status;
46 
47  status = rtems_io_register_name(
48    "/dev/console",
49    major,
50    (rtems_device_minor_number) 0
51  );
52 
53  if (status != RTEMS_SUCCESSFUL)
54    rtems_fatal_error_occurred(status);
55 
56  return RTEMS_SUCCESSFUL;
57}
58
59/*  is_character_ready
60 *
61 *  This routine returns TRUE if a character is available.
62 *
63 *  Input parameters: NONE
64 *
65 *  Output parameters:  NONE
66 *
67 *  Return values:
68 */
69
70rtems_boolean is_character_ready(
71  char *ch
72)
73{
74  rtems_unsigned8 rr_0;
75
76  for ( ; ; ) {
77    Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
78    if ( !(rr_0 & RR_0_RX_DATA_AVAILABLE) )
79      return( FALSE );
80
81    Z8x30_READ_DATA( CONSOLE_DATA, *ch );
82    return( TRUE );
83  }
84}
85
86/*  inbyte
87 *
88 *  This routine reads a character from the SCC.
89 *
90 *  Input parameters: NONE
91 *
92 *  Output parameters:  NONE
93 *
94 *  Return values:
95 *    character read from SCC
96 */
97
98char inbyte( void )
99{
100  rtems_unsigned8 rr_0;
101  char ch;
102
103  for ( ; ; ) {
104    Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
105    if ( (rr_0 & RR_0_RX_DATA_AVAILABLE) != 0 )
106      break;
107  }
108
109  Z8x30_READ_DATA( CONSOLE_DATA, ch );
110  return ( ch );
111}
112
113/*  outbyte
114 *
115 *  This routine transmits a character out the SCC.  It supports
116 *  XON/XOFF flow control.
117 *
118 *  Input parameters:
119 *    ch  - character to be transmitted
120 *
121 *  Output parameters:  NONE
122 */
123
124void outbyte(
125  char ch
126)
127{
128  rtems_unsigned8 rr_0;
129  char            flow_control;
130
131  for ( ; ; ) {
132    Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
133    if ( (rr_0 & RR_0_TX_BUFFER_EMPTY) != 0 )
134      break;
135  }
136
137  for ( ; ; ) {
138    Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
139    if ( (rr_0 & RR_0_RX_DATA_AVAILABLE) == 0 )
140      break;
141
142    Z8x30_READ_DATA( CONSOLE_DATA, flow_control );
143
144    if ( flow_control == XOFF )
145      do {
146        do {
147          Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
148        } while ( (rr_0 & RR_0_RX_DATA_AVAILABLE) == 0 );
149        Z8x30_READ_DATA( CONSOLE_DATA, flow_control );
150      } while ( flow_control != XON );
151  }
152
153  Z8x30_WRITE_DATA( CONSOLE_DATA, ch );
154}
155
156/*
157 *  Open entry point
158 */
159
160rtems_device_driver console_open(
161  rtems_device_major_number major,
162  rtems_device_minor_number minor,
163  void                    * arg
164)
165{
166  return RTEMS_SUCCESSFUL;
167}
168 
169/*
170 *  Close entry point
171 */
172
173rtems_device_driver console_close(
174  rtems_device_major_number major,
175  rtems_device_minor_number minor,
176  void                    * arg
177)
178{
179  return RTEMS_SUCCESSFUL;
180}
181
182/*
183 * read bytes from the serial port. We only have stdin.
184 */
185
186rtems_device_driver console_read(
187  rtems_device_major_number major,
188  rtems_device_minor_number minor,
189  void                    * arg
190)
191{
192  rtems_libio_rw_args_t *rw_args;
193  char *buffer;
194  int maximum;
195  int count = 0;
196 
197  rw_args = (rtems_libio_rw_args_t *) arg;
198
199  buffer = rw_args->buffer;
200  maximum = rw_args->count;
201
202  for (count = 0; count < maximum; count++) {
203    buffer[ count ] = inbyte();
204    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
205      buffer[ count++ ]  = '\n';
206      break;
207    }
208  }
209
210  rw_args->bytes_moved = count;
211  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
212}
213
214/*
215 * write bytes to the serial port. Stdout and stderr are the same.
216 */
217
218rtems_device_driver console_write(
219  rtems_device_major_number major,
220  rtems_device_minor_number minor,
221  void                    * arg
222)
223{
224  int count;
225  int maximum;
226  rtems_libio_rw_args_t *rw_args;
227  char *buffer;
228
229  rw_args = (rtems_libio_rw_args_t *) arg;
230
231  buffer = rw_args->buffer;
232  maximum = rw_args->count;
233
234  for (count = 0; count < maximum; count++) {
235    if ( buffer[ count ] == '\n') {
236      outbyte('\r');
237    }
238    outbyte( buffer[ count ] );
239  }
240
241  rw_args->bytes_moved = maximum;
242  return 0;
243}
244
245/*
246 *  IO Control entry point
247 */
248
249rtems_device_driver console_control(
250  rtems_device_major_number major,
251  rtems_device_minor_number minor,
252  void                    * arg
253)
254{
255  return RTEMS_SUCCESSFUL;
256}
257
Note: See TracBrowser for help on using the repository browser.