]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/event_groups.c
Update version number in preparation for official V8.2.0 release.
[freertos] / FreeRTOS / Source / event_groups.c
index c5017caf0626ab9992b528ec319f1aeca82ce2b6..ebac26884a502f70d55460ab0b55927d020a4ca6 100644 (file)
@@ -1,60 +1,64 @@
 /*\r
-    FreeRTOS V7.6.0 - Copyright (C) 2013 Real Time Engineers Ltd.\r
+    FreeRTOS V8.2.0 - Copyright (C) 2015 Real Time Engineers Ltd.\r
     All rights reserved\r
 \r
     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
 \r
-    ***************************************************************************\r
-     *                                                                       *\r
-     *    FreeRTOS provides completely free yet professionally developed,    *\r
-     *    robust, strictly quality controlled, supported, and cross          *\r
-     *    platform software that has become a de facto standard.             *\r
-     *                                                                       *\r
-     *    Help yourself get started quickly and support the FreeRTOS         *\r
-     *    project by purchasing a FreeRTOS tutorial book, reference          *\r
-     *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
-     *                                                                       *\r
-     *    Thank you!                                                         *\r
-     *                                                                       *\r
-    ***************************************************************************\r
-\r
     This file is part of the FreeRTOS distribution.\r
 \r
     FreeRTOS is free software; you can redistribute it and/or modify it under\r
     the terms of the GNU General Public License (version 2) as published by the\r
     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
 \r
-    >>! NOTE: The modification to the GPL is included to allow you to distribute\r
-    >>! a combined work that includes FreeRTOS without being obliged to provide\r
-    >>! the source code for proprietary components outside of the FreeRTOS\r
-    >>! kernel.\r
+       ***************************************************************************\r
+    >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
+    >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
+    >>!   obliged to provide the source code for proprietary components     !<<\r
+    >>!   outside of the FreeRTOS kernel.                                   !<<\r
+       ***************************************************************************\r
 \r
     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
-    FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
+    FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
     link: http://www.freertos.org/a00114.html\r
 \r
-    1 tab == 4 spaces!\r
-\r
     ***************************************************************************\r
      *                                                                       *\r
-     *    Having a problem?  Start by reading the FAQ "My application does   *\r
-     *    not run, what could be wrong?"                                     *\r
+     *    FreeRTOS provides completely free yet professionally developed,    *\r
+     *    robust, strictly quality controlled, supported, and cross          *\r
+     *    platform software that is more than just the market leader, it     *\r
+     *    is the industry's de facto standard.                               *\r
      *                                                                       *\r
-     *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
+     *    Help yourself get started quickly while simultaneously helping     *\r
+     *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
+     *    tutorial book, reference manual, or both:                          *\r
+     *    http://www.FreeRTOS.org/Documentation                              *\r
      *                                                                       *\r
     ***************************************************************************\r
 \r
-    http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
-    license and Real Time Engineers Ltd. contact details.\r
+    http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
+       the FAQ page "My application does not run, what could be wrong?".  Have you\r
+       defined configASSERT()?\r
+\r
+       http://www.FreeRTOS.org/support - In return for receiving this top quality\r
+       embedded software for free we request you assist our global community by\r
+       participating in the support forum.\r
+\r
+       http://www.FreeRTOS.org/training - Investing in training allows your team to\r
+       be as productive as possible as early as possible.  Now you can receive\r
+       FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
+       Ltd, and the world's leading authority on the world's leading RTOS.\r
 \r
     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
 \r
-    http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
-    Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
-    licenses offer ticketed support, indemnification and middleware.\r
+    http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
+    Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
+\r
+    http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
+    Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
+    licenses offer ticketed support, indemnification and commercial middleware.\r
 \r
     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
     engineered and independently SIL3 certified version for use in safety and\r
@@ -87,8 +91,8 @@ privileged Vs unprivileged linkage and placement. */
        #error configUSE_TIMERS must be set to 1 to make the xEventGroupSetBitFromISR() function available.\r
 #endif\r
 \r
