OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

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

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

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

powered by: WebSVN 2.1.0

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