rtems;:单调周期调度函数举例
20.3.6 : 例子
%A
%A 下列举例说明使用单调周期创建周期性任务的方法。
%A 20.3.7 : 简单的周期任务
%A
%A 下面的代码创建了一个每隔100个时钟滴哒执行一次的任务。
%A
%A rtems_task Periodic_task(rtems_task_argument arg)
%A
%A {
%A
%A rtems_name name;
%A
%A rtems_id period;
%A
%A rtems_status_code status;
%A
%A
%A
%A name = rtems_build_name( ‘P‘, ‘E‘, ‘R‘, ‘D‘ );
%A
%A
%A
%A status = rtems_rate_monotonic_create( name, &period );
%A
%A if ( status != RTEMS_STATUS_SUCCESSFUL ) {
%A
%A printf( "rtems_monotonic_create failed with status of %d.\n", rc );
%A
%A exit( 1 );
%A
%A }
%A
%A
%A
%A
%A
%A while ( 1 ) {
%A
%A if ( rtems_rate_monotonic_period( period, 100 ) == RTEMS_TIMEOUT )
%A
%A break;
%A
%A
%A
%A /* Perform some periodic actions */
%A
%A }
%A
%A
%A
%A /* missed period so delete period and SELF */
%A
%A
%A
%A status = rtems_rate_monotonic_delete( period );
%A
%A if ( status != RTEMS_STATUS_SUCCESSFUL ) {
%A
%A printf( "rtems_rate_monotonic_delete failed with status of %d.\n", status );
%A
%A exit( 1 );
%A
%A }
%A
%A
%A
%A status = rtems_task_delete( SELF ); /* should not return */
%A
%A printf( "rtems_task_delete returned with status of %d.\n", status );
%A
%A exit( 1 );
%A
%A }
%A
%A 上述的任务在任务初始化时创建了一个单调周期 , 在进入循环时 , rtems_rate_monotonic_period 函数创建了一个 100 滴哒的周期然后返回。rtems_rate_monotonic_period 函数的后来启用将会为 100 的剩余者造成任务阻断勾号时期。 如果,因为什么特殊原因,循环体执行时间超过 100个滴哒,rtems_rate_monotonic_period 函数将会返回 RTEMS_TIMEOUT。如果任务超过了它的截止期限, 它将会删除单调周期和它本身。
%A 20.3.8 : 具有多个周期的任务
%A
%A 下面的代码中,任务Periodic_task中有两个单调周期,分别是40和100滴哒。
%A
%A rtems_task Periodic_task(rtems_task_argument arg)
%A
%A {
%A
%A rtems_name name_1, name_2;
%A
%A rtems_id period_1, period_2;
%A
%A rtems_status_code status;
%A
%A
%A
%A name_1 = rtems_build_name( ‘P‘, ‘E‘, ‘R‘, ‘1‘ );
%A
%A name_2 = rtems_build_name( ‘P‘, ‘E‘, ‘R‘, ‘2‘ );
%A
%A
%A
%A (void ) rtems_rate_monotonic_create( name_1, &period_1 );
%A
%A (void ) rtems_rate_monotonic_create( name_2, &period_2 );
%A
%A
%A
%A while ( 1 ) {
%A
%A if ( rtems_rate_monotonic_period( period_1, 100 ) == TIMEOUT )
%A
%A break;
%A
%A
%A
%A if ( rtems_rate_monotonic_period( period_2, 40 ) == TIMEOUT )
%A
%A break;
%A
%A
%A
%A /*
%A
%A * Perform first set of actions between clock
%A
%A * ticks 0 and 39 of every 100 ticks.
%A
%A */
%A
%A
%A
%A if ( rtems_rate_monotonic_period( period_2, 30 ) == TIMEOUT )
%A
%A break;
%A
%A
%A
%A /*
%A
%A * Perform second set of actions between clock 40 and 69
%A
%A * of every 100 ticks. THEN ...
%A
%A *
%A
%A * Check to make sure we didn‘t miss the period_2 period.
%A
%A */
%A
%A
%A
%A if ( rtems_rate_monotonic_period( period_2, STATUS ) == TIMEOUT )
%A
%A break;
%A
%A
%A
%A (void) rtems_rate_monotonic_cancel( period_2 );
%A
%A }
%A
%A
%A
%A /* missed period so delete period and SELF */
%A
%A
%A
%A (void ) rtems_rate_monotonic_delete( period_1 );
%A
%A (void ) rtems_rate_monotonic_delete( period_2 );
%A
%A (void ) task_delete( SELF );
%A
%A }
%A
%A 循环第一次执行 , rtems_rate_monotonic_period 函数将 period_1 设置为 100 个滴哒然后返回。次后循环中 rtems_rate_monotonic_period( period_1, 100 ) 将会被阻塞 100 个滴哒。period_2用来控制每个100滴哒周期中的两种动作。rtems_rate_monotonic_cancel( period_2) 函数保证了period_2 任务在 period_1 时期上被阻塞的时候,周期period_2不会期满。如果不运行取消操作, 除了进入循环的第一次,以后每一次调用 rtems_rate_monotonic_period(period_2,40)都会返回RTEMS_TIMEOUT。
%A
%A 如果,因为任何原因,任务超出了任何一个截止期,rtems_rate_monotonic_period 函数将会返回RTEMS_TIMEOUT 函数状态。 如果上述任务超过了他自己的截止期限, 它将会删除单调周期以及他自己。
%A
%A
%A%A
%A
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。