]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/croutine.c
Update version number to 9.0.0rc2.
[freertos] / FreeRTOS / Source / croutine.c
index 4903540f4b1661efab17b403fa2e18e365b1747d..f4b09a966bc5707f8bd3bd7c853da2bb41e02a9a 100644 (file)
@@ -1,73 +1,79 @@
 /*\r
-    FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.\r
-\r
-\r
-    ***************************************************************************\r
-     *                                                                       *\r
-     *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
-     *    Complete, revised, and edited pdf reference manuals are also       *\r
-     *    available.                                                         *\r
-     *                                                                       *\r
-     *    Purchasing FreeRTOS documentation will not only help you, by       *\r
-     *    ensuring you get running as quickly as possible and with an        *\r
-     *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
-     *    the FreeRTOS project to continue with its mission of providing     *\r
-     *    professional grade, cross platform, de facto standard solutions    *\r
-     *    for microcontrollers - completely free of charge!                  *\r
-     *                                                                       *\r
-     *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
-     *                                                                       *\r
-     *    Thank you for using FreeRTOS, and thank you for your support!      *\r
-     *                                                                       *\r
-    ***************************************************************************\r
+    FreeRTOS V9.0.0rc2 - Copyright (C) 2016 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
     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
-    >>>NOTE<<< The modification to the GPL is included to allow you to\r
-    distribute a combined work that includes FreeRTOS without being obliged to\r
-    provide the source code for proprietary components outside of the FreeRTOS\r
-    kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
-    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
-    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
-    more details. You should have received a copy of the GNU General Public\r
-    License and the FreeRTOS license exception along with FreeRTOS; if not it\r
-    can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
-    by writing to Richard Barry, contact details for whom are available on the\r
-    FreeRTOS WEB site.\r
+    Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.\r
+\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 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
-    \r
-    http://www.FreeRTOS.org - Documentation, training, latest information, \r
-    license and contact details.\r
-    \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.\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
-    Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell \r
-    the code with commercial support, indemnification, and middleware, under \r
-    the OpenRTOS brand: http://www.OpenRTOS.com.  High Integrity Systems also\r
-    provide a safety engineered and independently SIL3 certified version under \r
-    the SafeRTOS brand: http://www.SafeRTOS.com.\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
+    mission critical applications that require provable dependability.\r
+\r
+    1 tab == 4 spaces!\r
 */\r
 \r
 #include "FreeRTOS.h"\r
 #include "task.h"\r
 #include "croutine.h"\r
 \r
+/* Remove the whole file is co-routines are not being used. */\r
+#if( configUSE_CO_ROUTINES != 0 )\r
+\r
 /*\r
  * Some kernel aware debuggers require data to be viewed to be global, rather\r
  * than file scope.\r
 \r
 \r
 /* Lists for ready and blocked co-routines. --------------------*/\r
-static xList pxReadyCoRoutineLists[ configMAX_CO_ROUTINE_PRIORITIES ]; /*< Prioritised ready co-routines. */\r
-static xList xDelayedCoRoutineList1;                                                                   /*< Delayed co-routines. */\r
-static xList xDelayedCoRoutineList2;                                                                   /*< Delayed co-routines (two lists are used - one for delays that have overflowed the current tick count. */\r
-static xList * pxDelayedCoRoutineList;                                                                 /*< Points to the delayed co-routine list currently being used. */\r
-static xList * pxOverflowDelayedCoRoutineList;                                                 /*< Points to the delayed co-routine list currently being used to hold co-routines that have overflowed the current tick count. */\r
-static xList xPendingReadyCoRoutineList;                                                                                       /*< Holds co-routines that have been readied by an external event.  They cannot be added directly to the ready lists as the ready lists cannot be accessed by interrupts. */\r
+static List_t pxReadyCoRoutineLists[ configMAX_CO_ROUTINE_PRIORITIES ];        /*< Prioritised ready co-routines. */\r
+static List_t xDelayedCoRoutineList1;                                                                  /*< Delayed co-routines. */\r
+static List_t xDelayedCoRoutineList2;                                                                  /*< Delayed co-routines (two lists are used - one for delays that have overflowed the current tick count. */\r
+static List_t * pxDelayedCoRoutineList;                                                                        /*< Points to the delayed co-routine list currently being used. */\r
+static List_t * pxOverflowDelayedCoRoutineList;                                                        /*< Points to the delayed co-routine list currently being used to hold co-routines that have overflowed the current tick count. */\r
+static List_t xPendingReadyCoRoutineList;                                                              /*< Holds co-routines that have been readied by an external event.  They cannot be added directly to the ready lists as the ready lists cannot be accessed by interrupts. */\r
 \r
 /* Other file private variables. --------------------------------*/\r
