OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [i960/] [rxgen960/] [console/] [console.c] - Blame information for rev 30

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
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: console.c,v 1.2 2001-09-27 11:59:58 chris Exp $
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" XXX JRS */
25
 
26
#ifndef lint
27
static 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
 
41
rtems_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
 
77
rtems_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
 
97
char 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
 
116
void 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
 
135
rtems_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
 
148
rtems_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
 
161
rtems_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
 
204
rtems_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
 
235
rtems_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
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.