1 /* This test is designed to test event flag suspension and resumption of two threads
2 waiting on different event flags. */
3
4 #include <stdio.h>
5 #include "tx_api.h"
6
7 static unsigned long thread_0_counter = 0;
8 static TX_THREAD thread_0;
9 static unsigned long thread_1_counter = 0;
10 static TX_THREAD thread_1;
11 static unsigned long thread_2_counter = 0;
12 static TX_THREAD thread_2;
13
14
15 static TX_EVENT_FLAGS_GROUP group_0;
16
17
18 /* Define thread prototypes. */
19
20 static void thread_0_entry(ULONG thread_input);
21 static void thread_1_entry(ULONG thread_input);
22 static void thread_2_entry(ULONG thread_input);
23
24
25 /* Prototype for test control return. */
26 void test_control_return(UINT status);
27
28
event_set_notify(TX_EVENT_FLAGS_GROUP * group)29 static void event_set_notify(TX_EVENT_FLAGS_GROUP *group)
30 {
31
32 /* Not necessary to do anything in this function. */
33 }
34
35
36 /* Define what the initial system looks like. */
37
38 #ifdef CTEST
test_application_define(void * first_unused_memory)39 void test_application_define(void *first_unused_memory)
40 #else
41 void threadx_event_flag_suspension_different_bits_application_define(void *first_unused_memory)
42 #endif
43 {
44
45 INT status;
46 CHAR *pointer;
47
48 /* Put first available memory address into a character pointer. */
49 pointer = (CHAR *) first_unused_memory;
50
51 /* Put system definition stuff in here, e.g. thread creates and other assorted
52 create information. */
53
54 status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
55 pointer, TEST_STACK_SIZE_PRINTF,
56 17, 17, 100, TX_AUTO_START);
57 pointer = pointer + TEST_STACK_SIZE_PRINTF;
58
59 /* Check status. */
60 if (status != TX_SUCCESS)
61 {
62
63 printf("Running Event Flag Suspension Unique Bit Test....................... ERROR #1\n");
64 test_control_return(1);
65 }
66
67 status = tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
68 pointer, TEST_STACK_SIZE_PRINTF,
69 16, 16, 100, TX_AUTO_START);
70 pointer = pointer + TEST_STACK_SIZE_PRINTF;
71
72 /* Check status. */
73 if (status != TX_SUCCESS)
74 {
75
76 printf("Running Event Flag Suspension Unique Bit Test....................... ERROR #2\n");
77 test_control_return(1);
78 }
79
80
81 status = tx_thread_create(&thread_2, "thread 2", thread_2_entry, 1,
82 pointer, TEST_STACK_SIZE_PRINTF,
83 16, 16, 100, TX_AUTO_START);
84 pointer = pointer + TEST_STACK_SIZE_PRINTF;
85
86 /* Check status. */
87 if (status != TX_SUCCESS)
88 {
89
90 printf("Running Event Flag Suspension Unique Bit Test....................... ERROR #3\n");
91 test_control_return(1);
92 }
93
94 /* Create event flag group 0. */
95 status = tx_event_flags_create(&group_0, "group 0");
96
97 /* Check status. */
98 if (status != TX_SUCCESS)
99 {
100
101 printf("Running Event Flag Suspension Unique Bit Test....................... ERROR #4\n");
102 test_control_return(1);
103 }
104
105 /* Register the event set notify function. */
106 status = tx_event_flags_set_notify(&group_0, event_set_notify);
107
108 #ifndef TX_DISABLE_NOTIFY_CALLBACKS
109
110 /* Check status. */
111 if (status != TX_SUCCESS)
112 {
113
114 printf("Running Event Flag Suspension Unique Bit Test....................... ERROR #5\n");
115 test_control_return(1);
116 }
117 #else
118
119 /* Check status. */
120 if (status != TX_FEATURE_NOT_ENABLED)
121 {
122
123 printf("Running Event Flag Suspension Unique Bit Test....................... ERROR #6\n");
124 test_control_return(1);
125 }
126
127 #endif
128
129 }
130
131
132
133 /* Define the test threads. */
134
thread_0_entry(ULONG thread_input)135 static void thread_0_entry(ULONG thread_input)
136 {
137
138 UINT status;
139
140
141 /* Inform user. */
142 printf("Running Event Flag Suspension Unique Bit Test....................... ");
143
144 /* Increment run counter. */
145 thread_0_counter++;
146
147 /* Set event flag. */
148 status = tx_event_flags_set(&group_0, 0x80000000, TX_OR);
149
150 /* Check status and run counters. */
151 if ((status != TX_SUCCESS) || (thread_1_counter != 2) ||
152 (thread_2_counter != 1))
153 {
154
155 /* Event flag error. */
156 printf("ERROR #7\n");
157 test_control_return(1);
158 }
159
160 /* Set event flag. */
161 status = tx_event_flags_set(&group_0, 0x00008000, TX_OR);
162
163 /* Check status. */
164 if ((status != TX_SUCCESS) || (thread_1_counter != 2) ||
165 (thread_2_counter != 2))
166 {
167
168 /* Event flag error. */
169 printf("ERROR #8\n");
170 test_control_return(1);
171 }
172
173 /* Successful test. */
174 printf("SUCCESS!\n");
175 test_control_return(0);
176 }
177
178
thread_1_entry(ULONG thread_input)179 static void thread_1_entry(ULONG thread_input)
180 {
181
182 UINT status;
183 ULONG actual_events;
184
185 /* Wait for event flags. */
186 while(1)
187 {
188
189 /* Increment run counter. */
190 thread_1_counter++;
191
192 /* Attempt to get events from event flag group. AND option. */
193 status = tx_event_flags_get(&group_0, 0x80000000, TX_AND, &actual_events, TX_WAIT_FOREVER);
194
195 /* Check status. */
196 if ((status != TX_SUCCESS) || (actual_events != 0x80000000UL))
197 return;
198
199 /* Clear the event flags. */
200 tx_event_flags_set(&group_0, 0x7FFFFFFF, TX_AND);
201 }
202 }
203
204
thread_2_entry(ULONG thread_input)205 static void thread_2_entry(ULONG thread_input)
206 {
207
208 UINT status;
209 //ULONG event_flag = 1;
210 ULONG actual_events;
211
212 /* Wait for event flags. */
213 while(1)
214 {
215
216 /* Increment run counter. */
217 thread_2_counter++;
218
219 /* Attempt to get events from event flag group. AND option. */
220 status = tx_event_flags_get(&group_0, 0x00008000, TX_AND, &actual_events, TX_WAIT_FOREVER);
221
222 /* Check status. */
223 if ((status != TX_SUCCESS) || (actual_events != 0x00008000UL))
224 return;
225
226 /* Clear the event flags. */
227 tx_event_flags_set(&group_0, 0xFFFF7FFF, TX_AND);
228 }
229 }
230
231