source: rtems/c/src/lib/libbsp/mips/p4000/console/console.c @ 5bb00a8

4.104.114.84.95
Last change on this file since 5bb00a8 was 5bb00a8, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 11, 1996 at 7:13:44 PM

added $Id$ string to file header

  • Property mode set to 100644
File size: 5.5 KB
Line 
1/*
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, 1990, 1991, 1992, 1993, 1994.
22 *  On-Line Applications Research Corporation (OAR).
23 *  All rights assigned to U.S. Government, 1994.
24 *
25 *  This material may be reproduced by or for the U.S. Government pursuant
26 *  to the copyright license under the clause at DFARS 252.227-7013.  This
27 *  notice must appear in all copies of this file and its derivatives.
28 *
29 *  $Id$
30 */
31
32
33#ifndef lint
34static char _sccsid[] = "@(#)console.c 08/20/96     1.6\n";
35#endif
36
37
38#include <bsp.h>
39#include <rtems/libio.h>
40#include <ctype.h>
41
42char idtsim_getchar( void );
43void idtsim_putchar( char c );
44void mips_leddisplay( char a, char b, char c, char d );
45
46
47/*  console_initialize
48 *
49 *  This routine initializes the console IO driver.
50 *
51 *  Input parameters: NONE
52 *
53 *  Output parameters:  NONE
54 *
55 *  Return values:
56 */
57
58rtems_device_driver console_initialize(
59  rtems_device_major_number  major,
60  rtems_device_minor_number  minor,
61  void                      *arg
62)
63{
64  rtems_status_code status;
65 
66  status = rtems_io_register_name(
67    "/dev/console",
68    major,
69    (rtems_device_minor_number) 0
70  );
71 
72  if (status != RTEMS_SUCCESSFUL)
73    rtems_fatal_error_occurred(status);
74 
75  return RTEMS_SUCCESSFUL;
76}
77
78
79/*  is_character_ready
80 *
81 *  This routine returns TRUE if a character is available.
82 *
83 *  Input parameters: NONE
84 *
85 *  Output parameters:  NONE
86 *
87 *  Return values:
88 */
89
90rtems_boolean is_character_ready(
91  char *ch
92)
93{
94  *ch = '\0';   /* return NULL for no particular reason */
95  return(TRUE);
96}
97
98/*  inbyte
99 *
100 *  This routine reads a character from the SOURCE.
101 *
102 *  Input parameters: NONE
103 *
104 *  Output parameters:  NONE
105 *
106 *  Return values:
107 *    character read from SOURCE
108 */
109
110char inbyte( void )
111{
112  /*
113   *  If polling, wait until a character is available.
114   */
115
116   return idtsim_getchar();
117}
118
119/*  outbyte
120 *
121 *  This routine transmits a character out the SOURCE.  It may support
122 *  XON/XOFF flow control.
123 *
124 *  Input parameters:
125 *    ch  - character to be transmitted
126 *
127 *  Output parameters:  NONE
128 */
129
130void outbyte(
131  char ch
132)
133{
134#define NUM_LEDS 4
135   static unsigned int cur_led = 0;
136   static unsigned char led_chars[NUM_LEDS];
137
138  /*
139   *  If polling, wait for the transmitter to be ready.
140   *  Check for flow control requests and process.
141   *  Then output the character.
142   */
143
144  idtsim_putchar( ch );
145
146  /* print out first four alpha numeric characters in a line */
147  if ( ch == '\n' )
148  {
149    mips_leddisplay( led_chars[0], led_chars[1], led_chars[2], led_chars[3] );
150    cur_led = 0;
151  }
152  else if ( isalnum( ch ) && cur_led < NUM_LEDS )
153  {
154    led_chars[cur_led++] = ch;
155  }
156
157}
158
159
160static int console_fd = -1;
161
162/*
163 *  Open entry point
164 */
165
166rtems_device_driver console_open(
167  rtems_device_major_number major,
168  rtems_device_minor_number minor,
169  void                    * arg
170)
171{
172#if 0
173  int console_fd = open("tty0", 2); /* open for read/write */
174#endif
175  return RTEMS_SUCCESSFUL;
176}
177 
178/*
179 *  Close entry point
180 */
181
182rtems_device_driver console_close(
183  rtems_device_major_number major,
184  rtems_device_minor_number minor,
185  void                    * arg
186)
187{
188#if 0
189  if ( console_fd )
190    close( console_fd );
191#endif
192  return RTEMS_SUCCESSFUL;
193}
194
195/*
196 * read bytes from the serial port. We only have stdin.
197 */
198
199rtems_device_driver console_read(
200  rtems_device_major_number major,
201  rtems_device_minor_number minor,
202  void                    * arg
203)
204{
205  rtems_libio_rw_args_t *rw_args;
206  char *buffer;
207  int maximum;
208  int count = 0;
209 
210  rw_args = (rtems_libio_rw_args_t *) arg;
211
212  buffer = rw_args->buffer;
213  maximum = rw_args->count;
214
215  for (count = 0; count < maximum; count++) {
216    buffer[ count ] = inbyte();
217    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
218      buffer[ count++ ]  = '\n';
219      buffer[ count ]  = 0;
220      break;
221    }
222  }
223
224  rw_args->bytes_moved = count;
225  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
226}
227
228/*
229 * write bytes to the serial port. Stdout and stderr are the same.
230 */
231
232rtems_device_driver console_write(
233  rtems_device_major_number major,
234  rtems_device_minor_number minor,
235  void                    * arg
236)
237{
238  int count;
239  int maximum;
240  rtems_libio_rw_args_t *rw_args;
241  char *buffer;
242
243  rw_args = (rtems_libio_rw_args_t *) arg;
244
245  buffer = rw_args->buffer;
246  maximum = rw_args->count;
247
248  for (count = 0; count < maximum; count++) {
249    if ( buffer[ count ] == '\n') {
250      outbyte('\r');
251    }
252    outbyte( buffer[ count ] );
253  }
254
255  rw_args->bytes_moved = maximum;
256  return 0;
257}
258
259/*
260 *  IO Control entry point
261 */
262
263rtems_device_driver console_control(
264  rtems_device_major_number major,
265  rtems_device_minor_number minor,
266  void                    * arg
267)
268{
269  return RTEMS_SUCCESSFUL;
270}
Note: See TracBrowser for help on using the repository browser.