source: rtems/c/src/lib/libbsp/m68k/dmv152/console/console.c @ f05b2ac

4.104.114.84.95
Last change on this file since f05b2ac was f05b2ac, checked in by Ralf Corsepius <ralf.corsepius@…>, on 04/21/04 at 16:01:48

Remove duplicate white lines.

  • Property mode set to 100644
File size: 5.0 KB
Line 
1/*
2 *  This file contains the TTY driver for the serial ports on the DMV152.
3 *  The serial ports use a Zilog Z8530.
4 *
5 *  NOTE: This driver uses the termios pseudo driver.
6 *        This driver is polled only.
7 *
8 *  COPYRIGHT (c) 1989-1999.
9 *  On-Line Applications Research Corporation (OAR).
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.com/license/LICENSE.
14 *
15 *  $Id$
16 */
17
18#include <bsp.h>
19#include <rtems/libio.h>
20#include <stdlib.h>
21#include <assert.h>
22
23/*
24 *  console_outbyte_polled
25 *
26 *  This routine transmits a character using polling.
27 */
28
29void console_outbyte_polled(
30  int  port,
31  char ch
32)
33{
34  uint32_t         control;
35  uint32_t         data;
36  uint8_t          rr_0;
37
38  if ( port == 0 ) {
39    control = CONSOLE_CONTROL_A;
40    data    = CONSOLE_DATA_A;
41  } else {
42    control = CONSOLE_CONTROL_B;
43    data    = CONSOLE_DATA_B;
44  }
45
46  for ( ; ; ) {
47    Z8x30_READ_CONTROL( control, RR_0, rr_0 );
48    if ( (rr_0 & RR_0_TX_BUFFER_EMPTY) != 0 )
49      break;
50  }
51
52  Z8x30_WRITE_DATA( control, ch );
53}
54
55/*
56 *  console_inbyte_nonblocking
57 *
58 *  This routine polls for a character.
59 */
60
61int console_inbyte_nonblocking(int port)
62{
63  uint32_t         control;
64  uint32_t         data;
65  uint8_t          rr_0;
66  char             ch;
67
68  if ( port == 0 ) {
69    control = CONSOLE_CONTROL_A;
70    data    = CONSOLE_DATA_A;
71  } else {
72    control = CONSOLE_CONTROL_B;
73    data    = CONSOLE_DATA_B;
74  }
75
76  Z8x30_READ_CONTROL( control, RR_0, rr_0 );
77  if ( !(rr_0 & RR_0_RX_DATA_AVAILABLE) )
78    return -1;
79
80  Z8x30_READ_DATA( data, ch );
81  return (int) ch;
82}
83
84/*
85 *  DEBUG_puts
86 *
87 *  This should be safe in the event of an error.  It attempts to insure
88 *  that no TX empty interrupts occur while it is doing polled IO.  Then
89 *  it restores the state of that external interrupt.
90 *
91 *  Input parameters:
92 *    string  - pointer to debug output string
93 *
94 *  Output parameters:  NONE
95 *
96 *  Return values:      NONE
97 */
98
99void DEBUG_puts(
100  char *string
101)
102{
103  char *s;
104
105  /* should disable interrupts here */
106    for ( s = string ; *s ; s++ )
107      console_outbyte_polled( 0, *s );
108
109    console_outbyte_polled( 0, '\r' );
110    console_outbyte_polled( 0, '\n' );
111  /* should enable interrupts here */
112}
113
114/*
115 *  Console Termios Support Entry Points
116 *
117 */
118
119int console_write_support (int minor, const char *buf, int len)
120{
121  int nwrite = 0;
122
123  while (nwrite < len) {
124    console_outbyte_polled( minor, *buf++ );
125    nwrite++;
126  }
127  return nwrite;
128}
129
130/*
131 *  Console Device Driver Entry Points
132 *
133 */
134
135rtems_device_driver console_initialize(
136  rtems_device_major_number  major,
137  rtems_device_minor_number  minor,
138  void                      *arg
139)
140{
141  rtems_status_code          status;
142  rtems_device_minor_number  console_minor;
143
144  rtems_termios_initialize();
145
146  /*
147   *  Register Device Names
148   */
149
150#if (USE_CHANNEL_A == 1)
151  console_minor = 0;
152#elif (USE_CHANNEL_B == 1)
153  console_minor = 1;
154#else
155#error "DMV152 Console Driver -- no console port configured!!!"
156#endif
157
158  status = rtems_io_register_name( "/dev/console", major, console_minor );
159  if (status != RTEMS_SUCCESSFUL)
160    rtems_fatal_error_occurred(status);
161
162  status = rtems_io_register_name( "/dev/console_a", major, 0 );
163  if (status != RTEMS_SUCCESSFUL)
164    rtems_fatal_error_occurred(status);
165
166  status = rtems_io_register_name( "/dev/console_b", major, 1 );
167  if (status != RTEMS_SUCCESSFUL)
168    rtems_fatal_error_occurred(status);
169
170  /*
171   *  Initialize Hardware
172   */
173
174  return RTEMS_SUCCESSFUL;
175}
176
177rtems_device_driver console_open(
178  rtems_device_major_number major,
179  rtems_device_minor_number minor,
180  void                    * arg
181)
182{
183  rtems_status_code sc;
184  static const rtems_termios_callbacks pollCallbacks = {
185    NULL,                        /* firstOpen */
186    NULL,                        /* lastClose */
187    console_inbyte_nonblocking,  /* pollRead */
188    console_write_support,       /* write */
189    NULL,                        /* setAttributes */
190    NULL,                        /* stopRemoteTx */
191    NULL,                        /* startRemoteTx */
192    0                            /* outputUsesInterrupts */
193  };
194
195  assert( minor <= 1 );
196  if ( minor > 2 )
197    return RTEMS_INVALID_NUMBER;
198
199  sc = rtems_termios_open (major, minor, arg, &pollCallbacks );
200
201  return RTEMS_SUCCESSFUL;
202}
203
204rtems_device_driver console_close(
205  rtems_device_major_number major,
206  rtems_device_minor_number minor,
207  void                    * arg
208)
209{
210  return rtems_termios_close (arg);
211}
212
213rtems_device_driver console_read(
214  rtems_device_major_number major,
215  rtems_device_minor_number minor,
216  void                    * arg
217)
218{
219  return rtems_termios_read (arg);
220}
221
222rtems_device_driver console_write(
223  rtems_device_major_number major,
224  rtems_device_minor_number minor,
225  void                    * arg
226)
227{
228  return rtems_termios_write (arg);
229}
230
231rtems_device_driver console_control(
232  rtems_device_major_number major,
233  rtems_device_minor_number minor,
234  void                    * arg
235)
236{
237  return rtems_termios_ioctl (arg);
238}
Note: See TracBrowser for help on using the repository browser.