]> git.sur5r.net Git - freertos/commitdiff
Continue work on the timers module.
authorrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Wed, 9 Feb 2011 10:46:45 +0000 (10:46 +0000)
committerrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Wed, 9 Feb 2011 10:46:45 +0000 (10:46 +0000)
git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@1279 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

Source/timers.c

index e1d464db0e1a3a31af943d33d3303b0b75fc26c1..5666661d35a534c85bfa32f3dc74f01071fe64c0 100644 (file)
@@ -65,9 +65,6 @@ task.h is included from an application file. */
 \r
 #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE\r
 \r
-/* IDs for commands that can be sent/received on the timer queue. */\r
-#define tmrCOMMAND_START               0\r
-\r
 /* Misc definitions. */\r
 #define tmrNO_DELAY            ( portTickType ) 0U\r
 \r
@@ -86,9 +83,9 @@ typedef struct tmrTimerControl
 queue. */\r
 typedef struct tmrTimerQueueMessage\r
 {\r
-       portBASE_TYPE                   xMessageID;\r
-       portTickType                    xMessageValue;\r
-       xTIMER *                                pxTimer;\r
+       portBASE_TYPE                   xMessageID;                     /*<< The command being sent to the timer service task. */\r
+       portTickType                    xMessageValue;          /*<< An optional value used by a subset of commands, for example, when chaning the period of a timer. */\r
+       xTIMER *                                pxTimer;                        /*<< The timer to which the command will be applied. */\r
 } xTIMER_MESSAGE;\r
 \r
 \r
@@ -102,19 +99,6 @@ PRIVILEGED_DATA static xQueueHandle xTimerQueue = NULL;
 \r
 /*-----------------------------------------------------------*/\r
 \r
-/*\r
- * Called when a timer is about to be modified.  If the timer is already in the\r
- * list of active timers then it is removed prior to the modification.\r
- */\r
-static void prvRemoveTimerFromActiveList( xTIMER *pxTimer ) PRIVILEGED_FUNCTION;\r
-\r
-/*\r
- * Send pxMessage to xTimerQueue using a block time of xBlockTime if the \r
- * scheduler is running, or a block time of zero if the scheduler is not\r
- * running.\r
- */\r
-static portBASE_TYPE prvSendMessageToTimerServiceTask( xTIMER_MESSAGE *pxMessage, portTickType xBlockTime ) PRIVILEGED_FUNCTION;\r
-\r
 /* \r
  * Initialise the infrustructure used by the timer service task if it has not\r
  * been initialised already.\r
@@ -186,20 +170,28 @@ xTIMER *pxNewTimer;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-portBASE_TYPE xTimerStart( xTimerHandle xTimer, portTickType xBlockTime )\r
+portBASE_TYPE xTimerGenericCommand( xTimerHandle xTimer, portBASE_TYPE xCommandID, portTickType xOptionalValue, portTickType xBlockTime )\r
 {\r
 portBASE_TYPE xReturn = pdFAIL;\r
 xTIMER_MESSAGE xMessage;\r
 \r
-       /* A timer cannot be started unless it is created, and creating a timer\r
-       will have resulted in the timer queue also being created. */\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
        {\r
                /* Send a command to the timer service task to start the xTimer timer. */\r
-               xMessage.xMessageID = tmrCOMMAND_START;\r
+               xMessage.xMessageID = xCommandID;\r
+               xMessage.xMessageValue = xOptionalValue;\r
                xMessage.pxTimer = ( xTIMER * ) xTimer;\r
 \r
-               prvSendMessageToTimerServiceTask( &xMessage, xBlockTime );\r
+               if( xTaskGetSchedulerState() == taskSCHEDULER_RUNNING )\r
+               {\r
+                       xReturn = xQueueSendToBack( xTimerQueue, &xMessage, xBlockTime );\r
+               }\r
+               else\r
+               {\r
+                       xReturn = xQueueSendToBack( xTimerQueue, &xMessage, tmrNO_DELAY );\r
+               }\r
        }\r
 \r
        return xReturn;\r
@@ -288,19 +280,44 @@ xTIMER *pxTimer;
                pxTimer = xMessage.pxTimer;\r
 \r
                /* Is the timer already in the list of active timers? */\r
