source: rtems/c/src/lib/libbsp/m68k/mvme162/console/console.c @ e4c07444

4.104.114.84.95
Last change on this file since e4c07444 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 17, 1999 at 5:51:34 PM

Updated copyright notice.

  • Property mode set to 100644
File size: 5.1 KB
Line 
1/*
2 *  This file contains the MVME162 console IO 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.OARcorp.com/rtems/license.html.
10 *
11 *  Modifications of respective RTEMS file: COPYRIGHT (c) 1994.
12 *  EISCAT Scientific Association. M.Savitski
13 *
14 *  This material is a part of the MVME162 Board Support Package
15 *  for the RTEMS executive. Its licensing policies are those of the
16 *  RTEMS above.
17 *
18 *  $Id$
19 */
20
21#define M162_INIT
22
23#include <bsp.h>
24#include <rtems/libio.h>
25#include <ringbuf.h>
26
27Ring_buffer_t  Console_Buffer[2];
28
29/*
30 *  Interrupt handler for receiver interrupts
31 */
32
33rtems_isr C_Receive_ISR(rtems_vector_number vector)
34{
35  register int    ipend, port;
36
37  ZWRITE0(1, 0x38);     /* reset highest IUS */
38
39  ipend = ZREAD(1, 3);  /* read int pending from A side */
40
41  if      (ipend == 0x04) port = 0;   /* channel B intr pending */
42  else if (ipend == 0x20) port = 1;   /* channel A intr pending */
43  else return;
44   
45  Ring_buffer_Add_character(&Console_Buffer[port], ZREADD(port));
46 
47  if (ZREAD(port, 1) & 0x70) {    /* check error stat */
48    ZWRITE0(port, 0x30);          /* reset error */
49  }
50}
51
52rtems_device_driver console_initialize(
53  rtems_device_major_number  major,
54  rtems_device_minor_number  minor,
55  void                      *arg
56)
57{
58  int     i;
59  rtems_status_code status;
60 
61  /*
62   * Initialise receiver interrupts on both ports
63   */
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 */
112
113rtems_boolean char_ready(int port, char *ch)
114{
115  if ( Ring_buffer_Is_empty( &Console_Buffer[port] ) )
116    return FALSE;
117
118  Ring_buffer_Remove_character( &Console_Buffer[port], *ch );
119 
120  return TRUE;
121}
122
123/*
124 *   Block on char input
125 */
126
127char inbyte(int port)
128{
129  unsigned char tmp_char;
130 
131  while ( !char_ready(port, &tmp_char) );
132  return tmp_char;
133}
134
135/* 
136 *   This routine transmits a character out the SCC.  It no longer supports
137 *   XON/XOFF flow control.
138 */
139
140void outbyte(char ch, int port)
141{
142  while (1) {
143    if (ZREAD0(port) & TX_BUFFER_EMPTY) break;
144  }
145  ZWRITED(port, ch);
146}
147
148/*
149 *  Open entry point
150 */
151
152rtems_device_driver console_open(
153  rtems_device_major_number major,
154  rtems_device_minor_number minor,
155  void                    * arg
156)
157{
158  return RTEMS_SUCCESSFUL;
159}
160 
161/*
162 *  Close entry point
163 */
164
165rtems_device_driver console_close(
166  rtems_device_major_number major,
167  rtems_device_minor_number minor,
168  void                    * arg
169)
170{
171  return RTEMS_SUCCESSFUL;
172}
173
174/*
175 * read bytes from the serial port. We only have stdin.
176 */
177
178rtems_device_driver console_read(
179  rtems_device_major_number major,
180  rtems_device_minor_number minor,
181  void                    * arg
182)
183{
184  rtems_libio_rw_args_t *rw_args;
185  char *buffer;
186  int maximum;
187  int count = 0;
188 
189  rw_args = (rtems_libio_rw_args_t *) arg;
190
191  buffer = rw_args->buffer;
192  maximum = rw_args->count;
193
194  if ( minor > 1 )
195    return RTEMS_INVALID_NUMBER;
196
197  for (count = 0; count < maximum; count++) {
198    buffer[ count ] = inbyte( minor );
199    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
200      buffer[ count++ ]  = '\n';
201      break;
202    }
203  }
204
205  rw_args->bytes_moved = count;
206  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
207}
208
209/*
210 * write bytes to the serial port. Stdout and stderr are the same.
211 */
212
213rtems_device_driver console_write(
214  rtems_device_major_number major,
215  rtems_device_minor_number minor,
216  void                    * arg
217)
218{
219  int count;
220  int maximum;
221  rtems_libio_rw_args_t *rw_args;
222  char *buffer;
223
224  rw_args = (rtems_libio_rw_args_t *) arg;
225
226  buffer = rw_args->buffer;
227  maximum = rw_args->count;
228
229  if ( minor > 1 )
230    return RTEMS_INVALID_NUMBER;
231
232  for (count = 0; count < maximum; count++) {
233    if ( buffer[ count ] == '\n') {
234      outbyte('\r', minor );
235    }
236    outbyte( buffer[ count ], minor  );
237  }
238
239  rw_args->bytes_moved = maximum;
240  return 0;
241}
242
243/*
244 *  IO Control entry point
245 */
246
247rtems_device_driver console_control(
248  rtems_device_major_number major,
249  rtems_device_minor_number minor,
250  void                    * arg
251)
252{
253  return RTEMS_SUCCESSFUL;
254}
Note: See TracBrowser for help on using the repository browser.