]> git.sur5r.net Git - freertos/commitdiff
Update the method used to detect if a timer is active. Previously the timer was...
authorrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Wed, 24 Oct 2018 21:37:59 +0000 (21:37 +0000)
committerrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Wed, 24 Oct 2018 21:37:59 +0000 (21:37 +0000)
git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2589 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

FreeRTOS/Source/include/FreeRTOS.h
FreeRTOS/Source/timers.c

index 9329e0cff070c87b375f54f29a95adc6a19690cd..e599b013b141c34141821b7bec24e53047607845 100644 (file)
@@ -1142,16 +1142,12 @@ typedef struct xSTATIC_TIMER
        void                            *pvDummy1;\r
        StaticListItem_t        xDummy2;\r
        TickType_t                      xDummy3;\r
-       UBaseType_t                     uxDummy4;\r
        void                            *pvDummy5;\r
        TaskFunction_t          pvDummy6;\r
        #if( configUSE_TRACE_FACILITY == 1 )\r
                UBaseType_t             uxDummy7;\r
        #endif\r
-\r
-       #if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\r
-               uint8_t                 ucDummy8;\r
-       #endif\r
+       uint8_t                         ucDummy8;\r
 \r
 } StaticTimer_t;\r
 \r
index 4e24a297adbcf3871176f5a25f148e3af8eefb2f..a64565b4108a9fc8afe5ec5b90492c19f9623805 100644 (file)
@@ -64,22 +64,23 @@ defining trmTIMER_SERVICE_TASK_NAME in FreeRTOSConfig.h. */
        #define configTIMER_SERVICE_TASK_NAME "Tmr Svc"\r
 #endif\r
 \r
+/* Bit definitions used in the ucStatus member of a timer structure. */\r
+#define tmrSTATUS_IS_ACTIVE                                    ( ( uint8_t ) 0x01 )\r
+#define tmrSTATUS_IS_STATICALLY_ALLOCATED      ( ( uint8_t ) 0x02 )\r
+#define tmrSTATUS_IS_AUTORELOAD                                ( ( uint8_t ) 0x04 )\r
+\r
 /* The definition of the timers themselves. */\r
 typedef struct tmrTimerControl /* The old naming convention is used to prevent breaking kernel aware debuggers. */\r
 {\r
        const char                              *pcTimerName;           /*<< Text name.  This is not used by the kernel, it is included simply to make debugging easier. */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
        ListItem_t                              xTimerListItem;         /*<< Standard linked list item as used by all kernel features for event management. */\r
        TickType_t                              xTimerPeriodInTicks;/*<< How quickly and often the timer expires. */\r
-       UBaseType_t                             uxAutoReload;           /*<< Set to pdTRUE if the timer should be automatically restarted once expired.  Set to pdFALSE if the timer is, in effect, a one-shot timer. */\r
        void                                    *pvTimerID;                     /*<< An ID to identify the timer.  This allows the timer to be identified when the same callback is used for multiple timers. */\r
        TimerCallbackFunction_t pxCallbackFunction;     /*<< The function that will be called when the timer expires. */\r
        #if( configUSE_TRACE_FACILITY == 1 )\r
                UBaseType_t                     uxTimerNumber;          /*<< An ID assigned by trace tools such as FreeRTOS+Trace */\r
        #endif\r
-\r
-       #if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\r
-               uint8_t                         ucStaticallyAllocated; /*<< Set to pdTRUE if the timer was created statically so no attempt is made to free the memory again if the timer is later deleted. */\r
-       #endif\r
+       uint8_t                                 ucStatus;                       /*<< Holds bits to say if the timer was statically allocated or not, and if it is active or not. */\r
 } xTIMER;\r
 \r
 /* The old xTIMER name is maintained above then typedefed to the new Timer_t\r
@@ -127,7 +128,7 @@ which static variables must be declared volatile. */
 \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
-timer service task is allowed to access these lists. \r
+timer service task is allowed to access these lists.\r
 xActiveTimerList1 and xActiveTimerList2 could be at function scope but that\r
 breaks some kernel aware debuggers, and debuggers that reply on removing the\r
 static qualifier. */\r
