source: rtems/testsuites/libtests/mouse01/init.c @ 7cb170b3

4.11
Last change on this file since 7cb170b3 was 7cb170b3, checked in by Ralf Corsepius <ralf.corsepius@…>, on Sep 29, 2011 at 3:54:09 PM

2011-09-29 Ralf Corsépius <ralf.corsepius@…>

  • mouse01/init.c, mouse01/msmouse.c, mouse01/serial_mouse_config.c: Add HAVE_CONFIG_H.
  • Property mode set to 100644
File size: 3.4 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#ifdef HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <bsp.h>
17
18#include <stdlib.h>
19#include <stdio.h>
20
21#include <sys/types.h>
22#include <sys/stat.h>
23#include <fcntl.h>
24#include <sys/ioctl.h>
25#include <unistd.h>
26#include <rtems/mw_uid.h>
27#include "termios_testdriver_intr.h"
28#include "tmacros.h"
29
30extern const char *Mouse_Type_Long;
31extern const char *Mouse_Type_Short;
32extern const unsigned char Mouse_Actions[];
33extern const size_t Mouse_Actions_Size;
34extern const size_t Mouse_Actions_Per_Iteration;
35
36int Mouse_Index = 0;
37
38bool enqueue_next_action(
39  const unsigned char *actions,
40  size_t               max,
41  size_t               to_enqueue
42)
43{
44  if ( (Mouse_Index + to_enqueue) > max )
45    return false;
46
47  termios_test_driver_set_rx_enqueue_now( true );
48 
49  termios_test_driver_set_rx( &actions[Mouse_Index], to_enqueue );
50  Mouse_Index += to_enqueue;
51
52  return true;
53}
54
55int Test_fd;
56
57void open_it(void)
58{
59  /* open the file */
60  puts( "open(/dev/mouse) - OK " );
61  Test_fd = open( "/dev/mouse", O_RDONLY );
62  rtems_test_assert( Test_fd != -1 );
63}
64
65void register_it(void)
66{
67  int                rc;
68  char               name[5] = "mous";
69
70  printf( "uid_open_queue() - mouse queue\n" );
71  rc = uid_open_queue( name, 0, 10 );
72  rtems_test_assert( rc == 0 );
73
74  printf( "uid_register_device() - OK\n");
75  rc = uid_register_device( Test_fd, name );
76  rtems_test_assert( rc == 0 );
77}
78
79void printf_uid_message(
80  struct MW_UID_MESSAGE *uid
81)
82{
83  uid_print_message_with_plugin(
84    stdout,
85    (rtems_printk_plugin_t)fprintf,
86    uid
87  );
88}
89
90void receive_uid_message(void)
91{
92  int                    rc;
93  struct MW_UID_MESSAGE  uid;
94
95  rc = uid_read_message( &uid, 0 );
96  if ( rc != sizeof(struct MW_UID_MESSAGE) )
97    return;
98  printf_uid_message( &uid );
99}
100
101void close_it(void)
102{
103  int rc;
104
105  printf( "uid_unregister_device() - OK\n" );
106  rc = uid_unregister_device( Test_fd );
107  rtems_test_assert( rc == 0 );
108
109  puts( "close(/dev/mouse) - OK " );
110  rc = close( Test_fd );
111  rtems_test_assert( rc == 0 );
112}
113
114rtems_task Init(
115  rtems_task_argument ignored
116)
117{
118  bool more_data;
119
120  printf( "\n\n*** %s TEST ***\n", Mouse_Type_Long );
121
122  open_it();
123  register_it(); 
124  do {
125    more_data = enqueue_next_action(
126      Mouse_Actions,
127      Mouse_Actions_Size, 
128      Mouse_Actions_Per_Iteration
129    );
130    receive_uid_message();
131  } while (more_data);
132  close_it(); 
133  printf( "*** END OF %s TEST ***\n", Mouse_Type_Long );
134  rtems_test_exit( 0 );
135}
136
137/* configuration information */
138
139#include <rtems/serial_mouse.h>
140#include "termios_testdriver_intr.h"
141
142/* NOTICE: the clock driver is explicitly disabled */
143#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
144#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
145#define CONFIGURE_APPLICATION_EXTRA_DRIVERS \
146    TERMIOS_TEST_DRIVER_TABLE_ENTRY, \
147    SERIAL_MOUSE_DRIVER_TABLE_ENTRY
148
149/* one for the console and one for the test port */
150#define CONFIGURE_NUMBER_OF_TERMIOS_PORTS 2
151
152/* we need to be able to open the test device and mouse */
153#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5
154#define CONFIGURE_MAXIMUM_TASKS  1
155#define CONFIGURE_MAXIMUM_TIMERS 2
156#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 1
157
158#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
159#define CONFIGURE_INIT
160
161#include <rtems/confdefs.h>
162
163/* end of file */
Note: See TracBrowser for help on using the repository browser.