source: rtems/c/src/lib/libbsp/powerpc/shared/console/console.c @ 1f8ac4a

4.104.115
Last change on this file since 1f8ac4a was 1f8ac4a, checked in by Till Straumann <strauman@…>, on Nov 3, 2008 at 9:10:25 PM

2008-11-03 Till Straumann <strauman@…>

PR 1332: call BSP_uart_termios_set()/BSP_uart_intr_ctrl()
only from 'firstOpen' and only if this is a serial console.

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