source: rtems/c/src/lib/libbsp/powerpc/mcp750/console/console.c @ fcee56c0

4.104.114.84.95
Last change on this file since fcee56c0 was fcee56c0, checked in by Joel Sherrill <joel.sherrill@…>, on Jul 1, 1999 at 11:39:13 PM

Patch from Eric Valette <valette@…> to clean up the
previous submission.

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