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