source: rtems/c/src/lib/libbsp/m68k/idp/console/console.c @ 6da91abb

4.115
Last change on this file since 6da91abb was 6da91abb, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 13, 2014 at 7:09:16 PM

m68k/idp: Fix warnings

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*
2 *  This file contains the Motorola IDP console IO package.
3 */
4
5/*
6 *  Written by Doug McBride, Colorado Space Grant College
7 *  Based off of the board support packages of RTEMS
8 *
9 *  Updated to RTEMS 3.2.0 by Joel Sherrill.
10 */
11
12#define MIDP_INIT
13
14#include <bsp.h>
15#include <rtems/libio.h>
16
17#include <rtems/ringbuf.h>
18
19Ring_buffer_t  Console_Buffer[ 2 ];
20
21rtems_isr C_Receive_ISR(rtems_vector_number vector);
22
23/*  console_initialize
24 *
25 *  This routine initializes the console IO driver.
26 */
27rtems_device_driver console_initialize(
28  rtems_device_major_number  major,
29  rtems_device_minor_number  minor,
30  void                      *arg
31)
32{
33  rtems_status_code status;
34
35  Ring_buffer_Initialize( &Console_Buffer[ 0 ] );
36  Ring_buffer_Initialize( &Console_Buffer[ 1 ] );
37
38  init_pit();
39
40  status = rtems_io_register_name(
41    "/dev/console",
42    major,
43    (rtems_device_minor_number) 0
44  );
45
46  if (status != RTEMS_SUCCESSFUL)
47    rtems_fatal_error_occurred(status);
48
49  status = rtems_io_register_name(
50    "/dev/tty00",
51    major,
52    (rtems_device_minor_number) 0
53  );
54
55  if (status != RTEMS_SUCCESSFUL)
56    rtems_fatal_error_occurred(status);
57
58  status = rtems_io_register_name(
59    "/dev/tty01",
60    major,
61    (rtems_device_minor_number) 1
62  );
63
64  if (status != RTEMS_SUCCESSFUL)
65    rtems_fatal_error_occurred(status);
66
67  return RTEMS_SUCCESSFUL;
68}
69
70/*  is_character_ready
71 *
72 *  This routine returns TRUE if a character is available.
73 */
74static bool is_character_ready(
75  char *ch,
76  int   port
77)
78{
79  if ( Ring_buffer_Is_empty( &Console_Buffer[ port ] ) )
80    return false;
81
82  Ring_buffer_Remove_character( &Console_Buffer[ port ], *ch );
83  return true;
84}
85
86/*  inbyte
87 *
88 *  This routine reads a character from the UART through a buffer.
89 */
90static char inbyte(
91  int port
92)
93{
94  char tmp_char;
95
96  /* If you come into this routine without checking is_character_ready() first
97     and you want nonblocking code, then it's your own fault */
98
99  while ( !is_character_ready( &tmp_char, port ) );
100
101  return tmp_char;
102}
103
104/*  outbyte
105 *
106 *  This routine transmits a character out the M68681.  It supports
107 *  XON/XOFF flow control.
108 */
109static void outbyte(
110  char ch,
111  int  port
112)
113{
114  switch ( port ) {
115    case 0:
116      transmit_char( ch );
117      break;
118    case 1:
119      transmit_char_portb( ch );
120      break;
121  }
122
123}
124
125/*
126 *  Open entry point
127 */
128rtems_device_driver console_open(
129  rtems_device_major_number major,
130  rtems_device_minor_number minor,
131  void                    * arg
132)
133{
134  return RTEMS_SUCCESSFUL;
135}
136
137/*
138 *  Close entry point
139 */
140rtems_device_driver console_close(
141  rtems_device_major_number major,
142  rtems_device_minor_number minor,
143  void                    * arg
144)
145{
146  return RTEMS_SUCCESSFUL;
147}
148
149/*
150 * read bytes from the serial port. We only have stdin.
151 */
152rtems_device_driver console_read(
153  rtems_device_major_number major,
154  rtems_device_minor_number minor,
155  void                    * arg
156)
157{
158  rtems_libio_rw_args_t *rw_args;
159  char *buffer;
160  int maximum;
161  int count = 0;
162
163  rw_args = (rtems_libio_rw_args_t *) arg;
164
165  buffer = rw_args->buffer;
166  maximum = rw_args->count;
167
168  if ( minor > 1 )
169    return RTEMS_INVALID_NUMBER;
170
171  for (count = 0; count < maximum; count++) {
172    buffer[ count ] = inbyte( minor );
173    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
174      buffer[ count++ ]  = '\n';
175      break;
176    }
177  }
178
179  rw_args->bytes_moved = count;
180  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
181}
182
183/*
184 * write bytes to the serial port. Stdout and stderr are the same.
185 */
186rtems_device_driver console_write(
187  rtems_device_major_number major,
188  rtems_device_minor_number minor,
189  void                    * arg
190)
191{
192  int count;
193  int maximum;
194  rtems_libio_rw_args_t *rw_args;
195  char *buffer;
196
197  rw_args = (rtems_libio_rw_args_t *) arg;
198
199  buffer = rw_args->buffer;
200  maximum = rw_args->count;
201
202  if ( minor > 1 )
203    return RTEMS_INVALID_NUMBER;
204
205  for (count = 0; count < maximum; count++) {
206    if ( buffer[ count ] == '\n') {
207      outbyte('\r', minor );
208    }
209    outbyte( buffer[ count ], minor  );
210  }
211
212  rw_args->bytes_moved = maximum;
213  return 0;
214}
215
216/*
217 *  IO Control entry point
218 */
219
220rtems_device_driver console_control(
221  rtems_device_major_number major,
222  rtems_device_minor_number minor,
223  void                    * arg
224)
225{
226  return RTEMS_SUCCESSFUL;
227}
Note: See TracBrowser for help on using the repository browser.