source: rtems/testsuites/libtests/mouse01/init.c @ 4c86e3d

4.115
Last change on this file since 4c86e3d was 4c86e3d, checked in by Joel Sherrill <joel.sherrill@…>, on 05/11/12 at 17:20:47

libtmtests - Eliminate missing prototype warnings

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