1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** ThreadX Component */
17 /** */
18 /** Event Flags */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23 #define TX_SOURCE_CODE
24
25
26 /* Include necessary system files. */
27
28 #include "tx_api.h"
29 #include "tx_thread.h"
30 #include "tx_timer.h"
31 #include "tx_event_flags.h"
32
33
34 /**************************************************************************/
35 /* */
36 /* FUNCTION RELEASE */
37 /* */
38 /* _txe_event_flags_get PORTABLE C */
39 /* 6.1 */
40 /* AUTHOR */
41 /* */
42 /* William E. Lamie, Microsoft Corporation */
43 /* */
44 /* DESCRIPTION */
45 /* */
46 /* This function checks for errors in the event flags get function */
47 /* call. */
48 /* */
49 /* INPUT */
50 /* */
51 /* group_ptr Pointer to group control block */
52 /* requested_event_flags Event flags requested */
53 /* get_option Specifies and/or and clear options*/
54 /* actual_flags_ptr Pointer to place the actual flags */
55 /* the service retrieved */
56 /* wait_option Suspension option */
57 /* */
58 /* OUTPUT */
59 /* */
60 /* TX_GROUP_ERROR Invalid event flags group pointer */
61 /* TX_PTR_ERROR Invalid actual flags pointer */
62 /* TX_WAIT_ERROR Invalid wait option */
63 /* TX_OPTION_ERROR Invalid get option */
64 /* TX_CALLER_ERROR Invalid caller of this function */
65 /* status Actual completion status */
66 /* */
67 /* CALLS */
68 /* */
69 /* _tx_event_flags_get Actual event flags get function */
70 /* */
71 /* CALLED BY */
72 /* */
73 /* Application Code */
74 /* */
75 /* RELEASE HISTORY */
76 /* */
77 /* DATE NAME DESCRIPTION */
78 /* */
79 /* 05-19-2020 William E. Lamie Initial Version 6.0 */
80 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
81 /* resulting in version 6.1 */
82 /* */
83 /**************************************************************************/
_txe_event_flags_get(TX_EVENT_FLAGS_GROUP * group_ptr,ULONG requested_flags,UINT get_option,ULONG * actual_flags_ptr,ULONG wait_option)84 UINT _txe_event_flags_get(TX_EVENT_FLAGS_GROUP *group_ptr, ULONG requested_flags,
85 UINT get_option, ULONG *actual_flags_ptr, ULONG wait_option)
86 {
87
88 UINT status;
89
90 #ifndef TX_TIMER_PROCESS_IN_ISR
91 TX_THREAD *current_thread;
92 #endif
93
94
95 /* Default status to success. */
96 status = TX_SUCCESS;
97
98 /* Check for an invalid event flag group pointer. */
99 if (group_ptr == TX_NULL)
100 {
101
102 /* Event flags group pointer is invalid, return appropriate error code. */
103 status = TX_GROUP_ERROR;
104 }
105
106 /* Now check for invalid event group ID. */
107 else if (group_ptr -> tx_event_flags_group_id != TX_EVENT_FLAGS_ID)
108 {
109
110 /* Event flags group pointer is invalid, return appropriate error code. */
111 status = TX_GROUP_ERROR;
112 }
113
114 /* Check for an invalid destination for actual flags. */
115 else if (actual_flags_ptr == TX_NULL)
116 {
117
118 /* Null destination pointer, return appropriate error. */
119 status = TX_PTR_ERROR;
120 }
121 else
122 {
123
124 /* Check for a wait option error. Only threads are allowed any form of
125 suspension. */
126 if (wait_option != TX_NO_WAIT)
127 {
128
129 /* Is the call from an ISR or Initialization? */
130 if (TX_THREAD_GET_SYSTEM_STATE() != ((ULONG) 0))
131 {
132
133 /* A non-thread is trying to suspend, return appropriate error code. */
134 status = TX_WAIT_ERROR;
135 }
136 #ifndef TX_TIMER_PROCESS_IN_ISR
137 else
138 {
139
140 /* Pickup thread pointer. */
141 TX_THREAD_GET_CURRENT(current_thread)
142
143 /* Is the current thread the timer thread? */
144 if (current_thread == &_tx_timer_thread)
145 {
146
147 /* A non-thread is trying to suspend, return appropriate error code. */
148 status = TX_WAIT_ERROR;
149 }
150 }
151 #endif
152 }
153 }
154
155 /* Is everything still okay? */
156 if (status == TX_SUCCESS)
157 {
158
159 /* Check for invalid get option. */
160 if (get_option > TX_AND_CLEAR)
161 {
162
163 /* Invalid get events option, return appropriate error. */
164 status = TX_OPTION_ERROR;
165 }
166 }
167
168 /* Determine if everything is okay. */
169 if (status == TX_SUCCESS)
170 {
171
172 /* Call actual event flags get function. */
173 status = _tx_event_flags_get(group_ptr, requested_flags, get_option, actual_flags_ptr, wait_option);
174 }
175
176 /* Return completion status. */
177 return(status);
178 }
179
180