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:
Richard Barry 2013-09-01 19:45:06 +00:00
parent 33bd63e287
commit ed399e801e
3 changed files with 132 additions and 52 deletions

View file

@ -72,27 +72,27 @@
This demo creates three tasks all of which access the same recursive mutex:
prvRecursiveMutexControllingTask() has the highest priority so executes
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
prvRecursiveMutexControllingTask() has the highest priority so executes
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
priority tasks execute. When it has completed its demo functionality
it gives the mutex back before suspending itself.
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
taken by the controlling task, causing the blocking task to block. It
does not unblock until the controlling task has given the mutex back,
and it does not actually run until the controlling task has suspended
taken by the controlling task, causing the blocking task to block. It
does not unblock until the controlling task has given the mutex back,
and it does not actually run until the controlling task has suspended
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
itself. At this point both the controlling task and the blocking task are
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
suspended.
prvRecursiveMutexPollingTask() runs at the idle priority. It spins round
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
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
blocking task prior to giving the mutex back - resulting in the polling
task temporarily inheriting the controlling tasks priority.
@ -117,7 +117,7 @@
/* Misc. */
#define recmuSHORT_DELAY ( 20 / portTICK_RATE_MS )
#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. */
static void prvRecursiveMutexControllingTask( void *pvParameters );
@ -131,7 +131,7 @@ static xSemaphoreHandle xMutex;
static volatile portBASE_TYPE xErrorOccurred = pdFALSE, xControllingIsSuspended = pdFALSE, xBlockingIsSuspended = pdFALSE;
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). */
static xTaskHandle xControllingTaskHandle, xBlockingTaskHandle;
@ -144,10 +144,10 @@ void vStartRecursiveMutexTasks( void )
xMutex = xSemaphoreCreateRecursiveMutex();
/* 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
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. */
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 like.
The first time through the mutex will be immediately available, on
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
@ -191,14 +191,14 @@ unsigned portBASE_TYPE ux;
long enough to ensure the polling task will execute again before the
block time expires. If the block time does expire then the error
flag will be set here. */
if( xSemaphoreTakeRecursive( xMutex, recmuTWO_TICK_DELAY ) != pdPASS )
if( xSemaphoreTakeRecursive( xMutex, recmuTHREE_TICK_DELAY ) != pdPASS )
{
xErrorOccurred = pdTRUE;
}
/* Ensure the other task attempting to access the mutex (and the
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. */
vTaskDelay( recmuSHORT_DELAY );
}
@ -228,7 +228,7 @@ unsigned portBASE_TYPE ux;
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. */
uxControllingCycles++;
@ -249,10 +249,12 @@ static void prvRecursiveMutexBlockingTask( void *pvParameters )
{
/* This task will run while the controlling task is blocked, and the
controlling task will block only once it has the mutex - therefore
this call should block until the controlling task has given up the
mutex, and not actually execute past this call until the controlling
task is suspended. */
if( xSemaphoreTakeRecursive( xMutex, portMAX_DELAY ) == pdPASS )
this call should block until the controlling task has given up the
mutex, and not actually execute past this call until the controlling
task is suspended. portMAX_DELAY - 1 is used instead of portMAX_DELAY
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 )
{
@ -287,7 +289,7 @@ static void prvRecursiveMutexBlockingTask( void *pvParameters )
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. */
uxBlockingCycles++;
}
@ -306,6 +308,13 @@ static void prvRecursiveMutexPollingTask( void *pvParameters )
happen when the controlling task is also suspended. */
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? */
if( ( xBlockingIsSuspended != pdTRUE ) || ( xControllingIsSuspended != pdTRUE ) )
{
@ -313,7 +322,7 @@ static void prvRecursiveMutexPollingTask( void *pvParameters )
}
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. */
uxPollingCycles++;
@ -328,14 +337,27 @@ static void prvRecursiveMutexPollingTask( void *pvParameters )
mutex by the time this fixed period has expired. */
vTaskResume( xBlockingTaskHandle );
vTaskResume( xControllingTaskHandle );
/* The other two tasks should now have executed and no longer
be suspended. */
if( ( xBlockingIsSuspended == pdTRUE ) || ( xControllingIsSuspended == 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. */
if( xSemaphoreGiveRecursive( xMutex ) != pdPASS )
{