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

5
Last change on this file since b02c77c6 was b02c77c6, checked in by Joel Sherrill <joel@…>, on Mar 29, 2016 at 5:54:00 PM

powerpc/shared/console/console.c: Add include of <rtems/console.h> to fix warning

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