Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:33

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2012.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0026  * POSSIBILITY OF SUCH DAMAGE.
0027  */
0028 
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032 
0033 #include <bsp.h>
0034 
0035 #include <stdlib.h>
0036 #include <stdio.h>
0037 
0038 #include <sys/types.h>
0039 #include <sys/stat.h>
0040 #include <fcntl.h>
0041 #include <sys/ioctl.h>
0042 #include <unistd.h>
0043 #include <rtems/mw_uid.h>
0044 #include "../termios04/termios_testdriver_intr.h"
0045 #include "tmacros.h"
0046 
0047 const char rtems_test_name[] = "MOUSE 1";
0048 
0049 #define UID_MESSAGE_COUNT 10
0050 
0051 /* forward declarations to avoid warnings */
0052 rtems_task Init(rtems_task_argument argument);
0053 bool enqueue_next_action(
0054   const unsigned char *actions,
0055   size_t               max,
0056   size_t               to_enqueue
0057 );
0058 void open_it(void);
0059 void register_it(void);
0060 void printf_uid_message(struct MW_UID_MESSAGE *uid);
0061 void receive_uid_message(void);
0062 void close_it(void);
0063 
0064 extern const char *Mouse_Type_Long;
0065 extern const char *Mouse_Type_Short;
0066 extern const unsigned char Mouse_Actions[];
0067 extern const size_t Mouse_Actions_Size;
0068 extern const size_t Mouse_Actions_Per_Iteration;
0069 
0070 int Mouse_Index = 0;
0071 
0072 bool enqueue_next_action(
0073   const unsigned char *actions,
0074   size_t               max,
0075   size_t               to_enqueue
0076 )
0077 {
0078   if ( (Mouse_Index + to_enqueue) > max )
0079     return false;
0080 
0081   termios_test_driver_set_rx_enqueue_now( true );
0082 
0083   termios_test_driver_set_rx( &actions[Mouse_Index], to_enqueue );
0084   Mouse_Index += to_enqueue;
0085 
0086   return true;
0087 }
0088 
0089 int Test_fd;
0090 
0091 void open_it(void)
0092 {
0093   /* open the file */
0094   puts( "open(/dev/mouse) - OK " );
0095   Test_fd = open( "/dev/mouse", O_RDONLY );
0096   rtems_test_assert( Test_fd != -1 );
0097 }
0098 
0099 void register_it(void)
0100 {
0101   int                rc;
0102   char               name[5] = "mous";
0103 
0104   printf( "uid_open_queue() - mouse queue\n" );
0105   rc = uid_open_queue( name, 0, UID_MESSAGE_COUNT );
0106   rtems_test_assert( rc == 0 );
0107 
0108   printf( "uid_register_device() - OK\n");
0109   rc = uid_register_device( Test_fd, name );
0110   rtems_test_assert( rc == 0 );
0111 }
0112 
0113 void printf_uid_message(
0114   struct MW_UID_MESSAGE *uid
0115 )
0116 {
0117   uid_print_message_with_plugin(
0118     &rtems_test_printer,
0119     uid
0120   );
0121 }
0122 
0123 void receive_uid_message(void)
0124 {
0125   int                    rc;
0126   struct MW_UID_MESSAGE  uid;
0127 
0128   rc = uid_read_message( &uid, 0 );
0129   if ( rc != sizeof(struct MW_UID_MESSAGE) )
0130     return;
0131   printf_uid_message( &uid );
0132 }
0133 
0134 void close_it(void)
0135 {
0136   int rc;
0137 
0138   printf( "uid_unregister_device() - OK\n" );
0139   rc = uid_unregister_device( Test_fd );
0140   rtems_test_assert( rc == 0 );
0141 
0142   puts( "close(/dev/mouse) - OK " );
0143   rc = close( Test_fd );
0144   rtems_test_assert( rc == 0 );
0145 }
0146 
0147 rtems_task Init(
0148   rtems_task_argument ignored
0149 )
0150 {
0151   bool more_data;
0152 
0153   TEST_BEGIN();
0154 
0155   open_it();
0156   register_it();
0157   do {
0158     more_data = enqueue_next_action(
0159       Mouse_Actions,
0160       Mouse_Actions_Size,
0161       Mouse_Actions_Per_Iteration
0162     );
0163     receive_uid_message();
0164   } while (more_data);
0165   close_it();
0166   TEST_END();
0167   rtems_test_exit( 0 );
0168 }
0169 
0170 /* configuration information */
0171 
0172 #include <rtems/serial_mouse.h>
0173 
0174 /* NOTICE: the clock driver is explicitly disabled */
0175 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0176 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0177 #define CONFIGURE_APPLICATION_EXTRA_DRIVERS \
0178     TERMIOS_TEST_DRIVER_TABLE_ENTRY, \
0179     SERIAL_MOUSE_DRIVER_TABLE_ENTRY
0180 
0181 /* we need to be able to open the test device and mouse */
0182 #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 5
0183 #define CONFIGURE_MAXIMUM_TASKS  1
0184 #define CONFIGURE_MAXIMUM_TIMERS 2
0185 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 1
0186 
0187 #define CONFIGURE_MESSAGE_BUFFER_MEMORY \
0188   CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE( \
0189     UID_MESSAGE_COUNT, \
0190     sizeof(struct MW_UID_MESSAGE) \
0191   )
0192 
0193 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0194 
0195 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0196 
0197 #define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
0198 
0199 #define CONFIGURE_INIT
0200 
0201 #include <rtems/confdefs.h>
0202 
0203 /* end of file */