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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [m68k/] [idp/] [console/] [console.c] - Blame information for rev 593

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

Line No. Rev Author Line
1 30 unneback
/*
2
 *  This file contains the Motorola IDP console IO package.
3
 *
4
 *  Written by Doug McBride, Colorado Space Grant College
5
 *  Based off of the board support packages of RTEMS
6
 *
7
 *  Updated to RTEMS 3.2.0 by Joel Sherrill.
8
 *
9
 *  $Id: console.c,v 1.2 2001-09-27 12:00:09 chris Exp $
10
 */
11
 
12
#define MIDP_INIT
13
 
14
#include <bsp.h>
15
#include <rtems/libio.h>
16
 
17
#include <ringbuf.h>
18
 
19
Ring_buffer_t  Console_Buffer[ 2 ];
20
 
21
rtems_isr C_Receive_ISR(rtems_vector_number vector);
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
 
34
rtems_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
  Ring_buffer_Initialize( &Console_Buffer[ 0 ] );
43
  Ring_buffer_Initialize( &Console_Buffer[ 1 ] );
44
 
45
  init_pit();
46
 
47
  status = rtems_io_register_name(
48
    "/dev/console",
49
    major,
50
    (rtems_device_minor_number) 0
51
  );
52
 
53
  if (status != RTEMS_SUCCESSFUL)
54
    rtems_fatal_error_occurred(status);
55
 
56
  status = rtems_io_register_name(
57
    "/dev/tty00",
58
    major,
59
    (rtems_device_minor_number) 0
60
  );
61
 
62
  if (status != RTEMS_SUCCESSFUL)
63
    rtems_fatal_error_occurred(status);
64
 
65
  status = rtems_io_register_name(
66
    "/dev/tty01",
67
    major,
68
    (rtems_device_minor_number) 1
69
  );
70
 
71
  if (status != RTEMS_SUCCESSFUL)
72
    rtems_fatal_error_occurred(status);
73
 
74
  return RTEMS_SUCCESSFUL;
75
}
76
 
77
 
78
/*  is_character_ready
79
 *
80
 *  This routine returns TRUE if a character is available.
81
 *
82
 *  Input parameters: NONE
83
 *
84
 *  Output parameters:  NONE
85
 *
86
 *  Return values:
87
 */
88
 
89
rtems_boolean is_character_ready(
90
  char *ch,
91
  int   port
92
)
93
{
94
  if ( Ring_buffer_Is_empty( &Console_Buffer[ port ] ) )
95
    return FALSE;
96
 
97
  Ring_buffer_Remove_character( &Console_Buffer[ port ], *ch );
98
  return TRUE;
99
}
100
 
101
/*  quick_char_check
102
 *
103
 *  This routine returns TRUE if a character is available.
104
 *  It is different from above because it does not disturb the ring buffer
105
 *
106
 *  Input parameters: NONE
107
 *
108
 *  Output parameters:  NONE
109
 *
110
 *  Return values:
111
 */
112
 
113
rtems_boolean quick_char_check(
114
  int   port
115
)
116
{
117
  if ( Ring_buffer_Is_empty( &Console_Buffer[ port ] ) )
118
    return FALSE;
119
 
120
  return TRUE;
121
}
122
 
123
/*  inbyte
124
 *
125
 *  This routine reads a character from the UART through a buffer.
126
 *
127
 *  Input parameters: NONE
128
 *
129
 *  Output parameters:  NONE
130
 *
131
 *  Return values:
132
 *    character read from UART
133
 */
134
 
135
char inbyte(
136
  int port
137
)
138
{
139
  unsigned char tmp_char;
140
 
141
  /* If you come into this routine without checking is_character_ready() first
142
     and you want nonblocking code, then it's your own fault */
143
 
144
  while ( !is_character_ready( &tmp_char, port ) );
145
 
146
  return tmp_char;
147
}
148
 
149
 
150
/*  outbyte
151
 *
152
 *  This routine transmits a character out the M68681.  It supports
153
 *  XON/XOFF flow control.
154
 *
155
 *  Input parameters:
156
 *    ch  - character to be transmitted
157
 *
158
 *  Output parameters:  NONE
159
 */
160
 
161
void outbyte(
162
  char ch,
163
  int  port
164
)
165
{
166
  switch ( port ) {
167
    case 0:
168
      transmit_char( ch );
169
      break;
170
    case 1:
171
      transmit_char_portb( ch );
172
      break;
173
  }
174
 
175
}
176
 
177
/*
178
 *  Open entry point
179
 */
180
 
181
rtems_device_driver console_open(
182
  rtems_device_major_number major,
183
  rtems_device_minor_number minor,
184
  void                    * arg
185
)
186
{
187
  return RTEMS_SUCCESSFUL;
188
}
189
 
190
/*
191
 *  Close entry point
192
 */
193
 
194
rtems_device_driver console_close(
195
  rtems_device_major_number major,
196
  rtems_device_minor_number minor,
197
  void                    * arg
198
)
199
{
200
  return RTEMS_SUCCESSFUL;
201
}
202
 
203
/*
204
 * read bytes from the serial port. We only have stdin.
205
 */
206
 
207
rtems_device_driver console_read(
208
  rtems_device_major_number major,
209
  rtems_device_minor_number minor,
210
  void                    * arg
211
)
212
{
213
  rtems_libio_rw_args_t *rw_args;
214
  char *buffer;
215
  int maximum;
216
  int count = 0;
217
 
218
  rw_args = (rtems_libio_rw_args_t *) arg;
219
 
220
  buffer = rw_args->buffer;
221
  maximum = rw_args->count;
222
 
223
  if ( minor > 1 )
224
    return RTEMS_INVALID_NUMBER;
225
 
226
  for (count = 0; count < maximum; count++) {
227
    buffer[ count ] = inbyte( minor );
228
    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
229
      buffer[ count++ ]  = '\n';
230
      break;
231
    }
232
  }
233
 
234
  rw_args->bytes_moved = count;
235
  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
236
}
237
 
238
/*
239
 * write bytes to the serial port. Stdout and stderr are the same.
240
 */
241
 
242
rtems_device_driver console_write(
243
  rtems_device_major_number major,
244
  rtems_device_minor_number minor,
245
  void                    * arg
246
)
247
{
248
  int count;
249
  int maximum;
250
  rtems_libio_rw_args_t *rw_args;
251
  char *buffer;
252
 
253
  rw_args = (rtems_libio_rw_args_t *) arg;
254
 
255
  buffer = rw_args->buffer;
256
  maximum = rw_args->count;
257
 
258
  if ( minor > 1 )
259
    return RTEMS_INVALID_NUMBER;
260
 
261
  for (count = 0; count < maximum; count++) {
262
    if ( buffer[ count ] == '\n') {
263
      outbyte('\r', minor );
264
    }
265
    outbyte( buffer[ count ], minor  );
266
  }
267
 
268
  rw_args->bytes_moved = maximum;
269
  return 0;
270
}
271
 
272
/*
273
 *  IO Control entry point
274
 */
275
 
276
rtems_device_driver console_control(
277
  rtems_device_major_number major,
278
  rtems_device_minor_number minor,
279
  void                    * arg
280
)
281
{
282
  return RTEMS_SUCCESSFUL;
283
}

powered by: WebSVN 2.1.0

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