source: rtems/c/src/lib/libbsp/i386/ts_386ex/console/console.c @ 5098898

4.104.114.84.95
Last change on this file since 5098898 was 5098898, checked in by Joel Sherrill <joel.sherrill@…>, on 03/28/02 at 13:52:14

2002-03-27 Ralf Corsepius <corsepiu@…>

  • include/bsp.h: include <libcpu/cpu.h>.
  • console/console.c: Remove unused variable console_open_count.
  • Property mode set to 100644
File size: 9.8 KB
Line 
1/*-------------------------------------------------------------------------+
2| console.c v1.1 - i386ex BSP - 1997/08/07
3+--------------------------------------------------------------------------+
4| This file contains the i386ex console I/O package. It is just a termios
5| wrapper.
6+--------------------------------------------------------------------------+
7| (C) Copyright 1997 -
8| - NavIST Group - Real-Time Distributed Systems and Industrial Automation
9|
10| http://pandora.ist.utl.pt
11|
12| Instituto Superior Tecnico * Lisboa * PORTUGAL
13+--------------------------------------------------------------------------+
14| Disclaimer:
15|
16| This file is provided "AS IS" without warranty of any kind, either
17| expressed or implied.
18+--------------------------------------------------------------------------+
19| This code is based on:
20|   console.c,v 1.4 1995/12/19 20:07:23 joel Exp - go32 BSP
21|   console.c,v 1.15 pc386 BSP
22| With the following copyright notice:
23| **************************************************************************
24| *  COPYRIGHT (c) 1989-1999.
25| *  On-Line Applications Research Corporation (OAR).
26| *
27| *  The license and distribution terms for this file may be
28| *  found in found in the file LICENSE in this distribution or at
29| *  http://www.OARcorp.com/rtems/license.html.
30| **************************************************************************
31|
32|  $Id$
33+--------------------------------------------------------------------------*/
34
35#include <stdio.h>
36#include <stdlib.h>
37#include <assert.h>
38
39/* workaround for gcc development tools */
40#undef __assert
41void __assert (const char *file, int line, const char *msg);
42
43#include <bsp.h>
44#include <irq.h>
45#include <rtems/libio.h>
46#include <termios.h>
47#include <uart.h>
48#include <libcpu/cpuModel.h>
49
50/*
51 * Possible value for console input/output :
52 *      BSP_UART_COM1
53 *      BSP_UART_COM2
54 *  BSP_CONSOLE_PORT_CONSOLE is not valid in this BSP. 
55 *      All references to either keyboard or video handling have been removed.
56 */
57
58int BSPConsolePort = BSP_UART_COM2;
59int BSPBaseBaud    = 115200;
60int BSP_poll_read(int);
61
62extern BSP_polling_getchar_function_type BSP_poll_char;
63
64static int  conSetAttr(int minor, const struct termios *);
65static void isr_on(const rtems_irq_connect_data *);
66static void isr_off(const rtems_irq_connect_data *);
67static int  isr_is_on(const rtems_irq_connect_data *);
68
69/*
70 * Change references to com2 if required.
71 */
72
73static rtems_irq_connect_data console_isr_data =
74{ BSP_UART_COM2_IRQ,
75  BSP_uart_termios_isr_com2,
76  isr_on,
77  isr_off,
78  isr_is_on};
79
80static void
81isr_on(const rtems_irq_connect_data *unused)
82{
83  return;
84}
85                                                   
86static void
87isr_off(const rtems_irq_connect_data *unused)
88{
89  return;
90}
91
92static int
93isr_is_on(const rtems_irq_connect_data *irq)
94{
95  return BSP_irq_enabled_at_i8259s(irq->name);
96}
97
98void __assert (const char *file, int line, const char *msg)
99{
100    static   char exit_msg[] = "EXECUTIVE SHUTDOWN! Any key to reboot...";
101  unsigned char  ch;
102   
103  /*
104   * Note we cannot call exit or printf from here,
105   * assert can fail inside ISR too
106   */
107
108   /*
109   * Close console
110   */
111  close(2);
112  close(1);
113  close(0);
114
115  printk("\nassert failed: %s: ", file);
116  printk("%d: ", line);
117  printk("%s\n\n", msg);
118  printk(exit_msg);
119  ch = BSP_poll_char();
120  printk("\nShould jump to reset now!\n");
121}
122
123
124/*-------------------------------------------------------------------------+
125| Console device driver INITIALIZE entry point.
126+--------------------------------------------------------------------------+
127| Initilizes the I/O console (keyboard + VGA display) driver.
128+--------------------------------------------------------------------------*/
129rtems_device_driver
130console_initialize(rtems_device_major_number major,
131                   rtems_device_minor_number minor,
132                   void                      *arg)
133{
134  rtems_status_code status;
135
136  /*
137   * Set up TERMIOS
138   */
139  rtems_termios_initialize ();
140 
141  /*
142   * Do device-specific initialization
143   */
144 
145  /* 115200-8-N-1, without hardware flow control */
146  BSP_uart_init(BSPConsolePort, 115200, CHR_8_BITS, 0, 0, 0);
147 
148  /* Set interrupt handler */
149  if(BSPConsolePort == BSP_UART_COM1)
150    {
151      console_isr_data.name = BSP_UART_COM1_IRQ;
152      console_isr_data.hdl  = BSP_uart_termios_isr_com1;
153     
154    }
155  else
156    {
157      assert(BSPConsolePort == BSP_UART_COM2);
158      console_isr_data.name = BSP_UART_COM2_IRQ;
159      console_isr_data.hdl  = BSP_uart_termios_isr_com2;
160    }
161 
162  status = BSP_install_rtems_irq_handler(&console_isr_data);
163 
164  if (!status){
165    printk("Error installing serial console interrupt handler!\n");
166    rtems_fatal_error_occurred(status);
167  }
168  /*
169   * Register the device
170   */
171  status = rtems_io_register_name ("/dev/console", major, 0);
172  if (status != RTEMS_SUCCESSFUL)
173    {
174      printk("Error registering console device!\n");
175      rtems_fatal_error_occurred (status);
176    }
177 
178  if(BSPConsolePort == BSP_UART_COM1)
179    {
180      printk("Initialized console on port COM1 115200-8-N-1\n\n");
181    }
182  else
183    {
184      printk("Initialized console on port COM2 115200-8-N-1\n\n");
185    }
186
187  return RTEMS_SUCCESSFUL;
188} /* console_initialize */
189
190
191static int console_last_close(int major, int minor, void *arg)
192{
193  BSP_remove_rtems_irq_handler (&console_isr_data);
194
195  return 0;
196}
197
198/*-------------------------------------------------------------------------+
199| Console device driver OPEN entry point
200+--------------------------------------------------------------------------*/
201rtems_device_driver
202console_open(rtems_device_major_number major,
203                rtems_device_minor_number minor,
204                void                      *arg)
205{
206  rtems_status_code              status;
207  static rtems_termios_callbacks cb =
208  {
209    NULL,                     /* firstOpen */
210    console_last_close,       /* lastClose */
211    NULL,                     /* poll read  */
212    BSP_uart_termios_write_com1, /* write */
213    conSetAttr,               /* setAttributes */
214    NULL,                     /* stopRemoteTx */
215    NULL,                     /* startRemoteTx */
216    1                         /* outputUsesInterrupts */
217  };
218
219  if(BSPConsolePort == BSP_UART_COM2)
220    {
221      cb.write = BSP_uart_termios_write_com2;
222    }
223
224  status = rtems_termios_open (major, minor, arg, &cb);
225
226  if(status != RTEMS_SUCCESSFUL)
227    {
228      printk("Error openning console device\n");
229      return status;
230    }
231
232  /*
233   * Pass data area info down to driver
234   */
235  BSP_uart_termios_set(BSPConsolePort,
236                         ((rtems_libio_open_close_args_t *)arg)->iop->data1);
237 
238  /* Enable interrupts  on channel */
239  BSP_uart_intr_ctrl(BSPConsolePort, BSP_UART_INTR_CTRL_TERMIOS);
240
241  return RTEMS_SUCCESSFUL;
242}
243
244/*-------------------------------------------------------------------------+
245| Console device driver CLOSE entry point
246+--------------------------------------------------------------------------*/
247rtems_device_driver
248console_close(rtems_device_major_number major,
249              rtems_device_minor_number minor,
250              void                      *arg)
251{
252
253  return (rtems_termios_close (arg));
254 
255} /* console_close */
256
257 
258/*-------------------------------------------------------------------------+
259| Console device driver READ entry point.
260+--------------------------------------------------------------------------+
261| Read characters from the I/O console. We only have stdin.
262+--------------------------------------------------------------------------*/
263rtems_device_driver
264console_read(rtems_device_major_number major,
265             rtems_device_minor_number minor,
266             void                      *arg)
267{
268  rtems_status_code sc;
269
270  sc = rtems_termios_read (arg);
271
272  if ( sc != RTEMS_SUCCESSFUL )
273    printk("console_read: fails %s\n",rtems_status_text(sc));
274
275  return sc;
276
277} /* console_read */
278 
279
280/*-------------------------------------------------------------------------+
281| Console device driver WRITE entry point.
282+--------------------------------------------------------------------------+
283| Write characters to the I/O console. Stderr and stdout are the same.
284+--------------------------------------------------------------------------*/
285rtems_device_driver
286console_write(rtems_device_major_number major,
287              rtems_device_minor_number minor,
288              void                    * arg)
289{
290        return rtems_termios_write (arg);
291 
292} /* console_write */
293
294
295 
296/*
297 * Handle ioctl request.
298 */
299rtems_device_driver
300console_control(rtems_device_major_number major,
301                rtems_device_minor_number minor,
302                void                      * arg
303)
304{
305  return rtems_termios_ioctl (arg);
306}
307
308static int
309conSetAttr(int minor, const struct termios *t)
310{
311  int baud;
312
313  switch (t->c_cflag & CBAUD)
314    {
315    case B50:   
316      baud = 50;
317      break;
318    case B75:   
319      baud = 75;       
320      break;
321    case B110: 
322      baud = 110;       
323      break;
324    case B134: 
325      baud = 134;       
326      break;
327    case B150: 
328      baud = 150;       
329      break;
330    case B200:
331      baud = 200;       
332      break;
333    case B300: 
334      baud = 300;
335      break;
336    case B600: 
337      baud = 600;       
338      break;
339    case B1200:
340      baud = 1200;
341      break;
342    case B1800:
343      baud = 1800;     
344      break;
345    case B2400:
346      baud = 2400;
347      break;
348    case B4800:
349      baud = 4800;
350      break;
351    case B9600:
352      baud = 9600;
353      break;
354    case B19200:
355      baud = 19200;
356      break;
357    case B38400:
358      baud = 38400;
359      break;
360    case B57600:       
361      baud = 57600;
362      break;
363    case B115200:
364      baud = 115200;
365      break;
366    default:
367      baud = 0;
368      rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR);
369      return 0;
370    }
371
372  BSP_uart_set_baud(BSPConsolePort, baud);
373
374  return 0;
375}
376
377/*
378 * BSP initialization
379 */
380
381BSP_output_char_function_type BSP_output_char =
382                       (BSP_output_char_function_type)    BSP_output_char_via_serial;
383
384BSP_polling_getchar_function_type BSP_poll_char = 
385                      (BSP_polling_getchar_function_type) BSP_poll_char_via_serial;
386
387int BSP_poll_read(int ttyMinor){
388 
389  return BSP_poll_char_via_serial();
390}
Note: See TracBrowser for help on using the repository browser.