source: rtems/c/src/lib/libbsp/i386/pc386/console/serial_mouse.c @ 664db30b

4.104.114.84.95
Last change on this file since 664db30b was 664db30b, checked in by Joel Sherrill <joel.sherrill@…>, on 10/18/00 at 15:51:41

2000-10-18 Charles-Antoine Gauthier <charles.gauthier@…>

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