2 FreeRTOS V8.2.1 - Copyright (C) 2015 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\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
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
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
25 ***************************************************************************
\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
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
37 ***************************************************************************
\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
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
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
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
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
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
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
70 #ifndef EVENT_GROUPS_H
\r
71 #define EVENT_GROUPS_H
\r
73 #ifndef INC_FREERTOS_H
\r
74 #error "include FreeRTOS.h" must appear in source files before "include event_groups.h"
\r
84 * An event group is a collection of bits to which an application can assign a
\r
85 * meaning. For example, an application may create an event group to convey
\r
86 * the status of various CAN bus related events in which bit 0 might mean "A CAN
\r
87 * message has been received and is ready for processing", bit 1 might mean "The
\r
88 * application has queued a message that is ready for sending onto the CAN
\r
89 * network", and bit 2 might mean "It is time to send a SYNC message onto the
\r
90 * CAN network" etc. A task can then test the bit values to see which events
\r
91 * are active, and optionally enter the Blocked state to wait for a specified
\r
92 * bit or a group of specified bits to be active. To continue the CAN bus
\r
93 * example, a CAN controlling task can enter the Blocked state (and therefore
\r
94 * not consume any processing time) until either bit 0, bit 1 or bit 2 are
\r
95 * active, at which time the bit that was actually active would inform the task
\r
96 * which action it had to take (process a received message, send a message, or
\r
99 * The event groups implementation contains intelligence to avoid race
\r
100 * conditions that would otherwise occur were an application to use a simple
\r
101 * variable for the same purpose. This is particularly important with respect
\r
102 * to when a bit within an event group is to be cleared, and when bits have to
\r
103 * be set and then tested atomically - as is the case where event groups are
\r
104 * used to create a synchronisation point between multiple tasks (a
\r
107 * \defgroup EventGroup
\r
115 * Type by which event groups are referenced. For example, a call to
\r
116 * xEventGroupCreate() returns an EventGroupHandle_t variable that can then
\r
117 * be used as a parameter to other event group functions.
\r
119 * \defgroup EventGroupHandle_t EventGroupHandle_t
\r
120 * \ingroup EventGroup
\r
122 typedef void * EventGroupHandle_t;
\r
125 * The type that holds event bits always matches TickType_t - therefore the
\r
126 * number of bits it holds is set by configUSE_16_BIT_TICKS (16 bits if set to 1,
\r
127 * 32 bits if set to 0.
\r
129 * \defgroup EventBits_t EventBits_t
\r
130 * \ingroup EventGroup
\r
132 typedef TickType_t EventBits_t;
\r
137 EventGroupHandle_t xEventGroupCreate( void );
\r
140 * Create a new event group. This function cannot be called from an interrupt.
\r
142 * Although event groups are not related to ticks, for internal implementation
\r
143 * reasons the number of bits available for use in an event group is dependent
\r
144 * on the configUSE_16_BIT_TICKS setting in FreeRTOSConfig.h. If
\r
145 * configUSE_16_BIT_TICKS is 1 then each event group contains 8 usable bits (bit
\r
146 * 0 to bit 7). If configUSE_16_BIT_TICKS is set to 0 then each event group has
\r
147 * 24 usable bits (bit 0 to bit 23). The EventBits_t type is used to store
\r
148 * event bits within an event group.
\r
150 * @return If the event group was created then a handle to the event group is
\r
151 * returned. If there was insufficient FreeRTOS heap available to create the
\r
152 * event group then NULL is returned. See http://www.freertos.org/a00111.html
\r
156 // Declare a variable to hold the created event group.
\r
157 EventGroupHandle_t xCreatedEventGroup;
\r
159 // Attempt to create the event group.
\r
160 xCreatedEventGroup = xEventGroupCreate();
\r
162 // Was the event group created successfully?
\r
163 if( xCreatedEventGroup == NULL )
\r
165 // The event group was not created because there was insufficient
\r
166 // FreeRTOS heap available.
\r
170 // The event group was created.
\r
173 * \defgroup xEventGroupCreate xEventGroupCreate
\r
174 * \ingroup EventGroup
\r
176 EventGroupHandle_t xEventGroupCreate( void ) PRIVILEGED_FUNCTION;
\r
181 EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup,
\r
182 const EventBits_t uxBitsToWaitFor,
\r
183 const BaseType_t xClearOnExit,
\r
184 const BaseType_t xWaitForAllBits,
\r
185 const TickType_t xTicksToWait );
\r
188 * [Potentially] block to wait for one or more bits to be set within a
\r
189 * previously created event group.
\r
191 * This function cannot be called from an interrupt.
\r
193 * @param xEventGroup The event group in which the bits are being tested. The
\r
194 * event group must have previously been created using a call to
\r
195 * xEventGroupCreate().
\r
197 * @param uxBitsToWaitFor A bitwise value that indicates the bit or bits to test
\r
198 * inside the event group. For example, to wait for bit 0 and/or bit 2 set
\r
199 * uxBitsToWaitFor to 0x05. To wait for bits 0 and/or bit 1 and/or bit 2 set
\r
200 * uxBitsToWaitFor to 0x07. Etc.
\r
202 * @param xClearOnExit If xClearOnExit is set to pdTRUE then any bits within
\r
203 * uxBitsToWaitFor that are set within the event group will be cleared before
\r
204 * xEventGroupWaitBits() returns if the wait condition was met (if the function
\r
205 * returns for a reason other than a timeout). If xClearOnExit is set to
\r
206 * pdFALSE then the bits set in the event group are not altered when the call to
\r
207 * xEventGroupWaitBits() returns.
\r
209 * @param xWaitForAllBits If xWaitForAllBits is set to pdTRUE then
\r
210 * xEventGroupWaitBits() will return when either all the bits in uxBitsToWaitFor
\r
211 * are set or the specified block time expires. If xWaitForAllBits is set to
\r
212 * pdFALSE then xEventGroupWaitBits() will return when any one of the bits set
\r
213 * in uxBitsToWaitFor is set or the specified block time expires. The block
\r
214 * time is specified by the xTicksToWait parameter.
\r
216 * @param xTicksToWait The maximum amount of time (specified in 'ticks') to wait
\r
217 * for one/all (depending on the xWaitForAllBits value) of the bits specified by
\r
218 * uxBitsToWaitFor to become set.
\r
220 * @return The value of the event group at the time either the bits being waited
\r
221 * for became set, or the block time expired. Test the return value to know
\r
222 * which bits were set. If xEventGroupWaitBits() returned because its timeout
\r
223 * expired then not all the bits being waited for will be set. If
\r
224 * xEventGroupWaitBits() returned because the bits it was waiting for were set
\r
225 * then the returned value is the event group value before any bits were
\r
226 * automatically cleared in the case that xClearOnExit parameter was set to
\r
231 #define BIT_0 ( 1 << 0 )
\r
232 #define BIT_4 ( 1 << 4 )
\r
234 void aFunction( EventGroupHandle_t xEventGroup )
\r
236 EventBits_t uxBits;
\r
237 const TickType_t xTicksToWait = 100 / portTICK_PERIOD_MS;
\r
239 // Wait a maximum of 100ms for either bit 0 or bit 4 to be set within
\r
240 // the event group. Clear the bits before exiting.
\r
241 uxBits = xEventGroupWaitBits(
\r
242 xEventGroup, // The event group being tested.
\r
243 BIT_0 | BIT_4, // The bits within the event group to wait for.
\r
244 pdTRUE, // BIT_0 and BIT_4 should be cleared before returning.
\r
245 pdFALSE, // Don't wait for both bits, either bit will do.
\r
246 xTicksToWait ); // Wait a maximum of 100ms for either bit to be set.
\r
248 if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
\r
250 // xEventGroupWaitBits() returned because both bits were set.
\r
252 else if( ( uxBits & BIT_0 ) != 0 )
\r
254 // xEventGroupWaitBits() returned because just BIT_0 was set.
\r
256 else if( ( uxBits & BIT_4 ) != 0 )
\r
258 // xEventGroupWaitBits() returned because just BIT_4 was set.
\r
262 // xEventGroupWaitBits() returned because xTicksToWait ticks passed
\r
263 // without either BIT_0 or BIT_4 becoming set.
\r
267 * \defgroup xEventGroupWaitBits xEventGroupWaitBits
\r
268 * \ingroup EventGroup
\r
270 EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToWaitFor, const BaseType_t xClearOnExit, const BaseType_t xWaitForAllBits, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
\r
275 EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear );
\r
278 * Clear bits within an event group. This function cannot be called from an
\r
281 * @param xEventGroup The event group in which the bits are to be cleared.
\r
283 * @param uxBitsToClear A bitwise value that indicates the bit or bits to clear
\r
284 * in the event group. For example, to clear bit 3 only, set uxBitsToClear to
\r
285 * 0x08. To clear bit 3 and bit 0 set uxBitsToClear to 0x09.
\r
287 * @return The value of the event group before the specified bits were cleared.
\r
291 #define BIT_0 ( 1 << 0 )
\r
292 #define BIT_4 ( 1 << 4 )
\r
294 void aFunction( EventGroupHandle_t xEventGroup )
\r
296 EventBits_t uxBits;
\r
298 // Clear bit 0 and bit 4 in xEventGroup.
\r
299 uxBits = xEventGroupClearBits(
\r
300 xEventGroup, // The event group being updated.
\r
301 BIT_0 | BIT_4 );// The bits being cleared.
\r
303 if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
\r
305 // Both bit 0 and bit 4 were set before xEventGroupClearBits() was
\r
306 // called. Both will now be clear (not set).
\r
308 else if( ( uxBits & BIT_0 ) != 0 )
\r
310 // Bit 0 was set before xEventGroupClearBits() was called. It will
\r
313 else if( ( uxBits & BIT_4 ) != 0 )
\r
315 // Bit 4 was set before xEventGroupClearBits() was called. It will
\r
320 // Neither bit 0 nor bit 4 were set in the first place.
\r
324 * \defgroup xEventGroupClearBits xEventGroupClearBits
\r
325 * \ingroup EventGroup
\r
327 EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear ) PRIVILEGED_FUNCTION;
\r
332 BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet );
\r
335 * A version of xEventGroupClearBits() that can be called from an interrupt.
\r
337 * Setting bits in an event group is not a deterministic operation because there
\r
338 * are an unknown number of tasks that may be waiting for the bit or bits being
\r
339 * set. FreeRTOS does not allow nondeterministic operations to be performed
\r
340 * while interrupts are disabled, so protects event groups that are accessed
\r
341 * from tasks by suspending the scheduler rather than disabling interrupts. As
\r
342 * a result event groups cannot be accessed directly from an interrupt service
\r
343 * routine. Therefore xEventGroupClearBitsFromISR() sends a message to the
\r
344 * timer task to have the clear operation performed in the context of the timer
\r
347 * @param xEventGroup The event group in which the bits are to be cleared.
\r
349 * @param uxBitsToClear A bitwise value that indicates the bit or bits to clear.
\r
350 * For example, to clear bit 3 only, set uxBitsToClear to 0x08. To clear bit 3
\r
351 * and bit 0 set uxBitsToClear to 0x09.
\r
353 * @return If the request to execute the function was posted successfully then
\r
354 * pdPASS is returned, otherwise pdFALSE is returned. pdFALSE will be returned
\r
355 * if the timer service queue was full.
\r
359 #define BIT_0 ( 1 << 0 )
\r
360 #define BIT_4 ( 1 << 4 )
\r
362 // An event group which it is assumed has already been created by a call to
\r
363 // xEventGroupCreate().
\r
364 EventGroupHandle_t xEventGroup;
\r
366 void anInterruptHandler( void )
\r
368 // Clear bit 0 and bit 4 in xEventGroup.
\r
369 xResult = xEventGroupClearBitsFromISR(
\r
370 xEventGroup, // The event group being updated.
\r
371 BIT_0 | BIT_4 ); // The bits being set.
\r
373 if( xResult == pdPASS )
\r
375 // The message was posted successfully.
\r
379 * \defgroup xEventGroupSetBitsFromISR xEventGroupSetBitsFromISR
\r
380 * \ingroup EventGroup
\r
382 #if( configUSE_TRACE_FACILITY == 1 )
\r
383 BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet ) PRIVILEGED_FUNCTION;
\r
385 #define xEventGroupClearBitsFromISR( xEventGroup, uxBitsToClear ) xTimerPendFunctionCallFromISR( vEventGroupClearBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToClear, NULL )
\r
391 EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet );
\r
394 * Set bits within an event group.
\r
395 * This function cannot be called from an interrupt. xEventGroupSetBitsFromISR()
\r
396 * is a version that can be called from an interrupt.
\r
398 * Setting bits in an event group will automatically unblock tasks that are
\r
399 * blocked waiting for the bits.
\r
401 * @param xEventGroup The event group in which the bits are to be set.
\r
403 * @param uxBitsToSet A bitwise value that indicates the bit or bits to set.
\r
404 * For example, to set bit 3 only, set uxBitsToSet to 0x08. To set bit 3
\r
405 * and bit 0 set uxBitsToSet to 0x09.
\r
407 * @return The value of the event group at the time the call to
\r
408 * xEventGroupSetBits() returns. There are two reasons why the returned value
\r
409 * might have the bits specified by the uxBitsToSet parameter cleared. First,
\r
410 * if setting a bit results in a task that was waiting for the bit leaving the
\r
411 * blocked state then it is possible the bit will be cleared automatically
\r
412 * (see the xClearBitOnExit parameter of xEventGroupWaitBits()). Second, any
\r
413 * unblocked (or otherwise Ready state) task that has a priority above that of
\r
414 * the task that called xEventGroupSetBits() will execute and may change the
\r
415 * event group value before the call to xEventGroupSetBits() returns.
\r
419 #define BIT_0 ( 1 << 0 )
\r
420 #define BIT_4 ( 1 << 4 )
\r
422 void aFunction( EventGroupHandle_t xEventGroup )
\r
424 EventBits_t uxBits;
\r
426 // Set bit 0 and bit 4 in xEventGroup.
\r
427 uxBits = xEventGroupSetBits(
\r
428 xEventGroup, // The event group being updated.
\r
429 BIT_0 | BIT_4 );// The bits being set.
\r
431 if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
\r
433 // Both bit 0 and bit 4 remained set when the function returned.
\r
435 else if( ( uxBits & BIT_0 ) != 0 )
\r
437 // Bit 0 remained set when the function returned, but bit 4 was
\r
438 // cleared. It might be that bit 4 was cleared automatically as a
\r
439 // task that was waiting for bit 4 was removed from the Blocked
\r
442 else if( ( uxBits & BIT_4 ) != 0 )
\r
444 // Bit 4 remained set when the function returned, but bit 0 was
\r
445 // cleared. It might be that bit 0 was cleared automatically as a
\r
446 // task that was waiting for bit 0 was removed from the Blocked
\r
451 // Neither bit 0 nor bit 4 remained set. It might be that a task
\r
452 // was waiting for both of the bits to be set, and the bits were
\r
453 // cleared as the task left the Blocked state.
\r
457 * \defgroup xEventGroupSetBits xEventGroupSetBits
\r
458 * \ingroup EventGroup
\r
460 EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet ) PRIVILEGED_FUNCTION;
\r
465 BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken );
\r
468 * A version of xEventGroupSetBits() that can be called from an interrupt.
\r
470 * Setting bits in an event group is not a deterministic operation because there
\r
471 * are an unknown number of tasks that may be waiting for the bit or bits being
\r
472 * set. FreeRTOS does not allow nondeterministic operations to be performed in
\r
473 * interrupts or from critical sections. Therefore xEventGroupSetBitFromISR()
\r
474 * sends a message to the timer task to have the set operation performed in the
\r
475 * context of the timer task - where a scheduler lock is used in place of a
\r
476 * critical section.
\r
478 * @param xEventGroup The event group in which the bits are to be set.
\r
480 * @param uxBitsToSet A bitwise value that indicates the bit or bits to set.
\r
481 * For example, to set bit 3 only, set uxBitsToSet to 0x08. To set bit 3
\r
482 * and bit 0 set uxBitsToSet to 0x09.
\r
484 * @param pxHigherPriorityTaskWoken As mentioned above, calling this function
\r
485 * will result in a message being sent to the timer daemon task. If the
\r
486 * priority of the timer daemon task is higher than the priority of the
\r
487 * currently running task (the task the interrupt interrupted) then
\r
488 * *pxHigherPriorityTaskWoken will be set to pdTRUE by
\r
489 * xEventGroupSetBitsFromISR(), indicating that a context switch should be
\r
490 * requested before the interrupt exits. For that reason
\r
491 * *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the
\r
492 * example code below.
\r
494 * @return If the request to execute the function was posted successfully then
\r
495 * pdPASS is returned, otherwise pdFALSE is returned. pdFALSE will be returned
\r
496 * if the timer service queue was full.
\r
500 #define BIT_0 ( 1 << 0 )
\r
501 #define BIT_4 ( 1 << 4 )
\r
503 // An event group which it is assumed has already been created by a call to
\r
504 // xEventGroupCreate().
\r
505 EventGroupHandle_t xEventGroup;
\r
507 void anInterruptHandler( void )
\r
509 BaseType_t xHigherPriorityTaskWoken, xResult;
\r
511 // xHigherPriorityTaskWoken must be initialised to pdFALSE.
\r
512 xHigherPriorityTaskWoken = pdFALSE;
\r
514 // Set bit 0 and bit 4 in xEventGroup.
\r
515 xResult = xEventGroupSetBitsFromISR(
\r
516 xEventGroup, // The event group being updated.
\r
517 BIT_0 | BIT_4 // The bits being set.
\r
518 &xHigherPriorityTaskWoken );
\r
520 // Was the message posted successfully?
\r
521 if( xResult == pdPASS )
\r
523 // If xHigherPriorityTaskWoken is now set to pdTRUE then a context
\r
524 // switch should be requested. The macro used is port specific and
\r
525 // will be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() -
\r
526 // refer to the documentation page for the port being used.
\r
527 portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
\r
531 * \defgroup xEventGroupSetBitsFromISR xEventGroupSetBitsFromISR
\r
532 * \ingroup EventGroup
\r
534 #if( configUSE_TRACE_FACILITY == 1 )
\r
535 BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
\r
537 #define xEventGroupSetBitsFromISR( xEventGroup, uxBitsToSet, pxHigherPriorityTaskWoken ) xTimerPendFunctionCallFromISR( vEventGroupSetBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToSet, pxHigherPriorityTaskWoken )
\r
543 EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup,
\r
544 const EventBits_t uxBitsToSet,
\r
545 const EventBits_t uxBitsToWaitFor,
\r
546 TickType_t xTicksToWait );
\r
549 * Atomically set bits within an event group, then wait for a combination of
\r
550 * bits to be set within the same event group. This functionality is typically
\r
551 * used to synchronise multiple tasks, where each task has to wait for the other
\r
552 * tasks to reach a synchronisation point before proceeding.
\r
554 * This function cannot be used from an interrupt.
\r
556 * The function will return before its block time expires if the bits specified
\r
557 * by the uxBitsToWait parameter are set, or become set within that time. In
\r
558 * this case all the bits specified by uxBitsToWait will be automatically
\r
559 * cleared before the function returns.
\r
561 * @param xEventGroup The event group in which the bits are being tested. The
\r
562 * event group must have previously been created using a call to
\r
563 * xEventGroupCreate().
\r
565 * @param uxBitsToSet The bits to set in the event group before determining
\r
566 * if, and possibly waiting for, all the bits specified by the uxBitsToWait
\r
567 * parameter are set.
\r
569 * @param uxBitsToWaitFor A bitwise value that indicates the bit or bits to test
\r
570 * inside the event group. For example, to wait for bit 0 and bit 2 set
\r
571 * uxBitsToWaitFor to 0x05. To wait for bits 0 and bit 1 and bit 2 set
\r
572 * uxBitsToWaitFor to 0x07. Etc.
\r
574 * @param xTicksToWait The maximum amount of time (specified in 'ticks') to wait
\r
575 * for all of the bits specified by uxBitsToWaitFor to become set.
\r
577 * @return The value of the event group at the time either the bits being waited
\r
578 * for became set, or the block time expired. Test the return value to know
\r
579 * which bits were set. If xEventGroupSync() returned because its timeout
\r
580 * expired then not all the bits being waited for will be set. If
\r
581 * xEventGroupSync() returned because all the bits it was waiting for were
\r
582 * set then the returned value is the event group value before any bits were
\r
583 * automatically cleared.
\r
587 // Bits used by the three tasks.
\r
588 #define TASK_0_BIT ( 1 << 0 )
\r
589 #define TASK_1_BIT ( 1 << 1 )
\r
590 #define TASK_2_BIT ( 1 << 2 )
\r
592 #define ALL_SYNC_BITS ( TASK_0_BIT | TASK_1_BIT | TASK_2_BIT )
\r
594 // Use an event group to synchronise three tasks. It is assumed this event
\r
595 // group has already been created elsewhere.
\r
596 EventGroupHandle_t xEventBits;
\r
598 void vTask0( void *pvParameters )
\r
600 EventBits_t uxReturn;
\r
601 TickType_t xTicksToWait = 100 / portTICK_PERIOD_MS;
\r
605 // Perform task functionality here.
\r
607 // Set bit 0 in the event flag to note this task has reached the
\r
608 // sync point. The other two tasks will set the other two bits defined
\r
609 // by ALL_SYNC_BITS. All three tasks have reached the synchronisation
\r
610 // point when all the ALL_SYNC_BITS are set. Wait a maximum of 100ms
\r
611 // for this to happen.
\r
612 uxReturn = xEventGroupSync( xEventBits, TASK_0_BIT, ALL_SYNC_BITS, xTicksToWait );
\r
614 if( ( uxReturn & ALL_SYNC_BITS ) == ALL_SYNC_BITS )
\r
616 // All three tasks reached the synchronisation point before the call
\r
617 // to xEventGroupSync() timed out.
\r
622 void vTask1( void *pvParameters )
\r
626 // Perform task functionality here.
\r
628 // Set bit 1 in the event flag to note this task has reached the
\r
629 // synchronisation point. The other two tasks will set the other two
\r
630 // bits defined by ALL_SYNC_BITS. All three tasks have reached the
\r
631 // synchronisation point when all the ALL_SYNC_BITS are set. Wait
\r
632 // indefinitely for this to happen.
\r
633 xEventGroupSync( xEventBits, TASK_1_BIT, ALL_SYNC_BITS, portMAX_DELAY );
\r
635 // xEventGroupSync() was called with an indefinite block time, so
\r
636 // this task will only reach here if the syncrhonisation was made by all
\r
637 // three tasks, so there is no need to test the return value.
\r
641 void vTask2( void *pvParameters )
\r
645 // Perform task functionality here.
\r
647 // Set bit 2 in the event flag to note this task has reached the
\r
648 // synchronisation point. The other two tasks will set the other two
\r
649 // bits defined by ALL_SYNC_BITS. All three tasks have reached the
\r
650 // synchronisation point when all the ALL_SYNC_BITS are set. Wait
\r
651 // indefinitely for this to happen.
\r
652 xEventGroupSync( xEventBits, TASK_2_BIT, ALL_SYNC_BITS, portMAX_DELAY );
\r
654 // xEventGroupSync() was called with an indefinite block time, so
\r
655 // this task will only reach here if the syncrhonisation was made by all
\r
656 // three tasks, so there is no need to test the return value.
\r
661 * \defgroup xEventGroupSync xEventGroupSync
\r
662 * \ingroup EventGroup
\r
664 EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, const EventBits_t uxBitsToWaitFor, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
\r
670 EventBits_t xEventGroupGetBits( EventGroupHandle_t xEventGroup );
\r
673 * Returns the current value of the bits in an event group. This function
\r
674 * cannot be used from an interrupt.
\r
676 * @param xEventGroup The event group being queried.
\r
678 * @return The event group bits at the time xEventGroupGetBits() was called.
\r
680 * \defgroup xEventGroupGetBits xEventGroupGetBits
\r
681 * \ingroup EventGroup
\r
683 #define xEventGroupGetBits( xEventGroup ) xEventGroupClearBits( xEventGroup, 0 )
\r
688 EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup );
\r
691 * A version of xEventGroupGetBits() that can be called from an ISR.
\r
693 * @param xEventGroup The event group being queried.
\r
695 * @return The event group bits at the time xEventGroupGetBitsFromISR() was called.
\r
697 * \defgroup xEventGroupGetBitsFromISR xEventGroupGetBitsFromISR
\r
698 * \ingroup EventGroup
\r
700 EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup ) PRIVILEGED_FUNCTION;
\r
705 void xEventGroupDelete( EventGroupHandle_t xEventGroup );
\r
708 * Delete an event group that was previously created by a call to
\r
709 * xEventGroupCreate(). Tasks that are blocked on the event group will be
\r
710 * unblocked and obtain 0 as the event group's value.
\r
712 * @param xEventGroup The event group being deleted.
\r
714 void vEventGroupDelete( EventGroupHandle_t xEventGroup ) PRIVILEGED_FUNCTION;
\r
716 /* For internal use only. */
\r
717 void vEventGroupSetBitsCallback( void *pvEventGroup, const uint32_t ulBitsToSet ) PRIVILEGED_FUNCTION;
\r
718 void vEventGroupClearBitsCallback( void *pvEventGroup, const uint32_t ulBitsToClear ) PRIVILEGED_FUNCTION;
\r
720 #if (configUSE_TRACE_FACILITY == 1)
\r
721 UBaseType_t uxEventGroupGetNumber( void* xEventGroup ) PRIVILEGED_FUNCTION;
\r
728 #endif /* EVENT_GROUPS_H */
\r