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

4.104.115
Last change on this file since debbc9e was e3a1d425, checked in by Joel Sherrill <joel.sherrill@…>, on 08/19/08 at 19:34:08

2008-08-19 Joel Sherrill <joel.sherrill@…>

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