-#if ( INCLUDE_xEventGroupSetBitFromISR == 1 ) && ( INCLUDE_xTimerPendCallbackFromISR == 0 )\r
-       #error INCLUDE_xTimerPendCallbackFromISR must also be set to one to make the xEventGroupSetBitFromISR() function available.\r
+#if ( INCLUDE_xEventGroupSetBitFromISR == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 0 )\r
+       #error INCLUDE_xTimerPendFunctionCall must also be set to one to make the xEventGroupSetBitFromISR() function available.\r
 #endif\r
 \r
 /* The following bit fields convey control information in a task's event list\r
@@ -106,10 +110,15 @@ taskEVENT_LIST_ITEM_VALUE_IN_USE definition. */
        #define eventEVENT_BITS_CONTROL_BYTES   0xff000000UL\r
 #endif\r
 \r
-typedef struct EVENT_GROUP_DEFINITION\r
+typedef struct xEventGroupDefinition\r
 {\r
        EventBits_t uxEventBits;\r
        List_t xTasksWaitingForBits;            /*< List of tasks waiting for a bit to be set. */\r
+\r
+       #if( configUSE_TRACE_FACILITY == 1 )\r
+               UBaseType_t uxEventGroupNumber;\r
+       #endif\r
+\r
 } EventGroup_t;\r
 \r
 /*-----------------------------------------------------------*/\r
@@ -151,6 +160,7 @@ EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup, const EventBits_t u
 EventBits_t uxOriginalBitValue, uxReturn;\r
 EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup;\r
 BaseType_t xAlreadyYielded;\r
+BaseType_t xTimeoutOccurred = pdFALSE;\r
 \r
        configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 );\r
        configASSERT( uxBitsToWaitFor != 0 );\r
@@ -162,8 +172,6 @@ BaseType_t xAlreadyYielded;
 \r
        vTaskSuspendAll();\r
        {\r
-               traceEVENT_GROUP_SYNC_START( xEventGroup, uxBitsToSet );\r
-\r
                uxOriginalBitValue = pxEventBits->uxEventBits;\r
 \r
                ( void ) xEventGroupSetBits( xEventGroup, uxBitsToSet );\r
@@ -175,7 +183,7 @@ BaseType_t xAlreadyYielded;
 \r
                        /* Rendezvous always clear the bits.  They will have been cleared\r
                        already unless this is the only task in the rendezvous. */\r
-                       pxEventBits->uxEventBits &= uxBitsToWaitFor;\r
+                       pxEventBits->uxEventBits &= ~uxBitsToWaitFor;\r
 \r
                        xTicksToWait = 0;\r
                }\r
@@ -183,6 +191,8 @@ BaseType_t xAlreadyYielded;
                {\r
                        if( xTicksToWait != ( TickType_t ) 0 )\r
                        {\r
+                               traceEVENT_GROUP_SYNC_BLOCK( xEventGroup, uxBitsToSet, uxBitsToWaitFor );\r
+\r
                                /* Store the bits that the calling task is waiting for in the\r
                                task's event list item so the kernel knows when a match is\r
                                found.  Then enter the blocked state. */\r
@@ -231,7 +241,7 @@ BaseType_t xAlreadyYielded;
                                /* Although the task got here because it timed out before the\r
                                bits it was waiting for were set, it is possible that since it\r
                                unblocked another task has set the bits.  If this is the case\r
-                               then it may be required to clear the bits before exiting. */\r
+                               then it needs to clear the bits before exiting. */\r
                                if( ( uxReturn & uxBitsToWaitFor ) == uxBitsToWaitFor )\r
                                {\r
                                        pxEventBits->uxEventBits &= ~uxBitsToWaitFor;\r
@@ -242,16 +252,21 @@ BaseType_t xAlreadyYielded;
                                }\r
                        }\r
                        taskEXIT_CRITICAL();\r
+\r
+                       xTimeoutOccurred = pdTRUE;\r
                }\r
                else\r
                {\r
-                       /* The task unblocked because the bits were set.  Clear the control\r
-                       bits before returning the value. */\r
-                       uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;\r
+                       /* The task unblocked because the bits were set. */\r
                }\r
