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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [mips64orion/] [p4000/] [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 IDT 4650 console IO package.
3
 *
4
 *  Author:     Craig Lebakken <craigl@transition.com>
5
 *
6
 *  COPYRIGHT (c) 1996 by Transition Networks Inc.
7
 *
8
 *  To anyone who acknowledges that this file is provided "AS IS"
9
 *  without any express or implied warranty:
10
 *      permission to use, copy, modify, and distribute this file
11
 *      for any purpose is hereby granted without fee, provided that
12
 *      the above copyright notice and this notice appears in all
13
 *      copies, and that the name of Transition Networks not be used in
14
 *      advertising or publicity pertaining to distribution of the
15
 *      software without specific, written prior permission.
16
 *      Transition Networks makes no representations about the suitability
17
 *      of this software for any purpose.
18
 *
19
 *  Derived from c/src/lib/libbsp/no_cpu/no_bsp/console/console.c:
20
 *
21
 *  COPYRIGHT (c) 1989-1999.
22
 *  On-Line Applications Research Corporation (OAR).
23
 *
24
 *  The license and distribution terms for this file may be
25
 *  found in the file LICENSE in this distribution or at
26
 *  http://www.OARcorp.com/rtems/license.html.
27
 *
28
 *  $Id: console.c,v 1.2 2001-09-27 12:00:24 chris Exp $
29
 */
30
 
31
 
32
/*
33
 *  Rather than deleting this, it is commented out to (hopefully) help
34
 *  the submitter send updates.
35
 *
36
 *  static char _sccsid[] = "@(#)console.c 08/20/96     1.6\n";
37
 */
38
 
39
 
40
 
41
#include <bsp.h>
42
#include <rtems/libio.h>
43
#include <ctype.h>
44
 
45
char idtsim_getchar( void );
46
void idtsim_putchar( char c );
47
void mips_leddisplay( char a, char b, char c, char d );
48
 
49
 
50
/*  console_initialize
51
 *
52
 *  This routine initializes the console IO driver.
53
 *
54
 *  Input parameters: NONE
55
 *
56
 *  Output parameters:  NONE
57
 *
58
 *  Return values:
59
 */
60
 
61
rtems_device_driver console_initialize(
62
  rtems_device_major_number  major,
63
  rtems_device_minor_number  minor,
64
  void                      *arg
65
)
66
{
67
  rtems_status_code status;
68
 
69
  status = rtems_io_register_name(
70
    "/dev/console",
71
    major,
72
    (rtems_device_minor_number) 0
73
  );
74
 
75
  if (status != RTEMS_SUCCESSFUL)
76
    rtems_fatal_error_occurred(status);
77
 
78
  return RTEMS_SUCCESSFUL;
79
}
80
 
81
 
82
/*  is_character_ready
83
 *
84
 *  This routine returns TRUE if a character is available.
85
 *
86
 *  Input parameters: NONE
87
 *
88
 *  Output parameters:  NONE
89
 *
90
 *  Return values:
91
 */
92
 
93
rtems_boolean is_character_ready(
94
  char *ch
95
)
96
{
97
  *ch = '\0';   /* return NULL for no particular reason */
98
  return(TRUE);
99
}
100
 
101
/*  inbyte
102
 *
103
 *  This routine reads a character from the SOURCE.
104
 *
105
 *  Input parameters: NONE
106
 *
107
 *  Output parameters:  NONE
108
 *
109
 *  Return values:
110
 *    character read from SOURCE
111
 */
112
 
113
char inbyte( void )
114
{
115
  /*
116
   *  If polling, wait until a character is available.
117
   */
118
 
119
   return idtsim_getchar();
120
}
121
 
122
/*  outbyte
123
 *
124
 *  This routine transmits a character out the SOURCE.  It may support
125
 *  XON/XOFF flow control.
126
 *
127
 *  Input parameters:
128
 *    ch  - character to be transmitted
129
 *
130
 *  Output parameters:  NONE
131
 */
132
 
133
void outbyte(
134
  char ch
135
)
136
{
137
#define NUM_LEDS 4
138
   static unsigned int cur_led = 0;
139
   static unsigned char led_chars[NUM_LEDS];
140
 
141
  /*
142
   *  If polling, wait for the transmitter to be ready.
143
   *  Check for flow control requests and process.
144
   *  Then output the character.
145
   */
146
 
147
  idtsim_putchar( ch );
148
 
149
  /* print out first four alpha numeric characters in a line */
150
  if ( ch == '\n' )
151
  {
152
    mips_leddisplay( led_chars[0], led_chars[1], led_chars[2], led_chars[3] );
153
    cur_led = 0;
154
  }
155
  else if ( isalnum( (unsigned char) ch ) && cur_led < NUM_LEDS )
156
  {
157
    led_chars[cur_led++] = ch;
158
  }
159
 
160
}
161
 
162
 
163
#if 0
164
static int console_fd = -1;
165
#endif
166
 
167
/*
168
 *  Open entry point
169
 */
170
 
171
rtems_device_driver console_open(
172
  rtems_device_major_number major,
173
  rtems_device_minor_number minor,
174
  void                    * arg
175
)
176
{
177
#if 0
178
  int console_fd = open("tty0", 2); /* open for read/write */
179
#endif
180
  return RTEMS_SUCCESSFUL;
181
}
182
 
183
/*
184
 *  Close entry point
185
 */
186
 
187
rtems_device_driver console_close(
188
  rtems_device_major_number major,
189
  rtems_device_minor_number minor,
190
  void                    * arg
191
)
192
{
193
#if 0
194
  if ( console_fd )
195
    close( console_fd );
196
#endif
197
  return RTEMS_SUCCESSFUL;
198
}
199
 
200
/*
201
 * read bytes from the serial port. We only have stdin.
202
 */
203
 
204
rtems_device_driver console_read(
205
  rtems_device_major_number major,
206
  rtems_device_minor_number minor,
207
  void                    * arg
208
)
209
{
210
  rtems_libio_rw_args_t *rw_args;
211
  char *buffer;
212
  int maximum;
213
  int count = 0;
214
 
215
  rw_args = (rtems_libio_rw_args_t *) arg;
216
 
217
  buffer = rw_args->buffer;
218
  maximum = rw_args->count;
219
 
220
  for (count = 0; count < maximum; count++) {
221
    buffer[ count ] = inbyte();
222
    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
223
      buffer[ count++ ]  = '\n';
224
      break;
225
    }
226
  }
227
 
228
  rw_args->bytes_moved = count;
229
  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
230
}
231
 
232
/*
233
 * write bytes to the serial port. Stdout and stderr are the same.
234
 */
235
 
236
rtems_device_driver console_write(
237
  rtems_device_major_number major,
238
  rtems_device_minor_number minor,
239
  void                    * arg
240
)
241
{
242
  int count;
243
  int maximum;
244
  rtems_libio_rw_args_t *rw_args;
245
  char *buffer;
246
 
247
  rw_args = (rtems_libio_rw_args_t *) arg;
248
 
249
  buffer = rw_args->buffer;
250
  maximum = rw_args->count;
251
 
252
  for (count = 0; count < maximum; count++) {
253
    if ( buffer[ count ] == '\n') {
254
      outbyte('\r');
255
    }
256
    outbyte( buffer[ count ] );
257
  }
258
 
259
  rw_args->bytes_moved = maximum;
260
  return 0;
261
}
262
 
263
/*
264
 *  IO Control entry point
265
 */
266
 
267
rtems_device_driver console_control(
268
  rtems_device_major_number major,
269
  rtems_device_minor_number minor,
270
  void                    * arg
271
)
272
{
273
  return RTEMS_SUCCESSFUL;
274
}

powered by: WebSVN 2.1.0

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