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

4.104.114.84.95
Last change on this file since 396555aa was 396555aa, checked in by Joel Sherrill <joel.sherrill@…>, on 10/20/00 at 16:01:13

2000-10-20 Rosimildo da Silva <rdasilva@…>

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