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

4.104.115
Last change on this file since b1274bd9 was b1274bd9, checked in by Ralf Corsepius <ralf.corsepius@…>, on 11/30/09 at 03:33:25

Whitespace removal.

  • Property mode set to 100644
File size: 4.0 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  puts( "*** END OF TEST 39 ***" );
173  rtems_test_exit( 0 );
174}
Note: See TracBrowser for help on using the repository browser.