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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [no_cpu/] [no_bsp/] [console/] [console.c] - Blame information for rev 214

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-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: console.c,v 1.2 2001-09-27 12:00:26 chris Exp $
12
 */
13
 
14
#define NO_BSP_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
 
30
rtems_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
/*  is_character_ready
52
 *
53
 *  This routine returns TRUE if a character is available.
54
 *
55
 *  Input parameters: NONE
56
 *
57
 *  Output parameters:  NONE
58
 *
59
 *  Return values:
60
 */
61
 
62
rtems_boolean is_character_ready(
63
  char *ch
64
)
65
{
66
  *ch = '\0';   /* return NULL for no particular reason */
67
  return(TRUE);
68
}
69
 
70
/*  inbyte
71
 *
72
 *  This routine reads a character from the SOURCE.
73
 *
74
 *  Input parameters: NONE
75
 *
76
 *  Output parameters:  NONE
77
 *
78
 *  Return values:
79
 *    character read from SOURCE
80
 */
81
 
82
char inbyte( void )
83
{
84
  /*
85
   *  If polling, wait until a character is available.
86
   */
87
 
88
  return '\0';
89
}
90
 
91
/*  outbyte
92
 *
93
 *  This routine transmits a character out the SOURCE.  It may support
94
 *  XON/XOFF flow control.
95
 *
96
 *  Input parameters:
97
 *    ch  - character to be transmitted
98
 *
99
 *  Output parameters:  NONE
100
 */
101
 
102
void outbyte(
103
  char ch
104
)
105
{
106
  /*
107
   *  If polling, wait for the transmitter to be ready.
108
   *  Check for flow control requests and process.
109
   *  Then output the character.
110
   */
111
 
112
  /*
113
   *  Carriage Return/New line translation.
114
   */
115
 
116
  if ( ch == '\n' )
117
    outbyte( '\r' );
118
}
119
 
120
 
121
/*
122
 *  Open entry point
123
 */
124
 
125
rtems_device_driver console_open(
126
  rtems_device_major_number major,
127
  rtems_device_minor_number minor,
128
  void                    * arg
129
)
130
{
131
  return RTEMS_SUCCESSFUL;
132
}
133
 
134
/*
135
 *  Close entry point
136
 */
137
 
138
rtems_device_driver console_close(
139
  rtems_device_major_number major,
140
  rtems_device_minor_number minor,
141
  void                    * arg
142
)
143
{
144
  return RTEMS_SUCCESSFUL;
145
}
146
 
147
/*
148
 * read bytes from the serial port. We only have stdin.
149
 */
150
 
151
rtems_device_driver console_read(
152
  rtems_device_major_number major,
153
  rtems_device_minor_number minor,
154
  void                    * arg
155
)
156
{
157
  rtems_libio_rw_args_t *rw_args;
158
  char *buffer;
159
  int maximum;
160
  int count = 0;
161
 
162
  rw_args = (rtems_libio_rw_args_t *) arg;
163
 
164
  buffer = rw_args->buffer;
165
  maximum = rw_args->count;
166
 
167
  for (count = 0; count < maximum; count++) {
168
    buffer[ count ] = inbyte();
169
    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
170
      buffer[ count++ ]  = '\n';
171
      break;
172
    }
173
  }
174
 
175
  rw_args->bytes_moved = count;
176
  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
177
}
178
 
179
/*
180
 * write bytes to the serial port. Stdout and stderr are the same.
181
 */
182
 
183
rtems_device_driver console_write(
184
  rtems_device_major_number major,
185
  rtems_device_minor_number minor,
186
  void                    * arg
187
)
188
{
189
  int count;
190
  int maximum;
191
  rtems_libio_rw_args_t *rw_args;
192
  char *buffer;
193
 
194
  rw_args = (rtems_libio_rw_args_t *) arg;
195
 
196
  buffer = rw_args->buffer;
197
  maximum = rw_args->count;
198
 
199
  for (count = 0; count < maximum; count++) {
200
    if ( buffer[ count ] == '\n') {
201
      outbyte('\r');
202
    }
203
    outbyte( buffer[ count ] );
204
  }
205
 
206
  rw_args->bytes_moved = maximum;
207
  return 0;
208
}
209
 
210
/*
211
 *  IO Control entry point
212
 */
213
 
214
rtems_device_driver console_control(
215
  rtems_device_major_number major,
216
  rtems_device_minor_number minor,
217
  void                    * arg
218
)
219
{
220
  return RTEMS_SUCCESSFUL;
221
}

powered by: WebSVN 2.1.0

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