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