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 /* The MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined
44 * for the header files above, but not in this file, in order to generate the
45 * correct privileged Vs unprivileged linkage and placement. */
46 #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
48 typedef struct EventGroupDef_t
50 EventBits_t uxEventBits;
51 List_t xTasksWaitingForBits; /**< List of tasks waiting for a bit to be set. */
53 #if ( configUSE_TRACE_FACILITY == 1 )
54 UBaseType_t uxEventGroupNumber;
57 #if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
58 uint8_t ucStaticallyAllocated; /**< Set to pdTRUE if the event group is statically allocated to ensure no attempt is made to free the memory. */
62 /*-----------------------------------------------------------*/
65 * Test the bits set in uxCurrentEventBits to see if the wait condition is met.
66 * The wait condition is defined by xWaitForAllBits. If xWaitForAllBits is
67 * pdTRUE then the wait condition is met if all the bits set in uxBitsToWaitFor
68 * are also set in uxCurrentEventBits. If xWaitForAllBits is pdFALSE then the
69 * wait condition is met if any of the bits set in uxBitsToWait for are also set
70 * in uxCurrentEventBits.
72 static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits,
73 const EventBits_t uxBitsToWaitFor,
74 const BaseType_t xWaitForAllBits ) PRIVILEGED_FUNCTION;
76 /*-----------------------------------------------------------*/
78 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
80 EventGroupHandle_t xEventGroupCreateStatic( StaticEventGroup_t * pxEventGroupBuffer )
82 EventGroup_t * pxEventBits;
84 traceENTER_xEventGroupCreateStatic( pxEventGroupBuffer );
86 /* A StaticEventGroup_t object must be provided. */
87 configASSERT( pxEventGroupBuffer );
89 #if ( configASSERT_DEFINED == 1 )
91 /* Sanity check that the size of the structure used to declare a
92 * variable of type StaticEventGroup_t equals the size of the real
93 * event group structure. */
94 volatile size_t xSize = sizeof( StaticEventGroup_t );
95 configASSERT( xSize == sizeof( EventGroup_t ) );
97 #endif /* configASSERT_DEFINED */
99 /* The user has provided a statically allocated event group - use it. */
100 /* MISRA Ref 11.3.1 [Misaligned access] */
101 /* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
102 /* coverity[misra_c_2012_rule_11_3_violation] */
103 pxEventBits = ( EventGroup_t * ) pxEventGroupBuffer;
105 if( pxEventBits != NULL )
107 pxEventBits->uxEventBits = 0;
108 vListInitialise( &( pxEventBits->xTasksWaitingForBits ) );
110 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
112 /* Both static and dynamic allocation can be used, so note that
113 * this event group was created statically in case the event group
114 * is later deleted. */
115 pxEventBits->ucStaticallyAllocated = pdTRUE;
117 #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
119 traceEVENT_GROUP_CREATE( pxEventBits );
123 /* xEventGroupCreateStatic should only ever be called with
124 * pxEventGroupBuffer pointing to a pre-allocated (compile time
125 * allocated) StaticEventGroup_t variable. */
126 traceEVENT_GROUP_CREATE_FAILED();
129 traceRETURN_xEventGroupCreateStatic( pxEventBits );
134 #endif /* configSUPPORT_STATIC_ALLOCATION */
135 /*-----------------------------------------------------------*/
137 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
139 EventGroupHandle_t xEventGroupCreate( void )
141 EventGroup_t * pxEventBits;
143 traceENTER_xEventGroupCreate();
145 /* MISRA Ref 11.5.1 [Malloc memory assignment] */
146 /* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-115 */
147 /* coverity[misra_c_2012_rule_11_5_violation] */
148 pxEventBits = ( EventGroup_t * ) pvPortMalloc( sizeof( EventGroup_t ) );
150 if( pxEventBits != NULL )
152 pxEventBits->uxEventBits = 0;
153 vListInitialise( &( pxEventBits->xTasksWaitingForBits ) );
155 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
157 /* Both static and dynamic allocation can be used, so note this
158 * event group was allocated statically in case the event group is
160 pxEventBits->ucStaticallyAllocated = pdFALSE;
162 #endif /* configSUPPORT_STATIC_ALLOCATION */
164 traceEVENT_GROUP_CREATE( pxEventBits );
168 traceEVENT_GROUP_CREATE_FAILED();
171 traceRETURN_xEventGroupCreate( pxEventBits );
176 #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
177 /*-----------------------------------------------------------*/
179 EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup,
180 const EventBits_t uxBitsToSet,
181 const EventBits_t uxBitsToWaitFor,
182 TickType_t xTicksToWait )
184 EventBits_t uxOriginalBitValue, uxReturn;
185 EventGroup_t * pxEventBits = xEventGroup;
186 BaseType_t xAlreadyYielded;
187 BaseType_t xTimeoutOccurred = pdFALSE;
189 traceENTER_xEventGroupSync( xEventGroup, uxBitsToSet, uxBitsToWaitFor, xTicksToWait );
191 configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
192 configASSERT( uxBitsToWaitFor != 0 );
193 #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
195 configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
201 uxOriginalBitValue = pxEventBits->uxEventBits;
203 ( void ) xEventGroupSetBits( xEventGroup, uxBitsToSet );
205 if( ( ( uxOriginalBitValue | uxBitsToSet ) & uxBitsToWaitFor ) == uxBitsToWaitFor )
207 /* All the rendezvous bits are now set - no need to block. */
208 uxReturn = ( uxOriginalBitValue | uxBitsToSet );
210 /* Rendezvous always clear the bits. They will have been cleared
211 * already unless this is the only task in the rendezvous. */
212 pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
218 if( xTicksToWait != ( TickType_t ) 0 )
220 traceEVENT_GROUP_SYNC_BLOCK( xEventGroup, uxBitsToSet, uxBitsToWaitFor );
222 /* Store the bits that the calling task is waiting for in the
223 * task's event list item so the kernel knows when a match is
224 * found. Then enter the blocked state. */
225 vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | eventCLEAR_EVENTS_ON_EXIT_BIT | eventWAIT_FOR_ALL_BITS ), xTicksToWait );
227 /* This assignment is obsolete as uxReturn will get set after
228 * the task unblocks, but some compilers mistakenly generate a
229 * warning about uxReturn being returned without being set if the
230 * assignment is omitted. */
235 /* The rendezvous bits were not set, but no block time was
236 * specified - just return the current event bit value. */
237 uxReturn = pxEventBits->uxEventBits;
238 xTimeoutOccurred = pdTRUE;
242 xAlreadyYielded = xTaskResumeAll();
244 if( xTicksToWait != ( TickType_t ) 0 )
246 if( xAlreadyYielded == pdFALSE )
248 taskYIELD_WITHIN_API();
252 mtCOVERAGE_TEST_MARKER();
255 /* The task blocked to wait for its required bits to be set - at this
256 * point either the required bits were set or the block time expired. If
257 * the required bits were set they will have been stored in the task's
258 * event list item, and they should now be retrieved then cleared. */
259 uxReturn = uxTaskResetEventItemValue();
261 if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 )
263 /* The task timed out, just return the current event bit value. */
264 taskENTER_CRITICAL();
266 uxReturn = pxEventBits->uxEventBits;
268 /* Although the task got here because it timed out before the
269 * bits it was waiting for were set, it is possible that since it
270 * unblocked another task has set the bits. If this is the case
271 * then it needs to clear the bits before exiting. */
272 if( ( uxReturn & uxBitsToWaitFor ) == uxBitsToWaitFor )
274 pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
278 mtCOVERAGE_TEST_MARKER();
283 xTimeoutOccurred = pdTRUE;
287 /* The task unblocked because the bits were set. */
290 /* Control bits might be set as the task had blocked should not be
292 uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;
295 traceEVENT_GROUP_SYNC_END( xEventGroup, uxBitsToSet, uxBitsToWaitFor, xTimeoutOccurred );
297 /* Prevent compiler warnings when trace macros are not used. */
298 ( void ) xTimeoutOccurred;
300 traceRETURN_xEventGroupSync( uxReturn );
304 /*-----------------------------------------------------------*/
306 EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup,
307 const EventBits_t uxBitsToWaitFor,
308 const BaseType_t xClearOnExit,
309 const BaseType_t xWaitForAllBits,
310 TickType_t xTicksToWait )
312 EventGroup_t * pxEventBits = xEventGroup;
313 EventBits_t uxReturn, uxControlBits = 0;
314 BaseType_t xWaitConditionMet, xAlreadyYielded;
315 BaseType_t xTimeoutOccurred = pdFALSE;
317 traceENTER_xEventGroupWaitBits( xEventGroup, uxBitsToWaitFor, xClearOnExit, xWaitForAllBits, xTicksToWait );
319 /* Check the user is not attempting to wait on the bits used by the kernel
320 * itself, and that at least one bit is being requested. */
321 configASSERT( xEventGroup );
322 configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
323 configASSERT( uxBitsToWaitFor != 0 );
324 #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
326 configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
332 const EventBits_t uxCurrentEventBits = pxEventBits->uxEventBits;
334 /* Check to see if the wait condition is already met or not. */
335 xWaitConditionMet = prvTestWaitCondition( uxCurrentEventBits, uxBitsToWaitFor, xWaitForAllBits );
337 if( xWaitConditionMet != pdFALSE )
339 /* The wait condition has already been met so there is no need to
341 uxReturn = uxCurrentEventBits;
342 xTicksToWait = ( TickType_t ) 0;
344 /* Clear the wait bits if requested to do so. */
345 if( xClearOnExit != pdFALSE )
347 pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
351 mtCOVERAGE_TEST_MARKER();
354 else if( xTicksToWait == ( TickType_t ) 0 )
356 /* The wait condition has not been met, but no block time was
357 * specified, so just return the current value. */
358 uxReturn = uxCurrentEventBits;
359 xTimeoutOccurred = pdTRUE;
363 /* The task is going to block to wait for its required bits to be
364 * set. uxControlBits are used to remember the specified behaviour of
365 * this call to xEventGroupWaitBits() - for use when the event bits
366 * unblock the task. */
367 if( xClearOnExit != pdFALSE )
369 uxControlBits |= eventCLEAR_EVENTS_ON_EXIT_BIT;
373 mtCOVERAGE_TEST_MARKER();
376 if( xWaitForAllBits != pdFALSE )
378 uxControlBits |= eventWAIT_FOR_ALL_BITS;
382 mtCOVERAGE_TEST_MARKER();
385 /* Store the bits that the calling task is waiting for in the
386 * task's event list item so the kernel knows when a match is
387 * found. Then enter the blocked state. */
388 vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | uxControlBits ), xTicksToWait );
390 /* This is obsolete as it will get set after the task unblocks, but
391 * some compilers mistakenly generate a warning about the variable
392 * being returned without being set if it is not done. */
395 traceEVENT_GROUP_WAIT_BITS_BLOCK( xEventGroup, uxBitsToWaitFor );
398 xAlreadyYielded = xTaskResumeAll();
400 if( xTicksToWait != ( TickType_t ) 0 )
402 if( xAlreadyYielded == pdFALSE )
404 taskYIELD_WITHIN_API();
408 mtCOVERAGE_TEST_MARKER();
411 /* The task blocked to wait for its required bits to be set - at this
412 * point either the required bits were set or the block time expired. If
413 * the required bits were set they will have been stored in the task's
414 * event list item, and they should now be retrieved then cleared. */
415 uxReturn = uxTaskResetEventItemValue();
417 if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 )
419 taskENTER_CRITICAL();
421 /* The task timed out, just return the current event bit value. */
422 uxReturn = pxEventBits->uxEventBits;
424 /* It is possible that the event bits were updated between this
425 * task leaving the Blocked state and running again. */
426 if( prvTestWaitCondition( uxReturn, uxBitsToWaitFor, xWaitForAllBits ) != pdFALSE )
428 if( xClearOnExit != pdFALSE )
430 pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
434 mtCOVERAGE_TEST_MARKER();
439 mtCOVERAGE_TEST_MARKER();
442 xTimeoutOccurred = pdTRUE;
448 /* The task unblocked because the bits were set. */
451 /* The task blocked so control bits may have been set. */
452 uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;
455 traceEVENT_GROUP_WAIT_BITS_END( xEventGroup, uxBitsToWaitFor, xTimeoutOccurred );
457 /* Prevent compiler warnings when trace macros are not used. */
458 ( void ) xTimeoutOccurred;
460 traceRETURN_xEventGroupWaitBits( uxReturn );
464 /*-----------------------------------------------------------*/
466 EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup,
467 const EventBits_t uxBitsToClear )
469 EventGroup_t * pxEventBits = xEventGroup;
470 EventBits_t uxReturn;
472 traceENTER_xEventGroupClearBits( xEventGroup, uxBitsToClear );
474 /* Check the user is not attempting to clear the bits used by the kernel
476 configASSERT( xEventGroup );
477 configASSERT( ( uxBitsToClear & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
479 taskENTER_CRITICAL();
481 traceEVENT_GROUP_CLEAR_BITS( xEventGroup, uxBitsToClear );
483 /* The value returned is the event group value prior to the bits being
485 uxReturn = pxEventBits->uxEventBits;
487 /* Clear the bits. */
488 pxEventBits->uxEventBits &= ~uxBitsToClear;
492 traceRETURN_xEventGroupClearBits( uxReturn );
496 /*-----------------------------------------------------------*/
498 #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) )
500 BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup,
501 const EventBits_t uxBitsToClear )
505 traceENTER_xEventGroupClearBitsFromISR( xEventGroup, uxBitsToClear );
507 traceEVENT_GROUP_CLEAR_BITS_FROM_ISR( xEventGroup, uxBitsToClear );
508 xReturn = xTimerPendFunctionCallFromISR( vEventGroupClearBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToClear, NULL );
510 traceRETURN_xEventGroupClearBitsFromISR( xReturn );
515 #endif /* if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) ) */
516 /*-----------------------------------------------------------*/
518 EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup )
520 UBaseType_t uxSavedInterruptStatus;
521 EventGroup_t const * const pxEventBits = xEventGroup;
522 EventBits_t uxReturn;
524 traceENTER_xEventGroupGetBitsFromISR( xEventGroup );
526 uxSavedInterruptStatus = taskENTER_CRITICAL_FROM_ISR();
528 uxReturn = pxEventBits->uxEventBits;
530 taskEXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus );
532 traceRETURN_xEventGroupGetBitsFromISR( uxReturn );
536 /*-----------------------------------------------------------*/
538 EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup,
539 const EventBits_t uxBitsToSet )
541 ListItem_t * pxListItem;
543 ListItem_t const * pxListEnd;
544 List_t const * pxList;
545 EventBits_t uxBitsToClear = 0, uxBitsWaitedFor, uxControlBits;
546 EventGroup_t * pxEventBits = xEventGroup;
547 BaseType_t xMatchFound = pdFALSE;
549 traceENTER_xEventGroupSetBits( xEventGroup, uxBitsToSet );
551 /* Check the user is not attempting to set the bits used by the kernel
553 configASSERT( xEventGroup );
554 configASSERT( ( uxBitsToSet & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
556 pxList = &( pxEventBits->xTasksWaitingForBits );
557 pxListEnd = listGET_END_MARKER( pxList );
560 traceEVENT_GROUP_SET_BITS( xEventGroup, uxBitsToSet );
562 pxListItem = listGET_HEAD_ENTRY( pxList );
565 pxEventBits->uxEventBits |= uxBitsToSet;
567 /* See if the new bit value should unblock any tasks. */
568 while( pxListItem != pxListEnd )
570 pxNext = listGET_NEXT( pxListItem );
571 uxBitsWaitedFor = listGET_LIST_ITEM_VALUE( pxListItem );
572 xMatchFound = pdFALSE;
574 /* Split the bits waited for from the control bits. */
575 uxControlBits = uxBitsWaitedFor & eventEVENT_BITS_CONTROL_BYTES;
576 uxBitsWaitedFor &= ~eventEVENT_BITS_CONTROL_BYTES;
578 if( ( uxControlBits & eventWAIT_FOR_ALL_BITS ) == ( EventBits_t ) 0 )
580 /* Just looking for single bit being set. */
581 if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) != ( EventBits_t ) 0 )
583 xMatchFound = pdTRUE;
587 mtCOVERAGE_TEST_MARKER();
590 else if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) == uxBitsWaitedFor )
592 /* All bits are set. */
593 xMatchFound = pdTRUE;
597 /* Need all bits to be set, but not all the bits were set. */
600 if( xMatchFound != pdFALSE )
602 /* The bits match. Should the bits be cleared on exit? */
603 if( ( uxControlBits & eventCLEAR_EVENTS_ON_EXIT_BIT ) != ( EventBits_t ) 0 )
605 uxBitsToClear |= uxBitsWaitedFor;
609 mtCOVERAGE_TEST_MARKER();
612 /* Store the actual event flag value in the task's event list
613 * item before removing the task from the event list. The
614 * eventUNBLOCKED_DUE_TO_BIT_SET bit is set so the task knows
615 * that is was unblocked due to its required bits matching, rather
616 * than because it timed out. */
617 vTaskRemoveFromUnorderedEventList( pxListItem, pxEventBits->uxEventBits | eventUNBLOCKED_DUE_TO_BIT_SET );
620 /* Move onto the next list item. Note pxListItem->pxNext is not
621 * used here as the list item may have been removed from the event list
622 * and inserted into the ready/pending reading list. */
626 /* Clear any bits that matched when the eventCLEAR_EVENTS_ON_EXIT_BIT
627 * bit was set in the control word. */
628 pxEventBits->uxEventBits &= ~uxBitsToClear;
630 ( void ) xTaskResumeAll();
632 traceRETURN_xEventGroupSetBits( pxEventBits->uxEventBits );
634 return pxEventBits->uxEventBits;
636 /*-----------------------------------------------------------*/
638 void vEventGroupDelete( EventGroupHandle_t xEventGroup )
640 EventGroup_t * pxEventBits = xEventGroup;
641 const List_t * pxTasksWaitingForBits;
643 traceENTER_vEventGroupDelete( xEventGroup );
645 configASSERT( pxEventBits );
647 pxTasksWaitingForBits = &( pxEventBits->xTasksWaitingForBits );
651 traceEVENT_GROUP_DELETE( xEventGroup );
653 while( listCURRENT_LIST_LENGTH( pxTasksWaitingForBits ) > ( UBaseType_t ) 0 )
655 /* Unblock the task, returning 0 as the event list is being deleted
656 * and cannot therefore have any bits set. */
657 configASSERT( pxTasksWaitingForBits->xListEnd.pxNext != ( const ListItem_t * ) &( pxTasksWaitingForBits->xListEnd ) );
658 vTaskRemoveFromUnorderedEventList( pxTasksWaitingForBits->xListEnd.pxNext, eventUNBLOCKED_DUE_TO_BIT_SET );
661 ( void ) xTaskResumeAll();
663 #if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) )
665 /* The event group can only have been allocated dynamically - free
667 vPortFree( pxEventBits );
669 #elif ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
671 /* The event group could have been allocated statically or
672 * dynamically, so check before attempting to free the memory. */
673 if( pxEventBits->ucStaticallyAllocated == ( uint8_t ) pdFALSE )
675 vPortFree( pxEventBits );
679 mtCOVERAGE_TEST_MARKER();
682 #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
684 traceRETURN_vEventGroupDelete();
686 /*-----------------------------------------------------------*/
688 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
689 BaseType_t xEventGroupGetStaticBuffer( EventGroupHandle_t xEventGroup,
690 StaticEventGroup_t ** ppxEventGroupBuffer )
693 EventGroup_t * pxEventBits = xEventGroup;
695 traceENTER_xEventGroupGetStaticBuffer( xEventGroup, ppxEventGroupBuffer );
697 configASSERT( pxEventBits );
698 configASSERT( ppxEventGroupBuffer );
700 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
702 /* Check if the event group was statically allocated. */
703 if( pxEventBits->ucStaticallyAllocated == ( uint8_t ) pdTRUE )
705 /* MISRA Ref 11.3.1 [Misaligned access] */
706 /* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
707 /* coverity[misra_c_2012_rule_11_3_violation] */
708 *ppxEventGroupBuffer = ( StaticEventGroup_t * ) pxEventBits;
716 #else /* configSUPPORT_DYNAMIC_ALLOCATION */
718 /* Event group must have been statically allocated. */
719 /* MISRA Ref 11.3.1 [Misaligned access] */
720 /* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-113 */
721 /* coverity[misra_c_2012_rule_11_3_violation] */
722 *ppxEventGroupBuffer = ( StaticEventGroup_t * ) pxEventBits;
725 #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
727 traceRETURN_xEventGroupGetStaticBuffer( xReturn );
731 #endif /* configSUPPORT_STATIC_ALLOCATION */
732 /*-----------------------------------------------------------*/
734 /* For internal use only - execute a 'set bits' command that was pended from
736 void vEventGroupSetBitsCallback( void * pvEventGroup,
737 uint32_t ulBitsToSet )
739 traceENTER_vEventGroupSetBitsCallback( pvEventGroup, ulBitsToSet );
741 /* MISRA Ref 11.5.4 [Callback function parameter] */
742 /* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-115 */
743 /* coverity[misra_c_2012_rule_11_5_violation] */
744 ( void ) xEventGroupSetBits( pvEventGroup, ( EventBits_t ) ulBitsToSet );
746 traceRETURN_vEventGroupSetBitsCallback();
748 /*-----------------------------------------------------------*/
750 /* For internal use only - execute a 'clear bits' command that was pended from
752 void vEventGroupClearBitsCallback( void * pvEventGroup,
753 uint32_t ulBitsToClear )
755 traceENTER_vEventGroupClearBitsCallback( pvEventGroup, ulBitsToClear );
757 /* MISRA Ref 11.5.4 [Callback function parameter] */
758 /* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-115 */
759 /* coverity[misra_c_2012_rule_11_5_violation] */
760 ( void ) xEventGroupClearBits( pvEventGroup, ( EventBits_t ) ulBitsToClear );
762 traceRETURN_vEventGroupClearBitsCallback();
764 /*-----------------------------------------------------------*/
766 static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits,
767 const EventBits_t uxBitsToWaitFor,
768 const BaseType_t xWaitForAllBits )
770 BaseType_t xWaitConditionMet = pdFALSE;
772 if( xWaitForAllBits == pdFALSE )
774 /* Task only has to wait for one bit within uxBitsToWaitFor to be
775 * set. Is one already set? */
776 if( ( uxCurrentEventBits & uxBitsToWaitFor ) != ( EventBits_t ) 0 )
778 xWaitConditionMet = pdTRUE;
782 mtCOVERAGE_TEST_MARKER();
787 /* Task has to wait for all the bits in uxBitsToWaitFor to be set.
788 * Are they set already? */
789 if( ( uxCurrentEventBits & uxBitsToWaitFor ) == uxBitsToWaitFor )
791 xWaitConditionMet = pdTRUE;
795 mtCOVERAGE_TEST_MARKER();
799 return xWaitConditionMet;
801 /*-----------------------------------------------------------*/
803 #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) )
805 BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup,
806 const EventBits_t uxBitsToSet,
807 BaseType_t * pxHigherPriorityTaskWoken )
811 traceENTER_xEventGroupSetBitsFromISR( xEventGroup, uxBitsToSet, pxHigherPriorityTaskWoken );
813 traceEVENT_GROUP_SET_BITS_FROM_ISR( xEventGroup, uxBitsToSet );
814 xReturn = xTimerPendFunctionCallFromISR( vEventGroupSetBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToSet, pxHigherPriorityTaskWoken );
816 traceRETURN_xEventGroupSetBitsFromISR( xReturn );
821 #endif /* if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) ) */
822 /*-----------------------------------------------------------*/
824 #if ( configUSE_TRACE_FACILITY == 1 )
826 UBaseType_t uxEventGroupGetNumber( void * xEventGroup )
830 /* MISRA Ref 11.5.2 [Opaque pointer] */
831 /* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-115 */
832 /* coverity[misra_c_2012_rule_11_5_violation] */
833 EventGroup_t const * pxEventBits = ( EventGroup_t * ) xEventGroup;
835 traceENTER_uxEventGroupGetNumber( xEventGroup );
837 if( xEventGroup == NULL )
843 xReturn = pxEventBits->uxEventGroupNumber;
846 traceRETURN_uxEventGroupGetNumber( xReturn );
851 #endif /* configUSE_TRACE_FACILITY */
852 /*-----------------------------------------------------------*/
854 #if ( configUSE_TRACE_FACILITY == 1 )
856 void vEventGroupSetNumber( void * xEventGroup,
857 UBaseType_t uxEventGroupNumber )
859 traceENTER_vEventGroupSetNumber( xEventGroup, uxEventGroupNumber );
861 /* MISRA Ref 11.5.2 [Opaque pointer] */
862 /* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-115 */
863 /* coverity[misra_c_2012_rule_11_5_violation] */
864 ( ( EventGroup_t * ) xEventGroup )->uxEventGroupNumber = uxEventGroupNumber;
866 traceRETURN_vEventGroupSetNumber();
869 #endif /* configUSE_TRACE_FACILITY */
870 /*-----------------------------------------------------------*/