source: rtems/c/src/lib/libbsp/i386/i386ex/console/console.c @ 0ebbf66

4.104.114.84.95
Last change on this file since 0ebbf66 was 0ebbf66, checked in by Joel Sherrill <joel.sherrill@…>, on 10/05/98 at 22:36:06

Large patch from Erik Ivanenko <erik.ivanenko@…> which
moves pieces of the pc386 bsp up to a shared level for all i386 BSPs
and modifies the i386ex BSP to use those shared pieces. Serial remote
debugging is included for both targets. Erik's notes:

There are several workarounds in it:

1) #define NEXT_GAS is hardcoded in pc386/start/start.s
2) #define NEXT_GAS is hardcoded in i386ex/start/start.s
3) #define NEW_GAS is hardcoded in pc386/start16.s
4) #undef assert and redeclare _assert hardcoded in console.c for

both pc386 and i386ex due to my egcs1.1b ~ newlib problem. Should have
modified t-rtems.cfg ( no time )

I've tested pc386 with both video and serial consoles and GDB remote.
All work fine, except that GDB acts weird. ( re: other posting)

I hope this will work for you. It took quite some time to locate the
autoconf error. The remainder was just grunt work.
Unfortunately, I think I've unwound the removal of the IBMPCInitVideo
stuff. Sorry. I REALLY can't spend more time... I've been at this
conversion to 4.0 locally and updating the release since Sept. 8th, and
have yet to compile my network driver.... This is as much as I can do
right now.

I look forward to the next patch to really test i368ex. I did make sure
that the sample tests worked for pc386.

  • Property mode set to 100644
