source: rtems/c/src/lib/libbsp/shared/console.c @ 5a23ca84

4.104.114.84.95
Last change on this file since 5a23ca84 was c73b8ac2, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 9, 1999 at 10:18:43 PM

This patch adds the basic framework for the ITRON 3.0 API implementation
for RTEMS.

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