]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/timers.c
TimerHandle_t is now type safe instead of void *.
[freertos] / FreeRTOS / Source / timers.c
index 10f08a18b7a5ccf4f261e928a18a1b4159591241..97e8786839e3c8b271380f8a2434df9ab11df543 100644 (file)
@@ -42,11 +42,11 @@ task.h is included from an application file. */
        #error configUSE_TIMERS must be set to 1 to make the xTimerPendFunctionCall() function available.\r
 #endif\r
 \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
+/* Lint e9021, e961 and e750 are suppressed as a MISRA exception justified\r
+because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined\r
+for the header files above, but not in this file, in order to generate the\r
+correct privileged Vs unprivileged linkage and placement. */\r
+#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e9021 !e961 !e750. */\r
 \r
 \r
 /* This entire source file will be skipped if the application is not configured\r
@@ -65,7 +65,7 @@ defining trmTIMER_SERVICE_TASK_NAME in FreeRTOSConfig.h. */
 #endif\r
 \r
 /* The definition of the timers themselves. */\r
-typedef struct tmrTimerControl\r
+typedef struct TimerDef_t\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
@@ -128,8 +128,6 @@ which static variables must be declared volatile. */
 /* 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
-PRIVILEGED_DATA static List_t xActiveTimerList1;\r
-PRIVILEGED_DATA static List_t xActiveTimerList2;\r
 PRIVILEGED_DATA static List_t *pxCurrentTimerList;\r
 PRIVILEGED_DATA static List_t *pxOverflowTimerList;\r
 \r
@@ -283,7 +281,7 @@ BaseType_t xReturn = pdFAIL;
        {\r
        Timer_t *pxNewTimer;\r
 \r
-               pxNewTimer = ( Timer_t * ) pvPortMalloc( sizeof( Timer_t ) );\r
+               pxNewTimer = ( Timer_t * ) pvPortMalloc( sizeof( Timer_t ) ); /*lint !e9087 !e9079 All values returned by pvPortMalloc() have at least the alignment required by the MCU's stack, and the first member of Timer_t is always a pointer to the timer's mame. */\r
 \r
                if( pxNewTimer != NULL )\r
                {\r
@@ -323,12 +321,13 @@ BaseType_t xReturn = pdFAIL;
                        structure. */\r
                        volatile size_t xSize = sizeof( StaticTimer_t );\r
                        configASSERT( xSize == sizeof( Timer_t ) );\r
+                       ( void ) xSize; /* Keeps lint quiet when configASSERT() is not defined. */\r
                }\r
                #endif /* configASSERT_DEFINED */\r
 \r
                /* A pointer to a StaticTimer_t structure MUST be provided, use it. */\r
                configASSERT( pxTimerBuffer );\r
