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

4.104.114.84.95
Last change on this file since 20b349f was 4f3e4f33, checked in by Joel Sherrill <joel.sherrill@…>, on 02/20/03 at 21:32:07

2003-02-20 Till Straumann <strauman@…>

PR 349/bsps

  • console/console.c, console/uart.c, console/uart.h: implement IOCTLs for the serial (UART) console to install/retrieve a BREAK-IRQ callback. The callback routine (if installed) is invoked from the UART ISR when a BREAK interrupt is detected. This can be used e.g. to enforce a "hotkey" reboot a la vxWorks Ctrl-X (although we use the serial line break condition) NOTE: The callback runs in ISR context.
  • Property mode set to 100644
File size: 8.4 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.OARcorp.com/rtems/license.html.
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 <termios.h>
36#include <bsp/uart.h>
37#include <bsp/consoleIo.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| External Prototypes
53+--------------------------------------------------------------------------*/
54
55static int  conSetAttr(int minor, const struct termios *);
56
57typedef struct TtySTblRec_ {
58                char    *name;
59                void    (*isr)(void); /* STUPID API doesn't pass a parameter :-( */
60} TtySTblRec, *TtySTbl;
61
62static TtySTblRec ttyS[]={
63                { "/dev/ttyS0",
64#ifdef BSP_UART_IOBASE_COM1
65                  BSP_uart_termios_isr_com1
66#else
67                  0
68#endif
69                },
70                { "/dev/ttyS1",
71#ifdef BSP_UART_IOBASE_COM2
72                  BSP_uart_termios_isr_com2
73#else
74                  0
75#endif
76                },
77};
78
79
80/*-------------------------------------------------------------------------+
81| Console device driver INITIALIZE entry point.
82+--------------------------------------------------------------------------+
83| Initilizes the I/O console (keyboard + VGA display) driver.
84+--------------------------------------------------------------------------*/
85rtems_device_driver
86console_initialize(rtems_device_major_number major,
87                   rtems_device_minor_number minor,
88                   void                      *arg)
89{
90  rtems_status_code status;
91
92  /*
93   *  The video was initialized in the start.s code and does not need
94   *  to be reinitialized.
95   */
96
97  /*
98   * Set up TERMIOS
99   */
100  rtems_termios_initialize ();
101     
102  /*
103   * Do device-specific initialization
104   */
105
106  /* RTEMS calls this routine once with 'minor'==0; loop through
107   * all known instances...
108   */
109     
110  for (minor=0; minor < sizeof(ttyS)/sizeof(ttyS[0]); minor++) {
111        char *nm;
112          /*
113           * Skip ports (possibly not supported by BSP...) we have no ISR for
114           */
115          if ( ! ttyS[minor].isr )
116                continue;
117          /*
118           * Register the device
119           */
120          status = rtems_io_register_name ((nm=ttyS[minor].name), major, minor);
121          if ( RTEMS_SUCCESSFUL==status && BSPConsolePort == minor)
122                {
123                  printk("Registering /dev/console as minor %i (==%s)\n",
124                                                        minor,
125                                                        ttyS[minor].name);
126                  /* also register an alias */
127                  status = rtems_io_register_name (
128                                                        (nm="/dev/console"),
129                                                        major,
130                                                        minor);
131                }
132          if (status != RTEMS_SUCCESSFUL)
133                {
134                  printk("Error registering %s!\n",nm);
135                  rtems_fatal_error_occurred (status);
136                }
137
138  }
139  return RTEMS_SUCCESSFUL;
140} /* console_initialize */
141
142static int console_first_open(int major, int minor, void *arg)
143{
144  rtems_status_code status;
145
146          /* must not open a minor device we have no ISR for */
147          assert( minor>=0 && minor < sizeof(ttyS)/sizeof(ttyS[0]) && ttyS[minor].isr );
148
149          /* 9600-8-N-1 */
150          BSP_uart_init(minor, 9600, 0);
151          status = BSP_uart_install_isr(minor, ttyS[minor].isr);
152          if (!status)
153                {
154                  printk("Error installing serial console interrupt handler for '%s'!\n",
155                                ttyS[minor].name);
156                  rtems_fatal_error_occurred(status);
157                }
158          return 0;
159}
160
161
162static int console_last_close(int major, int minor, void *arg)
163{
164  BSP_uart_remove_isr(minor, ttyS[minor].isr);
165  return 0;
166}
167
168/*-------------------------------------------------------------------------+
169| Console device driver OPEN entry point
170+--------------------------------------------------------------------------*/
171rtems_device_driver
172console_open(rtems_device_major_number major,
173                rtems_device_minor_number minor,
174                void                      *arg)
175{
176  rtems_status_code              status;
177  static rtems_termios_callbacks cb =
178  {
179    console_first_open,                 /* firstOpen */
180    console_last_close,                 /* lastClose */
181    NULL,                                               /* pollRead */
182    BSP_uart_termios_write_com, /* write */
183    conSetAttr,                                 /* setAttributes */
184    NULL,                                               /* stopRemoteTx */
185    NULL,                                               /* startRemoteTx */
186    1                                                   /* outputUsesInterrupts */
187  };
188
189  status = rtems_termios_open (major, minor, arg, &cb);
190
191  if(status != RTEMS_SUCCESSFUL)
192    {
193      printk("Error openning console device\n");
194      return status;
195    }
196
197  /*
198   * Pass data area info down to driver
199   */
200  BSP_uart_termios_set(minor,
201                         ((rtems_libio_open_close_args_t *)arg)->iop->data1);
202  /* Enable interrupts  on channel */
203  BSP_uart_intr_ctrl(minor, BSP_UART_INTR_CTRL_TERMIOS);
204
205  return RTEMS_SUCCESSFUL;
206}
207
208/*-------------------------------------------------------------------------+
209| Console device driver CLOSE entry point
210+--------------------------------------------------------------------------*/
211rtems_device_driver
212console_close(rtems_device_major_number major,
213              rtems_device_minor_number minor,
214              void                      *arg)
215{
216  rtems_device_driver res = RTEMS_SUCCESSFUL;
217
218  res =  rtems_termios_close (arg);
219 
220  return res;
221} /* console_close */
222
223 
224/*-------------------------------------------------------------------------+
225| Console device driver READ entry point.
226+--------------------------------------------------------------------------+
227| Read characters from the I/O console. We only have stdin.
228+--------------------------------------------------------------------------*/
229rtems_device_driver
230console_read(rtems_device_major_number major,
231             rtems_device_minor_number minor,
232             void                      *arg)
233{
234
235  return rtems_termios_read (arg);
236} /* console_read */
237 
238
239/*-------------------------------------------------------------------------+
240| Console device driver WRITE entry point.
241+--------------------------------------------------------------------------+
242| Write characters to the I/O console. Stderr and stdout are the same.
243+--------------------------------------------------------------------------*/
244rtems_device_driver
245console_write(rtems_device_major_number major,
246              rtems_device_minor_number minor,
247              void                    * arg)
248{
249
250  return rtems_termios_write (arg);
251 
252} /* console_write */
253
254
255 
256/*
257 * Handle ioctl request.
258 */
259rtems_device_driver
260console_control(rtems_device_major_number       major,
261                rtems_device_minor_number                       minor,
262                void                                            *arg
263)
264{
265/* does the BSP support break callbacks ? */
266#if defined(BIOCSETBREAKCB) && defined(BIOCGETBREAKCB)
267rtems_libio_ioctl_args_t        *ioa=arg;
268        switch (ioa->command) {
269                        case BIOCSETBREAKCB:
270                                return BSP_uart_set_break_cb(minor, ioa);
271                        case BIOCGETBREAKCB:
272                                return BSP_uart_get_break_cb(minor, ioa);
273                       
274                        default:
275                                break;
276        }
277#endif
278  return rtems_termios_ioctl (arg);
279}
280
281static int
282conSetAttr(int minor, const struct termios *t)
283{
284  int baud;
285
286  switch (t->c_cflag & CBAUD)
287    {
288    case B50:   
289      baud = 50;
290      break;
291    case B75:   
292      baud = 75;       
293      break;
294    case B110: 
295      baud = 110;       
296      break;
297    case B134: 
298      baud = 134;       
299      break;
300    case B150: 
301      baud = 150;       
302      break;
303    case B200:
304      baud = 200;       
305      break;
306    case B300: 
307      baud = 300;
308      break;
309    case B600: 
310      baud = 600;       
311      break;
312    case B1200:
313      baud = 1200;
314      break;
315    case B1800:
316      baud = 1800;     
317      break;
318    case B2400:
319      baud = 2400;
320      break;
321    case B4800:
322      baud = 4800;
323      break;
324    case B9600:
325      baud = 9600;
326      break;
327    case B19200:
328      baud = 19200;
329      break;
330    case B38400:
331      baud = 38400;
332      break;
333    case B57600:       
334      baud = 57600;
335      break;
336    case B115200:
337      baud = 115200;
338      break;
339    default:
340      baud = 0;
341      rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR);
342      return 0;
343    }
344
345  BSP_uart_set_baud(minor, baud);
346
347  return 0;
348}
Note: See TracBrowser for help on using the repository browser.