source: rtems/testsuites/sptests/spsimplesched02/init.c @ e3be6915

4.115
Last change on this file since e3be6915 was e3be6915, checked in by Sebastian Huber <sebastian.huber@…>, on 05/27/13 at 15:31:46

score: Remove idle field of Per_CPU_Control

This field is unused except for special case simulator clock drivers.
In these places use an alternative. Add and use
_Thread_Set_global_exit_status() and _Thread_Get_global_exit_status().

  • Property mode set to 100644
File size: 4.3 KB
Line 
1/*
2 *  COPYRIGHT (c) 2011.
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.com/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#include <tmacros.h>
15
16/* forward declarations to avoid warnings */
17rtems_task Init(rtems_task_argument argument);
18rtems_task Test_task(rtems_task_argument argument);
19void ObtainRelease(bool suspendIdle);
20
21/*
22 *  Keep the names and IDs in global variables so another task can use them.
23 */
24rtems_id   Idle_id;
25rtems_id   Task_id[ 3 ];         /* array of task ids */
26rtems_name Task_name[ 3 ];       /* array of task names */
27rtems_name Semaphore_name[ 2 ];
28rtems_id   Semaphore_id[ 2 ];
29
30rtems_task Test_task(
31  rtems_task_argument unused
32)
33{
34  rtems_id          tid;
35  rtems_status_code status;
36
37  status = rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &tid );
38  directive_failed( status, "wake after" );
39
40  for ( ; ; ) {
41    status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
42    directive_failed( status, "yield" );
43  }
44}
45
46void ObtainRelease( bool suspendIdle )
47{
48  rtems_status_code   status;
49
50  if (suspendIdle) {
51    puts( "INIT - Suspend Idle Task");
52    status = rtems_task_suspend( Idle_id );
53    directive_failed( status, "rtems_task_suspend idle" );
54  }
55
56  puts( "INIT - Obtain priority ceiling semaphore - priority increases" );
57  status= rtems_semaphore_obtain( Semaphore_id[1], RTEMS_DEFAULT_OPTIONS, 0 );
58  directive_failed( status, "rtems_semaphore_obtain" );
59
60  puts( "INIT - Obtain priority ceiling semaphore - priority decreases" );
61  status = rtems_semaphore_release( Semaphore_id[1] );
62  directive_failed( status, "rtems_semaphore_release" );
63
64  if (suspendIdle) {
65    puts( "INIT - Resume Idle Task");
66    status = rtems_task_resume( Idle_id );
67    directive_failed( status, "rtems_task_resume idle" );
68  }
69}
70
71rtems_task Init(
72  rtems_task_argument argument
73)
74{
75  rtems_status_code   status;
76
77  puts( "\n\n*** SIMPLE SCHEDULER 02 TEST ***" );
78
79  status = _Objects_Name_to_id_u32(
80    &_Thread_Internal_information,
81    rtems_build_name( 'I', 'D', 'L', 'E' ),
82    RTEMS_SEARCH_LOCAL_NODE,
83    &Idle_id
84  );
85  rtems_test_assert( status == RTEMS_SUCCESSFUL );
86
87  /*
88   * Create the semaphore. Then obtain and release the
89   * semaphore with no other tasks running.
90   */
91  puts( "INIT - Create priority ceiling semaphore" );
92  Semaphore_name[ 1 ] = rtems_build_name( 'S', 'M', '1', ' ' );
93  status = rtems_semaphore_create(
94    Semaphore_name[ 1 ],
95    1,
96    RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY_CEILING | RTEMS_PRIORITY,
97    2,
98    &Semaphore_id[ 1 ]
99  );
100  directive_failed( status, "rtems_semaphore_create of SM1" );
101  ObtainRelease( false );
102
103  /*
104   * Create test task and obtain release the semaphore with
105   * one other task running.
106   */
107  puts( "INIT - create task 1" );
108  Task_name[ 1 ] = rtems_build_name( 'T', 'A', '1', ' ' );
109  status = rtems_task_create(
110    Task_name[ 1 ], 1, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES,
111    RTEMS_DEFAULT_ATTRIBUTES, &Task_id[ 1 ]
112  );
113  status = rtems_task_start( Task_id[ 1 ], Test_task, 1 );
114  ObtainRelease( false );
115
116  /*
117   * Create a a second test task and obtain release the semaphore
118   * with both tasks running.
119   */
120  puts( "INIT - create task 2" );
121  Task_name[ 1 ] = rtems_build_name( 'T', 'A', '2', ' ' );
122  status = rtems_task_create(
123    Task_name[ 2 ], 1, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES,
124    RTEMS_DEFAULT_ATTRIBUTES, &Task_id[ 2 ]
125  );
126  status = rtems_task_start( Task_id[ 2 ], Test_task, 1 );
127  ObtainRelease( false );
128
129  /*
130   * Obtain and release the semaphore with the idle task suspended.
131   */
132  ObtainRelease( true );
133
134  /*  End the Test */
135  puts( "*** END OF SIMPLE SCHEDULER 02 TEST ***" );
136  rtems_test_exit(0);
137}
138
139/* configuration information */
140
141#define CONFIGURE_SCHEDULER_SIMPLE
142#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
143#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
144
145#define CONFIGURE_MAXIMUM_TASKS             3
146#define CONFIGURE_MAXIMUM_SEMAPHORES        2
147
148#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
149
150#define CONFIGURE_EXTRA_TASK_STACKS         (3 * RTEMS_MINIMUM_STACK_SIZE)
151#define CONFIGURE_INIT_TASK_PRIORITY        4
152
153#define CONFIGURE_INIT
154#include <rtems/confdefs.h>
155/* end of include file */
Note: See TracBrowser for help on using the repository browser.