***************************************************************************\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
+ 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
+\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
\r
#ifndef LIST_H\r
#define LIST_H\r
\r
+/*\r
+ * The list structure members are modified from within interrupts, and therefore\r
+ * by rights should be declared volatile. However, they are only modified in a\r
+ * functionally atomic way (within critical sections of with the scheduler\r
+ * suspended) and are either passed by reference into a function or indexed via\r
+ * a volatile variable. Therefore, in all use cases tested so far, the volatile\r
+ * qualifier can be omitted in order to provide a moderate performance\r
+ * improvement without adversely affecting functional behaviour. The assembly\r
+ * instructions generated by the IAR, ARM and GCC compilers when the respective\r
+ * compiler's options were set for maximum optimisation has been inspected and\r
+ * deemed to be as intended. That said, as compiler technology advances, and\r
+ * especially if aggressive cross module optimisation is used (a use case that\r
+ * has not been exercised to any great extend) then it is feasible that the\r
+ * volatile qualifier will be needed for correct optimisation. It is expected\r
+ * that a compiler removing essential code because, without the volatile\r
+ * qualifier on the list structure members and with aggressive cross module\r
+ * optimisation, the compiler deemed the code unnecessary will result in\r
+ * complete and obvious failure of the scheduler. If this is ever experienced\r
+ * then the volatile qualifier can be inserted in the relevant places within the\r
+ * list structures by simply defining configLIST_VOLATILE to volatile in\r
+ * FreeRTOSConfig.h (as per the example at the bottom of this comment block). \r
+ * If configLIST_VOLATILE is not defined then the preprocessor directives below \r
+ * will simply #define configLIST_VOLATILE away completely.\r
+ *\r
+ * To use volatile list structure members then add the following line to\r
+ * FreeRTOSConfig.h (without the quotes):\r
+ * "#define configLIST_VOLATILE volatile"\r
+ */\r
+#ifndef configLIST_VOLATILE\r
+ #define configLIST_VOLATILE\r
+#endif /* configSUPPORT_CROSS_MODULE_OPTIMISATION */\r
+\r
#ifdef __cplusplus\r
extern "C" {\r
#endif\r
*/\r
struct xLIST_ITEM\r
{\r
- portTickType xItemValue; /*< The value being listed. In most cases this is used to sort the list in descending order. */\r
- volatile struct xLIST_ITEM * pxNext; /*< Pointer to the next xListItem in the list. */\r
- volatile struct xLIST_ITEM * pxPrevious;/*< Pointer to the previous xListItem in the list. */\r
- void * pvOwner; /*< Pointer to the object (normally a TCB) that contains the list item. There is therefore a two way link between the object containing the list item and the list item itself. */\r
- void * pvContainer; /*< Pointer to the list in which this list item is placed (if any). */\r
+ configLIST_VOLATILE portTickType xItemValue; /*< The value being listed. In most cases this is used to sort the list in descending order. */\r
+ struct xLIST_ITEM * configLIST_VOLATILE pxNext; /*< Pointer to the next xListItem in the list. */\r
+ struct xLIST_ITEM * configLIST_VOLATILE pxPrevious;/*< Pointer to the previous xListItem in the list. */\r
+ void * pvOwner; /*< Pointer to the object (normally a TCB) that contains the list item. There is therefore a two way link between the object containing the list item and the list item itself. */\r
+ void * configLIST_VOLATILE pvContainer; /*< Pointer to the list in which this list item is placed (if any). */\r
};\r
-typedef struct xLIST_ITEM xListItem; /* For some reason lint wants this as two separate definitions. */\r
+typedef struct xLIST_ITEM xListItem; /* For some reason lint wants this as two separate definitions. */\r
\r
struct xMINI_LIST_ITEM\r
{\r
- portTickType xItemValue;\r
- volatile struct xLIST_ITEM *pxNext;\r
- volatile struct xLIST_ITEM *pxPrevious;\r
+ configLIST_VOLATILE portTickType xItemValue;\r
+ struct xLIST_ITEM * configLIST_VOLATILE pxNext;\r
+ struct xLIST_ITEM * configLIST_VOLATILE pxPrevious;\r
};\r
typedef struct xMINI_LIST_ITEM xMiniListItem;\r
\r
*/\r
typedef struct xLIST\r
{\r
- volatile unsigned portBASE_TYPE uxNumberOfItems;\r
- volatile xListItem * pxIndex; /*< Used to walk through the list. Points to the last item returned by a call to pvListGetOwnerOfNextEntry (). */\r
- volatile xMiniListItem xListEnd; /*< List item that contains the maximum possible item value meaning it is always at the end of the list and is therefore used as a marker. */\r
+ configLIST_VOLATILE unsigned portBASE_TYPE uxNumberOfItems;\r
+ xListItem * configLIST_VOLATILE pxIndex; /*< Used to walk through the list. Points to the last item returned by a call to pvListGetOwnerOfNextEntry (). */\r
+ xMiniListItem xListEnd; /*< List item that contains the maximum possible item value meaning it is always at the end of the list and is therefore used as a marker. */\r
} xList;\r
\r
/*\r
* \page vListInitialise vListInitialise\r
* \ingroup LinkedList\r
*/\r
-void vListInitialise( xList *pxList );\r
+void vListInitialise( xList * const pxList );\r
\r
/*\r
* Must be called before a list item is used. This sets the list container to\r
* \page vListInitialiseItem vListInitialiseItem\r
* \ingroup LinkedList\r
*/\r
-void vListInitialiseItem( xListItem *pxItem );\r
+void vListInitialiseItem( xListItem * const pxItem );\r
\r
/*\r
* Insert a list item into a list. The item will be inserted into the list in\r
* \page vListInsert vListInsert\r
* \ingroup LinkedList\r
*/\r
-void vListInsert( xList *pxList, xListItem *pxNewListItem );\r
+void vListInsert( xList * const pxList, xListItem * const pxNewListItem );\r
\r
/*\r
* Insert a list item into a list. The item will be inserted in a position\r
* \page vListInsertEnd vListInsertEnd\r
* \ingroup LinkedList\r
*/\r
-void vListInsertEnd( xList *pxList, xListItem *pxNewListItem );\r
+void vListInsertEnd( xList * const pxList, xListItem * const pxNewListItem );\r
\r
/*\r
* Remove an item from a list. The list item has a pointer to the list that\r
*\r
* @param uxListRemove The item to be removed. The item will remove itself from\r
* the list pointed to by it's pxContainer parameter.\r
- * \r
+ *\r
* @return The number of items that remain in the list after the list item has\r
* been removed.\r
*\r
* \page uxListRemove uxListRemove\r
* \ingroup LinkedList\r
*/\r
-unsigned portBASE_TYPE uxListRemove( xListItem *pxItemToRemove );\r
+unsigned portBASE_TYPE uxListRemove( xListItem * const pxItemToRemove );\r
\r
#ifdef __cplusplus\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
+ 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
+\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
\r
* PUBLIC LIST API documented in list.h\r
*----------------------------------------------------------*/\r
\r
-void vListInitialise( xList *pxList )\r
+void vListInitialise( xList * const pxList )\r
{\r
/* The list structure contains a list item which is used to mark the\r
end of the list. To initialise the list the list end is inserted\r
}\r
/*-----------------------------------------------------------*/\r
\r
-void vListInitialiseItem( xListItem *pxItem )\r
+void vListInitialiseItem( xListItem * const pxItem )\r
{\r
/* Make sure the list item is not recorded as being on a list. */\r
pxItem->pvContainer = NULL;\r
}\r
/*-----------------------------------------------------------*/\r
\r
-void vListInsertEnd( xList *pxList, xListItem *pxNewListItem )\r
+void vListInsertEnd( xList * const pxList, xListItem * const pxNewListItem )\r
{\r
-volatile xListItem * pxIndex;\r
+xListItem * pxIndex;\r
\r
/* Insert a new list item into pxList, but rather than sort the list,\r
makes the new list item the last item to be removed by a call to\r
\r
pxNewListItem->pxNext = pxIndex;\r
pxNewListItem->pxPrevious = pxIndex->pxPrevious;\r
- pxIndex->pxPrevious->pxNext = ( volatile xListItem * ) pxNewListItem;\r
- pxIndex->pxPrevious = ( volatile xListItem * ) pxNewListItem; \r
+ pxIndex->pxPrevious->pxNext = pxNewListItem;\r
+ pxIndex->pxPrevious = pxNewListItem;\r
\r
/* Remember which list the item is in. */\r
pxNewListItem->pvContainer = ( void * ) pxList;\r
}\r
/*-----------------------------------------------------------*/\r
\r
-void vListInsert( xList *pxList, xListItem *pxNewListItem )\r
+void vListInsert( xList * const pxList, xListItem * const pxNewListItem )\r
{\r
-volatile xListItem *pxIterator;\r
+xListItem *pxIterator;\r
portTickType xValueOfInsertion;\r
\r
/* Insert the new list item into the list, sorted in ulListItem order. */\r
}\r
\r
pxNewListItem->pxNext = pxIterator->pxNext;\r
- pxNewListItem->pxNext->pxPrevious = ( volatile xListItem * ) pxNewListItem;\r
+ pxNewListItem->pxNext->pxPrevious = pxNewListItem;\r
pxNewListItem->pxPrevious = pxIterator;\r
- pxIterator->pxNext = ( volatile xListItem * ) pxNewListItem;\r
+ pxIterator->pxNext = pxNewListItem;\r
\r
/* Remember which list the item is in. This allows fast removal of the\r
item later. */\r
}\r
/*-----------------------------------------------------------*/\r
\r
-unsigned portBASE_TYPE uxListRemove( xListItem *pxItemToRemove )\r
+unsigned portBASE_TYPE uxListRemove( xListItem * const pxItemToRemove )\r
{\r
xList * pxList;\r
\r
\r
portBASE_TYPE xQueueGenericReset( xQueueHandle xQueue, portBASE_TYPE xNewQueue )\r
{\r
-xQUEUE *pxQueue;\r
+xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
\r
- pxQueue = ( xQUEUE * ) xQueue;\r
configASSERT( pxQueue );\r
\r
taskENTER_CRITICAL();\r
portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle xMutex )\r
{\r
portBASE_TYPE xReturn;\r
- xQUEUE *pxMutex;\r
+ xQUEUE * const pxMutex = ( xQUEUE * ) xMutex;\r
\r
- pxMutex = ( xQUEUE * ) xMutex;\r
configASSERT( pxMutex );\r
\r
/* If this is the task that holds the mutex then pxMutexHolder will not\r
portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime )\r
{\r
portBASE_TYPE xReturn;\r
- xQUEUE *pxMutex;\r
+ xQUEUE * const pxMutex = ( xQUEUE * ) xMutex;\r
\r
- pxMutex = ( xQUEUE * ) xMutex;\r
configASSERT( pxMutex );\r
\r
/* Comments regarding mutual exclusion as per those within\r
{\r
signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
xTimeOutType xTimeOut;\r
-xQUEUE *pxQueue;\r
+xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
\r
- pxQueue = ( xQUEUE * ) xQueue;\r
configASSERT( pxQueue );\r
configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );\r
{\r
signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
xTimeOutType xTimeOut;\r
- xQUEUE *pxQueue;\r
+ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
\r
- pxQueue = ( xQUEUE * ) xQueue;\r
configASSERT( pxQueue );\r
configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
\r
signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
xTimeOutType xTimeOut;\r
signed char *pcOriginalReadPosition;\r
- xQUEUE *pxQueue;\r
+ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
\r
- pxQueue = ( xQUEUE * ) xQueue;\r
configASSERT( pxQueue );\r
configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
\r
{\r
traceQUEUE_RECEIVE( pxQueue );\r
\r
- /* We are actually removing data. */\r
+ /* Data is actually being removed (not just peeked). */\r
--( pxQueue->uxMessagesWaiting );\r
\r
#if ( configUSE_MUTEXES == 1 )\r
{\r
signed portBASE_TYPE xReturn;\r
unsigned portBASE_TYPE uxSavedInterruptStatus;\r
-xQUEUE *pxQueue;\r
+xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
\r
- pxQueue = ( xQUEUE * ) xQueue;\r
configASSERT( pxQueue );\r
configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );\r
signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
xTimeOutType xTimeOut;\r
signed char *pcOriginalReadPosition;\r
-xQUEUE *pxQueue;\r
+xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
\r
- pxQueue = ( xQUEUE * ) xQueue;\r
configASSERT( pxQueue );\r
configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
\r
{\r
signed portBASE_TYPE xReturn;\r
unsigned portBASE_TYPE uxSavedInterruptStatus;\r
-xQUEUE *pxQueue;\r
+xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
\r
- pxQueue = ( xQUEUE * ) xQueue;\r
configASSERT( pxQueue );\r
configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
\r
signed portBASE_TYPE xReturn;\r
unsigned portBASE_TYPE uxSavedInterruptStatus;\r
signed char *pcOriginalReadPosition;\r
-xQUEUE *pxQueue;\r
+xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
\r
- pxQueue = ( xQUEUE * ) xQueue;\r
configASSERT( pxQueue );\r
configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
\r
\r
void vQueueDelete( xQueueHandle xQueue )\r
{\r
-xQUEUE *pxQueue;\r
+xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
\r
- pxQueue = ( xQUEUE * ) xQueue;\r
configASSERT( pxQueue );\r
\r
traceQUEUE_DELETE( pxQueue );\r
signed portBASE_TYPE xQueueCRSend( xQueueHandle xQueue, const void *pvItemToQueue, portTickType xTicksToWait )\r
{\r
signed portBASE_TYPE xReturn;\r
- xQUEUE *pxQueue;\r
-\r
- pxQueue = ( xQUEUE * ) xQueue;\r
+ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
\r
/* If the queue is already full we may have to block. A critical section\r
is required to prevent an interrupt removing something from the queue\r
signed portBASE_TYPE xQueueCRReceive( xQueueHandle xQueue, void *pvBuffer, portTickType xTicksToWait )\r
{\r
signed portBASE_TYPE xReturn;\r
- xQUEUE *pxQueue;\r
-\r
- pxQueue = ( xQUEUE * ) xQueue;\r
+ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
\r
/* If the queue is already empty we may have to block. A critical section\r
is required to prevent an interrupt adding something to the queue\r
\r
signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle xQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken )\r
{\r
- xQUEUE *pxQueue;\r
-\r
- pxQueue = ( xQUEUE * ) xQueue;\r
+ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
\r
/* Cannot block within an ISR so if there is no space on the queue then\r
exit without doing anything. */\r
signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle xQueue, void *pvBuffer, signed portBASE_TYPE *pxCoRoutineWoken )\r
{\r
signed portBASE_TYPE xReturn;\r
- xQUEUE * pxQueue;\r
-\r
- pxQueue = ( xQUEUE * ) xQueue;\r
+ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
\r
/* We cannot block from an ISR, so check there is data available. If\r
not then just leave without doing anything. */\r
\r
void vQueueWaitForMessageRestricted( xQueueHandle xQueue, portTickType xTicksToWait )\r
{\r
- xQUEUE *pxQueue;\r
-\r
- pxQueue = ( xQUEUE * ) xQueue;\r
+ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
\r
/* This function should not be called by application code hence the\r
'Restricted' in its name. It is not part of the public API. It is\r
portBASE_TYPE xQueueRemoveFromSet( xQueueSetMemberHandle xQueueOrSemaphore, xQueueSetHandle xQueueSet )\r
{\r
portBASE_TYPE xReturn;\r
- xQUEUE *pxQueueOrSemaphore;\r
-\r
- pxQueueOrSemaphore = ( xQUEUE * ) xQueueOrSemaphore;\r
+ xQUEUE * const pxQueueOrSemaphore = ( xQUEUE * ) xQueueOrSemaphore;\r
\r
if( pxQueueOrSemaphore->pxQueueSetContainer != xQueueSet )\r
{\r
/* File private variables. --------------------------------*/\r
PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxCurrentNumberOfTasks = ( unsigned portBASE_TYPE ) 0U;\r
PRIVILEGED_DATA static volatile portTickType xTickCount = ( portTickType ) 0U;\r
-PRIVILEGED_DATA static unsigned portBASE_TYPE uxTopUsedPriority = tskIDLE_PRIORITY;\r
PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxTopReadyPriority = tskIDLE_PRIORITY;\r
PRIVILEGED_DATA static volatile signed portBASE_TYPE xSchedulerRunning = pdFALSE;\r
PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxSchedulerSuspended = ( unsigned portBASE_TYPE ) pdFALSE;\r
PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxPendedTicks = ( unsigned portBASE_TYPE ) 0U;\r
-PRIVILEGED_DATA static volatile portBASE_TYPE xYieldPending = ( portBASE_TYPE ) pdFALSE;\r
+PRIVILEGED_DATA static volatile portBASE_TYPE xYieldPending = ( portBASE_TYPE ) pdFALSE;\r
PRIVILEGED_DATA static volatile portBASE_TYPE xNumOfOverflows = ( portBASE_TYPE ) 0;\r
PRIVILEGED_DATA static unsigned portBASE_TYPE uxTaskNumber = ( unsigned portBASE_TYPE ) 0U;\r
PRIVILEGED_DATA static volatile portTickType xNextTaskUnblockTime = ( portTickType ) portMAX_DELAY;\r
#if ( configGENERATE_RUN_TIME_STATS == 1 )\r
\r
PRIVILEGED_DATA static unsigned long ulTaskSwitchedInTime = 0UL; /*< Holds the value of a timer/counter the last time a task was switched in. */\r
- PRIVILEGED_DATA static unsigned long ulTotalRunTime = 0UL; /*< Holds the total amount of execution time as defined by the run time counter clock. */\r
+ PRIVILEGED_DATA static unsigned long ulTotalRunTime = 0UL; /*< Holds the total amount of execution time as defined by the run time counter clock. */\r
\r
#endif\r
\r
}\r
}\r
\r
- /* Remember the top priority to make context switching faster. Use\r
- the priority in pxNewTCB as this has been capped to a valid value. */\r
- if( pxNewTCB->uxPriority > uxTopUsedPriority )\r
- {\r
- uxTopUsedPriority = pxNewTCB->uxPriority;\r
- }\r
-\r
uxTaskNumber++;\r
\r
#if ( configUSE_TRACE_FACILITY == 1 )\r
}\r
\r
/* Is the task waiting on an event also? */\r
- if( pxTCB->xEventListItem.pvContainer != NULL )\r
+ if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )\r
{\r
uxListRemove( &( pxTCB->xEventListItem ) );\r
}\r
\r
vTaskSuspendAll();\r
{\r
+ /* Minor optimisation. The tick count cannot change in this\r
+ block. */\r
+ const portTickType xConstTickCount = xTickCount;\r
+\r
/* Generate the tick time at which the task wants to wake. */\r
xTimeToWake = *pxPreviousWakeTime + xTimeIncrement;\r
\r
- if( xTickCount < *pxPreviousWakeTime )\r
+ if( xConstTickCount < *pxPreviousWakeTime )\r
{\r
/* The tick count has overflowed since this function was\r
lasted called. In this case the only time we should ever\r
actually delay is if the wake time has also overflowed,\r
and the wake time is greater than the tick time. When this\r
is the case it is as if neither time had overflowed. */\r
- if( ( xTimeToWake < *pxPreviousWakeTime ) && ( xTimeToWake > xTickCount ) )\r
+ if( ( xTimeToWake < *pxPreviousWakeTime ) && ( xTimeToWake > xConstTickCount ) )\r
{\r
xShouldDelay = pdTRUE;\r
}\r
/* The tick time has not overflowed. In this case we will\r
delay if either the wake time has overflowed, and/or the\r
tick time is less than the wake time. */\r
- if( ( xTimeToWake < *pxPreviousWakeTime ) || ( xTimeToWake > xTickCount ) )\r
+ if( ( xTimeToWake < *pxPreviousWakeTime ) || ( xTimeToWake > xConstTickCount ) )\r
{\r
xShouldDelay = pdTRUE;\r
}\r
{\r
eTaskState eReturn;\r
xList *pxStateList;\r
- tskTCB *pxTCB;\r
-\r
- pxTCB = ( tskTCB * ) xTask;\r
+ const tskTCB * const pxTCB = ( tskTCB * ) xTask;\r
\r
if( pxTCB == pxCurrentTCB )\r
{\r
}\r
\r
/* Is the task waiting on an event also? */\r
- if( pxTCB->xEventListItem.pvContainer != NULL )\r
+ if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )\r
{\r
uxListRemove( &( pxTCB->xEventListItem ) );\r
}\r
\r
void vTaskResume( xTaskHandle xTaskToResume )\r
{\r
- tskTCB *pxTCB;\r
+ tskTCB * const pxTCB = ( tskTCB * ) xTaskToResume;\r
\r
/* It does not make sense to resume the calling task. */\r
configASSERT( xTaskToResume );\r
\r
- /* Remove the task from whichever list it is currently in, and place\r
- it in the ready list. */\r
- pxTCB = ( tskTCB * ) xTaskToResume;\r
-\r
/* The parameter cannot be NULL as it is impossible to resume the\r
currently executing task. */\r
if( ( pxTCB != NULL ) && ( pxTCB != pxCurrentTCB ) )\r
portBASE_TYPE xTaskResumeFromISR( xTaskHandle xTaskToResume )\r
{\r
portBASE_TYPE xYieldRequired = pdFALSE;\r
- tskTCB *pxTCB;\r
+ tskTCB * const pxTCB = ( tskTCB * ) xTaskToResume;\r
unsigned portBASE_TYPE uxSavedInterruptStatus;\r
\r
configASSERT( xTaskToResume );\r
\r
- /* RTOS ports that support interrupt nesting have the concept of a \r
- maximum system call (or maximum API call) interrupt priority. \r
- Interrupts that are above the maximum system call priority are keep \r
- permanently enabled, even when the RTOS kernel is in a critical section, \r
- but cannot make any calls to FreeRTOS API functions. If configASSERT() \r
- is defined in FreeRTOSConfig.h then \r
+ /* RTOS ports that support interrupt nesting have the concept of a\r
+ maximum system call (or maximum API call) interrupt priority.\r
+ Interrupts that are above the maximum system call priority are keep\r
+ permanently enabled, even when the RTOS kernel is in a critical section,\r
+ but cannot make any calls to FreeRTOS API functions. If configASSERT()\r
+ is defined in FreeRTOSConfig.h then\r
portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
- failure if a FreeRTOS API function is called from an interrupt that has \r
- been assigned a priority above the configured maximum system call \r
- priority. Only FreeRTOS functions that end in FromISR can be called \r
- from interrupts that have been assigned a priority at or (logically) \r
- below the maximum system call interrupt priority. FreeRTOS maintains a \r
- separate interrupt safe API to ensure interrupt entry is as fast and as \r
- simple as possible. More information (albeit Cortex-M specific) is \r
- provided on the following link: \r
+ failure if a FreeRTOS API function is called from an interrupt that has\r
+ been assigned a priority above the configured maximum system call\r
+ priority. Only FreeRTOS functions that end in FromISR can be called\r
+ from interrupts that have been assigned a priority at or (logically)\r
+ below the maximum system call interrupt priority. FreeRTOS maintains a\r
+ separate interrupt safe API to ensure interrupt entry is as fast and as\r
+ simple as possible. More information (albeit Cortex-M specific) is\r
+ provided on the following link:\r
http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
\r
- pxTCB = ( tskTCB * ) xTaskToResume;\r
-\r
uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
{\r
if( xTaskIsTaskSuspended( pxTCB ) == pdTRUE )\r
\r
/* RTOS ports that support interrupt nesting have the concept of a maximum\r
system call (or maximum API call) interrupt priority. Interrupts that are\r
- above the maximum system call priority are keep permanently enabled, even \r
+ above the maximum system call priority are keep permanently enabled, even\r
when the RTOS kernel is in a critical section, but cannot make any calls to\r
- FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h \r
+ FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h\r
then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
failure if a FreeRTOS API function is called from an interrupt that has been\r
assigned a priority above the configured maximum system call priority.\r
Only FreeRTOS functions that end in FromISR can be called from interrupts\r
- that have been assigned a priority at or (logically) below the maximum \r
- system call interrupt priority. FreeRTOS maintains a separate interrupt \r
- safe API to ensure interrupt entry is as fast and as simple as possible. \r
- More information (albeit Cortex-M specific) is provided on the following \r
+ that have been assigned a priority at or (logically) below the maximum\r
+ system call interrupt priority. FreeRTOS maintains a separate interrupt\r
+ safe API to ensure interrupt entry is as fast and as simple as possible.\r
+ More information (albeit Cortex-M specific) is provided on the following\r
link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
- \r
+\r
uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
xReturn = xTickCount;\r
portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
\r
#if( INCLUDE_vTaskDelete == 1 )\r
{\r
- /* Fill in an xTaskStatusType structure with information on \r
+ /* Fill in an xTaskStatusType structure with information on\r
each task that has been deleted but not yet cleaned up. */\r
uxTask += prvListTaskWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &xTasksWaitingTermination, eDeleted );\r
}\r
\r
#if ( INCLUDE_vTaskSuspend == 1 )\r
{\r
- /* Fill in an xTaskStatusType structure with information on \r
+ /* Fill in an xTaskStatusType structure with information on\r
each task in the Suspended state. */\r
uxTask += prvListTaskWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &xSuspendedTaskList, eSuspended );\r
}\r
\r
#if ( configGENERATE_RUN_TIME_STATS == 1)\r
{\r
- *pulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE();\r
+ if( pulTotalRunTime != NULL )\r
+ {\r
+ *pulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE();\r
+ }\r
}\r
#else\r
{\r
- *pulTotalRunTime = 0;\r
+ if( pulTotalRunTime != NULL )\r
+ {\r
+ *pulTotalRunTime = 0;\r
+ }\r
}\r
#endif\r
}\r
/* Increment the RTOS tick, switching the delayed and overflowed\r
delayed lists if it wraps to 0. */\r
++xTickCount;\r
- if( xTickCount == ( portTickType ) 0U )\r
- {\r
- taskSWITCH_DELAYED_LISTS();\r
- }\r
\r
- /* See if this tick has made a timeout expire. Tasks are stored in the\r
- queue in the order of their wake time - meaning once one tasks has been\r
- found whose block time has not expired there is no need not look any\r
- further down the list. */\r
- if( xTickCount >= xNextTaskUnblockTime )\r
{\r
- for( ;; )\r
+ /* Minor optimisation. The tick count cannot change in this\r
+ block. */\r
+ const portTickType xConstTickCount = xTickCount;\r
+\r
+ if( xConstTickCount == ( portTickType ) 0U )\r
{\r
- if( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE )\r
- {\r
- /* The delayed list is empty. Set xNextTaskUnblockTime to\r
- the maximum possible value so it is extremely unlikely that\r
- the if( xTickCount >= xNextTaskUnblockTime ) test will pass\r
- next time through. */\r
- xNextTaskUnblockTime = portMAX_DELAY;\r
- break;\r
- }\r
- else\r
+ taskSWITCH_DELAYED_LISTS();\r
+ }\r
+\r
+ /* See if this tick has made a timeout expire. Tasks are stored in the\r
+ queue in the order of their wake time - meaning once one tasks has been\r
+ found whose block time has not expired there is no need not look any\r
+ further down the list. */\r
+ if( xConstTickCount >= xNextTaskUnblockTime )\r
+ {\r
+ for( ;; )\r
{\r
- /* The delayed list is not empty, get the value of the item\r
- at the head of the delayed list. This is the time at which\r
- the task at the head of the delayed list must be removed\r
- from the Blocked state. */\r
- pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList );\r
- xItemValue = listGET_LIST_ITEM_VALUE( &( pxTCB->xGenericListItem ) );\r
-\r
- if( xTickCount < xItemValue )\r
+ if( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE )\r
{\r
- /* It is not time to unblock this item yet, but the item\r
- value is the time at which the task at the head of the\r
- blocked list must be removed from the Blocked state -\r
- so record the item value in xNextTaskUnblockTime. */\r
- xNextTaskUnblockTime = xItemValue;\r
+ /* The delayed list is empty. Set xNextTaskUnblockTime to\r
+ the maximum possible value so it is extremely unlikely that\r
+ the if( xTickCount >= xNextTaskUnblockTime ) test will pass\r
+ next time through. */\r
+ xNextTaskUnblockTime = portMAX_DELAY;\r
break;\r
}\r
+ else\r
+ {\r
+ /* The delayed list is not empty, get the value of the item\r
+ at the head of the delayed list. This is the time at which\r
+ the task at the head of the delayed list must be removed\r
+ from the Blocked state. */\r
+ pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList );\r
+ xItemValue = listGET_LIST_ITEM_VALUE( &( pxTCB->xGenericListItem ) );\r
+\r
+ if( xConstTickCount < xItemValue )\r
+ {\r
+ /* It is not time to unblock this item yet, but the item\r
+ value is the time at which the task at the head of the\r
+ blocked list must be removed from the Blocked state -\r
+ so record the item value in xNextTaskUnblockTime. */\r
+ xNextTaskUnblockTime = xItemValue;\r
+ break;\r
+ }\r
\r
- /* It is time to remove the item from the Blocked state. */\r
- uxListRemove( &( pxTCB->xGenericListItem ) );\r
+ /* It is time to remove the item from the Blocked state. */\r
+ uxListRemove( &( pxTCB->xGenericListItem ) );\r
\r
- /* Is the task waiting on an event also? If so remove it\r
- from the event list. */\r
- if( pxTCB->xEventListItem.pvContainer != NULL )\r
- {\r
- uxListRemove( &( pxTCB->xEventListItem ) );\r
- }\r
+ /* Is the task waiting on an event also? If so remove it\r
+ from the event list. */\r
+ if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )\r
+ {\r
+ uxListRemove( &( pxTCB->xEventListItem ) );\r
+ }\r
\r
- /* Place the unblocked task into the appropriate ready\r
- list. */\r
- prvAddTaskToReadyList( pxTCB );\r
+ /* Place the unblocked task into the appropriate ready\r
+ list. */\r
+ prvAddTaskToReadyList( pxTCB );\r
\r
- /* A task being unblocked cannot cause an immediate context\r
- switch if preemption is turned off. */\r
- #if ( configUSE_PREEMPTION == 1 )\r
- {\r
- /* Preemption is on, but a context switch should only\r
- be performed if the unblocked task has a priority that\r
- is equal to or higher than the currently executing\r
- task. */\r
- if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )\r
+ /* A task being unblocked cannot cause an immediate context\r
+ switch if preemption is turned off. */\r
+ #if ( configUSE_PREEMPTION == 1 )\r
{\r
- xSwitchRequired = pdTRUE;\r
+ /* Preemption is on, but a context switch should only\r
+ be performed if the unblocked task has a priority that\r
+ is equal to or higher than the currently executing\r
+ task. */\r
+ if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )\r
+ {\r
+ xSwitchRequired = pdTRUE;\r
+ }\r
}\r
+ #endif /* configUSE_PREEMPTION */\r
}\r
- #endif /* configUSE_PREEMPTION */\r
}\r
}\r
}\r
\r
taskENTER_CRITICAL();\r
{\r
+ /* Minor optimisation. The tick count cannot change in this block. */\r
+ const portTickType xConstTickCount = xTickCount;\r
+\r
#if ( INCLUDE_vTaskSuspend == 1 )\r
/* If INCLUDE_vTaskSuspend is set to 1 and the block time specified is\r
the maximum block time then the task should block indefinitely, and\r
else /* We are not blocking indefinitely, perform the checks below. */\r
#endif\r
\r
- if( ( xNumOfOverflows != pxTimeOut->xOverflowCount ) && ( ( portTickType ) xTickCount >= ( portTickType ) pxTimeOut->xTimeOnEntering ) )\r
+ if( ( xNumOfOverflows != pxTimeOut->xOverflowCount ) && ( ( portTickType ) xConstTickCount >= ( portTickType ) pxTimeOut->xTimeOnEntering ) )\r
{\r
/* The tick count is greater than the time at which vTaskSetTimeout()\r
was called, but has also overflowed since vTaskSetTimeOut() was called.\r
passed since vTaskSetTimeout() was called. */\r
xReturn = pdTRUE;\r
}\r
- else if( ( ( portTickType ) ( ( portTickType ) xTickCount - ( portTickType ) pxTimeOut->xTimeOnEntering ) ) < ( portTickType ) *pxTicksToWait )\r
+ else if( ( ( portTickType ) ( ( portTickType ) xConstTickCount - ( portTickType ) pxTimeOut->xTimeOnEntering ) ) < ( portTickType ) *pxTicksToWait )\r
{\r
/* Not a genuine timeout. Adjust parameters for time remaining. */\r
- *pxTicksToWait -= ( ( portTickType ) xTickCount - ( portTickType ) pxTimeOut->xTimeOnEntering );\r
+ *pxTicksToWait -= ( ( portTickType ) xConstTickCount - ( portTickType ) pxTimeOut->xTimeOnEntering );\r
vTaskSetTimeOutState( pxTimeOut );\r
xReturn = pdFALSE;\r
}\r
unsigned portBASE_TYPE uxTask = 0;\r
\r
if( listCURRENT_LIST_LENGTH( pxList ) > 0 )\r
- { \r
+ {\r
listGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList );\r
- \r
- /* Populate an xTaskStatusType structure within the \r
+\r
+ /* Populate an xTaskStatusType structure within the\r
pxTaskStatusArray array for each task that is referenced from\r
pxList. See the definition of xTaskStatusType in task.h for the\r
meaning of each xTaskStatusType structure member. */\r
{\r
xTaskStatusType *pxTaskStatusArray;\r
volatile unsigned portBASE_TYPE uxArraySize, x;\r
- unsigned long ulTotalRunTime;\r
char cStatus;\r
\r
/*\r
if( pxTaskStatusArray != NULL )\r
{\r
/* Generate the (binary) data. */\r
- uxArraySize = xTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );\r
+ uxArraySize = xTaskGetSystemState( pxTaskStatusArray, uxArraySize, NULL );\r
\r
/* Create a human readable table from the binary data. */\r
for( x = 0; x < uxArraySize; x++ )\r
{\r
xTaskStatusType *pxTaskStatusArray;\r
volatile unsigned portBASE_TYPE uxArraySize, x;\r
- unsigned long ulTotalRunTime, ulStatsAsPercentage;\r
+ unsigned long ulTotalTime, ulStatsAsPercentage;\r
\r
/*\r
* PLEASE NOTE:\r
if( pxTaskStatusArray != NULL )\r
{\r
/* Generate the (binary) data. */\r
- uxArraySize = xTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );\r
+ uxArraySize = xTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalTime );\r
\r
/* For percentage calculations. */\r
- ulTotalRunTime /= 100UL;\r
+ ulTotalTime /= 100UL;\r
\r
/* Avoid divide by zero errors. */\r
- if( ulTotalRunTime > 0 )\r
+ if( ulTotalTime > 0 )\r
{\r
/* Create a human readable table from the binary data. */\r
for( x = 0; x < uxArraySize; x++ )\r
/* What percentage of the total run time has the task used?\r
This will always be rounded down to the nearest integer.\r
ulTotalRunTimeDiv100 has already been divided by 100. */\r
- ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime;\r
+ ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalTime;\r
\r
if( ulStatsAsPercentage > 0UL )\r
{\r