-               prvRemoveTimerFromActiveList( pxTimer );\r
+               if( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdFALSE )\r
+               {\r
+                       /* The timer is in the list, remove it. */\r
+                       vListRemove( &( pxTimer->xTimerListItem ) );\r
+               }\r
 \r
                switch( xMessage.xMessageID )\r
                {\r
-                       case tmrCOMMAND_START   :       /* Start or restart a timer. */\r
-                                                                               xTimeToExpire = xTaskGetTickCount() + pxTimer->xTimerPeriodInTicks;\r
-                                                                               listSET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ), xTimeToExpire );\r
-                                                                               listSET_LIST_ITEM_OWNER( &( pxTimer->xTimerListItem ), pxTimer );\r
-                                                                               vListInsert( &xActiveTimerList, &( pxTimer->xTimerListItem ) );\r
-                                                                               break;\r
-\r
-                       default                 :                       /* Don't expect to get here. */\r
-                                                                               break;\r
+                       case tmrCOMMAND_START : \r
+                               /* Start or restart a timer. */\r
+                               xTimeToExpire = xTaskGetTickCount() + pxTimer->xTimerPeriodInTicks;\r
+                               listSET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ), xTimeToExpire );\r
+                               listSET_LIST_ITEM_OWNER( &( pxTimer->xTimerListItem ), pxTimer );\r
+                               vListInsert( &xActiveTimerList, &( pxTimer->xTimerListItem ) );\r
+                               break;\r
+\r
+                       case tmrCOMMAND_STOP :  \r
+                               /* The timer has already been removed from the active list.\r
+                               There is nothing to do here. */\r
+                               break;\r
+\r
+                       case tmrCOMMAND_CHANGE_PERIOD :\r
+                               pxTimer->xTimerPeriodInTicks = xMessage.xMessageValue;\r
+                               xTimeToExpire = xTaskGetTickCount() + pxTimer->xTimerPeriodInTicks;\r
+                               listSET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ), xTimeToExpire );\r
+                               listSET_LIST_ITEM_OWNER( &( pxTimer->xTimerListItem ), pxTimer );\r
+                               vListInsert( &xActiveTimerList, &( pxTimer->xTimerListItem ) );\r
+                               break;\r
+\r
+                       case tmrCOMMAND_DELETE :\r
+                               /* The timer has already been removed from the active list,\r
+                               just free up the memory. */\r
+                               vPortFree( pxTimer );\r
+                               break;\r
+\r
+                       default :                       \r
+                               /* Don't expect to get here. */\r
+                               break;\r
                }\r
        }\r
 }\r
@@ -323,63 +340,27 @@ static void prvCheckForValidListAndQueue( void )
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-void *pvTimerGetTimerID( xTimerHandle xTimer )\r
+portBASE_TYPE xTimerIsTimerActive( xTimerHandle xTimer )\r
 {\r
+portBASE_TYPE xTimerIsInActiveList;\r
 xTIMER *pxTimer = ( xTIMER * ) xTimer;\r
 \r
-       return pxTimer->pvTimerID;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvRemoveTimerFromActiveList( xTIMER *pxTimer )\r
-{\r
-       /* Is the timer already in the list of active timers? */\r
-       if( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdFALSE )\r
-       {\r
-               /* The timer is in the list, remove it. */\r
-               vListRemove( &( pxTimer->xTimerListItem ) );\r
-       }\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static portBASE_TYPE prvSendMessageToTimerServiceTask( xTIMER_MESSAGE *pxMessage, portTickType xBlockTime )\r
-{\r
-portBASE_TYPE xReturn;\r
-\r
-       if( xTaskGetSchedulerState() == taskSCHEDULER_RUNNING )\r
-       {\r
-               xReturn = xQueueSendToBack( xTimerQueue, pxMessage, xBlockTime );\r
-       }\r
-       else\r
+       /* Is the timer in the list of active timers? */\r
+       taskENTER_CRITICAL();\r
        {\r
-               xReturn = xQueueSendToBack( xTimerQueue, pxMessage, tmrNO_DELAY );\r
+               xTimerIsInActiveList = listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) );\r
        }\r
+       taskEXIT_CRITICAL();\r
 \r
-       return xReturn;\r
+       return xTimerIsInActiveList;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-\r
-\r
-\r
-\r
-\r
-\r
-portBASE_TYPE xTimerIsTimerActive( xTimerHandle xTimer )\r
-{\r
-       return pdFALSE;\r
-}\r
-\r
-void vTimerStop( xTimerHandle xTimer )\r
-{\r
-}\r
-\r
-\r
-void vTimerChangePeriod( xTimerHandle xTimer )\r
+void *pvTimerGetTimerID( xTimerHandle xTimer )\r
 {\r
-}\r
+xTIMER *pxTimer = ( xTIMER * ) xTimer;\r
 \r
-void vTimerDelete( xTimerHandle xTimer )\r
-{\r
+       return pxTimer->pvTimerID;\r
 }\r
 /*-----------------------------------------------------------*/\r
+\r