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

4.104.114.84.95
Last change on this file since a9a27b5 was a9a27b5, checked in by Ralf Corsepius <ralf.corsepius@…>, on 04/01/04 at 10:10:06

2004-04-01 Ralf Corsepius <ralf_corsepius@…>

  • include/bsp.h: Include <rtems/clockdrv.h> instead of <clockdrv.h>.
  • include/bsp.h: Include <rtems/console.h> instead of <console.h>.
  • include/bsp.h: Include <rtems/iosupp.h> instead of <iosupp.h>.
  • console/console.c: Include <rtems/ringbuf.h> instead of <ringbuf.h>.
  • Property mode set to 100644
File size: 5.1 KB
RevLine 
[ac7d5ef0]1/*
2 *  This file contains the MVME162 console IO package.
3 *
[08311cc3]4 *  COPYRIGHT (c) 1989-1999.
[ac7d5ef0]5 *  On-Line Applications Research Corporation (OAR).
6 *
[98e4ebf5]7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
[f4fe0092]9 *  http://www.rtems.com/license/LICENSE.
[ac7d5ef0]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
[3a4ae6c]23#include <bsp.h>
24#include <rtems/libio.h>
[a9a27b5]25#include <rtems/ringbuf.h>
[ac7d5ef0]26
[98100d2]27Ring_buffer_t  Console_Buffer[2];
[c6fb8e90]28
29/*
30 *  Interrupt handler for receiver interrupts
[ac7d5ef0]31 */
32
[c6fb8e90]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   
[98100d2]45  Ring_buffer_Add_character(&Console_Buffer[port], ZREADD(port));
[c6fb8e90]46 
47  if (ZREAD(port, 1) & 0x70) {    /* check error stat */
48    ZWRITE0(port, 0x30);          /* reset error */
49  }
50}
51
[ac7d5ef0]52rtems_device_driver console_initialize(
53  rtems_device_major_number  major,
54  rtems_device_minor_number  minor,
[3a4ae6c]55  void                      *arg
[ac7d5ef0]56)
57{
[c6fb8e90]58  int     i;
[3a4ae6c]59  rtems_status_code status;
[c6fb8e90]60 
61  /*
62   * Initialise receiver interrupts on both ports
63   */
64
65  for (i = 0; i <= 1; i++) {
[98100d2]66    Ring_buffer_Initialize( &Console_Buffer[i] );
[c6fb8e90]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
[3a4ae6c]79  status = rtems_io_register_name(
80    "/dev/console",
81    major,
[da646dd]82    (rtems_device_minor_number) 1
[3a4ae6c]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,
[da646dd]100    (rtems_device_minor_number) 1
[3a4ae6c]101  );
102 
103  if (status != RTEMS_SUCCESSFUL)
104    rtems_fatal_error_occurred(status);
105 
106  return RTEMS_SUCCESSFUL;
[ac7d5ef0]107}
108
[c6fb8e90]109/*
110 *   Non-blocking char input
[ac7d5ef0]111 */
112
[c6fb8e90]113rtems_boolean char_ready(int port, char *ch)
[ac7d5ef0]114{
[98100d2]115  if ( Ring_buffer_Is_empty( &Console_Buffer[port] ) )
[c6fb8e90]116    return FALSE;
[ac7d5ef0]117
[98100d2]118  Ring_buffer_Remove_character( &Console_Buffer[port], *ch );
[c6fb8e90]119 
120  return TRUE;
[ac7d5ef0]121}
122
[c6fb8e90]123/*
124 *   Block on char input
[ac7d5ef0]125 */
126
[3a4ae6c]127char inbyte(int port)
[ac7d5ef0]128{
[c6fb8e90]129  unsigned char tmp_char;
130 
131  while ( !char_ready(port, &tmp_char) );
132  return tmp_char;
[ac7d5ef0]133}
134
[c6fb8e90]135/* 
136 *   This routine transmits a character out the SCC.  It no longer supports
137 *   XON/XOFF flow control.
[ac7d5ef0]138 */
139
[da646dd]140void outbyte(char ch, int port)
[ac7d5ef0]141{
[c6fb8e90]142  while (1) {
143    if (ZREAD0(port) & TX_BUFFER_EMPTY) break;
[ac7d5ef0]144  }
[c6fb8e90]145  ZWRITED(port, ch);
[ac7d5ef0]146}
147
148/*
[3a4ae6c]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.
[ac7d5ef0]176 */
177
[3a4ae6c]178rtems_device_driver console_read(
179  rtems_device_major_number major,
180  rtems_device_minor_number minor,
181  void                    * arg
182)
[ac7d5ef0]183{
[3a4ae6c]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;
[c6fb8e90]190
[3a4ae6c]191  buffer = rw_args->buffer;
192  maximum = rw_args->count;
[ac7d5ef0]193
[3a4ae6c]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';
[ac7d5ef0]201      break;
202    }
203  }
[3a4ae6c]204
205  rw_args->bytes_moved = count;
206  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
[ac7d5ef0]207}
208
209/*
[3a4ae6c]210 * write bytes to the serial port. Stdout and stderr are the same.
[ac7d5ef0]211 */
212
[3a4ae6c]213rtems_device_driver console_write(
214  rtems_device_major_number major,
215  rtems_device_minor_number minor,
216  void                    * arg
217)
[ac7d5ef0]218{
[3a4ae6c]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 );
[ac7d5ef0]235    }
[3a4ae6c]236    outbyte( buffer[ count ], minor  );
[ac7d5ef0]237  }
[3652ad35]238
239  rw_args->bytes_moved = maximum;
240  return 0;
[3a4ae6c]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;
[ac7d5ef0]254}
Note: See TracBrowser for help on using the repository browser.