source: rtems/c/src/lib/libbsp/i386/pc386/console/console.c @ 3cbb63a

4.104.114.84.95
Last change on this file since 3cbb63a was 3cbb63a, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 30, 2000 at 8:15:30 AM

2000-08-26 Rosimildo da Silva <rdasilva@…>

  • Major rework of the "/dev/console" driver.
  • Added termios support for stdin ( keyboard ).
  • Added ioctls() to support modes similar to Linux( XLATE, RAW, MEDIUMRAW ).
  • Added Keyboard mapping and handling of the keyboard's leds.
  • Added Micro FrameBuffer? driver ( "/dev/fb0" ) for bare VGA controller ( 16 colors ).
  • Added PS/2 and Serial mouse support for PC386 BSP.
  • console/defkeymap.c: New file.
  • console/fb_vga.c: New file.
  • console/fb_vga.h: New file.
  • console/i386kbd.h: New file.
  • console/kd.h: New file.
  • console/keyboard.c: New file.
  • console/keyboard.h: New file.
  • console/mouse_parser.c: New file.
  • console/mouse_parser.h: New file.
  • console/pc_keyb.c: New file.
  • console/ps2_drv.h: New file.
  • console/ps2_mouse.c: New file.
  • console/ps2_mouse.h: New file.
  • console/serial_mouse.c: New file.
  • console/serial_mouse.h: New file.
  • console/vgainit.c: New file.
  • console/vt.c: New file.
  • console/Makefile.am: Reflect new files.
  • console/console.c, console/inch.c, console/outch.c: Console functionality modifications.
  • startup/Makefile.am: Pick up tty_drv.c and gdb_glue.c
  • Property mode set to 100644
