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

4.104.114.84.95
Last change on this file since edd1329f was edd1329f, checked in by Joel Sherrill <joel.sherrill@…>, on 10/23/97 at 15:11:27

Overhauled console driver to use termios and to simultaneously support
both ports.

  • Property mode set to 100644
File size: 4.9 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-1997.
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(
63  int port,
64  char *c
65)
66{
67  rtems_unsigned32 control;
68  rtems_unsigned32 data;
69  rtems_unsigned8  rr_0;
70  char             ch;
71
72  if ( port == 0 ) {
73    control = CONSOLE_CONTROL_A;
74    data    = CONSOLE_DATA_A;
75  } else {
76    control = CONSOLE_CONTROL_B;
77    data    = CONSOLE_DATA_B;
78  }
79
80  Z8x30_READ_CONTROL( control, RR_0, rr_0 );
81  if ( !(rr_0 & RR_0_RX_DATA_AVAILABLE) )
82    return 0;
83
84  Z8x30_READ_DATA( data, ch );
85  return ch;
86}
87
88/*
89 *  DEBUG_puts
90 *
91 *  This should be safe in the event of an error.  It attempts to insure
92 *  that no TX empty interrupts occur while it is doing polled IO.  Then
93 *  it restores the state of that external interrupt.
94 *
95 *  Input parameters:
96 *    string  - pointer to debug output string
97 *
98 *  Output parameters:  NONE
99 *
100 *  Return values:      NONE
101 */
102
103void DEBUG_puts(
104  char *string
105)
106{
107  char *s;
108
109  /* should disable interrupts here */
110    for ( s = string ; *s ; s++ )
111      console_outbyte_polled( 0, *s );
112
113    console_outbyte_polled( 0, '\r' );
114    console_outbyte_polled( 0, '\n' );
115  /* should enable interrupts here */
116}
117
118
119/*
120 *  Console Termios Support Entry Points
121 *
122 */
123
124int console_write_support (int minor, char *buf, int len)
125{
126  int nwrite = 0;
127
128  while (nwrite < len) {
129    console_outbyte_polled( minor, *buf++ );
130    nwrite++;
131  }
132  return nwrite;
133}
134
135void console_reserve_resources(
136  rtems_configuration_table *configuration
137)
138{
139  rtems_termios_reserve_resources( configuration, 2 );
140}
141
142/*
143 *  Console Device Driver Entry Points
144 *
145 */
146 
147rtems_device_driver console_initialize(
148  rtems_device_major_number  major,
149  rtems_device_minor_number  minor,
150  void                      *arg
151)
152{
153  rtems_status_code          status;
154  rtems_device_minor_number  console_minor;
155
156  rtems_termios_initialize();
157
158  /*
159   *  Register Device Names
160   */
161
162#if (USE_CHANNEL_A == 1)
163  console_minor = 0;
164#elif (USE_CHANNEL_B == 1)
165  console_minor = 1;
166#else
167#error "DMV152 Console Driver -- no console port configured!!!"
168#endif
169
170  status = rtems_io_register_name( "/dev/console", major, console_minor );
171  if (status != RTEMS_SUCCESSFUL)
172    rtems_fatal_error_occurred(status);
173
174  status = rtems_io_register_name( "/dev/console_a", major, 0 );
175  if (status != RTEMS_SUCCESSFUL)
176    rtems_fatal_error_occurred(status);
177
178  status = rtems_io_register_name( "/dev/console_b", major, 1 );
179  if (status != RTEMS_SUCCESSFUL)
180    rtems_fatal_error_occurred(status);
181
182  /*
183   *  Initialize Hardware
184   */
185 
186  return RTEMS_SUCCESSFUL;
187}
188
189rtems_device_driver console_open(
190  rtems_device_major_number major,
191  rtems_device_minor_number minor,
192  void                    * arg
193)
194{
195        rtems_status_code sc;
196
197        assert( minor <= 1 );
198        if ( minor > 2 )
199          return RTEMS_INVALID_NUMBER;
200 
201        sc = rtems_termios_open (major, minor, arg,
202                        NULL,
203                        NULL,
204                        console_inbyte_nonblocking,
205                        console_write_support);
206
207  return RTEMS_SUCCESSFUL;
208}
209 
210rtems_device_driver console_close(
211  rtems_device_major_number major,
212  rtems_device_minor_number minor,
213  void                    * arg
214)
215{
216  return rtems_termios_close (arg);
217}
218 
219rtems_device_driver console_read(
220  rtems_device_major_number major,
221  rtems_device_minor_number minor,
222  void                    * arg
223)
224{
225  return rtems_termios_read (arg);
226}
227 
228rtems_device_driver console_write(
229  rtems_device_major_number major,
230  rtems_device_minor_number minor,
231  void                    * arg
232)
233{
234  return rtems_termios_write (arg);
235}
236 
237rtems_device_driver console_control(
238  rtems_device_major_number major,
239  rtems_device_minor_number minor,
240  void                    * arg
241)
242{
243  return rtems_termios_ioctl (arg);
244}
245
Note: See TracBrowser for help on using the repository browser.