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/event_groups.c@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 | /* Standard includes. */ |
dflet | 3:a8c249046181 | 71 | #include <stdlib.h> |
dflet | 3:a8c249046181 | 72 | |
dflet | 3:a8c249046181 | 73 | /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining |
dflet | 3:a8c249046181 | 74 | all the API functions to use the MPU wrappers. That should only be done when |
dflet | 3:a8c249046181 | 75 | task.h is included from an application file. */ |
dflet | 3:a8c249046181 | 76 | #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE |
dflet | 3:a8c249046181 | 77 | |
dflet | 3:a8c249046181 | 78 | /* FreeRTOS includes. */ |
dflet | 3:a8c249046181 | 79 | #include "FreeRTOS.h" |
dflet | 3:a8c249046181 | 80 | #include "task.h" |
dflet | 3:a8c249046181 | 81 | #include "timers.h" |
dflet | 3:a8c249046181 | 82 | #include "event_groups.h" |
dflet | 3:a8c249046181 | 83 | |
dflet | 3:a8c249046181 | 84 | /* Lint e961 and e750 are suppressed as a MISRA exception justified because the |
dflet | 3:a8c249046181 | 85 | MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined for the |
dflet | 3:a8c249046181 | 86 | header files above, but not in this file, in order to generate the correct |
dflet | 3:a8c249046181 | 87 | privileged Vs unprivileged linkage and placement. */ |
dflet | 3:a8c249046181 | 88 | #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750. */ |
dflet | 3:a8c249046181 | 89 | |
dflet | 3:a8c249046181 | 90 | #if ( INCLUDE_xEventGroupSetBitFromISR == 1 ) && ( configUSE_TIMERS == 0 ) |
dflet | 3:a8c249046181 | 91 | #error configUSE_TIMERS must be set to 1 to make the xEventGroupSetBitFromISR() function available. |
dflet | 3:a8c249046181 | 92 | #endif |
dflet | 3:a8c249046181 | 93 | |
dflet | 3:a8c249046181 | 94 | #if ( INCLUDE_xEventGroupSetBitFromISR == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 0 ) |
dflet | 3:a8c249046181 | 95 | #error INCLUDE_xTimerPendFunctionCall must also be set to one to make the xEventGroupSetBitFromISR() function available. |
dflet | 3:a8c249046181 | 96 | #endif |
dflet | 3:a8c249046181 | 97 | |
dflet | 3:a8c249046181 | 98 | /* The following bit fields convey control information in a task's event list |
dflet | 3:a8c249046181 | 99 | item value. It is important they don't clash with the |
dflet | 3:a8c249046181 | 100 | taskEVENT_LIST_ITEM_VALUE_IN_USE definition. */ |
dflet | 3:a8c249046181 | 101 | #if configUSE_16_BIT_TICKS == 1 |
dflet | 3:a8c249046181 | 102 | #define eventCLEAR_EVENTS_ON_EXIT_BIT 0x0100U |
dflet | 3:a8c249046181 | 103 | #define eventUNBLOCKED_DUE_TO_BIT_SET 0x0200U |
dflet | 3:a8c249046181 | 104 | #define eventWAIT_FOR_ALL_BITS 0x0400U |
dflet | 3:a8c249046181 | 105 | #define eventEVENT_BITS_CONTROL_BYTES 0xff00U |
dflet | 3:a8c249046181 | 106 | #else |
dflet | 3:a8c249046181 | 107 | #define eventCLEAR_EVENTS_ON_EXIT_BIT 0x01000000UL |
dflet | 3:a8c249046181 | 108 | #define eventUNBLOCKED_DUE_TO_BIT_SET 0x02000000UL |
dflet | 3:a8c249046181 | 109 | #define eventWAIT_FOR_ALL_BITS 0x04000000UL |
dflet | 3:a8c249046181 | 110 | #define eventEVENT_BITS_CONTROL_BYTES 0xff000000UL |
dflet | 3:a8c249046181 | 111 | #endif |
dflet | 3:a8c249046181 | 112 | |
dflet | 3:a8c249046181 | 113 | typedef struct xEventGroupDefinition |
dflet | 3:a8c249046181 | 114 | { |
dflet | 3:a8c249046181 | 115 | EventBits_t uxEventBits; |
dflet | 3:a8c249046181 | 116 | List_t xTasksWaitingForBits; /*< List of tasks waiting for a bit to be set. */ |
dflet | 3:a8c249046181 | 117 | |
dflet | 3:a8c249046181 | 118 | #if( configUSE_TRACE_FACILITY == 1 ) |
dflet | 3:a8c249046181 | 119 | UBaseType_t uxEventGroupNumber; |
dflet | 3:a8c249046181 | 120 | #endif |
dflet | 3:a8c249046181 | 121 | |
dflet | 3:a8c249046181 | 122 | } EventGroup_t; |
dflet | 3:a8c249046181 | 123 | |
dflet | 3:a8c249046181 | 124 | /*-----------------------------------------------------------*/ |
dflet | 3:a8c249046181 | 125 | |
dflet | 3:a8c249046181 | 126 | /* |
dflet | 3:a8c249046181 | 127 | * Test the bits set in uxCurrentEventBits to see if the wait condition is met. |
dflet | 3:a8c249046181 | 128 | * The wait condition is defined by xWaitForAllBits. If xWaitForAllBits is |
dflet | 3:a8c249046181 | 129 | * pdTRUE then the wait condition is met if all the bits set in uxBitsToWaitFor |
dflet | 3:a8c249046181 | 130 | * are also set in uxCurrentEventBits. If xWaitForAllBits is pdFALSE then the |
dflet | 3:a8c249046181 | 131 | * wait condition is met if any of the bits set in uxBitsToWait for are also set |
dflet | 3:a8c249046181 | 132 | * in uxCurrentEventBits. |
dflet | 3:a8c249046181 | 133 | */ |
dflet | 3:a8c249046181 | 134 | static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits, const EventBits_t uxBitsToWaitFor, const BaseType_t xWaitForAllBits ); |
dflet | 3:a8c249046181 | 135 | |
dflet | 3:a8c249046181 | 136 | /*-----------------------------------------------------------*/ |
dflet | 3:a8c249046181 | 137 | |
dflet | 3:a8c249046181 | 138 | EventGroupHandle_t xEventGroupCreate( void ) |
dflet | 3:a8c249046181 | 139 | { |
dflet | 3:a8c249046181 | 140 | EventGroup_t *pxEventBits; |
dflet | 3:a8c249046181 | 141 | |
dflet | 3:a8c249046181 | 142 | pxEventBits = ( EventGroup_t * ) pvPortMalloc( sizeof( EventGroup_t ) ); |
dflet | 3:a8c249046181 | 143 | if( pxEventBits != NULL ) |
dflet | 3:a8c249046181 | 144 | { |
dflet | 3:a8c249046181 | 145 | pxEventBits->uxEventBits = 0; |
dflet | 3:a8c249046181 | 146 | vListInitialise( &( pxEventBits->xTasksWaitingForBits ) ); |
dflet | 3:a8c249046181 | 147 | traceEVENT_GROUP_CREATE( pxEventBits ); |
dflet | 3:a8c249046181 | 148 | } |
dflet | 3:a8c249046181 | 149 | else |
dflet | 3:a8c249046181 | 150 | { |
dflet | 3:a8c249046181 | 151 | traceEVENT_GROUP_CREATE_FAILED(); |
dflet | 3:a8c249046181 | 152 | } |
dflet | 3:a8c249046181 | 153 | |
dflet | 3:a8c249046181 | 154 | return ( EventGroupHandle_t ) pxEventBits; |
dflet | 3:a8c249046181 | 155 | } |
dflet | 3:a8c249046181 | 156 | /*-----------------------------------------------------------*/ |
dflet | 3:a8c249046181 | 157 | |
dflet | 3:a8c249046181 | 158 | EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, const EventBits_t uxBitsToWaitFor, TickType_t xTicksToWait ) |
dflet | 3:a8c249046181 | 159 | { |
dflet | 3:a8c249046181 | 160 | EventBits_t uxOriginalBitValue, uxReturn; |
dflet | 3:a8c249046181 | 161 | EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup; |
dflet | 3:a8c249046181 | 162 | BaseType_t xAlreadyYielded; |
dflet | 3:a8c249046181 | 163 | BaseType_t xTimeoutOccurred = pdFALSE; |
dflet | 3:a8c249046181 | 164 | |
dflet | 3:a8c249046181 | 165 | configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 ); |
dflet | 3:a8c249046181 | 166 | configASSERT( uxBitsToWaitFor != 0 ); |
dflet | 3:a8c249046181 | 167 | #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) |
dflet | 3:a8c249046181 | 168 | { |
dflet | 3:a8c249046181 | 169 | configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) ); |
dflet | 3:a8c249046181 | 170 | } |
dflet | 3:a8c249046181 | 171 | #endif |
dflet | 3:a8c249046181 | 172 | |
dflet | 3:a8c249046181 | 173 | vTaskSuspendAll(); |
dflet | 3:a8c249046181 | 174 | { |
dflet | 3:a8c249046181 | 175 | uxOriginalBitValue = pxEventBits->uxEventBits; |
dflet | 3:a8c249046181 | 176 | |
dflet | 3:a8c249046181 | 177 | ( void ) xEventGroupSetBits( xEventGroup, uxBitsToSet ); |
dflet | 3:a8c249046181 | 178 | |
dflet | 3:a8c249046181 | 179 | if( ( ( uxOriginalBitValue | uxBitsToSet ) & uxBitsToWaitFor ) == uxBitsToWaitFor ) |
dflet | 3:a8c249046181 | 180 | { |
dflet | 3:a8c249046181 | 181 | /* All the rendezvous bits are now set - no need to block. */ |
dflet | 3:a8c249046181 | 182 | uxReturn = ( uxOriginalBitValue | uxBitsToSet ); |
dflet | 3:a8c249046181 | 183 | |
dflet | 3:a8c249046181 | 184 | /* Rendezvous always clear the bits. They will have been cleared |
dflet | 3:a8c249046181 | 185 | already unless this is the only task in the rendezvous. */ |
dflet | 3:a8c249046181 | 186 | pxEventBits->uxEventBits &= ~uxBitsToWaitFor; |
dflet | 3:a8c249046181 | 187 | |
dflet | 3:a8c249046181 | 188 | xTicksToWait = 0; |
dflet | 3:a8c249046181 | 189 | } |
dflet | 3:a8c249046181 | 190 | else |
dflet | 3:a8c249046181 | 191 | { |
dflet | 3:a8c249046181 | 192 | if( xTicksToWait != ( TickType_t ) 0 ) |
dflet | 3:a8c249046181 | 193 | { |
dflet | 3:a8c249046181 | 194 | traceEVENT_GROUP_SYNC_BLOCK( xEventGroup, uxBitsToSet, uxBitsToWaitFor ); |
dflet | 3:a8c249046181 | 195 | |
dflet | 3:a8c249046181 | 196 | /* Store the bits that the calling task is waiting for in the |
dflet | 3:a8c249046181 | 197 | task's event list item so the kernel knows when a match is |
dflet | 3:a8c249046181 | 198 | found. Then enter the blocked state. */ |
dflet | 3:a8c249046181 | 199 | vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | eventCLEAR_EVENTS_ON_EXIT_BIT | eventWAIT_FOR_ALL_BITS ), xTicksToWait ); |
dflet | 3:a8c249046181 | 200 | |
dflet | 3:a8c249046181 | 201 | /* This assignment is obsolete as uxReturn will get set after |
dflet | 3:a8c249046181 | 202 | the task unblocks, but some compilers mistakenly generate a |
dflet | 3:a8c249046181 | 203 | warning about uxReturn being returned without being set if the |
dflet | 3:a8c249046181 | 204 | assignment is omitted. */ |
dflet | 3:a8c249046181 | 205 | uxReturn = 0; |
dflet | 3:a8c249046181 | 206 | } |
dflet | 3:a8c249046181 | 207 | else |
dflet | 3:a8c249046181 | 208 | { |
dflet | 3:a8c249046181 | 209 | /* The rendezvous bits were not set, but no block time was |
dflet | 3:a8c249046181 | 210 | specified - just return the current event bit value. */ |
dflet | 3:a8c249046181 | 211 | uxReturn = pxEventBits->uxEventBits; |
dflet | 3:a8c249046181 | 212 | } |
dflet | 3:a8c249046181 | 213 | } |
dflet | 3:a8c249046181 | 214 | } |
dflet | 3:a8c249046181 | 215 | xAlreadyYielded = xTaskResumeAll(); |
dflet | 3:a8c249046181 | 216 | |
dflet | 3:a8c249046181 | 217 | if( xTicksToWait != ( TickType_t ) 0 ) |
dflet | 3:a8c249046181 | 218 | { |
dflet | 3:a8c249046181 | 219 | if( xAlreadyYielded == pdFALSE ) |
dflet | 3:a8c249046181 | 220 | { |
dflet | 3:a8c249046181 | 221 | portYIELD_WITHIN_API(); |
dflet | 3:a8c249046181 | 222 | } |
dflet | 3:a8c249046181 | 223 | else |
dflet | 3:a8c249046181 | 224 | { |
dflet | 3:a8c249046181 | 225 | mtCOVERAGE_TEST_MARKER(); |
dflet | 3:a8c249046181 | 226 | } |
dflet | 3:a8c249046181 | 227 | |
dflet | 3:a8c249046181 | 228 | /* The task blocked to wait for its required bits to be set - at this |
dflet | 3:a8c249046181 | 229 | point either the required bits were set or the block time expired. If |
dflet | 3:a8c249046181 | 230 | the required bits were set they will have been stored in the task's |
dflet | 3:a8c249046181 | 231 | event list item, and they should now be retrieved then cleared. */ |
dflet | 3:a8c249046181 | 232 | uxReturn = uxTaskResetEventItemValue(); |
dflet | 3:a8c249046181 | 233 | |
dflet | 3:a8c249046181 | 234 | if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 ) |
dflet | 3:a8c249046181 | 235 | { |
dflet | 3:a8c249046181 | 236 | /* The task timed out, just return the current event bit value. */ |
dflet | 3:a8c249046181 | 237 | taskENTER_CRITICAL(); |
dflet | 3:a8c249046181 | 238 | { |
dflet | 3:a8c249046181 | 239 | uxReturn = pxEventBits->uxEventBits; |
dflet | 3:a8c249046181 | 240 | |
dflet | 3:a8c249046181 | 241 | /* Although the task got here because it timed out before the |
dflet | 3:a8c249046181 | 242 | bits it was waiting for were set, it is possible that since it |
dflet | 3:a8c249046181 | 243 | unblocked another task has set the bits. If this is the case |
dflet | 3:a8c249046181 | 244 | then it needs to clear the bits before exiting. */ |
dflet | 3:a8c249046181 | 245 | if( ( uxReturn & uxBitsToWaitFor ) == uxBitsToWaitFor ) |
dflet | 3:a8c249046181 | 246 | { |
dflet | 3:a8c249046181 | 247 | pxEventBits->uxEventBits &= ~uxBitsToWaitFor; |
dflet | 3:a8c249046181 | 248 | } |
dflet | 3:a8c249046181 | 249 | else |
dflet | 3:a8c249046181 | 250 | { |
dflet | 3:a8c249046181 | 251 | mtCOVERAGE_TEST_MARKER(); |
dflet | 3:a8c249046181 | 252 | } |
dflet | 3:a8c249046181 | 253 | } |
dflet | 3:a8c249046181 | 254 | taskEXIT_CRITICAL(); |
dflet | 3:a8c249046181 | 255 | |
dflet | 3:a8c249046181 | 256 | xTimeoutOccurred = pdTRUE; |
dflet | 3:a8c249046181 | 257 | } |
dflet | 3:a8c249046181 | 258 | else |
dflet | 3:a8c249046181 | 259 | { |
dflet | 3:a8c249046181 | 260 | /* The task unblocked because the bits were set. */ |
dflet | 3:a8c249046181 | 261 | } |
dflet | 3:a8c249046181 | 262 | |
dflet | 3:a8c249046181 | 263 | /* Control bits might be set as the task had blocked should not be |
dflet | 3:a8c249046181 | 264 | returned. */ |
dflet | 3:a8c249046181 | 265 | uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES; |
dflet | 3:a8c249046181 | 266 | } |
dflet | 3:a8c249046181 | 267 | |
dflet | 3:a8c249046181 | 268 | traceEVENT_GROUP_SYNC_END( xEventGroup, uxBitsToSet, uxBitsToWaitFor, xTimeoutOccurred ); |
dflet | 3:a8c249046181 | 269 | |
dflet | 3:a8c249046181 | 270 | return uxReturn; |
dflet | 3:a8c249046181 | 271 | } |
dflet | 3:a8c249046181 | 272 | /*-----------------------------------------------------------*/ |
dflet | 3:a8c249046181 | 273 | |
dflet | 3:a8c249046181 | 274 | EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToWaitFor, const BaseType_t xClearOnExit, const BaseType_t xWaitForAllBits, TickType_t xTicksToWait ) |
dflet | 3:a8c249046181 | 275 | { |
dflet | 3:a8c249046181 | 276 | EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup; |
dflet | 3:a8c249046181 | 277 | EventBits_t uxReturn, uxControlBits = 0; |
dflet | 3:a8c249046181 | 278 | BaseType_t xWaitConditionMet, xAlreadyYielded; |
dflet | 3:a8c249046181 | 279 | BaseType_t xTimeoutOccurred = pdFALSE; |
dflet | 3:a8c249046181 | 280 | |
dflet | 3:a8c249046181 | 281 | /* Check the user is not attempting to wait on the bits used by the kernel |
dflet | 3:a8c249046181 | 282 | itself, and that at least one bit is being requested. */ |
dflet | 3:a8c249046181 | 283 | configASSERT( xEventGroup ); |
dflet | 3:a8c249046181 | 284 | configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 ); |
dflet | 3:a8c249046181 | 285 | configASSERT( uxBitsToWaitFor != 0 ); |
dflet | 3:a8c249046181 | 286 | #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) |
dflet | 3:a8c249046181 | 287 | { |
dflet | 3:a8c249046181 | 288 | configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) ); |
dflet | 3:a8c249046181 | 289 | } |
dflet | 3:a8c249046181 | 290 | #endif |
dflet | 3:a8c249046181 | 291 | |
dflet | 3:a8c249046181 | 292 | vTaskSuspendAll(); |
dflet | 3:a8c249046181 | 293 | { |
dflet | 3:a8c249046181 | 294 | const EventBits_t uxCurrentEventBits = pxEventBits->uxEventBits; |
dflet | 3:a8c249046181 | 295 | |
dflet | 3:a8c249046181 | 296 | /* Check to see if the wait condition is already met or not. */ |
dflet | 3:a8c249046181 | 297 | xWaitConditionMet = prvTestWaitCondition( uxCurrentEventBits, uxBitsToWaitFor, xWaitForAllBits ); |
dflet | 3:a8c249046181 | 298 | |
dflet | 3:a8c249046181 | 299 | if( xWaitConditionMet != pdFALSE ) |
dflet | 3:a8c249046181 | 300 | { |
dflet | 3:a8c249046181 | 301 | /* The wait condition has already been met so there is no need to |
dflet | 3:a8c249046181 | 302 | block. */ |
dflet | 3:a8c249046181 | 303 | uxReturn = uxCurrentEventBits; |
dflet | 3:a8c249046181 | 304 | xTicksToWait = ( TickType_t ) 0; |
dflet | 3:a8c249046181 | 305 | |
dflet | 3:a8c249046181 | 306 | /* Clear the wait bits if requested to do so. */ |
dflet | 3:a8c249046181 | 307 | if( xClearOnExit != pdFALSE ) |
dflet | 3:a8c249046181 | 308 | { |
dflet | 3:a8c249046181 | 309 | pxEventBits->uxEventBits &= ~uxBitsToWaitFor; |
dflet | 3:a8c249046181 | 310 | } |
dflet | 3:a8c249046181 | 311 | else |
dflet | 3:a8c249046181 | 312 | { |
dflet | 3:a8c249046181 | 313 | mtCOVERAGE_TEST_MARKER(); |
dflet | 3:a8c249046181 | 314 | } |
dflet | 3:a8c249046181 | 315 | } |
dflet | 3:a8c249046181 | 316 | else if( xTicksToWait == ( TickType_t ) 0 ) |
dflet | 3:a8c249046181 | 317 | { |
dflet | 3:a8c249046181 | 318 | /* The wait condition has not been met, but no block time was |
dflet | 3:a8c249046181 | 319 | specified, so just return the current value. */ |
dflet | 3:a8c249046181 | 320 | uxReturn = uxCurrentEventBits; |
dflet | 3:a8c249046181 | 321 | } |
dflet | 3:a8c249046181 | 322 | else |
dflet | 3:a8c249046181 | 323 | { |
dflet | 3:a8c249046181 | 324 | /* The task is going to block to wait for its required bits to be |
dflet | 3:a8c249046181 | 325 | set. uxControlBits are used to remember the specified behaviour of |
dflet | 3:a8c249046181 | 326 | this call to xEventGroupWaitBits() - for use when the event bits |
dflet | 3:a8c249046181 | 327 | unblock the task. */ |
dflet | 3:a8c249046181 | 328 | if( xClearOnExit != pdFALSE ) |
dflet | 3:a8c249046181 | 329 | { |
dflet | 3:a8c249046181 | 330 | uxControlBits |= eventCLEAR_EVENTS_ON_EXIT_BIT; |
dflet | 3:a8c249046181 | 331 | } |
dflet | 3:a8c249046181 | 332 | else |
dflet | 3:a8c249046181 | 333 | { |
dflet | 3:a8c249046181 | 334 | mtCOVERAGE_TEST_MARKER(); |
dflet | 3:a8c249046181 | 335 | } |
dflet | 3:a8c249046181 | 336 | |
dflet | 3:a8c249046181 | 337 | if( xWaitForAllBits != pdFALSE ) |
dflet | 3:a8c249046181 | 338 | { |
dflet | 3:a8c249046181 | 339 | uxControlBits |= eventWAIT_FOR_ALL_BITS; |
dflet | 3:a8c249046181 | 340 | } |
dflet | 3:a8c249046181 | 341 | else |
dflet | 3:a8c249046181 | 342 | { |
dflet | 3:a8c249046181 | 343 | mtCOVERAGE_TEST_MARKER(); |
dflet | 3:a8c249046181 | 344 | } |
dflet | 3:a8c249046181 | 345 | |
dflet | 3:a8c249046181 | 346 | /* Store the bits that the calling task is waiting for in the |
dflet | 3:a8c249046181 | 347 | task's event list item so the kernel knows when a match is |
dflet | 3:a8c249046181 | 348 | found. Then enter the blocked state. */ |
dflet | 3:a8c249046181 | 349 | vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | uxControlBits ), xTicksToWait ); |
dflet | 3:a8c249046181 | 350 | |
dflet | 3:a8c249046181 | 351 | /* This is obsolete as it will get set after the task unblocks, but |
dflet | 3:a8c249046181 | 352 | some compilers mistakenly generate a warning about the variable |
dflet | 3:a8c249046181 | 353 | being returned without being set if it is not done. */ |
dflet | 3:a8c249046181 | 354 | uxReturn = 0; |
dflet | 3:a8c249046181 | 355 | |
dflet | 3:a8c249046181 | 356 | traceEVENT_GROUP_WAIT_BITS_BLOCK( xEventGroup, uxBitsToWaitFor ); |
dflet | 3:a8c249046181 | 357 | } |
dflet | 3:a8c249046181 | 358 | } |
dflet | 3:a8c249046181 | 359 | xAlreadyYielded = xTaskResumeAll(); |
dflet | 3:a8c249046181 | 360 | |
dflet | 3:a8c249046181 | 361 | if( xTicksToWait != ( TickType_t ) 0 ) |
dflet | 3:a8c249046181 | 362 | { |
dflet | 3:a8c249046181 | 363 | if( xAlreadyYielded == pdFALSE ) |
dflet | 3:a8c249046181 | 364 | { |
dflet | 3:a8c249046181 | 365 | portYIELD_WITHIN_API(); |
dflet | 3:a8c249046181 | 366 | } |
dflet | 3:a8c249046181 | 367 | else |
dflet | 3:a8c249046181 | 368 | { |
dflet | 3:a8c249046181 | 369 | mtCOVERAGE_TEST_MARKER(); |
dflet | 3:a8c249046181 | 370 | } |
dflet | 3:a8c249046181 | 371 | |
dflet | 3:a8c249046181 | 372 | /* The task blocked to wait for its required bits to be set - at this |
dflet | 3:a8c249046181 | 373 | point either the required bits were set or the block time expired. If |
dflet | 3:a8c249046181 | 374 | the required bits were set they will have been stored in the task's |
dflet | 3:a8c249046181 | 375 | event list item, and they should now be retrieved then cleared. */ |
dflet | 3:a8c249046181 | 376 | uxReturn = uxTaskResetEventItemValue(); |
dflet | 3:a8c249046181 | 377 | |
dflet | 3:a8c249046181 | 378 | if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 ) |
dflet | 3:a8c249046181 | 379 | { |
dflet | 3:a8c249046181 | 380 | taskENTER_CRITICAL(); |
dflet | 3:a8c249046181 | 381 | { |
dflet | 3:a8c249046181 | 382 | /* The task timed out, just return the current event bit value. */ |
dflet | 3:a8c249046181 | 383 | uxReturn = pxEventBits->uxEventBits; |
dflet | 3:a8c249046181 | 384 | |
dflet | 3:a8c249046181 | 385 | /* It is possible that the event bits were updated between this |
dflet | 3:a8c249046181 | 386 | task leaving the Blocked state and running again. */ |
dflet | 3:a8c249046181 | 387 | if( prvTestWaitCondition( uxReturn, uxBitsToWaitFor, xWaitForAllBits ) != pdFALSE ) |
dflet | 3:a8c249046181 | 388 | { |
dflet | 3:a8c249046181 | 389 | if( xClearOnExit != pdFALSE ) |
dflet | 3:a8c249046181 | 390 | { |
dflet | 3:a8c249046181 | 391 | pxEventBits->uxEventBits &= ~uxBitsToWaitFor; |
dflet | 3:a8c249046181 | 392 | } |
dflet | 3:a8c249046181 | 393 | else |
dflet | 3:a8c249046181 | 394 | { |
dflet | 3:a8c249046181 | 395 | mtCOVERAGE_TEST_MARKER(); |
dflet | 3:a8c249046181 | 396 | } |
dflet | 3:a8c249046181 | 397 | } |
dflet | 3:a8c249046181 | 398 | else |
dflet | 3:a8c249046181 | 399 | { |
dflet | 3:a8c249046181 | 400 | mtCOVERAGE_TEST_MARKER(); |
dflet | 3:a8c249046181 | 401 | } |
dflet | 3:a8c249046181 | 402 | } |
dflet | 3:a8c249046181 | 403 | taskEXIT_CRITICAL(); |
dflet | 3:a8c249046181 | 404 | |
dflet | 3:a8c249046181 | 405 | /* Prevent compiler warnings when trace macros are not used. */ |
dflet | 3:a8c249046181 | 406 | xTimeoutOccurred = pdFALSE; |
dflet | 3:a8c249046181 | 407 | } |
dflet | 3:a8c249046181 | 408 | else |
dflet | 3:a8c249046181 | 409 | { |
dflet | 3:a8c249046181 | 410 | /* The task unblocked because the bits were set. */ |
dflet | 3:a8c249046181 | 411 | } |
dflet | 3:a8c249046181 | 412 | |
dflet | 3:a8c249046181 | 413 | /* The task blocked so control bits may have been set. */ |
dflet | 3:a8c249046181 | 414 | uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES; |
dflet | 3:a8c249046181 | 415 | } |
dflet | 3:a8c249046181 | 416 | traceEVENT_GROUP_WAIT_BITS_END( xEventGroup, uxBitsToWaitFor, xTimeoutOccurred ); |
dflet | 3:a8c249046181 | 417 | |
dflet | 3:a8c249046181 | 418 | return uxReturn; |
dflet | 3:a8c249046181 | 419 | } |
dflet | 3:a8c249046181 | 420 | /*-----------------------------------------------------------*/ |
dflet | 3:a8c249046181 | 421 | |
dflet | 3:a8c249046181 | 422 | EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear ) |
dflet | 3:a8c249046181 | 423 | { |
dflet | 3:a8c249046181 | 424 | EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup; |
dflet | 3:a8c249046181 | 425 | EventBits_t uxReturn; |
dflet | 3:a8c249046181 | 426 | |
dflet | 3:a8c249046181 | 427 | /* Check the user is not attempting to clear the bits used by the kernel |
dflet | 3:a8c249046181 | 428 | itself. */ |
dflet | 3:a8c249046181 | 429 | configASSERT( xEventGroup ); |
dflet | 3:a8c249046181 | 430 | configASSERT( ( uxBitsToClear & eventEVENT_BITS_CONTROL_BYTES ) == 0 ); |
dflet | 3:a8c249046181 | 431 | |
dflet | 3:a8c249046181 | 432 | taskENTER_CRITICAL(); |
dflet | 3:a8c249046181 | 433 | { |
dflet | 3:a8c249046181 | 434 | traceEVENT_GROUP_CLEAR_BITS( xEventGroup, uxBitsToClear ); |
dflet | 3:a8c249046181 | 435 | |
dflet | 3:a8c249046181 | 436 | /* The value returned is the event group value prior to the bits being |
dflet | 3:a8c249046181 | 437 | cleared. */ |
dflet | 3:a8c249046181 | 438 | uxReturn = pxEventBits->uxEventBits; |
dflet | 3:a8c249046181 | 439 | |
dflet | 3:a8c249046181 | 440 | /* Clear the bits. */ |
dflet | 3:a8c249046181 | 441 | pxEventBits->uxEventBits &= ~uxBitsToClear; |
dflet | 3:a8c249046181 | 442 | } |
dflet | 3:a8c249046181 | 443 | taskEXIT_CRITICAL(); |
dflet | 3:a8c249046181 | 444 | |
dflet | 3:a8c249046181 | 445 | return uxReturn; |
dflet | 3:a8c249046181 | 446 | } |
dflet | 3:a8c249046181 | 447 | /*-----------------------------------------------------------*/ |
dflet | 3:a8c249046181 | 448 | |
dflet | 3:a8c249046181 | 449 | #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) ) |
dflet | 3:a8c249046181 | 450 | |
dflet | 3:a8c249046181 | 451 | BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear ) |
dflet | 3:a8c249046181 | 452 | { |
dflet | 3:a8c249046181 | 453 | BaseType_t xReturn; |
dflet | 3:a8c249046181 | 454 | |
dflet | 3:a8c249046181 | 455 | traceEVENT_GROUP_CLEAR_BITS_FROM_ISR( xEventGroup, uxBitsToClear ); |
dflet | 3:a8c249046181 | 456 | xReturn = xTimerPendFunctionCallFromISR( vEventGroupClearBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToClear, NULL ); |
dflet | 3:a8c249046181 | 457 | |
dflet | 3:a8c249046181 | 458 | return xReturn; |
dflet | 3:a8c249046181 | 459 | } |
dflet | 3:a8c249046181 | 460 | |
dflet | 3:a8c249046181 | 461 | #endif |
dflet | 3:a8c249046181 | 462 | /*-----------------------------------------------------------*/ |
dflet | 3:a8c249046181 | 463 | |
dflet | 3:a8c249046181 | 464 | EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup ) |
dflet | 3:a8c249046181 | 465 | { |
dflet | 3:a8c249046181 | 466 | UBaseType_t uxSavedInterruptStatus; |
dflet | 3:a8c249046181 | 467 | EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup; |
dflet | 3:a8c249046181 | 468 | EventBits_t uxReturn; |
dflet | 3:a8c249046181 | 469 | |
dflet | 3:a8c249046181 | 470 | uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); |
dflet | 3:a8c249046181 | 471 | { |
dflet | 3:a8c249046181 | 472 | uxReturn = pxEventBits->uxEventBits; |
dflet | 3:a8c249046181 | 473 | } |
dflet | 3:a8c249046181 | 474 | portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); |
dflet | 3:a8c249046181 | 475 | |
dflet | 3:a8c249046181 | 476 | return uxReturn; |
dflet | 3:a8c249046181 | 477 | } |
dflet | 3:a8c249046181 | 478 | /*-----------------------------------------------------------*/ |
dflet | 3:a8c249046181 | 479 | |
dflet | 3:a8c249046181 | 480 | EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet ) |
dflet | 3:a8c249046181 | 481 | { |
dflet | 3:a8c249046181 | 482 | ListItem_t *pxListItem, *pxNext; |
dflet | 3:a8c249046181 | 483 | ListItem_t const *pxListEnd; |
dflet | 3:a8c249046181 | 484 | List_t *pxList; |
dflet | 3:a8c249046181 | 485 | EventBits_t uxBitsToClear = 0, uxBitsWaitedFor, uxControlBits; |
dflet | 3:a8c249046181 | 486 | EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup; |
dflet | 3:a8c249046181 | 487 | BaseType_t xMatchFound = pdFALSE; |
dflet | 3:a8c249046181 | 488 | |
dflet | 3:a8c249046181 | 489 | /* Check the user is not attempting to set the bits used by the kernel |
dflet | 3:a8c249046181 | 490 | itself. */ |
dflet | 3:a8c249046181 | 491 | configASSERT( xEventGroup ); |
dflet | 3:a8c249046181 | 492 | configASSERT( ( uxBitsToSet & eventEVENT_BITS_CONTROL_BYTES ) == 0 ); |
dflet | 3:a8c249046181 | 493 | |
dflet | 3:a8c249046181 | 494 | pxList = &( pxEventBits->xTasksWaitingForBits ); |
dflet | 3:a8c249046181 | 495 | pxListEnd = listGET_END_MARKER( pxList ); /*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */ |
dflet | 3:a8c249046181 | 496 | vTaskSuspendAll(); |
dflet | 3:a8c249046181 | 497 | { |
dflet | 3:a8c249046181 | 498 | traceEVENT_GROUP_SET_BITS( xEventGroup, uxBitsToSet ); |
dflet | 3:a8c249046181 | 499 | |
dflet | 3:a8c249046181 | 500 | pxListItem = listGET_HEAD_ENTRY( pxList ); |
dflet | 3:a8c249046181 | 501 | |
dflet | 3:a8c249046181 | 502 | /* Set the bits. */ |
dflet | 3:a8c249046181 | 503 | pxEventBits->uxEventBits |= uxBitsToSet; |
dflet | 3:a8c249046181 | 504 | |
dflet | 3:a8c249046181 | 505 | /* See if the new bit value should unblock any tasks. */ |
dflet | 3:a8c249046181 | 506 | while( pxListItem != pxListEnd ) |
dflet | 3:a8c249046181 | 507 | { |
dflet | 3:a8c249046181 | 508 | pxNext = listGET_NEXT( pxListItem ); |
dflet | 3:a8c249046181 | 509 | uxBitsWaitedFor = listGET_LIST_ITEM_VALUE( pxListItem ); |
dflet | 3:a8c249046181 | 510 | xMatchFound = pdFALSE; |
dflet | 3:a8c249046181 | 511 | |
dflet | 3:a8c249046181 | 512 | /* Split the bits waited for from the control bits. */ |
dflet | 3:a8c249046181 | 513 | uxControlBits = uxBitsWaitedFor & eventEVENT_BITS_CONTROL_BYTES; |
dflet | 3:a8c249046181 | 514 | uxBitsWaitedFor &= ~eventEVENT_BITS_CONTROL_BYTES; |
dflet | 3:a8c249046181 | 515 | |
dflet | 3:a8c249046181 | 516 | if( ( uxControlBits & eventWAIT_FOR_ALL_BITS ) == ( EventBits_t ) 0 ) |
dflet | 3:a8c249046181 | 517 | { |
dflet | 3:a8c249046181 | 518 | /* Just looking for single bit being set. */ |
dflet | 3:a8c249046181 | 519 | if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) != ( EventBits_t ) 0 ) |
dflet | 3:a8c249046181 | 520 | { |
dflet | 3:a8c249046181 | 521 | xMatchFound = pdTRUE; |
dflet | 3:a8c249046181 | 522 | } |
dflet | 3:a8c249046181 | 523 | else |
dflet | 3:a8c249046181 | 524 | { |
dflet | 3:a8c249046181 | 525 | mtCOVERAGE_TEST_MARKER(); |
dflet | 3:a8c249046181 | 526 | } |
dflet | 3:a8c249046181 | 527 | } |
dflet | 3:a8c249046181 | 528 | else if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) == uxBitsWaitedFor ) |
dflet | 3:a8c249046181 | 529 | { |
dflet | 3:a8c249046181 | 530 | /* All bits are set. */ |
dflet | 3:a8c249046181 | 531 | xMatchFound = pdTRUE; |
dflet | 3:a8c249046181 | 532 | } |
dflet | 3:a8c249046181 | 533 | else |
dflet | 3:a8c249046181 | 534 | { |
dflet | 3:a8c249046181 | 535 | /* Need all bits to be set, but not all the bits were set. */ |
dflet | 3:a8c249046181 | 536 | } |
dflet | 3:a8c249046181 | 537 | |
dflet | 3:a8c249046181 | 538 | if( xMatchFound != pdFALSE ) |
dflet | 3:a8c249046181 | 539 | { |
dflet | 3:a8c249046181 | 540 | /* The bits match. Should the bits be cleared on exit? */ |
dflet | 3:a8c249046181 | 541 | if( ( uxControlBits & eventCLEAR_EVENTS_ON_EXIT_BIT ) != ( EventBits_t ) 0 ) |
dflet | 3:a8c249046181 | 542 | { |
dflet | 3:a8c249046181 | 543 | uxBitsToClear |= uxBitsWaitedFor; |
dflet | 3:a8c249046181 | 544 | } |
dflet | 3:a8c249046181 | 545 | else |
dflet | 3:a8c249046181 | 546 | { |
dflet | 3:a8c249046181 | 547 | mtCOVERAGE_TEST_MARKER(); |
dflet | 3:a8c249046181 | 548 | } |
dflet | 3:a8c249046181 | 549 | |
dflet | 3:a8c249046181 | 550 | /* Store the actual event flag value in the task's event list |
dflet | 3:a8c249046181 | 551 | item before removing the task from the event list. The |
dflet | 3:a8c249046181 | 552 | eventUNBLOCKED_DUE_TO_BIT_SET bit is set so the task knows |
dflet | 3:a8c249046181 | 553 | that is was unblocked due to its required bits matching, rather |
dflet | 3:a8c249046181 | 554 | than because it timed out. */ |
dflet | 3:a8c249046181 | 555 | ( void ) xTaskRemoveFromUnorderedEventList( pxListItem, pxEventBits->uxEventBits | eventUNBLOCKED_DUE_TO_BIT_SET ); |
dflet | 3:a8c249046181 | 556 | } |
dflet | 3:a8c249046181 | 557 | |
dflet | 3:a8c249046181 | 558 | /* Move onto the next list item. Note pxListItem->pxNext is not |
dflet | 3:a8c249046181 | 559 | used here as the list item may have been removed from the event list |
dflet | 3:a8c249046181 | 560 | and inserted into the ready/pending reading list. */ |
dflet | 3:a8c249046181 | 561 | pxListItem = pxNext; |
dflet | 3:a8c249046181 | 562 | } |
dflet | 3:a8c249046181 | 563 | |
dflet | 3:a8c249046181 | 564 | /* Clear any bits that matched when the eventCLEAR_EVENTS_ON_EXIT_BIT |
dflet | 3:a8c249046181 | 565 | bit was set in the control word. */ |
dflet | 3:a8c249046181 | 566 | pxEventBits->uxEventBits &= ~uxBitsToClear; |
dflet | 3:a8c249046181 | 567 | } |
dflet | 3:a8c249046181 | 568 | ( void ) xTaskResumeAll(); |
dflet | 3:a8c249046181 | 569 | |
dflet | 3:a8c249046181 | 570 | return pxEventBits->uxEventBits; |
dflet | 3:a8c249046181 | 571 | } |
dflet | 3:a8c249046181 | 572 | /*-----------------------------------------------------------*/ |
dflet | 3:a8c249046181 | 573 | |
dflet | 3:a8c249046181 | 574 | void vEventGroupDelete( EventGroupHandle_t xEventGroup ) |
dflet | 3:a8c249046181 | 575 | { |
dflet | 3:a8c249046181 | 576 | EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup; |
dflet | 3:a8c249046181 | 577 | const List_t *pxTasksWaitingForBits = &( pxEventBits->xTasksWaitingForBits ); |
dflet | 3:a8c249046181 | 578 | |
dflet | 3:a8c249046181 | 579 | vTaskSuspendAll(); |
dflet | 3:a8c249046181 | 580 | { |
dflet | 3:a8c249046181 | 581 | traceEVENT_GROUP_DELETE( xEventGroup ); |
dflet | 3:a8c249046181 | 582 | |
dflet | 3:a8c249046181 | 583 | while( listCURRENT_LIST_LENGTH( pxTasksWaitingForBits ) > ( UBaseType_t ) 0 ) |
dflet | 3:a8c249046181 | 584 | { |
dflet | 3:a8c249046181 | 585 | /* Unblock the task, returning 0 as the event list is being deleted |
dflet | 3:a8c249046181 | 586 | and cannot therefore have any bits set. */ |
dflet | 3:a8c249046181 | 587 | configASSERT( pxTasksWaitingForBits->xListEnd.pxNext != ( ListItem_t * ) &( pxTasksWaitingForBits->xListEnd ) ); |
dflet | 3:a8c249046181 | 588 | ( void ) xTaskRemoveFromUnorderedEventList( pxTasksWaitingForBits->xListEnd.pxNext, eventUNBLOCKED_DUE_TO_BIT_SET ); |
dflet | 3:a8c249046181 | 589 | } |
dflet | 3:a8c249046181 | 590 | |
dflet | 3:a8c249046181 | 591 | vPortFree( pxEventBits ); |
dflet | 3:a8c249046181 | 592 | } |
dflet | 3:a8c249046181 | 593 | ( void ) xTaskResumeAll(); |
dflet | 3:a8c249046181 | 594 | } |
dflet | 3:a8c249046181 | 595 | /*-----------------------------------------------------------*/ |
dflet | 3:a8c249046181 | 596 | |
dflet | 3:a8c249046181 | 597 | /* For internal use only - execute a 'set bits' command that was pended from |
dflet | 3:a8c249046181 | 598 | an interrupt. */ |
dflet | 3:a8c249046181 | 599 | void vEventGroupSetBitsCallback( void *pvEventGroup, const uint32_t ulBitsToSet ) |
dflet | 3:a8c249046181 | 600 | { |
dflet | 3:a8c249046181 | 601 | ( void ) xEventGroupSetBits( pvEventGroup, ( EventBits_t ) ulBitsToSet ); |
dflet | 3:a8c249046181 | 602 | } |
dflet | 3:a8c249046181 | 603 | /*-----------------------------------------------------------*/ |
dflet | 3:a8c249046181 | 604 | |
dflet | 3:a8c249046181 | 605 | /* For internal use only - execute a 'clear bits' command that was pended from |
dflet | 3:a8c249046181 | 606 | an interrupt. */ |
dflet | 3:a8c249046181 | 607 | void vEventGroupClearBitsCallback( void *pvEventGroup, const uint32_t ulBitsToClear ) |
dflet | 3:a8c249046181 | 608 | { |
dflet | 3:a8c249046181 | 609 | ( void ) xEventGroupClearBits( pvEventGroup, ( EventBits_t ) ulBitsToClear ); |
dflet | 3:a8c249046181 | 610 | } |
dflet | 3:a8c249046181 | 611 | /*-----------------------------------------------------------*/ |
dflet | 3:a8c249046181 | 612 | |
dflet | 3:a8c249046181 | 613 | static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits, const EventBits_t uxBitsToWaitFor, const BaseType_t xWaitForAllBits ) |
dflet | 3:a8c249046181 | 614 | { |
dflet | 3:a8c249046181 | 615 | BaseType_t xWaitConditionMet = pdFALSE; |
dflet | 3:a8c249046181 | 616 | |
dflet | 3:a8c249046181 | 617 | if( xWaitForAllBits == pdFALSE ) |
dflet | 3:a8c249046181 | 618 | { |
dflet | 3:a8c249046181 | 619 | /* Task only has to wait for one bit within uxBitsToWaitFor to be |
dflet | 3:a8c249046181 | 620 | set. Is one already set? */ |
dflet | 3:a8c249046181 | 621 | if( ( uxCurrentEventBits & uxBitsToWaitFor ) != ( EventBits_t ) 0 ) |
dflet | 3:a8c249046181 | 622 | { |
dflet | 3:a8c249046181 | 623 | xWaitConditionMet = pdTRUE; |
dflet | 3:a8c249046181 | 624 | } |
dflet | 3:a8c249046181 | 625 | else |
dflet | 3:a8c249046181 | 626 | { |
dflet | 3:a8c249046181 | 627 | mtCOVERAGE_TEST_MARKER(); |
dflet | 3:a8c249046181 | 628 | } |
dflet | 3:a8c249046181 | 629 | } |
dflet | 3:a8c249046181 | 630 | else |
dflet | 3:a8c249046181 | 631 | { |
dflet | 3:a8c249046181 | 632 | /* Task has to wait for all the bits in uxBitsToWaitFor to be set. |
dflet | 3:a8c249046181 | 633 | Are they set already? */ |
dflet | 3:a8c249046181 | 634 | if( ( uxCurrentEventBits & uxBitsToWaitFor ) == uxBitsToWaitFor ) |
dflet | 3:a8c249046181 | 635 | { |
dflet | 3:a8c249046181 | 636 | xWaitConditionMet = pdTRUE; |
dflet | 3:a8c249046181 | 637 | } |
dflet | 3:a8c249046181 | 638 | else |
dflet | 3:a8c249046181 | 639 | { |
dflet | 3:a8c249046181 | 640 | mtCOVERAGE_TEST_MARKER(); |
dflet | 3:a8c249046181 | 641 | } |
dflet | 3:a8c249046181 | 642 | } |
dflet | 3:a8c249046181 | 643 | |
dflet | 3:a8c249046181 | 644 | return xWaitConditionMet; |
dflet | 3:a8c249046181 | 645 | } |
dflet | 3:a8c249046181 | 646 | /*-----------------------------------------------------------*/ |
dflet | 3:a8c249046181 | 647 | |
dflet | 3:a8c249046181 | 648 | #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) ) |
dflet | 3:a8c249046181 | 649 | |
dflet | 3:a8c249046181 | 650 | BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken ) |
dflet | 3:a8c249046181 | 651 | { |
dflet | 3:a8c249046181 | 652 | BaseType_t xReturn; |
dflet | 3:a8c249046181 | 653 | |
dflet | 3:a8c249046181 | 654 | traceEVENT_GROUP_SET_BITS_FROM_ISR( xEventGroup, uxBitsToSet ); |
dflet | 3:a8c249046181 | 655 | xReturn = xTimerPendFunctionCallFromISR( vEventGroupSetBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToSet, pxHigherPriorityTaskWoken ); |
dflet | 3:a8c249046181 | 656 | |
dflet | 3:a8c249046181 | 657 | return xReturn; |
dflet | 3:a8c249046181 | 658 | } |
dflet | 3:a8c249046181 | 659 | |
dflet | 3:a8c249046181 | 660 | #endif |
dflet | 3:a8c249046181 | 661 | /*-----------------------------------------------------------*/ |
dflet | 3:a8c249046181 | 662 | |
dflet | 3:a8c249046181 | 663 | #if (configUSE_TRACE_FACILITY == 1) |
dflet | 3:a8c249046181 | 664 | |
dflet | 3:a8c249046181 | 665 | UBaseType_t uxEventGroupGetNumber( void* xEventGroup ) |
dflet | 3:a8c249046181 | 666 | { |
dflet | 3:a8c249046181 | 667 | UBaseType_t xReturn; |
dflet | 3:a8c249046181 | 668 | EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup; |
dflet | 3:a8c249046181 | 669 | |
dflet | 3:a8c249046181 | 670 | if( xEventGroup == NULL ) |
dflet | 3:a8c249046181 | 671 | { |
dflet | 3:a8c249046181 | 672 | xReturn = 0; |
dflet | 3:a8c249046181 | 673 | } |
dflet | 3:a8c249046181 | 674 | else |
dflet | 3:a8c249046181 | 675 | { |
dflet | 3:a8c249046181 | 676 | xReturn = pxEventBits->uxEventGroupNumber; |
dflet | 3:a8c249046181 | 677 | } |
dflet | 3:a8c249046181 | 678 | |
dflet | 3:a8c249046181 | 679 | return xReturn; |
dflet | 3:a8c249046181 | 680 | } |
dflet | 3:a8c249046181 | 681 | |
dflet | 3:a8c249046181 | 682 | #endif |
dflet | 3:a8c249046181 | 683 | |
dflet | 3:a8c249046181 | 684 |