source: rtems/testsuites/sptests/sp39/init.c @ 8b7a713

4.104.114.9
Last change on this file since 8b7a713 was 8b7a713, checked in by Joel Sherrill <joel.sherrill@…>, on Jan 22, 2008 at 6:30:14 PM

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

  • sp39/init.c: Clean up.
  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 *  Classic API Signal to Task from ISR
3 *
4 *  COPYRIGHT (c) 1989-2007.
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 TEST_INIT
15#include "system.h"
16
17volatile boolean 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_task Init(
48  rtems_task_argument argument
49)
50{
51  rtems_status_code     status;
52  rtems_id              timer;
53  rtems_event_set       out;
54  int                   i;
55  int                   max;
56  int                   iterations = 0;
57
58  puts( "\n\n*** TEST 39 ***" );
59
60  main_task = rtems_task_self();
61
62  /*
63   *  Timer used in multiple ways
64   */
65  status = rtems_timer_create( 1, &timer );
66  directive_failed( status, "rtems_timer_create" );
67
68  status = rtems_task_create(
69     0xa5a5a5a5,
70     1,
71     RTEMS_MINIMUM_STACK_SIZE,
72     RTEMS_DEFAULT_MODES,
73     RTEMS_DEFAULT_ATTRIBUTES,
74     &other_task
75  );
76  directive_failed( status, "rtems_task_create" );
77
78  /*
79   * Test Event send successful from ISR
80   */
81  case_hit = FALSE;
82  iterations = 0;
83  max = 1;
84
85  while (1) {
86    if ( case_hit )
87      break;
88    status = rtems_timer_fire_after( timer, 1, test_event_from_isr, NULL );
89    directive_failed( status, "timer_fire_after failed" );
90
91    for (i=0 ; i<max ; i++ )
92      if ( _Event_Sync_state == THREAD_BLOCKING_OPERATION_SATISFIED )
93        break;
94
95    status = rtems_event_receive( 0x01, RTEMS_DEFAULT_OPTIONS, 0, &out );
96    directive_failed( status, "rtems_event_receive" );
97    if ( case_hit == TRUE )
98      break;
99    max += 2;
100
101    /* with our clock tick, this is about 30 seconds */
102    if ( ++iterations >= 4 * 1000 * 30)
103      break;
104  }
105
106   printf(
107     "Event sent from ISR hitting synchronization point has %soccurred\n",
108     (( case_hit == TRUE ) ? "" : "NOT ")
109  ); 
110
111  /*
112   *  Now try for a timeout case
113   */
114  iterations = 0;
115  case_hit = FALSE;
116  max = 1;
117
118  puts(
119    "Run multiple times in attempt to hit event timeout synchronization point"
120  ); 
121  while (1) {
122
123    for (i=0 ; i<max ; i++ )
124      if ( _Event_Sync_state == THREAD_BLOCKING_OPERATION_SATISFIED )
125        break;
126
127    status = rtems_event_receive( 0x01, RTEMS_DEFAULT_OPTIONS, 1, &out );
128    fatal_directive_status( status, RTEMS_TIMEOUT, "event_receive timeout" );
129
130    if ( ++max > 10240 )
131      max = 0;
132
133    /* with our clock tick, this is about 30 seconds */
134    if ( ++iterations >= 4 * 1000 * 30)
135      break;
136
137  }
138
139  puts( "*** END OF TEST 39 ***" );
140  rtems_test_exit( 0 );
141}
Note: See TracBrowser for help on using the repository browser.