[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 | |
---|
| 24 | int serial_mouse_fd = -1; |
---|
| 25 | const char *serial_mouse_device; |
---|
| 26 | const char *serial_mouse_type; |
---|
| 27 | |
---|
[3ab21dce] | 28 | static int serial_mouse_l_rint(int c, struct rtems_termios_tty *tp) |
---|
[3d6c1bb] | 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 | |
---|
| 37 | static 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 | */ |
---|
| 52 | rtems_device_driver serial_mouse_initialize( |
---|
| 53 | rtems_device_major_number major, |
---|
| 54 | rtems_device_minor_number minor, |
---|
| 55 | void *arg |
---|
| 56 | ) |
---|
| 57 | { |
---|
[2dc3399] | 58 | bsp_get_serial_mouse_device( |
---|
[3d6c1bb] | 59 | &serial_mouse_device, |
---|
| 60 | &serial_mouse_type |
---|
| 61 | ); |
---|
| 62 | |
---|
| 63 | (void) rtems_io_register_name( "/dev/mouse", major, 0 ); |
---|
| 64 | |
---|
| 65 | rtems_termios_linesw[ 6 ] = serial_mouse_linesw; |
---|
| 66 | |
---|
| 67 | return RTEMS_SUCCESSFUL; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | /* |
---|
| 71 | * serial_mouse - device driver OPEN entry point |
---|
| 72 | */ |
---|
| 73 | rtems_device_driver serial_mouse_open( |
---|
| 74 | rtems_device_major_number major, |
---|
| 75 | rtems_device_minor_number minor, |
---|
| 76 | void *args |
---|
| 77 | ) |
---|
| 78 | { |
---|
| 79 | struct termios termios_attr; |
---|
| 80 | int status; |
---|
| 81 | int disc = 6; |
---|
| 82 | |
---|
| 83 | /* XXX open(2) the configured /dev/comX */ |
---|
| 84 | /* XXX save the file descriptor */ |
---|
| 85 | serial_mouse_fd = open( serial_mouse_device, O_RDONLY ); |
---|
| 86 | if ( serial_mouse_fd == -1 ) { |
---|
| 87 | printk( |
---|
| 88 | "Error opening serial_mouse device on %s\n", |
---|
| 89 | serial_mouse_device |
---|
| 90 | ); |
---|
| 91 | return RTEMS_IO_ERROR; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | /* 1200-8-N-1, without hardware flow control */ |
---|
| 95 | /* BSP_uart_init( BSP_UART_PORT, 1200, CHR_8_BITS, 0, 0, 0 ); */ |
---|
| 96 | status = tcgetattr(serial_mouse_fd, &termios_attr ); |
---|
| 97 | if (status != 0) { |
---|
| 98 | printk("Error getting mouse attributes\n"); |
---|
| 99 | return RTEMS_IO_ERROR; |
---|
| 100 | } |
---|
| 101 | termios_attr.c_lflag &= ~(ICANON|ECHO|ECHONL|ECHOK|ECHOE|ECHOPRT|ECHOCTL); |
---|
| 102 | termios_attr.c_iflag &= ~(IXON|IXANY|IXOFF); |
---|
| 103 | /* |
---|
| 104 | termios_attr.c_cc[VMIN] = itask_VMIN; |
---|
| 105 | termios_attr.c_cc[VTIME] = itask_VTIME; |
---|
| 106 | */ |
---|
| 107 | termios_attr.c_cflag |= B1200; |
---|
| 108 | termios_attr.c_cflag |= CS8; |
---|
| 109 | status = tcsetattr( serial_mouse_fd, TCSANOW, &termios_attr ); |
---|
| 110 | if (status != 0) { |
---|
| 111 | printk("Error setting mouse attributes\n"); |
---|
| 112 | return RTEMS_IO_ERROR; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | status = ioctl(serial_mouse_fd, TIOCSETD, &disc); |
---|
| 116 | if (status != 0) { |
---|
| 117 | printk("Error setting mouse attributes\n"); |
---|
| 118 | return RTEMS_IO_ERROR; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | sleep(5); |
---|
| 122 | return RTEMS_SUCCESSFUL; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | rtems_device_driver serial_mouse_close( |
---|
| 126 | rtems_device_major_number major, |
---|
| 127 | rtems_device_minor_number minor, |
---|
| 128 | void *arg |
---|
| 129 | ) |
---|
| 130 | { |
---|
| 131 | close( serial_mouse_fd ); |
---|
| 132 | |
---|
| 133 | return RTEMS_SUCCESSFUL; |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | rtems_device_driver serial_mouse_read( |
---|
| 137 | rtems_device_major_number major, |
---|
| 138 | rtems_device_minor_number minor, |
---|
| 139 | void *arg |
---|
| 140 | ) |
---|
| 141 | { |
---|
| 142 | return RTEMS_SUCCESSFUL; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | |
---|
| 146 | rtems_device_driver serial_mouse_write( |
---|
| 147 | rtems_device_major_number major, |
---|
| 148 | rtems_device_minor_number minor, |
---|
| 149 | void *arg |
---|
| 150 | ) |
---|
| 151 | { |
---|
| 152 | return RTEMS_SUCCESSFUL; |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | |
---|
| 156 | rtems_device_driver serial_mouse_control( |
---|
| 157 | rtems_device_major_number major, |
---|
| 158 | rtems_device_minor_number minor, |
---|
| 159 | void *arg |
---|
| 160 | ) |
---|
| 161 | { |
---|
| 162 | rtems_libio_ioctl_args_t *args = (rtems_libio_ioctl_args_t *)arg; |
---|
| 163 | |
---|
| 164 | switch( args->command ) { |
---|
| 165 | |
---|
| 166 | case MW_UID_REGISTER_DEVICE: |
---|
| 167 | printk( "SerialMouse: reg=%s\n", args->buffer ); |
---|
| 168 | mouse_parser_initialize( serial_mouse_type ); |
---|
| 169 | break; |
---|
| 170 | |
---|
| 171 | case MW_UID_UNREGISTER_DEVICE: |
---|
| 172 | break; |
---|
| 173 | |
---|
| 174 | default: |
---|
| 175 | args->ioctl_return = ioctl(serial_mouse_fd, args->command, args->buffer ); |
---|
| 176 | if ( !args->ioctl_return ) |
---|
| 177 | return RTEMS_SUCCESSFUL; |
---|
| 178 | return RTEMS_IO_ERROR; |
---|
| 179 | } |
---|
| 180 | args->ioctl_return = 0; |
---|
| 181 | return RTEMS_SUCCESSFUL; |
---|
| 182 | } |
---|