source: rtems/c/src/lib/libbsp/m68k/ods68302/console/console.c @ 907bf4b8

4.104.114.95
Last change on this file since 907bf4b8 was 907bf4b8, checked in by Ralf Corsepius <ralf.corsepius@…>, on 09/05/08 at 08:46:27

Convert to "bool".

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * Initialize the MC68302 SCC2 for console IO board support 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.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#define GEN68302_INIT
15
16#include <debugport.h>
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/*  debug_port_initialise(); */
40
41  status = rtems_io_register_name(
42    "/dev/console",
43    major,
44    (rtems_device_minor_number) 0
45  );
46
47  if (status != RTEMS_SUCCESSFUL)
48    rtems_fatal_error_occurred(status);
49
50  return RTEMS_SUCCESSFUL;
51
52}
53
54/*  is_character_ready
55 *
56 *  Check to see if a character is available on the MC68302's SCC2.  If so,
57 *  then return a TRUE (along with the character).  Otherwise return FALSE.
58 *
59 *  Input parameters:   pointer to location in which to return character
60 *
61 *  Output parameters:  character (if available)
62 *
63 *  Return values:      TRUE - character available
64 *                      FALSE - no character available
65 */
66
67bool is_character_ready(
68  char *ch                              /* -> character  */
69)
70{
71  if (debug_port_status(0))
72  {
73    *ch = debug_port_in();
74    return true;
75  }
76  return false;
77}
78
79/*  inbyte
80 *
81 *  Receive a character from the MC68302's SCC2.
82 *
83 *  Input parameters:   NONE
84 *
85 *  Output parameters:  NONE
86 *
87 *  Return values:      character read
88 */
89
90char inbyte( void )
91{
92  char ch;
93
94  while (!is_character_ready(&ch));
95
96  return ch;
97}
98
99/*  outbyte
100 *
101 *  Transmit a character out on the MC68302's SCC2.
102 *  It may support XON/XOFF flow control.
103 *
104 *  Input parameters:
105 *    ch  - character to be transmitted
106 *
107 *  Output parameters:  NONE
108 */
109
110void outbyte(
111  char ch
112)
113{
114  debug_port_out(ch);
115}
116
117/*
118 *  Open entry point
119 */
120
121rtems_device_driver console_open(
122  rtems_device_major_number major,
123  rtems_device_minor_number minor,
124  void                    * arg
125)
126{
127  return RTEMS_SUCCESSFUL;
128}
129
130/*
131 *  Close entry point
132 */
133
134rtems_device_driver console_close(
135  rtems_device_major_number major,
136  rtems_device_minor_number minor,
137  void                    * arg
138)
139{
140  return RTEMS_SUCCESSFUL;
141}
142
143/*
144 * read bytes from the serial port. We only have stdin.
145 */
146
147rtems_device_driver console_read(
148  rtems_device_major_number major,
149  rtems_device_minor_number minor,
150  void                    * arg
151)
152{
153  rtems_libio_rw_args_t *rw_args;
154  char *buffer;
155  int maximum;
156  int count = 0;
157
158  rw_args = (rtems_libio_rw_args_t *) arg;
159
160  buffer = rw_args->buffer;
161  maximum = rw_args->count;
162
163  for (count = 0; count < maximum; count++) {
164    buffer[ count ] = inbyte();
165    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
166      buffer[ count++ ]  = '\n';
167      break;
168    }
169  }
170
171  rw_args->bytes_moved = count;
172  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
173}
174
175/*
176 * write bytes to the serial port. Stdout and stderr are the same.
177 */
178
179rtems_device_driver console_write(
180  rtems_device_major_number major,
181  rtems_device_minor_number minor,
182  void                    * arg
183)
184{
185  int count;
186  int maximum;
187  rtems_libio_rw_args_t *rw_args;
188  char *buffer;
189
190  rw_args = (rtems_libio_rw_args_t *) arg;
191
192  buffer = rw_args->buffer;
193  maximum = rw_args->count;
194
195  for (count = 0; count < maximum; count++) {
196    if ( buffer[ count ] == '\n') {
197      outbyte('\r');
198    }
199    outbyte( buffer[ count ] );
200  }
201
202  rw_args->bytes_moved = maximum;
203  return 0;
204}
205
206/*
207 *  IO Control entry point
208 */
209
210rtems_device_driver console_control(
211  rtems_device_major_number major,
212  rtems_device_minor_number minor,
213  void                    * arg
214)
215{
216  return RTEMS_SUCCESSFUL;
217}
Note: See TracBrowser for help on using the repository browser.