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

4.104.114.84.95
Last change on this file since 9980062 was 9980062, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 4, 2003 at 6:51:36 PM

2003-09-04 Joel Sherrill <joel@…>

  • clock/ckinit.c, console/console.c, include/bsp.h, include/coverhd.h, spurious/spinit.c, startup/bspclean.c, startup/bspstart.c, startup/linkcmds, startup/vmeintr.c, timer/timer.c, timer/timerisr.S: URL for license changed.
  • 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  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
131/*
132 *  Console Device Driver Entry Points
133 *
134 */
135 
136rtems_device_driver console_initialize(
137  rtems_device_major_number  major,
138  rtems_device_minor_number  minor,
139  void                      *arg
140)
141{
142  rtems_status_code          status;
143  rtems_device_minor_number  console_minor;
144
145  rtems_termios_initialize();
146
147  /*
148   *  Register Device Names
149   */
150
151#if (USE_CHANNEL_A == 1)
152  console_minor = 0;
153#elif (USE_CHANNEL_B == 1)
154  console_minor = 1;
155#else
156#error "DMV152 Console Driver -- no console port configured!!!"
157#endif
158
159  status = rtems_io_register_name( "/dev/console", major, console_minor );
160  if (status != RTEMS_SUCCESSFUL)
161    rtems_fatal_error_occurred(status);
162
163  status = rtems_io_register_name( "/dev/console_a", major, 0 );
164  if (status != RTEMS_SUCCESSFUL)
165    rtems_fatal_error_occurred(status);
166
167  status = rtems_io_register_name( "/dev/console_b", major, 1 );
168  if (status != RTEMS_SUCCESSFUL)
169    rtems_fatal_error_occurred(status);
170
171  /*
172   *  Initialize Hardware
173   */
174 
175  return RTEMS_SUCCESSFUL;
176}
177
178rtems_device_driver console_open(
179  rtems_device_major_number major,
180  rtems_device_minor_number minor,
181  void                    * arg
182)
183{
184  rtems_status_code sc;
185  static const rtems_termios_callbacks pollCallbacks = {
186    NULL,                        /* firstOpen */
187    NULL,                        /* lastClose */
188    console_inbyte_nonblocking,  /* pollRead */
189    console_write_support,       /* write */
190    NULL,                        /* setAttributes */
191    NULL,                        /* stopRemoteTx */
192    NULL,                        /* startRemoteTx */
193    0                            /* outputUsesInterrupts */
194  };
195
196  assert( minor <= 1 );
197  if ( minor > 2 )
198    return RTEMS_INVALID_NUMBER;
199
200  sc = rtems_termios_open (major, minor, arg, &pollCallbacks );
201
202  return RTEMS_SUCCESSFUL;
203}
204 
205rtems_device_driver console_close(
206  rtems_device_major_number major,
207  rtems_device_minor_number minor,
208  void                    * arg
209)
210{
211  return rtems_termios_close (arg);
212}
213 
214rtems_device_driver console_read(
215  rtems_device_major_number major,
216  rtems_device_minor_number minor,
217  void                    * arg
218)
219{
220  return rtems_termios_read (arg);
221}
222 
223rtems_device_driver console_write(
224  rtems_device_major_number major,
225  rtems_device_minor_number minor,
226  void                    * arg
227)
228{
229  return rtems_termios_write (arg);
230}
231 
232rtems_device_driver console_control(
233  rtems_device_major_number major,
234  rtems_device_minor_number minor,
235  void                    * arg
236)
237{
238  return rtems_termios_ioctl (arg);
239}
240
Note: See TracBrowser for help on using the repository browser.