source: rtems/c/src/lib/libbsp/m68k/dmv152/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.1 KB
Line 
1/*
2 *  This file contains the DMV152 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 D152_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/*  inbyte
52 *
53 *  This routine reads a character from the SCC.
54 *
55 *  Input parameters: NONE
56 *
57 *  Output parameters:  NONE
58 *
59 *  Return values:
60 *    character read from SCC
61 */
62
63char inbyte( void )
64{
65  rtems_unsigned8 rr_0;
66  char ch;
67
68  for ( ; ; ) {
69    Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
70    if ( (rr_0 & RR_0_RX_DATA_AVAILABLE) != 0 )
71      break;
72  }
73
74  Z8x30_READ_DATA( CONSOLE_DATA, ch );
75  return ( ch );
76}
77
78/*  outbyte
79 *
80 *  This routine transmits a character out the SCC.  It supports
81 *  XON/XOFF flow control.
82 *
83 *  Input parameters:
84 *    ch  - character to be transmitted
85 *
86 *  Output parameters:  NONE
87 */
88
89void outbyte(
90  char ch
91)
92{
93  rtems_unsigned8 rr_0;
94  char            flow_control;
95
96  for ( ; ; ) {
97    Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
98    if ( (rr_0 & RR_0_TX_BUFFER_EMPTY) != 0 )
99      break;
100  }
101
102  for ( ; ; ) {
103    Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
104    if ( (rr_0 & RR_0_RX_DATA_AVAILABLE) == 0 )
105      break;
106
107    Z8x30_READ_DATA( CONSOLE_DATA, flow_control );
108
109    if ( flow_control == XOFF )
110      do {
111        do {
112          Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
113        } while ( (rr_0 & RR_0_RX_DATA_AVAILABLE) == 0 );
114        Z8x30_READ_DATA( CONSOLE_DATA, flow_control );
115      } while ( flow_control != XON );
116  }
117
118  Z8x30_WRITE_DATA( CONSOLE_DATA, ch );
119}
120
121/*
122 *  Open entry point
123 */
124
125rtems_device_driver console_open(
126  rtems_device_major_number major,
127  rtems_device_minor_number minor,
128  void                    * arg
129)
130{
131  return RTEMS_SUCCESSFUL;
132}
133 
134/*
135 *  Close entry point
136 */
137
138rtems_device_driver console_close(
139  rtems_device_major_number major,
140  rtems_device_minor_number minor,
141  void                    * arg
142)
143{
144  return RTEMS_SUCCESSFUL;
145}
146
147/*
148 * read bytes from the serial port. We only have stdin.
149 */
150
151rtems_device_driver console_read(
152  rtems_device_major_number major,
153  rtems_device_minor_number minor,
154  void                    * arg
155)
156{
157  rtems_libio_rw_args_t *rw_args;
158  char *buffer;
159  int maximum;
160  int count = 0;
161 
162  rw_args = (rtems_libio_rw_args_t *) arg;
163
164  buffer = rw_args->buffer;
165  maximum = rw_args->count;
166
167  for (count = 0; count < maximum; count++) {
168    buffer[ count ] = inbyte();
169    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
170      buffer[ count++ ]  = '\n';
171      break;
172    }
173  }
174
175  rw_args->bytes_moved = count;
176  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
177}
178
179/*
180 * write bytes to the serial port. Stdout and stderr are the same.
181 */
182
183rtems_device_driver console_write(
184  rtems_device_major_number major,
185  rtems_device_minor_number minor,
186  void                    * arg
187)
188{
189  int count;
190  int maximum;
191  rtems_libio_rw_args_t *rw_args;
192  char *buffer;
193
194  rw_args = (rtems_libio_rw_args_t *) arg;
195
196  buffer = rw_args->buffer;
197  maximum = rw_args->count;
198
199  for (count = 0; count < maximum; count++) {
200    if ( buffer[ count ] == '\n') {
201      outbyte('\r');
202    }
203    outbyte( buffer[ count ] );
204  }
205
206  rw_args->bytes_moved = maximum;
207  return 0;
208}
209
210/*
211 *  IO Control entry point
212 */
213
214rtems_device_driver console_control(
215  rtems_device_major_number major,
216  rtems_device_minor_number minor,
217  void                    * arg
218)
219{
220  return RTEMS_SUCCESSFUL;
221}
Note: See TracBrowser for help on using the repository browser.