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

4.104.114.84.95
Last change on this file since b2b4835 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 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.OARcorp.com/rtems/license.html.
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  rtems_unsigned32 control;
35  rtems_unsigned32 data;
36  rtems_unsigned8  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  rtems_unsigned32 control;
64  rtems_unsigned32 data;
65  rtems_unsigned8  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/*
116 *  Console Termios Support Entry Points
117 *
118 */
119
120int console_write_support (int minor, const char *buf, int len)
121{
122  int nwrite = 0;
123
124  while (nwrite < len) {
125    console_outbyte_polled( minor, *buf++ );
126    nwrite++;
127  }
128  return nwrite;
129}
130
131void console_reserve_resources(
132  rtems_configuration_table *configuration
133)
134{
135  rtems_termios_reserve_resources( configuration, 2 );
136}
137
138/*
139 *  Console Device Driver Entry Points
140 *
141 */
142 
143rtems_device_driver console_initialize(
144  rtems_device_major_number  major,
145  rtems_device_minor_number  minor,
146  void                      *arg
147)
148{
149  rtems_status_code          status;
150  rtems_device_minor_number  console_minor;
151
152  rtems_termios_initialize();
153
154  /*
155   *  Register Device Names
156   */
157
158#if (USE_CHANNEL_A == 1)
159  console_minor = 0;
160#elif (USE_CHANNEL_B == 1)
161  console_minor = 1;
162#else
163#error "DMV152 Console Driver -- no console port configured!!!"
164#endif
165
166  status = rtems_io_register_name( "/dev/console", major, console_minor );
167  if (status != RTEMS_SUCCESSFUL)
168    rtems_fatal_error_occurred(status);
169
170  status = rtems_io_register_name( "/dev/console_a", major, 0 );
171  if (status != RTEMS_SUCCESSFUL)
172    rtems_fatal_error_occurred(status);
173
174  status = rtems_io_register_name( "/dev/console_b", major, 1 );
175  if (status != RTEMS_SUCCESSFUL)
176    rtems_fatal_error_occurred(status);
177
178  /*
179   *  Initialize Hardware
180   */
181 
182  return RTEMS_SUCCESSFUL;
183}
184
185rtems_device_driver console_open(
186  rtems_device_major_number major,
187  rtems_device_minor_number minor,
188  void                    * arg
189)
190{
191  rtems_status_code sc;
192  static const rtems_termios_callbacks pollCallbacks = {
193    NULL,                        /* firstOpen */
194    NULL,                        /* lastClose */
195    console_inbyte_nonblocking,  /* pollRead */
196    console_write_support,       /* write */
197    NULL,                        /* setAttributes */
198    NULL,                        /* stopRemoteTx */
199    NULL,                        /* startRemoteTx */
200    0                            /* outputUsesInterrupts */
201  };
202
203  assert( minor <= 1 );
204  if ( minor > 2 )
205    return RTEMS_INVALID_NUMBER;
206
207  sc = rtems_termios_open (major, minor, arg, &pollCallbacks );
208
209  return RTEMS_SUCCESSFUL;
210}
211 
212rtems_device_driver console_close(
213  rtems_device_major_number major,
214  rtems_device_minor_number minor,
215  void                    * arg
216)
217{
218  return rtems_termios_close (arg);
219}
220 
221rtems_device_driver console_read(
222  rtems_device_major_number major,
223  rtems_device_minor_number minor,
224  void                    * arg
225)
226{
227  return rtems_termios_read (arg);
228}
229 
230rtems_device_driver console_write(
231  rtems_device_major_number major,
232  rtems_device_minor_number minor,
233  void                    * arg
234)
235{
236  return rtems_termios_write (arg);
237}
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_termios_ioctl (arg);
246}
247
Note: See TracBrowser for help on using the repository browser.