mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-05-29 00:19:04 -04:00
Add additional configASSERTS() to some standard demo tasks.
Use own rand() function in QueueSet.c to prevent library versions being referenced.
This commit is contained in:
parent
33bd63e287
commit
ed399e801e
|
@ -109,7 +109,7 @@ in the range of 0xffff to ULONG_MAX. */
|
||||||
|
|
||||||
/* For test purposes the priority of the sending task is changed after every
|
/* For test purposes the priority of the sending task is changed after every
|
||||||
queuesetPRIORITY_CHANGE_LOOPS number of values are sent to a queue. */
|
queuesetPRIORITY_CHANGE_LOOPS number of values are sent to a queue. */
|
||||||
#define queuesetPRIORITY_CHANGE_LOOPS 100UL
|
#define queuesetPRIORITY_CHANGE_LOOPS ( ( queuesetNUM_QUEUES_IN_SET * queuesetQUEUE_LENGTH ) * 3 )
|
||||||
|
|
||||||
/* The ISR sends to the queue every queuesetISR_TX_PERIOD ticks. */
|
/* The ISR sends to the queue every queuesetISR_TX_PERIOD ticks. */
|
||||||
#define queuesetISR_TX_PERIOD ( 100UL )
|
#define queuesetISR_TX_PERIOD ( 100UL )
|
||||||
|
@ -161,6 +161,13 @@ static void prvSetupTest( xTaskHandle xQueueSetSendingTask );
|
||||||
*/
|
*/
|
||||||
static portBASE_TYPE prvCheckReceivedValueWithinExpectedRange( unsigned long ulReceived, unsigned long ulExpectedReceived );
|
static portBASE_TYPE prvCheckReceivedValueWithinExpectedRange( unsigned long ulReceived, unsigned long ulExpectedReceived );
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Local pseudo random number seed and return functions. Used to avoid calls
|
||||||
|
* to the standard library.
|
||||||
|
*/
|
||||||
|
static unsigned long prvRand( void );
|
||||||
|
static void prvSRand( unsigned long ulSeed );
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/* The queues that are added to the set. */
|
/* The queues that are added to the set. */
|
||||||
|
@ -193,6 +200,9 @@ xAreQueeuSetTasksStillRunning() function can check it is incrementing as
|
||||||
expected. */
|
expected. */
|
||||||
static volatile unsigned long ulISRTxValue = queuesetINITIAL_ISR_TX_VALUE;
|
static volatile unsigned long ulISRTxValue = queuesetINITIAL_ISR_TX_VALUE;
|
||||||
|
|
||||||
|
/* Used by the pseudo random number generator. */
|
||||||
|
static unsigned long ulNextRand = 0;
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void vStartQueueSetTasks( void )
|
void vStartQueueSetTasks( void )
|
||||||
|
@ -264,25 +274,25 @@ portBASE_TYPE xReturn = pdPASS, x;
|
||||||
|
|
||||||
static void prvQueueSetSendingTask( void *pvParameters )
|
static void prvQueueSetSendingTask( void *pvParameters )
|
||||||
{
|
{
|
||||||
unsigned long ulTaskTxValue = 0;
|
unsigned long ulTaskTxValue = 0, ulQueueToWriteTo;
|
||||||
portBASE_TYPE xQueueToWriteTo;
|
|
||||||
xQueueHandle xQueueInUse;
|
xQueueHandle xQueueInUse;
|
||||||
unsigned portBASE_TYPE uxPriority = queuesetMEDIUM_PRIORITY, ulLoops = 0;
|
unsigned portBASE_TYPE uxPriority = queuesetMEDIUM_PRIORITY, ulLoops = 0;
|
||||||
|
|
||||||
/* Remove compiler warning about the unused parameter. */
|
/* Remove compiler warning about the unused parameter. */
|
||||||
( void ) pvParameters;
|
( void ) pvParameters;
|
||||||
|
|
||||||
srand( ( unsigned int ) &ulTaskTxValue );
|
/* Seed mini pseudo random number generator. */
|
||||||
|
prvSRand( ( unsigned long ) &ulTaskTxValue );
|
||||||
|
|
||||||
for( ;; )
|
for( ;; )
|
||||||
{
|
{
|
||||||
/* Generate the index for the queue to which a value is to be sent. */
|
/* Generate the index for the queue to which a value is to be sent. */
|
||||||
xQueueToWriteTo = rand() % queuesetNUM_QUEUES_IN_SET;
|
ulQueueToWriteTo = prvRand() % queuesetNUM_QUEUES_IN_SET;
|
||||||
xQueueInUse = xQueues[ xQueueToWriteTo ];
|
xQueueInUse = xQueues[ ulQueueToWriteTo ];
|
||||||
|
|
||||||
/* Note which index is being written to to ensure all the queues are
|
/* Note which index is being written to to ensure all the queues are
|
||||||
used. */
|
used. */
|
||||||
( ulQueueUsedCounter[ xQueueToWriteTo ] )++;
|
( ulQueueUsedCounter[ ulQueueToWriteTo ] )++;
|
||||||
|
|
||||||
/* Send to the queue to unblock the task that is waiting for data to
|
/* Send to the queue to unblock the task that is waiting for data to
|
||||||
arrive on a queue within the queue set to which this queue belongs. */
|
arrive on a queue within the queue set to which this queue belongs. */
|
||||||
|
@ -637,3 +647,17 @@ unsigned long ulValueToSend = 0;
|
||||||
/* Let the ISR access the queues also. */
|
/* Let the ISR access the queues also. */
|
||||||
xSetupComplete = pdTRUE;
|
xSetupComplete = pdTRUE;
|
||||||
}
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
static unsigned long prvRand( void )
|
||||||
|
{
|
||||||
|
ulNextRand = ( ulNextRand * 1103515245UL ) + 12345UL;
|
||||||
|
return (ulNextRand / 65536UL ) % 32768UL;
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
static void prvSRand( unsigned long ulSeed )
|
||||||
|
{
|
||||||
|
ulNextRand = ulSeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,14 +72,14 @@
|
||||||
*
|
*
|
||||||
* One counter task loops indefinitely, incrementing the shared count variable
|
* One counter task loops indefinitely, incrementing the shared count variable
|
||||||
* on each iteration. To ensure it has exclusive access to the variable it
|
* on each iteration. To ensure it has exclusive access to the variable it
|
||||||
* raises it's priority above that of the controller task before each
|
* raises its priority above that of the controller task before each
|
||||||
* increment, lowering it again to it's original priority before starting the
|
* increment, lowering it again to its original priority before starting the
|
||||||
* next iteration.
|
* next iteration.
|
||||||
*
|
*
|
||||||
* The other counter task increments the shared count variable on each
|
* The other counter task increments the shared count variable on each
|
||||||
* iteration of it's loop until the count has reached a limit of 0xff - at
|
* iteration of its loop until the count has reached a limit of 0xff - at
|
||||||
* which point it suspends itself. It will not start a new loop until the
|
* which point it suspends itself. It will not start a new loop until the
|
||||||
* controller task has made it "ready" again by calling vTaskResume ().
|
* controller task has made it "ready" again by calling vTaskResume().
|
||||||
* This second counter task operates at a higher priority than controller
|
* This second counter task operates at a higher priority than controller
|
||||||
* task so does not need to worry about mutual exclusion of the counter
|
* task so does not need to worry about mutual exclusion of the counter
|
||||||
* variable.
|
* variable.
|
||||||
|
@ -105,7 +105,7 @@
|
||||||
* continuous count task, and moves on to its second section.
|
* continuous count task, and moves on to its second section.
|
||||||
*
|
*
|
||||||
* At the start of the second section the shared variable is cleared to zero.
|
* At the start of the second section the shared variable is cleared to zero.
|
||||||
* The limited count task is then woken from it's suspension by a call to
|
* The limited count task is then woken from its suspension by a call to
|
||||||
* vTaskResume (). As this counter task operates at a higher priority than
|
* vTaskResume (). As this counter task operates at a higher priority than
|
||||||
* the controller task the controller task should not run again until the
|
* the controller task the controller task should not run again until the
|
||||||
* shared variable has been counted up to the limited value causing the counter
|
* shared variable has been counted up to the limited value causing the counter
|
||||||
|
@ -153,11 +153,11 @@ static portTASK_FUNCTION_PROTO( vQueueSendWhenSuspendedTask, pvParameters );
|
||||||
|
|
||||||
/* Handles to the two counter tasks. These could be passed in as parameters
|
/* Handles to the two counter tasks. These could be passed in as parameters
|
||||||
to the controller task to prevent them having to be file scope. */
|
to the controller task to prevent them having to be file scope. */
|
||||||
static xTaskHandle xContinousIncrementHandle, xLimitedIncrementHandle;
|
static xTaskHandle xContinuousIncrementHandle, xLimitedIncrementHandle;
|
||||||
|
|
||||||
/* The shared counter variable. This is passed in as a parameter to the two
|
/* The shared counter variable. This is passed in as a parameter to the two
|
||||||
counter variables for demonstration purposes. */
|
counter variables for demonstration purposes. */
|
||||||
static unsigned long ulCounter;
|
static volatile unsigned long ulCounter;
|
||||||
|
|
||||||
/* Variables used to check that the tasks are still operating without error.
|
/* Variables used to check that the tasks are still operating without error.
|
||||||
Each complete iteration of the controller task increments this variable
|
Each complete iteration of the controller task increments this variable
|
||||||
|
@ -192,7 +192,7 @@ void vStartDynamicPriorityTasks( void )
|
||||||
defined to be less than 1. */
|
defined to be less than 1. */
|
||||||
vQueueAddToRegistry( xSuspendedTestQueue, ( signed char * ) "Suspended_Test_Queue" );
|
vQueueAddToRegistry( xSuspendedTestQueue, ( signed char * ) "Suspended_Test_Queue" );
|
||||||
|
|
||||||
xTaskCreate( vContinuousIncrementTask, ( signed char * ) "CNT_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY, &xContinousIncrementHandle );
|
xTaskCreate( vContinuousIncrementTask, ( signed char * ) "CNT_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY, &xContinuousIncrementHandle );
|
||||||
xTaskCreate( vLimitedIncrementTask, ( signed char * ) "LIM_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY + 1, &xLimitedIncrementHandle );
|
xTaskCreate( vLimitedIncrementTask, ( signed char * ) "LIM_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY + 1, &xLimitedIncrementHandle );
|
||||||
xTaskCreate( vCounterControlTask, ( signed char * ) "C_CTRL", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
|
xTaskCreate( vCounterControlTask, ( signed char * ) "C_CTRL", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
|
||||||
xTaskCreate( vQueueSendWhenSuspendedTask, ( signed char * ) "SUSP_TX", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
|
xTaskCreate( vQueueSendWhenSuspendedTask, ( signed char * ) "SUSP_TX", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
|
||||||
|
@ -235,7 +235,7 @@ unsigned long *pulCounter;
|
||||||
*/
|
*/
|
||||||
static portTASK_FUNCTION( vContinuousIncrementTask, pvParameters )
|
static portTASK_FUNCTION( vContinuousIncrementTask, pvParameters )
|
||||||
{
|
{
|
||||||
unsigned long *pulCounter;
|
volatile unsigned long *pulCounter;
|
||||||
unsigned portBASE_TYPE uxOurPriority;
|
unsigned portBASE_TYPE uxOurPriority;
|
||||||
|
|
||||||
/* Take a pointer to the shared variable from the parameters passed into
|
/* Take a pointer to the shared variable from the parameters passed into
|
||||||
|
@ -248,11 +248,15 @@ unsigned portBASE_TYPE uxOurPriority;
|
||||||
|
|
||||||
for( ;; )
|
for( ;; )
|
||||||
{
|
{
|
||||||
/* Raise our priority above the controller task to ensure a context
|
/* Raise the priority above the controller task to ensure a context
|
||||||
switch does not occur while we are accessing this variable. */
|
switch does not occur while the variable is being accessed. */
|
||||||
vTaskPrioritySet( NULL, uxOurPriority + 1 );
|
vTaskPrioritySet( NULL, uxOurPriority + 1 );
|
||||||
|
{
|
||||||
|
configASSERT( ( uxTaskPriorityGet( NULL ) == ( uxOurPriority + 1 ) ) );
|
||||||
( *pulCounter )++;
|
( *pulCounter )++;
|
||||||
|
}
|
||||||
vTaskPrioritySet( NULL, uxOurPriority );
|
vTaskPrioritySet( NULL, uxOurPriority );
|
||||||
|
configASSERT( ( uxTaskPriorityGet( NULL ) == uxOurPriority ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
@ -280,10 +284,26 @@ short sError = pdFALSE;
|
||||||
for( sLoops = 0; sLoops < priLOOPS; sLoops++ )
|
for( sLoops = 0; sLoops < priLOOPS; sLoops++ )
|
||||||
{
|
{
|
||||||
/* Suspend the continuous count task so we can take a mirror of the
|
/* Suspend the continuous count task so we can take a mirror of the
|
||||||
shared variable without risk of corruption. */
|
shared variable without risk of corruption. This is not really
|
||||||
vTaskSuspend( xContinousIncrementHandle );
|
needed as the other task raises its priority above this task's
|
||||||
|
priority. */
|
||||||
|
vTaskSuspend( xContinuousIncrementHandle );
|
||||||
|
{
|
||||||
|
#if( INCLUDE_eTaskGetState == 1 )
|
||||||
|
{
|
||||||
|
configASSERT( eTaskGetState( xContinuousIncrementHandle ) == eSuspended );
|
||||||
|
}
|
||||||
|
#endif /* INCLUDE_eTaskGetState */
|
||||||
|
|
||||||
ulLastCounter = ulCounter;
|
ulLastCounter = ulCounter;
|
||||||
vTaskResume( xContinousIncrementHandle );
|
}
|
||||||
|
vTaskResume( xContinuousIncrementHandle );
|
||||||
|
|
||||||
|
#if( INCLUDE_eTaskGetState == 1 )
|
||||||
|
{
|
||||||
|
configASSERT( eTaskGetState( xContinuousIncrementHandle ) == eReady );
|
||||||
|
}
|
||||||
|
#endif /* INCLUDE_eTaskGetState */
|
||||||
|
|
||||||
/* Now delay to ensure the other task has processor time. */
|
/* Now delay to ensure the other task has processor time. */
|
||||||
vTaskDelay( priSLEEP_TIME );
|
vTaskDelay( priSLEEP_TIME );
|
||||||
|
@ -303,20 +323,34 @@ short sError = pdFALSE;
|
||||||
xTaskResumeAll();
|
xTaskResumeAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Second section: */
|
/* Second section: */
|
||||||
|
|
||||||
/* Suspend the continuous counter task so it stops accessing the shared variable. */
|
/* Suspend the continuous counter task so it stops accessing the shared
|
||||||
vTaskSuspend( xContinousIncrementHandle );
|
variable. */
|
||||||
|
vTaskSuspend( xContinuousIncrementHandle );
|
||||||
|
|
||||||
/* Reset the variable. */
|
/* Reset the variable. */
|
||||||
ulCounter = ( unsigned long ) 0;
|
ulCounter = ( unsigned long ) 0;
|
||||||
|
|
||||||
|
#if( INCLUDE_eTaskGetState == 1 )
|
||||||
|
{
|
||||||
|
configASSERT( eTaskGetState( xLimitedIncrementHandle ) == eSuspended );
|
||||||
|
}
|
||||||
|
#endif /* INCLUDE_eTaskGetState */
|
||||||
|
|
||||||
/* Resume the limited count task which has a higher priority than us.
|
/* Resume the limited count task which has a higher priority than us.
|
||||||
We should therefore not return from this call until the limited count
|
We should therefore not return from this call until the limited count
|
||||||
task has suspended itself with a known value in the counter variable. */
|
task has suspended itself with a known value in the counter variable. */
|
||||||
vTaskResume( xLimitedIncrementHandle );
|
vTaskResume( xLimitedIncrementHandle );
|
||||||
|
|
||||||
|
/* This task should not run again until xLimitedIncrementHandle has
|
||||||
|
suspended itself. */
|
||||||
|
#if( INCLUDE_eTaskGetState == 1 )
|
||||||
|
{
|
||||||
|
configASSERT( eTaskGetState( xLimitedIncrementHandle ) == eSuspended );
|
||||||
|
}
|
||||||
|
#endif /* INCLUDE_eTaskGetState */
|
||||||
|
|
||||||
/* Does the counter variable have the expected value? */
|
/* Does the counter variable have the expected value? */
|
||||||
if( ulCounter != priMAX_COUNT )
|
if( ulCounter != priMAX_COUNT )
|
||||||
{
|
{
|
||||||
|
@ -332,7 +366,7 @@ short sError = pdFALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Resume the continuous count task and do it all again. */
|
/* Resume the continuous count task and do it all again. */
|
||||||
vTaskResume( xContinousIncrementHandle );
|
vTaskResume( xContinuousIncrementHandle );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
|
@ -72,27 +72,27 @@
|
||||||
|
|
||||||
This demo creates three tasks all of which access the same recursive mutex:
|
This demo creates three tasks all of which access the same recursive mutex:
|
||||||
|
|
||||||
prvRecursiveMutexControllingTask() has the highest priority so executes
|
prvRecursiveMutexControllingTask() has the highest priority so executes
|
||||||
first and grabs the mutex. It then performs some recursive accesses -
|
first and grabs the mutex. It then performs some recursive accesses -
|
||||||
between each of which it sleeps for a short period to let the lower
|
between each of which it sleeps for a short period to let the lower
|
||||||
priority tasks execute. When it has completed its demo functionality
|
priority tasks execute. When it has completed its demo functionality
|
||||||
it gives the mutex back before suspending itself.
|
it gives the mutex back before suspending itself.
|
||||||
|
|
||||||
prvRecursiveMutexBlockingTask() attempts to access the mutex by performing
|
prvRecursiveMutexBlockingTask() attempts to access the mutex by performing
|
||||||
a blocking 'take'. The blocking task has a lower priority than the
|
a blocking 'take'. The blocking task has a lower priority than the
|
||||||
controlling task so by the time it executes the mutex has already been
|
controlling task so by the time it executes the mutex has already been
|
||||||
taken by the controlling task, causing the blocking task to block. It
|
taken by the controlling task, causing the blocking task to block. It
|
||||||
does not unblock until the controlling task has given the mutex back,
|
does not unblock until the controlling task has given the mutex back,
|
||||||
and it does not actually run until the controlling task has suspended
|
and it does not actually run until the controlling task has suspended
|
||||||
itself (due to the relative priorities). When it eventually does obtain
|
itself (due to the relative priorities). When it eventually does obtain
|
||||||
the mutex all it does is give the mutex back prior to also suspending
|
the mutex all it does is give the mutex back prior to also suspending
|
||||||
itself. At this point both the controlling task and the blocking task are
|
itself. At this point both the controlling task and the blocking task are
|
||||||
suspended.
|
suspended.
|
||||||
|
|
||||||
prvRecursiveMutexPollingTask() runs at the idle priority. It spins round
|
prvRecursiveMutexPollingTask() runs at the idle priority. It spins round
|
||||||
a tight loop attempting to obtain the mutex with a non-blocking call. As
|
a tight loop attempting to obtain the mutex with a non-blocking call. As
|
||||||
the lowest priority task it will not successfully obtain the mutex until
|
the lowest priority task it will not successfully obtain the mutex until
|
||||||
both the controlling and blocking tasks are suspended. Once it eventually
|
both the controlling and blocking tasks are suspended. Once it eventually
|
||||||
does obtain the mutex it first unsuspends both the controlling task and
|
does obtain the mutex it first unsuspends both the controlling task and
|
||||||
blocking task prior to giving the mutex back - resulting in the polling
|
blocking task prior to giving the mutex back - resulting in the polling
|
||||||
task temporarily inheriting the controlling tasks priority.
|
task temporarily inheriting the controlling tasks priority.
|
||||||
|
@ -117,7 +117,7 @@
|
||||||
/* Misc. */
|
/* Misc. */
|
||||||
#define recmuSHORT_DELAY ( 20 / portTICK_RATE_MS )
|
#define recmuSHORT_DELAY ( 20 / portTICK_RATE_MS )
|
||||||
#define recmuNO_DELAY ( ( portTickType ) 0 )
|
#define recmuNO_DELAY ( ( portTickType ) 0 )
|
||||||
#define recmuTWO_TICK_DELAY ( ( portTickType ) 2 )
|
#define recmuTHREE_TICK_DELAY ( ( portTickType ) 3 )
|
||||||
|
|
||||||
/* The three tasks as described at the top of this file. */
|
/* The three tasks as described at the top of this file. */
|
||||||
static void prvRecursiveMutexControllingTask( void *pvParameters );
|
static void prvRecursiveMutexControllingTask( void *pvParameters );
|
||||||
|
@ -131,7 +131,7 @@ static xSemaphoreHandle xMutex;
|
||||||
static volatile portBASE_TYPE xErrorOccurred = pdFALSE, xControllingIsSuspended = pdFALSE, xBlockingIsSuspended = pdFALSE;
|
static volatile portBASE_TYPE xErrorOccurred = pdFALSE, xControllingIsSuspended = pdFALSE, xBlockingIsSuspended = pdFALSE;
|
||||||
static volatile unsigned portBASE_TYPE uxControllingCycles = 0, uxBlockingCycles = 0, uxPollingCycles = 0;
|
static volatile unsigned portBASE_TYPE uxControllingCycles = 0, uxBlockingCycles = 0, uxPollingCycles = 0;
|
||||||
|
|
||||||
/* Handles of the two higher priority tasks, required so they can be resumed
|
/* Handles of the two higher priority tasks, required so they can be resumed
|
||||||
(unsuspended). */
|
(unsuspended). */
|
||||||
static xTaskHandle xControllingTaskHandle, xBlockingTaskHandle;
|
static xTaskHandle xControllingTaskHandle, xBlockingTaskHandle;
|
||||||
|
|
||||||
|
@ -144,10 +144,10 @@ void vStartRecursiveMutexTasks( void )
|
||||||
xMutex = xSemaphoreCreateRecursiveMutex();
|
xMutex = xSemaphoreCreateRecursiveMutex();
|
||||||
|
|
||||||
/* vQueueAddToRegistry() adds the mutex to the registry, if one is
|
/* vQueueAddToRegistry() adds the mutex to the registry, if one is
|
||||||
in use. The registry is provided as a means for kernel aware
|
in use. The registry is provided as a means for kernel aware
|
||||||
debuggers to locate mutex and has no purpose if a kernel aware debugger
|
debuggers to locate mutex and has no purpose if a kernel aware debugger
|
||||||
is not being used. The call to vQueueAddToRegistry() will be removed
|
is not being used. The call to vQueueAddToRegistry() will be removed
|
||||||
by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is
|
by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is
|
||||||
defined to be less than 1. */
|
defined to be less than 1. */
|
||||||
vQueueAddToRegistry( ( xQueueHandle ) xMutex, ( signed portCHAR * ) "Recursive_Mutex" );
|
vQueueAddToRegistry( ( xQueueHandle ) xMutex, ( signed portCHAR * ) "Recursive_Mutex" );
|
||||||
|
|
||||||
|
@ -183,7 +183,7 @@ unsigned portBASE_TYPE ux;
|
||||||
{
|
{
|
||||||
/* We should now be able to take the mutex as many times as
|
/* We should now be able to take the mutex as many times as
|
||||||
we like.
|
we like.
|
||||||
|
|
||||||
The first time through the mutex will be immediately available, on
|
The first time through the mutex will be immediately available, on
|
||||||
subsequent times through the mutex will be held by the polling task
|
subsequent times through the mutex will be held by the polling task
|
||||||
at this point and this Take will cause the polling task to inherit
|
at this point and this Take will cause the polling task to inherit
|
||||||
|
@ -191,14 +191,14 @@ unsigned portBASE_TYPE ux;
|
||||||
long enough to ensure the polling task will execute again before the
|
long enough to ensure the polling task will execute again before the
|
||||||
block time expires. If the block time does expire then the error
|
block time expires. If the block time does expire then the error
|
||||||
flag will be set here. */
|
flag will be set here. */
|
||||||
if( xSemaphoreTakeRecursive( xMutex, recmuTWO_TICK_DELAY ) != pdPASS )
|
if( xSemaphoreTakeRecursive( xMutex, recmuTHREE_TICK_DELAY ) != pdPASS )
|
||||||
{
|
{
|
||||||
xErrorOccurred = pdTRUE;
|
xErrorOccurred = pdTRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ensure the other task attempting to access the mutex (and the
|
/* Ensure the other task attempting to access the mutex (and the
|
||||||
other demo tasks) are able to execute to ensure they either block
|
other demo tasks) are able to execute to ensure they either block
|
||||||
(where a block time is specified) or return an error (where no
|
(where a block time is specified) or return an error (where no
|
||||||
block time is specified) as the mutex is held by this task. */
|
block time is specified) as the mutex is held by this task. */
|
||||||
vTaskDelay( recmuSHORT_DELAY );
|
vTaskDelay( recmuSHORT_DELAY );
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,7 @@ unsigned portBASE_TYPE ux;
|
||||||
xErrorOccurred = pdTRUE;
|
xErrorOccurred = pdTRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Keep count of the number of cycles this task has performed so a
|
/* Keep count of the number of cycles this task has performed so a
|
||||||
stall can be detected. */
|
stall can be detected. */
|
||||||
uxControllingCycles++;
|
uxControllingCycles++;
|
||||||
|
|
||||||
|
@ -249,10 +249,12 @@ static void prvRecursiveMutexBlockingTask( void *pvParameters )
|
||||||
{
|
{
|
||||||
/* This task will run while the controlling task is blocked, and the
|
/* This task will run while the controlling task is blocked, and the
|
||||||
controlling task will block only once it has the mutex - therefore
|
controlling task will block only once it has the mutex - therefore
|
||||||
this call should block until the controlling task has given up the
|
this call should block until the controlling task has given up the
|
||||||
mutex, and not actually execute past this call until the controlling
|
mutex, and not actually execute past this call until the controlling
|
||||||
task is suspended. */
|
task is suspended. portMAX_DELAY - 1 is used instead of portMAX_DELAY
|
||||||
if( xSemaphoreTakeRecursive( xMutex, portMAX_DELAY ) == pdPASS )
|
to ensure the task's state is reported as Blocked and not Suspended in
|
||||||
|
a later call to configASSERT() (within the polling task). */
|
||||||
|
if( xSemaphoreTakeRecursive( xMutex, ( portMAX_DELAY - 1 ) ) == pdPASS )
|
||||||
{
|
{
|
||||||
if( xControllingIsSuspended != pdTRUE )
|
if( xControllingIsSuspended != pdTRUE )
|
||||||
{
|
{
|
||||||
|
@ -287,7 +289,7 @@ static void prvRecursiveMutexBlockingTask( void *pvParameters )
|
||||||
xErrorOccurred = pdTRUE;
|
xErrorOccurred = pdTRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Keep count of the number of cycles this task has performed so a
|
/* Keep count of the number of cycles this task has performed so a
|
||||||
stall can be detected. */
|
stall can be detected. */
|
||||||
uxBlockingCycles++;
|
uxBlockingCycles++;
|
||||||
}
|
}
|
||||||
|
@ -306,6 +308,13 @@ static void prvRecursiveMutexPollingTask( void *pvParameters )
|
||||||
happen when the controlling task is also suspended. */
|
happen when the controlling task is also suspended. */
|
||||||
if( xSemaphoreTakeRecursive( xMutex, recmuNO_DELAY ) == pdPASS )
|
if( xSemaphoreTakeRecursive( xMutex, recmuNO_DELAY ) == pdPASS )
|
||||||
{
|
{
|
||||||
|
#if( INCLUDE_eTaskGetState == 1 )
|
||||||
|
{
|
||||||
|
configASSERT( eTaskGetState( xControllingTaskHandle ) == eSuspended );
|
||||||
|
configASSERT( eTaskGetState( xBlockingTaskHandle ) == eSuspended );
|
||||||
|
}
|
||||||
|
#endif /* INCLUDE_eTaskGetState */
|
||||||
|
|
||||||
/* Is the blocking task suspended? */
|
/* Is the blocking task suspended? */
|
||||||
if( ( xBlockingIsSuspended != pdTRUE ) || ( xControllingIsSuspended != pdTRUE ) )
|
if( ( xBlockingIsSuspended != pdTRUE ) || ( xControllingIsSuspended != pdTRUE ) )
|
||||||
{
|
{
|
||||||
|
@ -313,7 +322,7 @@ static void prvRecursiveMutexPollingTask( void *pvParameters )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Keep count of the number of cycles this task has performed
|
/* Keep count of the number of cycles this task has performed
|
||||||
so a stall can be detected. */
|
so a stall can be detected. */
|
||||||
uxPollingCycles++;
|
uxPollingCycles++;
|
||||||
|
|
||||||
|
@ -328,14 +337,27 @@ static void prvRecursiveMutexPollingTask( void *pvParameters )
|
||||||
mutex by the time this fixed period has expired. */
|
mutex by the time this fixed period has expired. */
|
||||||
vTaskResume( xBlockingTaskHandle );
|
vTaskResume( xBlockingTaskHandle );
|
||||||
vTaskResume( xControllingTaskHandle );
|
vTaskResume( xControllingTaskHandle );
|
||||||
|
|
||||||
/* The other two tasks should now have executed and no longer
|
/* The other two tasks should now have executed and no longer
|
||||||
be suspended. */
|
be suspended. */
|
||||||
if( ( xBlockingIsSuspended == pdTRUE ) || ( xControllingIsSuspended == pdTRUE ) )
|
if( ( xBlockingIsSuspended == pdTRUE ) || ( xControllingIsSuspended == pdTRUE ) )
|
||||||
{
|
{
|
||||||
xErrorOccurred = pdTRUE;
|
xErrorOccurred = pdTRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if( INCLUDE_uxTaskPriorityGet == 1 )
|
||||||
|
{
|
||||||
|
configASSERT( uxTaskPriorityGet( NULL ) == recmuCONTROLLING_TASK_PRIORITY );
|
||||||
|
}
|
||||||
|
#endif /* INCLUDE_uxTaskPriorityGet */
|
||||||
|
|
||||||
|
#if( INCLUDE_eTaskGetState == 1 )
|
||||||
|
{
|
||||||
|
configASSERT( eTaskGetState( xControllingTaskHandle ) == eBlocked );
|
||||||
|
configASSERT( eTaskGetState( xBlockingTaskHandle ) == eBlocked );
|
||||||
|
}
|
||||||
|
#endif /* INCLUDE_eTaskGetState */
|
||||||
|
|
||||||
/* Release the mutex, disinheriting the higher priority again. */
|
/* Release the mutex, disinheriting the higher priority again. */
|
||||||
if( xSemaphoreGiveRecursive( xMutex ) != pdPASS )
|
if( xSemaphoreGiveRecursive( xMutex ) != pdPASS )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue