In process of module testing event_groups.c.

Introduce xPortRunning variable into Win32 simulator port layer.
Add port optimised task selection macro for the GCC Win32 port layer (the MSVC version has had one for a while).
Ensure the event list item value does not get modified by code in tasks.c (priority inheritance, or priority change) when it is in use by the event group implementation.
This commit is contained in:
Richard Barry 2013-12-23 16:02:03 +00:00
parent 0147415c40
commit 64ad1c00b5
7 changed files with 322 additions and 134 deletions

View file

@ -91,17 +91,19 @@ privileged Vs unprivileged linkage and placement. */
#error INCLUDE_xTimerPendCallbackFromISR must also be set to one to make the xEventGroupSetBitFromISR() function available. #error INCLUDE_xTimerPendCallbackFromISR must also be set to one to make the xEventGroupSetBitFromISR() function available.
#endif #endif
/* The following bit fields convey control information in a task's event list
item value. It is important they don't clash with the
taskEVENT_LIST_ITEM_VALUE_IN_USE definition. */
#if configUSE_16_BIT_TICKS == 1 #if configUSE_16_BIT_TICKS == 1
#define taskCLEAR_EVENTS_ON_EXIT_BIT 0x0100U #define eventCLEAR_EVENTS_ON_EXIT_BIT 0x0100U
#define taskUNBLOCKED_DUE_TO_BIT_SET 0x0200U #define eventUNBLOCKED_DUE_TO_BIT_SET 0x0200U
#define taskWAIT_FOR_ALL_BITS 0x0400U #define eventWAIT_FOR_ALL_BITS 0x0400U
#define taskEVENT_BITS_CONTROL_BYTES 0xff00U #define eventEVENT_BITS_CONTROL_BYTES 0xff00U
#else #else
#define taskCLEAR_EVENTS_ON_EXIT_BIT 0x01000000UL #define eventCLEAR_EVENTS_ON_EXIT_BIT 0x01000000UL
#define taskUNBLOCKED_DUE_TO_BIT_SET 0x02000000UL #define eventUNBLOCKED_DUE_TO_BIT_SET 0x02000000UL
#define taskWAIT_FOR_ALL_BITS 0x04000000UL #define eventWAIT_FOR_ALL_BITS 0x04000000UL
#define taskEVENT_BITS_CONTROL_BYTES 0xff000000UL #define eventEVENT_BITS_CONTROL_BYTES 0xff000000UL
#endif #endif
typedef struct EventBitsDefinition typedef struct EventBitsDefinition
@ -119,6 +121,18 @@ typedef struct EVENT_GROUP_CALLBACK_PARAMTERS
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/*
* Test the bits set in uxCurrentEventBits to see if the wait condition is met.
* The wait condition is defined by xWaitForAllBits. If xWaitForAllBits is
* pdTRUE then the wait condition is met if all the bits set in uxBitsToWaitFor
* are also set in uxCurrentEventBits. If xWaitForAllBits is pdFALSE then the
* wait condition is met if any of the bits set in uxBitsToWait for are also set
* in uxCurrentEventBits.
*/
static portBASE_TYPE prvTestWaitCondition( const xEventBitsType uxCurrentEventBits, const xEventBitsType uxBitsToWaitFor, const portBASE_TYPE xWaitForAllBits );
/*-----------------------------------------------------------*/
xEventGroupHandle xEventGroupCreate( void ) xEventGroupHandle xEventGroupCreate( void )
{ {
xEVENT_BITS *pxEventBits; xEVENT_BITS *pxEventBits;
@ -128,7 +142,7 @@ xEVENT_BITS *pxEventBits;
{ {
pxEventBits->uxEventBits = 0; pxEventBits->uxEventBits = 0;
vListInitialise( &( pxEventBits->xTasksWaitingForBits ) ); vListInitialise( &( pxEventBits->xTasksWaitingForBits ) );
traceEVENT_GROUP_CREATE( pxEventBits ); traceEVENT_GROUP_CREATE( pxEventBits );
} }
else else
{ {
@ -139,12 +153,14 @@ xEVENT_BITS *pxEventBits;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
xEventBitsType xEventGroupSync( xEventGroupHandle xEventGroup, xEventBitsType uxBitsToSet, xEventBitsType uxBitsToWaitFor, portTickType xTicksToWait ) xEventBitsType xEventGroupSync( xEventGroupHandle xEventGroup, const xEventBitsType uxBitsToSet, const xEventBitsType uxBitsToWaitFor, portTickType xTicksToWait )
{ {
xEventBitsType uxOriginalBitValue, uxReturn; xEventBitsType uxOriginalBitValue, uxReturn;
xEVENT_BITS *pxEventBits = ( xEVENT_BITS * ) xEventGroup; xEVENT_BITS *pxEventBits = ( xEVENT_BITS * ) xEventGroup;
portBASE_TYPE xYieldedAlready; portBASE_TYPE xAlreadyYielded;
configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
configASSERT( uxBitsToWaitFor != 0 );
#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
{ {
configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) ); configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
@ -161,8 +177,7 @@ portBASE_TYPE xYieldedAlready;
if( ( ( uxOriginalBitValue | uxBitsToSet ) & uxBitsToWaitFor ) == uxBitsToWaitFor ) if( ( ( uxOriginalBitValue | uxBitsToSet ) & uxBitsToWaitFor ) == uxBitsToWaitFor )
{ {
/* All the rendezvous bits will have been set once this task set /* All the rendezvous bits are now set - no need to block. */
its bits - no need to block. */
uxReturn = ( uxOriginalBitValue | uxBitsToSet ); uxReturn = ( uxOriginalBitValue | uxBitsToSet );
/* Rendezvous always clear the bits. They will have been cleared /* Rendezvous always clear the bits. They will have been cleared
@ -178,11 +193,12 @@ portBASE_TYPE xYieldedAlready;
/* Store the bits that the calling task is waiting for in the /* Store the bits that the calling task is waiting for in the
task's event list item so the kernel knows when a match is task's event list item so the kernel knows when a match is
found. Then enter the blocked state. */ found. Then enter the blocked state. */
vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | taskCLEAR_EVENTS_ON_EXIT_BIT | taskWAIT_FOR_ALL_BITS ), xTicksToWait ); vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | eventCLEAR_EVENTS_ON_EXIT_BIT | eventWAIT_FOR_ALL_BITS ), xTicksToWait );
/* This is obsolete as it will get set after the task unblocks, /* This assignment is obsolete as uxReturn will get set after
but some compilers mistakenly generate a warning about the the task unblocks, but some compilers mistakenly generate a
variable being returned without being set if it is not done. */ warning about uxReturn being returned without being set if the
assignment is omitted. */
uxReturn = 0; uxReturn = 0;
} }
else else
@ -193,14 +209,18 @@ portBASE_TYPE xYieldedAlready;
} }
} }
} }
xYieldedAlready = xTaskResumeAll(); xAlreadyYielded = xTaskResumeAll();
if( xTicksToWait != ( portTickType ) 0 ) if( xTicksToWait != ( portTickType ) 0 )
{ {
if( xYieldedAlready == pdFALSE ) if( xAlreadyYielded == pdFALSE )
{ {
portYIELD_WITHIN_API(); portYIELD_WITHIN_API();
} }
else
{
mtBRANCH_TEST_INSTRUCTION();
}
/* The task blocked to wait for its required bits to be set - at this /* The task blocked to wait for its required bits to be set - at this
point either the required bits were set or the block time expired. If point either the required bits were set or the block time expired. If
@ -208,16 +228,33 @@ portBASE_TYPE xYieldedAlready;
event list item, and they should now be retrieved then cleared. */ event list item, and they should now be retrieved then cleared. */
uxReturn = uxTaskResetEventItemValue(); uxReturn = uxTaskResetEventItemValue();
if( ( uxReturn & taskUNBLOCKED_DUE_TO_BIT_SET ) == ( xEventBitsType ) 0 ) if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( xEventBitsType ) 0 )
{ {
/* The task timed out, just return the current event bit value. */ /* The task timed out, just return the current event bit value. */
uxReturn = pxEventBits->uxEventBits; taskENTER_CRITICAL();
{
uxReturn = pxEventBits->uxEventBits;
/* Although the task got here because it timed out before the
bits it was waiting for were set, it is possible that since it
unblocked another task has set the bits. If this is the case
then it may be required to clear the bits before exiting. */
if( ( uxReturn & uxBitsToWaitFor ) == uxBitsToWaitFor )
{
pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
}
else
{
mtBRANCH_TEST_INSTRUCTION();
}
}
taskEXIT_CRITICAL();
} }
else else
{ {
/* The task unblocked because the bits were set. Clear the control /* The task unblocked because the bits were set. Clear the control
bits before returning the value. */ bits before returning the value. */
uxReturn &= ~taskEVENT_BITS_CONTROL_BYTES; uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;
} }
} }
@ -226,14 +263,15 @@ portBASE_TYPE xYieldedAlready;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
xEventBitsType xEventGroupWaitBits( xEventGroupHandle xEventGroup, xEventBitsType uxBitsToWaitFor, portBASE_TYPE xClearOnExit, portBASE_TYPE xWaitForAllBits, portTickType xTicksToWait ) xEventBitsType xEventGroupWaitBits( xEventGroupHandle xEventGroup, const xEventBitsType uxBitsToWaitFor, const portBASE_TYPE xClearOnExit, const portBASE_TYPE xWaitForAllBits, portTickType xTicksToWait )
{ {
xEVENT_BITS *pxEventBits = ( xEVENT_BITS * ) xEventGroup; xEVENT_BITS *pxEventBits = ( xEVENT_BITS * ) xEventGroup;
xEventBitsType uxReturn, uxControlBits = 0; xEventBitsType uxReturn, uxControlBits = 0;
portBASE_TYPE xWaitConditionMet, xAlreadyYielded;
/* Check the user is not attempting to wait on the bits used by the kernel /* Check the user is not attempting to wait on the bits used by the kernel
itself, and that at least one bit is being requested. */ itself, and that at least one bit is being requested. */
configASSERT( ( uxBitsToWaitFor & taskEVENT_BITS_CONTROL_BYTES ) == 0 ); configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
configASSERT( uxBitsToWaitFor != 0 ); configASSERT( uxBitsToWaitFor != 0 );
#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
{ {
@ -241,46 +279,37 @@ xEventBitsType uxReturn, uxControlBits = 0;
} }
#endif #endif
taskENTER_CRITICAL(); vTaskSuspendAll();
{ {
const xEventBitsType uxCurrentEventBits = pxEventBits->uxEventBits; const xEventBitsType uxCurrentEventBits = pxEventBits->uxEventBits;
traceEVENT_GROUP_WAIT_BITS_START( xEventGroup, uxBitsToWaitFor ); traceEVENT_GROUP_WAIT_BITS_START( xEventGroup, uxBitsToWaitFor );
if( xWaitForAllBits == pdFALSE ) /* Check to see if the wait condition is already met or not. */
{ xWaitConditionMet = prvTestWaitCondition( uxCurrentEventBits, uxBitsToWaitFor, xWaitForAllBits );
/* Task only has to wait for one bit within uxBitsToWaitFor to be set. Is
one already set? */
if( ( uxCurrentEventBits & uxBitsToWaitFor ) != ( xEventBitsType ) 0 )
{
/* At least one of the bits was set. No need to block. */
xTicksToWait = 0;
}
}
else
{
/* Task has to wait for all the bits in uxBitsToWaitFor to be set. Are they
set already? */
if( ( uxCurrentEventBits & uxBitsToWaitFor ) == uxBitsToWaitFor )
{
/* All the bits were set, no need to block. */
xTicksToWait = 0;
}
}
/* The task can return now if either its wait condition is already met if( xWaitConditionMet != pdFALSE )
or the requested block time is 0. */
if( xTicksToWait == ( portTickType ) 0 )
{ {
/* No need to block, just set the return value. */ /* The wait condition has already been met so there is no need to
block. */
uxReturn = uxCurrentEventBits; uxReturn = uxCurrentEventBits;
xTicksToWait = ( portTickType ) 0;
/* Clear the wait bits if requested to do so. */
if( xClearOnExit != pdFALSE ) if( xClearOnExit != pdFALSE )
{ {
/* The user requested the bits be cleared again prior to exiting
this function. */
pxEventBits->uxEventBits &= ~uxBitsToWaitFor; pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
} }
else
{
mtBRANCH_TEST_INSTRUCTION();
}
}
else if( xTicksToWait == ( portTickType ) 0 )
{
/* The wait condition has not been met, but no block time was
specified, so just return the current value. */
uxReturn = uxCurrentEventBits;
} }
else else
{ {
@ -290,19 +319,26 @@ xEventBitsType uxReturn, uxControlBits = 0;
unblock the task. */ unblock the task. */
if( xClearOnExit != pdFALSE ) if( xClearOnExit != pdFALSE )
{ {
uxControlBits |= taskCLEAR_EVENTS_ON_EXIT_BIT; uxControlBits |= eventCLEAR_EVENTS_ON_EXIT_BIT;
}
else
{
mtBRANCH_TEST_INSTRUCTION();
} }
if( xWaitForAllBits != pdFALSE ) if( xWaitForAllBits != pdFALSE )
{ {
uxControlBits |= taskWAIT_FOR_ALL_BITS; uxControlBits |= eventWAIT_FOR_ALL_BITS;
}
else
{
mtBRANCH_TEST_INSTRUCTION();
} }
/* Store the bits that the calling task is waiting for in the /* Store the bits that the calling task is waiting for in the
task's event list item so the kernel knows when a match is task's event list item so the kernel knows when a match is
found. Then enter the blocked state. */ found. Then enter the blocked state. */
vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | uxControlBits ), xTicksToWait ); vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | uxControlBits ), xTicksToWait );
portYIELD_WITHIN_API();
/* This is obsolete as it will get set after the task unblocks, but /* This is obsolete as it will get set after the task unblocks, but
some compilers mistakenly generate a warning about the variable some compilers mistakenly generate a warning about the variable
@ -310,26 +346,57 @@ xEventBitsType uxReturn, uxControlBits = 0;
uxReturn = 0; uxReturn = 0;
} }
} }
taskEXIT_CRITICAL(); xAlreadyYielded = xTaskResumeAll();
if( xTicksToWait != ( portTickType ) 0 ) if( xTicksToWait != ( portTickType ) 0 )
{ {
if( xAlreadyYielded == pdFALSE )
{
portYIELD_WITHIN_API();
}
else
{
mtBRANCH_TEST_INSTRUCTION();
}
/* The task blocked to wait for its required bits to be set - at this /* The task blocked to wait for its required bits to be set - at this
point either the required bits were set or the block time expired. If point either the required bits were set or the block time expired. If
the required bits were set they will have been stored in the task's the required bits were set they will have been stored in the task's
event list item, and they should now be retrieved then cleared. */ event list item, and they should now be retrieved then cleared. */
uxReturn = uxTaskResetEventItemValue(); uxReturn = uxTaskResetEventItemValue();
if( ( uxReturn & taskUNBLOCKED_DUE_TO_BIT_SET ) == ( xEventBitsType ) 0 ) if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( xEventBitsType ) 0 )
{ {
/* The task timed out, just return the current event bit value. */ taskENTER_CRITICAL();
uxReturn = pxEventBits->uxEventBits; {
/* The task timed out, just return the current event bit value. */
uxReturn = pxEventBits->uxEventBits;
/* It is possible that the event bits were updated between this
task leaving the Blocked state and running again. */
if( prvTestWaitCondition( uxReturn, uxBitsToWaitFor, xWaitForAllBits ) != pdFALSE )
{
if( xClearOnExit != pdFALSE )
{
pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
}
else
{
mtBRANCH_TEST_INSTRUCTION();
}
}
else
{
mtBRANCH_TEST_INSTRUCTION();
}
}
taskEXIT_CRITICAL();
} }
else else
{ {
/* The task unblocked because the bits were set. Clear the control /* The task unblocked because the bits were set. Clear the control
bits before returning the value. */ bits before returning the value. */
uxReturn &= ~taskEVENT_BITS_CONTROL_BYTES; uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;
} }
} }
@ -338,26 +405,25 @@ xEventBitsType uxReturn, uxControlBits = 0;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
xEventBitsType xEventGroupClearBits( xEventGroupHandle xEventGroup, xEventBitsType uxBitsToClear ) xEventBitsType xEventGroupClearBits( xEventGroupHandle xEventGroup, const xEventBitsType uxBitsToClear )
{ {
xEVENT_BITS *pxEventBits = ( xEVENT_BITS * ) xEventGroup; xEVENT_BITS *pxEventBits = ( xEVENT_BITS * ) xEventGroup;
xEventBitsType uxReturn; xEventBitsType uxReturn;
/* Check the user is not attempting to clear the bits used by the kernel /* Check the user is not attempting to clear the bits used by the kernel
itself. */ itself. */
configASSERT( ( uxBitsToClear & taskEVENT_BITS_CONTROL_BYTES ) == 0 ); configASSERT( ( uxBitsToClear & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
uxBitsToClear = ~uxBitsToClear;
taskENTER_CRITICAL(); taskENTER_CRITICAL();
{ {
traceEVENT_GROUP_CLEAR_BITS( xEventGroup, ~uxBitsToClear ); traceEVENT_GROUP_CLEAR_BITS( xEventGroup, uxBitsToClear );
/* The value returned is the event group value prior to the bits being /* The value returned is the event group value prior to the bits being
cleared. */ cleared. */
uxReturn = pxEventBits->uxEventBits; uxReturn = pxEventBits->uxEventBits;
/* Clear the bits. */ /* Clear the bits. */
pxEventBits->uxEventBits &= uxBitsToClear; pxEventBits->uxEventBits &= ~uxBitsToClear;
} }
taskEXIT_CRITICAL(); taskEXIT_CRITICAL();
@ -365,7 +431,7 @@ xEventBitsType uxReturn;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
xEventBitsType xEventGroupSetBits( xEventGroupHandle xEventGroup, xEventBitsType uxBitsToSet ) xEventBitsType xEventGroupSetBits( xEventGroupHandle xEventGroup, const xEventBitsType uxBitsToSet )
{ {
xListItem *pxListItem, *pxNext; xListItem *pxListItem, *pxNext;
xListItem const *pxListEnd; xListItem const *pxListEnd;
@ -376,7 +442,7 @@ portBASE_TYPE xMatchFound = pdFALSE;
/* Check the user is not attempting to set the bits used by the kernel /* Check the user is not attempting to set the bits used by the kernel
itself. */ itself. */
configASSERT( ( uxBitsToSet & taskEVENT_BITS_CONTROL_BYTES ) == 0 ); configASSERT( ( uxBitsToSet & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
pxList = &( pxEventBits->xTasksWaitingForBits ); pxList = &( pxEventBits->xTasksWaitingForBits );
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. */ 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. */
@ -397,16 +463,20 @@ portBASE_TYPE xMatchFound = pdFALSE;
xMatchFound = pdFALSE; xMatchFound = pdFALSE;
/* Split the bits waited for from the control bits. */ /* Split the bits waited for from the control bits. */
uxControlBits = uxBitsWaitedFor & taskEVENT_BITS_CONTROL_BYTES; uxControlBits = uxBitsWaitedFor & eventEVENT_BITS_CONTROL_BYTES;
uxBitsWaitedFor &= ~taskEVENT_BITS_CONTROL_BYTES; uxBitsWaitedFor &= ~eventEVENT_BITS_CONTROL_BYTES;
if( ( uxControlBits & taskWAIT_FOR_ALL_BITS ) == ( xEventBitsType ) 0 ) if( ( uxControlBits & eventWAIT_FOR_ALL_BITS ) == ( xEventBitsType ) 0 )
{ {
/* Just looking for single bit being set. */ /* Just looking for single bit being set. */
if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) != ( xEventBitsType ) 0 ) if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) != ( xEventBitsType ) 0 )
{ {
xMatchFound = pdTRUE; xMatchFound = pdTRUE;
} }
else
{
mtBRANCH_TEST_INSTRUCTION();
}
} }
else if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) == uxBitsWaitedFor ) else if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) == uxBitsWaitedFor )
{ {
@ -421,17 +491,21 @@ portBASE_TYPE xMatchFound = pdFALSE;
if( xMatchFound != pdFALSE ) if( xMatchFound != pdFALSE )
{ {
/* The bits match. Should the bits be cleared on exit? */ /* The bits match. Should the bits be cleared on exit? */
if( ( uxControlBits & taskCLEAR_EVENTS_ON_EXIT_BIT ) != ( xEventBitsType ) 0 ) if( ( uxControlBits & eventCLEAR_EVENTS_ON_EXIT_BIT ) != ( xEventBitsType ) 0 )
{ {
uxBitsToClear |= uxBitsWaitedFor; uxBitsToClear |= uxBitsWaitedFor;
} }
else
{
mtBRANCH_TEST_INSTRUCTION();
}
/* Store the actual event flag value in the task's event list /* Store the actual event flag value in the task's event list
item before removing the task from the event list. The item before removing the task from the event list. The
taskUNBLOCKED_DUE_TO_BIT_SET bit is set so the task knows eventUNBLOCKED_DUE_TO_BIT_SET bit is set so the task knows
that is was unblocked due to its required bits matching, rather that is was unblocked due to its required bits matching, rather
than because it timed out. */ than because it timed out. */
( void ) xTaskRemoveFromUnorderedEventList( pxListItem, pxEventBits->uxEventBits | taskUNBLOCKED_DUE_TO_BIT_SET ); ( void ) xTaskRemoveFromUnorderedEventList( pxListItem, pxEventBits->uxEventBits | eventUNBLOCKED_DUE_TO_BIT_SET );
} }
/* Move onto the next list item. Note pxListItem->pxNext is not /* Move onto the next list item. Note pxListItem->pxNext is not
@ -440,7 +514,7 @@ portBASE_TYPE xMatchFound = pdFALSE;
pxListItem = pxNext; pxListItem = pxNext;
} }
/* Clear any bits that matched when the taskCLEAR_EVENTS_ON_EXIT_BIT /* Clear any bits that matched when the eventCLEAR_EVENTS_ON_EXIT_BIT
bit was set in the control word. */ bit was set in the control word. */
pxEventBits->uxEventBits &= ~uxBitsToClear; pxEventBits->uxEventBits &= ~uxBitsToClear;
} }
@ -464,7 +538,7 @@ const xList *pxTasksWaitingForBits = &( pxEventBits->xTasksWaitingForBits );
/* Unblock the task, returning 0 as the event list is being deleted /* Unblock the task, returning 0 as the event list is being deleted
and cannot therefore have any bits set. */ and cannot therefore have any bits set. */
configASSERT( pxTasksWaitingForBits->xListEnd.pxNext != ( xListItem * ) &( pxTasksWaitingForBits->xListEnd ) ); configASSERT( pxTasksWaitingForBits->xListEnd.pxNext != ( xListItem * ) &( pxTasksWaitingForBits->xListEnd ) );
( void ) xTaskRemoveFromUnorderedEventList( pxTasksWaitingForBits->xListEnd.pxNext, ( portTickType ) taskUNBLOCKED_DUE_TO_BIT_SET ); ( void ) xTaskRemoveFromUnorderedEventList( pxTasksWaitingForBits->xListEnd.pxNext, ( portTickType ) eventUNBLOCKED_DUE_TO_BIT_SET );
} }
vPortFree( pxEventBits ); vPortFree( pxEventBits );
@ -475,9 +549,44 @@ const xList *pxTasksWaitingForBits = &( pxEventBits->xTasksWaitingForBits );
/* For internal use only - execute a 'set bits' command that was pended from /* For internal use only - execute a 'set bits' command that was pended from
an interrupt. */ an interrupt. */
void vEventGroupSetBitsCallback( void *pvEventGroup, unsigned long ulBitsToSet ) void vEventGroupSetBitsCallback( void *pvEventGroup, const unsigned long ulBitsToSet )
{ {
( void ) xEventGroupSetBits( pvEventGroup, ( xEventBitsType ) ulBitsToSet ); ( void ) xEventGroupSetBits( pvEventGroup, ( xEventBitsType ) ulBitsToSet );
} }
/*-----------------------------------------------------------*/
static portBASE_TYPE prvTestWaitCondition( const xEventBitsType uxCurrentEventBits, const xEventBitsType uxBitsToWaitFor, const portBASE_TYPE xWaitForAllBits )
{
portBASE_TYPE xWaitConditionMet = pdFALSE;
if( xWaitForAllBits == pdFALSE )
{
/* Task only has to wait for one bit within uxBitsToWaitFor to be
set. Is one already set? */
if( ( uxCurrentEventBits & uxBitsToWaitFor ) != ( xEventBitsType ) 0 )
{
xWaitConditionMet = pdTRUE;
}
else
{
mtBRANCH_TEST_INSTRUCTION();
}
}
else
{
/* Task has to wait for all the bits in uxBitsToWaitFor to be set.
Are they set already? */
if( ( uxCurrentEventBits & uxBitsToWaitFor ) == uxBitsToWaitFor )
{
xWaitConditionMet = pdTRUE;
}
else
{
mtBRANCH_TEST_INSTRUCTION();
}
}
return xWaitConditionMet;
}

