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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [a29k/] [portsw/] [console/] [console.c] - Blame information for rev 173

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
2
 *  This file contains the template for a 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 11:59:36 chris Exp $
12
 */
13
 
14
#define NO_BSP_INIT
15
 
16
 
17
/* only one of the following can be defined */
18
#define SERIAL_INPUT  /* use serial input */
19
/* #define HIF_INPUT */     /* use HIF input */
20
 
21
#if defined(SERIAL_INPUT) && defined(HIF_INPUT)
22
#error SERIAL_INPUT and HIF_INPUT cannot both be defined!!!
23
#endif
24
 
25
/* both of the following can be defined */
26
#define SERIAL_OUTPUT /* remove to disable serial port console output */
27
/* #define HIF_OUTPUT */   /* remove to disable HIF console output */
28
 
29
#include <bsp.h>
30
#include <rtems/libio.h>
31
#include "serial.h"
32
#include "concntl.h"
33
 
34
#ifndef lint
35
static char _sccsid[] = "@(#)console.c 09/12/96     1.13\n";
36
#endif
37
 
38
/*  console_initialize
39
 *
40
 *  This routine initializes the console IO driver.
41
 *
42
 *  Input parameters: NONE
43
 *
44
 *  Output parameters:  NONE
45
 *
46
 *  Return values:
47
 */
48
 
49
rtems_device_driver console_initialize(
50
  rtems_device_major_number  major,
51
  rtems_device_minor_number  minor,
52
  void                      *arg
53
)
54
{
55
  rtems_status_code status;
56
 
57
  if ( arg )
58
  {
59
     if ( console_duartinit(minor,*(unsigned32*)arg) )
60
        return RTEMS_INVALID_NUMBER;
61
  }
62
  else
63
  {
64
     if ( console_duartinit(1,9600) || console_duartinit(0,9600) )
65
     {
66
        return RTEMS_INVALID_NUMBER;
67
     }
68
  }
69
 
70
  status = rtems_io_register_name(
71
    "/dev/console",
72
    major,
73
    (rtems_device_minor_number) 0
74
  );
75
 
76
  if (status != RTEMS_SUCCESSFUL)
77
    rtems_fatal_error_occurred(status);
78
 
79
  return RTEMS_SUCCESSFUL;
80
}
81
 
82
 
83
/*  is_character_ready
84
 *
85
 *  This routine returns TRUE if a character is available.
86
 *
87
 *  Input parameters: NONE
88
 *
89
 *  Output parameters:  NONE
90
 *
91
 *  Return values:
92
 */
93
 
94
rtems_boolean is_character_ready(
95
  char *ch
96
)
97
{
98
  *ch = '\0';   /* return NULL for no particular reason */
99
  return(TRUE);
100
}
101
 
102
/*  inbyte
103
 *
104
 *  This routine reads a character from the SOURCE.
105
 *
106
 *  Input parameters: NONE
107
 *
108
 *  Output parameters:  NONE
109
 *
110
 *  Return values:
111
 *    character read from SOURCE
112
 */
113
 
114
char inbyte( unsigned int minor )
115
{
116
  /*
117
   *  If polling, wait until a character is available.
118
   */
119
#ifdef HIF_INPUT
120
  char retch;
121
  _read( 1, &retch, 1 );
122
  return retch;
123
#endif
124
#ifdef SERIAL_INPUT
125
  return console_sps_getc( minor );
126
#endif
127
}
128
 
129
/*  outbyte
130
 *
131
 *  This routine transmits a character out the SOURCE.  It may support
132
 *  XON/XOFF flow control.
133
 *
134
 *  Input parameters:
135
 *    ch  - character to be transmitted
136
 *
137
 *  Output parameters:  NONE
138
 */
139
 
140
void outbyte( unsigned int minor,
141
  char ch
142
)
143
{
144
  /*
145
   *  If polling, wait for the transmitter to be ready.
146
   *  Check for flow control requests and process.
147
   *  Then output the character.
148
   */
149
 
150
#ifdef SERIAL_OUTPUT
151
  console_sps_putc( minor, ch );
152
#endif
153
 
154
  /*
155
   *  Carriage Return/New line translation.
156
   */
157
 
158
  if ( ch == '\n' )
159
    outbyte( minor, '\r' );
160
}
161
 