File size: 10.1 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    = 781250;
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  __rtems_close(2);
119  __rtems_close(1);
120  __rtems_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  /* 9600-8-N-1, no hardware flow control */
153  BSP_uart_init(BSPConsolePort, 9600, 0);
154 
155 
156  /* Set interrupt handler */
157  if(BSPConsolePort == BSP_UART_COM1)
158    {
159      console_isr_data.name = BSP_UART_COM1_IRQ;
160      console_isr_data.hdl  = BSP_uart_termios_isr_com1;
161     
162    }
163  else
164    {
165      assert(BSPConsolePort == BSP_UART_COM2);
166      console_isr_data.name = BSP_UART_COM2_IRQ;
167      console_isr_data.hdl  = BSP_uart_termios_isr_com2;
168    }
169 
170  status = BSP_install_rtems_irq_handler(&console_isr_data);
171 
172  if (!status){
173    printk("Error installing serial console interrupt handler!\n");
174    rtems_fatal_error_occurred(status);
175  }
176  /*
177   * Register the device
178   */
179  status = rtems_io_register_name ("/dev/console", major, 0);
180  if (status != RTEMS_SUCCESSFUL)
181    {
182      printk("Error registering console device!\n");
183      rtems_fatal_error_occurred (status);
184    }
185 
186  if(BSPConsolePort == BSP_UART_COM1)
187    {
188      printk("Initialized console on port COM1 9600-8-N-1\n\n");
189    }
190  else
191    {
192      printk("Initialized console on port COM2 9600-8-N-1\n\n");
193    }
194
195  return RTEMS_SUCCESSFUL;
196} /* console_initialize */
197
198
199static int console_open_count = 0;
200
201static int console_last_close(int major, int minor, void *arg)
202{
203  BSP_remove_rtems_irq_handler (&console_isr_data);
204
205  return 0;
206}
207
208/*-------------------------------------------------------------------------+
209| Console device driver OPEN entry point
210+--------------------------------------------------------------------------*/
211rtems_device_driver
212console_open(rtems_device_major_number major,
213                rtems_device_minor_number minor,
214                void                      *arg)
215{
216  rtems_status_code              status;
217  static rtems_termios_callbacks cb =
218  {
219    NULL,                     /* firstOpen */
220    console_last_close,       /* lastClose */
221    NULL,                     /* poll read  */
222    BSP_uart_termios_write_com2, /* write */
223    conSetAttr,               /* setAttributes */
224    NULL,                     /* stopRemoteTx */
225    NULL,                     /* startRemoteTx */
226    1                         /* outputUsesInterrupts */
227  };
228
229  if(BSPConsolePort == BSP_UART_COM2)
230    {
231      cb.write = BSP_uart_termios_write_com2;
232    }
233
234  status = rtems_termios_open (major, minor, arg, &cb);
235
236  if(status != RTEMS_SUCCESSFUL)
237    {
238      printk("Error openning console device\n");
239      return status;
240    }
241
242  /*
243   * Pass data area info down to driver
244   */
245  BSP_uart_termios_set(BSPConsolePort,
246                         ((rtems_libio_open_close_args_t *)arg)->iop->data1);
247 
248  /* Enable interrupts  on channel */
249  BSP_uart_intr_ctrl(BSPConsolePort, BSP_UART_INTR_CTRL_TERMIOS);
250
251  return RTEMS_SUCCESSFUL;
252}
253
254/*-------------------------------------------------------------------------+
255| Console device driver CLOSE entry point
256+--------------------------------------------------------------------------*/
257rtems_device_driver
258console_close(rtems_device_major_number major,
259              rtems_device_minor_number minor,
260              void                      *arg)
261{
262
263  return (rtems_termios_close (arg));
264 
265} /* console_close */
266
267 
268/*-------------------------------------------------------------------------+
269| Console device driver READ entry point.
270+--------------------------------------------------------------------------+
271| Read characters from the I/O console. We only have stdin.
272+--------------------------------------------------------------------------*/
273rtems_device_driver
274console_read(rtems_device_major_number major,
275             rtems_device_minor_number minor,
276             void                      *arg)
277{
278  rtems_status_code sc;
279  printf("read the console\n");
280
281  sc = rtems_termios_read (arg);
282
283  if ( sc != RTEMS_SUCCESSFUL )
284    printf("console_read: fails %s\n",rtems_status_text(sc));
285
286  return sc;
287
288} /* console_read */
289 
290
291/*-------------------------------------------------------------------------+
292| Console device driver WRITE entry point.
293+--------------------------------------------------------------------------+
294| Write characters to the I/O console. Stderr and stdout are the same.
295+--------------------------------------------------------------------------*/
296rtems_device_driver
297console_write(rtems_device_major_number major,
298              rtems_device_minor_number minor,
299              void                    * arg)
300{
301        return rtems_termios_write (arg);
302 
303} /* console_write */
304
305
306 
307/*
308 * Handle ioctl request.
309 */
310rtems_device_driver
311console_control(rtems_device_major_number major,
312                rtems_device_minor_number minor,
313                void                      * arg
314)
315{
316  return rtems_termios_ioctl (arg);
317}
318
319static int
320conSetAttr(int minor, const struct termios *t)
321{
322  int baud;
323
324  switch (t->c_cflag & CBAUD)
325    {
326    case B50:   
327      baud = 50;
328      break;
329    case B75:   
330      baud = 75;       
331      break;
332    case B110: 
333      baud = 110;       
334      break;
335    case B134: 
336      baud = 134;       
337      break;
338    case B150: 
339      baud = 150;       
340      break;
341    case B200:
342      baud = 200;       
343      break;
344    case B300: 
345      baud = 300;
346      break;
347    case B600: 
348      baud = 600;       
349      break;
350    case B1200:
351      baud = 1200;
352      break;
353    case B1800:
354      baud = 1800;     
355      break;
356    case B2400:
357      baud = 2400;
358      break;
359    case B4800:
360      baud = 4800;
361      break;
362    case B9600:
363      baud = 9600;
364      break;
365    case B19200:
366      baud = 19200;
367      break;
368    case B38400:
369      baud = 38400;
370      break;
371    case B57600:       
372      baud = 57600;
373      break;
374    case B115200:
375      baud = 115200;
376      break;
377    default:
378      baud = 0;
379      rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR);
380      return 0;
381    }
382
383  BSP_uart_set_baud(BSPConsolePort, baud);
384
385  return 0;
386}
387
388/*
389 * BSP initialization
390 */
391
392BSP_output_char_function_type BSP_output_char =
393                       (BSP_output_char_function_type)    BSP_output_char_via_serial;
394
395BSP_polling_getchar_function_type BSP_poll_char = 
396                      (BSP_polling_getchar_function_type) BSP_poll_char_via_serial;
397
398int BSP_poll_read(int ttyMinor){
399 
400  return BSP_poll_char_via_serial();
401}
Note: See TracBrowser for help on using the repository browser.