source: rtems/c/src/lib/libbsp/powerpc/shared/console/console.c @ 4ac1d23

4.104.114.95
Last change on this file since 4ac1d23 was 4ac1d23, checked in by Joel Sherrill <joel.sherrill@…>, on May 22, 2008 at 10:45:14 PM

2008-05-22 Joel Sherrill <joel.sherrill@…>

  • shared/console/console.c: Fix typo.
  • 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  return 0;
171}
172
173static int console_last_close(int major, int minor, void *arg)
174{
175  BSP_uart_remove_isr(minor, ttyS[minor].isr);
176  return 0;
177}
178
179/*-------------------------------------------------------------------------+
180| Console device driver OPEN entry point
181+--------------------------------------------------------------------------*/
182rtems_device_driver console_open(
183  rtems_device_major_number major,
184  rtems_device_minor_number minor,
185  void                      *arg
186)
187{
188  rtems_status_code              status;
189  static rtems_termios_callbacks cb =
190#if defined(USE_POLLED_IO)
191  { 
192     NULL,                              /* firstOpen */
193     NULL,                              /* lastClose */
194     NULL,                              /* pollRead */
195     BSP_uart_termios_write_polled,     /* write */
196     conSetAttr,                        /* setAttributes */
197     NULL,                              /* stopRemoteTx */
198     NULL,                              /* startRemoteTx */
199     TERMIOS_POLLED                     /* outputUsesInterrupts */
200  };
201#else
202  { 
203     console_first_open,                /* firstOpen */
204     console_last_close,                /* lastClose */
205#if ( TERMIOS_OUTPUT_MODE == TERMIOS_TASK_DRIVEN )
206     BSP_uart_termios_read_com,         /* pollRead */
207#else
208     NULL,                              /* pollRead */
209#endif
210     BSP_uart_termios_write_com,        /* write */
211     conSetAttr,                        /* setAttributes */
212     NULL,                              /* stopRemoteTx */
213     NULL,                              /* startRemoteTx */
214     TERMIOS_OUTPUT_MODE                /* outputUsesInterrupts */
215  };
216#endif
217
218  status = rtems_termios_open (major, minor, arg, &cb);
219
220  if (status != RTEMS_SUCCESSFUL) {
221    printk("Error opening console device\n");
222    return status;
223  }
224
225  /*
226   * Pass data area info down to driver
227   */
228  BSP_uart_termios_set(minor,
229       ((rtems_libio_open_close_args_t *)arg)->iop->data1);
230  /* Enable interrupts  on channel */
231  BSP_uart_intr_ctrl(minor, BSP_UART_INTR_CTRL_TERMIOS);
232
233  return RTEMS_SUCCESSFUL;
234}
235
236/*-------------------------------------------------------------------------+
237| Console device driver CLOSE entry point
238+--------------------------------------------------------------------------*/
239rtems_device_driver
240console_close(
241  rtems_device_major_number major,
242  rtems_device_minor_number minor,
243  void                      *arg
244)
245{
246  rtems_device_driver res = RTEMS_SUCCESSFUL;
247
248  res =  rtems_termios_close (arg);
249
250  return res;
251} /* console_close */
252
253/*-------------------------------------------------------------------------+
254| Console device driver READ entry point.
255+--------------------------------------------------------------------------+
256| Read characters from the I/O console. We only have stdin.
257+--------------------------------------------------------------------------*/
258rtems_device_driver console_read(
259  rtems_device_major_number major,
260  rtems_device_minor_number minor,
261  void                      *arg
262)
263{
264  return rtems_termios_read (arg);
265} /* console_read */
266
267/*-------------------------------------------------------------------------+
268| Console device driver WRITE entry point.
269+--------------------------------------------------------------------------+
270| Write characters to the I/O console. Stderr and stdout are the same.
271+--------------------------------------------------------------------------*/
272rtems_device_driver console_write(
273  rtems_device_major_number major,
274  rtems_device_minor_number minor,
275  void                      *arg
276)
277{
278  return rtems_termios_write (arg);
279} /* console_write */
280
281/*
282 * Handle ioctl request.
283 */
284rtems_device_driver console_control(
285  rtems_device_major_number major,
286  rtems_device_minor_number minor,
287  void                      *arg
288)
289{
290/* does the BSP support break callbacks ? */
291#if defined(BIOCSETBREAKCB) && defined(BIOCGETBREAKCB)
292  rtems_libio_ioctl_args_t  *ioa=arg;
293  switch (ioa->command) {
294    case BIOCSETBREAKCB: return BSP_uart_set_break_cb(minor, ioa);
295    case BIOCGETBREAKCB: return BSP_uart_get_break_cb(minor, ioa);
296    default:             break;
297  }
298#endif
299  return rtems_termios_ioctl (arg);
300}
301
302static int conSetAttr(
303  int                   minor,
304  const struct termios *t
305)
306{
307  int baud;
308
309  baud = termios_baud_to_number(t->c_cflag & CBAUD);
310  if ( baud > 115200 )
311    rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR);
312
313  BSP_uart_set_baud(minor, baud);
314
315  return 0;
316}
Note: See TracBrowser for help on using the repository browser.