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

4.104.114.84.95
Last change on this file since 0074691 was 0074691, checked in by Joel Sherrill <joel.sherrill@…>, on Jul 31, 1997 at 10:13:29 PM

Merged very large and much appreciated patch from Chris Johns
<cjohns@…>. This patch includes the ods68302 bsp,
the RTEMS++ class library, and the rtems++ test.

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
2 * Initialize the MC68302 SCC2 for console IO board support 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 GEN68302_INIT
16
17#include <debugport.h>
18#include <bsp.h>
19#include <rtems/libio.h>
20
21/*  console_initialize
22 *
23 *  This routine initializes the console IO driver.
24 *
25 *  Input parameters: NONE
26 *
27 *  Output parameters:  NONE
28 *
29 *  Return values:
30 */
31
32rtems_device_driver console_initialize(
33  rtems_device_major_number  major,
34  rtems_device_minor_number  minor,
35  void                      *arg
36)
37{
38  rtems_status_code status;
39
40/*  debug_port_initialise(); */
41
42  status = rtems_io_register_name(
43    "/dev/console",
44    major,
45    (rtems_device_minor_number) 0
46  );
47 
48  if (status != RTEMS_SUCCESSFUL)
49    rtems_fatal_error_occurred(status);
50 
51  return RTEMS_SUCCESSFUL;
52
53}
54
55/*  is_character_ready
56 *
57 *  Check to see if a character is available on the MC68302's SCC2.  If so,
58 *  then return a TRUE (along with the character).  Otherwise return FALSE.
59 *
60 *  Input parameters:   pointer to location in which to return character
61 *
62 *  Output parameters:  character (if available)
63 *
64 *  Return values:      TRUE - character available
65 *                      FALSE - no character available
66 */
67
68rtems_boolean is_character_ready(
69  char *ch                              /* -> character  */
70)
71{
72  if (debug_port_status(0))
73  {
74    ch = debug_port_in();
75    return TRUE;
76  }
77  return FALSE;
78}
79
80
81/*  inbyte
82 *
83 *  Receive a character from the MC68302's SCC2.
84 *
85 *  Input parameters:   NONE
86 *
87 *  Output parameters:  NONE
88 *
89 *  Return values:      character read
90 */
91
92char inbyte( void )
93{
94  char ch;
95 
96  while (!is_character_ready(&ch));
97 
98  return ch;
99}
100
101
102/*  outbyte
103 *
104 *  Transmit a character out on the MC68302's SCC2.
105 *  It may support XON/XOFF flow control.
106 *
107 *  Input parameters:
108 *    ch  - character to be transmitted
109 *
110 *  Output parameters:  NONE
111 */
112
113void outbyte(
114  char ch
115)
116{
117  debug_port_out(ch);
118}
119
120/*
121 *  Open entry point
122 */
123
124rtems_device_driver console_open(
125  rtems_device_major_number major,
126  rtems_device_minor_number minor,
127  void                    * arg
128)
129{
130  return RTEMS_SUCCESSFUL;
131}
132 
133/*
134 *  Close entry point
135 */
136
137rtems_device_driver console_close(
138  rtems_device_major_number major,
139  rtems_device_minor_number minor,
140  void                    * arg
141)
142{
143  return RTEMS_SUCCESSFUL;
144}
145
146/*
147 * read bytes from the serial port. We only have stdin.
148 */
149
150rtems_device_driver console_read(
151  rtems_device_major_number major,
152  rtems_device_minor_number minor,
153  void                    * arg
154)
155{
156  rtems_libio_rw_args_t *rw_args;
157  char *buffer;
158  int maximum;
159  int count = 0;
160 
161  rw_args = (rtems_libio_rw_args_t *) arg;
162
163  buffer = rw_args->buffer;
164  maximum = rw_args->count;
165
166  for (count = 0; count < maximum; count++) {
167    buffer[ count ] = inbyte();
168    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
169      buffer[ count++ ]  = '\n';
170      buffer[ count ]  = 0;
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
183rtems_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
214rtems_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}
Note: See TracBrowser for help on using the repository browser.