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