]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/timers.c
Add configASSERT()s to ensure counting semaphores are not created with a max count...
[freertos] / FreeRTOS / Source / timers.c
index ddfdb704704ba75689d406ca9b919ffb1de86198..004b3f47df7a2ce1f7ebf5b991ab7aa8e798c59f 100644 (file)
@@ -1,48 +1,38 @@
 /*\r
-    FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd.\r
+    FreeRTOS V7.5.3 - Copyright (C) 2013 Real Time Engineers Ltd. \r
+    All rights reserved\r
 \r
-    FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME.  PLEASE VISIT\r
-    http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
+    VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\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
+     *    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
-     *    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
+     *    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
-     *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
-     *                                                                       *\r
-     *    Thank you for using FreeRTOS, and thank you for your support!      *\r
+     *    Thank you!                                                         *\r
      *                                                                       *\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
-    >>>>>>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.\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.  See the GNU General Public License for more\r
-    details. You should have received a copy of the GNU General Public License\r
-    and the FreeRTOS license exception along with FreeRTOS; if not itcan be\r
-    viewed here: http://www.freertos.org/a00114.html and also obtained by\r
-    writing to Real Time Engineers Ltd., contact details for whom are available\r
-    on the FreeRTOS WEB site.\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
 \r
-\r
-    http://www.FreeRTOS.org - Documentation, books, training, latest versions, \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, and our new\r
-    fully thread aware and reentrant UDP/IP stack.\r
-\r
-    http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High \r
-    Integrity Systems, who sell the code with commercial support, \r
-    indemnification and middleware, under the OpenRTOS brand.\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
+    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
 \r
+/* Standard includes. */\r
+#include <stdlib.h>\r
+\r
 /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining\r
 all the API functions to use the MPU wrappers.  That should only be done when\r
 task.h is included from an application file. */\r
@@ -82,7 +76,12 @@ task.h is included from an application file. */
 #include "queue.h"\r
 #include "timers.h"\r
 \r
-#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE\r
+/* Lint e961 and e750 are suppressed as a MISRA exception justified because the\r
+MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined for the\r
+header files above, but not in this file, in order to generate the correct\r
+privileged Vs unprivileged linkage and placement. */\r
+#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750. */\r
+\r
 \r
 /* This entire source file will be skipped if the application is not configured\r
 to include software timer functionality.  This #if is closed at the very bottom\r
@@ -113,6 +112,8 @@ typedef struct tmrTimerQueueMessage
        xTIMER *                                pxTimer;                        /*<< The timer to which the command will be applied. */\r
 } xTIMER_MESSAGE;\r
 \r
+/*lint -e956 A manual analysis and inspection has been used to determine which\r
+static variables must be declared volatile. */\r
 \r
 /* The list in which active timers are stored.  Timers are referenced in expire\r
 time order, with the nearest expiry time at the front of the list.  Only the\r
@@ -131,6 +132,8 @@ PRIVILEGED_DATA static xQueueHandle xTimerQueue = NULL;
 \r
 #endif\r
 \r
+/*lint +e956 */\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
 /*\r
@@ -231,7 +234,6 @@ xTIMER *pxNewTimer;
        if( xTimerPeriodInTicks == ( portTickType ) 0U )\r
        {\r
                pxNewTimer = NULL;\r
-               configASSERT( ( xTimerPeriodInTicks > 0 ) );\r
        }\r
        else\r
        {\r
@@ -258,6 +260,9 @@ xTIMER *pxNewTimer;
                }\r
        }\r
 \r
+       /* 0 is not a valid value for xTimerPeriodInTicks. */\r
+       configASSERT( ( xTimerPeriodInTicks > 0 ) );\r
+\r
        return ( xTimerHandle ) pxNewTimer;\r
 }\r
 /*-----------------------------------------------------------*/\r
@@ -320,7 +325,7 @@ portBASE_TYPE xResult;
        /* Remove the timer from the list of active timers.  A check has already\r
        been performed to ensure the list is not empty. */\r
        pxTimer = ( xTIMER * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList );\r
-       uxListRemove( &( pxTimer->xTimerListItem ) );\r
+       ( void ) uxListRemove( &( pxTimer->xTimerListItem ) );\r
        traceTIMER_EXPIRED( pxTimer );\r
 \r
        /* If the timer is an auto reload timer then calculate the next\r
@@ -390,7 +395,7 @@ portBASE_TYPE xTimerListsWereSwitched;
                        /* The tick count has not overflowed, has the timer expired? */\r
                        if( ( xListWasEmpty == pdFALSE ) && ( xNextExpireTime <= xTimeNow ) )\r
                        {\r
-                               xTaskResumeAll();\r
+                               ( void ) xTaskResumeAll();\r
                                prvProcessExpiredTimer( xNextExpireTime, xTimeNow );\r
                        }\r
                        else\r
