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