]> git.sur5r.net Git - freertos/commitdiff
Finilise timers testing.
authorrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Sun, 27 Feb 2011 13:08:44 +0000 (13:08 +0000)
committerrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Sun, 27 Feb 2011 13:08:44 +0000 (13:08 +0000)
git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@1306 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

Source/timers.c

index 5b29f55848ca7bc1e51b314257c6a23c02df19bd..fb79603a62427a2e4f7e2c358a9060e414658ff2 100644 (file)
@@ -135,7 +135,7 @@ static void prvProcessExpiredTimer( portTickType xNextExpireTime, portTickType x
  * The tick count has overflowed.  Switch the timer lists after ensuring the\r
  * current timer list does not still reference some timers.\r
  */\r
-static void prvSwitchTimerLists( portTickType xLastTime ) PRIVILEGED_FUNCTION;\r
+static void prvSwitchTimerLists( portTickType xLastTime, portTickType xTimeNow ) PRIVILEGED_FUNCTION;\r
 \r
 /*\r
  * Obtain the current tick count, setting *pxTimerListsWereSwitched to pdTRUE\r
@@ -391,7 +391,7 @@ static portTickType xLastTime = ( portTickType ) 0U;
        \r
        if( xTimeNow < xLastTime )\r
        {\r
-               prvSwitchTimerLists( xLastTime );\r
+               prvSwitchTimerLists( xLastTime, xTimeNow );\r
                *pxTimerListsWereSwitched = pdTRUE;\r
        }\r
        else\r
@@ -517,9 +517,9 @@ portTickType xTimeNow;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static void prvSwitchTimerLists( portTickType xLastTime )\r
+static void prvSwitchTimerLists( portTickType xLastTime, portTickType xTimeNow )\r
 {\r
-portTickType xNextExpireTime;\r
+portTickType xNextExpireTime, xReloadTime;\r
 xList *pxTemp;\r
 xTIMER *pxTimer;\r
 portBASE_TYPE xResult;\r
@@ -534,7 +534,6 @@ portBASE_TYPE xResult;
        while( listLIST_IS_EMPTY( pxCurrentTimerList ) == pdFALSE )\r
        {\r
                xNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxCurrentTimerList );\r
-               configASSERT( ( xNextExpireTime >= xLastTime ) );\r
 \r
                /* Remove the timer from the list. */\r
                pxTimer = ( xTIMER * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList );\r
@@ -544,11 +543,28 @@ portBASE_TYPE xResult;
                it is an auto-reload timer.  It cannot be restarted here as the lists\r
                have not yet been switched. */\r
                pxTimer->pxCallbackFunction( ( xTimerHandle ) pxTimer );\r
+\r
                if( pxTimer->uxAutoReload == pdTRUE )\r
                {\r
-                       xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START, xNextExpireTime, NULL, tmrNO_DELAY );\r
-                       configASSERT( xResult );\r
-                       ( void ) xResult;\r
+                       /* Calculate the reload value, and if the reload value results in\r
+                       the timer going into the same timer list then it has already expired\r
+                       and the timer should be re-inserted into the current list so it is\r
+                       processed again within this loop.  Otherwise a command should be sent\r
+                       to restart the timer to ensure it is only inserted into a list after\r
+                       the lists have been swapped. */\r
+                       xReloadTime = ( xNextExpireTime + pxTimer->xTimerPeriodInTicks );\r
+                       if( xReloadTime > xNextExpireTime )\r
+                       {\r
+                               listSET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ), xReloadTime );\r
+                               listSET_LIST_ITEM_OWNER( &( pxTimer->xTimerListItem ), pxTimer );\r
+                               vListInsert( pxCurrentTimerList, &( pxTimer->xTimerListItem ) );\r
+                       }\r
+                       else\r
+                       {\r
+                               xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START, xNextExpireTime, NULL, tmrNO_DELAY );\r
+                               configASSERT( xResult );\r
+                               ( void ) xResult;\r
+                       }\r
                }\r
        }\r
 \r