-               pxNewTimer = ( Timer_t * ) pxTimerBuffer; /*lint !e740 Unusual cast is ok as the structures are designed to have the same alignment, and the size is checked by an assert. */\r
+               pxNewTimer = ( Timer_t * ) pxTimerBuffer; /*lint !e740 !e9087 StaticTimer_t is a pointer to a Timer_t, so guaranteed to be aligned and sized correctly (checked by an assert()), so this is safe. */\r
 \r
                if( pxNewTimer != NULL )\r
                {\r
@@ -392,7 +391,7 @@ DaemonTaskMessage_t xMessage;
                /* Send a command to the timer service task to start the xTimer timer. */\r
                xMessage.xMessageID = xCommandID;\r
                xMessage.u.xTimerParameters.xMessageValue = xOptionalValue;\r
-               xMessage.u.xTimerParameters.pxTimer = ( Timer_t * ) xTimer;\r
+               xMessage.u.xTimerParameters.pxTimer = xTimer;\r
 \r
                if( xCommandID < tmrFIRST_FROM_ISR_COMMAND )\r
                {\r
@@ -432,7 +431,7 @@ TaskHandle_t xTimerGetTimerDaemonTaskHandle( void )
 \r
 TickType_t xTimerGetPeriod( TimerHandle_t xTimer )\r
 {\r
-Timer_t *pxTimer = ( Timer_t * ) xTimer;\r
+Timer_t *pxTimer = xTimer;\r
 \r
        configASSERT( xTimer );\r
        return pxTimer->xTimerPeriodInTicks;\r
@@ -441,7 +440,7 @@ Timer_t *pxTimer = ( Timer_t * ) xTimer;
 \r
 TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer )\r
 {\r
-Timer_t * pxTimer = ( Timer_t * ) xTimer;\r
+Timer_t * pxTimer =  xTimer;\r
 TickType_t xReturn;\r
 \r
        configASSERT( xTimer );\r
@@ -452,7 +451,7 @@ TickType_t xReturn;
 \r
 const char * pcTimerGetName( TimerHandle_t xTimer ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
 {\r
-Timer_t *pxTimer = ( Timer_t * ) xTimer;\r
+Timer_t *pxTimer = xTimer;\r
 \r
        configASSERT( xTimer );\r
        return pxTimer->pcTimerName;\r
@@ -462,7 +461,7 @@ Timer_t *pxTimer = ( Timer_t * ) xTimer;
 static void prvProcessExpiredTimer( const TickType_t xNextExpireTime, const TickType_t xTimeNow )\r
 {\r
 BaseType_t xResult;\r
-Timer_t * const pxTimer = ( Timer_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList );\r
+Timer_t * const pxTimer = ( Timer_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList ); /*lint !e9087 !e9079 void * is used as this macro is used with tasks and co-routines too.  Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */\r
 \r
        /* Remove the timer from the list of active timers.  A check has already\r
        been performed to ensure the list is not empty. */\r
@@ -848,7 +847,7 @@ BaseType_t xResult;
                xNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxCurrentTimerList );\r
 \r
                /* Remove the timer from the list. */\r
-               pxTimer = ( Timer_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList );\r
+               pxTimer = ( Timer_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList ); /*lint !e9087 !e9079 void * is used as this macro is used with tasks and co-routines too.  Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */\r
                ( void ) uxListRemove( &( pxTimer->xTimerListItem ) );\r
                traceTIMER_EXPIRED( pxTimer );\r
 \r
@@ -893,6 +892,9 @@ BaseType_t xResult;
 \r
 static void prvCheckForValidListAndQueue( void )\r
 {\r
+PRIVILEGED_DATA static List_t xActiveTimerList1;\r
+PRIVILEGED_DATA static List_t xActiveTimerList2;\r
+\r
        /* Check that the list from which active timers are referenced, and the\r
        queue used to communicate with the timer service, have been\r
        initialised. */\r
@@ -945,7 +947,7 @@ static void prvCheckForValidListAndQueue( void )
 BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer )\r
 {\r
 BaseType_t xTimerIsInActiveList;\r
-Timer_t *pxTimer = ( Timer_t * ) xTimer;\r
+Timer_t *pxTimer = xTimer;\r
 \r
        configASSERT( xTimer );\r
 \r
@@ -955,7 +957,14 @@ Timer_t *pxTimer = ( Timer_t * ) xTimer;
                /* 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
-               xTimerIsInActiveList = ( BaseType_t ) !( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) ); /*lint !e961. Cast is only redundant when NULL is passed into the macro. */\r
+               if( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdTRUE )\r
+               {\r
+                       xTimerIsInActiveList = pdFALSE;\r
+               }\r
+               else\r
+               {\r
+                       xTimerIsInActiveList = pdTRUE;\r
+               }\r
        }\r
        taskEXIT_CRITICAL();\r
 \r
@@ -965,7 +974,7 @@ Timer_t *pxTimer = ( Timer_t * ) xTimer;
 \r
 void *pvTimerGetTimerID( const TimerHandle_t xTimer )\r
 {\r
-Timer_t * const pxTimer = ( Timer_t * ) xTimer;\r
+Timer_t * const pxTimer = xTimer;\r
 void *pvReturn;\r
 \r
        configASSERT( xTimer );\r
@@ -982,7 +991,7 @@ void *pvReturn;
 \r
 void vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID )\r
 {\r
-Timer_t * const pxTimer = ( Timer_t * ) xTimer;\r
+Timer_t * const pxTimer = xTimer;\r
 \r
        configASSERT( xTimer );\r
 \r