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

4.104.114.84.95
Last change on this file since e7d06758 was e7d06758, checked in by Joel Sherrill <joel.sherrill@…>, on 08/19/05 at 16:19:48

2005-08-19 Cedric Aubert <cedric_aubert@…>

PR 577/bsps

  • console.c: The console_close() method currently calls StopRemoteTx?() on all invocations. It should should be ok for last close only but not for any others. If you open a port multiple times, you only want to call StopRemoteTx?() only as part of the last close.
  • Property mode set to 100644
File size: 6.6 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
131  /* Get the tty refcount to determine if we need to do deviceStopRemoteTx.
132   * Stop only if it's the last one opened.
133   */
134  if ( (current_tty->refcount == 1) ) {
135    if ( (args->iop->flags&LIBIO_FLAGS_READ) &&
136          Console_Port_Tbl[minor].pDeviceFlow &&
137          Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx) {
138      Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx(minor);
139    }
140  }
141
142  return rtems_termios_close (arg);
143}
144
145/*PAGE
146 *
147 *  console_read
148 *
149 *  This routine uses the termios driver to read a character.
150 */
151
152rtems_device_driver console_read(
153  rtems_device_major_number major,
154  rtems_device_minor_number minor,
155  void                    * arg
156)
157{
158  return rtems_termios_read (arg);
159}
160
161/*PAGE
162 *
163 *  console_write
164 *
165 *  this routine uses the termios driver to write a character.
166 */
167
168rtems_device_driver console_write(
169  rtems_device_major_number major,
170  rtems_device_minor_number minor,
171  void                    * arg
172)
173{
174  return rtems_termios_write (arg);
175}
176
177/*PAGE
178 *
179 *  console_control
180 *
181 *  this routine uses the termios driver to process io
182 */
183
184rtems_device_driver console_control(
185  rtems_device_major_number major,
186  rtems_device_minor_number minor,
187  void                    * arg
188)
189{
190  return rtems_termios_ioctl (arg);
191}
192
193/*PAGE
194 *
195 *  console_initialize
196 *
197 *  Routine called to initialize the console device driver.
198 */
199
200rtems_device_driver console_initialize(
201  rtems_device_major_number  major,
202  rtems_device_minor_number  minor_arg,
203  void                      *arg
204)
205{
206  rtems_status_code          status;
207  rtems_device_minor_number  minor;
208
209  /*
210   * initialize the termio interface.
211   */
212
213  rtems_termios_initialize();
214
215  for (minor=0; minor < Console_Port_Count ; minor++) {
216    /*
217     * First perform the configuration dependent probe, then the
218     * device dependent probe
219     */
220
221    if ((!Console_Port_Tbl[minor].deviceProbe ||
222         Console_Port_Tbl[minor].deviceProbe(minor)) &&
223         Console_Port_Tbl[minor].pDeviceFns->deviceProbe(minor)) {
224      /*
225       * Use this device for the console
226       */
227      break;
228    }
229  }
230  if ( minor == Console_Port_Count ) {
231    /*
232     * Failed to find a working device
233     */
234    rtems_fatal_error_occurred(RTEMS_IO_ERROR);
235  }
236
237  Console_Port_Minor=minor;
238
239  /*
240   * Register Device Names
241   */
242  status = rtems_io_register_name("/dev/console", major, Console_Port_Minor );
243  if (status != RTEMS_SUCCESSFUL) {
244    rtems_fatal_error_occurred(status);
245  }
246  Console_Port_Tbl[minor].pDeviceFns->deviceInitialize(Console_Port_Minor);
247
248  for (minor++;minor<Console_Port_Count;minor++) {
249    /*
250     * First perform the configuration dependent probe, then the
251     * device dependent probe
252     */
253
254    if ( (!Console_Port_Tbl[minor].deviceProbe ||
255         Console_Port_Tbl[minor].deviceProbe(minor)) &&
256         Console_Port_Tbl[minor].pDeviceFns->deviceProbe(minor)) {
257      status = rtems_io_register_name(
258        Console_Port_Tbl[minor].sDeviceName,
259        major,
260        minor );
261      if (status != RTEMS_SUCCESSFUL) {
262        rtems_fatal_error_occurred(status);
263      }
264
265      /*
266       * Initialize the hardware device.
267       */
268
269      Console_Port_Tbl[minor].pDeviceFns->deviceInitialize(minor);
270
271    }
272  }
273
274  return RTEMS_SUCCESSFUL;
275}
Note: See TracBrowser for help on using the repository browser.