]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/event_groups.c
Add xEventGroupClearBitsFromISR() and xEventGroupGetBitsFromISR() functions.
[freertos] / FreeRTOS / Source / event_groups.c
1 /*\r
2     FreeRTOS V7.6.0 - Copyright (C) 2013 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS provides completely free yet professionally developed,    *\r
10      *    robust, strictly quality controlled, supported, and cross          *\r
11      *    platform software that has become a de facto standard.             *\r
12      *                                                                       *\r
13      *    Help yourself get started quickly and support the FreeRTOS         *\r
14      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
15      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
16      *                                                                       *\r
17      *    Thank you!                                                         *\r
18      *                                                                       *\r
19     ***************************************************************************\r
20 \r
21     This file is part of the FreeRTOS distribution.\r
22 \r
23     FreeRTOS is free software; you can redistribute it and/or modify it under\r
24     the terms of the GNU General Public License (version 2) as published by the\r
25     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
26 \r
27     >>! NOTE: The modification to the GPL is included to allow you to distribute\r
28     >>! a combined work that includes FreeRTOS without being obliged to provide\r
29     >>! the source code for proprietary components outside of the FreeRTOS\r
30     >>! kernel.\r
31 \r
32     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
33     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
34     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
35     link: http://www.freertos.org/a00114.html\r
36 \r
37     1 tab == 4 spaces!\r
38 \r
39     ***************************************************************************\r
40      *                                                                       *\r
41      *    Having a problem?  Start by reading the FAQ "My application does   *\r
42      *    not run, what could be wrong?"                                     *\r
43      *                                                                       *\r
44      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
49     license and Real Time Engineers Ltd. contact details.\r
50 \r
51     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
52     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
53     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
54 \r
55     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
56     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
57     licenses offer ticketed support, indemnification and middleware.\r
58 \r
59     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
60     engineered and independently SIL3 certified version for use in safety and\r
61     mission critical applications that require provable dependability.\r
62 \r
63     1 tab == 4 spaces!\r
64 */\r
65 \r
66 /* Standard includes. */\r
67 #include <stdlib.h>\r
68 \r
69 /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining\r
70 all the API functions to use the MPU wrappers.  That should only be done when\r
71 task.h is included from an application file. */\r
72 #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE\r
73 \r
74 /* FreeRTOS includes. */\r
75 #include "FreeRTOS.h"\r
76 #include "task.h"\r
77 #include "timers.h"\r
78 #include "event_groups.h"\r
79 \r
80 /* Lint e961 and e750 are suppressed as a MISRA exception justified because the\r
81 MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined for the\r
82 header files above, but not in this file, in order to generate the correct\r
83 privileged Vs unprivileged linkage and placement. */\r
84 #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750. */\r
85 \r
86 #if ( INCLUDE_xEventGroupSetBitFromISR == 1 ) && ( configUSE_TIMERS == 0 )\r
87         #error configUSE_TIMERS must be set to 1 to make the xEventGroupSetBitFromISR() function available.\r
88 #endif\r
89 \r
90 #if ( INCLUDE_xEventGroupSetBitFromISR == 1 ) && ( INCLUDE_xTimerPendFunctionCallFromISR == 0 )\r
91         #error INCLUDE_xTimerPendFunctionCallFromISR must also be set to one to make the xEventGroupSetBitFromISR() function available.\r
92 #endif\r
93 \r
94 /* The following bit fields convey control information in a task's event list\r
95 item value.  It is important they don't clash with the\r
96 taskEVENT_LIST_ITEM_VALUE_IN_USE definition. */\r
97 #if configUSE_16_BIT_TICKS == 1\r
98         #define eventCLEAR_EVENTS_ON_EXIT_BIT   0x0100U\r
99         #define eventUNBLOCKED_DUE_TO_BIT_SET   0x0200U\r
100         #define eventWAIT_FOR_ALL_BITS                  0x0400U\r
101         #define eventEVENT_BITS_CONTROL_BYTES   0xff00U\r
102 #else\r
103         #define eventCLEAR_EVENTS_ON_EXIT_BIT   0x01000000UL\r
104         #define eventUNBLOCKED_DUE_TO_BIT_SET   0x02000000UL\r
105         #define eventWAIT_FOR_ALL_BITS                  0x04000000UL\r
106         #define eventEVENT_BITS_CONTROL_BYTES   0xff000000UL\r
107 #endif\r
108 \r
109 typedef struct EVENT_GROUP_DEFINITION\r
110 {\r
111         EventBits_t uxEventBits;\r
112         List_t xTasksWaitingForBits;            /*< List of tasks waiting for a bit to be set. */\r
113 } EventGroup_t;\r
114 \r
115 /*-----------------------------------------------------------*/\r
116 \r
117 /*\r
118  * Test the bits set in uxCurrentEventBits to see if the wait condition is met.\r
119  * The wait condition is defined by xWaitForAllBits.  If xWaitForAllBits is\r
120  * pdTRUE then the wait condition is met if all the bits set in uxBitsToWaitFor\r
121  * are also set in uxCurrentEventBits.  If xWaitForAllBits is pdFALSE then the\r
122  * wait condition is met if any of the bits set in uxBitsToWait for are also set\r
123  * in uxCurrentEventBits.\r
124  */\r
125 static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits, const EventBits_t uxBitsToWaitFor, const BaseType_t xWaitForAllBits );\r
126 \r
127 /*-----------------------------------------------------------*/\r
128 \r
129 EventGroupHandle_t xEventGroupCreate( void )\r
130 {\r
131 EventGroup_t *pxEventBits;\r
132 \r
133         pxEventBits = pvPortMalloc( sizeof( EventGroup_t ) );\r
134         if( pxEventBits != NULL )\r
135         {\r
136                 pxEventBits->uxEventBits = 0;\r
137                 vListInitialise( &( pxEventBits->xTasksWaitingForBits ) );\r
138                 traceEVENT_GROUP_CREATE( pxEventBits );\r
139         }\r
140         else\r
141         {\r
142                 traceEVENT_GROUP_CREATE_FAILED();\r
143         }\r
144 \r
145         return ( EventGroupHandle_t ) pxEventBits;\r
146 }\r
147 /*-----------------------------------------------------------*/\r
148 \r
149 EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, const EventBits_t uxBitsToWaitFor, TickType_t xTicksToWait )\r
150 {\r
151 EventBits_t uxOriginalBitValue, uxReturn;\r
152 EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup;\r
153 BaseType_t xAlreadyYielded;\r
154 \r
155         configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 );\r
156         configASSERT( uxBitsToWaitFor != 0 );\r
157         #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )\r
158         {\r
159                 configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );\r
160         }\r
161         #endif\r
162 \r
163         vTaskSuspendAll();\r
164         {\r
165                 traceEVENT_GROUP_SYNC_START( xEventGroup, uxBitsToSet );\r
166 \r
167                 uxOriginalBitValue = pxEventBits->uxEventBits;\r
168 \r
169                 ( void ) xEventGroupSetBits( xEventGroup, uxBitsToSet );\r
170 \r
171                 if( ( ( uxOriginalBitValue | uxBitsToSet ) & uxBitsToWaitFor ) == uxBitsToWaitFor )\r
172                 {\r
173                         /* All the rendezvous bits are now set - no need to block. */\r
174                         uxReturn = ( uxOriginalBitValue | uxBitsToSet );\r
175 \r
176                         /* Rendezvous always clear the bits.  They will have been cleared\r
177                         already unless this is the only task in the rendezvous. */\r
178                         pxEventBits->uxEventBits &= uxBitsToWaitFor;\r
179 \r
180                         xTicksToWait = 0;\r
181                 }\r
182                 else\r
183                 {\r
184                         if( xTicksToWait != ( TickType_t ) 0 )\r
185                         {\r
186                                 /* Store the bits that the calling task is waiting for in the\r
187                                 task's event list item so the kernel knows when a match is\r
188                                 found.  Then enter the blocked state. */\r
189                                 vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | eventCLEAR_EVENTS_ON_EXIT_BIT | eventWAIT_FOR_ALL_BITS ), xTicksToWait );\r
190 \r
191                                 /* This assignment is obsolete as uxReturn will get set after\r
192                                 the task unblocks, but some compilers mistakenly generate a\r
193                                 warning about uxReturn being returned without being set if the\r
194                                 assignment is omitted. */\r
195                                 uxReturn = 0;\r
196                         }\r
197                         else\r
198                         {\r
199                                 /* The rendezvous bits were not set, but no block time was\r
200                                 specified - just return the current event bit value. */\r
201                                 uxReturn = pxEventBits->uxEventBits;\r
202                         }\r
203                 }\r
204         }\r
205         xAlreadyYielded = xTaskResumeAll();\r
206 \r
207         if( xTicksToWait != ( TickType_t ) 0 )\r
208         {\r
209                 if( xAlreadyYielded == pdFALSE )\r
210                 {\r
211                         portYIELD_WITHIN_API();\r
212                 }\r
213                 else\r
214                 {\r
215                         mtCOVERAGE_TEST_MARKER();\r
216                 }\r
217 \r
218                 /* The task blocked to wait for its required bits to be set - at this\r
219                 point either the required bits were set or the block time expired.  If\r
220                 the required bits were set they will have been stored in the task's\r
221                 event list item, and they should now be retrieved then cleared. */\r
222                 uxReturn = uxTaskResetEventItemValue();\r
223 \r
224                 if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 )\r
225                 {\r
226                         /* The task timed out, just return the current event bit value. */\r
227                         taskENTER_CRITICAL();\r
228                         {\r
229                                 uxReturn = pxEventBits->uxEventBits;\r
230 \r
231                                 /* Although the task got here because it timed out before the\r
232                                 bits it was waiting for were set, it is possible that since it\r
233                                 unblocked another task has set the bits.  If this is the case\r
234                                 then it may be required to clear the bits before exiting. */\r
235                                 if( ( uxReturn & uxBitsToWaitFor ) == uxBitsToWaitFor )\r
236                                 {\r
237                                         pxEventBits->uxEventBits &= ~uxBitsToWaitFor;\r
238                                 }\r
239                                 else\r
240                                 {\r
241                                         mtCOVERAGE_TEST_MARKER();\r
242                                 }\r
243                         }\r
244                         taskEXIT_CRITICAL();\r
245                 }\r
246                 else\r
247                 {\r
248                         /* The task unblocked because the bits were set.  Clear the control\r
249                         bits before returning the value. */\r
250                         uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;\r
251                 }\r
252         }\r
253 \r
254         traceEVENT_GROUP_SYNC_END( xEventGroup, uxReturn );\r
255         return uxReturn;\r
256 }\r
257 /*-----------------------------------------------------------*/\r
258 \r
259 EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToWaitFor, const BaseType_t xClearOnExit, const BaseType_t xWaitForAllBits, TickType_t xTicksToWait )\r
260 {\r
261 EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup;\r
262 EventBits_t uxReturn, uxControlBits = 0;\r
263 BaseType_t xWaitConditionMet, xAlreadyYielded;\r
264 \r
265         /* Check the user is not attempting to wait on the bits used by the kernel\r
266         itself, and that at least one bit is being requested. */\r
267         configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 );\r
268         configASSERT( uxBitsToWaitFor != 0 );\r
269         #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )\r
270         {\r
271                 configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );\r
272         }\r
273         #endif\r
274 \r
275         vTaskSuspendAll();\r
276         {\r
277                 const EventBits_t uxCurrentEventBits = pxEventBits->uxEventBits;\r
278 \r
279                 traceEVENT_GROUP_WAIT_BITS_START( xEventGroup, uxBitsToWaitFor );\r
280 \r
281                 /* Check to see if the wait condition is already met or not. */\r
282                 xWaitConditionMet = prvTestWaitCondition( uxCurrentEventBits, uxBitsToWaitFor, xWaitForAllBits );\r
283 \r
284                 if( xWaitConditionMet != pdFALSE )\r
285                 {\r
286                         /* The wait condition has already been met so there is no need to\r
287                         block. */\r
288                         uxReturn = uxCurrentEventBits;\r
289                         xTicksToWait = ( TickType_t ) 0;\r
290 \r
291                         /* Clear the wait bits if requested to do so. */\r
292                         if( xClearOnExit != pdFALSE )\r
293                         {\r
294                                 pxEventBits->uxEventBits &= ~uxBitsToWaitFor;\r
295                         }\r
296                         else\r
297                         {\r
298                                 mtCOVERAGE_TEST_MARKER();\r
299                         }\r
300                 }\r
301                 else if( xTicksToWait == ( TickType_t ) 0 )\r
302                 {\r
303                         /* The wait condition has not been met, but no block time was\r
304                         specified, so just return the current value. */\r
305                         uxReturn = uxCurrentEventBits;\r
306                 }\r
307                 else\r
308                 {\r
309                         /* The task is going to block to wait for its required bits to be\r
310                         set.  uxControlBits are used to remember the specified behaviour of\r
311                         this call to xEventGroupWaitBits() - for use when the event bits\r
312                         unblock the task. */\r
313                         if( xClearOnExit != pdFALSE )\r
314                         {\r
315                                 uxControlBits |= eventCLEAR_EVENTS_ON_EXIT_BIT;\r
316                         }\r
317                         else\r
318                         {\r
319                                 mtCOVERAGE_TEST_MARKER();\r
320                         }\r
321 \r
322                         if( xWaitForAllBits != pdFALSE )\r
323                         {\r
324                                 uxControlBits |= eventWAIT_FOR_ALL_BITS;\r
325                         }\r
326                         else\r
327                         {\r
328                                 mtCOVERAGE_TEST_MARKER();\r
329                         }\r
330 \r
331                         /* Store the bits that the calling task is waiting for in the\r
332                         task's event list item so the kernel knows when a match is\r
333                         found.  Then enter the blocked state. */\r
334                         vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | uxControlBits ), xTicksToWait );\r
335 \r
336                         /* This is obsolete as it will get set after the task unblocks, but\r
337                         some compilers mistakenly generate a warning about the variable\r
338                         being returned without being set if it is not done. */\r
339                         uxReturn = 0;\r
340                 }\r
341         }\r
342         xAlreadyYielded = xTaskResumeAll();\r
343 \r
344         if( xTicksToWait != ( TickType_t ) 0 )\r
345         {\r
346                 if( xAlreadyYielded == pdFALSE )\r
347                 {\r
348                         portYIELD_WITHIN_API();\r
349                 }\r
350                 else\r
351                 {\r
352                         mtCOVERAGE_TEST_MARKER();\r
353                 }\r
354 \r
355                 /* The task blocked to wait for its required bits to be set - at this\r
356                 point either the required bits were set or the block time expired.  If\r
357                 the required bits were set they will have been stored in the task's\r
358                 event list item, and they should now be retrieved then cleared. */\r
359                 uxReturn = uxTaskResetEventItemValue();\r
360 \r
361                 if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 )\r
362                 {\r
363                         taskENTER_CRITICAL();\r
364                         {\r
365                                 /* The task timed out, just return the current event bit value. */\r
366                                 uxReturn = pxEventBits->uxEventBits;\r
367 \r
368                                 /* It is possible that the event bits were updated between this\r
369                                 task leaving the Blocked state and running again. */\r
370                                 if( prvTestWaitCondition( uxReturn, uxBitsToWaitFor, xWaitForAllBits ) != pdFALSE )\r
371                                 {\r
372                                         if( xClearOnExit != pdFALSE )\r
373                                         {\r
374                                                 pxEventBits->uxEventBits &= ~uxBitsToWaitFor;\r
375                                         }\r
376                                         else\r
377                                         {\r
378                                                 mtCOVERAGE_TEST_MARKER();\r
379                                         }\r
380                                 }\r
381                                 else\r
382                                 {\r
383                                         mtCOVERAGE_TEST_MARKER();\r
384                                 }\r
385                         }\r
386                         taskEXIT_CRITICAL();\r
387                 }\r
388                 else\r
389                 {\r
390                         /* The task unblocked because the bits were set.  Clear the control\r
391                         bits before returning the value. */\r
392                         uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;\r
393                 }\r
394         }\r
395 \r
396         traceEVENT_GROUP_WAIT_BITS_END( xEventGroup, uxReturn );\r
397         return uxReturn;\r
398 }\r
399 /*-----------------------------------------------------------*/\r
400 \r
401 EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear )\r
402 {\r
403 EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup;\r
404 EventBits_t uxReturn;\r
405 \r
406         /* Check the user is not attempting to clear the bits used by the kernel\r
407         itself. */\r
408         configASSERT( ( uxBitsToClear & eventEVENT_BITS_CONTROL_BYTES ) == 0 );\r
409 \r
410         taskENTER_CRITICAL();\r
411         {\r
412                 traceEVENT_GROUP_CLEAR_BITS( xEventGroup, uxBitsToClear );\r
413 \r
414                 /* The value returned is the event group value prior to the bits being\r
415                 cleared. */\r
416                 uxReturn = pxEventBits->uxEventBits;\r
417 \r
418                 /* Clear the bits. */\r
419                 pxEventBits->uxEventBits &= ~uxBitsToClear;\r
420         }\r
421         taskEXIT_CRITICAL();\r
422 \r
423         return uxReturn;\r
424 }\r
425 /*-----------------------------------------------------------*/\r
426 \r
427 EventBits_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear )\r
428 {\r
429 UBaseType_t uxSavedInterruptStatus;\r
430 EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup;\r
431 EventBits_t uxReturn;\r
432 \r
433         /* Check the user is not attempting to clear the bits used by the kernel\r
434         itself. */\r
435         configASSERT( ( uxBitsToClear & eventEVENT_BITS_CONTROL_BYTES ) == 0 );\r
436 \r
437         uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
438         {\r
439                 traceEVENT_GROUP_CLEAR_BITS_FROM_ISR( xEventGroup, uxBitsToClear );\r
440 \r
441                 /* The value returned is the event group value prior to the bits being\r
442                 cleared. */\r
443                 uxReturn = pxEventBits->uxEventBits;\r
444 \r
445                 /* Clear the bits. */\r
446                 pxEventBits->uxEventBits &= ~uxBitsToClear;\r
447         }\r
448         portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
449 \r
450         return uxReturn;\r
451 }\r
452 /*-----------------------------------------------------------*/\r
453 \r
454 EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet )\r
455 {\r
456 ListItem_t *pxListItem, *pxNext;\r
457 ListItem_t const *pxListEnd;\r
458 List_t *pxList;\r
459 EventBits_t uxBitsToClear = 0, uxBitsWaitedFor, uxControlBits;\r
460 EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup;\r
461 BaseType_t xMatchFound = pdFALSE;\r
462 \r
463         /* Check the user is not attempting to set the bits used by the kernel\r
464         itself. */\r
465         configASSERT( ( uxBitsToSet & eventEVENT_BITS_CONTROL_BYTES ) == 0 );\r
466 \r
467         pxList = &( pxEventBits->xTasksWaitingForBits );\r
468         pxListEnd = listGET_END_MARKER( pxList ); /*lint !e826 !e740 The mini list structure is used as the list end to save RAM.  This is checked and valid. */\r
469         vTaskSuspendAll();\r
470         {\r
471                 traceEVENT_GROUP_SET_BITS( xEventGroup, uxBitsToSet );\r
472 \r
473                 pxListItem = listGET_HEAD_ENTRY( pxList );\r
474 \r
475                 /* Set the bits. */\r
476                 pxEventBits->uxEventBits |= uxBitsToSet;\r
477 \r
478                 /* See if the new bit value should unblock any tasks. */\r
479                 while( pxListItem != pxListEnd )\r
480                 {\r
481                         pxNext = listGET_NEXT( pxListItem );\r
482                         uxBitsWaitedFor = listGET_LIST_ITEM_VALUE( pxListItem );\r
483                         xMatchFound = pdFALSE;\r
484 \r
485                         /* Split the bits waited for from the control bits. */\r
486                         uxControlBits = uxBitsWaitedFor & eventEVENT_BITS_CONTROL_BYTES;\r
487                         uxBitsWaitedFor &= ~eventEVENT_BITS_CONTROL_BYTES;\r
488 \r
489                         if( ( uxControlBits & eventWAIT_FOR_ALL_BITS ) == ( EventBits_t ) 0 )\r
490                         {\r
491                                 /* Just looking for single bit being set. */\r
492                                 if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) != ( EventBits_t ) 0 )\r
493                                 {\r
494                                         xMatchFound = pdTRUE;\r
495                                 }\r
496                                 else\r
497                                 {\r
498                                         mtCOVERAGE_TEST_MARKER();\r
499                                 }\r
500                         }\r
501                         else if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) == uxBitsWaitedFor )\r
502                         {\r
503                                 /* All bits are set. */\r
504                                 xMatchFound = pdTRUE;\r
505                         }\r
506                         else\r
507                         {\r
508                                 /* Need all bits to be set, but not all the bits were set. */\r
509                         }\r
510 \r
511                         if( xMatchFound != pdFALSE )\r
512                         {\r
513                                 /* The bits match.  Should the bits be cleared on exit? */\r
514                                 if( ( uxControlBits & eventCLEAR_EVENTS_ON_EXIT_BIT ) != ( EventBits_t ) 0 )\r
515                                 {\r
516                                         uxBitsToClear |= uxBitsWaitedFor;\r
517                                 }\r
518                                 else\r
519                                 {\r
520                                         mtCOVERAGE_TEST_MARKER();\r
521                                 }\r
522 \r
523                                 /* Store the actual event flag value in the task's event list\r
524                                 item before removing the task from the event list.  The\r
525                                 eventUNBLOCKED_DUE_TO_BIT_SET bit is set so the task knows\r
526                                 that is was unblocked due to its required bits matching, rather\r
527                                 than because it timed out. */\r
528                                 ( void ) xTaskRemoveFromUnorderedEventList( pxListItem, pxEventBits->uxEventBits | eventUNBLOCKED_DUE_TO_BIT_SET );\r
529                         }\r
530 \r
531                         /* Move onto the next list item.  Note pxListItem->pxNext is not\r
532                         used here as the list item may have been removed from the event list\r
533                         and inserted into the ready/pending reading list. */\r
534                         pxListItem = pxNext;\r
535                 }\r
536 \r
537                 /* Clear any bits that matched when the eventCLEAR_EVENTS_ON_EXIT_BIT\r
538                 bit was set in the control word. */\r
539                 pxEventBits->uxEventBits &= ~uxBitsToClear;\r
540         }\r
541         ( void ) xTaskResumeAll();\r
542 \r
543         return pxEventBits->uxEventBits;\r
544 }\r
545 /*-----------------------------------------------------------*/\r
546 \r
547 void vEventGroupDelete( EventGroupHandle_t xEventGroup )\r
548 {\r
549 EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup;\r
550 const List_t *pxTasksWaitingForBits = &( pxEventBits->xTasksWaitingForBits );\r
551 \r
552         vTaskSuspendAll();\r
553         {\r
554                 traceEVENT_GROUP_DELETE( xEventGroup );\r
555 \r
556                 while( listCURRENT_LIST_LENGTH( pxTasksWaitingForBits ) > ( UBaseType_t ) 0 )\r
557                 {\r
558                         /* Unblock the task, returning 0 as the event list is being deleted\r
559                         and     cannot therefore have any bits set. */\r
560                         configASSERT( pxTasksWaitingForBits->xListEnd.pxNext != ( ListItem_t * ) &( pxTasksWaitingForBits->xListEnd ) );\r
561                         ( void ) xTaskRemoveFromUnorderedEventList( pxTasksWaitingForBits->xListEnd.pxNext, ( TickType_t ) eventUNBLOCKED_DUE_TO_BIT_SET );\r
562                 }\r
563 \r
564                 vPortFree( pxEventBits );\r
565         }\r
566         ( void ) xTaskResumeAll();\r
567 }\r
568 /*-----------------------------------------------------------*/\r
569 \r
570 /* For internal use only - execute a 'set bits' command that was pended from\r
571 an interrupt. */\r
572 void vEventGroupSetBitsCallback( void *pvEventGroup, const uint32_t ulBitsToSet )\r
573 {\r
574         ( void ) xEventGroupSetBits( pvEventGroup, ( EventBits_t ) ulBitsToSet );\r
575 }\r
576 /*-----------------------------------------------------------*/\r
577 \r
578 static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits, const EventBits_t uxBitsToWaitFor, const BaseType_t xWaitForAllBits )\r
579 {\r
580 BaseType_t xWaitConditionMet = pdFALSE;\r
581 \r
582         if( xWaitForAllBits == pdFALSE )\r
583         {\r
584                 /* Task only has to wait for one bit within uxBitsToWaitFor to be\r
585                 set.  Is one already set? */\r
586                 if( ( uxCurrentEventBits & uxBitsToWaitFor ) != ( EventBits_t ) 0 )\r
587                 {\r
588                         xWaitConditionMet = pdTRUE;\r
589                 }\r
590                 else\r
591                 {\r
592                         mtCOVERAGE_TEST_MARKER();\r
593                 }\r
594         }\r
595         else\r
596         {\r
597                 /* Task has to wait for all the bits in uxBitsToWaitFor to be set.\r
598                 Are they set already? */\r
599                 if( ( uxCurrentEventBits & uxBitsToWaitFor ) == uxBitsToWaitFor )\r
600                 {\r
601                         xWaitConditionMet = pdTRUE;\r
602                 }\r
603                 else\r
604                 {\r
605                         mtCOVERAGE_TEST_MARKER();\r
606                 }\r
607         }\r
608 \r
609         return xWaitConditionMet;\r
610 }\r
611 \r
612 \r