source: rtems/cpukit/libmisc/mouse/serial_mouse.c @ 03b5096

4.115
Last change on this file since 03b5096 was 03b5096, checked in by Joel Sherrill <joel.sherrill@…>, on 03/14/11 at 18:17:28

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

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