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

4.104.114.95
Last change on this file since 6825d06 was 6825d06, checked in by Joel Sherrill <joel.sherrill@…>, on 05/23/08 at 15:48:38

2008-05-23 Joel Sherrill <joel.sherrill@…>

  • console/console.c: Eliminate copies of switches to convert termios Bxxx constants to xxx as an integer. Use the shared termios_baud_to_number() routine to do the same conversion.
  • Property mode set to 100644
File size: 8.4 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.rtems.com/license/LICENSE.
30| **************************************************************************
31|
32|  $Id$
33+--------------------------------------------------------------------------*/
34
35#include <stdio.h>
36#include <stdlib.h>
37#include <assert.h>
38#include <rtems/error.h>
39
40#include <bsp.h>
41#include <bsp/irq.h>
42#include <rtems/libio.h>
43#include <termios.h>
44#include <uart.h>
45#include <libcpu/cpuModel.h>
46
47/*
48 * Possible value for console input/output :
49 *      BSP_UART_COM1
50 *      BSP_UART_COM2
51 *  BSP_CONSOLE_PORT_CONSOLE is not valid in this BSP.
52 *      All references to either keyboard or video handling have been removed.
53 */
54
55int BSPConsolePort = BSP_UART_COM2;
56int BSPBaseBaud    = 115200;
57int BSP_poll_read(int);
58
59extern BSP_polling_getchar_function_type BSP_poll_char;
60
61static int  conSetAttr(int minor, const struct termios *);
62static void isr_on(const rtems_irq_connect_data *);
63static void isr_off(const rtems_irq_connect_data *);
64static int  isr_is_on(const rtems_irq_connect_data *);
65
66/*
67 * Change references to com2 if required.
68 */
69
70static rtems_irq_connect_data console_isr_data =
71{ BSP_UART_COM2_IRQ,
72  BSP_uart_termios_isr_com2,
73  0,
74  isr_on,
75  isr_off,
76  isr_is_on};
77
78static void
79isr_on(const rtems_irq_connect_data *unused)
80{
81  return;
82}
83
84static void
85isr_off(const rtems_irq_connect_data *unused)
86{
87  return;
88}
89
90static int
91isr_is_on(const rtems_irq_connect_data *irq)
92{
93  return BSP_irq_enabled_at_i8259s(irq->name);
94}
95
96/*-------------------------------------------------------------------------+
97| Console device driver INITIALIZE entry point.
98+--------------------------------------------------------------------------+
99| Initilizes the I/O console (keyboard + VGA display) driver.
100+--------------------------------------------------------------------------*/
101rtems_device_driver
102console_initialize(rtems_device_major_number major,
103                   rtems_device_minor_number minor,
104                   void                      *arg)
105{
106  rtems_status_code status;
107
108  /*
109   * Set up TERMIOS
110   */
111  rtems_termios_initialize ();
112
113  /*
114   * Do device-specific initialization
115   */
116
117  /* 115200-8-N-1, without hardware flow control */
118  BSP_uart_init(BSPConsolePort, 115200, CHR_8_BITS, 0, 0, 0);
119
120  /* Set interrupt handler */
121  if(BSPConsolePort == BSP_UART_COM1)
122    {
123      console_isr_data.name = BSP_UART_COM1_IRQ;
124      console_isr_data.hdl  = BSP_uart_termios_isr_com1;
125
126    }
127  else
128    {
129      assert(BSPConsolePort == BSP_UART_COM2);
130      console_isr_data.name = BSP_UART_COM2_IRQ;
131      console_isr_data.hdl  = BSP_uart_termios_isr_com2;
132    }
133
134  status = BSP_install_rtems_irq_handler(&console_isr_data);
135
136  if (!status){
137    printk("Error installing serial console interrupt handler!\n");
138    rtems_fatal_error_occurred(status);
139  }
140  /*
141   * Register the device
142   */
143  status = rtems_io_register_name ("/dev/console", major, 0);
144  if (status != RTEMS_SUCCESSFUL)
145    {
146      printk("Error registering console device!\n");
147      rtems_fatal_error_occurred (status);
148    }
149
150  if(BSPConsolePort == BSP_UART_COM1)
151    {
152      printk("Initialized console on port COM1 115200-8-N-1\n\n");
153    }
154  else
155    {
156      printk("Initialized console on port COM2 115200-8-N-1\n\n");
157    }
158
159  return RTEMS_SUCCESSFUL;
160} /* console_initialize */
161
162static int console_last_close(int major, int minor, void *arg)
163{
164  BSP_remove_rtems_irq_handler (&console_isr_data);
165
166  return 0;
167}
168
169/*-------------------------------------------------------------------------+
170| Console device driver OPEN entry point
171+--------------------------------------------------------------------------*/
172rtems_device_driver
173console_open(rtems_device_major_number major,
174                rtems_device_minor_number minor,
175                void                      *arg)
176{
177  rtems_status_code              status;
178  static rtems_termios_callbacks cb =
179  {
180    NULL,                     /* firstOpen */
181    console_last_close,       /* lastClose */
182    NULL,                     /* poll read  */
183    BSP_uart_termios_write_com1, /* write */
184    conSetAttr,               /* setAttributes */
185    NULL,                     /* stopRemoteTx */
186    NULL,                     /* startRemoteTx */
187    1                         /* outputUsesInterrupts */
188  };
189
190  if(BSPConsolePort == BSP_UART_COM2)
191    {
192      cb.write = BSP_uart_termios_write_com2;
193    }
194
195  status = rtems_termios_open (major, minor, arg, &cb);
196
197  if(status != RTEMS_SUCCESSFUL)
198    {
199      printk("Error openning console device\n");
200      return status;
201    }
202
203  /*
204   * Pass data area info down to driver
205   */
206  BSP_uart_termios_set(BSPConsolePort,
207                         ((rtems_libio_open_close_args_t *)arg)->iop->data1);
208
209  /* Enable interrupts  on channel */
210  BSP_uart_intr_ctrl(BSPConsolePort, BSP_UART_INTR_CTRL_TERMIOS);
211
212  return RTEMS_SUCCESSFUL;
213}
214
215/*-------------------------------------------------------------------------+
216| Console device driver CLOSE entry point
217+--------------------------------------------------------------------------*/
218rtems_device_driver
219console_close(rtems_device_major_number major,
220              rtems_device_minor_number minor,
221              void                      *arg)
222{
223
224  return (rtems_termios_close (arg));
225
226} /* console_close */
227
228/*-------------------------------------------------------------------------+
229| Console device driver READ entry point.
230+--------------------------------------------------------------------------+
231| Read characters from the I/O console. We only have stdin.
232+--------------------------------------------------------------------------*/
233rtems_device_driver
234console_read(rtems_device_major_number major,
235             rtems_device_minor_number minor,
236             void                      *arg)
237{
238  rtems_status_code sc;
239
240  sc = rtems_termios_read (arg);
241
242  if ( sc != RTEMS_SUCCESSFUL )
243    printk("console_read: fails %s\n",rtems_status_text(sc));
244
245  return sc;
246
247} /* console_read */
248
249/*-------------------------------------------------------------------------+
250| Console device driver WRITE entry point.
251+--------------------------------------------------------------------------+
252| Write characters to the I/O console. Stderr and stdout are the same.
253+--------------------------------------------------------------------------*/
254rtems_device_driver
255console_write(rtems_device_major_number major,
256              rtems_device_minor_number minor,
257              void                    * arg)
258{
259        return rtems_termios_write (arg);
260
261} /* console_write */
262
263/*
264 * Handle ioctl request.
265 */
266rtems_device_driver
267console_control(rtems_device_major_number major,
268                rtems_device_minor_number minor,
269                void                      * arg
270)
271{
272  return rtems_termios_ioctl (arg);
273}
274
275static int
276conSetAttr(int minor, const struct termios *t)
277{
278  int baud;
279
280  baud = termios_baud_to_number(t->c_cflag & CBAUD);
281  if ( baud > 115200 )
282    rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR);
283
284  BSP_uart_set_baud(BSPConsolePort, baud);
285
286  return 0;
287}
288
289/*
290 * BSP initialization
291 */
292
293BSP_output_char_function_type BSP_output_char =
294                       (BSP_output_char_function_type)    BSP_output_char_via_serial;
295
296BSP_polling_getchar_function_type BSP_poll_char =
297                      (BSP_polling_getchar_function_type) BSP_poll_char_via_serial;
298
299int BSP_poll_read(int ttyMinor){
300
301  return BSP_poll_char_via_serial();
302}
Note: See TracBrowser for help on using the repository browser.