+\r
+               /* Control bits might be set as the task had blocked should not be\r
+               returned. */\r
+               uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;\r
        }\r
 \r
-       traceEVENT_GROUP_SYNC_END( xEventGroup, uxReturn );\r
+       traceEVENT_GROUP_SYNC_END( xEventGroup, uxBitsToSet, uxBitsToWaitFor, xTimeoutOccurred );\r
+\r
        return uxReturn;\r
 }\r
 /*-----------------------------------------------------------*/\r
@@ -261,9 +276,11 @@ EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup, const EventBits
 EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup;\r
 EventBits_t uxReturn, uxControlBits = 0;\r
 BaseType_t xWaitConditionMet, xAlreadyYielded;\r
+BaseType_t xTimeoutOccurred = pdFALSE;\r
 \r
        /* Check the user is not attempting to wait on the bits used by the kernel\r
        itself, and that at least one bit is being requested. */\r
+       configASSERT( xEventGroup );\r
        configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 );\r
        configASSERT( uxBitsToWaitFor != 0 );\r
        #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )\r
@@ -276,8 +293,6 @@ BaseType_t xWaitConditionMet, xAlreadyYielded;
        {\r
                const EventBits_t uxCurrentEventBits = pxEventBits->uxEventBits;\r
 \r
-               traceEVENT_GROUP_WAIT_BITS_START( xEventGroup, uxBitsToWaitFor );\r
-\r
                /* Check to see if the wait condition is already met or not. */\r
                xWaitConditionMet = prvTestWaitCondition( uxCurrentEventBits, uxBitsToWaitFor, xWaitForAllBits );\r
 \r
@@ -337,6 +352,8 @@ BaseType_t xWaitConditionMet, xAlreadyYielded;
                        some compilers mistakenly generate a warning about the variable\r
                        being returned without being set if it is not done. */\r
                        uxReturn = 0;\r
+\r
+                       traceEVENT_GROUP_WAIT_BITS_BLOCK( xEventGroup, uxBitsToWaitFor );\r
                }\r
        }\r
        xAlreadyYielded = xTaskResumeAll();\r
@@ -384,16 +401,20 @@ BaseType_t xWaitConditionMet, xAlreadyYielded;
                                }\r
                        }\r
                        taskEXIT_CRITICAL();\r
+\r
+                       /* Prevent compiler warnings when trace macros are not used. */\r
+                       xTimeoutOccurred = pdFALSE;\r
                }\r
                else\r
                {\r
-                       /* The task unblocked because the bits were set.  Clear the control\r
-                       bits before returning the value. */\r
-                       uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;\r
+                       /* The task unblocked because the bits were set. */\r
                }\r
+\r
+               /* The task blocked so control bits may have been set. */\r
+               uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;\r
        }\r
+       traceEVENT_GROUP_WAIT_BITS_END( xEventGroup, uxBitsToWaitFor, xTimeoutOccurred );\r
 \r
-       traceEVENT_GROUP_WAIT_BITS_END( xEventGroup, uxReturn );\r
        return uxReturn;\r
 }\r
 /*-----------------------------------------------------------*/\r
@@ -405,6 +426,7 @@ EventBits_t uxReturn;
 \r
        /* Check the user is not attempting to clear the bits used by the kernel\r
        itself. */\r
+       configASSERT( xEventGroup );\r
        configASSERT( ( uxBitsToClear & eventEVENT_BITS_CONTROL_BYTES ) == 0 );\r
 \r
        taskENTER_CRITICAL();\r
