source: rtems/c/src/lib/libbsp/i386/i386ex/console/console.c @ 6ff7e2c

4.104.114.84.95
Last change on this file since 6ff7e2c was 6ff7e2c, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 4, 2003 at 6:51:20 PM

2003-09-04 Joel Sherrill <joel@…>

  • clock/ckinit.c, console/console.c, include/bsp.h, include/coverhd.h, start/80386ex.h, start/80386ex.inc, start/macros.inc, start/start.S, startup/bspstart.c, startup/linkcmds, startup/setvec.c, timer/timer.c, timer/timerisr.S: URL for license changed.
  • 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 <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  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  /* 9600-8-N-1, no hardware flow control */
117  BSP_uart_init(BSPConsolePort, 9600, CHR_8_BITS, 0, 0, 0);
118 
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
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/*-------------------------------------------------------------------------+
231| Console device driver READ entry point.
232+--------------------------------------------------------------------------+
233| Read characters from the I/O console. We only have stdin.
234+--------------------------------------------------------------------------*/
235rtems_device_driver
236console_read(rtems_device_major_number major,
237             rtems_device_minor_number minor,
238             void                      *arg)
239{
240  rtems_status_code sc;
241  printf("read the console\n");
242
243  sc = rtems_termios_read (arg);
244
245  if ( sc != RTEMS_SUCCESSFUL )
246    printf("console_read: fails %s\n",rtems_status_text(sc));
247
248  return sc;
249
250} /* console_read */
251 
252
253/*-------------------------------------------------------------------------+
254| Console device driver WRITE entry point.
255+--------------------------------------------------------------------------+
256| Write characters to the I/O console. Stderr and stdout are the same.
257+--------------------------------------------------------------------------*/
258rtems_device_driver
259console_write(rtems_device_major_number major,
260              rtems_device_minor_number minor,
261              void                    * arg)
262{
263        return rtems_termios_write (arg);
264 
265} /* console_write */
266
267
268 
269/*
270 * Handle ioctl request.
271 */
272rtems_device_driver
273console_control(rtems_device_major_number major,
274                rtems_device_minor_number minor,
275                void                      * arg
276)
277{ 
278  return rtems_termios_ioctl (arg);
279}
280
281static int
282conSetAttr(int minor, const struct termios *t)
283{
284  int baud;
285
286  switch (t->c_cflag & CBAUD) 
287    {
288    case B50:   
289      baud = 50;
290      break;
291    case B75:   
292      baud = 75;       
293      break;
294    case B110: 
295      baud = 110;       
296      break;
297    case B134: 
298      baud = 134;       
299      break;
300    case B150: 
301      baud = 150;       
302      break;
303    case B200:
304      baud = 200;       
305      break;
306    case B300: 
307      baud = 300;
308      break;
309    case B600: 
310      baud = 600;       
311      break;
312    case B1200: 
313      baud = 1200;
314      break;
315    case B1800: 
316      baud = 1800;     
317      break;
318    case B2400: 
319      baud = 2400;
320      break;
321    case B4800: 
322      baud = 4800;
323      break;
324    case B9600: 
325      baud = 9600;
326      break;
327    case B19200:
328      baud = 19200;
329      break;
330    case B38400:
331      baud = 38400;
332      break;
333    case B57600:       
334      baud = 57600;
335      break;
336    case B115200:
337      baud = 115200;
338      break;
339    default:
340      baud = 0;
341      rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR);
342      return 0;
343    }
344
345  BSP_uart_set_baud(BSPConsolePort, baud);
346
347  return 0;
348}
349
350/*
351 * BSP initialization
352 */
353
354BSP_output_char_function_type BSP_output_char = 
355                       (BSP_output_char_function_type)    BSP_output_char_via_serial;
356
357BSP_polling_getchar_function_type BSP_poll_char = 
358                      (BSP_polling_getchar_function_type) BSP_poll_char_via_serial;
359
360int BSP_poll_read(int ttyMinor){
361 
362  return BSP_poll_char_via_serial();
363}
Note: See TracBrowser for help on using the repository browser.