source: rtems/c/src/lib/libbsp/shared/console.c @ 8b8e1ee5

4.104.114.84.95
Last change on this file since 8b8e1ee5 was 50189556, checked in by Joel Sherrill <joel.sherrill@…>, on 09/02/05 at 20:29:22

2005-09-02 Joel Sherrill <joel@…>

PR 577/bsps

  • console.c: Make the previously committed patch for this PR compile.
  • Property mode set to 100644
File size: 6.7 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 *
10 *  The license and distribution terms for this file may be
11 *  found in the file LICENSE in this distribution or at
12 *  http://www.rtems.com/license/LICENSE.
13 *
14 *  $Id$
15 */
16
17#include <bsp.h>
18#include <rtems/libio.h>
19#include <stdlib.h>
20#include <assert.h>
21#include <termios.h>
22
23#include <rtems/termiostypes.h>
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  struct rtems_termios_tty      *current_tty;
55
56  /*
57   * Verify the port number is valid.
58   */
59  if ( minor > Console_Port_Count ) {
60    return RTEMS_INVALID_NUMBER;
61  }
62
63  /*
64   * Open the port as a termios console driver.
65   */
66
67  cptr = &Console_Port_Tbl[minor];
68  Callbacks.firstOpen            = cptr->pDeviceFns->deviceFirstOpen;
69  Callbacks.lastClose            = cptr->pDeviceFns->deviceLastClose;
70  Callbacks.pollRead             = cptr->pDeviceFns->deviceRead;
71  Callbacks.write                = cptr->pDeviceFns->deviceWrite;
72  Callbacks.setAttributes        = cptr->pDeviceFns->deviceSetAttributes;
73  Callbacks.stopRemoteTx         = cptr->pDeviceFlow->deviceStopRemoteTx;
74  Callbacks.startRemoteTx        = cptr->pDeviceFlow->deviceStartRemoteTx;
75  Callbacks.outputUsesInterrupts = cptr->pDeviceFns->deviceOutputUsesInterrupts;
76
77  /* XXX what about
78   *        Console_Port_Tbl[minor].ulMargin,
79   *        Console_Port_Tbl[minor].ulHysteresis);
80   */
81
82  status = rtems_termios_open ( major, minor, arg, &Callbacks );
83  Console_Port_Data[minor].termios_data = args->iop->data1;
84
85  /* Get tty pointeur from the Console_Port_Data */
86  current_tty = Console_Port_Data[minor].termios_data;
87
88  if ( (current_tty->refcount == 1) ) {
89  /*
90   * If it's the first open, modified, if need, the port parameters
91   */
92        if (minor!=Console_Port_Minor) {
93                /*
94                 * If this is not the console we do not want ECHO and
95                 * so forth
96                 */
97                IoctlArgs.iop=args->iop;
98                IoctlArgs.command=RTEMS_IO_GET_ATTRIBUTES;
99                IoctlArgs.buffer=&Termios;
100                rtems_termios_ioctl(&IoctlArgs);
101                Termios.c_lflag=ICANON;
102                IoctlArgs.command=RTEMS_IO_SET_ATTRIBUTES;
103                rtems_termios_ioctl(&IoctlArgs);
104        }
105  }
106
107  if ( (args->iop->flags&LIBIO_FLAGS_READ) &&
108      Console_Port_Tbl[minor].pDeviceFlow &&
109      Console_Port_Tbl[minor].pDeviceFlow->deviceStartRemoteTx) {
110    Console_Port_Tbl[minor].pDeviceFlow->deviceStartRemoteTx(minor);
111  }
112
113  return status;
114}
115
116/*PAGE
117 *
118 *  console_close
119 *
120 *  This routine closes a port that has been opened as console.
121 */
122
123rtems_device_driver console_close(
124  rtems_device_major_number major,
125  rtems_device_minor_number minor,
126  void                    * arg
127)
128{
129  rtems_libio_open_close_args_t *args = arg;
130  struct rtems_termios_tty      *current_tty;
131
132  /* Get tty pointeur from the Console_Port_Data */
133  current_tty = Console_Port_Data[minor].termios_data;
134
135  /* Get the tty refcount to determine if we need to do deviceStopRemoteTx.
136   * Stop only if it's the last one opened.
137   */
138  if ( (current_tty->refcount == 1) ) {
139    if ( (args->iop->flags&LIBIO_FLAGS_READ) &&
140          Console_Port_Tbl[minor].pDeviceFlow &&
141          Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx) {
142      Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx(minor);
143    }
144  }
145
146  return rtems_termios_close (arg);
147}
148
149/*PAGE
150 *
151 *  console_read
152 *
153 *  This routine uses the termios driver to read a character.
154 */
155
156rtems_device_driver console_read(
157  rtems_device_major_number major,
158  rtems_device_minor_number minor,
159  void                    * arg
160)
161{
162  return rtems_termios_read (arg);
163}
164
165/*PAGE
166 *
167 *  console_write
168 *
169 *  this routine uses the termios driver to write a character.
170 */
171
172rtems_device_driver console_write(
173  rtems_device_major_number major,
174  rtems_device_minor_number minor,
175  void                    * arg
176)
177{
178  return rtems_termios_write (arg);
179}
180
181/*PAGE
182 *
183 *  console_control
184 *
185 *  this routine uses the termios driver to process io
186 */
187
188rtems_device_driver console_control(
189  rtems_device_major_number major,
190  rtems_device_minor_number minor,
191  void                    * arg
192)
193{
194  return rtems_termios_ioctl (arg);
195}
196
197/*PAGE
198 *
199 *  console_initialize
200 *
201 *  Routine called to initialize the console device driver.
202 */
203
204rtems_device_driver console_initialize(
205  rtems_device_major_number  major,
206  rtems_device_minor_number  minor_arg,
207  void                      *arg
208)
209{
210  rtems_status_code          status;
211  rtems_device_minor_number  minor;
212
213  /*
214   * initialize the termio interface.
215   */
216
217  rtems_termios_initialize();
218
219  for (minor=0; minor < Console_Port_Count ; minor++) {
220    /*
221     * First perform the configuration dependent probe, then the
222     * device dependent probe
223     */
224
225    if ((!Console_Port_Tbl[minor].deviceProbe ||
226         Console_Port_Tbl[minor].deviceProbe(minor)) &&
227         Console_Port_Tbl[minor].pDeviceFns->deviceProbe(minor)) {
228      /*
229       * Use this device for the console
230       */
231      break;
232    }
233  }
234  if ( minor == Console_Port_Count ) {
235    /*
236     * Failed to find a working device
237     */
238    rtems_fatal_error_occurred(RTEMS_IO_ERROR);
239  }
240
241  Console_Port_Minor=minor;
242
243  /*
244   * Register Device Names
245   */
246  status = rtems_io_register_name("/dev/console", major, Console_Port_Minor );
247  if (status != RTEMS_SUCCESSFUL) {
248    rtems_fatal_error_occurred(status);
249  }
250  Console_Port_Tbl[minor].pDeviceFns->deviceInitialize(Console_Port_Minor);
251
252  for (minor++;minor<Console_Port_Count;minor++) {
253    /*
254     * First perform the configuration dependent probe, then the
255     * device dependent probe
256     */
257
258    if ( (!Console_Port_Tbl[minor].deviceProbe ||
259         Console_Port_Tbl[minor].deviceProbe(minor)) &&
260         Console_Port_Tbl[minor].pDeviceFns->deviceProbe(minor)) {
261      status = rtems_io_register_name(
262        Console_Port_Tbl[minor].sDeviceName,
263        major,
264        minor );
265      if (status != RTEMS_SUCCESSFUL) {
266        rtems_fatal_error_occurred(status);
267      }
268
269      /*
270       * Initialize the hardware device.
271       */
272
273      Console_Port_Tbl[minor].pDeviceFns->deviceInitialize(minor);
274
275    }
276  }
277
278  return RTEMS_SUCCESSFUL;
279}
Note: See TracBrowser for help on using the repository browser.