Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2011.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  *  Copyright (c) 2009 embedded brains GmbH & Co. KG
0008  *
0009  * Redistribution and use in source and binary forms, with or without
0010  * modification, are permitted provided that the following conditions
0011  * are met:
0012  * 1. Redistributions of source code must retain the above copyright
0013  *    notice, this list of conditions and the following disclaimer.
0014  * 2. Redistributions in binary form must reproduce the above copyright
0015  *    notice, this list of conditions and the following disclaimer in the
0016  *    documentation and/or other materials provided with the distribution.
0017  *
0018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0019  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0020  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0021  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0022  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0023  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0024  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0025  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0026  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0027  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0028  * POSSIBILITY OF SUCH DAMAGE.
0029  */
0030 
0031 #ifdef HAVE_CONFIG_H
0032 #include "config.h"
0033 #endif
0034 
0035 #include "system.h"
0036 
0037 #include <rtems/rtems/timerimpl.h>
0038 
0039 rtems_timer_service_routine Should_not_fire_TSR(
0040   rtems_id  ignored_id,
0041   void     *ignored_address
0042 );
0043 
0044 volatile int TSR_fired;
0045 
0046 rtems_timer_service_routine Should_not_fire_TSR(
0047   rtems_id  ignored_id,
0048   void     *ignored_address
0049 )
0050 {
0051   TSR_fired = 1;
0052 }
0053 
0054 static rtems_timer_service_routine Do_nothing(
0055   rtems_id  ignored_id,
0056   void     *ignored_address
0057 )
0058 {
0059   /* Do nothing */
0060 }
0061 
0062 rtems_task Task_1(
0063   rtems_task_argument argument
0064 )
0065 {
0066   rtems_id                 tmid;
0067   rtems_id                 tmid2;
0068   rtems_time_of_day        time;
0069   rtems_status_code        status;
0070   rtems_timer_information  info;
0071 
0072 /* Get id */
0073 
0074   puts( "TA1 - rtems_timer_ident - identing timer 1" );
0075   status = rtems_timer_ident( Timer_name[ 1 ], &tmid );
0076   directive_failed( status, "rtems_timer_ident" );
0077   printf( "TA1 - timer 1 has id (0x%" PRIxrtems_id ")\n", tmid );
0078 
0079   puts( "TA1 - rtems_timer_ident - identing timer 2" );
0080   status = rtems_timer_ident( Timer_name[ 2 ], &tmid2 );
0081   directive_failed( status, "rtems_timer_ident" );
0082   printf( "TA1 - timer 2 has id (0x%" PRIxrtems_id ")\n", tmid2 );
0083 
0084 /* make sure insertion does not unintentionally fire a timer per PR147 */
0085 
0086   TSR_fired = 0;
0087 
0088   puts( "TA1 - rtems_timer_server_fire_after - 1 second" );
0089   status = rtems_timer_server_fire_after(
0090     tmid, rtems_clock_get_ticks_per_second(), Should_not_fire_TSR, NULL );
0091   directive_failed( status, "rtems_timer_server_fire_after" );
0092 
0093   puts( "TA1 - rtems_task_wake_after - 1/2 second" );
0094   status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() / 2 );
0095   directive_failed( status, "rtems_timer_server_fire_after" );
0096 
0097   directive_failed( status, "rtems_timer_server_fire_after" );
0098   puts( "TA1 - rtems_timer_server_fire_after - timer 2 in 1/2 second" );
0099   status = rtems_timer_server_fire_after(
0100     tmid2, rtems_clock_get_ticks_per_second() / 2, Should_not_fire_TSR, NULL );
0101   directive_failed( status, "rtems_timer_server_fire_after" );
0102 
0103   if ( TSR_fired ) {
0104     puts( "TA1 - TSR fired and should not have!" );
0105     rtems_test_exit(1);
0106   }
0107 
0108   puts( "TA1 - rtems_timer_cancel - timer 1" );
0109   status = rtems_timer_cancel( tmid );
0110   directive_failed( status, "rtems_timer_cancel" );
0111 
0112   puts( "TA1 - rtems_timer_cancel - timer 2" );
0113   status = rtems_timer_cancel( tmid2 );
0114   directive_failed( status, "rtems_timer_cancel" );
0115 
0116 
0117 /* now check that rescheduling an active timer works OK. */
0118   puts( "TA1 - rtems_timer_server_fire_after - timer 1 in 30 seconds" );
0119   status = rtems_timer_server_fire_after(
0120     tmid, 30 * rtems_clock_get_ticks_per_second(), Delayed_resume, NULL );
0121   directive_failed( status, "rtems_timer_server_fire_after" );
0122 
0123   puts( "TA1 - rtems_timer_server_fire_after - timer 2 in 60 seconds" );
0124   status = rtems_timer_server_fire_after(
0125     tmid2, 60 * rtems_clock_get_ticks_per_second(), Delayed_resume, NULL );
0126   directive_failed( status, "rtems_timer_server_fire_after" );
0127 
0128   status = rtems_timer_get_information( tmid, &info );
0129   printf(
0130     "Timer 1 scheduled for %" PRIdWatchdog_Interval " ticks since boot\n",
0131     info.start_time + info.initial
0132   );
0133 
0134   puts( "TA1 - rtems_task_wake_after - 1 second" );
0135   status = rtems_task_wake_after( 1 * rtems_clock_get_ticks_per_second() );
0136   directive_failed( status, "rtems_timer_wake_after" );
0137 
0138   puts( "TA1 - rtems_timer_server_fire_after - timer 2 in 60 seconds" );
0139   status = rtems_timer_server_fire_after(
0140     tmid2, 60 * rtems_clock_get_ticks_per_second(), Delayed_resume, NULL );
0141   directive_failed( status, "rtems_timer_server_fire_after" );
0142 
0143   status = rtems_timer_get_information( tmid, &info );
0144   directive_failed( status, "rtems_timer_get_information" );
0145   printf(
0146     "Timer 1 scheduled for %" PRIdWatchdog_Interval " ticks since boot\n",
0147     info.start_time + info.initial
0148   );
0149 
0150   puts( "TA1 - rtems_task_wake_after - 1 second" );
0151   status = rtems_task_wake_after( 1 * rtems_clock_get_ticks_per_second() );
0152   directive_failed( status, "rtems_timer_wake_after" );
0153 
0154   puts( "TA1 - rtems_timer_server_fire_after - timer 2 in 60 seconds" );
0155   status = rtems_timer_server_fire_after(
0156     tmid2, 60 * rtems_clock_get_ticks_per_second(), Delayed_resume, NULL );
0157   directive_failed( status, "rtems_timer_server_fire_after" );
0158 
0159   status = rtems_timer_get_information( tmid, &info );
0160   directive_failed( status, "rtems_timer_get_information" );
0161   printf(
0162     "Timer 1 scheduled for %" PRIdWatchdog_Interval " ticks since boot\n",
0163      info.start_time + info.initial
0164   );
0165 
0166   puts( "TA1 - rtems_timer_cancel - timer 1" );
0167   status = rtems_timer_cancel( tmid );
0168   directive_failed( status, "rtems_timer_cancel" );
0169 
0170   puts( "TA1 - rtems_timer_cancel - timer 2" );
0171   status = rtems_timer_cancel( tmid2 );
0172   directive_failed( status, "rtems_timer_cancel" );
0173 
0174 /* after which is allowed to fire */
0175 
0176   Print_time();
0177 
0178   puts( "TA1 - rtems_timer_server_fire_after - timer 1 in 3 seconds" );
0179   status = rtems_timer_server_fire_after(
0180     tmid,
0181     3 * rtems_clock_get_ticks_per_second(),
0182     Delayed_resume,
0183     NULL
0184   );
0185   directive_failed( status, "rtems_timer_server_fire_after" );
0186 
0187   puts( "TA1 - rtems_task_suspend( RTEMS_SELF )" );
0188   status = rtems_task_suspend( RTEMS_SELF );
0189   directive_failed( status, "rtems_task_suspend" );
0190 
0191   Print_time();
0192 
0193 /* after which is reset and allowed to fire */
0194 
0195   puts( "TA1 - rtems_timer_server_fire_after - timer 1 in 3 seconds" );
0196   status = rtems_timer_server_fire_after(
0197     tmid,
0198     3 * rtems_clock_get_ticks_per_second(),
0199     Delayed_resume,
0200     NULL
0201   );
0202   directive_failed( status, "rtems_timer_server_fire_after" );
0203 
0204   puts( "TA1 - rtems_task_wake_after - 1 second" );
0205   status = rtems_task_wake_after( 1 * rtems_clock_get_ticks_per_second() );
0206   directive_failed( status, "rtems_task_wake_after" );
0207 
0208   Print_time();
0209 
0210   puts( "TA1 - rtems_timer_reset - timer 1" );
0211   status = rtems_timer_reset( tmid );
0212   directive_failed( status, "rtems_timer_reset" );
0213 
0214   puts( "TA1 - rtems_task_suspend( RTEMS_SELF )" );
0215   status = rtems_task_suspend( RTEMS_SELF );
0216   directive_failed( status, "rtems_task_suspend" );
0217 
0218   Print_time();
0219 
0220   /*
0221    *  Reset the time since we do not know how long the user waited
0222    *  before pressing <cr> at the pause.  This insures that the
0223    *  actual output matches the screen.
0224    */
0225 
0226   build_time( &time, 12, 31, 1988, 9, 0, 7, 0 );
0227 
0228   status = rtems_clock_set( &time );
0229   directive_failed( status, "rtems_clock_set" );
0230 
0231 /* after which is canceled */
0232 
0233   puts( "TA1 - rtems_timer_server_fire_after - timer 1 in 3 seconds" );
0234   status = rtems_timer_server_fire_after(
0235     tmid,
0236     3 * rtems_clock_get_ticks_per_second(),
0237     Delayed_resume,
0238     NULL
0239   );
0240   directive_failed( status, "rtems_timer_server_fire_after" );
0241 
0242   puts( "TA1 - rtems_timer_cancel - timer 1" );
0243   status = rtems_timer_cancel( tmid );
0244   directive_failed( status, "rtems_timer_cancel" );
0245 
0246 /* when which is allowed to fire */
0247 
0248   Print_time();
0249 
0250   status = rtems_clock_get_tod( &time );
0251   directive_failed( status, "rtems_clock_get_tod" );
0252 
0253   time.second += 3;
0254 
0255   puts( "TA1 - rtems_timer_server_fire_when - timer 1 in 3 seconds" );
0256   status = rtems_timer_server_fire_when( tmid, &time, Delayed_resume, NULL );
0257   directive_failed( status, "rtems_timer_server_fire_when" );
0258 
0259   puts( "TA1 - rtems_task_suspend( RTEMS_SELF )" );
0260   status = rtems_task_suspend( RTEMS_SELF );
0261   directive_failed( status, "rtems_task_suspend" );
0262 
0263   Print_time();
0264 
0265 /* when which is canceled */
0266 
0267   status = rtems_clock_get_tod( &time );
0268   directive_failed( status, "rtems_clock_get_tod" );
0269 
0270   time.second += 3;
0271 
0272   puts( "TA1 - rtems_timer_server_fire_when - timer 1 in 3 seconds" );
0273   status = rtems_timer_server_fire_when( tmid, &time, Delayed_resume, NULL );
0274   directive_failed( status, "rtems_timer_server_fire_when" );
0275 
0276   puts( "TA1 - rtems_task_wake_after - 1 second" );
0277   status = rtems_task_wake_after( 1 * rtems_clock_get_ticks_per_second() );
0278   directive_failed( status, "rtems_task_wake_after" );
0279 
0280   Print_time();
0281 
0282   puts( "TA1 - rtems_timer_cancel - timer 1" );
0283   status = rtems_timer_cancel( tmid );
0284   directive_failed( status, "rtems_timer_cancel" );
0285 
0286 /* TOD timer insert with non empty TOD timer chain */
0287 
0288   status = rtems_clock_get_tod( &time );
0289   directive_failed( status, "rtems_clock_get_tod" );
0290 
0291   time.second += 3;
0292 
0293   puts( "TA1 - rtems_timer_server_fire_when - timer 1 in 3 seconds" );
0294   status = rtems_timer_server_fire_when( tmid, &time, Do_nothing, NULL );
0295   directive_failed( status, "rtems_timer_server_fire_when" );
0296 
0297   puts( "TA1 - rtems_timer_server_fire_when - timer 2 in 3 seconds" );
0298   status = rtems_timer_server_fire_when( tmid2, &time, Do_nothing, NULL );
0299   directive_failed( status, "rtems_timer_server_fire_when" );
0300 
0301   puts( "TA1 - rtems_task_wake_after - 1 second" );
0302   status = rtems_task_wake_after( 1 * rtems_clock_get_ticks_per_second() );
0303   directive_failed( status, "rtems_task_wake_after" );
0304 
0305   puts( "TA1 - rtems_timer_server_fire_when - timer 2 in 3 seconds" );
0306   status = rtems_timer_server_fire_when( tmid2, &time, Do_nothing, NULL );
0307   directive_failed( status, "rtems_timer_server_fire_when" );
0308 
0309   puts( "TA1 - rtems_timer_cancel - timer 1" );
0310   status = rtems_timer_cancel( tmid );
0311   directive_failed( status, "rtems_timer_cancel" );
0312 
0313   puts( "TA1 - rtems_timer_cancel - timer 2" );
0314   status = rtems_timer_cancel( tmid2 );
0315   directive_failed( status, "rtems_timer_cancel" );
0316 
0317 /* TOD chain processing with time wrap */
0318 
0319   time.second = 30;
0320 
0321   status = rtems_clock_set( &time );
0322   directive_failed( status, "rtems_clock_set" );
0323 
0324   time.second = 31;
0325 
0326   puts( "TA1 - rtems_timer_server_fire_when - timer 1 in 1 seconds" );
0327   status = rtems_timer_server_fire_when( tmid, &time, Do_nothing, NULL );
0328   directive_failed( status, "rtems_timer_server_fire_when" );
0329 
0330   time.second = 29;
0331 
0332   status = rtems_clock_set( &time );
0333   directive_failed( status, "rtems_clock_set" );
0334 
0335   puts( "TA1 - rtems_timer_server_fire_after - timer 2 in 1 tick" );
0336   status = rtems_timer_server_fire_after( tmid2, 1, Do_nothing, NULL );
0337   directive_failed( status, "rtems_timer_server_fire_after" );
0338 
0339   puts( "TA1 - rtems_task_wake_after - 1 tick" );
0340   status = rtems_task_wake_after( 1 );
0341   directive_failed( status, "rtems_task_wake_after" );
0342 
0343   puts( "TA1 - rtems_timer_cancel - timer 1" );
0344   status = rtems_timer_cancel( tmid );
0345   directive_failed( status, "rtems_timer_cancel" );
0346 
0347 /* delete */
0348   puts( "TA1 - rtems_task_wake_after - YIELD (only task at priority)" );
0349   status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
0350   directive_failed( status, "rtems_task_wake_after" );
0351 
0352   puts( "TA1 - timer_deleting - timer 1" );
0353   status = rtems_timer_delete( tmid );
0354   directive_failed( status, "rtems_timer_delete" );
0355 
0356   TEST_END();
0357   rtems_test_exit( 0 );
0358 }