View file

@ -689,6 +689,10 @@ typedef portTickType xEventBitsType;
#define configUSE_TRACE_FACILITY 0 #define configUSE_TRACE_FACILITY 0
#endif #endif
#ifndef configBRANCH_TEST_INSTRUCTION
#define configBRANCH_TEST_INSTRUCTION()
#endif
/* For backward compatability. */ /* For backward compatability. */
#define eTaskStateGet eTaskGetState #define eTaskStateGet eTaskGetState

View file

@ -82,7 +82,7 @@ extern "C" {
* the status of various CAN bus related events in which bit 0 might mean "A CAN * the status of various CAN bus related events in which bit 0 might mean "A CAN
* message has been received and is ready for processing", bit 1 might mean "The * message has been received and is ready for processing", bit 1 might mean "The
* application has queued a message that is ready for sending onto the CAN * application has queued a message that is ready for sending onto the CAN
* network", and bit 2 might mean "it is time to send a SYNC message onto the * network", and bit 2 might mean "It is time to send a SYNC message onto the
* CAN network" etc. A task can then test the bit values to see which events * CAN network" etc. A task can then test the bit values to see which events
* are active, and optionally enter the Blocked state to wait for a specified * are active, and optionally enter the Blocked state to wait for a specified
* bit or a group of specified bits to be active. To continue the CAN bus * bit or a group of specified bits to be active. To continue the CAN bus
@ -165,10 +165,10 @@ xEventGroupHandle xEventGroupCreate( void ) PRIVILEGED_FUNCTION;
* event_groups.h * event_groups.h
*<pre> *<pre>
xEventBitsType xEventGroupWaitBits( xEventGroupHandle xEventGroup, xEventBitsType xEventGroupWaitBits( xEventGroupHandle xEventGroup,
xEventBitsType uxBitsToWaitFor, const xEventBitsType uxBitsToWaitFor,
portBASE_TYPE xClearOnExit, const portBASE_TYPE xClearOnExit,
portBASE_TYPE xWaitForAllBits, const portBASE_TYPE xWaitForAllBits,
portTickType xTicksToWait ); const portTickType xTicksToWait );
</pre> </pre>
* *
* [Potentially] block to wait for one or more bits to be set within a * [Potentially] block to wait for one or more bits to be set within a
@ -187,15 +187,17 @@ xEventGroupHandle xEventGroupCreate( void ) PRIVILEGED_FUNCTION;
* *
* @param xClearOnExit If xClearOnExit is set to pdTRUE then any bits within * @param xClearOnExit If xClearOnExit is set to pdTRUE then any bits within
* uxBitsToWaitFor that are set within the event group will be cleared before * uxBitsToWaitFor that are set within the event group will be cleared before
* xEventGroupWaitBits() returns. If xClearOnExit is set to pdFALSE then the * xEventGroupWaitBits() returns if the wait condition was met (if the function
* bits set in the event group are not altered when the call to * returns for a reason other than a timeout). If xClearOnExit is set to
* pdFALSE then the bits set in the event group are not altered when the call to
* xEventGroupWaitBits() returns. * xEventGroupWaitBits() returns.
* *
* @param xWaitForAllBits If xWaitForAllBits is set to pdTRUE then * @param xWaitForAllBits If xWaitForAllBits is set to pdTRUE then
* xEventGroupWaitBits() will return when either all the bits in uxBitsToWaitFor * xEventGroupWaitBits() will return when either all the bits in uxBitsToWaitFor
* are set or the specified block time expires. If xWaitForAllBits is set to * are set or the specified block time expires. If xWaitForAllBits is set to
* pdFALSE then xEventGroupWaitBits() will return when any one of the bits set * pdFALSE then xEventGroupWaitBits() will return when any one of the bits set
* in uxBitsToWaitFor is set or the specified block time expires. * in uxBitsToWaitFor is set or the specified block time expires. The block
* time is specified by the xTicksToWait parameter.
* *
* @param xTicksToWait The maximum amount of time (specified in 'ticks') to wait * @param xTicksToWait The maximum amount of time (specified in 'ticks') to wait
* for one/all (depending on the xWaitForAllBits value) of the bits specified by * for one/all (depending on the xWaitForAllBits value) of the bits specified by
@ -207,7 +209,8 @@ xEventGroupHandle xEventGroupCreate( void ) PRIVILEGED_FUNCTION;
* expired then not all the bits being waited for will be set. If * expired then not all the bits being waited for will be set. If
* xEventGroupWaitBits() returned because the bits it was waiting for were set * xEventGroupWaitBits() returned because the bits it was waiting for were set
* then the returned value is the event group value before any bits were * then the returned value is the event group value before any bits were
* automatically cleared because the xClearOnExit parameter was set to pdTRUE. * automatically cleared in the case that xClearOnExit parameter was set to
* pdTRUE.
* *
* Example usage: * Example usage:
<pre> <pre>
@ -250,12 +253,12 @@ xEventGroupHandle xEventGroupCreate( void ) PRIVILEGED_FUNCTION;
* \defgroup xEventGroupWaitBits xEventGroupWaitBits * \defgroup xEventGroupWaitBits xEventGroupWaitBits
* \ingroup EventGroup * \ingroup EventGroup
*/ */
xEventBitsType xEventGroupWaitBits( xEventGroupHandle xEventGroup, xEventBitsType uxBitsToWaitFor, portBASE_TYPE xClearOnExit, portBASE_TYPE xWaitForAllBits, portTickType xTicksToWait ) PRIVILEGED_FUNCTION; xEventBitsType xEventGroupWaitBits( xEventGroupHandle xEventGroup, const xEventBitsType uxBitsToWaitFor, const portBASE_TYPE xClearOnExit, const portBASE_TYPE xWaitForAllBits, portTickType xTicksToWait ) PRIVILEGED_FUNCTION;
/** /**
* event_groups.h * event_groups.h
*<pre> *<pre>
xEventBitsType xEventGroupClearBits( xEventGroupHandle xEventGroup, xEventBitsType uxBitsToClear ); xEventBitsType xEventGroupClearBits( xEventGroupHandle xEventGroup, const xEventBitsType uxBitsToClear );
</pre> </pre>
* *
* Clear bits within an event group. This function cannot be called from an * Clear bits within an event group. This function cannot be called from an
@ -285,9 +288,8 @@ xEventBitsType xEventGroupWaitBits( xEventGroupHandle xEventGroup, xEventBitsTyp
if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) ) if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
{ {
// Both bit 0 and bit 4 were set before the call to // Both bit 0 and bit 4 were set before xEventGroupClearBits() was
// xEventGroupClearBits() was called. Both will now be clear (not // called. Both will now be clear (not set).
// set).
} }
else if( ( uxBits & BIT_0 ) != 0 ) else if( ( uxBits & BIT_0 ) != 0 )
{ {
@ -308,12 +310,12 @@ xEventBitsType xEventGroupWaitBits( xEventGroupHandle xEventGroup, xEventBitsTyp
* \defgroup xEventGroupClearBits xEventGroupClearBits * \defgroup xEventGroupClearBits xEventGroupClearBits
* \ingroup EventGroup * \ingroup EventGroup
*/ */
xEventBitsType xEventGroupClearBits( xEventGroupHandle xEventGroup, xEventBitsType uxBitsToClear ) PRIVILEGED_FUNCTION; xEventBitsType xEventGroupClearBits( xEventGroupHandle xEventGroup, const xEventBitsType uxBitsToClear ) PRIVILEGED_FUNCTION;
/** /**
* event_groups.h * event_groups.h
*<pre> *<pre>
xEventBitsType xEventGroupSetBits( xEventGroupHandle xEventGroup, xEventBitsType uxBitsToSet ); xEventBitsType xEventGroupSetBits( xEventGroupHandle xEventGroup, const xEventBitsType uxBitsToSet );
</pre> </pre>
* *
* Set bits within an event group. * Set bits within an event group.
@ -374,20 +376,20 @@ xEventBitsType xEventGroupClearBits( xEventGroupHandle xEventGroup, xEventBitsTy
else else
{ {
// Neither bit 0 nor bit 4 remained set. It might be that a task // Neither bit 0 nor bit 4 remained set. It might be that a task
// was waiting for either or both of the bits to be set, and the // was waiting for both of the bits to be set, and the bits were
// bits were cleared as the task left the Blocked state. // cleared as the task left the Blocked state.
} }
} }
</pre> </pre>
* \defgroup xEventGroupSetBits xEventGroupSetBits * \defgroup xEventGroupSetBits xEventGroupSetBits
* \ingroup EventGroup * \ingroup EventGroup
*/ */
xEventBitsType xEventGroupSetBits( xEventGroupHandle xEventGroup, xEventBitsType uxBitsToSet ) PRIVILEGED_FUNCTION; xEventBitsType xEventGroupSetBits( xEventGroupHandle xEventGroup, const xEventBitsType uxBitsToSet ) PRIVILEGED_FUNCTION;
/** /**
* event_groups.h * event_groups.h
*<pre> *<pre>
xEventBitsType xEventGroupSetBitsFromISR( xEventGroupHandle xEventGroup, xEventBitsType uxBitsToSet, portBASE_TYPE *pxHigherPriorityTaskWoken ); xEventBitsType xEventGroupSetBitsFromISR( xEventGroupHandle xEventGroup, const xEventBitsType uxBitsToSet, portBASE_TYPE *pxHigherPriorityTaskWoken );
</pre> </pre>
* *
* A version of xEventGroupSetBits() that can be called from an interrupt. * A version of xEventGroupSetBits() that can be called from an interrupt.
@ -406,13 +408,14 @@ xEventBitsType xEventGroupSetBits( xEventGroupHandle xEventGroup, xEventBitsType
* For example, to set bit 3 only, set uxBitsToSet to 0x08. To set bit 3 * For example, to set bit 3 only, set uxBitsToSet to 0x08. To set bit 3
* and bit 0 set uxBitsToSet to 0x09. * and bit 0 set uxBitsToSet to 0x09.
* *
* @ pxHigherPriorityTaskWoken As mentioned above, calling this function will * @param pxHigherPriorityTaskWoken As mentioned above, calling this function
* result in a message being sent to the timer daemon task. If the priority of * will result in a message being sent to the timer daemon task. If the
* the timer daemon task is higher than the priority of the currently running * priority of the timer daemon task is higher than the priority of the
* task (the task the interrupt interrupted) then *pxHigherPriorityTaskWoken * currently running task (the task the interrupt interrupted) then
* will be set to pdTRUE by xEventGroupSetBitsFromISR(), indicating that a * *pxHigherPriorityTaskWoken will be set to pdTRUE by
* context switch should be requested before the interrupt exits. For that * xEventGroupSetBitsFromISR(), indicating that a context switch should be
* reason *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the * requested before the interrupt exits. For that reason
* *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the
* example code below. * example code below.
* *
* @return If the callback request was registered successfully then pdPASS is * @return If the callback request was registered successfully then pdPASS is
@ -424,7 +427,7 @@ xEventBitsType xEventGroupSetBits( xEventGroupHandle xEventGroup, xEventBitsType
#define BIT_0 ( 1 << 0 ) #define BIT_0 ( 1 << 0 )
#define BIT_4 ( 1 << 4 ) #define BIT_4 ( 1 << 4 )
// An event group which it is assume has already been created by a call to // An event group which it is assumed has already been created by a call to
// xEventGroupCreate(). // xEventGroupCreate().
xEventGroupHandle xEventGroup; xEventGroupHandle xEventGroup;
@ -432,7 +435,7 @@ xEventBitsType xEventGroupSetBits( xEventGroupHandle xEventGroup, xEventBitsType
{ {
portBASE_TYPE xHigherPriorityTaskWoken; portBASE_TYPE xHigherPriorityTaskWoken;
// xHigherPriorityTaskWoken must be initialised to pdFALSE; // xHigherPriorityTaskWoken must be initialised to pdFALSE.
xHigherPriorityTaskWoken = pdFALSE; xHigherPriorityTaskWoken = pdFALSE;
// Set bit 0 and bit 4 in xEventGroup. // Set bit 0 and bit 4 in xEventGroup.
@ -457,8 +460,8 @@ xEventBitsType xEventGroupSetBits( xEventGroupHandle xEventGroup, xEventBitsType
* event_groups.h * event_groups.h
*<pre> *<pre>
xEventBitsType xEventGroupSync( xEventGroupHandle xEventGroup, xEventBitsType xEventGroupSync( xEventGroupHandle xEventGroup,
xEventBitsType uxBitsToSet, const xEventBitsType uxBitsToSet,
xEventBitsType uxBitsToWaitFor, const xEventBitsType uxBitsToWaitFor,
portTickType xTicksToWait ); portTickType xTicksToWait );
</pre> </pre>
* *
@ -577,7 +580,7 @@ xEventBitsType xEventGroupSetBits( xEventGroupHandle xEventGroup, xEventBitsType
* \defgroup xEventGroupSync xEventGroupSync * \defgroup xEventGroupSync xEventGroupSync
* \ingroup EventGroup * \ingroup EventGroup
*/ */
xEventBitsType xEventGroupSync( xEventGroupHandle xEventGroup, xEventBitsType uxBitsToSet, xEventBitsType uxBitsToWaitFor, portTickType xTicksToWait ) PRIVILEGED_FUNCTION; xEventBitsType xEventGroupSync( xEventGroupHandle xEventGroup, const xEventBitsType uxBitsToSet, const xEventBitsType uxBitsToWaitFor, portTickType xTicksToWait ) PRIVILEGED_FUNCTION;
/** /**
@ -613,7 +616,7 @@ xEventBitsType xEventGroupSync( xEventGroupHandle xEventGroup, xEventBitsType ux
void vEventGroupDelete( xEventGroupHandle xEventGroup ); void vEventGroupDelete( xEventGroupHandle xEventGroup );
/* For internal use only. */ /* For internal use only. */
void vEventGroupSetBitsCallback( void *pvEventGroup, unsigned long ulBitsToSet ); void vEventGroupSetBitsCallback( void *pvEventGroup, const unsigned long ulBitsToSet );
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -993,6 +993,9 @@ xTaskHandle xTimerGetTimerDaemonTaskHandle( void );
* *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the * *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the
* example code below. * example code below.
* *
* @return pdPASS is returned if the message was successfully sent to the
* timer daemon task, otherwise pdFALSE is returned.
*
* Example usage: * Example usage:
* @verbatim * @verbatim
* *

View file

@ -148,6 +148,9 @@ static unsigned long (*ulIsrHandler[ portMAX_INTERRUPTS ])( void ) = { 0 };
/* Pointer to the TCB of the currently executing task. */ /* Pointer to the TCB of the currently executing task. */
extern void *pxCurrentTCB; extern void *pxCurrentTCB;
/* Used to ensure nothing is processed during the startup sequence. */
static portBASE_TYPE xPortRunning = pdFALSE;
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static DWORD WINAPI prvSimulatedPeripheralTimer( LPVOID lpParameter ) static DWORD WINAPI prvSimulatedPeripheralTimer( LPVOID lpParameter )
@ -190,6 +193,8 @@ TIMECAPS xTimeCaps;
Sleep( portTICK_RATE_MS ); Sleep( portTICK_RATE_MS );
} }
configASSERT( xPortRunning );
WaitForSingleObject( pvInterruptEventMutex, INFINITE ); WaitForSingleObject( pvInterruptEventMutex, INFINITE );
/* The timer has expired, generate the simulated tick event. */ /* The timer has expired, generate the simulated tick event. */
@ -197,7 +202,10 @@ TIMECAPS xTimeCaps;
/* The interrupt is now pending - notify the simulated interrupt /* The interrupt is now pending - notify the simulated interrupt
handler thread. */ handler thread. */
SetEvent( pvInterruptEvent ); if( ulCriticalNesting == 0 )
{
SetEvent( pvInterruptEvent );
}
/* Give back the mutex so the simulated interrupt handler unblocks /* Give back the mutex so the simulated interrupt handler unblocks
and can access the interrupt handler variables. */ and can access the interrupt handler variables. */
@ -312,7 +320,7 @@ xThreadState *pxThreadState;
ulCriticalNesting = portNO_CRITICAL_NESTING; ulCriticalNesting = portNO_CRITICAL_NESTING;
/* Bump up the priority of the thread that is going to run, in the /* Bump up the priority of the thread that is going to run, in the
hope that this will asist in getting the Windows thread scheduler to hope that this will assist in getting the Windows thread scheduler to
behave as an embedded engineer might expect. */ behave as an embedded engineer might expect. */
ResumeThread( pxThreadState->pvThread ); ResumeThread( pxThreadState->pvThread );
@ -338,6 +346,7 @@ static unsigned long prvProcessTickInterrupt( void )
unsigned long ulSwitchRequired; unsigned long ulSwitchRequired;
/* Process the tick itself. */ /* Process the tick itself. */
configASSERT( xPortRunning );
ulSwitchRequired = ( unsigned long ) xTaskIncrementTick(); ulSwitchRequired = ( unsigned long ) xTaskIncrementTick();
return ulSwitchRequired; return ulSwitchRequired;
@ -356,6 +365,13 @@ void *pvObjectList[ 2 ];
pvObjectList[ 0 ] = pvInterruptEventMutex; pvObjectList[ 0 ] = pvInterruptEventMutex;
pvObjectList[ 1 ] = pvInterruptEvent; pvObjectList[ 1 ] = pvInterruptEvent;
/* Create a pending tick to ensure the first task is started as soon as
this thread pends. */
ulPendingInterrupts |= ( 1 << portINTERRUPT_TICK );
SetEvent( pvInterruptEvent );
xPortRunning = pdTRUE;
for(;;) for(;;)
{ {
WaitForMultipleObjects( sizeof( pvObjectList ) / sizeof( void * ), pvObjectList, TRUE, INFINITE ); WaitForMultipleObjects( sizeof( pvObjectList ) / sizeof( void * ), pvObjectList, TRUE, INFINITE );
@ -489,6 +505,8 @@ void vPortEndScheduler( void )
void vPortGenerateSimulatedInterrupt( unsigned long ulInterruptNumber ) void vPortGenerateSimulatedInterrupt( unsigned long ulInterruptNumber )
{ {
configASSERT( xPortRunning );
if( ( ulInterruptNumber < portMAX_INTERRUPTS ) && ( pvInterruptEventMutex != NULL ) ) if( ( ulInterruptNumber < portMAX_INTERRUPTS ) && ( pvInterruptEventMutex != NULL ) )
{ {
/* Yield interrupts are processed even when critical nesting is non-zero. */ /* Yield interrupts are processed even when critical nesting is non-zero. */
@ -528,7 +546,7 @@ void vPortSetInterruptHandler( unsigned long ulInterruptNumber, unsigned long (*
void vPortEnterCritical( void ) void vPortEnterCritical( void )
{ {
if( xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED ) if( xPortRunning == pdTRUE )
{ {
/* The interrupt event mutex is held for the entire critical section, /* The interrupt event mutex is held for the entire critical section,
effectively disabling (simulated) interrupts. */ effectively disabling (simulated) interrupts. */
@ -561,6 +579,7 @@ long lMutexNeedsReleasing;
(simulated) disabled? */ (simulated) disabled? */
if( ulPendingInterrupts != 0UL ) if( ulPendingInterrupts != 0UL )
{ {
configASSERT( xPortRunning );
SetEvent( pvInterruptEvent ); SetEvent( pvInterruptEvent );
/* Mutex will be released now, so does not require releasing /* Mutex will be released now, so does not require releasing
@ -577,9 +596,13 @@ long lMutexNeedsReleasing;
} }
} }
if( lMutexNeedsReleasing == pdTRUE ) if( pvInterruptEventMutex != NULL )
{ {
ReleaseMutex( pvInterruptEventMutex ); if( lMutexNeedsReleasing == pdTRUE )
{
configASSERT( xPortRunning );
ReleaseMutex( pvInterruptEventMutex );
}
} }
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/

View file

@ -99,8 +99,8 @@ void vPortCloseRunningThread( void *pvTaskToDelete, volatile portBASE_TYPE *pxPe
void vPortDeleteThread( void *pvThreadToDelete ); void vPortDeleteThread( void *pvThreadToDelete );
#define portCLEAN_UP_TCB( pxTCB ) vPortDeleteThread( pxTCB ) #define portCLEAN_UP_TCB( pxTCB ) vPortDeleteThread( pxTCB )
#define portPRE_TASK_DELETE_HOOK( pvTaskToDelete, pxPendYield ) vPortCloseRunningThread( ( pvTaskToDelete ), ( pxPendYield ) ) #define portPRE_TASK_DELETE_HOOK( pvTaskToDelete, pxPendYield ) vPortCloseRunningThread( ( pvTaskToDelete ), ( pxPendYield ) )
#define portDISABLE_INTERRUPTS() #define portDISABLE_INTERRUPTS() vPortEnterCritical()
#define portENABLE_INTERRUPTS() #define portENABLE_INTERRUPTS() vPortExitCritical()
/* Critical section handling. */ /* Critical section handling. */
void vPortEnterCritical( void ); void vPortEnterCritical( void );
@ -109,27 +109,34 @@ void vPortExitCritical( void );
#define portENTER_CRITICAL() vPortEnterCritical() #define portENTER_CRITICAL() vPortEnterCritical()
#define portEXIT_CRITICAL() vPortExitCritical() #define portEXIT_CRITICAL() vPortExitCritical()
#ifndef __GNUC__ #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
#if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
/* Check the configuration. */ /* Check the configuration. */
#if( configMAX_PRIORITIES > 32 ) #if( configMAX_PRIORITIES > 32 )
#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. #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.
#endif #endif
/* Store/clear the ready priorities in a bit map. */ /* Store/clear the ready priorities in a bit map. */
#define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) ) #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
#define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) ) #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
#ifdef __GNUC__
#define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) \
__asm volatile( "mov %0, %%eax \n\t" \
"bsr %%eax, %%eax \n\t" \
"mov %%eax, %1 \n\t" \
:"=r"(uxTopPriority) : "r"(uxReadyPriorities) : "eax" )
#else
/* BitScanReverse returns the bit position of the most significant '1' /* BitScanReverse returns the bit position of the most significant '1'
in the word. */ in the word. */
#define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) _BitScanReverse( ( DWORD * ) &( uxTopPriority ), ( uxReadyPriorities ) ) #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) _BitScanReverse( ( DWORD * ) &( uxTopPriority ), ( uxReadyPriorities ) )
#endif /* __GNUC__ */
#endif /* taskRECORD_READY_PRIORITY */
#endif /* taskRECORD_READY_PRIORITY */
#endif /* __GNUC__ */

View file

@ -362,9 +362,28 @@ count overflows. */
*/ */
#define prvGetTCBFromHandle( pxHandle ) ( ( ( pxHandle ) == NULL ) ? ( tskTCB * ) pxCurrentTCB : ( tskTCB * ) ( pxHandle ) ) #define prvGetTCBFromHandle( pxHandle ) ( ( ( pxHandle ) == NULL ) ? ( tskTCB * ) pxCurrentTCB : ( tskTCB * ) ( pxHandle ) )
/* The item value of the event list item is normally used to hold the priority
of the task to which it belongs (coded to allow it to be held in reverse
priority order). However, it is occasionally borrowed for other purposes. It
is important its value is not updated due to a task priority change while it is
being used for another purpose. The following bit definition is used to inform
the scheduler that the value should not be changed - in which case it is the
responsibility of whichever module is using the value to ensure it gets set back
to its original value when it is released. */
#if configUSE_16_BIT_TICKS == 1
#define taskEVENT_LIST_ITEM_VALUE_IN_USE 0x8000U
#else
#define taskEVENT_LIST_ITEM_VALUE_IN_USE 0x80000000UL
#endif
/* Callback function prototypes. --------------------------*/ /* Callback function prototypes. --------------------------*/
extern void vApplicationStackOverflowHook( xTaskHandle xTask, signed char *pcTaskName ); #if configCHECK_FOR_STACK_OVERFLOW > 0
extern void vApplicationTickHook( void ); extern void vApplicationStackOverflowHook( xTaskHandle xTask, signed char *pcTaskName );
#endif
#if configUSE_TICK_HOOK > 0
extern void vApplicationTickHook( void );
#endif
/* File private functions. --------------------------------*/ /* File private functions. --------------------------------*/
@ -1014,7 +1033,12 @@ tskTCB * pxNewTCB;
} }
#endif #endif
listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( ( portTickType ) configMAX_PRIORITIES - ( portTickType ) uxNewPriority ) ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ /* Only reset the event list item value if the value is not
being used for anything else. */
if( ( listGET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == 0 )
{
listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( ( portTickType ) configMAX_PRIORITIES - ( portTickType ) uxNewPriority ) ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */
}
/* If the task is in the blocked or suspended list we need do /* If the task is in the blocked or suspended list we need do
nothing more than change it's priority variable. However, if nothing more than change it's priority variable. However, if
@ -1424,8 +1448,9 @@ portBASE_TYPE xAlreadyYielded = pdFALSE;
} }
/* If any ticks occurred while the scheduler was suspended then /* If any ticks occurred while the scheduler was suspended then
they should be processed now. This ensures the tick count does not they should be processed now. This ensures the tick count does
slip, and that any delayed tasks are resumed at the correct time. */ not slip, and that any delayed tasks are resumed at the correct
time. */
if( uxPendedTicks > ( unsigned portBASE_TYPE ) 0U ) if( uxPendedTicks > ( unsigned portBASE_TYPE ) 0U )
{ {
while( uxPendedTicks > ( unsigned portBASE_TYPE ) 0U ) while( uxPendedTicks > ( unsigned portBASE_TYPE ) 0U )
@ -1975,7 +2000,7 @@ portTickType xTimeToWake;
SCHEDULER SUSPENDED. */ SCHEDULER SUSPENDED. */
/* Store the item value in the event list item. */ /* Store the item value in the event list item. */
listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xEventListItem ), xItemValue ); listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xEventListItem ), xItemValue | taskEVENT_LIST_ITEM_VALUE_IN_USE );
/* Place the event list item of the TCB at the end of the appropriate event /* Place the event list item of the TCB at the end of the appropriate event
list. */ list. */
@ -2124,7 +2149,7 @@ portBASE_TYPE xReturn;
SCHEDULER SUSPENDED. It can also be called from within an ISR. */ SCHEDULER SUSPENDED. It can also be called from within an ISR. */
/* Store the new item value in the event list. */ /* Store the new item value in the event list. */
listSET_LIST_ITEM_VALUE( pxEventListItem, xItemValue ); listSET_LIST_ITEM_VALUE( pxEventListItem, xItemValue | taskEVENT_LIST_ITEM_VALUE_IN_USE );
/* Remove the TCB from the delayed list, and add it to the ready list. */ /* Remove the TCB from the delayed list, and add it to the ready list. */
@ -2852,8 +2877,13 @@ tskTCB *pxTCB;
{ {
if( pxTCB->uxPriority < pxCurrentTCB->uxPriority ) if( pxTCB->uxPriority < pxCurrentTCB->uxPriority )
{ {
/* Adjust the mutex holder state to account for its new priority. */ /* Adjust the mutex holder state to account for its new
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. */ priority. Only reset the event list item value if the value is
not being used for anything else. */
if( ( listGET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == 0 )
{
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. */
}
/* If the task being modified is in the ready state it will need to /* If the task being modified is in the ready state it will need to
be moved into a new list. */ be moved into a new list. */
@ -2903,7 +2933,13 @@ tskTCB *pxTCB;
ready list. */ ready list. */
traceTASK_PRIORITY_DISINHERIT( pxTCB, pxTCB->uxBasePriority ); traceTASK_PRIORITY_DISINHERIT( pxTCB, pxTCB->uxBasePriority );
pxTCB->uxPriority = pxTCB->uxBasePriority; pxTCB->uxPriority = pxTCB->uxBasePriority;
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. */
/* Only reset the event list item value if the value is not
being used for anything else. */
if( ( listGET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == 0 )
{
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. */
}
prvAddTaskToReadyList( pxTCB ); prvAddTaskToReadyList( pxTCB );
} }
} }
@ -3150,4 +3186,7 @@ portTickType uxReturn;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
#ifdef FREERTOS_MODULE_TEST
#include "tasks_test_access_functions.h"
#endif