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

4.104.114.84.95
Last change on this file since 9751c913 was 9751c913, checked in by Joel Sherrill <joel.sherrill@…>, on 12/05/00 at 16:37:38

2000-12-01 Joel Sherrill <joel@…>

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