RTEMS Logo

RTEMS 4.9.2 On-Line Library


Rate Monotonic Manager Task with Multiple Periods

PREV UP NEXT Bookshelf RTEMS C User's Guide

19.3.8: Task with Multiple Periods

This example consists of a single periodic task which, after initialization, performs two sets of actions every 100 clock ticks. The first set of actions is performed in the first forty clock ticks of every 100 clock ticks, while the second set of actions is performed between the fortieth and seventieth clock ticks. The last thirty clock ticks are not used by this task.

rtems_task Periodic_task(rtems_task_argument arg)
{
  rtems_name        name_1, name_2;
  rtems_id          period_1, period_2;
  rtems_status_code status;

  name_1 = rtems_build_name( 'P', 'E', 'R', '1' );
  name_2 = rtems_build_name( 'P', 'E', 'R', '2' );

  (void ) rtems_rate_monotonic_create( name_1, &period_1 );
  (void ) rtems_rate_monotonic_create( name_2, &period_2 );

  while ( 1 ) {
    if ( rtems_rate_monotonic_period( period_1, 100 ) == TIMEOUT )
      break;

    if ( rtems_rate_monotonic_period( period_2, 40 ) == TIMEOUT )
      break;

    /*
     *  Perform first set of actions between clock
     *  ticks 0 and 39 of every 100 ticks.
     */

    if ( rtems_rate_monotonic_period( period_2, 30 ) == TIMEOUT )
      break;

    /*
     *  Perform second set of actions between clock 40 and 69
     *  of every 100 ticks.  THEN ...
     *
     *  Check to make sure we didn't miss the period_2 period.
     */

    if ( rtems_rate_monotonic_period( period_2, STATUS ) == TIMEOUT )
      break;

    (void) rtems_rate_monotonic_cancel( period_2 );
  }

  /* missed period so delete period and SELF */

  (void ) rtems_rate_monotonic_delete( period_1 );
  (void ) rtems_rate_monotonic_delete( period_2 );
  (void ) task_delete( SELF );
}

The above task creates two rate monotonic periods as part of its initialization. The first time the loop is executed, the rtems_rate_monotonic_period directive will initiate the period_1 period for 100 ticks and return immediately. Subsequent invocations of the rtems_rate_monotonic_period directive for period_1 will result in the task blocking for the remainder of the 100 tick period. The period_2 period is used to control the execution time of the two sets of actions within each 100 tick period established by period_1. The rtems_rate_monotonic_cancel( period_2 ) call is performed to ensure that the period_2 period does not expire while the task is blocked on the period_1 period. If this cancel operation were not performed, every time the rtems_rate_monotonic_period( period_2, 40 ) call is executed, except for the initial one, a directive status of RTEMS_TIMEOUT is returned. It is important to note that every time this call is made, the period_2 period will be initiated immediately and the task will not block.

If, for any reason, the task misses any deadline, the rtems_rate_monotonic_period directive will return the RTEMS_TIMEOUT directive status. If the above task misses its deadline, it will delete the rate monotonic periods and itself.


PREV UP NEXT Bookshelf RTEMS C User's Guide

Copyright © 1988-2008 OAR Corporation