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

4.104.114.84.95
Last change on this file since 20603d1 was 20603d1, checked in by Joel Sherrill <joel.sherrill@…>, on Apr 3, 2002 at 2:22:16 PM

2002-04-02 Ralf Corsepius <corsepiu@…>

  • residual/residual.c: Include <string.h>.
  • vectors/vectors_init.c: Include <rtems/bspIo.h> for printk.
  • bootloader/mm.c: Ditto.
  • bootloader/pci.c: Ditto.
  • console/console.c: Ditto.
  • openpic/openpic.c: Ditto.
  • Property mode set to 100644
File size: 8.8 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 * http://pandora.ist.utl.pt
13 *
14 * Instituto Superior Tecnico * Lisboa * PORTUGAL
15 *  The license and distribution terms for this file may be
16 *  found in found in the file LICENSE in this distribution or at
17 *  http://www.OARcorp.com/rtems/license.html.
18 *
19 * $Id$
20 */
21 
22#include <stdlib.h>
23#include <assert.h>
24#include <stdlib.h>
25
26#undef __assert
27void __assert (const char *file, int line, const char *msg);
28extern int close(int fd);
29
30#include <bsp.h>
31#include <bsp/irq.h>
32#include <rtems/bspIo.h>
33#include <rtems/libio.h>
34#include <termios.h>
35#include <bsp/uart.h>
36#include <bsp/consoleIo.h>
37
38/* Definitions for BSPConsolePort */
39#define BSP_CONSOLE_PORT_CONSOLE (-1)
40#define BSP_CONSOLE_PORT_COM1    (BSP_UART_COM1)
41#define BSP_CONSOLE_PORT_COM2    (BSP_UART_COM2)
42/*
43 * Possible value for console input/output :
44 *      BSP_CONSOLE_PORT_CONSOLE
45 *      BSP_UART_COM1
46 *      BSP_UART_COM2
47 */
48
49int BSPConsolePort = BSP_UART_COM1;
50
51/* int BSPConsolePort = BSP_UART_COM2;  */
52int BSPBaseBaud    = 115200;
53
54/*-------------------------------------------------------------------------+
55| External Prototypes
56+--------------------------------------------------------------------------*/
57
58static int  conSetAttr(int minor, const struct termios *);
59static void isr_on(const rtems_irq_connect_data *);
60static void isr_off(const rtems_irq_connect_data *);
61static int  isr_is_on(const rtems_irq_connect_data *);
62
63
64static rtems_irq_connect_data console_isr_data = {BSP_ISA_UART_COM1_IRQ,
65                                                   BSP_uart_termios_isr_com1,
66                                                   isr_on,
67                                                   isr_off,
68                                                   isr_is_on};
69
70static void
71isr_on(const rtems_irq_connect_data *unused)
72{
73  return;
74}
75                                                   
76static void
77isr_off(const rtems_irq_connect_data *unused)
78{
79  return;
80}
81
82static int
83isr_is_on(const rtems_irq_connect_data *irq)
84{
85  return BSP_irq_enabled_at_i8259s(irq->name);
86}
87
88void __assert (const char *file, int line, const char *msg)
89{
90    static   char exit_msg[] = "EXECUTIVE SHUTDOWN! Any key to reboot...";
91  unsigned char  ch;
92   
93  /*
94   * Note we cannot call exit or printf from here,
95   * assert can fail inside ISR too
96   */
97
98   /*
99    * Close console
100   */
101  close(2);
102  close(1);
103  close(0);
104
105  printk("\nassert failed: %s: ", file);
106  printk("%d: ", line);
107  printk("%s\n\n", msg);
108  printk(exit_msg);
109  ch = debug_getc();
110  printk("\n\n");
111  rtemsReboot();
112
113}
114
115
116/*-------------------------------------------------------------------------+
117| Console device driver INITIALIZE entry point.
118+--------------------------------------------------------------------------+
119| Initilizes the I/O console (keyboard + VGA display) driver.
120+--------------------------------------------------------------------------*/
121rtems_device_driver
122console_initialize(rtems_device_major_number major,
123                   rtems_device_minor_number minor,
124                   void                      *arg)
125{
126  rtems_status_code status;
127
128  /*
129   *  The video was initialized in the start.s code and does not need
130   *  to be reinitialized.
131   */
132
133
134  /*
135   * Set up TERMIOS
136   */
137  rtems_termios_initialize ();
138     
139  /*
140   * Do device-specific initialization
141   */
142     
143  /* 9600-8-N-1 */
144  BSP_uart_init(BSPConsolePort, 9600, 0);
145     
146     
147  /* Set interrupt handler */
148  if(BSPConsolePort == BSP_UART_COM1)
149    {
150      console_isr_data.name = BSP_ISA_UART_COM1_IRQ;
151      console_isr_data.hdl  = BSP_uart_termios_isr_com1;
152         
153    }
154  else
155    {
156      assert(BSPConsolePort == BSP_UART_COM2);
157      console_isr_data.name = BSP_ISA_UART_COM2_IRQ;
158      console_isr_data.hdl  = BSP_uart_termios_isr_com2;
159    }
160
161  status = BSP_install_rtems_irq_handler(&console_isr_data);
162
163  if (!status){
164    printk("Error installing serial console interrupt handler!\n");
165    rtems_fatal_error_occurred(status);
166  }
167  /*
168   * Register the device
169   */
170  status = rtems_io_register_name ("/dev/console", major, 0);
171  if (status != RTEMS_SUCCESSFUL)
172    {
173      printk("Error registering console device!\n");
174      rtems_fatal_error_occurred (status);
175    }
176
177  if(BSPConsolePort == BSP_UART_COM1)
178    {
179      printk("Initialized console on port COM1 9600-8-N-1\n\n");
180    }
181  else
182    {
183      printk("Initialized console on port COM2 9600-8-N-1\n\n");
184    }
185  return RTEMS_SUCCESSFUL;
186} /* console_initialize */
187
188
189static int console_last_close(int major, int minor, void *arg)
190{
191  BSP_remove_rtems_irq_handler (&console_isr_data);
192
193  return 0;
194}
195
196/*-------------------------------------------------------------------------+
197| Console device driver OPEN entry point
198+--------------------------------------------------------------------------*/
199rtems_device_driver
200console_open(rtems_device_major_number major,
201                rtems_device_minor_number minor,
202                void                      *arg)
203{
204  rtems_status_code              status;
205  static rtems_termios_callbacks cb = 
206  {
207    NULL,                     /* firstOpen */
208    console_last_close,       /* lastClose */
209    NULL,                     /* pollRead */
210    BSP_uart_termios_write_com1, /* write */
211    conSetAttr,               /* setAttributes */
212    NULL,                     /* stopRemoteTx */
213    NULL,                     /* startRemoteTx */
214    1                         /* outputUsesInterrupts */
215  };
216
217  if(BSPConsolePort == BSP_UART_COM2)
218    {
219      cb.write = BSP_uart_termios_write_com2;
220    }
221
222  status = rtems_termios_open (major, minor, arg, &cb);
223
224  if(status != RTEMS_SUCCESSFUL)
225    {
226      printk("Error openning console device\n");
227      return status;
228    }
229
230  /*
231   * Pass data area info down to driver
232   */
233  BSP_uart_termios_set(BSPConsolePort, 
234                         ((rtems_libio_open_close_args_t *)arg)->iop->data1);
235  /* Enable interrupts  on channel */
236  BSP_uart_intr_ctrl(BSPConsolePort, BSP_UART_INTR_CTRL_TERMIOS);
237
238  return RTEMS_SUCCESSFUL;
239}
240
241/*-------------------------------------------------------------------------+
242| Console device driver CLOSE entry point
243+--------------------------------------------------------------------------*/
244rtems_device_driver
245console_close(rtems_device_major_number major,
246              rtems_device_minor_number minor,
247              void                      *arg)
248{
249  rtems_device_driver res = RTEMS_SUCCESSFUL;
250
251  res =  rtems_termios_close (arg);
252 
253  return res;
254} /* console_close */
255
256 
257/*-------------------------------------------------------------------------+
258| Console device driver READ entry point.
259+--------------------------------------------------------------------------+
260| Read characters from the I/O console. We only have stdin.
261+--------------------------------------------------------------------------*/
262rtems_device_driver
263console_read(rtems_device_major_number major,
264             rtems_device_minor_number minor,
265             void                      *arg)
266{
267
268  return rtems_termios_read (arg);
269} /* console_read */
270 
271
272/*-------------------------------------------------------------------------+
273| Console device driver WRITE entry point.
274+--------------------------------------------------------------------------+
275| Write characters to the I/O console. Stderr and stdout are the same.
276+--------------------------------------------------------------------------*/
277rtems_device_driver
278console_write(rtems_device_major_number major,
279              rtems_device_minor_number minor,
280              void                    * arg)
281{
282
283  return rtems_termios_write (arg);
284 
285} /* console_write */
286
287
288 
289/*
290 * Handle ioctl request.
291 */
292rtems_device_driver
293console_control(rtems_device_major_number major,
294                rtems_device_minor_number minor,
295                void                      * arg
296)
297{ 
298  return rtems_termios_ioctl (arg);
299}
300
301static int
302conSetAttr(int minor, const struct termios *t)
303{
304  int baud;
305
306  switch (t->c_cflag & CBAUD) 
307    {
308    case B50:   
309      baud = 50;
310      break;
311    case B75:   
312      baud = 75;       
313      break;
314    case B110: 
315      baud = 110;       
316      break;
317    case B134: 
318      baud = 134;       
319      break;
320    case B150: 
321      baud = 150;       
322      break;
323    case B200:
324      baud = 200;       
325      break;
326    case B300: 
327      baud = 300;
328      break;
329    case B600: 
330      baud = 600;       
331      break;
332    case B1200: 
333      baud = 1200;
334      break;
335    case B1800: 
336      baud = 1800;     
337      break;
338    case B2400: 
339      baud = 2400;
340      break;
341    case B4800: 
342      baud = 4800;
343      break;
344    case B9600: 
345      baud = 9600;
346      break;
347    case B19200:
348      baud = 19200;
349      break;
350    case B38400:
351      baud = 38400;
352      break;
353    case B57600:       
354      baud = 57600;
355      break;
356    case B115200:
357      baud = 115200;
358      break;
359    default:
360      baud = 0;
361      rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR);
362      return 0;
363    }
364
365  BSP_uart_set_baud(BSPConsolePort, baud);
366
367  return 0;
368}
369
370
371
Note: See TracBrowser for help on using the repository browser.