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