source: rtems/c/src/lib/libbsp/i386/ts_386ex/console/console.c @ 1d4048b2

4.104.114.84.95
Last change on this file since 1d4048b2 was 1d4048b2, checked in by Joel Sherrill <joel.sherrill@…>, on 08/11/99 at 23:45:57

Patch from Tony R. Ambardar <tonya@…>:

I'm attaching a big patch for the ts_386ex BSP which adds and includes
the following:

1) Conversion to ELF format + minor code cleanups + documentation.

2) An Ada95 binding to FreeBSD sockets, based on Samuel Tardieu's

adasockets-0.1.3 package. This includes some sample applications.

3) Some Ada and C interfaces to add serial-port debugging to

programs. Comes with examples, too; the Ada one shows how
transparent adding the support can be. Note that Rosimildo sent me
the original C code.

The network stuff is not BSP specific, and could be added to your Ada
code collection. The debugging stuff is specific to the i386. Right
now, everything sits in my "tools" directory.

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