File indexing completed on 2025-05-11 08:24:50
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #if !defined(OPERATION_COUNT)
0030 #define OPERATION_COUNT 100
0031 #endif
0032
0033 #ifdef HAVE_CONFIG_H
0034 #include "config.h"
0035 #endif
0036
0037 #include <rtems/btimer.h>
0038
0039 #define CONFIGURE_INIT
0040 #include "system.h"
0041
0042 #if defined(TM03)
0043 const char rtems_test_name[] = "TIME TEST 3";
0044 #define SEMAPHORE_ATTRIBUTES (RTEMS_COUNTING_SEMAPHORE | RTEMS_FIFO)
0045 #define ATTR_DESC "counting/FIFO"
0046
0047 #elif defined(TM32)
0048 const char rtems_test_name[] = "TIME TEST 32";
0049 #define SEMAPHORE_ATTRIBUTES (RTEMS_COUNTING_SEMAPHORE | RTEMS_PRIORITY)
0050 #define ATTR_DESC "counting/priority"
0051
0052 #elif defined(TM34)
0053 const char rtems_test_name[] = "TIME TEST 34";
0054 #define SEMAPHORE_ATTRIBUTES RTEMS_BINARY_SEMAPHORE
0055 #define ATTR_DESC "binary/FIFO"
0056
0057 #elif defined(TM36)
0058 const char rtems_test_name[] = "TIME TEST 36";
0059 #define SEMAPHORE_ATTRIBUTES (RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY)
0060 #define ATTR_DESC "binary/priority"
0061
0062 #else
0063 #error "Unknown test configuration"
0064 #endif
0065
0066
0067 rtems_id Semaphore_id;
0068 rtems_task test_init(
0069 rtems_task_argument argument
0070 );
0071
0072 rtems_task Middle_tasks(
0073 rtems_task_argument argument
0074 );
0075
0076 rtems_task High_task(
0077 rtems_task_argument argument
0078 );
0079
0080 int operation_count = OPERATION_COUNT;
0081
0082 rtems_task Init(
0083 rtems_task_argument argument
0084 )
0085 {
0086 rtems_status_code status;
0087 rtems_id task_id;
0088
0089 Print_Warning();
0090
0091 TEST_BEGIN();
0092 status = rtems_task_create(
0093 rtems_build_name( 'T', 'A', '1', ' ' ),
0094 RTEMS_MAXIMUM_PRIORITY - 1u,
0095 RTEMS_MINIMUM_STACK_SIZE,
0096 RTEMS_DEFAULT_MODES,
0097 RTEMS_DEFAULT_ATTRIBUTES,
0098 &task_id
0099 );
0100 directive_failed( status, "rtems_task_create of test_init" );
0101
0102 status = rtems_task_start( task_id, test_init, 0 );
0103 directive_failed( status, "rtems_task_start of test_init" );
0104
0105 rtems_task_exit();
0106 }
0107
0108 rtems_task test_init(
0109 rtems_task_argument argument
0110 )
0111 {
0112 rtems_status_code status;
0113 int index;
0114 rtems_id task_id;
0115 rtems_task_priority priority;
0116
0117 priority = RTEMS_MAXIMUM_PRIORITY - 2u;
0118
0119 status = rtems_semaphore_create(
0120 rtems_build_name( 'S', 'M', '1', '\0'),
0121 0,
0122 SEMAPHORE_ATTRIBUTES,
0123 RTEMS_NO_PRIORITY,
0124 &Semaphore_id
0125 );
0126 directive_failed( status, "rtems_semaphore_create of SM1" );
0127
0128 if ( OPERATION_COUNT > RTEMS_MAXIMUM_PRIORITY - 2u )
0129 operation_count = (int) (RTEMS_MAXIMUM_PRIORITY - 2u);
0130 for ( index = 2 ; index < operation_count ; index ++ ) {
0131 rtems_task_create(
0132 rtems_build_name( 'M', 'I', 'D', ' ' ),
0133 priority,
0134 RTEMS_MINIMUM_STACK_SIZE,
0135 RTEMS_DEFAULT_MODES,
0136 RTEMS_DEFAULT_ATTRIBUTES,
0137 &task_id
0138 );
0139 directive_failed( status, "rtems_task_create middle" );
0140
0141 priority--;
0142
0143 rtems_task_start( task_id, Middle_tasks, 0 );
0144 directive_failed( status, "rtems_task_start middle" );
0145 }
0146
0147 status = rtems_task_create(
0148 rtems_build_name( 'H', 'I', 'G', 'H' ),
0149 priority,
0150 RTEMS_MINIMUM_STACK_SIZE,
0151 RTEMS_DEFAULT_MODES,
0152 RTEMS_DEFAULT_ATTRIBUTES,
0153 &task_id
0154 );
0155 directive_failed( status, "rtems_task_create of high task" );
0156
0157 status = rtems_task_start( task_id, High_task, 0 );
0158 directive_failed( status, "rtems_task_start of high task" );
0159
0160 benchmark_timer_initialize();
0161 status = rtems_semaphore_release( Semaphore_id );
0162 }
0163
0164 rtems_task Middle_tasks(
0165 rtems_task_argument argument
0166 )
0167 {
0168 (void) rtems_semaphore_obtain(
0169 Semaphore_id,
0170 RTEMS_DEFAULT_OPTIONS,
0171 RTEMS_NO_TIMEOUT
0172 );
0173
0174 (void) rtems_semaphore_release( Semaphore_id );
0175 }
0176
0177 rtems_task High_task(
0178 rtems_task_argument argument
0179 )
0180 {
0181 (void) rtems_semaphore_obtain(
0182 Semaphore_id,
0183 RTEMS_DEFAULT_OPTIONS,
0184 RTEMS_NO_TIMEOUT
0185 );
0186
0187 end_time = benchmark_timer_read();
0188
0189 put_time(
0190 "rtems_semaphore_release: " ATTR_DESC " task readied preempts caller",
0191 end_time,
0192 operation_count - 1,
0193 0,
0194 0
0195 );
0196
0197 TEST_END();
0198 rtems_test_exit( 0 );
0199 }