File indexing completed on 2025-05-11 08:24:48
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include "system.h"
0017
0018 rtems_task Task_Periodic(
0019 rtems_task_argument argument
0020 )
0021 {
0022 rtems_id rmid;
0023 rtems_status_code status;
0024
0025 time_t approved_budget, exec_time, abs_time, current_budget;
0026
0027 int start, stop, now;
0028
0029 qres_sid_t server_id, tsid;
0030 qres_params_t params, tparams;
0031
0032 params.P = Period;
0033 params.Q = Execution+1;
0034
0035 printf( "Periodic task: Create server and Attach thread\n" );
0036 if ( qres_create_server( ¶ms, &server_id ) )
0037 printf( "ERROR: CREATE SERVER FAILED\n" );
0038 if ( qres_attach_thread( server_id, 0, Task_id ) )
0039 printf( "ERROR: ATTACH THREAD FAILED\n" );
0040
0041 printf( "Periodic task: ID and Get parameters\n" );
0042 if ( qres_get_sid( 0, Task_id, &tsid ) )
0043 printf( "ERROR: GET SERVER ID FAILED\n" );
0044 if ( tsid != server_id )
0045 printf( "ERROR: SERVER ID MISMATCH\n" );
0046 if ( qres_get_params( server_id, &tparams ) )
0047 printf( "ERROR: GET PARAMETERS FAILED\n" );
0048 if ( params.P != tparams.P ||
0049 params.Q != tparams.Q )
0050 printf( "ERROR: PARAMETERS MISMATCH\n" );
0051
0052 printf( "Periodic task: Detach thread and Destroy server\n" );
0053 if ( qres_detach_thread( server_id, 0, Task_id ) )
0054 printf( "ERROR: DETACH THREAD FAILED\n" );
0055 if ( qres_destroy_server( server_id ) )
0056 printf( "ERROR: DESTROY SERVER FAILED\n" );
0057 if ( qres_create_server( ¶ms, &server_id ) )
0058 printf( "ERROR: CREATE SERVER FAILED\n" );
0059
0060 printf( "Periodic task: Current budget and Execution time\n" );
0061 if ( qres_get_curr_budget( server_id, ¤t_budget ) )
0062 printf( "ERROR: GET REMAINING BUDGET FAILED\n" );
0063 if ( current_budget != params.Q )
0064 printf( "ERROR: REMAINING BUDGET MISMATCH\n" );
0065 if ( qres_get_exec_time( server_id, &exec_time, &abs_time ) )
0066 printf( "ERROR: GET EXECUTION TIME FAILED\n" );
0067
0068 printf( "Periodic task: Set parameters\n" );
0069 if ( qres_attach_thread( server_id, 0, Task_id ) )
0070 printf( "ERROR: ATTACH THREAD FAILED\n" );
0071 params.P = Period * 2;
0072 params.Q = Execution * 2 +1;
0073 if ( qres_set_params( server_id, ¶ms ) )
0074 printf( "ERROR: SET PARAMS FAILED\n" );
0075 if ( qres_get_params( server_id, &tparams ) )
0076 printf( "ERROR: GET PARAMS FAILED\n" );
0077 if ( params.P != tparams.P ||
0078 params.Q != tparams.Q )
0079 printf( "ERROR: PARAMS MISMATCH\n" );
0080 params.P = Period;
0081 params.Q = Execution+1;
0082 if ( qres_set_params( server_id, ¶ms ) )
0083 printf( "ERROR: SET PARAMS FAILED\n" );
0084 if ( qres_get_appr_budget( server_id, &approved_budget ) )
0085 printf( "ERROR: GET APPROVED BUDGET FAILED\n" );
0086
0087 printf( "Periodic task: Approved budget\n" );
0088 if ( approved_budget != params.Q )
0089 printf( "ERROR: APPROVED BUDGET MISMATCH\n" );
0090
0091 status = rtems_rate_monotonic_create( argument, &rmid );
0092 directive_failed( status, "rtems_rate_monotonic_create" );
0093
0094
0095 printf( "Periodic task: Starting periodic behavior\n" );
0096 status = rtems_task_wake_after( 1 + Phase );
0097 directive_failed( status, "rtems_task_wake_after" );
0098
0099 while ( FOREVER ) {
0100 if ( rtems_rate_monotonic_period(rmid, Period) == RTEMS_TIMEOUT )
0101 printf( "P%" PRIdPTR " - Deadline miss\n", argument );
0102
0103 start = rtems_clock_get_ticks_since_boot();
0104 printf( "P%" PRIdPTR "-S ticks:%d\n", argument, start );
0105 if ( start > 4*Period+Phase ) break;
0106
0107 while(FOREVER) {
0108 now = rtems_clock_get_ticks_since_boot();
0109 if ( now >= start + Execution ) break;
0110
0111 if ( qres_get_exec_time( server_id, &exec_time, &abs_time ) )
0112 printf( "ERROR: GET EXECUTION TIME FAILED\n" );
0113 if ( qres_get_curr_budget( server_id, ¤t_budget) )
0114 printf( "ERROR: GET CURRENT BUDGET FAILED\n" );
0115 if ( (current_budget + exec_time) > (Execution + 1) ) {
0116 printf( "ERROR: CURRENT BUDGET AND EXECUTION TIME MISMATCH\n" );
0117 rtems_test_exit( 0 );
0118 }
0119 }
0120 stop = rtems_clock_get_ticks_since_boot();
0121 printf( "P%" PRIdPTR "-F ticks:%d\n", argument, stop );
0122 }
0123
0124
0125 status = rtems_rate_monotonic_delete( rmid );
0126 if ( status != RTEMS_SUCCESSFUL ) {
0127 printf("rtems_rate_monotonic_delete failed with status of %d.\n", status);
0128 rtems_test_exit( 0 );
0129 }
0130 if ( qres_cleanup() )
0131 printf( "ERROR: QRES CLEANUP\n" );
0132
0133 fflush(stdout);
0134 TEST_END();
0135 rtems_test_exit( 0 );
0136 }