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

4.104.114.84.95
Last change on this file since 69ed59f was 69ed59f, checked in by Joel Sherrill <joel.sherrill@…>, on May 14, 2002 at 5:10:17 PM

2001-05-14 Till Straumann <strauman@…>

  • bootloader/misc.c, console/Makefile.am, console/console.c, console/consoleIo.h, console/inch.c, console/polled_io.c, console/uart.c, console/uart.h, include/bsp.h, irq/Makefile.am, irq/irq.c, irq/irq.h, irq/irq_init.c, openpic/openpic.c, openpic/openpic.h, pci/Makefile.am, pci/pci.c, pci/pci.h, residual/Makefile.am, start/start.S, startup/bspstart.c, vectors/vectors.S, vectors/vectors.h, vectors/vectors_init.c: Per PR216, "libbsp/powerpc/shared" BSP has been modified considerably with the goal to make it more flexible and reusable by other BSPs. The main strategies were:
    • eliminate hardcoded base addresses; devices use offsets and a BSP defined base address.
    • separate functionality into different files (e.g. reboot from inch.c to reboot.c) which can be overridden by a 'derived' BSP.
    • separate initialization code into separate files (e.g. PCI bridge detection/initialization was separated from the more generic PCI access routines), also to make it easier for 'derived' BSPs to substitute their own initialization code.

There are also a couple of enhancements and fixes:

  • IRQ handling code now has a hook for attaching a VME bridge.
  • OpenPIC is now explicitely initialized (polarities, senses). Eliminated the implicit assumption on the presence of an ISA PIC.
  • UART and console driver now supports more than 1 port. The current maximum of 2 can easily be extended by enlarging a table (it would even be easier if the ISR API was not broken by design).
  • fixed polled_io.c so it correctly supports console on COM2
  • fixed TLB invalidation code (start.S).
  • exception handler prints a stack backtrace.
  • added BSP_pciFindDevice() to scan the pci bus for a particular vendor/device/instance.
  • Property mode set to 100644
