source: rtems/testsuites/sptests/spsimplesched02/init.c @ 3c8eda7

4.115
Last change on this file since 3c8eda7 was 3c8eda7, checked in by Joel Sherrill <joel.sherrill@…>, on 05/12/12 at 16:01:26

sptests - Eliminate missing prototype warnings

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