-corCRCB * pxCurrentCoRoutine = NULL;\r
-static unsigned portBASE_TYPE uxTopCoRoutineReadyPriority = 0;\r
-static portTickType xCoRoutineTickCount = 0, xLastTickCount = 0, xPassedTicks = 0;\r
+CRCB_t * pxCurrentCoRoutine = NULL;\r
+static UBaseType_t uxTopCoRoutineReadyPriority = 0;\r
+static TickType_t xCoRoutineTickCount = 0, xLastTickCount = 0, xPassedTicks = 0;\r
 \r
 /* The initial state of the co-routine when it is created. */\r
 #define corINITIAL_STATE       ( 0 )\r
@@ -106,8 +112,8 @@ static portTickType xCoRoutineTickCount = 0, xLastTickCount = 0, xPassedTicks =
        {                                                                                                                                                                                                                               \\r
                uxTopCoRoutineReadyPriority = pxCRCB->uxPriority;                                                                                                                       \\r
        }                                                                                                                                                                                                                               \\r
-       vListInsertEnd( ( xList * ) &( pxReadyCoRoutineLists[ pxCRCB->uxPriority ] ), &( pxCRCB->xGenericListItem ) );  \\r
-}      \r
+       vListInsertEnd( ( List_t * ) &( pxReadyCoRoutineLists[ pxCRCB->uxPriority ] ), &( pxCRCB->xGenericListItem ) ); \\r
+}\r
 \r
 /*\r
  * Utility to ready all the lists used by the scheduler.  This is called\r
@@ -135,13 +141,13 @@ static void prvCheckDelayedList( void );
 \r
 /*-----------------------------------------------------------*/\r
 \r
-signed portBASE_TYPE xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, unsigned portBASE_TYPE uxPriority, unsigned portBASE_TYPE uxIndex )\r
+BaseType_t xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, UBaseType_t uxPriority, UBaseType_t uxIndex )\r
 {\r
-signed portBASE_TYPE xReturn;\r
-corCRCB *pxCoRoutine;\r
+BaseType_t xReturn;\r
+CRCB_t *pxCoRoutine;\r
 \r
        /* Allocate the memory that will store the co-routine control block. */\r
-       pxCoRoutine = ( corCRCB * ) pvPortMalloc( sizeof( corCRCB ) );\r
+       pxCoRoutine = ( CRCB_t * ) pvPortMalloc( sizeof( CRCB_t ) );\r
        if( pxCoRoutine )\r
        {\r
                /* If pxCurrentCoRoutine is NULL then this is the first co-routine to\r
@@ -168,15 +174,15 @@ corCRCB *pxCoRoutine;
                vListInitialiseItem( &( pxCoRoutine->xGenericListItem ) );\r
                vListInitialiseItem( &( pxCoRoutine->xEventListItem ) );\r
 \r
-               /* Set the co-routine control block as a link back from the xListItem.\r
+               /* Set the co-routine control block as a link back from the ListItem_t.\r
                This is so we can get back to the containing CRCB from a generic item\r
                in a list. */\r
                listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xGenericListItem ), pxCoRoutine );\r
                listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xEventListItem ), pxCoRoutine );\r
-       \r
+\r
                /* Event lists are always in priority order. */\r
-               listSET_LIST_ITEM_VALUE( &( pxCoRoutine->xEventListItem ), configMAX_PRIORITIES - ( portTickType ) uxPriority );\r
-               \r
+               listSET_LIST_ITEM_VALUE( &( pxCoRoutine->xEventListItem ), ( ( TickType_t ) configMAX_CO_ROUTINE_PRIORITIES - ( TickType_t ) uxPriority ) );\r
+\r
                /* Now the co-routine has been initialised it can be added to the ready\r
                list at the correct priority. */\r
                prvAddCoRoutineToReadyQueue( pxCoRoutine );\r
@@ -184,17 +190,17 @@ corCRCB *pxCoRoutine;
                xReturn = pdPASS;\r
        }\r
        else\r
