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

4.104.114.84.95
Last change on this file since 55951bc was 55951bc, checked in by Joel Sherrill <joel.sherrill@…>, on 05/04/98 at 12:40:21

Switched to termios callback structure.

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