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