source: rtems/c/src/lib/libbsp/powerpc/shared/console/console.c @ 5191d84

4.115
Last change on this file since 5191d84 was 5191d84, checked in by Ralf Corsepius <ralf.corsepius@…>, on 10/07/11 at 14:25:31

2011-10-07 Ralf Corsépius <ralf.corsepius@…>

  • shared/console/console.c: Remove stray local decl of "close".
  • Property mode set to 100644
File size: 8.6 KB
Line 
1/*
2 *  console.c  -- console I/O package
3 *
4 *  Copyright (C) 1999 Eric Valette. valette@crf.canon.fr
5 *
6 * This code is based on the pc386 BSP console.c so the following
7 * copyright also applies :
8 *
9 * (C) Copyright 1997 -
10 * - NavIST Group - Real-Time Distributed Systems and Industrial Automation
11 *
12 * Till Straumann, <strauman@slac.stanford.edu>, 12/20/2001
13 * separate BSP specific stuff from generics...
14 *
15 * http://pandora.ist.utl.pt
16 *
17 * Instituto Superior Tecnico * Lisboa * PORTUGAL
18 *  The license and distribution terms for this file may be
19 *  found in the file LICENSE in this distribution or at
20 *  http://www.rtems.com/license/LICENSE.
21 *
22 * $Id$
23 */
24
25#include <stdlib.h>
26#include <assert.h>
27#include <stdlib.h>
28
29#include <bsp.h>
30#include <bsp/irq.h>
31#include <rtems/bspIo.h>
32#include <rtems/libio.h>
33#include <rtems/termiostypes.h>
34#include <termios.h>
35#include <bsp/uart.h>
36#include <rtems/bspIo.h>  /* printk */
37
38/* Definitions for BSPConsolePort */
39/*
40 * Possible value for console input/output :
41 *    BSP_CONSOLE_PORT_CONSOLE
42 *    BSP_UART_COM1
43 *    BSP_UART_COM2
44 */
45int BSPConsolePort = BSP_CONSOLE_PORT;
46
47int BSPBaseBaud    = BSP_UART_BAUD_BASE;
48
49/*
50 * TERMIOS_OUTPUT_MODE should be a 'bspopts.h/configure'-able option;
51 * we could even make it a link-time option (but that would require
52 * small changes)...
53 */
54#ifndef TERMIOS_OUTPUT_MODE
55  #if 1
56    #define TERMIOS_OUTPUT_MODE TERMIOS_IRQ_DRIVEN
57  #else
58    #define TERMIOS_OUTPUT_MODE TERMIOS_TASK_DRIVEN
59  #endif
60#endif
61
62#if ! defined(USE_POLLED_IO) && (TERMIOS_OUTPUT_MODE == TERMIOS_POLLED)
63  #define USE_POLLED_IO
64#endif
65
66/*-------------------------------------------------------------------------+
67| External Prototypes
68+--------------------------------------------------------------------------*/
69
70static int  conSetAttr(int minor, const struct termios *);
71
72typedef struct TtySTblRec_ {
73  char          *name;
74  rtems_irq_hdl  isr;
75} TtySTblRec, *TtySTbl;
76
77static TtySTblRec ttyS[]={
78    { "/dev/ttyS0",
79#ifdef BSP_UART_IOBASE_COM1
80      BSP_uart_termios_isr_com1
81#else
82      0
83#endif
84    },
85    { "/dev/ttyS1",
86#ifdef BSP_UART_IOBASE_COM2
87      BSP_uart_termios_isr_com2
88#else
89      0
90#endif
91    },
92};
93
94/*-------------------------------------------------------------------------+
95| Console device driver INITIALIZE entry point.
96+--------------------------------------------------------------------------+
97| Initilizes the I/O console (keyboard + VGA display) driver.
98+--------------------------------------------------------------------------*/
99rtems_device_driver console_initialize(
100  rtems_device_major_number major,
101  rtems_device_minor_number minor,
102  void                      *arg
103)
104{
105  rtems_status_code status;
106
107  /*
108   *  The video was initialized in the start.s code and does not need
109   *  to be reinitialized.
110   */
111
112  /*
113   * Set up TERMIOS
114   */
115  rtems_termios_initialize();
116
117  /*
118   * Do device-specific initialization
119   */
120
121  /* RTEMS calls this routine once with 'minor'==0; loop through
122   * all known instances...
123   */
124
125  for (minor=0; minor < sizeof(ttyS)/sizeof(ttyS[0]); minor++) {
126    char *nm;
127    /*
128     * Skip ports (possibly not supported by BSP...) we have no ISR for
129     */
130    if ( ! ttyS[minor].isr )
131      continue;
132    /*
133     * Register the device
134     */
135    status = rtems_io_register_name ((nm=ttyS[minor].name), major, minor);
136    if ( RTEMS_SUCCESSFUL==status && BSPConsolePort == minor) {
137      printk("Registering /dev/console as minor %d (==%s)\n",
138              minor,
139              ttyS[minor].name);
140      /* also register an alias */
141      status = rtems_io_register_name ( (nm="/dev/console"), major, minor);
142    }
143
144    if (status != RTEMS_SUCCESSFUL) {
145      printk("Error registering %s!\n",nm);
146      rtems_fatal_error_occurred (status);
147    }
148  }
149
150  return RTEMS_SUCCESSFUL;
151} /* console_initialize */
152
153static int console_first_open(int major, int minor, void *arg)
154{
155  rtems_status_code status;
156
157  /* must not open a minor device we have no ISR for */
158  assert( minor>=0 && minor < sizeof(ttyS)/sizeof(ttyS[0]) && ttyS[minor].isr );
159
160  /* 9600-8-N-1 */
161  BSP_uart_init(minor, 9600, 0);
162  status = BSP_uart_install_isr(minor, ttyS[minor].isr);
163  if (!status) {
164    printk("Error installing serial console interrupt handler for '%s'!\n",
165      ttyS[minor].name);
166    rtems_fatal_error_occurred(status);
167  }
168
169  /*
170   * Pass data area info down to driver
171   */
172  BSP_uart_termios_set(minor, ((rtems_libio_open_close_args_t *)arg)->iop->data1);
173
174  /* Enable interrupts  on channel */
175  BSP_uart_intr_ctrl(minor, BSP_UART_INTR_CTRL_TERMIOS);
176
177  return 0;
178}
179
180static int console_last_close(int major, int minor, void *arg)
181{
182  BSP_uart_remove_isr(minor, ttyS[minor].isr);
183  return 0;
184}
185
186/*-------------------------------------------------------------------------+
187| Console device driver OPEN entry point
188+--------------------------------------------------------------------------*/
189rtems_device_driver console_open(
190  rtems_device_major_number major,
191  rtems_device_minor_number minor,
192  void                      *arg
193)
194{
195  rtems_status_code              status;
196  static rtems_termios_callbacks cb =
197#if defined(USE_POLLED_IO)
198  {
199     NULL,                              /* firstOpen */
200     NULL,                              /* lastClose */
201     NULL,                              /* pollRead */
202     BSP_uart_termios_write_polled,     /* write */
203     conSetAttr,                        /* setAttributes */
204     NULL,                              /* stopRemoteTx */
205     NULL,                              /* startRemoteTx */
206     TERMIOS_POLLED                     /* outputUsesInterrupts */
207  };
208#else
209  {
210     console_first_open,                /* firstOpen */
211     console_last_close,                /* lastClose */
212#if ( TERMIOS_OUTPUT_MODE == TERMIOS_TASK_DRIVEN )
213     BSP_uart_termios_read_com,         /* pollRead */
214#else
215     NULL,                              /* pollRead */
216#endif
217     BSP_uart_termios_write_com,        /* write */
218     conSetAttr,                        /* setAttributes */
219     NULL,                              /* stopRemoteTx */
220     NULL,                              /* startRemoteTx */
221     TERMIOS_OUTPUT_MODE                /* outputUsesInterrupts */
222  };
223#endif
224
225  status = rtems_termios_open (major, minor, arg, &cb);
226
227  if (status != RTEMS_SUCCESSFUL) {
228    printk("Error opening console device\n");
229    return status;
230  }
231
232  return RTEMS_SUCCESSFUL;
233}
234
235/*-------------------------------------------------------------------------+
236| Console device driver CLOSE entry point
237+--------------------------------------------------------------------------*/
238rtems_device_driver
239console_close(
240  rtems_device_major_number major,
241  rtems_device_minor_number minor,
242  void                      *arg
243)
244{
245  rtems_device_driver res = RTEMS_SUCCESSFUL;
246
247  res =  rtems_termios_close (arg);
248
249  return res;
250} /* console_close */
251
252/*-------------------------------------------------------------------------+
253| Console device driver READ entry point.
254+--------------------------------------------------------------------------+
255| Read characters from the I/O console. We only have stdin.
256+--------------------------------------------------------------------------*/
257rtems_device_driver console_read(
258  rtems_device_major_number major,
259  rtems_device_minor_number minor,
260  void                      *arg
261)
262{
263  return rtems_termios_read (arg);
264} /* console_read */
265
266/*-------------------------------------------------------------------------+
267| Console device driver WRITE entry point.
268+--------------------------------------------------------------------------+
269| Write characters to the I/O console. Stderr and stdout are the same.
270+--------------------------------------------------------------------------*/
271rtems_device_driver console_write(
272  rtems_device_major_number major,
273  rtems_device_minor_number minor,
274  void                      *arg
275)
276{
277  return rtems_termios_write (arg);
278} /* console_write */
279
280/*
281 * Handle ioctl request.
282 */
283rtems_device_driver console_control(
284  rtems_device_major_number major,
285  rtems_device_minor_number minor,
286  void                      *arg
287)
288{
289/* does the BSP support break callbacks ? */
290#if defined(BIOCSETBREAKCB) && defined(BIOCGETBREAKCB)
291  rtems_libio_ioctl_args_t  *ioa=arg;
292  switch (ioa->command) {
293    case BIOCSETBREAKCB: return BSP_uart_set_break_cb(minor, ioa);
294    case BIOCGETBREAKCB: return BSP_uart_get_break_cb(minor, ioa);
295    default:             break;
296  }
297#endif
298  return rtems_termios_ioctl (arg);
299}
300
301static int conSetAttr(
302  int                   minor,
303  const struct termios *t
304)
305{
306  rtems_termios_baud_t baud;
307
308  baud = rtems_termios_baud_to_number(t->c_cflag & CBAUD);
309  if ( baud > 115200 )
310    rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR);
311
312  BSP_uart_set_baud(minor, baud);
313
314  return 0;
315}
Note: See TracBrowser for help on using the repository browser.