source: rtems/testsuites/libtests/mouse01/init.c @ 5a868873

4.11
Last change on this file since 5a868873 was 5a868873, checked in by Sebastian Huber <sebastian.huber@…>, on Oct 26, 2011 at 11:13:59 AM

2011-10-26 Sebastian Huber <sebastian.huber@…>

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