@@ -290,16 +291,11 @@ BaseType_t xReturn = pdFAIL;
 \r
                if( pxNewTimer != NULL )\r
                {\r
+                       /* Status is thus far zero as the timer is not created statically\r
+                       and has not been started.  The autoreload bit may get set in\r
+                       prvInitialiseNewTimer. */\r
+                       pxNewTimer->ucStatus = 0x00;\r
                        prvInitialiseNewTimer( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction, pxNewTimer );\r
-\r
-                       #if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
-                       {\r
-                               /* Timers can be created statically or dynamically, so note this\r
-                               timer was created dynamically in case the timer is later\r
-                               deleted. */\r
-                               pxNewTimer->ucStaticallyAllocated = pdFALSE;\r
-                       }\r
-                       #endif /* configSUPPORT_STATIC_ALLOCATION */\r
                }\r
 \r
                return pxNewTimer;\r
@@ -336,15 +332,12 @@ BaseType_t xReturn = pdFAIL;
 \r
                if( pxNewTimer != NULL )\r
                {\r
-                       prvInitialiseNewTimer( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction, pxNewTimer );\r
+                       /* Timers can be created statically or dynamically so note this\r
+                       timer was created statically in case it is later deleted.  The\r
+                       autoreload bit may get set in prvInitialiseNewTimer(). */\r
+                       pxNewTimer->ucStatus = tmrSTATUS_IS_STATICALLY_ALLOCATED;\r
 \r
-                       #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )\r
-                       {\r
-                               /* Timers can be created statically or dynamically so note this\r
-                               timer was created statically in case it is later deleted. */\r
-                               pxNewTimer->ucStaticallyAllocated = pdTRUE;\r
-                       }\r
-                       #endif /* configSUPPORT_DYNAMIC_ALLOCATION */\r
+                       prvInitialiseNewTimer( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction, pxNewTimer );\r
                }\r
 \r
                return pxNewTimer;\r
@@ -373,10 +366,13 @@ static void prvInitialiseNewTimer(        const char * const pcTimerName,                 /*lint !e97
                parameters. */\r
                pxNewTimer->pcTimerName = pcTimerName;\r
                pxNewTimer->xTimerPeriodInTicks = xTimerPeriodInTicks;\r
-               pxNewTimer->uxAutoReload = uxAutoReload;\r
                pxNewTimer->pvTimerID = pvTimerID;\r
                pxNewTimer->pxCallbackFunction = pxCallbackFunction;\r
                vListInitialiseItem( &( pxNewTimer->xTimerListItem ) );\r
+               if( uxAutoReload != pdFALSE )\r
+               {\r
+                       pxNewTimer->ucStatus |= tmrSTATUS_IS_AUTORELOAD;\r
+               }\r
                traceTIMER_CREATE( pxNewTimer );\r
        }\r
 }\r
