source: rtems/c/src/lib/libbsp/i386/ts_386ex/console/console.c @ 3299388d

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

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

  • clock/ckinit.c, clock/rtc.c, console/console.c, include/bsp.h, include/coverhd.h, network/ne2000.c, 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, tools/debug_ada/init.c, tools/debug_c/init.c, tools/debug_c/serial_gdb.c, tools/debug_c/system.h, tools/network_ada/listener/init.c, tools/network_ada/tcprelay/init.c, tools/ts_1325_ada/init.c: 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#include <rtems/error.h>
39
40#include <bsp.h>
41#include <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
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_com1, /* 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/*-------------------------------------------------------------------------+
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/*-------------------------------------------------------------------------+
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 
267/*
268 * Handle ioctl request.
269 */
270rtems_device_driver
271console_control(rtems_device_major_number major,
272                rtems_device_minor_number minor,
273                void                      * arg
274)
275{ 
276  return rtems_termios_ioctl (arg);
277}
278
279static int
280conSetAttr(int minor, const struct termios *t)
281{
282  int baud;
283
284  switch (t->c_cflag & CBAUD) 
285    {
286    case B50:   
287      baud = 50;
288      break;
289    case B75:   
290      baud = 75;       
291      break;
292    case B110: 
293      baud = 110;       
294      break;
295    case B134: 
296      baud = 134;       
297      break;
298    case B150: 
299      baud = 150;       
300      break;
301    case B200:
302      baud = 200;       
303      break;
304    case B300: 
305      baud = 300;
306      break;
307    case B600: 
308      baud = 600;       
309      break;
310    case B1200: 
311      baud = 1200;
312      break;
313    case B1800: 
314      baud = 1800;     
315      break;
316    case B2400: 
317      baud = 2400;
318      break;
319    case B4800: 
320      baud = 4800;
321      break;
322    case B9600: 
323      baud = 9600;
324      break;
325    case B19200:
326      baud = 19200;
327      break;
328    case B38400:
329      baud = 38400;
330      break;
331    case B57600:       
332      baud = 57600;
333      break;
334    case B115200:
335      baud = 115200;
336      break;
337    default:
338      baud = 0;
339      rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR);
340      return 0;
341    }
342
343  BSP_uart_set_baud(BSPConsolePort, baud);
344
345  return 0;
346}
347
348/*
349 * BSP initialization
350 */
351
352BSP_output_char_function_type BSP_output_char = 
353                       (BSP_output_char_function_type)    BSP_output_char_via_serial;
354
355BSP_polling_getchar_function_type BSP_poll_char = 
356                      (BSP_polling_getchar_function_type) BSP_poll_char_via_serial;
357
358int BSP_poll_read(int ttyMinor){
359 
360  return BSP_poll_char_via_serial();
361}
Note: See TracBrowser for help on using the repository browser.