@@ -415,7 +420,7 @@ portBASE_TYPE xTimerListsWereSwitched;
                }\r
                else\r
                {\r
-                       xTaskResumeAll();\r
+                       ( void ) xTaskResumeAll();\r
                }\r
        }\r
 }\r
@@ -450,7 +455,7 @@ portTickType xNextExpireTime;
 static portTickType prvSampleTimeNow( portBASE_TYPE *pxTimerListsWereSwitched )\r
 {\r
 portTickType xTimeNow;\r
-PRIVILEGED_DATA static portTickType xLastTime = ( portTickType ) 0U;\r
+PRIVILEGED_DATA static portTickType xLastTime = ( portTickType ) 0U; /*lint !e956 Variable is only accessible to one task. */\r
 \r
        xTimeNow = xTaskGetTickCount();\r
 \r
@@ -481,7 +486,7 @@ portBASE_TYPE xProcessTimerNow = pdFALSE;
        {\r
                /* Has the expiry time elapsed between the command to start/reset a\r
                timer was issued, and the time the command was processed? */\r
-               if( ( ( portTickType ) ( xTimeNow - xCommandTime ) ) >= pxTimer->xTimerPeriodInTicks )\r
+               if( ( xTimeNow - xCommandTime ) >= pxTimer->xTimerPeriodInTicks )\r
                {\r
                        /* The time between a command being issued and the command being\r
                        processed actually exceeds the timers period.  */\r
@@ -518,14 +523,14 @@ xTIMER *pxTimer;
 portBASE_TYPE xTimerListsWereSwitched, xResult;\r
 portTickType xTimeNow;\r
 \r
-       while( xQueueReceive( xTimerQueue, &xMessage, tmrNO_DELAY ) != pdFAIL )\r
+       while( xQueueReceive( xTimerQueue, &xMessage, tmrNO_DELAY ) != pdFAIL ) /*lint !e603 xMessage does not have to be initialised as it is passed out, not in, and it is not used unless xQueueReceive() returns pdTRUE. */\r
        {\r
                pxTimer = xMessage.pxTimer;\r
 \r
                if( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdFALSE )\r
                {\r
                        /* The timer is in a list, remove it. */\r
-                       uxListRemove( &( pxTimer->xTimerListItem ) );\r
+                       ( void ) uxListRemove( &( pxTimer->xTimerListItem ) );\r
                }\r
 \r
                traceTIMER_COMMAND_RECEIVED( pxTimer, xMessage.xMessageID, xMessage.xMessageValue );\r
@@ -565,7 +570,14 @@ portTickType xTimeNow;
                        case tmrCOMMAND_CHANGE_PERIOD :\r
                                pxTimer->xTimerPeriodInTicks = xMessage.xMessageValue;\r
                                configASSERT( ( pxTimer->xTimerPeriodInTicks > 0 ) );\r
-                               prvInsertTimerInActiveList( pxTimer, ( xTimeNow + pxTimer->xTimerPeriodInTicks ), xTimeNow, xTimeNow );\r
+\r
+                               /* The new period does not really have a reference, and can be\r
+                               longer or shorter than the old one.  The command time is \r
+                               therefore set to the current time, and as the period cannot be\r
+                               zero the next expiry time can only be in the future, meaning\r
+                               (unlike for the xTimerStart() case above) there is no fail case\r
+                               that needs to be handled here. */\r
+                               ( void ) prvInsertTimerInActiveList( pxTimer, ( xTimeNow + pxTimer->xTimerPeriodInTicks ), xTimeNow, xTimeNow );\r
                                break;\r
 \r
                        case tmrCOMMAND_DELETE :\r
@@ -602,7 +614,7 @@ portBASE_TYPE xResult;
 \r
                /* Remove the timer from the list. */\r
                pxTimer = ( xTIMER * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList );\r
-               uxListRemove( &( pxTimer->xTimerListItem ) );\r
+               ( void ) uxListRemove( &( pxTimer->xTimerListItem ) );\r
 \r
                /* Execute its callback, then send a command to restart the timer if\r
                it is an auto-reload timer.  It cannot be restarted here as the lists\r