OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [m68k/] [mvme147/] [console/] [console.c] - Blame information for rev 493

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.