source: rtems/testsuites/sptests/sp39/init.c @ b84f1fdc

4.104.11
Last change on this file since b84f1fdc was b84f1fdc, checked in by Joel Sherrill <joel.sherrill@…>, on May 10, 2009 at 2:39:46 PM

2009-05-10 Joel Sherrill <joel.sherrill@…>

  • sp04/system.h, sp04/task1.c, sp04/tswitch.c, sp07/init.c, sp12/init.c, sp13/putbuff.c, sp13/system.h, sp13/task1.c, sp15/init.c, sp16/system.h, sp19/fptask.c, sp25/system.h, sp26/task1.c, sp27/init.c, sp28/init.c, sp29/init.c, sp31/task1.c, sp33/init.c, sp34/changepri.c, sp35/priinv.c, sp37/init.c, sp38/init.c, sp39/init.c, sp41/init.c, sp42/init.c, sp43/init.c, sp44/init.c, sp45/init.c, sp46/init.c, sp47/init.c, sp48/init.c, spfatal03/testcase.h, spfatal05/testcase.h, spfatal06/testcase.h, spfatal_support/system.h, spobjgetnext/init.c, spsize/getint.c, spsize/size.c: Fix warnings.
  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 *  Classic API Signal to Task from ISR
3 *
4 *  COPYRIGHT (c) 1989-2009.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#define CONFIGURE_INIT
15#include "system.h"
16
17rtems_timer_service_routine test_event_from_isr(
18  rtems_id  timer,
19  void     *arg
20);
21rtems_timer_service_routine test_event_with_timeout_from_isr(
22  rtems_id  timer,
23  void     *arg
24);
25
26volatile bool case_hit;
27
28rtems_id main_task;
29rtems_id other_task;
30
31rtems_timer_service_routine test_event_from_isr(
32  rtems_id  timer,
33  void     *arg
34)
35{
36  rtems_status_code     status;
37
38  if ( _Event_Sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED ) {
39    /*
40     *  This event send hits the critical section but sends to
41     *  another task so doesn't impact this critical section.
42     */
43    rtems_event_send( other_task, 0x02 );
44
45    /*
46     *  This event send hits the main task but doesn't satisfy
47     *  it's blocking condition so it will still block
48     */
49    rtems_event_send( main_task, 0x02 );
50
51    case_hit = TRUE;
52  }
53  status = rtems_event_send( main_task, 0x01 );
54}
55
56rtems_timer_service_routine test_event_with_timeout_from_isr(
57  rtems_id  timer,
58  void     *arg
59)
60{
61  rtems_status_code     status;
62
63  if ( _Event_Sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED ) {
64    /*
65     *  We want to catch the task while it is blocking.  Otherwise
66     *  just send and make it happy.
67     */
68    case_hit = TRUE;
69  }
70  status = rtems_event_send( main_task, 0x01 );
71}
72
73rtems_task Init(
74  rtems_task_argument argument
75)
76{
77  rtems_status_code     status;
78  rtems_id              timer;
79  rtems_event_set       out;
80  int                   i;
81  int                   max;
82  uint32_t              iterations = 0;
83
84  puts( "\n\n*** TEST 39 ***" );
85
86  main_task = rtems_task_self();
87
88  /*
89   *  Timer used in multiple ways
90   */
91  status = rtems_timer_create( 1, &timer );
92  directive_failed( status, "rtems_timer_create" );
93
94  status = rtems_task_create(
95     0xa5a5a5a5,
96     1,
97     RTEMS_MINIMUM_STACK_SIZE,
98     RTEMS_DEFAULT_MODES,
99     RTEMS_DEFAULT_ATTRIBUTES,
100     &other_task
101  );
102  directive_failed( status, "rtems_task_create" );
103
104  /*
105   * Test Event send successful from ISR -- receive is forever
106   */
107  case_hit = FALSE;
108  iterations = 0;
109  max = 1;
110
111  while (1) {
112    if ( case_hit )
113      break;
114    status = rtems_timer_fire_after( timer, 1, test_event_from_isr, NULL );
115    directive_failed( status, "timer_fire_after failed" );
116
117    for (i=0 ; i<max ; i++ )
118      if ( _Event_Sync_state == THREAD_BLOCKING_OPERATION_SATISFIED )
119        break;
120
121    status = rtems_event_receive( 0x01, RTEMS_DEFAULT_OPTIONS, 0, &out );
122    directive_failed( status, "rtems_event_receive" );
123    if ( case_hit == TRUE )
124      break;
125    max += 2;
126
127    /* with our clock tick, this is about 30 seconds */
128    if ( ++iterations >= 4L * 1000L * 30L)
129      break;
130  }
131
132   printf(
133     "Event sent from ISR hitting synchronization point has %soccurred\n",
134     (( case_hit == TRUE ) ? "" : "NOT ")
135  ); 
136
137  /*
138   * Test Event send successful from ISR -- receive has timeout
139   */
140  case_hit = FALSE;
141  iterations = 0;
142  max = 1;
143
144  while (1) {
145    if ( case_hit )
146      break;
147    status = rtems_timer_fire_after(
148      timer, 1, test_event_with_timeout_from_isr, NULL );
149    directive_failed( status, "timer_fire_after failed" );
150
151    for (i=0 ; i<max ; i++ )
152      if ( _Event_Sync_state == THREAD_BLOCKING_OPERATION_SATISFIED )
153        break;
154
155    status = rtems_event_receive( 0x01, RTEMS_DEFAULT_OPTIONS, 10, &out );
156    directive_failed( status, "rtems_event_receive" );
157    if ( case_hit == TRUE )
158      break;
159    max += 2;
160
161    /* with our clock tick, this is about 30 seconds */
162    if ( ++iterations >= 4L * 1000L * 30L)
163      break;
164  }
165
166   printf(
167     "Event sent from ISR (with timeout) hitting synchronization "
168       "point has %soccurred\n",
169     (( case_hit == TRUE ) ? "" : "NOT ")
170  ); 
171
172  /*
173   *  Now try for a timeout case
174   */
175  iterations = 0;
176  case_hit = FALSE;
177  max = 1;
178
179  puts(
180    "Run multiple times in attempt to hit event timeout synchronization point"
181  ); 
182  while (1) {
183
184    for (i=0 ; i<max ; i++ )
185      if ( _Event_Sync_state == THREAD_BLOCKING_OPERATION_SATISFIED )
186        break;
187
188    status = rtems_event_receive( 0x01, RTEMS_DEFAULT_OPTIONS, 1, &out );
189    fatal_directive_status( status, RTEMS_TIMEOUT, "event_receive timeout" );
190
191    if ( ++max > 10240 )
192      max = 0;
193
194    /* with our clock tick, this is about 30 seconds */
195    if ( ++iterations >= 4L * 1000L * 30L)
196      break;
197
198  }
199
200  puts( "*** END OF TEST 39 ***" );
201  rtems_test_exit( 0 );
202}
Note: See TracBrowser for help on using the repository browser.