]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/croutine.c
Roll up the minor changes checked into svn since V10.0.0 into new V10.0.1 ready for...
[freertos] / FreeRTOS / Source / croutine.c
index 2b135f84eb8e4bfceb7f163319270940c2748598..b995073559790db7108fa293db7c7d2c3029cb7b 100644 (file)
@@ -1,72 +1,37 @@
 /*\r
-    FreeRTOS V7.6.0 - Copyright (C) 2013 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
-    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
-    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
-     *                                                                       *\r
-     *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
-     *                                                                       *\r
-    ***************************************************************************\r
-\r
-    http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
-    license and Real Time Engineers Ltd. contact details.\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
-\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
+ * FreeRTOS Kernel V10.0.1\r
+ * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+ * this software and associated documentation files (the "Software"), to deal in\r
+ * the Software without restriction, including without limitation the rights to\r
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
+ * the Software, and to permit persons to whom the Software is furnished to do so,\r
+ * subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in all\r
+ * copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ *\r
+ * http://www.FreeRTOS.org\r
+ * http://aws.amazon.com/freertos\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
@@ -105,7 +70,7 @@ static portTickType xCoRoutineTickCount = 0, xLastTickCount = 0, xPassedTicks =
        {                                                                                                                                                                                                                               \\r
                uxTopCoRoutineReadyPriority = pxCRCB->uxPriority;                                                                                                                       \\r
        }                                                                                                                                                                                                                               \\r
-       vListInsertEnd( ( xList * ) &( pxReadyCoRoutineLists[ pxCRCB->uxPriority ] ), &( pxCRCB->xGenericListItem ) );  \\r
+       vListInsertEnd( ( List_t * ) &( pxReadyCoRoutineLists[ pxCRCB->uxPriority ] ), &( pxCRCB->xGenericListItem ) ); \\r
 }\r
 \r
 /*\r
@@ -134,13 +99,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
@@ -167,14 +132,14 @@ 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
                /* Event lists are always in priority order. */\r
-               listSET_LIST_ITEM_VALUE( &( pxCoRoutine->xEventListItem ), configMAX_PRIORITIES - ( portTickType ) uxPriority );\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
@@ -191,9 +156,9 @@ corCRCB *pxCoRoutine;
 }\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
@@ -202,7 +167,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
-       ( void ) uxListRemove( ( 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
@@ -211,13 +176,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
@@ -236,12 +201,12 @@ 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
+                       pxUnblockedCRCB = ( CRCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( (&xPendingReadyCoRoutineList) );\r
                        ( void ) uxListRemove( &( pxUnblockedCRCB->xEventListItem ) );\r
                }\r
                portENABLE_INTERRUPTS();\r
@@ -254,7 +219,7 @@ static void prvCheckPendingReadyList( void )
 \r
 static void prvCheckDelayedList( void )\r
 {\r
-corCRCB *pxCRCB;\r
+CRCB_t *pxCRCB;\r
 \r
        xPassedTicks = xTaskGetTickCount() - xLastTickCount;\r
        while( xPassedTicks )\r
@@ -265,7 +230,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
@@ -277,7 +242,7 @@ 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
@@ -292,7 +257,7 @@ 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
-                               uxListRemove( &( pxCRCB->xGenericListItem ) );\r
+                               ( void ) uxListRemove( &( pxCRCB->xGenericListItem ) );\r
 \r
                                /* Is the co-routine waiting on an event also? */\r
                                if( pxCRCB->xEventListItem.pvContainer )\r
@@ -342,16 +307,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
@@ -360,17 +325,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
+       pxUnblockedCRCB = ( CRCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList );\r
        ( void ) uxListRemove( &( pxUnblockedCRCB->xEventListItem ) );\r
-       vListInsertEnd( ( xList * ) &( xPendingReadyCoRoutineList ), &( pxUnblockedCRCB->xEventListItem ) );\r
+       vListInsertEnd( ( List_t * ) &( xPendingReadyCoRoutineList ), &( pxUnblockedCRCB->xEventListItem ) );\r
 \r
        if( pxUnblockedCRCB->uxPriority >= pxCurrentCoRoutine->uxPriority )\r
        {\r
@@ -384,3 +349,5 @@ signed portBASE_TYPE xReturn;
        return xReturn;\r
 }\r
 \r
+#endif /* configUSE_CO_ROUTINES == 0 */\r
+\r