-       {               \r
+       {\r
                xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY;\r
        }\r
-       \r
-       return xReturn; \r
+\r
+       return xReturn;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-void vCoRoutineAddToDelayedList( portTickType xTicksToDelay, xList *pxEventList )\r
+void vCoRoutineAddToDelayedList( TickType_t xTicksToDelay, List_t *pxEventList )\r
 {\r
-portTickType xTimeToWake;\r
+TickType_t xTimeToWake;\r
 \r
        /* Calculate the time to wake - this may overflow but this is\r
        not a problem. */\r
@@ -203,7 +209,7 @@ portTickType xTimeToWake;
        /* We must remove ourselves from the ready list before adding\r
        ourselves to the blocked list as the same list item is used for\r
        both lists. */\r
-       vListRemove( ( xListItem * ) &( pxCurrentCoRoutine->xGenericListItem ) );\r
+       ( void ) uxListRemove( ( ListItem_t * ) &( pxCurrentCoRoutine->xGenericListItem ) );\r
 \r
        /* The list item will be inserted in wake time order. */\r
        listSET_LIST_ITEM_VALUE( &( pxCurrentCoRoutine->xGenericListItem ), xTimeToWake );\r
@@ -212,13 +218,13 @@ portTickType xTimeToWake;
        {\r
                /* Wake time has overflowed.  Place this item in the\r
                overflow list. */\r
-               vListInsert( ( xList * ) pxOverflowDelayedCoRoutineList, ( xListItem * ) &( pxCurrentCoRoutine->xGenericListItem ) );\r
+               vListInsert( ( List_t * ) pxOverflowDelayedCoRoutineList, ( ListItem_t * ) &( pxCurrentCoRoutine->xGenericListItem ) );\r
        }\r
        else\r
        {\r
                /* The wake time has not overflowed, so we can use the\r
                current block list. */\r
-               vListInsert( ( xList * ) pxDelayedCoRoutineList, ( xListItem * ) &( pxCurrentCoRoutine->xGenericListItem ) );\r
+               vListInsert( ( List_t * ) pxDelayedCoRoutineList, ( ListItem_t * ) &( pxCurrentCoRoutine->xGenericListItem ) );\r
        }\r
 \r
        if( pxEventList )\r
@@ -237,25 +243,25 @@ static void prvCheckPendingReadyList( void )
        the     ready lists itself. */\r
        while( listLIST_IS_EMPTY( &xPendingReadyCoRoutineList ) == pdFALSE )\r
        {\r
-               corCRCB *pxUnblockedCRCB;\r
+               CRCB_t *pxUnblockedCRCB;\r
 \r
                /* The pending ready list can be accessed by an ISR. */\r
                portDISABLE_INTERRUPTS();\r
-               {       \r
-                       pxUnblockedCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( (&xPendingReadyCoRoutineList) );                   \r
-                       vListRemove( &( pxUnblockedCRCB->xEventListItem ) );\r
+               {\r
+                       pxUnblockedCRCB = ( CRCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( (&xPendingReadyCoRoutineList) );\r
+                       ( void ) uxListRemove( &( pxUnblockedCRCB->xEventListItem ) );\r
                }\r
                portENABLE_INTERRUPTS();\r
 \r
-               vListRemove( &( pxUnblockedCRCB->xGenericListItem ) );\r
-               prvAddCoRoutineToReadyQueue( pxUnblockedCRCB ); \r
+               ( void ) uxListRemove( &( pxUnblockedCRCB->xGenericListItem ) );\r
+               prvAddCoRoutineToReadyQueue( pxUnblockedCRCB );\r
        }\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
 static void prvCheckDelayedList( void )\r
 {\r
-corCRCB *pxCRCB;\r
+CRCB_t *pxCRCB;\r
 \r
        xPassedTicks = xTaskGetTickCount() - xLastTickCount;\r
        while( xPassedTicks )\r
@@ -266,7 +272,7 @@ corCRCB *pxCRCB;
                /* If the tick count has overflowed we need to swap the ready lists. */\r
                if( xCoRoutineTickCount == 0 )\r
                {\r
-                       xList * pxTemp;\r
+                       List_t * pxTemp;\r
 \r
                        /* Tick count has overflowed so we need to swap the delay lists.  If there are\r
                        any items in pxDelayedCoRoutineList here then there is an error! */\r
@@ -278,13 +284,13 @@ corCRCB *pxCRCB;
                /* See if this tick has made a timeout expire. */\r
                while( listLIST_IS_EMPTY( pxDelayedCoRoutineList ) == pdFALSE )\r
                {\r
-                       pxCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedCoRoutineList );\r
+                       pxCRCB = ( CRCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedCoRoutineList );\r
 \r
-                       if( xCoRoutineTickCount < listGET_LIST_ITEM_VALUE( &( pxCRCB->xGenericListItem ) ) )                            \r
-                       {                       \r
-                               /* Timeout not yet expired. */                                                                                                                                                  \r
-                               break;                                                                                                                                                          \r
-                       }                                                                                                                                                                               \r
+                       if( xCoRoutineTickCount < listGET_LIST_ITEM_VALUE( &( pxCRCB->xGenericListItem ) ) )\r
+                       {\r
+                               /* Timeout not yet expired. */\r
+                               break;\r
+                       }\r
 \r
                        portDISABLE_INTERRUPTS();\r
                        {\r
@@ -293,18 +299,18 @@ corCRCB *pxCRCB;
                                have been moved to the pending ready list and the following\r
                                line is still valid.  Also the pvContainer parameter will have\r
                                been set to NULL so the following lines are also valid. */\r
-                               vListRemove( &( pxCRCB->xGenericListItem ) );                                                                                   \r
+                               ( void ) uxListRemove( &( pxCRCB->xGenericListItem ) );\r
 \r
-                               /* Is the co-routine waiting on an event also? */                                                                                               \r
-                               if( pxCRCB->xEventListItem.pvContainer )                                                                                                        \r
-                               {                                                                                                                       \r
-                                       vListRemove( &( pxCRCB->xEventListItem ) );                                                                                     \r
+                               /* Is the co-routine waiting on an event also? */\r
+                               if( pxCRCB->xEventListItem.pvContainer )\r
+                               {\r
+                                       ( void ) uxListRemove( &( pxCRCB->xEventListItem ) );\r
                                }\r
                        }\r
                        portENABLE_INTERRUPTS();\r
 \r
-                       prvAddCoRoutineToReadyQueue( pxCRCB );                                                                                                  \r
-               }                                                                                                                                                                                                       \r
+                       prvAddCoRoutineToReadyQueue( pxCRCB );\r
+               }\r
        }\r
 \r
        xLastTickCount = xCoRoutineTickCount;\r
@@ -343,16 +349,16 @@ void vCoRoutineSchedule( void )
 \r
 static void prvInitialiseCoRoutineLists( void )\r
 {\r
-unsigned portBASE_TYPE uxPriority;\r
+UBaseType_t uxPriority;\r
 \r
        for( uxPriority = 0; uxPriority < configMAX_CO_ROUTINE_PRIORITIES; uxPriority++ )\r
        {\r
-               vListInitialise( ( xList * ) &( pxReadyCoRoutineLists[ uxPriority ] ) );\r
+               vListInitialise( ( List_t * ) &( pxReadyCoRoutineLists[ uxPriority ] ) );\r
        }\r
 \r
-       vListInitialise( ( xList * ) &xDelayedCoRoutineList1 );\r
-       vListInitialise( ( xList * ) &xDelayedCoRoutineList2 );\r
-       vListInitialise( ( xList * ) &xPendingReadyCoRoutineList );\r
+       vListInitialise( ( List_t * ) &xDelayedCoRoutineList1 );\r
+       vListInitialise( ( List_t * ) &xDelayedCoRoutineList2 );\r
+       vListInitialise( ( List_t * ) &xPendingReadyCoRoutineList );\r
 \r
        /* Start with pxDelayedCoRoutineList using list1 and the\r
        pxOverflowDelayedCoRoutineList using list2. */\r
@@ -361,17 +367,17 @@ unsigned portBASE_TYPE uxPriority;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-signed portBASE_TYPE xCoRoutineRemoveFromEventList( const xList *pxEventList )\r
+BaseType_t xCoRoutineRemoveFromEventList( const List_t *pxEventList )\r
 {\r
-corCRCB *pxUnblockedCRCB;\r
-signed portBASE_TYPE xReturn;\r
+CRCB_t *pxUnblockedCRCB;\r
+BaseType_t xReturn;\r
 \r
        /* This function is called from within an interrupt.  It can only access\r
        event lists and the pending ready list.  This function assumes that a\r
        check has already been made to ensure pxEventList is not empty. */\r
-       pxUnblockedCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList );\r
-       vListRemove( &( pxUnblockedCRCB->xEventListItem ) );\r
-       vListInsertEnd( ( xList * ) &( xPendingReadyCoRoutineList ), &( pxUnblockedCRCB->xEventListItem ) );\r
+       pxUnblockedCRCB = ( CRCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList );\r
+       ( void ) uxListRemove( &( pxUnblockedCRCB->xEventListItem ) );\r
+       vListInsertEnd( ( List_t * ) &( xPendingReadyCoRoutineList ), &( pxUnblockedCRCB->xEventListItem ) );\r
 \r
        if( pxUnblockedCRCB->uxPriority >= pxCurrentCoRoutine->uxPriority )\r
        {\r
@@ -385,3 +391,5 @@ signed portBASE_TYPE xReturn;
        return xReturn;\r
 }\r
 \r
+#endif /* configUSE_CO_ROUTINES == 0 */\r
+\r