source: rtems/c/src/lib/libbsp/shared/console.c @ 08b5f55

4.104.114.84.95
Last change on this file since 08b5f55 was 870284d, checked in by Joel Sherrill <joel.sherrill@…>, on 08/08/98 at 16:37:43

Corrected spacing.

  • Property mode set to 100644
File size: 7.0 KB
Line 
1/*
2 *  This file contains the TTY driver for the PPCn_60x
3 *
4 *  This driver uses the termios pseudo driver.
5 *
6 *  COPYRIGHT (c) 1998 by Radstone Technology
7 *
8 *
9 * THIS FILE IS PROVIDED TO YOU, THE USER, "AS IS", WITHOUT WARRANTY OF ANY
10 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
11 * IMPLIED WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK
12 * AS TO THE QUALITY AND PERFORMANCE OF ALL CODE IN THIS FILE IS WITH YOU.
13 *
14 * You are hereby granted permission to use, copy, modify, and distribute
15 * this file, provided that this notice, plus the above copyright notice
16 * and disclaimer, appears in all copies. Radstone Technology will provide
17 * no support for this code.
18 *
19 *  COPYRIGHT (c) 1989-1997.
20 *  On-Line Applications Research Corporation (OAR).
21 *  Copyright assigned to U.S. Government, 1994.
22 *
23 *  The license and distribution terms for this file may be
24 *  found in the file LICENSE in this distribution or at
25 *  http://www.OARcorp.com/rtems/license.html.
26 *
27 *  $Id$
28 */
29
30#include <bsp.h>
31#include <rtems/libio.h>
32#include <stdlib.h>
33#include <assert.h>
34#include <termios.h>
35
36#include <libchip/serial.h>
37
38/*
39 *  Configuration Information
40 */
41
42extern console_data  Console_Port_Data[];
43extern unsigned long  Console_Port_Count;
44extern rtems_device_minor_number  Console_Port_Minor;
45 
46/*PAGE
47 *
48 *  console_open
49 *
50 *  open a port as a termios console.
51 *
52 */
53
54rtems_device_driver console_open(
55  rtems_device_major_number major,
56  rtems_device_minor_number minor,
57  void                    * arg
58)
59{
60  rtems_status_code              status;
61  rtems_libio_open_close_args_t *args = arg;
62  rtems_libio_ioctl_args_t       IoctlArgs;
63  struct termios                 Termios;
64  rtems_termios_callbacks        Callbacks;
65  console_tbl                   *cptr;
66
67  /*
68   * Verify the port number is valid.
69   */
70  if ( minor > Console_Port_Count ) {
71    return RTEMS_INVALID_NUMBER;
72  }
73
74  /*
75   * Open the port as a termios console driver.
76   */
77
78  cptr = &Console_Port_Tbl[minor];
79  Callbacks.firstOpen            = cptr->pDeviceFns->deviceFirstOpen;
80  Callbacks.lastClose            = cptr->pDeviceFns->deviceLastClose;
81  Callbacks.pollRead             = cptr->pDeviceFns->deviceRead;
82  Callbacks.write                = cptr->pDeviceFns->deviceWrite;
83  Callbacks.setAttributes        = cptr->pDeviceFns->deviceSetAttributes;
84  Callbacks.stopRemoteTx         = cptr->pDeviceFlow->deviceStopRemoteTx;
85  Callbacks.startRemoteTx        = cptr->pDeviceFlow->deviceStartRemoteTx;
86  Callbacks.outputUsesInterrupts = cptr->pDeviceFns->deviceOutputUsesInterrupts;
87
88  /* XXX what about
89   *        Console_Port_Tbl[minor].ulMargin,
90   *        Console_Port_Tbl[minor].ulHysteresis);
91   */
92
93  status = rtems_termios_open ( major, minor, arg, &Callbacks );
94  Console_Port_Data[minor].termios_data = args->iop->data1;
95
96  if (minor!=Console_Port_Minor) {
97    /*
98     * If this is not the console we do not want ECHO and
99     * so forth
100     */
101    IoctlArgs.iop=args->iop;
102    IoctlArgs.command=RTEMS_IO_GET_ATTRIBUTES;
103    IoctlArgs.buffer=&Termios;
104    rtems_termios_ioctl(&IoctlArgs);
105    Termios.c_lflag=ICANON;
106    IoctlArgs.command=RTEMS_IO_SET_ATTRIBUTES;
107    rtems_termios_ioctl(&IoctlArgs);
108  }
109
110  if ( (args->iop->flags&LIBIO_FLAGS_READ) &&
111      Console_Port_Tbl[minor].pDeviceFlow &&
112      Console_Port_Tbl[minor].pDeviceFlow->deviceStartRemoteTx) {
113    Console_Port_Tbl[minor].pDeviceFlow->deviceStartRemoteTx(minor);
114  }
115
116  return status;
117}
118 
119/*PAGE
120 *
121 *  console_reserve_resources
122 *
123 *  This routine uses the termios driver to reserve resources.
124 */
125
126void console_reserve_resources(
127  rtems_configuration_table *configuration
128)
129{
130  rtems_termios_reserve_resources( configuration, 4 );
131}
132
133
134/*PAGE
135 *
136 *  console_close
137 *
138 *  This routine closes a port that has been opened as console.
139 */
140
141rtems_device_driver console_close(
142  rtems_device_major_number major,
143  rtems_device_minor_number minor,
144  void                    * arg
145)
146{
147  rtems_libio_open_close_args_t *args = arg;
148
149  if ( (args->iop->flags&LIBIO_FLAGS_READ) &&
150        Console_Port_Tbl[minor].pDeviceFlow &&
151        Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx) {
152    Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx(minor);
153  }
154
155  return rtems_termios_close (arg);
156}
157 
158/*PAGE
159 *
160 *  console_read
161 *
162 *  This routine uses the termios driver to read a character.
163 */
164
165rtems_device_driver console_read(
166  rtems_device_major_number major,
167  rtems_device_minor_number minor,
168  void                    * arg
169)
170{
171  return rtems_termios_read (arg);
172}
173 
174/*PAGE
175 *
176 *  console_write
177 *
178 *  this routine uses the termios driver to write a character.
179 */
180
181rtems_device_driver console_write(
182  rtems_device_major_number major,
183  rtems_device_minor_number minor,
184  void                    * arg
185)
186{
187  return rtems_termios_write (arg);
188}
189 
190/*PAGE
191 *
192 *  console_control
193 *
194 *  this routine uses the termios driver to process io
195 */
196
197rtems_device_driver console_control(
198  rtems_device_major_number major,
199  rtems_device_minor_number minor,
200  void                    * arg
201)
202{
203  return rtems_termios_ioctl (arg);
204}
205
206/*PAGE
207 *
208 *  console_initialize
209 *
210 *  Routine called to initialize the console device driver.
211 */
212
213rtems_device_driver console_initialize(
214  rtems_device_major_number  major,
215  rtems_device_minor_number  minor_arg,
216  void                      *arg
217)
218{
219  rtems_status_code          status;
220  rtems_device_minor_number  minor;
221
222  /*
223   * initialize the termio interface.
224   */
225
226  rtems_termios_initialize();
227
228  for (minor=0; minor < Console_Port_Count ; minor++) {
229    /*
230     * First perform the configuration dependent probe, then the
231     * device dependent probe
232     */
233
234    if ((!Console_Port_Tbl[minor].deviceProbe ||
235         Console_Port_Tbl[minor].deviceProbe(minor)) &&
236         Console_Port_Tbl[minor].pDeviceFns->deviceProbe(minor)) {
237      /*
238       * Use this device for the console
239       */
240      break;
241    }
242  }
243  if ( minor == Console_Port_Count ) {
244    /*
245     * Failed to find a working device
246     */
247    rtems_fatal_error_occurred(RTEMS_IO_ERROR);
248  }
249 
250  Console_Port_Minor=minor;
251
252  /*
253   * Register Device Names
254   */
255  status = rtems_io_register_name("/dev/console", major, Console_Port_Minor );
256  if (status != RTEMS_SUCCESSFUL) {
257    rtems_fatal_error_occurred(status);
258  }
259  Console_Port_Tbl[minor].pDeviceFns->deviceInitialize(Console_Port_Minor);
260
261  for (minor++;minor<Console_Port_Count;minor++) {
262    /*
263     * First perform the configuration dependent probe, then the
264     * device dependent probe
265     */
266
267    if ( (!Console_Port_Tbl[minor].deviceProbe ||
268         Console_Port_Tbl[minor].deviceProbe(minor)) &&
269         Console_Port_Tbl[minor].pDeviceFns->deviceProbe(minor)) {
270      status = rtems_io_register_name(
271        Console_Port_Tbl[minor].sDeviceName,
272        major,
273        minor );
274      if (status != RTEMS_SUCCESSFUL) {
275        rtems_fatal_error_occurred(status);
276      }
277
278      /*
279       * Initialize the hardware device.
280       */
281
282      Console_Port_Tbl[minor].pDeviceFns->deviceInitialize(minor);
283
284    }
285  }
286
287  return RTEMS_SUCCESSFUL;
288}
289
290
291
Note: See TracBrowser for help on using the repository browser.