162
 
163
/*
164
 *  Open entry point
165
 */
166
 
167
rtems_device_driver console_open(
168
  rtems_device_major_number major,
169
  rtems_device_minor_number minor,
170
  void                    * arg
171
)
172
{
173
  return RTEMS_SUCCESSFUL;
174
}
175
 
176
/*
177
 *  Close entry point
178
 */
179
 
180
rtems_device_driver console_close(
181
  rtems_device_major_number major,
182
  rtems_device_minor_number minor,
183
  void                    * arg
184
)
185
{
186
  return RTEMS_SUCCESSFUL;
187
}
188
 
189
/*
190
 * read bytes from the serial port. We only have stdin.
191
 */
192
 
193
rtems_device_driver console_read(
194
  rtems_device_major_number major,
195
  rtems_device_minor_number minor,
196
  void                    * arg
197
)
198
{
199
  rtems_libio_rw_args_t *rw_args;
200
  unsigned8 *buffer;
201
  unsigned32 maximum;
202
  unsigned32 count = 0;
203
 
204
  rw_args = (rtems_libio_rw_args_t *) arg;
205
 
206
  buffer = rw_args->buffer;
207
  maximum = rw_args->count;
208
 
209
  for (count = 0; count < maximum; count++) {
210
    buffer[ count ] = inbyte(minor);
211
    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
212
      buffer[ count++ ]  = '\n';
213
      outbyte( minor, '\n' ); /* newline */
214
      break;
215
    }
216
    else if (buffer[ count ] == '\b' && count > 0 )
217
    {
218
      outbyte( minor, '\b' ); /* move back one space */
219
      outbyte( minor, ' ' ); /* erase the character */
220
      outbyte( minor, '\b' ); /* move back one space */
221
      count-=2;
222
    }
223
    else
224
      outbyte( minor, buffer[ count ] ); /* echo the character */
225
  }
226
 
227
  rw_args->bytes_moved = count;
228
  return (count > 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
229
}
230
 
231
/*
232
 * write bytes to the serial port. Stdout and stderr are the same.
233
 */
234
 
235
rtems_device_driver console_write(
236
  rtems_device_major_number major,
237
  rtems_device_minor_number minor,
238
  void                    * arg
239
)
240
{
241
  int count;
242
  int maximum;
243
  rtems_libio_rw_args_t *rw_args;
244
  unsigned8 *buffer;
245
 
246
  rw_args = (rtems_libio_rw_args_t *) arg;
247
 
248
  buffer = rw_args->buffer;
249
  maximum = rw_args->count;
250
 
251
#ifdef HIF_OUTPUT
252
  _write( 0, buffer, maximum );
253
#endif
254
#ifdef SERIAL_OUTPUT
255
  for (count = 0; count < maximum; count++) {
256
    if ( buffer[ count ] == '\n') {
257
      outbyte(minor,'\r');
258
    }
259
    outbyte( minor,buffer[ count ] );
260
  }
261
#endif
262
 
263
  rw_args->bytes_moved = maximum;
264
  return 0;
265
}
266
 
267
/*
268
 *  IO Control entry point
269
 */
270
 
271
rtems_device_driver console_control(
272
  rtems_device_major_number major,
273
  rtems_device_minor_number minor,
274
  void                    * arg
275
)
276
{
277
  if (!arg)
278
     return RTEMS_INVALID_ADDRESS;
279
 
280
  switch( ((console_ioctl_request_t *)arg)->ioctl_type )
281
  {
282
     case CON_KBHIT:
283
        /* check if keyboard was hit */
284
        ((console_ioctl_request_t *)arg)->param = console_sps_kbhit(minor);
285
        break;
286
 
287
     case CON_GET_RAW_BYTE:
288
        ((console_ioctl_request_t *)arg)->param = inbyte(minor);
289
        break;
290
 
291
     case CON_SEND_RAW_BYTE:
292
        outbyte(minor, ((console_ioctl_request_t *)arg)->param);
293
        break;
294
 
295
     default:
296
        break;
297
  }
298
 
299
  return RTEMS_SUCCESSFUL;
300
}

powered by: WebSVN 2.1.0

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