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

4.104.115
Last change on this file since ac7af4a was e9bb4fb, checked in by Joel Sherrill <joel.sherrill@…>, on 08/10/09 at 14:54:52

2009-08-10 Joel Sherrill <joel.sherrill@…>

  • console.c: Fix tabs and allow the BSP to override the default baud rate.
  • Property mode set to 100644
File size: 7.0 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 pointur from the Console_Port_Data */
86  current_tty = Console_Port_Data[minor].termios_data;
87
88  if ( (current_tty->refcount == 1) ) {
89
90    /*
91     *  If this BSP has a preferred default rate, then use that.
92     */
93    #if defined(BSP_DEFAULT_BAUD_RATE)
94      rtems_termios_set_initial_baud( current_tty, BSP_DEFAULT_BAUD_RATE );
95    #endif
96
97    /*
98     * If it's the first open, modified, if need, the port parameters
99     */
100    if (minor!=Console_Port_Minor) {
101      /*
102       * If this is not the console we do not want ECHO and
103       * so forth
104       */
105      IoctlArgs.iop=args->iop;
106      IoctlArgs.command=RTEMS_IO_GET_ATTRIBUTES;
107      IoctlArgs.buffer=&Termios;
108      rtems_termios_ioctl(&IoctlArgs);
109      Termios.c_lflag=ICANON;
110      IoctlArgs.command=RTEMS_IO_SET_ATTRIBUTES;
111      rtems_termios_ioctl(&IoctlArgs);
112    }
113  }
114
115  if ( (args->iop->flags&LIBIO_FLAGS_READ) &&
116      Console_Port_Tbl[minor].pDeviceFlow &&
117      Console_Port_Tbl[minor].pDeviceFlow->deviceStartRemoteTx) {
118    Console_Port_Tbl[minor].pDeviceFlow->deviceStartRemoteTx(minor);
119  }
120
121  return status;
122}
123
124/*PAGE
125 *
126 *  console_close
127 *
128 *  This routine closes a port that has been opened as console.
129 */
130
131rtems_device_driver console_close(
132  rtems_device_major_number major,
133  rtems_device_minor_number minor,
134  void                    * arg
135)
136{
137  rtems_libio_open_close_args_t *args = arg;
138  struct rtems_termios_tty      *current_tty;
139
140  /* Get tty pointeur from the Console_Port_Data */
141  current_tty = Console_Port_Data[minor].termios_data;
142
143  /* Get the tty refcount to determine if we need to do deviceStopRemoteTx.
144   * Stop only if it's the last one opened.
145   */
146  if ( (current_tty->refcount == 1) ) {
147    if ( (args->iop->flags&LIBIO_FLAGS_READ) &&
148          Console_Port_Tbl[minor].pDeviceFlow &&
149          Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx) {
150      Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx(minor);
151    }
152  }
153
154  return rtems_termios_close (arg);
155}
156
157/*PAGE
158 *
159 *  console_read
160 *
161 *  This routine uses the termios driver to read a character.
162 */
163
164rtems_device_driver console_read(
165  rtems_device_major_number major,
166  rtems_device_minor_number minor,
167  void                    * arg
168)
169{
170  return rtems_termios_read (arg);
171}
172
173/*PAGE
174 *
175 *  console_write
176 *
177 *  this routine uses the termios driver to write a character.
178 */
179
180rtems_device_driver console_write(
181  rtems_device_major_number major,
182  rtems_device_minor_number minor,
183  void                    * arg
184)
185{
186  return rtems_termios_write (arg);
187}
188
189/*PAGE
190 *
191 *  console_control
192 *
193 *  this routine uses the termios driver to process io
194 */
195
196rtems_device_driver console_control(
197  rtems_device_major_number major,
198  rtems_device_minor_number minor,
199  void                    * arg
200)
201{
202  return rtems_termios_ioctl (arg);
203}
204
205/*PAGE
206 *
207 *  console_initialize
208 *
209 *  Routine called to initialize the console device driver.
210 */
211
212rtems_device_driver console_initialize(
213  rtems_device_major_number  major,
214  rtems_device_minor_number  minor_arg,
215  void                      *arg
216)
217{
218  rtems_status_code          status;
219  rtems_device_minor_number  minor;
220
221  /*
222   * initialize the termio interface.
223   */
224
225  rtems_termios_initialize();
226
227  for (minor=0; minor < Console_Port_Count ; minor++) {
228    /*
229     * First perform the configuration dependent probe, then the
230     * device dependent probe
231     */
232
233    if ((!Console_Port_Tbl[minor].deviceProbe ||
234         Console_Port_Tbl[minor].deviceProbe(minor)) &&
235         Console_Port_Tbl[minor].pDeviceFns->deviceProbe(minor)) {
236      /*
237       * Use this device for the console
238       */
239      break;
240    }
241  }
242  if ( minor == Console_Port_Count ) {
243    /*
244     * Failed to find a working device
245     */
246    rtems_fatal_error_occurred(RTEMS_IO_ERROR);
247  }
248
249  Console_Port_Minor=minor;
250
251  /*
252   * Register Device Names
253   */
254  status = rtems_io_register_name("/dev/console", major, Console_Port_Minor );
255  if (status != RTEMS_SUCCESSFUL) {
256    rtems_fatal_error_occurred(status);
257  }
258  Console_Port_Tbl[minor].pDeviceFns->deviceInitialize(Console_Port_Minor);
259
260  for (minor++;minor<Console_Port_Count;minor++) {
261    /*
262     * First perform the configuration dependent probe, then the
263     * device dependent probe
264     */
265
266    if ( (!Console_Port_Tbl[minor].deviceProbe ||
267         Console_Port_Tbl[minor].deviceProbe(minor)) &&
268         Console_Port_Tbl[minor].pDeviceFns->deviceProbe(minor)) {
269      status = rtems_io_register_name(
270        Console_Port_Tbl[minor].sDeviceName,
271        major,
272        minor );
273      if (status != RTEMS_SUCCESSFUL) {
274        rtems_fatal_error_occurred(status);
275      }
276
277      /*
278       * Initialize the hardware device.
279       */
280
281      Console_Port_Tbl[minor].pDeviceFns->deviceInitialize(minor);
282
283    }
284  }
285
286  return RTEMS_SUCCESSFUL;
287}
Note: See TracBrowser for help on using the repository browser.