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