]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/event_groups.c
Update version number to 8.1.2 after moving the defaulting of configUSE_PORT_OPTIMISE...
[freertos] / FreeRTOS / Source / event_groups.c
1 /*\r
2     FreeRTOS V8.1.2 - Copyright (C) 2014 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     !<<\r
28     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
29     >>!   obliged to provide the source code for proprietary components     !<<\r
30     >>!   outside of the FreeRTOS 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_xTimerPendFunctionCall == 0 )\r
91         #error INCLUDE_xTimerPendFunctionCall 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 xEventGroupDefinition\r
110 {\r
111         EventBits_t uxEventBits;\r
112         List_t xTasksWaitingForBits;            /*< List of tasks waiting for a bit to be set. */\r
113 \r
114         #if( configUSE_TRACE_FACILITY == 1 )\r
115                 UBaseType_t uxEventGroupNumber;\r
116         #endif\r
117 \r
118 } EventGroup_t;\r
119 \r
120 /*-----------------------------------------------------------*/\r
121 \r
122 /*\r
123  * Test the bits set in uxCurrentEventBits to see if the wait condition is met.\r
124  * The wait condition is defined by xWaitForAllBits.  If xWaitForAllBits is\r
125  * pdTRUE then the wait condition is met if all the bits set in uxBitsToWaitFor\r
126  * are also set in uxCurrentEventBits.  If xWaitForAllBits is pdFALSE then the\r
127  * wait condition is met if any of the bits set in uxBitsToWait for are also set\r
128  * in uxCurrentEventBits.\r
129  */\r
130 static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits, const EventBits_t uxBitsToWaitFor, const BaseType_t xWaitForAllBits );\r
131 \r
132 /*-----------------------------------------------------------*/\r
133 \r
134 EventGroupHandle_t xEventGroupCreate( void )\r
135 {\r
136 EventGroup_t *pxEventBits;\r
137 \r
138         pxEventBits = pvPortMalloc( sizeof( EventGroup_t ) );\r
139         if( pxEventBits != NULL )\r
140         {\r
141                 pxEventBits->uxEventBits = 0;\r
142                 vListInitialise( &( pxEventBits->xTasksWaitingForBits ) );\r
143                 traceEVENT_GROUP_CREATE( pxEventBits );\r
144         }\r
145         else\r
146         {\r
147                 traceEVENT_GROUP_CREATE_FAILED();\r
148         }\r
149 \r
150         return ( EventGroupHandle_t ) pxEventBits;\r
151 }\r
152 /*-----------------------------------------------------------*/\r
153 \r
154 EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, const EventBits_t uxBitsToWaitFor, TickType_t xTicksToWait )\r
155 {\r
156 EventBits_t uxOriginalBitValue, uxReturn;\r
157 EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup;\r
158 BaseType_t xAlreadyYielded;\r
159 BaseType_t xTimeoutOccurred = pdFALSE;\r
160 \r
161         configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 );\r
162         configASSERT( uxBitsToWaitFor != 0 );\r
163         #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )\r
164         {\r
165                 configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );\r
166         }\r
167         #endif\r
168 \r
169         vTaskSuspendAll();\r
170         {\r
171                 uxOriginalBitValue = pxEventBits->uxEventBits;\r
172 \r
173                 ( void ) xEventGroupSetBits( xEventGroup, uxBitsToSet );\r
174 \r
175                 if( ( ( uxOriginalBitValue | uxBitsToSet ) & uxBitsToWaitFor ) == uxBitsToWaitFor )\r
176                 {\r
177                         /* All the rendezvous bits are now set - no need to block. */\r
178                         uxReturn = ( uxOriginalBitValue | uxBitsToSet );\r
179 \r
180                         /* Rendezvous always clear the bits.  They will have been cleared\r
181                         already unless this is the only task in the rendezvous. */\r
182                         pxEventBits->uxEventBits &= ~uxBitsToWaitFor;\r
183 \r
184                         xTicksToWait = 0;\r
185                 }\r
186                 else\r
187                 {\r
188                         if( xTicksToWait != ( TickType_t ) 0 )\r
189                         {\r
190                                 traceEVENT_GROUP_SYNC_BLOCK( xEventGroup, uxBitsToSet, uxBitsToWaitFor );\r
191 \r
192                                 /* Store the bits that the calling task is waiting for in the\r
193                                 task's event list item so the kernel knows when a match is\r
194                                 found.  Then enter the blocked state. */\r
195                                 vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | eventCLEAR_EVENTS_ON_EXIT_BIT | eventWAIT_FOR_ALL_BITS ), xTicksToWait );\r
196 \r
197                                 /* This assignment is obsolete as uxReturn will get set after\r
198                                 the task unblocks, but some compilers mistakenly generate a\r
199                                 warning about uxReturn being returned without being set if the\r
200                                 assignment is omitted. */\r
201                                 uxReturn = 0;\r
202                         }\r
203                         else\r
204                         {\r
205                                 /* The rendezvous bits were not set, but no block time was\r
206                                 specified - just return the current event bit value. */\r
207                                 uxReturn = pxEventBits->uxEventBits;\r
208                         }\r
209                 }\r
210         }\r
211         xAlreadyYielded = xTaskResumeAll();\r
212 \r
213         if( xTicksToWait != ( TickType_t ) 0 )\r
214         {\r
215                 if( xAlreadyYielded == pdFALSE )\r
216                 {\r
217                         portYIELD_WITHIN_API();\r
218                 }\r
219                 else\r
220                 {\r
221                         mtCOVERAGE_TEST_MARKER();\r
222                 }\r
223 \r
224                 /* The task blocked to wait for its required bits to be set - at this\r
225                 point either the required bits were set or the block time expired.  If\r
226                 the required bits were set they will have been stored in the task's\r
227                 event list item, and they should now be retrieved then cleared. */\r
228                 uxReturn = uxTaskResetEventItemValue();\r
229 \r
230                 if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 )\r
231                 {\r
232                         /* The task timed out, just return the current event bit value. */\r
233                         taskENTER_CRITICAL();\r
234                         {\r
235                                 uxReturn = pxEventBits->uxEventBits;\r
236 \r
237                                 /* Although the task got here because it timed out before the\r
238                                 bits it was waiting for were set, it is possible that since it\r
239                                 unblocked another task has set the bits.  If this is the case\r
240                                 then it needs to clear the bits before exiting. */\r
241                                 if( ( uxReturn & uxBitsToWaitFor ) == uxBitsToWaitFor )\r
242                                 {\r
243                                         pxEventBits->uxEventBits &= ~uxBitsToWaitFor;\r
244                                 }\r
245                                 else\r
246                                 {\r
247                                         mtCOVERAGE_TEST_MARKER();\r
248                                 }\r
249                         }\r
250                         taskEXIT_CRITICAL();\r
251 \r
252                         xTimeoutOccurred = pdTRUE;\r
253                 }\r
254                 else\r
255                 {\r
256                         /* The task unblocked because the bits were set. */\r
257                 }\r
258 \r
259                 /* Control bits might be set as the task had blocked should not be\r
260                 returned. */\r
261                 uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;\r
262         }\r
263 \r
264         traceEVENT_GROUP_SYNC_END( xEventGroup, uxBitsToSet, uxBitsToWaitFor, xTimeoutOccurred );\r
265 \r
266         return uxReturn;\r
267 }\r
268 /*-----------------------------------------------------------*/\r
269 \r
270 EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToWaitFor, const BaseType_t xClearOnExit, const BaseType_t xWaitForAllBits, TickType_t xTicksToWait )\r
271 {\r
272 EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup;\r
273 EventBits_t uxReturn, uxControlBits = 0;\r
274 BaseType_t xWaitConditionMet, xAlreadyYielded;\r
275 BaseType_t xTimeoutOccurred = pdFALSE;\r
276 \r
277         /* Check the user is not attempting to wait on the bits used by the kernel\r
278         itself, and that at least one bit is being requested. */\r
279         configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 );\r
280         configASSERT( uxBitsToWaitFor != 0 );\r
281         #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )\r
282         {\r
283                 configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );\r
284         }\r
285         #endif\r
286 \r
287         vTaskSuspendAll();\r
288         {\r
289                 const EventBits_t uxCurrentEventBits = pxEventBits->uxEventBits;\r
290 \r
291                 /* Check to see if the wait condition is already met or not. */\r
292                 xWaitConditionMet = prvTestWaitCondition( uxCurrentEventBits, uxBitsToWaitFor, xWaitForAllBits );\r
293 \r
294                 if( xWaitConditionMet != pdFALSE )\r
295                 {\r
296                         /* The wait condition has already been met so there is no need to\r
297                         block. */\r
298                         uxReturn = uxCurrentEventBits;\r
299                         xTicksToWait = ( TickType_t ) 0;\r
300 \r
301                         /* Clear the wait bits if requested to do so. */\r
302                         if( xClearOnExit != pdFALSE )\r
303                         {\r
304                                 pxEventBits->uxEventBits &= ~uxBitsToWaitFor;\r
305                         }\r
306                         else\r
307                         {\r
308                                 mtCOVERAGE_TEST_MARKER();\r
309                         }\r
310                 }\r
311                 else if( xTicksToWait == ( TickType_t ) 0 )\r
312                 {\r
313                         /* The wait condition has not been met, but no block time was\r
314                         specified, so just return the current value. */\r
315                         uxReturn = uxCurrentEventBits;\r
316                 }\r
317                 else\r
318                 {\r
319                         /* The task is going to block to wait for its required bits to be\r
320                         set.  uxControlBits are used to remember the specified behaviour of\r
321                         this call to xEventGroupWaitBits() - for use when the event bits\r
322                         unblock the task. */\r
323                         if( xClearOnExit != pdFALSE )\r
324                         {\r
325                                 uxControlBits |= eventCLEAR_EVENTS_ON_EXIT_BIT;\r
326                         }\r
327                         else\r
328                         {\r
329                                 mtCOVERAGE_TEST_MARKER();\r
330                         }\r
331 \r
332                         if( xWaitForAllBits != pdFALSE )\r
333                         {\r
334                                 uxControlBits |= eventWAIT_FOR_ALL_BITS;\r
335                         }\r
336                         else\r
337                         {\r
338                                 mtCOVERAGE_TEST_MARKER();\r
339                         }\r
340 \r
341                         /* Store the bits that the calling task is waiting for in the\r
342                         task's event list item so the kernel knows when a match is\r
343                         found.  Then enter the blocked state. */\r
344                         vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | uxControlBits ), xTicksToWait );\r
345 \r
346                         /* This is obsolete as it will get set after the task unblocks, but\r
347                         some compilers mistakenly generate a warning about the variable\r
348                         being returned without being set if it is not done. */\r
349                         uxReturn = 0;\r
350 \r
351                         traceEVENT_GROUP_WAIT_BITS_BLOCK( xEventGroup, uxBitsToWaitFor );\r
352                 }\r
353         }\r
354         xAlreadyYielded = xTaskResumeAll();\r
355 \r
356         if( xTicksToWait != ( TickType_t ) 0 )\r
357         {\r
358                 if( xAlreadyYielded == pdFALSE )\r
359                 {\r
360                         portYIELD_WITHIN_API();\r
361                 }\r
362                 else\r
363                 {\r
364                         mtCOVERAGE_TEST_MARKER();\r
365                 }\r
366 \r
367                 /* The task blocked to wait for its required bits to be set - at this\r
368                 point either the required bits were set or the block time expired.  If\r
369                 the required bits were set they will have been stored in the task's\r
370                 event list item, and they should now be retrieved then cleared. */\r
371                 uxReturn = uxTaskResetEventItemValue();\r
372 \r
373                 if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 )\r
374                 {\r
375                         taskENTER_CRITICAL();\r
376                         {\r
377                                 /* The task timed out, just return the current event bit value. */\r
378                                 uxReturn = pxEventBits->uxEventBits;\r
379 \r
380                                 /* It is possible that the event bits were updated between this\r
381                                 task leaving the Blocked state and running again. */\r
382                                 if( prvTestWaitCondition( uxReturn, uxBitsToWaitFor, xWaitForAllBits ) != pdFALSE )\r
383                                 {\r
384                                         if( xClearOnExit != pdFALSE )\r
385                                         {\r
386                                                 pxEventBits->uxEventBits &= ~uxBitsToWaitFor;\r
387                                         }\r
388                                         else\r
389                                         {\r
390                                                 mtCOVERAGE_TEST_MARKER();\r
391                                         }\r
392                                 }\r
393                                 else\r
394                                 {\r
395                                         mtCOVERAGE_TEST_MARKER();\r
396                                 }\r
397                         }\r
398                         taskEXIT_CRITICAL();\r
399 \r
400                         /* Prevent compiler warnings when trace macros are not used. */\r
401                         xTimeoutOccurred = pdFALSE;\r
402                 }\r
403                 else\r
404                 {\r
405                         /* The task unblocked because the bits were set. */\r
406                 }\r
407 \r
408                 /* The task blocked so control bits may have been set. */\r
409                 uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;\r
410         }\r
411         traceEVENT_GROUP_WAIT_BITS_END( xEventGroup, uxBitsToWaitFor, xTimeoutOccurred );\r
412 \r
413         return uxReturn;\r
414 }\r
415 /*-----------------------------------------------------------*/\r
416 \r
417 EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear )\r
418 {\r
419 EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup;\r
420 EventBits_t uxReturn;\r
421 \r
422         /* Check the user is not attempting to clear the bits used by the kernel\r
423         itself. */\r
424         configASSERT( ( uxBitsToClear & eventEVENT_BITS_CONTROL_BYTES ) == 0 );\r
425 \r
426         taskENTER_CRITICAL();\r
427         {\r
428                 traceEVENT_GROUP_CLEAR_BITS( xEventGroup, uxBitsToClear );\r
429 \r
430                 /* The value returned is the event group value prior to the bits being\r
431                 cleared. */\r
432                 uxReturn = pxEventBits->uxEventBits;\r
433 \r
434                 /* Clear the bits. */\r
435                 pxEventBits->uxEventBits &= ~uxBitsToClear;\r
436         }\r
437         taskEXIT_CRITICAL();\r
438 \r
439         return uxReturn;\r
440 }\r
441 /*-----------------------------------------------------------*/\r
442 \r
443 #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) )\r
444 \r
445         BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear )\r
446         {\r
447                 BaseType_t xReturn;\r
448 \r
449                 traceEVENT_GROUP_CLEAR_BITS_FROM_ISR( xEventGroup, uxBitsToClear );\r
450                 xReturn = xTimerPendFunctionCallFromISR( vEventGroupClearBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToClear, NULL );\r
451 \r
452                 return xReturn;\r
453         }\r
454 \r
455 #endif\r
456 /*-----------------------------------------------------------*/\r
457 \r
458 EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup )\r
459 {\r
460 UBaseType_t uxSavedInterruptStatus;\r
461 EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup;\r
462 EventBits_t uxReturn;\r
463 \r
464         uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
465         {\r
466                 uxReturn = pxEventBits->uxEventBits;\r
467         }\r
468         portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
469 \r
470         return uxReturn;\r
471 }\r
472 /*-----------------------------------------------------------*/\r
473 \r
474 EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet )\r
475 {\r
476 ListItem_t *pxListItem, *pxNext;\r
477 ListItem_t const *pxListEnd;\r
478 List_t *pxList;\r
479 EventBits_t uxBitsToClear = 0, uxBitsWaitedFor, uxControlBits;\r
480 EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup;\r
481 BaseType_t xMatchFound = pdFALSE;\r
482 \r
483         /* Check the user is not attempting to set the bits used by the kernel\r
484         itself. */\r
485         configASSERT( ( uxBitsToSet & eventEVENT_BITS_CONTROL_BYTES ) == 0 );\r
486 \r
487         pxList = &( pxEventBits->xTasksWaitingForBits );\r
488         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
489         vTaskSuspendAll();\r
490         {\r
491                 traceEVENT_GROUP_SET_BITS( xEventGroup, uxBitsToSet );\r
492 \r
493                 pxListItem = listGET_HEAD_ENTRY( pxList );\r
494 \r
495                 /* Set the bits. */\r
496                 pxEventBits->uxEventBits |= uxBitsToSet;\r
497 \r
498                 /* See if the new bit value should unblock any tasks. */\r
499                 while( pxListItem != pxListEnd )\r
500                 {\r
501                         pxNext = listGET_NEXT( pxListItem );\r
502                         uxBitsWaitedFor = listGET_LIST_ITEM_VALUE( pxListItem );\r
503                         xMatchFound = pdFALSE;\r
504 \r
505                         /* Split the bits waited for from the control bits. */\r
506                         uxControlBits = uxBitsWaitedFor & eventEVENT_BITS_CONTROL_BYTES;\r
507                         uxBitsWaitedFor &= ~eventEVENT_BITS_CONTROL_BYTES;\r
508 \r
509                         if( ( uxControlBits & eventWAIT_FOR_ALL_BITS ) == ( EventBits_t ) 0 )\r
510                         {\r
511                                 /* Just looking for single bit being set. */\r
512                                 if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) != ( EventBits_t ) 0 )\r
513                                 {\r
514                                         xMatchFound = pdTRUE;\r
515                                 }\r
516                                 else\r
517                                 {\r
518                                         mtCOVERAGE_TEST_MARKER();\r
519                                 }\r
520                         }\r
521                         else if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) == uxBitsWaitedFor )\r
522                         {\r
523                                 /* All bits are set. */\r
524                                 xMatchFound = pdTRUE;\r
525                         }\r
526                         else\r
527                         {\r
528                                 /* Need all bits to be set, but not all the bits were set. */\r
529                         }\r
530 \r
531                         if( xMatchFound != pdFALSE )\r
532                         {\r
533                                 /* The bits match.  Should the bits be cleared on exit? */\r
534                                 if( ( uxControlBits & eventCLEAR_EVENTS_ON_EXIT_BIT ) != ( EventBits_t ) 0 )\r
535                                 {\r
536                                         uxBitsToClear |= uxBitsWaitedFor;\r
537                                 }\r
538                                 else\r
539                                 {\r
540                                         mtCOVERAGE_TEST_MARKER();\r
541                                 }\r
542 \r
543                                 /* Store the actual event flag value in the task's event list\r
544                                 item before removing the task from the event list.  The\r
545                                 eventUNBLOCKED_DUE_TO_BIT_SET bit is set so the task knows\r
546                                 that is was unblocked due to its required bits matching, rather\r
547                                 than because it timed out. */\r
548                                 ( void ) xTaskRemoveFromUnorderedEventList( pxListItem, pxEventBits->uxEventBits | eventUNBLOCKED_DUE_TO_BIT_SET );\r
549                         }\r
550 \r
551                         /* Move onto the next list item.  Note pxListItem->pxNext is not\r
552                         used here as the list item may have been removed from the event list\r
553                         and inserted into the ready/pending reading list. */\r
554                         pxListItem = pxNext;\r
555                 }\r
556 \r
557                 /* Clear any bits that matched when the eventCLEAR_EVENTS_ON_EXIT_BIT\r
558                 bit was set in the control word. */\r
559                 pxEventBits->uxEventBits &= ~uxBitsToClear;\r
560         }\r
561         ( void ) xTaskResumeAll();\r
562 \r
563         return pxEventBits->uxEventBits;\r
564 }\r
565 /*-----------------------------------------------------------*/\r
566 \r
567 void vEventGroupDelete( EventGroupHandle_t xEventGroup )\r
568 {\r
569 EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup;\r
570 const List_t *pxTasksWaitingForBits = &( pxEventBits->xTasksWaitingForBits );\r
571 \r
572         vTaskSuspendAll();\r
573         {\r
574                 traceEVENT_GROUP_DELETE( xEventGroup );\r
575 \r
576                 while( listCURRENT_LIST_LENGTH( pxTasksWaitingForBits ) > ( UBaseType_t ) 0 )\r
577                 {\r
578                         /* Unblock the task, returning 0 as the event list is being deleted\r
579                         and     cannot therefore have any bits set. */\r
580                         configASSERT( pxTasksWaitingForBits->xListEnd.pxNext != ( ListItem_t * ) &( pxTasksWaitingForBits->xListEnd ) );\r
581                         ( void ) xTaskRemoveFromUnorderedEventList( pxTasksWaitingForBits->xListEnd.pxNext, eventUNBLOCKED_DUE_TO_BIT_SET );\r
582                 }\r
583 \r
584                 vPortFree( pxEventBits );\r
585         }\r
586         ( void ) xTaskResumeAll();\r
587 }\r
588 /*-----------------------------------------------------------*/\r
589 \r
590 /* For internal use only - execute a 'set bits' command that was pended from\r
591 an interrupt. */\r
592 void vEventGroupSetBitsCallback( void *pvEventGroup, const uint32_t ulBitsToSet )\r
593 {\r
594         ( void ) xEventGroupSetBits( pvEventGroup, ( EventBits_t ) ulBitsToSet );\r
595 }\r
596 /*-----------------------------------------------------------*/\r
597 \r
598 /* For internal use only - execute a 'clear bits' command that was pended from\r
599 an interrupt. */\r
600 void vEventGroupClearBitsCallback( void *pvEventGroup, const uint32_t ulBitsToClear )\r
601 {\r
602         ( void ) xEventGroupClearBits( pvEventGroup, ( EventBits_t ) ulBitsToClear );\r
603 }\r
604 /*-----------------------------------------------------------*/\r
605 \r
606 static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits, const EventBits_t uxBitsToWaitFor, const BaseType_t xWaitForAllBits )\r
607 {\r
608 BaseType_t xWaitConditionMet = pdFALSE;\r
609 \r
610         if( xWaitForAllBits == pdFALSE )\r
611         {\r
612                 /* Task only has to wait for one bit within uxBitsToWaitFor to be\r
613                 set.  Is one already set? */\r
614                 if( ( uxCurrentEventBits & uxBitsToWaitFor ) != ( EventBits_t ) 0 )\r
615                 {\r
616                         xWaitConditionMet = pdTRUE;\r
617                 }\r
618                 else\r
619                 {\r
620                         mtCOVERAGE_TEST_MARKER();\r
621                 }\r
622         }\r
623         else\r
624         {\r
625                 /* Task has to wait for all the bits in uxBitsToWaitFor to be set.\r
626                 Are they set already? */\r
627                 if( ( uxCurrentEventBits & uxBitsToWaitFor ) == uxBitsToWaitFor )\r
628                 {\r
629                         xWaitConditionMet = pdTRUE;\r
630                 }\r
631                 else\r
632                 {\r
633                         mtCOVERAGE_TEST_MARKER();\r
634                 }\r
635         }\r
636 \r
637         return xWaitConditionMet;\r
638 }\r
639 /*-----------------------------------------------------------*/\r
640 \r
641 #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) )\r
642 \r
643         BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken )\r
644         {\r
645         BaseType_t xReturn;\r
646 \r
647                 traceEVENT_GROUP_SET_BITS_FROM_ISR( xEventGroup, uxBitsToSet );\r
648                 xReturn = xTimerPendFunctionCallFromISR( vEventGroupSetBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToSet, pxHigherPriorityTaskWoken );\r
649 \r
650                 return xReturn;\r
651         }\r
652 \r
653 #endif\r
654 /*-----------------------------------------------------------*/\r
655 \r
656 #if (configUSE_TRACE_FACILITY == 1)\r
657 \r
658         UBaseType_t uxEventGroupGetNumber( void* xEventGroup )\r
659         {\r
660         UBaseType_t xReturn;\r
661         EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup;\r
662 \r
663                 if( xEventGroup == NULL )\r
664                 {\r
665                         xReturn = 0;\r
666                 }\r
667                 else\r
668                 {\r
669                         xReturn = pxEventBits->uxEventGroupNumber;\r
670                 }\r
671 \r
672                 return xReturn;\r
673         }\r
674 \r
675 #endif\r
676 \r