source: rtems/c/src/lib/libbsp/i386/i386ex/console/console.c @ 7abb741

4.104.115
Last change on this file since 7abb741 was 7abb741, checked in by Ralf Corsepius <ralf.corsepius@…>, on 12/10/09 at 13:56:21

2009-12-10 Ralf Corsépius <ralf.corsepius@…>

  • console/console.c: Eliminate casts.
  • Property mode set to 100644
File size: 8.3 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
39#include <bsp.h>
40#include <bsp/irq.h>
41#include <rtems/libio.h>
42#include <rtems/error.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    = 781250;
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  /* 9600-8-N-1, no hardware flow control */
119  BSP_uart_init(BSPConsolePort, 9600, 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 9600-8-N-1\n\n");
154    }
155  else
156    {
157      printk("Initialized console on port COM2 9600-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_com2, /* 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  printf("read the console\n");
241
242  sc = rtems_termios_read (arg);
243
244  if ( sc != RTEMS_SUCCESSFUL )
245    printf("console_read: fails %s\n",rtems_status_text(sc));
246
247  return sc;
248
249} /* console_read */
250
251/*-------------------------------------------------------------------------+
252| Console device driver WRITE entry point.
253+--------------------------------------------------------------------------+
254| Write characters to the I/O console. Stderr and stdout are the same.
255+--------------------------------------------------------------------------*/
256rtems_device_driver
257console_write(rtems_device_major_number major,
258              rtems_device_minor_number minor,
259              void                    * arg)
260{
261        return rtems_termios_write (arg);
262
263} /* console_write */
264
265/*
266 * Handle ioctl request.
267 */
268rtems_device_driver
269console_control(rtems_device_major_number major,
270                rtems_device_minor_number minor,
271                void                      * arg
272)
273{
274  return rtems_termios_ioctl (arg);
275}
276
277static int
278conSetAttr(int minor, const struct termios *t)
279{
280  int baud;
281
282  baud = rtems_termios_baud_to_number(t->c_cflag & CBAUD);
283  if ( baud > 115200 )
284    rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR);
285
286  BSP_uart_set_baud(BSPConsolePort, baud);
287
288  return 0;
289}
290
291/*
292 * BSP initialization
293 */
294
295BSP_output_char_function_type BSP_output_char = BSP_output_char_via_serial;
296
297BSP_polling_getchar_function_type BSP_poll_char = 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.