]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/timers.c
Changes to the FreeRTOS code:
[freertos] / FreeRTOS / Source / timers.c
index 080e4e8fe8afb690d32a5f92898e8d408f3db40b..0aef5ad71b5f6fb0e103f85a08e0d3959b94a19f 100644 (file)
@@ -1,60 +1,64 @@
 /*\r
-    FreeRTOS V8.1.2 - Copyright (C) 2014 Real Time Engineers Ltd.\r
+    FreeRTOS V8.2.3 - 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
+    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 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
@@ -174,6 +178,16 @@ PRIVILEGED_DATA static QueueHandle_t xTimerQueue = NULL;
 \r
 /*-----------------------------------------------------------*/\r
 \r
+#if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
+\r
+       /* If static allocation is supported then the application must provide the\r
+       following callback function - which enables the application to optionally\r
+       provide the memory that will be used by the timer task as the task's stack\r
+       and TCB. */\r
+       extern void vApplicationGetTimerTaskMemory( DummyTCB_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint16_t *pusTimerTaskStackSize );\r
+\r
+#endif\r
+\r
 /*\r
  * Initialise the infrastructure used by the timer service task if it has not\r
  * been initialised already.\r
@@ -191,7 +205,7 @@ static void prvTimerTask( void *pvParameters ) PRIVILEGED_FUNCTION;
  * Called by the timer service task to interpret and process a command it\r
  * received on the timer queue.\r
  */\r
-static void    prvProcessReceivedCommands( void ) PRIVILEGED_FUNCTION;\r
+static void prvProcessReceivedCommands( void ) PRIVILEGED_FUNCTION;\r
 \r
 /*\r
  * Insert the timer into either xActiveTimerList1, or xActiveTimerList2,\r
@@ -229,13 +243,17 @@ static TickType_t prvGetNextExpireTime( BaseType_t * const pxListWasEmpty ) PRIV
  * If a timer has expired, process it.  Otherwise, block the timer service task\r
  * until either a timer does expire or a command is received.\r
  */\r
