source: rtems/bsps/m68k/mvme162/console/console.c @ d7d66d7

5
Last change on this file since d7d66d7 was d7d66d7, checked in by Sebastian Huber <sebastian.huber@…>, on 04/19/18 at 04:28:01

bsps: Move console drivers to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 6.0 KB
Line 
1/*
2 *  This file contains the MVME162 console IO package.
3 */
4
5/*
6 *  COPYRIGHT (c) 1989-2013.
7 *  On-Line Applications Research Corporation (OAR).
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.rtems.org/license/LICENSE.
12 *
13 *  Modifications of respective RTEMS file: COPYRIGHT (c) 1994.
14 *  EISCAT Scientific Association. M.Savitski
15 *
16 *  This material is a part of the MVME162 Board Support Package
17 *  for the RTEMS executive. Its licensing policies are those of the
18 *  RTEMS above.
19 */
20
21#define M162_INIT
22
23#include <rtems/bspIo.h>
24#include <rtems/console.h>
25#include <rtems/libio.h>
26#include <rtems/ringbuf.h>
27#include <bsp.h>
28
29Ring_buffer_t  Console_Buffer[2];
30
31/*
32 *  Interrupt handler for receiver interrupts
33 */
34static rtems_isr C_Receive_ISR(rtems_vector_number vector)
35{
36  register int    ipend, port;
37
38  ZWRITE0(1, 0x38);     /* reset highest IUS */
39
40  ipend = ZREAD(1, 3);  /* read int pending from A side */
41
42  if      (ipend == 0x04) port = 0;   /* channel B intr pending */
43  else if (ipend == 0x20) port = 1;   /* channel A intr pending */
44  else return;
45
46  Ring_buffer_Add_character(&Console_Buffer[port], ZREADD(port));
47
48  if (ZREAD(port, 1) & 0x70) {    /* check error stat */
49    ZWRITE0(port, 0x30);          /* reset error */
50  }
51}
52
53rtems_device_driver console_initialize(
54  rtems_device_major_number  major,
55  rtems_device_minor_number  minor,
56  void                      *arg
57)
58{
59  int     i;
60  rtems_status_code status;
61
62  /*
63   * Initialise receiver interrupts on both ports
64   */
65  for (i = 0; i <= 1; i++) {
66    Ring_buffer_Initialize( &Console_Buffer[i] );
67    ZWRITE(i, 2, SCC_VECTOR);
68    ZWRITE(i, 10, 0);
69    ZWRITE(i, 1, 0x10);     /* int on all Rx chars or special condition */
70    ZWRITE(i, 9, 8);        /* master interrupt enable */
71  }
72
73  set_vector(C_Receive_ISR, SCC_VECTOR, 1); /* install ISR for ports A and B */
74
75  mcchip->vector_base = 0;
76  mcchip->gen_control = 2;        /* MIEN */
77  mcchip->SCC_int_ctl = 0x13;     /* SCC IEN, IPL3 */
78
79  status = rtems_io_register_name(
80    "/dev/console",
81    major,
82    (rtems_device_minor_number) 1
83  );
84
85  if (status != RTEMS_SUCCESSFUL)
86    rtems_fatal_error_occurred(status);
87
88  status = rtems_io_register_name(
89    "/dev/tty00",
90    major,
91    (rtems_device_minor_number) 0
92  );
93
94  if (status != RTEMS_SUCCESSFUL)
95    rtems_fatal_error_occurred(status);
96
97  status = rtems_io_register_name(
98    "/dev/tty01",
99    major,
100    (rtems_device_minor_number) 1
101  );
102
103  if (status != RTEMS_SUCCESSFUL)
104    rtems_fatal_error_occurred(status);
105
106  return RTEMS_SUCCESSFUL;
107}
108
109/*
110 *   Non-blocking char input
111 */
112bool char_ready(int port, char *ch)
113{
114  if ( Ring_buffer_Is_empty( &Console_Buffer[port] ) )
115    return false;
116
117  Ring_buffer_Remove_character( &Console_Buffer[port], *ch );
118
119  return true;
120}
121
122/*
123 *   Block on char input
124 */
125static char inbyte(int port)
126{
127  char tmp_char;
128
129  while ( !char_ready(port, &tmp_char) );
130  return tmp_char;
131}
132
133/*
134 *   This routine transmits a character out the SCC.  It no longer supports
135 *   XON/XOFF flow control.
136 */
137static void outbyte(char ch, int port)
138{
139  while (1) {
140    if (ZREAD0(port) & TX_BUFFER_EMPTY) break;
141  }
142  ZWRITED(port, ch);
143}
144
145/*
146 *  Open entry point
147 */
148rtems_device_driver console_open(
149  rtems_device_major_number major,
150  rtems_device_minor_number minor,
151  void                    * arg
152)
153{
154  return RTEMS_SUCCESSFUL;
155}
156
157/*
158 *  Close entry point
159 */
160rtems_device_driver console_close(
161  rtems_device_major_number major,
162  rtems_device_minor_number minor,
163  void                    * arg
164)
165{
166  return RTEMS_SUCCESSFUL;
167}
168
169/*
170 * read bytes from the serial port. We only have stdin.
171 */
172rtems_device_driver console_read(
173  rtems_device_major_number major,
174  rtems_device_minor_number minor,
175  void                    * arg
176)
177{
178  rtems_libio_rw_args_t *rw_args;
179  char *buffer;
180  int maximum;
181  int count = 0;
182
183  rw_args = (rtems_libio_rw_args_t *) arg;
184
185  buffer = rw_args->buffer;
186  maximum = rw_args->count;
187
188  if ( minor > 1 )
189    return RTEMS_INVALID_NUMBER;
190
191  for (count = 0; count < maximum; count++) {
192    buffer[ count ] = inbyte( minor );
193    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
194      buffer[ count++ ]  = '\n';
195      break;
196    }
197  }
198
199  rw_args->bytes_moved = count;
200  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
201}
202
203/*
204 * write bytes to the serial port. Stdout and stderr are the same.
205 */
206rtems_device_driver console_write(
207  rtems_device_major_number major,
208  rtems_device_minor_number minor,
209  void                    * arg
210)
211{
212  int count;
213  int maximum;
214  rtems_libio_rw_args_t *rw_args;
215  char *buffer;
216
217  rw_args = (rtems_libio_rw_args_t *) arg;
218
219  buffer = rw_args->buffer;
220  maximum = rw_args->count;
221
222  if ( minor > 1 )
223    return RTEMS_INVALID_NUMBER;
224
225  for (count = 0; count < maximum; count++) {
226    if ( buffer[ count ] == '\n') {
227      outbyte('\r', minor );
228    }
229    outbyte( buffer[ count ], minor  );
230  }
231
232  rw_args->bytes_moved = maximum;
233  return 0;
234}
235
236/*
237 *  IO Control entry point
238 */
239rtems_device_driver console_control(
240  rtems_device_major_number major,
241  rtems_device_minor_number minor,
242  void                    * arg
243)
244{
245  return RTEMS_SUCCESSFUL;
246}
247
248/*
249 *  _162Bug_output_char
250 *
251 *  Output a single character using the 162Bug functions.  The character
252 *  will be written to the default output port.
253 */
254static void _162Bug_output_char( char c )
255{
256  asm volatile( "moveb  %0, -(%%sp)\n\t"   /* char to output */
257                "trap   #15\n\t"           /* Trap to 162Bug */
258                ".short 0x20"              /* Code for .OUTCHR */
259    :: "d" (c) );
260}
261
262/*
263 *  _BSP_output_char
264 *
265 *  printk() function prototyped in bspIo.h. Does not use termios.
266 *
267 *  If we have initialized the console device then use it, otherwise
268 *  use the 162Bug routines to send it to the default output port.
269 */
270static void _BSP_output_char(char c)
271{
272  _162Bug_output_char(c);
273}
274
275/* Printk function */
276BSP_output_char_function_type           BSP_output_char = _BSP_output_char;
277BSP_polling_getchar_function_type       BSP_poll_char = NULL;
Note: See TracBrowser for help on using the repository browser.