source: rtems/c/src/lib/libbsp/i386/i386ex/console/console.c @ 5c7f274

4.104.114.84.95
Last change on this file since 5c7f274 was d5bbaa8, checked in by Jennifer Averett <Jennifer.Averett@…>, on 05/06/05 at 19:50:28

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

  • clock/ckinit.c, console/console.c, include/bsp.h, startup/bspstart.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
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
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    = 781250;
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  /* 9600-8-N-1, no hardware flow control */
118  BSP_uart_init(BSPConsolePort, 9600, 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 9600-8-N-1\n\n");
153    }
154  else
155    {
156      printk("Initialized console on port COM2 9600-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_com2, /* 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  printf("read the console\n");
240
241  sc = rtems_termios_read (arg);
242
243  if ( sc != RTEMS_SUCCESSFUL )
244    printf("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  int baud;
280
281  switch (t->c_cflag & CBAUD)
282    {
283    case B50:
284      baud = 50;
285      break;
286    case B75:
287      baud = 75;
288      break;
289    case B110:
290      baud = 110;
291      break;
292    case B134:
293      baud = 134;
294      break;
295    case B150:
296      baud = 150;
297      break;
298    case B200:
299      baud = 200;
300      break;
301    case B300:
302      baud = 300;
303      break;
304    case B600:
305      baud = 600;
306      break;
307    case B1200:
308      baud = 1200;
309      break;
310    case B1800:
311      baud = 1800;
312      break;
313    case B2400:
314      baud = 2400;
315      break;
316    case B4800:
317      baud = 4800;
318      break;
319    case B9600:
320      baud = 9600;
321      break;
322    case B19200:
323      baud = 19200;
324      break;
325    case B38400:
326      baud = 38400;
327      break;
328    case B57600:
329      baud = 57600;
330      break;
331    case B115200:
332      baud = 115200;
333      break;
334    default:
335      baud = 0;
336      rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR);
337      return 0;
338    }
339
340  BSP_uart_set_baud(BSPConsolePort, baud);
341
342  return 0;
343}
344
345/*
346 * BSP initialization
347 */
348
349BSP_output_char_function_type BSP_output_char =
350                       (BSP_output_char_function_type)    BSP_output_char_via_serial;
351
352BSP_polling_getchar_function_type BSP_poll_char =
353                      (BSP_polling_getchar_function_type) BSP_poll_char_via_serial;
354
355int BSP_poll_read(int ttyMinor){
356
357  return BSP_poll_char_via_serial();
358}
Note: See TracBrowser for help on using the repository browser.