source: rtems/testsuites/tmtests/tm11/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.5 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 Queue_id;
18
19long Buffer[4];
20
21rtems_task test_init(
22  rtems_task_argument argument
23);
24
25rtems_task Middle_tasks(
26  rtems_task_argument argument
27);
28
29rtems_task High_task(
30  rtems_task_argument argument
31);
32
33int operation_count = OPERATION_COUNT;
34
35void Init(
36  rtems_task_argument argument
37)
38{
39  rtems_status_code status;
40  rtems_id id;
41
42  Print_Warning();
43
44  puts( "\n\n*** TIME TEST 11 ***" );
45
46  status = rtems_task_create(
47    1,
48    RTEMS_MAXIMUM_PRIORITY - 1u,
49    RTEMS_MINIMUM_STACK_SIZE,
50    RTEMS_DEFAULT_MODES,
51    RTEMS_DEFAULT_ATTRIBUTES,
52    &id
53  );
54  directive_failed( status, "rtems_task_create" );
55
56  status = rtems_task_start( id, test_init, 0 );
57  directive_failed( status, "rtems_task_start" );
58
59  status = rtems_task_delete( RTEMS_SELF );
60  directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
61}
62
63#define MESSAGE_SIZE (sizeof(long) * 4)
64
65rtems_task test_init(
66  rtems_task_argument argument
67)
68{
69  int                 index;
70  rtems_task_entry    task_entry;
71  rtems_task_priority priority;
72  rtems_id            task_id;
73  rtems_status_code   status;
74
75/*  As each task is started, it preempts this task and
76 *  performs a blocking rtems_message_queue_receive.  Upon completion of
77 *  this loop all created tasks are blocked.
78 */
79
80  status = rtems_message_queue_create(
81    rtems_build_name( 'M', 'Q', '1', ' '  ),
82    OPERATION_COUNT,
83    MESSAGE_SIZE,
84    RTEMS_DEFAULT_ATTRIBUTES,
85    &Queue_id
86  );
87  directive_failed( status, "rtems_message_queue_create" );
88
89  priority = RTEMS_MAXIMUM_PRIORITY - 2u;
90
91  if ( OPERATION_COUNT > RTEMS_MAXIMUM_PRIORITY - 2u )
92    operation_count =  RTEMS_MAXIMUM_PRIORITY - 2u;
93  for( index = 0; index < operation_count ; index++ ) {
94    status = rtems_task_create(
95      rtems_build_name( 'T', 'I', 'M', 'E'  ),
96      priority,
97      RTEMS_MINIMUM_STACK_SIZE,
98      RTEMS_DEFAULT_MODES,
99      RTEMS_DEFAULT_ATTRIBUTES,
100      &task_id
101    );
102    directive_failed( status, "rtems_task_create LOOP" );
103
104    priority--;
105
106    if ( index==operation_count-1 ) task_entry = High_task;
107    else                            task_entry = Middle_tasks;
108
109    status = rtems_task_start( task_id, task_entry, 0 );
110    directive_failed( status, "rtems_task_start LOOP" );
111  }
112
113  benchmark_timer_initialize();
114    (void) rtems_message_queue_send( Queue_id, Buffer, MESSAGE_SIZE );
115}
116
117rtems_task Middle_tasks(
118  rtems_task_argument argument
119)
120{
121  size_t  size;
122
123  (void) rtems_message_queue_receive(
124           Queue_id,
125           (long (*)[4]) Buffer,
126           &size,
127           RTEMS_DEFAULT_OPTIONS,
128           RTEMS_NO_TIMEOUT
129         );
130
131  (void) rtems_message_queue_send( Queue_id, (long (*)[4]) Buffer, size );
132}
133
134rtems_task High_task(
135  rtems_task_argument argument
136)
137{
138  size_t  size;
139
140  (void) rtems_message_queue_receive(
141           Queue_id,
142           (long (*)[4]) Buffer,
143           &size,
144           RTEMS_DEFAULT_OPTIONS,
145           RTEMS_NO_TIMEOUT
146         );
147
148  end_time = benchmark_timer_read();
149
150  put_time(
151    "rtems_message_queue_send: task readied preempts caller",
152    end_time,
153    operation_count,
154    0,
155    CALLING_OVERHEAD_MESSAGE_QUEUE_SEND
156  );
157
158  puts( "*** END OF TEST 11 ***" );
159  rtems_test_exit( 0 );
160}
Note: See TracBrowser for help on using the repository browser.