source: rtems/c/src/lib/libbsp/i960/rxgen960/console/console.c @ 2ea8df3

4.104.114.84.95
Last change on this file since 2ea8df3 was 702c5f5, checked in by Joel Sherrill <joel.sherrill@…>, on 10/27/99 at 15:29:18

The rxgen960 BSP and i960 RPM support was submitted by Mark Bronson
<mark@…> of RAMIX.

  • Property mode set to 100644
File size: 5.0 KB
Line 
1/*
2 *  This file contains the template for a console IO package.
3 *
4 *  COPYRIGHT (c) 1989-1997.
5 *  On-Line Applications Research Corporation (OAR).
6 *  Copyright assigned to U.S. Government, 1994.
7 *
8 *  The license and distribution terms for this file may in
9 *  the file LICENSE in this distribution or at
10 *  http://www.OARcorp.com/rtems/license.html.
11 *
12 *  $Id$
13 */
14
15#define NO_BSP_INIT
16
17
18/* only one of the following can be defined */
19#define SERIAL_INPUT  /* use serial input */
20
21#include <bsp.h>
22#include <rtems/libio.h>
23#include "concntl.h"
24#include "pcimsgreg.h"
25
26#ifndef lint
27static char _sccsid[] = "@(#)console.c 09/12/96     1.13\n";
28#endif
29
30/*  console_initialize
31 *
32 *  This routine initializes the console IO driver.
33 *
34 *  Input parameters: NONE
35 *
36 *  Output parameters:  NONE
37 *
38 *  Return values:
39 */
40
41rtems_device_driver console_initialize(
42  rtems_device_major_number  major,
43  rtems_device_minor_number  minor,
44  void                      *arg
45)
46{
47  rtems_status_code status;
48 
49     if ( console_pmr_init(*(unsigned32*)arg) )
50        return RTEMS_INVALID_NUMBER;
51
52 
53  status = rtems_io_register_name(
54    "/dev/console",
55    major,
56    (rtems_device_minor_number) 0
57  );
58 
59  if (status != RTEMS_SUCCESSFUL)
60    rtems_fatal_error_occurred(status);
61 
62  return RTEMS_SUCCESSFUL;
63}
64
65
66/*  is_character_ready
67 *
68 *  This routine returns TRUE if a character is available.
69 *
70 *  Input parameters: NONE
71 *
72 *  Output parameters:  NONE
73 *
74 *  Return values:
75 */
76
77rtems_boolean is_character_ready(
78  char *ch
79)
80{
81  *ch = '\0';   /* return NULL for no particular reason */
82  return(console_pmr_kbhit());
83}
84
85/*  inbyte
86 *
87 *  This routine reads a character from the SOURCE.
88 *
89 *  Input parameters: NONE
90 *
91 *  Output parameters:  NONE
92 *
93 *  Return values:
94 *    character read from SOURCE
95 */
96
97char inbyte( unsigned int minor )
98{
99  /*
100   *  If polling, wait until a character is available.
101   */
102  return console_pmr_getc();
103}
104
105/*  outbyte
106 *
107 *  This routine transmits a character out the SOURCE.  It may support
108 *  XON/XOFF flow control.
109 *
110 *  Input parameters:
111 *    ch  - character to be transmitted
112 *
113 *  Output parameters:  NONE
114 */
115
116void outbyte( unsigned int minor,
117  char ch
118)
119{
120  console_pmr_putc( ch );
121
122  /*
123   *  Carriage Return/New line translation.
124   */
125
126  if ( ch == '\n' )
127    outbyte( minor, '\r' );
128}
129
130
131/*
132 *  Open entry point
133 */
134
135rtems_device_driver console_open(
136  rtems_device_major_number major,
137  rtems_device_minor_number minor,
138  void                    * arg
139)
140{
141  return RTEMS_SUCCESSFUL;
142}
143 
144/*
145 *  Close entry point
146 */
147
148rtems_device_driver console_close(
149  rtems_device_major_number major,
150  rtems_device_minor_number minor,
151  void                    * arg
152)
153{
154  return RTEMS_SUCCESSFUL;
155}
156
157/*
158 * read bytes from the serial port. We only have stdin.
159 */
160
161rtems_device_driver console_read(
162  rtems_device_major_number major,
163  rtems_device_minor_number minor,
164  void                    * arg
165)
166{
167  rtems_libio_rw_args_t *rw_args;
168  unsigned8 *buffer;
169  unsigned32 maximum;
170  unsigned32 count = 0;
171 
172  rw_args = (rtems_libio_rw_args_t *) arg;
173
174  buffer = rw_args->buffer;
175  maximum = rw_args->count;
176
177  for (count = 0; count < maximum; count++) {
178    buffer[ count ] = inbyte(minor);
179    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
180      buffer[ count++ ]  = '\n';
181      buffer[ count ]  = 0;
182      outbyte( minor, '\n' ); /* newline */
183      break;
184    }
185    else if (buffer[ count ] == '\b' && count > 0 )
186    {
187      outbyte( minor, '\b' ); /* move back one space */
188      outbyte( minor, ' ' ); /* erase the character */
189      outbyte( minor, '\b' ); /* move back one space */
190      count-=2;
191    }
192    else
193      outbyte( minor, buffer[ count ] ); /* echo the character */
194  }
195
196  rw_args->bytes_moved = count;
197  return (count > 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
198}
199
200/*
201 * write bytes to the serial port. Stdout and stderr are the same.
202 */
203
204rtems_device_driver console_write(
205  rtems_device_major_number major,
206  rtems_device_minor_number minor,
207  void                    * arg
208)
209{
210  int count;
211  int maximum;
212  rtems_libio_rw_args_t *rw_args;
213  unsigned8 *buffer;
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    if ( buffer[ count ] == '\n') {
222      outbyte(minor,'\r');
223    }
224    outbyte( minor,buffer[ count ] );
225  }
226
227  rw_args->bytes_moved = maximum;
228  return 0;
229}
230
231/*
232 *  IO Control entry point
233 */
234
235rtems_device_driver console_control(
236  rtems_device_major_number major,
237  rtems_device_minor_number minor,
238  void                    * arg
239)
240{
241  if (!arg)
242     return RTEMS_INVALID_ADDRESS;
243
244  switch( ((console_ioctl_request_t *)arg)->ioctl_type )
245  {
246     case CON_KBHIT:
247        /* check if keyboard was hit */
248        ((console_ioctl_request_t *)arg)->param = console_pmr_kbhit();
249        break;
250
251     case CON_GET_RAW_BYTE:
252        ((console_ioctl_request_t *)arg)->param = inbyte(minor);
253        break;
254
255     case CON_SEND_RAW_BYTE:
256        outbyte(minor, ((console_ioctl_request_t *)arg)->param);
257        break;
258
259     default:
260        break;
261  }
262
263  return RTEMS_SUCCESSFUL;
264}
Note: See TracBrowser for help on using the repository browser.