Update revision to use TI's mqtt and Freertos.
Dependencies: mbed client server
Fork of cc3100_Test_mqtt_CM3 by
FreeRTOS_V8_2_1/source/include/event_groups.h@3:a8c249046181, 2015-09-03 (annotated)
- Committer:
- dflet
- Date:
- Thu Sep 03 14:02:37 2015 +0000
- Revision:
- 3:a8c249046181
SPI Mode change 1 to 0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dflet | 3:a8c249046181 | 1 | /* |
dflet | 3:a8c249046181 | 2 | FreeRTOS V8.2.1 - Copyright (C) 2015 Real Time Engineers Ltd. |
dflet | 3:a8c249046181 | 3 | All rights reserved |
dflet | 3:a8c249046181 | 4 | |
dflet | 3:a8c249046181 | 5 | VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. |
dflet | 3:a8c249046181 | 6 | |
dflet | 3:a8c249046181 | 7 | This file is part of the FreeRTOS distribution. |
dflet | 3:a8c249046181 | 8 | |
dflet | 3:a8c249046181 | 9 | FreeRTOS is free software; you can redistribute it and/or modify it under |
dflet | 3:a8c249046181 | 10 | the terms of the GNU General Public License (version 2) as published by the |
dflet | 3:a8c249046181 | 11 | Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception. |
dflet | 3:a8c249046181 | 12 | |
dflet | 3:a8c249046181 | 13 | *************************************************************************** |
dflet | 3:a8c249046181 | 14 | >>! NOTE: The modification to the GPL is included to allow you to !<< |
dflet | 3:a8c249046181 | 15 | >>! distribute a combined work that includes FreeRTOS without being !<< |
dflet | 3:a8c249046181 | 16 | >>! obliged to provide the source code for proprietary components !<< |
dflet | 3:a8c249046181 | 17 | >>! outside of the FreeRTOS kernel. !<< |
dflet | 3:a8c249046181 | 18 | *************************************************************************** |
dflet | 3:a8c249046181 | 19 | |
dflet | 3:a8c249046181 | 20 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY |
dflet | 3:a8c249046181 | 21 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
dflet | 3:a8c249046181 | 22 | FOR A PARTICULAR PURPOSE. Full license text is available on the following |
dflet | 3:a8c249046181 | 23 | link: http://www.freertos.org/a00114.html |
dflet | 3:a8c249046181 | 24 | |
dflet | 3:a8c249046181 | 25 | *************************************************************************** |
dflet | 3:a8c249046181 | 26 | * * |
dflet | 3:a8c249046181 | 27 | * FreeRTOS provides completely free yet professionally developed, * |
dflet | 3:a8c249046181 | 28 | * robust, strictly quality controlled, supported, and cross * |
dflet | 3:a8c249046181 | 29 | * platform software that is more than just the market leader, it * |
dflet | 3:a8c249046181 | 30 | * is the industry's de facto standard. * |
dflet | 3:a8c249046181 | 31 | * * |
dflet | 3:a8c249046181 | 32 | * Help yourself get started quickly while simultaneously helping * |
dflet | 3:a8c249046181 | 33 | * to support the FreeRTOS project by purchasing a FreeRTOS * |
dflet | 3:a8c249046181 | 34 | * tutorial book, reference manual, or both: * |
dflet | 3:a8c249046181 | 35 | * http://www.FreeRTOS.org/Documentation * |
dflet | 3:a8c249046181 | 36 | * * |
dflet | 3:a8c249046181 | 37 | *************************************************************************** |
dflet | 3:a8c249046181 | 38 | |
dflet | 3:a8c249046181 | 39 | http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading |
dflet | 3:a8c249046181 | 40 | the FAQ page "My application does not run, what could be wrong?". Have you |
dflet | 3:a8c249046181 | 41 | defined configASSERT()? |
dflet | 3:a8c249046181 | 42 | |
dflet | 3:a8c249046181 | 43 | http://www.FreeRTOS.org/support - In return for receiving this top quality |
dflet | 3:a8c249046181 | 44 | embedded software for free we request you assist our global community by |
dflet | 3:a8c249046181 | 45 | participating in the support forum. |
dflet | 3:a8c249046181 | 46 | |
dflet | 3:a8c249046181 | 47 | http://www.FreeRTOS.org/training - Investing in training allows your team to |
dflet | 3:a8c249046181 | 48 | be as productive as possible as early as possible. Now you can receive |
dflet | 3:a8c249046181 | 49 | FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers |
dflet | 3:a8c249046181 | 50 | Ltd, and the world's leading authority on the world's leading RTOS. |
dflet | 3:a8c249046181 | 51 | |
dflet | 3:a8c249046181 | 52 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, |
dflet | 3:a8c249046181 | 53 | including FreeRTOS+Trace - an indispensable productivity tool, a DOS |
dflet | 3:a8c249046181 | 54 | compatible FAT file system, and our tiny thread aware UDP/IP stack. |
dflet | 3:a8c249046181 | 55 | |
dflet | 3:a8c249046181 | 56 | http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate. |
dflet | 3:a8c249046181 | 57 | Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS. |
dflet | 3:a8c249046181 | 58 | |
dflet | 3:a8c249046181 | 59 | http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High |
dflet | 3:a8c249046181 | 60 | Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS |
dflet | 3:a8c249046181 | 61 | licenses offer ticketed support, indemnification and commercial middleware. |
dflet | 3:a8c249046181 | 62 | |
dflet | 3:a8c249046181 | 63 | http://www.SafeRTOS.com - High Integrity Systems also provide a safety |
dflet | 3:a8c249046181 | 64 | engineered and independently SIL3 certified version for use in safety and |
dflet | 3:a8c249046181 | 65 | mission critical applications that require provable dependability. |
dflet | 3:a8c249046181 | 66 | |
dflet | 3:a8c249046181 | 67 | 1 tab == 4 spaces! |
dflet | 3:a8c249046181 | 68 | */ |
dflet | 3:a8c249046181 | 69 | |
dflet | 3:a8c249046181 | 70 | #ifndef EVENT_GROUPS_H |
dflet | 3:a8c249046181 | 71 | #define EVENT_GROUPS_H |
dflet | 3:a8c249046181 | 72 | |
dflet | 3:a8c249046181 | 73 | #ifndef INC_FREERTOS_H |
dflet | 3:a8c249046181 | 74 | #error "include FreeRTOS.h" must appear in source files before "include event_groups.h" |
dflet | 3:a8c249046181 | 75 | #endif |
dflet | 3:a8c249046181 | 76 | |
dflet | 3:a8c249046181 | 77 | #include "timers.h" |
dflet | 3:a8c249046181 | 78 | |
dflet | 3:a8c249046181 | 79 | #ifdef __cplusplus |
dflet | 3:a8c249046181 | 80 | extern "C" { |
dflet | 3:a8c249046181 | 81 | #endif |
dflet | 3:a8c249046181 | 82 | |
dflet | 3:a8c249046181 | 83 | /** |
dflet | 3:a8c249046181 | 84 | * An event group is a collection of bits to which an application can assign a |
dflet | 3:a8c249046181 | 85 | * meaning. For example, an application may create an event group to convey |
dflet | 3:a8c249046181 | 86 | * the status of various CAN bus related events in which bit 0 might mean "A CAN |
dflet | 3:a8c249046181 | 87 | * message has been received and is ready for processing", bit 1 might mean "The |
dflet | 3:a8c249046181 | 88 | * application has queued a message that is ready for sending onto the CAN |
dflet | 3:a8c249046181 | 89 | * network", and bit 2 might mean "It is time to send a SYNC message onto the |
dflet | 3:a8c249046181 | 90 | * CAN network" etc. A task can then test the bit values to see which events |
dflet | 3:a8c249046181 | 91 | * are active, and optionally enter the Blocked state to wait for a specified |
dflet | 3:a8c249046181 | 92 | * bit or a group of specified bits to be active. To continue the CAN bus |
dflet | 3:a8c249046181 | 93 | * example, a CAN controlling task can enter the Blocked state (and therefore |
dflet | 3:a8c249046181 | 94 | * not consume any processing time) until either bit 0, bit 1 or bit 2 are |
dflet | 3:a8c249046181 | 95 | * active, at which time the bit that was actually active would inform the task |
dflet | 3:a8c249046181 | 96 | * which action it had to take (process a received message, send a message, or |
dflet | 3:a8c249046181 | 97 | * send a SYNC). |
dflet | 3:a8c249046181 | 98 | * |
dflet | 3:a8c249046181 | 99 | * The event groups implementation contains intelligence to avoid race |
dflet | 3:a8c249046181 | 100 | * conditions that would otherwise occur were an application to use a simple |
dflet | 3:a8c249046181 | 101 | * variable for the same purpose. This is particularly important with respect |
dflet | 3:a8c249046181 | 102 | * to when a bit within an event group is to be cleared, and when bits have to |
dflet | 3:a8c249046181 | 103 | * be set and then tested atomically - as is the case where event groups are |
dflet | 3:a8c249046181 | 104 | * used to create a synchronisation point between multiple tasks (a |
dflet | 3:a8c249046181 | 105 | * 'rendezvous'). |
dflet | 3:a8c249046181 | 106 | * |
dflet | 3:a8c249046181 | 107 | * \defgroup EventGroup |
dflet | 3:a8c249046181 | 108 | */ |
dflet | 3:a8c249046181 | 109 | |
dflet | 3:a8c249046181 | 110 | |
dflet | 3:a8c249046181 | 111 | |
dflet | 3:a8c249046181 | 112 | /** |
dflet | 3:a8c249046181 | 113 | * event_groups.h |
dflet | 3:a8c249046181 | 114 | * |
dflet | 3:a8c249046181 | 115 | * Type by which event groups are referenced. For example, a call to |
dflet | 3:a8c249046181 | 116 | * xEventGroupCreate() returns an EventGroupHandle_t variable that can then |
dflet | 3:a8c249046181 | 117 | * be used as a parameter to other event group functions. |
dflet | 3:a8c249046181 | 118 | * |
dflet | 3:a8c249046181 | 119 | * \defgroup EventGroupHandle_t EventGroupHandle_t |
dflet | 3:a8c249046181 | 120 | * \ingroup EventGroup |
dflet | 3:a8c249046181 | 121 | */ |
dflet | 3:a8c249046181 | 122 | typedef void * EventGroupHandle_t; |
dflet | 3:a8c249046181 | 123 | |
dflet | 3:a8c249046181 | 124 | /* |
dflet | 3:a8c249046181 | 125 | * The type that holds event bits always matches TickType_t - therefore the |
dflet | 3:a8c249046181 | 126 | * number of bits it holds is set by configUSE_16_BIT_TICKS (16 bits if set to 1, |
dflet | 3:a8c249046181 | 127 | * 32 bits if set to 0. |
dflet | 3:a8c249046181 | 128 | * |
dflet | 3:a8c249046181 | 129 | * \defgroup EventBits_t EventBits_t |
dflet | 3:a8c249046181 | 130 | * \ingroup EventGroup |
dflet | 3:a8c249046181 | 131 | */ |
dflet | 3:a8c249046181 | 132 | typedef TickType_t EventBits_t; |
dflet | 3:a8c249046181 | 133 | |
dflet | 3:a8c249046181 | 134 | /** |
dflet | 3:a8c249046181 | 135 | * event_groups.h |
dflet | 3:a8c249046181 | 136 | *<pre> |
dflet | 3:a8c249046181 | 137 | EventGroupHandle_t xEventGroupCreate( void ); |
dflet | 3:a8c249046181 | 138 | </pre> |
dflet | 3:a8c249046181 | 139 | * |
dflet | 3:a8c249046181 | 140 | * Create a new event group. This function cannot be called from an interrupt. |
dflet | 3:a8c249046181 | 141 | * |
dflet | 3:a8c249046181 | 142 | * Although event groups are not related to ticks, for internal implementation |
dflet | 3:a8c249046181 | 143 | * reasons the number of bits available for use in an event group is dependent |
dflet | 3:a8c249046181 | 144 | * on the configUSE_16_BIT_TICKS setting in FreeRTOSConfig.h. If |
dflet | 3:a8c249046181 | 145 | * configUSE_16_BIT_TICKS is 1 then each event group contains 8 usable bits (bit |
dflet | 3:a8c249046181 | 146 | * 0 to bit 7). If configUSE_16_BIT_TICKS is set to 0 then each event group has |
dflet | 3:a8c249046181 | 147 | * 24 usable bits (bit 0 to bit 23). The EventBits_t type is used to store |
dflet | 3:a8c249046181 | 148 | * event bits within an event group. |
dflet | 3:a8c249046181 | 149 | * |
dflet | 3:a8c249046181 | 150 | * @return If the event group was created then a handle to the event group is |
dflet | 3:a8c249046181 | 151 | * returned. If there was insufficient FreeRTOS heap available to create the |
dflet | 3:a8c249046181 | 152 | * event group then NULL is returned. See http://www.freertos.org/a00111.html |
dflet | 3:a8c249046181 | 153 | * |
dflet | 3:a8c249046181 | 154 | * Example usage: |
dflet | 3:a8c249046181 | 155 | <pre> |
dflet | 3:a8c249046181 | 156 | // Declare a variable to hold the created event group. |
dflet | 3:a8c249046181 | 157 | EventGroupHandle_t xCreatedEventGroup; |
dflet | 3:a8c249046181 | 158 | |
dflet | 3:a8c249046181 | 159 | // Attempt to create the event group. |
dflet | 3:a8c249046181 | 160 | xCreatedEventGroup = xEventGroupCreate(); |
dflet | 3:a8c249046181 | 161 | |
dflet | 3:a8c249046181 | 162 | // Was the event group created successfully? |
dflet | 3:a8c249046181 | 163 | if( xCreatedEventGroup == NULL ) |
dflet | 3:a8c249046181 | 164 | { |
dflet | 3:a8c249046181 | 165 | // The event group was not created because there was insufficient |
dflet | 3:a8c249046181 | 166 | // FreeRTOS heap available. |
dflet | 3:a8c249046181 | 167 | } |
dflet | 3:a8c249046181 | 168 | else |
dflet | 3:a8c249046181 | 169 | { |
dflet | 3:a8c249046181 | 170 | // The event group was created. |
dflet | 3:a8c249046181 | 171 | } |
dflet | 3:a8c249046181 | 172 | </pre> |
dflet | 3:a8c249046181 | 173 | * \defgroup xEventGroupCreate xEventGroupCreate |
dflet | 3:a8c249046181 | 174 | * \ingroup EventGroup |
dflet | 3:a8c249046181 | 175 | */ |
dflet | 3:a8c249046181 | 176 | EventGroupHandle_t xEventGroupCreate( void ) PRIVILEGED_FUNCTION; |
dflet | 3:a8c249046181 | 177 | |
dflet | 3:a8c249046181 | 178 | /** |
dflet | 3:a8c249046181 | 179 | * event_groups.h |
dflet | 3:a8c249046181 | 180 | *<pre> |
dflet | 3:a8c249046181 | 181 | EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup, |
dflet | 3:a8c249046181 | 182 | const EventBits_t uxBitsToWaitFor, |
dflet | 3:a8c249046181 | 183 | const BaseType_t xClearOnExit, |
dflet | 3:a8c249046181 | 184 | const BaseType_t xWaitForAllBits, |
dflet | 3:a8c249046181 | 185 | const TickType_t xTicksToWait ); |
dflet | 3:a8c249046181 | 186 | </pre> |
dflet | 3:a8c249046181 | 187 | * |
dflet | 3:a8c249046181 | 188 | * [Potentially] block to wait for one or more bits to be set within a |
dflet | 3:a8c249046181 | 189 | * previously created event group. |
dflet | 3:a8c249046181 | 190 | * |
dflet | 3:a8c249046181 | 191 | * This function cannot be called from an interrupt. |
dflet | 3:a8c249046181 | 192 | * |
dflet | 3:a8c249046181 | 193 | * @param xEventGroup The event group in which the bits are being tested. The |
dflet | 3:a8c249046181 | 194 | * event group must have previously been created using a call to |
dflet | 3:a8c249046181 | 195 | * xEventGroupCreate(). |
dflet | 3:a8c249046181 | 196 | * |
dflet | 3:a8c249046181 | 197 | * @param uxBitsToWaitFor A bitwise value that indicates the bit or bits to test |
dflet | 3:a8c249046181 | 198 | * inside the event group. For example, to wait for bit 0 and/or bit 2 set |
dflet | 3:a8c249046181 | 199 | * uxBitsToWaitFor to 0x05. To wait for bits 0 and/or bit 1 and/or bit 2 set |
dflet | 3:a8c249046181 | 200 | * uxBitsToWaitFor to 0x07. Etc. |
dflet | 3:a8c249046181 | 201 | * |
dflet | 3:a8c249046181 | 202 | * @param xClearOnExit If xClearOnExit is set to pdTRUE then any bits within |
dflet | 3:a8c249046181 | 203 | * uxBitsToWaitFor that are set within the event group will be cleared before |
dflet | 3:a8c249046181 | 204 | * xEventGroupWaitBits() returns if the wait condition was met (if the function |
dflet | 3:a8c249046181 | 205 | * returns for a reason other than a timeout). If xClearOnExit is set to |
dflet | 3:a8c249046181 | 206 | * pdFALSE then the bits set in the event group are not altered when the call to |
dflet | 3:a8c249046181 | 207 | * xEventGroupWaitBits() returns. |
dflet | 3:a8c249046181 | 208 | * |
dflet | 3:a8c249046181 | 209 | * @param xWaitForAllBits If xWaitForAllBits is set to pdTRUE then |
dflet | 3:a8c249046181 | 210 | * xEventGroupWaitBits() will return when either all the bits in uxBitsToWaitFor |
dflet | 3:a8c249046181 | 211 | * are set or the specified block time expires. If xWaitForAllBits is set to |
dflet | 3:a8c249046181 | 212 | * pdFALSE then xEventGroupWaitBits() will return when any one of the bits set |
dflet | 3:a8c249046181 | 213 | * in uxBitsToWaitFor is set or the specified block time expires. The block |
dflet | 3:a8c249046181 | 214 | * time is specified by the xTicksToWait parameter. |
dflet | 3:a8c249046181 | 215 | * |
dflet | 3:a8c249046181 | 216 | * @param xTicksToWait The maximum amount of time (specified in 'ticks') to wait |
dflet | 3:a8c249046181 | 217 | * for one/all (depending on the xWaitForAllBits value) of the bits specified by |
dflet | 3:a8c249046181 | 218 | * uxBitsToWaitFor to become set. |
dflet | 3:a8c249046181 | 219 | * |
dflet | 3:a8c249046181 | 220 | * @return The value of the event group at the time either the bits being waited |
dflet | 3:a8c249046181 | 221 | * for became set, or the block time expired. Test the return value to know |
dflet | 3:a8c249046181 | 222 | * which bits were set. If xEventGroupWaitBits() returned because its timeout |
dflet | 3:a8c249046181 | 223 | * expired then not all the bits being waited for will be set. If |
dflet | 3:a8c249046181 | 224 | * xEventGroupWaitBits() returned because the bits it was waiting for were set |
dflet | 3:a8c249046181 | 225 | * then the returned value is the event group value before any bits were |
dflet | 3:a8c249046181 | 226 | * automatically cleared in the case that xClearOnExit parameter was set to |
dflet | 3:a8c249046181 | 227 | * pdTRUE. |
dflet | 3:a8c249046181 | 228 | * |
dflet | 3:a8c249046181 | 229 | * Example usage: |
dflet | 3:a8c249046181 | 230 | <pre> |
dflet | 3:a8c249046181 | 231 | #define BIT_0 ( 1 << 0 ) |
dflet | 3:a8c249046181 | 232 | #define BIT_4 ( 1 << 4 ) |
dflet | 3:a8c249046181 | 233 | |
dflet | 3:a8c249046181 | 234 | void aFunction( EventGroupHandle_t xEventGroup ) |
dflet | 3:a8c249046181 | 235 | { |
dflet | 3:a8c249046181 | 236 | EventBits_t uxBits; |
dflet | 3:a8c249046181 | 237 | const TickType_t xTicksToWait = 100 / portTICK_PERIOD_MS; |
dflet | 3:a8c249046181 | 238 | |
dflet | 3:a8c249046181 | 239 | // Wait a maximum of 100ms for either bit 0 or bit 4 to be set within |
dflet | 3:a8c249046181 | 240 | // the event group. Clear the bits before exiting. |
dflet | 3:a8c249046181 | 241 | uxBits = xEventGroupWaitBits( |
dflet | 3:a8c249046181 | 242 | xEventGroup, // The event group being tested. |
dflet | 3:a8c249046181 | 243 | BIT_0 | BIT_4, // The bits within the event group to wait for. |
dflet | 3:a8c249046181 | 244 | pdTRUE, // BIT_0 and BIT_4 should be cleared before returning. |
dflet | 3:a8c249046181 | 245 | pdFALSE, // Don't wait for both bits, either bit will do. |
dflet | 3:a8c249046181 | 246 | xTicksToWait ); // Wait a maximum of 100ms for either bit to be set. |
dflet | 3:a8c249046181 | 247 | |
dflet | 3:a8c249046181 | 248 | if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) ) |
dflet | 3:a8c249046181 | 249 | { |
dflet | 3:a8c249046181 | 250 | // xEventGroupWaitBits() returned because both bits were set. |
dflet | 3:a8c249046181 | 251 | } |
dflet | 3:a8c249046181 | 252 | else if( ( uxBits & BIT_0 ) != 0 ) |
dflet | 3:a8c249046181 | 253 | { |
dflet | 3:a8c249046181 | 254 | // xEventGroupWaitBits() returned because just BIT_0 was set. |
dflet | 3:a8c249046181 | 255 | } |
dflet | 3:a8c249046181 | 256 | else if( ( uxBits & BIT_4 ) != 0 ) |
dflet | 3:a8c249046181 | 257 | { |
dflet | 3:a8c249046181 | 258 | // xEventGroupWaitBits() returned because just BIT_4 was set. |
dflet | 3:a8c249046181 | 259 | } |
dflet | 3:a8c249046181 | 260 | else |
dflet | 3:a8c249046181 | 261 | { |
dflet | 3:a8c249046181 | 262 | // xEventGroupWaitBits() returned because xTicksToWait ticks passed |
dflet | 3:a8c249046181 | 263 | // without either BIT_0 or BIT_4 becoming set. |
dflet | 3:a8c249046181 | 264 | } |
dflet | 3:a8c249046181 | 265 | } |
dflet | 3:a8c249046181 | 266 | </pre> |
dflet | 3:a8c249046181 | 267 | * \defgroup xEventGroupWaitBits xEventGroupWaitBits |
dflet | 3:a8c249046181 | 268 | * \ingroup EventGroup |
dflet | 3:a8c249046181 | 269 | */ |
dflet | 3:a8c249046181 | 270 | EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToWaitFor, const BaseType_t xClearOnExit, const BaseType_t xWaitForAllBits, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; |
dflet | 3:a8c249046181 | 271 | |
dflet | 3:a8c249046181 | 272 | /** |
dflet | 3:a8c249046181 | 273 | * event_groups.h |
dflet | 3:a8c249046181 | 274 | *<pre> |
dflet | 3:a8c249046181 | 275 | EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear ); |
dflet | 3:a8c249046181 | 276 | </pre> |
dflet | 3:a8c249046181 | 277 | * |
dflet | 3:a8c249046181 | 278 | * Clear bits within an event group. This function cannot be called from an |
dflet | 3:a8c249046181 | 279 | * interrupt. |
dflet | 3:a8c249046181 | 280 | * |
dflet | 3:a8c249046181 | 281 | * @param xEventGroup The event group in which the bits are to be cleared. |
dflet | 3:a8c249046181 | 282 | * |
dflet | 3:a8c249046181 | 283 | * @param uxBitsToClear A bitwise value that indicates the bit or bits to clear |
dflet | 3:a8c249046181 | 284 | * in the event group. For example, to clear bit 3 only, set uxBitsToClear to |
dflet | 3:a8c249046181 | 285 | * 0x08. To clear bit 3 and bit 0 set uxBitsToClear to 0x09. |
dflet | 3:a8c249046181 | 286 | * |
dflet | 3:a8c249046181 | 287 | * @return The value of the event group before the specified bits were cleared. |
dflet | 3:a8c249046181 | 288 | * |
dflet | 3:a8c249046181 | 289 | * Example usage: |
dflet | 3:a8c249046181 | 290 | <pre> |
dflet | 3:a8c249046181 | 291 | #define BIT_0 ( 1 << 0 ) |
dflet | 3:a8c249046181 | 292 | #define BIT_4 ( 1 << 4 ) |
dflet | 3:a8c249046181 | 293 | |
dflet | 3:a8c249046181 | 294 | void aFunction( EventGroupHandle_t xEventGroup ) |
dflet | 3:a8c249046181 | 295 | { |
dflet | 3:a8c249046181 | 296 | EventBits_t uxBits; |
dflet | 3:a8c249046181 | 297 | |
dflet | 3:a8c249046181 | 298 | // Clear bit 0 and bit 4 in xEventGroup. |
dflet | 3:a8c249046181 | 299 | uxBits = xEventGroupClearBits( |
dflet | 3:a8c249046181 | 300 | xEventGroup, // The event group being updated. |
dflet | 3:a8c249046181 | 301 | BIT_0 | BIT_4 );// The bits being cleared. |
dflet | 3:a8c249046181 | 302 | |
dflet | 3:a8c249046181 | 303 | if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) ) |
dflet | 3:a8c249046181 | 304 | { |
dflet | 3:a8c249046181 | 305 | // Both bit 0 and bit 4 were set before xEventGroupClearBits() was |
dflet | 3:a8c249046181 | 306 | // called. Both will now be clear (not set). |
dflet | 3:a8c249046181 | 307 | } |
dflet | 3:a8c249046181 | 308 | else if( ( uxBits & BIT_0 ) != 0 ) |
dflet | 3:a8c249046181 | 309 | { |
dflet | 3:a8c249046181 | 310 | // Bit 0 was set before xEventGroupClearBits() was called. It will |
dflet | 3:a8c249046181 | 311 | // now be clear. |
dflet | 3:a8c249046181 | 312 | } |
dflet | 3:a8c249046181 | 313 | else if( ( uxBits & BIT_4 ) != 0 ) |
dflet | 3:a8c249046181 | 314 | { |
dflet | 3:a8c249046181 | 315 | // Bit 4 was set before xEventGroupClearBits() was called. It will |
dflet | 3:a8c249046181 | 316 | // now be clear. |
dflet | 3:a8c249046181 | 317 | } |
dflet | 3:a8c249046181 | 318 | else |
dflet | 3:a8c249046181 | 319 | { |
dflet | 3:a8c249046181 | 320 | // Neither bit 0 nor bit 4 were set in the first place. |
dflet | 3:a8c249046181 | 321 | } |
dflet | 3:a8c249046181 | 322 | } |
dflet | 3:a8c249046181 | 323 | </pre> |
dflet | 3:a8c249046181 | 324 | * \defgroup xEventGroupClearBits xEventGroupClearBits |
dflet | 3:a8c249046181 | 325 | * \ingroup EventGroup |
dflet | 3:a8c249046181 | 326 | */ |
dflet | 3:a8c249046181 | 327 | EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear ) PRIVILEGED_FUNCTION; |
dflet | 3:a8c249046181 | 328 | |
dflet | 3:a8c249046181 | 329 | /** |
dflet | 3:a8c249046181 | 330 | * event_groups.h |
dflet | 3:a8c249046181 | 331 | *<pre> |
dflet | 3:a8c249046181 | 332 | BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet ); |
dflet | 3:a8c249046181 | 333 | </pre> |
dflet | 3:a8c249046181 | 334 | * |
dflet | 3:a8c249046181 | 335 | * A version of xEventGroupClearBits() that can be called from an interrupt. |
dflet | 3:a8c249046181 | 336 | * |
dflet | 3:a8c249046181 | 337 | * Setting bits in an event group is not a deterministic operation because there |
dflet | 3:a8c249046181 | 338 | * are an unknown number of tasks that may be waiting for the bit or bits being |
dflet | 3:a8c249046181 | 339 | * set. FreeRTOS does not allow nondeterministic operations to be performed |
dflet | 3:a8c249046181 | 340 | * while interrupts are disabled, so protects event groups that are accessed |
dflet | 3:a8c249046181 | 341 | * from tasks by suspending the scheduler rather than disabling interrupts. As |
dflet | 3:a8c249046181 | 342 | * a result event groups cannot be accessed directly from an interrupt service |
dflet | 3:a8c249046181 | 343 | * routine. Therefore xEventGroupClearBitsFromISR() sends a message to the |
dflet | 3:a8c249046181 | 344 | * timer task to have the clear operation performed in the context of the timer |
dflet | 3:a8c249046181 | 345 | * task. |
dflet | 3:a8c249046181 | 346 | * |
dflet | 3:a8c249046181 | 347 | * @param xEventGroup The event group in which the bits are to be cleared. |
dflet | 3:a8c249046181 | 348 | * |
dflet | 3:a8c249046181 | 349 | * @param uxBitsToClear A bitwise value that indicates the bit or bits to clear. |
dflet | 3:a8c249046181 | 350 | * For example, to clear bit 3 only, set uxBitsToClear to 0x08. To clear bit 3 |
dflet | 3:a8c249046181 | 351 | * and bit 0 set uxBitsToClear to 0x09. |
dflet | 3:a8c249046181 | 352 | * |
dflet | 3:a8c249046181 | 353 | * @return If the request to execute the function was posted successfully then |
dflet | 3:a8c249046181 | 354 | * pdPASS is returned, otherwise pdFALSE is returned. pdFALSE will be returned |
dflet | 3:a8c249046181 | 355 | * if the timer service queue was full. |
dflet | 3:a8c249046181 | 356 | * |
dflet | 3:a8c249046181 | 357 | * Example usage: |
dflet | 3:a8c249046181 | 358 | <pre> |
dflet | 3:a8c249046181 | 359 | #define BIT_0 ( 1 << 0 ) |
dflet | 3:a8c249046181 | 360 | #define BIT_4 ( 1 << 4 ) |
dflet | 3:a8c249046181 | 361 | |
dflet | 3:a8c249046181 | 362 | // An event group which it is assumed has already been created by a call to |
dflet | 3:a8c249046181 | 363 | // xEventGroupCreate(). |
dflet | 3:a8c249046181 | 364 | EventGroupHandle_t xEventGroup; |
dflet | 3:a8c249046181 | 365 | |
dflet | 3:a8c249046181 | 366 | void anInterruptHandler( void ) |
dflet | 3:a8c249046181 | 367 | { |
dflet | 3:a8c249046181 | 368 | // Clear bit 0 and bit 4 in xEventGroup. |
dflet | 3:a8c249046181 | 369 | xResult = xEventGroupClearBitsFromISR( |
dflet | 3:a8c249046181 | 370 | xEventGroup, // The event group being updated. |
dflet | 3:a8c249046181 | 371 | BIT_0 | BIT_4 ); // The bits being set. |
dflet | 3:a8c249046181 | 372 | |
dflet | 3:a8c249046181 | 373 | if( xResult == pdPASS ) |
dflet | 3:a8c249046181 | 374 | { |
dflet | 3:a8c249046181 | 375 | // The message was posted successfully. |
dflet | 3:a8c249046181 | 376 | } |
dflet | 3:a8c249046181 | 377 | } |
dflet | 3:a8c249046181 | 378 | </pre> |
dflet | 3:a8c249046181 | 379 | * \defgroup xEventGroupSetBitsFromISR xEventGroupSetBitsFromISR |
dflet | 3:a8c249046181 | 380 | * \ingroup EventGroup |
dflet | 3:a8c249046181 | 381 | */ |
dflet | 3:a8c249046181 | 382 | #if( configUSE_TRACE_FACILITY == 1 ) |
dflet | 3:a8c249046181 | 383 | BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet ); |
dflet | 3:a8c249046181 | 384 | #else |
dflet | 3:a8c249046181 | 385 | #define xEventGroupClearBitsFromISR( xEventGroup, uxBitsToClear ) xTimerPendFunctionCallFromISR( vEventGroupClearBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToClear, NULL ) |
dflet | 3:a8c249046181 | 386 | #endif |
dflet | 3:a8c249046181 | 387 | |
dflet | 3:a8c249046181 | 388 | /** |
dflet | 3:a8c249046181 | 389 | * event_groups.h |
dflet | 3:a8c249046181 | 390 | *<pre> |
dflet | 3:a8c249046181 | 391 | EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet ); |
dflet | 3:a8c249046181 | 392 | </pre> |
dflet | 3:a8c249046181 | 393 | * |
dflet | 3:a8c249046181 | 394 | * Set bits within an event group. |
dflet | 3:a8c249046181 | 395 | * This function cannot be called from an interrupt. xEventGroupSetBitsFromISR() |
dflet | 3:a8c249046181 | 396 | * is a version that can be called from an interrupt. |
dflet | 3:a8c249046181 | 397 | * |
dflet | 3:a8c249046181 | 398 | * Setting bits in an event group will automatically unblock tasks that are |
dflet | 3:a8c249046181 | 399 | * blocked waiting for the bits. |
dflet | 3:a8c249046181 | 400 | * |
dflet | 3:a8c249046181 | 401 | * @param xEventGroup The event group in which the bits are to be set. |
dflet | 3:a8c249046181 | 402 | * |
dflet | 3:a8c249046181 | 403 | * @param uxBitsToSet A bitwise value that indicates the bit or bits to set. |
dflet | 3:a8c249046181 | 404 | * For example, to set bit 3 only, set uxBitsToSet to 0x08. To set bit 3 |
dflet | 3:a8c249046181 | 405 | * and bit 0 set uxBitsToSet to 0x09. |
dflet | 3:a8c249046181 | 406 | * |
dflet | 3:a8c249046181 | 407 | * @return The value of the event group at the time the call to |
dflet | 3:a8c249046181 | 408 | * xEventGroupSetBits() returns. There are two reasons why the returned value |
dflet | 3:a8c249046181 | 409 | * might have the bits specified by the uxBitsToSet parameter cleared. First, |
dflet | 3:a8c249046181 | 410 | * if setting a bit results in a task that was waiting for the bit leaving the |
dflet | 3:a8c249046181 | 411 | * blocked state then it is possible the bit will be cleared automatically |
dflet | 3:a8c249046181 | 412 | * (see the xClearBitOnExit parameter of xEventGroupWaitBits()). Second, any |
dflet | 3:a8c249046181 | 413 | * unblocked (or otherwise Ready state) task that has a priority above that of |
dflet | 3:a8c249046181 | 414 | * the task that called xEventGroupSetBits() will execute and may change the |
dflet | 3:a8c249046181 | 415 | * event group value before the call to xEventGroupSetBits() returns. |
dflet | 3:a8c249046181 | 416 | * |
dflet | 3:a8c249046181 | 417 | * Example usage: |
dflet | 3:a8c249046181 | 418 | <pre> |
dflet | 3:a8c249046181 | 419 | #define BIT_0 ( 1 << 0 ) |
dflet | 3:a8c249046181 | 420 | #define BIT_4 ( 1 << 4 ) |
dflet | 3:a8c249046181 | 421 | |
dflet | 3:a8c249046181 | 422 | void aFunction( EventGroupHandle_t xEventGroup ) |
dflet | 3:a8c249046181 | 423 | { |
dflet | 3:a8c249046181 | 424 | EventBits_t uxBits; |
dflet | 3:a8c249046181 | 425 | |
dflet | 3:a8c249046181 | 426 | // Set bit 0 and bit 4 in xEventGroup. |
dflet | 3:a8c249046181 | 427 | uxBits = xEventGroupSetBits( |
dflet | 3:a8c249046181 | 428 | xEventGroup, // The event group being updated. |
dflet | 3:a8c249046181 | 429 | BIT_0 | BIT_4 );// The bits being set. |
dflet | 3:a8c249046181 | 430 | |
dflet | 3:a8c249046181 | 431 | if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) ) |
dflet | 3:a8c249046181 | 432 | { |
dflet | 3:a8c249046181 | 433 | // Both bit 0 and bit 4 remained set when the function returned. |
dflet | 3:a8c249046181 | 434 | } |
dflet | 3:a8c249046181 | 435 | else if( ( uxBits & BIT_0 ) != 0 ) |
dflet | 3:a8c249046181 | 436 | { |
dflet | 3:a8c249046181 | 437 | // Bit 0 remained set when the function returned, but bit 4 was |
dflet | 3:a8c249046181 | 438 | // cleared. It might be that bit 4 was cleared automatically as a |
dflet | 3:a8c249046181 | 439 | // task that was waiting for bit 4 was removed from the Blocked |
dflet | 3:a8c249046181 | 440 | // state. |
dflet | 3:a8c249046181 | 441 | } |
dflet | 3:a8c249046181 | 442 | else if( ( uxBits & BIT_4 ) != 0 ) |
dflet | 3:a8c249046181 | 443 | { |
dflet | 3:a8c249046181 | 444 | // Bit 4 remained set when the function returned, but bit 0 was |
dflet | 3:a8c249046181 | 445 | // cleared. It might be that bit 0 was cleared automatically as a |
dflet | 3:a8c249046181 | 446 | // task that was waiting for bit 0 was removed from the Blocked |
dflet | 3:a8c249046181 | 447 | // state. |
dflet | 3:a8c249046181 | 448 | } |
dflet | 3:a8c249046181 | 449 | else |
dflet | 3:a8c249046181 | 450 | { |
dflet | 3:a8c249046181 | 451 | // Neither bit 0 nor bit 4 remained set. It might be that a task |
dflet | 3:a8c249046181 | 452 | // was waiting for both of the bits to be set, and the bits were |
dflet | 3:a8c249046181 | 453 | // cleared as the task left the Blocked state. |
dflet | 3:a8c249046181 | 454 | } |
dflet | 3:a8c249046181 | 455 | } |
dflet | 3:a8c249046181 | 456 | </pre> |
dflet | 3:a8c249046181 | 457 | * \defgroup xEventGroupSetBits xEventGroupSetBits |
dflet | 3:a8c249046181 | 458 | * \ingroup EventGroup |
dflet | 3:a8c249046181 | 459 | */ |
dflet | 3:a8c249046181 | 460 | EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet ) PRIVILEGED_FUNCTION; |
dflet | 3:a8c249046181 | 461 | |
dflet | 3:a8c249046181 | 462 | /** |
dflet | 3:a8c249046181 | 463 | * event_groups.h |
dflet | 3:a8c249046181 | 464 | *<pre> |
dflet | 3:a8c249046181 | 465 | BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken ); |
dflet | 3:a8c249046181 | 466 | </pre> |
dflet | 3:a8c249046181 | 467 | * |
dflet | 3:a8c249046181 | 468 | * A version of xEventGroupSetBits() that can be called from an interrupt. |
dflet | 3:a8c249046181 | 469 | * |
dflet | 3:a8c249046181 | 470 | * Setting bits in an event group is not a deterministic operation because there |
dflet | 3:a8c249046181 | 471 | * are an unknown number of tasks that may be waiting for the bit or bits being |
dflet | 3:a8c249046181 | 472 | * set. FreeRTOS does not allow nondeterministic operations to be performed in |
dflet | 3:a8c249046181 | 473 | * interrupts or from critical sections. Therefore xEventGroupSetBitFromISR() |
dflet | 3:a8c249046181 | 474 | * sends a message to the timer task to have the set operation performed in the |
dflet | 3:a8c249046181 | 475 | * context of the timer task - where a scheduler lock is used in place of a |
dflet | 3:a8c249046181 | 476 | * critical section. |
dflet | 3:a8c249046181 | 477 | * |
dflet | 3:a8c249046181 | 478 | * @param xEventGroup The event group in which the bits are to be set. |
dflet | 3:a8c249046181 | 479 | * |
dflet | 3:a8c249046181 | 480 | * @param uxBitsToSet A bitwise value that indicates the bit or bits to set. |
dflet | 3:a8c249046181 | 481 | * For example, to set bit 3 only, set uxBitsToSet to 0x08. To set bit 3 |
dflet | 3:a8c249046181 | 482 | * and bit 0 set uxBitsToSet to 0x09. |
dflet | 3:a8c249046181 | 483 | * |
dflet | 3:a8c249046181 | 484 | * @param pxHigherPriorityTaskWoken As mentioned above, calling this function |
dflet | 3:a8c249046181 | 485 | * will result in a message being sent to the timer daemon task. If the |
dflet | 3:a8c249046181 | 486 | * priority of the timer daemon task is higher than the priority of the |
dflet | 3:a8c249046181 | 487 | * currently running task (the task the interrupt interrupted) then |
dflet | 3:a8c249046181 | 488 | * *pxHigherPriorityTaskWoken will be set to pdTRUE by |
dflet | 3:a8c249046181 | 489 | * xEventGroupSetBitsFromISR(), indicating that a context switch should be |
dflet | 3:a8c249046181 | 490 | * requested before the interrupt exits. For that reason |
dflet | 3:a8c249046181 | 491 | * *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the |
dflet | 3:a8c249046181 | 492 | * example code below. |
dflet | 3:a8c249046181 | 493 | * |
dflet | 3:a8c249046181 | 494 | * @return If the request to execute the function was posted successfully then |
dflet | 3:a8c249046181 | 495 | * pdPASS is returned, otherwise pdFALSE is returned. pdFALSE will be returned |
dflet | 3:a8c249046181 | 496 | * if the timer service queue was full. |
dflet | 3:a8c249046181 | 497 | * |
dflet | 3:a8c249046181 | 498 | * Example usage: |
dflet | 3:a8c249046181 | 499 | <pre> |
dflet | 3:a8c249046181 | 500 | #define BIT_0 ( 1 << 0 ) |
dflet | 3:a8c249046181 | 501 | #define BIT_4 ( 1 << 4 ) |
dflet | 3:a8c249046181 | 502 | |
dflet | 3:a8c249046181 | 503 | // An event group which it is assumed has already been created by a call to |
dflet | 3:a8c249046181 | 504 | // xEventGroupCreate(). |
dflet | 3:a8c249046181 | 505 | EventGroupHandle_t xEventGroup; |
dflet | 3:a8c249046181 | 506 | |
dflet | 3:a8c249046181 | 507 | void anInterruptHandler( void ) |
dflet | 3:a8c249046181 | 508 | { |
dflet | 3:a8c249046181 | 509 | BaseType_t xHigherPriorityTaskWoken, xResult; |
dflet | 3:a8c249046181 | 510 | |
dflet | 3:a8c249046181 | 511 | // xHigherPriorityTaskWoken must be initialised to pdFALSE. |
dflet | 3:a8c249046181 | 512 | xHigherPriorityTaskWoken = pdFALSE; |
dflet | 3:a8c249046181 | 513 | |
dflet | 3:a8c249046181 | 514 | // Set bit 0 and bit 4 in xEventGroup. |
dflet | 3:a8c249046181 | 515 | xResult = xEventGroupSetBitsFromISR( |
dflet | 3:a8c249046181 | 516 | xEventGroup, // The event group being updated. |
dflet | 3:a8c249046181 | 517 | BIT_0 | BIT_4 // The bits being set. |
dflet | 3:a8c249046181 | 518 | &xHigherPriorityTaskWoken ); |
dflet | 3:a8c249046181 | 519 | |
dflet | 3:a8c249046181 | 520 | // Was the message posted successfully? |
dflet | 3:a8c249046181 | 521 | if( xResult == pdPASS ) |
dflet | 3:a8c249046181 | 522 | { |
dflet | 3:a8c249046181 | 523 | // If xHigherPriorityTaskWoken is now set to pdTRUE then a context |
dflet | 3:a8c249046181 | 524 | // switch should be requested. The macro used is port specific and |
dflet | 3:a8c249046181 | 525 | // will be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() - |
dflet | 3:a8c249046181 | 526 | // refer to the documentation page for the port being used. |
dflet | 3:a8c249046181 | 527 | portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); |
dflet | 3:a8c249046181 | 528 | } |
dflet | 3:a8c249046181 | 529 | } |
dflet | 3:a8c249046181 | 530 | </pre> |
dflet | 3:a8c249046181 | 531 | * \defgroup xEventGroupSetBitsFromISR xEventGroupSetBitsFromISR |
dflet | 3:a8c249046181 | 532 | * \ingroup EventGroup |
dflet | 3:a8c249046181 | 533 | */ |
dflet | 3:a8c249046181 | 534 | #if( configUSE_TRACE_FACILITY == 1 ) |
dflet | 3:a8c249046181 | 535 | BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken ); |
dflet | 3:a8c249046181 | 536 | #else |
dflet | 3:a8c249046181 | 537 | #define xEventGroupSetBitsFromISR( xEventGroup, uxBitsToSet, pxHigherPriorityTaskWoken ) xTimerPendFunctionCallFromISR( vEventGroupSetBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToSet, pxHigherPriorityTaskWoken ) |
dflet | 3:a8c249046181 | 538 | #endif |
dflet | 3:a8c249046181 | 539 | |
dflet | 3:a8c249046181 | 540 | /** |
dflet | 3:a8c249046181 | 541 | * event_groups.h |
dflet | 3:a8c249046181 | 542 | *<pre> |
dflet | 3:a8c249046181 | 543 | EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup, |
dflet | 3:a8c249046181 | 544 | const EventBits_t uxBitsToSet, |
dflet | 3:a8c249046181 | 545 | const EventBits_t uxBitsToWaitFor, |
dflet | 3:a8c249046181 | 546 | TickType_t xTicksToWait ); |
dflet | 3:a8c249046181 | 547 | </pre> |
dflet | 3:a8c249046181 | 548 | * |
dflet | 3:a8c249046181 | 549 | * Atomically set bits within an event group, then wait for a combination of |
dflet | 3:a8c249046181 | 550 | * bits to be set within the same event group. This functionality is typically |
dflet | 3:a8c249046181 | 551 | * used to synchronise multiple tasks, where each task has to wait for the other |
dflet | 3:a8c249046181 | 552 | * tasks to reach a synchronisation point before proceeding. |
dflet | 3:a8c249046181 | 553 | * |
dflet | 3:a8c249046181 | 554 | * This function cannot be used from an interrupt. |
dflet | 3:a8c249046181 | 555 | * |
dflet | 3:a8c249046181 | 556 | * The function will return before its block time expires if the bits specified |
dflet | 3:a8c249046181 | 557 | * by the uxBitsToWait parameter are set, or become set within that time. In |
dflet | 3:a8c249046181 | 558 | * this case all the bits specified by uxBitsToWait will be automatically |
dflet | 3:a8c249046181 | 559 | * cleared before the function returns. |
dflet | 3:a8c249046181 | 560 | * |
dflet | 3:a8c249046181 | 561 | * @param xEventGroup The event group in which the bits are being tested. The |
dflet | 3:a8c249046181 | 562 | * event group must have previously been created using a call to |
dflet | 3:a8c249046181 | 563 | * xEventGroupCreate(). |
dflet | 3:a8c249046181 | 564 | * |
dflet | 3:a8c249046181 | 565 | * @param uxBitsToSet The bits to set in the event group before determining |
dflet | 3:a8c249046181 | 566 | * if, and possibly waiting for, all the bits specified by the uxBitsToWait |
dflet | 3:a8c249046181 | 567 | * parameter are set. |
dflet | 3:a8c249046181 | 568 | * |
dflet | 3:a8c249046181 | 569 | * @param uxBitsToWaitFor A bitwise value that indicates the bit or bits to test |
dflet | 3:a8c249046181 | 570 | * inside the event group. For example, to wait for bit 0 and bit 2 set |
dflet | 3:a8c249046181 | 571 | * uxBitsToWaitFor to 0x05. To wait for bits 0 and bit 1 and bit 2 set |
dflet | 3:a8c249046181 | 572 | * uxBitsToWaitFor to 0x07. Etc. |
dflet | 3:a8c249046181 | 573 | * |
dflet | 3:a8c249046181 | 574 | * @param xTicksToWait The maximum amount of time (specified in 'ticks') to wait |
dflet | 3:a8c249046181 | 575 | * for all of the bits specified by uxBitsToWaitFor to become set. |
dflet | 3:a8c249046181 | 576 | * |
dflet | 3:a8c249046181 | 577 | * @return The value of the event group at the time either the bits being waited |
dflet | 3:a8c249046181 | 578 | * for became set, or the block time expired. Test the return value to know |
dflet | 3:a8c249046181 | 579 | * which bits were set. If xEventGroupSync() returned because its timeout |
dflet | 3:a8c249046181 | 580 | * expired then not all the bits being waited for will be set. If |
dflet | 3:a8c249046181 | 581 | * xEventGroupSync() returned because all the bits it was waiting for were |
dflet | 3:a8c249046181 | 582 | * set then the returned value is the event group value before any bits were |
dflet | 3:a8c249046181 | 583 | * automatically cleared. |
dflet | 3:a8c249046181 | 584 | * |
dflet | 3:a8c249046181 | 585 | * Example usage: |
dflet | 3:a8c249046181 | 586 | <pre> |
dflet | 3:a8c249046181 | 587 | // Bits used by the three tasks. |
dflet | 3:a8c249046181 | 588 | #define TASK_0_BIT ( 1 << 0 ) |
dflet | 3:a8c249046181 | 589 | #define TASK_1_BIT ( 1 << 1 ) |
dflet | 3:a8c249046181 | 590 | #define TASK_2_BIT ( 1 << 2 ) |
dflet | 3:a8c249046181 | 591 | |
dflet | 3:a8c249046181 | 592 | #define ALL_SYNC_BITS ( TASK_0_BIT | TASK_1_BIT | TASK_2_BIT ) |
dflet | 3:a8c249046181 | 593 | |
dflet | 3:a8c249046181 | 594 | // Use an event group to synchronise three tasks. It is assumed this event |
dflet | 3:a8c249046181 | 595 | // group has already been created elsewhere. |
dflet | 3:a8c249046181 | 596 | EventGroupHandle_t xEventBits; |
dflet | 3:a8c249046181 | 597 | |
dflet | 3:a8c249046181 | 598 | void vTask0( void *pvParameters ) |
dflet | 3:a8c249046181 | 599 | { |
dflet | 3:a8c249046181 | 600 | EventBits_t uxReturn; |
dflet | 3:a8c249046181 | 601 | TickType_t xTicksToWait = 100 / portTICK_PERIOD_MS; |
dflet | 3:a8c249046181 | 602 | |
dflet | 3:a8c249046181 | 603 | for( ;; ) |
dflet | 3:a8c249046181 | 604 | { |
dflet | 3:a8c249046181 | 605 | // Perform task functionality here. |
dflet | 3:a8c249046181 | 606 | |
dflet | 3:a8c249046181 | 607 | // Set bit 0 in the event flag to note this task has reached the |
dflet | 3:a8c249046181 | 608 | // sync point. The other two tasks will set the other two bits defined |
dflet | 3:a8c249046181 | 609 | // by ALL_SYNC_BITS. All three tasks have reached the synchronisation |
dflet | 3:a8c249046181 | 610 | // point when all the ALL_SYNC_BITS are set. Wait a maximum of 100ms |
dflet | 3:a8c249046181 | 611 | // for this to happen. |
dflet | 3:a8c249046181 | 612 | uxReturn = xEventGroupSync( xEventBits, TASK_0_BIT, ALL_SYNC_BITS, xTicksToWait ); |
dflet | 3:a8c249046181 | 613 | |
dflet | 3:a8c249046181 | 614 | if( ( uxReturn & ALL_SYNC_BITS ) == ALL_SYNC_BITS ) |
dflet | 3:a8c249046181 | 615 | { |
dflet | 3:a8c249046181 | 616 | // All three tasks reached the synchronisation point before the call |
dflet | 3:a8c249046181 | 617 | // to xEventGroupSync() timed out. |
dflet | 3:a8c249046181 | 618 | } |
dflet | 3:a8c249046181 | 619 | } |
dflet | 3:a8c249046181 | 620 | } |
dflet | 3:a8c249046181 | 621 | |
dflet | 3:a8c249046181 | 622 | void vTask1( void *pvParameters ) |
dflet | 3:a8c249046181 | 623 | { |
dflet | 3:a8c249046181 | 624 | for( ;; ) |
dflet | 3:a8c249046181 | 625 | { |
dflet | 3:a8c249046181 | 626 | // Perform task functionality here. |
dflet | 3:a8c249046181 | 627 | |
dflet | 3:a8c249046181 | 628 | // Set bit 1 in the event flag to note this task has reached the |
dflet | 3:a8c249046181 | 629 | // synchronisation point. The other two tasks will set the other two |
dflet | 3:a8c249046181 | 630 | // bits defined by ALL_SYNC_BITS. All three tasks have reached the |
dflet | 3:a8c249046181 | 631 | // synchronisation point when all the ALL_SYNC_BITS are set. Wait |
dflet | 3:a8c249046181 | 632 | // indefinitely for this to happen. |
dflet | 3:a8c249046181 | 633 | xEventGroupSync( xEventBits, TASK_1_BIT, ALL_SYNC_BITS, portMAX_DELAY ); |
dflet | 3:a8c249046181 | 634 | |
dflet | 3:a8c249046181 | 635 | // xEventGroupSync() was called with an indefinite block time, so |
dflet | 3:a8c249046181 | 636 | // this task will only reach here if the syncrhonisation was made by all |
dflet | 3:a8c249046181 | 637 | // three tasks, so there is no need to test the return value. |
dflet | 3:a8c249046181 | 638 | } |
dflet | 3:a8c249046181 | 639 | } |
dflet | 3:a8c249046181 | 640 | |
dflet | 3:a8c249046181 | 641 | void vTask2( void *pvParameters ) |
dflet | 3:a8c249046181 | 642 | { |
dflet | 3:a8c249046181 | 643 | for( ;; ) |
dflet | 3:a8c249046181 | 644 | { |
dflet | 3:a8c249046181 | 645 | // Perform task functionality here. |
dflet | 3:a8c249046181 | 646 | |
dflet | 3:a8c249046181 | 647 | // Set bit 2 in the event flag to note this task has reached the |
dflet | 3:a8c249046181 | 648 | // synchronisation point. The other two tasks will set the other two |
dflet | 3:a8c249046181 | 649 | // bits defined by ALL_SYNC_BITS. All three tasks have reached the |
dflet | 3:a8c249046181 | 650 | // synchronisation point when all the ALL_SYNC_BITS are set. Wait |
dflet | 3:a8c249046181 | 651 | // indefinitely for this to happen. |
dflet | 3:a8c249046181 | 652 | xEventGroupSync( xEventBits, TASK_2_BIT, ALL_SYNC_BITS, portMAX_DELAY ); |
dflet | 3:a8c249046181 | 653 | |
dflet | 3:a8c249046181 | 654 | // xEventGroupSync() was called with an indefinite block time, so |
dflet | 3:a8c249046181 | 655 | // this task will only reach here if the syncrhonisation was made by all |
dflet | 3:a8c249046181 | 656 | // three tasks, so there is no need to test the return value. |
dflet | 3:a8c249046181 | 657 | } |
dflet | 3:a8c249046181 | 658 | } |
dflet | 3:a8c249046181 | 659 | |
dflet | 3:a8c249046181 | 660 | </pre> |
dflet | 3:a8c249046181 | 661 | * \defgroup xEventGroupSync xEventGroupSync |
dflet | 3:a8c249046181 | 662 | * \ingroup EventGroup |
dflet | 3:a8c249046181 | 663 | */ |
dflet | 3:a8c249046181 | 664 | EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, const EventBits_t uxBitsToWaitFor, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; |
dflet | 3:a8c249046181 | 665 | |
dflet | 3:a8c249046181 | 666 | |
dflet | 3:a8c249046181 | 667 | /** |
dflet | 3:a8c249046181 | 668 | * event_groups.h |
dflet | 3:a8c249046181 | 669 | *<pre> |
dflet | 3:a8c249046181 | 670 | EventBits_t xEventGroupGetBits( EventGroupHandle_t xEventGroup ); |
dflet | 3:a8c249046181 | 671 | </pre> |
dflet | 3:a8c249046181 | 672 | * |
dflet | 3:a8c249046181 | 673 | * Returns the current value of the bits in an event group. This function |
dflet | 3:a8c249046181 | 674 | * cannot be used from an interrupt. |
dflet | 3:a8c249046181 | 675 | * |
dflet | 3:a8c249046181 | 676 | * @param xEventGroup The event group being queried. |
dflet | 3:a8c249046181 | 677 | * |
dflet | 3:a8c249046181 | 678 | * @return The event group bits at the time xEventGroupGetBits() was called. |
dflet | 3:a8c249046181 | 679 | * |
dflet | 3:a8c249046181 | 680 | * \defgroup xEventGroupGetBits xEventGroupGetBits |
dflet | 3:a8c249046181 | 681 | * \ingroup EventGroup |
dflet | 3:a8c249046181 | 682 | */ |
dflet | 3:a8c249046181 | 683 | #define xEventGroupGetBits( xEventGroup ) xEventGroupClearBits( xEventGroup, 0 ) |
dflet | 3:a8c249046181 | 684 | |
dflet | 3:a8c249046181 | 685 | /** |
dflet | 3:a8c249046181 | 686 | * event_groups.h |
dflet | 3:a8c249046181 | 687 | *<pre> |
dflet | 3:a8c249046181 | 688 | EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup ); |
dflet | 3:a8c249046181 | 689 | </pre> |
dflet | 3:a8c249046181 | 690 | * |
dflet | 3:a8c249046181 | 691 | * A version of xEventGroupGetBits() that can be called from an ISR. |
dflet | 3:a8c249046181 | 692 | * |
dflet | 3:a8c249046181 | 693 | * @param xEventGroup The event group being queried. |
dflet | 3:a8c249046181 | 694 | * |
dflet | 3:a8c249046181 | 695 | * @return The event group bits at the time xEventGroupGetBitsFromISR() was called. |
dflet | 3:a8c249046181 | 696 | * |
dflet | 3:a8c249046181 | 697 | * \defgroup xEventGroupGetBitsFromISR xEventGroupGetBitsFromISR |
dflet | 3:a8c249046181 | 698 | * \ingroup EventGroup |
dflet | 3:a8c249046181 | 699 | */ |
dflet | 3:a8c249046181 | 700 | EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup ); |
dflet | 3:a8c249046181 | 701 | |
dflet | 3:a8c249046181 | 702 | /** |
dflet | 3:a8c249046181 | 703 | * event_groups.h |
dflet | 3:a8c249046181 | 704 | *<pre> |
dflet | 3:a8c249046181 | 705 | void xEventGroupDelete( EventGroupHandle_t xEventGroup ); |
dflet | 3:a8c249046181 | 706 | </pre> |
dflet | 3:a8c249046181 | 707 | * |
dflet | 3:a8c249046181 | 708 | * Delete an event group that was previously created by a call to |
dflet | 3:a8c249046181 | 709 | * xEventGroupCreate(). Tasks that are blocked on the event group will be |
dflet | 3:a8c249046181 | 710 | * unblocked and obtain 0 as the event group's value. |
dflet | 3:a8c249046181 | 711 | * |
dflet | 3:a8c249046181 | 712 | * @param xEventGroup The event group being deleted. |
dflet | 3:a8c249046181 | 713 | */ |
dflet | 3:a8c249046181 | 714 | void vEventGroupDelete( EventGroupHandle_t xEventGroup ); |
dflet | 3:a8c249046181 | 715 | |
dflet | 3:a8c249046181 | 716 | /* For internal use only. */ |
dflet | 3:a8c249046181 | 717 | void vEventGroupSetBitsCallback( void *pvEventGroup, const uint32_t ulBitsToSet ); |
dflet | 3:a8c249046181 | 718 | void vEventGroupClearBitsCallback( void *pvEventGroup, const uint32_t ulBitsToClear ); |
dflet | 3:a8c249046181 | 719 | |
dflet | 3:a8c249046181 | 720 | #if (configUSE_TRACE_FACILITY == 1) |
dflet | 3:a8c249046181 | 721 | UBaseType_t uxEventGroupGetNumber( void* xEventGroup ); |
dflet | 3:a8c249046181 | 722 | #endif |
dflet | 3:a8c249046181 | 723 | |
dflet | 3:a8c249046181 | 724 | #ifdef __cplusplus |
dflet | 3:a8c249046181 | 725 | } |
dflet | 3:a8c249046181 | 726 | #endif |
dflet | 3:a8c249046181 | 727 | |
dflet | 3:a8c249046181 | 728 | #endif /* EVENT_GROUPS_H */ |
dflet | 3:a8c249046181 | 729 | |
dflet | 3:a8c249046181 | 730 | |
dflet | 3:a8c249046181 | 731 |