2 * FreeRTOS Kernel <DEVELOPMENT BRANCH>
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * SPDX-License-Identifier: MIT
7 * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 * this software and associated documentation files (the "Software"), to deal in
9 * the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 * the Software, and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * https://www.FreeRTOS.org
25 * https://github.com/FreeRTOS
29 /* Standard includes. */
32 /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining
33 * all the API functions to use the MPU wrappers. That should only be done when
34 * task.h is included from an application file. */
35 #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
37 /* FreeRTOS includes. */
41 #include "event_groups.h"
43 /* Lint e961, e750 and e9021 are suppressed as a MISRA exception justified
44 * because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined
45 * for the header files above, but not in this file, in order to generate the
46 * correct privileged Vs unprivileged linkage and placement. */
47 #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750 !e9021 See comment above. */
49 /* The following bit fields convey control information in a task's event list
50 * item value. It is important they don't clash with the
51 * taskEVENT_LIST_ITEM_VALUE_IN_USE definition. */
52 #if configUSE_16_BIT_TICKS == 1
53 #define eventCLEAR_EVENTS_ON_EXIT_BIT 0x0100U
54 #define eventUNBLOCKED_DUE_TO_BIT_SET 0x0200U
55 #define eventWAIT_FOR_ALL_BITS 0x0400U
56 #define eventEVENT_BITS_CONTROL_BYTES 0xff00U
58 #define eventCLEAR_EVENTS_ON_EXIT_BIT 0x01000000UL
59 #define eventUNBLOCKED_DUE_TO_BIT_SET 0x02000000UL
60 #define eventWAIT_FOR_ALL_BITS 0x04000000UL
61 #define eventEVENT_BITS_CONTROL_BYTES 0xff000000UL
64 typedef struct EventGroupDef_t
66 EventBits_t uxEventBits;
67 List_t xTasksWaitingForBits; /*< List of tasks waiting for a bit to be set. */
69 #if ( configUSE_TRACE_FACILITY == 1 )
70 UBaseType_t uxEventGroupNumber;
73 #if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
74 uint8_t ucStaticallyAllocated; /*< Set to pdTRUE if the event group is statically allocated to ensure no attempt is made to free the memory. */
78 /*-----------------------------------------------------------*/
81 * Test the bits set in uxCurrentEventBits to see if the wait condition is met.
82 * The wait condition is defined by xWaitForAllBits. If xWaitForAllBits is
83 * pdTRUE then the wait condition is met if all the bits set in uxBitsToWaitFor
84 * are also set in uxCurrentEventBits. If xWaitForAllBits is pdFALSE then the
85 * wait condition is met if any of the bits set in uxBitsToWait for are also set
86 * in uxCurrentEventBits.
88 static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits,
89 const EventBits_t uxBitsToWaitFor,
90 const BaseType_t xWaitForAllBits ) PRIVILEGED_FUNCTION;
92 /*-----------------------------------------------------------*/
94 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
96 EventGroupHandle_t xEventGroupCreateStatic( StaticEventGroup_t * pxEventGroupBuffer )
98 EventGroup_t * pxEventBits;
100 /* A StaticEventGroup_t object must be provided. */
101 configASSERT( pxEventGroupBuffer );
103 #if ( configASSERT_DEFINED == 1 )
105 /* Sanity check that the size of the structure used to declare a
106 * variable of type StaticEventGroup_t equals the size of the real
107 * event group structure. */
108 volatile size_t xSize = sizeof( StaticEventGroup_t );
109 configASSERT( xSize == sizeof( EventGroup_t ) );
110 } /*lint !e529 xSize is referenced if configASSERT() is defined. */
111 #endif /* configASSERT_DEFINED */
113 /* The user has provided a statically allocated event group - use it. */
114 pxEventBits = ( EventGroup_t * ) pxEventGroupBuffer; /*lint !e740 !e9087 EventGroup_t and StaticEventGroup_t are deliberately aliased for data hiding purposes and guaranteed to have the same size and alignment requirement - checked by configASSERT(). */
116 if( pxEventBits != NULL )
118 pxEventBits->uxEventBits = 0;
119 vListInitialise( &( pxEventBits->xTasksWaitingForBits ) );
121 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
123 /* Both static and dynamic allocation can be used, so note that
124 * this event group was created statically in case the event group
125 * is later deleted. */
126 pxEventBits->ucStaticallyAllocated = pdTRUE;
128 #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
130 traceEVENT_GROUP_CREATE( pxEventBits );
134 /* xEventGroupCreateStatic should only ever be called with
135 * pxEventGroupBuffer pointing to a pre-allocated (compile time
136 * allocated) StaticEventGroup_t variable. */
137 traceEVENT_GROUP_CREATE_FAILED();
143 #endif /* configSUPPORT_STATIC_ALLOCATION */
144 /*-----------------------------------------------------------*/
146 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
148 EventGroupHandle_t xEventGroupCreate( void )
150 EventGroup_t * pxEventBits;
152 /* Allocate the event group. Justification for MISRA deviation as
153 * follows: pvPortMalloc() always ensures returned memory blocks are
154 * aligned per the requirements of the MCU stack. In this case
155 * pvPortMalloc() must return a pointer that is guaranteed to meet the
156 * alignment requirements of the EventGroup_t structure - which (if you
157 * follow it through) is the alignment requirements of the TickType_t type
158 * (EventBits_t being of TickType_t itself). Therefore, whenever the
159 * stack alignment requirements are greater than or equal to the
160 * TickType_t alignment requirements the cast is safe. In other cases,
161 * where the natural word size of the architecture is less than
162 * sizeof( TickType_t ), the TickType_t variables will be accessed in two
163 * or more reads operations, and the alignment requirements is only that
164 * of each individual read. */
165 pxEventBits = ( EventGroup_t * ) pvPortMalloc( sizeof( EventGroup_t ) ); /*lint !e9087 !e9079 see comment above. */
167 if( pxEventBits != NULL )
169 pxEventBits->uxEventBits = 0;
170 vListInitialise( &( pxEventBits->xTasksWaitingForBits ) );
172 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
174 /* Both static and dynamic allocation can be used, so note this
175 * event group was allocated statically in case the event group is
177 pxEventBits->ucStaticallyAllocated = pdFALSE;
179 #endif /* configSUPPORT_STATIC_ALLOCATION */
181 traceEVENT_GROUP_CREATE( pxEventBits );
185 traceEVENT_GROUP_CREATE_FAILED(); /*lint !e9063 Else branch only exists to allow tracing and does not generate code if trace macros are not defined. */
191 #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
192 /*-----------------------------------------------------------*/
194 EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup,
195 const EventBits_t uxBitsToSet,
196 const EventBits_t uxBitsToWaitFor,
197 TickType_t xTicksToWait )
199 EventBits_t uxOriginalBitValue, uxReturn;
200 EventGroup_t * pxEventBits = xEventGroup;
201 BaseType_t xAlreadyYielded;
202 BaseType_t xTimeoutOccurred = pdFALSE;
204 configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
205 configASSERT( uxBitsToWaitFor != 0 );
206 #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
208 configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
214 uxOriginalBitValue = pxEventBits->uxEventBits;
216 ( void ) xEventGroupSetBits( xEventGroup, uxBitsToSet );
218 if( ( ( uxOriginalBitValue | uxBitsToSet ) & uxBitsToWaitFor ) == uxBitsToWaitFor )
220 /* All the rendezvous bits are now set - no need to block. */
221 uxReturn = ( uxOriginalBitValue | uxBitsToSet );
223 /* Rendezvous always clear the bits. They will have been cleared
224 * already unless this is the only task in the rendezvous. */
225 pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
231 if( xTicksToWait != ( TickType_t ) 0 )
233 traceEVENT_GROUP_SYNC_BLOCK( xEventGroup, uxBitsToSet, uxBitsToWaitFor );
235 /* Store the bits that the calling task is waiting for in the
236 * task's event list item so the kernel knows when a match is
237 * found. Then enter the blocked state. */
238 vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | eventCLEAR_EVENTS_ON_EXIT_BIT | eventWAIT_FOR_ALL_BITS ), xTicksToWait );
240 /* This assignment is obsolete as uxReturn will get set after
241 * the task unblocks, but some compilers mistakenly generate a
242 * warning about uxReturn being returned without being set if the
243 * assignment is omitted. */
248 /* The rendezvous bits were not set, but no block time was
249 * specified - just return the current event bit value. */
250 uxReturn = pxEventBits->uxEventBits;
251 xTimeoutOccurred = pdTRUE;
255 xAlreadyYielded = xTaskResumeAll();
257 if( xTicksToWait != ( TickType_t ) 0 )
259 if( xAlreadyYielded == pdFALSE )
261 portYIELD_WITHIN_API();
265 mtCOVERAGE_TEST_MARKER();
268 /* The task blocked to wait for its required bits to be set - at this
269 * point either the required bits were set or the block time expired. If
270 * the required bits were set they will have been stored in the task's
271 * event list item, and they should now be retrieved then cleared. */
272 uxReturn = uxTaskResetEventItemValue();
274 if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 )
276 /* The task timed out, just return the current event bit value. */
277 taskENTER_CRITICAL();
279 uxReturn = pxEventBits->uxEventBits;
281 /* Although the task got here because it timed out before the
282 * bits it was waiting for were set, it is possible that since it
283 * unblocked another task has set the bits. If this is the case
284 * then it needs to clear the bits before exiting. */
285 if( ( uxReturn & uxBitsToWaitFor ) == uxBitsToWaitFor )
287 pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
291 mtCOVERAGE_TEST_MARKER();
296 xTimeoutOccurred = pdTRUE;
300 /* The task unblocked because the bits were set. */
303 /* Control bits might be set as the task had blocked should not be
305 uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;
308 traceEVENT_GROUP_SYNC_END( xEventGroup, uxBitsToSet, uxBitsToWaitFor, xTimeoutOccurred );
310 /* Prevent compiler warnings when trace macros are not used. */
311 ( void ) xTimeoutOccurred;
315 /*-----------------------------------------------------------*/
317 EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup,
318 const EventBits_t uxBitsToWaitFor,
319 const BaseType_t xClearOnExit,
320 const BaseType_t xWaitForAllBits,
321 TickType_t xTicksToWait )
323 EventGroup_t * pxEventBits = xEventGroup;
324 EventBits_t uxReturn, uxControlBits = 0;
325 BaseType_t xWaitConditionMet, xAlreadyYielded;
326 BaseType_t xTimeoutOccurred = pdFALSE;
328 /* Check the user is not attempting to wait on the bits used by the kernel
329 * itself, and that at least one bit is being requested. */
330 configASSERT( xEventGroup );
331 configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
332 configASSERT( uxBitsToWaitFor != 0 );
333 #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
335 configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
341 const EventBits_t uxCurrentEventBits = pxEventBits->uxEventBits;
343 /* Check to see if the wait condition is already met or not. */
344 xWaitConditionMet = prvTestWaitCondition( uxCurrentEventBits, uxBitsToWaitFor, xWaitForAllBits );
346 if( xWaitConditionMet != pdFALSE )
348 /* The wait condition has already been met so there is no need to
350 uxReturn = uxCurrentEventBits;
351 xTicksToWait = ( TickType_t ) 0;
353 /* Clear the wait bits if requested to do so. */
354 if( xClearOnExit != pdFALSE )
356 pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
360 mtCOVERAGE_TEST_MARKER();
363 else if( xTicksToWait == ( TickType_t ) 0 )
365 /* The wait condition has not been met, but no block time was
366 * specified, so just return the current value. */
367 uxReturn = uxCurrentEventBits;
368 xTimeoutOccurred = pdTRUE;
372 /* The task is going to block to wait for its required bits to be
373 * set. uxControlBits are used to remember the specified behaviour of
374 * this call to xEventGroupWaitBits() - for use when the event bits
375 * unblock the task. */
376 if( xClearOnExit != pdFALSE )
378 uxControlBits |= eventCLEAR_EVENTS_ON_EXIT_BIT;
382 mtCOVERAGE_TEST_MARKER();
385 if( xWaitForAllBits != pdFALSE )
387 uxControlBits |= eventWAIT_FOR_ALL_BITS;
391 mtCOVERAGE_TEST_MARKER();
394 /* Store the bits that the calling task is waiting for in the
395 * task's event list item so the kernel knows when a match is
396 * found. Then enter the blocked state. */
397 vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | uxControlBits ), xTicksToWait );
399 /* This is obsolete as it will get set after the task unblocks, but
400 * some compilers mistakenly generate a warning about the variable
401 * being returned without being set if it is not done. */
404 traceEVENT_GROUP_WAIT_BITS_BLOCK( xEventGroup, uxBitsToWaitFor );
407 xAlreadyYielded = xTaskResumeAll();
409 if( xTicksToWait != ( TickType_t ) 0 )
411 if( xAlreadyYielded == pdFALSE )
413 portYIELD_WITHIN_API();
417 mtCOVERAGE_TEST_MARKER();
420 /* The task blocked to wait for its required bits to be set - at this
421 * point either the required bits were set or the block time expired. If
422 * the required bits were set they will have been stored in the task's
423 * event list item, and they should now be retrieved then cleared. */
424 uxReturn = uxTaskResetEventItemValue();
426 if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 )
428 taskENTER_CRITICAL();
430 /* The task timed out, just return the current event bit value. */
431 uxReturn = pxEventBits->uxEventBits;
433 /* It is possible that the event bits were updated between this
434 * task leaving the Blocked state and running again. */
435 if( prvTestWaitCondition( uxReturn, uxBitsToWaitFor, xWaitForAllBits ) != pdFALSE )
437 if( xClearOnExit != pdFALSE )
439 pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
443 mtCOVERAGE_TEST_MARKER();
448 mtCOVERAGE_TEST_MARKER();
451 xTimeoutOccurred = pdTRUE;
457 /* The task unblocked because the bits were set. */
460 /* The task blocked so control bits may have been set. */
461 uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;
464 traceEVENT_GROUP_WAIT_BITS_END( xEventGroup, uxBitsToWaitFor, xTimeoutOccurred );
466 /* Prevent compiler warnings when trace macros are not used. */
467 ( void ) xTimeoutOccurred;
471 /*-----------------------------------------------------------*/
473 EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup,
474 const EventBits_t uxBitsToClear )
476 EventGroup_t * pxEventBits = xEventGroup;
477 EventBits_t uxReturn;
479 /* Check the user is not attempting to clear the bits used by the kernel
481 configASSERT( xEventGroup );
482 configASSERT( ( uxBitsToClear & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
484 taskENTER_CRITICAL();
486 traceEVENT_GROUP_CLEAR_BITS( xEventGroup, uxBitsToClear );
488 /* The value returned is the event group value prior to the bits being
490 uxReturn = pxEventBits->uxEventBits;
492 /* Clear the bits. */
493 pxEventBits->uxEventBits &= ~uxBitsToClear;
499 /*-----------------------------------------------------------*/
501 #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) )
503 BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup,
504 const EventBits_t uxBitsToClear )
508 traceEVENT_GROUP_CLEAR_BITS_FROM_ISR( xEventGroup, uxBitsToClear );
509 xReturn = xTimerPendFunctionCallFromISR( vEventGroupClearBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToClear, NULL ); /*lint !e9087 Can't avoid cast to void* as a generic callback function not specific to this use case. Callback casts back to original type so safe. */
514 #endif /* if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) ) */
515 /*-----------------------------------------------------------*/
517 EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup )
519 UBaseType_t uxSavedInterruptStatus;
520 EventGroup_t const * const pxEventBits = xEventGroup;
521 EventBits_t uxReturn;
523 uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
525 uxReturn = pxEventBits->uxEventBits;
527 portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );
530 } /*lint !e818 EventGroupHandle_t is a typedef used in other functions to so can't be pointer to const. */
531 /*-----------------------------------------------------------*/
533 EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup,
534 const EventBits_t uxBitsToSet )
536 ListItem_t * pxListItem;
538 ListItem_t const * pxListEnd;
539 List_t const * pxList;
540 EventBits_t uxBitsToClear = 0, uxBitsWaitedFor, uxControlBits;
541 EventGroup_t * pxEventBits = xEventGroup;
542 BaseType_t xMatchFound = pdFALSE;
544 /* Check the user is not attempting to set the bits used by the kernel
546 configASSERT( xEventGroup );
547 configASSERT( ( uxBitsToSet & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
549 pxList = &( pxEventBits->xTasksWaitingForBits );
550 pxListEnd = listGET_END_MARKER( pxList ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
553 traceEVENT_GROUP_SET_BITS( xEventGroup, uxBitsToSet );
555 pxListItem = listGET_HEAD_ENTRY( pxList );
558 pxEventBits->uxEventBits |= uxBitsToSet;
560 /* See if the new bit value should unblock any tasks. */
561 while( pxListItem != pxListEnd )
563 pxNext = listGET_NEXT( pxListItem );
564 uxBitsWaitedFor = listGET_LIST_ITEM_VALUE( pxListItem );
565 xMatchFound = pdFALSE;
567 /* Split the bits waited for from the control bits. */
568 uxControlBits = uxBitsWaitedFor & eventEVENT_BITS_CONTROL_BYTES;
569 uxBitsWaitedFor &= ~eventEVENT_BITS_CONTROL_BYTES;
571 if( ( uxControlBits & eventWAIT_FOR_ALL_BITS ) == ( EventBits_t ) 0 )
573 /* Just looking for single bit being set. */
574 if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) != ( EventBits_t ) 0 )
576 xMatchFound = pdTRUE;
580 mtCOVERAGE_TEST_MARKER();
583 else if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) == uxBitsWaitedFor )
585 /* All bits are set. */
586 xMatchFound = pdTRUE;
590 /* Need all bits to be set, but not all the bits were set. */
593 if( xMatchFound != pdFALSE )
595 /* The bits match. Should the bits be cleared on exit? */
596 if( ( uxControlBits & eventCLEAR_EVENTS_ON_EXIT_BIT ) != ( EventBits_t ) 0 )
598 uxBitsToClear |= uxBitsWaitedFor;
602 mtCOVERAGE_TEST_MARKER();
605 /* Store the actual event flag value in the task's event list
606 * item before removing the task from the event list. The
607 * eventUNBLOCKED_DUE_TO_BIT_SET bit is set so the task knows
608 * that is was unblocked due to its required bits matching, rather
609 * than because it timed out. */
610 vTaskRemoveFromUnorderedEventList( pxListItem, pxEventBits->uxEventBits | eventUNBLOCKED_DUE_TO_BIT_SET );
613 /* Move onto the next list item. Note pxListItem->pxNext is not
614 * used here as the list item may have been removed from the event list
615 * and inserted into the ready/pending reading list. */
619 /* Clear any bits that matched when the eventCLEAR_EVENTS_ON_EXIT_BIT
620 * bit was set in the control word. */
621 pxEventBits->uxEventBits &= ~uxBitsToClear;
623 ( void ) xTaskResumeAll();
625 return pxEventBits->uxEventBits;
627 /*-----------------------------------------------------------*/
629 void vEventGroupDelete( EventGroupHandle_t xEventGroup )
631 EventGroup_t * pxEventBits = xEventGroup;
632 const List_t * pxTasksWaitingForBits;
634 configASSERT( pxEventBits );
636 pxTasksWaitingForBits = &( pxEventBits->xTasksWaitingForBits );
640 traceEVENT_GROUP_DELETE( xEventGroup );
642 while( listCURRENT_LIST_LENGTH( pxTasksWaitingForBits ) > ( UBaseType_t ) 0 )
644 /* Unblock the task, returning 0 as the event list is being deleted
645 * and cannot therefore have any bits set. */
646 configASSERT( pxTasksWaitingForBits->xListEnd.pxNext != ( const ListItem_t * ) &( pxTasksWaitingForBits->xListEnd ) );
647 vTaskRemoveFromUnorderedEventList( pxTasksWaitingForBits->xListEnd.pxNext, eventUNBLOCKED_DUE_TO_BIT_SET );
650 ( void ) xTaskResumeAll();
652 #if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) )
654 /* The event group can only have been allocated dynamically - free
656 vPortFree( pxEventBits );
658 #elif ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
660 /* The event group could have been allocated statically or
661 * dynamically, so check before attempting to free the memory. */
662 if( pxEventBits->ucStaticallyAllocated == ( uint8_t ) pdFALSE )
664 vPortFree( pxEventBits );
668 mtCOVERAGE_TEST_MARKER();
671 #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
673 /*-----------------------------------------------------------*/
675 /* For internal use only - execute a 'set bits' command that was pended from
677 void vEventGroupSetBitsCallback( void * pvEventGroup,
678 const uint32_t ulBitsToSet )
680 ( void ) xEventGroupSetBits( pvEventGroup, ( EventBits_t ) ulBitsToSet ); /*lint !e9079 Can't avoid cast to void* as a generic timer callback prototype. Callback casts back to original type so safe. */
682 /*-----------------------------------------------------------*/
684 /* For internal use only - execute a 'clear bits' command that was pended from
686 void vEventGroupClearBitsCallback( void * pvEventGroup,
687 const uint32_t ulBitsToClear )
689 ( void ) xEventGroupClearBits( pvEventGroup, ( EventBits_t ) ulBitsToClear ); /*lint !e9079 Can't avoid cast to void* as a generic timer callback prototype. Callback casts back to original type so safe. */
691 /*-----------------------------------------------------------*/
693 static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits,
694 const EventBits_t uxBitsToWaitFor,
695 const BaseType_t xWaitForAllBits )
697 BaseType_t xWaitConditionMet = pdFALSE;
699 if( xWaitForAllBits == pdFALSE )
701 /* Task only has to wait for one bit within uxBitsToWaitFor to be
702 * set. Is one already set? */
703 if( ( uxCurrentEventBits & uxBitsToWaitFor ) != ( EventBits_t ) 0 )
705 xWaitConditionMet = pdTRUE;
709 mtCOVERAGE_TEST_MARKER();
714 /* Task has to wait for all the bits in uxBitsToWaitFor to be set.
715 * Are they set already? */
716 if( ( uxCurrentEventBits & uxBitsToWaitFor ) == uxBitsToWaitFor )
718 xWaitConditionMet = pdTRUE;
722 mtCOVERAGE_TEST_MARKER();
726 return xWaitConditionMet;
728 /*-----------------------------------------------------------*/
730 #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) )
732 BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup,
733 const EventBits_t uxBitsToSet,
734 BaseType_t * pxHigherPriorityTaskWoken )
738 traceEVENT_GROUP_SET_BITS_FROM_ISR( xEventGroup, uxBitsToSet );
739 xReturn = xTimerPendFunctionCallFromISR( vEventGroupSetBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToSet, pxHigherPriorityTaskWoken ); /*lint !e9087 Can't avoid cast to void* as a generic callback function not specific to this use case. Callback casts back to original type so safe. */
744 #endif /* if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) ) */
745 /*-----------------------------------------------------------*/
747 #if ( configUSE_TRACE_FACILITY == 1 )
749 UBaseType_t uxEventGroupGetNumber( void * xEventGroup )
752 EventGroup_t const * pxEventBits = ( EventGroup_t * ) xEventGroup; /*lint !e9087 !e9079 EventGroupHandle_t is a pointer to an EventGroup_t, but EventGroupHandle_t is kept opaque outside of this file for data hiding purposes. */
754 if( xEventGroup == NULL )
760 xReturn = pxEventBits->uxEventGroupNumber;
766 #endif /* configUSE_TRACE_FACILITY */
767 /*-----------------------------------------------------------*/
769 #if ( configUSE_TRACE_FACILITY == 1 )
771 void vEventGroupSetNumber( void * xEventGroup,
772 UBaseType_t uxEventGroupNumber )
774 ( ( EventGroup_t * ) xEventGroup )->uxEventGroupNumber = uxEventGroupNumber; /*lint !e9087 !e9079 EventGroupHandle_t is a pointer to an EventGroup_t, but EventGroupHandle_t is kept opaque outside of this file for data hiding purposes. */
777 #endif /* configUSE_TRACE_FACILITY */
778 /*-----------------------------------------------------------*/