Back to home page

LXR

 
 

    


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

0001 /*
0002  *  Based upon test code posted on the RTEMS User's Mailing List
0003  *  by Sergio Faustino <sergio.faustino@edisoft.pt>:
0004  *
0005  *    http://www.rtems.org/pipermail/rtems-users/2009-June/005540.html
0006  *
0007  *  The license and distribution terms for this file may be
0008  *  found in the file LICENSE in this distribution or at
0009  *  http://www.rtems.org/license/LICENSE.
0010  */
0011 
0012 #if defined(USE_TIMER_SERVER)
0013    #define TEST_NUMBER      "53"
0014    #define TSR_MODE         "Server"
0015    #define FIRE_WHEN        rtems_timer_server_fire_when
0016    #define FIRE_WHEN_STRING "rtems_timer_server_fire_when"
0017 #else
0018    #define TEST_NUMBER      "52"
0019    #define TSR_MODE         "Interrupt"
0020    #define FIRE_WHEN        rtems_timer_fire_when
0021    #define FIRE_WHEN_STRING "rtems_timer_fire_when"
0022 #endif
0023 
0024 #ifdef HAVE_CONFIG_H
0025 #include "config.h"
0026 #endif
0027 
0028 #include <tmacros.h>
0029 #include <string.h>
0030 
0031 const char rtems_test_name[] = "SP " TEST_NUMBER;
0032 
0033 #define INITIAL_YEAR 2009
0034 
0035 static bool _timer_passage;
0036 
0037 static rtems_time_of_day time_to_fire;
0038 
0039 /*timer Routine*/
0040 static rtems_timer_service_routine TIMER_service_routine(
0041   rtems_id  ignored_id,
0042   void     *user_data
0043 )
0044 {
0045   rtems_status_code status;
0046   rtems_time_of_day now;
0047 
0048   _timer_passage = true;
0049 
0050   memset( &now, 0, sizeof( now ) );
0051 
0052   status = rtems_clock_get_tod( &now );
0053   rtems_test_assert( status == RTEMS_SUCCESSFUL );
0054   rtems_test_assert( memcmp( &now, &time_to_fire, sizeof( now ) ) == 0 );
0055 }
0056 
0057 static rtems_task Init(
0058   rtems_task_argument argument
0059 )
0060 {
0061   rtems_status_code status;
0062   rtems_id          timer_id;
0063   rtems_name        timer_name;
0064 
0065   rtems_time_of_day global_time;
0066 
0067   TEST_BEGIN();
0068 
0069   /* build timer name*/
0070   timer_name = rtems_build_name('T', 'M', '1', ' ');
0071 
0072   /* create Timer */
0073   status = rtems_timer_create(timer_name, &timer_id);
0074   directive_failed( status, "rtems_timer_create" );
0075 
0076   #if defined(USE_TIMER_SERVER)
0077     /* initiate timer server */
0078     status = rtems_timer_initiate_server(
0079       RTEMS_MINIMUM_PRIORITY,
0080       RTEMS_MINIMUM_STACK_SIZE,
0081       RTEMS_DEFAULT_ATTRIBUTES
0082     );
0083     directive_failed( status, "rtems_timer_initiate_server" );
0084   #endif
0085 
0086   /* Set system clock  */
0087   build_time(&global_time, 6, 8, INITIAL_YEAR, 16, 5, 13, 0);
0088   status = rtems_clock_set(&global_time);
0089   directive_failed( status, "rtems_clock_set" );
0090 
0091   /* Set Timer to Fire */
0092   /* build fire times */
0093   time_to_fire = global_time;
0094 
0095   /* only diferent second */
0096   time_to_fire.year = INITIAL_YEAR + 5;
0097 
0098   status = FIRE_WHEN(
0099     timer_id,
0100     &time_to_fire,
0101     TIMER_service_routine,
0102     (void*) NULL
0103   );
0104   directive_failed( status, FIRE_WHEN_STRING );
0105 
0106   /* Set system clock FORWARD */
0107   global_time.year = time_to_fire.year;
0108   status = rtems_clock_set(&global_time);
0109 
0110   if (!_timer_passage) {
0111     puts( TSR_MODE " Timer FAILED to fire after setting time forward");
0112     rtems_test_exit(0);
0113   }
0114 
0115   puts( TSR_MODE " Timer fired after setting time forward -- OK");
0116 
0117   TEST_END();
0118   rtems_test_exit(0);
0119 }
0120 
0121 /* configuration stuff */
0122 
0123 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0124 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0125 
0126 #define CONFIGURE_MICROSECONDS_PER_TICK 50000
0127 
0128 #define CONFIGURE_MAXIMUM_TASKS              2
0129 #define CONFIGURE_MAXIMUM_TIMERS             1
0130 
0131 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0132 
0133 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0134 
0135 #define CONFIGURE_INIT_TASK_PRIORITY (RTEMS_MINIMUM_PRIORITY + 1)
0136 #define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES
0137 
0138 #define CONFIGURE_INIT
0139 #include <rtems/confdefs.h>