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

4.104.114.84.9
Last change on this file since cba119c9 was cba119c9, checked in by Ralf Corsepius <ralf.corsepius@…>, on Oct 17, 2005 at 10:34:02 AM

Remove CVS Log

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