@@ -475,7 +471,7 @@ Timer_t * const pxTimer = ( Timer_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTi
 \r
        /* If the timer is an auto reload timer then calculate the next\r
        expiry time and re-insert the timer in the list of active timers. */\r
-       if( pxTimer->uxAutoReload == ( UBaseType_t ) pdTRUE )\r
+       if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0 )\r
        {\r
                /* The timer is inserted into a list using a time relative to anything\r
                other than the current time.  It will therefore be inserted into the\r
@@ -495,6 +491,7 @@ Timer_t * const pxTimer = ( Timer_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTi
        }\r
        else\r
        {\r
+               pxTimer->ucStatus &= ~tmrSTATUS_IS_ACTIVE;\r
                mtCOVERAGE_TEST_MARKER();\r
        }\r
 \r
@@ -756,6 +753,7 @@ TickType_t xTimeNow;
                            case tmrCOMMAND_RESET_FROM_ISR :\r
                                case tmrCOMMAND_START_DONT_TRACE :\r
                                        /* Start or restart a timer. */\r
+                                       pxTimer->ucStatus |= tmrSTATUS_IS_ACTIVE;\r
                                        if( prvInsertTimerInActiveList( pxTimer,  xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, xTimeNow, xMessage.u.xTimerParameters.xMessageValue ) != pdFALSE )\r
                                        {\r
                                                /* The timer expired before it was added to the active\r
@@ -763,7 +761,7 @@ TickType_t xTimeNow;
                                                pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer );\r
                                                traceTIMER_EXPIRED( pxTimer );\r
 \r
-                                               if( pxTimer->uxAutoReload == ( UBaseType_t ) pdTRUE )\r
+                                               if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0 )\r
                                                {\r
                                                        xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START_DONT_TRACE, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, NULL, tmrNO_DELAY );\r
                                                        configASSERT( xResult );\r
@@ -782,12 +780,13 @@ TickType_t xTimeNow;
 \r
                                case tmrCOMMAND_STOP :\r
                                case tmrCOMMAND_STOP_FROM_ISR :\r
-                                       /* The timer has already been removed from the active list.\r
-                                       There is nothing to do here. */\r
+                                       /* The timer has already been removed from the active list. */\r
+                                       pxTimer->ucStatus &= ~tmrSTATUS_IS_ACTIVE;\r
                                        break;\r
 \r
                                case tmrCOMMAND_CHANGE_PERIOD :\r
                                case tmrCOMMAND_CHANGE_PERIOD_FROM_ISR :\r
+                                       pxTimer->ucStatus |= tmrSTATUS_IS_ACTIVE;\r
                                        pxTimer->xTimerPeriodInTicks = xMessage.u.xTimerParameters.xMessageValue;\r
                                        configASSERT( ( pxTimer->xTimerPeriodInTicks > 0 ) );\r
 \r
@@ -804,27 +803,14 @@ TickType_t xTimeNow;
                                        /* The timer has already been removed from the active list,\r
                                        just free up the memory if the memory was dynamically\r
                                        allocated. */\r
-                                       #if( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) )\r
+                                       if( ( pxTimer->ucStatus & tmrSTATUS_IS_STATICALLY_ALLOCATED ) == ( uint8_t ) 0 )\r
                                        {\r
-                                               /* The timer can only have been allocated dynamically -\r
-                                               free it again. */\r
                                                vPortFree( pxTimer );\r
                                        }\r
-                                       #elif( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )\r
+                                       else\r
                                        {\r
-                                               /* The timer could have been allocated statically or\r
-                                               dynamically, so check before attempting to free the\r
-                                               memory. */\r
-                                               if( pxTimer->ucStaticallyAllocated == ( uint8_t ) pdFALSE )\r
-                                               {\r
-                                                       vPortFree( pxTimer );\r
-                                               }\r
-                                               else\r
-                                               {\r
-                                                       mtCOVERAGE_TEST_MARKER();\r
-                                               }\r
+                                               pxTimer->ucStatus &= ~tmrSTATUS_IS_ACTIVE;\r
                                        }\r
-                                       #endif /* configSUPPORT_DYNAMIC_ALLOCATION */\r
                                        break;\r
 \r
                                default :\r
@@ -861,7 +847,7 @@ BaseType_t xResult;
                have not yet been switched. */\r
                pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer );\r
 \r
-               if( pxTimer->uxAutoReload == ( UBaseType_t ) pdTRUE )\r
+               if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0 )\r
                {\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
@@ -948,7 +934,7 @@ static void prvCheckForValidListAndQueue( void )
 \r
 BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer )\r
 {\r
-BaseType_t xTimerIsInActiveList;\r
+BaseType_t xReturn;\r
 Timer_t *pxTimer = xTimer;\r
 \r
        configASSERT( xTimer );\r
@@ -956,21 +942,18 @@ Timer_t *pxTimer = xTimer;
        /* Is the timer in the list of active timers? */\r
        taskENTER_CRITICAL();\r
        {\r
-               /* Checking to see if it is in the NULL list in effect checks to see if\r
-               it is referenced from either the current or the overflow timer lists in\r
-               one go, but the logic has to be reversed, hence the '!'. */\r
-               if( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdTRUE )\r
+               if( ( pxTimer->ucStatus & tmrSTATUS_IS_ACTIVE ) == 0 )\r
                {\r
-                       xTimerIsInActiveList = pdFALSE;\r
+                       xReturn = pdFALSE;\r
                }\r
                else\r
                {\r
-                       xTimerIsInActiveList = pdTRUE;\r
+                       xReturn = pdTRUE;\r
                }\r
        }\r
        taskEXIT_CRITICAL();\r
 \r
-       return xTimerIsInActiveList;\r
+       return xReturn;\r
 } /*lint !e818 Can't be pointer to const due to the typedef. */\r
 /*-----------------------------------------------------------*/\r
 \r