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

5
Last change on this file since c2a4b8bf was c2a4b8bf, checked in by Sebastian Huber <sebastian.huber@…>, on 07/19/16 at 07:42:26

bsps/powerpc: Fix shared console driver

The Termios modes are now an emum. Do not use them in #if expressions.

Close #2762.

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