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 typedef struct EventGroupDef_t
51 EventBits_t uxEventBits;
52 List_t xTasksWaitingForBits; /**< List of tasks waiting for a bit to be set. */
54 #if ( configUSE_TRACE_FACILITY == 1 )
55 UBaseType_t uxEventGroupNumber;
58 #if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
59 uint8_t ucStaticallyAllocated; /**< Set to pdTRUE if the event group is statically allocated to ensure no attempt is made to free the memory. */
63 /*-----------------------------------------------------------*/
66 * Test the bits set in uxCurrentEventBits to see if the wait condition is met.
67 * The wait condition is defined by xWaitForAllBits. If xWaitForAllBits is
68 * pdTRUE then the wait condition is met if all the bits set in uxBitsToWaitFor
69 * are also set in uxCurrentEventBits. If xWaitForAllBits is pdFALSE then the
70 * wait condition is met if any of the bits set in uxBitsToWait for are also set
71 * in uxCurrentEventBits.
73 static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits,
74 const EventBits_t uxBitsToWaitFor,
75 const BaseType_t xWaitForAllBits ) PRIVILEGED_FUNCTION;
77 /*-----------------------------------------------------------*/
79 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
81 EventGroupHandle_t xEventGroupCreateStatic( StaticEventGroup_t * pxEventGroupBuffer )
83 EventGroup_t * pxEventBits;
85 traceENTER_xEventGroupCreateStatic( pxEventGroupBuffer );
87 /* A StaticEventGroup_t object must be provided. */
88 configASSERT( pxEventGroupBuffer );
90 #if ( configASSERT_DEFINED == 1 )
92 /* Sanity check that the size of the structure used to declare a
93 * variable of type StaticEventGroup_t equals the size of the real
94 * event group structure. */
95 volatile size_t xSize = sizeof( StaticEventGroup_t );
96 configASSERT( xSize == sizeof( EventGroup_t ) );
97 } /*lint !e529 xSize is referenced if configASSERT() is defined. */
98 #endif /* configASSERT_DEFINED */
100 /* The user has provided a statically allocated event group - use it. */
101 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(). */
103 if( pxEventBits != NULL )
105 pxEventBits->uxEventBits = 0;
106 vListInitialise( &( pxEventBits->xTasksWaitingForBits ) );
108 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
110 /* Both static and dynamic allocation can be used, so note that
111 * this event group was created statically in case the event group
112 * is later deleted. */
113 pxEventBits->ucStaticallyAllocated = pdTRUE;
115 #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
117 traceEVENT_GROUP_CREATE( pxEventBits );
121 /* xEventGroupCreateStatic should only ever be called with
122 * pxEventGroupBuffer pointing to a pre-allocated (compile time
123 * allocated) StaticEventGroup_t variable. */
124 traceEVENT_GROUP_CREATE_FAILED();
127 traceRETURN_xEventGroupCreateStatic( pxEventBits );
132 #endif /* configSUPPORT_STATIC_ALLOCATION */
133 /*-----------------------------------------------------------*/
135 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
137 EventGroupHandle_t xEventGroupCreate( void )
139 EventGroup_t * pxEventBits;
141 traceENTER_xEventGroupCreate();
143 /* Allocate the event group. Justification for MISRA deviation as
144 * follows: pvPortMalloc() always ensures returned memory blocks are
145 * aligned per the requirements of the MCU stack. In this case
146 * pvPortMalloc() must return a pointer that is guaranteed to meet the
147 * alignment requirements of the EventGroup_t structure - which (if you
148 * follow it through) is the alignment requirements of the TickType_t type
149 * (EventBits_t being of TickType_t itself). Therefore, whenever the
150 * stack alignment requirements are greater than or equal to the
151 * TickType_t alignment requirements the cast is safe. In other cases,
152 * where the natural word size of the architecture is less than
153 * sizeof( TickType_t ), the TickType_t variables will be accessed in two
154 * or more reads operations, and the alignment requirements is only that
155 * of each individual read. */
156 pxEventBits = ( EventGroup_t * ) pvPortMalloc( sizeof( EventGroup_t ) ); /*lint !e9087 !e9079 see comment above. */
158 if( pxEventBits != NULL )
160 pxEventBits->uxEventBits = 0;
161 vListInitialise( &( pxEventBits->xTasksWaitingForBits ) );
163 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
165 /* Both static and dynamic allocation can be used, so note this
166 * event group was allocated statically in case the event group is
168 pxEventBits->ucStaticallyAllocated = pdFALSE;
170 #endif /* configSUPPORT_STATIC_ALLOCATION */
172 traceEVENT_GROUP_CREATE( pxEventBits );
176 traceEVENT_GROUP_CREATE_FAILED(); /*lint !e9063 Else branch only exists to allow tracing and does not generate code if trace macros are not defined. */
179 traceRETURN_xEventGroupCreate( pxEventBits );
184 #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
185 /*-----------------------------------------------------------*/
187 EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup,
188 const EventBits_t uxBitsToSet,
189 const EventBits_t uxBitsToWaitFor,
190 TickType_t xTicksToWait )
192 EventBits_t uxOriginalBitValue, uxReturn;
193 EventGroup_t * pxEventBits = xEventGroup;
194 BaseType_t xAlreadyYielded;
195 BaseType_t xTimeoutOccurred = pdFALSE;
197 traceENTER_xEventGroupSync( xEventGroup, uxBitsToSet, uxBitsToWaitFor, xTicksToWait );
199 configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
200 configASSERT( uxBitsToWaitFor != 0 );
201 #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
203 configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
209 uxOriginalBitValue = pxEventBits->uxEventBits;
211 ( void ) xEventGroupSetBits( xEventGroup, uxBitsToSet );
213 if( ( ( uxOriginalBitValue | uxBitsToSet ) & uxBitsToWaitFor ) == uxBitsToWaitFor )
215 /* All the rendezvous bits are now set - no need to block. */
216 uxReturn = ( uxOriginalBitValue | uxBitsToSet );
218 /* Rendezvous always clear the bits. They will have been cleared
219 * already unless this is the only task in the rendezvous. */
220 pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
226 if( xTicksToWait != ( TickType_t ) 0 )
228 traceEVENT_GROUP_SYNC_BLOCK( xEventGroup, uxBitsToSet, uxBitsToWaitFor );
230 /* Store the bits that the calling task is waiting for in the
231 * task's event list item so the kernel knows when a match is
232 * found. Then enter the blocked state. */
233 vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | eventCLEAR_EVENTS_ON_EXIT_BIT | eventWAIT_FOR_ALL_BITS ), xTicksToWait );
235 /* This assignment is obsolete as uxReturn will get set after
236 * the task unblocks, but some compilers mistakenly generate a
237 * warning about uxReturn being returned without being set if the
238 * assignment is omitted. */
243 /* The rendezvous bits were not set, but no block time was
244 * specified - just return the current event bit value. */
245 uxReturn = pxEventBits->uxEventBits;
246 xTimeoutOccurred = pdTRUE;
250 xAlreadyYielded = xTaskResumeAll();
252 if( xTicksToWait != ( TickType_t ) 0 )
254 if( xAlreadyYielded == pdFALSE )
256 taskYIELD_WITHIN_API();
260 mtCOVERAGE_TEST_MARKER();
263 /* The task blocked to wait for its required bits to be set - at this
264 * point either the required bits were set or the block time expired. If
265 * the required bits were set they will have been stored in the task's
266 * event list item, and they should now be retrieved then cleared. */
267 uxReturn = uxTaskResetEventItemValue();
269 if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 )
271 /* The task timed out, just return the current event bit value. */
272 taskENTER_CRITICAL();
274 uxReturn = pxEventBits->uxEventBits;
276 /* Although the task got here because it timed out before the
277 * bits it was waiting for were set, it is possible that since it
278 * unblocked another task has set the bits. If this is the case
279 * then it needs to clear the bits before exiting. */
280 if( ( uxReturn & uxBitsToWaitFor ) == uxBitsToWaitFor )
282 pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
286 mtCOVERAGE_TEST_MARKER();
291 xTimeoutOccurred = pdTRUE;
295 /* The task unblocked because the bits were set. */
298 /* Control bits might be set as the task had blocked should not be
300 uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;
303 traceEVENT_GROUP_SYNC_END( xEventGroup, uxBitsToSet, uxBitsToWaitFor, xTimeoutOccurred );
305 /* Prevent compiler warnings when trace macros are not used. */
306 ( void ) xTimeoutOccurred;
308 traceRETURN_xEventGroupSync( uxReturn );
312 /*-----------------------------------------------------------*/
314 EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup,
315 const EventBits_t uxBitsToWaitFor,
316 const BaseType_t xClearOnExit,
317 const BaseType_t xWaitForAllBits,
318 TickType_t xTicksToWait )
320 EventGroup_t * pxEventBits = xEventGroup;
321 EventBits_t uxReturn, uxControlBits = 0;
322 BaseType_t xWaitConditionMet, xAlreadyYielded;
323 BaseType_t xTimeoutOccurred = pdFALSE;
325 traceENTER_xEventGroupWaitBits( xEventGroup, uxBitsToWaitFor, xClearOnExit, xWaitForAllBits, xTicksToWait );
327 /* Check the user is not attempting to wait on the bits used by the kernel
328 * itself, and that at least one bit is being requested. */
329 configASSERT( xEventGroup );
330 configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
331 configASSERT( uxBitsToWaitFor != 0 );
332 #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
334 configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
340 const EventBits_t uxCurrentEventBits = pxEventBits->uxEventBits;
342 /* Check to see if the wait condition is already met or not. */
343 xWaitConditionMet = prvTestWaitCondition( uxCurrentEventBits, uxBitsToWaitFor, xWaitForAllBits );
345 if( xWaitConditionMet != pdFALSE )
347 /* The wait condition has already been met so there is no need to
349 uxReturn = uxCurrentEventBits;
350 xTicksToWait = ( TickType_t ) 0;
352 /* Clear the wait bits if requested to do so. */
353 if( xClearOnExit != pdFALSE )
355 pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
359 mtCOVERAGE_TEST_MARKER();
362 else if( xTicksToWait == ( TickType_t ) 0 )
364 /* The wait condition has not been met, but no block time was
365 * specified, so just return the current value. */
366 uxReturn = uxCurrentEventBits;
367 xTimeoutOccurred = pdTRUE;
371 /* The task is going to block to wait for its required bits to be
372 * set. uxControlBits are used to remember the specified behaviour of
373 * this call to xEventGroupWaitBits() - for use when the event bits
374 * unblock the task. */
375 if( xClearOnExit != pdFALSE )
377 uxControlBits |= eventCLEAR_EVENTS_ON_EXIT_BIT;
381 mtCOVERAGE_TEST_MARKER();
384 if( xWaitForAllBits != pdFALSE )
386 uxControlBits |= eventWAIT_FOR_ALL_BITS;
390 mtCOVERAGE_TEST_MARKER();
393 /* Store the bits that the calling task is waiting for in the
394 * task's event list item so the kernel knows when a match is
395 * found. Then enter the blocked state. */
396 vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | uxControlBits ), xTicksToWait );
398 /* This is obsolete as it will get set after the task unblocks, but
399 * some compilers mistakenly generate a warning about the variable
400 * being returned without being set if it is not done. */
403 traceEVENT_GROUP_WAIT_BITS_BLOCK( xEventGroup, uxBitsToWaitFor );
406 xAlreadyYielded = xTaskResumeAll();
408 if( xTicksToWait != ( TickType_t ) 0 )
410 if( xAlreadyYielded == pdFALSE )
412 taskYIELD_WITHIN_API();
416 mtCOVERAGE_TEST_MARKER();
419 /* The task blocked to wait for its required bits to be set - at this
420 * point either the required bits were set or the block time expired. If
421 * the required bits were set they will have been stored in the task's
422 * event list item, and they should now be retrieved then cleared. */
423 uxReturn = uxTaskResetEventItemValue();
425 if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 )
427 taskENTER_CRITICAL();
429 /* The task timed out, just return the current event bit value. */
430 uxReturn = pxEventBits->uxEventBits;
432 /* It is possible that the event bits were updated between this
433 * task leaving the Blocked state and running again. */
434 if( prvTestWaitCondition( uxReturn, uxBitsToWaitFor, xWaitForAllBits ) != pdFALSE )
436 if( xClearOnExit != pdFALSE )
438 pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
442 mtCOVERAGE_TEST_MARKER();
447 mtCOVERAGE_TEST_MARKER();
450 xTimeoutOccurred = pdTRUE;
456 /* The task unblocked because the bits were set. */
459 /* The task blocked so control bits may have been set. */
460 uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;
463 traceEVENT_GROUP_WAIT_BITS_END( xEventGroup, uxBitsToWaitFor, xTimeoutOccurred );
465 /* Prevent compiler warnings when trace macros are not used. */
466 ( void ) xTimeoutOccurred;
468 traceRETURN_xEventGroupWaitBits( uxReturn );
472 /*-----------------------------------------------------------*/
474 EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup,
475 const EventBits_t uxBitsToClear )
477 EventGroup_t * pxEventBits = xEventGroup;
478 EventBits_t uxReturn;
480 traceENTER_xEventGroupClearBits( xEventGroup, uxBitsToClear );
482 /* Check the user is not attempting to clear the bits used by the kernel
484 configASSERT( xEventGroup );
485 configASSERT( ( uxBitsToClear & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
487 taskENTER_CRITICAL();
489 traceEVENT_GROUP_CLEAR_BITS( xEventGroup, uxBitsToClear );
491 /* The value returned is the event group value prior to the bits being
493 uxReturn = pxEventBits->uxEventBits;
495 /* Clear the bits. */
496 pxEventBits->uxEventBits &= ~uxBitsToClear;
500 traceRETURN_xEventGroupClearBits( uxReturn );
504 /*-----------------------------------------------------------*/
506 #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) )
508 BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup,
509 const EventBits_t uxBitsToClear )
513 traceENTER_xEventGroupClearBitsFromISR( xEventGroup, uxBitsToClear );
515 traceEVENT_GROUP_CLEAR_BITS_FROM_ISR( xEventGroup, uxBitsToClear );
516 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. */
518 traceRETURN_xEventGroupClearBitsFromISR( xReturn );
523 #endif /* if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) ) */
524 /*-----------------------------------------------------------*/
526 EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup )
528 UBaseType_t uxSavedInterruptStatus;
529 EventGroup_t const * const pxEventBits = xEventGroup;
530 EventBits_t uxReturn;
532 traceENTER_xEventGroupGetBitsFromISR( xEventGroup );
534 uxSavedInterruptStatus = taskENTER_CRITICAL_FROM_ISR();
536 uxReturn = pxEventBits->uxEventBits;
538 taskEXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus );
540 traceRETURN_xEventGroupGetBitsFromISR( uxReturn );
543 } /*lint !e818 EventGroupHandle_t is a typedef used in other functions to so can't be pointer to const. */
544 /*-----------------------------------------------------------*/
546 EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup,
547 const EventBits_t uxBitsToSet )
549 ListItem_t * pxListItem;
551 ListItem_t const * pxListEnd;
552 List_t const * pxList;
553 EventBits_t uxBitsToClear = 0, uxBitsWaitedFor, uxControlBits;
554 EventGroup_t * pxEventBits = xEventGroup;
555 BaseType_t xMatchFound = pdFALSE;
557 traceENTER_xEventGroupSetBits( xEventGroup, uxBitsToSet );
559 /* Check the user is not attempting to set the bits used by the kernel
561 configASSERT( xEventGroup );
562 configASSERT( ( uxBitsToSet & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
564 pxList = &( pxEventBits->xTasksWaitingForBits );
565 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. */
568 traceEVENT_GROUP_SET_BITS( xEventGroup, uxBitsToSet );
570 pxListItem = listGET_HEAD_ENTRY( pxList );
573 pxEventBits->uxEventBits |= uxBitsToSet;
575 /* See if the new bit value should unblock any tasks. */
576 while( pxListItem != pxListEnd )
578 pxNext = listGET_NEXT( pxListItem );
579 uxBitsWaitedFor = listGET_LIST_ITEM_VALUE( pxListItem );
580 xMatchFound = pdFALSE;
582 /* Split the bits waited for from the control bits. */
583 uxControlBits = uxBitsWaitedFor & eventEVENT_BITS_CONTROL_BYTES;
584 uxBitsWaitedFor &= ~eventEVENT_BITS_CONTROL_BYTES;
586 if( ( uxControlBits & eventWAIT_FOR_ALL_BITS ) == ( EventBits_t ) 0 )
588 /* Just looking for single bit being set. */
589 if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) != ( EventBits_t ) 0 )
591 xMatchFound = pdTRUE;
595 mtCOVERAGE_TEST_MARKER();
598 else if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) == uxBitsWaitedFor )
600 /* All bits are set. */
601 xMatchFound = pdTRUE;
605 /* Need all bits to be set, but not all the bits were set. */
608 if( xMatchFound != pdFALSE )
610 /* The bits match. Should the bits be cleared on exit? */
611 if( ( uxControlBits & eventCLEAR_EVENTS_ON_EXIT_BIT ) != ( EventBits_t ) 0 )
613 uxBitsToClear |= uxBitsWaitedFor;
617 mtCOVERAGE_TEST_MARKER();
620 /* Store the actual event flag value in the task's event list
621 * item before removing the task from the event list. The
622 * eventUNBLOCKED_DUE_TO_BIT_SET bit is set so the task knows
623 * that is was unblocked due to its required bits matching, rather
624 * than because it timed out. */
625 vTaskRemoveFromUnorderedEventList( pxListItem, pxEventBits->uxEventBits | eventUNBLOCKED_DUE_TO_BIT_SET );
628 /* Move onto the next list item. Note pxListItem->pxNext is not
629 * used here as the list item may have been removed from the event list
630 * and inserted into the ready/pending reading list. */
634 /* Clear any bits that matched when the eventCLEAR_EVENTS_ON_EXIT_BIT
635 * bit was set in the control word. */
636 pxEventBits->uxEventBits &= ~uxBitsToClear;
638 ( void ) xTaskResumeAll();
640 traceRETURN_xEventGroupSetBits( pxEventBits->uxEventBits );
642 return pxEventBits->uxEventBits;
644 /*-----------------------------------------------------------*/
646 void vEventGroupDelete( EventGroupHandle_t xEventGroup )
648 EventGroup_t * pxEventBits = xEventGroup;
649 const List_t * pxTasksWaitingForBits;
651 traceENTER_vEventGroupDelete( xEventGroup );
653 configASSERT( pxEventBits );
655 pxTasksWaitingForBits = &( pxEventBits->xTasksWaitingForBits );
659 traceEVENT_GROUP_DELETE( xEventGroup );
661 while( listCURRENT_LIST_LENGTH( pxTasksWaitingForBits ) > ( UBaseType_t ) 0 )
663 /* Unblock the task, returning 0 as the event list is being deleted
664 * and cannot therefore have any bits set. */
665 configASSERT( pxTasksWaitingForBits->xListEnd.pxNext != ( const ListItem_t * ) &( pxTasksWaitingForBits->xListEnd ) );
666 vTaskRemoveFromUnorderedEventList( pxTasksWaitingForBits->xListEnd.pxNext, eventUNBLOCKED_DUE_TO_BIT_SET );
669 ( void ) xTaskResumeAll();
671 #if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) )
673 /* The event group can only have been allocated dynamically - free
675 vPortFree( pxEventBits );
677 #elif ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
679 /* The event group could have been allocated statically or
680 * dynamically, so check before attempting to free the memory. */
681 if( pxEventBits->ucStaticallyAllocated == ( uint8_t ) pdFALSE )
683 vPortFree( pxEventBits );
687 mtCOVERAGE_TEST_MARKER();
690 #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
692 traceRETURN_vEventGroupDelete();
694 /*-----------------------------------------------------------*/
696 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
697 BaseType_t xEventGroupGetStaticBuffer( EventGroupHandle_t xEventGroup,
698 StaticEventGroup_t ** ppxEventGroupBuffer )
701 EventGroup_t * pxEventBits = xEventGroup;
703 traceENTER_xEventGroupGetStaticBuffer( xEventGroup, ppxEventGroupBuffer );
705 configASSERT( pxEventBits );
706 configASSERT( ppxEventGroupBuffer );
708 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
710 /* Check if the event group was statically allocated. */
711 if( pxEventBits->ucStaticallyAllocated == ( uint8_t ) pdTRUE )
713 *ppxEventGroupBuffer = ( StaticEventGroup_t * ) pxEventBits;
721 #else /* configSUPPORT_DYNAMIC_ALLOCATION */
723 /* Event group must have been statically allocated. */
724 *ppxEventGroupBuffer = ( StaticEventGroup_t * ) pxEventBits;
727 #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
729 traceRETURN_xEventGroupGetStaticBuffer( xReturn );
733 #endif /* configSUPPORT_STATIC_ALLOCATION */
734 /*-----------------------------------------------------------*/
736 /* For internal use only - execute a 'set bits' command that was pended from
738 void vEventGroupSetBitsCallback( void * pvEventGroup,
739 const uint32_t ulBitsToSet )
741 traceENTER_vEventGroupSetBitsCallback( pvEventGroup, ulBitsToSet );
743 ( 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. */
745 traceRETURN_vEventGroupSetBitsCallback();
747 /*-----------------------------------------------------------*/
749 /* For internal use only - execute a 'clear bits' command that was pended from
751 void vEventGroupClearBitsCallback( void * pvEventGroup,
752 const uint32_t ulBitsToClear )
754 traceENTER_vEventGroupClearBitsCallback( pvEventGroup, ulBitsToClear );
756 ( 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. */
758 traceRETURN_vEventGroupClearBitsCallback();
760 /*-----------------------------------------------------------*/
762 static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits,
763 const EventBits_t uxBitsToWaitFor,
764 const BaseType_t xWaitForAllBits )
766 BaseType_t xWaitConditionMet = pdFALSE;
768 if( xWaitForAllBits == pdFALSE )
770 /* Task only has to wait for one bit within uxBitsToWaitFor to be
771 * set. Is one already set? */
772 if( ( uxCurrentEventBits & uxBitsToWaitFor ) != ( EventBits_t ) 0 )
774 xWaitConditionMet = pdTRUE;
778 mtCOVERAGE_TEST_MARKER();
783 /* Task has to wait for all the bits in uxBitsToWaitFor to be set.
784 * Are they set already? */
785 if( ( uxCurrentEventBits & uxBitsToWaitFor ) == uxBitsToWaitFor )
787 xWaitConditionMet = pdTRUE;
791 mtCOVERAGE_TEST_MARKER();
795 return xWaitConditionMet;
797 /*-----------------------------------------------------------*/
799 #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) )
801 BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup,
802 const EventBits_t uxBitsToSet,
803 BaseType_t * pxHigherPriorityTaskWoken )
807 traceENTER_xEventGroupSetBitsFromISR( xEventGroup, uxBitsToSet, pxHigherPriorityTaskWoken );
809 traceEVENT_GROUP_SET_BITS_FROM_ISR( xEventGroup, uxBitsToSet );
810 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. */
812 traceRETURN_xEventGroupSetBitsFromISR( xReturn );
817 #endif /* if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) ) */
818 /*-----------------------------------------------------------*/
820 #if ( configUSE_TRACE_FACILITY == 1 )
822 UBaseType_t uxEventGroupGetNumber( void * xEventGroup )
825 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. */
827 traceENTER_uxEventGroupGetNumber( xEventGroup );
829 if( xEventGroup == NULL )
835 xReturn = pxEventBits->uxEventGroupNumber;
838 traceRETURN_uxEventGroupGetNumber( xReturn );
843 #endif /* configUSE_TRACE_FACILITY */
844 /*-----------------------------------------------------------*/
846 #if ( configUSE_TRACE_FACILITY == 1 )
848 void vEventGroupSetNumber( void * xEventGroup,
849 UBaseType_t uxEventGroupNumber )
851 traceENTER_vEventGroupSetNumber( xEventGroup, uxEventGroupNumber );
853 ( ( 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. */
855 traceRETURN_vEventGroupSetNumber();
858 #endif /* configUSE_TRACE_FACILITY */
859 /*-----------------------------------------------------------*/