source: rtems/c/src/lib/libbsp/a29k/portsw/console/console.c @ b7894a8c

Last change on this file since b7894a8c was b7894a8c, checked in by Joel Sherrill <joel.sherrill@…>, on 09/04/03 at 18:43:42

2003-09-04 Joel Sherrill <joel@…>

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