RTEMS Logo

RTEMS 4.7.2 On-Line Library


Rate Monotonic Manager Simple Periodic Task

PREV UP NEXT Bookshelf RTEMS C User's Guide

19.3.7: Simple Periodic Task

This example consists of a single periodic task which, after initialization, executes every 100 clock ticks.

rtems_task Periodic_task(rtems_task_argument arg)
{
  rtems_name        name;
  rtems_id          period;
  rtems_status_code status;

  name = rtems_build_name( 'P', 'E', 'R', 'D' );

  status = rtems_rate_monotonic_create( name, &period );
  if ( status != RTEMS_STATUS_SUCCESSFUL ) {
    printf( "rtems_monotonic_create failed with status of %d.\n", rc );
    exit( 1 );
  }


  while ( 1 ) {
    if ( rtems_rate_monotonic_period( period, 100 ) == RTEMS_TIMEOUT )
      break;

    /* Perform some periodic actions */
  }

  /* missed period so delete period and SELF */

  status = rtems_rate_monotonic_delete( period );
  if ( status != RTEMS_STATUS_SUCCESSFUL ) {
    printf( "rtems_rate_monotonic_delete failed with status of %d.\n", status );
    exit( 1 );
  }

  status = rtems_task_delete( SELF );    /* should not return */
  printf( "rtems_task_delete returned with status of %d.\n", status );
  exit( 1 );
}

The above task creates a rate monotonic period as part of its initialization. The first time the loop is executed, the rtems_rate_monotonic_period directive will initiate the period for 100 ticks and return immediately. Subsequent invocations of the rtems_rate_monotonic_period directive will result in the task blocking for the remainder of the 100 tick period. If, for any reason, the body of the loop takes more than 100 ticks to execute, the rtems_rate_monotonic_period directive will return the RTEMS_TIMEOUT status. If the above task misses its deadline, it will delete the rate monotonic period and itself.


PREV UP NEXT Bookshelf RTEMS C User's Guide

Copyright © 1988-2004 OAR Corporation