-static void prvProcessTimerOrBlockTask( const TickType_t xNextExpireTime, const BaseType_t xListWasEmpty ) PRIVILEGED_FUNCTION;\r
+static void prvProcessTimerOrBlockTask( const TickType_t xNextExpireTime, BaseType_t xListWasEmpty ) PRIVILEGED_FUNCTION;\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
 BaseType_t xTimerCreateTimerTask( void )\r
 {\r
 BaseType_t xReturn = pdFAIL;\r
+DummyTCB_t *pxTimerTaskTCBBuffer = NULL;\r
+StackType_t *pxTimerTaskStackBuffer = NULL;\r
+uint16_t usTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;\r
+\r
 \r
        /* This function is called when the scheduler is started if\r
        configUSE_TIMERS is set to 1.  Check that the infrastructure used by the\r
@@ -245,16 +263,24 @@ BaseType_t xReturn = pdFAIL;
 \r
        if( xTimerQueue != NULL )\r
        {\r
+\r
+               #if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
+               {\r
+                       vApplicationGetTimerTaskMemory( &pxTimerTaskTCBBuffer, &pxTimerTaskStackBuffer, &usTimerTaskStackSize );\r
+               }\r
+               #endif /* configSUPPORT_STATIC_ALLOCATION */\r
+\r
+\r
                #if ( INCLUDE_xTimerGetTimerDaemonTaskHandle == 1 )\r
                {\r
                        /* Create the timer task, storing its handle in xTimerTaskHandle so\r
                        it can be returned by the xTimerGetTimerDaemonTaskHandle() function. */\r
-                       xReturn = xTaskCreate( prvTimerTask, "Tmr Svc", ( uint16_t ) configTIMER_TASK_STACK_DEPTH, NULL, ( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT, &xTimerTaskHandle );\r
+                       xReturn = xTaskGenericCreate( prvTimerTask, "Tmr Svc", usTimerTaskStackSize, NULL, ( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT, &xTimerTaskHandle, pxTimerTaskStackBuffer, pxTimerTaskTCBBuffer, NULL );\r
                }\r
                #else\r
                {\r
                        /* Create the timer task without storing its handle. */\r
-                       xReturn = xTaskCreate( prvTimerTask, "Tmr Svc", ( uint16_t ) configTIMER_TASK_STACK_DEPTH, NULL, ( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT, NULL);\r
+                       xReturn = xTaskGenericCreate( prvTimerTask, "Tmr Svc", usTimerTaskStackSize, NULL, ( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT, NULL, pxTimerTaskStackBuffer, pxTimerTaskTCBBuffer, NULL );\r
                }\r
                #endif\r
        }\r
@@ -314,6 +340,8 @@ BaseType_t xTimerGenericCommand( TimerHandle_t xTimer, const BaseType_t xCommand
 BaseType_t xReturn = pdFAIL;\r
 DaemonTaskMessage_t xMessage;\r
 \r
+       configASSERT( xTimer );\r
+\r
        /* Send a message to the timer service task to perform a particular action\r
        on a particular timer definition. */\r
        if( xTimerQueue != NULL )\r
@@ -367,6 +395,7 @@ const char * pcTimerGetTimerName( TimerHandle_t xTimer )
 {\r
 Timer_t *pxTimer = ( Timer_t * ) xTimer;\r
 \r
+       configASSERT( xTimer );\r
        return pxTimer->pcTimerName;\r
 }\r
 /*-----------------------------------------------------------*/\r
@@ -435,7 +464,7 @@ BaseType_t xListWasEmpty;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static void prvProcessTimerOrBlockTask( const TickType_t xNextExpireTime, const BaseType_t xListWasEmpty )\r
+static void prvProcessTimerOrBlockTask( const TickType_t xNextExpireTime, BaseType_t xListWasEmpty )\r
 {\r
 TickType_t xTimeNow;\r
 BaseType_t xTimerListsWereSwitched;\r
@@ -464,14 +493,21 @@ BaseType_t xTimerListsWereSwitched;
                                received - whichever comes first.  The following line cannot\r
                                be reached unless xNextExpireTime > xTimeNow, except in the\r
                                case when the current timer list is empty. */\r
-                               vQueueWaitForMessageRestricted( xTimerQueue, ( xNextExpireTime - xTimeNow ) );\r
+                               if( xListWasEmpty != pdFALSE )\r
+                               {\r
+                                       /* The current timer list is empty - is the overflow list\r
+                                       also empty? */\r
+                                       xListWasEmpty = listLIST_IS_EMPTY( pxOverflowTimerList );\r
+                               }\r
+\r
+                               vQueueWaitForMessageRestricted( xTimerQueue, ( xNextExpireTime - xTimeNow ), xListWasEmpty );\r
 \r
                                if( xTaskResumeAll() == pdFALSE )\r
                                {\r
-                                       /* Yield to wait for either a command to arrive, or the block time\r
-                                       to expire.  If a command arrived between the critical section being\r
-                                       exited and this yield then the yield will not cause the task\r
-                                       to block. */\r
+                                       /* Yield to wait for either a command to arrive, or the\r
+                                       block time to expire.  If a command arrived between the\r
+                                       critical section being exited and this yield then the yield\r
+                                       will not cause the task to block. */\r
                                        portYIELD_WITHIN_API();\r
                                }\r
                                else\r
@@ -806,6 +842,8 @@ BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer )
 BaseType_t xTimerIsInActiveList;\r
 Timer_t *pxTimer = ( Timer_t * ) xTimer;\r
 \r
+       configASSERT( xTimer );\r
+\r
        /* Is the timer in the list of active timers? */\r
        taskENTER_CRITICAL();\r
        {\r
@@ -823,8 +861,31 @@ Timer_t *pxTimer = ( Timer_t * ) xTimer;
 void *pvTimerGetTimerID( const TimerHandle_t xTimer )\r
 {\r
 Timer_t * const pxTimer = ( Timer_t * ) xTimer;\r
+void *pvReturn;\r
+\r
+       configASSERT( xTimer );\r
+\r
+       taskENTER_CRITICAL();\r
+       {\r
+               pvReturn = pxTimer->pvTimerID;\r
+       }\r
+       taskEXIT_CRITICAL();\r
+\r
+       return pvReturn;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID )\r
+{\r
+Timer_t * const pxTimer = ( Timer_t * ) xTimer;\r
+\r
+       configASSERT( xTimer );\r
 \r
-       return pxTimer->pvTimerID;\r
+       taskENTER_CRITICAL();\r
+       {\r
+               pxTimer->pvTimerID = pvNewID;\r
+       }\r
+       taskEXIT_CRITICAL();\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -843,7 +904,7 @@ Timer_t * const pxTimer = ( Timer_t * ) xTimer;
                xMessage.u.xCallbackParameters.ulParameter2 = ulParameter2;\r
 \r
                xReturn = xQueueSendFromISR( xTimerQueue, &xMessage, pxHigherPriorityTaskWoken );\r
-               \r
+\r
                tracePEND_FUNC_CALL_FROM_ISR( xFunctionToPend, pvParameter1, ulParameter2, xReturn );\r
 \r
                return xReturn;\r
@@ -859,6 +920,11 @@ Timer_t * const pxTimer = ( Timer_t * ) xTimer;
        DaemonTaskMessage_t xMessage;\r
        BaseType_t xReturn;\r
 \r
+               /* This function can only be called after a timer has been created or\r
+               after the scheduler has been started because, until then, the timer\r
+               queue does not exist. */\r
+               configASSERT( xTimerQueue );\r
+\r
                /* Complete the message with the function parameters and post it to the\r
                daemon task. */\r
                xMessage.xMessageID = tmrCOMMAND_EXECUTE_CALLBACK;\r
@@ -869,7 +935,7 @@ Timer_t * const pxTimer = ( Timer_t * ) xTimer;
                xReturn = xQueueSendToBack( xTimerQueue, &xMessage, xTicksToWait );\r
 \r
                tracePEND_FUNC_CALL( xFunctionToPend, pvParameter1, ulParameter2, xReturn );\r
-               \r
+\r
                return xReturn;\r
        }\r
 \r