source: rtems/testsuites/sptests/sp39/init.c @ 82478ffc

4.104.11
Last change on this file since 82478ffc was 82478ffc, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 2, 2008 at 8:57:28 PM

2008-10-02 Joel Sherrill <joel.sherrill@…>

  • sp09/screen01.c, sp09/screen12.c, sp25/system.h, sp25/task1.c, sp28/init.c, sp39/init.c, sp41/init.c, spfatal01/testcase.h, spfatal08/testcase.h: Change size_t to ssize_t on all Heap, Workspace and Region calls. On 16-bit architectures, size_t can be 16-bits which would limit sizes to 64K. Also address constants which overflowed on 16-bit integer targets.
  • Property mode set to 100644
File size: 4.5 KB
Line 
1/*
2 *  Classic API Signal to Task from ISR
3 *
4 *  COPYRIGHT (c) 1989-2008.
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
17volatile bool case_hit;
18
19rtems_id main_task;
20rtems_id other_task;
21
22rtems_timer_service_routine test_event_from_isr(
23  rtems_id  timer,
24  void     *arg
25)
26{
27  rtems_status_code     status;
28
29  if ( _Event_Sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED ) {
30    /*
31     *  This event send hits the critical section but sends to
32     *  another task so doesn't impact this critical section.
33     */
34    rtems_event_send( other_task, 0x02 );
35
36    /*
37     *  This event send hits the main task but doesn't satisfy
38     *  it's blocking condition so it will still block
39     */
40    rtems_event_send( main_task, 0x02 );
41
42    case_hit = TRUE;
43  }
44  status = rtems_event_send( main_task, 0x01 );
45}
46
47rtems_timer_service_routine test_event_with_timeout_from_isr(
48  rtems_id  timer,
49  void     *arg
50)
51{
52  rtems_status_code     status;
53
54  if ( _Event_Sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED ) {
55    /*
56     *  We want to catch the task while it is blocking.  Otherwise
57     *  just send and make it happy.
58     */
59    case_hit = TRUE;
60  }
61  status = rtems_event_send( main_task, 0x01 );
62}
63
64rtems_task Init(
65  rtems_task_argument argument
66)
67{
68  rtems_status_code     status;
69  rtems_id              timer;
70  rtems_event_set       out;
71  int                   i;
72  int                   max;
73  uint32_t              iterations = 0;
74
75  puts( "\n\n*** TEST 39 ***" );
76
77  main_task = rtems_task_self();
78
79  /*
80   *  Timer used in multiple ways
81   */
82  status = rtems_timer_create( 1, &timer );
83  directive_failed( status, "rtems_timer_create" );
84
85  status = rtems_task_create(
86     0xa5a5a5a5,
87     1,
88     RTEMS_MINIMUM_STACK_SIZE,
89     RTEMS_DEFAULT_MODES,
90     RTEMS_DEFAULT_ATTRIBUTES,
91     &other_task
92  );
93  directive_failed( status, "rtems_task_create" );
94
95  /*
96   * Test Event send successful from ISR -- receive is forever
97   */
98  case_hit = FALSE;
99  iterations = 0;
100  max = 1;
101
102  while (1) {
103    if ( case_hit )
104      break;
105    status = rtems_timer_fire_after( timer, 1, test_event_from_isr, NULL );
106    directive_failed( status, "timer_fire_after failed" );
107
108    for (i=0 ; i<max ; i++ )
109      if ( _Event_Sync_state == THREAD_BLOCKING_OPERATION_SATISFIED )
110        break;
111
112    status = rtems_event_receive( 0x01, RTEMS_DEFAULT_OPTIONS, 0, &out );
113    directive_failed( status, "rtems_event_receive" );
114    if ( case_hit == TRUE )
115      break;
116    max += 2;
117
118    /* with our clock tick, this is about 30 seconds */
119    if ( ++iterations >= 4L * 1000L * 30L)
120      break;
121  }
122
123   printf(
124     "Event sent from ISR hitting synchronization point has %soccurred\n",
125     (( case_hit == TRUE ) ? "" : "NOT ")
126  ); 
127
128  /*
129   * Test Event send successful from ISR -- receive has timeout
130   */
131  case_hit = FALSE;
132  iterations = 0;
133  max = 1;
134
135  while (1) {
136    if ( case_hit )
137      break;
138    status = rtems_timer_fire_after(
139      timer, 1, test_event_with_timeout_from_isr, NULL );
140    directive_failed( status, "timer_fire_after failed" );
141
142    for (i=0 ; i<max ; i++ )
143      if ( _Event_Sync_state == THREAD_BLOCKING_OPERATION_SATISFIED )
144        break;
145
146    status = rtems_event_receive( 0x01, RTEMS_DEFAULT_OPTIONS, 10, &out );
147    directive_failed( status, "rtems_event_receive" );
148    if ( case_hit == TRUE )
149      break;
150    max += 2;
151
152    /* with our clock tick, this is about 30 seconds */
153    if ( ++iterations >= 4L * 1000L * 30L)
154      break;
155  }
156
157   printf(
158     "Event sent from ISR (with timeout) hitting synchronization "
159       "point has %soccurred\n",
160     (( case_hit == TRUE ) ? "" : "NOT ")
161  ); 
162
163  /*
164   *  Now try for a timeout case
165   */
166  iterations = 0;
167  case_hit = FALSE;
168  max = 1;
169
170  puts(
171    "Run multiple times in attempt to hit event timeout synchronization point"
172  ); 
173  while (1) {
174
175    for (i=0 ; i<max ; i++ )
176      if ( _Event_Sync_state == THREAD_BLOCKING_OPERATION_SATISFIED )
177        break;
178
179    status = rtems_event_receive( 0x01, RTEMS_DEFAULT_OPTIONS, 1, &out );
180    fatal_directive_status( status, RTEMS_TIMEOUT, "event_receive timeout" );
181
182    if ( ++max > 10240 )
183      max = 0;
184
185    /* with our clock tick, this is about 30 seconds */
186    if ( ++iterations >= 4L * 1000L * 30L)
187      break;
188
189  }
190
191  puts( "*** END OF TEST 39 ***" );
192  rtems_test_exit( 0 );
193}
Note: See TracBrowser for help on using the repository browser.