source: rtems/cpukit/libmisc/mouse/serial_mouse.c @ 3d6c1bb

4.11
Last change on this file since 3d6c1bb was 3d6c1bb, checked in by Joel Sherrill <joel.sherrill@…>, on Mar 14, 2011 at 2:56:08 PM

2011-03-14 Joel Sherrill <joel.sherrill@…>

PR 1762/cpukit

  • Makefile.am, preinstall.am, libmisc/Makefile.am, wrapup/Makefile.am: Add generic serial mouse driver and mouse parser. The parser code was in the pc386 BSP but was generic so cleaned up and placed here. Serial mouse driver itself is new.
  • libmisc/mouse/README, libmisc/mouse/mouse_parser.c, libmisc/mouse/mouse_parser.h, libmisc/mouse/serial_mouse.c, libmisc/mouse/serial_mouse.h: New files.
  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2011.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#include <stdio.h>
13#include <stdlib.h>
14#include <bsp.h>
15#include <sys/types.h>
16#include <sys/stat.h>
17#include <fcntl.h>
18
19#include <rtems/libio.h>
20#include <termios.h>
21#include <rtems/termiostypes.h>
22#include <rtems/mouse_parser.h>
23#include <rtems/serial_mouse.h>
24
25int         serial_mouse_fd = -1;
26const char *serial_mouse_device;
27const char *serial_mouse_type;
28
29int serial_mouse_l_rint(int c, struct rtems_termios_tty *tp)
30{
31  unsigned char buf = c;
32 
33  /* call mouse_parser( void *ptr, char *buffer, int size ) */
34  mouse_parser_enqueue( &buf, 1 );
35  return 0;
36}
37
38static struct rtems_termios_linesw serial_mouse_linesw = {
39  .l_open = NULL,
40  .l_close = NULL,
41  .l_read  = NULL,
42  .l_write = NULL,
43  .l_rint  = serial_mouse_l_rint,
44  .l_start = NULL,
45  .l_ioctl = NULL,
46  .l_modem = NULL
47};
48
49
50/*
51 *  Serial Mouse - device driver INITIALIZE entry point.
52 */
53rtems_device_driver serial_mouse_initialize(
54  rtems_device_major_number  major,
55  rtems_device_minor_number  minor,
56  void                      *arg
57)
58{
59  bool status;
60
61  status = bsp_get_serial_mouse_device(
62    &serial_mouse_device,
63    &serial_mouse_type
64  );
65
66  (void) rtems_io_register_name( "/dev/mouse", major, 0 );
67
68  rtems_termios_linesw[ 6 ] = serial_mouse_linesw;
69
70  return RTEMS_SUCCESSFUL;
71}
72
73/*
74 * serial_mouse - device driver OPEN entry point
75 */
76rtems_device_driver serial_mouse_open(
77  rtems_device_major_number  major,
78  rtems_device_minor_number  minor,
79  void                      *args
80)
81{
82  struct termios  termios_attr;
83  int             status;
84  int             disc = 6;
85
86  /* XXX open(2) the configured /dev/comX */
87  /* XXX save the file descriptor */
88  serial_mouse_fd = open( serial_mouse_device, O_RDONLY );
89  if ( serial_mouse_fd == -1 ) {
90   printk(
91     "Error opening serial_mouse device on %s\n",
92     serial_mouse_device
93   );
94   return RTEMS_IO_ERROR;
95  }
96
97  /* 1200-8-N-1, without hardware flow control */
98  /* BSP_uart_init( BSP_UART_PORT, 1200, CHR_8_BITS, 0, 0, 0 ); */
99  status = tcgetattr(serial_mouse_fd, &termios_attr );
100  if (status != 0) {
101    printk("Error getting mouse attributes\n");
102    return RTEMS_IO_ERROR;
103  }
104  termios_attr.c_lflag &= ~(ICANON|ECHO|ECHONL|ECHOK|ECHOE|ECHOPRT|ECHOCTL);
105  termios_attr.c_iflag &= ~(IXON|IXANY|IXOFF);
106  /*
107  termios_attr.c_cc[VMIN] = itask_VMIN;
108  termios_attr.c_cc[VTIME] = itask_VTIME;
109  */
110  termios_attr.c_cflag |= B1200;
111  termios_attr.c_cflag |= CS8;
112  status = tcsetattr( serial_mouse_fd, TCSANOW, &termios_attr );
113  if (status != 0) {
114    printk("Error setting mouse attributes\n");
115    return RTEMS_IO_ERROR;
116  }
117
118  status = ioctl(serial_mouse_fd, TIOCSETD, &disc);
119  if (status != 0) {
120    printk("Error setting mouse attributes\n");
121    return RTEMS_IO_ERROR;
122  }
123
124  sleep(5);
125  return RTEMS_SUCCESSFUL;
126}
127
128rtems_device_driver serial_mouse_close(
129  rtems_device_major_number  major,
130  rtems_device_minor_number  minor,
131  void                      *arg
132)
133{
134  close( serial_mouse_fd );
135
136  return RTEMS_SUCCESSFUL;
137}
138
139rtems_device_driver serial_mouse_read(
140  rtems_device_major_number  major,
141  rtems_device_minor_number  minor,
142  void                      *arg
143)
144{
145  return RTEMS_SUCCESSFUL;
146}
147
148
149rtems_device_driver serial_mouse_write(
150  rtems_device_major_number  major,
151  rtems_device_minor_number  minor,
152  void                      *arg
153)
154{
155  return RTEMS_SUCCESSFUL;
156}
157
158
159rtems_device_driver serial_mouse_control(
160  rtems_device_major_number  major,
161  rtems_device_minor_number  minor,
162  void                      *arg
163)
164{
165  rtems_libio_ioctl_args_t *args = (rtems_libio_ioctl_args_t *)arg;
166
167  switch( args->command ) {
168
169    case MW_UID_REGISTER_DEVICE:
170      printk( "SerialMouse: reg=%s\n", args->buffer );
171      mouse_parser_initialize( serial_mouse_type );
172      break;
173
174    case MW_UID_UNREGISTER_DEVICE:
175      break;
176
177    default:
178      args->ioctl_return = ioctl(serial_mouse_fd, args->command, args->buffer );
179      if ( !args->ioctl_return )
180        return RTEMS_SUCCESSFUL;
181      return RTEMS_IO_ERROR;
182  }
183  args->ioctl_return = 0;
184  return RTEMS_SUCCESSFUL;
185}
Note: See TracBrowser for help on using the repository browser.