Back to home page

LXR

 
 

    


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

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 
0013 #ifdef HAVE_CONFIG_H
0014 #include "config.h"
0015 #endif
0016 
0017 #include <tmacros.h>
0018 
0019 #include <rtems/score/watchdogimpl.h>
0020 
0021 const char rtems_test_name[] = "SP 67";
0022 
0023 /* forward declarations to avoid warnings */
0024 rtems_task Init(rtems_task_argument argument);
0025 rtems_timer_service_routine TIMER_service_routine(
0026   rtems_id  ignored_id,
0027   void     *user_data
0028 );
0029 
0030 volatile bool _timer_passage_1 = FALSE;
0031 volatile bool _timer_passage_2 = FALSE;
0032 
0033 /*timer Routine*/
0034 rtems_timer_service_routine TIMER_service_routine(
0035   rtems_id  ignored_id,
0036   void     *user_data
0037 )
0038 {
0039   bool *passed = (bool *)user_data;
0040   *passed = TRUE;
0041 }
0042 
0043 rtems_task Init(
0044   rtems_task_argument argument
0045 )
0046 {
0047   rtems_status_code status;
0048   rtems_id          timer1;
0049   rtems_id          timer2;
0050 
0051   TEST_BEGIN();
0052 
0053   /* build timer name*/
0054 
0055   /* create Timer */
0056   puts( "Init - create timer 1" );
0057   status = rtems_timer_create( rtems_build_name('T', 'M', '1', ' '), &timer1 );
0058   directive_failed( status, "rtems_timer_create #1" );
0059 
0060   puts( "Init - create timer 2" );
0061   status = rtems_timer_create( rtems_build_name('T', 'M', '2', ' '), &timer2 );
0062   directive_failed( status, "rtems_timer_create #1" );
0063 
0064   /* Manipulate the time */
0065   _Watchdog_Ticks_since_boot = (Watchdog_Interval) -15;
0066 
0067   /* initiate timer server */
0068   puts( "Init - Initiate the timer server" );
0069   status = rtems_timer_initiate_server(
0070     RTEMS_MINIMUM_PRIORITY,
0071     RTEMS_MINIMUM_STACK_SIZE,
0072     RTEMS_DEFAULT_ATTRIBUTES
0073   );
0074   directive_failed( status, "rtems_timer_initiate_server" );
0075 
0076   /* Give the timer server some time to initialize */
0077   status = rtems_task_wake_after( 10 );
0078   directive_failed( status, "task wake_after" );
0079 
0080   status = rtems_timer_server_fire_after(
0081     timer1,
0082     10,
0083     TIMER_service_routine,
0084     (void*) &_timer_passage_1
0085   );
0086   directive_failed( status, "rtems_timer_server_fire_after" );
0087 
0088   status = rtems_timer_server_fire_after(
0089     timer2,
0090     20,
0091     TIMER_service_routine,
0092     (void*) &_timer_passage_2
0093   );
0094   directive_failed( status, "rtems_timer_server_fire_after" );
0095 
0096   status = rtems_task_wake_after( 15 );
0097   directive_failed( status, "task wake_after" );
0098 
0099   if (!_timer_passage_1) {
0100     puts( "Timer 1 FAILED to fire after wrapping time");
0101     rtems_test_exit(0);
0102   }
0103   puts( "Server Timer 1 fired after wrapping ticks since boot-- OK");
0104 
0105   if (_timer_passage_2) {
0106     puts( "Timer 2 fired and should not have after wrapping time");
0107     rtems_test_exit(0);
0108   }
0109 
0110   TEST_END();
0111   rtems_test_exit(0);
0112 }
0113 
0114 /* configuration stuff */
0115 
0116 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0117 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0118 
0119 #define CONFIGURE_MAXIMUM_TASKS              2
0120 #define CONFIGURE_MAXIMUM_TIMERS             2
0121 
0122 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0123 
0124 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0125 
0126 #define CONFIGURE_INIT
0127 #include <rtems/confdefs.h>