File size: 13.5 KB
Line 
1/*-------------------------------------------------------------------------+
2| console.c v1.1 - PC386 BSP - 1997/08/07
3+--------------------------------------------------------------------------+
4| This file contains the PC386 console I/O package.
5+--------------------------------------------------------------------------+
6| (C) Copyright 1997 -
7| - NavIST Group - Real-Time Distributed Systems and Industrial Automation
8|
9| http://pandora.ist.utl.pt
10|
11| Instituto Superior Tecnico * Lisboa * PORTUGAL
12+--------------------------------------------------------------------------+
13| Disclaimer:
14|
15| This file is provided "AS IS" without warranty of any kind, either
16| expressed or implied.
17+--------------------------------------------------------------------------+
18| This code is based on:
19|   console.c,v 1.4 1995/12/19 20:07:23 joel Exp - go32 BSP
20| With the following copyright notice:
21| **************************************************************************
22| *  COPYRIGHT (c) 1989-1999.
23| *  On-Line Applications Research Corporation (OAR).
24| *
25| *  The license and distribution terms for this file may be
26| *  found in found in the file LICENSE in this distribution or at
27| *  http://www.OARcorp.com/rtems/license.html.
28| **************************************************************************
29|
30|  $Id$
31+--------------------------------------------------------------------------*/
32
33#include <stdio.h>
34#include <stdlib.h>
35#include <assert.h>
36#include <unistd.h>
37#undef __assert
38void __assert (const char *file, int line, const char *msg);
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#include <rtems/mw_uid.h>
48#include "mouse_parser.h"
49
50/*
51 * Possible value for console input/output :
52 *      BSP_CONSOLE_PORT_CONSOLE
53 *      BSP_UART_COM1
54 *      BSP_UART_COM2
55 *
56 * Note:
57 *   1. Currently BSPPrintkPort, cannot be assigned to COM2,
58 *      it will be fixed soon.
59 *
60 *   2. If both BSPConsolePort and BSPPrintkport are assigned
61 *      to same serial device it does not work that great
62 */
63
64int BSPConsolePort = BSP_CONSOLE_PORT_CONSOLE;
65int BSPPrintkPort  = BSP_CONSOLE_PORT_CONSOLE;
66
67/* int BSPConsolePort = BSP_UART_COM2;  */
68int BSPBaseBaud    = 115200;
69
70extern BSP_polling_getchar_function_type BSP_poll_char;
71extern int getch( void );
72extern void kbd_init( void );
73
74/*-------------------------------------------------------------------------+
75| External Prototypes
76+--------------------------------------------------------------------------*/
77extern void keyboard_interrupt(void);
78extern char BSP_wait_polled_input(void);
79extern void _IBMPC_initVideo(void);
80
81static int  conSetAttr(int minor, const struct termios *);
82static void isr_on(const rtems_irq_connect_data *);
83static void isr_off(const rtems_irq_connect_data *);
84static int  isr_is_on(const rtems_irq_connect_data *);
85
86extern int rtems_kbpoll( void );
87
88static rtems_irq_connect_data console_isr_data = {BSP_KEYBOARD,
89                     keyboard_interrupt,
90                                                   isr_on,
91                                                   isr_off,
92                                                   isr_is_on};
93
94static void
95isr_on(const rtems_irq_connect_data *unused)
96{
97  return;
98}
99                                                   
100static void
101isr_off(const rtems_irq_connect_data *unused)
102{
103  return;
104}
105
106static int
107isr_is_on(const rtems_irq_connect_data *irq)
108{
109  return BSP_irq_enabled_at_i8259s(irq->name);
110}
111
112extern char _IBMPC_inch(void);
113extern int  rtems_kbpoll( void );
114
115static int
116ibmpc_console_write(int minor, const char *buf, int len)
117{
118  int count;
119  for (count = 0; count < len; count++)
120  {
121    _IBMPC_outch( buf[ count ] );
122    if( buf[ count ] == '\n')
123      _IBMPC_outch( '\r' );            /* LF = LF + CR */
124  }
125  return 0;
126}
127
128
129int kbd_poll_read( int minor )
130{
131  if( rtems_kbpoll() )
132  {
133     int c = getch();
134     return c;
135  }
136  return -1;
137}
138
139/*
140static void*         termios_ttyp_console         = NULL;
141void enq_key( char key )
142{
143  if( termios_ttyp_console )
144  {
145          rtems_termios_enqueue_raw_characters(termios_ttyp_console, &key,1 );
146  }
147}
148*/
149
150void __assert (const char *file, int line, const char *msg)
151{
152    static   char exit_msg[] = "EXECUTIVE SHUTDOWN! Any key to reboot...";
153  unsigned char  ch;
154   
155  /*
156   * Note we cannot call exit or printf from here,
157   * assert can fail inside ISR too
158   */
159
160   /*
161   * Close console
162   */
163  close(2);
164  close(1);
165  close(0);
166
167  printk("\nassert failed: %s: ", file);
168  printk("%d: ", line);
169  printk("%s\n\n", msg);
170  printk(exit_msg);
171  ch = BSP_poll_char();
172  printk("\n\n");
173  rtemsReboot();
174
175}
176
177
178/*-------------------------------------------------------------------------+
179| Console device driver INITIALIZE entry point.
180+--------------------------------------------------------------------------+
181| Initilizes the I/O console (keyboard + VGA display) driver.
182+--------------------------------------------------------------------------*/
183rtems_device_driver
184console_initialize(rtems_device_major_number major,
185                   rtems_device_minor_number minor,
186                   void                      *arg)
187{
188  rtems_status_code status;
189
190
191  /* Initialize the KBD interface */
192  kbd_init();
193
194  /*
195   * Set up TERMIOS
196   */
197  rtems_termios_initialize ();
198
199  /*
200   *  The video was initialized in the start.s code and does not need
201   *  to be reinitialized.
202   */
203
204  if(BSPConsolePort == BSP_CONSOLE_PORT_CONSOLE)
205    {
206      /* Install keyboard interrupt handler */
207      status = BSP_install_rtems_irq_handler(&console_isr_data);
208 
209    if (!status)
210        {
211          printk("Error installing keyboard interrupt handler!\n");
212          rtems_fatal_error_occurred(status);
213        }
214     
215      status = rtems_io_register_name("/dev/console", major, 0);
216      if (status != RTEMS_SUCCESSFUL)
217        {
218          printk("Error registering console device!\n");
219          rtems_fatal_error_occurred(status);
220        }
221      printk("Initialized console on port CONSOLE\n\n");
222    }
223  else
224    {
225      /*
226       * Do device-specific initialization
227       */
228      /* 9600-8-N-1 */
229      BSP_uart_init(BSPConsolePort, 9600, 0);
230     
231     
232      /* Set interrupt handler */
233      if(BSPConsolePort == BSP_UART_COM1)
234        {
235             console_isr_data.name = BSP_UART_COM1_IRQ;
236        console_isr_data.hdl  = BSP_uart_termios_isr_com1;
237         
238        }
239      else
240           {
241          assert(BSPConsolePort == BSP_UART_COM2);
242          console_isr_data.name = BSP_UART_COM2_IRQ;
243          console_isr_data.hdl  = BSP_uart_termios_isr_com2;
244        }
245      status = BSP_install_rtems_irq_handler(&console_isr_data);
246
247      if (!status){
248          printk("Error installing serial console interrupt handler!\n");
249          rtems_fatal_error_occurred(status);
250      }
251      /*
252       * Register the device
253       */
254      status = rtems_io_register_name ("/dev/console", major, 0);
255      if (status != RTEMS_SUCCESSFUL)
256        {
257          printk("Error registering console device!\n");
258          rtems_fatal_error_occurred (status);
259        }
260
261      if(BSPConsolePort == BSP_UART_COM1)
262        {
263          printk("Initialized console on port COM1 9600-8-N-1\n\n");
264        }
265      else
266        {
267          printk("Initialized console on port COM2 9600-8-N-1\n\n");
268        }
269
270      if(BSPPrintkPort == BSP_UART_COM1)
271        {
272          printk("Warning : This will be the last message on console\n");
273
274          /*
275           * FIXME: cast below defeats the very idea of having
276           * function pointer types defined
277           */
278          BSP_output_char = (BSP_output_char_function_type)
279                              BSP_output_char_via_serial;
280          BSP_poll_char   = (BSP_polling_getchar_function_type)
281                              BSP_poll_char_via_serial;
282        }
283      else if(BSPPrintkPort != BSP_CONSOLE_PORT_CONSOLE)
284        {
285           printk("illegal assignement of projtk channel");
286         rtems_fatal_error_occurred (status);
287        }
288
289    }
290  return RTEMS_SUCCESSFUL;
291} /* console_initialize */
292
293
294static int console_open_count = 0;
295
296static int console_last_close(int major, int minor, void *arg)
297{
298  BSP_remove_rtems_irq_handler (&console_isr_data);
299
300  return 0;
301}
302
303/*-------------------------------------------------------------------------+
304| Console device driver OPEN entry point
305+--------------------------------------------------------------------------*/
306rtems_device_driver
307console_open(rtems_device_major_number major,
308                rtems_device_minor_number minor,
309                void                      *arg)
310{
311  rtems_status_code              status;
312  static rtems_termios_callbacks cb = 
313  {
314    NULL,                     /* firstOpen */
315    console_last_close,       /* lastClose */
316    NULL,          /* pollRead */
317    BSP_uart_termios_write_com1, /* write */
318    conSetAttr,               /* setAttributes */
319    NULL,                     /* stopRemoteTx */
320    NULL,                     /* startRemoteTx */
321    1                         /* outputUsesInterrupts */
322  };
323
324  if(BSPConsolePort == BSP_CONSOLE_PORT_CONSOLE)
325    {
326
327      /* Let's set the routines for termios to poll the
328       * Kbd queue for data
329       */
330      cb.pollRead = kbd_poll_read;
331      cb.outputUsesInterrupts = 0;
332      /* write the "echo" if it is on */
333      cb.write = ibmpc_console_write;
334
335      cb.setAttributes = NULL;
336      ++console_open_count;
337      status = rtems_termios_open (major, minor, arg, &cb);
338      if(status != RTEMS_SUCCESSFUL)
339      {
340         printk("Error openning console device\n");
341      }
342      return status;
343    }
344
345  if(BSPConsolePort == BSP_UART_COM2)
346    {
347      cb.write = BSP_uart_termios_write_com2;
348    }
349
350  status = rtems_termios_open (major, minor, arg, &cb);
351
352  if(status != RTEMS_SUCCESSFUL)
353    {
354      printk("Error openning console device\n");
355      return status;
356    }
357
358  /*
359   * Pass data area info down to driver
360   */
361  BSP_uart_termios_set(BSPConsolePort, 
362                         ((rtems_libio_open_close_args_t *)arg)->iop->data1);
363 
364  /* Enable interrupts  on channel */
365  BSP_uart_intr_ctrl(BSPConsolePort, BSP_UART_INTR_CTRL_TERMIOS);
366
367  return RTEMS_SUCCESSFUL;
368}
369
370/*-------------------------------------------------------------------------+
371| Console device driver CLOSE entry point
372+--------------------------------------------------------------------------*/
373rtems_device_driver
374console_close(rtems_device_major_number major,
375              rtems_device_minor_number minor,
376              void                      *arg)
377{
378   return rtems_termios_close (arg);
379} /* console_close */
380
381 
382/*-------------------------------------------------------------------------+
383| Console device driver READ entry point.
384+--------------------------------------------------------------------------+
385| Read characters from the I/O console. We only have stdin.
386+--------------------------------------------------------------------------*/
387rtems_device_driver
388console_read(rtems_device_major_number major,
389             rtems_device_minor_number minor,
390             void                      *arg)
391{
392 return rtems_termios_read( arg );
393} /* console_read */
394 
395
396/*-------------------------------------------------------------------------+
397| Console device driver WRITE entry point.
398+--------------------------------------------------------------------------+
399| Write characters to the I/O console. Stderr and stdout are the same.
400+--------------------------------------------------------------------------*/
401rtems_device_driver
402console_write(rtems_device_major_number major,
403              rtems_device_minor_number minor,
404              void                    * arg)
405{
406  rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *)arg;
407  char                  *buffer  = rw_args->buffer;
408  int                    maximum  = rw_args->count;
409
410  if(BSPConsolePort != BSP_CONSOLE_PORT_CONSOLE)
411    {
412      return rtems_termios_write (arg);
413    }
414 
415  /* write data to VGA */
416  ibmpc_console_write( minor, buffer, maximum );
417  rw_args->bytes_moved = maximum;
418  return RTEMS_SUCCESSFUL;
419} /* console_write */
420
421
422extern int vt_ioctl( unsigned int cmd, unsigned long arg);
423 
424/*
425 * Handle ioctl request.
426 */
427rtems_device_driver
428console_control(rtems_device_major_number major,
429                rtems_device_minor_number minor,
430                void                      * arg
431)
432{ 
433        rtems_libio_ioctl_args_t *args = arg;
434        switch (args->command) 
435        {
436           default:
437      if( vt_ioctl( args->command, (unsigned long)args->buffer ) != 0 )
438          return rtems_termios_ioctl (arg);
439                break;
440
441      case MW_UID_REGISTER_DEVICE:
442      printk( "SerialMouse: reg=%s\n", args->buffer );
443      register_kbd_msg_queue( args->buffer, 0 );
444                break;
445
446      case MW_UID_UNREGISTER_DEVICE:
447      unregister_kbd_msg_queue( 0 );
448                break;
449   }
450        args->ioctl_return = 0;
451   return RTEMS_SUCCESSFUL;
452}
453
454static int
455conSetAttr(int minor, const struct termios *t)
456{
457  int baud;
458
459  switch (t->c_cflag & CBAUD) 
460    {
461    case B50:   
462      baud = 50;
463      break;
464    case B75:   
465      baud = 75;       
466      break;
467    case B110: 
468      baud = 110;       
469      break;
470    case B134: 
471      baud = 134;       
472      break;
473    case B150: 
474      baud = 150;       
475      break;
476    case B200:
477      baud = 200;       
478      break;
479    case B300: 
480      baud = 300;
481      break;
482    case B600: 
483      baud = 600;       
484      break;
485    case B1200: 
486      baud = 1200;
487      break;
488    case B1800: 
489      baud = 1800;     
490      break;
491    case B2400: 
492      baud = 2400;
493      break;
494    case B4800: 
495      baud = 4800;
496      break;
497    case B9600: 
498      baud = 9600;
499      break;
500    case B19200:
501      baud = 19200;
502      break;
503    case B38400:
504      baud = 38400;
505      break;
506    case B57600:       
507      baud = 57600;
508      break;
509    case B115200:
510      baud = 115200;
511      break;
512    default:
513      baud = 0;
514      rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR);
515      return 0;
516    }
517
518  BSP_uart_set_baud(BSPConsolePort, baud);
519
520  return 0;
521}
522
523/*
524 * BSP initialization
525 */
526
527BSP_output_char_function_type BSP_output_char = 
528                       (BSP_output_char_function_type) _IBMPC_outch;
529
530BSP_polling_getchar_function_type BSP_poll_char = BSP_wait_polled_input;
531
532
Note: See TracBrowser for help on using the repository browser.