#error INCLUDE_xTimerPendCallbackFromISR must also be set to one to make the xEventGroupSetBitFromISR() function available.\r
#endif\r
\r
-\r
+/* The following bit fields convey control information in a task's event list\r
+item value. It is important they don't clash with the\r
+taskEVENT_LIST_ITEM_VALUE_IN_USE definition. */\r
#if configUSE_16_BIT_TICKS == 1\r
- #define taskCLEAR_EVENTS_ON_EXIT_BIT 0x0100U\r
- #define taskUNBLOCKED_DUE_TO_BIT_SET 0x0200U\r
- #define taskWAIT_FOR_ALL_BITS 0x0400U\r
- #define taskEVENT_BITS_CONTROL_BYTES 0xff00U\r
+ #define eventCLEAR_EVENTS_ON_EXIT_BIT 0x0100U\r
+ #define eventUNBLOCKED_DUE_TO_BIT_SET 0x0200U\r
+ #define eventWAIT_FOR_ALL_BITS 0x0400U\r
+ #define eventEVENT_BITS_CONTROL_BYTES 0xff00U\r
#else\r
- #define taskCLEAR_EVENTS_ON_EXIT_BIT 0x01000000UL\r
- #define taskUNBLOCKED_DUE_TO_BIT_SET 0x02000000UL\r
- #define taskWAIT_FOR_ALL_BITS 0x04000000UL\r
- #define taskEVENT_BITS_CONTROL_BYTES 0xff000000UL\r
+ #define eventCLEAR_EVENTS_ON_EXIT_BIT 0x01000000UL\r
+ #define eventUNBLOCKED_DUE_TO_BIT_SET 0x02000000UL\r
+ #define eventWAIT_FOR_ALL_BITS 0x04000000UL\r
+ #define eventEVENT_BITS_CONTROL_BYTES 0xff000000UL\r
#endif\r
\r
typedef struct EventBitsDefinition\r
\r
/*-----------------------------------------------------------*/\r
\r
+/*\r
+ * Test the bits set in uxCurrentEventBits to see if the wait condition is met.\r
+ * The wait condition is defined by xWaitForAllBits. If xWaitForAllBits is\r
+ * pdTRUE then the wait condition is met if all the bits set in uxBitsToWaitFor\r
+ * are also set in uxCurrentEventBits. If xWaitForAllBits is pdFALSE then the\r
+ * wait condition is met if any of the bits set in uxBitsToWait for are also set\r
+ * in uxCurrentEventBits.\r
+ */\r
+static portBASE_TYPE prvTestWaitCondition( const xEventBitsType uxCurrentEventBits, const xEventBitsType uxBitsToWaitFor, const portBASE_TYPE xWaitForAllBits );\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
xEventGroupHandle xEventGroupCreate( void )\r
{\r
xEVENT_BITS *pxEventBits;\r
{\r
pxEventBits->uxEventBits = 0;\r
vListInitialise( &( pxEventBits->xTasksWaitingForBits ) );\r
- traceEVENT_GROUP_CREATE( pxEventBits ); \r
+ traceEVENT_GROUP_CREATE( pxEventBits );\r
}\r
else\r
{\r
}\r
/*-----------------------------------------------------------*/\r
\r
-xEventBitsType xEventGroupSync( xEventGroupHandle xEventGroup, xEventBitsType uxBitsToSet, xEventBitsType uxBitsToWaitFor, portTickType xTicksToWait )\r
+xEventBitsType xEventGroupSync( xEventGroupHandle xEventGroup, const xEventBitsType uxBitsToSet, const xEventBitsType uxBitsToWaitFor, portTickType xTicksToWait )\r
{\r
xEventBitsType uxOriginalBitValue, uxReturn;\r
xEVENT_BITS *pxEventBits = ( xEVENT_BITS * ) xEventGroup;\r
-portBASE_TYPE xYieldedAlready;\r
+portBASE_TYPE xAlreadyYielded;\r
\r
+ configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 );\r
+ configASSERT( uxBitsToWaitFor != 0 );\r
#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )\r
{\r
configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );\r
\r
if( ( ( uxOriginalBitValue | uxBitsToSet ) & uxBitsToWaitFor ) == uxBitsToWaitFor )\r
{\r
- /* All the rendezvous bits will have been set once this task set\r
- its bits - no need to block. */\r
+ /* All the rendezvous bits are now set - no need to block. */\r
uxReturn = ( uxOriginalBitValue | uxBitsToSet );\r
\r
/* Rendezvous always clear the bits. They will have been cleared\r
/* Store the bits that the calling task is waiting for in the\r
task's event list item so the kernel knows when a match is\r
found. Then enter the blocked state. */\r
- vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | taskCLEAR_EVENTS_ON_EXIT_BIT | taskWAIT_FOR_ALL_BITS ), xTicksToWait );\r
+ vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | eventCLEAR_EVENTS_ON_EXIT_BIT | eventWAIT_FOR_ALL_BITS ), xTicksToWait );\r
\r
- /* This is obsolete as it will get set after the task unblocks,\r
- but some compilers mistakenly generate a warning about the\r
- variable being returned without being set if it is not done. */\r
+ /* This assignment is obsolete as uxReturn will get set after\r
+ the task unblocks, but some compilers mistakenly generate a\r
+ warning about uxReturn being returned without being set if the\r
+ assignment is omitted. */\r
uxReturn = 0;\r
}\r
else\r
}\r
}\r
}\r
- xYieldedAlready = xTaskResumeAll();\r
+ xAlreadyYielded = xTaskResumeAll();\r
\r
if( xTicksToWait != ( portTickType ) 0 )\r
{\r
- if( xYieldedAlready == pdFALSE )\r
+ if( xAlreadyYielded == pdFALSE )\r
{\r
portYIELD_WITHIN_API();\r
}\r
+ else\r
+ {\r
+ mtBRANCH_TEST_INSTRUCTION();\r
+ }\r
\r
/* The task blocked to wait for its required bits to be set - at this\r
point either the required bits were set or the block time expired. If\r
event list item, and they should now be retrieved then cleared. */\r
uxReturn = uxTaskResetEventItemValue();\r
\r
- if( ( uxReturn & taskUNBLOCKED_DUE_TO_BIT_SET ) == ( xEventBitsType ) 0 )\r
+ if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( xEventBitsType ) 0 )\r
{\r
/* The task timed out, just return the current event bit value. */\r
- uxReturn = pxEventBits->uxEventBits;\r
+ taskENTER_CRITICAL();\r
+ {\r
+ uxReturn = pxEventBits->uxEventBits;\r
+\r
+ /* Although the task got here because it timed out before the\r
+ bits it was waiting for were set, it is possible that since it\r
+ unblocked another task has set the bits. If this is the case\r
+ then it may be required to clear the bits before exiting. */\r
+ if( ( uxReturn & uxBitsToWaitFor ) == uxBitsToWaitFor )\r
+ {\r
+ pxEventBits->uxEventBits &= ~uxBitsToWaitFor;\r
+ }\r
+ else\r
+ {\r
+ mtBRANCH_TEST_INSTRUCTION();\r
+ }\r
+ }\r
+ taskEXIT_CRITICAL();\r
}\r
else\r
{\r
/* The task unblocked because the bits were set. Clear the control\r
bits before returning the value. */\r
- uxReturn &= ~taskEVENT_BITS_CONTROL_BYTES;\r
+ uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;\r
}\r
}\r
\r
}\r
/*-----------------------------------------------------------*/\r
\r
-xEventBitsType xEventGroupWaitBits( xEventGroupHandle xEventGroup, xEventBitsType uxBitsToWaitFor, portBASE_TYPE xClearOnExit, portBASE_TYPE xWaitForAllBits, portTickType xTicksToWait )\r
+xEventBitsType xEventGroupWaitBits( xEventGroupHandle xEventGroup, const xEventBitsType uxBitsToWaitFor, const portBASE_TYPE xClearOnExit, const portBASE_TYPE xWaitForAllBits, portTickType xTicksToWait )\r
{\r
xEVENT_BITS *pxEventBits = ( xEVENT_BITS * ) xEventGroup;\r
xEventBitsType uxReturn, uxControlBits = 0;\r
+portBASE_TYPE xWaitConditionMet, xAlreadyYielded;\r
\r
/* Check the user is not attempting to wait on the bits used by the kernel\r
itself, and that at least one bit is being requested. */\r
- configASSERT( ( uxBitsToWaitFor & taskEVENT_BITS_CONTROL_BYTES ) == 0 );\r
+ configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 );\r
configASSERT( uxBitsToWaitFor != 0 );\r
#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )\r
{\r
}\r
#endif\r
\r
- taskENTER_CRITICAL();\r
+ vTaskSuspendAll();\r
{\r
const xEventBitsType uxCurrentEventBits = pxEventBits->uxEventBits;\r
\r
traceEVENT_GROUP_WAIT_BITS_START( xEventGroup, uxBitsToWaitFor );\r
\r
- if( xWaitForAllBits == pdFALSE )\r
- {\r
- /* Task only has to wait for one bit within uxBitsToWaitFor to be set. Is\r
- one already set? */\r
- if( ( uxCurrentEventBits & uxBitsToWaitFor ) != ( xEventBitsType ) 0 )\r
- {\r
- /* At least one of the bits was set. No need to block. */\r
- xTicksToWait = 0;\r
- }\r
- }\r
- else\r
- {\r
- /* Task has to wait for all the bits in uxBitsToWaitFor to be set. Are they\r
- set already? */\r
- if( ( uxCurrentEventBits & uxBitsToWaitFor ) == uxBitsToWaitFor )\r
- {\r
- /* All the bits were set, no need to block. */\r
- xTicksToWait = 0;\r
- }\r
- }\r
+ /* Check to see if the wait condition is already met or not. */\r
+ xWaitConditionMet = prvTestWaitCondition( uxCurrentEventBits, uxBitsToWaitFor, xWaitForAllBits );\r
\r
- /* The task can return now if either its wait condition is already met\r
- or the requested block time is 0. */\r
- if( xTicksToWait == ( portTickType ) 0 )\r
+ if( xWaitConditionMet != pdFALSE )\r
{\r
- /* No need to block, just set the return value. */\r
+ /* The wait condition has already been met so there is no need to\r
+ block. */\r
uxReturn = uxCurrentEventBits;\r
+ xTicksToWait = ( portTickType ) 0;\r
\r
+ /* Clear the wait bits if requested to do so. */\r
if( xClearOnExit != pdFALSE )\r
{\r
- /* The user requested the bits be cleared again prior to exiting\r
- this function. */\r
pxEventBits->uxEventBits &= ~uxBitsToWaitFor;\r
}\r
+ else\r
+ {\r
+ mtBRANCH_TEST_INSTRUCTION();\r
+ }\r
+ }\r
+ else if( xTicksToWait == ( portTickType ) 0 )\r
+ {\r
+ /* The wait condition has not been met, but no block time was\r
+ specified, so just return the current value. */\r
+ uxReturn = uxCurrentEventBits;\r
}\r
else\r
{\r
unblock the task. */\r
if( xClearOnExit != pdFALSE )\r
{\r
- uxControlBits |= taskCLEAR_EVENTS_ON_EXIT_BIT;\r
+ uxControlBits |= eventCLEAR_EVENTS_ON_EXIT_BIT;\r
+ }\r
+ else\r
+ {\r
+ mtBRANCH_TEST_INSTRUCTION();\r
}\r
\r
if( xWaitForAllBits != pdFALSE )\r
{\r
- uxControlBits |= taskWAIT_FOR_ALL_BITS;\r
+ uxControlBits |= eventWAIT_FOR_ALL_BITS;\r
+ }\r
+ else\r
+ {\r
+ mtBRANCH_TEST_INSTRUCTION();\r
}\r
\r
/* Store the bits that the calling task is waiting for in the\r
task's event list item so the kernel knows when a match is\r
found. Then enter the blocked state. */\r
vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | uxControlBits ), xTicksToWait );\r
- portYIELD_WITHIN_API();\r
\r
/* This is obsolete as it will get set after the task unblocks, but\r
some compilers mistakenly generate a warning about the variable\r
uxReturn = 0;\r
}\r
}\r
- taskEXIT_CRITICAL();\r
+ xAlreadyYielded = xTaskResumeAll();\r
\r
if( xTicksToWait != ( portTickType ) 0 )\r
{\r
+ if( xAlreadyYielded == pdFALSE )\r
+ {\r
+ portYIELD_WITHIN_API();\r
+ }\r
+ else\r
+ {\r
+ mtBRANCH_TEST_INSTRUCTION();\r
+ }\r
+\r
/* The task blocked to wait for its required bits to be set - at this\r
point either the required bits were set or the block time expired. If\r
the required bits were set they will have been stored in the task's\r
event list item, and they should now be retrieved then cleared. */\r
uxReturn = uxTaskResetEventItemValue();\r
\r
- if( ( uxReturn & taskUNBLOCKED_DUE_TO_BIT_SET ) == ( xEventBitsType ) 0 )\r
+ if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( xEventBitsType ) 0 )\r
{\r
- /* The task timed out, just return the current event bit value. */\r
- uxReturn = pxEventBits->uxEventBits;\r
+ taskENTER_CRITICAL();\r
+ {\r
+ /* The task timed out, just return the current event bit value. */\r
+ uxReturn = pxEventBits->uxEventBits;\r
+\r
+ /* It is possible that the event bits were updated between this\r
+ task leaving the Blocked state and running again. */\r
+ if( prvTestWaitCondition( uxReturn, uxBitsToWaitFor, xWaitForAllBits ) != pdFALSE )\r
+ {\r
+ if( xClearOnExit != pdFALSE )\r
+ {\r
+ pxEventBits->uxEventBits &= ~uxBitsToWaitFor;\r
+ }\r
+ else\r
+ {\r
+ mtBRANCH_TEST_INSTRUCTION();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ mtBRANCH_TEST_INSTRUCTION();\r
+ }\r
+ }\r
+ taskEXIT_CRITICAL();\r
}\r
else\r
{\r
/* The task unblocked because the bits were set. Clear the control\r
bits before returning the value. */\r
- uxReturn &= ~taskEVENT_BITS_CONTROL_BYTES;\r
+ uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;\r
}\r
}\r
\r
}\r
/*-----------------------------------------------------------*/\r
\r
-xEventBitsType xEventGroupClearBits( xEventGroupHandle xEventGroup, xEventBitsType uxBitsToClear )\r
+xEventBitsType xEventGroupClearBits( xEventGroupHandle xEventGroup, const xEventBitsType uxBitsToClear )\r
{\r
xEVENT_BITS *pxEventBits = ( xEVENT_BITS * ) xEventGroup;\r
xEventBitsType uxReturn;\r
\r
/* Check the user is not attempting to clear the bits used by the kernel\r
itself. */\r
- configASSERT( ( uxBitsToClear & taskEVENT_BITS_CONTROL_BYTES ) == 0 );\r
+ configASSERT( ( uxBitsToClear & eventEVENT_BITS_CONTROL_BYTES ) == 0 );\r
\r
- uxBitsToClear = ~uxBitsToClear;\r
taskENTER_CRITICAL();\r
{\r
- traceEVENT_GROUP_CLEAR_BITS( xEventGroup, ~uxBitsToClear );\r
+ traceEVENT_GROUP_CLEAR_BITS( xEventGroup, uxBitsToClear );\r
\r
/* The value returned is the event group value prior to the bits being\r
cleared. */\r
uxReturn = pxEventBits->uxEventBits;\r
\r
/* Clear the bits. */\r
- pxEventBits->uxEventBits &= uxBitsToClear;\r
+ pxEventBits->uxEventBits &= ~uxBitsToClear;\r
}\r
taskEXIT_CRITICAL();\r
\r
}\r
/*-----------------------------------------------------------*/\r
\r
-xEventBitsType xEventGroupSetBits( xEventGroupHandle xEventGroup, xEventBitsType uxBitsToSet )\r
+xEventBitsType xEventGroupSetBits( xEventGroupHandle xEventGroup, const xEventBitsType uxBitsToSet )\r
{\r
xListItem *pxListItem, *pxNext;\r
xListItem const *pxListEnd;\r
\r
/* Check the user is not attempting to set the bits used by the kernel\r
itself. */\r
- configASSERT( ( uxBitsToSet & taskEVENT_BITS_CONTROL_BYTES ) == 0 );\r
+ configASSERT( ( uxBitsToSet & eventEVENT_BITS_CONTROL_BYTES ) == 0 );\r
\r
pxList = &( pxEventBits->xTasksWaitingForBits );\r
pxListEnd = listGET_END_MARKER( pxList ); /*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */\r
xMatchFound = pdFALSE;\r
\r
/* Split the bits waited for from the control bits. */\r
- uxControlBits = uxBitsWaitedFor & taskEVENT_BITS_CONTROL_BYTES;\r
- uxBitsWaitedFor &= ~taskEVENT_BITS_CONTROL_BYTES;\r
+ uxControlBits = uxBitsWaitedFor & eventEVENT_BITS_CONTROL_BYTES;\r
+ uxBitsWaitedFor &= ~eventEVENT_BITS_CONTROL_BYTES;\r
\r
- if( ( uxControlBits & taskWAIT_FOR_ALL_BITS ) == ( xEventBitsType ) 0 )\r
+ if( ( uxControlBits & eventWAIT_FOR_ALL_BITS ) == ( xEventBitsType ) 0 )\r
{\r
/* Just looking for single bit being set. */\r
if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) != ( xEventBitsType ) 0 )\r
{\r
xMatchFound = pdTRUE;\r
}\r
+ else\r
+ {\r
+ mtBRANCH_TEST_INSTRUCTION();\r
+ }\r
}\r
else if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) == uxBitsWaitedFor )\r
{\r
if( xMatchFound != pdFALSE )\r
{\r
/* The bits match. Should the bits be cleared on exit? */\r
- if( ( uxControlBits & taskCLEAR_EVENTS_ON_EXIT_BIT ) != ( xEventBitsType ) 0 )\r
+ if( ( uxControlBits & eventCLEAR_EVENTS_ON_EXIT_BIT ) != ( xEventBitsType ) 0 )\r
{\r
uxBitsToClear |= uxBitsWaitedFor;\r
}\r
+ else\r
+ {\r
+ mtBRANCH_TEST_INSTRUCTION();\r
+ }\r
\r
/* Store the actual event flag value in the task's event list\r
item before removing the task from the event list. The\r
- taskUNBLOCKED_DUE_TO_BIT_SET bit is set so the task knows\r
+ eventUNBLOCKED_DUE_TO_BIT_SET bit is set so the task knows\r
that is was unblocked due to its required bits matching, rather\r
than because it timed out. */\r
- ( void ) xTaskRemoveFromUnorderedEventList( pxListItem, pxEventBits->uxEventBits | taskUNBLOCKED_DUE_TO_BIT_SET );\r
+ ( void ) xTaskRemoveFromUnorderedEventList( pxListItem, pxEventBits->uxEventBits | eventUNBLOCKED_DUE_TO_BIT_SET );\r
}\r
\r
/* Move onto the next list item. Note pxListItem->pxNext is not\r
pxListItem = pxNext;\r
}\r
\r
- /* Clear any bits that matched when the taskCLEAR_EVENTS_ON_EXIT_BIT\r
+ /* Clear any bits that matched when the eventCLEAR_EVENTS_ON_EXIT_BIT\r
bit was set in the control word. */\r
pxEventBits->uxEventBits &= ~uxBitsToClear;\r
}\r
/* Unblock the task, returning 0 as the event list is being deleted\r
and cannot therefore have any bits set. */\r
configASSERT( pxTasksWaitingForBits->xListEnd.pxNext != ( xListItem * ) &( pxTasksWaitingForBits->xListEnd ) );\r
- ( void ) xTaskRemoveFromUnorderedEventList( pxTasksWaitingForBits->xListEnd.pxNext, ( portTickType ) taskUNBLOCKED_DUE_TO_BIT_SET );\r
+ ( void ) xTaskRemoveFromUnorderedEventList( pxTasksWaitingForBits->xListEnd.pxNext, ( portTickType ) eventUNBLOCKED_DUE_TO_BIT_SET );\r
}\r
\r
vPortFree( pxEventBits );\r
\r
/* For internal use only - execute a 'set bits' command that was pended from\r
an interrupt. */\r
-void vEventGroupSetBitsCallback( void *pvEventGroup, unsigned long ulBitsToSet )\r
+void vEventGroupSetBitsCallback( void *pvEventGroup, const unsigned long ulBitsToSet )\r
{\r
( void ) xEventGroupSetBits( pvEventGroup, ( xEventBitsType ) ulBitsToSet );\r
}\r
+/*-----------------------------------------------------------*/\r
+\r
+static portBASE_TYPE prvTestWaitCondition( const xEventBitsType uxCurrentEventBits, const xEventBitsType uxBitsToWaitFor, const portBASE_TYPE xWaitForAllBits )\r
+{\r
+portBASE_TYPE xWaitConditionMet = pdFALSE;\r
+\r
+ if( xWaitForAllBits == pdFALSE )\r
+ {\r
+ /* Task only has to wait for one bit within uxBitsToWaitFor to be\r
+ set. Is one already set? */\r
+ if( ( uxCurrentEventBits & uxBitsToWaitFor ) != ( xEventBitsType ) 0 )\r
+ {\r
+ xWaitConditionMet = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ mtBRANCH_TEST_INSTRUCTION();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* Task has to wait for all the bits in uxBitsToWaitFor to be set.\r
+ Are they set already? */\r
+ if( ( uxCurrentEventBits & uxBitsToWaitFor ) == uxBitsToWaitFor )\r
+ {\r
+ xWaitConditionMet = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ mtBRANCH_TEST_INSTRUCTION();\r
+ }\r
+ }\r
+\r
+ return xWaitConditionMet;\r
+}\r
\r
\r
#define configUSE_TRACE_FACILITY 0\r
#endif\r
\r
+#ifndef configBRANCH_TEST_INSTRUCTION\r
+ #define configBRANCH_TEST_INSTRUCTION()\r
+#endif\r
+\r
/* For backward compatability. */\r
#define eTaskStateGet eTaskGetState\r
\r
* the status of various CAN bus related events in which bit 0 might mean "A CAN\r
* message has been received and is ready for processing", bit 1 might mean "The\r
* application has queued a message that is ready for sending onto the CAN\r
- * network", and bit 2 might mean "it is time to send a SYNC message onto the\r
+ * network", and bit 2 might mean "It is time to send a SYNC message onto the\r
* CAN network" etc. A task can then test the bit values to see which events\r
* are active, and optionally enter the Blocked state to wait for a specified\r
* bit or a group of specified bits to be active. To continue the CAN bus\r
* event_groups.h\r
*<pre>\r
xEventBitsType xEventGroupWaitBits( xEventGroupHandle xEventGroup,\r
- xEventBitsType uxBitsToWaitFor,\r
- portBASE_TYPE xClearOnExit,\r
- portBASE_TYPE xWaitForAllBits,\r
- portTickType xTicksToWait );\r
+ const xEventBitsType uxBitsToWaitFor,\r
+ const portBASE_TYPE xClearOnExit,\r
+ const portBASE_TYPE xWaitForAllBits,\r
+ const portTickType xTicksToWait );\r
</pre>\r
*\r
* [Potentially] block to wait for one or more bits to be set within a\r
*\r
* @param xClearOnExit If xClearOnExit is set to pdTRUE then any bits within\r
* uxBitsToWaitFor that are set within the event group will be cleared before\r
- * xEventGroupWaitBits() returns. If xClearOnExit is set to pdFALSE then the\r
- * bits set in the event group are not altered when the call to\r
+ * xEventGroupWaitBits() returns if the wait condition was met (if the function\r
+ * returns for a reason other than a timeout). If xClearOnExit is set to\r
+ * pdFALSE then the bits set in the event group are not altered when the call to\r
* xEventGroupWaitBits() returns.\r
*\r
* @param xWaitForAllBits If xWaitForAllBits is set to pdTRUE then\r
* xEventGroupWaitBits() will return when either all the bits in uxBitsToWaitFor\r
* are set or the specified block time expires. If xWaitForAllBits is set to\r
* pdFALSE then xEventGroupWaitBits() will return when any one of the bits set\r
- * in uxBitsToWaitFor is set or the specified block time expires.\r
+ * in uxBitsToWaitFor is set or the specified block time expires. The block\r
+ * time is specified by the xTicksToWait parameter.\r
*\r
* @param xTicksToWait The maximum amount of time (specified in 'ticks') to wait\r
* for one/all (depending on the xWaitForAllBits value) of the bits specified by\r
* expired then not all the bits being waited for will be set. If\r
* xEventGroupWaitBits() returned because the bits it was waiting for were set\r
* then the returned value is the event group value before any bits were\r
- * automatically cleared because the xClearOnExit parameter was set to pdTRUE.\r
+ * automatically cleared in the case that xClearOnExit parameter was set to\r
+ * pdTRUE.\r
*\r
* Example usage:\r
<pre>\r
* \defgroup xEventGroupWaitBits xEventGroupWaitBits\r
* \ingroup EventGroup\r
*/\r
-xEventBitsType xEventGroupWaitBits( xEventGroupHandle xEventGroup, xEventBitsType uxBitsToWaitFor, portBASE_TYPE xClearOnExit, portBASE_TYPE xWaitForAllBits, portTickType xTicksToWait ) PRIVILEGED_FUNCTION;\r
+xEventBitsType xEventGroupWaitBits( xEventGroupHandle xEventGroup, const xEventBitsType uxBitsToWaitFor, const portBASE_TYPE xClearOnExit, const portBASE_TYPE xWaitForAllBits, portTickType xTicksToWait ) PRIVILEGED_FUNCTION;\r
\r
/**\r
* event_groups.h\r
*<pre>\r
- xEventBitsType xEventGroupClearBits( xEventGroupHandle xEventGroup, xEventBitsType uxBitsToClear );\r
+ xEventBitsType xEventGroupClearBits( xEventGroupHandle xEventGroup, const xEventBitsType uxBitsToClear );\r
</pre>\r
*\r
* Clear bits within an event group. This function cannot be called from an\r
\r
if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )\r
{\r
- // Both bit 0 and bit 4 were set before the call to\r
- // xEventGroupClearBits() was called. Both will now be clear (not\r
- // set).\r
+ // Both bit 0 and bit 4 were set before xEventGroupClearBits() was\r
+ // called. Both will now be clear (not set).\r
}\r
else if( ( uxBits & BIT_0 ) != 0 )\r
{\r
* \defgroup xEventGroupClearBits xEventGroupClearBits\r
* \ingroup EventGroup\r
*/\r
-xEventBitsType xEventGroupClearBits( xEventGroupHandle xEventGroup, xEventBitsType uxBitsToClear ) PRIVILEGED_FUNCTION;\r
+xEventBitsType xEventGroupClearBits( xEventGroupHandle xEventGroup, const xEventBitsType uxBitsToClear ) PRIVILEGED_FUNCTION;\r
\r
/**\r
* event_groups.h\r
*<pre>\r
- xEventBitsType xEventGroupSetBits( xEventGroupHandle xEventGroup, xEventBitsType uxBitsToSet );\r
+ xEventBitsType xEventGroupSetBits( xEventGroupHandle xEventGroup, const xEventBitsType uxBitsToSet );\r
</pre>\r
*\r
* Set bits within an event group.\r
else\r
{\r
// Neither bit 0 nor bit 4 remained set. It might be that a task\r
- // was waiting for either or both of the bits to be set, and the\r
- // bits were cleared as the task left the Blocked state.\r
+ // was waiting for both of the bits to be set, and the bits were\r
+ // cleared as the task left the Blocked state.\r
}\r
}\r
</pre>\r
* \defgroup xEventGroupSetBits xEventGroupSetBits\r
* \ingroup EventGroup\r
*/\r
-xEventBitsType xEventGroupSetBits( xEventGroupHandle xEventGroup, xEventBitsType uxBitsToSet ) PRIVILEGED_FUNCTION;\r
+xEventBitsType xEventGroupSetBits( xEventGroupHandle xEventGroup, const xEventBitsType uxBitsToSet ) PRIVILEGED_FUNCTION;\r
\r
/**\r
* event_groups.h\r
*<pre>\r
- xEventBitsType xEventGroupSetBitsFromISR( xEventGroupHandle xEventGroup, xEventBitsType uxBitsToSet, portBASE_TYPE *pxHigherPriorityTaskWoken );\r
+ xEventBitsType xEventGroupSetBitsFromISR( xEventGroupHandle xEventGroup, const xEventBitsType uxBitsToSet, portBASE_TYPE *pxHigherPriorityTaskWoken );\r
</pre>\r
*\r
* A version of xEventGroupSetBits() that can be called from an interrupt.\r
* For example, to set bit 3 only, set uxBitsToSet to 0x08. To set bit 3\r
* and bit 0 set uxBitsToSet to 0x09.\r
*\r
- * @ pxHigherPriorityTaskWoken As mentioned above, calling this function will\r
- * result in a message being sent to the timer daemon task. If the priority of\r
- * the timer daemon task is higher than the priority of the currently running\r
- * task (the task the interrupt interrupted) then *pxHigherPriorityTaskWoken\r
- * will be set to pdTRUE by xEventGroupSetBitsFromISR(), indicating that a\r
- * context switch should be requested before the interrupt exits. For that\r
- * reason *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the\r
+ * @param pxHigherPriorityTaskWoken As mentioned above, calling this function\r
+ * will result in a message being sent to the timer daemon task. If the\r
+ * priority of the timer daemon task is higher than the priority of the\r
+ * currently running task (the task the interrupt interrupted) then\r
+ * *pxHigherPriorityTaskWoken will be set to pdTRUE by\r
+ * xEventGroupSetBitsFromISR(), indicating that a context switch should be\r
+ * requested before the interrupt exits. For that reason\r
+ * *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the\r
* example code below.\r
*\r
* @return If the callback request was registered successfully then pdPASS is\r
#define BIT_0 ( 1 << 0 )\r
#define BIT_4 ( 1 << 4 )\r
\r
- // An event group which it is assume has already been created by a call to\r
+ // An event group which it is assumed has already been created by a call to\r
// xEventGroupCreate().\r
xEventGroupHandle xEventGroup;\r
\r
{\r
portBASE_TYPE xHigherPriorityTaskWoken;\r
\r
- // xHigherPriorityTaskWoken must be initialised to pdFALSE;\r
+ // xHigherPriorityTaskWoken must be initialised to pdFALSE.\r
xHigherPriorityTaskWoken = pdFALSE;\r
\r
// Set bit 0 and bit 4 in xEventGroup.\r
* event_groups.h\r
*<pre>\r
xEventBitsType xEventGroupSync( xEventGroupHandle xEventGroup,\r
- xEventBitsType uxBitsToSet,\r
- xEventBitsType uxBitsToWaitFor,\r
+ const xEventBitsType uxBitsToSet,\r
+ const xEventBitsType uxBitsToWaitFor,\r
portTickType xTicksToWait );\r
</pre>\r
*\r
* \defgroup xEventGroupSync xEventGroupSync\r
* \ingroup EventGroup\r
*/\r
-xEventBitsType xEventGroupSync( xEventGroupHandle xEventGroup, xEventBitsType uxBitsToSet, xEventBitsType uxBitsToWaitFor, portTickType xTicksToWait ) PRIVILEGED_FUNCTION;\r
+xEventBitsType xEventGroupSync( xEventGroupHandle xEventGroup, const xEventBitsType uxBitsToSet, const xEventBitsType uxBitsToWaitFor, portTickType xTicksToWait ) PRIVILEGED_FUNCTION;\r
\r
\r
/**\r
void vEventGroupDelete( xEventGroupHandle xEventGroup );\r
\r
/* For internal use only. */\r
-void vEventGroupSetBitsCallback( void *pvEventGroup, unsigned long ulBitsToSet );\r
+void vEventGroupSetBitsCallback( void *pvEventGroup, const unsigned long ulBitsToSet );\r
\r
\r
#ifdef __cplusplus\r
* *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the\r
* example code below.\r
*\r
+ * @return pdPASS is returned if the message was successfully sent to the\r
+ * timer daemon task, otherwise pdFALSE is returned.\r
+ *\r
* Example usage:\r
* @verbatim\r
*\r
/* Pointer to the TCB of the currently executing task. */\r
extern void *pxCurrentTCB;\r
\r
+/* Used to ensure nothing is processed during the startup sequence. */\r
+static portBASE_TYPE xPortRunning = pdFALSE;\r
+\r
/*-----------------------------------------------------------*/\r
\r
static DWORD WINAPI prvSimulatedPeripheralTimer( LPVOID lpParameter )\r
Sleep( portTICK_RATE_MS );\r
}\r
\r
+ configASSERT( xPortRunning );\r
+\r
WaitForSingleObject( pvInterruptEventMutex, INFINITE );\r
\r
/* The timer has expired, generate the simulated tick event. */\r
\r
/* The interrupt is now pending - notify the simulated interrupt \r
handler thread. */\r
- SetEvent( pvInterruptEvent );\r
+ if( ulCriticalNesting == 0 )\r
+ {\r
+ SetEvent( pvInterruptEvent );\r
+ }\r
\r
/* Give back the mutex so the simulated interrupt handler unblocks \r
and can access the interrupt handler variables. */\r
ulCriticalNesting = portNO_CRITICAL_NESTING;\r
\r
/* Bump up the priority of the thread that is going to run, in the\r
- hope that this will asist in getting the Windows thread scheduler to\r
+ hope that this will assist in getting the Windows thread scheduler to\r
behave as an embedded engineer might expect. */\r
ResumeThread( pxThreadState->pvThread );\r
\r
unsigned long ulSwitchRequired;\r
\r
/* Process the tick itself. */\r
+ configASSERT( xPortRunning );\r
ulSwitchRequired = ( unsigned long ) xTaskIncrementTick();\r
\r
return ulSwitchRequired;\r
pvObjectList[ 0 ] = pvInterruptEventMutex;\r
pvObjectList[ 1 ] = pvInterruptEvent;\r
\r
+ /* Create a pending tick to ensure the first task is started as soon as\r
+ this thread pends. */\r
+ ulPendingInterrupts |= ( 1 << portINTERRUPT_TICK );\r
+ SetEvent( pvInterruptEvent );\r
+\r
+ xPortRunning = pdTRUE;\r
+\r
for(;;)\r
{\r
WaitForMultipleObjects( sizeof( pvObjectList ) / sizeof( void * ), pvObjectList, TRUE, INFINITE );\r
\r
void vPortGenerateSimulatedInterrupt( unsigned long ulInterruptNumber )\r
{\r
+ configASSERT( xPortRunning );\r
+\r
if( ( ulInterruptNumber < portMAX_INTERRUPTS ) && ( pvInterruptEventMutex != NULL ) )\r
{\r
/* Yield interrupts are processed even when critical nesting is non-zero. */\r
\r
void vPortEnterCritical( void )\r
{\r
- if( xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED )\r
+ if( xPortRunning == pdTRUE )\r
{\r
/* The interrupt event mutex is held for the entire critical section,\r
effectively disabling (simulated) interrupts. */\r
(simulated) disabled? */\r
if( ulPendingInterrupts != 0UL )\r
{\r
+ configASSERT( xPortRunning );\r
SetEvent( pvInterruptEvent );\r
\r
/* Mutex will be released now, so does not require releasing\r
}\r
}\r
\r
- if( lMutexNeedsReleasing == pdTRUE )\r
+ if( pvInterruptEventMutex != NULL )\r
{\r
- ReleaseMutex( pvInterruptEventMutex );\r
+ if( lMutexNeedsReleasing == pdTRUE )\r
+ {\r
+ configASSERT( xPortRunning );\r
+ ReleaseMutex( pvInterruptEventMutex );\r
+ }\r
}\r
}\r
/*-----------------------------------------------------------*/\r
void vPortDeleteThread( void *pvThreadToDelete );\r
#define portCLEAN_UP_TCB( pxTCB ) vPortDeleteThread( pxTCB )\r
#define portPRE_TASK_DELETE_HOOK( pvTaskToDelete, pxPendYield ) vPortCloseRunningThread( ( pvTaskToDelete ), ( pxPendYield ) )\r
-#define portDISABLE_INTERRUPTS()\r
-#define portENABLE_INTERRUPTS()\r
+#define portDISABLE_INTERRUPTS() vPortEnterCritical()\r
+#define portENABLE_INTERRUPTS() vPortExitCritical()\r
\r
/* Critical section handling. */\r
void vPortEnterCritical( void );\r
#define portENTER_CRITICAL() vPortEnterCritical()\r
#define portEXIT_CRITICAL() vPortExitCritical()\r
\r
-#ifndef __GNUC__\r
- #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1\r
+#if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1\r
\r
/* Check the configuration. */\r
#if( configMAX_PRIORITIES > 32 )\r
#error configUSE_PORT_OPTIMISED_TASK_SELECTION can only be set to 1 when configMAX_PRIORITIES is less than or equal to 32. It is very rare that a system requires more than 10 to 15 difference priorities as tasks that share a priority will time slice.\r
#endif\r
\r
- /* Store/clear the ready priorities in a bit map. */\r
- #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )\r
- #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )\r
+ /* Store/clear the ready priorities in a bit map. */\r
+ #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )\r
+ #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )\r
\r
\r
- /*-----------------------------------------------------------*/\r
+ /*-----------------------------------------------------------*/\r
\r
+ #ifdef __GNUC__\r
+ #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) \\r
+ __asm volatile( "mov %0, %%eax \n\t" \\r
+ "bsr %%eax, %%eax \n\t" \\r
+ "mov %%eax, %1 \n\t" \\r
+ :"=r"(uxTopPriority) : "r"(uxReadyPriorities) : "eax" )\r
+ #else\r
/* BitScanReverse returns the bit position of the most significant '1'\r
in the word. */\r
#define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) _BitScanReverse( ( DWORD * ) &( uxTopPriority ), ( uxReadyPriorities ) )\r
+ #endif /* __GNUC__ */\r
+\r
+#endif /* taskRECORD_READY_PRIORITY */\r
\r
- #endif /* taskRECORD_READY_PRIORITY */\r
-#endif /* __GNUC__ */\r
\r
\r
\r
*/\r
#define prvGetTCBFromHandle( pxHandle ) ( ( ( pxHandle ) == NULL ) ? ( tskTCB * ) pxCurrentTCB : ( tskTCB * ) ( pxHandle ) )\r
\r
+/* The item value of the event list item is normally used to hold the priority\r
+of the task to which it belongs (coded to allow it to be held in reverse\r
+priority order). However, it is occasionally borrowed for other purposes. It\r
+is important its value is not updated due to a task priority change while it is\r
+being used for another purpose. The following bit definition is used to inform\r
+the scheduler that the value should not be changed - in which case it is the\r
+responsibility of whichever module is using the value to ensure it gets set back\r
+to its original value when it is released. */\r
+#if configUSE_16_BIT_TICKS == 1\r
+ #define taskEVENT_LIST_ITEM_VALUE_IN_USE 0x8000U\r
+#else\r
+ #define taskEVENT_LIST_ITEM_VALUE_IN_USE 0x80000000UL\r
+#endif\r
+\r
/* Callback function prototypes. --------------------------*/\r
-extern void vApplicationStackOverflowHook( xTaskHandle xTask, signed char *pcTaskName );\r
-extern void vApplicationTickHook( void );\r
+#if configCHECK_FOR_STACK_OVERFLOW > 0\r
+ extern void vApplicationStackOverflowHook( xTaskHandle xTask, signed char *pcTaskName );\r
+#endif\r
+\r
+#if configUSE_TICK_HOOK > 0\r
+ extern void vApplicationTickHook( void );\r
+#endif\r
\r
/* File private functions. --------------------------------*/\r
\r
}\r
#endif\r
\r
- listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( ( portTickType ) configMAX_PRIORITIES - ( portTickType ) uxNewPriority ) ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+ /* Only reset the event list item value if the value is not\r
+ being used for anything else. */\r
+ if( ( listGET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == 0 )\r
+ {\r
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( ( portTickType ) configMAX_PRIORITIES - ( portTickType ) uxNewPriority ) ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+ }\r
\r
/* If the task is in the blocked or suspended list we need do\r
nothing more than change it's priority variable. However, if\r
}\r
\r
/* If any ticks occurred while the scheduler was suspended then\r
- they should be processed now. This ensures the tick count does not\r
- slip, and that any delayed tasks are resumed at the correct time. */\r
+ they should be processed now. This ensures the tick count does \r
+ not slip, and that any delayed tasks are resumed at the correct \r
+ time. */\r
if( uxPendedTicks > ( unsigned portBASE_TYPE ) 0U )\r
{\r
while( uxPendedTicks > ( unsigned portBASE_TYPE ) 0U )\r
SCHEDULER SUSPENDED. */\r
\r
/* Store the item value in the event list item. */\r
- listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xEventListItem ), xItemValue );\r
+ listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xEventListItem ), xItemValue | taskEVENT_LIST_ITEM_VALUE_IN_USE );\r
\r
/* Place the event list item of the TCB at the end of the appropriate event\r
list. */\r
SCHEDULER SUSPENDED. It can also be called from within an ISR. */\r
\r
/* Store the new item value in the event list. */\r
- listSET_LIST_ITEM_VALUE( pxEventListItem, xItemValue );\r
+ listSET_LIST_ITEM_VALUE( pxEventListItem, xItemValue | taskEVENT_LIST_ITEM_VALUE_IN_USE );\r
\r
/* Remove the TCB from the delayed list, and add it to the ready list. */\r
\r
{\r
if( pxTCB->uxPriority < pxCurrentTCB->uxPriority )\r
{\r
- /* Adjust the mutex holder state to account for its new priority. */\r
- listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( portTickType ) configMAX_PRIORITIES - ( portTickType ) pxCurrentTCB->uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+ /* Adjust the mutex holder state to account for its new\r
+ priority. Only reset the event list item value if the value is\r
+ not being used for anything else. */\r
+ if( ( listGET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == 0 )\r
+ {\r
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( portTickType ) configMAX_PRIORITIES - ( portTickType ) pxCurrentTCB->uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+ }\r
\r
/* If the task being modified is in the ready state it will need to\r
be moved into a new list. */\r
ready list. */\r
traceTASK_PRIORITY_DISINHERIT( pxTCB, pxTCB->uxBasePriority );\r
pxTCB->uxPriority = pxTCB->uxBasePriority;\r
- listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( portTickType ) configMAX_PRIORITIES - ( portTickType ) pxTCB->uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+\r
+ /* Only reset the event list item value if the value is not\r
+ being used for anything else. */\r
+ if( ( listGET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == 0 )\r
+ {\r
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( portTickType ) configMAX_PRIORITIES - ( portTickType ) pxTCB->uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+ }\r
prvAddTaskToReadyList( pxTCB );\r
}\r
}\r
}\r
/*-----------------------------------------------------------*/\r
\r
+#ifdef FREERTOS_MODULE_TEST\r
+ #include "tasks_test_access_functions.h"\r
+#endif\r
\r