1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup ClassicEventSystem |
---|
5 | * |
---|
6 | * @brief rtems_event_system_receive() implementation. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2012 embedded brains GmbH. All rights reserved. |
---|
11 | * |
---|
12 | * embedded brains GmbH |
---|
13 | * Obere Lagerstr. 30 |
---|
14 | * 82178 Puchheim |
---|
15 | * Germany |
---|
16 | * <rtems@embedded-brains.de> |
---|
17 | * |
---|
18 | * The license and distribution terms for this file may be |
---|
19 | * found in the file LICENSE in this distribution or at |
---|
20 | * http://www.rtems.org/license/LICENSE. |
---|
21 | */ |
---|
22 | |
---|
23 | #if HAVE_CONFIG_H |
---|
24 | #include "config.h" |
---|
25 | #endif |
---|
26 | |
---|
27 | #include <rtems/rtems/eventimpl.h> |
---|
28 | #include <rtems/rtems/tasks.h> |
---|
29 | #include <rtems/score/statesimpl.h> |
---|
30 | #include <rtems/score/threadimpl.h> |
---|
31 | |
---|
32 | rtems_status_code rtems_event_system_receive( |
---|
33 | rtems_event_set event_in, |
---|
34 | rtems_option option_set, |
---|
35 | rtems_interval ticks, |
---|
36 | rtems_event_set *event_out |
---|
37 | ) |
---|
38 | { |
---|
39 | rtems_status_code sc; |
---|
40 | |
---|
41 | if ( event_out != NULL ) { |
---|
42 | ISR_lock_Context lock_context; |
---|
43 | Thread_Control *executing; |
---|
44 | RTEMS_API_Control *api; |
---|
45 | Event_Control *event; |
---|
46 | |
---|
47 | executing = _Thread_Lock_acquire_default_for_executing( &lock_context ); |
---|
48 | api = executing->API_Extensions[ THREAD_API_RTEMS ]; |
---|
49 | event = &api->System_event; |
---|
50 | |
---|
51 | if ( !_Event_sets_Is_empty( event_in ) ) { |
---|
52 | sc = _Event_Seize( |
---|
53 | event_in, |
---|
54 | option_set, |
---|
55 | ticks, |
---|
56 | event_out, |
---|
57 | executing, |
---|
58 | event, |
---|
59 | THREAD_WAIT_CLASS_SYSTEM_EVENT, |
---|
60 | STATES_WAITING_FOR_SYSTEM_EVENT, |
---|
61 | &lock_context |
---|
62 | ); |
---|
63 | } else { |
---|
64 | *event_out = event->pending_events; |
---|
65 | _Thread_Lock_release_default( executing, &lock_context ); |
---|
66 | sc = RTEMS_SUCCESSFUL; |
---|
67 | } |
---|
68 | } else { |
---|
69 | sc = RTEMS_INVALID_ADDRESS; |
---|
70 | } |
---|
71 | |
---|
72 | return sc; |
---|
73 | } |
---|