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

4.104.114.84.95
Last change on this file since 48ad38db was 48ad38db, checked in by Jennifer Averett <Jennifer.Averett@…>, on 05/06/05 at 19:57:27

2005-05-06 Jennifer Averett <jennifer.averett@…>

  • clock/ckinit.c, console/console.c, include/bsp.h, network/ne2000.c: Moved irq.h to bsp subdirectory.
  • Property mode set to 100644
File size: 9.2 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  isr_on,
74  isr_off,
75  isr_is_on};
76
77static void
78isr_on(const rtems_irq_connect_data *unused)
79{
80  return;
81}
82
83static void
84isr_off(const rtems_irq_connect_data *unused)
85{
86  return;
87}
88
89static int
90isr_is_on(const rtems_irq_connect_data *irq)
91{
92  return BSP_irq_enabled_at_i8259s(irq->name);
93}
94
95/*-------------------------------------------------------------------------+
96| Console device driver INITIALIZE entry point.
97+--------------------------------------------------------------------------+
98| Initilizes the I/O console (keyboard + VGA display) driver.
99+--------------------------------------------------------------------------*/
100rtems_device_driver
101console_initialize(rtems_device_major_number major,
102                   rtems_device_minor_number minor,
103                   void                      *arg)
104{
105  rtems_status_code status;
106
107  /*
108   * Set up TERMIOS
109   */
110  rtems_termios_initialize ();
111
112  /*
113   * Do device-specific initialization
114   */
115
116  /* 115200-8-N-1, without hardware flow control */
117  BSP_uart_init(BSPConsolePort, 115200, CHR_8_BITS, 0, 0, 0);
118
119  /* Set interrupt handler */
120  if(BSPConsolePort == BSP_UART_COM1)
121    {
122      console_isr_data.name = BSP_UART_COM1_IRQ;
123      console_isr_data.hdl  = BSP_uart_termios_isr_com1;
124
125    }
126  else
127    {
128      assert(BSPConsolePort == BSP_UART_COM2);
129      console_isr_data.name = BSP_UART_COM2_IRQ;
130      console_isr_data.hdl  = BSP_uart_termios_isr_com2;
131    }
132
133  status = BSP_install_rtems_irq_handler(&console_isr_data);
134
135  if (!status){
136    printk("Error installing serial console interrupt handler!\n");
137    rtems_fatal_error_occurred(status);
138  }
139  /*
140   * Register the device
141   */
142  status = rtems_io_register_name ("/dev/console", major, 0);
143  if (status != RTEMS_SUCCESSFUL)
144    {
145      printk("Error registering console device!\n");
146      rtems_fatal_error_occurred (status);
147    }
148
149  if(BSPConsolePort == BSP_UART_COM1)
150    {
151      printk("Initialized console on port COM1 115200-8-N-1\n\n");
152    }
153  else
154    {
155      printk("Initialized console on port COM2 115200-8-N-1\n\n");
156    }
157
158  return RTEMS_SUCCESSFUL;
159} /* console_initialize */
160
161static int console_last_close(int major, int minor, void *arg)
162{
163  BSP_remove_rtems_irq_handler (&console_isr_data);
164
165  return 0;
166}
167
168/*-------------------------------------------------------------------------+
169| Console device driver OPEN entry point
170+--------------------------------------------------------------------------*/
171rtems_device_driver
172console_open(rtems_device_major_number major,
173                rtems_device_minor_number minor,
174                void                      *arg)
175{
176  rtems_status_code              status;
177  static rtems_termios_callbacks cb =
178  {
179    NULL,                     /* firstOpen */
180    console_last_close,       /* lastClose */
181    NULL,                     /* poll read  */
182    BSP_uart_termios_write_com1, /* write */
183    conSetAttr,               /* setAttributes */
184    NULL,                     /* stopRemoteTx */
185    NULL,                     /* startRemoteTx */
186    1                         /* outputUsesInterrupts */
187  };
188
189  if(BSPConsolePort == BSP_UART_COM2)
190    {
191      cb.write = BSP_uart_termios_write_com2;
192    }
193
194  status = rtems_termios_open (major, minor, arg, &cb);
195
196  if(status != RTEMS_SUCCESSFUL)
197    {
198      printk("Error openning console device\n");
199      return status;
200    }
201
202  /*
203   * Pass data area info down to driver
204   */
205  BSP_uart_termios_set(BSPConsolePort,
206                         ((rtems_libio_open_close_args_t *)arg)->iop->data1);
207
208  /* Enable interrupts  on channel */
209  BSP_uart_intr_ctrl(BSPConsolePort, BSP_UART_INTR_CTRL_TERMIOS);
210
211  return RTEMS_SUCCESSFUL;
212}
213
214/*-------------------------------------------------------------------------+
215| Console device driver CLOSE entry point
216+--------------------------------------------------------------------------*/
217rtems_device_driver
218console_close(rtems_device_major_number major,
219              rtems_device_minor_number minor,
220              void                      *arg)
221{
222
223  return (rtems_termios_close (arg));
224
225} /* console_close */
226
227/*-------------------------------------------------------------------------+
228| Console device driver READ entry point.
229+--------------------------------------------------------------------------+
230| Read characters from the I/O console. We only have stdin.
231+--------------------------------------------------------------------------*/
232rtems_device_driver
233console_read(rtems_device_major_number major,
234             rtems_device_minor_number minor,
235             void                      *arg)
236{
237  rtems_status_code sc;
238
239  sc = rtems_termios_read (arg);
240
241  if ( sc != RTEMS_SUCCESSFUL )
242    printk("console_read: fails %s\n",rtems_status_text(sc));
243
244  return sc;
245
246} /* console_read */
247
248/*-------------------------------------------------------------------------+
249| Console device driver WRITE entry point.
250+--------------------------------------------------------------------------+
251| Write characters to the I/O console. Stderr and stdout are the same.
252+--------------------------------------------------------------------------*/
253rtems_device_driver
254console_write(rtems_device_major_number major,
255              rtems_device_minor_number minor,
256              void                    * arg)
257{
258        return rtems_termios_write (arg);
259
260} /* console_write */
261
262/*
263 * Handle ioctl request.
264 */
265rtems_device_driver
266console_control(rtems_device_major_number major,
267                rtems_device_minor_number minor,
268                void                      * arg
269)
270{
271  return rtems_termios_ioctl (arg);
272}
273
274static int
275conSetAttr(int minor, const struct termios *t)
276{
277  int baud;
278
279  switch (t->c_cflag & CBAUD)
280    {
281    case B50:
282      baud = 50;
283      break;
284    case B75:
285      baud = 75;
286      break;
287    case B110:
288      baud = 110;
289      break;
290    case B134:
291      baud = 134;
292      break;
293    case B150:
294      baud = 150;
295      break;
296    case B200:
297      baud = 200;
298      break;
299    case B300:
300      baud = 300;
301      break;
302    case B600:
303      baud = 600;
304      break;
305    case B1200:
306      baud = 1200;
307      break;
308    case B1800:
309      baud = 1800;
310      break;
311    case B2400:
312      baud = 2400;
313      break;
314    case B4800:
315      baud = 4800;
316      break;
317    case B9600:
318      baud = 9600;
319      break;
320    case B19200:
321      baud = 19200;
322      break;
323    case B38400:
324      baud = 38400;
325      break;
326    case B57600:
327      baud = 57600;
328      break;
329    case B115200:
330      baud = 115200;
331      break;
332    default:
333      baud = 0;
334      rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR);
335      return 0;
336    }
337
338  BSP_uart_set_baud(BSPConsolePort, baud);
339
340  return 0;
341}
342
343/*
344 * BSP initialization
345 */
346
347BSP_output_char_function_type BSP_output_char =
348                       (BSP_output_char_function_type)    BSP_output_char_via_serial;
349
350BSP_polling_getchar_function_type BSP_poll_char =
351                      (BSP_polling_getchar_function_type) BSP_poll_char_via_serial;
352
353int BSP_poll_read(int ttyMinor){
354
355  return BSP_poll_char_via_serial();
356}
Note: See TracBrowser for help on using the repository browser.