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

4.11
Last change on this file since 3e8cdf8 was 3e8cdf8, checked in by Joel Sherrill <joel.sherrill@…>, on Jan 28, 2011 at 8:35:36 PM

2011-01-28 Joel Sherrill <joel.sherrilL@…>

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