Back to home page

LXR

 
 

    


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

0001 /*  Tasks_Periodic
0002  *
0003  *  This routine serves as a test task for the CBS scheduler
0004  *  implementation.
0005  *
0006  *  Input parameters:
0007  *    argument - task argument
0008  *
0009  *  Output parameters:  NONE
0010  *
0011  *  The license and distribution terms for this file may be
0012  *  found in the file LICENSE in this distribution or at
0013  *  http://www.rtems.org/license/LICENSE.
0014  */
0015 
0016 #ifdef HAVE_CONFIG_H
0017 #include "config.h"
0018 #endif
0019 
0020 #include "system.h"
0021 
0022 #include <rtems/bspIo.h>
0023 
0024 /* forward declarations to avoid warnings */
0025 void overrun_handler_task_4(rtems_cbs_server_id server_id);
0026 
0027 void overrun_handler_task_4(
0028   rtems_cbs_server_id server_id
0029 )
0030 {
0031   printk( "Signal overrun, fixing the task\n" );
0032   Violating_task[ 4 ] = 0;
0033   /* rtems_task_restart( RTEMS_SELF, 4 ); might be also possible*/
0034   return;
0035 }
0036 
0037 rtems_task Tasks_Periodic(
0038   rtems_task_argument argument
0039 )
0040 {
0041   rtems_id          rmid;
0042   rtems_id          test_rmid;
0043   rtems_status_code status;
0044   bool              scenario_done = 0;
0045 
0046   int start, stop, now;
0047 
0048   rtems_cbs_server_id server_id, tsid;
0049   rtems_cbs_parameters params, tparams;
0050 
0051   params.deadline = Periods[ argument ];
0052   params.budget = Execution[ argument ]+1;
0053 
0054   if ( argument == 4 ) {
0055     if ( rtems_cbs_create_server( &params, &overrun_handler_task_4, &server_id ))
0056       printf( "ERROR: CREATE SERVER FAILED\n" );
0057   }
0058   else {
0059     if ( rtems_cbs_create_server( &params, NULL, &server_id ) )
0060       printf( "ERROR: CREATE SERVER FAILED\n" );
0061   }
0062   if ( rtems_cbs_attach_thread( server_id, Task_id[ argument ] ) )
0063     printf( "ERROR: ATTACH THREAD FAILED\n" );
0064   if ( rtems_cbs_get_server_id( Task_id[ argument ], &tsid ) )
0065     printf( "ERROR: GET SERVER ID FAILED\n" );
0066   if ( tsid != server_id )
0067     printf( "ERROR: SERVER ID MISMATCH\n" );
0068   if ( rtems_cbs_get_parameters( server_id, &tparams ) )
0069     printf( "ERROR: GET PARAMETERS FAILED\n" );
0070   if ( params.deadline != tparams.deadline ||
0071        params.budget != tparams.budget )
0072     printf( "ERROR: PARAMETERS MISMATCH\n" );
0073 
0074   status = rtems_rate_monotonic_create( argument, &rmid );
0075   directive_failed( status, "rtems_rate_monotonic_create" );
0076   put_name( Task_name[ argument ], FALSE );
0077   printf( "- rtems_rate_monotonic_create id = 0x%08" PRIxrtems_id "\n",
0078           rmid );
0079 
0080   status = rtems_rate_monotonic_ident( argument, &test_rmid );
0081   directive_failed( status, "rtems_rate_monotonic_ident" );
0082   put_name( Task_name[ argument ], FALSE );
0083   printf( "- rtems_rate_monotonic_ident id = 0x%08" PRIxrtems_id "\n",
0084           test_rmid );
0085 
0086   if ( rmid != test_rmid ) {
0087      printf( "RMID's DO NOT MATCH (0x%" PRIxrtems_id " and 0x%"
0088              PRIxrtems_id ")\n", rmid, test_rmid );
0089      rtems_test_exit( 0 );
0090   }
0091 
0092   put_name( Task_name[ argument ], FALSE );
0093   printf( "- (0x%08" PRIxrtems_id ") period %" PRIu32 "\n",
0094           rmid, Periods[ argument ] );
0095 
0096   status = rtems_task_wake_after( 2 + Phases[argument] );
0097   directive_failed( status, "rtems_task_wake_after" );
0098 
0099   while (FOREVER) {
0100     if (rtems_rate_monotonic_period(rmid, Periods[argument])==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 >= 2*HP_LENGTH ) break; /* stop */
0106 
0107     /* Specific scenario for task 4: tries to exceed announced budget,
0108        the task priority has to be pulled down to background. */
0109     now = rtems_clock_get_ticks_since_boot();
0110     if ( !scenario_done && argument == 4 && now >= 200 ) {
0111       Violating_task[ argument ] = 1;
0112       scenario_done = 1;
0113     }
0114     /* Specific scenario for task 3: changes scheduling parameters. */
0115     if ( !scenario_done && argument == 3 && now >= 250 ) {
0116       Periods[ argument ]   = Periods[ argument ] * 2;
0117       Execution[ argument ] = Execution[ argument ] * 2;
0118       params.deadline = Periods[ argument ];
0119       params.budget   = Execution[ argument ]+1;
0120       if ( rtems_cbs_set_parameters( server_id, &params) )
0121         printf( "ERROR: SET PARAMETERS FAILED\n" );
0122       if ( rtems_cbs_get_parameters( server_id, &tparams ) )
0123         printf( "ERROR: GET PARAMETERS FAILED\n" );
0124       if ( params.deadline != tparams.deadline ||
0125            params.budget != tparams.budget )
0126         printf( "ERROR: PARAMETERS MISMATCH\n" );
0127       scenario_done = 1;
0128     }
0129     /* Specific scenario for task 2: late unblock after being blocked by
0130        itself, the task priority has to be pulled down to background. */
0131     if ( !scenario_done && argument == 2 && now >= 500 ) {
0132       Violating_task[ argument ] = 1;
0133       scenario_done = 1;
0134     }
0135     if (argument == 2 && Violating_task[ argument ])
0136       rtems_task_wake_after( 10 );
0137 
0138     /* active computing */
0139     while(FOREVER) {
0140       now = rtems_clock_get_ticks_since_boot();
0141       if ( argument == 4 && !Violating_task[ argument ] &&
0142           (now >= start + Execution[argument]))
0143         break;
0144       if ( argument != 4 && (now >= start + Execution[argument]) )
0145         break;
0146     }
0147     stop = rtems_clock_get_ticks_since_boot();
0148     printf("P%" PRIdPTR "-F ticks:%d\n", argument, stop);
0149   }
0150 
0151   /* delete period and SELF */
0152   status = rtems_rate_monotonic_delete( rmid );
0153   if ( status != RTEMS_SUCCESSFUL ) {
0154     printf("rtems_rate_monotonic_delete failed with status of %d.\n",status);
0155     rtems_test_exit( 0 );
0156   }
0157   if ( rtems_cbs_cleanup() )
0158     printf( "ERROR: CBS CLEANUP\n" );
0159   fflush(stdout);
0160   TEST_END();
0161   rtems_test_exit( 0 );
0162 }