]> begriffs open source - freertos/blob - include/event_groups.h
Add support for MISRA rule 20.7 (#546)
[freertos] / include / event_groups.h
1 /*
2  * FreeRTOS Kernel <DEVELOPMENT BRANCH>
3  * Copyright (C) 2021 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * SPDX-License-Identifier: MIT
6  *
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:
13  *
14  * The above copyright notice and this permission notice shall be included in all
15  * copies or substantial portions of the Software.
16  *
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.
23  *
24  * https://www.FreeRTOS.org
25  * https://github.com/FreeRTOS
26  *
27  */
28
29 #ifndef EVENT_GROUPS_H
30 #define EVENT_GROUPS_H
31
32 #ifndef INC_FREERTOS_H
33     #error "include FreeRTOS.h" must appear in source files before "include event_groups.h"
34 #endif
35
36 /* FreeRTOS includes. */
37 #include "timers.h"
38
39 /* *INDENT-OFF* */
40 #ifdef __cplusplus
41     extern "C" {
42 #endif
43 /* *INDENT-ON* */
44
45 /**
46  * An event group is a collection of bits to which an application can assign a
47  * meaning.  For example, an application may create an event group to convey
48  * the status of various CAN bus related events in which bit 0 might mean "A CAN
49  * message has been received and is ready for processing", bit 1 might mean "The
50  * application has queued a message that is ready for sending onto the CAN
51  * network", and bit 2 might mean "It is time to send a SYNC message onto the
52  * CAN network" etc.  A task can then test the bit values to see which events
53  * are active, and optionally enter the Blocked state to wait for a specified
54  * bit or a group of specified bits to be active.  To continue the CAN bus
55  * example, a CAN controlling task can enter the Blocked state (and therefore
56  * not consume any processing time) until either bit 0, bit 1 or bit 2 are
57  * active, at which time the bit that was actually active would inform the task
58  * which action it had to take (process a received message, send a message, or
59  * send a SYNC).
60  *
61  * The event groups implementation contains intelligence to avoid race
62  * conditions that would otherwise occur were an application to use a simple
63  * variable for the same purpose.  This is particularly important with respect
64  * to when a bit within an event group is to be cleared, and when bits have to
65  * be set and then tested atomically - as is the case where event groups are
66  * used to create a synchronisation point between multiple tasks (a
67  * 'rendezvous').
68  */
69
70
71
72 /**
73  * event_groups.h
74  *
75  * Type by which event groups are referenced.  For example, a call to
76  * xEventGroupCreate() returns an EventGroupHandle_t variable that can then
77  * be used as a parameter to other event group functions.
78  *
79  * \defgroup EventGroupHandle_t EventGroupHandle_t
80  * \ingroup EventGroup
81  */
82 struct EventGroupDef_t;
83 typedef struct EventGroupDef_t   * EventGroupHandle_t;
84
85 /*
86  * The type that holds event bits always matches TickType_t - therefore the
87  * number of bits it holds is set by configUSE_16_BIT_TICKS (16 bits if set to 1,
88  * 32 bits if set to 0.
89  *
90  * \defgroup EventBits_t EventBits_t
91  * \ingroup EventGroup
92  */
93 typedef TickType_t               EventBits_t;
94
95 /**
96  * event_groups.h
97  * @code{c}
98  * EventGroupHandle_t xEventGroupCreate( void );
99  * @endcode
100  *
101  * Create a new event group.
102  *
103  * Internally, within the FreeRTOS implementation, event groups use a [small]
104  * block of memory, in which the event group's structure is stored.  If an event
105  * groups is created using xEventGroupCreate() then the required memory is
106  * automatically dynamically allocated inside the xEventGroupCreate() function.
107  * (see https://www.FreeRTOS.org/a00111.html).  If an event group is created
108  * using xEventGroupCreateStatic() then the application writer must instead
109  * provide the memory that will get used by the event group.
110  * xEventGroupCreateStatic() therefore allows an event group to be created
111  * without using any dynamic memory allocation.
112  *
113  * Although event groups are not related to ticks, for internal implementation
114  * reasons the number of bits available for use in an event group is dependent
115  * on the configUSE_16_BIT_TICKS setting in FreeRTOSConfig.h.  If
116  * configUSE_16_BIT_TICKS is 1 then each event group contains 8 usable bits (bit
117  * 0 to bit 7).  If configUSE_16_BIT_TICKS is set to 0 then each event group has
118  * 24 usable bits (bit 0 to bit 23).  The EventBits_t type is used to store
119  * event bits within an event group.
120  *
121  * @return If the event group was created then a handle to the event group is
122  * returned.  If there was insufficient FreeRTOS heap available to create the
123  * event group then NULL is returned.  See https://www.FreeRTOS.org/a00111.html
124  *
125  * Example usage:
126  * @code{c}
127  *  // Declare a variable to hold the created event group.
128  *  EventGroupHandle_t xCreatedEventGroup;
129  *
130  *  // Attempt to create the event group.
131  *  xCreatedEventGroup = xEventGroupCreate();
132  *
133  *  // Was the event group created successfully?
134  *  if( xCreatedEventGroup == NULL )
135  *  {
136  *      // The event group was not created because there was insufficient
137  *      // FreeRTOS heap available.
138  *  }
139  *  else
140  *  {
141  *      // The event group was created.
142  *  }
143  * @endcode
144  * \defgroup xEventGroupCreate xEventGroupCreate
145  * \ingroup EventGroup
146  */
147 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
148     EventGroupHandle_t xEventGroupCreate( void ) PRIVILEGED_FUNCTION;
149 #endif
150
151 /**
152  * event_groups.h
153  * @code{c}
154  * EventGroupHandle_t xEventGroupCreateStatic( EventGroupHandle_t * pxEventGroupBuffer );
155  * @endcode
156  *
157  * Create a new event group.
158  *
159  * Internally, within the FreeRTOS implementation, event groups use a [small]
160  * block of memory, in which the event group's structure is stored.  If an event
161  * groups is created using xEventGroupCreate() then the required memory is
162  * automatically dynamically allocated inside the xEventGroupCreate() function.
163  * (see https://www.FreeRTOS.org/a00111.html).  If an event group is created
164  * using xEventGroupCreateStatic() then the application writer must instead
165  * provide the memory that will get used by the event group.
166  * xEventGroupCreateStatic() therefore allows an event group to be created
167  * without using any dynamic memory allocation.
168  *
169  * Although event groups are not related to ticks, for internal implementation
170  * reasons the number of bits available for use in an event group is dependent
171  * on the configUSE_16_BIT_TICKS setting in FreeRTOSConfig.h.  If
172  * configUSE_16_BIT_TICKS is 1 then each event group contains 8 usable bits (bit
173  * 0 to bit 7).  If configUSE_16_BIT_TICKS is set to 0 then each event group has
174  * 24 usable bits (bit 0 to bit 23).  The EventBits_t type is used to store
175  * event bits within an event group.
176  *
177  * @param pxEventGroupBuffer pxEventGroupBuffer must point to a variable of type
178  * StaticEventGroup_t, which will be then be used to hold the event group's data
179  * structures, removing the need for the memory to be allocated dynamically.
180  *
181  * @return If the event group was created then a handle to the event group is
182  * returned.  If pxEventGroupBuffer was NULL then NULL is returned.
183  *
184  * Example usage:
185  * @code{c}
186  *  // StaticEventGroup_t is a publicly accessible structure that has the same
187  *  // size and alignment requirements as the real event group structure.  It is
188  *  // provided as a mechanism for applications to know the size of the event
189  *  // group (which is dependent on the architecture and configuration file
190  *  // settings) without breaking the strict data hiding policy by exposing the
191  *  // real event group internals.  This StaticEventGroup_t variable is passed
192  *  // into the xSemaphoreCreateEventGroupStatic() function and is used to store
193  *  // the event group's data structures
194  *  StaticEventGroup_t xEventGroupBuffer;
195  *
196  *  // Create the event group without dynamically allocating any memory.
197  *  xEventGroup = xEventGroupCreateStatic( &xEventGroupBuffer );
198  * @endcode
199  */
200 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
201     EventGroupHandle_t xEventGroupCreateStatic( StaticEventGroup_t * pxEventGroupBuffer ) PRIVILEGED_FUNCTION;
202 #endif
203
204 /**
205  * event_groups.h
206  * @code{c}
207  *  EventBits_t xEventGroupWaitBits(    EventGroupHandle_t xEventGroup,
208  *                                      const EventBits_t uxBitsToWaitFor,
209  *                                      const BaseType_t xClearOnExit,
210  *                                      const BaseType_t xWaitForAllBits,
211  *                                      const TickType_t xTicksToWait );
212  * @endcode
213  *
214  * [Potentially] block to wait for one or more bits to be set within a
215  * previously created event group.
216  *
217  * This function cannot be called from an interrupt.
218  *
219  * @param xEventGroup The event group in which the bits are being tested.  The
220  * event group must have previously been created using a call to
221  * xEventGroupCreate().
222  *
223  * @param uxBitsToWaitFor A bitwise value that indicates the bit or bits to test
224  * inside the event group.  For example, to wait for bit 0 and/or bit 2 set
225  * uxBitsToWaitFor to 0x05.  To wait for bits 0 and/or bit 1 and/or bit 2 set
226  * uxBitsToWaitFor to 0x07.  Etc.
227  *
228  * @param xClearOnExit If xClearOnExit is set to pdTRUE then any bits within
229  * uxBitsToWaitFor that are set within the event group will be cleared before
230  * xEventGroupWaitBits() returns if the wait condition was met (if the function
231  * returns for a reason other than a timeout).  If xClearOnExit is set to
232  * pdFALSE then the bits set in the event group are not altered when the call to
233  * xEventGroupWaitBits() returns.
234  *
235  * @param xWaitForAllBits If xWaitForAllBits is set to pdTRUE then
236  * xEventGroupWaitBits() will return when either all the bits in uxBitsToWaitFor
237  * are set or the specified block time expires.  If xWaitForAllBits is set to
238  * pdFALSE then xEventGroupWaitBits() will return when any one of the bits set
239  * in uxBitsToWaitFor is set or the specified block time expires.  The block
240  * time is specified by the xTicksToWait parameter.
241  *
242  * @param xTicksToWait The maximum amount of time (specified in 'ticks') to wait
243  * for one/all (depending on the xWaitForAllBits value) of the bits specified by
244  * uxBitsToWaitFor to become set. A value of portMAX_DELAY can be used to block
245  * indefinitely (provided INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h).
246  *
247  * @return The value of the event group at the time either the bits being waited
248  * for became set, or the block time expired.  Test the return value to know
249  * which bits were set.  If xEventGroupWaitBits() returned because its timeout
250  * expired then not all the bits being waited for will be set.  If
251  * xEventGroupWaitBits() returned because the bits it was waiting for were set
252  * then the returned value is the event group value before any bits were
253  * automatically cleared in the case that xClearOnExit parameter was set to
254  * pdTRUE.
255  *
256  * Example usage:
257  * @code{c}
258  * #define BIT_0 ( 1 << 0 )
259  * #define BIT_4 ( 1 << 4 )
260  *
261  * void aFunction( EventGroupHandle_t xEventGroup )
262  * {
263  * EventBits_t uxBits;
264  * const TickType_t xTicksToWait = 100 / portTICK_PERIOD_MS;
265  *
266  *      // Wait a maximum of 100ms for either bit 0 or bit 4 to be set within
267  *      // the event group.  Clear the bits before exiting.
268  *      uxBits = xEventGroupWaitBits(
269  *                  xEventGroup,    // The event group being tested.
270  *                  BIT_0 | BIT_4,  // The bits within the event group to wait for.
271  *                  pdTRUE,         // BIT_0 and BIT_4 should be cleared before returning.
272  *                  pdFALSE,        // Don't wait for both bits, either bit will do.
273  *                  xTicksToWait ); // Wait a maximum of 100ms for either bit to be set.
274  *
275  *      if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
276  *      {
277  *          // xEventGroupWaitBits() returned because both bits were set.
278  *      }
279  *      else if( ( uxBits & BIT_0 ) != 0 )
280  *      {
281  *          // xEventGroupWaitBits() returned because just BIT_0 was set.
282  *      }
283  *      else if( ( uxBits & BIT_4 ) != 0 )
284  *      {
285  *          // xEventGroupWaitBits() returned because just BIT_4 was set.
286  *      }
287  *      else
288  *      {
289  *          // xEventGroupWaitBits() returned because xTicksToWait ticks passed
290  *          // without either BIT_0 or BIT_4 becoming set.
291  *      }
292  * }
293  * @endcode
294  * \defgroup xEventGroupWaitBits xEventGroupWaitBits
295  * \ingroup EventGroup
296  */
297 EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup,
298                                  const EventBits_t uxBitsToWaitFor,
299                                  const BaseType_t xClearOnExit,
300                                  const BaseType_t xWaitForAllBits,
301                                  TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
302
303 /**
304  * event_groups.h
305  * @code{c}
306  *  EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear );
307  * @endcode
308  *
309  * Clear bits within an event group.  This function cannot be called from an
310  * interrupt.
311  *
312  * @param xEventGroup The event group in which the bits are to be cleared.
313  *
314  * @param uxBitsToClear A bitwise value that indicates the bit or bits to clear
315  * in the event group.  For example, to clear bit 3 only, set uxBitsToClear to
316  * 0x08.  To clear bit 3 and bit 0 set uxBitsToClear to 0x09.
317  *
318  * @return The value of the event group before the specified bits were cleared.
319  *
320  * Example usage:
321  * @code{c}
322  * #define BIT_0 ( 1 << 0 )
323  * #define BIT_4 ( 1 << 4 )
324  *
325  * void aFunction( EventGroupHandle_t xEventGroup )
326  * {
327  * EventBits_t uxBits;
328  *
329  *      // Clear bit 0 and bit 4 in xEventGroup.
330  *      uxBits = xEventGroupClearBits(
331  *                              xEventGroup,    // The event group being updated.
332  *                              BIT_0 | BIT_4 );// The bits being cleared.
333  *
334  *      if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
335  *      {
336  *          // Both bit 0 and bit 4 were set before xEventGroupClearBits() was
337  *          // called.  Both will now be clear (not set).
338  *      }
339  *      else if( ( uxBits & BIT_0 ) != 0 )
340  *      {
341  *          // Bit 0 was set before xEventGroupClearBits() was called.  It will
342  *          // now be clear.
343  *      }
344  *      else if( ( uxBits & BIT_4 ) != 0 )
345  *      {
346  *          // Bit 4 was set before xEventGroupClearBits() was called.  It will
347  *          // now be clear.
348  *      }
349  *      else
350  *      {
351  *          // Neither bit 0 nor bit 4 were set in the first place.
352  *      }
353  * }
354  * @endcode
355  * \defgroup xEventGroupClearBits xEventGroupClearBits
356  * \ingroup EventGroup
357  */
358 EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup,
359                                   const EventBits_t uxBitsToClear ) PRIVILEGED_FUNCTION;
360
361 /**
362  * event_groups.h
363  * @code{c}
364  *  BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet );
365  * @endcode
366  *
367  * A version of xEventGroupClearBits() that can be called from an interrupt.
368  *
369  * Setting bits in an event group is not a deterministic operation because there
370  * are an unknown number of tasks that may be waiting for the bit or bits being
371  * set.  FreeRTOS does not allow nondeterministic operations to be performed
372  * while interrupts are disabled, so protects event groups that are accessed
373  * from tasks by suspending the scheduler rather than disabling interrupts.  As
374  * a result event groups cannot be accessed directly from an interrupt service
375  * routine.  Therefore xEventGroupClearBitsFromISR() sends a message to the
376  * timer task to have the clear operation performed in the context of the timer
377  * task.
378  *
379  * @note If this function returns pdPASS then the timer task is ready to run
380  * and a portYIELD_FROM_ISR(pdTRUE) should be executed to perform the needed
381  * clear on the event group.  This behavior is different from
382  * xEventGroupSetBitsFromISR because the parameter xHigherPriorityTaskWoken is
383  * not present.
384  *
385  * @param xEventGroup The event group in which the bits are to be cleared.
386  *
387  * @param uxBitsToClear A bitwise value that indicates the bit or bits to clear.
388  * For example, to clear bit 3 only, set uxBitsToClear to 0x08.  To clear bit 3
389  * and bit 0 set uxBitsToClear to 0x09.
390  *
391  * @return If the request to execute the function was posted successfully then
392  * pdPASS is returned, otherwise pdFALSE is returned.  pdFALSE will be returned
393  * if the timer service queue was full.
394  *
395  * Example usage:
396  * @code{c}
397  * #define BIT_0 ( 1 << 0 )
398  * #define BIT_4 ( 1 << 4 )
399  *
400  * // An event group which it is assumed has already been created by a call to
401  * // xEventGroupCreate().
402  * EventGroupHandle_t xEventGroup;
403  *
404  * void anInterruptHandler( void )
405  * {
406  *      // Clear bit 0 and bit 4 in xEventGroup.
407  *      xResult = xEventGroupClearBitsFromISR(
408  *                          xEventGroup,     // The event group being updated.
409  *                          BIT_0 | BIT_4 ); // The bits being set.
410  *
411  *      if( xResult == pdPASS )
412  *      {
413  *          // The message was posted successfully.
414  *          portYIELD_FROM_ISR(pdTRUE);
415  *      }
416  * }
417  * @endcode
418  * \defgroup xEventGroupClearBitsFromISR xEventGroupClearBitsFromISR
419  * \ingroup EventGroup
420  */
421 #if ( configUSE_TRACE_FACILITY == 1 )
422     BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup,
423                                             const EventBits_t uxBitsToClear ) PRIVILEGED_FUNCTION;
424 #else
425     #define xEventGroupClearBitsFromISR( xEventGroup, uxBitsToClear ) \
426     xTimerPendFunctionCallFromISR( vEventGroupClearBitsCallback, ( void * ) ( xEventGroup ), ( uint32_t ) ( uxBitsToClear ), NULL )
427 #endif
428
429 /**
430  * event_groups.h
431  * @code{c}
432  *  EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet );
433  * @endcode
434  *
435  * Set bits within an event group.
436  * This function cannot be called from an interrupt.  xEventGroupSetBitsFromISR()
437  * is a version that can be called from an interrupt.
438  *
439  * Setting bits in an event group will automatically unblock tasks that are
440  * blocked waiting for the bits.
441  *
442  * @param xEventGroup The event group in which the bits are to be set.
443  *
444  * @param uxBitsToSet A bitwise value that indicates the bit or bits to set.
445  * For example, to set bit 3 only, set uxBitsToSet to 0x08.  To set bit 3
446  * and bit 0 set uxBitsToSet to 0x09.
447  *
448  * @return The value of the event group at the time the call to
449  * xEventGroupSetBits() returns.  There are two reasons why the returned value
450  * might have the bits specified by the uxBitsToSet parameter cleared.  First,
451  * if setting a bit results in a task that was waiting for the bit leaving the
452  * blocked state then it is possible the bit will be cleared automatically
453  * (see the xClearBitOnExit parameter of xEventGroupWaitBits()).  Second, any
454  * unblocked (or otherwise Ready state) task that has a priority above that of
455  * the task that called xEventGroupSetBits() will execute and may change the
456  * event group value before the call to xEventGroupSetBits() returns.
457  *
458  * Example usage:
459  * @code{c}
460  * #define BIT_0 ( 1 << 0 )
461  * #define BIT_4 ( 1 << 4 )
462  *
463  * void aFunction( EventGroupHandle_t xEventGroup )
464  * {
465  * EventBits_t uxBits;
466  *
467  *      // Set bit 0 and bit 4 in xEventGroup.
468  *      uxBits = xEventGroupSetBits(
469  *                          xEventGroup,    // The event group being updated.
470  *                          BIT_0 | BIT_4 );// The bits being set.
471  *
472  *      if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
473  *      {
474  *          // Both bit 0 and bit 4 remained set when the function returned.
475  *      }
476  *      else if( ( uxBits & BIT_0 ) != 0 )
477  *      {
478  *          // Bit 0 remained set when the function returned, but bit 4 was
479  *          // cleared.  It might be that bit 4 was cleared automatically as a
480  *          // task that was waiting for bit 4 was removed from the Blocked
481  *          // state.
482  *      }
483  *      else if( ( uxBits & BIT_4 ) != 0 )
484  *      {
485  *          // Bit 4 remained set when the function returned, but bit 0 was
486  *          // cleared.  It might be that bit 0 was cleared automatically as a
487  *          // task that was waiting for bit 0 was removed from the Blocked
488  *          // state.
489  *      }
490  *      else
491  *      {
492  *          // Neither bit 0 nor bit 4 remained set.  It might be that a task
493  *          // was waiting for both of the bits to be set, and the bits were
494  *          // cleared as the task left the Blocked state.
495  *      }
496  * }
497  * @endcode
498  * \defgroup xEventGroupSetBits xEventGroupSetBits
499  * \ingroup EventGroup
500  */
501 EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup,
502                                 const EventBits_t uxBitsToSet ) PRIVILEGED_FUNCTION;
503
504 /**
505  * event_groups.h
506  * @code{c}
507  *  BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken );
508  * @endcode
509  *
510  * A version of xEventGroupSetBits() that can be called from an interrupt.
511  *
512  * Setting bits in an event group is not a deterministic operation because there
513  * are an unknown number of tasks that may be waiting for the bit or bits being
514  * set.  FreeRTOS does not allow nondeterministic operations to be performed in
515  * interrupts or from critical sections.  Therefore xEventGroupSetBitsFromISR()
516  * sends a message to the timer task to have the set operation performed in the
517  * context of the timer task - where a scheduler lock is used in place of a
518  * critical section.
519  *
520  * @param xEventGroup The event group in which the bits are to be set.
521  *
522  * @param uxBitsToSet A bitwise value that indicates the bit or bits to set.
523  * For example, to set bit 3 only, set uxBitsToSet to 0x08.  To set bit 3
524  * and bit 0 set uxBitsToSet to 0x09.
525  *
526  * @param pxHigherPriorityTaskWoken As mentioned above, calling this function
527  * will result in a message being sent to the timer daemon task.  If the
528  * priority of the timer daemon task is higher than the priority of the
529  * currently running task (the task the interrupt interrupted) then
530  * *pxHigherPriorityTaskWoken will be set to pdTRUE by
531  * xEventGroupSetBitsFromISR(), indicating that a context switch should be
532  * requested before the interrupt exits.  For that reason
533  * *pxHigherPriorityTaskWoken must be initialised to pdFALSE.  See the
534  * example code below.
535  *
536  * @return If the request to execute the function was posted successfully then
537  * pdPASS is returned, otherwise pdFALSE is returned.  pdFALSE will be returned
538  * if the timer service queue was full.
539  *
540  * Example usage:
541  * @code{c}
542  * #define BIT_0 ( 1 << 0 )
543  * #define BIT_4 ( 1 << 4 )
544  *
545  * // An event group which it is assumed has already been created by a call to
546  * // xEventGroupCreate().
547  * EventGroupHandle_t xEventGroup;
548  *
549  * void anInterruptHandler( void )
550  * {
551  * BaseType_t xHigherPriorityTaskWoken, xResult;
552  *
553  *      // xHigherPriorityTaskWoken must be initialised to pdFALSE.
554  *      xHigherPriorityTaskWoken = pdFALSE;
555  *
556  *      // Set bit 0 and bit 4 in xEventGroup.
557  *      xResult = xEventGroupSetBitsFromISR(
558  *                          xEventGroup,    // The event group being updated.
559  *                          BIT_0 | BIT_4   // The bits being set.
560  *                          &xHigherPriorityTaskWoken );
561  *
562  *      // Was the message posted successfully?
563  *      if( xResult == pdPASS )
564  *      {
565  *          // If xHigherPriorityTaskWoken is now set to pdTRUE then a context
566  *          // switch should be requested.  The macro used is port specific and
567  *          // will be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() -
568  *          // refer to the documentation page for the port being used.
569  *          portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
570  *      }
571  * }
572  * @endcode
573  * \defgroup xEventGroupSetBitsFromISR xEventGroupSetBitsFromISR
574  * \ingroup EventGroup
575  */
576 #if ( configUSE_TRACE_FACILITY == 1 )
577     BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup,
578                                           const EventBits_t uxBitsToSet,
579                                           BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
580 #else
581     #define xEventGroupSetBitsFromISR( xEventGroup, uxBitsToSet, pxHigherPriorityTaskWoken ) \
582     xTimerPendFunctionCallFromISR( vEventGroupSetBitsCallback, ( void * ) ( xEventGroup ), ( uint32_t ) ( uxBitsToSet ), ( pxHigherPriorityTaskWoken ) )
583 #endif
584
585 /**
586  * event_groups.h
587  * @code{c}
588  *  EventBits_t xEventGroupSync(    EventGroupHandle_t xEventGroup,
589  *                                  const EventBits_t uxBitsToSet,
590  *                                  const EventBits_t uxBitsToWaitFor,
591  *                                  TickType_t xTicksToWait );
592  * @endcode
593  *
594  * Atomically set bits within an event group, then wait for a combination of
595  * bits to be set within the same event group.  This functionality is typically
596  * used to synchronise multiple tasks, where each task has to wait for the other
597  * tasks to reach a synchronisation point before proceeding.
598  *
599  * This function cannot be used from an interrupt.
600  *
601  * The function will return before its block time expires if the bits specified
602  * by the uxBitsToWait parameter are set, or become set within that time.  In
603  * this case all the bits specified by uxBitsToWait will be automatically
604  * cleared before the function returns.
605  *
606  * @param xEventGroup The event group in which the bits are being tested.  The
607  * event group must have previously been created using a call to
608  * xEventGroupCreate().
609  *
610  * @param uxBitsToSet The bits to set in the event group before determining
611  * if, and possibly waiting for, all the bits specified by the uxBitsToWait
612  * parameter are set.
613  *
614  * @param uxBitsToWaitFor A bitwise value that indicates the bit or bits to test
615  * inside the event group.  For example, to wait for bit 0 and bit 2 set
616  * uxBitsToWaitFor to 0x05.  To wait for bits 0 and bit 1 and bit 2 set
617  * uxBitsToWaitFor to 0x07.  Etc.
618  *
619  * @param xTicksToWait The maximum amount of time (specified in 'ticks') to wait
620  * for all of the bits specified by uxBitsToWaitFor to become set.
621  *
622  * @return The value of the event group at the time either the bits being waited
623  * for became set, or the block time expired.  Test the return value to know
624  * which bits were set.  If xEventGroupSync() returned because its timeout
625  * expired then not all the bits being waited for will be set.  If
626  * xEventGroupSync() returned because all the bits it was waiting for were
627  * set then the returned value is the event group value before any bits were
628  * automatically cleared.
629  *
630  * Example usage:
631  * @code{c}
632  * // Bits used by the three tasks.
633  * #define TASK_0_BIT     ( 1 << 0 )
634  * #define TASK_1_BIT     ( 1 << 1 )
635  * #define TASK_2_BIT     ( 1 << 2 )
636  *
637  * #define ALL_SYNC_BITS ( TASK_0_BIT | TASK_1_BIT | TASK_2_BIT )
638  *
639  * // Use an event group to synchronise three tasks.  It is assumed this event
640  * // group has already been created elsewhere.
641  * EventGroupHandle_t xEventBits;
642  *
643  * void vTask0( void *pvParameters )
644  * {
645  * EventBits_t uxReturn;
646  * TickType_t xTicksToWait = 100 / portTICK_PERIOD_MS;
647  *
648  *   for( ;; )
649  *   {
650  *      // Perform task functionality here.
651  *
652  *      // Set bit 0 in the event flag to note this task has reached the
653  *      // sync point.  The other two tasks will set the other two bits defined
654  *      // by ALL_SYNC_BITS.  All three tasks have reached the synchronisation
655  *      // point when all the ALL_SYNC_BITS are set.  Wait a maximum of 100ms
656  *      // for this to happen.
657  *      uxReturn = xEventGroupSync( xEventBits, TASK_0_BIT, ALL_SYNC_BITS, xTicksToWait );
658  *
659  *      if( ( uxReturn & ALL_SYNC_BITS ) == ALL_SYNC_BITS )
660  *      {
661  *          // All three tasks reached the synchronisation point before the call
662  *          // to xEventGroupSync() timed out.
663  *      }
664  *  }
665  * }
666  *
667  * void vTask1( void *pvParameters )
668  * {
669  *   for( ;; )
670  *   {
671  *      // Perform task functionality here.
672  *
673  *      // Set bit 1 in the event flag to note this task has reached the
674  *      // synchronisation point.  The other two tasks will set the other two
675  *      // bits defined by ALL_SYNC_BITS.  All three tasks have reached the
676  *      // synchronisation point when all the ALL_SYNC_BITS are set.  Wait
677  *      // indefinitely for this to happen.
678  *      xEventGroupSync( xEventBits, TASK_1_BIT, ALL_SYNC_BITS, portMAX_DELAY );
679  *
680  *      // xEventGroupSync() was called with an indefinite block time, so
681  *      // this task will only reach here if the synchronisation was made by all
682  *      // three tasks, so there is no need to test the return value.
683  *   }
684  * }
685  *
686  * void vTask2( void *pvParameters )
687  * {
688  *   for( ;; )
689  *   {
690  *      // Perform task functionality here.
691  *
692  *      // Set bit 2 in the event flag to note this task has reached the
693  *      // synchronisation point.  The other two tasks will set the other two
694  *      // bits defined by ALL_SYNC_BITS.  All three tasks have reached the
695  *      // synchronisation point when all the ALL_SYNC_BITS are set.  Wait
696  *      // indefinitely for this to happen.
697  *      xEventGroupSync( xEventBits, TASK_2_BIT, ALL_SYNC_BITS, portMAX_DELAY );
698  *
699  *      // xEventGroupSync() was called with an indefinite block time, so
700  *      // this task will only reach here if the synchronisation was made by all
701  *      // three tasks, so there is no need to test the return value.
702  *  }
703  * }
704  *
705  * @endcode
706  * \defgroup xEventGroupSync xEventGroupSync
707  * \ingroup EventGroup
708  */
709 EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup,
710                              const EventBits_t uxBitsToSet,
711                              const EventBits_t uxBitsToWaitFor,
712                              TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
713
714
715 /**
716  * event_groups.h
717  * @code{c}
718  *  EventBits_t xEventGroupGetBits( EventGroupHandle_t xEventGroup );
719  * @endcode
720  *
721  * Returns the current value of the bits in an event group.  This function
722  * cannot be used from an interrupt.
723  *
724  * @param xEventGroup The event group being queried.
725  *
726  * @return The event group bits at the time xEventGroupGetBits() was called.
727  *
728  * \defgroup xEventGroupGetBits xEventGroupGetBits
729  * \ingroup EventGroup
730  */
731 #define xEventGroupGetBits( xEventGroup )    xEventGroupClearBits( ( xEventGroup ), 0 )
732
733 /**
734  * event_groups.h
735  * @code{c}
736  *  EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup );
737  * @endcode
738  *
739  * A version of xEventGroupGetBits() that can be called from an ISR.
740  *
741  * @param xEventGroup The event group being queried.
742  *
743  * @return The event group bits at the time xEventGroupGetBitsFromISR() was called.
744  *
745  * \defgroup xEventGroupGetBitsFromISR xEventGroupGetBitsFromISR
746  * \ingroup EventGroup
747  */
748 EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup ) PRIVILEGED_FUNCTION;
749
750 /**
751  * event_groups.h
752  * @code{c}
753  *  void xEventGroupDelete( EventGroupHandle_t xEventGroup );
754  * @endcode
755  *
756  * Delete an event group that was previously created by a call to
757  * xEventGroupCreate().  Tasks that are blocked on the event group will be
758  * unblocked and obtain 0 as the event group's value.
759  *
760  * @param xEventGroup The event group being deleted.
761  */
762 void vEventGroupDelete( EventGroupHandle_t xEventGroup ) PRIVILEGED_FUNCTION;
763
764 /* For internal use only. */
765 void vEventGroupSetBitsCallback( void * pvEventGroup,
766                                  const uint32_t ulBitsToSet ) PRIVILEGED_FUNCTION;
767 void vEventGroupClearBitsCallback( void * pvEventGroup,
768                                    const uint32_t ulBitsToClear ) PRIVILEGED_FUNCTION;
769
770
771 #if ( configUSE_TRACE_FACILITY == 1 )
772     UBaseType_t uxEventGroupGetNumber( void * xEventGroup ) PRIVILEGED_FUNCTION;
773     void vEventGroupSetNumber( void * xEventGroup,
774                                UBaseType_t uxEventGroupNumber ) PRIVILEGED_FUNCTION;
775 #endif
776
777 /* *INDENT-OFF* */
778 #ifdef __cplusplus
779     }
780 #endif
781 /* *INDENT-ON* */
782
783 #endif /* EVENT_GROUPS_H */