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

4.104.114.84.95
Last change on this file since f05b2ac was f05b2ac, checked in by Ralf Corsepius <ralf.corsepius@…>, on 04/21/04 at 16:01:48

Remove duplicate white lines.

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