[fa98897] | 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 | |
---|
| 17 | volatile boolean case_hit; |
---|
| 18 | |
---|
| 19 | rtems_id main_task; |
---|
| 20 | rtems_id other_task; |
---|
| 21 | |
---|
| 22 | rtems_timer_service_routine test_event_from_isr( |
---|
| 23 | rtems_id timer, |
---|
| 24 | void *arg |
---|
| 25 | ) |
---|
| 26 | { |
---|
| 27 | rtems_status_code status; |
---|
| 28 | |
---|
[265d9b64] | 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 ); |
---|
[fa98897] | 41 | |
---|
| 42 | case_hit = TRUE; |
---|
[265d9b64] | 43 | } |
---|
| 44 | status = rtems_event_send( main_task, 0x01 ); |
---|
[fa98897] | 45 | } |
---|
| 46 | |
---|
| 47 | rtems_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; |
---|
[8b7a713] | 82 | iterations = 0; |
---|
[fa98897] | 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++ ) |
---|
[265d9b64] | 92 | if ( _Event_Sync_state == THREAD_BLOCKING_OPERATION_SATISFIED ) |
---|
[fa98897] | 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; |
---|
[8b7a713] | 100 | |
---|
| 101 | /* with our clock tick, this is about 30 seconds */ |
---|
| 102 | if ( ++iterations >= 4 * 1000 * 30) |
---|
| 103 | break; |
---|
[fa98897] | 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 | */ |
---|
[265d9b64] | 114 | iterations = 0; |
---|
[fa98897] | 115 | case_hit = FALSE; |
---|
| 116 | max = 1; |
---|
| 117 | |
---|
[265d9b64] | 118 | puts( |
---|
| 119 | "Run multiple times in attempt to hit event timeout synchronization point" |
---|
| 120 | ); |
---|
[fa98897] | 121 | while (1) { |
---|
| 122 | |
---|
| 123 | for (i=0 ; i<max ; i++ ) |
---|
[265d9b64] | 124 | if ( _Event_Sync_state == THREAD_BLOCKING_OPERATION_SATISFIED ) |
---|
[fa98897] | 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 | |
---|
[8b7a713] | 130 | if ( ++max > 10240 ) |
---|
[265d9b64] | 131 | max = 0; |
---|
| 132 | |
---|
[8b7a713] | 133 | /* with our clock tick, this is about 30 seconds */ |
---|
| 134 | if ( ++iterations >= 4 * 1000 * 30) |
---|
[265d9b64] | 135 | break; |
---|
[8b7a713] | 136 | |
---|
[265d9b64] | 137 | } |
---|
[fa98897] | 138 | |
---|
| 139 | puts( "*** END OF TEST 39 ***" ); |
---|
| 140 | rtems_test_exit( 0 ); |
---|
| 141 | } |
---|