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

4.104.114.84.9
Last change on this file since 6daada6 was 6daada6, checked in by Jennifer Averett <Jennifer.Averett@…>, on May 6, 2005 at 7:53:03 PM

2005-05-06 Jennifer Averett <jennifer.averett@…>

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