source: rtems/c/src/lib/libbsp/i960/rxgen960/console/console.c @ 129daf3

4.104.114.84.95
Last change on this file since 129daf3 was 129daf3, checked in by Joel Sherrill <joel.sherrill@…>, on 09/04/03 at 18:51:33

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