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