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

Last change on this file since 6ad36947 was 6ad36947, checked in by Joel Sherrill <joel.sherrill@…>, on Apr 10, 2003 at 4:35:13 PM

2003-04-10 Till Straumann <strauman@…>

PR 379/bsps

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