source: rtems/c/src/lib/libbsp/m68k/dmv152/console/console.c @ 3652ad35

4.104.114.84.95
Last change on this file since 3652ad35 was 3652ad35, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 19, 1995 at 2:53:29 PM

Minor bug fixes to get all targets compilable and running. The
single biggest changes were the expansion of the workspace size
macro to include other types of objects and the increase in the
minimum stack size for most CPUs.

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 *  This file contains the DMV152 console IO package.
3 *
4 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
5 *  On-Line Applications Research Corporation (OAR).
6 *  All rights assigned to U.S. Government, 1994.
7 *
8 *  This material may be reproduced by or for the U.S. Government pursuant
9 *  to the copyright license under the clause at DFARS 252.227-7013.  This
10 *  notice must appear in all copies of this file and its derivatives.
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/*  is_character_ready
52 *
53 *  This routine returns TRUE if a character is available.
54 *
55 *  Input parameters: NONE
56 *
57 *  Output parameters:  NONE
58 *
59 *  Return values:
60 */
61
62rtems_boolean is_character_ready(
63  char *ch
64)
65{
66  rtems_unsigned8 rr_0;
67
68  for ( ; ; ) {
69    Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
70    if ( !(rr_0 & RR_0_RX_DATA_AVAILABLE) )
71      return( FALSE );
72
73    Z8x30_READ_DATA( CONSOLE_DATA, *ch );
74    return( TRUE );
75  }
76}
77
78/*  inbyte
79 *
80 *  This routine reads a character from the SCC.
81 *
82 *  Input parameters: NONE
83 *
84 *  Output parameters:  NONE
85 *
86 *  Return values:
87 *    character read from SCC
88 */
89
90char inbyte( void )
91{
92  rtems_unsigned8 rr_0;
93  char ch;
94
95  for ( ; ; ) {
96    Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
97    if ( (rr_0 & RR_0_RX_DATA_AVAILABLE) != 0 )
98      break;
99  }
100
101  Z8x30_READ_DATA( CONSOLE_DATA, ch );
102  return ( ch );
103}
104
105/*  outbyte
106 *
107 *  This routine transmits a character out the SCC.  It supports
108 *  XON/XOFF flow control.
109 *
110 *  Input parameters:
111 *    ch  - character to be transmitted
112 *
113 *  Output parameters:  NONE
114 */
115
116void outbyte(
117  char ch
118)
119{
120  rtems_unsigned8 rr_0;
121  char            flow_control;
122
123  for ( ; ; ) {
124    Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
125    if ( (rr_0 & RR_0_TX_BUFFER_EMPTY) != 0 )
126      break;
127  }
128
129  for ( ; ; ) {
130    Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
131    if ( (rr_0 & RR_0_RX_DATA_AVAILABLE) == 0 )
132      break;
133
134    Z8x30_READ_DATA( CONSOLE_DATA, flow_control );
135
136    if ( flow_control == XOFF )
137      do {
138        do {
139          Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
140        } while ( (rr_0 & RR_0_RX_DATA_AVAILABLE) == 0 );
141        Z8x30_READ_DATA( CONSOLE_DATA, flow_control );
142      } while ( flow_control != XON );
143  }
144
145  Z8x30_WRITE_DATA( CONSOLE_DATA, ch );
146}
147
148/*
149 *  Open entry point
150 */
151
152rtems_device_driver console_open(
153  rtems_device_major_number major,
154  rtems_device_minor_number minor,
155  void                    * arg
156)
157{
158  return RTEMS_SUCCESSFUL;
159}
160 
161/*
162 *  Close entry point
163 */
164
165rtems_device_driver console_close(
166  rtems_device_major_number major,
167  rtems_device_minor_number minor,
168  void                    * arg
169)
170{
171  return RTEMS_SUCCESSFUL;
172}
173
174/*
175 * read bytes from the serial port. We only have stdin.
176 */
177
178rtems_device_driver console_read(
179  rtems_device_major_number major,
180  rtems_device_minor_number minor,
181  void                    * arg
182)
183{
184  rtems_libio_rw_args_t *rw_args;
185  char *buffer;
186  int maximum;
187  int count = 0;
188 
189  rw_args = (rtems_libio_rw_args_t *) arg;
190
191  buffer = rw_args->buffer;
192  maximum = rw_args->count;
193
194  for (count = 0; count < maximum; count++) {
195    buffer[ count ] = inbyte();
196    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
197      buffer[ count++ ]  = '\n';
198      buffer[ count ]  = 0;
199      break;
200    }
201  }
202
203  rw_args->bytes_moved = count;
204  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
205}
206
207/*
208 * write bytes to the serial port. Stdout and stderr are the same.
209 */
210
211rtems_device_driver console_write(
212  rtems_device_major_number major,
213  rtems_device_minor_number minor,
214  void                    * arg
215)
216{
217  int count;
218  int maximum;
219  rtems_libio_rw_args_t *rw_args;
220  char *buffer;
221
222  rw_args = (rtems_libio_rw_args_t *) arg;
223
224  buffer = rw_args->buffer;
225  maximum = rw_args->count;
226
227  for (count = 0; count < maximum; count++) {
228    if ( buffer[ count ] == '\n') {
229      outbyte('\r');
230    }
231    outbyte( buffer[ count ] );
232  }
233
234  rw_args->bytes_moved = maximum;
235  return 0;
236}
237
238/*
239 *  IO Control entry point
240 */
241
242rtems_device_driver console_control(
243  rtems_device_major_number major,
244  rtems_device_minor_number minor,
245  void                    * arg
246)
247{
248  return RTEMS_SUCCESSFUL;
249}
Note: See TracBrowser for help on using the repository browser.