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

4.104.114.84.95
Last change on this file since 3cbb63a was 3cbb63a, checked in by Joel Sherrill <joel.sherrill@…>, on 08/30/00 at 08:15:30

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: 8.0 KB
Line 
1/***************************************************************************
2 *
3 * $Header$
4 *
5 * MODULE DESCRIPTION:
6 * This module implements the RTEMS drivers for the PC serial ports
7 * as /dev/ttyS1 for COM1 and /dev/ttyS2 as COM2. If one of the ports
8 * is used as the console, this driver would fail to initialize.
9 *
10 * This code was based on the console driver. It is based on the
11 * current termios framework. This is just a shell around the
12 * termios support.
13 *
14 * by: Rosimildo da Silva:
15 *     rdasilva@connecttel.com
16 *     http://www.connecttel.com
17 *
18 * MODIFICATION/HISTORY:
19 *
20 * $Log$
21 ****************************************************************************/
22
23#include <stdio.h>
24#include <stdlib.h>
25#include <assert.h>
26
27#include <bsp.h>
28#include <irq.h>
29#include <rtems/libio.h>
30#include <termios.h>
31#include <uart.h>
32#include <libcpu/cpuModel.h>
33
34int BSP_poll_read(int);
35
36#include <rtems/mw_uid.h>
37#include "serial_mouse.h"
38#include "mouse_parser.h"
39
40/* Internal routines */
41static int serial_mouse_conSetAttr( int minor, const struct termios *t);
42static void isr_on(const rtems_irq_connect_data *);
43static void isr_off(const rtems_irq_connect_data *);
44static int  isr_is_on(const rtems_irq_connect_data *);
45
46
47extern BSP_polling_getchar_function_type BSP_poll_char;
48extern int BSPConsolePort;
49
50/* Select Default to be COM1  */
51#if !defined( SERIAL_MOUSE_COM1 ) && !defined( SERIAL_MOUSE_COM2 )
52#define SERIAL_MOUSE_COM1  1
53#endif
54
55/* select which serial port the mouse is connected to */
56#ifdef   SERIAL_MOUSE_COM1
57#define  BSP_UART_PORT    BSP_UART_COM1
58#define  BSP_UART_IRQ     BSP_UART_COM1_IRQ
59#define  BSP_ISR_FUNC     BSP_uart_termios_isr_com1
60#define  BSP_WRITE_FUNC   BSP_uart_termios_write_com1
61#endif
62
63#ifdef   SERIAL_MOUSE_COM2
64#define  BSP_UART_PORT    BSP_UART_COM2
65#define  BSP_UART_IRQ     BSP_UART_COM2_IRQ
66#define  BSP_ISR_FUNC     BSP_uart_termios_isr_com2
67#define  BSP_WRITE_FUNC   BSP_uart_termios_write_com2
68#endif
69
70/*
71 * Interrupt structure for serial_mouse
72 */
73static rtems_irq_connect_data serial_mouse_isr_data =
74{
75  BSP_UART_IRQ,
76  BSP_ISR_FUNC,
77  isr_on,
78  isr_off,
79  isr_is_on};
80
81static void isr_on(const rtems_irq_connect_data *unused)
82{
83  return;
84}
85                                                   
86static void isr_off(const rtems_irq_connect_data *unused)
87{
88  return;
89}
90
91static int isr_is_on(const rtems_irq_connect_data *irq)
92{
93  return BSP_irq_enabled_at_i8259s(irq->name);
94}
95
96void serial_mouse_reserve_resources(rtems_configuration_table *conf)
97{
98  rtems_termios_reserve_resources(conf, 1);
99  return;
100}
101
102/*
103 *  Serial Mouse - device driver INITIALIZE entry point.
104 */
105rtems_device_driver
106serial_mouse_initialize(rtems_device_major_number major,
107                   rtems_device_minor_number minor,
108                   void                      *arg)
109{
110  rtems_status_code status;
111
112  /* Check if this port is not been used as console */
113  if( BSPConsolePort == BSP_UART_PORT )
114  {
115    status = -1;
116    printk("SERIAL MOUSE: port selected as console.( %d )\n", BSP_UART_PORT  );
117    rtems_fatal_error_occurred( status );
118  }
119
120  /*
121   * Set up TERMIOS
122   */
123  rtems_termios_initialize();
124 
125  /*
126   * Do device-specific initialization
127   */
128  /* 9600-8-N-1, without hardware flow control */
129  BSP_uart_init( BSP_UART_PORT, 1200, 0 );
130  status = BSP_install_rtems_irq_handler( &serial_mouse_isr_data );
131  if( !status )
132  {
133    printk("Error installing serial mouse interrupt handler!\n");
134    rtems_fatal_error_occurred(status);
135  }
136  /*
137   * Register the device
138   */
139  status = rtems_io_register_name ("/dev/mouse", major, 0);
140  if (status != RTEMS_SUCCESSFUL)
141  {
142      printk("Error registering /dev/mouse device!\n");
143      rtems_fatal_error_occurred (status);
144  }
145  printk("Device: /dev/mouse on COM%d -- ok \n", BSP_UART_PORT );
146  return RTEMS_SUCCESSFUL;
147} /* tty_initialize */
148
149
150static int serial_mouse_last_close(int major, int minor, void *arg)
151{
152  BSP_remove_rtems_irq_handler( &serial_mouse_isr_data );
153  return 0;
154}
155
156/*
157 * serial_mouse - device driver OPEN entry point
158 */
159rtems_device_driver
160serial_mouse_open(rtems_device_major_number major,
161                rtems_device_minor_number minor,
162                void                      *arg)
163{
164  rtems_status_code  status;
165  static rtems_termios_callbacks cb =
166  {
167    NULL,                     /* firstOpen */
168    serial_mouse_last_close,       /* lastClose */
169    NULL,                          /* poll read  */
170    BSP_WRITE_FUNC,        /* write */
171    serial_mouse_conSetAttr,         /* setAttributes */
172    NULL,                     /* stopRemoteTx */
173    NULL,                     /* startRemoteTx */
174    1                         /* outputUsesInterrupts */
175  };
176
177  status = rtems_termios_open( major, minor, arg, &cb );
178  if(status != RTEMS_SUCCESSFUL)
179  {
180     printk("Error openning serial_mouse device\n");
181     return status;
182  }
183
184  /*
185   * Pass data area info down to driver
186   */
187  BSP_uart_termios_set( BSP_UART_PORT,
188                       ((rtems_libio_open_close_args_t *)arg)->iop->data1 );
189  /* Enable interrupts  on channel */
190  BSP_uart_intr_ctrl( BSP_UART_PORT, BSP_UART_INTR_CTRL_TERMIOS);
191  return RTEMS_SUCCESSFUL;
192}
193
194/*
195 * TTY - device driver CLOSE entry point
196 */
197rtems_device_driver
198serial_mouse_close(rtems_device_major_number major,
199              rtems_device_minor_number minor,
200              void                      *arg)
201{
202
203  return (rtems_termios_close (arg));
204 
205} /* tty_close */
206
207 
208/*
209 * TTY device driver READ entry point.
210 * Read characters from the tty device.
211 */
212rtems_device_driver
213serial_mouse_read(rtems_device_major_number major,
214             rtems_device_minor_number minor,
215             void                      *arg)
216{
217  return rtems_termios_read (arg);
218} /* tty_read */
219 
220
221/*
222 * TTY device driver WRITE entry point.
223 * Write characters to the tty device.
224 */
225rtems_device_driver
226serial_mouse_write(rtems_device_major_number major,
227              rtems_device_minor_number minor,
228              void                    * arg)
229{
230    return rtems_termios_write (arg);
231 
232} /* tty_write */
233
234/*
235 * Handle ioctl request. This is a generic internal
236 * routine to handle both devices.
237 */
238static rtems_device_driver serial_mouse_control_internal( int port, void  *arg )
239{
240        rtems_libio_ioctl_args_t *args = arg;
241        switch( args->command )
242        {
243           default:
244      return rtems_termios_ioctl (arg);
245                break;
246
247      case MW_UID_REGISTER_DEVICE:
248      printk( "SerialMouse: reg=%s\n", args->buffer );
249      register_mou_msg_queue( args->buffer, BSP_UART_PORT );
250                break;
251
252      case MW_UID_UNREGISTER_DEVICE:
253      unregister_mou_msg_queue( BSP_UART_PORT );
254                break;
255
256   }
257        args->ioctl_return = 0;
258   return RTEMS_SUCCESSFUL;
259}
260
261/*
262 * Handle ioctl request for ttyS1.
263 */
264rtems_device_driver
265serial_mouse_control(rtems_device_major_number major,
266                rtems_device_minor_number minor,
267                void                      * arg
268)
269{
270  return serial_mouse_control_internal( BSP_UART_PORT, arg );
271}
272
273static int
274conSetAttr(int port, int minor, const struct termios *t)
275{
276  int baud;
277
278  switch (t->c_cflag & CBAUD)
279    {
280    case B50:   
281      baud = 50;
282      break;
283    case B75:   
284      baud = 75;       
285      break;
286    case B110: 
287      baud = 110;       
288      break;
289    case B134: 
290      baud = 134;       
291      break;
292    case B150: 
293      baud = 150;       
294      break;
295    case B200:
296      baud = 200;       
297      break;
298    case B300: 
299      baud = 300;
300      break;
301    case B600: 
302      baud = 600;       
303      break;
304    case B1200:
305      baud = 1200;
306      break;
307    case B1800:
308      baud = 1800;     
309      break;
310    case B2400:
311      baud = 2400;
312      break;
313    case B4800:
314      baud = 4800;
315      break;
316    case B9600:
317      baud = 9600;
318      break;
319    case B19200:
320      baud = 19200;
321      break;
322    case B38400:
323      baud = 38400;
324      break;
325    case B57600:       
326      baud = 57600;
327      break;
328    case B115200:
329      baud = 115200;
330      break;
331    default:
332      baud = 0;
333      rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR);
334      return 0;
335    }
336  printk("Mouse baud, port=%X, baud=%d\n", port, baud );
337  BSP_uart_set_baud( port, baud );
338  return 0;
339}
340
341/*
342 * Handle ioctl request for ttyS2.
343 */
344static int
345serial_mouse_conSetAttr( int minor, const struct termios *t)
346{
347  return conSetAttr( BSP_UART_PORT, minor, t );
348}
Note: See TracBrowser for help on using the repository browser.