@@ -424,6 +446,37 @@ EventBits_t uxReturn;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) )\r
+\r
+       BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear )\r
+       {\r
+               BaseType_t xReturn;\r
+\r
+               traceEVENT_GROUP_CLEAR_BITS_FROM_ISR( xEventGroup, uxBitsToClear );\r
+               xReturn = xTimerPendFunctionCallFromISR( vEventGroupClearBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToClear, NULL );\r
+\r
+               return xReturn;\r
+       }\r
+\r
+#endif\r
+/*-----------------------------------------------------------*/\r
+\r
+EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup )\r
+{\r
+UBaseType_t uxSavedInterruptStatus;\r
+EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup;\r
+EventBits_t uxReturn;\r
+\r
+       uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
+       {\r
+               uxReturn = pxEventBits->uxEventBits;\r
+       }\r
+       portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
+\r
+       return uxReturn;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
 EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet )\r
 {\r
 ListItem_t *pxListItem, *pxNext;\r
@@ -435,6 +488,7 @@ BaseType_t xMatchFound = pdFALSE;
 \r
        /* Check the user is not attempting to set the bits used by the kernel\r
        itself. */\r
+       configASSERT( xEventGroup );\r
        configASSERT( ( uxBitsToSet & eventEVENT_BITS_CONTROL_BYTES ) == 0 );\r
 \r
        pxList = &( pxEventBits->xTasksWaitingForBits );\r
@@ -531,7 +585,7 @@ const List_t *pxTasksWaitingForBits = &( pxEventBits->xTasksWaitingForBits );
                        /* Unblock the task, returning 0 as the event list is being deleted\r
                        and     cannot therefore have any bits set. */\r
                        configASSERT( pxTasksWaitingForBits->xListEnd.pxNext != ( ListItem_t * ) &( pxTasksWaitingForBits->xListEnd ) );\r
-                       ( void ) xTaskRemoveFromUnorderedEventList( pxTasksWaitingForBits->xListEnd.pxNext, ( TickType_t ) eventUNBLOCKED_DUE_TO_BIT_SET );\r
+                       ( void ) xTaskRemoveFromUnorderedEventList( pxTasksWaitingForBits->xListEnd.pxNext, eventUNBLOCKED_DUE_TO_BIT_SET );\r
                }\r
 \r
                vPortFree( pxEventBits );\r
@@ -548,6 +602,14 @@ void vEventGroupSetBitsCallback( void *pvEventGroup, const uint32_t ulBitsToSet
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+/* For internal use only - execute a 'clear bits' command that was pended from\r
+an interrupt. */\r
+void vEventGroupClearBitsCallback( void *pvEventGroup, const uint32_t ulBitsToClear )\r
+{\r
+       ( void ) xEventGroupClearBits( pvEventGroup, ( EventBits_t ) ulBitsToClear );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
 static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits, const EventBits_t uxBitsToWaitFor, const BaseType_t xWaitForAllBits )\r
 {\r
 BaseType_t xWaitConditionMet = pdFALSE;\r
@@ -581,5 +643,41 @@ BaseType_t xWaitConditionMet = pdFALSE;
 \r
        return xWaitConditionMet;\r
 }\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) )\r
+\r
+       BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken )\r
+       {\r
+       BaseType_t xReturn;\r
+\r
+               traceEVENT_GROUP_SET_BITS_FROM_ISR( xEventGroup, uxBitsToSet );\r
+               xReturn = xTimerPendFunctionCallFromISR( vEventGroupSetBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToSet, pxHigherPriorityTaskWoken );\r
+\r
+               return xReturn;\r
+       }\r
+\r
+#endif\r
+/*-----------------------------------------------------------*/\r
+\r
+#if (configUSE_TRACE_FACILITY == 1)\r
+\r
+       UBaseType_t uxEventGroupGetNumber( void* xEventGroup )\r
+       {\r
+       UBaseType_t xReturn;\r
+       EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup;\r
 \r
+               if( xEventGroup == NULL )\r
+               {\r
+                       xReturn = 0;\r
+               }\r
+               else\r
+               {\r
+                       xReturn = pxEventBits->uxEventGroupNumber;\r
+               }\r
+\r
+               return xReturn;\r
+       }\r
+\r
+#endif\r
 \r