source: rtems/c/src/lib/libbsp/i960/rxgen960/console/console.c @ 1fc3537

4.104.114.84.95
Last change on this file since 1fc3537 was 1fc3537, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 12, 2001 at 9:07:45 PM

2001-10-12 Joel Sherrill <joel@…>

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