source: rtems/c/src/lib/libbsp/i960/cvme961/console/console.c @ 5f57730

4.104.114.84.95
Last change on this file since 5f57730 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 *  This file contains the CVME961 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.OARcorp.com/rtems/license.html.
10 *
11 *  $Id$
12 */
13
14#define C961_INIT
15
16#include <bsp.h>
17#include <rtems/libio.h>
18
19/*  console_initialize
20 *
21 *  This routine initializes the console IO driver.
22 *
23 *  Input parameters: NONE
24 *
25 *  Output parameters:  NONE
26 *
27 *  Return values:
28 */
29
30rtems_device_driver console_initialize(
31  rtems_device_major_number  major,
32  rtems_device_minor_number  minor,
33  void                      *arg
34)
35{
36 rtems_status_code status;
37 
38  status = rtems_io_register_name(
39    "/dev/console",
40    major,
41    (rtems_device_minor_number) 0
42  );
43 
44  if (status != RTEMS_SUCCESSFUL)
45    rtems_fatal_error_occurred(status);
46 
47  return RTEMS_SUCCESSFUL;
48}
49
50/*
51 *  NINDY_IO( ... )
52 *
53 *  Interface to NINDY.
54 */
55
56#define NINDY_INPUT   0
57#define NINDY_OUTPUT  1
58
59void NINDY_IO();
60
61void ___NINDY_IO_WRAPPER( void )  /* never called */
62{
63   asm volatile ( "       .text" );
64   asm volatile ( "       .align 4" );
65   asm volatile ( "       .globl _NINDY_IO" );
66   asm volatile ( "_NINDY_IO:" );
67   asm volatile ( "        calls   0       /* call console routines */" );
68   asm volatile ( "        ret" );
69}
70
71/*  inbyte
72 *
73 *  This routine reads a character from the console using NINDY.
74 *
75 *  Input parameters: NONE
76 *
77 *  Output parameters:  NONE
78 *
79 *  Return values:
80 *    character read from UART
81 */
82
83char inbyte( void )
84{
85  char ch;
86
87  NINDY_IO( NINDY_INPUT, &ch );
88  return ch;
89}
90
91
92/*  outbyte
93 *
94 *  This routine transmits a character out the console using NINDY.
95 *
96 *  Input parameters:
97 *    ch  - character to be transmitted
98 *
99 *  Output parameters:  NONE
100 */
101
102void outbyte(
103  char ch
104)
105{
106  NINDY_IO( NINDY_OUTPUT, ch );
107}
108
109/*
110 *  Open entry point
111 */
112 
113rtems_device_driver console_open(
114  rtems_device_major_number major,
115  rtems_device_minor_number minor,
116  void                    * arg
117)
118{
119  return RTEMS_SUCCESSFUL;
120}
121 
122/*
123 *  Close entry point
124 */
125 
126rtems_device_driver console_close(
127  rtems_device_major_number major,
128  rtems_device_minor_number minor,
129  void                    * arg
130)
131{
132  return RTEMS_SUCCESSFUL;
133}
134 
135/*
136 * read bytes from the serial port. We only have stdin.
137 */
138 
139rtems_device_driver console_read(
140  rtems_device_major_number major,
141  rtems_device_minor_number minor,
142  void                    * arg
143)
144{
145  rtems_libio_rw_args_t *rw_args;
146  char *buffer;
147  int maximum;
148  int count = 0;
149 
150  rw_args = (rtems_libio_rw_args_t *) arg;
151 
152  buffer = rw_args->buffer;
153  maximum = rw_args->count;
154 
155  for (count = 0; count < maximum; count++) {
156    buffer[ count ] = inbyte();
157    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
158      buffer[ count++ ]  = '\n';
159      break;
160    }
161  }
162 
163  rw_args->bytes_moved = count;
164  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
165}
166 
167/*
168 * write bytes to the serial port. Stdout and stderr are the same.
169 */
170 
171rtems_device_driver console_write(
172  rtems_device_major_number major,
173  rtems_device_minor_number minor,
174  void                    * arg
175)
176{
177  int count;
178  int maximum;
179  rtems_libio_rw_args_t *rw_args;
180  char *buffer;
181 
182  rw_args = (rtems_libio_rw_args_t *) arg;
183 
184  buffer = rw_args->buffer;
185  maximum = rw_args->count;
186 
187  for (count = 0; count < maximum; count++) {
188    if ( buffer[ count ] == '\n') {
189      outbyte('\r');
190    }
191    outbyte( buffer[ count ] );
192  }
193
194  rw_args->bytes_moved = maximum;
195  return 0;
196}
197 
198/*
199 *  IO Control entry point
200 */
201 
202rtems_device_driver console_control(
203  rtems_device_major_number major,
204  rtems_device_minor_number minor,
205  void                    * arg
206)
207{
208  return RTEMS_SUCCESSFUL;
209}
210
Note: See TracBrowser for help on using the repository browser.