File size: 8.6 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
29#undef __assert
30void __assert (const char *file, int line, const char *msg);
31extern int close(int fd);
32
33#include <bsp.h>
34#include <bsp/irq.h>
35#include <rtems/bspIo.h>
36#include <rtems/libio.h>
37#include <termios.h>
38#include <bsp/uart.h>
39#include <bsp/consoleIo.h>
40#include <rtems/bspIo.h>        /* printk */
41
42/* Definitions for BSPConsolePort */
43/*
44 * Possible value for console input/output :
45 *      BSP_CONSOLE_PORT_CONSOLE
46 *      BSP_UART_COM1
47 *      BSP_UART_COM2
48 */
49int BSPConsolePort = BSP_CONSOLE_PORT;
50
51int BSPBaseBaud    = BSP_UART_BAUD_BASE;
52
53/*-------------------------------------------------------------------------+
54| External Prototypes
55+--------------------------------------------------------------------------*/
56
57static int  conSetAttr(int minor, const struct termios *);
58
59void __assert (const char *file, int line, const char *msg)
60{
61    static   char exit_msg[] = "EXECUTIVE SHUTDOWN! Any key to reboot...";
62  unsigned char  ch;
63   
64  /*
65   * Note we cannot call exit or printf from here,
66   * assert can fail inside ISR too
67   */
68
69   /*
70    * Close console
71   */
72  close(2);
73  close(1);
74  close(0);
75
76  printk("\nassert failed: %s: ", file);
77  printk("%d: ", line);
78  printk("%s\n\n", msg);
79  printk(exit_msg);
80  ch = debug_getc();
81  printk("\n\n");
82  rtemsReboot();
83
84}
85
86typedef struct TtySTblRec_ {
87                char    *name;
88                void    (*isr)(void); /* STUPID API doesn't pass a parameter :-( */
89} TtySTblRec, *TtySTbl;
90
91static TtySTblRec ttyS[]={
92                { "/dev/ttyS0",
93#ifdef BSP_UART_IOBASE_COM1
94                  BSP_uart_termios_isr_com1
95#else
96                  0
97#endif
98                },
99                { "/dev/ttyS1",
100#ifdef BSP_UART_IOBASE_COM2
101                  BSP_uart_termios_isr_com2
102#else
103                  0
104#endif
105                },
106};
107
108
109/*-------------------------------------------------------------------------+
110| Console device driver INITIALIZE entry point.
111+--------------------------------------------------------------------------+
112| Initilizes the I/O console (keyboard + VGA display) driver.
113+--------------------------------------------------------------------------*/
114rtems_device_driver
115console_initialize(rtems_device_major_number major,
116                   rtems_device_minor_number minor,
117                   void                      *arg)
118{
119  rtems_status_code status;
120
121  /*
122   *  The video was initialized in the start.s code and does not need
123   *  to be reinitialized.
124   */
125
126  /*
127   * Set up TERMIOS
128   */
129  rtems_termios_initialize ();
130     
131  /*
132   * Do device-specific initialization
133   */
134
135  /* RTEMS calls this routine once with 'minor'==0; loop through
136   * all known instances...
137   */
138     
139  for (minor=0; minor < sizeof(ttyS)/sizeof(ttyS[0]); minor++) {
140        char *nm;
141          /*
142           * Skip ports (possibly not supported by BSP...) we have no ISR for
143           */
144          if ( ! ttyS[minor].isr )
145                continue;
146          /*
147           * Register the device
148           */
149          status = rtems_io_register_name ((nm=ttyS[minor].name), major, minor);
150          if ( RTEMS_SUCCESSFUL==status && BSPConsolePort == minor)
151                {
152                  printk("Registering /dev/console as minor %i (==%s)\n",
153                                                        minor,
154                                                        ttyS[minor].name);
155                  /* also register an alias */
156                  status = rtems_io_register_name (
157                                                        (nm="/dev/console"),
158                                                        major,
159                                                        minor);
160                }
161          if (status != RTEMS_SUCCESSFUL)
162                {
163                  printk("Error registering %s!\n",nm);
164                  rtems_fatal_error_occurred (status);
165                }
166
167  }
168  return RTEMS_SUCCESSFUL;
169} /* console_initialize */
170
171static int console_first_open(int major, int minor, void *arg)
172{
173  rtems_status_code status;
174
175          /* must not open a minor device we have no ISR for */
176          assert( minor>=0 && minor < sizeof(ttyS)/sizeof(ttyS[0]) && ttyS[minor].isr );
177
178          /* 9600-8-N-1 */
179          BSP_uart_init(minor, 9600, 0);
180          status = BSP_uart_install_isr(minor, ttyS[minor].isr);
181          if (!status)
182                {
183                  printk("Error installing serial console interrupt handler for '%s'!\n",
184                                ttyS[minor].name);
185                  rtems_fatal_error_occurred(status);
186                }
187          return 0;
188}
189
190
191static int console_last_close(int major, int minor, void *arg)
192{
193  BSP_uart_remove_isr(minor, ttyS[minor].isr);
194  return 0;
195}
196
197/*-------------------------------------------------------------------------+
198| Console device driver OPEN entry point
199+--------------------------------------------------------------------------*/
200rtems_device_driver
201console_open(rtems_device_major_number major,
202                rtems_device_minor_number minor,
203                void                      *arg)
204{
205  rtems_status_code              status;
206  static rtems_termios_callbacks cb = 
207  {
208    console_first_open,                 /* firstOpen */
209    console_last_close,                 /* lastClose */
210    NULL,                                               /* pollRead */
211    BSP_uart_termios_write_com, /* write */
212    conSetAttr,                                 /* setAttributes */
213    NULL,                                               /* stopRemoteTx */
214    NULL,                                               /* startRemoteTx */
215    1                                                   /* outputUsesInterrupts */
216  };
217
218  status = rtems_termios_open (major, minor, arg, &cb);
219
220  if(status != RTEMS_SUCCESSFUL)
221    {
222      printk("Error openning console device\n");
223      return status;
224    }
225
226  /*
227   * Pass data area info down to driver
228   */
229  BSP_uart_termios_set(minor, 
230                         ((rtems_libio_open_close_args_t *)arg)->iop->data1);
231  /* Enable interrupts  on channel */
232  BSP_uart_intr_ctrl(minor, BSP_UART_INTR_CTRL_TERMIOS);
233
234  return RTEMS_SUCCESSFUL;
235}
236
237/*-------------------------------------------------------------------------+
238| Console device driver CLOSE entry point
239+--------------------------------------------------------------------------*/
240rtems_device_driver
241console_close(rtems_device_major_number major,
242              rtems_device_minor_number minor,
243              void                      *arg)
244{
245  rtems_device_driver res = RTEMS_SUCCESSFUL;
246
247  res =  rtems_termios_close (arg);
248 
249  return res;
250} /* console_close */
251
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
259console_read(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/*-------------------------------------------------------------------------+
269| Console device driver WRITE entry point.
270+--------------------------------------------------------------------------+
271| Write characters to the I/O console. Stderr and stdout are the same.
272+--------------------------------------------------------------------------*/
273rtems_device_driver
274console_write(rtems_device_major_number major,
275              rtems_device_minor_number minor,
276              void                    * arg)
277{
278
279  return rtems_termios_write (arg);
280 
281} /* console_write */
282
283
284 
285/*
286 * Handle ioctl request.
287 */
288rtems_device_driver
289console_control(rtems_device_major_number major,
290                rtems_device_minor_number minor,
291                void                      * arg
292)
293{ 
294  return rtems_termios_ioctl (arg);
295}
296
297static int
298conSetAttr(int minor, const struct termios *t)
299{
300  int baud;
301
302  switch (t->c_cflag & CBAUD) 
303    {
304    case B50:   
305      baud = 50;
306      break;
307    case B75:   
308      baud = 75;       
309      break;
310    case B110: 
311      baud = 110;       
312      break;
313    case B134: 
314      baud = 134;       
315      break;
316    case B150: 
317      baud = 150;       
318      break;
319    case B200:
320      baud = 200;       
321      break;
322    case B300: 
323      baud = 300;
324      break;
325    case B600: 
326      baud = 600;       
327      break;
328    case B1200: 
329      baud = 1200;
330      break;
331    case B1800: 
332      baud = 1800;     
333      break;
334    case B2400: 
335      baud = 2400;
336      break;
337    case B4800: 
338      baud = 4800;
339      break;
340    case B9600: 
341      baud = 9600;
342      break;
343    case B19200:
344      baud = 19200;
345      break;
346    case B38400:
347      baud = 38400;
348      break;
349    case B57600:       
350      baud = 57600;
351      break;
352    case B115200:
353      baud = 115200;
354      break;
355    default:
356      baud = 0;
357      rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR);
358      return 0;
359    }
360
361  BSP_uart_set_baud(minor, baud);
362
363  return 0;
364}
Note: See TracBrowser for help on using the repository browser.