[4c90eb4] | 1 | /** |
---|
| 2 | * @file |
---|
[cc2bc302] | 3 | * |
---|
[4c90eb4] | 4 | * @brief Event Manager Initialization |
---|
| 5 | * @ingroup ClassicEvent Events |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | /* |
---|
[3168deaa] | 9 | * COPYRIGHT (c) 1989-2008. |
---|
[cc2bc302] | 10 | * On-Line Applications Research Corporation (OAR). |
---|
| 11 | * |
---|
| 12 | * The license and distribution terms for this file may be |
---|
| 13 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 14 | * http://www.rtems.org/license/LICENSE. |
---|
[cc2bc302] | 15 | */ |
---|
| 16 | |
---|
[1095ec1] | 17 | #if HAVE_CONFIG_H |
---|
[990575c] | 18 | #include "config.h" |
---|
[1095ec1] | 19 | #endif |
---|
| 20 | |
---|
[ae85b066] | 21 | #include <rtems/sysinit.h> |
---|
[e151eb1] | 22 | #include <rtems/rtems/eventimpl.h> |
---|
[caab339] | 23 | #include <rtems/rtems/optionsimpl.h> |
---|
[dce48791] | 24 | #include <rtems/rtems/statusimpl.h> |
---|
[5618c37a] | 25 | #include <rtems/score/threadimpl.h> |
---|
[4b48ece0] | 26 | #include <rtems/score/watchdogimpl.h> |
---|
[cc2bc302] | 27 | |
---|
[dce48791] | 28 | rtems_status_code _Event_Seize( |
---|
[7d6e94b] | 29 | rtems_event_set event_in, |
---|
| 30 | rtems_option option_set, |
---|
| 31 | rtems_interval ticks, |
---|
| 32 | rtems_event_set *event_out, |
---|
| 33 | Thread_Control *executing, |
---|
| 34 | Event_Control *event, |
---|
| 35 | Thread_Wait_flags wait_class, |
---|
| 36 | States_Control block_state, |
---|
| 37 | ISR_lock_Context *lock_context |
---|
[cc2bc302] | 38 | ) |
---|
| 39 | { |
---|
[7d6e94b] | 40 | rtems_event_set seized_events; |
---|
| 41 | rtems_event_set pending_events; |
---|
| 42 | bool success; |
---|
| 43 | Thread_Wait_flags intend_to_block; |
---|
| 44 | Per_CPU_Control *cpu_self; |
---|
[cc2bc302] | 45 | |
---|
[990575c] | 46 | pending_events = event->pending_events; |
---|
[cc2bc302] | 47 | seized_events = _Event_sets_Get( pending_events, event_in ); |
---|
| 48 | |
---|
| 49 | if ( !_Event_sets_Is_empty( seized_events ) && |
---|
| 50 | (seized_events == event_in || _Options_Is_any( option_set )) ) { |
---|
[990575c] | 51 | event->pending_events = |
---|
[cc2bc302] | 52 | _Event_sets_Clear( pending_events, seized_events ); |
---|
[1fcac5ad] | 53 | _Thread_Wait_release_default( executing, lock_context ); |
---|
[cc2bc302] | 54 | *event_out = seized_events; |
---|
[dce48791] | 55 | return RTEMS_SUCCESSFUL; |
---|
[cc2bc302] | 56 | } |
---|
| 57 | |
---|
| 58 | if ( _Options_Is_no_wait( option_set ) ) { |
---|
[1fcac5ad] | 59 | _Thread_Wait_release_default( executing, lock_context ); |
---|
[cc2bc302] | 60 | *event_out = seized_events; |
---|
[dce48791] | 61 | return RTEMS_UNSATISFIED; |
---|
[cc2bc302] | 62 | } |
---|
| 63 | |
---|
[7d6e94b] | 64 | intend_to_block = wait_class | THREAD_WAIT_STATE_INTEND_TO_BLOCK; |
---|
| 65 | |
---|
[4b45c13] | 66 | /* |
---|
| 67 | * Note what we are waiting for BEFORE we enter the critical section. |
---|
| 68 | * The interrupt critical section management code needs this to be |
---|
| 69 | * set properly when we are marked as in the event critical section. |
---|
| 70 | * |
---|
| 71 | * NOTE: Since interrupts are disabled, this isn't that much of an |
---|
| 72 | * issue but better safe than sorry. |
---|
| 73 | */ |
---|
[dce48791] | 74 | executing->Wait.return_code = STATUS_SUCCESSFUL; |
---|
[7d6e94b] | 75 | executing->Wait.option = option_set; |
---|
| 76 | executing->Wait.count = event_in; |
---|
| 77 | executing->Wait.return_argument = event_out; |
---|
| 78 | _Thread_Wait_flags_set( executing, intend_to_block ); |
---|
[4b45c13] | 79 | |
---|
[d5423295] | 80 | cpu_self = _Thread_Dispatch_disable_critical( lock_context ); |
---|
[1fcac5ad] | 81 | _Thread_Wait_release_default( executing, lock_context ); |
---|
[cc2bc302] | 82 | |
---|
| 83 | if ( ticks ) { |
---|
[02878626] | 84 | _Thread_Add_timeout_ticks( executing, cpu_self, ticks ); |
---|
[cc2bc302] | 85 | } |
---|
| 86 | |
---|
[7d6e94b] | 87 | _Thread_Set_state( executing, block_state ); |
---|
[cc2bc302] | 88 | |
---|
[02987728] | 89 | success = _Thread_Wait_flags_try_change_acquire( |
---|
[7d6e94b] | 90 | executing, |
---|
| 91 | intend_to_block, |
---|
| 92 | wait_class | THREAD_WAIT_STATE_BLOCKED |
---|
| 93 | ); |
---|
| 94 | if ( !success ) { |
---|
[03b900d] | 95 | _Thread_Timer_remove( executing ); |
---|
[7d6e94b] | 96 | _Thread_Unblock( executing ); |
---|
[cc2bc302] | 97 | } |
---|
[3168deaa] | 98 | |
---|
[ed24ed4e] | 99 | _Thread_Dispatch_direct( cpu_self ); |
---|
[dce48791] | 100 | return _Status_Get_after_wait( executing ); |
---|
[cc2bc302] | 101 | } |
---|
[ae85b066] | 102 | |
---|
| 103 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 104 | static void _Event_Manager_initialization( void ) |
---|
| 105 | { |
---|
| 106 | _MPCI_Register_packet_processor( MP_PACKET_EVENT, _Event_MP_Process_packet ); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | RTEMS_SYSINIT_ITEM( |
---|
| 110 | _Event_Manager_initialization, |
---|
| 111 | RTEMS_SYSINIT_CLASSIC_EVENT, |
---|
| 112 | RTEMS_SYSINIT_ORDER_MIDDLE |
---|
| 113 | ); |
---|
| 114 | #endif |
---|