source: rtems/c/src/lib/libbsp/i960/cvme961/console/console.c @ 8f35817

4.104.114.84.95
Last change on this file since 8f35817 was 8f35817, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 15, 1997 at 6:52:26 PM

eliminated potential for overfilling buffer on read

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