source: rtems/testsuites/tmtests/tm03/task1.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2013.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.org/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#define CONFIGURE_INIT
15#include "system.h"
16
17rtems_id Semaphore_id;
18rtems_task test_init(
19  rtems_task_argument argument
20);
21
22rtems_task Middle_tasks(
23  rtems_task_argument argument
24);
25
26rtems_task High_task(
27  rtems_task_argument argument
28);
29
30int operation_count = OPERATION_COUNT;
31
32rtems_task Init(
33  rtems_task_argument argument
34)
35{
36  rtems_status_code status;
37  rtems_id          task_id;
38
39  Print_Warning();
40
41  puts( "\n\n*** TIME TEST 3 ***" );
42  status = rtems_task_create(
43    rtems_build_name( 'T', 'A', '1', ' ' ),
44    RTEMS_MAXIMUM_PRIORITY - 1u,
45    RTEMS_MINIMUM_STACK_SIZE,
46    RTEMS_DEFAULT_MODES,
47    RTEMS_DEFAULT_ATTRIBUTES,
48    &task_id
49  );
50  directive_failed( status, "rtems_task_create of test_init" );
51
52  status = rtems_task_start( task_id, test_init, 0 );
53  directive_failed( status, "rtems_task_start of test_init" );
54
55  status = rtems_task_delete( RTEMS_SELF );
56  directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
57}
58
59rtems_task test_init(
60  rtems_task_argument argument
61)
62{
63  rtems_status_code   status;
64  int                 index;
65  rtems_id            task_id;
66  rtems_task_priority priority;
67
68  priority = RTEMS_MAXIMUM_PRIORITY - 2u;
69
70  status = rtems_semaphore_create(
71    rtems_build_name( 'S', 'M', '1', '\0'),
72    0,
73    RTEMS_DEFAULT_ATTRIBUTES,
74    RTEMS_NO_PRIORITY,
75    &Semaphore_id
76  );
77  directive_failed( status, "rtems_semaphore_create of SM1" );
78
79  if ( OPERATION_COUNT > RTEMS_MAXIMUM_PRIORITY - 2u )
80    operation_count =  (int) (RTEMS_MAXIMUM_PRIORITY - 2u);
81  for ( index = 2 ; index < operation_count ; index ++ ) {
82    rtems_task_create(
83      rtems_build_name( 'M', 'I', 'D', ' ' ),
84      priority,
85      RTEMS_MINIMUM_STACK_SIZE,
86      RTEMS_DEFAULT_MODES,
87      RTEMS_DEFAULT_ATTRIBUTES,
88      &task_id
89    );
90    directive_failed( status, "rtems_task_create middle" );
91
92    priority--;
93
94    rtems_task_start( task_id, Middle_tasks, 0 );
95    directive_failed( status, "rtems_task_start middle" );
96  }
97
98  status = rtems_task_create(
99    rtems_build_name( 'H', 'I', 'G', 'H' ),
100    priority,
101    RTEMS_MINIMUM_STACK_SIZE,
102    RTEMS_DEFAULT_MODES,
103    RTEMS_DEFAULT_ATTRIBUTES,
104    &task_id
105  );
106  directive_failed( status, "rtems_task_create of high task" );
107
108  status = rtems_task_start( task_id, High_task, 0 );
109  directive_failed( status, "rtems_task_start of high task" );
110
111  benchmark_timer_initialize();                          /* start the timer */
112  status = rtems_semaphore_release( Semaphore_id );
113}
114
115rtems_task Middle_tasks(
116  rtems_task_argument argument
117)
118{
119  (void) rtems_semaphore_obtain(
120    Semaphore_id,
121    RTEMS_DEFAULT_OPTIONS,
122    RTEMS_NO_TIMEOUT
123  );
124
125  (void) rtems_semaphore_release( Semaphore_id );
126}
127
128rtems_task High_task(
129  rtems_task_argument argument
130)
131{
132  (void) rtems_semaphore_obtain(
133    Semaphore_id,
134    RTEMS_DEFAULT_OPTIONS,
135    RTEMS_NO_TIMEOUT
136  );
137
138  end_time = benchmark_timer_read();
139
140  put_time(
141    "rtems_semaphore_release: task readied preempts caller",
142    end_time,
143    operation_count - 1,
144    0,
145    CALLING_OVERHEAD_SEMAPHORE_RELEASE
146  );
147
148  puts( "*** END OF TEST 3 ***" );
149  rtems_test_exit( 0 );
150}
Note: See TracBrowser for help on using the repository browser.