source: rtems/c/src/lib/libbsp/i386/ts_386ex/console/console.c @ 08311cc3

4.104.114.84.95
Last change on this file since 08311cc3 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

  • Property mode set to 100644
File size: 10.0 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.OARcorp.com/rtems/license.html.
30| **************************************************************************
31|
32|  $Id$
33+--------------------------------------------------------------------------*/
34
35#include <stdio.h>
36#include <stdlib.h>
37#include <assert.h>
38
39/* workaround for gcc development tools */
40#undef __assert
41void __assert (const char *file, int line, const char *msg);
42
43#include <bsp.h>
44#include <irq.h>
45#include <rtems/libio.h>
46#include <termios.h>
47#include <uart.h>
48#include <libcpu/cpuModel.h>
49
50/*
51 * Possible value for console input/output :
52 *      BSP_UART_COM1
53 *      BSP_UART_COM2
54 *  BSP_CONSOLE_PORT_CONSOLE is not valid in this BSP. 
55 *      All references to either keyboard or video handling have been removed.
56 */
57
58int BSPConsolePort = BSP_UART_COM2;
59int BSPBaseBaud    = 115200;
60int BSP_poll_read(int);
61
62extern BSP_polling_getchar_function_type BSP_poll_char;
63
64static int  conSetAttr(int minor, const struct termios *);
65static void isr_on(const rtems_irq_connect_data *);
66static void isr_off(const rtems_irq_connect_data *);
67static int  isr_is_on(const rtems_irq_connect_data *);
68
69/*
70 * Change references to com2 if required.
71 */
72
73static rtems_irq_connect_data console_isr_data =
74{ BSP_UART_COM2_IRQ,
75  BSP_uart_termios_isr_com2,
76  isr_on,
77  isr_off,
78  isr_is_on};
79
80static void
81isr_on(const rtems_irq_connect_data *unused)
82{
83  return;
84}
85                                                   
86static void
87isr_off(const rtems_irq_connect_data *unused)
88{
89  return;
90}
91
92static int
93isr_is_on(const rtems_irq_connect_data *irq)
94{
95  return BSP_irq_enabled_at_i8259s(irq->name);
96}
97
98void console_reserve_resources(rtems_configuration_table *conf)
99{
100  rtems_termios_reserve_resources(conf, 1);
101  return;
102}
103
104void __assert (const char *file, int line, const char *msg)
105{
106    static   char exit_msg[] = "EXECUTIVE SHUTDOWN! Any key to reboot...";
107  unsigned char  ch;
108   
109  /*
110   * Note we cannot call exit or printf from here,
111   * assert can fail inside ISR too
112   */
113
114   /*
115   * Close console
116   */
117  close(2);
118  close(1);
119  close(0);
120
121  printk("\nassert failed: %s: ", file);
122  printk("%d: ", line);
123  printk("%s\n\n", msg);
124  printk(exit_msg);
125  ch = BSP_poll_char();
126  printk("\nShould jump to reset now!\n");
127}
128
129
130/*-------------------------------------------------------------------------+
131| Console device driver INITIALIZE entry point.
132+--------------------------------------------------------------------------+
133| Initilizes the I/O console (keyboard + VGA display) driver.
134+--------------------------------------------------------------------------*/
135rtems_device_driver
136console_initialize(rtems_device_major_number major,
137                   rtems_device_minor_number minor,
138                   void                      *arg)
139{
140  rtems_status_code status;
141
142  /*
143   * Set up TERMIOS
144   */
145  rtems_termios_initialize ();
146 
147  /*
148   * Do device-specific initialization
149   */
150 
151  /* 115200-8-N-1, without hardware flow control */
152  BSP_uart_init(BSPConsolePort, 115200, 0);
153 
154  /* Set interrupt handler */
155  if(BSPConsolePort == BSP_UART_COM1)
156    {
157      console_isr_data.name = BSP_UART_COM1_IRQ;
158      console_isr_data.hdl  = BSP_uart_termios_isr_com1;
159     
160    }
161  else
162    {
163      assert(BSPConsolePort == BSP_UART_COM2);
164      console_isr_data.name = BSP_UART_COM2_IRQ;
165      console_isr_data.hdl  = BSP_uart_termios_isr_com2;
166    }
167 
168  status = BSP_install_rtems_irq_handler(&console_isr_data);
169 
170  if (!status){
171    printk("Error installing serial console interrupt handler!\n");
172    rtems_fatal_error_occurred(status);
173  }
174  /*
175   * Register the device
176   */
177  status = rtems_io_register_name ("/dev/console", major, 0);
178  if (status != RTEMS_SUCCESSFUL)
179    {
180      printk("Error registering console device!\n");
181      rtems_fatal_error_occurred (status);
182    }
183 
184  if(BSPConsolePort == BSP_UART_COM1)
185    {
186      printk("Initialized console on port COM1 115200-8-N-1\n\n");
187    }
188  else
189    {
190      printk("Initialized console on port COM2 115200-8-N-1\n\n");
191    }
192
193  return RTEMS_SUCCESSFUL;
194} /* console_initialize */
195
196
197static int console_open_count = 0;
198
199static int console_last_close(int major, int minor, void *arg)
200{
201  BSP_remove_rtems_irq_handler (&console_isr_data);
202
203  return 0;
204}
205
206/*-------------------------------------------------------------------------+
207| Console device driver OPEN entry point
208+--------------------------------------------------------------------------*/
209rtems_device_driver
210console_open(rtems_device_major_number major,
211                rtems_device_minor_number minor,
212                void                      *arg)
213{
214  rtems_status_code              status;
215  static rtems_termios_callbacks cb =
216  {
217    NULL,                     /* firstOpen */
218    console_last_close,       /* lastClose */
219    NULL,                     /* poll read  */
220    BSP_uart_termios_write_com1, /* write */
221    conSetAttr,               /* setAttributes */
222    NULL,                     /* stopRemoteTx */
223    NULL,                     /* startRemoteTx */
224    1                         /* outputUsesInterrupts */
225  };
226
227  if(BSPConsolePort == BSP_UART_COM2)
228    {
229      cb.write = BSP_uart_termios_write_com2;
230    }
231
232  status = rtems_termios_open (major, minor, arg, &cb);
233
234  if(status != RTEMS_SUCCESSFUL)
235    {
236      printk("Error openning console device\n");
237      return status;
238    }
239
240  /*
241   * Pass data area info down to driver
242   */
243  BSP_uart_termios_set(BSPConsolePort,
244                         ((rtems_libio_open_close_args_t *)arg)->iop->data1);
245 
246  /* Enable interrupts  on channel */
247  BSP_uart_intr_ctrl(BSPConsolePort, BSP_UART_INTR_CTRL_TERMIOS);
248
249  return RTEMS_SUCCESSFUL;
250}
251
252/*-------------------------------------------------------------------------+
253| Console device driver CLOSE entry point
254+--------------------------------------------------------------------------*/
255rtems_device_driver
256console_close(rtems_device_major_number major,
257              rtems_device_minor_number minor,
258              void                      *arg)
259{
260
261  return (rtems_termios_close (arg));
262 
263} /* console_close */
264
265 
266/*-------------------------------------------------------------------------+
267| Console device driver READ entry point.
268+--------------------------------------------------------------------------+
269| Read characters from the I/O console. We only have stdin.
270+--------------------------------------------------------------------------*/
271rtems_device_driver
272console_read(rtems_device_major_number major,
273             rtems_device_minor_number minor,
274             void                      *arg)
275{
276  rtems_status_code sc;
277
278  sc = rtems_termios_read (arg);
279
280  if ( sc != RTEMS_SUCCESSFUL )
281    printk("console_read: fails %s\n",rtems_status_text(sc));
282
283  return sc;
284
285} /* console_read */
286 
287
288/*-------------------------------------------------------------------------+
289| Console device driver WRITE entry point.
290+--------------------------------------------------------------------------+
291| Write characters to the I/O console. Stderr and stdout are the same.
292+--------------------------------------------------------------------------*/
293rtems_device_driver
294console_write(rtems_device_major_number major,
295              rtems_device_minor_number minor,
296              void                    * arg)
297{
298        return rtems_termios_write (arg);
299 
300} /* console_write */
301
302
303 
304/*
305 * Handle ioctl request.
306 */
307rtems_device_driver
308console_control(rtems_device_major_number major,
309                rtems_device_minor_number minor,
310                void                      * arg
311)
312{
313  return rtems_termios_ioctl (arg);
314}
315
316static int
317conSetAttr(int minor, const struct termios *t)
318{
319  int baud;
320
321  switch (t->c_cflag & CBAUD)
322    {
323    case B50:   
324      baud = 50;
325      break;
326    case B75:   
327      baud = 75;       
328      break;
329    case B110: 
330      baud = 110;       
331      break;
332    case B134: 
333      baud = 134;       
334      break;
335    case B150: 
336      baud = 150;       
337      break;
338    case B200:
339      baud = 200;       
340      break;
341    case B300: 
342      baud = 300;
343      break;
344    case B600: 
345      baud = 600;       
346      break;
347    case B1200:
348      baud = 1200;
349      break;
350    case B1800:
351      baud = 1800;     
352      break;
353    case B2400:
354      baud = 2400;
355      break;
356    case B4800:
357      baud = 4800;
358      break;
359    case B9600:
360      baud = 9600;
361      break;
362    case B19200:
363      baud = 19200;
364      break;
365    case B38400:
366      baud = 38400;
367      break;
368    case B57600:       
369      baud = 57600;
370      break;
371    case B115200:
372      baud = 115200;
373      break;
374    default:
375      baud = 0;
376      rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR);
377      return 0;
378    }
379
380  BSP_uart_set_baud(BSPConsolePort, baud);
381
382  return 0;
383}
384
385/*
386 * BSP initialization
387 */
388
389BSP_output_char_function_type BSP_output_char =
390                       (BSP_output_char_function_type)    BSP_output_char_via_serial;
391
392BSP_polling_getchar_function_type BSP_poll_char = 
393                      (BSP_polling_getchar_function_type) BSP_poll_char_via_serial;
394
395int BSP_poll_read(int ttyMinor){
396 
397  return BSP_poll_char_via_serial();
398}
Note: See TracBrowser for help on using the repository browser.