source: rtems/testsuites/sptests/sp34/changepri.c @ 23a368d

4.104.114.95
Last change on this file since 23a368d was 23a368d, checked in by Joel Sherrill <joel.sherrill@…>, on 01/23/08 at 22:57:54

2008-01-23 Joel Sherrill <joel.sherrill@…>

  • sp34/changepri.c, sp35/priinv.c: Convert the Objects_Name type from a simple type to a union of an unsigned 32 bit integer and a pointer. This should help eliminate weird casts between u32 and pointers in various places. The APIs now have to explicitly call _u32 or _string versions of helper routines. This should also simplify things and eliminate the need for ugly casts in some cases.
  • Property mode set to 100644
File size: 5.0 KB
Line 
1/*
2 *  Test program to demonstrate reordering of threads on thread queues
3 *  when their priority changes.
4 *
5 *  $Id$
6 */
7
8#include <bsp.h>
9#include <stdio.h>
10
11/********************************************************************/
12/* define this to use the RTEMS 4.5 scheme for object names */
13/* #define TEST_ON_RTEMS_45 */
14
15/* define this to print the Id of the calling task */
16/* #define TEST_ON_TASK_ID */
17
18/********************************************************************/
19
20#define CONFIGURE_INIT
21
22#include <bsp.h>
23#include <stdio.h>
24#include "tmacros.h"
25
26rtems_task BlockingTasks(rtems_task_argument arg);
27
28/*
29 *  CallerName -- print the calling tasks name or id as configured
30 */
31const char *CallerName()
32{
33  static char buffer[32];
34#if defined(TEST_PRINT_TASK_ID)
35  sprintf( buffer, "0x%08x -- %d",
36      rtems_task_self(), _Thread_Executing->current_priority );
37#else
38  union {
39    uint32_t u;
40    unsigned char c[4];
41  } TempName;
42
43  #if defined(TEST_ON_RTEMS_45)
44    TempName.u = *(uint32_t *)_Thread_Executing->Object.name;
45  #else
46    TempName.u = _Thread_Executing->Object.name.name_u32;
47  #endif
48  sprintf( buffer, "%c%c%c%c -- %d",
49      TempName.c[0], TempName.c[1], TempName.c[2], TempName.c[3],
50      _Thread_Executing->current_priority
51  );
52#endif
53  return buffer;
54}
55
56#define NUMBER_OF_BLOCKING_TASKS 5
57
58/* RTEMS ids of blocking threads */
59rtems_id  Blockers[NUMBER_OF_BLOCKING_TASKS];
60
61/* Semaphore they are all blocked on */
62rtems_id  Semaphore;
63
64rtems_task BlockingTasks(rtems_task_argument arg)
65{
66  rtems_status_code   status;
67  rtems_task_priority opri;
68  rtems_task_priority npri;
69
70  status = rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &opri);
71  directive_failed( status, "rtems_task_set_priority" );
72
73  printf("semaphore_obtain -- BlockingTask %d @ pri=%d) blocks\n", arg, opri);
74  status = rtems_semaphore_obtain(Semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
75  directive_failed( status, "rtems_semaphore_obtain" );
76
77  /* priority should have changed while blocked */
78  status = rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &npri);
79  directive_failed( status, "rtems_task_set_priority" );
80
81  printf("semaphore_obtain -- BlockingTask %d @ pri=%d) returns\n", arg, npri);
82
83  (void) rtems_task_delete( RTEMS_SELF );
84}
85
86/*************************************************************************/
87/**********************        INITIALIZATION        *********************/
88/*************************************************************************/
89
90rtems_task Init(rtems_task_argument ignored)
91{
92  rtems_status_code   status;   
93  int                 i;
94 
95  puts( "\n\n*** TEST 34 ***" );
96
97  /* Create synchronisation semaphore for LocalHwIsr -> Test Tasks */
98  status = rtems_semaphore_create(
99    rtems_build_name ('S', 'E', 'M', '1'),           /* name */
100    0,                                               /* initial count = 0 */
101    RTEMS_LOCAL                   |
102    RTEMS_COUNTING_SEMAPHORE      |
103    RTEMS_PRIORITY,
104    0,
105    &Semaphore);                                    /* *id */
106  directive_failed( status, "rtems_semaphore_create" );
107 
108  /* Create and start all tasks in the test */
109
110  for (i = 0; i < NUMBER_OF_BLOCKING_TASKS; i++) {
111    status = rtems_task_create(
112      rtems_build_name('B','L','K','0'+i),               /* Name */
113      2+i,                                               /* Priority */
114      RTEMS_MINIMUM_STACK_SIZE*2,                        /* Stack size (8KB) */
115      RTEMS_DEFAULT_MODES | RTEMS_NO_ASR,                /* Mode */
116      RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT,   /* Attributes */
117      &Blockers[i]);                                     /* Assigned ID */
118    directive_failed( status, "rtems_task_create (BLKn)" );
119 
120    printf( "Blockers[%d] Id = 0x%08x\n", i, Blockers[i] );
121    status = rtems_task_start(Blockers[i], BlockingTasks, i);
122    directive_failed( status, "rtems_task_start (BLKn)" );
123  }
124
125  status = rtems_task_wake_after( 100 );
126  directive_failed( status, "rtems_task_wake_after" );
127
128  puts( "rtems_task_set_priority -- invert priorities of tasks" );
129  for (i = 0; i < NUMBER_OF_BLOCKING_TASKS; i++) {
130    rtems_task_priority opri;
131    rtems_task_priority npri= 2 + NUMBER_OF_BLOCKING_TASKS - i - 1;
132
133    status = rtems_task_set_priority(Blockers[i], npri, &opri);
134    directive_failed( status, "rtems_task_set_priority" );
135  }
136
137  for (i = 0; i < NUMBER_OF_BLOCKING_TASKS; i++) {
138    puts( "rtems_semaphore_release -- OK" );
139    status = rtems_semaphore_release(Semaphore);
140    directive_failed( status, "rtems_semaphore_release" );
141
142    status = rtems_task_wake_after( 100 );
143    directive_failed( status, "rtems_task_wake_after" );
144  }
145
146  /* exit the test */
147  puts( "*** END OF TEST 34 ***" );
148  exit(0);
149}
150
151/* configuration information */
152
153#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
154#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
155
156#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
157
158#define CONFIGURE_EXTRA_TASK_STACKS \
159          (RTEMS_MINIMUM_STACK_SIZE * NUMBER_OF_BLOCKING_TASKS)
160
161#define CONFIGURE_MAXIMUM_TASKS 6
162#define CONFIGURE_MAXIMUM_SEMAPHORES 1
163
164#include <rtems/confdefs.h>
165
166/* end of file */
Note: See TracBrowser for help on using the repository browser.