mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-12-08 12:45:22 -05:00
Add uncrustify github workflow (#659)
* Add uncrustify github workflow * Fix exclusion pattern * fix find expression * exclude uncrustify files * Uncrustify common demo and test files * exlude white space checking files * Fix EOL whitespace checker * Remove whitespaces from EOL * Fix space at EOL * Fix find spaces at EOL Co-authored-by: Archit Aggarwal <architag@amazon.com>
This commit is contained in:
parent
dd80d615b5
commit
ae92d8c6ee
191 changed files with 17540 additions and 17102 deletions
32
.github/workflows/ci.yml
vendored
32
.github/workflows/ci.yml
vendored
|
|
@ -24,6 +24,38 @@ jobs:
|
|||
run: |
|
||||
git-secrets --register-aws
|
||||
git-secrets --scan
|
||||
|
||||
formatting:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Install Uncrustify
|
||||
run: sudo apt-get install uncrustify
|
||||
- name: Run Uncrustify
|
||||
run: |
|
||||
uncrustify --version
|
||||
find FreeRTOS/Demo/Common FreeRTOS/Test \( -name ethernet -o -name drivers -o -path 'FreeRTOS/Test/CMock/CMock' \) -prune -false -o -name "*.[hc]" -exec uncrustify --check -c tools/uncrustify.cfg {} +
|
||||
- name: Check For Trailing Whitespace
|
||||
run: |
|
||||
set +e
|
||||
ERROR=0
|
||||
find . \( -name '.git' -o -path "./FreeRTOS/Test/CBMC/patches" -o -path "./FreeRTOS-Plus" -o -path "./FreeRTOS/Source" -o -path "./FreeRTOS/Test/CMock/CMock" -o -path "./FreeRTOS/Demo" \) -prune -false -o -type f -a -name "*" -exec grep -In -e "[[:blank:]]$" {} +
|
||||
if [ "$?" = "0" ]; then
|
||||
echo "Files have trailing whitespace."
|
||||
ERROR=1
|
||||
fi
|
||||
|
||||
find FreeRTOS/Demo/Common \( -name "ethernet" \) -prune -o -false -o -type f -a -name "*" -exec grep --color=yes -In -e "[[:blank:]]$" {} +
|
||||
if [ "$?" = "0" ]; then
|
||||
echo "Files have trailing whitespace."
|
||||
exit 1
|
||||
else
|
||||
if [ "$ERROR" -eq "1" ]; then
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
doxygen:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ int main()
|
|||
#error "Invalid Selection...\nPlease Select a Demo application from the main command"
|
||||
}
|
||||
#endif /* if ( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 ) */
|
||||
snprint
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ static void prvRWAccessTask( void * pvParameters );
|
|||
|
||||
static void prvROAccessTask( void * pvParameters )
|
||||
{
|
||||
uint8_t ucVal;
|
||||
uint8_t ucVal;
|
||||
|
||||
/* Unused parameters. */
|
||||
( void ) pvParameters;
|
||||
|
|
@ -123,36 +123,38 @@ static void prvRWAccessTask( void * pvParameters )
|
|||
|
||||
void vStartMPUDemo( void )
|
||||
{
|
||||
static StackType_t xROAccessTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) );
|
||||
static StackType_t xRWAccessTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) );
|
||||
TaskParameters_t xROAccessTaskParameters =
|
||||
{
|
||||
static StackType_t xROAccessTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) );
|
||||
static StackType_t xRWAccessTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) );
|
||||
TaskParameters_t xROAccessTaskParameters =
|
||||
{
|
||||
.pvTaskCode = prvROAccessTask,
|
||||
.pcName = "ROAccess",
|
||||
.usStackDepth = configMINIMAL_STACK_SIZE,
|
||||
.pvParameters = NULL,
|
||||
.uxPriority = tskIDLE_PRIORITY,
|
||||
.puxStackBuffer = xROAccessTaskStack,
|
||||
.xRegions = {
|
||||
.xRegions =
|
||||
{
|
||||
{ ucSharedMemory, 32, tskMPU_REGION_READ_ONLY | tskMPU_REGION_EXECUTE_NEVER },
|
||||
{ ucROTaskFaultTracker, 32, tskMPU_REGION_READ_WRITE | tskMPU_REGION_EXECUTE_NEVER },
|
||||
{ 0, 0, 0 },
|
||||
}
|
||||
};
|
||||
TaskParameters_t xRWAccessTaskParameters =
|
||||
{
|
||||
};
|
||||
TaskParameters_t xRWAccessTaskParameters =
|
||||
{
|
||||
.pvTaskCode = prvRWAccessTask,
|
||||
.pcName = "RWAccess",
|
||||
.usStackDepth = configMINIMAL_STACK_SIZE,
|
||||
.pvParameters = NULL,
|
||||
.uxPriority = tskIDLE_PRIORITY,
|
||||
.puxStackBuffer = xRWAccessTaskStack,
|
||||
.xRegions = {
|
||||
.xRegions =
|
||||
{
|
||||
{ ucSharedMemory, 32, tskMPU_REGION_READ_WRITE | tskMPU_REGION_EXECUTE_NEVER },
|
||||
{ 0, 0, 0 },
|
||||
{ 0, 0, 0 },
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/* Create an unprivileged task with RO access to ucSharedMemory. */
|
||||
xTaskCreateRestricted( &( xROAccessTaskParameters ), NULL );
|
||||
|
|
@ -164,8 +166,8 @@ TaskParameters_t xRWAccessTaskParameters =
|
|||
|
||||
portDONT_DISCARD void vHandleMemoryFault( uint32_t * pulFaultStackAddress )
|
||||
{
|
||||
uint32_t ulPC;
|
||||
uint16_t usOffendingInstruction;
|
||||
uint32_t ulPC;
|
||||
uint16_t usOffendingInstruction;
|
||||
|
||||
/* Is this an expected fault? */
|
||||
if( ucROTaskFaultTracker[ 0 ] == 1 )
|
||||
|
|
@ -174,7 +176,7 @@ uint16_t usOffendingInstruction;
|
|||
ulPC = pulFaultStackAddress[ 6 ];
|
||||
|
||||
/* Read the offending instruction. */
|
||||
usOffendingInstruction = *( uint16_t * )ulPC;
|
||||
usOffendingInstruction = *( uint16_t * ) ulPC;
|
||||
|
||||
/* From ARM docs:
|
||||
* If the value of bits[15:11] of the halfword being decoded is one of
|
||||
|
|
@ -192,9 +194,9 @@ uint16_t usOffendingInstruction;
|
|||
|
||||
/* Determine if the offending instruction is a 32-bit instruction or
|
||||
* a 16-bit instruction. */
|
||||
if( usOffendingInstruction == 0x001F ||
|
||||
usOffendingInstruction == 0x001E ||
|
||||
usOffendingInstruction == 0x001D )
|
||||
if( ( usOffendingInstruction == 0x001F ) ||
|
||||
( usOffendingInstruction == 0x001E ) ||
|
||||
( usOffendingInstruction == 0x001D ) )
|
||||
{
|
||||
/* Since the offending instruction is a 32-bit instruction,
|
||||
* increment the program counter by 4 to move to the next
|
||||
|
|
|
|||
|
|
@ -37,12 +37,12 @@ static uint32_t ulSecureCounter = 0;
|
|||
/**
|
||||
* @brief typedef for non-secure callback.
|
||||
*/
|
||||
typedef void ( *NonSecureCallback_t ) ( void ) __attribute__( ( cmse_nonsecure_call ) );
|
||||
typedef void ( *NonSecureCallback_t )( void ) __attribute__( ( cmse_nonsecure_call ) );
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
secureportNON_SECURE_CALLABLE uint32_t NSCFunction( Callback_t pxCallback )
|
||||
{
|
||||
NonSecureCallback_t pxNonSecureCallback;
|
||||
NonSecureCallback_t pxNonSecureCallback;
|
||||
|
||||
/* Return function pointer with cleared LSB. */
|
||||
pxNonSecureCallback = ( NonSecureCallback_t ) cmse_nsfptr_create( pxCallback );
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
/**
|
||||
* @brief Callback function pointer definition.
|
||||
*/
|
||||
typedef void ( *Callback_t ) ( void );
|
||||
typedef void ( * Callback_t ) ( void );
|
||||
|
||||
/**
|
||||
* @brief Invokes the supplied callback which is on the non-secure side.
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@
|
|||
* 4 bytes and upto 32 bytes will also fall in the same MPU region and the task
|
||||
* having access to ulNonSecureCounter will also have access to all those items.
|
||||
*/
|
||||
static uint32_t ulNonSecureCounter[8] __attribute__( ( aligned( 32 ) ) ) = { 0 };
|
||||
static uint32_t ulNonSecureCounter[ 8 ] __attribute__( ( aligned( 32 ) ) ) = { 0 };
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
|
|
@ -68,21 +68,22 @@ static void prvSecureCallingTask( void * pvParameters );
|
|||
|
||||
void vStartTZDemo( void )
|
||||
{
|
||||
static StackType_t xSecureCallingTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) );
|
||||
TaskParameters_t xSecureCallingTaskParameters =
|
||||
{
|
||||
static StackType_t xSecureCallingTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) );
|
||||
TaskParameters_t xSecureCallingTaskParameters =
|
||||
{
|
||||
.pvTaskCode = prvSecureCallingTask,
|
||||
.pcName = "SecCalling",
|
||||
.usStackDepth = configMINIMAL_STACK_SIZE,
|
||||
.pvParameters = NULL,
|
||||
.uxPriority = tskIDLE_PRIORITY,
|
||||
.puxStackBuffer = xSecureCallingTaskStack,
|
||||
.xRegions = {
|
||||
.xRegions =
|
||||
{
|
||||
{ ulNonSecureCounter, 32, tskMPU_REGION_READ_WRITE | tskMPU_REGION_EXECUTE_NEVER },
|
||||
{ 0, 0, 0 },
|
||||
{ 0, 0, 0 },
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/* Create an unprivileged task which calls secure functions. */
|
||||
xTaskCreateRestricted( &( xSecureCallingTaskParameters ), NULL );
|
||||
|
|
@ -100,8 +101,8 @@ static void prvCallback( void )
|
|||
|
||||
static void prvSecureCallingTask( void * pvParameters )
|
||||
{
|
||||
uint32_t ulLastSecureCounter = 0, ulLastNonSecureCounter = 0;
|
||||
uint32_t ulCurrentSecureCounter = 0;
|
||||
uint32_t ulLastSecureCounter = 0, ulLastNonSecureCounter = 0;
|
||||
uint32_t ulCurrentSecureCounter = 0;
|
||||
|
||||
/* This task calls secure side functions. So allocate a secure context for
|
||||
* it. */
|
||||
|
|
|
|||
|
|
@ -53,21 +53,21 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
Changes from V1.00:
|
||||
|
||||
* Changes from V1.00:
|
||||
*
|
||||
+ Reversed the priority and block times of the second two demo tasks so
|
||||
they operate as per the description above.
|
||||
|
||||
Changes from V2.0.0
|
||||
|
||||
+ they operate as per the description above.
|
||||
+
|
||||
+ Changes from V2.0.0
|
||||
+
|
||||
+ Delay periods are now specified using variables and constants of
|
||||
TickType_t rather than unsigned long.
|
||||
|
||||
Changes from V4.0.2
|
||||
|
||||
+ TickType_t rather than unsigned long.
|
||||
+
|
||||
+ Changes from V4.0.2
|
||||
+
|
||||
+ The second set of tasks were created the wrong way around. This has been
|
||||
corrected.
|
||||
*/
|
||||
+ corrected.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
|
|
@ -89,35 +89,35 @@ typedef struct BLOCKING_QUEUE_PARAMETERS
|
|||
{
|
||||
QueueHandle_t xQueue; /*< The queue to be used by the task. */
|
||||
TickType_t xBlockTime; /*< The block time to use on queue reads/writes. */
|
||||
volatile short *psCheckVariable; /*< Incremented on each successful cycle to check the task is still running. */
|
||||
volatile short * psCheckVariable; /*< Incremented on each successful cycle to check the task is still running. */
|
||||
} xBlockingQueueParameters;
|
||||
|
||||
/* Task function that creates an incrementing number and posts it on a queue. */
|
||||
static void vBlockingQueueProducer( void *pvParameters );
|
||||
static void vBlockingQueueProducer( void * pvParameters );
|
||||
|
||||
/* Task function that removes the incrementing number from a queue and checks that
|
||||
it is the expected number. */
|
||||
static void vBlockingQueueConsumer( void *pvParameters );
|
||||
* it is the expected number. */
|
||||
static void vBlockingQueueConsumer( void * pvParameters );
|
||||
|
||||
/* Variables which are incremented each time an item is removed from a queue, and
|
||||
found to be the expected value.
|
||||
These are used to check that the tasks are still running. */
|
||||
* found to be the expected value.
|
||||
* These are used to check that the tasks are still running. */
|
||||
static volatile short sBlockingConsumerCount[ blckqNUM_TASK_SETS ] = { ( short ) 0, ( short ) 0, ( short ) 0 };
|
||||
|
||||
/* Variable which are incremented each time an item is posted on a queue. These
|
||||
are used to check that the tasks are still running. */
|
||||
* are used to check that the tasks are still running. */
|
||||
static volatile short sBlockingProducerCount[ blckqNUM_TASK_SETS ] = { ( short ) 0, ( short ) 0, ( short ) 0 };
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vStartBlockingQueueTasks( unsigned portBASE_TYPE uxPriority )
|
||||
{
|
||||
xBlockingQueueParameters *pxQueueParameters1, *pxQueueParameters2;
|
||||
xBlockingQueueParameters *pxQueueParameters3, *pxQueueParameters4;
|
||||
xBlockingQueueParameters *pxQueueParameters5, *pxQueueParameters6;
|
||||
const unsigned portBASE_TYPE uxQueueSize1 = 1, uxQueueSize5 = 5;
|
||||
const TickType_t xBlockTime = ( TickType_t ) 1000 / portTICK_PERIOD_MS;
|
||||
const TickType_t xDontBlock = ( TickType_t ) 0;
|
||||
xBlockingQueueParameters * pxQueueParameters1, * pxQueueParameters2;
|
||||
xBlockingQueueParameters * pxQueueParameters3, * pxQueueParameters4;
|
||||
xBlockingQueueParameters * pxQueueParameters5, * pxQueueParameters6;
|
||||
const unsigned portBASE_TYPE uxQueueSize1 = 1, uxQueueSize5 = 5;
|
||||
const TickType_t xBlockTime = ( TickType_t ) 1000 / portTICK_PERIOD_MS;
|
||||
const TickType_t xDontBlock = ( TickType_t ) 0;
|
||||
|
||||
/* Create the first two tasks as described at the top of the file. */
|
||||
|
||||
|
|
@ -125,14 +125,14 @@ const TickType_t xDontBlock = ( TickType_t ) 0;
|
|||
pxQueueParameters1 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
|
||||
|
||||
/* Create the queue used by the first two tasks to pass the incrementing number.
|
||||
Pass a pointer to the queue in the parameter structure. */
|
||||
* Pass a pointer to the queue in the parameter structure. */
|
||||
pxQueueParameters1->xQueue = xQueueCreate( uxQueueSize1, ( unsigned portBASE_TYPE ) sizeof( unsigned short ) );
|
||||
|
||||
/* The consumer is created first so gets a block time as described above. */
|
||||
pxQueueParameters1->xBlockTime = xBlockTime;
|
||||
|
||||
/* Pass in the variable that this task is going to increment so we can check it
|
||||
is still running. */
|
||||
* is still running. */
|
||||
pxQueueParameters1->psCheckVariable = &( sBlockingConsumerCount[ 0 ] );
|
||||
|
||||
/* Create the structure used to pass parameters to the producer task. */
|
||||
|
|
@ -142,23 +142,23 @@ const TickType_t xDontBlock = ( TickType_t ) 0;
|
|||
pxQueueParameters2->xQueue = pxQueueParameters1->xQueue;
|
||||
|
||||
/* The producer is not going to block - as soon as it posts the consumer will
|
||||
wake and remove the item so the producer should always have room to post. */
|
||||
* wake and remove the item so the producer should always have room to post. */
|
||||
pxQueueParameters2->xBlockTime = xDontBlock;
|
||||
|
||||
/* Pass in the variable that this task is going to increment so we can check
|
||||
it is still running. */
|
||||
* it is still running. */
|
||||
pxQueueParameters2->psCheckVariable = &( sBlockingProducerCount[ 0 ] );
|
||||
|
||||
|
||||
/* Note the producer has a lower priority than the consumer when the tasks are
|
||||
spawned. */
|
||||
* spawned. */
|
||||
xTaskCreate( vBlockingQueueConsumer, "QConsB1", blckqSTACK_SIZE, ( void * ) pxQueueParameters1, uxPriority, NULL );
|
||||
xTaskCreate( vBlockingQueueProducer, "QProdB2", blckqSTACK_SIZE, ( void * ) pxQueueParameters2, tskIDLE_PRIORITY, NULL );
|
||||
|
||||
|
||||
|
||||
/* Create the second two tasks as described at the top of the file. This uses
|
||||
the same mechanism but reverses the task priorities. */
|
||||
* the same mechanism but reverses the task priorities. */
|
||||
|
||||
pxQueueParameters3 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
|
||||
pxQueueParameters3->xQueue = xQueueCreate( uxQueueSize1, ( unsigned portBASE_TYPE ) sizeof( unsigned short ) );
|
||||
|
|
@ -176,7 +176,7 @@ const TickType_t xDontBlock = ( TickType_t ) 0;
|
|||
|
||||
|
||||
/* Create the last two tasks as described above. The mechanism is again just
|
||||
the same. This time both parameter structures are given a block time. */
|
||||
* the same. This time both parameter structures are given a block time. */
|
||||
pxQueueParameters5 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
|
||||
pxQueueParameters5->xQueue = xQueueCreate( uxQueueSize5, ( unsigned portBASE_TYPE ) sizeof( unsigned short ) );
|
||||
pxQueueParameters5->xBlockTime = xBlockTime;
|
||||
|
|
@ -192,20 +192,20 @@ const TickType_t xDontBlock = ( TickType_t ) 0;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vBlockingQueueProducer( void *pvParameters )
|
||||
static void vBlockingQueueProducer( void * pvParameters )
|
||||
{
|
||||
unsigned short usValue = 0;
|
||||
xBlockingQueueParameters *pxQueueParameters;
|
||||
const char * const pcTaskStartMsg = "Blocking queue producer started.\r\n";
|
||||
const char * const pcTaskErrorMsg = "Could not post on blocking queue\r\n";
|
||||
short sErrorEverOccurred = pdFALSE;
|
||||
unsigned short usValue = 0;
|
||||
xBlockingQueueParameters * pxQueueParameters;
|
||||
const char * const pcTaskStartMsg = "Blocking queue producer started.\r\n";
|
||||
const char * const pcTaskErrorMsg = "Could not post on blocking queue\r\n";
|
||||
short sErrorEverOccurred = pdFALSE;
|
||||
|
||||
pxQueueParameters = ( xBlockingQueueParameters * ) pvParameters;
|
||||
|
||||
/* Queue a message for printing to say the task has started. */
|
||||
vPrintDisplayMessage( &pcTaskStartMsg );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
if( xQueueSendToBack( pxQueueParameters->xQueue, ( void * ) &usValue, pxQueueParameters->xBlockTime ) != pdPASS )
|
||||
{
|
||||
|
|
@ -215,34 +215,34 @@ short sErrorEverOccurred = pdFALSE;
|
|||
else
|
||||
{
|
||||
/* We have successfully posted a message, so increment the variable
|
||||
used to check we are still running. */
|
||||
* used to check we are still running. */
|
||||
if( sErrorEverOccurred == pdFALSE )
|
||||
{
|
||||
( *pxQueueParameters->psCheckVariable )++;
|
||||
}
|
||||
|
||||
/* Increment the variable we are going to post next time round. The
|
||||
consumer will expect the numbers to follow in numerical order. */
|
||||
* consumer will expect the numbers to follow in numerical order. */
|
||||
++usValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vBlockingQueueConsumer( void *pvParameters )
|
||||
static void vBlockingQueueConsumer( void * pvParameters )
|
||||
{
|
||||
unsigned short usData, usExpectedValue = 0;
|
||||
xBlockingQueueParameters *pxQueueParameters;
|
||||
const char * const pcTaskStartMsg = "Blocking queue consumer started.\r\n";
|
||||
const char * const pcTaskErrorMsg = "Incorrect value received on blocking queue.\r\n";
|
||||
short sErrorEverOccurred = pdFALSE;
|
||||
unsigned short usData, usExpectedValue = 0;
|
||||
xBlockingQueueParameters * pxQueueParameters;
|
||||
const char * const pcTaskStartMsg = "Blocking queue consumer started.\r\n";
|
||||
const char * const pcTaskErrorMsg = "Incorrect value received on blocking queue.\r\n";
|
||||
short sErrorEverOccurred = pdFALSE;
|
||||
|
||||
/* Queue a message for printing to say the task has started. */
|
||||
vPrintDisplayMessage( &pcTaskStartMsg );
|
||||
|
||||
pxQueueParameters = ( xBlockingQueueParameters * ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
if( xQueueReceive( pxQueueParameters->xQueue, &usData, pxQueueParameters->xBlockTime ) == pdPASS )
|
||||
{
|
||||
|
|
@ -258,14 +258,14 @@ short sErrorEverOccurred = pdFALSE;
|
|||
else
|
||||
{
|
||||
/* We have successfully received a message, so increment the
|
||||
variable used to check we are still running. */
|
||||
* variable used to check we are still running. */
|
||||
if( sErrorEverOccurred == pdFALSE )
|
||||
{
|
||||
( *pxQueueParameters->psCheckVariable )++;
|
||||
}
|
||||
|
||||
/* Increment the value we expect to remove from the queue next time
|
||||
round. */
|
||||
* round. */
|
||||
++usExpectedValue;
|
||||
}
|
||||
}
|
||||
|
|
@ -276,16 +276,16 @@ short sErrorEverOccurred = pdFALSE;
|
|||
/* This is called to check that all the created tasks are still running. */
|
||||
portBASE_TYPE xAreBlockingQueuesStillRunning( void )
|
||||
{
|
||||
static short sLastBlockingConsumerCount[ blckqNUM_TASK_SETS ] = { ( short ) 0, ( short ) 0, ( short ) 0 };
|
||||
static short sLastBlockingProducerCount[ blckqNUM_TASK_SETS ] = { ( short ) 0, ( short ) 0, ( short ) 0 };
|
||||
portBASE_TYPE xReturn = pdPASS, xTasks;
|
||||
static short sLastBlockingConsumerCount[ blckqNUM_TASK_SETS ] = { ( short ) 0, ( short ) 0, ( short ) 0 };
|
||||
static short sLastBlockingProducerCount[ blckqNUM_TASK_SETS ] = { ( short ) 0, ( short ) 0, ( short ) 0 };
|
||||
portBASE_TYPE xReturn = pdPASS, xTasks;
|
||||
|
||||
/* Not too worried about mutual exclusion on these variables as they are 16
|
||||
bits and we are only reading them. We also only care to see if they have
|
||||
changed or not.
|
||||
|
||||
Loop through each check variable and return pdFALSE if any are found not
|
||||
to have changed since the last call. */
|
||||
* bits and we are only reading them. We also only care to see if they have
|
||||
* changed or not.
|
||||
*
|
||||
* Loop through each check variable and return pdFALSE if any are found not
|
||||
* to have changed since the last call. */
|
||||
|
||||
for( xTasks = 0; xTasks < blckqNUM_TASK_SETS; xTasks++ )
|
||||
{
|
||||
|
|
@ -293,16 +293,16 @@ portBASE_TYPE xReturn = pdPASS, xTasks;
|
|||
{
|
||||
xReturn = pdFALSE;
|
||||
}
|
||||
sLastBlockingConsumerCount[ xTasks ] = sBlockingConsumerCount[ xTasks ];
|
||||
|
||||
sLastBlockingConsumerCount[ xTasks ] = sBlockingConsumerCount[ xTasks ];
|
||||
|
||||
if( sBlockingProducerCount[ xTasks ] == sLastBlockingProducerCount[ xTasks ] )
|
||||
{
|
||||
xReturn = pdFALSE;
|
||||
}
|
||||
|
||||
sLastBlockingProducerCount[ xTasks ] = sBlockingProducerCount[ xTasks ];
|
||||
}
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,11 +53,11 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
Changes from V2.0.0
|
||||
|
||||
* Changes from V2.0.0
|
||||
*
|
||||
+ Delay periods are now specified using variables and constants of
|
||||
TickType_t rather than unsigned long.
|
||||
*/
|
||||
+ TickType_t rather than unsigned long.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -73,10 +73,10 @@ Changes from V2.0.0
|
|||
#define pollqSTACK_SIZE ( ( unsigned short ) configMINIMAL_STACK_SIZE )
|
||||
|
||||
/* The task that posts the incrementing number onto the queue. */
|
||||
static void vPolledQueueProducer( void *pvParameters );
|
||||
static void vPolledQueueProducer( void * pvParameters );
|
||||
|
||||
/* The task that empties the queue. */
|
||||
static void vPolledQueueConsumer( void *pvParameters );
|
||||
static void vPolledQueueConsumer( void * pvParameters );
|
||||
|
||||
/* Variables that are used to check that the tasks are still running with no errors. */
|
||||
static volatile short sPollingConsumerCount = 0, sPollingProducerCount = 0;
|
||||
|
|
@ -84,8 +84,8 @@ static volatile short sPollingConsumerCount = 0, sPollingProducerCount = 0;
|
|||
|
||||
void vStartPolledQueueTasks( unsigned portBASE_TYPE uxPriority )
|
||||
{
|
||||
static QueueHandle_t xPolledQueue;
|
||||
const unsigned portBASE_TYPE uxQueueSize = 10;
|
||||
static QueueHandle_t xPolledQueue;
|
||||
const unsigned portBASE_TYPE uxQueueSize = 10;
|
||||
|
||||
/* Create the queue used by the producer and consumer. */
|
||||
xPolledQueue = xQueueCreate( uxQueueSize, ( unsigned portBASE_TYPE ) sizeof( unsigned short ) );
|
||||
|
|
@ -96,15 +96,15 @@ const unsigned portBASE_TYPE uxQueueSize = 10;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vPolledQueueProducer( void *pvParameters )
|
||||
static void vPolledQueueProducer( void * pvParameters )
|
||||
{
|
||||
unsigned short usValue = 0, usLoop;
|
||||
QueueHandle_t *pxQueue;
|
||||
const TickType_t xDelay = ( TickType_t ) 200 / portTICK_PERIOD_MS;
|
||||
const unsigned short usNumToProduce = 3;
|
||||
const char * const pcTaskStartMsg = "Polled queue producer started.\r\n";
|
||||
const char * const pcTaskErrorMsg = "Could not post on polled queue.\r\n";
|
||||
short sError = pdFALSE;
|
||||
unsigned short usValue = 0, usLoop;
|
||||
QueueHandle_t * pxQueue;
|
||||
const TickType_t xDelay = ( TickType_t ) 200 / portTICK_PERIOD_MS;
|
||||
const unsigned short usNumToProduce = 3;
|
||||
const char * const pcTaskStartMsg = "Polled queue producer started.\r\n";
|
||||
const char * const pcTaskErrorMsg = "Could not post on polled queue.\r\n";
|
||||
short sError = pdFALSE;
|
||||
|
||||
/* Queue a message for printing to say the task has started. */
|
||||
vPrintDisplayMessage( &pcTaskStartMsg );
|
||||
|
|
@ -112,7 +112,7 @@ short sError = pdFALSE;
|
|||
/* The queue being used is passed in as the parameter. */
|
||||
pxQueue = ( QueueHandle_t * ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
for( usLoop = 0; usLoop < usNumToProduce; ++usLoop )
|
||||
{
|
||||
|
|
@ -128,7 +128,7 @@ short sError = pdFALSE;
|
|||
if( sError == pdFALSE )
|
||||
{
|
||||
/* If an error has ever been recorded we stop incrementing the
|
||||
check variable. */
|
||||
* check variable. */
|
||||
++sPollingProducerCount;
|
||||
}
|
||||
|
||||
|
|
@ -138,20 +138,20 @@ short sError = pdFALSE;
|
|||
}
|
||||
|
||||
/* Wait before we start posting again to ensure the consumer runs and
|
||||
empties the queue. */
|
||||
* empties the queue. */
|
||||
vTaskDelay( xDelay );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vPolledQueueConsumer( void *pvParameters )
|
||||
static void vPolledQueueConsumer( void * pvParameters )
|
||||
{
|
||||
unsigned short usData, usExpectedValue = 0;
|
||||
QueueHandle_t *pxQueue;
|
||||
const TickType_t xDelay = ( TickType_t ) 200 / portTICK_PERIOD_MS;
|
||||
const char * const pcTaskStartMsg = "Polled queue consumer started.\r\n";
|
||||
const char * const pcTaskErrorMsg = "Incorrect value received on polled queue.\r\n";
|
||||
short sError = pdFALSE;
|
||||
unsigned short usData, usExpectedValue = 0;
|
||||
QueueHandle_t * pxQueue;
|
||||
const TickType_t xDelay = ( TickType_t ) 200 / portTICK_PERIOD_MS;
|
||||
const char * const pcTaskStartMsg = "Polled queue consumer started.\r\n";
|
||||
const char * const pcTaskErrorMsg = "Incorrect value received on polled queue.\r\n";
|
||||
short sError = pdFALSE;
|
||||
|
||||
/* Queue a message for printing to say the task has started. */
|
||||
vPrintDisplayMessage( &pcTaskStartMsg );
|
||||
|
|
@ -159,7 +159,7 @@ short sError = pdFALSE;
|
|||
/* The queue being used is passed in as the parameter. */
|
||||
pxQueue = ( QueueHandle_t * ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Loop until the queue is empty. */
|
||||
while( uxQueueMessagesWaiting( *pxQueue ) )
|
||||
|
|
@ -169,11 +169,12 @@ short sError = pdFALSE;
|
|||
if( usData != usExpectedValue )
|
||||
{
|
||||
/* This is not what we expected to receive so an error has
|
||||
occurred. */
|
||||
* occurred. */
|
||||
vPrintDisplayMessage( &pcTaskErrorMsg );
|
||||
sError = pdTRUE;
|
||||
|
||||
/* Catch-up to the value we received so our next expected value
|
||||
should again be correct. */
|
||||
* should again be correct. */
|
||||
usExpectedValue = usData;
|
||||
}
|
||||
else
|
||||
|
|
@ -181,16 +182,17 @@ short sError = pdFALSE;
|
|||
if( sError == pdFALSE )
|
||||
{
|
||||
/* Only increment the check variable if no errors have
|
||||
occurred. */
|
||||
* occurred. */
|
||||
++sPollingConsumerCount;
|
||||
}
|
||||
}
|
||||
|
||||
++usExpectedValue;
|
||||
}
|
||||
}
|
||||
|
||||
/* Now the queue is empty we block, allowing the producer to place more
|
||||
items in the queue. */
|
||||
* items in the queue. */
|
||||
vTaskDelay( xDelay );
|
||||
}
|
||||
}
|
||||
|
|
@ -199,8 +201,8 @@ short sError = pdFALSE;
|
|||
/* This is called to check that all the created tasks are still running with no errors. */
|
||||
portBASE_TYPE xArePollingQueuesStillRunning( void )
|
||||
{
|
||||
static short sLastPollingConsumerCount = 0, sLastPollingProducerCount = 0;
|
||||
portBASE_TYPE xReturn;
|
||||
static short sLastPollingConsumerCount = 0, sLastPollingProducerCount = 0;
|
||||
portBASE_TYPE xReturn;
|
||||
|
||||
if( ( sLastPollingConsumerCount == sPollingConsumerCount ) ||
|
||||
( sLastPollingProducerCount == sPollingProducerCount )
|
||||
|
|
|
|||
|
|
@ -55,36 +55,36 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
Changes from V1.00:
|
||||
|
||||
* Changes from V1.00:
|
||||
*
|
||||
+ The priority of the Rx task has been lowered. Received characters are
|
||||
now processed (read from the queue) at the idle priority, allowing low
|
||||
priority tasks to run evenly at times of a high communications overhead.
|
||||
|
||||
Changes from V1.01:
|
||||
|
||||
+ now processed (read from the queue) at the idle priority, allowing low
|
||||
+ priority tasks to run evenly at times of a high communications overhead.
|
||||
+
|
||||
+ Changes from V1.01:
|
||||
+
|
||||
+ The Tx task now waits a pseudo random time between transmissions.
|
||||
Previously a fixed period was used but this was not such a good test as
|
||||
interrupts fired at regular intervals.
|
||||
|
||||
Changes From V1.2.0:
|
||||
|
||||
+ Previously a fixed period was used but this was not such a good test as
|
||||
+ interrupts fired at regular intervals.
|
||||
+
|
||||
+ Changes From V1.2.0:
|
||||
+
|
||||
+ Use vSerialPutString() instead of single character puts.
|
||||
+ Only stop the check variable incrementing after two consecutive errors.
|
||||
|
||||
Changed from V1.2.5
|
||||
|
||||
+
|
||||
+ Changed from V1.2.5
|
||||
+
|
||||
+ Made the Rx task 2 priorities higher than the Tx task. Previously it was
|
||||
only 1. This is done to tie in better with the other demo application
|
||||
tasks.
|
||||
|
||||
Changes from V2.0.0
|
||||
|
||||
+ only 1. This is done to tie in better with the other demo application
|
||||
+ tasks.
|
||||
+
|
||||
+ Changes from V2.0.0
|
||||
+
|
||||
+ Delay periods are now specified using variables and constants of
|
||||
TickType_t rather than unsigned long.
|
||||
+ TickType_t rather than unsigned long.
|
||||
+ Slight modification to task priorities.
|
||||
|
||||
*/
|
||||
+
|
||||
*/
|
||||
|
||||
|
||||
/* Scheduler include files. */
|
||||
|
|
@ -99,7 +99,7 @@ Changes from V2.0.0
|
|||
#include "print.h"
|
||||
|
||||
/* The Tx task will transmit the sequence of characters at a pseudo random
|
||||
interval. This is the maximum and minimum block time between sends. */
|
||||
* interval. This is the maximum and minimum block time between sends. */
|
||||
#define comTX_MAX_BLOCK_TIME ( ( TickType_t ) 0x15e )
|
||||
#define comTX_MIN_BLOCK_TIME ( ( TickType_t ) 0xc8 )
|
||||
|
||||
|
|
@ -113,10 +113,10 @@ interval. This is the maximum and minimum block time between sends. */
|
|||
static xComPortHandle xPort;
|
||||
|
||||
/* The transmit function as described at the top of the file. */
|
||||
static void vComTxTask( void *pvParameters );
|
||||
static void vComTxTask( void * pvParameters );
|
||||
|
||||
/* The receive function as described at the top of the file. */
|
||||
static void vComRxTask( void *pvParameters );
|
||||
static void vComRxTask( void * pvParameters );
|
||||
|
||||
/* The semaphore test function as described at the top of the file. */
|
||||
static void vSemTestTask( void * pvParameters );
|
||||
|
|
@ -126,7 +126,7 @@ const char * const pcMessageToExchange = "Send this message over and over again
|
|||
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n";
|
||||
|
||||
/* Variables that are incremented on each cycle of each task. These are used to
|
||||
check that both tasks are still executing. */
|
||||
* check that both tasks are still executing. */
|
||||
volatile short sTxCount = 0, sRxCount = 0, sSemCount = 0;
|
||||
|
||||
/* The handle to the semaphore test task. */
|
||||
|
|
@ -134,9 +134,11 @@ static TaskHandle_t xSemTestTaskHandle = NULL;
|
|||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vStartComTestTasks( unsigned portBASE_TYPE uxPriority, eCOMPort ePort, eBaud eBaudRate )
|
||||
void vStartComTestTasks( unsigned portBASE_TYPE uxPriority,
|
||||
eCOMPort ePort,
|
||||
eBaud eBaudRate )
|
||||
{
|
||||
const unsigned portBASE_TYPE uxBufferLength = 255;
|
||||
const unsigned portBASE_TYPE uxBufferLength = 255;
|
||||
|
||||
/* Initialise the com port then spawn both tasks. */
|
||||
xPort = xSerialPortInit( ePort, eBaudRate, serNO_PARITY, serBITS_8, serSTOP_1, uxBufferLength );
|
||||
|
|
@ -146,10 +148,10 @@ const unsigned portBASE_TYPE uxBufferLength = 255;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vComTxTask( void *pvParameters )
|
||||
static void vComTxTask( void * pvParameters )
|
||||
{
|
||||
const char * const pcTaskStartMsg = "COM Tx task started.\r\n";
|
||||
TickType_t xTimeToWait;
|
||||
const char * const pcTaskStartMsg = "COM Tx task started.\r\n";
|
||||
TickType_t xTimeToWait;
|
||||
|
||||
/* Stop warnings. */
|
||||
( void ) pvParameters;
|
||||
|
|
@ -157,14 +159,14 @@ TickType_t xTimeToWait;
|
|||
/* Queue a message for printing to say the task has started. */
|
||||
vPrintDisplayMessage( &pcTaskStartMsg );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Send the string to the serial port. */
|
||||
vSerialPutString( xPort, pcMessageToExchange, strlen( pcMessageToExchange ) );
|
||||
|
||||
/* We have posted all the characters in the string - increment the variable
|
||||
used to check that this task is still running, then wait before re-sending
|
||||
the string. */
|
||||
* used to check that this task is still running, then wait before re-sending
|
||||
* the string. */
|
||||
sTxCount++;
|
||||
|
||||
xTimeToWait = xTaskGetTickCount();
|
||||
|
|
@ -183,17 +185,17 @@ TickType_t xTimeToWait;
|
|||
} /*lint !e715 !e818 pvParameters is required for a task function even if it is not referenced. */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vComRxTask( void *pvParameters )
|
||||
static void vComRxTask( void * pvParameters )
|
||||
{
|
||||
const char * const pcTaskStartMsg = "COM Rx task started.\r\n";
|
||||
const char * const pcTaskErrorMsg = "COM read error\r\n";
|
||||
const char * const pcTaskRestartMsg = "COM resynced\r\n";
|
||||
const char * const pcTaskTimeoutMsg = "COM Rx timed out\r\n";
|
||||
const TickType_t xBlockTime = ( TickType_t ) 0xffff / portTICK_PERIOD_MS;
|
||||
const char *pcExpectedChar;
|
||||
portBASE_TYPE xGotChar;
|
||||
char cRxedChar;
|
||||
short sResyncRequired, sConsecutiveErrors, sLatchedError;
|
||||
const char * const pcTaskStartMsg = "COM Rx task started.\r\n";
|
||||
const char * const pcTaskErrorMsg = "COM read error\r\n";
|
||||
const char * const pcTaskRestartMsg = "COM resynced\r\n";
|
||||
const char * const pcTaskTimeoutMsg = "COM Rx timed out\r\n";
|
||||
const TickType_t xBlockTime = ( TickType_t ) 0xffff / portTICK_PERIOD_MS;
|
||||
const char * pcExpectedChar;
|
||||
portBASE_TYPE xGotChar;
|
||||
char cRxedChar;
|
||||
short sResyncRequired, sConsecutiveErrors, sLatchedError;
|
||||
|
||||
/* Stop warnings. */
|
||||
( void ) pvParameters;
|
||||
|
|
@ -207,31 +209,33 @@ short sResyncRequired, sConsecutiveErrors, sLatchedError;
|
|||
sConsecutiveErrors = 0;
|
||||
sLatchedError = pdFALSE;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Receive a message from the com port interrupt routine. If a message is
|
||||
not yet available the call will block the task. */
|
||||
* not yet available the call will block the task. */
|
||||
xGotChar = xSerialGetChar( xPort, &cRxedChar, xBlockTime );
|
||||
|
||||
if( xGotChar == pdTRUE )
|
||||
{
|
||||
if( sResyncRequired == pdTRUE )
|
||||
{
|
||||
/* We got out of sequence and are waiting for the start of the next
|
||||
transmission of the string. */
|
||||
* transmission of the string. */
|
||||
if( cRxedChar == '\n' )
|
||||
{
|
||||
/* This is the end of the message so we can start again - with
|
||||
the first character in the string being the next thing we expect
|
||||
to receive. */
|
||||
* the first character in the string being the next thing we expect
|
||||
* to receive. */
|
||||
pcExpectedChar = pcMessageToExchange;
|
||||
sResyncRequired = pdFALSE;
|
||||
|
||||
/* Queue a message for printing to say that we are going to try
|
||||
again. */
|
||||
* again. */
|
||||
vPrintDisplayMessage( &pcTaskRestartMsg );
|
||||
|
||||
/* Stop incrementing the check variable, if consecutive errors occur. */
|
||||
sConsecutiveErrors++;
|
||||
|
||||
if( sConsecutiveErrors >= comMAX_CONSECUTIVE_ERRORS )
|
||||
{
|
||||
sLatchedError = pdTRUE;
|
||||
|
|
@ -244,17 +248,18 @@ short sResyncRequired, sConsecutiveErrors, sLatchedError;
|
|||
if( cRxedChar != *pcExpectedChar )
|
||||
{
|
||||
/* This was not the expected character so post a message for
|
||||
printing to say that an error has occurred. We will then wait
|
||||
to resynchronise. */
|
||||
* printing to say that an error has occurred. We will then wait
|
||||
* to resynchronise. */
|
||||
vPrintDisplayMessage( &pcTaskErrorMsg );
|
||||
sResyncRequired = pdTRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This was the expected character so next time we will expect
|
||||
the next character in the string. Wrap back to the beginning
|
||||
of the string when the null terminator has been reached. */
|
||||
* the next character in the string. Wrap back to the beginning
|
||||
* of the string when the null terminator has been reached. */
|
||||
pcExpectedChar++;
|
||||
|
||||
if( *pcExpectedChar == '\0' )
|
||||
{
|
||||
pcExpectedChar = pcMessageToExchange;
|
||||
|
|
@ -266,7 +271,7 @@ short sResyncRequired, sConsecutiveErrors, sLatchedError;
|
|||
}
|
||||
|
||||
/* Increment the count that is used to check that this task is still
|
||||
running. This is only done if an error has never occurred. */
|
||||
* running. This is only done if an error has never occurred. */
|
||||
if( sLatchedError == pdFALSE )
|
||||
{
|
||||
sRxCount++;
|
||||
|
|
@ -282,8 +287,8 @@ short sResyncRequired, sConsecutiveErrors, sLatchedError;
|
|||
|
||||
static void vSemTestTask( void * pvParameters )
|
||||
{
|
||||
const char * const pcTaskStartMsg = "ISR Semaphore test started.\r\n";
|
||||
portBASE_TYPE xError = pdFALSE;
|
||||
const char * const pcTaskStartMsg = "ISR Semaphore test started.\r\n";
|
||||
portBASE_TYPE xError = pdFALSE;
|
||||
|
||||
/* Stop warnings. */
|
||||
( void ) pvParameters;
|
||||
|
|
@ -291,7 +296,7 @@ portBASE_TYPE xError = pdFALSE;
|
|||
/* Queue a message for printing to say the task has started. */
|
||||
vPrintDisplayMessage( &pcTaskStartMsg );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
if( xSerialWaitForSemaphore( xPort ) )
|
||||
{
|
||||
|
|
@ -311,12 +316,12 @@ portBASE_TYPE xError = pdFALSE;
|
|||
/* This is called to check that all the created tasks are still running. */
|
||||
portBASE_TYPE xAreComTestTasksStillRunning( void )
|
||||
{
|
||||
static short sLastTxCount = 0, sLastRxCount = 0, sLastSemCount = 0;
|
||||
portBASE_TYPE xReturn;
|
||||
static short sLastTxCount = 0, sLastRxCount = 0, sLastSemCount = 0;
|
||||
portBASE_TYPE xReturn;
|
||||
|
||||
/* Not too worried about mutual exclusion on these variables as they are 16
|
||||
bits and we are only reading them. We also only care to see if they have
|
||||
changed or not. */
|
||||
* bits and we are only reading them. We also only care to see if they have
|
||||
* changed or not. */
|
||||
|
||||
if( ( sTxCount == sLastTxCount ) || ( sRxCount == sLastRxCount ) || ( sSemCount == sLastSemCount ) )
|
||||
{
|
||||
|
|
@ -338,8 +343,8 @@ portBASE_TYPE xReturn;
|
|||
void vComTestUnsuspendTask( void )
|
||||
{
|
||||
/* The task that is suspended on the semaphore will be referenced from the
|
||||
Suspended list as it is blocking indefinitely. This call just checks that
|
||||
the kernel correctly detects this and does not attempt to unsuspend the
|
||||
task. */
|
||||
* Suspended list as it is blocking indefinitely. This call just checks that
|
||||
* the kernel correctly detects this and does not attempt to unsuspend the
|
||||
* task. */
|
||||
xTaskResumeFromISR( xSemTestTaskHandle );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,11 +44,11 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
Changes from V2.0.0
|
||||
|
||||
* Changes from V2.0.0
|
||||
*
|
||||
+ Delay periods are now specified using variables and constants of
|
||||
TickType_t rather than unsigned long.
|
||||
*/
|
||||
+ TickType_t rather than unsigned long.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -63,63 +63,63 @@ Changes from V2.0.0
|
|||
#define deathSTACK_SIZE ( ( unsigned short ) 512 )
|
||||
|
||||
/* The task originally created which is responsible for periodically dynamically
|
||||
creating another four tasks. */
|
||||
static void vCreateTasks( void *pvParameters );
|
||||
* creating another four tasks. */
|
||||
static void vCreateTasks( void * pvParameters );
|
||||
|
||||
/* The task function of the dynamically created tasks. */
|
||||
static void vSuicidalTask( void *pvParameters );
|
||||
static void vSuicidalTask( void * pvParameters );
|
||||
|
||||
/* A variable which is incremented every time the dynamic tasks are created. This
|
||||
is used to check that the task is still running. */
|
||||
* is used to check that the task is still running. */
|
||||
static volatile short sCreationCount = 0;
|
||||
|
||||
/* Used to store the number of tasks that were originally running so the creator
|
||||
task can tell if any of the suicidal tasks have failed to die. */
|
||||
* task can tell if any of the suicidal tasks have failed to die. */
|
||||
static volatile unsigned portBASE_TYPE uxTasksRunningAtStart = 0;
|
||||
static const unsigned portBASE_TYPE uxMaxNumberOfExtraTasksRunning = 5;
|
||||
|
||||
/* Used to store a handle to the tasks that should be killed by a suicidal task,
|
||||
before it kills itself. */
|
||||
* before it kills itself. */
|
||||
TaskHandle_t xCreatedTask1, xCreatedTask2;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vCreateSuicidalTasks( unsigned portBASE_TYPE uxPriority )
|
||||
{
|
||||
unsigned portBASE_TYPE *puxPriority;
|
||||
unsigned portBASE_TYPE * puxPriority;
|
||||
|
||||
/* Create the Creator tasks - passing in as a parameter the priority at which
|
||||
the suicidal tasks should be created. */
|
||||
* the suicidal tasks should be created. */
|
||||
puxPriority = ( unsigned portBASE_TYPE * ) pvPortMalloc( sizeof( unsigned portBASE_TYPE ) );
|
||||
*puxPriority = uxPriority;
|
||||
|
||||
xTaskCreate( vCreateTasks, "CREATOR", deathSTACK_SIZE, ( void * ) puxPriority, uxPriority, NULL );
|
||||
|
||||
/* Record the number of tasks that are running now so we know if any of the
|
||||
suicidal tasks have failed to be killed. */
|
||||
* suicidal tasks have failed to be killed. */
|
||||
uxTasksRunningAtStart = uxTaskGetNumberOfTasks();
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vSuicidalTask( void *pvParameters )
|
||||
static void vSuicidalTask( void * pvParameters )
|
||||
{
|
||||
portDOUBLE d1, d2;
|
||||
TaskHandle_t xTaskToKill;
|
||||
const TickType_t xDelay = ( TickType_t ) 500 / portTICK_PERIOD_MS;
|
||||
portDOUBLE d1, d2;
|
||||
TaskHandle_t xTaskToKill;
|
||||
const TickType_t xDelay = ( TickType_t ) 500 / portTICK_PERIOD_MS;
|
||||
|
||||
if( pvParameters != NULL )
|
||||
{
|
||||
/* This task is periodically created four times. Tow created tasks are
|
||||
passed a handle to the other task so it can kill it before killing itself.
|
||||
The other task is passed in null. */
|
||||
xTaskToKill = *( TaskHandle_t* )pvParameters;
|
||||
* passed a handle to the other task so it can kill it before killing itself.
|
||||
* The other task is passed in null. */
|
||||
xTaskToKill = *( TaskHandle_t * ) pvParameters;
|
||||
}
|
||||
else
|
||||
{
|
||||
xTaskToKill = NULL;
|
||||
}
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Do something random just to use some stack and registers. */
|
||||
d1 = 2.4;
|
||||
|
|
@ -137,14 +137,14 @@ const TickType_t xDelay = ( TickType_t ) 500 / portTICK_PERIOD_MS;
|
|||
vTaskDelete( NULL );
|
||||
}
|
||||
}
|
||||
}/*lint !e818 !e550 Function prototype must be as per standard for task functions. */
|
||||
} /*lint !e818 !e550 Function prototype must be as per standard for task functions. */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vCreateTasks( void *pvParameters )
|
||||
static void vCreateTasks( void * pvParameters )
|
||||
{
|
||||
const TickType_t xDelay = ( TickType_t ) 1000 / portTICK_PERIOD_MS;
|
||||
unsigned portBASE_TYPE uxPriority;
|
||||
const char * const pcTaskStartMsg = "Create task started.\r\n";
|
||||
const TickType_t xDelay = ( TickType_t ) 1000 / portTICK_PERIOD_MS;
|
||||
unsigned portBASE_TYPE uxPriority;
|
||||
const char * const pcTaskStartMsg = "Create task started.\r\n";
|
||||
|
||||
/* Queue a message for printing to say the task has started. */
|
||||
vPrintDisplayMessage( &pcTaskStartMsg );
|
||||
|
|
@ -152,7 +152,7 @@ const char * const pcTaskStartMsg = "Create task started.\r\n";
|
|||
uxPriority = *( unsigned portBASE_TYPE * ) pvParameters;
|
||||
vPortFree( pvParameters );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Just loop round, delaying then creating the four suicidal tasks. */
|
||||
vTaskDelay( xDelay );
|
||||
|
|
@ -169,17 +169,18 @@ const char * const pcTaskStartMsg = "Create task started.\r\n";
|
|||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* This is called to check that the creator task is still running and that there
|
||||
are not any more than four extra tasks. */
|
||||
* are not any more than four extra tasks. */
|
||||
portBASE_TYPE xIsCreateTaskStillRunning( void )
|
||||
{
|
||||
static short sLastCreationCount = 0;
|
||||
short sReturn = pdTRUE;
|
||||
unsigned portBASE_TYPE uxTasksRunningNow;
|
||||
static short sLastCreationCount = 0;
|
||||
short sReturn = pdTRUE;
|
||||
unsigned portBASE_TYPE uxTasksRunningNow;
|
||||
|
||||
if( sLastCreationCount == sCreationCount )
|
||||
{
|
||||
sReturn = pdFALSE;
|
||||
}
|
||||
|
||||
sLastCreationCount = sCreationCount;
|
||||
|
||||
uxTasksRunningNow = uxTaskGetNumberOfTasks();
|
||||
|
|
@ -199,5 +200,3 @@ unsigned portBASE_TYPE uxTasksRunningNow;
|
|||
|
||||
return sReturn;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -91,20 +91,20 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
Changes from V2.0.0
|
||||
|
||||
* Changes from V2.0.0
|
||||
*
|
||||
+ Delay periods are now specified using variables and constants of
|
||||
TickType_t rather than unsigned long.
|
||||
+ TickType_t rather than unsigned long.
|
||||
+ Added a second, simple test that uses the functions
|
||||
vQueueReceiveWhenSuspendedTask() and vQueueSendWhenSuspendedTask().
|
||||
|
||||
Changes from V3.1.1
|
||||
|
||||
+ vQueueReceiveWhenSuspendedTask() and vQueueSendWhenSuspendedTask().
|
||||
+
|
||||
+ Changes from V3.1.1
|
||||
+
|
||||
+ Added a third simple test that uses the vTaskPrioritySet() function
|
||||
while the scheduler is suspended.
|
||||
+ while the scheduler is suspended.
|
||||
+ Modified the controller task slightly to test the calling of
|
||||
vTaskResumeAll() while the scheduler is suspended.
|
||||
*/
|
||||
+ vTaskResumeAll() while the scheduler is suspended.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -127,14 +127,14 @@ static void vContinuousIncrementTask( void * pvParameters );
|
|||
static void vCounterControlTask( void * pvParameters );
|
||||
|
||||
/* The simple test functions that check sending and receiving while the
|
||||
scheduler is suspended. */
|
||||
static void vQueueReceiveWhenSuspendedTask( void *pvParameters );
|
||||
static void vQueueSendWhenSuspendedTask( void *pvParameters );
|
||||
* scheduler is suspended. */
|
||||
static void vQueueReceiveWhenSuspendedTask( void * pvParameters );
|
||||
static void vQueueSendWhenSuspendedTask( void * pvParameters );
|
||||
|
||||
/* The simple test functions that check raising and lowering of task priorities
|
||||
while the scheduler is suspended. */
|
||||
static void prvChangePriorityWhenSuspendedTask( void *pvParameters );
|
||||
static void prvChangePriorityHelperTask( void *pvParameters );
|
||||
* while the scheduler is suspended. */
|
||||
static void prvChangePriorityWhenSuspendedTask( void * pvParameters );
|
||||
static void prvChangePriorityHelperTask( void * pvParameters );
|
||||
|
||||
|
||||
/* Demo task specific constants. */
|
||||
|
|
@ -148,21 +148,21 @@ static void prvChangePriorityHelperTask( void *pvParameters );
|
|||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* 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 TaskHandle_t xContinuousIncrementHandle, xLimitedIncrementHandle, xChangePriorityWhenSuspendedHandle;
|
||||
|
||||
/* 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;
|
||||
|
||||
/* Variable used in a similar way by the test that checks the raising and
|
||||
lowering of task priorities while the scheduler is suspended. */
|
||||
* lowering of task priorities while the scheduler is suspended. */
|
||||
static unsigned long ulPrioritySetCounter;
|
||||
|
||||
/* Variables used to check that the tasks are still operating without error.
|
||||
Each complete iteration of the controller task increments this variable
|
||||
provided no errors have been found. The variable maintaining the same value
|
||||
is therefore indication of an error. */
|
||||
* Each complete iteration of the controller task increments this variable
|
||||
* provided no errors have been found. The variable maintaining the same value
|
||||
* is therefore indication of an error. */
|
||||
static unsigned short usCheckVariable = ( unsigned short ) 0;
|
||||
static portBASE_TYPE xSuspendedQueueSendError = pdFALSE;
|
||||
static portBASE_TYPE xSuspendedQueueReceiveError = pdFALSE;
|
||||
|
|
@ -172,6 +172,7 @@ static portBASE_TYPE xPriorityRaiseWhenSuspendedError = pdFALSE;
|
|||
QueueHandle_t xSuspendedTestQueue;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
* Start the seven tasks as described at the top of the file.
|
||||
* Note that the limited count task is given a higher priority.
|
||||
|
|
@ -195,17 +196,17 @@ void vStartDynamicPriorityTasks( void )
|
|||
*/
|
||||
static void vLimitedIncrementTask( void * pvParameters )
|
||||
{
|
||||
unsigned long *pulCounter;
|
||||
unsigned long * pulCounter;
|
||||
|
||||
/* Take a pointer to the shared variable from the parameters passed into
|
||||
the task. */
|
||||
* the task. */
|
||||
pulCounter = ( unsigned long * ) pvParameters;
|
||||
|
||||
/* This will run before the control task, so the first thing it does is
|
||||
suspend - the control task will resume it when ready. */
|
||||
* suspend - the control task will resume it when ready. */
|
||||
vTaskSuspend( NULL );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Just count up to a value then suspend. */
|
||||
( *pulCounter )++;
|
||||
|
|
@ -224,21 +225,21 @@ unsigned long *pulCounter;
|
|||
*/
|
||||
static void vContinuousIncrementTask( void * pvParameters )
|
||||
{
|
||||
unsigned long *pulCounter;
|
||||
unsigned portBASE_TYPE uxOurPriority;
|
||||
unsigned long * pulCounter;
|
||||
unsigned portBASE_TYPE uxOurPriority;
|
||||
|
||||
/* Take a pointer to the shared variable from the parameters passed into
|
||||
the task. */
|
||||
* the task. */
|
||||
pulCounter = ( unsigned long * ) pvParameters;
|
||||
|
||||
/* Query our priority so we can raise it when exclusive access to the
|
||||
shared variable is required. */
|
||||
* shared variable is required. */
|
||||
uxOurPriority = uxTaskPriorityGet( NULL );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Raise our priority above the controller task to ensure a context
|
||||
switch does not occur while we are accessing this variable. */
|
||||
* switch does not occur while we are accessing this variable. */
|
||||
vTaskPrioritySet( NULL, uxOurPriority + 1 );
|
||||
( *pulCounter )++;
|
||||
vTaskPrioritySet( NULL, uxOurPriority );
|
||||
|
|
@ -255,11 +256,11 @@ unsigned portBASE_TYPE uxOurPriority;
|
|||
*/
|
||||
static void vCounterControlTask( void * pvParameters )
|
||||
{
|
||||
unsigned long ulLastCounter;
|
||||
short sLoops;
|
||||
short sError = pdFALSE;
|
||||
const char * const pcTaskStartMsg = "Priority manipulation tasks started.\r\n";
|
||||
const char * const pcTaskFailMsg = "Priority manipulation Task Failed\r\n";
|
||||
unsigned long ulLastCounter;
|
||||
short sLoops;
|
||||
short sError = pdFALSE;
|
||||
const char * const pcTaskStartMsg = "Priority manipulation tasks started.\r\n";
|
||||
const char * const pcTaskFailMsg = "Priority manipulation Task Failed\r\n";
|
||||
|
||||
/* Just to stop warning messages. */
|
||||
( void ) pvParameters;
|
||||
|
|
@ -267,7 +268,7 @@ const char * const pcTaskFailMsg = "Priority manipulation Task Failed\r\n";
|
|||
/* Queue a message for printing to say the task has started. */
|
||||
vPrintDisplayMessage( &pcTaskStartMsg );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Start with the counter at zero. */
|
||||
ulCounter = ( unsigned long ) 0;
|
||||
|
|
@ -278,7 +279,7 @@ const char * const pcTaskFailMsg = "Priority manipulation Task Failed\r\n";
|
|||
for( sLoops = 0; sLoops < priLOOPS; sLoops++ )
|
||||
{
|
||||
/* 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. */
|
||||
vTaskSuspend( xContinuousIncrementHandle );
|
||||
ulLastCounter = ulCounter;
|
||||
vTaskResume( xContinuousIncrementHandle );
|
||||
|
|
@ -287,14 +288,14 @@ const char * const pcTaskFailMsg = "Priority manipulation Task Failed\r\n";
|
|||
vTaskDelay( priSLEEP_TIME );
|
||||
|
||||
/* Check the shared variable again. This time to ensure mutual
|
||||
exclusion the whole scheduler will be locked. This is just for
|
||||
demo purposes! */
|
||||
* exclusion the whole scheduler will be locked. This is just for
|
||||
* demo purposes! */
|
||||
vTaskSuspendAll();
|
||||
{
|
||||
if( ulLastCounter == ulCounter )
|
||||
{
|
||||
/* The shared variable has not changed. There is a problem
|
||||
with the continuous count task so flag an error. */
|
||||
* with the continuous count task so flag an error. */
|
||||
sError = pdTRUE;
|
||||
xTaskResumeAll();
|
||||
vPrintDisplayMessage( &pcTaskFailMsg );
|
||||
|
|
@ -304,7 +305,6 @@ const char * const pcTaskFailMsg = "Priority manipulation Task Failed\r\n";
|
|||
xTaskResumeAll();
|
||||
}
|
||||
|
||||
|
||||
/* Second section: */
|
||||
|
||||
/* Suspend the continuous counter task so it stops accessing the shared variable. */
|
||||
|
|
@ -314,10 +314,10 @@ const char * const pcTaskFailMsg = "Priority manipulation Task Failed\r\n";
|
|||
ulCounter = ( unsigned long ) 0;
|
||||
|
||||
/* Resume the limited count task which has a higher priority than us.
|
||||
We should therefore not return from this call until the limited count
|
||||
task has suspended itself with a known value in the counter variable.
|
||||
The scheduler suspension is not necessary but is included for test
|
||||
purposes. */
|
||||
* We should therefore not return from this call until the limited count
|
||||
* task has suspended itself with a known value in the counter variable.
|
||||
* The scheduler suspension is not necessary but is included for test
|
||||
* purposes. */
|
||||
vTaskSuspendAll();
|
||||
vTaskResume( xLimitedIncrementHandle );
|
||||
xTaskResumeAll();
|
||||
|
|
@ -347,11 +347,11 @@ const char * const pcTaskFailMsg = "Priority manipulation Task Failed\r\n";
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vQueueSendWhenSuspendedTask( void *pvParameters )
|
||||
static void vQueueSendWhenSuspendedTask( void * pvParameters )
|
||||
{
|
||||
static unsigned long ulValueToSend = ( unsigned long ) 0;
|
||||
const char * const pcTaskStartMsg = "Queue send while suspended task started.\r\n";
|
||||
const char * const pcTaskFailMsg = "Queue send while suspended failed.\r\n";
|
||||
static unsigned long ulValueToSend = ( unsigned long ) 0;
|
||||
const char * const pcTaskStartMsg = "Queue send while suspended task started.\r\n";
|
||||
const char * const pcTaskFailMsg = "Queue send while suspended failed.\r\n";
|
||||
|
||||
/* Just to stop warning messages. */
|
||||
( void ) pvParameters;
|
||||
|
|
@ -359,7 +359,7 @@ const char * const pcTaskFailMsg = "Queue send while suspended failed.\r\n";
|
|||
/* Queue a message for printing to say the task has started. */
|
||||
vPrintDisplayMessage( &pcTaskStartMsg );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
vTaskSuspendAll();
|
||||
{
|
||||
|
|
@ -385,12 +385,12 @@ const char * const pcTaskFailMsg = "Queue send while suspended failed.\r\n";
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vQueueReceiveWhenSuspendedTask( void *pvParameters )
|
||||
static void vQueueReceiveWhenSuspendedTask( void * pvParameters )
|
||||
{
|
||||
static unsigned long ulExpectedValue = ( unsigned long ) 0, ulReceivedValue;
|
||||
const char * const pcTaskStartMsg = "Queue receive while suspended task started.\r\n";
|
||||
const char * const pcTaskFailMsg = "Queue receive while suspended failed.\r\n";
|
||||
portBASE_TYPE xGotValue;
|
||||
static unsigned long ulExpectedValue = ( unsigned long ) 0, ulReceivedValue;
|
||||
const char * const pcTaskStartMsg = "Queue receive while suspended task started.\r\n";
|
||||
const char * const pcTaskFailMsg = "Queue receive while suspended failed.\r\n";
|
||||
portBASE_TYPE xGotValue;
|
||||
|
||||
/* Just to stop warning messages. */
|
||||
( void ) pvParameters;
|
||||
|
|
@ -398,21 +398,22 @@ portBASE_TYPE xGotValue;
|
|||
/* Queue a message for printing to say the task has started. */
|
||||
vPrintDisplayMessage( &pcTaskStartMsg );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
do
|
||||
{
|
||||
/* Suspending the scheduler here is fairly pointless and
|
||||
undesirable for a normal application. It is done here purely
|
||||
to test the scheduler. The inner xTaskResumeAll() should
|
||||
never return pdTRUE as the scheduler is still locked by the
|
||||
outer call. */
|
||||
* undesirable for a normal application. It is done here purely
|
||||
* to test the scheduler. The inner xTaskResumeAll() should
|
||||
* never return pdTRUE as the scheduler is still locked by the
|
||||
* outer call. */
|
||||
vTaskSuspendAll();
|
||||
{
|
||||
vTaskSuspendAll();
|
||||
{
|
||||
xGotValue = xQueueReceive( xSuspendedTestQueue, ( void * ) &ulReceivedValue, priNO_BLOCK );
|
||||
}
|
||||
|
||||
if( xTaskResumeAll() )
|
||||
{
|
||||
xSuspendedQueueReceiveError = pdTRUE;
|
||||
|
|
@ -423,7 +424,6 @@ portBASE_TYPE xGotValue;
|
|||
#if configUSE_PREEMPTION == 0
|
||||
taskYIELD();
|
||||
#endif
|
||||
|
||||
} while( xGotValue == pdFALSE );
|
||||
|
||||
if( ulReceivedValue != ulExpectedValue )
|
||||
|
|
@ -432,6 +432,7 @@ portBASE_TYPE xGotValue;
|
|||
{
|
||||
vPrintDisplayMessage( &pcTaskFailMsg );
|
||||
}
|
||||
|
||||
xSuspendedQueueReceiveError = pdTRUE;
|
||||
}
|
||||
|
||||
|
|
@ -440,10 +441,10 @@ portBASE_TYPE xGotValue;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvChangePriorityWhenSuspendedTask( void *pvParameters )
|
||||
static void prvChangePriorityWhenSuspendedTask( void * pvParameters )
|
||||
{
|
||||
const char * const pcTaskStartMsg = "Priority change when suspended task started.\r\n";
|
||||
const char * const pcTaskFailMsg = "Priority change when suspended task failed.\r\n";
|
||||
const char * const pcTaskStartMsg = "Priority change when suspended task started.\r\n";
|
||||
const char * const pcTaskFailMsg = "Priority change when suspended task failed.\r\n";
|
||||
|
||||
/* Just to stop warning messages. */
|
||||
( void ) pvParameters;
|
||||
|
|
@ -451,14 +452,14 @@ const char * const pcTaskFailMsg = "Priority change when suspended task failed.\
|
|||
/* Queue a message for printing to say the task has started. */
|
||||
vPrintDisplayMessage( &pcTaskStartMsg );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Start with the counter at 0 so we know what the counter should be
|
||||
when we check it next. */
|
||||
* when we check it next. */
|
||||
ulPrioritySetCounter = ( unsigned long ) 0;
|
||||
|
||||
/* Resume the helper task. At this time it has a priority lower than
|
||||
ours so no context switch should occur. */
|
||||
* ours so no context switch should occur. */
|
||||
vTaskResume( xChangePriorityWhenSuspendedHandle );
|
||||
|
||||
/* Check to ensure the task just resumed has not executed. */
|
||||
|
|
@ -478,8 +479,8 @@ const char * const pcTaskFailMsg = "Priority change when suspended task failed.\
|
|||
vTaskPrioritySet( xChangePriorityWhenSuspendedHandle, ( configMAX_PRIORITIES - 1 ) );
|
||||
|
||||
/* Again, even though the helper task has a priority greater than
|
||||
ours, it should not have executed yet because the scheduler is
|
||||
suspended. */
|
||||
* ours, it should not have executed yet because the scheduler is
|
||||
* suspended. */
|
||||
portENTER_CRITICAL();
|
||||
{
|
||||
if( ulPrioritySetCounter != ( unsigned long ) 0 )
|
||||
|
|
@ -493,10 +494,10 @@ const char * const pcTaskFailMsg = "Priority change when suspended task failed.\
|
|||
xTaskResumeAll();
|
||||
|
||||
/* Now the scheduler has been resumed the helper task should
|
||||
immediately preempt us and execute. When it executes it will increment
|
||||
the ulPrioritySetCounter exactly once before suspending itself.
|
||||
|
||||
We should now always find the counter set to 1. */
|
||||
* immediately preempt us and execute. When it executes it will increment
|
||||
* the ulPrioritySetCounter exactly once before suspending itself.
|
||||
*
|
||||
* We should now always find the counter set to 1. */
|
||||
portENTER_CRITICAL();
|
||||
{
|
||||
if( ulPrioritySetCounter != ( unsigned long ) 1 )
|
||||
|
|
@ -511,7 +512,7 @@ const char * const pcTaskFailMsg = "Priority change when suspended task failed.\
|
|||
vTaskDelay( priSLEEP_TIME * 2 );
|
||||
|
||||
/* Set the priority of the helper task back ready for the next
|
||||
execution of this task. */
|
||||
* execution of this task. */
|
||||
vTaskSuspendAll();
|
||||
vTaskPrioritySet( xChangePriorityWhenSuspendedHandle, tskIDLE_PRIORITY );
|
||||
xTaskResumeAll();
|
||||
|
|
@ -519,18 +520,18 @@ const char * const pcTaskFailMsg = "Priority change when suspended task failed.\
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvChangePriorityHelperTask( void *pvParameters )
|
||||
static void prvChangePriorityHelperTask( void * pvParameters )
|
||||
{
|
||||
/* Just to stop warning messages. */
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* This is the helper task for prvChangePriorityWhenSuspendedTask().
|
||||
It has it's priority raised and lowered. When it runs it simply
|
||||
increments the counter then suspends itself again. This allows
|
||||
prvChangePriorityWhenSuspendedTask() to know how many times it has
|
||||
executed. */
|
||||
* It has it's priority raised and lowered. When it runs it simply
|
||||
* increments the counter then suspends itself again. This allows
|
||||
* prvChangePriorityWhenSuspendedTask() to know how many times it has
|
||||
* executed. */
|
||||
ulPrioritySetCounter++;
|
||||
vTaskSuspend( NULL );
|
||||
}
|
||||
|
|
@ -541,12 +542,12 @@ static void prvChangePriorityHelperTask( void *pvParameters )
|
|||
portBASE_TYPE xAreDynamicPriorityTasksStillRunning( void )
|
||||
{
|
||||
/* Keep a history of the check variables so we know if it has been incremented
|
||||
since the last call. */
|
||||
static unsigned short usLastTaskCheck = ( unsigned short ) 0;
|
||||
portBASE_TYPE xReturn = pdTRUE;
|
||||
* since the last call. */
|
||||
static unsigned short usLastTaskCheck = ( unsigned short ) 0;
|
||||
portBASE_TYPE xReturn = pdTRUE;
|
||||
|
||||
/* Check the tasks are still running by ensuring the check variable
|
||||
is still incrementing. */
|
||||
* is still incrementing. */
|
||||
|
||||
if( usCheckVariable == usLastTaskCheck )
|
||||
{
|
||||
|
|
@ -572,7 +573,3 @@ portBASE_TYPE xReturn = pdTRUE;
|
|||
usLastTaskCheck = usCheckVariable;
|
||||
return xReturn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -66,65 +66,66 @@
|
|||
#define evtNO_DELAY 0
|
||||
|
||||
/* Just indexes used to uniquely identify the tasks. Note that two tasks are
|
||||
'highest' priority. */
|
||||
* 'highest' priority. */
|
||||
#define evtHIGHEST_PRIORITY_INDEX_2 3
|
||||
#define evtHIGHEST_PRIORITY_INDEX_1 2
|
||||
#define evtMEDIUM_PRIORITY_INDEX 1
|
||||
#define evtLOWEST_PRIORITY_INDEX 0
|
||||
|
||||
/* Each event task increments one of these counters each time it reads data
|
||||
from the queue. */
|
||||
* from the queue. */
|
||||
static volatile portBASE_TYPE xTaskCounters[ evtNUM_TASKS ] = { 0, 0, 0, 0 };
|
||||
|
||||
/* Each time the controlling task posts onto the queue it increments the
|
||||
expected count of the task that it expected to read the data from the queue
|
||||
(i.e. the task with the highest priority that should be blocked on the queue).
|
||||
|
||||
xExpectedTaskCounters are incremented from the controlling task, and
|
||||
xTaskCounters are incremented from the individual event tasks - therefore
|
||||
comparing xTaskCounters to xExpectedTaskCounters shows whether or not the
|
||||
correct task was unblocked by the post. */
|
||||
* expected count of the task that it expected to read the data from the queue
|
||||
* (i.e. the task with the highest priority that should be blocked on the queue).
|
||||
*
|
||||
* xExpectedTaskCounters are incremented from the controlling task, and
|
||||
* xTaskCounters are incremented from the individual event tasks - therefore
|
||||
* comparing xTaskCounters to xExpectedTaskCounters shows whether or not the
|
||||
* correct task was unblocked by the post. */
|
||||
static portBASE_TYPE xExpectedTaskCounters[ evtNUM_TASKS ] = { 0, 0, 0, 0 };
|
||||
|
||||
/* Handles to the four event tasks. These are required to suspend and resume
|
||||
the tasks. */
|
||||
* the tasks. */
|
||||
static TaskHandle_t xCreatedTasks[ evtNUM_TASKS ];
|
||||
|
||||
/* The single queue onto which the controlling task posts, and the four event
|
||||
tasks block. */
|
||||
* tasks block. */
|
||||
static QueueHandle_t xQueue;
|
||||
|
||||
/* Flag used to indicate whether or not an error has occurred at any time.
|
||||
An error is either the queue being full when not expected, or an unexpected
|
||||
task reading data from the queue. */
|
||||
* An error is either the queue being full when not expected, or an unexpected
|
||||
* task reading data from the queue. */
|
||||
static portBASE_TYPE xHealthStatus = pdPASS;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Function that implements the event task. This is created four times. */
|
||||
static void prvMultiEventTask( void *pvParameters );
|
||||
static void prvMultiEventTask( void * pvParameters );
|
||||
|
||||
/* Function that implements the controlling task. */
|
||||
static void prvEventControllerTask( void *pvParameters );
|
||||
static void prvEventControllerTask( void * pvParameters );
|
||||
|
||||
/* This is a utility function that posts data to the queue, then compares
|
||||
xExpectedTaskCounters with xTaskCounters to ensure everything worked as
|
||||
expected.
|
||||
|
||||
The event tasks all have higher priorities the controlling task. Therefore
|
||||
the controlling task will always get preempted between writhing to the queue
|
||||
and checking the task counters.
|
||||
|
||||
@param xExpectedTask The index to the task that the controlling task thinks
|
||||
should be the highest priority task waiting for data, and
|
||||
therefore the task that will unblock.
|
||||
|
||||
@param xIncrement The number of items that should be written to the queue.
|
||||
*/
|
||||
static void prvCheckTaskCounters( portBASE_TYPE xExpectedTask, portBASE_TYPE xIncrement );
|
||||
* xExpectedTaskCounters with xTaskCounters to ensure everything worked as
|
||||
* expected.
|
||||
*
|
||||
* The event tasks all have higher priorities the controlling task. Therefore
|
||||
* the controlling task will always get preempted between writhing to the queue
|
||||
* and checking the task counters.
|
||||
*
|
||||
* @param xExpectedTask The index to the task that the controlling task thinks
|
||||
* should be the highest priority task waiting for data, and
|
||||
* therefore the task that will unblock.
|
||||
*
|
||||
* @param xIncrement The number of items that should be written to the queue.
|
||||
*/
|
||||
static void prvCheckTaskCounters( portBASE_TYPE xExpectedTask,
|
||||
portBASE_TYPE xIncrement );
|
||||
|
||||
/* This is just incremented each cycle of the controlling tasks function so
|
||||
the main application can ensure the test is still running. */
|
||||
* the main application can ensure the test is still running. */
|
||||
static portBASE_TYPE xCheckVariable = 0;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
|
@ -135,11 +136,11 @@ void vStartMultiEventTasks( void )
|
|||
xQueue = xQueueCreate( evtQUEUE_LENGTH, ( unsigned portBASE_TYPE ) sizeof( unsigned portBASE_TYPE ) );
|
||||
|
||||
/* Start the controlling task. This has the idle priority to ensure it is
|
||||
always preempted by the event tasks. */
|
||||
* always preempted by the event tasks. */
|
||||
xTaskCreate( prvEventControllerTask, "EvntCTRL", evtSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
|
||||
|
||||
/* Start the four event tasks. Note that two have priority 3, one
|
||||
priority 2 and the other priority 1. */
|
||||
* priority 2 and the other priority 1. */
|
||||
xTaskCreate( prvMultiEventTask, "Event0", evtSTACK_SIZE, ( void * ) &( xTaskCounters[ 0 ] ), 1, &( xCreatedTasks[ evtLOWEST_PRIORITY_INDEX ] ) );
|
||||
xTaskCreate( prvMultiEventTask, "Event1", evtSTACK_SIZE, ( void * ) &( xTaskCounters[ 1 ] ), 2, &( xCreatedTasks[ evtMEDIUM_PRIORITY_INDEX ] ) );
|
||||
xTaskCreate( prvMultiEventTask, "Event2", evtSTACK_SIZE, ( void * ) &( xTaskCounters[ 2 ] ), 3, &( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] ) );
|
||||
|
|
@ -147,24 +148,24 @@ void vStartMultiEventTasks( void )
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvMultiEventTask( void *pvParameters )
|
||||
static void prvMultiEventTask( void * pvParameters )
|
||||
{
|
||||
portBASE_TYPE *pxCounter;
|
||||
unsigned portBASE_TYPE uxDummy;
|
||||
const char * const pcTaskStartMsg = "Multi event task started.\r\n";
|
||||
portBASE_TYPE * pxCounter;
|
||||
unsigned portBASE_TYPE uxDummy;
|
||||
const char * const pcTaskStartMsg = "Multi event task started.\r\n";
|
||||
|
||||
/* The variable this task will increment is passed in as a parameter. */
|
||||
pxCounter = ( portBASE_TYPE * ) pvParameters;
|
||||
|
||||
vPrintDisplayMessage( &pcTaskStartMsg );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Block on the queue. */
|
||||
if( xQueueReceive( xQueue, &uxDummy, portMAX_DELAY ) )
|
||||
{
|
||||
/* We unblocked by reading the queue - so simply increment
|
||||
the counter specific to this task instance. */
|
||||
* the counter specific to this task instance. */
|
||||
( *pxCounter )++;
|
||||
}
|
||||
else
|
||||
|
|
@ -175,23 +176,23 @@ const char * const pcTaskStartMsg = "Multi event task started.\r\n";
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvEventControllerTask( void *pvParameters )
|
||||
static void prvEventControllerTask( void * pvParameters )
|
||||
{
|
||||
const char * const pcTaskStartMsg = "Multi event controller task started.\r\n";
|
||||
portBASE_TYPE xDummy = 0;
|
||||
const char * const pcTaskStartMsg = "Multi event controller task started.\r\n";
|
||||
portBASE_TYPE xDummy = 0;
|
||||
|
||||
/* Just to stop warnings. */
|
||||
( void ) pvParameters;
|
||||
|
||||
vPrintDisplayMessage( &pcTaskStartMsg );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* All tasks are blocked on the queue. When a message is posted one of
|
||||
the two tasks that share the highest priority should unblock to read
|
||||
the queue. The next message written should unblock the other task with
|
||||
the same high priority, and so on in order. No other task should
|
||||
unblock to read data as they have lower priorities. */
|
||||
* the two tasks that share the highest priority should unblock to read
|
||||
* the queue. The next message written should unblock the other task with
|
||||
* the same high priority, and so on in order. No other task should
|
||||
* unblock to read data as they have lower priorities. */
|
||||
|
||||
prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_1, 1 );
|
||||
prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_2, 1 );
|
||||
|
|
@ -200,32 +201,32 @@ portBASE_TYPE xDummy = 0;
|
|||
prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_1, 1 );
|
||||
|
||||
/* For the rest of these tests we don't need the second 'highest'
|
||||
priority task - so it is suspended. */
|
||||
* priority task - so it is suspended. */
|
||||
vTaskSuspend( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_2 ] );
|
||||
|
||||
|
||||
|
||||
/* Now suspend the other highest priority task. The medium priority
|
||||
task will then be the task with the highest priority that remains
|
||||
blocked on the queue. */
|
||||
* task will then be the task with the highest priority that remains
|
||||
* blocked on the queue. */
|
||||
vTaskSuspend( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
|
||||
|
||||
/* This time, when we post onto the queue we will expect the medium
|
||||
priority task to unblock and preempt us. */
|
||||
* priority task to unblock and preempt us. */
|
||||
prvCheckTaskCounters( evtMEDIUM_PRIORITY_INDEX, 1 );
|
||||
|
||||
/* Now try resuming the highest priority task while the scheduler is
|
||||
suspended. The task should start executing as soon as the scheduler
|
||||
is resumed - therefore when we post to the queue again, the highest
|
||||
priority task should again preempt us. */
|
||||
* suspended. The task should start executing as soon as the scheduler
|
||||
* is resumed - therefore when we post to the queue again, the highest
|
||||
* priority task should again preempt us. */
|
||||
vTaskSuspendAll();
|
||||
vTaskResume( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
|
||||
xTaskResumeAll();
|
||||
prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_1, 1 );
|
||||
|
||||
/* Now we are going to suspend the high and medium priority tasks. The
|
||||
low priority task should then preempt us. Again the task suspension is
|
||||
done with the whole scheduler suspended just for test purposes. */
|
||||
* low priority task should then preempt us. Again the task suspension is
|
||||
* done with the whole scheduler suspended just for test purposes. */
|
||||
vTaskSuspendAll();
|
||||
vTaskSuspend( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
|
||||
vTaskSuspend( xCreatedTasks[ evtMEDIUM_PRIORITY_INDEX ] );
|
||||
|
|
@ -233,9 +234,9 @@ portBASE_TYPE xDummy = 0;
|
|||
prvCheckTaskCounters( evtLOWEST_PRIORITY_INDEX, 1 );
|
||||
|
||||
/* Do the same basic test another few times - selectively suspending
|
||||
and resuming tasks and each time calling prvCheckTaskCounters() passing
|
||||
to the function the number of the task we expected to be unblocked by
|
||||
the post. */
|
||||
* and resuming tasks and each time calling prvCheckTaskCounters() passing
|
||||
* to the function the number of the task we expected to be unblocked by
|
||||
* the post. */
|
||||
|
||||
vTaskResume( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
|
||||
prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_1, 1 );
|
||||
|
|
@ -261,19 +262,19 @@ portBASE_TYPE xDummy = 0;
|
|||
vTaskSuspend( xCreatedTasks[ evtLOWEST_PRIORITY_INDEX ] );
|
||||
|
||||
/* Now when we resume the low priority task and write to the queue 3
|
||||
times. We expect the low priority task to service the queue three
|
||||
times. */
|
||||
* times. We expect the low priority task to service the queue three
|
||||
* times. */
|
||||
vTaskResume( xCreatedTasks[ evtLOWEST_PRIORITY_INDEX ] );
|
||||
prvCheckTaskCounters( evtLOWEST_PRIORITY_INDEX, evtQUEUE_LENGTH );
|
||||
|
||||
/* Again suspend all tasks (only the low priority task is not suspended
|
||||
already). */
|
||||
* already). */
|
||||
vTaskSuspend( xCreatedTasks[ evtLOWEST_PRIORITY_INDEX ] );
|
||||
|
||||
/* This time we are going to suspend the scheduler, resume the low
|
||||
priority task, then resume the high priority task. In this state we
|
||||
will write to the queue three times. When the scheduler is resumed
|
||||
we expect the high priority task to service all three messages. */
|
||||
* priority task, then resume the high priority task. In this state we
|
||||
* will write to the queue three times. When the scheduler is resumed
|
||||
* we expect the high priority task to service all three messages. */
|
||||
vTaskSuspendAll();
|
||||
{
|
||||
vTaskResume( xCreatedTasks[ evtLOWEST_PRIORITY_INDEX ] );
|
||||
|
|
@ -288,7 +289,7 @@ portBASE_TYPE xDummy = 0;
|
|||
}
|
||||
|
||||
/* The queue should not have been serviced yet!. The scheduler
|
||||
is still suspended. */
|
||||
* is still suspended. */
|
||||
if( memcmp( ( void * ) xExpectedTaskCounters, ( void * ) xTaskCounters, sizeof( xExpectedTaskCounters ) ) )
|
||||
{
|
||||
xHealthStatus = pdFAIL;
|
||||
|
|
@ -297,16 +298,17 @@ portBASE_TYPE xDummy = 0;
|
|||
xTaskResumeAll();
|
||||
|
||||
/* We should have been preempted by resuming the scheduler - so by the
|
||||
time we are running again we expect the high priority task to have
|
||||
removed three items from the queue. */
|
||||
* time we are running again we expect the high priority task to have
|
||||
* removed three items from the queue. */
|
||||
xExpectedTaskCounters[ evtHIGHEST_PRIORITY_INDEX_1 ] += evtQUEUE_LENGTH;
|
||||
|
||||
if( memcmp( ( void * ) xExpectedTaskCounters, ( void * ) xTaskCounters, sizeof( xExpectedTaskCounters ) ) )
|
||||
{
|
||||
xHealthStatus = pdFAIL;
|
||||
}
|
||||
|
||||
/* The medium priority and second high priority tasks are still
|
||||
suspended. Make sure to resume them before starting again. */
|
||||
* suspended. Make sure to resume them before starting again. */
|
||||
vTaskResume( xCreatedTasks[ evtMEDIUM_PRIORITY_INDEX ] );
|
||||
vTaskResume( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_2 ] );
|
||||
|
||||
|
|
@ -316,12 +318,13 @@ portBASE_TYPE xDummy = 0;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvCheckTaskCounters( portBASE_TYPE xExpectedTask, portBASE_TYPE xIncrement )
|
||||
static void prvCheckTaskCounters( portBASE_TYPE xExpectedTask,
|
||||
portBASE_TYPE xIncrement )
|
||||
{
|
||||
portBASE_TYPE xDummy = 0;
|
||||
portBASE_TYPE xDummy = 0;
|
||||
|
||||
/* Write to the queue the requested number of times. The data written is
|
||||
not important. */
|
||||
* not important. */
|
||||
for( xDummy = 0; xDummy < xIncrement; xDummy++ )
|
||||
{
|
||||
if( xQueueSend( xQueue, &xDummy, evtNO_DELAY ) != pdTRUE )
|
||||
|
|
@ -332,17 +335,17 @@ portBASE_TYPE xDummy = 0;
|
|||
}
|
||||
|
||||
/* All the tasks blocked on the queue have a priority higher than the
|
||||
controlling task. Writing to the queue will therefore have caused this
|
||||
task to be preempted. By the time this line executes the event task will
|
||||
have executed and incremented its counter. Increment the expected counter
|
||||
to the same value. */
|
||||
* controlling task. Writing to the queue will therefore have caused this
|
||||
* task to be preempted. By the time this line executes the event task will
|
||||
* have executed and incremented its counter. Increment the expected counter
|
||||
* to the same value. */
|
||||
( xExpectedTaskCounters[ xExpectedTask ] ) += xIncrement;
|
||||
|
||||
/* Check the actual counts and expected counts really are the same. */
|
||||
if( memcmp( ( void * ) xExpectedTaskCounters, ( void * ) xTaskCounters, sizeof( xExpectedTaskCounters ) ) )
|
||||
{
|
||||
/* The counters were not the same. This means a task we did not expect
|
||||
to unblock actually did unblock. */
|
||||
* to unblock actually did unblock. */
|
||||
xHealthStatus = pdFAIL;
|
||||
}
|
||||
}
|
||||
|
|
@ -350,10 +353,10 @@ portBASE_TYPE xDummy = 0;
|
|||
|
||||
portBASE_TYPE xAreMultiEventTasksStillRunning( void )
|
||||
{
|
||||
static portBASE_TYPE xPreviousCheckVariable = 0;
|
||||
static portBASE_TYPE xPreviousCheckVariable = 0;
|
||||
|
||||
/* Called externally to periodically check that this test is still
|
||||
operational. */
|
||||
* operational. */
|
||||
|
||||
if( xPreviousCheckVariable == xCheckVariable )
|
||||
{
|
||||
|
|
@ -364,5 +367,3 @@ static portBASE_TYPE xPreviousCheckVariable = 0;
|
|||
|
||||
return xHealthStatus;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -42,16 +42,16 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
Changes from V2.0.0
|
||||
|
||||
* Changes from V2.0.0
|
||||
*
|
||||
+ Delay periods are now specified using variables and constants of
|
||||
TickType_t rather than unsigned long.
|
||||
|
||||
Changes from V2.1.1
|
||||
|
||||
+ TickType_t rather than unsigned long.
|
||||
+
|
||||
+ Changes from V2.1.1
|
||||
+
|
||||
+ The stack size now uses configMINIMAL_STACK_SIZE.
|
||||
+ String constants made file scope to decrease stack depth on 8051 port.
|
||||
*/
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -74,8 +74,8 @@ typedef struct LED_PARAMETERS
|
|||
} xLEDParameters;
|
||||
|
||||
/* The task that is created eight times - each time with a different xLEDParaemtes
|
||||
structure passed in as the parameter. */
|
||||
static void vLEDFlashTask( void *pvParameters );
|
||||
* structure passed in as the parameter. */
|
||||
static void vLEDFlashTask( void * pvParameters );
|
||||
|
||||
/* String to print if USE_STDIO is defined. */
|
||||
const char * const pcTaskStartMsg = "LED flash task started.\r\n";
|
||||
|
|
@ -84,16 +84,16 @@ const char * const pcTaskStartMsg = "LED flash task started.\r\n";
|
|||
|
||||
void vStartLEDFlashTasks( unsigned portBASE_TYPE uxPriority )
|
||||
{
|
||||
unsigned portBASE_TYPE uxLEDTask;
|
||||
xLEDParameters *pxLEDParameters;
|
||||
const unsigned portBASE_TYPE uxNumOfLEDs = 8;
|
||||
const TickType_t xFlashRate = 125;
|
||||
unsigned portBASE_TYPE uxLEDTask;
|
||||
xLEDParameters * pxLEDParameters;
|
||||
const unsigned portBASE_TYPE uxNumOfLEDs = 8;
|
||||
const TickType_t xFlashRate = 125;
|
||||
|
||||
/* Create the eight tasks. */
|
||||
for( uxLEDTask = 0; uxLEDTask < uxNumOfLEDs; ++uxLEDTask )
|
||||
{
|
||||
/* Create and complete the structure used to pass parameters to the next
|
||||
created task. */
|
||||
* created task. */
|
||||
pxLEDParameters = ( xLEDParameters * ) pvPortMalloc( sizeof( xLEDParameters ) );
|
||||
pxLEDParameters->uxLED = uxLEDTask;
|
||||
pxLEDParameters->xFlashRate = ( xFlashRate + ( xFlashRate * ( TickType_t ) uxLEDTask ) );
|
||||
|
|
@ -105,16 +105,16 @@ const TickType_t xFlashRate = 125;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vLEDFlashTask( void *pvParameters )
|
||||
static void vLEDFlashTask( void * pvParameters )
|
||||
{
|
||||
xLEDParameters *pxParameters;
|
||||
xLEDParameters * pxParameters;
|
||||
|
||||
/* Queue a message for printing to say the task has started. */
|
||||
vPrintDisplayMessage( &pcTaskStartMsg );
|
||||
|
||||
pxParameters = ( xLEDParameters * ) pvParameters;
|
||||
|
||||
for(;;)
|
||||
for( ; ; )
|
||||
{
|
||||
/* Delay for half the flash period then turn the LED on. */
|
||||
vTaskDelay( pxParameters->xFlashRate / ( TickType_t ) 2 );
|
||||
|
|
@ -125,4 +125,3 @@ xLEDParameters *pxParameters;
|
|||
vParTestToggleLED( pxParameters->uxLED );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,11 +26,11 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
Changes from V1.2.3
|
||||
|
||||
* Changes from V1.2.3
|
||||
*
|
||||
+ The created tasks now include calls to tskYIELD(), allowing them to be used
|
||||
with the cooperative scheduler.
|
||||
*/
|
||||
+ with the cooperative scheduler.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates eight tasks, each of which loops continuously performing an (emulated)
|
||||
|
|
@ -64,15 +64,15 @@ Changes from V1.2.3
|
|||
#define mathNUMBER_OF_TASKS ( 8 )
|
||||
|
||||
/* Four tasks, each of which performs a different floating point calculation.
|
||||
Each of the four is created twice. */
|
||||
static void vCompetingMathTask1( void *pvParameters );
|
||||
static void vCompetingMathTask2( void *pvParameters );
|
||||
static void vCompetingMathTask3( void *pvParameters );
|
||||
static void vCompetingMathTask4( void *pvParameters );
|
||||
* Each of the four is created twice. */
|
||||
static void vCompetingMathTask1( void * pvParameters );
|
||||
static void vCompetingMathTask2( void * pvParameters );
|
||||
static void vCompetingMathTask3( void * pvParameters );
|
||||
static void vCompetingMathTask4( void * pvParameters );
|
||||
|
||||
/* These variables are used to check that all the tasks are still running. If a
|
||||
task gets a calculation wrong it will
|
||||
stop incrementing its check variable. */
|
||||
* task gets a calculation wrong it will
|
||||
* stop incrementing its check variable. */
|
||||
static volatile unsigned short usTaskCheck[ mathNUMBER_OF_TASKS ] = { ( unsigned short ) 0 };
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
|
@ -90,24 +90,24 @@ void vStartMathTasks( unsigned portBASE_TYPE uxPriority )
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vCompetingMathTask1( void *pvParameters )
|
||||
static void vCompetingMathTask1( void * pvParameters )
|
||||
{
|
||||
portDOUBLE d1, d2, d3, d4;
|
||||
volatile unsigned short *pusTaskCheckVariable;
|
||||
const portDOUBLE dAnswer = ( 123.4567 + 2345.6789 ) * -918.222;
|
||||
const char * const pcTaskStartMsg = "Math task 1 started.\r\n";
|
||||
const char * const pcTaskFailMsg = "Math task 1 failed.\r\n";
|
||||
short sError = pdFALSE;
|
||||
portDOUBLE d1, d2, d3, d4;
|
||||
volatile unsigned short * pusTaskCheckVariable;
|
||||
const portDOUBLE dAnswer = ( 123.4567 + 2345.6789 ) * -918.222;
|
||||
const char * const pcTaskStartMsg = "Math task 1 started.\r\n";
|
||||
const char * const pcTaskFailMsg = "Math task 1 failed.\r\n";
|
||||
short sError = pdFALSE;
|
||||
|
||||
/* Queue a message for printing to say the task has started. */
|
||||
vPrintDisplayMessage( &pcTaskStartMsg );
|
||||
|
||||
/* The variable this task increments to show it is still running is passed in
|
||||
as the parameter. */
|
||||
* as the parameter. */
|
||||
pusTaskCheckVariable = ( unsigned short * ) pvParameters;
|
||||
|
||||
/* Keep performing a calculation and checking the result against a constant. */
|
||||
for(;;)
|
||||
for( ; ; )
|
||||
{
|
||||
d1 = 123.4567;
|
||||
d2 = 2345.6789;
|
||||
|
|
@ -118,7 +118,7 @@ short sError = pdFALSE;
|
|||
taskYIELD();
|
||||
|
||||
/* If the calculation does not match the expected constant, stop the
|
||||
increment of the check variable. */
|
||||
* increment of the check variable. */
|
||||
if( fabs( d4 - dAnswer ) > 0.001 )
|
||||
{
|
||||
vPrintDisplayMessage( &pcTaskFailMsg );
|
||||
|
|
@ -128,7 +128,7 @@ short sError = pdFALSE;
|
|||
if( sError == pdFALSE )
|
||||
{
|
||||
/* If the calculation has always been correct, increment the check
|
||||
variable so we know this task is still running okay. */
|
||||
* variable so we know this task is still running okay. */
|
||||
( *pusTaskCheckVariable )++;
|
||||
}
|
||||
|
||||
|
|
@ -137,24 +137,24 @@ short sError = pdFALSE;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vCompetingMathTask2( void *pvParameters )
|
||||
static void vCompetingMathTask2( void * pvParameters )
|
||||
{
|
||||
portDOUBLE d1, d2, d3, d4;
|
||||
volatile unsigned short *pusTaskCheckVariable;
|
||||
const portDOUBLE dAnswer = ( -389.38 / 32498.2 ) * -2.0001;
|
||||
const char * const pcTaskStartMsg = "Math task 2 started.\r\n";
|
||||
const char * const pcTaskFailMsg = "Math task 2 failed.\r\n";
|
||||
short sError = pdFALSE;
|
||||
portDOUBLE d1, d2, d3, d4;
|
||||
volatile unsigned short * pusTaskCheckVariable;
|
||||
const portDOUBLE dAnswer = ( -389.38 / 32498.2 ) * -2.0001;
|
||||
const char * const pcTaskStartMsg = "Math task 2 started.\r\n";
|
||||
const char * const pcTaskFailMsg = "Math task 2 failed.\r\n";
|
||||
short sError = pdFALSE;
|
||||
|
||||
/* Queue a message for printing to say the task has started. */
|
||||
vPrintDisplayMessage( &pcTaskStartMsg );
|
||||
|
||||
/* The variable this task increments to show it is still running is passed in
|
||||
as the parameter. */
|
||||
* as the parameter. */
|
||||
pusTaskCheckVariable = ( unsigned short * ) pvParameters;
|
||||
|
||||
/* Keep performing a calculation and checking the result against a constant. */
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
d1 = -389.38;
|
||||
d2 = 32498.2;
|
||||
|
|
@ -165,7 +165,7 @@ short sError = pdFALSE;
|
|||
taskYIELD();
|
||||
|
||||
/* If the calculation does not match the expected constant, stop the
|
||||
increment of the check variable. */
|
||||
* increment of the check variable. */
|
||||
if( fabs( d4 - dAnswer ) > 0.001 )
|
||||
{
|
||||
vPrintDisplayMessage( &pcTaskFailMsg );
|
||||
|
|
@ -175,8 +175,8 @@ short sError = pdFALSE;
|
|||
if( sError == pdFALSE )
|
||||
{
|
||||
/* If the calculation has always been correct, increment the check
|
||||
variable so we know
|
||||
this task is still running okay. */
|
||||
* variable so we know
|
||||
* this task is still running okay. */
|
||||
( *pusTaskCheckVariable )++;
|
||||
}
|
||||
|
||||
|
|
@ -185,29 +185,29 @@ short sError = pdFALSE;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vCompetingMathTask3( void *pvParameters )
|
||||
static void vCompetingMathTask3( void * pvParameters )
|
||||
{
|
||||
portDOUBLE *pdArray, dTotal1, dTotal2, dDifference;
|
||||
volatile unsigned short *pusTaskCheckVariable;
|
||||
const unsigned short usArraySize = 250;
|
||||
unsigned short usPosition;
|
||||
const char * const pcTaskStartMsg = "Math task 3 started.\r\n";
|
||||
const char * const pcTaskFailMsg = "Math task 3 failed.\r\n";
|
||||
short sError = pdFALSE;
|
||||
portDOUBLE * pdArray, dTotal1, dTotal2, dDifference;
|
||||
volatile unsigned short * pusTaskCheckVariable;
|
||||
const unsigned short usArraySize = 250;
|
||||
unsigned short usPosition;
|
||||
const char * const pcTaskStartMsg = "Math task 3 started.\r\n";
|
||||
const char * const pcTaskFailMsg = "Math task 3 failed.\r\n";
|
||||
short sError = pdFALSE;
|
||||
|
||||
/* Queue a message for printing to say the task has started. */
|
||||
vPrintDisplayMessage( &pcTaskStartMsg );
|
||||
|
||||
/* The variable this task increments to show it is still running is passed in
|
||||
as the parameter. */
|
||||
* as the parameter. */
|
||||
pusTaskCheckVariable = ( unsigned short * ) pvParameters;
|
||||
|
||||
pdArray = ( portDOUBLE * ) pvPortMalloc( ( size_t ) 250 * sizeof( portDOUBLE ) );
|
||||
|
||||
/* Keep filling an array, keeping a running total of the values placed in the
|
||||
array. Then run through the array adding up all the values. If the two totals
|
||||
do not match, stop the check variable from incrementing. */
|
||||
for( ;; )
|
||||
* array. Then run through the array adding up all the values. If the two totals
|
||||
* do not match, stop the check variable from incrementing. */
|
||||
for( ; ; )
|
||||
{
|
||||
dTotal1 = 0.0;
|
||||
dTotal2 = 0.0;
|
||||
|
|
@ -226,6 +226,7 @@ short sError = pdFALSE;
|
|||
}
|
||||
|
||||
dDifference = dTotal1 - dTotal2;
|
||||
|
||||
if( fabs( dDifference ) > 0.001 )
|
||||
{
|
||||
vPrintDisplayMessage( &pcTaskFailMsg );
|
||||
|
|
@ -237,36 +238,36 @@ short sError = pdFALSE;
|
|||
if( sError == pdFALSE )
|
||||
{
|
||||
/* If the calculation has always been correct, increment the check
|
||||
variable so we know this task is still running okay. */
|
||||
* variable so we know this task is still running okay. */
|
||||
( *pusTaskCheckVariable )++;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vCompetingMathTask4( void *pvParameters )
|
||||
static void vCompetingMathTask4( void * pvParameters )
|
||||
{
|
||||
portDOUBLE *pdArray, dTotal1, dTotal2, dDifference;
|
||||
volatile unsigned short *pusTaskCheckVariable;
|
||||
const unsigned short usArraySize = 250;
|
||||
unsigned short usPosition;
|
||||
const char * const pcTaskStartMsg = "Math task 4 started.\r\n";
|
||||
const char * const pcTaskFailMsg = "Math task 4 failed.\r\n";
|
||||
short sError = pdFALSE;
|
||||
portDOUBLE * pdArray, dTotal1, dTotal2, dDifference;
|
||||
volatile unsigned short * pusTaskCheckVariable;
|
||||
const unsigned short usArraySize = 250;
|
||||
unsigned short usPosition;
|
||||
const char * const pcTaskStartMsg = "Math task 4 started.\r\n";
|
||||
const char * const pcTaskFailMsg = "Math task 4 failed.\r\n";
|
||||
short sError = pdFALSE;
|
||||
|
||||
/* Queue a message for printing to say the task has started. */
|
||||
vPrintDisplayMessage( &pcTaskStartMsg );
|
||||
|
||||
/* The variable this task increments to show it is still running is passed in
|
||||
as the parameter. */
|
||||
* as the parameter. */
|
||||
pusTaskCheckVariable = ( unsigned short * ) pvParameters;
|
||||
|
||||
pdArray = ( portDOUBLE * ) pvPortMalloc( ( size_t ) 250 * sizeof( portDOUBLE ) );
|
||||
|
||||
/* Keep filling an array, keeping a running total of the values placed in the
|
||||
array. Then run through the array adding up all the values. If the two totals
|
||||
do not match, stop the check variable from incrementing. */
|
||||
for( ;; )
|
||||
* array. Then run through the array adding up all the values. If the two totals
|
||||
* do not match, stop the check variable from incrementing. */
|
||||
for( ; ; )
|
||||
{
|
||||
dTotal1 = 0.0;
|
||||
dTotal2 = 0.0;
|
||||
|
|
@ -285,6 +286,7 @@ short sError = pdFALSE;
|
|||
}
|
||||
|
||||
dDifference = dTotal1 - dTotal2;
|
||||
|
||||
if( fabs( dDifference ) > 0.001 )
|
||||
{
|
||||
vPrintDisplayMessage( &pcTaskFailMsg );
|
||||
|
|
@ -296,7 +298,7 @@ short sError = pdFALSE;
|
|||
if( sError == pdFALSE )
|
||||
{
|
||||
/* If the calculation has always been correct, increment the check
|
||||
variable so we know this task is still running okay. */
|
||||
* variable so we know this task is still running okay. */
|
||||
( *pusTaskCheckVariable )++;
|
||||
}
|
||||
}
|
||||
|
|
@ -307,12 +309,12 @@ short sError = pdFALSE;
|
|||
portBASE_TYPE xAreMathsTaskStillRunning( void )
|
||||
{
|
||||
/* Keep a history of the check variables so we know if they have been incremented
|
||||
since the last call. */
|
||||
static unsigned short usLastTaskCheck[ mathNUMBER_OF_TASKS ] = { ( unsigned short ) 0 };
|
||||
portBASE_TYPE xReturn = pdTRUE, xTask;
|
||||
* since the last call. */
|
||||
static unsigned short usLastTaskCheck[ mathNUMBER_OF_TASKS ] = { ( unsigned short ) 0 };
|
||||
portBASE_TYPE xReturn = pdTRUE, xTask;
|
||||
|
||||
/* Check the maths tasks are still running by ensuring their check variables
|
||||
are still incrementing. */
|
||||
* are still incrementing. */
|
||||
for( xTask = 0; xTask < mathNUMBER_OF_TASKS; xTask++ )
|
||||
{
|
||||
if( usTaskCheck[ xTask ] == usLastTaskCheck[ xTask ] )
|
||||
|
|
@ -326,6 +328,3 @@ portBASE_TYPE xReturn = pdTRUE, xTask;
|
|||
|
||||
return xReturn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -26,11 +26,11 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
Changes from V1.2.3
|
||||
|
||||
* Changes from V1.2.3
|
||||
*
|
||||
+ The created tasks now include calls to tskYIELD(), allowing them to be used
|
||||
with the cooperative scheduler.
|
||||
*/
|
||||
+ with the cooperative scheduler.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This does the same as flop. c, but uses variables of type long instead of
|
||||
|
|
@ -49,11 +49,11 @@ Changes from V1.2.3
|
|||
*/
|
||||
|
||||
/*
|
||||
Changes from V1.2.1
|
||||
|
||||
* Changes from V1.2.1
|
||||
*
|
||||
+ The constants used in the calculations are larger to ensure the
|
||||
optimiser does not truncate them to 16 bits.
|
||||
*/
|
||||
+ optimiser does not truncate them to 16 bits.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -69,14 +69,14 @@ Changes from V1.2.1
|
|||
#define intgNUMBER_OF_TASKS ( 8 )
|
||||
|
||||
/* Four tasks, each of which performs a different calculation on four byte
|
||||
variables. Each of the four is created twice. */
|
||||
static void vCompeteingIntMathTask1( void *pvParameters );
|
||||
static void vCompeteingIntMathTask2( void *pvParameters );
|
||||
static void vCompeteingIntMathTask3( void *pvParameters );
|
||||
static void vCompeteingIntMathTask4( void *pvParameters );
|
||||
* variables. Each of the four is created twice. */
|
||||
static void vCompeteingIntMathTask1( void * pvParameters );
|
||||
static void vCompeteingIntMathTask2( void * pvParameters );
|
||||
static void vCompeteingIntMathTask3( void * pvParameters );
|
||||
static void vCompeteingIntMathTask4( void * pvParameters );
|
||||
|
||||
/* These variables are used to check that all the tasks are still running. If a
|
||||
task gets a calculation wrong it will stop incrementing its check variable. */
|
||||
* task gets a calculation wrong it will stop incrementing its check variable. */
|
||||
static volatile unsigned short usTaskCheck[ intgNUMBER_OF_TASKS ] = { ( unsigned short ) 0 };
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
|
|
@ -93,24 +93,24 @@ void vStartIntegerMathTasks( unsigned portBASE_TYPE uxPriority )
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vCompeteingIntMathTask1( void *pvParameters )
|
||||
static void vCompeteingIntMathTask1( void * pvParameters )
|
||||
{
|
||||
long l1, l2, l3, l4;
|
||||
short sError = pdFALSE;
|
||||
volatile unsigned short *pusTaskCheckVariable;
|
||||
const long lAnswer = ( ( long ) 74565L + ( long ) 1234567L ) * ( long ) -918L;
|
||||
const char * const pcTaskStartMsg = "Integer math task 1 started.\r\n";
|
||||
const char * const pcTaskFailMsg = "Integer math task 1 failed.\r\n";
|
||||
long l1, l2, l3, l4;
|
||||
short sError = pdFALSE;
|
||||
volatile unsigned short * pusTaskCheckVariable;
|
||||
const long lAnswer = ( ( long ) 74565L + ( long ) 1234567L ) * ( long ) -918L;
|
||||
const char * const pcTaskStartMsg = "Integer math task 1 started.\r\n";
|
||||
const char * const pcTaskFailMsg = "Integer math task 1 failed.\r\n";
|
||||
|
||||
/* Queue a message for printing to say the task has started. */
|
||||
vPrintDisplayMessage( &pcTaskStartMsg );
|
||||
|
||||
/* The variable this task increments to show it is still running is passed in
|
||||
as the parameter. */
|
||||
* as the parameter. */
|
||||
pusTaskCheckVariable = ( unsigned short * ) pvParameters;
|
||||
|
||||
/* Keep performing a calculation and checking the result against a constant. */
|
||||
for(;;)
|
||||
for( ; ; )
|
||||
{
|
||||
l1 = ( long ) 74565L;
|
||||
l2 = ( long ) 1234567L;
|
||||
|
|
@ -121,7 +121,7 @@ const char * const pcTaskFailMsg = "Integer math task 1 failed.\r\n";
|
|||
taskYIELD();
|
||||
|
||||
/* If the calculation does not match the expected constant, stop the
|
||||
increment of the check variable. */
|
||||
* increment of the check variable. */
|
||||
if( l4 != lAnswer )
|
||||
{
|
||||
vPrintDisplayMessage( &pcTaskFailMsg );
|
||||
|
|
@ -131,31 +131,31 @@ const char * const pcTaskFailMsg = "Integer math task 1 failed.\r\n";
|
|||
if( sError == pdFALSE )
|
||||
{
|
||||
/* If the calculation has always been correct, increment the check
|
||||
variable so we know this task is still running okay. */
|
||||
* variable so we know this task is still running okay. */
|
||||
( *pusTaskCheckVariable )++;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vCompeteingIntMathTask2( void *pvParameters )
|
||||
static void vCompeteingIntMathTask2( void * pvParameters )
|
||||
{
|
||||
long l1, l2, l3, l4;
|
||||
short sError = pdFALSE;
|
||||
volatile unsigned short *pusTaskCheckVariable;
|
||||
const long lAnswer = ( ( long ) -389000L / ( long ) 329999L ) * ( long ) -89L;
|
||||
const char * const pcTaskStartMsg = "Integer math task 2 started.\r\n";
|
||||
const char * const pcTaskFailMsg = "Integer math task 2 failed.\r\n";
|
||||
long l1, l2, l3, l4;
|
||||
short sError = pdFALSE;
|
||||
volatile unsigned short * pusTaskCheckVariable;
|
||||
const long lAnswer = ( ( long ) -389000L / ( long ) 329999L ) * ( long ) -89L;
|
||||
const char * const pcTaskStartMsg = "Integer math task 2 started.\r\n";
|
||||
const char * const pcTaskFailMsg = "Integer math task 2 failed.\r\n";
|
||||
|
||||
/* Queue a message for printing to say the task has started. */
|
||||
vPrintDisplayMessage( &pcTaskStartMsg );
|
||||
|
||||
/* The variable this task increments to show it is still running is passed in
|
||||
as the parameter. */
|
||||
* as the parameter. */
|
||||
pusTaskCheckVariable = ( unsigned short * ) pvParameters;
|
||||
|
||||
/* Keep performing a calculation and checking the result against a constant. */
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
l1 = -389000L;
|
||||
l2 = 329999L;
|
||||
|
|
@ -166,7 +166,7 @@ const char * const pcTaskFailMsg = "Integer math task 2 failed.\r\n";
|
|||
taskYIELD();
|
||||
|
||||
/* If the calculation does not match the expected constant, stop the
|
||||
increment of the check variable. */
|
||||
* increment of the check variable. */
|
||||
if( l4 != lAnswer )
|
||||
{
|
||||
vPrintDisplayMessage( &pcTaskFailMsg );
|
||||
|
|
@ -176,37 +176,37 @@ const char * const pcTaskFailMsg = "Integer math task 2 failed.\r\n";
|
|||
if( sError == pdFALSE )
|
||||
{
|
||||
/* If the calculation has always been correct, increment the check
|
||||
variable so we know this task is still running okay. */
|
||||
* variable so we know this task is still running okay. */
|
||||
( *pusTaskCheckVariable )++;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vCompeteingIntMathTask3( void *pvParameters )
|
||||
static void vCompeteingIntMathTask3( void * pvParameters )
|
||||
{
|
||||
long *plArray, lTotal1, lTotal2;
|
||||
short sError = pdFALSE;
|
||||
volatile unsigned short *pusTaskCheckVariable;
|
||||
const unsigned short usArraySize = ( unsigned short ) 250;
|
||||
unsigned short usPosition;
|
||||
const char * const pcTaskStartMsg = "Integer math task 3 started.\r\n";
|
||||
const char * const pcTaskFailMsg = "Integer math task 3 failed.\r\n";
|
||||
long * plArray, lTotal1, lTotal2;
|
||||
short sError = pdFALSE;
|
||||
volatile unsigned short * pusTaskCheckVariable;
|
||||
const unsigned short usArraySize = ( unsigned short ) 250;
|
||||
unsigned short usPosition;
|
||||
const char * const pcTaskStartMsg = "Integer math task 3 started.\r\n";
|
||||
const char * const pcTaskFailMsg = "Integer math task 3 failed.\r\n";
|
||||
|
||||
/* Queue a message for printing to say the task has started. */
|
||||
vPrintDisplayMessage( &pcTaskStartMsg );
|
||||
|
||||
/* The variable this task increments to show it is still running is passed in
|
||||
as the parameter. */
|
||||
* as the parameter. */
|
||||
pusTaskCheckVariable = ( unsigned short * ) pvParameters;
|
||||
|
||||
/* Create the array we are going to use for our check calculation. */
|
||||
plArray = ( long * ) pvPortMalloc( ( size_t ) 250 * sizeof( long ) );
|
||||
|
||||
/* Keep filling the array, keeping a running total of the values placed in the
|
||||
array. Then run through the array adding up all the values. If the two totals
|
||||
do not match, stop the check variable from incrementing. */
|
||||
for( ;; )
|
||||
* array. Then run through the array adding up all the values. If the two totals
|
||||
* do not match, stop the check variable from incrementing. */
|
||||
for( ; ; )
|
||||
{
|
||||
lTotal1 = ( long ) 0;
|
||||
lTotal2 = ( long ) 0;
|
||||
|
|
@ -235,37 +235,37 @@ const char * const pcTaskFailMsg = "Integer math task 3 failed.\r\n";
|
|||
if( sError == pdFALSE )
|
||||
{
|
||||
/* If the calculation has always been correct, increment the check
|
||||
variable so we know this task is still running okay. */
|
||||
* variable so we know this task is still running okay. */
|
||||
( *pusTaskCheckVariable )++;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vCompeteingIntMathTask4( void *pvParameters )
|
||||
static void vCompeteingIntMathTask4( void * pvParameters )
|
||||
{
|
||||
long *plArray, lTotal1, lTotal2;
|
||||
short sError = pdFALSE;
|
||||
volatile unsigned short *pusTaskCheckVariable;
|
||||
const unsigned short usArraySize = 250;
|
||||
unsigned short usPosition;
|
||||
const char * const pcTaskStartMsg = "Integer math task 4 started.\r\n";
|
||||
const char * const pcTaskFailMsg = "Integer math task 4 failed.\r\n";
|
||||
long * plArray, lTotal1, lTotal2;
|
||||
short sError = pdFALSE;
|
||||
volatile unsigned short * pusTaskCheckVariable;
|
||||
const unsigned short usArraySize = 250;
|
||||
unsigned short usPosition;
|
||||
const char * const pcTaskStartMsg = "Integer math task 4 started.\r\n";
|
||||
const char * const pcTaskFailMsg = "Integer math task 4 failed.\r\n";
|
||||
|
||||
/* Queue a message for printing to say the task has started. */
|
||||
vPrintDisplayMessage( &pcTaskStartMsg );
|
||||
|
||||
/* The variable this task increments to show it is still running is passed in
|
||||
as the parameter. */
|
||||
* as the parameter. */
|
||||
pusTaskCheckVariable = ( unsigned short * ) pvParameters;
|
||||
|
||||
/* Create the array we are going to use for our check calculation. */
|
||||
plArray = ( long * ) pvPortMalloc( ( size_t ) 250 * sizeof( long ) );
|
||||
|
||||
/* Keep filling the array, keeping a running total of the values placed in the
|
||||
array. Then run through the array adding up all the values. If the two totals
|
||||
do not match, stop the check variable from incrementing. */
|
||||
for( ;; )
|
||||
* array. Then run through the array adding up all the values. If the two totals
|
||||
* do not match, stop the check variable from incrementing. */
|
||||
for( ; ; )
|
||||
{
|
||||
lTotal1 = ( long ) 0;
|
||||
lTotal2 = ( long ) 0;
|
||||
|
|
@ -283,7 +283,6 @@ const char * const pcTaskFailMsg = "Integer math task 4 failed.\r\n";
|
|||
lTotal2 += plArray[ usPosition ];
|
||||
}
|
||||
|
||||
|
||||
if( lTotal1 != lTotal2 )
|
||||
{
|
||||
vPrintDisplayMessage( &pcTaskFailMsg );
|
||||
|
|
@ -295,7 +294,7 @@ const char * const pcTaskFailMsg = "Integer math task 4 failed.\r\n";
|
|||
if( sError == pdFALSE )
|
||||
{
|
||||
/* If the calculation has always been correct, increment the check
|
||||
variable so we know this task is still running okay. */
|
||||
* variable so we know this task is still running okay. */
|
||||
( *pusTaskCheckVariable )++;
|
||||
}
|
||||
}
|
||||
|
|
@ -306,12 +305,12 @@ const char * const pcTaskFailMsg = "Integer math task 4 failed.\r\n";
|
|||
portBASE_TYPE xAreIntegerMathsTaskStillRunning( void )
|
||||
{
|
||||
/* Keep a history of the check variables so we know if they have been incremented
|
||||
since the last call. */
|
||||
static unsigned short usLastTaskCheck[ intgNUMBER_OF_TASKS ] = { ( unsigned short ) 0 };
|
||||
portBASE_TYPE xReturn = pdTRUE, xTask;
|
||||
* since the last call. */
|
||||
static unsigned short usLastTaskCheck[ intgNUMBER_OF_TASKS ] = { ( unsigned short ) 0 };
|
||||
portBASE_TYPE xReturn = pdTRUE, xTask;
|
||||
|
||||
/* Check the maths tasks are still running by ensuring their check variables
|
||||
are still incrementing. */
|
||||
* are still incrementing. */
|
||||
for( xTask = 0; xTask < intgNUMBER_OF_TASKS; xTask++ )
|
||||
{
|
||||
if( usTaskCheck[ xTask ] == usLastTaskCheck[ xTask ] )
|
||||
|
|
|
|||
|
|
@ -50,11 +50,11 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
Changes from V2.0.0
|
||||
|
||||
* Changes from V2.0.0
|
||||
*
|
||||
+ Delay periods are now specified using variables and constants of
|
||||
TickType_t rather than unsigned long.
|
||||
*/
|
||||
+ TickType_t rather than unsigned long.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ static QueueHandle_t xPrintQueue;
|
|||
|
||||
void vPrintInitialise( void )
|
||||
{
|
||||
const unsigned portBASE_TYPE uxQueueSize = 20;
|
||||
const unsigned portBASE_TYPE uxQueueSize = 20;
|
||||
|
||||
/* Create the queue on which errors will be reported. */
|
||||
xPrintQueue = xQueueCreate( uxQueueSize, ( unsigned portBASE_TYPE ) sizeof( char * ) );
|
||||
|
|
@ -89,9 +89,9 @@ void vPrintDisplayMessage( const char * const * ppcMessageToSend )
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
const char *pcPrintGetNextMessage( TickType_t xPrintRate )
|
||||
const char * pcPrintGetNextMessage( TickType_t xPrintRate )
|
||||
{
|
||||
char *pcMessage;
|
||||
char * pcMessage;
|
||||
|
||||
if( xQueueReceive( xPrintQueue, &pcMessage, xPrintRate ) == pdPASS )
|
||||
{
|
||||
|
|
@ -102,5 +102,3 @@ char *pcMessage;
|
|||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -52,24 +52,24 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
Changes from V1.2.0:
|
||||
|
||||
* Changes from V1.2.0:
|
||||
*
|
||||
+ The tasks that operate at the idle priority now use a lower expected
|
||||
count than those running at a higher priority. This prevents the low
|
||||
priority tasks from signaling an error because they have not been
|
||||
scheduled enough time for each of them to count the shared variable to
|
||||
the high value.
|
||||
|
||||
Changes from V2.0.0
|
||||
|
||||
+ count than those running at a higher priority. This prevents the low
|
||||
+ priority tasks from signaling an error because they have not been
|
||||
+ scheduled enough time for each of them to count the shared variable to
|
||||
+ the high value.
|
||||
+
|
||||
+ Changes from V2.0.0
|
||||
+
|
||||
+ Delay periods are now specified using variables and constants of
|
||||
TickType_t rather than unsigned long.
|
||||
|
||||
Changes from V2.1.1
|
||||
|
||||
+ TickType_t rather than unsigned long.
|
||||
+
|
||||
+ Changes from V2.1.1
|
||||
+
|
||||
+ The stack size now uses configMINIMAL_STACK_SIZE.
|
||||
+ String constants made file scope to decrease stack depth on 8051 port.
|
||||
*/
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -93,13 +93,13 @@ Changes from V2.1.1
|
|||
#define semtstDELAY_FACTOR ( ( TickType_t ) 10 )
|
||||
|
||||
/* The task function as described at the top of the file. */
|
||||
static void prvSemaphoreTest( void *pvParameters );
|
||||
static void prvSemaphoreTest( void * pvParameters );
|
||||
|
||||
/* Structure used to pass parameters to each task. */
|
||||
typedef struct SEMAPHORE_PARAMETERS
|
||||
{
|
||||
SemaphoreHandle_t xSemaphore;
|
||||
volatile unsigned long *pulSharedVariable;
|
||||
volatile unsigned long * pulSharedVariable;
|
||||
TickType_t xBlockTime;
|
||||
} xSemaphoreParameters;
|
||||
|
||||
|
|
@ -115,8 +115,8 @@ const char * const pcSemaphoreTaskStart = "Guarded shared variable task started.
|
|||
|
||||
void vStartSemaphoreTasks( unsigned portBASE_TYPE uxPriority )
|
||||
{
|
||||
xSemaphoreParameters *pxFirstSemaphoreParameters, *pxSecondSemaphoreParameters;
|
||||
const TickType_t xBlockTime = ( TickType_t ) 100;
|
||||
xSemaphoreParameters * pxFirstSemaphoreParameters, * pxSecondSemaphoreParameters;
|
||||
const TickType_t xBlockTime = ( TickType_t ) 100;
|
||||
|
||||
/* Create the structure used to pass parameters to the first two tasks. */
|
||||
pxFirstSemaphoreParameters = ( xSemaphoreParameters * ) pvPortMalloc( sizeof( xSemaphoreParameters ) );
|
||||
|
|
@ -144,8 +144,9 @@ const TickType_t xBlockTime = ( TickType_t ) 100;
|
|||
}
|
||||
|
||||
/* Do exactly the same to create the second set of tasks, only this time
|
||||
provide a block time for the semaphore calls. */
|
||||
* provide a block time for the semaphore calls. */
|
||||
pxSecondSemaphoreParameters = ( xSemaphoreParameters * ) pvPortMalloc( sizeof( xSemaphoreParameters ) );
|
||||
|
||||
if( pxSecondSemaphoreParameters != NULL )
|
||||
{
|
||||
vSemaphoreCreateBinary( pxSecondSemaphoreParameters->xSemaphore );
|
||||
|
|
@ -163,15 +164,15 @@ const TickType_t xBlockTime = ( TickType_t ) 100;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvSemaphoreTest( void *pvParameters )
|
||||
static void prvSemaphoreTest( void * pvParameters )
|
||||
{
|
||||
xSemaphoreParameters *pxParameters;
|
||||
volatile unsigned long *pulSharedVariable, ulExpectedValue;
|
||||
unsigned long ulCounter;
|
||||
short sError = pdFALSE, sCheckVariableToUse;
|
||||
xSemaphoreParameters * pxParameters;
|
||||
volatile unsigned long * pulSharedVariable, ulExpectedValue;
|
||||
unsigned long ulCounter;
|
||||
short sError = pdFALSE, sCheckVariableToUse;
|
||||
|
||||
/* See which check variable to use. sNextCheckVariable is not semaphore
|
||||
protected! */
|
||||
* protected! */
|
||||
portENTER_CRITICAL();
|
||||
sCheckVariableToUse = sNextCheckVariable;
|
||||
sNextCheckVariable++;
|
||||
|
|
@ -181,12 +182,12 @@ short sError = pdFALSE, sCheckVariableToUse;
|
|||
vPrintDisplayMessage( &pcSemaphoreTaskStart );
|
||||
|
||||
/* A structure is passed in as the parameter. This contains the shared
|
||||
variable being guarded. */
|
||||
* variable being guarded. */
|
||||
pxParameters = ( xSemaphoreParameters * ) pvParameters;
|
||||
pulSharedVariable = pxParameters->pulSharedVariable;
|
||||
|
||||
/* If we are blocking we use a much higher count to ensure loads of context
|
||||
switches occur during the count. */
|
||||
* switches occur during the count. */
|
||||
if( pxParameters->xBlockTime > ( TickType_t ) 0 )
|
||||
{
|
||||
ulExpectedValue = semtstBLOCKING_EXPECTED_VALUE;
|
||||
|
|
@ -196,14 +197,14 @@ short sError = pdFALSE, sCheckVariableToUse;
|
|||
ulExpectedValue = semtstNON_BLOCKING_EXPECTED_VALUE;
|
||||
}
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Try to obtain the semaphore. */
|
||||
if( xSemaphoreTake( pxParameters->xSemaphore, pxParameters->xBlockTime ) == pdPASS )
|
||||
{
|
||||
/* We have the semaphore and so expect any other tasks using the
|
||||
shared variable to have left it in the state we expect to find
|
||||
it. */
|
||||
* shared variable to have left it in the state we expect to find
|
||||
* it. */
|
||||
if( *pulSharedVariable != ulExpectedValue )
|
||||
{
|
||||
vPrintDisplayMessage( &pcPollingSemaphoreTaskError );
|
||||
|
|
@ -211,23 +212,25 @@ short sError = pdFALSE, sCheckVariableToUse;
|
|||
}
|
||||
|
||||
/* Clear the variable, then count it back up to the expected value
|
||||
before releasing the semaphore. Would expect a context switch or
|
||||
two during this time. */
|
||||
* before releasing the semaphore. Would expect a context switch or
|
||||
* two during this time. */
|
||||
for( ulCounter = ( unsigned long ) 0; ulCounter <= ulExpectedValue; ulCounter++ )
|
||||
{
|
||||
*pulSharedVariable = ulCounter;
|
||||
|
||||
if( *pulSharedVariable != ulCounter )
|
||||
{
|
||||
if( sError == pdFALSE )
|
||||
{
|
||||
vPrintDisplayMessage( &pcPollingSemaphoreTaskError );
|
||||
}
|
||||
|
||||
sError = pdTRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Release the semaphore, and if no errors have occurred increment the check
|
||||
variable. */
|
||||
* variable. */
|
||||
if( xSemaphoreGive( pxParameters->xSemaphore ) == pdFALSE )
|
||||
{
|
||||
vPrintDisplayMessage( &pcPollingSemaphoreTaskError );
|
||||
|
|
@ -243,10 +246,10 @@ short sError = pdFALSE, sCheckVariableToUse;
|
|||
}
|
||||
|
||||
/* If we have a block time then we are running at a priority higher
|
||||
than the idle priority. This task takes a long time to complete
|
||||
a cycle (deliberately so to test the guarding) so will be starving
|
||||
out lower priority tasks. Block for some time to allow give lower
|
||||
priority tasks some processor time. */
|
||||
* than the idle priority. This task takes a long time to complete
|
||||
* a cycle (deliberately so to test the guarding) so will be starving
|
||||
* out lower priority tasks. Block for some time to allow give lower
|
||||
* priority tasks some processor time. */
|
||||
vTaskDelay( pxParameters->xBlockTime * semtstDELAY_FACTOR );
|
||||
}
|
||||
else
|
||||
|
|
@ -254,8 +257,8 @@ short sError = pdFALSE, sCheckVariableToUse;
|
|||
if( pxParameters->xBlockTime == ( TickType_t ) 0 )
|
||||
{
|
||||
/* We have not got the semaphore yet, so no point using the
|
||||
processor. We are not blocking when attempting to obtain the
|
||||
semaphore. */
|
||||
* processor. We are not blocking when attempting to obtain the
|
||||
* semaphore. */
|
||||
taskYIELD();
|
||||
}
|
||||
}
|
||||
|
|
@ -266,8 +269,8 @@ short sError = pdFALSE, sCheckVariableToUse;
|
|||
/* This is called to check that all the created tasks are still running. */
|
||||
BaseType_t xAreSemaphoreTasksStillRunning( void )
|
||||
{
|
||||
static short sLastCheckVariables[ semtstNUM_TASKS ] = { 0 };
|
||||
portBASE_TYPE xTask, xReturn = pdTRUE;
|
||||
static short sLastCheckVariables[ semtstNUM_TASKS ] = { 0 };
|
||||
portBASE_TYPE xTask, xReturn = pdTRUE;
|
||||
|
||||
for( xTask = 0; xTask < semtstNUM_TASKS; xTask++ )
|
||||
{
|
||||
|
|
@ -281,5 +284,3 @@ portBASE_TYPE xTask, xReturn = pdTRUE;
|
|||
|
||||
return xReturn;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -47,32 +47,32 @@
|
|||
#include "AbortDelay.h"
|
||||
|
||||
/* This file can only be used if the functionality it tests is included in the
|
||||
build. Remove the whole file if this is not the case. */
|
||||
#if( INCLUDE_xTaskAbortDelay == 1 )
|
||||
* build. Remove the whole file if this is not the case. */
|
||||
#if ( INCLUDE_xTaskAbortDelay == 1 )
|
||||
|
||||
#if( INCLUDE_xTaskGetHandle != 1 )
|
||||
#if ( INCLUDE_xTaskGetHandle != 1 )
|
||||
#error This test file uses the xTaskGetHandle() API function so INCLUDE_xTaskGetHandle must be set to 1 in FreeRTOSConfig.h.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Task priorities. Allow these to be overridden. */
|
||||
#ifndef abtCONTROLLING_PRIORITY
|
||||
#ifndef abtCONTROLLING_PRIORITY
|
||||
#define abtCONTROLLING_PRIORITY ( configMAX_PRIORITIES - 3 )
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef abtBLOCKING_PRIORITY
|
||||
#ifndef abtBLOCKING_PRIORITY
|
||||
#define abtBLOCKING_PRIORITY ( configMAX_PRIORITIES - 2 )
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* The tests that are performed. */
|
||||
#define abtNOTIFY_WAIT_ABORTS 0
|
||||
#define abtNOTIFY_TAKE_ABORTS 1
|
||||
#define abtDELAY_ABORTS 2
|
||||
#define abtDELAY_UNTIL_ABORTS 3
|
||||
#define abtSEMAPHORE_TAKE_ABORTS 4
|
||||
#define abtEVENT_GROUP_ABORTS 5
|
||||
#define abtQUEUE_SEND_ABORTS 6
|
||||
#define abtSTREAM_BUFFER_RECEIVE 7
|
||||
#define abtMAX_TESTS 8
|
||||
#define abtNOTIFY_WAIT_ABORTS 0
|
||||
#define abtNOTIFY_TAKE_ABORTS 1
|
||||
#define abtDELAY_ABORTS 2
|
||||
#define abtDELAY_UNTIL_ABORTS 3
|
||||
#define abtSEMAPHORE_TAKE_ABORTS 4
|
||||
#define abtEVENT_GROUP_ABORTS 5
|
||||
#define abtQUEUE_SEND_ABORTS 6
|
||||
#define abtSTREAM_BUFFER_RECEIVE 7
|
||||
#define abtMAX_TESTS 8
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
|
|
@ -80,8 +80,8 @@ build. Remove the whole file if this is not the case. */
|
|||
* The two test tasks. The controlling task specifies which test to executed.
|
||||
* More information is provided in the comments within the tasks.
|
||||
*/
|
||||
static void prvControllingTask( void *pvParameters );
|
||||
static void prvBlockingTask( void *pvParameters );
|
||||
static void prvControllingTask( void * pvParameters );
|
||||
static void prvBlockingTask( void * pvParameters );
|
||||
|
||||
/*
|
||||
* Test functions called by the blocking task. Each function follows the same
|
||||
|
|
@ -92,62 +92,63 @@ static void prvBlockingTask( void *pvParameters );
|
|||
* expected to be aborted by the controlling task half way through the block
|
||||
* time.
|
||||
*/
|
||||
static void prvTestAbortingTaskNotifyWait( void );
|
||||
static void prvTestAbortingTaskNotifyTake( void );
|
||||
static void prvTestAbortingTaskDelay( void );
|
||||
static void prvTestAbortingTaskDelayUntil( void );
|
||||
static void prvTestAbortingSemaphoreTake( void );
|
||||
static void prvTestAbortingEventGroupWait( void );
|
||||
static void prvTestAbortingQueueSend( void );
|
||||
static void prvTestAbortingStreamBufferReceive( void );
|
||||
static void prvTestAbortingTaskNotifyWait( void );
|
||||
static void prvTestAbortingTaskNotifyTake( void );
|
||||
static void prvTestAbortingTaskDelay( void );
|
||||
static void prvTestAbortingTaskDelayUntil( void );
|
||||
static void prvTestAbortingSemaphoreTake( void );
|
||||
static void prvTestAbortingEventGroupWait( void );
|
||||
static void prvTestAbortingQueueSend( void );
|
||||
static void prvTestAbortingStreamBufferReceive( void );
|
||||
|
||||
/*
|
||||
* Performs a few tests to cover code paths not otherwise covered by the continuous
|
||||
* tests.
|
||||
*/
|
||||
static void prvPerformSingleTaskTests( void );
|
||||
static void prvPerformSingleTaskTests( void );
|
||||
|
||||
/*
|
||||
* Checks the amount of time a task spent in the Blocked state is within the
|
||||
* expected bounds.
|
||||
*/
|
||||
static void prvCheckExpectedTimeIsWithinAnAcceptableMargin( TickType_t xStartTime, TickType_t xExpectedBlockTime );
|
||||
static void prvCheckExpectedTimeIsWithinAnAcceptableMargin( TickType_t xStartTime,
|
||||
TickType_t xExpectedBlockTime );
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Used to ensure that tasks are still executing without error. */
|
||||
static volatile BaseType_t xControllingCycles = 0, xBlockingCycles = 0;
|
||||
static volatile BaseType_t xErrorOccurred = pdFALSE;
|
||||
static volatile BaseType_t xControllingCycles = 0, xBlockingCycles = 0;
|
||||
static volatile BaseType_t xErrorOccurred = pdFALSE;
|
||||
|
||||
/* Each task needs to know the other tasks handle so they can send signals to
|
||||
each other. The handle is obtained from the task's name. */
|
||||
static const char *pcControllingTaskName = "AbtCtrl", *pcBlockingTaskName = "AbtBlk";
|
||||
* each other. The handle is obtained from the task's name. */
|
||||
static const char * pcControllingTaskName = "AbtCtrl", * pcBlockingTaskName = "AbtBlk";
|
||||
|
||||
/* The maximum amount of time a task will block for. */
|
||||
const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 100 );
|
||||
const TickType_t xHalfMaxBlockTime = pdMS_TO_TICKS( 50 );
|
||||
const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 100 );
|
||||
const TickType_t xHalfMaxBlockTime = pdMS_TO_TICKS( 50 );
|
||||
|
||||
/* The actual block time is dependent on the priority of other tasks in the
|
||||
system so the actual block time might be greater than that expected, but it
|
||||
should be within an acceptable upper bound. */
|
||||
const TickType_t xAllowableMargin = pdMS_TO_TICKS( 7 );
|
||||
* system so the actual block time might be greater than that expected, but it
|
||||
* should be within an acceptable upper bound. */
|
||||
const TickType_t xAllowableMargin = pdMS_TO_TICKS( 7 );
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vCreateAbortDelayTasks( void )
|
||||
{
|
||||
void vCreateAbortDelayTasks( void )
|
||||
{
|
||||
/* Create the two test tasks described above. */
|
||||
xTaskCreate( prvControllingTask, pcControllingTaskName, configMINIMAL_STACK_SIZE, NULL, abtCONTROLLING_PRIORITY, NULL );
|
||||
xTaskCreate( prvBlockingTask, pcBlockingTaskName, configMINIMAL_STACK_SIZE, NULL, abtBLOCKING_PRIORITY, NULL );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvControllingTask( void *pvParameters )
|
||||
{
|
||||
TaskHandle_t xBlockingTask;
|
||||
uint32_t ulTestToPerform = abtNOTIFY_WAIT_ABORTS;
|
||||
TickType_t xTimeAtStart;
|
||||
const TickType_t xStartMargin = 2UL;
|
||||
static void prvControllingTask( void * pvParameters )
|
||||
{
|
||||
TaskHandle_t xBlockingTask;
|
||||
uint32_t ulTestToPerform = abtNOTIFY_WAIT_ABORTS;
|
||||
TickType_t xTimeAtStart;
|
||||
const TickType_t xStartMargin = 2UL;
|
||||
|
||||
/* Just to remove compiler warnings. */
|
||||
( void ) pvParameters;
|
||||
|
|
@ -155,25 +156,26 @@ const TickType_t xStartMargin = 2UL;
|
|||
xBlockingTask = xTaskGetHandle( pcBlockingTaskName );
|
||||
configASSERT( xBlockingTask );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Tell the secondary task to perform the next test. */
|
||||
xTimeAtStart = xTaskGetTickCount();
|
||||
xTaskNotify( xBlockingTask, ulTestToPerform, eSetValueWithOverwrite );
|
||||
|
||||
/* The secondary task has a higher priority, so will now be in the
|
||||
Blocked state to wait for a maximum of xMaxBlockTime. It expects that
|
||||
period to complete with a timeout. It will then block for
|
||||
xMaxBlockTimeAgain, but this time it expects to the block time to abort
|
||||
half way through. Block until it is time to send the abort to the
|
||||
secondary task. xStartMargin is used because this task takes timing
|
||||
from the beginning of the test, whereas the blocking task takes timing
|
||||
from the entry into the Blocked state - and as the tasks run at
|
||||
different priorities, there may be some discrepancy. Also, temporarily
|
||||
raise the priority of the controlling task to that of the blocking
|
||||
task to minimise discrepancies. */
|
||||
* Blocked state to wait for a maximum of xMaxBlockTime. It expects that
|
||||
* period to complete with a timeout. It will then block for
|
||||
* xMaxBlockTimeAgain, but this time it expects to the block time to abort
|
||||
* half way through. Block until it is time to send the abort to the
|
||||
* secondary task. xStartMargin is used because this task takes timing
|
||||
* from the beginning of the test, whereas the blocking task takes timing
|
||||
* from the entry into the Blocked state - and as the tasks run at
|
||||
* different priorities, there may be some discrepancy. Also, temporarily
|
||||
* raise the priority of the controlling task to that of the blocking
|
||||
* task to minimise discrepancies. */
|
||||
vTaskPrioritySet( NULL, abtBLOCKING_PRIORITY );
|
||||
vTaskDelay( xMaxBlockTime + xHalfMaxBlockTime + xStartMargin );
|
||||
|
||||
if( xTaskAbortDelay( xBlockingTask ) != pdPASS )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
|
|
@ -183,12 +185,12 @@ const TickType_t xStartMargin = 2UL;
|
|||
vTaskPrioritySet( NULL, abtCONTROLLING_PRIORITY );
|
||||
|
||||
/* Now wait to be notified that the secondary task has completed its
|
||||
test. */
|
||||
* test. */
|
||||
ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
|
||||
|
||||
/* Did the entire test run for the expected time, which is two full
|
||||
block times plus the half block time caused by calling
|
||||
xTaskAbortDelay()? */
|
||||
* block times plus the half block time caused by calling
|
||||
* xTaskAbortDelay()? */
|
||||
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, ( xMaxBlockTime + xMaxBlockTime + xHalfMaxBlockTime ) );
|
||||
|
||||
/* Move onto the next test. */
|
||||
|
|
@ -202,26 +204,26 @@ const TickType_t xStartMargin = 2UL;
|
|||
/* To indicate this task is still executing. */
|
||||
xControllingCycles++;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvBlockingTask( void *pvParameters )
|
||||
{
|
||||
TaskHandle_t xControllingTask;
|
||||
uint32_t ulNotificationValue;
|
||||
const uint32_t ulMax = 0xffffffffUL;
|
||||
static void prvBlockingTask( void * pvParameters )
|
||||
{
|
||||
TaskHandle_t xControllingTask;
|
||||
uint32_t ulNotificationValue;
|
||||
const uint32_t ulMax = 0xffffffffUL;
|
||||
|
||||
/* Just to remove compiler warnings. */
|
||||
( void ) pvParameters;
|
||||
|
||||
/* Start by performing a few tests to cover code not exercised in the loops
|
||||
below. */
|
||||
* below. */
|
||||
prvPerformSingleTaskTests();
|
||||
|
||||
xControllingTask = xTaskGetHandle( pcControllingTaskName );
|
||||
configASSERT( xControllingTask );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Wait to be notified of the test that is to be performed next. */
|
||||
xTaskNotifyWait( 0, ulMax, &ulNotificationValue, portMAX_DELAY );
|
||||
|
|
@ -271,52 +273,54 @@ const uint32_t ulMax = 0xffffffffUL;
|
|||
/* To indicate this task is still executing. */
|
||||
xBlockingCycles++;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvPerformSingleTaskTests( void )
|
||||
{
|
||||
TaskHandle_t xThisTask;
|
||||
BaseType_t xReturned;
|
||||
static void prvPerformSingleTaskTests( void )
|
||||
{
|
||||
TaskHandle_t xThisTask;
|
||||
BaseType_t xReturned;
|
||||
|
||||
/* Try unblocking this task using both the task and ISR versions of the API -
|
||||
both should return false as this task is not blocked. */
|
||||
* both should return false as this task is not blocked. */
|
||||
xThisTask = xTaskGetCurrentTaskHandle();
|
||||
|
||||
xReturned = xTaskAbortDelay( xThisTask );
|
||||
|
||||
if( xReturned != pdFALSE )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvTestAbortingTaskDelayUntil( void )
|
||||
{
|
||||
TickType_t xTimeAtStart, xLastBlockTime;
|
||||
BaseType_t xReturned;
|
||||
static void prvTestAbortingTaskDelayUntil( void )
|
||||
{
|
||||
TickType_t xTimeAtStart, xLastBlockTime;
|
||||
BaseType_t xReturned;
|
||||
|
||||
/* Note the time before the delay so the length of the delay is known. */
|
||||
xTimeAtStart = xTaskGetTickCount();
|
||||
|
||||
/* Take a copy of the time as it is updated in the call to
|
||||
xTaskDelayUntil() but its original value is needed to determine the actual
|
||||
time spend in the Blocked state. */
|
||||
* xTaskDelayUntil() but its original value is needed to determine the actual
|
||||
* time spend in the Blocked state. */
|
||||
xLastBlockTime = xTimeAtStart;
|
||||
|
||||
/* This first delay should just time out. */
|
||||
xReturned = xTaskDelayUntil( &xLastBlockTime, xMaxBlockTime );
|
||||
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
|
||||
configASSERT( xReturned == pdTRUE );
|
||||
|
||||
/* Remove compiler warning about value being set but not used in the case
|
||||
configASSERT() is not defined. */
|
||||
* configASSERT() is not defined. */
|
||||
( void ) xReturned;
|
||||
|
||||
/* This second delay should be aborted by the primary task half way
|
||||
through. Again take a copy of the time as it is updated in the call to
|
||||
vTaskDelayUntil() buts its original value is needed to determine the amount
|
||||
of time actually spent in the Blocked state. This uses vTaskDelayUntil()
|
||||
in place of xTaskDelayUntil() for test coverage. */
|
||||
* through. Again take a copy of the time as it is updated in the call to
|
||||
* vTaskDelayUntil() buts its original value is needed to determine the amount
|
||||
* of time actually spent in the Blocked state. This uses vTaskDelayUntil()
|
||||
* in place of xTaskDelayUntil() for test coverage. */
|
||||
xTimeAtStart = xTaskGetTickCount();
|
||||
xLastBlockTime = xTimeAtStart;
|
||||
vTaskDelayUntil( &xLastBlockTime, xMaxBlockTime );
|
||||
|
|
@ -328,15 +332,16 @@ BaseType_t xReturned;
|
|||
xReturned = xTaskDelayUntil( &xLastBlockTime, xMaxBlockTime );
|
||||
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
|
||||
configASSERT( xReturned == pdTRUE );
|
||||
|
||||
/* Remove compiler warning about value being set but not used in the case
|
||||
configASSERT() is not defined. */
|
||||
* configASSERT() is not defined. */
|
||||
( void ) xReturned;
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvTestAbortingTaskDelay( void )
|
||||
{
|
||||
TickType_t xTimeAtStart;
|
||||
static void prvTestAbortingTaskDelay( void )
|
||||
{
|
||||
TickType_t xTimeAtStart;
|
||||
|
||||
/* Note the time before the delay so the length of the delay is known. */
|
||||
xTimeAtStart = xTaskGetTickCount();
|
||||
|
|
@ -349,7 +354,7 @@ TickType_t xTimeAtStart;
|
|||
xTimeAtStart = xTaskGetTickCount();
|
||||
|
||||
/* This second delay should be aborted by the primary task half way
|
||||
through. */
|
||||
* through. */
|
||||
vTaskDelay( xMaxBlockTime );
|
||||
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xHalfMaxBlockTime );
|
||||
|
||||
|
|
@ -359,35 +364,39 @@ TickType_t xTimeAtStart;
|
|||
/* This third delay should just time out again. */
|
||||
vTaskDelay( xMaxBlockTime );
|
||||
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvTestAbortingTaskNotifyTake( void )
|
||||
{
|
||||
TickType_t xTimeAtStart;
|
||||
uint32_t ulReturn;
|
||||
static void prvTestAbortingTaskNotifyTake( void )
|
||||
{
|
||||
TickType_t xTimeAtStart;
|
||||
uint32_t ulReturn;
|
||||
|
||||
/* Note the time before the delay so the length of the delay is known. */
|
||||
xTimeAtStart = xTaskGetTickCount();
|
||||
|
||||
/* This first delay should just time out. */
|
||||
ulReturn = ulTaskNotifyTake( pdFALSE, xMaxBlockTime );
|
||||
|
||||
if( ulReturn != 0 )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
|
||||
|
||||
/* Note the time before the delay so the length of the delay is known. */
|
||||
xTimeAtStart = xTaskGetTickCount();
|
||||
|
||||
/* This second delay should be aborted by the primary task half way
|
||||
through. */
|
||||
* through. */
|
||||
ulReturn = ulTaskNotifyTake( pdFALSE, xMaxBlockTime );
|
||||
|
||||
if( ulReturn != 0 )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xHalfMaxBlockTime );
|
||||
|
||||
/* Note the time before the delay so the length of the delay is known. */
|
||||
|
|
@ -395,26 +404,28 @@ uint32_t ulReturn;
|
|||
|
||||
/* This third delay should just time out again. */
|
||||
ulReturn = ulTaskNotifyTake( pdFALSE, xMaxBlockTime );
|
||||
|
||||
if( ulReturn != 0 )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvTestAbortingEventGroupWait( void )
|
||||
{
|
||||
TickType_t xTimeAtStart;
|
||||
EventGroupHandle_t xEventGroup;
|
||||
EventBits_t xBitsToWaitFor = ( EventBits_t ) 0x01, xReturn;
|
||||
static void prvTestAbortingEventGroupWait( void )
|
||||
{
|
||||
TickType_t xTimeAtStart;
|
||||
EventGroupHandle_t xEventGroup;
|
||||
EventBits_t xBitsToWaitFor = ( EventBits_t ) 0x01, xReturn;
|
||||
|
||||
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
{
|
||||
static StaticEventGroup_t xEventGroupBuffer;
|
||||
|
||||
/* Create the event group. Statically allocated memory is used so the
|
||||
creation cannot fail. */
|
||||
* creation cannot fail. */
|
||||
xEventGroup = xEventGroupCreateStatic( &xEventGroupBuffer );
|
||||
}
|
||||
#else
|
||||
|
|
@ -422,29 +433,33 @@ EventBits_t xBitsToWaitFor = ( EventBits_t ) 0x01, xReturn;
|
|||
xEventGroup = xEventGroupCreate();
|
||||
configASSERT( xEventGroup );
|
||||
}
|
||||
#endif
|
||||
#endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
|
||||
|
||||
/* Note the time before the delay so the length of the delay is known. */
|
||||
xTimeAtStart = xTaskGetTickCount();
|
||||
|
||||
/* This first delay should just time out. */
|
||||
xReturn = xEventGroupWaitBits( xEventGroup, xBitsToWaitFor, pdTRUE, pdTRUE, xMaxBlockTime );
|
||||
|
||||
if( xReturn != 0x00 )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
|
||||
|
||||
/* Note the time before the delay so the length of the delay is known. */
|
||||
xTimeAtStart = xTaskGetTickCount();
|
||||
|
||||
/* This second delay should be aborted by the primary task half way
|
||||
through. */
|
||||
* through. */
|
||||
xReturn = xEventGroupWaitBits( xEventGroup, xBitsToWaitFor, pdTRUE, pdTRUE, xMaxBlockTime );
|
||||
|
||||
if( xReturn != 0x00 )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xHalfMaxBlockTime );
|
||||
|
||||
/* Note the time before the delay so the length of the delay is known. */
|
||||
|
|
@ -452,29 +467,31 @@ EventBits_t xBitsToWaitFor = ( EventBits_t ) 0x01, xReturn;
|
|||
|
||||
/* This third delay should just time out again. */
|
||||
xReturn = xEventGroupWaitBits( xEventGroup, xBitsToWaitFor, pdTRUE, pdTRUE, xMaxBlockTime );
|
||||
|
||||
if( xReturn != 0x00 )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
|
||||
|
||||
/* Not really necessary in this case, but for completeness. */
|
||||
vEventGroupDelete( xEventGroup );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvTestAbortingStreamBufferReceive( void )
|
||||
{
|
||||
TickType_t xTimeAtStart;
|
||||
StreamBufferHandle_t xStreamBuffer;
|
||||
size_t xReturn;
|
||||
const size_t xTriggerLevelBytes = ( size_t ) 1;
|
||||
uint8_t uxRxData;
|
||||
static void prvTestAbortingStreamBufferReceive( void )
|
||||
{
|
||||
TickType_t xTimeAtStart;
|
||||
StreamBufferHandle_t xStreamBuffer;
|
||||
size_t xReturn;
|
||||
const size_t xTriggerLevelBytes = ( size_t ) 1;
|
||||
uint8_t uxRxData;
|
||||
|
||||
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
{
|
||||
/* Defines the memory that will actually hold the streams within the
|
||||
stream buffer. */
|
||||
* stream buffer. */
|
||||
static uint8_t ucStorageBuffer[ sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ) + 1 ];
|
||||
|
||||
/* The variable used to hold the stream buffer structure. */
|
||||
|
|
@ -486,34 +503,38 @@ uint8_t uxRxData;
|
|||
ucStorageBuffer,
|
||||
&xStreamBufferStruct );
|
||||
}
|
||||
#else
|
||||
#else /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
|
||||
{
|
||||
xStreamBuffer = xStreamBufferCreate( sizeof( uint8_t ), xTriggerLevelBytes );
|
||||
configASSERT( xStreamBuffer );
|
||||
}
|
||||
#endif
|
||||
#endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
|
||||
|
||||
/* Note the time before the delay so the length of the delay is known. */
|
||||
xTimeAtStart = xTaskGetTickCount();
|
||||
|
||||
/* This first delay should just time out. */
|
||||
xReturn = xStreamBufferReceive( xStreamBuffer, &uxRxData, sizeof( uxRxData ), xMaxBlockTime );
|
||||
|
||||
if( xReturn != 0x00 )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
|
||||
|
||||
/* Note the time before the delay so the length of the delay is known. */
|
||||
xTimeAtStart = xTaskGetTickCount();
|
||||
|
||||
/* This second delay should be aborted by the primary task half way
|
||||
through xMaxBlockTime. */
|
||||
* through xMaxBlockTime. */
|
||||
xReturn = xStreamBufferReceive( xStreamBuffer, &uxRxData, sizeof( uxRxData ), xMaxBlockTime );
|
||||
|
||||
if( xReturn != 0x00 )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xHalfMaxBlockTime );
|
||||
|
||||
/* Note the time before the delay so the length of the delay is known. */
|
||||
|
|
@ -521,32 +542,34 @@ uint8_t uxRxData;
|
|||
|
||||
/* This third delay should just time out again. */
|
||||
xReturn = xStreamBufferReceive( xStreamBuffer, &uxRxData, sizeof( uxRxData ), xMaxBlockTime );
|
||||
|
||||
if( xReturn != 0x00 )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
|
||||
|
||||
/* Not really necessary in this case, but for completeness. */
|
||||
vStreamBufferDelete( xStreamBuffer );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvTestAbortingQueueSend( void )
|
||||
{
|
||||
TickType_t xTimeAtStart;
|
||||
BaseType_t xReturn;
|
||||
const UBaseType_t xQueueLength = ( UBaseType_t ) 1;
|
||||
QueueHandle_t xQueue;
|
||||
uint8_t ucItemToQueue;
|
||||
static void prvTestAbortingQueueSend( void )
|
||||
{
|
||||
TickType_t xTimeAtStart;
|
||||
BaseType_t xReturn;
|
||||
const UBaseType_t xQueueLength = ( UBaseType_t ) 1;
|
||||
QueueHandle_t xQueue;
|
||||
uint8_t ucItemToQueue;
|
||||
|
||||
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
{
|
||||
static StaticQueue_t xQueueBuffer;
|
||||
static uint8_t ucQueueStorage[ sizeof( uint8_t ) ];
|
||||
|
||||
/* Create the queue. Statically allocated memory is used so the
|
||||
creation cannot fail. */
|
||||
* creation cannot fail. */
|
||||
xQueue = xQueueCreateStatic( xQueueLength, sizeof( uint8_t ), ucQueueStorage, &xQueueBuffer );
|
||||
}
|
||||
#else
|
||||
|
|
@ -554,11 +577,12 @@ uint8_t ucItemToQueue;
|
|||
xQueue = xQueueCreate( xQueueLength, sizeof( uint8_t ) );
|
||||
configASSERT( xQueue );
|
||||
}
|
||||
#endif
|
||||
#endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
|
||||
|
||||
/* This function tests aborting when in the blocked state waiting to send,
|
||||
so the queue must be full. There is only one space in the queue. */
|
||||
* so the queue must be full. There is only one space in the queue. */
|
||||
xReturn = xQueueSend( xQueue, &ucItemToQueue, xMaxBlockTime );
|
||||
|
||||
if( xReturn != pdPASS )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
|
|
@ -569,22 +593,26 @@ uint8_t ucItemToQueue;
|
|||
|
||||
/* This first delay should just time out. */
|
||||
xReturn = xQueueSend( xQueue, &ucItemToQueue, xMaxBlockTime );
|
||||
|
||||
if( xReturn != pdFALSE )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
|
||||
|
||||
/* Note the time before the delay so the length of the delay is known. */
|
||||
xTimeAtStart = xTaskGetTickCount();
|
||||
|
||||
/* This second delay should be aborted by the primary task half way
|
||||
through. */
|
||||
* through. */
|
||||
xReturn = xQueueSend( xQueue, &ucItemToQueue, xMaxBlockTime );
|
||||
|
||||
if( xReturn != pdFALSE )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xHalfMaxBlockTime );
|
||||
|
||||
/* Note the time before the delay so the length of the delay is known. */
|
||||
|
|
@ -592,29 +620,31 @@ uint8_t ucItemToQueue;
|
|||
|
||||
/* This third delay should just time out again. */
|
||||
xReturn = xQueueSend( xQueue, &ucItemToQueue, xMaxBlockTime );
|
||||
|
||||
if( xReturn != pdFALSE )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
|
||||
|
||||
/* Not really necessary in this case, but for completeness. */
|
||||
vQueueDelete( xQueue );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvTestAbortingSemaphoreTake( void )
|
||||
{
|
||||
TickType_t xTimeAtStart;
|
||||
BaseType_t xReturn;
|
||||
SemaphoreHandle_t xSemaphore;
|
||||
static void prvTestAbortingSemaphoreTake( void )
|
||||
{
|
||||
TickType_t xTimeAtStart;
|
||||
BaseType_t xReturn;
|
||||
SemaphoreHandle_t xSemaphore;
|
||||
|
||||
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
{
|
||||
static StaticSemaphore_t xSemaphoreBuffer;
|
||||
|
||||
/* Create the semaphore. Statically allocated memory is used so the
|
||||
creation cannot fail. */
|
||||
* creation cannot fail. */
|
||||
xSemaphore = xSemaphoreCreateBinaryStatic( &xSemaphoreBuffer );
|
||||
}
|
||||
#else
|
||||
|
|
@ -628,22 +658,26 @@ SemaphoreHandle_t xSemaphore;
|
|||
|
||||
/* This first delay should just time out. */
|
||||
xReturn = xSemaphoreTake( xSemaphore, xMaxBlockTime );
|
||||
|
||||
if( xReturn != pdFALSE )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
|
||||
|
||||
/* Note the time before the delay so the length of the delay is known. */
|
||||
xTimeAtStart = xTaskGetTickCount();
|
||||
|
||||
/* This second delay should be aborted by the primary task half way
|
||||
through xMaxBlockTime. */
|
||||
* through xMaxBlockTime. */
|
||||
xReturn = xSemaphoreTake( xSemaphore, portMAX_DELAY );
|
||||
|
||||
if( xReturn != pdFALSE )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xHalfMaxBlockTime );
|
||||
|
||||
/* Note the time before the delay so the length of the delay is known. */
|
||||
|
|
@ -651,43 +685,49 @@ SemaphoreHandle_t xSemaphore;
|
|||
|
||||
/* This third delay should just time out again. */
|
||||
xReturn = xSemaphoreTake( xSemaphore, xMaxBlockTime );
|
||||
|
||||
if( xReturn != pdFALSE )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
|
||||
|
||||
/* Not really necessary in this case, but for completeness. */
|
||||
vSemaphoreDelete( xSemaphore );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvTestAbortingTaskNotifyWait( void )
|
||||
{
|
||||
TickType_t xTimeAtStart;
|
||||
BaseType_t xReturn;
|
||||
static void prvTestAbortingTaskNotifyWait( void )
|
||||
{
|
||||
TickType_t xTimeAtStart;
|
||||
BaseType_t xReturn;
|
||||
|
||||
/* Note the time before the delay so the length of the delay is known. */
|
||||
xTimeAtStart = xTaskGetTickCount();
|
||||
|
||||
/* This first delay should just time out. */
|
||||
xReturn = xTaskNotifyWait( 0, 0, NULL, xMaxBlockTime );
|
||||
|
||||
if( xReturn != pdFALSE )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
|
||||
|
||||
/* Note the time before the delay so the length of the delay is known. */
|
||||
xTimeAtStart = xTaskGetTickCount();
|
||||
|
||||
/* This second delay should be aborted by the primary task half way
|
||||
through xMaxBlockTime. */
|
||||
* through xMaxBlockTime. */
|
||||
xReturn = xTaskNotifyWait( 0, 0, NULL, portMAX_DELAY );
|
||||
|
||||
if( xReturn != pdFALSE )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xHalfMaxBlockTime );
|
||||
|
||||
/* Note the time before the delay so the length of the delay is known. */
|
||||
|
|
@ -695,17 +735,20 @@ BaseType_t xReturn;
|
|||
|
||||
/* This third delay should just time out again. */
|
||||
xReturn = xTaskNotifyWait( 0, 0, NULL, xMaxBlockTime );
|
||||
|
||||
if( xReturn != pdFALSE )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvCheckExpectedTimeIsWithinAnAcceptableMargin( TickType_t xStartTime, TickType_t xExpectedBlockTime )
|
||||
{
|
||||
TickType_t xTimeNow, xActualBlockTime;
|
||||
static void prvCheckExpectedTimeIsWithinAnAcceptableMargin( TickType_t xStartTime,
|
||||
TickType_t xExpectedBlockTime )
|
||||
{
|
||||
TickType_t xTimeNow, xActualBlockTime;
|
||||
|
||||
xTimeNow = xTaskGetTickCount();
|
||||
xActualBlockTime = xTimeNow - xStartTime;
|
||||
|
|
@ -717,22 +760,22 @@ TickType_t xTimeNow, xActualBlockTime;
|
|||
}
|
||||
|
||||
/* The actual block time can be greater than the expected block time, as it
|
||||
depends on the priority of the other tasks, but it should be within an
|
||||
acceptable margin. */
|
||||
* depends on the priority of the other tasks, but it should be within an
|
||||
* acceptable margin. */
|
||||
if( xActualBlockTime > ( xExpectedBlockTime + xAllowableMargin ) )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
BaseType_t xAreAbortDelayTestTasksStillRunning( void )
|
||||
{
|
||||
static BaseType_t xLastControllingCycleCount = 0, xLastBlockingCycleCount = 0;
|
||||
BaseType_t xReturn = pdPASS;
|
||||
BaseType_t xAreAbortDelayTestTasksStillRunning( void )
|
||||
{
|
||||
static BaseType_t xLastControllingCycleCount = 0, xLastBlockingCycleCount = 0;
|
||||
BaseType_t xReturn = pdPASS;
|
||||
|
||||
/* Have both tasks performed at least one cycle since this function was
|
||||
last called? */
|
||||
* last called? */
|
||||
if( xControllingCycles == xLastControllingCycleCount )
|
||||
{
|
||||
xReturn = pdFAIL;
|
||||
|
|
@ -752,6 +795,6 @@ BaseType_t xReturn = pdPASS;
|
|||
xLastControllingCycleCount = xControllingCycles;
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* INCLUDE_xTaskAbortDelay == 1 */
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@
|
|||
#define blckqSTACK_SIZE configMINIMAL_STACK_SIZE
|
||||
#define blckqNUM_TASK_SETS ( 3 )
|
||||
|
||||
#if( configSUPPORT_DYNAMIC_ALLOCATION == 0 )
|
||||
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 0 )
|
||||
#error This example cannot be used if dynamic allocation is not allowed.
|
||||
#endif
|
||||
|
||||
|
|
@ -71,35 +71,35 @@ typedef struct BLOCKING_QUEUE_PARAMETERS
|
|||
{
|
||||
QueueHandle_t xQueue; /*< The queue to be used by the task. */
|
||||
TickType_t xBlockTime; /*< The block time to use on queue reads/writes. */
|
||||
volatile short *psCheckVariable; /*< Incremented on each successful cycle to check the task is still running. */
|
||||
volatile short * psCheckVariable; /*< Incremented on each successful cycle to check the task is still running. */
|
||||
} xBlockingQueueParameters;
|
||||
|
||||
/* Task function that creates an incrementing number and posts it on a queue. */
|
||||
static portTASK_FUNCTION_PROTO( vBlockingQueueProducer, pvParameters );
|
||||
|
||||
/* Task function that removes the incrementing number from a queue and checks that
|
||||
it is the expected number. */
|
||||
* it is the expected number. */
|
||||
static portTASK_FUNCTION_PROTO( vBlockingQueueConsumer, pvParameters );
|
||||
|
||||
/* Variables which are incremented each time an item is removed from a queue, and
|
||||
found to be the expected value.
|
||||
These are used to check that the tasks are still running. */
|
||||
* found to be the expected value.
|
||||
* These are used to check that the tasks are still running. */
|
||||
static volatile short sBlockingConsumerCount[ blckqNUM_TASK_SETS ] = { ( uint16_t ) 0, ( uint16_t ) 0, ( uint16_t ) 0 };
|
||||
|
||||
/* Variable which are incremented each time an item is posted on a queue. These
|
||||
are used to check that the tasks are still running. */
|
||||
* are used to check that the tasks are still running. */
|
||||
static volatile short sBlockingProducerCount[ blckqNUM_TASK_SETS ] = { ( uint16_t ) 0, ( uint16_t ) 0, ( uint16_t ) 0 };
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vStartBlockingQueueTasks( UBaseType_t uxPriority )
|
||||
{
|
||||
xBlockingQueueParameters *pxQueueParameters1, *pxQueueParameters2;
|
||||
xBlockingQueueParameters *pxQueueParameters3, *pxQueueParameters4;
|
||||
xBlockingQueueParameters *pxQueueParameters5, *pxQueueParameters6;
|
||||
const UBaseType_t uxQueueSize1 = 1, uxQueueSize5 = 5;
|
||||
const TickType_t xBlockTime = pdMS_TO_TICKS( ( TickType_t ) 1000 );
|
||||
const TickType_t xDontBlock = ( TickType_t ) 0;
|
||||
xBlockingQueueParameters * pxQueueParameters1, * pxQueueParameters2;
|
||||
xBlockingQueueParameters * pxQueueParameters3, * pxQueueParameters4;
|
||||
xBlockingQueueParameters * pxQueueParameters5, * pxQueueParameters6;
|
||||
const UBaseType_t uxQueueSize1 = 1, uxQueueSize5 = 5;
|
||||
const TickType_t xBlockTime = pdMS_TO_TICKS( ( TickType_t ) 1000 );
|
||||
const TickType_t xDontBlock = ( TickType_t ) 0;
|
||||
|
||||
/* Create the first two tasks as described at the top of the file. */
|
||||
|
||||
|
|
@ -107,14 +107,14 @@ const TickType_t xDontBlock = ( TickType_t ) 0;
|
|||
pxQueueParameters1 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
|
||||
|
||||
/* Create the queue used by the first two tasks to pass the incrementing number.
|
||||
Pass a pointer to the queue in the parameter structure. */
|
||||
* Pass a pointer to the queue in the parameter structure. */
|
||||
pxQueueParameters1->xQueue = xQueueCreate( uxQueueSize1, ( UBaseType_t ) sizeof( uint16_t ) );
|
||||
|
||||
/* The consumer is created first so gets a block time as described above. */
|
||||
pxQueueParameters1->xBlockTime = xBlockTime;
|
||||
|
||||
/* Pass in the variable that this task is going to increment so we can check it
|
||||
is still running. */
|
||||
* is still running. */
|
||||
pxQueueParameters1->psCheckVariable = &( sBlockingConsumerCount[ 0 ] );
|
||||
|
||||
/* Create the structure used to pass parameters to the producer task. */
|
||||
|
|
@ -124,23 +124,23 @@ const TickType_t xDontBlock = ( TickType_t ) 0;
|
|||
pxQueueParameters2->xQueue = pxQueueParameters1->xQueue;
|
||||
|
||||
/* The producer is not going to block - as soon as it posts the consumer will
|
||||
wake and remove the item so the producer should always have room to post. */
|
||||
* wake and remove the item so the producer should always have room to post. */
|
||||
pxQueueParameters2->xBlockTime = xDontBlock;
|
||||
|
||||
/* Pass in the variable that this task is going to increment so we can check
|
||||
it is still running. */
|
||||
* it is still running. */
|
||||
pxQueueParameters2->psCheckVariable = &( sBlockingProducerCount[ 0 ] );
|
||||
|
||||
|
||||
/* Note the producer has a lower priority than the consumer when the tasks are
|
||||
spawned. */
|
||||
* spawned. */
|
||||
xTaskCreate( vBlockingQueueConsumer, "QConsB1", blckqSTACK_SIZE, ( void * ) pxQueueParameters1, uxPriority, NULL );
|
||||
xTaskCreate( vBlockingQueueProducer, "QProdB2", blckqSTACK_SIZE, ( void * ) pxQueueParameters2, tskIDLE_PRIORITY, NULL );
|
||||
|
||||
|
||||
|
||||
/* Create the second two tasks as described at the top of the file. This uses
|
||||
the same mechanism but reverses the task priorities. */
|
||||
* the same mechanism but reverses the task priorities. */
|
||||
|
||||
pxQueueParameters3 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
|
||||
pxQueueParameters3->xQueue = xQueueCreate( uxQueueSize1, ( UBaseType_t ) sizeof( uint16_t ) );
|
||||
|
|
@ -158,7 +158,7 @@ const TickType_t xDontBlock = ( TickType_t ) 0;
|
|||
|
||||
|
||||
/* Create the last two tasks as described above. The mechanism is again just
|
||||
the same. This time both parameter structures are given a block time. */
|
||||
* the same. This time both parameter structures are given a block time. */
|
||||
pxQueueParameters5 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
|
||||
pxQueueParameters5->xQueue = xQueueCreate( uxQueueSize5, ( UBaseType_t ) sizeof( uint16_t ) );
|
||||
pxQueueParameters5->xBlockTime = xBlockTime;
|
||||
|
|
@ -176,13 +176,13 @@ const TickType_t xDontBlock = ( TickType_t ) 0;
|
|||
|
||||
static portTASK_FUNCTION( vBlockingQueueProducer, pvParameters )
|
||||
{
|
||||
uint16_t usValue = 0;
|
||||
xBlockingQueueParameters *pxQueueParameters;
|
||||
short sErrorEverOccurred = pdFALSE;
|
||||
uint16_t usValue = 0;
|
||||
xBlockingQueueParameters * pxQueueParameters;
|
||||
short sErrorEverOccurred = pdFALSE;
|
||||
|
||||
pxQueueParameters = ( xBlockingQueueParameters * ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
if( xQueueSend( pxQueueParameters->xQueue, ( void * ) &usValue, pxQueueParameters->xBlockTime ) != pdPASS )
|
||||
{
|
||||
|
|
@ -191,14 +191,14 @@ short sErrorEverOccurred = pdFALSE;
|
|||
else
|
||||
{
|
||||
/* We have successfully posted a message, so increment the variable
|
||||
used to check we are still running. */
|
||||
* used to check we are still running. */
|
||||
if( sErrorEverOccurred == pdFALSE )
|
||||
{
|
||||
( *pxQueueParameters->psCheckVariable )++;
|
||||
}
|
||||
|
||||
/* Increment the variable we are going to post next time round. The
|
||||
consumer will expect the numbers to follow in numerical order. */
|
||||
* consumer will expect the numbers to follow in numerical order. */
|
||||
++usValue;
|
||||
|
||||
#if configUSE_PREEMPTION == 0
|
||||
|
|
@ -211,13 +211,13 @@ short sErrorEverOccurred = pdFALSE;
|
|||
|
||||
static portTASK_FUNCTION( vBlockingQueueConsumer, pvParameters )
|
||||
{
|
||||
uint16_t usData, usExpectedValue = 0;
|
||||
xBlockingQueueParameters *pxQueueParameters;
|
||||
short sErrorEverOccurred = pdFALSE;
|
||||
uint16_t usData, usExpectedValue = 0;
|
||||
xBlockingQueueParameters * pxQueueParameters;
|
||||
short sErrorEverOccurred = pdFALSE;
|
||||
|
||||
pxQueueParameters = ( xBlockingQueueParameters * ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
if( xQueueReceive( pxQueueParameters->xQueue, &usData, pxQueueParameters->xBlockTime ) == pdPASS )
|
||||
{
|
||||
|
|
@ -231,14 +231,14 @@ short sErrorEverOccurred = pdFALSE;
|
|||
else
|
||||
{
|
||||
/* We have successfully received a message, so increment the
|
||||
variable used to check we are still running. */
|
||||
* variable used to check we are still running. */
|
||||
if( sErrorEverOccurred == pdFALSE )
|
||||
{
|
||||
( *pxQueueParameters->psCheckVariable )++;
|
||||
}
|
||||
|
||||
/* Increment the value we expect to remove from the queue next time
|
||||
round. */
|
||||
* round. */
|
||||
++usExpectedValue;
|
||||
}
|
||||
|
||||
|
|
@ -258,16 +258,16 @@ short sErrorEverOccurred = pdFALSE;
|
|||
/* This is called to check that all the created tasks are still running. */
|
||||
BaseType_t xAreBlockingQueuesStillRunning( void )
|
||||
{
|
||||
static short sLastBlockingConsumerCount[ blckqNUM_TASK_SETS ] = { ( uint16_t ) 0, ( uint16_t ) 0, ( uint16_t ) 0 };
|
||||
static short sLastBlockingProducerCount[ blckqNUM_TASK_SETS ] = { ( uint16_t ) 0, ( uint16_t ) 0, ( uint16_t ) 0 };
|
||||
BaseType_t xReturn = pdPASS, xTasks;
|
||||
static short sLastBlockingConsumerCount[ blckqNUM_TASK_SETS ] = { ( uint16_t ) 0, ( uint16_t ) 0, ( uint16_t ) 0 };
|
||||
static short sLastBlockingProducerCount[ blckqNUM_TASK_SETS ] = { ( uint16_t ) 0, ( uint16_t ) 0, ( uint16_t ) 0 };
|
||||
BaseType_t xReturn = pdPASS, xTasks;
|
||||
|
||||
/* Not too worried about mutual exclusion on these variables as they are 16
|
||||
bits and we are only reading them. We also only care to see if they have
|
||||
changed or not.
|
||||
|
||||
Loop through each check variable to and return pdFALSE if any are found not
|
||||
to have changed since the last call. */
|
||||
* bits and we are only reading them. We also only care to see if they have
|
||||
* changed or not.
|
||||
*
|
||||
* Loop through each check variable to and return pdFALSE if any are found not
|
||||
* to have changed since the last call. */
|
||||
|
||||
for( xTasks = 0; xTasks < blckqNUM_TASK_SETS; xTasks++ )
|
||||
{
|
||||
|
|
@ -275,16 +275,16 @@ BaseType_t xReturn = pdPASS, xTasks;
|
|||
{
|
||||
xReturn = pdFALSE;
|
||||
}
|
||||
sLastBlockingConsumerCount[ xTasks ] = sBlockingConsumerCount[ xTasks ];
|
||||
|
||||
sLastBlockingConsumerCount[ xTasks ] = sBlockingConsumerCount[ xTasks ];
|
||||
|
||||
if( sBlockingProducerCount[ xTasks ] == sLastBlockingProducerCount[ xTasks ] )
|
||||
{
|
||||
xReturn = pdFALSE;
|
||||
}
|
||||
|
||||
sLastBlockingProducerCount[ xTasks ] = sBlockingProducerCount[ xTasks ];
|
||||
}
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,14 +28,14 @@
|
|||
|
||||
|
||||
/*
|
||||
* This file contains fairly comprehensive checks on the behaviour of event
|
||||
* groups. It is not intended to be a user friendly demonstration of the
|
||||
* event groups API.
|
||||
*
|
||||
* NOTE: The tests implemented in this file are informal 'sanity' tests
|
||||
* only and are not part of the module tests that make use of the
|
||||
* mtCOVERAGE_TEST_MARKER macro within the event groups implementation.
|
||||
*/
|
||||
* This file contains fairly comprehensive checks on the behaviour of event
|
||||
* groups. It is not intended to be a user friendly demonstration of the
|
||||
* event groups API.
|
||||
*
|
||||
* NOTE: The tests implemented in this file are informal 'sanity' tests
|
||||
* only and are not part of the module tests that make use of the
|
||||
* mtCOVERAGE_TEST_MARKER macro within the event groups implementation.
|
||||
*/
|
||||
|
||||
|
||||
/* Scheduler include files. */
|
||||
|
|
@ -46,7 +46,7 @@
|
|||
/* Demo app includes. */
|
||||
#include "EventGroupsDemo.h"
|
||||
|
||||
#if( INCLUDE_eTaskGetState != 1 )
|
||||
#if ( INCLUDE_eTaskGetState != 1 )
|
||||
#error INCLUDE_eTaskGetState must be set to 1 in FreeRTOSConfig.h to use this demo file.
|
||||
#endif
|
||||
|
||||
|
|
@ -69,7 +69,7 @@
|
|||
#define ebALL_BITS ( ebBIT_0 | ebBIT_1 | ebBIT_2 | ebBIT_3 | ebBIT_4 | ebBIT_5 | ebBIT_6 | ebBIT_7 )
|
||||
|
||||
/* Associate a bit to each task. These bits are used to identify all the tasks
|
||||
that synchronise with the xEventGroupSync() function. */
|
||||
* that synchronise with the xEventGroupSync() function. */
|
||||
#define ebSET_BIT_TASK_SYNC_BIT ebBIT_0
|
||||
#define ebWAIT_BIT_TASK_SYNC_BIT ebBIT_1
|
||||
#define ebRENDESVOUS_TASK_1_SYNC_BIT ebBIT_2
|
||||
|
|
@ -83,7 +83,7 @@ that synchronise with the xEventGroupSync() function. */
|
|||
#define ebSHORT_DELAY pdMS_TO_TICKS( ( TickType_t ) 5 )
|
||||
|
||||
/* Used in the selective bits test which checks no, one or both tasks blocked on
|
||||
event bits in a group are unblocked as appropriate as different bits get set. */
|
||||
* event bits in a group are unblocked as appropriate as different bits get set. */
|
||||
#define ebSELECTIVE_BITS_1 0x03
|
||||
#define ebSELECTIVE_BITS_2 0x05
|
||||
|
||||
|
|
@ -116,27 +116,29 @@ event bits in a group are unblocked as appropriate as different bits get set. */
|
|||
*
|
||||
* 3) Calls prvPerformTaskSyncTests() to test task synchronisation behaviour.
|
||||
*/
|
||||
static void prvTestMasterTask( void *pvParameters );
|
||||
static void prvTestMasterTask( void * pvParameters );
|
||||
|
||||
/*
|
||||
* A helper task that enables the 'test master' task to perform several
|
||||
* behavioural tests. See the comments above the prvTestMasterTask() prototype
|
||||
* above.
|
||||
*/
|
||||
static void prvTestSlaveTask( void *pvParameters );
|
||||
static void prvTestSlaveTask( void * pvParameters );
|
||||
|
||||
/*
|
||||
* The part of the test that is performed between the 'test master' task and the
|
||||
* 'test slave' task to test the behaviour when the slave blocks on various
|
||||
* event bit combinations.
|
||||
*/
|
||||
static BaseType_t prvBitCombinationTestMasterFunction( BaseType_t xError, TaskHandle_t xTestSlaveTaskHandle );
|
||||
static BaseType_t prvBitCombinationTestMasterFunction( BaseType_t xError,
|
||||
TaskHandle_t xTestSlaveTaskHandle );
|
||||
|
||||
/*
|
||||
* The part of the test that uses all the tasks to test the task synchronisation
|
||||
* behaviour.
|
||||
*/
|
||||
static BaseType_t prvPerformTaskSyncTests( BaseType_t xError, TaskHandle_t xTestSlaveTaskHandle );
|
||||
static BaseType_t prvPerformTaskSyncTests( BaseType_t xError,
|
||||
TaskHandle_t xTestSlaveTaskHandle );
|
||||
|
||||
/*
|
||||
* Two instances of prvSyncTask() are created. They start by calling
|
||||
|
|
@ -144,7 +146,7 @@ static BaseType_t prvPerformTaskSyncTests( BaseType_t xError, TaskHandle_t xTest
|
|||
* executing the prvSelectiveBitsTestMasterFunction() function. They then loop
|
||||
* to test the task synchronisation (rendezvous) behaviour.
|
||||
*/
|
||||
static void prvSyncTask( void *pvParameters );
|
||||
static void prvSyncTask( void * pvParameters );
|
||||
|
||||
/*
|
||||
* Functions used in a test that blocks two tasks on various different bits
|
||||
|
|
@ -157,7 +159,7 @@ static void prvSelectiveBitsTestSlaveFunction( void );
|
|||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Variables that are incremented by the tasks on each cycle provided no errors
|
||||
have been found. Used to detect an error or stall in the test cycling. */
|
||||
* have been found. Used to detect an error or stall in the test cycling. */
|
||||
static volatile uint32_t ulTestMasterCycles = 0, ulTestSlaveCycles = 0, ulISRCycles = 0;
|
||||
|
||||
/* The event group used by all the task based tests. */
|
||||
|
|
@ -173,7 +175,7 @@ static TaskHandle_t xSyncTask1 = NULL, xSyncTask2 = NULL;
|
|||
|
||||
void vStartEventGroupTasks( void )
|
||||
{
|
||||
TaskHandle_t xTestSlaveTaskHandle;
|
||||
TaskHandle_t xTestSlaveTaskHandle;
|
||||
|
||||
/*
|
||||
* This file contains fairly comprehensive checks on the behaviour of event
|
||||
|
|
@ -195,18 +197,18 @@ TaskHandle_t xTestSlaveTaskHandle;
|
|||
configASSERT( xSyncTask2 );
|
||||
|
||||
/* Create the event group used by the ISR tests. The event group used by
|
||||
the tasks is created by the tasks themselves. */
|
||||
* the tasks is created by the tasks themselves. */
|
||||
xISREventGroup = xEventGroupCreate();
|
||||
configASSERT( xISREventGroup );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvTestMasterTask( void *pvParameters )
|
||||
static void prvTestMasterTask( void * pvParameters )
|
||||
{
|
||||
BaseType_t xError;
|
||||
BaseType_t xError;
|
||||
|
||||
/* The handle to the slave task is passed in as the task parameter. */
|
||||
TaskHandle_t xTestSlaveTaskHandle = ( TaskHandle_t ) pvParameters;
|
||||
TaskHandle_t xTestSlaveTaskHandle = ( TaskHandle_t ) pvParameters;
|
||||
|
||||
/* Avoid compiler warnings. */
|
||||
( void ) pvParameters;
|
||||
|
|
@ -216,18 +218,18 @@ TaskHandle_t xTestSlaveTaskHandle = ( TaskHandle_t ) pvParameters;
|
|||
configASSERT( xEventGroup );
|
||||
|
||||
/* Perform the tests that block two tasks on different combinations of bits,
|
||||
then set each bit in turn and check the correct tasks unblock at the correct
|
||||
times. */
|
||||
* then set each bit in turn and check the correct tasks unblock at the correct
|
||||
* times. */
|
||||
xError = prvSelectiveBitsTestMasterFunction();
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Recreate the event group ready for the next cycle. */
|
||||
xEventGroup = xEventGroupCreate();
|
||||
configASSERT( xEventGroup );
|
||||
|
||||
/* Perform the tests that check the behaviour when a single task is
|
||||
blocked on various combinations of event bits. */
|
||||
* blocked on various combinations of event bits. */
|
||||
xError = prvBitCombinationTestMasterFunction( xError, xTestSlaveTaskHandle );
|
||||
|
||||
/* Perform the task synchronisation tests. */
|
||||
|
|
@ -237,7 +239,7 @@ TaskHandle_t xTestSlaveTaskHandle = ( TaskHandle_t ) pvParameters;
|
|||
vEventGroupDelete( xEventGroup );
|
||||
|
||||
/* Now all the other tasks should have completed and suspended
|
||||
themselves ready for the next go around the loop. */
|
||||
* themselves ready for the next go around the loop. */
|
||||
if( eTaskGetState( xTestSlaveTaskHandle ) != eSuspended )
|
||||
{
|
||||
xError = pdTRUE;
|
||||
|
|
@ -264,52 +266,52 @@ TaskHandle_t xTestSlaveTaskHandle = ( TaskHandle_t ) pvParameters;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvSyncTask( void *pvParameters )
|
||||
static void prvSyncTask( void * pvParameters )
|
||||
{
|
||||
EventBits_t uxSynchronisationBit, uxReturned;
|
||||
EventBits_t uxSynchronisationBit, uxReturned;
|
||||
|
||||
/* A few tests that check the behaviour when two tasks are blocked on
|
||||
various different bits within an event group are performed before this task
|
||||
enters its infinite loop to carry out its main demo function. */
|
||||
* various different bits within an event group are performed before this task
|
||||
* enters its infinite loop to carry out its main demo function. */
|
||||
prvSelectiveBitsTestSlaveFunction();
|
||||
|
||||
/* The bit to use to indicate this task is at the synchronisation point is
|
||||
passed in as the task parameter. */
|
||||
* passed in as the task parameter. */
|
||||
uxSynchronisationBit = ( EventBits_t ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Now this task takes part in a task synchronisation - sometimes known
|
||||
as a 'rendezvous'. Its execution pattern is controlled by the 'test
|
||||
master' task, which is responsible for taking this task out of the
|
||||
Suspended state when it is time to test the synchronisation behaviour.
|
||||
See: http://www.freertos.org/xEventGroupSync.html. */
|
||||
* as a 'rendezvous'. Its execution pattern is controlled by the 'test
|
||||
* master' task, which is responsible for taking this task out of the
|
||||
* Suspended state when it is time to test the synchronisation behaviour.
|
||||
* See: http://www.freertos.org/xEventGroupSync.html. */
|
||||
vTaskSuspend( NULL );
|
||||
|
||||
/* Set the bit that indicates this task is at the synchronisation
|
||||
point. The first time this is done the 'test master' task has a lower
|
||||
priority than this task so this task will get to the sync point before
|
||||
the set bits task - test this by calling xEventGroupSync() with a zero
|
||||
block time before calling again with a max delay - the first call should
|
||||
return before the rendezvous completes, the second only after the
|
||||
rendezvous is complete. */
|
||||
* point. The first time this is done the 'test master' task has a lower
|
||||
* priority than this task so this task will get to the sync point before
|
||||
* the set bits task - test this by calling xEventGroupSync() with a zero
|
||||
* block time before calling again with a max delay - the first call should
|
||||
* return before the rendezvous completes, the second only after the
|
||||
* rendezvous is complete. */
|
||||
uxReturned = xEventGroupSync( xEventGroup, /* The event group used for the synchronisation. */
|
||||
uxSynchronisationBit, /* The bit to set in the event group to indicate this task is at the sync point. */
|
||||
ebALL_SYNC_BITS,/* The bits to wait for - these bits are set by the other tasks taking part in the sync. */
|
||||
ebALL_SYNC_BITS, /* The bits to wait for - these bits are set by the other tasks taking part in the sync. */
|
||||
ebDONT_BLOCK ); /* The maximum time to wait for the sync condition to be met before giving up. */
|
||||
|
||||
/* No block time was specified, so as per the comments above, the
|
||||
rendezvous is not expected to have completed yet. */
|
||||
* rendezvous is not expected to have completed yet. */
|
||||
configASSERT( ( uxReturned & ebALL_SYNC_BITS ) != ebALL_SYNC_BITS );
|
||||
|
||||
uxReturned = xEventGroupSync( xEventGroup, /* The event group used for the synchronisation. */
|
||||
uxSynchronisationBit, /* The bit to set in the event group to indicate this task is at the sync point. */
|
||||
ebALL_SYNC_BITS,/* The bits to wait for - these bits are set by the other tasks taking part in the sync. */
|
||||
portMAX_DELAY );/* The maximum time to wait for the sync condition to be met before giving up. */
|
||||
ebALL_SYNC_BITS, /* The bits to wait for - these bits are set by the other tasks taking part in the sync. */
|
||||
portMAX_DELAY ); /* The maximum time to wait for the sync condition to be met before giving up. */
|
||||
|
||||
/* A max delay was used, so this task should only exit the above
|
||||
function call when the sync condition is met. Check this is the
|
||||
case. */
|
||||
* function call when the sync condition is met. Check this is the
|
||||
* case. */
|
||||
configASSERT( ( uxReturned & ebALL_SYNC_BITS ) == ebALL_SYNC_BITS );
|
||||
|
||||
/* Remove compiler warning if configASSERT() is not defined. */
|
||||
|
|
@ -319,47 +321,47 @@ EventBits_t uxSynchronisationBit, uxReturned;
|
|||
vTaskSuspend( NULL );
|
||||
|
||||
/* Set the bit that indicates this task is at the synchronisation
|
||||
point again. This time the 'test master' task has a higher priority
|
||||
than this task so will get to the sync point before this task. */
|
||||
* point again. This time the 'test master' task has a higher priority
|
||||
* than this task so will get to the sync point before this task. */
|
||||
uxReturned = xEventGroupSync( xEventGroup, uxSynchronisationBit, ebALL_SYNC_BITS, portMAX_DELAY );
|
||||
|
||||
/* Again a max delay was used, so this task should only exit the above
|
||||
function call when the sync condition is met. Check this is the
|
||||
case. */
|
||||
* function call when the sync condition is met. Check this is the
|
||||
* case. */
|
||||
configASSERT( ( uxReturned & ebALL_SYNC_BITS ) == ebALL_SYNC_BITS );
|
||||
|
||||
/* Block on the event group again. This time the event group is going
|
||||
to be deleted while this task is blocked on it so it is expected that 0
|
||||
be returned. */
|
||||
* to be deleted while this task is blocked on it so it is expected that 0
|
||||
* be returned. */
|
||||
uxReturned = xEventGroupWaitBits( xEventGroup, ebALL_SYNC_BITS, pdFALSE, pdTRUE, portMAX_DELAY );
|
||||
configASSERT( uxReturned == 0 );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvTestSlaveTask( void *pvParameters )
|
||||
static void prvTestSlaveTask( void * pvParameters )
|
||||
{
|
||||
EventBits_t uxReturned;
|
||||
BaseType_t xError = pdFALSE;
|
||||
EventBits_t uxReturned;
|
||||
BaseType_t xError = pdFALSE;
|
||||
|
||||
/* Avoid compiler warnings. */
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/**********************************************************************
|
||||
* Part 1: This section is the counterpart to the
|
||||
* prvBitCombinationTestMasterFunction() function which is called by the
|
||||
* test master task.
|
||||
***********************************************************************
|
||||
|
||||
This task is controller by the 'test master' task (which is
|
||||
implemented by prvTestMasterTask()). Suspend until resumed by the
|
||||
'test master' task. */
|
||||
*
|
||||
* This task is controller by the 'test master' task (which is
|
||||
* implemented by prvTestMasterTask()). Suspend until resumed by the
|
||||
* 'test master' task. */
|
||||
vTaskSuspend( NULL );
|
||||
|
||||
/* Wait indefinitely for one of the bits in ebCOMBINED_BITS to get
|
||||
set. Clear the bit on exit. */
|
||||
* set. Clear the bit on exit. */
|
||||
uxReturned = xEventGroupWaitBits( xEventGroup, /* The event group that contains the event bits being queried. */
|
||||
ebBIT_1, /* The bit to wait for. */
|
||||
pdTRUE, /* Clear the bit on exit. */
|
||||
|
|
@ -367,19 +369,19 @@ BaseType_t xError = pdFALSE;
|
|||
portMAX_DELAY ); /* Block indefinitely to wait for the condition to be met. */
|
||||
|
||||
/* The 'test master' task set all the bits defined by ebCOMBINED_BITS,
|
||||
only one of which was being waited for by this task. The return value
|
||||
shows the state of the event bits when the task was unblocked, however
|
||||
because the task was waiting for ebBIT_1 and 'clear on exit' was set to
|
||||
the current state of the event bits will have ebBIT_1 clear. */
|
||||
* only one of which was being waited for by this task. The return value
|
||||
* shows the state of the event bits when the task was unblocked, however
|
||||
* because the task was waiting for ebBIT_1 and 'clear on exit' was set to
|
||||
* the current state of the event bits will have ebBIT_1 clear. */
|
||||
if( uxReturned != ebCOMBINED_BITS )
|
||||
{
|
||||
xError = pdTRUE;
|
||||
}
|
||||
|
||||
/* Now call xEventGroupWaitBits() again, this time waiting for all the
|
||||
bits in ebCOMBINED_BITS to be set. This call should block until the
|
||||
'test master' task sets ebBIT_1 - which was the bit cleared in the call
|
||||
to xEventGroupWaitBits() above. */
|
||||
* bits in ebCOMBINED_BITS to be set. This call should block until the
|
||||
* 'test master' task sets ebBIT_1 - which was the bit cleared in the call
|
||||
* to xEventGroupWaitBits() above. */
|
||||
uxReturned = xEventGroupWaitBits( xEventGroup,
|
||||
ebCOMBINED_BITS, /* The bits being waited on. */
|
||||
pdFALSE, /* Don't clear the bits on exit. */
|
||||
|
|
@ -396,8 +398,8 @@ BaseType_t xError = pdFALSE;
|
|||
vTaskSuspend( NULL );
|
||||
|
||||
/* Now call xEventGroupWaitBits() again, again waiting for all the bits
|
||||
in ebCOMBINED_BITS to be set, but this time clearing the bits when the
|
||||
task is unblocked. */
|
||||
* in ebCOMBINED_BITS to be set, but this time clearing the bits when the
|
||||
* task is unblocked. */
|
||||
uxReturned = xEventGroupWaitBits( xEventGroup,
|
||||
ebCOMBINED_BITS, /* The bits being waited on. */
|
||||
pdTRUE, /* Clear the bits on exit. */
|
||||
|
|
@ -405,48 +407,44 @@ BaseType_t xError = pdFALSE;
|
|||
portMAX_DELAY );
|
||||
|
||||
/* The 'test master' task set all the bits in the event group, so that
|
||||
is the value that should have been returned. The bits defined by
|
||||
ebCOMBINED_BITS will have been clear again in the current value though
|
||||
as 'clear on exit' was set to pdTRUE. */
|
||||
* is the value that should have been returned. The bits defined by
|
||||
* ebCOMBINED_BITS will have been clear again in the current value though
|
||||
* as 'clear on exit' was set to pdTRUE. */
|
||||
if( uxReturned != ebALL_BITS )
|
||||
{
|
||||
xError = pdTRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* Part 2: This section is the counterpart to the
|
||||
* prvPerformTaskSyncTests() function which is called by the
|
||||
* test master task.
|
||||
***********************************************************************
|
||||
|
||||
|
||||
Once again wait for the 'test master' task to unsuspend this task
|
||||
when it is time for the next test. */
|
||||
*
|
||||
*
|
||||
* Once again wait for the 'test master' task to unsuspend this task
|
||||
* when it is time for the next test. */
|
||||
vTaskSuspend( NULL );
|
||||
|
||||
/* Now peform a synchronisation with all the other tasks. At this point
|
||||
the 'test master' task has the lowest priority so will get to the sync
|
||||
point after all the other synchronising tasks. */
|
||||
* the 'test master' task has the lowest priority so will get to the sync
|
||||
* point after all the other synchronising tasks. */
|
||||
uxReturned = xEventGroupSync( xEventGroup, /* The event group used for the sync. */
|
||||
ebWAIT_BIT_TASK_SYNC_BIT, /* The bit in the event group used to indicate this task is at the sync point. */
|
||||
ebALL_SYNC_BITS, /* The bits to wait for. These bits are set by the other tasks taking part in the sync. */
|
||||
portMAX_DELAY ); /* The maximum time to wait for the sync condition to be met before giving up. */
|
||||
|
||||
/* A sync with a max delay should only exit when all the synchronisation
|
||||
bits are set... */
|
||||
* bits are set... */
|
||||
if( ( uxReturned & ebALL_SYNC_BITS ) != ebALL_SYNC_BITS )
|
||||
{
|
||||
xError = pdTRUE;
|
||||
}
|
||||
|
||||
/* ...but now the synchronisation bits should be clear again. Read back
|
||||
the current value of the bits within the event group to check that is
|
||||
the case. Setting the bits to zero will return the bits previous value
|
||||
then leave all the bits clear. */
|
||||
* the current value of the bits within the event group to check that is
|
||||
* the case. Setting the bits to zero will return the bits previous value
|
||||
* then leave all the bits clear. */
|
||||
if( xEventGroupSetBits( xEventGroup, 0x00 ) != 0 )
|
||||
{
|
||||
xError = pdTRUE;
|
||||
|
|
@ -467,12 +465,12 @@ BaseType_t xError = pdFALSE;
|
|||
vTaskSuspend( NULL );
|
||||
|
||||
/* This time sync when the 'test master' task has the highest priority
|
||||
at the point where it sets its sync bit - so this time the 'test master'
|
||||
task will get to the sync point before this task. */
|
||||
* at the point where it sets its sync bit - so this time the 'test master'
|
||||
* task will get to the sync point before this task. */
|
||||
uxReturned = xEventGroupSync( xEventGroup, ebWAIT_BIT_TASK_SYNC_BIT, ebALL_SYNC_BITS, portMAX_DELAY );
|
||||
|
||||
/* A sync with a max delay should only exit when all the synchronisation
|
||||
bits are set... */
|
||||
* bits are set... */
|
||||
if( ( uxReturned & ebALL_SYNC_BITS ) != ebALL_SYNC_BITS )
|
||||
{
|
||||
xError = pdTRUE;
|
||||
|
|
@ -485,8 +483,8 @@ BaseType_t xError = pdFALSE;
|
|||
}
|
||||
|
||||
/* Block on the event group again. This time the event group is going
|
||||
to be deleted while this task is blocked on it, so it is expected that 0
|
||||
will be returned. */
|
||||
* to be deleted while this task is blocked on it, so it is expected that 0
|
||||
* will be returned. */
|
||||
uxReturned = xEventGroupWaitBits( xEventGroup, ebALL_SYNC_BITS, pdFALSE, pdTRUE, portMAX_DELAY );
|
||||
|
||||
if( uxReturned != 0 )
|
||||
|
|
@ -505,12 +503,13 @@ BaseType_t xError = pdFALSE;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static BaseType_t prvPerformTaskSyncTests( BaseType_t xError, TaskHandle_t xTestSlaveTaskHandle )
|
||||
static BaseType_t prvPerformTaskSyncTests( BaseType_t xError,
|
||||
TaskHandle_t xTestSlaveTaskHandle )
|
||||
{
|
||||
EventBits_t uxBits;
|
||||
EventBits_t uxBits;
|
||||
|
||||
/* The three tasks that take part in the synchronisation (rendezvous) are
|
||||
expected to be in the suspended state at the start of the test. */
|
||||
* expected to be in the suspended state at the start of the test. */
|
||||
if( eTaskGetState( xTestSlaveTaskHandle ) != eSuspended )
|
||||
{
|
||||
xError = pdTRUE;
|
||||
|
|
@ -527,25 +526,25 @@ EventBits_t uxBits;
|
|||
}
|
||||
|
||||
/* Try a synch with no other tasks involved. First set all the bits other
|
||||
than this task's bit. */
|
||||
* than this task's bit. */
|
||||
xEventGroupSetBits( xEventGroup, ( ebALL_SYNC_BITS & ~ebSET_BIT_TASK_SYNC_BIT ) );
|
||||
|
||||
/* Then wait on just one bit - the bit that is being set. */
|
||||
uxBits = xEventGroupSync( xEventGroup, /* The event group used for the synchronisation. */
|
||||
ebSET_BIT_TASK_SYNC_BIT,/* The bit set by this task when it reaches the sync point. */
|
||||
ebSET_BIT_TASK_SYNC_BIT,/* The bits to wait for - in this case it is just waiting for itself. */
|
||||
ebSET_BIT_TASK_SYNC_BIT, /* The bit set by this task when it reaches the sync point. */
|
||||
ebSET_BIT_TASK_SYNC_BIT, /* The bits to wait for - in this case it is just waiting for itself. */
|
||||
portMAX_DELAY ); /* The maximum time to wait for the sync condition to be met. */
|
||||
|
||||
/* A sync with a max delay should only exit when all the synchronise
|
||||
bits are set...check that is the case. In this case there is only one
|
||||
sync bit anyway. */
|
||||
* bits are set...check that is the case. In this case there is only one
|
||||
* sync bit anyway. */
|
||||
if( ( uxBits & ebSET_BIT_TASK_SYNC_BIT ) != ebSET_BIT_TASK_SYNC_BIT )
|
||||
{
|
||||
xError = pdTRUE;
|
||||
}
|
||||
|
||||
/* ...but now the sync bits should be clear again, leaving all the other
|
||||
bits set (as only one bit was being waited for). */
|
||||
* bits set (as only one bit was being waited for). */
|
||||
if( xEventGroupGetBits( xEventGroup ) != ( ebALL_SYNC_BITS & ~ebSET_BIT_TASK_SYNC_BIT ) )
|
||||
{
|
||||
xError = pdTRUE;
|
||||
|
|
@ -553,13 +552,14 @@ EventBits_t uxBits;
|
|||
|
||||
/* Clear all the bits to zero again. */
|
||||
xEventGroupClearBits( xEventGroup, ( ebALL_SYNC_BITS & ~ebSET_BIT_TASK_SYNC_BIT ) );
|
||||
|
||||
if( xEventGroupGetBits( xEventGroup ) != 0 )
|
||||
{
|
||||
xError = pdTRUE;
|
||||
}
|
||||
|
||||
/* Unsuspend the other tasks then check they have executed up to the
|
||||
synchronisation point. */
|
||||
* synchronisation point. */
|
||||
vTaskResume( xTestSlaveTaskHandle );
|
||||
vTaskResume( xSyncTask1 );
|
||||
vTaskResume( xSyncTask2 );
|
||||
|
|
@ -581,12 +581,12 @@ EventBits_t uxBits;
|
|||
|
||||
/* Set this task's sync bit. */
|
||||
uxBits = xEventGroupSync( xEventGroup, /* The event group used for the synchronisation. */
|
||||
ebSET_BIT_TASK_SYNC_BIT,/* The bit set by this task when it reaches the sync point. */
|
||||
ebSET_BIT_TASK_SYNC_BIT, /* The bit set by this task when it reaches the sync point. */
|
||||
ebALL_SYNC_BITS, /* The bits to wait for - these bits are set by the other tasks that take part in the sync. */
|
||||
portMAX_DELAY ); /* The maximum time to wait for the sync condition to be met. */
|
||||
|
||||
/* A sync with a max delay should only exit when all the synchronise
|
||||
bits are set...check that is the case. */
|
||||
* bits are set...check that is the case. */
|
||||
if( ( uxBits & ebALL_SYNC_BITS ) != ebALL_SYNC_BITS )
|
||||
{
|
||||
xError = pdTRUE;
|
||||
|
|
@ -598,9 +598,8 @@ EventBits_t uxBits;
|
|||
xError = pdTRUE;
|
||||
}
|
||||
|
||||
|
||||
/* The other tasks should now all be suspended again, ready for the next
|
||||
synchronisation. */
|
||||
* synchronisation. */
|
||||
if( eTaskGetState( xTestSlaveTaskHandle ) != eSuspended )
|
||||
{
|
||||
xError = pdTRUE;
|
||||
|
|
@ -616,11 +615,10 @@ EventBits_t uxBits;
|
|||
xError = pdTRUE;
|
||||
}
|
||||
|
||||
|
||||
/* Sync again - but this time set the last necessary bit as the
|
||||
highest priority task, rather than the lowest priority task. Unsuspend
|
||||
the other tasks then check they have executed up to the synchronisation
|
||||
point. */
|
||||
* highest priority task, rather than the lowest priority task. Unsuspend
|
||||
* the other tasks then check they have executed up to the synchronisation
|
||||
* point. */
|
||||
vTaskResume( xTestSlaveTaskHandle );
|
||||
vTaskResume( xSyncTask1 );
|
||||
vTaskResume( xSyncTask2 );
|
||||
|
|
@ -647,7 +645,7 @@ EventBits_t uxBits;
|
|||
uxBits = xEventGroupSync( xEventGroup, ebSET_BIT_TASK_SYNC_BIT, ebALL_SYNC_BITS, portMAX_DELAY );
|
||||
|
||||
/* A sync with a max delay should only exit when all the synchronisation
|
||||
bits are set... */
|
||||
* bits are set... */
|
||||
if( ( uxBits & ebALL_SYNC_BITS ) != ebALL_SYNC_BITS )
|
||||
{
|
||||
xError = pdTRUE;
|
||||
|
|
@ -659,9 +657,8 @@ EventBits_t uxBits;
|
|||
xError = pdTRUE;
|
||||
}
|
||||
|
||||
|
||||
/* The other tasks should now all be in the ready state again, but not
|
||||
executed yet as this task still has a higher relative priority. */
|
||||
* executed yet as this task still has a higher relative priority. */
|
||||
if( eTaskGetState( xTestSlaveTaskHandle ) != eReady )
|
||||
{
|
||||
xError = pdTRUE;
|
||||
|
|
@ -677,12 +674,11 @@ EventBits_t uxBits;
|
|||
xError = pdTRUE;
|
||||
}
|
||||
|
||||
|
||||
/* Reset the priority of this task back to its original value. */
|
||||
vTaskPrioritySet( NULL, ebSET_BIT_TASK_PRIORITY );
|
||||
|
||||
/* Now all the other tasks should have reblocked on the event bits
|
||||
to test the behaviour when the event bits are deleted. */
|
||||
* to test the behaviour when the event bits are deleted. */
|
||||
if( eTaskGetState( xTestSlaveTaskHandle ) != eBlocked )
|
||||
{
|
||||
xError = pdTRUE;
|
||||
|
|
@ -702,12 +698,13 @@ EventBits_t uxBits;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static BaseType_t prvBitCombinationTestMasterFunction( BaseType_t xError, TaskHandle_t xTestSlaveTaskHandle )
|
||||
static BaseType_t prvBitCombinationTestMasterFunction( BaseType_t xError,
|
||||
TaskHandle_t xTestSlaveTaskHandle )
|
||||
{
|
||||
EventBits_t uxBits;
|
||||
EventBits_t uxBits;
|
||||
|
||||
/* Resume the other task. It will block, pending a single bit from
|
||||
within ebCOMBINED_BITS. */
|
||||
* within ebCOMBINED_BITS. */
|
||||
vTaskResume( xTestSlaveTaskHandle );
|
||||
|
||||
/* Ensure the other task is blocked on the task. */
|
||||
|
|
@ -717,13 +714,13 @@ EventBits_t uxBits;
|
|||
}
|
||||
|
||||
/* Set all the bits in ebCOMBINED_BITS - the 'test slave' task is only
|
||||
blocked waiting for one of them. */
|
||||
* blocked waiting for one of them. */
|
||||
xEventGroupSetBits( xEventGroup, ebCOMBINED_BITS );
|
||||
|
||||
/* The 'test slave' task should now have executed, clearing ebBIT_1 (the
|
||||
bit it was blocked on), then re-entered the Blocked state to wait for
|
||||
all the other bits in ebCOMBINED_BITS to be set again. First check
|
||||
ebBIT_1 is clear. */
|
||||
* bit it was blocked on), then re-entered the Blocked state to wait for
|
||||
* all the other bits in ebCOMBINED_BITS to be set again. First check
|
||||
* ebBIT_1 is clear. */
|
||||
uxBits = xEventGroupWaitBits( xEventGroup, ebALL_BITS, pdFALSE, pdFALSE, ebDONT_BLOCK );
|
||||
|
||||
if( uxBits != ( ebCOMBINED_BITS & ~ebBIT_1 ) )
|
||||
|
|
@ -738,7 +735,7 @@ EventBits_t uxBits;
|
|||
}
|
||||
|
||||
/* Set all the bits other than ebBIT_1 - which is the bit that must be
|
||||
set before the other task unblocks. */
|
||||
* set before the other task unblocks. */
|
||||
xEventGroupSetBits( xEventGroup, ebALL_BITS & ~ebBIT_1 );
|
||||
|
||||
/* Ensure all the expected bits are still set. */
|
||||
|
|
@ -756,7 +753,7 @@ EventBits_t uxBits;
|
|||
}
|
||||
|
||||
/* Now also set ebBIT_1, which should unblock the other task, which will
|
||||
then suspend itself. */
|
||||
* then suspend itself. */
|
||||
xEventGroupSetBits( xEventGroup, ebBIT_1 );
|
||||
|
||||
/* Ensure the other task is suspended. */
|
||||
|
|
@ -766,7 +763,7 @@ EventBits_t uxBits;
|
|||
}
|
||||
|
||||
/* The other task should not have cleared the bits - so all the bits
|
||||
should still be set. */
|
||||
* should still be set. */
|
||||
if( xEventGroupSetBits( xEventGroup, 0x00 ) != ebALL_BITS )
|
||||
{
|
||||
xError = pdTRUE;
|
||||
|
|
@ -779,7 +776,7 @@ EventBits_t uxBits;
|
|||
}
|
||||
|
||||
/* Resume the other task - which will wait on all the ebCOMBINED_BITS
|
||||
again - this time clearing the bits when it is unblocked. */
|
||||
* again - this time clearing the bits when it is unblocked. */
|
||||
vTaskResume( xTestSlaveTaskHandle );
|
||||
|
||||
/* Ensure the other task is blocked once again. */
|
||||
|
|
@ -798,7 +795,7 @@ EventBits_t uxBits;
|
|||
}
|
||||
|
||||
/* The other task should have cleared the bits in ebCOMBINED_BITS.
|
||||
Clear the remaining bits. */
|
||||
* Clear the remaining bits. */
|
||||
uxBits = xEventGroupWaitBits( xEventGroup, ebALL_BITS, pdFALSE, pdFALSE, ebDONT_BLOCK );
|
||||
|
||||
if( uxBits != ( ebALL_BITS & ~ebCOMBINED_BITS ) )
|
||||
|
|
@ -807,7 +804,7 @@ EventBits_t uxBits;
|
|||
}
|
||||
|
||||
/* Clear all bits ready for the sync with the other three tasks. The
|
||||
value returned is the value prior to the bits being cleared. */
|
||||
* value returned is the value prior to the bits being cleared. */
|
||||
if( xEventGroupClearBits( xEventGroup, ebALL_BITS ) != ( ebALL_BITS & ~ebCOMBINED_BITS ) )
|
||||
{
|
||||
xError = pdTRUE;
|
||||
|
|
@ -825,15 +822,15 @@ EventBits_t uxBits;
|
|||
|
||||
static void prvSelectiveBitsTestSlaveFunction( void )
|
||||
{
|
||||
EventBits_t uxPendBits, uxReturned;
|
||||
EventBits_t uxPendBits, uxReturned;
|
||||
|
||||
/* Used in a test that blocks two tasks on various different bits within an
|
||||
event group - then sets each bit in turn and checks that the correct tasks
|
||||
unblock at the correct times.
|
||||
|
||||
This function is called by two different tasks - each of which will use a
|
||||
different bit. Check the task handle to see which task the function was
|
||||
called by. */
|
||||
* event group - then sets each bit in turn and checks that the correct tasks
|
||||
* unblock at the correct times.
|
||||
*
|
||||
* This function is called by two different tasks - each of which will use a
|
||||
* different bit. Check the task handle to see which task the function was
|
||||
* called by. */
|
||||
if( xTaskGetCurrentTaskHandle() == xSyncTask1 )
|
||||
{
|
||||
uxPendBits = ebSELECTIVE_BITS_1;
|
||||
|
|
@ -843,11 +840,11 @@ EventBits_t uxPendBits, uxReturned;
|
|||
uxPendBits = ebSELECTIVE_BITS_2;
|
||||
}
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Wait until it is time to perform the next cycle of the test. The
|
||||
task is unsuspended by the tests implemented in the
|
||||
prvSelectiveBitsTestMasterFunction() function. */
|
||||
* task is unsuspended by the tests implemented in the
|
||||
* prvSelectiveBitsTestMasterFunction() function. */
|
||||
vTaskSuspend( NULL );
|
||||
uxReturned = xEventGroupWaitBits( xEventGroup, uxPendBits, pdTRUE, pdFALSE, portMAX_DELAY );
|
||||
|
||||
|
|
@ -861,16 +858,16 @@ EventBits_t uxPendBits, uxReturned;
|
|||
|
||||
static BaseType_t prvSelectiveBitsTestMasterFunction( void )
|
||||
{
|
||||
BaseType_t xError = pdFALSE;
|
||||
EventBits_t uxBit;
|
||||
BaseType_t xError = pdFALSE;
|
||||
EventBits_t uxBit;
|
||||
|
||||
/* Used in a test that blocks two tasks on various different bits within an
|
||||
event group - then sets each bit in turn and checks that the correct tasks
|
||||
unblock at the correct times. The two other tasks (xSyncTask1 and
|
||||
xSyncTask2) call prvSelectiveBitsTestSlaveFunction() to perform their parts in
|
||||
this test.
|
||||
|
||||
Both other tasks should start in the suspended state. */
|
||||
* event group - then sets each bit in turn and checks that the correct tasks
|
||||
* unblock at the correct times. The two other tasks (xSyncTask1 and
|
||||
* xSyncTask2) call prvSelectiveBitsTestSlaveFunction() to perform their parts in
|
||||
* this test.
|
||||
*
|
||||
* Both other tasks should start in the suspended state. */
|
||||
if( eTaskGetState( xSyncTask1 ) != eSuspended )
|
||||
{
|
||||
xError = pdTRUE;
|
||||
|
|
@ -903,7 +900,7 @@ EventBits_t uxBit;
|
|||
xEventGroupSetBits( xEventGroup, uxBit );
|
||||
|
||||
/* Is the bit set in the first set of selective bits? If so the first
|
||||
sync task should have unblocked and returned to the suspended state. */
|
||||
* sync task should have unblocked and returned to the suspended state. */
|
||||
if( ( uxBit & ebSELECTIVE_BITS_1 ) == 0 )
|
||||
{
|
||||
/* Task should not have unblocked. */
|
||||
|
|
@ -941,13 +938,13 @@ EventBits_t uxBit;
|
|||
}
|
||||
|
||||
/* Ensure both tasks are blocked on the event group again, then delete the
|
||||
event group so the other tasks leave this portion of the test. */
|
||||
* event group so the other tasks leave this portion of the test. */
|
||||
vTaskResume( xSyncTask1 );
|
||||
vTaskResume( xSyncTask2 );
|
||||
|
||||
/* Deleting the event group is the signal that the two other tasks should
|
||||
leave the prvSelectiveBitsTestSlaveFunction() function and continue to the main
|
||||
part of their functionality. */
|
||||
* leave the prvSelectiveBitsTestSlaveFunction() function and continue to the main
|
||||
* part of their functionality. */
|
||||
vEventGroupDelete( xEventGroup );
|
||||
|
||||
return xError;
|
||||
|
|
@ -956,14 +953,14 @@ EventBits_t uxBit;
|
|||
|
||||
void vPeriodicEventGroupsProcessing( void )
|
||||
{
|
||||
static BaseType_t xCallCount = 0, xISRTestError = pdFALSE;
|
||||
const BaseType_t xSetBitCount = 100, xGetBitsCount = 200, xClearBitsCount = 300;
|
||||
const EventBits_t uxBitsToSet = 0x12U;
|
||||
EventBits_t uxReturned;
|
||||
BaseType_t xMessagePosted;
|
||||
static BaseType_t xCallCount = 0, xISRTestError = pdFALSE;
|
||||
const BaseType_t xSetBitCount = 100, xGetBitsCount = 200, xClearBitsCount = 300;
|
||||
const EventBits_t uxBitsToSet = 0x12U;
|
||||
EventBits_t uxReturned;
|
||||
BaseType_t xMessagePosted;
|
||||
|
||||
/* Called periodically from the tick hook to exercise the "FromISR"
|
||||
functions. */
|
||||
* functions. */
|
||||
|
||||
/* Check the even group tasks were actually created. */
|
||||
configASSERT( xISREventGroup );
|
||||
|
|
@ -974,6 +971,7 @@ BaseType_t xMessagePosted;
|
|||
{
|
||||
/* All the event bits should start clear. */
|
||||
uxReturned = xEventGroupGetBitsFromISR( xISREventGroup );
|
||||
|
||||
if( uxReturned != 0x00 )
|
||||
{
|
||||
xISRTestError = pdTRUE;
|
||||
|
|
@ -981,9 +979,10 @@ BaseType_t xMessagePosted;
|
|||
else
|
||||
{
|
||||
/* Set the bits. This is called from the tick hook so it is not
|
||||
necessary to use the last parameter to ensure a context switch
|
||||
occurs immediately. */
|
||||
* necessary to use the last parameter to ensure a context switch
|
||||
* occurs immediately. */
|
||||
xMessagePosted = xEventGroupSetBitsFromISR( xISREventGroup, uxBitsToSet, NULL );
|
||||
|
||||
if( xMessagePosted != pdPASS )
|
||||
{
|
||||
xISRTestError = pdTRUE;
|
||||
|
|
@ -994,6 +993,7 @@ BaseType_t xMessagePosted;
|
|||
{
|
||||
/* Check the bits were set as expected. */
|
||||
uxReturned = xEventGroupGetBitsFromISR( xISREventGroup );
|
||||
|
||||
if( uxReturned != uxBitsToSet )
|
||||
{
|
||||
xISRTestError = pdTRUE;
|
||||
|
|
@ -1014,7 +1014,7 @@ BaseType_t xMessagePosted;
|
|||
xCallCount = 0;
|
||||
|
||||
/* If no errors have been detected then increment the count of test
|
||||
cycles. */
|
||||
* cycles. */
|
||||
if( xISRTestError == pdFALSE )
|
||||
{
|
||||
ulISRCycles++;
|
||||
|
|
@ -1030,30 +1030,30 @@ BaseType_t xMessagePosted;
|
|||
/* This is called to check that all the created tasks are still running. */
|
||||
BaseType_t xAreEventGroupTasksStillRunning( void )
|
||||
{
|
||||
static uint32_t ulPreviousWaitBitCycles = 0, ulPreviousSetBitCycles = 0, ulPreviousISRCycles = 0;
|
||||
BaseType_t xStatus = pdPASS;
|
||||
static uint32_t ulPreviousWaitBitCycles = 0, ulPreviousSetBitCycles = 0, ulPreviousISRCycles = 0;
|
||||
BaseType_t xStatus = pdPASS;
|
||||
|
||||
/* Check the tasks are still cycling without finding any errors. */
|
||||
if( ulPreviousSetBitCycles == ulTestMasterCycles )
|
||||
{
|
||||
xStatus = pdFAIL;
|
||||
}
|
||||
|
||||
ulPreviousSetBitCycles = ulTestMasterCycles;
|
||||
|
||||
if( ulPreviousWaitBitCycles == ulTestSlaveCycles )
|
||||
{
|
||||
xStatus = pdFAIL;
|
||||
}
|
||||
|
||||
ulPreviousWaitBitCycles = ulTestSlaveCycles;
|
||||
|
||||
if( ulPreviousISRCycles == ulISRCycles )
|
||||
{
|
||||
xStatus = pdFAIL;
|
||||
}
|
||||
|
||||
ulPreviousISRCycles = ulISRCycles;
|
||||
|
||||
return xStatus;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@
|
|||
* check the resultant queue order is as expected. Queue data is also
|
||||
* peeked.
|
||||
*/
|
||||
static void prvSendFrontAndBackTest( void *pvParameters );
|
||||
static void prvSendFrontAndBackTest( void * pvParameters );
|
||||
|
||||
/*
|
||||
* The following three tasks are used to demonstrate the mutex behaviour.
|
||||
|
|
@ -86,9 +86,9 @@ static void prvSendFrontAndBackTest( void *pvParameters );
|
|||
* low priority, and is therefore immediately preempted by first the high
|
||||
* priority task and then the medium priority task before it can continue.
|
||||
*/
|
||||
static void prvLowPriorityMutexTask( void *pvParameters );
|
||||
static void prvMediumPriorityMutexTask( void *pvParameters );
|
||||
static void prvHighPriorityMutexTask( void *pvParameters );
|
||||
static void prvLowPriorityMutexTask( void * pvParameters );
|
||||
static void prvMediumPriorityMutexTask( void * pvParameters );
|
||||
static void prvHighPriorityMutexTask( void * pvParameters );
|
||||
|
||||
/*
|
||||
* Tests the behaviour when a low priority task inherits the priority of a
|
||||
|
|
@ -96,29 +96,31 @@ static void prvHighPriorityMutexTask( void *pvParameters );
|
|||
* first the same order as the two mutexes were obtained, and second the
|
||||
* opposite order as the two mutexes were obtained.
|
||||
*/
|
||||
static void prvTakeTwoMutexesReturnInSameOrder( SemaphoreHandle_t xMutex, SemaphoreHandle_t xLocalMutex );
|
||||
static void prvTakeTwoMutexesReturnInDifferentOrder( SemaphoreHandle_t xMutex, SemaphoreHandle_t xLocalMutex );
|
||||
static void prvTakeTwoMutexesReturnInSameOrder( SemaphoreHandle_t xMutex,
|
||||
SemaphoreHandle_t xLocalMutex );
|
||||
static void prvTakeTwoMutexesReturnInDifferentOrder( SemaphoreHandle_t xMutex,
|
||||
SemaphoreHandle_t xLocalMutex );
|
||||
|
||||
#if( INCLUDE_xTaskAbortDelay == 1 )
|
||||
#if ( INCLUDE_xTaskAbortDelay == 1 )
|
||||
|
||||
#if( configUSE_PREEMPTION == 0 )
|
||||
#if ( configUSE_PREEMPTION == 0 )
|
||||
#error The additional tests included when INCLUDE_xTaskAbortDelay is 1 expect preemption to be used.
|
||||
#endif
|
||||
|
||||
/* Tests the behaviour when a low priority task inherits the priority of a
|
||||
high priority task only for the high priority task to timeout before
|
||||
obtaining the mutex. */
|
||||
/* Tests the behaviour when a low priority task inherits the priority of a
|
||||
* high priority task only for the high priority task to timeout before
|
||||
* obtaining the mutex. */
|
||||
static void prvHighPriorityTimeout( SemaphoreHandle_t xMutex );
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Flag that will be latched to pdTRUE should any unexpected behaviour be
|
||||
detected in any of the tasks. */
|
||||
* detected in any of the tasks. */
|
||||
static volatile BaseType_t xErrorDetected = pdFALSE;
|
||||
|
||||
/* Counters that are incremented on each cycle of a test. This is used to
|
||||
detect a stalled task - a test that is no longer running. */
|
||||
* detect a stalled task - a test that is no longer running. */
|
||||
static volatile uint32_t ulLoopCounter = 0;
|
||||
static volatile uint32_t ulLoopCounter2 = 0;
|
||||
|
||||
|
|
@ -126,44 +128,44 @@ static volatile uint32_t ulLoopCounter2 = 0;
|
|||
static volatile uint32_t ulGuardedVariable = 0;
|
||||
|
||||
/* Handles used in the mutex test to suspend and resume the high and medium
|
||||
priority mutex test tasks. */
|
||||
* priority mutex test tasks. */
|
||||
static TaskHandle_t xHighPriorityMutexTask, xMediumPriorityMutexTask;
|
||||
|
||||
/* If INCLUDE_xTaskAbortDelay is 1 additional tests are performed, requiring an
|
||||
additional task. */
|
||||
#if( INCLUDE_xTaskAbortDelay == 1 )
|
||||
* additional task. */
|
||||
#if ( INCLUDE_xTaskAbortDelay == 1 )
|
||||
static TaskHandle_t xSecondMediumPriorityMutexTask;
|
||||
#endif
|
||||
|
||||
/* Lets the high priority semaphore task know that its wait for the semaphore
|
||||
was aborted, in which case not being able to obtain the semaphore is not to be
|
||||
considered an error. */
|
||||
* was aborted, in which case not being able to obtain the semaphore is not to be
|
||||
* considered an error. */
|
||||
static volatile BaseType_t xBlockWasAborted = pdFALSE;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vStartGenericQueueTasks( UBaseType_t uxPriority )
|
||||
{
|
||||
QueueHandle_t xQueue;
|
||||
SemaphoreHandle_t xMutex;
|
||||
QueueHandle_t xQueue;
|
||||
SemaphoreHandle_t xMutex;
|
||||
|
||||
/* Create the queue that we are going to use for the
|
||||
prvSendFrontAndBackTest demo. */
|
||||
* prvSendFrontAndBackTest demo. */
|
||||
xQueue = xQueueCreate( genqQUEUE_LENGTH, sizeof( uint32_t ) );
|
||||
|
||||
if( xQueue != NULL )
|
||||
{
|
||||
/* vQueueAddToRegistry() adds the queue to the queue registry, if one
|
||||
is in use. The queue registry is provided as a means for kernel aware
|
||||
debuggers to locate queues 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
|
||||
defined to be less than 1. */
|
||||
* is in use. The queue registry is provided as a means for kernel aware
|
||||
* debuggers to locate queues 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
|
||||
* defined to be less than 1. */
|
||||
vQueueAddToRegistry( xQueue, "Gen_Queue_Test" );
|
||||
|
||||
/* Create the demo task and pass it the queue just created. We are
|
||||
passing the queue handle by value so it does not matter that it is
|
||||
declared on the stack here. */
|
||||
* passing the queue handle by value so it does not matter that it is
|
||||
* declared on the stack here. */
|
||||
xTaskCreate( prvSendFrontAndBackTest, "GenQ", genqGENERIC_QUEUE_TEST_TASK_STACK_SIZE, ( void * ) xQueue, uxPriority, NULL );
|
||||
}
|
||||
|
||||
|
|
@ -173,23 +175,23 @@ SemaphoreHandle_t xMutex;
|
|||
if( xMutex != NULL )
|
||||
{
|
||||
/* vQueueAddToRegistry() adds the mutex to the registry, if one is
|
||||
in use. The registry is provided as a means for kernel aware
|
||||
debuggers to locate mutexes 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 defined to be less than 1. */
|
||||
* in use. The registry is provided as a means for kernel aware
|
||||
* debuggers to locate mutexes 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 defined to be less than 1. */
|
||||
vQueueAddToRegistry( ( QueueHandle_t ) xMutex, "Gen_Queue_Mutex" );
|
||||
|
||||
/* Create the mutex demo tasks and pass it the mutex just created. We
|
||||
are passing the mutex handle by value so it does not matter that it is
|
||||
declared on the stack here. */
|
||||
* are passing the mutex handle by value so it does not matter that it is
|
||||
* declared on the stack here. */
|
||||
xTaskCreate( prvLowPriorityMutexTask, "MuLow", genqMUTEX_TEST_TASK_STACK_SIZE, ( void * ) xMutex, genqMUTEX_LOW_PRIORITY, NULL );
|
||||
xTaskCreate( prvMediumPriorityMutexTask, "MuMed", configMINIMAL_STACK_SIZE, NULL, genqMUTEX_MEDIUM_PRIORITY, &xMediumPriorityMutexTask );
|
||||
xTaskCreate( prvHighPriorityMutexTask, "MuHigh", genqMUTEX_TEST_TASK_STACK_SIZE, ( void * ) xMutex, genqMUTEX_HIGH_PRIORITY, &xHighPriorityMutexTask );
|
||||
|
||||
/* If INCLUDE_xTaskAbortDelay is set then additional tests are performed,
|
||||
requiring two instances of prvHighPriorityMutexTask(). */
|
||||
#if( INCLUDE_xTaskAbortDelay == 1 )
|
||||
* requiring two instances of prvHighPriorityMutexTask(). */
|
||||
#if ( INCLUDE_xTaskAbortDelay == 1 )
|
||||
{
|
||||
xTaskCreate( prvHighPriorityMutexTask, "MuHigh2", configMINIMAL_STACK_SIZE, ( void * ) xMutex, genqMUTEX_MEDIUM_PRIORITY, &xSecondMediumPriorityMutexTask );
|
||||
}
|
||||
|
|
@ -198,10 +200,10 @@ SemaphoreHandle_t xMutex;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvSendFrontAndBackTest( void *pvParameters )
|
||||
static void prvSendFrontAndBackTest( void * pvParameters )
|
||||
{
|
||||
uint32_t ulData, ulData2, ulLoopCounterSnapshot;
|
||||
QueueHandle_t xQueue;
|
||||
uint32_t ulData, ulData2, ulLoopCounterSnapshot;
|
||||
QueueHandle_t xQueue;
|
||||
|
||||
#ifdef USE_STDIO
|
||||
void vPrintDisplayMessage( const char * const * ppcMessageToSend );
|
||||
|
|
@ -214,12 +216,12 @@ QueueHandle_t xQueue;
|
|||
|
||||
xQueue = ( QueueHandle_t ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* The queue is empty, so sending an item to the back of the queue
|
||||
should have the same effect as sending it to the front of the queue.
|
||||
|
||||
First send to the front and check everything is as expected. */
|
||||
* should have the same effect as sending it to the front of the queue.
|
||||
*
|
||||
* First send to the front and check everything is as expected. */
|
||||
ulLoopCounterSnapshot = ulLoopCounter;
|
||||
xQueueSendToFront( xQueue, ( void * ) &ulLoopCounterSnapshot, intsemNO_BLOCK );
|
||||
|
||||
|
|
@ -234,14 +236,14 @@ QueueHandle_t xQueue;
|
|||
}
|
||||
|
||||
/* The data we sent to the queue should equal the data we just received
|
||||
from the queue. */
|
||||
* from the queue. */
|
||||
if( ulLoopCounter != ulData )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
/* Then do the same, sending the data to the back, checking everything
|
||||
is as expected. */
|
||||
* is as expected. */
|
||||
if( uxQueueMessagesWaiting( xQueue ) != 0 )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -266,7 +268,7 @@ QueueHandle_t xQueue;
|
|||
}
|
||||
|
||||
/* The data sent to the queue should equal the data just received from
|
||||
the queue. */
|
||||
* the queue. */
|
||||
if( ulLoopCounter != ulData )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -276,8 +278,6 @@ QueueHandle_t xQueue;
|
|||
taskYIELD();
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Place 2, 3, 4 into the queue, adding items to the back of the queue. */
|
||||
for( ulData = 2; ulData < 5; ulData++ )
|
||||
{
|
||||
|
|
@ -285,18 +285,19 @@ QueueHandle_t xQueue;
|
|||
}
|
||||
|
||||
/* Now the order in the queue should be 2, 3, 4, with 2 being the first
|
||||
thing to be read out. Now add 1 then 0 to the front of the queue. */
|
||||
* thing to be read out. Now add 1 then 0 to the front of the queue. */
|
||||
if( uxQueueMessagesWaiting( xQueue ) != 3 )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
ulData = 1;
|
||||
xQueueSendToFront( xQueue, ( void * ) &ulData, intsemNO_BLOCK );
|
||||
ulData = 0;
|
||||
xQueueSendToFront( xQueue, ( void * ) &ulData, intsemNO_BLOCK );
|
||||
|
||||
/* Now the queue should be full, and when we read the data out we
|
||||
should receive 0, 1, 2, 3, 4. */
|
||||
* should receive 0, 1, 2, 3, 4. */
|
||||
if( uxQueueMessagesWaiting( xQueue ) != 5 )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -330,10 +331,10 @@ QueueHandle_t xQueue;
|
|||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
|
||||
/* Now try receiving the data for real. The value should be the
|
||||
same. Clobber the value first so we know we really received it. */
|
||||
* same. Clobber the value first so we know we really received it. */
|
||||
ulData2 = ~ulData2;
|
||||
|
||||
if( xQueueReceive( xQueue, &ulData2, intsemNO_BLOCK ) != pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -358,11 +359,14 @@ QueueHandle_t xQueue;
|
|||
|
||||
/* Our queue is empty once more, add 10, 11 to the back. */
|
||||
ulData = 10;
|
||||
|
||||
if( xQueueSend( xQueue, &ulData, intsemNO_BLOCK ) != pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
ulData = 11;
|
||||
|
||||
if( xQueueSend( xQueue, &ulData, intsemNO_BLOCK ) != pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -374,7 +378,7 @@ QueueHandle_t xQueue;
|
|||
}
|
||||
|
||||
/* Now we should have 10, 11 in the queue. Add 7, 8, 9 to the
|
||||
front. */
|
||||
* front. */
|
||||
for( ulData = 9; ulData >= 7; ulData-- )
|
||||
{
|
||||
if( xQueueSendToFront( xQueue, ( void * ) &ulData, intsemNO_BLOCK ) != pdPASS )
|
||||
|
|
@ -384,7 +388,7 @@ QueueHandle_t xQueue;
|
|||
}
|
||||
|
||||
/* Now check that the queue is full, and that receiving data provides
|
||||
the expected sequence of 7, 8, 9, 10, 11. */
|
||||
* the expected sequence of 7, 8, 9, 10, 11. */
|
||||
if( uxQueueMessagesWaiting( xQueue ) != 5 )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -424,128 +428,134 @@ QueueHandle_t xQueue;
|
|||
}
|
||||
|
||||
/* Increment the loop counter to indicate these tasks are still
|
||||
executing. */
|
||||
* executing. */
|
||||
ulLoopCounter++;
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#if( INCLUDE_xTaskAbortDelay == 1 )
|
||||
#if ( INCLUDE_xTaskAbortDelay == 1 )
|
||||
|
||||
static void prvHighPriorityTimeout( SemaphoreHandle_t xMutex )
|
||||
{
|
||||
static UBaseType_t uxLoopCount = 0;
|
||||
|
||||
/* The tests in this function are very similar, the slight variations
|
||||
are for code coverage purposes. */
|
||||
* are for code coverage purposes. */
|
||||
|
||||
/* Take the mutex. It should be available now. Check before and after
|
||||
taking that the holder is reported correctly. */
|
||||
* taking that the holder is reported correctly. */
|
||||
if( xSemaphoreGetMutexHolder( xMutex ) != NULL )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
if( xSemaphoreTake( xMutex, intsemNO_BLOCK ) != pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
if( xSemaphoreGetMutexHolder( xMutex ) != xTaskGetCurrentTaskHandle() )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
/* This task's priority should be as per that assigned when the task was
|
||||
created. */
|
||||
* created. */
|
||||
if( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
/* Now unsuspend the high priority task. This will attempt to take the
|
||||
mutex, and block when it finds it cannot obtain it. */
|
||||
* mutex, and block when it finds it cannot obtain it. */
|
||||
vTaskResume( xHighPriorityMutexTask );
|
||||
|
||||
/* This task should now have inherited the priority of the high priority
|
||||
task as by now the high priority task will have attempted to obtain the
|
||||
mutex. */
|
||||
* task as by now the high priority task will have attempted to obtain the
|
||||
* mutex. */
|
||||
if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
/* Unblock a second medium priority task. It too will attempt to take
|
||||
the mutex and enter the Blocked state - it won't run yet though as this
|
||||
task has inherited a priority above it. */
|
||||
* the mutex and enter the Blocked state - it won't run yet though as this
|
||||
* task has inherited a priority above it. */
|
||||
vTaskResume( xSecondMediumPriorityMutexTask );
|
||||
|
||||
/* This task should still have the priority of the high priority task as
|
||||
that had already been inherited as is the highest priority of the three
|
||||
tasks using the mutex. */
|
||||
* that had already been inherited as is the highest priority of the three
|
||||
* tasks using the mutex. */
|
||||
if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
/* On some loops, block for a short while to provide additional
|
||||
code coverage. Blocking here will allow the medium priority task to
|
||||
execute and so also block on the mutex so when the high priority task
|
||||
causes this task to disinherit the high priority it is inherited down to
|
||||
the priority of the medium priority task. When there is no delay the
|
||||
medium priority task will not run until after the disinheritance, so
|
||||
this task will disinherit back to its base priority, then only up to the
|
||||
medium priority after the medium priority has executed. */
|
||||
* code coverage. Blocking here will allow the medium priority task to
|
||||
* execute and so also block on the mutex so when the high priority task
|
||||
* causes this task to disinherit the high priority it is inherited down to
|
||||
* the priority of the medium priority task. When there is no delay the
|
||||
* medium priority task will not run until after the disinheritance, so
|
||||
* this task will disinherit back to its base priority, then only up to the
|
||||
* medium priority after the medium priority has executed. */
|
||||
vTaskDelay( uxLoopCount & ( UBaseType_t ) 0x07 );
|
||||
|
||||
/* Now force the high priority task to unblock. It will fail to obtain
|
||||
the mutex and go back to the suspended state - allowing this task to
|
||||
execute again. xBlockWasAborted is set to pdTRUE so the higher priority
|
||||
task knows that its failure to obtain the semaphore is not an error. */
|
||||
* the mutex and go back to the suspended state - allowing this task to
|
||||
* execute again. xBlockWasAborted is set to pdTRUE so the higher priority
|
||||
* task knows that its failure to obtain the semaphore is not an error. */
|
||||
xBlockWasAborted = pdTRUE;
|
||||
|
||||
if( xTaskAbortDelay( xHighPriorityMutexTask ) != pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
/* This task has inherited the priority of xHighPriorityMutexTask so
|
||||
could still be running even though xHighPriorityMutexTask is no longer
|
||||
blocked. Delay for a short while to ensure xHighPriorityMutexTask gets
|
||||
a chance to run - indicated by this task changing priority. It should
|
||||
disinherit the high priority task, but then inherit the priority of the
|
||||
medium priority task that is waiting for the same mutex. */
|
||||
* could still be running even though xHighPriorityMutexTask is no longer
|
||||
* blocked. Delay for a short while to ensure xHighPriorityMutexTask gets
|
||||
* a chance to run - indicated by this task changing priority. It should
|
||||
* disinherit the high priority task, but then inherit the priority of the
|
||||
* medium priority task that is waiting for the same mutex. */
|
||||
while( uxTaskPriorityGet( NULL ) != genqMUTEX_MEDIUM_PRIORITY )
|
||||
{
|
||||
/* If this task gets stuck here then the check variables will stop
|
||||
incrementing and the check task will detect the error. */
|
||||
* incrementing and the check task will detect the error. */
|
||||
vTaskDelay( genqSHORT_BLOCK );
|
||||
}
|
||||
|
||||
/* Now force the medium priority task to unblock. xBlockWasAborted is
|
||||
set to pdTRUE so the medium priority task knows that its failure to
|
||||
obtain the semaphore is not an error. */
|
||||
* set to pdTRUE so the medium priority task knows that its failure to
|
||||
* obtain the semaphore is not an error. */
|
||||
xBlockWasAborted = pdTRUE;
|
||||
|
||||
if( xTaskAbortDelay( xSecondMediumPriorityMutexTask ) != pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
/* This time no other tasks are waiting for the mutex, so this task
|
||||
should return to its base priority. This might not happen straight
|
||||
away as it is running at the same priority as the task it just
|
||||
unblocked. */
|
||||
* should return to its base priority. This might not happen straight
|
||||
* away as it is running at the same priority as the task it just
|
||||
* unblocked. */
|
||||
while( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )
|
||||
{
|
||||
/* If this task gets stuck here then the check variables will stop
|
||||
incrementing and the check task will detect the error. */
|
||||
* incrementing and the check task will detect the error. */
|
||||
vTaskDelay( genqSHORT_BLOCK );
|
||||
}
|
||||
|
||||
/* Give the semaphore back ready for the next test. Check the mutex
|
||||
holder before and after using the "FromISR" version for code coverage. */
|
||||
* holder before and after using the "FromISR" version for code coverage. */
|
||||
if( xSemaphoreGetMutexHolderFromISR( xMutex ) != xTaskGetCurrentTaskHandle() )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
xSemaphoreGive( xMutex );
|
||||
|
||||
if( xSemaphoreGetMutexHolderFromISR( xMutex ) != NULL )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -553,15 +563,13 @@ QueueHandle_t xQueue;
|
|||
|
||||
configASSERT( xErrorDetected == pdFALSE );
|
||||
|
||||
|
||||
|
||||
/* Now do the same again, but this time unsuspend the tasks in the
|
||||
opposite order. This takes a different path though the code because
|
||||
when the high priority task has its block aborted there is already
|
||||
another task in the list of tasks waiting for the mutex, and the
|
||||
low priority task drops down to that priority, rather than dropping
|
||||
down to its base priority before inheriting the priority of the medium
|
||||
priority task. */
|
||||
* opposite order. This takes a different path though the code because
|
||||
* when the high priority task has its block aborted there is already
|
||||
* another task in the list of tasks waiting for the mutex, and the
|
||||
* low priority task drops down to that priority, rather than dropping
|
||||
* down to its base priority before inheriting the priority of the medium
|
||||
* priority task. */
|
||||
if( xSemaphoreTake( xMutex, intsemNO_BLOCK ) != pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -573,11 +581,11 @@ QueueHandle_t xQueue;
|
|||
}
|
||||
|
||||
/* This time unsuspend the medium priority task first. This will
|
||||
attempt to take the mutex, and block when it finds it cannot obtain it. */
|
||||
* attempt to take the mutex, and block when it finds it cannot obtain it. */
|
||||
vTaskResume( xSecondMediumPriorityMutexTask );
|
||||
|
||||
/* This time this task should now have inherited the priority of the
|
||||
medium task. */
|
||||
* medium task. */
|
||||
if( uxTaskPriorityGet( NULL ) != genqMUTEX_MEDIUM_PRIORITY )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -587,17 +595,18 @@ QueueHandle_t xQueue;
|
|||
vTaskResume( xHighPriorityMutexTask );
|
||||
|
||||
/* The high priority task should already have run, causing this task to
|
||||
inherit a priority for the second time. */
|
||||
* inherit a priority for the second time. */
|
||||
if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
/* This time, when the high priority task has its delay aborted and it
|
||||
fails to obtain the mutex this task will immediately have its priority
|
||||
lowered down to that of the highest priority task waiting on the mutex,
|
||||
which is the medium priority task. */
|
||||
* fails to obtain the mutex this task will immediately have its priority
|
||||
* lowered down to that of the highest priority task waiting on the mutex,
|
||||
* which is the medium priority task. */
|
||||
xBlockWasAborted = pdTRUE;
|
||||
|
||||
if( xTaskAbortDelay( xHighPriorityMutexTask ) != pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -606,14 +615,15 @@ QueueHandle_t xQueue;
|
|||
while( uxTaskPriorityGet( NULL ) != genqMUTEX_MEDIUM_PRIORITY )
|
||||
{
|
||||
/* If this task gets stuck here then the check variables will stop
|
||||
incrementing and the check task will detect the error. */
|
||||
* incrementing and the check task will detect the error. */
|
||||
vTaskDelay( genqSHORT_BLOCK );
|
||||
}
|
||||
|
||||
/* And finally, when the medium priority task also have its delay
|
||||
aborted there are no other tasks waiting for the mutex so this task
|
||||
returns to its base priority. */
|
||||
* aborted there are no other tasks waiting for the mutex so this task
|
||||
* returns to its base priority. */
|
||||
xBlockWasAborted = pdTRUE;
|
||||
|
||||
if( xTaskAbortDelay( xSecondMediumPriorityMutexTask ) != pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -622,7 +632,7 @@ QueueHandle_t xQueue;
|
|||
while( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )
|
||||
{
|
||||
/* If this task gets stuck here then the check variables will stop
|
||||
incrementing and the check task will detect the error. */
|
||||
* incrementing and the check task will detect the error. */
|
||||
vTaskDelay( genqSHORT_BLOCK );
|
||||
}
|
||||
|
||||
|
|
@ -632,14 +642,15 @@ QueueHandle_t xQueue;
|
|||
configASSERT( xErrorDetected == pdFALSE );
|
||||
|
||||
/* uxLoopCount is used to add a variable delay, and in-so-doing provide
|
||||
additional code coverage. */
|
||||
* additional code coverage. */
|
||||
uxLoopCount++;
|
||||
}
|
||||
|
||||
#endif /* INCLUDE_xTaskAbortDelay == 1 */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvTakeTwoMutexesReturnInDifferentOrder( SemaphoreHandle_t xMutex, SemaphoreHandle_t xLocalMutex )
|
||||
static void prvTakeTwoMutexesReturnInDifferentOrder( SemaphoreHandle_t xMutex,
|
||||
SemaphoreHandle_t xLocalMutex )
|
||||
{
|
||||
/* Take the mutex. It should be available now. */
|
||||
if( xSemaphoreTake( xMutex, intsemNO_BLOCK ) != pdPASS )
|
||||
|
|
@ -651,14 +662,14 @@ static void prvTakeTwoMutexesReturnInDifferentOrder( SemaphoreHandle_t xMutex, S
|
|||
ulGuardedVariable = 0;
|
||||
|
||||
/* This task's priority should be as per that assigned when the task was
|
||||
created. */
|
||||
* created. */
|
||||
if( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
/* Now unsuspend the high priority task. This will attempt to take the
|
||||
mutex, and block when it finds it cannot obtain it. */
|
||||
* mutex, and block when it finds it cannot obtain it. */
|
||||
vTaskResume( xHighPriorityMutexTask );
|
||||
|
||||
#if configUSE_PREEMPTION == 0
|
||||
|
|
@ -666,37 +677,38 @@ static void prvTakeTwoMutexesReturnInDifferentOrder( SemaphoreHandle_t xMutex, S
|
|||
#endif
|
||||
|
||||
/* Ensure the task is reporting its priority as blocked and not
|
||||
suspended (as it would have done in versions up to V7.5.3). */
|
||||
#if( INCLUDE_eTaskGetState == 1 )
|
||||
* suspended (as it would have done in versions up to V7.5.3). */
|
||||
#if ( INCLUDE_eTaskGetState == 1 )
|
||||
{
|
||||
configASSERT( eTaskGetState( xHighPriorityMutexTask ) == eBlocked );
|
||||
}
|
||||
#endif /* INCLUDE_eTaskGetState */
|
||||
|
||||
/* This task should now have inherited the priority of the high priority
|
||||
task as by now the high priority task will have attempted to obtain the
|
||||
mutex. */
|
||||
* task as by now the high priority task will have attempted to obtain the
|
||||
* mutex. */
|
||||
if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
/* Attempt to set the priority of this task to the test priority -
|
||||
between the idle priority and the medium/high test priorities, but the
|
||||
actual priority should remain at the high priority. */
|
||||
* between the idle priority and the medium/high test priorities, but the
|
||||
* actual priority should remain at the high priority. */
|
||||
vTaskPrioritySet( NULL, genqMUTEX_TEST_PRIORITY );
|
||||
|
||||
if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
/* Now unsuspend the medium priority task. This should not run as the
|
||||
inherited priority of this task is above that of the medium priority
|
||||
task. */
|
||||
* inherited priority of this task is above that of the medium priority
|
||||
* task. */
|
||||
vTaskResume( xMediumPriorityMutexTask );
|
||||
|
||||
/* If the medium priority task did run then it will have incremented the
|
||||
guarded variable. */
|
||||
* guarded variable. */
|
||||
if( ulGuardedVariable != 0 )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -709,11 +721,11 @@ static void prvTakeTwoMutexesReturnInDifferentOrder( SemaphoreHandle_t xMutex, S
|
|||
}
|
||||
|
||||
/* When the semaphore is given back the priority of this task should not
|
||||
yet be disinherited because the local mutex is still held. This is a
|
||||
simplification to allow FreeRTOS to be integrated with middleware that
|
||||
attempts to hold multiple mutexes without bloating the code with complex
|
||||
algorithms. It is possible that the high priority mutex task will
|
||||
execute as it shares a priority with this task. */
|
||||
* yet be disinherited because the local mutex is still held. This is a
|
||||
* simplification to allow FreeRTOS to be integrated with middleware that
|
||||
* attempts to hold multiple mutexes without bloating the code with complex
|
||||
* algorithms. It is possible that the high priority mutex task will
|
||||
* execute as it shares a priority with this task. */
|
||||
if( xSemaphoreGive( xMutex ) != pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -724,8 +736,8 @@ static void prvTakeTwoMutexesReturnInDifferentOrder( SemaphoreHandle_t xMutex, S
|
|||
#endif
|
||||
|
||||
/* The guarded variable is only incremented by the medium priority task,
|
||||
which still should not have executed as this task should remain at the
|
||||
higher priority, ensure this is the case. */
|
||||
* which still should not have executed as this task should remain at the
|
||||
* higher priority, ensure this is the case. */
|
||||
if( ulGuardedVariable != 0 )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -737,11 +749,11 @@ static void prvTakeTwoMutexesReturnInDifferentOrder( SemaphoreHandle_t xMutex, S
|
|||
}
|
||||
|
||||
/* Now also give back the local mutex, taking the held count back to 0.
|
||||
This time the priority of this task should be disinherited back to the
|
||||
priority to which it was set while the mutex was held. This means
|
||||
the medium priority task should execute and increment the guarded
|
||||
variable. When this task next runs both the high and medium priority
|
||||
tasks will have been suspended again. */
|
||||
* This time the priority of this task should be disinherited back to the
|
||||
* priority to which it was set while the mutex was held. This means
|
||||
* the medium priority task should execute and increment the guarded
|
||||
* variable. When this task next runs both the high and medium priority
|
||||
* tasks will have been suspended again. */
|
||||
if( xSemaphoreGive( xLocalMutex ) != pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -758,19 +770,20 @@ static void prvTakeTwoMutexesReturnInDifferentOrder( SemaphoreHandle_t xMutex, S
|
|||
}
|
||||
|
||||
/* ... and that the priority of this task has been disinherited to
|
||||
genqMUTEX_TEST_PRIORITY. */
|
||||
* genqMUTEX_TEST_PRIORITY. */
|
||||
if( uxTaskPriorityGet( NULL ) != genqMUTEX_TEST_PRIORITY )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
/* Set the priority of this task back to its original value, ready for
|
||||
the next loop around this test. */
|
||||
* the next loop around this test. */
|
||||
vTaskPrioritySet( NULL, genqMUTEX_LOW_PRIORITY );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvTakeTwoMutexesReturnInSameOrder( SemaphoreHandle_t xMutex, SemaphoreHandle_t xLocalMutex )
|
||||
static void prvTakeTwoMutexesReturnInSameOrder( SemaphoreHandle_t xMutex,
|
||||
SemaphoreHandle_t xLocalMutex )
|
||||
{
|
||||
/* Take the mutex. It should be available now. */
|
||||
if( xSemaphoreTake( xMutex, intsemNO_BLOCK ) != pdPASS )
|
||||
|
|
@ -782,14 +795,14 @@ static void prvTakeTwoMutexesReturnInSameOrder( SemaphoreHandle_t xMutex, Semaph
|
|||
ulGuardedVariable = 0;
|
||||
|
||||
/* This task's priority should be as per that assigned when the task was
|
||||
created. */
|
||||
* created. */
|
||||
if( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
/* Now unsuspend the high priority task. This will attempt to take the
|
||||
mutex, and block when it finds it cannot obtain it. */
|
||||
* mutex, and block when it finds it cannot obtain it. */
|
||||
vTaskResume( xHighPriorityMutexTask );
|
||||
|
||||
#if configUSE_PREEMPTION == 0
|
||||
|
|
@ -797,28 +810,28 @@ static void prvTakeTwoMutexesReturnInSameOrder( SemaphoreHandle_t xMutex, Semaph
|
|||
#endif
|
||||
|
||||
/* Ensure the task is reporting its priority as blocked and not
|
||||
suspended (as it would have done in versions up to V7.5.3). */
|
||||
#if( INCLUDE_eTaskGetState == 1 )
|
||||
* suspended (as it would have done in versions up to V7.5.3). */
|
||||
#if ( INCLUDE_eTaskGetState == 1 )
|
||||
{
|
||||
configASSERT( eTaskGetState( xHighPriorityMutexTask ) == eBlocked );
|
||||
}
|
||||
#endif /* INCLUDE_eTaskGetState */
|
||||
|
||||
/* This task should now have inherited the priority of the high priority
|
||||
task as by now the high priority task will have attempted to obtain the
|
||||
mutex. */
|
||||
* task as by now the high priority task will have attempted to obtain the
|
||||
* mutex. */
|
||||
if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
/* Now unsuspend the medium priority task. This should not run as the
|
||||
inherited priority of this task is above that of the medium priority
|
||||
task. */
|
||||
* inherited priority of this task is above that of the medium priority
|
||||
* task. */
|
||||
vTaskResume( xMediumPriorityMutexTask );
|
||||
|
||||
/* If the medium priority task did run then it will have incremented the
|
||||
guarded variable. */
|
||||
* guarded variable. */
|
||||
if( ulGuardedVariable != 0 )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -831,11 +844,11 @@ static void prvTakeTwoMutexesReturnInSameOrder( SemaphoreHandle_t xMutex, Semaph
|
|||
}
|
||||
|
||||
/* When the local semaphore is given back the priority of this task should
|
||||
not yet be disinherited because the shared mutex is still held. This is a
|
||||
simplification to allow FreeRTOS to be integrated with middleware that
|
||||
attempts to hold multiple mutexes without bloating the code with complex
|
||||
algorithms. It is possible that the high priority mutex task will
|
||||
execute as it shares a priority with this task. */
|
||||
* not yet be disinherited because the shared mutex is still held. This is a
|
||||
* simplification to allow FreeRTOS to be integrated with middleware that
|
||||
* attempts to hold multiple mutexes without bloating the code with complex
|
||||
* algorithms. It is possible that the high priority mutex task will
|
||||
* execute as it shares a priority with this task. */
|
||||
if( xSemaphoreGive( xLocalMutex ) != pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -846,8 +859,8 @@ static void prvTakeTwoMutexesReturnInSameOrder( SemaphoreHandle_t xMutex, Semaph
|
|||
#endif
|
||||
|
||||
/* The guarded variable is only incremented by the medium priority task,
|
||||
which still should not have executed as this task should remain at the
|
||||
higher priority, ensure this is the case. */
|
||||
* which still should not have executed as this task should remain at the
|
||||
* higher priority, ensure this is the case. */
|
||||
if( ulGuardedVariable != 0 )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -859,10 +872,10 @@ static void prvTakeTwoMutexesReturnInSameOrder( SemaphoreHandle_t xMutex, Semaph
|
|||
}
|
||||
|
||||
/* Now also give back the shared mutex, taking the held count back to 0.
|
||||
This time the priority of this task should be disinherited back to the
|
||||
priority at which it was created. This means the medium priority task
|
||||
should execute and increment the guarded variable. When this task next runs
|
||||
both the high and medium priority tasks will have been suspended again. */
|
||||
* This time the priority of this task should be disinherited back to the
|
||||
* priority at which it was created. This means the medium priority task
|
||||
* should execute and increment the guarded variable. When this task next runs
|
||||
* both the high and medium priority tasks will have been suspended again. */
|
||||
if( xSemaphoreGive( xMutex ) != pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -879,7 +892,7 @@ static void prvTakeTwoMutexesReturnInSameOrder( SemaphoreHandle_t xMutex, Semaph
|
|||
}
|
||||
|
||||
/* ... and that the priority of this task has been disinherited to
|
||||
genqMUTEX_LOW_PRIORITY. */
|
||||
* genqMUTEX_LOW_PRIORITY. */
|
||||
if( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -887,9 +900,9 @@ static void prvTakeTwoMutexesReturnInSameOrder( SemaphoreHandle_t xMutex, Semaph
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvLowPriorityMutexTask( void *pvParameters )
|
||||
static void prvLowPriorityMutexTask( void * pvParameters )
|
||||
{
|
||||
SemaphoreHandle_t xMutex = ( SemaphoreHandle_t ) pvParameters, xLocalMutex;
|
||||
SemaphoreHandle_t xMutex = ( SemaphoreHandle_t ) pvParameters, xLocalMutex;
|
||||
|
||||
#ifdef USE_STDIO
|
||||
void vPrintDisplayMessage( const char * const * ppcMessageToSend );
|
||||
|
|
@ -904,11 +917,11 @@ SemaphoreHandle_t xMutex = ( SemaphoreHandle_t ) pvParameters, xLocalMutex;
|
|||
xLocalMutex = xSemaphoreCreateMutex();
|
||||
configASSERT( xLocalMutex );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* The first tests exercise the priority inheritance when two mutexes
|
||||
are taken then returned in a different order to which they were
|
||||
taken. */
|
||||
* are taken then returned in a different order to which they were
|
||||
* taken. */
|
||||
prvTakeTwoMutexesReturnInDifferentOrder( xMutex, xLocalMutex );
|
||||
|
||||
/* Just to show this task is still running. */
|
||||
|
|
@ -919,7 +932,7 @@ SemaphoreHandle_t xMutex = ( SemaphoreHandle_t ) pvParameters, xLocalMutex;
|
|||
#endif
|
||||
|
||||
/* The second tests exercise the priority inheritance when two mutexes
|
||||
are taken then returned in the same order in which they were taken. */
|
||||
* are taken then returned in the same order in which they were taken. */
|
||||
prvTakeTwoMutexesReturnInSameOrder( xMutex, xLocalMutex );
|
||||
|
||||
/* Just to show this task is still running. */
|
||||
|
|
@ -929,11 +942,11 @@ SemaphoreHandle_t xMutex = ( SemaphoreHandle_t ) pvParameters, xLocalMutex;
|
|||
taskYIELD();
|
||||
#endif
|
||||
|
||||
#if( INCLUDE_xTaskAbortDelay == 1 )
|
||||
#if ( INCLUDE_xTaskAbortDelay == 1 )
|
||||
{
|
||||
/* Tests the behaviour when a low priority task inherits the
|
||||
priority of a high priority task only for the high priority task to
|
||||
timeout before obtaining the mutex. */
|
||||
* priority of a high priority task only for the high priority task to
|
||||
* timeout before obtaining the mutex. */
|
||||
prvHighPriorityTimeout( xMutex );
|
||||
}
|
||||
#endif
|
||||
|
|
@ -941,41 +954,41 @@ SemaphoreHandle_t xMutex = ( SemaphoreHandle_t ) pvParameters, xLocalMutex;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvMediumPriorityMutexTask( void *pvParameters )
|
||||
static void prvMediumPriorityMutexTask( void * pvParameters )
|
||||
{
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* The medium priority task starts by suspending itself. The low
|
||||
priority task will unsuspend this task when required. */
|
||||
* priority task will unsuspend this task when required. */
|
||||
vTaskSuspend( NULL );
|
||||
|
||||
/* When this task unsuspends all it does is increment the guarded
|
||||
variable, this is so the low priority task knows that it has
|
||||
executed. */
|
||||
* variable, this is so the low priority task knows that it has
|
||||
* executed. */
|
||||
ulGuardedVariable++;
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvHighPriorityMutexTask( void *pvParameters )
|
||||
static void prvHighPriorityMutexTask( void * pvParameters )
|
||||
{
|
||||
SemaphoreHandle_t xMutex = ( SemaphoreHandle_t ) pvParameters;
|
||||
SemaphoreHandle_t xMutex = ( SemaphoreHandle_t ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* The high priority task starts by suspending itself. The low
|
||||
priority task will unsuspend this task when required. */
|
||||
* priority task will unsuspend this task when required. */
|
||||
vTaskSuspend( NULL );
|
||||
|
||||
/* When this task unsuspends all it does is attempt to obtain the
|
||||
mutex. It should find the mutex is not available so a block time is
|
||||
specified. */
|
||||
* mutex. It should find the mutex is not available so a block time is
|
||||
* specified. */
|
||||
if( xSemaphoreTake( xMutex, portMAX_DELAY ) != pdPASS )
|
||||
{
|
||||
/* This task would expect to obtain the mutex unless its wait for
|
||||
the mutex was aborted. */
|
||||
* the mutex was aborted. */
|
||||
if( xBlockWasAborted == pdFALSE )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -988,7 +1001,7 @@ SemaphoreHandle_t xMutex = ( SemaphoreHandle_t ) pvParameters;
|
|||
else
|
||||
{
|
||||
/* When the mutex is eventually obtained it is just given back before
|
||||
returning to suspend ready for the next cycle. */
|
||||
* returning to suspend ready for the next cycle. */
|
||||
if( xSemaphoreGive( xMutex ) != pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -1002,10 +1015,10 @@ SemaphoreHandle_t xMutex = ( SemaphoreHandle_t ) pvParameters;
|
|||
/* This is called to check that all the created tasks are still running. */
|
||||
BaseType_t xAreGenericQueueTasksStillRunning( void )
|
||||
{
|
||||
static uint32_t ulLastLoopCounter = 0, ulLastLoopCounter2 = 0;
|
||||
static uint32_t ulLastLoopCounter = 0, ulLastLoopCounter2 = 0;
|
||||
|
||||
/* If the demo task is still running then we expect the loop counters to
|
||||
have incremented since this function was last called. */
|
||||
* have incremented since this function was last called. */
|
||||
if( ulLastLoopCounter == ulLoopCounter )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -1020,9 +1033,7 @@ static uint32_t ulLastLoopCounter = 0, ulLastLoopCounter2 = 0;
|
|||
ulLastLoopCounter2 = ulLoopCounter2;
|
||||
|
||||
/* Errors detected in the task itself will have latched xErrorDetected
|
||||
to true. */
|
||||
* to true. */
|
||||
|
||||
return ( BaseType_t ) !xErrorDetected;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@
|
|||
#include "IntQueue.h"
|
||||
#include "IntQueueTimer.h"
|
||||
|
||||
#if( INCLUDE_eTaskGetState != 1 )
|
||||
#if ( INCLUDE_eTaskGetState != 1 )
|
||||
#error INCLUDE_eTaskGetState must be set to 1 in FreeRTOSConfig.h to use this demo file.
|
||||
#endif
|
||||
|
||||
|
|
@ -63,24 +63,24 @@
|
|||
#define intqLOWER_PRIORITY ( tskIDLE_PRIORITY )
|
||||
|
||||
/* The number of values to send/receive before checking that all values were
|
||||
processed as expected. */
|
||||
* processed as expected. */
|
||||
#define intqNUM_VALUES_TO_LOG ( 200 )
|
||||
#define intqSHORT_DELAY ( 140 )
|
||||
|
||||
/* The value by which the value being sent to or received from a queue should
|
||||
increment past intqNUM_VALUES_TO_LOG before we check that all values have been
|
||||
sent/received correctly. This is done to ensure that all tasks and interrupts
|
||||
accessing the queue have completed their accesses with the
|
||||
intqNUM_VALUES_TO_LOG range. */
|
||||
* increment past intqNUM_VALUES_TO_LOG before we check that all values have been
|
||||
* sent/received correctly. This is done to ensure that all tasks and interrupts
|
||||
* accessing the queue have completed their accesses with the
|
||||
* intqNUM_VALUES_TO_LOG range. */
|
||||
#define intqVALUE_OVERRUN ( 50 )
|
||||
|
||||
/* The delay used by the polling task. A short delay is used for code
|
||||
coverage. */
|
||||
* coverage. */
|
||||
#define intqONE_TICK_DELAY ( 1 )
|
||||
|
||||
/* Each task and interrupt is given a unique identifier. This value is used to
|
||||
identify which task sent or received each value. The identifier is also used
|
||||
to distinguish between two tasks that are running the same task function. */
|
||||
* identify which task sent or received each value. The identifier is also used
|
||||
* to distinguish between two tasks that are running the same task function. */
|
||||
#define intqHIGH_PRIORITY_TASK1 ( ( UBaseType_t ) 1 )
|
||||
#define intqHIGH_PRIORITY_TASK2 ( ( UBaseType_t ) 2 )
|
||||
#define intqLOW_PRIORITY_TASK ( ( UBaseType_t ) 3 )
|
||||
|
|
@ -89,11 +89,11 @@ to distinguish between two tasks that are running the same task function. */
|
|||
#define intqQUEUE_LENGTH ( ( UBaseType_t ) 10 )
|
||||
|
||||
/* At least intqMIN_ACCEPTABLE_TASK_COUNT values should be sent to/received
|
||||
from each queue by each task, otherwise an error is detected. */
|
||||
* from each queue by each task, otherwise an error is detected. */
|
||||
#define intqMIN_ACCEPTABLE_TASK_COUNT ( 5 )
|
||||
|
||||
/* Send the next value to the queue that is normally empty. This is called
|
||||
from within the interrupts. */
|
||||
* from within the interrupts. */
|
||||
#define timerNORMALLY_EMPTY_TX() \
|
||||
if( xQueueIsQueueFullFromISR( xNormallyEmptyQueue ) != pdTRUE ) \
|
||||
{ \
|
||||
|
|
@ -109,8 +109,9 @@ from within the interrupts. */
|
|||
portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); \
|
||||
} \
|
||||
|
||||
|
||||
/* Send the next value to the queue that is normally full. This is called
|
||||
from within the interrupts. */
|
||||
* from within the interrupts. */
|
||||
#define timerNORMALLY_FULL_TX() \
|
||||
if( xQueueIsQueueFullFromISR( xNormallyFullQueue ) != pdTRUE ) \
|
||||
{ \
|
||||
|
|
@ -126,8 +127,9 @@ from within the interrupts. */
|
|||
portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); \
|
||||
} \
|
||||
|
||||
|
||||
/* Receive a value from the normally empty queue. This is called from within
|
||||
an interrupt. */
|
||||
* an interrupt. */
|
||||
#define timerNORMALLY_EMPTY_RX() \
|
||||
if( xQueueReceiveFromISR( xNormallyEmptyQueue, &uxRxedValue, &xHigherPriorityTaskWoken ) != pdPASS ) \
|
||||
{ \
|
||||
|
|
@ -139,7 +141,7 @@ an interrupt. */
|
|||
}
|
||||
|
||||
/* Receive a value from the normally full queue. This is called from within
|
||||
an interrupt. */
|
||||
* an interrupt. */
|
||||
#define timerNORMALLY_FULL_RX() \
|
||||
if( xQueueReceiveFromISR( xNormallyFullQueue, &uxRxedValue, &xHigherPriorityTaskWoken ) == pdPASS ) \
|
||||
{ \
|
||||
|
|
@ -156,7 +158,7 @@ static QueueHandle_t xNormallyEmptyQueue, xNormallyFullQueue;
|
|||
static volatile UBaseType_t uxHighPriorityLoops1 = 0, uxHighPriorityLoops2 = 0, uxLowPriorityLoops1 = 0, uxLowPriorityLoops2 = 0;
|
||||
|
||||
/* Any unexpected behaviour sets xErrorStatus to fail and log the line that
|
||||
caused the error in xErrorLine. */
|
||||
* caused the error in xErrorLine. */
|
||||
static BaseType_t xErrorStatus = pdPASS;
|
||||
static volatile UBaseType_t xErrorLine = ( UBaseType_t ) 0;
|
||||
|
||||
|
|
@ -164,30 +166,32 @@ static volatile UBaseType_t xErrorLine = ( UBaseType_t ) 0;
|
|||
static BaseType_t xWasSuspended = pdFALSE;
|
||||
|
||||
/* The values that are sent to the queues. An incremented value is sent each
|
||||
time to each queue. */
|
||||
* time to each queue. */
|
||||
static volatile UBaseType_t uxValueForNormallyEmptyQueue = 0, uxValueForNormallyFullQueue = 0;
|
||||
|
||||
/* A handle to some of the tasks is required so they can be suspended/resumed. */
|
||||
TaskHandle_t xHighPriorityNormallyEmptyTask1, xHighPriorityNormallyEmptyTask2, xHighPriorityNormallyFullTask1, xHighPriorityNormallyFullTask2;
|
||||
|
||||
/* When a value is received in a queue the value is ticked off in the array
|
||||
the array position of the value is set to a the identifier of the task or
|
||||
interrupt that accessed the queue. This way missing or duplicate values can be
|
||||
detected. */
|
||||
* the array position of the value is set to a the identifier of the task or
|
||||
* interrupt that accessed the queue. This way missing or duplicate values can be
|
||||
* detected. */
|
||||
static uint8_t ucNormallyEmptyReceivedValues[ intqNUM_VALUES_TO_LOG ] = { 0 };
|
||||
static uint8_t ucNormallyFullReceivedValues[ intqNUM_VALUES_TO_LOG ] = { 0 };
|
||||
|
||||
/* The test tasks themselves. */
|
||||
static void prvLowerPriorityNormallyEmptyTask( void *pvParameters );
|
||||
static void prvLowerPriorityNormallyFullTask( void *pvParameters );
|
||||
static void prvHigherPriorityNormallyEmptyTask( void *pvParameters );
|
||||
static void prv1stHigherPriorityNormallyFullTask( void *pvParameters );
|
||||
static void prv2ndHigherPriorityNormallyFullTask( void *pvParameters );
|
||||
static void prvLowerPriorityNormallyEmptyTask( void * pvParameters );
|
||||
static void prvLowerPriorityNormallyFullTask( void * pvParameters );
|
||||
static void prvHigherPriorityNormallyEmptyTask( void * pvParameters );
|
||||
static void prv1stHigherPriorityNormallyFullTask( void * pvParameters );
|
||||
static void prv2ndHigherPriorityNormallyFullTask( void * pvParameters );
|
||||
|
||||
/* Used to mark the positions within the ucNormallyEmptyReceivedValues and
|
||||
ucNormallyFullReceivedValues arrays, while checking for duplicates. */
|
||||
static void prvRecordValue_NormallyEmpty( UBaseType_t uxValue, UBaseType_t uxSource );
|
||||
static void prvRecordValue_NormallyFull( UBaseType_t uxValue, UBaseType_t uxSource );
|
||||
* ucNormallyFullReceivedValues arrays, while checking for duplicates. */
|
||||
static void prvRecordValue_NormallyEmpty( UBaseType_t uxValue,
|
||||
UBaseType_t uxSource );
|
||||
static void prvRecordValue_NormallyFull( UBaseType_t uxValue,
|
||||
UBaseType_t uxSource );
|
||||
|
||||
/* Logs the line on which an error occurred. */
|
||||
static void prvQueueAccessLogError( UBaseType_t uxLine );
|
||||
|
|
@ -205,27 +209,28 @@ void vStartInterruptQueueTasks( void )
|
|||
xTaskCreate( prvLowerPriorityNormallyFullTask, "L2QRx", configMINIMAL_STACK_SIZE, NULL, intqLOWER_PRIORITY, NULL );
|
||||
|
||||
/* Create the queues that are accessed by multiple tasks and multiple
|
||||
interrupts. */
|
||||
* interrupts. */
|
||||
xNormallyFullQueue = xQueueCreate( intqQUEUE_LENGTH, ( UBaseType_t ) sizeof( UBaseType_t ) );
|
||||
xNormallyEmptyQueue = xQueueCreate( intqQUEUE_LENGTH, ( UBaseType_t ) sizeof( UBaseType_t ) );
|
||||
|
||||
/* vQueueAddToRegistry() adds the queue to the queue registry, if one is
|
||||
in use. The queue registry is provided as a means for kernel aware
|
||||
debuggers to locate queues 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
|
||||
defined to be less than 1. */
|
||||
* in use. The queue registry is provided as a means for kernel aware
|
||||
* debuggers to locate queues 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
|
||||
* defined to be less than 1. */
|
||||
vQueueAddToRegistry( xNormallyFullQueue, "NormallyFull" );
|
||||
vQueueAddToRegistry( xNormallyEmptyQueue, "NormallyEmpty" );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvRecordValue_NormallyFull( UBaseType_t uxValue, UBaseType_t uxSource )
|
||||
static void prvRecordValue_NormallyFull( UBaseType_t uxValue,
|
||||
UBaseType_t uxSource )
|
||||
{
|
||||
if( uxValue < intqNUM_VALUES_TO_LOG )
|
||||
{
|
||||
/* We don't expect to receive the same value twice, so if the value
|
||||
has already been marked as received an error has occurred. */
|
||||
* has already been marked as received an error has occurred. */
|
||||
if( ucNormallyFullReceivedValues[ uxValue ] != 0x00 )
|
||||
{
|
||||
prvQueueAccessLogError( __LINE__ );
|
||||
|
|
@ -237,12 +242,13 @@ static void prvRecordValue_NormallyFull( UBaseType_t uxValue, UBaseType_t uxSour
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvRecordValue_NormallyEmpty( UBaseType_t uxValue, UBaseType_t uxSource )
|
||||
static void prvRecordValue_NormallyEmpty( UBaseType_t uxValue,
|
||||
UBaseType_t uxSource )
|
||||
{
|
||||
if( uxValue < intqNUM_VALUES_TO_LOG )
|
||||
{
|
||||
/* We don't expect to receive the same value twice, so if the value
|
||||
has already been marked as received an error has occurred. */
|
||||
* has already been marked as received an error has occurred. */
|
||||
if( ucNormallyEmptyReceivedValues[ uxValue ] != 0x00 )
|
||||
{
|
||||
prvQueueAccessLogError( __LINE__ );
|
||||
|
|
@ -262,22 +268,22 @@ static void prvQueueAccessLogError( UBaseType_t uxLine )
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvHigherPriorityNormallyEmptyTask( void *pvParameters )
|
||||
static void prvHigherPriorityNormallyEmptyTask( void * pvParameters )
|
||||
{
|
||||
UBaseType_t uxRxed, ux, uxTask1, uxTask2, uxInterrupts, uxErrorCount1 = 0, uxErrorCount2 = 0;
|
||||
UBaseType_t uxRxed, ux, uxTask1, uxTask2, uxInterrupts, uxErrorCount1 = 0, uxErrorCount2 = 0;
|
||||
|
||||
/* The timer should not be started until after the scheduler has started.
|
||||
More than one task is running this code so we check the parameter value
|
||||
to determine which task should start the timer. */
|
||||
* More than one task is running this code so we check the parameter value
|
||||
* to determine which task should start the timer. */
|
||||
if( ( UBaseType_t ) pvParameters == intqHIGH_PRIORITY_TASK1 )
|
||||
{
|
||||
vInitialiseTimerForIntQueueTest();
|
||||
}
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Block waiting to receive a value from the normally empty queue.
|
||||
Interrupts will write to the queue so we should receive a value. */
|
||||
* Interrupts will write to the queue so we should receive a value. */
|
||||
if( xQueueReceive( xNormallyEmptyQueue, &uxRxed, intqSHORT_DELAY ) != pdPASS )
|
||||
{
|
||||
prvQueueAccessLogError( __LINE__ );
|
||||
|
|
@ -285,7 +291,7 @@ UBaseType_t uxRxed, ux, uxTask1, uxTask2, uxInterrupts, uxErrorCount1 = 0, uxErr
|
|||
else
|
||||
{
|
||||
/* Note which value was received so we can check all expected
|
||||
values are received and no values are duplicated. */
|
||||
* values are received and no values are duplicated. */
|
||||
prvRecordValue_NormallyEmpty( uxRxed, ( UBaseType_t ) pvParameters );
|
||||
}
|
||||
|
||||
|
|
@ -304,8 +310,8 @@ UBaseType_t uxRxed, ux, uxTask1, uxTask2, uxInterrupts, uxErrorCount1 = 0, uxErr
|
|||
uxInterrupts = 0;
|
||||
|
||||
/* Loop through the array, checking that both tasks have
|
||||
placed values into the array, and that no values are missing.
|
||||
Start at 1 as we expect position 0 to be unused. */
|
||||
* placed values into the array, and that no values are missing.
|
||||
* Start at 1 as we expect position 0 to be unused. */
|
||||
for( ux = 1; ux < intqNUM_VALUES_TO_LOG; ux++ )
|
||||
{
|
||||
if( ucNormallyEmptyReceivedValues[ ux ] == 0 )
|
||||
|
|
@ -336,6 +342,7 @@ UBaseType_t uxRxed, ux, uxTask1, uxTask2, uxInterrupts, uxErrorCount1 = 0, uxErr
|
|||
{
|
||||
/* Only task 2 seemed to log any values. */
|
||||
uxErrorCount1++;
|
||||
|
||||
if( uxErrorCount1 > 2 )
|
||||
{
|
||||
prvQueueAccessLogError( __LINE__ );
|
||||
|
|
@ -350,6 +357,7 @@ UBaseType_t uxRxed, ux, uxTask1, uxTask2, uxInterrupts, uxErrorCount1 = 0, uxErr
|
|||
{
|
||||
/* Only task 1 seemed to log any values. */
|
||||
uxErrorCount2++;
|
||||
|
||||
if( uxErrorCount2 > 2 )
|
||||
{
|
||||
prvQueueAccessLogError( __LINE__ );
|
||||
|
|
@ -372,11 +380,11 @@ UBaseType_t uxRxed, ux, uxTask1, uxTask2, uxInterrupts, uxErrorCount1 = 0, uxErr
|
|||
uxValueForNormallyEmptyQueue = 0;
|
||||
|
||||
/* Suspend ourselves, allowing the lower priority task to
|
||||
actually receive something from the queue. Until now it
|
||||
will have been prevented from doing so by the higher
|
||||
priority tasks. The lower priority task will resume us
|
||||
if it receives something. We will then resume the other
|
||||
higher priority task. */
|
||||
* actually receive something from the queue. Until now it
|
||||
* will have been prevented from doing so by the higher
|
||||
* priority tasks. The lower priority task will resume us
|
||||
* if it receives something. We will then resume the other
|
||||
* higher priority task. */
|
||||
vTaskSuspend( NULL );
|
||||
vTaskResume( xHighPriorityNormallyEmptyTask2 );
|
||||
}
|
||||
|
|
@ -385,19 +393,19 @@ UBaseType_t uxRxed, ux, uxTask1, uxTask2, uxInterrupts, uxErrorCount1 = 0, uxErr
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvLowerPriorityNormallyEmptyTask( void *pvParameters )
|
||||
static void prvLowerPriorityNormallyEmptyTask( void * pvParameters )
|
||||
{
|
||||
UBaseType_t uxValue, uxRxed;
|
||||
UBaseType_t uxValue, uxRxed;
|
||||
|
||||
/* The parameters are not being used so avoid compiler warnings. */
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
if( xQueueReceive( xNormallyEmptyQueue, &uxRxed, intqONE_TICK_DELAY ) != errQUEUE_EMPTY )
|
||||
{
|
||||
/* A value should only be obtained when the high priority task is
|
||||
suspended. */
|
||||
* suspended. */
|
||||
if( eTaskGetState( xHighPriorityNormallyEmptyTask1 ) != eSuspended )
|
||||
{
|
||||
prvQueueAccessLogError( __LINE__ );
|
||||
|
|
@ -412,7 +420,7 @@ UBaseType_t uxValue, uxRxed;
|
|||
else
|
||||
{
|
||||
/* Raise our priority while we send so we can preempt the higher
|
||||
priority task, and ensure we get the Tx value into the queue. */
|
||||
* priority task, and ensure we get the Tx value into the queue. */
|
||||
vTaskPrioritySet( NULL, intqHIGHER_PRIORITY + 1 );
|
||||
|
||||
portENTER_CRITICAL();
|
||||
|
|
@ -433,15 +441,15 @@ UBaseType_t uxValue, uxRxed;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prv1stHigherPriorityNormallyFullTask( void *pvParameters )
|
||||
static void prv1stHigherPriorityNormallyFullTask( void * pvParameters )
|
||||
{
|
||||
UBaseType_t uxValueToTx, ux, uxInterrupts;
|
||||
UBaseType_t uxValueToTx, ux, uxInterrupts;
|
||||
|
||||
/* The parameters are not being used so avoid compiler warnings. */
|
||||
( void ) pvParameters;
|
||||
|
||||
/* Make sure the queue starts full or near full. >> 1 as there are two
|
||||
high priority tasks. */
|
||||
* high priority tasks. */
|
||||
for( ux = 0; ux < ( intqQUEUE_LENGTH >> 1 ); ux++ )
|
||||
{
|
||||
portENTER_CRITICAL();
|
||||
|
|
@ -454,7 +462,7 @@ UBaseType_t uxValueToTx, ux, uxInterrupts;
|
|||
xQueueSend( xNormallyFullQueue, &uxValueToTx, intqSHORT_DELAY );
|
||||
}
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
portENTER_CRITICAL();
|
||||
{
|
||||
|
|
@ -466,7 +474,7 @@ UBaseType_t uxValueToTx, ux, uxInterrupts;
|
|||
if( xQueueSend( xNormallyFullQueue, &uxValueToTx, intqSHORT_DELAY ) != pdPASS )
|
||||
{
|
||||
/* intqHIGH_PRIORITY_TASK2 is never suspended so we would not
|
||||
expect it to ever time out. */
|
||||
* expect it to ever time out. */
|
||||
prvQueueAccessLogError( __LINE__ );
|
||||
}
|
||||
|
||||
|
|
@ -477,7 +485,7 @@ UBaseType_t uxValueToTx, ux, uxInterrupts;
|
|||
if( uxValueToTx > ( intqNUM_VALUES_TO_LOG + intqVALUE_OVERRUN ) )
|
||||
{
|
||||
/* Make sure the other high priority task completes its send of
|
||||
any values below intqNUM_VALUE_TO_LOG. */
|
||||
* any values below intqNUM_VALUE_TO_LOG. */
|
||||
vTaskDelay( intqSHORT_DELAY );
|
||||
|
||||
vTaskSuspend( xHighPriorityNormallyFullTask2 );
|
||||
|
|
@ -485,12 +493,12 @@ UBaseType_t uxValueToTx, ux, uxInterrupts;
|
|||
if( xWasSuspended == pdTRUE )
|
||||
{
|
||||
/* We would have expected the other high priority task to have
|
||||
set this back to false by now. */
|
||||
* set this back to false by now. */
|
||||
prvQueueAccessLogError( __LINE__ );
|
||||
}
|
||||
|
||||
/* Set the suspended flag so an error is not logged if the other
|
||||
task recognises a time out when it is unsuspended. */
|
||||
* task recognises a time out when it is unsuspended. */
|
||||
xWasSuspended = pdTRUE;
|
||||
|
||||
/* Check interrupts are also sending. */
|
||||
|
|
@ -513,7 +521,7 @@ UBaseType_t uxValueToTx, ux, uxInterrupts;
|
|||
if( uxInterrupts == 0 )
|
||||
{
|
||||
/* No writes from interrupts were found. Are interrupts
|
||||
actually running? */
|
||||
* actually running? */
|
||||
prvQueueAccessLogError( __LINE__ );
|
||||
}
|
||||
|
||||
|
|
@ -524,11 +532,11 @@ UBaseType_t uxValueToTx, ux, uxInterrupts;
|
|||
uxValueForNormallyFullQueue = 0;
|
||||
|
||||
/* Suspend ourselves, allowing the lower priority task to
|
||||
actually receive something from the queue. Until now it
|
||||
will have been prevented from doing so by the higher
|
||||
priority tasks. The lower priority task will resume us
|
||||
if it receives something. We will then resume the other
|
||||
higher priority task. */
|
||||
* actually receive something from the queue. Until now it
|
||||
* will have been prevented from doing so by the higher
|
||||
* priority tasks. The lower priority task will resume us
|
||||
* if it receives something. We will then resume the other
|
||||
* higher priority task. */
|
||||
vTaskSuspend( NULL );
|
||||
vTaskResume( xHighPriorityNormallyFullTask2 );
|
||||
}
|
||||
|
|
@ -536,15 +544,15 @@ UBaseType_t uxValueToTx, ux, uxInterrupts;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prv2ndHigherPriorityNormallyFullTask( void *pvParameters )
|
||||
static void prv2ndHigherPriorityNormallyFullTask( void * pvParameters )
|
||||
{
|
||||
UBaseType_t uxValueToTx, ux;
|
||||
UBaseType_t uxValueToTx, ux;
|
||||
|
||||
/* The parameters are not being used so avoid compiler warnings. */
|
||||
( void ) pvParameters;
|
||||
|
||||
/* Make sure the queue starts full or near full. >> 1 as there are two
|
||||
high priority tasks. */
|
||||
* high priority tasks. */
|
||||
for( ux = 0; ux < ( intqQUEUE_LENGTH >> 1 ); ux++ )
|
||||
{
|
||||
portENTER_CRITICAL();
|
||||
|
|
@ -557,7 +565,7 @@ UBaseType_t uxValueToTx, ux;
|
|||
xQueueSend( xNormallyFullQueue, &uxValueToTx, intqSHORT_DELAY );
|
||||
}
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
portENTER_CRITICAL();
|
||||
{
|
||||
|
|
@ -582,14 +590,14 @@ UBaseType_t uxValueToTx, ux;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvLowerPriorityNormallyFullTask( void *pvParameters )
|
||||
static void prvLowerPriorityNormallyFullTask( void * pvParameters )
|
||||
{
|
||||
UBaseType_t uxValue, uxTxed = 9999;
|
||||
UBaseType_t uxValue, uxTxed = 9999;
|
||||
|
||||
/* The parameters are not being used so avoid compiler warnings. */
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
if( xQueueSend( xNormallyFullQueue, &uxTxed, intqONE_TICK_DELAY ) != errQUEUE_FULL )
|
||||
{
|
||||
|
|
@ -605,7 +613,7 @@ UBaseType_t uxValue, uxTxed = 9999;
|
|||
else
|
||||
{
|
||||
/* Raise our priority while we receive so we can preempt the higher
|
||||
priority task, and ensure we get the value from the queue. */
|
||||
* priority task, and ensure we get the value from the queue. */
|
||||
vTaskPrioritySet( NULL, intqHIGHER_PRIORITY + 1 );
|
||||
|
||||
if( xQueueReceive( xNormallyFullQueue, &uxValue, portMAX_DELAY ) != pdPASS )
|
||||
|
|
@ -625,12 +633,12 @@ UBaseType_t uxValue, uxTxed = 9999;
|
|||
|
||||
BaseType_t xFirstTimerHandler( void )
|
||||
{
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
UBaseType_t uxRxedValue;
|
||||
static UBaseType_t uxNextOperation = 0;
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
UBaseType_t uxRxedValue;
|
||||
static UBaseType_t uxNextOperation = 0;
|
||||
|
||||
/* Called from a timer interrupt. Perform various read and write
|
||||
accesses on the queues. */
|
||||
* accesses on the queues. */
|
||||
|
||||
uxNextOperation++;
|
||||
|
||||
|
|
@ -653,12 +661,12 @@ static UBaseType_t uxNextOperation = 0;
|
|||
|
||||
BaseType_t xSecondTimerHandler( void )
|
||||
{
|
||||
UBaseType_t uxRxedValue;
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
static UBaseType_t uxNextOperation = 0;
|
||||
UBaseType_t uxRxedValue;
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
static UBaseType_t uxNextOperation = 0;
|
||||
|
||||
/* Called from a timer interrupt. Perform various read and write
|
||||
accesses on the queues. */
|
||||
* accesses on the queues. */
|
||||
|
||||
uxNextOperation++;
|
||||
|
||||
|
|
@ -685,10 +693,10 @@ static UBaseType_t uxNextOperation = 0;
|
|||
|
||||
BaseType_t xAreIntQueueTasksStillRunning( void )
|
||||
{
|
||||
static UBaseType_t uxLastHighPriorityLoops1 = 0, uxLastHighPriorityLoops2 = 0, uxLastLowPriorityLoops1 = 0, uxLastLowPriorityLoops2 = 0;
|
||||
static UBaseType_t uxLastHighPriorityLoops1 = 0, uxLastHighPriorityLoops2 = 0, uxLastLowPriorityLoops1 = 0, uxLastLowPriorityLoops2 = 0;
|
||||
|
||||
/* xErrorStatus can be set outside of this function. This function just
|
||||
checks that all the tasks are still cycling. */
|
||||
* checks that all the tasks are still cycling. */
|
||||
|
||||
if( uxHighPriorityLoops1 == uxLastHighPriorityLoops1 )
|
||||
{
|
||||
|
|
@ -724,4 +732,3 @@ static UBaseType_t uxLastHighPriorityLoops1 = 0, uxLastHighPriorityLoops2 = 0, u
|
|||
|
||||
return xErrorStatus;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@
|
|||
#define intsemNO_BLOCK 0
|
||||
|
||||
/* The maximum count value for the counting semaphore given from an
|
||||
interrupt. */
|
||||
* interrupt. */
|
||||
#define intsemMAX_COUNT 3
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
|
@ -69,8 +69,8 @@ interrupt. */
|
|||
* on a mutex that is shared between the master and the slave - which is a
|
||||
* separate mutex to that given by the interrupt.
|
||||
*/
|
||||
static void vInterruptMutexSlaveTask( void *pvParameters );
|
||||
static void vInterruptMutexMasterTask( void *pvParameters );
|
||||
static void vInterruptMutexSlaveTask( void * pvParameters );
|
||||
static void vInterruptMutexMasterTask( void * pvParameters );
|
||||
|
||||
/*
|
||||
* A test whereby the master takes the shared and interrupt mutexes in that
|
||||
|
|
@ -90,37 +90,37 @@ static void prvTakeAndGiveInTheOppositeOrder( void );
|
|||
* A simple task that interacts with an interrupt using a counting semaphore,
|
||||
* primarily for code coverage purposes.
|
||||
*/
|
||||
static void vInterruptCountingSemaphoreTask( void *pvParameters );
|
||||
static void vInterruptCountingSemaphoreTask( void * pvParameters );
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Flag that will be latched to pdTRUE should any unexpected behaviour be
|
||||
detected in any of the tasks. */
|
||||
* detected in any of the tasks. */
|
||||
static volatile BaseType_t xErrorDetected = pdFALSE;
|
||||
|
||||
/* Counters that are incremented on each cycle of a test. This is used to
|
||||
detect a stalled task - a test that is no longer running. */
|
||||
* detect a stalled task - a test that is no longer running. */
|
||||
static volatile uint32_t ulMasterLoops = 0, ulCountingSemaphoreLoops = 0;
|
||||
|
||||
/* Handles of the test tasks that must be accessed from other test tasks. */
|
||||
static TaskHandle_t xSlaveHandle;
|
||||
|
||||
/* A mutex which is given from an interrupt - although generally mutexes should
|
||||
not be used given in interrupts (and definitely never taken in an interrupt)
|
||||
there are some circumstances when it may be desirable. */
|
||||
* not be used given in interrupts (and definitely never taken in an interrupt)
|
||||
* there are some circumstances when it may be desirable. */
|
||||
static SemaphoreHandle_t xISRMutex = NULL;
|
||||
|
||||
/* A counting semaphore which is given from an interrupt. */
|
||||
static SemaphoreHandle_t xISRCountingSemaphore = NULL;
|
||||
|
||||
/* A mutex which is shared between the master and slave tasks - the master
|
||||
does both sharing of this mutex with the slave and receiving a mutex from the
|
||||
interrupt. */
|
||||
* does both sharing of this mutex with the slave and receiving a mutex from the
|
||||
* interrupt. */
|
||||
static SemaphoreHandle_t xMasterSlaveMutex = NULL;
|
||||
|
||||
/* Flag that allows the master task to control when the interrupt gives or does
|
||||
not give the mutex. There is no mutual exclusion on this variable, but this is
|
||||
only test code and it should be fine in the 32=bit test environment. */
|
||||
* not give the mutex. There is no mutual exclusion on this variable, but this is
|
||||
* only test code and it should be fine in the 32=bit test environment. */
|
||||
static BaseType_t xOkToGiveMutex = pdFALSE, xOkToGiveCountingSemaphore = pdFALSE;
|
||||
|
||||
/* Used to coordinate timing between tasks and the interrupt. */
|
||||
|
|
@ -137,8 +137,8 @@ void vStartInterruptSemaphoreTasks( void )
|
|||
configASSERT( xISRCountingSemaphore );
|
||||
|
||||
/* Create the mutex that is shared between the master and slave tasks (the
|
||||
master receives a mutex from an interrupt and shares a mutex with the
|
||||
slave. */
|
||||
* master receives a mutex from an interrupt and shares a mutex with the
|
||||
* slave. */
|
||||
xMasterSlaveMutex = xSemaphoreCreateMutex();
|
||||
configASSERT( xMasterSlaveMutex );
|
||||
|
||||
|
|
@ -151,12 +151,12 @@ void vStartInterruptSemaphoreTasks( void )
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vInterruptMutexMasterTask( void *pvParameters )
|
||||
static void vInterruptMutexMasterTask( void * pvParameters )
|
||||
{
|
||||
/* Just to avoid compiler warnings. */
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
prvTakeAndGiveInTheSameOrder();
|
||||
|
||||
|
|
@ -176,8 +176,8 @@ static void vInterruptMutexMasterTask( void *pvParameters )
|
|||
static void prvTakeAndGiveInTheSameOrder( void )
|
||||
{
|
||||
/* Ensure the slave is suspended, and that this task is running at the
|
||||
lower priority as expected as the start conditions. */
|
||||
#if( INCLUDE_eTaskGetState == 1 )
|
||||
* lower priority as expected as the start conditions. */
|
||||
#if ( INCLUDE_eTaskGetState == 1 )
|
||||
{
|
||||
configASSERT( eTaskGetState( xSlaveHandle ) == eSuspended );
|
||||
}
|
||||
|
|
@ -195,35 +195,37 @@ static void prvTakeAndGiveInTheSameOrder( void )
|
|||
}
|
||||
|
||||
/* This task now has the mutex. Unsuspend the slave so it too
|
||||
attempts to take the mutex. */
|
||||
* attempts to take the mutex. */
|
||||
vTaskResume( xSlaveHandle );
|
||||
|
||||
/* The slave has the higher priority so should now have executed and
|
||||
blocked on the semaphore. */
|
||||
#if( INCLUDE_eTaskGetState == 1 )
|
||||
* blocked on the semaphore. */
|
||||
#if ( INCLUDE_eTaskGetState == 1 )
|
||||
{
|
||||
configASSERT( eTaskGetState( xSlaveHandle ) == eBlocked );
|
||||
}
|
||||
#endif /* INCLUDE_eTaskGetState */
|
||||
|
||||
/* This task should now have inherited the priority of the slave
|
||||
task. */
|
||||
* task. */
|
||||
if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
/* Now wait a little longer than the time between ISR gives to also
|
||||
obtain the ISR mutex. */
|
||||
* obtain the ISR mutex. */
|
||||
xOkToGiveMutex = pdTRUE;
|
||||
|
||||
if( xSemaphoreTake( xISRMutex, ( xInterruptGivePeriod * 2 ) ) != pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
xOkToGiveMutex = pdFALSE;
|
||||
|
||||
/* Attempting to take again immediately should fail as the mutex is
|
||||
already held. */
|
||||
* already held. */
|
||||
if( xSemaphoreTake( xISRMutex, intsemNO_BLOCK ) != pdFAIL )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -236,8 +238,8 @@ static void prvTakeAndGiveInTheSameOrder( void )
|
|||
}
|
||||
|
||||
/* Give back the ISR semaphore to ensure the priority is not
|
||||
disinherited as the shared mutex (which the higher priority task is
|
||||
attempting to obtain) is still held. */
|
||||
* disinherited as the shared mutex (which the higher priority task is
|
||||
* attempting to obtain) is still held. */
|
||||
if( xSemaphoreGive( xISRMutex ) != pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -249,9 +251,9 @@ static void prvTakeAndGiveInTheSameOrder( void )
|
|||
}
|
||||
|
||||
/* Finally give back the shared mutex. This time the higher priority
|
||||
task should run before this task runs again - so this task should have
|
||||
disinherited the priority and the higher priority task should be in the
|
||||
suspended state again. */
|
||||
* task should run before this task runs again - so this task should have
|
||||
* disinherited the priority and the higher priority task should be in the
|
||||
* suspended state again. */
|
||||
if( xSemaphoreGive( xMasterSlaveMutex ) != pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -262,7 +264,7 @@ static void prvTakeAndGiveInTheSameOrder( void )
|
|||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
#if( INCLUDE_eTaskGetState == 1 )
|
||||
#if ( INCLUDE_eTaskGetState == 1 )
|
||||
{
|
||||
configASSERT( eTaskGetState( xSlaveHandle ) == eSuspended );
|
||||
}
|
||||
|
|
@ -276,8 +278,8 @@ static void prvTakeAndGiveInTheSameOrder( void )
|
|||
static void prvTakeAndGiveInTheOppositeOrder( void )
|
||||
{
|
||||
/* Ensure the slave is suspended, and that this task is running at the
|
||||
lower priority as expected as the start conditions. */
|
||||
#if( INCLUDE_eTaskGetState == 1 )
|
||||
* lower priority as expected as the start conditions. */
|
||||
#if ( INCLUDE_eTaskGetState == 1 )
|
||||
{
|
||||
configASSERT( eTaskGetState( xSlaveHandle ) == eSuspended );
|
||||
}
|
||||
|
|
@ -295,35 +297,37 @@ static void prvTakeAndGiveInTheOppositeOrder( void )
|
|||
}
|
||||
|
||||
/* This task now has the mutex. Unsuspend the slave so it too
|
||||
attempts to take the mutex. */
|
||||
* attempts to take the mutex. */
|
||||
vTaskResume( xSlaveHandle );
|
||||
|
||||
/* The slave has the higher priority so should now have executed and
|
||||
blocked on the semaphore. */
|
||||
#if( INCLUDE_eTaskGetState == 1 )
|
||||
* blocked on the semaphore. */
|
||||
#if ( INCLUDE_eTaskGetState == 1 )
|
||||
{
|
||||
configASSERT( eTaskGetState( xSlaveHandle ) == eBlocked );
|
||||
}
|
||||
#endif /* INCLUDE_eTaskGetState */
|
||||
|
||||
/* This task should now have inherited the priority of the slave
|
||||
task. */
|
||||
* task. */
|
||||
if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
/* Now wait a little longer than the time between ISR gives to also
|
||||
obtain the ISR mutex. */
|
||||
* obtain the ISR mutex. */
|
||||
xOkToGiveMutex = pdTRUE;
|
||||
|
||||
if( xSemaphoreTake( xISRMutex, ( xInterruptGivePeriod * 2 ) ) != pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
xOkToGiveMutex = pdFALSE;
|
||||
|
||||
/* Attempting to take again immediately should fail as the mutex is
|
||||
already held. */
|
||||
* already held. */
|
||||
if( xSemaphoreTake( xISRMutex, intsemNO_BLOCK ) != pdFAIL )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -336,23 +340,23 @@ static void prvTakeAndGiveInTheOppositeOrder( void )
|
|||
}
|
||||
|
||||
/* Give back the shared semaphore to ensure the priority is not disinherited
|
||||
as the ISR mutex is still held. The higher priority slave task should run
|
||||
before this task runs again. */
|
||||
* as the ISR mutex is still held. The higher priority slave task should run
|
||||
* before this task runs again. */
|
||||
if( xSemaphoreGive( xMasterSlaveMutex ) != pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
/* Should still be at the priority of the slave task as this task still
|
||||
holds one semaphore (this is a simplification in the priority inheritance
|
||||
mechanism. */
|
||||
* holds one semaphore (this is a simplification in the priority inheritance
|
||||
* mechanism. */
|
||||
if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
/* Give back the ISR semaphore, which should result in the priority being
|
||||
disinherited as it was the last mutex held. */
|
||||
* disinherited as it was the last mutex held. */
|
||||
if( xSemaphoreGive( xISRMutex ) != pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -368,20 +372,20 @@ static void prvTakeAndGiveInTheOppositeOrder( void )
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vInterruptMutexSlaveTask( void *pvParameters )
|
||||
static void vInterruptMutexSlaveTask( void * pvParameters )
|
||||
{
|
||||
/* Just to avoid compiler warnings. */
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* This task starts by suspending itself so when it executes can be
|
||||
controlled by the master task. */
|
||||
* controlled by the master task. */
|
||||
vTaskSuspend( NULL );
|
||||
|
||||
/* This task will execute when the master task already holds the mutex.
|
||||
Attempting to take the mutex will place this task in the Blocked
|
||||
state. */
|
||||
* Attempting to take the mutex will place this task in the Blocked
|
||||
* state. */
|
||||
if( xSemaphoreTake( xMasterSlaveMutex, portMAX_DELAY ) != pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -395,14 +399,14 @@ static void vInterruptMutexSlaveTask( void *pvParameters )
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vInterruptCountingSemaphoreTask( void *pvParameters )
|
||||
static void vInterruptCountingSemaphoreTask( void * pvParameters )
|
||||
{
|
||||
BaseType_t xCount;
|
||||
const TickType_t xDelay = pdMS_TO_TICKS( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS ) * ( intsemMAX_COUNT + 1 );
|
||||
BaseType_t xCount;
|
||||
const TickType_t xDelay = pdMS_TO_TICKS( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS ) * ( intsemMAX_COUNT + 1 );
|
||||
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Expect to start with the counting semaphore empty. */
|
||||
if( uxQueueMessagesWaiting( ( QueueHandle_t ) xISRCountingSemaphore ) != 0 )
|
||||
|
|
@ -411,7 +415,7 @@ const TickType_t xDelay = pdMS_TO_TICKS( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS )
|
|||
}
|
||||
|
||||
/* Wait until it is expected that the interrupt will have filled the
|
||||
counting semaphore. */
|
||||
* counting semaphore. */
|
||||
xOkToGiveCountingSemaphore = pdTRUE;
|
||||
vTaskDelay( xDelay );
|
||||
xOkToGiveCountingSemaphore = pdFALSE;
|
||||
|
|
@ -430,9 +434,10 @@ const TickType_t xDelay = pdMS_TO_TICKS( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS )
|
|||
ulCountingSemaphoreLoops++;
|
||||
|
||||
/* Expect to be able to take the counting semaphore intsemMAX_COUNT
|
||||
times. A block time of 0 is used as the semaphore should already be
|
||||
there. */
|
||||
* times. A block time of 0 is used as the semaphore should already be
|
||||
* there. */
|
||||
xCount = 0;
|
||||
|
||||
while( xSemaphoreTake( xISRCountingSemaphore, 0 ) == pdPASS )
|
||||
{
|
||||
xCount++;
|
||||
|
|
@ -444,7 +449,7 @@ const TickType_t xDelay = pdMS_TO_TICKS( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS )
|
|||
}
|
||||
|
||||
/* Now raise the priority of this task so it runs immediately that the
|
||||
semaphore is given from the interrupt. */
|
||||
* semaphore is given from the interrupt. */
|
||||
vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );
|
||||
|
||||
/* Block to wait for the semaphore to be given from the interrupt. */
|
||||
|
|
@ -463,20 +468,22 @@ const TickType_t xDelay = pdMS_TO_TICKS( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS )
|
|||
|
||||
void vInterruptSemaphorePeriodicTest( void )
|
||||
{
|
||||
static TickType_t xLastGiveTime = 0;
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
TickType_t xTimeNow;
|
||||
static TickType_t xLastGiveTime = 0;
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
TickType_t xTimeNow;
|
||||
|
||||
/* No mutual exclusion on xOkToGiveMutex, but this is only test code (and
|
||||
only executed on a 32-bit architecture) so ignore that in this case. */
|
||||
* only executed on a 32-bit architecture) so ignore that in this case. */
|
||||
xTimeNow = xTaskGetTickCountFromISR();
|
||||
|
||||
if( ( ( TickType_t ) ( xTimeNow - xLastGiveTime ) ) >= pdMS_TO_TICKS( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS ) )
|
||||
{
|
||||
configASSERT( xISRMutex );
|
||||
|
||||
if( xOkToGiveMutex != pdFALSE )
|
||||
{
|
||||
/* Null is used as the second parameter in this give, and non-NULL
|
||||
in the other gives for code coverage reasons. */
|
||||
* in the other gives for code coverage reasons. */
|
||||
xSemaphoreGiveFromISR( xISRMutex, NULL );
|
||||
|
||||
/* Second give attempt should fail. */
|
||||
|
|
@ -487,6 +494,7 @@ TickType_t xTimeNow;
|
|||
{
|
||||
xSemaphoreGiveFromISR( xISRCountingSemaphore, &xHigherPriorityTaskWoken );
|
||||
}
|
||||
|
||||
xLastGiveTime = xTimeNow;
|
||||
}
|
||||
|
||||
|
|
@ -498,10 +506,10 @@ TickType_t xTimeNow;
|
|||
/* This is called to check that all the created tasks are still running. */
|
||||
BaseType_t xAreInterruptSemaphoreTasksStillRunning( void )
|
||||
{
|
||||
static uint32_t ulLastMasterLoopCounter = 0, ulLastCountingSemaphoreLoops = 0;
|
||||
static uint32_t ulLastMasterLoopCounter = 0, ulLastCountingSemaphoreLoops = 0;
|
||||
|
||||
/* If the demo tasks are running then it is expected that the loop counters
|
||||
will have changed since this function was last called. */
|
||||
* will have changed since this function was last called. */
|
||||
if( ulLastMasterLoopCounter == ulMasterLoops )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -517,9 +525,7 @@ static uint32_t ulLastMasterLoopCounter = 0, ulLastCountingSemaphoreLoops = 0;
|
|||
ulLastCountingSemaphoreLoops = ulCountingSemaphoreLoops++;
|
||||
|
||||
/* Errors detected in the task itself will have latched xErrorDetected
|
||||
to true. */
|
||||
* to true. */
|
||||
|
||||
return ( BaseType_t ) !xErrorDetected;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -68,11 +68,11 @@
|
|||
#include "MessageBufferAMP.h"
|
||||
|
||||
/* Enough for 3 4 byte pointers, including the additional 4 bytes per message
|
||||
overhead of message buffers. */
|
||||
* overhead of message buffers. */
|
||||
#define mbaCONTROL_MESSAGE_BUFFER_SIZE ( 24 )
|
||||
|
||||
/* Enough four 4 8 byte strings, plus the additional 4 bytes per message
|
||||
overhead of message buffers. */
|
||||
* overhead of message buffers. */
|
||||
#define mbaTASK_MESSAGE_BUFFER_SIZE ( 60 )
|
||||
|
||||
/* The number of instances of prvCoreBTasks that are created. */
|
||||
|
|
@ -82,7 +82,7 @@ overhead of message buffers. */
|
|||
#define mbaDONT_BLOCK 0
|
||||
|
||||
/* Macro that mimics an interrupt service routine executing by simply calling
|
||||
the routine inline. */
|
||||
* the routine inline. */
|
||||
#define mbaGENERATE_CORE_B_INTERRUPT() prvCoreBInterruptHandler()
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
|
@ -91,14 +91,14 @@ the routine inline. */
|
|||
* Implementation of the task that, on a real dual core device, would run on
|
||||
* core A and send message to tasks running on core B.
|
||||
*/
|
||||
static void prvCoreATask( void *pvParameters );
|
||||
static void prvCoreATask( void * pvParameters );
|
||||
|
||||
/*
|
||||
* Implementation of the task that, on a real dual core device, would run on
|
||||
* core B and receive message from core A. The demo creates two instances of
|
||||
* this task.
|
||||
*/
|
||||
static void prvCoreBTasks( void *pvParameters );
|
||||
static void prvCoreBTasks( void * pvParameters );
|
||||
|
||||
/*
|
||||
* The function that, on a real dual core device, would handle inter-core
|
||||
|
|
@ -112,22 +112,22 @@ static void prvCoreBInterruptHandler( void );
|
|||
static MessageBufferHandle_t xCoreBMessageBuffers[ mbaNUMBER_OF_CORE_B_TASKS ];
|
||||
|
||||
/* The control message buffer. This is used to pass the handle of the message
|
||||
message buffer that holds application data into the core to core interrupt
|
||||
service routine. */
|
||||
* message buffer that holds application data into the core to core interrupt
|
||||
* service routine. */
|
||||
static MessageBufferHandle_t xControlMessageBuffer;
|
||||
|
||||
/* Counters used to indicate to the check that the tasks are still executing. */
|
||||
static uint32_t ulCycleCounters[ mbaNUMBER_OF_CORE_B_TASKS ];
|
||||
|
||||
/* Set to pdFALSE if any errors are detected. Used to inform the check task
|
||||
that something might be wrong. */
|
||||
* that something might be wrong. */
|
||||
BaseType_t xDemoStatus = pdPASS;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vStartMessageBufferAMPTasks( configSTACK_DEPTH_TYPE xStackSize )
|
||||
{
|
||||
BaseType_t x;
|
||||
BaseType_t x;
|
||||
|
||||
xControlMessageBuffer = xMessageBufferCreate( mbaCONTROL_MESSAGE_BUFFER_SIZE );
|
||||
|
||||
|
|
@ -144,8 +144,8 @@ BaseType_t x;
|
|||
configASSERT( xCoreBMessageBuffers[ x ] );
|
||||
|
||||
/* Pass the loop counter into the created task using the task's
|
||||
parameter. The task then uses the value as an index into the
|
||||
ulCycleCounters and xCoreBMessageBuffers arrays. */
|
||||
* parameter. The task then uses the value as an index into the
|
||||
* ulCycleCounters and xCoreBMessageBuffers arrays. */
|
||||
xTaskCreate( prvCoreBTasks,
|
||||
"AMPCoreB1",
|
||||
xStackSize,
|
||||
|
|
@ -156,28 +156,28 @@ BaseType_t x;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvCoreATask( void *pvParameters )
|
||||
static void prvCoreATask( void * pvParameters )
|
||||
{
|
||||
BaseType_t x;
|
||||
uint32_t ulNextValue = 0;
|
||||
const TickType_t xDelay = pdMS_TO_TICKS( 250 );
|
||||
char cString[ 15 ]; /* At least large enough to hold "4294967295\0" (0xffffffff). */
|
||||
BaseType_t x;
|
||||
uint32_t ulNextValue = 0;
|
||||
const TickType_t xDelay = pdMS_TO_TICKS( 250 );
|
||||
char cString[ 15 ]; /* At least large enough to hold "4294967295\0" (0xffffffff). */
|
||||
|
||||
/* Remove warning about unused parameters. */
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Create the next string to send. The value is incremented on each
|
||||
loop iteration, and the length of the string changes as the number of
|
||||
digits in the value increases. */
|
||||
* loop iteration, and the length of the string changes as the number of
|
||||
* digits in the value increases. */
|
||||
sprintf( cString, "%lu", ( unsigned long ) ulNextValue );
|
||||
|
||||
/* Send the value from this (pseudo) Core A to the tasks on the (pseudo)
|
||||
Core B via the message buffers. This will result in sbSEND_COMPLETED()
|
||||
being executed, which in turn will write the handle of the message
|
||||
buffer written to into xControlMessageBuffer then generate an interrupt
|
||||
in core B. */
|
||||
* Core B via the message buffers. This will result in sbSEND_COMPLETED()
|
||||
* being executed, which in turn will write the handle of the message
|
||||
* buffer written to into xControlMessageBuffer then generate an interrupt
|
||||
* in core B. */
|
||||
for( x = 0; x < mbaNUMBER_OF_CORE_B_TASKS; x++ )
|
||||
{
|
||||
xMessageBufferSend( /* The message buffer to write to. */
|
||||
|
|
@ -191,27 +191,27 @@ char cString[ 15 ]; /* At least large enough to hold "4294967295\0" (0xffffffff)
|
|||
}
|
||||
|
||||
/* Delay before repeating with a different and potentially different
|
||||
length string. */
|
||||
* length string. */
|
||||
vTaskDelay( xDelay );
|
||||
ulNextValue++;
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvCoreBTasks( void *pvParameters )
|
||||
static void prvCoreBTasks( void * pvParameters )
|
||||
{
|
||||
BaseType_t x;
|
||||
size_t xReceivedBytes;
|
||||
uint32_t ulNextValue = 0;
|
||||
char cExpectedString[ 15 ]; /* At least large enough to hold "4294967295\0" (0xffffffff). */
|
||||
char cReceivedString[ 15 ];
|
||||
BaseType_t x;
|
||||
size_t xReceivedBytes;
|
||||
uint32_t ulNextValue = 0;
|
||||
char cExpectedString[ 15 ]; /* At least large enough to hold "4294967295\0" (0xffffffff). */
|
||||
char cReceivedString[ 15 ];
|
||||
|
||||
/* The index into the xCoreBMessageBuffers and ulLoopCounter arrays is
|
||||
passed into this task using the task's parameter. */
|
||||
* passed into this task using the task's parameter. */
|
||||
x = ( BaseType_t ) pvParameters;
|
||||
configASSERT( x < mbaNUMBER_OF_CORE_B_TASKS );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Create the string that is expected to be received this time round. */
|
||||
sprintf( cExpectedString, "%lu", ( unsigned long ) ulNextValue );
|
||||
|
|
@ -232,7 +232,7 @@ char cReceivedString[ 15 ];
|
|||
( void ) xReceivedBytes; /* Incase configASSERT() is not defined. */
|
||||
|
||||
/* If the received string matches that expected then increment the loop
|
||||
counter so the check task knows this task is still running. */
|
||||
* counter so the check task knows this task is still running. */
|
||||
if( strcmp( cReceivedString, cExpectedString ) == 0 )
|
||||
{
|
||||
( ulCycleCounters[ x ] )++;
|
||||
|
|
@ -249,69 +249,69 @@ char cReceivedString[ 15 ];
|
|||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Called by the reimplementation of sbSEND_COMPLETED(), which can be defined
|
||||
as follows in FreeRTOSConfig.h:
|
||||
#define sbSEND_COMPLETED( pxStreamBuffer ) vGenerateCoreBInterrupt( pxStreamBuffer )
|
||||
*/
|
||||
* as follows in FreeRTOSConfig.h:
|
||||
#define sbSEND_COMPLETED( pxStreamBuffer ) vGenerateCoreBInterrupt( pxStreamBuffer )
|
||||
*/
|
||||
void vGenerateCoreBInterrupt( void * xUpdatedMessageBuffer )
|
||||
{
|
||||
MessageBufferHandle_t xUpdatedBuffer = ( MessageBufferHandle_t ) xUpdatedMessageBuffer;
|
||||
MessageBufferHandle_t xUpdatedBuffer = ( MessageBufferHandle_t ) xUpdatedMessageBuffer;
|
||||
|
||||
/* If sbSEND_COMPLETED() has been implemented as above, then this function
|
||||
is called from within xMessageBufferSend(). As this function also calls
|
||||
xMessageBufferSend() itself it is necessary to guard against a recursive
|
||||
call. If the message buffer just updated is the message buffer written to
|
||||
by this function, then this is a recursive call, and the function can just
|
||||
exit without taking further action. */
|
||||
* is called from within xMessageBufferSend(). As this function also calls
|
||||
* xMessageBufferSend() itself it is necessary to guard against a recursive
|
||||
* call. If the message buffer just updated is the message buffer written to
|
||||
* by this function, then this is a recursive call, and the function can just
|
||||
* exit without taking further action. */
|
||||
if( xUpdatedBuffer != xControlMessageBuffer )
|
||||
{
|
||||
/* Use xControlMessageBuffer to pass the handle of the message buffer
|
||||
written to by core A to the interrupt handler about to be generated in
|
||||
core B. */
|
||||
* written to by core A to the interrupt handler about to be generated in
|
||||
* core B. */
|
||||
xMessageBufferSend( xControlMessageBuffer, &xUpdatedBuffer, sizeof( xUpdatedBuffer ), mbaDONT_BLOCK );
|
||||
|
||||
/* This is where the interrupt would be generated. In this case it is
|
||||
not a genuine interrupt handler that executes, just a standard function
|
||||
call. */
|
||||
* not a genuine interrupt handler that executes, just a standard function
|
||||
* call. */
|
||||
mbaGENERATE_CORE_B_INTERRUPT();
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Handler for the interrupts that are triggered on core A but execute on core
|
||||
B. */
|
||||
* B. */
|
||||
static void prvCoreBInterruptHandler( void )
|
||||
{
|
||||
MessageBufferHandle_t xUpdatedMessageBuffer;
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
MessageBufferHandle_t xUpdatedMessageBuffer;
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
|
||||
/* xControlMessageBuffer contains the handle of the message buffer that
|
||||
contains data. */
|
||||
* contains data. */
|
||||
if( xMessageBufferReceive( xControlMessageBuffer,
|
||||
&xUpdatedMessageBuffer,
|
||||
sizeof( xUpdatedMessageBuffer ),
|
||||
mbaDONT_BLOCK ) == sizeof( xUpdatedMessageBuffer ) )
|
||||
{
|
||||
/* Call the API function that sends a notification to any task that is
|
||||
blocked on the xUpdatedMessageBuffer message buffer waiting for data to
|
||||
arrive. */
|
||||
* blocked on the xUpdatedMessageBuffer message buffer waiting for data to
|
||||
* arrive. */
|
||||
xMessageBufferSendCompletedFromISR( xUpdatedMessageBuffer, &xHigherPriorityTaskWoken );
|
||||
}
|
||||
|
||||
/* Normal FreeRTOS yield from interrupt semantics, where
|
||||
xHigherPriorityTaskWoken is initialized to pdFALSE and will then get set to
|
||||
pdTRUE if the interrupt safe API unblocks a task that has a priority above
|
||||
that of the currently executing task. */
|
||||
* xHigherPriorityTaskWoken is initialized to pdFALSE and will then get set to
|
||||
* pdTRUE if the interrupt safe API unblocks a task that has a priority above
|
||||
* that of the currently executing task. */
|
||||
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
BaseType_t xAreMessageBufferAMPTasksStillRunning( void )
|
||||
{
|
||||
static uint32_t ulLastCycleCounters[ mbaNUMBER_OF_CORE_B_TASKS ] = { 0 };
|
||||
BaseType_t x;
|
||||
static uint32_t ulLastCycleCounters[ mbaNUMBER_OF_CORE_B_TASKS ] = { 0 };
|
||||
BaseType_t x;
|
||||
|
||||
/* Called by the check task to determine the health status of the tasks
|
||||
implemented in this demo. */
|
||||
* implemented in this demo. */
|
||||
for( x = 0; x < mbaNUMBER_OF_CORE_B_TASKS; x++ )
|
||||
{
|
||||
if( ulLastCycleCounters[ x ] == ulCycleCounters[ x ] )
|
||||
|
|
@ -326,4 +326,3 @@ BaseType_t x;
|
|||
|
||||
return xDemoStatus;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@
|
|||
#define mbNUMBER_OF_SENDER_TASKS ( 2 )
|
||||
|
||||
/* Priority of the test tasks. The send and receive go from low to high
|
||||
priority tasks, and from high to low priority tasks. */
|
||||
* priority tasks, and from high to low priority tasks. */
|
||||
#define mbLOWER_PRIORITY ( tskIDLE_PRIORITY )
|
||||
#define mbHIGHER_PRIORITY ( tskIDLE_PRIORITY + 1 )
|
||||
|
||||
|
|
@ -75,23 +75,24 @@ static void prvSingleTaskTests( MessageBufferHandle_t xMessageBuffer );
|
|||
* message back to the echo client which, checks it receives exactly what it
|
||||
* sent.
|
||||
*/
|
||||
static void prvEchoClient( void *pvParameters );
|
||||
static void prvEchoServer( void *pvParameters );
|
||||
static void prvEchoClient( void * pvParameters );
|
||||
static void prvEchoServer( void * pvParameters );
|
||||
|
||||
/*
|
||||
* Tasks that send and receive to a message buffer at a low priority and without
|
||||
* blocking, so the send and receive functions interleave in time as the tasks
|
||||
* are switched in and out.
|
||||
*/
|
||||
static void prvNonBlockingReceiverTask( void *pvParameters );
|
||||
static void prvNonBlockingSenderTask( void *pvParameters );
|
||||
static void prvNonBlockingReceiverTask( void * pvParameters );
|
||||
static void prvNonBlockingSenderTask( void * pvParameters );
|
||||
|
||||
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
/* This file tests both statically and dynamically allocated message buffers.
|
||||
Allocate the structures and buffers to be used by the statically allocated
|
||||
objects, which get used in the echo tests. */
|
||||
static void prvReceiverTask( void *pvParameters );
|
||||
static void prvSenderTask( void *pvParameters );
|
||||
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
|
||||
/* This file tests both statically and dynamically allocated message buffers.
|
||||
* Allocate the structures and buffers to be used by the statically allocated
|
||||
* objects, which get used in the echo tests. */
|
||||
static void prvReceiverTask( void * pvParameters );
|
||||
static void prvSenderTask( void * pvParameters );
|
||||
|
||||
static StaticMessageBuffer_t xStaticMessageBuffers[ mbNUMBER_OF_ECHO_CLIENTS ];
|
||||
static uint8_t ucBufferStorage[ mbNUMBER_OF_SENDER_TASKS ][ mbMESSAGE_BUFFER_LENGTH_BYTES + 1 ];
|
||||
|
|
@ -99,18 +100,18 @@ static void prvNonBlockingSenderTask( void *pvParameters );
|
|||
#endif /* configSUPPORT_STATIC_ALLOCATION */
|
||||
|
||||
|
||||
#if( configRUN_ADDITIONAL_TESTS == 1 )
|
||||
#if ( configRUN_ADDITIONAL_TESTS == 1 )
|
||||
#define mbCOHERENCE_TEST_BUFFER_SIZE 20
|
||||
#define mbCOHERENCE_TEST_BYTES_WRITTEN 5
|
||||
#define mbBYTES_TO_STORE_MESSAGE_LENGTH ( sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ) )
|
||||
#define mbEXPECTED_FREE_BYTES_AFTER_WRITING_STRING ( mbCOHERENCE_TEST_BUFFER_SIZE - ( mbCOHERENCE_TEST_BYTES_WRITTEN + mbBYTES_TO_STORE_MESSAGE_LENGTH ) )
|
||||
|
||||
static void prvSpaceAvailableCoherenceActor( void *pvParameters );
|
||||
static void prvSpaceAvailableCoherenceTester( void *pvParameters );
|
||||
static void prvSpaceAvailableCoherenceActor( void * pvParameters );
|
||||
static void prvSpaceAvailableCoherenceTester( void * pvParameters );
|
||||
static MessageBufferHandle_t xCoherenceTestMessageBuffer = NULL;
|
||||
|
||||
static uint32_t ulSizeCoherencyTestCycles = 0UL;
|
||||
#endif
|
||||
#endif /* if ( configRUN_ADDITIONAL_TESTS == 1 ) */
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
|
|
@ -124,55 +125,55 @@ typedef struct ECHO_MESSAGE_BUFFERS
|
|||
static uint32_t ulEchoLoopCounters[ mbNUMBER_OF_ECHO_CLIENTS ] = { 0 };
|
||||
|
||||
/* The non-blocking tasks monitor their operation, and if no errors have been
|
||||
found, increment ulNonBlockingRxCounter. xAreMessageBufferTasksStillRunning()
|
||||
then checks ulNonBlockingRxCounter and only returns pdPASS if
|
||||
ulNonBlockingRxCounter is still incrementing. */
|
||||
* found, increment ulNonBlockingRxCounter. xAreMessageBufferTasksStillRunning()
|
||||
* then checks ulNonBlockingRxCounter and only returns pdPASS if
|
||||
* ulNonBlockingRxCounter is still incrementing. */
|
||||
static uint32_t ulNonBlockingRxCounter = 0;
|
||||
|
||||
/* A message that is longer than the buffer, parts of which are written to the
|
||||
message buffer to test writing different lengths at different offsets. */
|
||||
static const char *pc55ByteString = "One two three four five six seven eight nine ten eleve";
|
||||
* message buffer to test writing different lengths at different offsets. */
|
||||
static const char * pc55ByteString = "One two three four five six seven eight nine ten eleve";
|
||||
|
||||
/* Remember the required stack size so tasks can be created at run time (after
|
||||
initialisation time. */
|
||||
* initialisation time. */
|
||||
static configSTACK_DEPTH_TYPE xBlockingStackSize = 0;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vStartMessageBufferTasks( configSTACK_DEPTH_TYPE xStackSize )
|
||||
{
|
||||
MessageBufferHandle_t xMessageBuffer;
|
||||
MessageBufferHandle_t xMessageBuffer;
|
||||
|
||||
#ifndef configMESSAGE_BUFFER_BLOCK_TASK_STACK_SIZE
|
||||
#ifndef configMESSAGE_BUFFER_BLOCK_TASK_STACK_SIZE
|
||||
xBlockingStackSize = ( xStackSize + ( xStackSize >> 1U ) );
|
||||
#else
|
||||
#else
|
||||
xBlockingStackSize = configMESSAGE_BUFFER_BLOCK_TASK_STACK_SIZE;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* The echo servers sets up the message buffers before creating the echo
|
||||
client tasks. One set of tasks has the server as the higher priority, and
|
||||
the other has the client as the higher priority. */
|
||||
* client tasks. One set of tasks has the server as the higher priority, and
|
||||
* the other has the client as the higher priority. */
|
||||
xTaskCreate( prvEchoServer, "1EchoServer", xBlockingStackSize, NULL, mbHIGHER_PRIORITY, NULL );
|
||||
xTaskCreate( prvEchoServer, "2EchoServer", xBlockingStackSize, NULL, mbLOWER_PRIORITY, NULL );
|
||||
|
||||
/* The non blocking tasks run continuously and will interleave with each
|
||||
other, so must be created at the lowest priority. The message buffer they
|
||||
use is created and passed in using the task's parameter. */
|
||||
* other, so must be created at the lowest priority. The message buffer they
|
||||
* use is created and passed in using the task's parameter. */
|
||||
xMessageBuffer = xMessageBufferCreate( mbMESSAGE_BUFFER_LENGTH_BYTES );
|
||||
xTaskCreate( prvNonBlockingReceiverTask, "NonBlkRx", xStackSize, ( void * ) xMessageBuffer, tskIDLE_PRIORITY, NULL );
|
||||
xTaskCreate( prvNonBlockingSenderTask, "NonBlkTx", xStackSize, ( void * ) xMessageBuffer, tskIDLE_PRIORITY, NULL );
|
||||
|
||||
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
{
|
||||
/* The sender tasks set up the message buffers before creating the
|
||||
receiver tasks. Priorities must be 0 and 1 as the priority is used to
|
||||
index into the xStaticMessageBuffers and ucBufferStorage arrays. */
|
||||
* receiver tasks. Priorities must be 0 and 1 as the priority is used to
|
||||
* index into the xStaticMessageBuffers and ucBufferStorage arrays. */
|
||||
xTaskCreate( prvSenderTask, "1Sender", xBlockingStackSize, NULL, mbHIGHER_PRIORITY, NULL );
|
||||
xTaskCreate( prvSenderTask, "2Sender", xBlockingStackSize, NULL, mbLOWER_PRIORITY, NULL );
|
||||
}
|
||||
#endif /* configSUPPORT_STATIC_ALLOCATION */
|
||||
|
||||
#if( configRUN_ADDITIONAL_TESTS == 1 )
|
||||
#if ( configRUN_ADDITIONAL_TESTS == 1 )
|
||||
{
|
||||
xCoherenceTestMessageBuffer = xMessageBufferCreate( mbCOHERENCE_TEST_BUFFER_SIZE );
|
||||
configASSERT( xCoherenceTestMessageBuffer );
|
||||
|
|
@ -186,20 +187,20 @@ MessageBufferHandle_t xMessageBuffer;
|
|||
|
||||
static void prvSingleTaskTests( MessageBufferHandle_t xMessageBuffer )
|
||||
{
|
||||
size_t xReturned, xItem, xExpectedSpace, xNextLength;
|
||||
const size_t xMax6ByteMessages = mbMESSAGE_BUFFER_LENGTH_BYTES / ( 6 + mbBYTES_TO_STORE_MESSAGE_LENGTH );
|
||||
const size_t x6ByteLength = 6, x17ByteLength = 17;
|
||||
uint8_t *pucFullBuffer, *pucData, *pucReadData;
|
||||
TickType_t xTimeBeforeCall, xTimeAfterCall;
|
||||
const TickType_t xBlockTime = pdMS_TO_TICKS( 25 ), xAllowableMargin = pdMS_TO_TICKS( 3 );
|
||||
UBaseType_t uxOriginalPriority;
|
||||
size_t xReturned, xItem, xExpectedSpace, xNextLength;
|
||||
const size_t xMax6ByteMessages = mbMESSAGE_BUFFER_LENGTH_BYTES / ( 6 + mbBYTES_TO_STORE_MESSAGE_LENGTH );
|
||||
const size_t x6ByteLength = 6, x17ByteLength = 17;
|
||||
uint8_t * pucFullBuffer, * pucData, * pucReadData;
|
||||
TickType_t xTimeBeforeCall, xTimeAfterCall;
|
||||
const TickType_t xBlockTime = pdMS_TO_TICKS( 25 ), xAllowableMargin = pdMS_TO_TICKS( 3 );
|
||||
UBaseType_t uxOriginalPriority;
|
||||
|
||||
/* Remove warning in case configASSERT() is not defined. */
|
||||
( void ) xAllowableMargin;
|
||||
|
||||
/* To minimise stack and heap usage a full size buffer is allocated from
|
||||
the heap, then buffers which hold smaller amounts of data are overlayed
|
||||
with the larger buffer - just make sure not to use both at once!. */
|
||||
* the heap, then buffers which hold smaller amounts of data are overlayed
|
||||
* with the larger buffer - just make sure not to use both at once!. */
|
||||
pucFullBuffer = pvPortMalloc( mbMESSAGE_BUFFER_LENGTH_BYTES );
|
||||
configASSERT( pucFullBuffer );
|
||||
|
||||
|
|
@ -207,7 +208,7 @@ UBaseType_t uxOriginalPriority;
|
|||
pucReadData = pucData + x17ByteLength;
|
||||
|
||||
/* Nothing has been added or removed yet, so expect the free space to be
|
||||
exactly as created and the length of the next message to be 0. */
|
||||
* exactly as created and the length of the next message to be 0. */
|
||||
xExpectedSpace = xMessageBufferSpaceAvailable( xMessageBuffer );
|
||||
configASSERT( xExpectedSpace == mbMESSAGE_BUFFER_LENGTH_BYTES );
|
||||
configASSERT( xMessageBufferIsEmpty( xMessageBuffer ) == pdTRUE );
|
||||
|
|
@ -218,7 +219,7 @@ UBaseType_t uxOriginalPriority;
|
|||
( void ) xNextLength;
|
||||
|
||||
/* Try sending more bytes than possible, first using the FromISR version, then
|
||||
with an infinite block time to ensure this task does not lock up. */
|
||||
* with an infinite block time to ensure this task does not lock up. */
|
||||
xReturned = xMessageBufferSendFromISR( xMessageBuffer, ( void * ) pucData, mbMESSAGE_BUFFER_LENGTH_BYTES + sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ), NULL );
|
||||
configASSERT( xReturned == ( size_t ) 0 );
|
||||
/* In case configASSERT() is not defined. */
|
||||
|
|
@ -229,22 +230,22 @@ UBaseType_t uxOriginalPriority;
|
|||
( void ) xReturned;
|
||||
|
||||
/* The buffer is 50 bytes long. When an item is added to the buffer an
|
||||
additional 4 bytes are added to hold the item's size. That means adding
|
||||
6 bytes to the buffer will actually add 10 bytes to the buffer. Therefore,
|
||||
with a 50 byte buffer, a maximum of 5 6 bytes items can be added before the
|
||||
buffer is completely full. NOTE: The numbers in this paragraph assume
|
||||
sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ) == 4. */
|
||||
* additional 4 bytes are added to hold the item's size. That means adding
|
||||
* 6 bytes to the buffer will actually add 10 bytes to the buffer. Therefore,
|
||||
* with a 50 byte buffer, a maximum of 5 6 bytes items can be added before the
|
||||
* buffer is completely full. NOTE: The numbers in this paragraph assume
|
||||
* sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ) == 4. */
|
||||
for( xItem = 0; xItem < xMax6ByteMessages; xItem++ )
|
||||
{
|
||||
configASSERT( xMessageBufferIsFull( xMessageBuffer ) == pdFALSE );
|
||||
|
||||
/* Generate recognisable data to write to the buffer. This is just
|
||||
ascii characters that shows which loop iteration the data was written
|
||||
in. The 'FromISR' version is used to give it some exercise as a block
|
||||
time is not used. That requires the call to be in a critical section
|
||||
so this code can also run on FreeRTOS ports that do not support
|
||||
interrupt nesting (and so don't have interrupt safe critical
|
||||
sections).*/
|
||||
* ascii characters that shows which loop iteration the data was written
|
||||
* in. The 'FromISR' version is used to give it some exercise as a block
|
||||
* time is not used. That requires the call to be in a critical section
|
||||
* so this code can also run on FreeRTOS ports that do not support
|
||||
* interrupt nesting (and so don't have interrupt safe critical
|
||||
* sections).*/
|
||||
memset( ( void * ) pucData, ( ( int ) '0' ) + ( int ) xItem, x6ByteLength );
|
||||
taskENTER_CRITICAL();
|
||||
{
|
||||
|
|
@ -255,8 +256,8 @@ UBaseType_t uxOriginalPriority;
|
|||
( void ) xReturned; /* In case configASSERT() is not defined. */
|
||||
|
||||
/* The space in the buffer will have reduced by the amount of user data
|
||||
written into the buffer and the amount of space used to store the length
|
||||
of the data written into the buffer. */
|
||||
* written into the buffer and the amount of space used to store the length
|
||||
* of the data written into the buffer. */
|
||||
xExpectedSpace -= ( x6ByteLength + mbBYTES_TO_STORE_MESSAGE_LENGTH );
|
||||
xReturned = xMessageBufferSpaceAvailable( xMessageBuffer );
|
||||
configASSERT( xReturned == xExpectedSpace );
|
||||
|
|
@ -269,15 +270,15 @@ UBaseType_t uxOriginalPriority;
|
|||
}
|
||||
|
||||
/* Now the buffer should be full, and attempting to add anything will should
|
||||
fail. */
|
||||
* fail. */
|
||||
configASSERT( xMessageBufferIsFull( xMessageBuffer ) == pdTRUE );
|
||||
xReturned = xMessageBufferSend( xMessageBuffer, ( void * ) pucData, sizeof( pucData[ 0 ] ), mbDONT_BLOCK );
|
||||
configASSERT( xReturned == 0 );
|
||||
( void ) xReturned; /* In case configASSERT() is not defined. */
|
||||
|
||||
/* Adding with a timeout should also fail after the appropriate time. The
|
||||
priority is temporarily boosted in this part of the test to keep the
|
||||
allowable margin to a minimum. */
|
||||
* priority is temporarily boosted in this part of the test to keep the
|
||||
* allowable margin to a minimum. */
|
||||
uxOriginalPriority = uxTaskPriorityGet( NULL );
|
||||
vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );
|
||||
xTimeBeforeCall = xTaskGetTickCount();
|
||||
|
|
@ -291,17 +292,16 @@ UBaseType_t uxOriginalPriority;
|
|||
( void ) xTimeBeforeCall;
|
||||
( void ) xTimeAfterCall;
|
||||
|
||||
|
||||
/* The buffer is now full of data in the form "000000", "111111", etc. Make
|
||||
sure the data is read out as expected. */
|
||||
* sure the data is read out as expected. */
|
||||
for( xItem = 0; xItem < xMax6ByteMessages; xItem++ )
|
||||
{
|
||||
/* Generate the data that is expected to be read out for this loop
|
||||
iteration. */
|
||||
* iteration. */
|
||||
memset( ( void * ) pucData, ( ( int ) '0' ) + ( int ) xItem, x6ByteLength );
|
||||
|
||||
/* Try reading the message into a buffer that is too small. The message
|
||||
should remain in the buffer. */
|
||||
* should remain in the buffer. */
|
||||
xReturned = xMessageBufferReceive( xMessageBuffer, ( void * ) pucReadData, x6ByteLength - 1, mbDONT_BLOCK );
|
||||
configASSERT( xReturned == 0 );
|
||||
( void ) xReturned; /* In case configASSERT() is not defined. */
|
||||
|
|
@ -312,10 +312,10 @@ UBaseType_t uxOriginalPriority;
|
|||
( void ) xNextLength; /* In case configASSERT() is not defined. */
|
||||
|
||||
/* Read the next 6 bytes out. The 'FromISR' version is used to give it
|
||||
some exercise as a block time is not used. THa requires the code to be
|
||||
in a critical section so this test can be run with FreeRTOS ports that
|
||||
do not support interrupt nesting (and therefore don't have interrupt
|
||||
safe critical sections). */
|
||||
* some exercise as a block time is not used. THa requires the code to be
|
||||
* in a critical section so this test can be run with FreeRTOS ports that
|
||||
* do not support interrupt nesting (and therefore don't have interrupt
|
||||
* safe critical sections). */
|
||||
taskENTER_CRITICAL();
|
||||
{
|
||||
xReturned = xMessageBufferReceiveFromISR( xMessageBuffer, ( void * ) pucReadData, x6ByteLength, NULL );
|
||||
|
|
@ -328,8 +328,8 @@ UBaseType_t uxOriginalPriority;
|
|||
configASSERT( memcmp( ( void * ) pucData, ( void * ) pucReadData, x6ByteLength ) == 0 );
|
||||
|
||||
/* The space in the buffer will have increased by the amount of user
|
||||
data read from into the buffer and the amount of space used to store the
|
||||
length of the data read into the buffer. */
|
||||
* data read from into the buffer and the amount of space used to store the
|
||||
* length of the data read into the buffer. */
|
||||
xExpectedSpace += ( x6ByteLength + mbBYTES_TO_STORE_MESSAGE_LENGTH );
|
||||
xReturned = xMessageBufferSpaceAvailable( xMessageBuffer );
|
||||
configASSERT( xReturned == xExpectedSpace );
|
||||
|
|
@ -347,8 +347,8 @@ UBaseType_t uxOriginalPriority;
|
|||
|
||||
|
||||
/* Reading with a timeout should also fail after the appropriate time. The
|
||||
priority is temporarily boosted in this part of the test to keep the
|
||||
allowable margin to a minimum. */
|
||||
* priority is temporarily boosted in this part of the test to keep the
|
||||
* allowable margin to a minimum. */
|
||||
vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );
|
||||
xTimeBeforeCall = xTaskGetTickCount();
|
||||
xReturned = xMessageBufferReceive( xMessageBuffer, ( void * ) pucReadData, x6ByteLength, xBlockTime );
|
||||
|
|
@ -363,19 +363,19 @@ UBaseType_t uxOriginalPriority;
|
|||
|
||||
|
||||
/* In the next loop 17 bytes are written to then read out on each iteration.
|
||||
The expected length variable is always used after 17 bytes have been written
|
||||
into the buffer - the length of the message is also written, making a total
|
||||
of 21 bytes consumed for each 17 byte message. */
|
||||
* The expected length variable is always used after 17 bytes have been written
|
||||
* into the buffer - the length of the message is also written, making a total
|
||||
* of 21 bytes consumed for each 17 byte message. */
|
||||
xExpectedSpace = mbMESSAGE_BUFFER_LENGTH_BYTES - ( x17ByteLength + mbBYTES_TO_STORE_MESSAGE_LENGTH );
|
||||
|
||||
/* Reading and writing 17 bytes at a time will result in 21 bytes being
|
||||
written into the buffer, and as 50 is not divisible by 21, writing multiple
|
||||
times will cause the data to wrap in the buffer.*/
|
||||
* written into the buffer, and as 50 is not divisible by 21, writing multiple
|
||||
* times will cause the data to wrap in the buffer.*/
|
||||
for( xItem = 0; xItem < 100; xItem++ )
|
||||
{
|
||||
/* Generate recognisable data to write to the queue. This is just
|
||||
ascii characters that shows which loop iteration the data was written
|
||||
in. */
|
||||
* ascii characters that shows which loop iteration the data was written
|
||||
* in. */
|
||||
memset( ( void * ) pucData, ( ( int ) '0' ) + ( int ) xItem, x17ByteLength );
|
||||
xReturned = xMessageBufferSend( xMessageBuffer, ( void * ) pucData, x17ByteLength, mbDONT_BLOCK );
|
||||
configASSERT( xReturned == x17ByteLength );
|
||||
|
|
@ -387,8 +387,8 @@ UBaseType_t uxOriginalPriority;
|
|||
( void ) xNextLength; /* In case configASSERT() is not defined. */
|
||||
|
||||
/* The space in the buffer will have reduced by the amount of user data
|
||||
written into the buffer and the amount of space used to store the length
|
||||
of the data written into the buffer. */
|
||||
* written into the buffer and the amount of space used to store the length
|
||||
* of the data written into the buffer. */
|
||||
xReturned = xMessageBufferSpaceAvailable( xMessageBuffer );
|
||||
configASSERT( xReturned == xExpectedSpace );
|
||||
( void ) xReturned; /* In case configASSERT() is not defined. */
|
||||
|
|
@ -402,7 +402,7 @@ UBaseType_t uxOriginalPriority;
|
|||
configASSERT( memcmp( ( void * ) pucData, ( void * ) pucReadData, x17ByteLength ) == 0 );
|
||||
|
||||
/* Don't expect any messages to be available as the data was read out
|
||||
again. */
|
||||
* again. */
|
||||
xNextLength = xMessageBufferNextLengthBytes( xMessageBuffer );
|
||||
configASSERT( xNextLength == 0 );
|
||||
( void ) xNextLength; /* In case configASSERT() is not defined. */
|
||||
|
|
@ -414,15 +414,15 @@ UBaseType_t uxOriginalPriority;
|
|||
configASSERT( xExpectedSpace == mbMESSAGE_BUFFER_LENGTH_BYTES );
|
||||
|
||||
/* Cannot write within sizeof( size_t ) (assumed to be 4 bytes in this test)
|
||||
bytes of the full 50 bytes, as that would not leave space for the four bytes
|
||||
taken by the data length. */
|
||||
* bytes of the full 50 bytes, as that would not leave space for the four bytes
|
||||
* taken by the data length. */
|
||||
xReturned = xMessageBufferSend( xMessageBuffer, ( const void * ) pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES, mbDONT_BLOCK );
|
||||
configASSERT( xReturned == 0 );
|
||||
( void ) xReturned; /* In case configASSERT() is not defined. */
|
||||
#ifndef configMESSAGE_BUFFER_LENGTH_TYPE
|
||||
{
|
||||
/* The following will fail if configMESSAGE_BUFFER_LENGTH_TYPE is set
|
||||
to a non 32-bit type. */
|
||||
* to a non 32-bit type. */
|
||||
xReturned = xMessageBufferSend( xMessageBuffer, ( const void * ) pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES - 1, mbDONT_BLOCK );
|
||||
configASSERT( xReturned == 0 );
|
||||
( void ) xReturned; /* In case configASSERT() is not defined. */
|
||||
|
|
@ -433,10 +433,10 @@ UBaseType_t uxOriginalPriority;
|
|||
configASSERT( xReturned == 0 );
|
||||
( void ) xReturned; /* In case configASSERT() is not defined. */
|
||||
}
|
||||
#endif
|
||||
#endif /* ifndef configMESSAGE_BUFFER_LENGTH_TYPE */
|
||||
|
||||
/* Don't expect any messages to be available as the above were too large to
|
||||
get written. */
|
||||
* get written. */
|
||||
xNextLength = xMessageBufferNextLengthBytes( xMessageBuffer );
|
||||
configASSERT( xNextLength == 0 );
|
||||
( void ) xNextLength; /* In case configASSERT() is not defined. */
|
||||
|
|
@ -459,29 +459,30 @@ UBaseType_t uxOriginalPriority;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvNonBlockingSenderTask( void *pvParameters )
|
||||
static void prvNonBlockingSenderTask( void * pvParameters )
|
||||
{
|
||||
MessageBufferHandle_t xMessageBuffer;
|
||||
int32_t iDataToSend = 0;
|
||||
size_t xStringLength;
|
||||
const int32_t iMaxValue = 1500;
|
||||
char cTxString[ 12 ]; /* Large enough to hold a 32 number in ASCII. */
|
||||
MessageBufferHandle_t xMessageBuffer;
|
||||
int32_t iDataToSend = 0;
|
||||
size_t xStringLength;
|
||||
const int32_t iMaxValue = 1500;
|
||||
char cTxString[ 12 ]; /* Large enough to hold a 32 number in ASCII. */
|
||||
|
||||
/* In this case the message buffer has already been created and is passed
|
||||
into the task using the task's parameter. */
|
||||
* into the task using the task's parameter. */
|
||||
|
||||
xMessageBuffer = ( MessageBufferHandle_t ) pvParameters;
|
||||
|
||||
/* Create a string from an incrementing number. The length of the
|
||||
string will increase and decrease as the value of the number increases
|
||||
then overflows. */
|
||||
* string will increase and decrease as the value of the number increases
|
||||
* then overflows. */
|
||||
memset( cTxString, 0x00, sizeof( cTxString ) );
|
||||
sprintf( cTxString, "%d", ( int ) iDataToSend );
|
||||
xStringLength = strlen( cTxString );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Doesn't block so calls can interleave with the non-blocking
|
||||
receives performed by prvNonBlockingReceiverTask(). */
|
||||
* receives performed by prvNonBlockingReceiverTask(). */
|
||||
if( xMessageBufferSend( xMessageBuffer, ( void * ) cTxString, strlen( cTxString ), mbDONT_BLOCK ) == xStringLength )
|
||||
{
|
||||
iDataToSend++;
|
||||
|
|
@ -489,7 +490,7 @@ char cTxString[ 12 ]; /* Large enough to hold a 32 number in ASCII. */
|
|||
if( iDataToSend > iMaxValue )
|
||||
{
|
||||
/* The value sent is reset back to 0 to ensure the string being sent
|
||||
does not remain at the same length for too long. */
|
||||
* does not remain at the same length for too long. */
|
||||
iDataToSend = 0;
|
||||
}
|
||||
|
||||
|
|
@ -502,37 +503,37 @@ char cTxString[ 12 ]; /* Large enough to hold a 32 number in ASCII. */
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvNonBlockingReceiverTask( void *pvParameters )
|
||||
static void prvNonBlockingReceiverTask( void * pvParameters )
|
||||
{
|
||||
MessageBufferHandle_t xMessageBuffer;
|
||||
BaseType_t xNonBlockingReceiveError = pdFALSE;
|
||||
int32_t iDataToSend = 0;
|
||||
size_t xStringLength, xReceiveLength;
|
||||
const int32_t iMaxValue = 1500;
|
||||
char cExpectedString[ 12 ]; /* Large enough to hold a 32 number in ASCII. */
|
||||
char cRxString[ 12 ];
|
||||
MessageBufferHandle_t xMessageBuffer;
|
||||
BaseType_t xNonBlockingReceiveError = pdFALSE;
|
||||
int32_t iDataToSend = 0;
|
||||
size_t xStringLength, xReceiveLength;
|
||||
const int32_t iMaxValue = 1500;
|
||||
char cExpectedString[ 12 ]; /* Large enough to hold a 32 number in ASCII. */
|
||||
char cRxString[ 12 ];
|
||||
|
||||
/* In this case the message buffer has already been created and is passed
|
||||
into the task using the task's parameter. */
|
||||
* into the task using the task's parameter. */
|
||||
xMessageBuffer = ( MessageBufferHandle_t ) pvParameters;
|
||||
|
||||
/* Create a string from an incrementing number. The length of the
|
||||
string will increase and decrease as the value of the number increases
|
||||
then overflows. This should always match the string sent to the buffer by
|
||||
the non blocking sender task. */
|
||||
* string will increase and decrease as the value of the number increases
|
||||
* then overflows. This should always match the string sent to the buffer by
|
||||
* the non blocking sender task. */
|
||||
memset( cExpectedString, 0x00, sizeof( cExpectedString ) );
|
||||
memset( cRxString, 0x00, sizeof( cRxString ) );
|
||||
sprintf( cExpectedString, "%d", ( int ) iDataToSend );
|
||||
xStringLength = strlen( cExpectedString );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Doesn't block so calls can interleave with the non-blocking
|
||||
receives performed by prvNonBlockingReceiverTask(). */
|
||||
* receives performed by prvNonBlockingReceiverTask(). */
|
||||
xReceiveLength = xMessageBufferReceive( xMessageBuffer, ( void * ) cRxString, sizeof( cRxString ), mbDONT_BLOCK );
|
||||
|
||||
/* Should only ever receive no data is available, or the expected
|
||||
length of data is available. */
|
||||
* length of data is available. */
|
||||
if( ( xReceiveLength != 0 ) && ( xReceiveLength != xStringLength ) )
|
||||
{
|
||||
xNonBlockingReceiveError = pdTRUE;
|
||||
|
|
@ -541,7 +542,7 @@ char cRxString[ 12 ];
|
|||
if( xReceiveLength == xStringLength )
|
||||
{
|
||||
/* Ensure the received data was that expected, then generate the
|
||||
next expected string. */
|
||||
* next expected string. */
|
||||
if( strcmp( cRxString, cExpectedString ) != 0 )
|
||||
{
|
||||
xNonBlockingReceiveError = pdTRUE;
|
||||
|
|
@ -552,7 +553,7 @@ char cRxString[ 12 ];
|
|||
if( iDataToSend > iMaxValue )
|
||||
{
|
||||
/* The value sent is reset back to 0 to ensure the string being sent
|
||||
does not remain at the same length for too long. */
|
||||
* does not remain at the same length for too long. */
|
||||
iDataToSend = 0;
|
||||
}
|
||||
|
||||
|
|
@ -564,7 +565,7 @@ char cRxString[ 12 ];
|
|||
if( xNonBlockingReceiveError == pdFALSE )
|
||||
{
|
||||
/* No errors detected so increment the counter that lets the
|
||||
check task know this test is still functioning correctly. */
|
||||
* check task know this test is still functioning correctly. */
|
||||
ulNonBlockingRxCounter++;
|
||||
}
|
||||
}
|
||||
|
|
@ -572,9 +573,9 @@ char cRxString[ 12 ];
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
|
||||
static void prvSenderTask( void *pvParameters )
|
||||
static void prvSenderTask( void * pvParameters )
|
||||
{
|
||||
MessageBufferHandle_t xMessageBuffer, xTempMessageBuffer;
|
||||
int32_t iDataToSend = 0;
|
||||
|
|
@ -586,11 +587,11 @@ char cRxString[ 12 ];
|
|||
|
||||
|
||||
/* The task's priority is used as an index into the loop counters used to
|
||||
indicate this task is still running. */
|
||||
* indicate this task is still running. */
|
||||
UBaseType_t uxIndex = uxTaskPriorityGet( NULL );
|
||||
|
||||
/* Make sure a change in priority does not inadvertently result in an
|
||||
invalid array index. */
|
||||
* invalid array index. */
|
||||
configASSERT( uxIndex < mbNUMBER_OF_ECHO_CLIENTS );
|
||||
|
||||
/* Avoid compiler warnings about unused parameters. */
|
||||
|
|
@ -601,13 +602,13 @@ char cRxString[ 12 ];
|
|||
&( xStaticMessageBuffers[ uxIndex ] ) ); /* The static message buffer structure to use within the array. */
|
||||
|
||||
/* Now the message buffer has been created the receiver task can be created.
|
||||
If this sender task has the higher priority then the receiver task is
|
||||
created at the lower priority - if this sender task has the lower priority
|
||||
then the receiver task is created at the higher priority. */
|
||||
* If this sender task has the higher priority then the receiver task is
|
||||
* created at the lower priority - if this sender task has the lower priority
|
||||
* then the receiver task is created at the higher priority. */
|
||||
if( uxTaskPriorityGet( NULL ) == mbLOWER_PRIORITY )
|
||||
{
|
||||
/* Here prvSingleTaskTests() performs various tests on a message buffer
|
||||
that was created statically. */
|
||||
* that was created statically. */
|
||||
prvSingleTaskTests( xMessageBuffer );
|
||||
xTaskCreate( prvReceiverTask, "MsgReceiver", xBlockingStackSize, ( void * ) xMessageBuffer, mbHIGHER_PRIORITY, NULL );
|
||||
}
|
||||
|
|
@ -616,25 +617,25 @@ char cRxString[ 12 ];
|
|||
xTaskCreate( prvReceiverTask, "MsgReceiver", xBlockingStackSize, ( void * ) xMessageBuffer, mbLOWER_PRIORITY, NULL );
|
||||
}
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Create a string from an incrementing number. The length of the
|
||||
string will increase and decrease as the value of the number increases
|
||||
then overflows. */
|
||||
* string will increase and decrease as the value of the number increases
|
||||
* then overflows. */
|
||||
memset( cTxString, 0x00, sizeof( cTxString ) );
|
||||
sprintf( cTxString, "%d", ( int ) iDataToSend );
|
||||
|
||||
do
|
||||
{
|
||||
xBytesSent = xMessageBufferSend( xMessageBuffer, ( void * ) cTxString, strlen( cTxString ), xTicksToWait );
|
||||
} while ( xBytesSent == 0 ); /* Buffer may become full when receiver is running at the idle priority. */
|
||||
} while( xBytesSent == 0 ); /* Buffer may become full when receiver is running at the idle priority. */
|
||||
|
||||
iDataToSend++;
|
||||
|
||||
if( ( iDataToSend % iSendsBetweenIncrements ) == 0 )
|
||||
{
|
||||
/* Increment a loop counter so a check task can tell this task is
|
||||
still running as expected. */
|
||||
* still running as expected. */
|
||||
ulSenderLoopCounters[ uxIndex ]++;
|
||||
|
||||
if( uxTaskPriorityGet( NULL ) == mbHIGHER_PRIORITY )
|
||||
|
|
@ -644,10 +645,10 @@ char cRxString[ 12 ];
|
|||
}
|
||||
|
||||
/* This message buffer is just created and deleted to ensure no
|
||||
issues when attempting to delete a message buffer that was
|
||||
created using statically allocated memory. To save stack space
|
||||
the buffer is set to point to the cTxString array - this is
|
||||
ok because nothing is actually written to the memory. */
|
||||
* issues when attempting to delete a message buffer that was
|
||||
* created using statically allocated memory. To save stack space
|
||||
* the buffer is set to point to the cTxString array - this is
|
||||
* ok because nothing is actually written to the memory. */
|
||||
xTempMessageBuffer = xMessageBufferCreateStatic( sizeof( cTxString ), ( uint8_t * ) cTxString, &xStaticMessageBuffer );
|
||||
vMessageBufferDelete( xTempMessageBuffer );
|
||||
}
|
||||
|
|
@ -657,9 +658,9 @@ char cRxString[ 12 ];
|
|||
#endif /* configSUPPORT_STATIC_ALLOCATION */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
|
||||
static void prvReceiverTask( void *pvParameters )
|
||||
static void prvReceiverTask( void * pvParameters )
|
||||
{
|
||||
MessageBufferHandle_t * const pxMessageBuffer = ( MessageBufferHandle_t * ) pvParameters;
|
||||
char cExpectedString[ 12 ]; /* Large enough to hold a 32-bit number in ASCII. */
|
||||
|
|
@ -668,7 +669,7 @@ char cRxString[ 12 ];
|
|||
const TickType_t xTicksToWait = pdMS_TO_TICKS( 5UL );
|
||||
size_t xReceivedBytes;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Generate the next expected string in the cExpectedString buffer. */
|
||||
memset( cExpectedString, 0x00, sizeof( cExpectedString ) );
|
||||
|
|
@ -680,7 +681,6 @@ char cRxString[ 12 ];
|
|||
do
|
||||
{
|
||||
xReceivedBytes = xMessageBufferReceive( pxMessageBuffer, ( void * ) cReceivedString, sizeof( cExpectedString ), xTicksToWait );
|
||||
|
||||
} while( xReceivedBytes == 0 );
|
||||
|
||||
/* Ensure the received string matches the expected string. */
|
||||
|
|
@ -693,50 +693,50 @@ char cRxString[ 12 ];
|
|||
#endif /* configSUPPORT_STATIC_ALLOCATION */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvEchoClient( void *pvParameters )
|
||||
static void prvEchoClient( void * pvParameters )
|
||||
{
|
||||
size_t xSendLength = 0, ux;
|
||||
char *pcStringToSend, *pcStringReceived, cNextChar = mbASCII_SPACE;
|
||||
const TickType_t xTicksToWait = pdMS_TO_TICKS( 50 );
|
||||
size_t xSendLength = 0, ux;
|
||||
char * pcStringToSend, * pcStringReceived, cNextChar = mbASCII_SPACE;
|
||||
const TickType_t xTicksToWait = pdMS_TO_TICKS( 50 );
|
||||
|
||||
/* The task's priority is used as an index into the loop counters used to
|
||||
indicate this task is still running. */
|
||||
UBaseType_t uxIndex = uxTaskPriorityGet( NULL );
|
||||
* indicate this task is still running. */
|
||||
UBaseType_t uxIndex = uxTaskPriorityGet( NULL );
|
||||
|
||||
/* Pointers to the client and server message buffers are passed into this task
|
||||
using the task's parameter. */
|
||||
EchoMessageBuffers_t *pxMessageBuffers = ( EchoMessageBuffers_t * ) pvParameters;
|
||||
* using the task's parameter. */
|
||||
EchoMessageBuffers_t * pxMessageBuffers = ( EchoMessageBuffers_t * ) pvParameters;
|
||||
|
||||
/* Prevent compiler warnings. */
|
||||
( void ) pvParameters;
|
||||
|
||||
/* Create the buffer into which strings to send to the server will be
|
||||
created, and the buffer into which strings echoed back from the server will
|
||||
be copied. */
|
||||
* created, and the buffer into which strings echoed back from the server will
|
||||
* be copied. */
|
||||
pcStringToSend = ( char * ) pvPortMalloc( mbMESSAGE_BUFFER_LENGTH_BYTES );
|
||||
pcStringReceived = ( char * ) pvPortMalloc( mbMESSAGE_BUFFER_LENGTH_BYTES );
|
||||
|
||||
configASSERT( pcStringToSend );
|
||||
configASSERT( pcStringReceived );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Generate the length of the next string to send. */
|
||||
xSendLength++;
|
||||
|
||||
/* The message buffer is being used to hold variable length data, so
|
||||
each data item requires sizeof( size_t ) bytes to hold the data's
|
||||
length, hence the sizeof() in the if() condition below. */
|
||||
* each data item requires sizeof( size_t ) bytes to hold the data's
|
||||
* length, hence the sizeof() in the if() condition below. */
|
||||
if( xSendLength > ( mbMESSAGE_BUFFER_LENGTH_BYTES - sizeof( size_t ) ) )
|
||||
{
|
||||
/* Back to a string length of 1. */
|
||||
xSendLength = sizeof( char );
|
||||
|
||||
/* Maintain a count of the number of times this code executes so a
|
||||
check task can determine if this task is still functioning as
|
||||
expected or not. As there are two client tasks, and the priorities
|
||||
used are 0 and 1, the task's priority is used as an index into the
|
||||
loop count array. */
|
||||
* check task can determine if this task is still functioning as
|
||||
* expected or not. As there are two client tasks, and the priorities
|
||||
* used are 0 and 1, the task's priority is used as an index into the
|
||||
* loop count array. */
|
||||
ulEchoLoopCounters[ uxIndex ]++;
|
||||
}
|
||||
|
||||
|
|
@ -763,7 +763,6 @@ EchoMessageBuffers_t *pxMessageBuffers = ( EchoMessageBuffers_t * ) pvParameters
|
|||
{
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
|
||||
} while( ux == 0 );
|
||||
|
||||
/* Wait for the string to be echoed back. */
|
||||
|
|
@ -775,21 +774,21 @@ EchoMessageBuffers_t *pxMessageBuffers = ( EchoMessageBuffers_t * ) pvParameters
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvEchoServer( void *pvParameters )
|
||||
static void prvEchoServer( void * pvParameters )
|
||||
{
|
||||
MessageBufferHandle_t xTempMessageBuffer;
|
||||
size_t xReceivedLength;
|
||||
char *pcReceivedString;
|
||||
EchoMessageBuffers_t xMessageBuffers;
|
||||
TickType_t xTimeOnEntering;
|
||||
const TickType_t xTicksToBlock = pdMS_TO_TICKS( 250UL );
|
||||
MessageBufferHandle_t xTempMessageBuffer;
|
||||
size_t xReceivedLength;
|
||||
char * pcReceivedString;
|
||||
EchoMessageBuffers_t xMessageBuffers;
|
||||
TickType_t xTimeOnEntering;
|
||||
const TickType_t xTicksToBlock = pdMS_TO_TICKS( 250UL );
|
||||
|
||||
/* Prevent compiler warnings about unused parameters. */
|
||||
( void ) pvParameters;
|
||||
|
||||
/* Create the message buffer used to send data from the client to the server,
|
||||
and the message buffer used to echo the data from the server back to the
|
||||
client. */
|
||||
* and the message buffer used to echo the data from the server back to the
|
||||
* client. */
|
||||
xMessageBuffers.xEchoClientBuffer = xMessageBufferCreate( mbMESSAGE_BUFFER_LENGTH_BYTES );
|
||||
xMessageBuffers.xEchoServerBuffer = xMessageBufferCreate( mbMESSAGE_BUFFER_LENGTH_BYTES );
|
||||
configASSERT( xMessageBuffers.xEchoClientBuffer );
|
||||
|
|
@ -807,9 +806,9 @@ const TickType_t xTicksToBlock = pdMS_TO_TICKS( 250UL );
|
|||
( void ) xTimeOnEntering; /* In case configASSERT() is not defined. */
|
||||
|
||||
/* Now the message buffers have been created the echo client task can be
|
||||
created. If this server task has the higher priority then the client task
|
||||
is created at the lower priority - if this server task has the lower
|
||||
priority then the client task is created at the higher priority. */
|
||||
* created. If this server task has the higher priority then the client task
|
||||
* is created at the lower priority - if this server task has the lower
|
||||
* priority then the client task is created at the higher priority. */
|
||||
if( uxTaskPriorityGet( NULL ) == mbLOWER_PRIORITY )
|
||||
{
|
||||
xTaskCreate( prvEchoClient, "EchoClient", configMINIMAL_STACK_SIZE, ( void * ) &xMessageBuffers, mbHIGHER_PRIORITY, NULL );
|
||||
|
|
@ -817,12 +816,12 @@ const TickType_t xTicksToBlock = pdMS_TO_TICKS( 250UL );
|
|||
else
|
||||
{
|
||||
/* Here prvSingleTaskTests() performs various tests on a message buffer
|
||||
that was created dynamically. */
|
||||
* that was created dynamically. */
|
||||
prvSingleTaskTests( xMessageBuffers.xEchoClientBuffer );
|
||||
xTaskCreate( prvEchoClient, "EchoClient", configMINIMAL_STACK_SIZE, ( void * ) &xMessageBuffers, mbLOWER_PRIORITY, NULL );
|
||||
}
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
memset( pcReceivedString, 0x00, mbMESSAGE_BUFFER_LENGTH_BYTES );
|
||||
|
||||
|
|
@ -836,7 +835,7 @@ const TickType_t xTicksToBlock = pdMS_TO_TICKS( 250UL );
|
|||
xMessageBufferSend( xMessageBuffers.xEchoServerBuffer, ( void * ) pcReceivedString, xReceivedLength, portMAX_DELAY );
|
||||
|
||||
/* This message buffer is just created and deleted to ensure no memory
|
||||
leaks. */
|
||||
* leaks. */
|
||||
xTempMessageBuffer = xMessageBufferCreate( mbMESSAGE_BUFFER_LENGTH_BYTES );
|
||||
vMessageBufferDelete( xTempMessageBuffer );
|
||||
}
|
||||
|
|
@ -847,24 +846,24 @@ const TickType_t xTicksToBlock = pdMS_TO_TICKS( 250UL );
|
|||
* platforms or have been added to pre-existing files that are already in use
|
||||
* by other test projects without ensuring they don't cause those pre-existing
|
||||
* projects to run out of program or data memory. */
|
||||
#if( configRUN_ADDITIONAL_TESTS == 1 )
|
||||
#if ( configRUN_ADDITIONAL_TESTS == 1 )
|
||||
|
||||
static void prvSpaceAvailableCoherenceActor( void *pvParameters )
|
||||
static void prvSpaceAvailableCoherenceActor( void * pvParameters )
|
||||
{
|
||||
static char *cTxString = "12345";
|
||||
static char * cTxString = "12345";
|
||||
char cRxString[ mbCOHERENCE_TEST_BYTES_WRITTEN + 1 ]; /* +1 for NULL terminator. */
|
||||
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Add bytes to the buffer so the other task should see
|
||||
mbEXPECTED_FREE_BYTES_AFTER_WRITING_STRING bytes free. */
|
||||
* mbEXPECTED_FREE_BYTES_AFTER_WRITING_STRING bytes free. */
|
||||
xMessageBufferSend( xCoherenceTestMessageBuffer, ( void * ) cTxString, strlen( cTxString ), 0 );
|
||||
configASSERT( xMessageBufferSpacesAvailable( xCoherenceTestMessageBuffer ) == mbEXPECTED_FREE_BYTES_AFTER_WRITING_STRING );
|
||||
|
||||
/* Read out message again so the other task should read the full
|
||||
mbCOHERENCE_TEST_BUFFER_SIZE bytes free again. */
|
||||
* mbCOHERENCE_TEST_BUFFER_SIZE bytes free again. */
|
||||
memset( ( void * ) cRxString, 0x00, sizeof( cRxString ) );
|
||||
xMessageBufferReceive( xCoherenceTestMessageBuffer, ( void * ) cRxString, mbCOHERENCE_TEST_BYTES_WRITTEN, 0 );
|
||||
configASSERT( strcmp( cTxString, cRxString ) == 0 );
|
||||
|
|
@ -872,25 +871,25 @@ const TickType_t xTicksToBlock = pdMS_TO_TICKS( 250UL );
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvSpaceAvailableCoherenceTester( void *pvParameters )
|
||||
static void prvSpaceAvailableCoherenceTester( void * pvParameters )
|
||||
{
|
||||
size_t xSpaceAvailable;
|
||||
BaseType_t xErrorFound = pdFALSE;
|
||||
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* This message buffer is only ever empty or contains 5 bytes. So all
|
||||
queries of its free space should result in one of the two values tested
|
||||
below. */
|
||||
* queries of its free space should result in one of the two values tested
|
||||
* below. */
|
||||
xSpaceAvailable = xMessageBufferSpacesAvailable( xCoherenceTestMessageBuffer );
|
||||
|
||||
if( ( xSpaceAvailable == mbCOHERENCE_TEST_BUFFER_SIZE ) ||
|
||||
( xSpaceAvailable == mbEXPECTED_FREE_BYTES_AFTER_WRITING_STRING ) )
|
||||
{
|
||||
/* Only continue to increment the variable that shows this task
|
||||
is still executing if no errors have been found. */
|
||||
* is still executing if no errors have been found. */
|
||||
if( xErrorFound == pdFALSE )
|
||||
{
|
||||
ulSizeCoherencyTestCycles++;
|
||||
|
|
@ -910,9 +909,9 @@ const TickType_t xTicksToBlock = pdMS_TO_TICKS( 250UL );
|
|||
|
||||
BaseType_t xAreMessageBufferTasksStillRunning( void )
|
||||
{
|
||||
static uint32_t ulLastEchoLoopCounters[ mbNUMBER_OF_ECHO_CLIENTS ] = { 0 };
|
||||
static uint32_t ulLastNonBlockingRxCounter = 0;
|
||||
BaseType_t xReturn = pdPASS, x;
|
||||
static uint32_t ulLastEchoLoopCounters[ mbNUMBER_OF_ECHO_CLIENTS ] = { 0 };
|
||||
static uint32_t ulLastNonBlockingRxCounter = 0;
|
||||
BaseType_t xReturn = pdPASS, x;
|
||||
|
||||
for( x = 0; x < mbNUMBER_OF_ECHO_CLIENTS; x++ )
|
||||
{
|
||||
|
|
@ -935,7 +934,7 @@ BaseType_t xReturn = pdPASS, x;
|
|||
ulLastNonBlockingRxCounter = ulNonBlockingRxCounter;
|
||||
}
|
||||
|
||||
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
{
|
||||
static uint32_t ulLastSenderLoopCounters[ mbNUMBER_OF_ECHO_CLIENTS ] = { 0 };
|
||||
|
||||
|
|
@ -953,7 +952,7 @@ BaseType_t xReturn = pdPASS, x;
|
|||
}
|
||||
#endif /* configSUPPORT_STATIC_ALLOCATION */
|
||||
|
||||
#if( configRUN_ADDITIONAL_TESTS == 1 )
|
||||
#if ( configRUN_ADDITIONAL_TESTS == 1 )
|
||||
{
|
||||
static uint32_t ullastSizeCoherencyTestCycles = 0UL;
|
||||
|
||||
|
|
@ -966,10 +965,8 @@ BaseType_t xReturn = pdPASS, x;
|
|||
ullastSizeCoherencyTestCycles = ulSizeCoherencyTestCycles;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif /* if ( configRUN_ADDITIONAL_TESTS == 1 ) */
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -49,11 +49,11 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
Changes from V2.0.0
|
||||
|
||||
* Changes from V2.0.0
|
||||
*
|
||||
+ Delay periods are now specified using variables and constants of
|
||||
TickType_t rather than uint32_t.
|
||||
*/
|
||||
+ TickType_t rather than uint32_t.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -80,14 +80,14 @@ static portTASK_FUNCTION_PROTO( vPolledQueueProducer, pvParameters );
|
|||
static portTASK_FUNCTION_PROTO( vPolledQueueConsumer, pvParameters );
|
||||
|
||||
/* Variables that are used to check that the tasks are still running with no
|
||||
errors. */
|
||||
* errors. */
|
||||
static volatile BaseType_t xPollingConsumerCount = pollqINITIAL_VALUE, xPollingProducerCount = pollqINITIAL_VALUE;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vStartPolledQueueTasks( UBaseType_t uxPriority )
|
||||
{
|
||||
static QueueHandle_t xPolledQueue;
|
||||
static QueueHandle_t xPolledQueue;
|
||||
|
||||
/* Create the queue used by the producer and consumer. */
|
||||
xPolledQueue = xQueueCreate( pollqQUEUE_SIZE, ( UBaseType_t ) sizeof( uint16_t ) );
|
||||
|
|
@ -95,11 +95,11 @@ static QueueHandle_t xPolledQueue;
|
|||
if( xPolledQueue != NULL )
|
||||
{
|
||||
/* vQueueAddToRegistry() adds the queue to the queue registry, if one is
|
||||
in use. The queue registry is provided as a means for kernel aware
|
||||
debuggers to locate queues 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
|
||||
defined to be less than 1. */
|
||||
* in use. The queue registry is provided as a means for kernel aware
|
||||
* debuggers to locate queues 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
|
||||
* defined to be less than 1. */
|
||||
vQueueAddToRegistry( xPolledQueue, "Poll_Test_Queue" );
|
||||
|
||||
/* Spawn the producer and consumer. */
|
||||
|
|
@ -111,10 +111,10 @@ static QueueHandle_t xPolledQueue;
|
|||
|
||||
static portTASK_FUNCTION( vPolledQueueProducer, pvParameters )
|
||||
{
|
||||
uint16_t usValue = ( uint16_t ) 0;
|
||||
BaseType_t xError = pdFALSE, xLoop;
|
||||
uint16_t usValue = ( uint16_t ) 0;
|
||||
BaseType_t xError = pdFALSE, xLoop;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
for( xLoop = 0; xLoop < pollqVALUES_TO_PRODUCE; xLoop++ )
|
||||
{
|
||||
|
|
@ -122,7 +122,7 @@ BaseType_t xError = pdFALSE, xLoop;
|
|||
if( xQueueSend( *( ( QueueHandle_t * ) pvParameters ), ( void * ) &usValue, pollqNO_DELAY ) != pdPASS )
|
||||
{
|
||||
/* We should never find the queue full so if we get here there
|
||||
has been an error. */
|
||||
* has been an error. */
|
||||
xError = pdTRUE;
|
||||
}
|
||||
else
|
||||
|
|
@ -130,7 +130,7 @@ BaseType_t xError = pdFALSE, xLoop;
|
|||
if( xError == pdFALSE )
|
||||
{
|
||||
/* If an error has ever been recorded we stop incrementing the
|
||||
check variable. */
|
||||
* check variable. */
|
||||
portENTER_CRITICAL();
|
||||
xPollingProducerCount++;
|
||||
portEXIT_CRITICAL();
|
||||
|
|
@ -142,7 +142,7 @@ BaseType_t xError = pdFALSE, xLoop;
|
|||
}
|
||||
|
||||
/* Wait before we start posting again to ensure the consumer runs and
|
||||
empties the queue. */
|
||||
* empties the queue. */
|
||||
vTaskDelay( pollqPRODUCER_DELAY );
|
||||
}
|
||||
} /*lint !e818 Function prototype must conform to API. */
|
||||
|
|
@ -150,10 +150,10 @@ BaseType_t xError = pdFALSE, xLoop;
|
|||
|
||||
static portTASK_FUNCTION( vPolledQueueConsumer, pvParameters )
|
||||
{
|
||||
uint16_t usData, usExpectedValue = ( uint16_t ) 0;
|
||||
BaseType_t xError = pdFALSE;
|
||||
uint16_t usData, usExpectedValue = ( uint16_t ) 0;
|
||||
BaseType_t xError = pdFALSE;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Loop until the queue is empty. */
|
||||
while( uxQueueMessagesWaiting( *( ( QueueHandle_t * ) pvParameters ) ) )
|
||||
|
|
@ -163,11 +163,11 @@ BaseType_t xError = pdFALSE;
|
|||
if( usData != usExpectedValue )
|
||||
{
|
||||
/* This is not what we expected to receive so an error has
|
||||
occurred. */
|
||||
* occurred. */
|
||||
xError = pdTRUE;
|
||||
|
||||
/* Catch-up to the value we received so our next expected
|
||||
value should again be correct. */
|
||||
* value should again be correct. */
|
||||
usExpectedValue = usData;
|
||||
}
|
||||
else
|
||||
|
|
@ -175,7 +175,7 @@ BaseType_t xError = pdFALSE;
|
|||
if( xError == pdFALSE )
|
||||
{
|
||||
/* Only increment the check variable if no errors have
|
||||
occurred. */
|
||||
* occurred. */
|
||||
portENTER_CRITICAL();
|
||||
xPollingConsumerCount++;
|
||||
portEXIT_CRITICAL();
|
||||
|
|
@ -188,7 +188,7 @@ BaseType_t xError = pdFALSE;
|
|||
}
|
||||
|
||||
/* Now the queue is empty we block, allowing the producer to place more
|
||||
items in the queue. */
|
||||
* items in the queue. */
|
||||
vTaskDelay( pollqCONSUMER_DELAY );
|
||||
}
|
||||
} /*lint !e818 Function prototype must conform to API. */
|
||||
|
|
@ -197,12 +197,12 @@ BaseType_t xError = pdFALSE;
|
|||
/* This is called to check that all the created tasks are still running with no errors. */
|
||||
BaseType_t xArePollingQueuesStillRunning( void )
|
||||
{
|
||||
BaseType_t xReturn;
|
||||
BaseType_t xReturn;
|
||||
|
||||
/* Check both the consumer and producer poll count to check they have both
|
||||
been changed since out last trip round. We do not need a critical section
|
||||
around the check variables as this is called from a higher priority than
|
||||
the other tasks that access the same variables. */
|
||||
* been changed since out last trip round. We do not need a critical section
|
||||
* around the check variables as this is called from a higher priority than
|
||||
* the other tasks that access the same variables. */
|
||||
if( ( xPollingConsumerCount == pollqINITIAL_VALUE ) ||
|
||||
( xPollingProducerCount == pollqINITIAL_VALUE )
|
||||
)
|
||||
|
|
@ -215,7 +215,7 @@ BaseType_t xReturn;
|
|||
}
|
||||
|
||||
/* Set the check variables back down so we know if they have been
|
||||
incremented the next time around. */
|
||||
* incremented the next time around. */
|
||||
xPollingConsumerCount = pollqINITIAL_VALUE;
|
||||
xPollingProducerCount = pollqINITIAL_VALUE;
|
||||
|
||||
|
|
|
|||
|
|
@ -59,19 +59,19 @@
|
|||
* Each task is given a different priority to demonstrate the order in which
|
||||
* tasks are woken as data is peeked from a queue.
|
||||
*/
|
||||
static void prvLowPriorityPeekTask( void *pvParameters );
|
||||
static void prvMediumPriorityPeekTask( void *pvParameters );
|
||||
static void prvHighPriorityPeekTask( void *pvParameters );
|
||||
static void prvHighestPriorityPeekTask( void *pvParameters );
|
||||
static void prvLowPriorityPeekTask( void * pvParameters );
|
||||
static void prvMediumPriorityPeekTask( void * pvParameters );
|
||||
static void prvHighPriorityPeekTask( void * pvParameters );
|
||||
static void prvHighestPriorityPeekTask( void * pvParameters );
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Flag that will be latched to pdTRUE should any unexpected behaviour be
|
||||
detected in any of the tasks. */
|
||||
* detected in any of the tasks. */
|
||||
static volatile BaseType_t xErrorDetected = pdFALSE;
|
||||
|
||||
/* Counter that is incremented on each cycle of a test. This is used to
|
||||
detect a stalled task - a test that is no longer running. */
|
||||
* detect a stalled task - a test that is no longer running. */
|
||||
static volatile uint32_t ulLoopCounter = 0;
|
||||
|
||||
/* Handles to the test tasks. */
|
||||
|
|
@ -80,7 +80,7 @@ TaskHandle_t xMediumPriorityTask, xHighPriorityTask, xHighestPriorityTask;
|
|||
|
||||
void vStartQueuePeekTasks( void )
|
||||
{
|
||||
QueueHandle_t xQueue;
|
||||
QueueHandle_t xQueue;
|
||||
|
||||
/* Create the queue that we are going to use for the test/demo. */
|
||||
xQueue = xQueueCreate( qpeekQUEUE_LENGTH, sizeof( uint32_t ) );
|
||||
|
|
@ -88,16 +88,16 @@ QueueHandle_t xQueue;
|
|||
if( xQueue != NULL )
|
||||
{
|
||||
/* vQueueAddToRegistry() adds the queue to the queue registry, if one is
|
||||
in use. The queue registry is provided as a means for kernel aware
|
||||
debuggers to locate queues 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
|
||||
defined to be less than 1. */
|
||||
* in use. The queue registry is provided as a means for kernel aware
|
||||
* debuggers to locate queues 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
|
||||
* defined to be less than 1. */
|
||||
vQueueAddToRegistry( xQueue, "QPeek_Test_Queue" );
|
||||
|
||||
/* Create the demo tasks and pass it the queue just created. We are
|
||||
passing the queue handle by value so it does not matter that it is declared
|
||||
on the stack here. */
|
||||
* passing the queue handle by value so it does not matter that it is declared
|
||||
* on the stack here. */
|
||||
xTaskCreate( prvLowPriorityPeekTask, "PeekL", configMINIMAL_STACK_SIZE, ( void * ) xQueue, qpeekLOW_PRIORITY, NULL );
|
||||
xTaskCreate( prvMediumPriorityPeekTask, "PeekM", configMINIMAL_STACK_SIZE, ( void * ) xQueue, qpeekMEDIUM_PRIORITY, &xMediumPriorityTask );
|
||||
xTaskCreate( prvHighPriorityPeekTask, "PeekH1", configMINIMAL_STACK_SIZE, ( void * ) xQueue, qpeekHIGH_PRIORITY, &xHighPriorityTask );
|
||||
|
|
@ -106,10 +106,10 @@ QueueHandle_t xQueue;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvHighestPriorityPeekTask( void *pvParameters )
|
||||
static void prvHighestPriorityPeekTask( void * pvParameters )
|
||||
{
|
||||
QueueHandle_t xQueue = ( QueueHandle_t ) pvParameters;
|
||||
uint32_t ulValue;
|
||||
QueueHandle_t xQueue = ( QueueHandle_t ) pvParameters;
|
||||
uint32_t ulValue;
|
||||
|
||||
#ifdef USE_STDIO
|
||||
{
|
||||
|
|
@ -122,10 +122,10 @@ uint32_t ulValue;
|
|||
}
|
||||
#endif
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Try peeking from the queue. The queue should be empty so we will
|
||||
block, allowing the high priority task to execute. */
|
||||
* block, allowing the high priority task to execute. */
|
||||
if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
|
||||
{
|
||||
/* We expected to have received something by the time we unblock. */
|
||||
|
|
@ -133,11 +133,11 @@ uint32_t ulValue;
|
|||
}
|
||||
|
||||
/* When we reach here the high and medium priority tasks should still
|
||||
be blocked on the queue. We unblocked because the low priority task
|
||||
wrote a value to the queue, which we should have peeked. Peeking the
|
||||
data (rather than receiving it) will leave the data on the queue, so
|
||||
the high priority task should then have also been unblocked, but not
|
||||
yet executed. */
|
||||
* be blocked on the queue. We unblocked because the low priority task
|
||||
* wrote a value to the queue, which we should have peeked. Peeking the
|
||||
* data (rather than receiving it) will leave the data on the queue, so
|
||||
* the high priority task should then have also been unblocked, but not
|
||||
* yet executed. */
|
||||
if( ulValue != 0x11223344 )
|
||||
{
|
||||
/* We did not receive the expected value. */
|
||||
|
|
@ -151,9 +151,10 @@ uint32_t ulValue;
|
|||
}
|
||||
|
||||
/* Now we are going to actually receive the data, so when the high
|
||||
priority task runs it will find the queue empty and return to the
|
||||
blocked state. */
|
||||
* priority task runs it will find the queue empty and return to the
|
||||
* blocked state. */
|
||||
ulValue = 0;
|
||||
|
||||
if( xQueueReceive( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
|
||||
{
|
||||
/* We expected to receive the value. */
|
||||
|
|
@ -163,12 +164,12 @@ uint32_t ulValue;
|
|||
if( ulValue != 0x11223344 )
|
||||
{
|
||||
/* We did not receive the expected value - which should have been
|
||||
the same value as was peeked. */
|
||||
* the same value as was peeked. */
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
/* Now we will block again as the queue is once more empty. The low
|
||||
priority task can then execute again. */
|
||||
* priority task can then execute again. */
|
||||
if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
|
||||
{
|
||||
/* We expected to have received something by the time we unblock. */
|
||||
|
|
@ -176,7 +177,7 @@ uint32_t ulValue;
|
|||
}
|
||||
|
||||
/* When we get here the low priority task should have again written to the
|
||||
queue. */
|
||||
* queue. */
|
||||
if( ulValue != 0x01234567 )
|
||||
{
|
||||
/* We did not receive the expected value. */
|
||||
|
|
@ -190,16 +191,14 @@ uint32_t ulValue;
|
|||
}
|
||||
|
||||
/* We only peeked the data, so suspending ourselves now should enable
|
||||
the high priority task to also peek the data. The high priority task
|
||||
will have been unblocked when we peeked the data as we left the data
|
||||
in the queue. */
|
||||
* the high priority task to also peek the data. The high priority task
|
||||
* will have been unblocked when we peeked the data as we left the data
|
||||
* in the queue. */
|
||||
vTaskSuspend( NULL );
|
||||
|
||||
|
||||
|
||||
/* This time we are going to do the same as the above test, but the
|
||||
high priority task is going to receive the data, rather than peek it.
|
||||
This means that the medium priority task should never peek the value. */
|
||||
* high priority task is going to receive the data, rather than peek it.
|
||||
* This means that the medium priority task should never peek the value. */
|
||||
if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -215,16 +214,16 @@ uint32_t ulValue;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvHighPriorityPeekTask( void *pvParameters )
|
||||
static void prvHighPriorityPeekTask( void * pvParameters )
|
||||
{
|
||||
QueueHandle_t xQueue = ( QueueHandle_t ) pvParameters;
|
||||
uint32_t ulValue;
|
||||
QueueHandle_t xQueue = ( QueueHandle_t ) pvParameters;
|
||||
uint32_t ulValue;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Try peeking from the queue. The queue should be empty so we will
|
||||
block, allowing the medium priority task to execute. Both the high
|
||||
and highest priority tasks will then be blocked on the queue. */
|
||||
* block, allowing the medium priority task to execute. Both the high
|
||||
* and highest priority tasks will then be blocked on the queue. */
|
||||
if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
|
||||
{
|
||||
/* We expected to have received something by the time we unblock. */
|
||||
|
|
@ -232,8 +231,8 @@ uint32_t ulValue;
|
|||
}
|
||||
|
||||
/* When we get here the highest priority task should have peeked the data
|
||||
(unblocking this task) then suspended (allowing this task to also peek
|
||||
the data). */
|
||||
* (unblocking this task) then suspended (allowing this task to also peek
|
||||
* the data). */
|
||||
if( ulValue != 0x01234567 )
|
||||
{
|
||||
/* We did not receive the expected value. */
|
||||
|
|
@ -247,14 +246,13 @@ uint32_t ulValue;
|
|||
}
|
||||
|
||||
/* We only peeked the data, so suspending ourselves now should enable
|
||||
the medium priority task to also peek the data. The medium priority task
|
||||
will have been unblocked when we peeked the data as we left the data
|
||||
in the queue. */
|
||||
* the medium priority task to also peek the data. The medium priority task
|
||||
* will have been unblocked when we peeked the data as we left the data
|
||||
* in the queue. */
|
||||
vTaskSuspend( NULL );
|
||||
|
||||
|
||||
/* This time we are going actually receive the value, so the medium
|
||||
priority task will never peek the data - we removed it from the queue. */
|
||||
* priority task will never peek the data - we removed it from the queue. */
|
||||
if( xQueueReceive( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -270,16 +268,16 @@ uint32_t ulValue;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvMediumPriorityPeekTask( void *pvParameters )
|
||||
static void prvMediumPriorityPeekTask( void * pvParameters )
|
||||
{
|
||||
QueueHandle_t xQueue = ( QueueHandle_t ) pvParameters;
|
||||
uint32_t ulValue;
|
||||
QueueHandle_t xQueue = ( QueueHandle_t ) pvParameters;
|
||||
uint32_t ulValue;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Try peeking from the queue. The queue should be empty so we will
|
||||
block, allowing the low priority task to execute. The highest, high
|
||||
and medium priority tasks will then all be blocked on the queue. */
|
||||
* block, allowing the low priority task to execute. The highest, high
|
||||
* and medium priority tasks will then all be blocked on the queue. */
|
||||
if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
|
||||
{
|
||||
/* We expected to have received something by the time we unblock. */
|
||||
|
|
@ -287,8 +285,8 @@ uint32_t ulValue;
|
|||
}
|
||||
|
||||
/* When we get here the high priority task should have peeked the data
|
||||
(unblocking this task) then suspended (allowing this task to also peek
|
||||
the data). */
|
||||
* (unblocking this task) then suspended (allowing this task to also peek
|
||||
* the data). */
|
||||
if( ulValue != 0x01234567 )
|
||||
{
|
||||
/* We did not receive the expected value. */
|
||||
|
|
@ -305,26 +303,27 @@ uint32_t ulValue;
|
|||
ulLoopCounter++;
|
||||
|
||||
/* Now we can suspend ourselves so the low priority task can execute
|
||||
again. */
|
||||
* again. */
|
||||
vTaskSuspend( NULL );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvLowPriorityPeekTask( void *pvParameters )
|
||||
static void prvLowPriorityPeekTask( void * pvParameters )
|
||||
{
|
||||
QueueHandle_t xQueue = ( QueueHandle_t ) pvParameters;
|
||||
uint32_t ulValue;
|
||||
QueueHandle_t xQueue = ( QueueHandle_t ) pvParameters;
|
||||
uint32_t ulValue;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Write some data to the queue. This should unblock the highest
|
||||
priority task that is waiting to peek data from the queue. */
|
||||
* priority task that is waiting to peek data from the queue. */
|
||||
ulValue = 0x11223344;
|
||||
|
||||
if( xQueueSendToBack( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
|
||||
{
|
||||
/* We were expecting the queue to be empty so we should not of
|
||||
had a problem writing to the queue. */
|
||||
* had a problem writing to the queue. */
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
|
|
@ -333,19 +332,20 @@ uint32_t ulValue;
|
|||
#endif
|
||||
|
||||
/* By the time we get here the data should have been removed from
|
||||
the queue. */
|
||||
* the queue. */
|
||||
if( uxQueueMessagesWaiting( xQueue ) != 0 )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
/* Write another value to the queue, again waking the highest priority
|
||||
task that is blocked on the queue. */
|
||||
* task that is blocked on the queue. */
|
||||
ulValue = 0x01234567;
|
||||
|
||||
if( xQueueSendToBack( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
|
||||
{
|
||||
/* We were expecting the queue to be empty so we should not of
|
||||
had a problem writing to the queue. */
|
||||
* had a problem writing to the queue. */
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
|
|
@ -354,8 +354,9 @@ uint32_t ulValue;
|
|||
#endif
|
||||
|
||||
/* All the other tasks should now have successfully peeked the data.
|
||||
The data is still in the queue so we should be able to receive it. */
|
||||
* The data is still in the queue so we should be able to receive it. */
|
||||
ulValue = 0;
|
||||
|
||||
if( xQueueReceive( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
|
||||
{
|
||||
/* We expected to receive the data. */
|
||||
|
|
@ -369,27 +370,28 @@ uint32_t ulValue;
|
|||
}
|
||||
|
||||
/* Lets just delay a while as this is an intensive test as we don't
|
||||
want to starve other tests of processing time. */
|
||||
* want to starve other tests of processing time. */
|
||||
vTaskDelay( qpeekSHORT_DELAY );
|
||||
|
||||
/* Unsuspend the other tasks so we can repeat the test - this time
|
||||
however not all the other tasks will peek the data as the high
|
||||
priority task is actually going to remove it from the queue. Send
|
||||
to front is used just to be different. As the queue is empty it
|
||||
makes no difference to the result. */
|
||||
* however not all the other tasks will peek the data as the high
|
||||
* priority task is actually going to remove it from the queue. Send
|
||||
* to front is used just to be different. As the queue is empty it
|
||||
* makes no difference to the result. */
|
||||
vTaskResume( xMediumPriorityTask );
|
||||
vTaskResume( xHighPriorityTask );
|
||||
vTaskResume( xHighestPriorityTask );
|
||||
|
||||
#if( configUSE_PREEMPTION == 0 )
|
||||
#if ( configUSE_PREEMPTION == 0 )
|
||||
taskYIELD();
|
||||
#endif
|
||||
|
||||
ulValue = 0xaabbaabb;
|
||||
|
||||
if( xQueueSendToFront( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
|
||||
{
|
||||
/* We were expecting the queue to be empty so we should not of
|
||||
had a problem writing to the queue. */
|
||||
* had a problem writing to the queue. */
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
|
|
@ -398,7 +400,7 @@ uint32_t ulValue;
|
|||
#endif
|
||||
|
||||
/* This time we should find that the queue is empty. The high priority
|
||||
task actually removed the data rather than just peeking it. */
|
||||
* task actually removed the data rather than just peeking it. */
|
||||
if( xQueuePeek( xQueue, &ulValue, qpeekNO_BLOCK ) != errQUEUE_EMPTY )
|
||||
{
|
||||
/* We expected to receive the data. */
|
||||
|
|
@ -406,13 +408,13 @@ uint32_t ulValue;
|
|||
}
|
||||
|
||||
/* Unsuspend the highest and high priority tasks so we can go back
|
||||
and repeat the whole thing. The medium priority task should not be
|
||||
suspended as it was not able to peek the data in this last case. */
|
||||
* and repeat the whole thing. The medium priority task should not be
|
||||
* suspended as it was not able to peek the data in this last case. */
|
||||
vTaskResume( xHighPriorityTask );
|
||||
vTaskResume( xHighestPriorityTask );
|
||||
|
||||
/* Lets just delay a while as this is an intensive test as we don't
|
||||
want to starve other tests of processing time. */
|
||||
* want to starve other tests of processing time. */
|
||||
vTaskDelay( qpeekSHORT_DELAY );
|
||||
}
|
||||
}
|
||||
|
|
@ -421,10 +423,10 @@ uint32_t ulValue;
|
|||
/* This is called to check that all the created tasks are still running. */
|
||||
BaseType_t xAreQueuePeekTasksStillRunning( void )
|
||||
{
|
||||
static uint32_t ulLastLoopCounter = 0;
|
||||
static uint32_t ulLastLoopCounter = 0;
|
||||
|
||||
/* If the demo task is still running then we expect the loopcounter to
|
||||
have incremented since this function was last called. */
|
||||
* have incremented since this function was last called. */
|
||||
if( ulLastLoopCounter == ulLoopCounter )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -433,8 +435,7 @@ static uint32_t ulLastLoopCounter = 0;
|
|||
ulLastLoopCounter = ulLoopCounter;
|
||||
|
||||
/* Errors detected in the task itself will have latched xErrorDetected
|
||||
to true. */
|
||||
* to true. */
|
||||
|
||||
return ( BaseType_t ) !xErrorDetected;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,54 +45,54 @@
|
|||
#define qoLOOPS 5
|
||||
|
||||
/* The task that uses the queue. */
|
||||
static void prvQueueOverwriteTask( void *pvParameters );
|
||||
static void prvQueueOverwriteTask( void * pvParameters );
|
||||
|
||||
/* Variable that is incremented on each loop of prvQueueOverwriteTask() provided
|
||||
prvQueueOverwriteTask() has not found any errors. */
|
||||
* prvQueueOverwriteTask() has not found any errors. */
|
||||
static uint32_t ulLoopCounter = 0;
|
||||
|
||||
/* Set to pdFALSE if an error is discovered by the
|
||||
vQueueOverwritePeriodicISRDemo() function. */
|
||||
* vQueueOverwritePeriodicISRDemo() function. */
|
||||
static BaseType_t xISRTestStatus = pdPASS;
|
||||
|
||||
/* The queue that is accessed from the ISR. The queue accessed by the task is
|
||||
created inside the task itself. */
|
||||
* created inside the task itself. */
|
||||
static QueueHandle_t xISRQueue = NULL;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vStartQueueOverwriteTask( UBaseType_t uxPriority )
|
||||
{
|
||||
const UBaseType_t uxQueueLength = 1;
|
||||
const UBaseType_t uxQueueLength = 1;
|
||||
|
||||
/* Create the queue used by the ISR. xQueueOverwriteFromISR() should only
|
||||
be used on queues that have a length of 1. */
|
||||
* be used on queues that have a length of 1. */
|
||||
xISRQueue = xQueueCreate( uxQueueLength, ( UBaseType_t ) sizeof( uint32_t ) );
|
||||
|
||||
/* Create the test task. The queue used by the test task is created inside
|
||||
the task itself. */
|
||||
* the task itself. */
|
||||
xTaskCreate( prvQueueOverwriteTask, "QOver", configMINIMAL_STACK_SIZE, NULL, uxPriority, ( TaskHandle_t * ) NULL );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvQueueOverwriteTask( void *pvParameters )
|
||||
static void prvQueueOverwriteTask( void * pvParameters )
|
||||
{
|
||||
QueueHandle_t xTaskQueue;
|
||||
const UBaseType_t uxQueueLength = 1;
|
||||
uint32_t ulValue, ulStatus = pdPASS, x;
|
||||
QueueHandle_t xTaskQueue;
|
||||
const UBaseType_t uxQueueLength = 1;
|
||||
uint32_t ulValue, ulStatus = pdPASS, x;
|
||||
|
||||
/* The parameter is not used. */
|
||||
( void ) pvParameters;
|
||||
|
||||
/* Create the queue. xQueueOverwrite() should only be used on queues that
|
||||
have a length of 1. */
|
||||
* have a length of 1. */
|
||||
xTaskQueue = xQueueCreate( uxQueueLength, ( UBaseType_t ) sizeof( uint32_t ) );
|
||||
configASSERT( xTaskQueue );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* The queue is empty. Writing to the queue then reading from the queue
|
||||
should return the item written. */
|
||||
* should return the item written. */
|
||||
ulValue = 10;
|
||||
xQueueOverwrite( xTaskQueue, &ulValue );
|
||||
|
||||
|
|
@ -105,15 +105,16 @@ uint32_t ulValue, ulStatus = pdPASS, x;
|
|||
}
|
||||
|
||||
/* Now try writing to the queue several times. Each time the value
|
||||
in the queue should get overwritten. */
|
||||
* in the queue should get overwritten. */
|
||||
for( x = 0; x < qoLOOPS; x++ )
|
||||
{
|
||||
/* Write to the queue. */
|
||||
xQueueOverwrite( xTaskQueue, &x );
|
||||
|
||||
/* Check the value in the queue is that written, even though the
|
||||
queue was not necessarily empty. */
|
||||
* queue was not necessarily empty. */
|
||||
xQueuePeek( xTaskQueue, &ulValue, qoDONT_BLOCK );
|
||||
|
||||
if( ulValue != x )
|
||||
{
|
||||
ulStatus = pdFAIL;
|
||||
|
|
@ -137,11 +138,11 @@ uint32_t ulValue, ulStatus = pdPASS, x;
|
|||
if( ulStatus != pdFAIL )
|
||||
{
|
||||
/* Increment a counter to show this task is still running without
|
||||
error. */
|
||||
* error. */
|
||||
ulLoopCounter++;
|
||||
}
|
||||
|
||||
#if( configUSE_PREEMPTION == 0 )
|
||||
#if ( configUSE_PREEMPTION == 0 )
|
||||
taskYIELD();
|
||||
#endif
|
||||
}
|
||||
|
|
@ -150,7 +151,7 @@ uint32_t ulValue, ulStatus = pdPASS, x;
|
|||
|
||||
BaseType_t xIsQueueOverwriteTaskStillRunning( void )
|
||||
{
|
||||
BaseType_t xReturn;
|
||||
BaseType_t xReturn;
|
||||
|
||||
if( xISRTestStatus != pdPASS )
|
||||
{
|
||||
|
|
@ -174,51 +175,57 @@ BaseType_t xReturn;
|
|||
|
||||
void vQueueOverwritePeriodicISRDemo( void )
|
||||
{
|
||||
static uint32_t ulCallCount = 0;
|
||||
const uint32_t ulTx1 = 10UL, ulTx2 = 20UL, ulNumberOfSwitchCases = 3UL;
|
||||
uint32_t ulRx;
|
||||
static uint32_t ulCallCount = 0;
|
||||
const uint32_t ulTx1 = 10UL, ulTx2 = 20UL, ulNumberOfSwitchCases = 3UL;
|
||||
uint32_t ulRx;
|
||||
|
||||
/* This function should be called from an interrupt, such as the tick hook
|
||||
function vApplicationTickHook(). */
|
||||
* function vApplicationTickHook(). */
|
||||
|
||||
configASSERT( xISRQueue );
|
||||
|
||||
switch( ulCallCount )
|
||||
{
|
||||
case 0:
|
||||
|
||||
/* The queue is empty. Write ulTx1 to the queue. In this demo the
|
||||
last parameter is not used because there are no tasks blocked on
|
||||
this queue. */
|
||||
* last parameter is not used because there are no tasks blocked on
|
||||
* this queue. */
|
||||
xQueueOverwriteFromISR( xISRQueue, &ulTx1, NULL );
|
||||
|
||||
/* Peek the queue to check it holds the expected value. */
|
||||
xQueuePeekFromISR( xISRQueue, &ulRx );
|
||||
|
||||
if( ulRx != ulTx1 )
|
||||
{
|
||||
xISRTestStatus = pdFAIL;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 1:
|
||||
|
||||
/* The queue already holds ulTx1. Overwrite the value in the queue
|
||||
with ulTx2. */
|
||||
* with ulTx2. */
|
||||
xQueueOverwriteFromISR( xISRQueue, &ulTx2, NULL );
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
/* Read from the queue to empty the queue again. The value read
|
||||
should be ulTx2. */
|
||||
* should be ulTx2. */
|
||||
xQueueReceiveFromISR( xISRQueue, &ulRx, NULL );
|
||||
|
||||
if( ulRx != ulTx2 )
|
||||
{
|
||||
xISRTestStatus = pdFAIL;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
/* Run the next case in the switch statement above next time this function
|
||||
is called. */
|
||||
* is called. */
|
||||
ulCallCount++;
|
||||
|
||||
if( ulCallCount >= ulNumberOfSwitchCases )
|
||||
|
|
@ -227,4 +234,3 @@ uint32_t ulRx;
|
|||
ulCallCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -51,43 +51,43 @@
|
|||
/* Demo includes. */
|
||||
#include "QueueSetPolling.h"
|
||||
|
||||
#if( configUSE_QUEUE_SETS == 1 ) /* Remove tests if queue sets are not defined. */
|
||||
#if ( configUSE_QUEUE_SETS == 1 ) /* Remove tests if queue sets are not defined. */
|
||||
|
||||
/* The length of each created queue. */
|
||||
#define setpollQUEUE_LENGTH 10
|
||||
#define setpollQUEUE_LENGTH 10
|
||||
|
||||
/* Block times used in this demo. A block time or 0 means "don't block". */
|
||||
#define setpollDONT_BLOCK 0
|
||||
#define setpollDONT_BLOCK 0
|
||||
|
||||
/* The ISR sends to the queue every setpollISR_TX_PERIOD ticks. */
|
||||
#define queuesetISR_TX_PERIOD ( 50UL )
|
||||
#define queuesetISR_TX_PERIOD ( 50UL )
|
||||
|
||||
/*
|
||||
* The task that reads from the queue set.
|
||||
*/
|
||||
static void prvQueueSetReceivingTask( void *pvParameters );
|
||||
static void prvQueueSetReceivingTask( void * pvParameters );
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* The queue that is added to the set. */
|
||||
static QueueHandle_t xQueue = NULL;
|
||||
static QueueHandle_t xQueue = NULL;
|
||||
|
||||
/* The handle of the queue set to which the queue is added. */
|
||||
static QueueSetHandle_t xQueueSet = NULL;
|
||||
static QueueSetHandle_t xQueueSet = NULL;
|
||||
|
||||
/* Set to pdFAIL if an error is detected by any queue set task.
|
||||
ulCycleCounter will only be incremented if xQueueSetTasksSatus equals pdPASS. */
|
||||
static volatile BaseType_t xQueueSetPollStatus = pdPASS;
|
||||
* ulCycleCounter will only be incremented if xQueueSetTasksSatus equals pdPASS. */
|
||||
static volatile BaseType_t xQueueSetPollStatus = pdPASS;
|
||||
|
||||
/* Counter used to ensure the task is still running. */
|
||||
static uint32_t ulCycleCounter = 0;
|
||||
static uint32_t ulCycleCounter = 0;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vStartQueueSetPollingTask( void )
|
||||
{
|
||||
void vStartQueueSetPollingTask( void )
|
||||
{
|
||||
/* Create the queue that is added to the set, the set, and add the queue to
|
||||
the set. */
|
||||
* the set. */
|
||||
xQueue = xQueueCreate( setpollQUEUE_LENGTH, sizeof( uint32_t ) );
|
||||
xQueueSet = xQueueCreateSet( setpollQUEUE_LENGTH );
|
||||
|
||||
|
|
@ -98,28 +98,28 @@ void vStartQueueSetPollingTask( void )
|
|||
/* Create the task. */
|
||||
xTaskCreate( prvQueueSetReceivingTask, "SetPoll", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvQueueSetReceivingTask( void *pvParameters )
|
||||
{
|
||||
uint32_t ulReceived, ulExpected = 0;
|
||||
QueueHandle_t xActivatedQueue;
|
||||
static void prvQueueSetReceivingTask( void * pvParameters )
|
||||
{
|
||||
uint32_t ulReceived, ulExpected = 0;
|
||||
QueueHandle_t xActivatedQueue;
|
||||
|
||||
/* Remove compiler warnings. */
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Is a message waiting? A block time is not used to ensure the queue
|
||||
set is polled while it is being written to from an interrupt. */
|
||||
* set is polled while it is being written to from an interrupt. */
|
||||
xActivatedQueue = xQueueSelectFromSet( xQueueSet, setpollDONT_BLOCK );
|
||||
|
||||
if( xActivatedQueue != NULL )
|
||||
{
|
||||
/* Reading from the queue should pass with a zero block time as
|
||||
this task will only run when something has been posted to a task
|
||||
in the queue set. */
|
||||
* this task will only run when something has been posted to a task
|
||||
* in the queue set. */
|
||||
if( xQueueReceive( xActivatedQueue, &ulReceived, setpollDONT_BLOCK ) != pdPASS )
|
||||
{
|
||||
xQueueSetPollStatus = pdFAIL;
|
||||
|
|
@ -140,16 +140,17 @@ QueueHandle_t xActivatedQueue;
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vQueueSetPollingInterruptAccess( void )
|
||||
{
|
||||
static uint32_t ulCallCount = 0, ulValueToSend = 0;
|
||||
void vQueueSetPollingInterruptAccess( void )
|
||||
{
|
||||
static uint32_t ulCallCount = 0, ulValueToSend = 0;
|
||||
|
||||
/* It is intended that this function is called from the tick hook
|
||||
function, so each call is one tick period apart. */
|
||||
* function, so each call is one tick period apart. */
|
||||
ulCallCount++;
|
||||
|
||||
if( ulCallCount > queuesetISR_TX_PERIOD )
|
||||
{
|
||||
ulCallCount = 0;
|
||||
|
|
@ -160,12 +161,12 @@ static uint32_t ulCallCount = 0, ulValueToSend = 0;
|
|||
ulValueToSend++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
BaseType_t xAreQueueSetPollTasksStillRunning( void )
|
||||
{
|
||||
static uint32_t ulLastCycleCounter = 0;
|
||||
BaseType_t xAreQueueSetPollTasksStillRunning( void )
|
||||
{
|
||||
static uint32_t ulLastCycleCounter = 0;
|
||||
|
||||
if( ulLastCycleCounter == ulCycleCounter )
|
||||
{
|
||||
|
|
@ -175,7 +176,7 @@ static uint32_t ulLastCycleCounter = 0;
|
|||
ulLastCycleCounter = ulCycleCounter;
|
||||
|
||||
return xQueueSetPollStatus;
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -54,7 +54,7 @@
|
|||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Implements the task that receives a stream of bytes from the interrupt. */
|
||||
static void prvReceivingTask( void *pvParameters );
|
||||
static void prvReceivingTask( void * pvParameters );
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
|
|
@ -62,19 +62,19 @@ static void prvReceivingTask( void *pvParameters );
|
|||
static StreamBufferHandle_t xStreamBuffer = NULL;
|
||||
|
||||
/* The string that is sent from the interrupt to the task four bytes at a
|
||||
time. Must be multiple of 4 bytes long as the ISR sends 4 bytes at a time*/
|
||||
* time. Must be multiple of 4 bytes long as the ISR sends 4 bytes at a time*/
|
||||
static const char * pcStringToSend = "_____Hello FreeRTOS_____";
|
||||
|
||||
/* The string to task is looking for, which must be a substring of
|
||||
pcStringToSend. */
|
||||
* pcStringToSend. */
|
||||
static const char * pcStringToReceive = "Hello FreeRTOS";
|
||||
|
||||
/* Set to pdFAIL if anything unexpected happens. */
|
||||
static BaseType_t xDemoStatus = pdPASS;
|
||||
|
||||
/* Incremented each time pcStringToReceive is correctly received, provided no
|
||||
errors have occurred. Used so the check task can check this task is still
|
||||
running as expected. */
|
||||
* errors have occurred. Used so the check task can check this task is still
|
||||
* running as expected. */
|
||||
static uint32_t ulCycleCount = 0;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
|
@ -82,7 +82,7 @@ static uint32_t ulCycleCount = 0;
|
|||
void vStartStreamBufferInterruptDemo( void )
|
||||
{
|
||||
/* Create the stream buffer that sends data from the interrupt to the
|
||||
task, and create the task. */
|
||||
* task, and create the task. */
|
||||
xStreamBuffer = xStreamBufferCreate( /* The buffer length in bytes. */
|
||||
sbiSTREAM_BUFFER_LENGTH_BYTES,
|
||||
/* The stream buffer's trigger level. */
|
||||
|
|
@ -97,16 +97,16 @@ void vStartStreamBufferInterruptDemo( void )
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvReceivingTask( void *pvParameters )
|
||||
static void prvReceivingTask( void * pvParameters )
|
||||
{
|
||||
char cRxBuffer[ 20 ];
|
||||
BaseType_t xNextByte = 0;
|
||||
char cRxBuffer[ 20 ];
|
||||
BaseType_t xNextByte = 0;
|
||||
|
||||
/* Remove warning about unused parameters. */
|
||||
( void ) pvParameters;
|
||||
|
||||
/* Make sure the string will fit in the Rx buffer, including the NULL
|
||||
terminator. */
|
||||
* terminator. */
|
||||
configASSERT( sizeof( cRxBuffer ) > strlen( pcStringToReceive ) );
|
||||
|
||||
/* Make sure the stream buffer has been created. */
|
||||
|
|
@ -115,37 +115,38 @@ BaseType_t xNextByte = 0;
|
|||
/* Start with the Rx buffer in a known state. */
|
||||
memset( cRxBuffer, 0x00, sizeof( cRxBuffer ) );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Keep receiving characters until the end of the string is received.
|
||||
Note: An infinite block time is used to simplify the example. Infinite
|
||||
block times are not recommended in production code as they do not allow
|
||||
for error recovery. */
|
||||
* Note: An infinite block time is used to simplify the example. Infinite
|
||||
* block times are not recommended in production code as they do not allow
|
||||
* for error recovery. */
|
||||
xStreamBufferReceive( /* The stream buffer data is being received from. */
|
||||
xStreamBuffer,
|
||||
/* Where to place received data. */
|
||||
( void * ) &( cRxBuffer[ xNextByte ] ),
|
||||
/* The number of bytes to receive. */
|
||||
sizeof( char ),
|
||||
|
||||
/* The time to wait for the next data if the buffer
|
||||
is empty. */
|
||||
* is empty. */
|
||||
portMAX_DELAY );
|
||||
|
||||
/* If xNextByte is 0 then this task is looking for the start of the
|
||||
string, which is 'H'. */
|
||||
* string, which is 'H'. */
|
||||
if( xNextByte == 0 )
|
||||
{
|
||||
if( cRxBuffer[ xNextByte ] == 'H' )
|
||||
{
|
||||
/* The start of the string has been found. Now receive
|
||||
characters until the end of the string is found. */
|
||||
* characters until the end of the string is found. */
|
||||
xNextByte++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Receiving characters while looking for the end of the string,
|
||||
which is an 'S'. */
|
||||
* which is an 'S'. */
|
||||
if( cRxBuffer[ xNextByte ] == 'S' )
|
||||
{
|
||||
/* The string has now been received. Check its validity. */
|
||||
|
|
@ -155,12 +156,12 @@ BaseType_t xNextByte = 0;
|
|||
}
|
||||
|
||||
/* Return to start looking for the beginning of the string
|
||||
again. */
|
||||
* again. */
|
||||
memset( cRxBuffer, 0x00, sizeof( cRxBuffer ) );
|
||||
xNextByte = 0;
|
||||
|
||||
/* Increment the cycle count as an indication to the check task
|
||||
that this demo is still running. */
|
||||
* that this demo is still running. */
|
||||
if( xDemoStatus == pdPASS )
|
||||
{
|
||||
ulCycleCount++;
|
||||
|
|
@ -169,7 +170,7 @@ BaseType_t xNextByte = 0;
|
|||
else
|
||||
{
|
||||
/* Receive the next character the next time around, while
|
||||
continuing to look for the end of the string. */
|
||||
* continuing to look for the end of the string. */
|
||||
xNextByte++;
|
||||
|
||||
configASSERT( ( size_t ) xNextByte < sizeof( cRxBuffer ) );
|
||||
|
|
@ -181,12 +182,13 @@ BaseType_t xNextByte = 0;
|
|||
|
||||
void vBasicStreamBufferSendFromISR( void )
|
||||
{
|
||||
static size_t xNextByteToSend = 0;
|
||||
const BaseType_t xCallsBetweenSends = 100, xBytesToSend = 4;
|
||||
static BaseType_t xCallCount = 0;
|
||||
static size_t xNextByteToSend = 0;
|
||||
const BaseType_t xCallsBetweenSends = 100, xBytesToSend = 4;
|
||||
static BaseType_t xCallCount = 0;
|
||||
|
||||
/* Is it time to write to the stream buffer again? */
|
||||
xCallCount++;
|
||||
|
||||
if( xCallCount > xCallsBetweenSends )
|
||||
{
|
||||
xCallCount = 0;
|
||||
|
|
@ -198,7 +200,7 @@ static BaseType_t xCallCount = 0;
|
|||
NULL );
|
||||
|
||||
/* Send the next four bytes the next time around, wrapping to the start
|
||||
of the string if necessary. */
|
||||
* of the string if necessary. */
|
||||
xNextByteToSend += xBytesToSend;
|
||||
|
||||
if( xNextByteToSend >= strlen( pcStringToSend ) )
|
||||
|
|
@ -211,7 +213,7 @@ static BaseType_t xCallCount = 0;
|
|||
|
||||
BaseType_t xIsInterruptStreamBufferDemoStillRunning( void )
|
||||
{
|
||||
uint32_t ulLastCycleCount = 0;
|
||||
uint32_t ulLastCycleCount = 0;
|
||||
|
||||
/* Check the demo is still running. */
|
||||
if( ulLastCycleCount == ulCycleCount )
|
||||
|
|
@ -225,4 +227,3 @@ uint32_t ulLastCycleCount = 0;
|
|||
|
||||
return xDemoStatus;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@
|
|||
/*
|
||||
* Implementation of the task that gets notified.
|
||||
*/
|
||||
static void prvNotifiedTask( void *pvParameters );
|
||||
static void prvNotifiedTask( void * pvParameters );
|
||||
|
||||
/*
|
||||
* Performs a few initial tests that can be done prior to creating the second
|
||||
|
|
@ -98,8 +98,8 @@ static volatile uint32_t ulNotifyCycleCount = 0;
|
|||
static TaskHandle_t xTaskToNotify = NULL;
|
||||
|
||||
/* Used to count the notifications sent to the task from a software timer and
|
||||
the number of notifications received by the task from the software timer. The
|
||||
two should stay synchronised. */
|
||||
* the number of notifications received by the task from the software timer. The
|
||||
* two should stay synchronised. */
|
||||
static uint32_t ulTimerNotificationsReceived = 0UL, ulTimerNotificationsSent = 0UL;
|
||||
|
||||
/* The timer used to notify the task. */
|
||||
|
|
@ -113,7 +113,7 @@ static size_t uxNextRand = 0;
|
|||
void vStartTaskNotifyTask( void )
|
||||
{
|
||||
/* Create the task that performs some tests by itself, then loops around
|
||||
being notified by both a software timer and an interrupt. */
|
||||
* being notified by both a software timer and an interrupt. */
|
||||
xTaskCreate( prvNotifiedTask, /* Function that implements the task. */
|
||||
"Notified", /* Text name for the task - for debugging only - not used by the kernel. */
|
||||
notifyNOTIFIED_TASK_STACK_SIZE, /* Task's stack size in words, not bytes!. */
|
||||
|
|
@ -128,17 +128,17 @@ void vStartTaskNotifyTask( void )
|
|||
|
||||
static void prvSingleTaskTests( void )
|
||||
{
|
||||
const TickType_t xTicksToWait = pdMS_TO_TICKS( 100UL );
|
||||
BaseType_t xReturned;
|
||||
uint32_t ulNotifiedValue, ulLoop, ulNotifyingValue, ulPreviousValue, ulExpectedValue;
|
||||
TickType_t xTimeOnEntering;
|
||||
const uint32_t ulFirstNotifiedConst = 100001UL, ulSecondNotifiedValueConst = 5555UL, ulMaxLoops = 5UL;
|
||||
const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
|
||||
TimerHandle_t xSingleTaskTimer;
|
||||
const TickType_t xTicksToWait = pdMS_TO_TICKS( 100UL );
|
||||
BaseType_t xReturned;
|
||||
uint32_t ulNotifiedValue, ulLoop, ulNotifyingValue, ulPreviousValue, ulExpectedValue;
|
||||
TickType_t xTimeOnEntering;
|
||||
const uint32_t ulFirstNotifiedConst = 100001UL, ulSecondNotifiedValueConst = 5555UL, ulMaxLoops = 5UL;
|
||||
const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
|
||||
TimerHandle_t xSingleTaskTimer;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
Check blocking when there are no notifications. */
|
||||
* Check blocking when there are no notifications. */
|
||||
xTimeOnEntering = xTaskGetTickCount();
|
||||
xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, xTicksToWait );
|
||||
( void ) xReturned; /* In case configASSERT() is not defined. */
|
||||
|
|
@ -148,6 +148,7 @@ TimerHandle_t xSingleTaskTimer;
|
|||
{
|
||||
xErrorStatus = pdFAIL;
|
||||
}
|
||||
|
||||
configASSERT( xReturned == pdFAIL );
|
||||
configASSERT( ulNotifiedValue == 0UL );
|
||||
( void ) xReturned; /* In case configASSERT() is not defined. */
|
||||
|
|
@ -155,15 +156,14 @@ TimerHandle_t xSingleTaskTimer;
|
|||
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
Check no blocking when notifications are pending. First notify itself -
|
||||
this would not be a normal thing to do and is done here for test purposes
|
||||
only. */
|
||||
* Check no blocking when notifications are pending. First notify itself -
|
||||
* this would not be a normal thing to do and is done here for test purposes
|
||||
* only. */
|
||||
xReturned = xTaskNotifyAndQuery( xTaskToNotify, ulFirstNotifiedConst, eSetValueWithoutOverwrite, &ulPreviousValue );
|
||||
|
||||
/* Even through the 'without overwrite' action was used the update should
|
||||
have been successful. */
|
||||
* have been successful. */
|
||||
configASSERT( xReturned == pdPASS );
|
||||
( void ) xReturned; /* In case configASSERT() is not defined. */
|
||||
|
||||
|
|
@ -181,7 +181,7 @@ TimerHandle_t xSingleTaskTimer;
|
|||
}
|
||||
|
||||
/* The task should have been notified, and the notified value should
|
||||
be equal to ulFirstNotifiedConst. */
|
||||
* be equal to ulFirstNotifiedConst. */
|
||||
configASSERT( xReturned == pdPASS );
|
||||
configASSERT( ulNotifiedValue == ulFirstNotifiedConst );
|
||||
( void ) xReturned; /* In case configASSERT() is not defined. */
|
||||
|
|
@ -192,13 +192,11 @@ TimerHandle_t xSingleTaskTimer;
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
Check the non-overwriting functionality. The notification is done twice
|
||||
using two different notification values. The action says don't overwrite so
|
||||
only the first notification should pass and the value read back should also
|
||||
be that used with the first notification. */
|
||||
* Check the non-overwriting functionality. The notification is done twice
|
||||
* using two different notification values. The action says don't overwrite so
|
||||
* only the first notification should pass and the value read back should also
|
||||
* be that used with the first notification. */
|
||||
xReturned = xTaskNotify( xTaskToNotify, ulFirstNotifiedConst, eSetValueWithoutOverwrite );
|
||||
configASSERT( xReturned == pdPASS );
|
||||
( void ) xReturned; /* In case configASSERT() is not defined. */
|
||||
|
|
@ -208,7 +206,7 @@ TimerHandle_t xSingleTaskTimer;
|
|||
( void ) xReturned; /* In case configASSERT() is not defined. */
|
||||
|
||||
/* Waiting for the notification should now return immediately so a block
|
||||
time of zero is used. */
|
||||
* time of zero is used. */
|
||||
xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );
|
||||
|
||||
configASSERT( xReturned == pdPASS );
|
||||
|
|
@ -218,13 +216,11 @@ TimerHandle_t xSingleTaskTimer;
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
Do the same again, only this time use the overwriting version. This time
|
||||
both notifications should pass, and the value written the second time should
|
||||
overwrite the value written the first time, and so be the value that is read
|
||||
back. */
|
||||
* Do the same again, only this time use the overwriting version. This time
|
||||
* both notifications should pass, and the value written the second time should
|
||||
* overwrite the value written the first time, and so be the value that is read
|
||||
* back. */
|
||||
xReturned = xTaskNotify( xTaskToNotify, ulFirstNotifiedConst, eSetValueWithOverwrite );
|
||||
configASSERT( xReturned == pdPASS );
|
||||
( void ) xReturned; /* In case configASSERT() is not defined. */
|
||||
|
|
@ -239,11 +235,10 @@ TimerHandle_t xSingleTaskTimer;
|
|||
|
||||
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
Check notifications with no action pass without updating the value. Even
|
||||
though ulFirstNotifiedConst is used as the value the value read back should
|
||||
remain at ulSecondNotifiedConst. */
|
||||
* Check notifications with no action pass without updating the value. Even
|
||||
* though ulFirstNotifiedConst is used as the value the value read back should
|
||||
* remain at ulSecondNotifiedConst. */
|
||||
xReturned = xTaskNotify( xTaskToNotify, ulFirstNotifiedConst, eNoAction );
|
||||
configASSERT( xReturned == pdPASS );
|
||||
( void ) xReturned; /* In case configASSERT() is not defined. */
|
||||
|
|
@ -251,13 +246,10 @@ TimerHandle_t xSingleTaskTimer;
|
|||
configASSERT( ulNotifiedValue == ulSecondNotifiedValueConst );
|
||||
( void ) ulNotifiedValue; /* In case configASSERT() is not defined. */
|
||||
|
||||
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
Check incrementing values. Send ulMaxLoop increment notifications, then
|
||||
ensure the received value is as expected - which should be
|
||||
ulSecondNotificationValueConst plus how ever many times to loop iterated. */
|
||||
* Check incrementing values. Send ulMaxLoop increment notifications, then
|
||||
* ensure the received value is as expected - which should be
|
||||
* ulSecondNotificationValueConst plus how ever many times to loop iterated. */
|
||||
for( ulLoop = 0; ulLoop < ulMaxLoops; ulLoop++ )
|
||||
{
|
||||
xReturned = xTaskNotify( xTaskToNotify, 0, eIncrement );
|
||||
|
|
@ -279,12 +271,11 @@ TimerHandle_t xSingleTaskTimer;
|
|||
|
||||
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
Check all bits can be set by notifying the task with one additional bit set
|
||||
on each notification, and exiting the loop when all the bits are found to be
|
||||
set. As there are 32-bits the loop should execute 32 times before all the
|
||||
bits are found to be set. */
|
||||
* Check all bits can be set by notifying the task with one additional bit set
|
||||
* on each notification, and exiting the loop when all the bits are found to be
|
||||
* set. As there are 32-bits the loop should execute 32 times before all the
|
||||
* bits are found to be set. */
|
||||
ulNotifyingValue = 0x01;
|
||||
ulLoop = 0;
|
||||
|
||||
|
|
@ -297,8 +288,8 @@ TimerHandle_t xSingleTaskTimer;
|
|||
xTaskNotify( xTaskToNotify, ulNotifyingValue, eSetBits );
|
||||
|
||||
/* Wait for the notified value - which of course will already be
|
||||
available. Don't clear the bits on entry or exit as this loop is exited
|
||||
when all the bits are set. */
|
||||
* available. Don't clear the bits on entry or exit as this loop is exited
|
||||
* when all the bits are set. */
|
||||
xReturned = xTaskNotifyWait( 0, 0, &ulNotifiedValue, 0 );
|
||||
configASSERT( xReturned == pdPASS );
|
||||
( void ) xReturned; /* In case configASSERT() is not defined. */
|
||||
|
|
@ -307,34 +298,32 @@ TimerHandle_t xSingleTaskTimer;
|
|||
|
||||
/* Use the next bit on the next iteration around this loop. */
|
||||
ulNotifyingValue <<= 1UL;
|
||||
|
||||
} while ( ulNotifiedValue != notifyUINT32_MAX );
|
||||
} while( ulNotifiedValue != notifyUINT32_MAX );
|
||||
|
||||
/* As a 32-bit value was used the loop should have executed 32 times before
|
||||
all the bits were set. */
|
||||
* all the bits were set. */
|
||||
configASSERT( ulLoop == 32 );
|
||||
|
||||
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
Check bits are cleared on entry but not on exit when a notification fails
|
||||
to arrive before timing out - both with and without a timeout value. Wait
|
||||
for the notification again - but this time it is not given by anything and
|
||||
should return pdFAIL. The parameters are set to clear bit zero on entry and
|
||||
bit one on exit. As no notification was received only the bit cleared on
|
||||
entry should actually get cleared. */
|
||||
* Check bits are cleared on entry but not on exit when a notification fails
|
||||
* to arrive before timing out - both with and without a timeout value. Wait
|
||||
* for the notification again - but this time it is not given by anything and
|
||||
* should return pdFAIL. The parameters are set to clear bit zero on entry and
|
||||
* bit one on exit. As no notification was received only the bit cleared on
|
||||
* entry should actually get cleared. */
|
||||
xReturned = xTaskNotifyWait( ulBit0, ulBit1, &ulNotifiedValue, xTicksToWait );
|
||||
configASSERT( xReturned == pdFAIL );
|
||||
( void ) xReturned; /* In case configASSERT() is not defined. */
|
||||
|
||||
/* Notify the task with no action so as not to update the bits even though
|
||||
notifyUINT32_MAX is used as the notification value. */
|
||||
* notifyUINT32_MAX is used as the notification value. */
|
||||
xTaskNotify( xTaskToNotify, notifyUINT32_MAX, eNoAction );
|
||||
|
||||
/* Reading back the value should should find bit 0 is clear, as this was
|
||||
cleared on entry, but bit 1 is not clear as it will not have been cleared on
|
||||
exit as no notification was received. */
|
||||
* cleared on entry, but bit 1 is not clear as it will not have been cleared on
|
||||
* exit as no notification was received. */
|
||||
xReturned = xTaskNotifyWait( 0x00UL, 0x00UL, &ulNotifiedValue, 0 );
|
||||
configASSERT( xReturned == pdPASS );
|
||||
configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~ulBit0 ) );
|
||||
|
|
@ -342,22 +331,20 @@ TimerHandle_t xSingleTaskTimer;
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
Now try clearing the bit on exit. For that to happen a notification must be
|
||||
received, so the task is notified first. */
|
||||
* Now try clearing the bit on exit. For that to happen a notification must be
|
||||
* received, so the task is notified first. */
|
||||
xTaskNotify( xTaskToNotify, 0, eNoAction );
|
||||
xTaskNotifyWait( 0x00, ulBit1, &ulNotifiedValue, 0 );
|
||||
|
||||
/* However as the bit is cleared on exit, after the returned notification
|
||||
value is set, the returned notification value should not have the bit
|
||||
cleared... */
|
||||
* value is set, the returned notification value should not have the bit
|
||||
* cleared... */
|
||||
configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~ulBit0 ) );
|
||||
|
||||
/* ...but reading the value back again should find that the bit was indeed
|
||||
cleared internally. The returned value should be pdFAIL however as nothing
|
||||
has notified the task in the mean time. */
|
||||
* cleared internally. The returned value should be pdFAIL however as nothing
|
||||
* has notified the task in the mean time. */
|
||||
xReturned = xTaskNotifyWait( 0x00, 0x00, &ulNotifiedValue, 0 );
|
||||
configASSERT( xReturned == pdFAIL );
|
||||
configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~( ulBit0 | ulBit1 ) ) );
|
||||
|
|
@ -365,9 +352,8 @@ TimerHandle_t xSingleTaskTimer;
|
|||
|
||||
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
Now try querying the previous value while notifying a task. */
|
||||
* Now try querying the previous value while notifying a task. */
|
||||
xTaskNotifyAndQuery( xTaskToNotify, 0x00, eSetBits, &ulPreviousValue );
|
||||
configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~( ulBit0 | ulBit1 ) ) );
|
||||
|
||||
|
|
@ -377,54 +363,53 @@ TimerHandle_t xSingleTaskTimer;
|
|||
configASSERT( ulPreviousValue == 0 );
|
||||
|
||||
ulExpectedValue = 0;
|
||||
|
||||
for( ulLoop = 0x01; ulLoop < 0x80UL; ulLoop <<= 1UL )
|
||||
{
|
||||
/* Set the next bit up, and expect to receive the last bits set (so
|
||||
the previous value will not yet have the bit being set this time
|
||||
around). */
|
||||
* the previous value will not yet have the bit being set this time
|
||||
* around). */
|
||||
xTaskNotifyAndQuery( xTaskToNotify, ulLoop, eSetBits, &ulPreviousValue );
|
||||
configASSERT( ulExpectedValue == ulPreviousValue );
|
||||
ulExpectedValue |= ulLoop;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
Clear the previous notifications. */
|
||||
* Clear the previous notifications. */
|
||||
xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );
|
||||
|
||||
/* The task should not have any notifications pending, so an attempt to clear
|
||||
the notification state should fail. */
|
||||
* the notification state should fail. */
|
||||
configASSERT( xTaskNotifyStateClear( NULL ) == pdFALSE );
|
||||
|
||||
/* Get the task to notify itself. This is not a normal thing to do, and is
|
||||
only done here for test purposes. */
|
||||
* only done here for test purposes. */
|
||||
xTaskNotifyAndQuery( xTaskToNotify, ulFirstNotifiedConst, eSetValueWithoutOverwrite, &ulPreviousValue );
|
||||
|
||||
/* Now the notification state should be eNotified, so it should now be
|
||||
possible to clear the notification state. */
|
||||
* possible to clear the notification state. */
|
||||
configASSERT( xTaskNotifyStateClear( NULL ) == pdTRUE );
|
||||
configASSERT( xTaskNotifyStateClear( NULL ) == pdFALSE );
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
Clear bits in the notification value. */
|
||||
* Clear bits in the notification value. */
|
||||
|
||||
/* Get the task to set all bits its own notification value. This is not a
|
||||
normal thing to do, and is only done here for test purposes. */
|
||||
* normal thing to do, and is only done here for test purposes. */
|
||||
xTaskNotify( xTaskToNotify, notifyUINT32_MAX, eSetBits );
|
||||
|
||||
/* Now clear the top bytes - the returned value from the first call should
|
||||
indicate that previously all bits were set. */
|
||||
* indicate that previously all bits were set. */
|
||||
configASSERT( ulTaskNotifyValueClear( xTaskToNotify, notifyUINT32_HIGH_BYTE ) == notifyUINT32_MAX );
|
||||
|
||||
/* Next clear the bottom bytes - the returned value this time should indicate
|
||||
that the top byte was clear (before the bottom byte was cleared. */
|
||||
* that the top byte was clear (before the bottom byte was cleared. */
|
||||
configASSERT( ulTaskNotifyValueClear( xTaskToNotify, notifyUINT32_LOW_BYTE ) == ( notifyUINT32_MAX & ~notifyUINT32_HIGH_BYTE ) );
|
||||
|
||||
/* Next clear all bytes - the returned value should indicate that previously the
|
||||
high and low bytes were clear. */
|
||||
* high and low bytes were clear. */
|
||||
configASSERT( ulTaskNotifyValueClear( xTaskToNotify, notifyUINT32_MAX ) == ( notifyUINT32_MAX & ~notifyUINT32_HIGH_BYTE & ~notifyUINT32_LOW_BYTE ) );
|
||||
|
||||
/* Now all bits should be clear. */
|
||||
|
|
@ -433,14 +418,14 @@ TimerHandle_t xSingleTaskTimer;
|
|||
configASSERT( ulTaskNotifyValueClear( xTaskToNotify, notifyUINT32_MAX ) == 0 );
|
||||
|
||||
/* Now the notification state should be eNotified, so it should now be
|
||||
possible to clear the notification state. */
|
||||
* possible to clear the notification state. */
|
||||
configASSERT( xTaskNotifyStateClear( NULL ) == pdTRUE );
|
||||
configASSERT( xTaskNotifyStateClear( NULL ) == pdFALSE );
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
Create a timer that will try notifying this task while it is suspended. */
|
||||
* Create a timer that will try notifying this task while it is suspended. */
|
||||
xSingleTaskTimer = xTimerCreate( "SingleNotify", notifySUSPENDED_TEST_TIMER_PERIOD, pdFALSE, NULL, prvSuspendedTaskTimerTestCallback );
|
||||
configASSERT( xSingleTaskTimer );
|
||||
|
||||
|
|
@ -451,13 +436,13 @@ TimerHandle_t xSingleTaskTimer;
|
|||
xTaskNotifyWait( notifyUINT32_MAX, 0, NULL, 0 );
|
||||
|
||||
/* Raise the task's priority so it can suspend itself before the timer
|
||||
expires. */
|
||||
* expires. */
|
||||
vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );
|
||||
|
||||
/* Start the timer that will try notifying this task while it is
|
||||
suspended, then wait for a notification. The first time the callback
|
||||
executes the timer will suspend the task, then resume the task, without
|
||||
ever sending a notification to the task. */
|
||||
* suspended, then wait for a notification. The first time the callback
|
||||
* executes the timer will suspend the task, then resume the task, without
|
||||
* ever sending a notification to the task. */
|
||||
ulNotifiedValue = 0;
|
||||
xTimerStart( xSingleTaskTimer, portMAX_DELAY );
|
||||
|
||||
|
|
@ -471,9 +456,9 @@ TimerHandle_t xSingleTaskTimer;
|
|||
ulNotifyCycleCount++;
|
||||
|
||||
/* Start the timer that will try notifying this task while it is
|
||||
suspended, then wait for a notification. The second time the callback
|
||||
executes the timer will suspend the task, notify the task, then resume the
|
||||
task (previously it was suspended and resumed without being notified). */
|
||||
* suspended, then wait for a notification. The second time the callback
|
||||
* executes the timer will suspend the task, notify the task, then resume the
|
||||
* task (previously it was suspended and resumed without being notified). */
|
||||
xTimerStart( xSingleTaskTimer, portMAX_DELAY );
|
||||
|
||||
/* Check a notification is received. */
|
||||
|
|
@ -483,7 +468,7 @@ TimerHandle_t xSingleTaskTimer;
|
|||
configASSERT( ulNotifiedValue != 0 );
|
||||
|
||||
/* Return the task to its proper priority and delete the timer as it is
|
||||
not used again. */
|
||||
* not used again. */
|
||||
vTaskPrioritySet( NULL, notifyTASK_PRIORITY );
|
||||
xTimerDelete( xSingleTaskTimer, portMAX_DELAY );
|
||||
|
||||
|
|
@ -497,15 +482,15 @@ TimerHandle_t xSingleTaskTimer;
|
|||
|
||||
static void prvSuspendedTaskTimerTestCallback( TimerHandle_t xExpiredTimer )
|
||||
{
|
||||
static uint32_t ulCallCount = 0;
|
||||
static uint32_t ulCallCount = 0;
|
||||
|
||||
/* Remove compiler warnings about unused parameters. */
|
||||
( void ) xExpiredTimer;
|
||||
|
||||
/* Callback for a timer that is used during preliminary testing. The timer
|
||||
tests the behaviour when 1: a task waiting for a notification is suspended
|
||||
and then resumed without ever receiving a notification, and 2: when a task
|
||||
waiting for a notification receives a notification while it is suspended. */
|
||||
* tests the behaviour when 1: a task waiting for a notification is suspended
|
||||
* and then resumed without ever receiving a notification, and 2: when a task
|
||||
* waiting for a notification receives a notification while it is suspended. */
|
||||
|
||||
if( ulCallCount == 0 )
|
||||
{
|
||||
|
|
@ -518,8 +503,8 @@ static uint32_t ulCallCount = 0;
|
|||
vTaskSuspend( xTaskToNotify );
|
||||
|
||||
/* Sending a notification while the task is suspended should pass, but
|
||||
not cause the task to resume. ulCallCount is just used as a convenient
|
||||
non-zero value. */
|
||||
* not cause the task to resume. ulCallCount is just used as a convenient
|
||||
* non-zero value. */
|
||||
xTaskNotify( xTaskToNotify, ulCallCount, eSetValueWithOverwrite );
|
||||
|
||||
/* Make sure giving the notification didn't resume the task. */
|
||||
|
|
@ -547,29 +532,30 @@ static void prvNotifyingTimer( TimerHandle_t xNotUsed )
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvNotifiedTask( void *pvParameters )
|
||||
static void prvNotifiedTask( void * pvParameters )
|
||||
{
|
||||
const TickType_t xMaxPeriod = pdMS_TO_TICKS( 90 ), xMinPeriod = pdMS_TO_TICKS( 10 ), xDontBlock = 0;
|
||||
TickType_t xPeriod;
|
||||
const uint32_t ulCyclesToRaisePriority = 50UL;
|
||||
const TickType_t xMaxPeriod = pdMS_TO_TICKS( 90 ), xMinPeriod = pdMS_TO_TICKS( 10 ), xDontBlock = 0;
|
||||
TickType_t xPeriod;
|
||||
const uint32_t ulCyclesToRaisePriority = 50UL;
|
||||
|
||||
/* Remove compiler warnings about unused parameters. */
|
||||
( void ) pvParameters;
|
||||
|
||||
/* Run a few tests that can be done from a single task before entering the
|
||||
main loop. */
|
||||
* main loop. */
|
||||
prvSingleTaskTests();
|
||||
|
||||
/* Create the software timer that is used to send notifications to this
|
||||
task. Notifications are also received from an interrupt. */
|
||||
* task. Notifications are also received from an interrupt. */
|
||||
xTimer = xTimerCreate( "Notifier", xMaxPeriod, pdFALSE, NULL, prvNotifyingTimer );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Start the timer again with a different period. Sometimes the period
|
||||
will be higher than the task's block time, sometimes it will be lower
|
||||
than the task's block time. */
|
||||
* will be higher than the task's block time, sometimes it will be lower
|
||||
* than the task's block time. */
|
||||
xPeriod = prvRand() % xMaxPeriod;
|
||||
|
||||
if( xPeriod < xMinPeriod )
|
||||
{
|
||||
xPeriod = xMinPeriod;
|
||||
|
|
@ -579,47 +565,47 @@ const uint32_t ulCyclesToRaisePriority = 50UL;
|
|||
xTimerChangePeriod( xTimer, xPeriod, portMAX_DELAY );
|
||||
|
||||
/* Block waiting for the notification again with a different period.
|
||||
Sometimes the period will be higher than the task's block time,
|
||||
sometimes it will be lower than the task's block time. */
|
||||
* Sometimes the period will be higher than the task's block time,
|
||||
* sometimes it will be lower than the task's block time. */
|
||||
xPeriod = prvRand() % xMaxPeriod;
|
||||
|
||||
if( xPeriod < xMinPeriod )
|
||||
{
|
||||
xPeriod = xMinPeriod;
|
||||
}
|
||||
|
||||
/* Block to wait for a notification but without clearing the
|
||||
notification count, so only add one to the count of received
|
||||
notifications as any other notifications will remain pending. */
|
||||
* notification count, so only add one to the count of received
|
||||
* notifications as any other notifications will remain pending. */
|
||||
if( ulTaskNotifyTake( pdFALSE, xPeriod ) != 0 )
|
||||
{
|
||||
ulTimerNotificationsReceived++;
|
||||
}
|
||||
|
||||
|
||||
/* Take a notification without clearing again, but this time without a
|
||||
block time specified. */
|
||||
* block time specified. */
|
||||
if( ulTaskNotifyTake( pdFALSE, xDontBlock ) != 0 )
|
||||
{
|
||||
ulTimerNotificationsReceived++;
|
||||
}
|
||||
|
||||
/* Wait for the next notification from the timer, clearing all
|
||||
notifications if one is received, so this time adding the total number
|
||||
of notifications that were pending as none will be left pending after
|
||||
the function call. */
|
||||
* notifications if one is received, so this time adding the total number
|
||||
* of notifications that were pending as none will be left pending after
|
||||
* the function call. */
|
||||
ulTimerNotificationsReceived += ulTaskNotifyTake( pdTRUE, xPeriod );
|
||||
|
||||
/* Occasionally raise the priority of the task being notified to test
|
||||
the path where the task is notified from an ISR and becomes the highest
|
||||
priority ready state task, but the pxHigherPriorityTaskWoken parameter
|
||||
is NULL (which it is in the tick hook that sends notifications to this
|
||||
task). */
|
||||
* the path where the task is notified from an ISR and becomes the highest
|
||||
* priority ready state task, but the pxHigherPriorityTaskWoken parameter
|
||||
* is NULL (which it is in the tick hook that sends notifications to this
|
||||
* task). */
|
||||
if( ( ulNotifyCycleCount % ulCyclesToRaisePriority ) == 0 )
|
||||
{
|
||||
vTaskPrioritySet( xTaskToNotify, configMAX_PRIORITIES - 1 );
|
||||
|
||||
/* Wait for the next notification again, clearing all notifications
|
||||
if one is received, but this time blocking indefinitely. */
|
||||
* if one is received, but this time blocking indefinitely. */
|
||||
ulTimerNotificationsReceived += ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
|
||||
|
||||
/* Reset the priority. */
|
||||
|
|
@ -628,7 +614,7 @@ const uint32_t ulCyclesToRaisePriority = 50UL;
|
|||
else
|
||||
{
|
||||
/* Wait for the next notification again, clearing all notifications
|
||||
if one is received, but this time blocking indefinitely. */
|
||||
* if one is received, but this time blocking indefinitely. */
|
||||
ulTimerNotificationsReceived += ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
|
||||
}
|
||||
|
||||
|
|
@ -640,18 +626,18 @@ const uint32_t ulCyclesToRaisePriority = 50UL;
|
|||
|
||||
void xNotifyTaskFromISR( void )
|
||||
{
|
||||
static BaseType_t xCallCount = 0, xAPIToUse = 0;
|
||||
const BaseType_t xCallInterval = pdMS_TO_TICKS( 50 );
|
||||
uint32_t ulPreviousValue;
|
||||
const uint32_t ulUnexpectedValue = 0xff;
|
||||
static BaseType_t xCallCount = 0, xAPIToUse = 0;
|
||||
const BaseType_t xCallInterval = pdMS_TO_TICKS( 50 );
|
||||
uint32_t ulPreviousValue;
|
||||
const uint32_t ulUnexpectedValue = 0xff;
|
||||
|
||||
/* Check the task notification demo tasks were actually created. */
|
||||
configASSERT( xTaskToNotify );
|
||||
|
||||
/* The task performs some tests before starting the timer that gives the
|
||||
notification from this interrupt. If the timer has not been created yet
|
||||
then the initial tests have not yet completed and the notification should
|
||||
not be sent. */
|
||||
* notification from this interrupt. If the timer has not been created yet
|
||||
* then the initial tests have not yet completed and the notification should
|
||||
* not be sent. */
|
||||
if( xTimer != NULL )
|
||||
{
|
||||
xCallCount++;
|
||||
|
|
@ -662,24 +648,27 @@ const uint32_t ulUnexpectedValue = 0xff;
|
|||
xCallCount = 0;
|
||||
|
||||
/* Test using both vTaskNotifyGiveFromISR(), xTaskNotifyFromISR()
|
||||
and xTaskNotifyAndQueryFromISR(). */
|
||||
* and xTaskNotifyAndQueryFromISR(). */
|
||||
switch( xAPIToUse )
|
||||
{
|
||||
case 0: vTaskNotifyGiveFromISR( xTaskToNotify, NULL );
|
||||
case 0:
|
||||
vTaskNotifyGiveFromISR( xTaskToNotify, NULL );
|
||||
xAPIToUse++;
|
||||
break;
|
||||
|
||||
case 1: xTaskNotifyFromISR( xTaskToNotify, 0, eIncrement, NULL );
|
||||
case 1:
|
||||
xTaskNotifyFromISR( xTaskToNotify, 0, eIncrement, NULL );
|
||||
xAPIToUse++;
|
||||
break;
|
||||
|
||||
case 2: ulPreviousValue = ulUnexpectedValue;
|
||||
case 2:
|
||||
ulPreviousValue = ulUnexpectedValue;
|
||||
xTaskNotifyAndQueryFromISR( xTaskToNotify, 0, eIncrement, &ulPreviousValue, NULL );
|
||||
configASSERT( ulPreviousValue != ulUnexpectedValue );
|
||||
xAPIToUse = 0;
|
||||
break;
|
||||
|
||||
default:/* Should never get here!. */
|
||||
default: /* Should never get here!. */
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -690,14 +679,14 @@ const uint32_t ulUnexpectedValue = 0xff;
|
|||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* This is called to check the created tasks are still running and have not
|
||||
detected any errors. */
|
||||
* detected any errors. */
|
||||
BaseType_t xAreTaskNotificationTasksStillRunning( void )
|
||||
{
|
||||
static uint32_t ulLastNotifyCycleCount = 0;
|
||||
const uint32_t ulMaxSendReceiveDeviation = 5UL;
|
||||
static uint32_t ulLastNotifyCycleCount = 0;
|
||||
const uint32_t ulMaxSendReceiveDeviation = 5UL;
|
||||
|
||||
/* Check the cycle count is still incrementing to ensure the task is still
|
||||
actually running. */
|
||||
* actually running. */
|
||||
if( ulLastNotifyCycleCount == ulNotifyCycleCount )
|
||||
{
|
||||
xErrorStatus = pdFAIL;
|
||||
|
|
@ -708,7 +697,7 @@ const uint32_t ulMaxSendReceiveDeviation = 5UL;
|
|||
}
|
||||
|
||||
/* Check the count of 'takes' from the software timer is keeping track with
|
||||
the amount of 'gives'. */
|
||||
* the amount of 'gives'. */
|
||||
if( ulTimerNotificationsSent > ulTimerNotificationsReceived )
|
||||
{
|
||||
if( ( ulTimerNotificationsSent - ulTimerNotificationsReceived ) > ulMaxSendReceiveDeviation )
|
||||
|
|
@ -723,7 +712,7 @@ const uint32_t ulMaxSendReceiveDeviation = 5UL;
|
|||
|
||||
static UBaseType_t prvRand( void )
|
||||
{
|
||||
const size_t uxMultiplier = ( size_t ) 0x015a4e35, uxIncrement = ( size_t ) 1;
|
||||
const size_t uxMultiplier = ( size_t ) 0x015a4e35, uxIncrement = ( size_t ) 1;
|
||||
|
||||
/* Utility function to generate a pseudo random number. */
|
||||
uxNextRand = ( uxMultiplier * uxNextRand ) + uxIncrement;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -56,21 +56,21 @@
|
|||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* The callback functions used by the timers. These each increment a counter
|
||||
to indicate which timer has expired. The auto-reload timers that are used by
|
||||
the test task (as opposed to being used from an ISR) all share the same
|
||||
prvAutoReloadTimerCallback() callback function, and use the ID of the
|
||||
pxExpiredTimer parameter passed into that function to know which counter to
|
||||
increment. The other timers all have their own unique callback function and
|
||||
simply increment their counters without using the callback function parameter. */
|
||||
* to indicate which timer has expired. The auto-reload timers that are used by
|
||||
* the test task (as opposed to being used from an ISR) all share the same
|
||||
* prvAutoReloadTimerCallback() callback function, and use the ID of the
|
||||
* pxExpiredTimer parameter passed into that function to know which counter to
|
||||
* increment. The other timers all have their own unique callback function and
|
||||
* simply increment their counters without using the callback function parameter. */
|
||||
static void prvAutoReloadTimerCallback( TimerHandle_t pxExpiredTimer );
|
||||
static void prvOneShotTimerCallback( TimerHandle_t pxExpiredTimer );
|
||||
static void prvTimerTestTask( void *pvParameters );
|
||||
static void prvTimerTestTask( void * pvParameters );
|
||||
static void prvISRAutoReloadTimerCallback( TimerHandle_t pxExpiredTimer );
|
||||
static void prvISROneShotTimerCallback( TimerHandle_t pxExpiredTimer );
|
||||
|
||||
/* The test functions used by the timer test task. These manipulate the auto
|
||||
reload and one-shot timers in various ways, then delay, then inspect the timers
|
||||
to ensure they have behaved as expected. */
|
||||
* reload and one-shot timers in various ways, then delay, then inspect the timers
|
||||
* to ensure they have behaved as expected. */
|
||||
static void prvTest1_CreateTimersWithoutSchedulerRunning( void );
|
||||
static void prvTest2_CheckTaskAndTimersInitialState( void );
|
||||
static void prvTest3_CheckAutoReloadExpireRates( void );
|
||||
|
|
@ -83,47 +83,47 @@ static void prvResetStartConditionsForNextIteration( void );
|
|||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Flag that will be latched to pdFAIL should any unexpected behaviour be
|
||||
detected in any of the demo tests. */
|
||||
* detected in any of the demo tests. */
|
||||
static volatile BaseType_t xTestStatus = pdPASS;
|
||||
|
||||
/* Flag indicating whether the testing includes the backlog demo. The backlog
|
||||
demo can be disruptive to other demos because the timer backlog is created by
|
||||
calling xTaskCatchUpTicks(). */
|
||||
* demo can be disruptive to other demos because the timer backlog is created by
|
||||
* calling xTaskCatchUpTicks(). */
|
||||
static uint8_t ucIsBacklogDemoEnabled = ( uint8_t ) pdFALSE;
|
||||
|
||||
/* Counter that is incremented on each cycle of a test. This is used to
|
||||
detect a stalled task - a test that is no longer running. */
|
||||
* detect a stalled task - a test that is no longer running. */
|
||||
static volatile uint32_t ulLoopCounter = 0;
|
||||
|
||||
/* A set of auto-reload timers - each of which use the same callback function.
|
||||
The callback function uses the timer ID to index into, and then increment, a
|
||||
counter in the ucAutoReloadTimerCounters[] array. The callback function stops
|
||||
xAutoReloadTimers[0] during its callback if ucIsStopNeededInTimerZeroCallback is
|
||||
pdTRUE. The auto-reload timers referenced from xAutoReloadTimers[] are used by
|
||||
the prvTimerTestTask task. */
|
||||
* The callback function uses the timer ID to index into, and then increment, a
|
||||
* counter in the ucAutoReloadTimerCounters[] array. The callback function stops
|
||||
* xAutoReloadTimers[0] during its callback if ucIsStopNeededInTimerZeroCallback is
|
||||
* pdTRUE. The auto-reload timers referenced from xAutoReloadTimers[] are used by
|
||||
* the prvTimerTestTask task. */
|
||||
static TimerHandle_t xAutoReloadTimers[ configTIMER_QUEUE_LENGTH + 1 ] = { 0 };
|
||||
static uint8_t ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH + 1 ] = { 0 };
|
||||
static uint8_t ucIsStopNeededInTimerZeroCallback = ( uint8_t ) pdFALSE;
|
||||
|
||||
/* The one-shot timer is configured to use a callback function that increments
|
||||
ucOneShotTimerCounter each time it gets called. */
|
||||
* ucOneShotTimerCounter each time it gets called. */
|
||||
static TimerHandle_t xOneShotTimer = NULL;
|
||||
static uint8_t ucOneShotTimerCounter = ( uint8_t ) 0;
|
||||
|
||||
/* The ISR reload timer is controlled from the tick hook to exercise the timer
|
||||
API functions that can be used from an ISR. It is configured to increment
|
||||
ucISRReloadTimerCounter each time its callback function is executed. */
|
||||
* API functions that can be used from an ISR. It is configured to increment
|
||||
* ucISRReloadTimerCounter each time its callback function is executed. */
|
||||
static TimerHandle_t xISRAutoReloadTimer = NULL;
|
||||
static uint8_t ucISRAutoReloadTimerCounter = ( uint8_t ) 0;
|
||||
|
||||
/* The ISR one-shot timer is controlled from the tick hook to exercise the timer
|
||||
API functions that can be used from an ISR. It is configured to increment
|
||||
ucISRReloadTimerCounter each time its callback function is executed. */
|
||||
* API functions that can be used from an ISR. It is configured to increment
|
||||
* ucISRReloadTimerCounter each time its callback function is executed. */
|
||||
static TimerHandle_t xISROneShotTimer = NULL;
|
||||
static uint8_t ucISROneShotTimerCounter = ( uint8_t ) 0;
|
||||
|
||||
/* The period of all the timers are a multiple of the base period. The base
|
||||
period is configured by the parameter to vStartTimerDemoTask(). */
|
||||
* period is configured by the parameter to vStartTimerDemoTask(). */
|
||||
static TickType_t xBasePeriod = 0;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
|
@ -131,22 +131,22 @@ static TickType_t xBasePeriod = 0;
|
|||
void vStartTimerDemoTask( TickType_t xBasePeriodIn )
|
||||
{
|
||||
/* Start with the timer and counter arrays clear - this is only necessary
|
||||
where the compiler does not clear them automatically on start up. */
|
||||
* where the compiler does not clear them automatically on start up. */
|
||||
memset( ucAutoReloadTimerCounters, 0x00, sizeof( ucAutoReloadTimerCounters ) );
|
||||
memset( xAutoReloadTimers, 0x00, sizeof( xAutoReloadTimers ) );
|
||||
|
||||
/* Store the period from which all the timer periods will be generated from
|
||||
(multiples of). */
|
||||
* (multiples of). */
|
||||
xBasePeriod = xBasePeriodIn;
|
||||
|
||||
/* Create a set of timers for use by this demo/test. */
|
||||
prvTest1_CreateTimersWithoutSchedulerRunning();
|
||||
|
||||
/* Create the task that will control and monitor the timers. This is
|
||||
created at a lower priority than the timer service task to ensure, as
|
||||
far as it is concerned, commands on timers are acted on immediately
|
||||
(sending a command to the timer service task will unblock the timer service
|
||||
task, which will then preempt this task). */
|
||||
* created at a lower priority than the timer service task to ensure, as
|
||||
* far as it is concerned, commands on timers are acted on immediately
|
||||
* (sending a command to the timer service task will unblock the timer service
|
||||
* task, which will then preempt this task). */
|
||||
if( xTestStatus != pdFAIL )
|
||||
{
|
||||
xTaskCreate( prvTimerTestTask, "Tmr Tst", tmrTIMER_TEST_TASK_STACK_SIZE, NULL, configTIMER_TASK_PRIORITY - 1, NULL );
|
||||
|
|
@ -160,12 +160,12 @@ void vTimerDemoIncludeBacklogTests( BaseType_t includeBacklogTests )
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvTimerTestTask( void *pvParameters )
|
||||
static void prvTimerTestTask( void * pvParameters )
|
||||
{
|
||||
( void ) pvParameters;
|
||||
|
||||
/* Create a one-shot timer for use later on in this test. For test purposes it
|
||||
is created as an auto-reload timer then converted to a one-shot timer. */
|
||||
* is created as an auto-reload timer then converted to a one-shot timer. */
|
||||
xOneShotTimer = xTimerCreate( "Oneshot Timer", /* Text name to facilitate debugging. The kernel does not use this itself. */
|
||||
tmrdemoONE_SHOT_TIMER_PERIOD, /* The period for the timer. */
|
||||
pdFALSE, /* Autoreload is false, so created as a one-shot timer. */
|
||||
|
|
@ -179,7 +179,7 @@ static void prvTimerTestTask( void *pvParameters )
|
|||
}
|
||||
|
||||
/* Purely for test coverage purposes - change and query the reload mode to
|
||||
auto-reload then back to one-shot. */
|
||||
* auto-reload then back to one-shot. */
|
||||
|
||||
/* Change timer to auto-reload. */
|
||||
vTimerSetReloadMode( xOneShotTimer, pdTRUE );
|
||||
|
|
@ -194,27 +194,27 @@ static void prvTimerTestTask( void *pvParameters )
|
|||
configASSERT( uxTimerGetReloadMode( xOneShotTimer ) == pdFALSE );
|
||||
|
||||
/* Ensure all the timers are in their expected initial state. This
|
||||
depends on the timer service task having a higher priority than this task. */
|
||||
* depends on the timer service task having a higher priority than this task. */
|
||||
prvTest2_CheckTaskAndTimersInitialState();
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Check the auto-reload timers expire at the expected/correct rates. */
|
||||
prvTest3_CheckAutoReloadExpireRates();
|
||||
|
||||
/* Check the auto-reload timers can be stopped correctly, and correctly
|
||||
report their state. */
|
||||
* report their state. */
|
||||
prvTest4_CheckAutoReloadTimersCanBeStopped();
|
||||
|
||||
/* Check the one-shot timer only calls its callback once after it has been
|
||||
started, and that it reports its state correctly. */
|
||||
* started, and that it reports its state correctly. */
|
||||
prvTest5_CheckBasicOneShotTimerBehaviour();
|
||||
|
||||
/* Check timer reset behaviour. */
|
||||
prvTest6_CheckAutoReloadResetBehaviour();
|
||||
|
||||
/* Check timer behaviour when the timer task gets behind in its work. */
|
||||
if ( ucIsBacklogDemoEnabled == ( uint8_t ) pdTRUE )
|
||||
if( ucIsBacklogDemoEnabled == ( uint8_t ) pdTRUE )
|
||||
{
|
||||
prvTest7_CheckBacklogBehaviour();
|
||||
}
|
||||
|
|
@ -226,33 +226,34 @@ static void prvTimerTestTask( void *pvParameters )
|
|||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* This is called to check that the created task is still running and has not
|
||||
detected any errors. */
|
||||
* detected any errors. */
|
||||
BaseType_t xAreTimerDemoTasksStillRunning( TickType_t xCycleFrequency )
|
||||
{
|
||||
static uint32_t ulLastLoopCounter = 0UL;
|
||||
TickType_t xMaxBlockTimeUsedByTheseTests, xLoopCounterIncrementTimeMax;
|
||||
static TickType_t xIterationsWithoutCounterIncrement = ( TickType_t ) 0, xLastCycleFrequency;
|
||||
static uint32_t ulLastLoopCounter = 0UL;
|
||||
TickType_t xMaxBlockTimeUsedByTheseTests, xLoopCounterIncrementTimeMax;
|
||||
static TickType_t xIterationsWithoutCounterIncrement = ( TickType_t ) 0, xLastCycleFrequency;
|
||||
|
||||
if( xLastCycleFrequency != xCycleFrequency )
|
||||
{
|
||||
/* The cycle frequency has probably become much faster due to an error
|
||||
elsewhere. Start counting Iterations again. */
|
||||
* elsewhere. Start counting Iterations again. */
|
||||
xIterationsWithoutCounterIncrement = ( TickType_t ) 0;
|
||||
xLastCycleFrequency = xCycleFrequency;
|
||||
}
|
||||
|
||||
/* Calculate the maximum number of times that it is permissible for this
|
||||
function to be called without ulLoopCounter being incremented. This is
|
||||
necessary because the tests in this file block for extended periods, and the
|
||||
block period might be longer than the time between calls to this function. */
|
||||
* function to be called without ulLoopCounter being incremented. This is
|
||||
* necessary because the tests in this file block for extended periods, and the
|
||||
* block period might be longer than the time between calls to this function. */
|
||||
xMaxBlockTimeUsedByTheseTests = ( ( TickType_t ) configTIMER_QUEUE_LENGTH ) * xBasePeriod;
|
||||
xLoopCounterIncrementTimeMax = ( xMaxBlockTimeUsedByTheseTests / xCycleFrequency ) + 1;
|
||||
|
||||
/* If the demo task is still running then the loop counter is expected to
|
||||
have incremented every xLoopCounterIncrementTimeMax calls. */
|
||||
* have incremented every xLoopCounterIncrementTimeMax calls. */
|
||||
if( ulLastLoopCounter == ulLoopCounter )
|
||||
{
|
||||
xIterationsWithoutCounterIncrement++;
|
||||
|
||||
if( xIterationsWithoutCounterIncrement > xLoopCounterIncrementTimeMax )
|
||||
{
|
||||
/* The tests appear to be no longer running (stalled). */
|
||||
|
|
@ -262,14 +263,14 @@ static TickType_t xIterationsWithoutCounterIncrement = ( TickType_t ) 0, xLastCy
|
|||
else
|
||||
{
|
||||
/* ulLoopCounter changed, so the count of times this function was called
|
||||
without a change can be reset to zero. */
|
||||
* without a change can be reset to zero. */
|
||||
xIterationsWithoutCounterIncrement = ( TickType_t ) 0;
|
||||
}
|
||||
|
||||
ulLastLoopCounter = ulLoopCounter;
|
||||
|
||||
/* Errors detected in the task itself will have latched xTestStatus
|
||||
to pdFAIL. */
|
||||
* to pdFAIL. */
|
||||
|
||||
return xTestStatus;
|
||||
}
|
||||
|
|
@ -277,16 +278,16 @@ static TickType_t xIterationsWithoutCounterIncrement = ( TickType_t ) 0, xLastCy
|
|||
|
||||
static void prvTest1_CreateTimersWithoutSchedulerRunning( void )
|
||||
{
|
||||
TickType_t xTimer;
|
||||
TickType_t xTimer;
|
||||
|
||||
for( xTimer = 0; xTimer < configTIMER_QUEUE_LENGTH; xTimer++ )
|
||||
{
|
||||
/* As the timer queue is not yet full, it should be possible to both
|
||||
create and start a timer. These timers are being started before the
|
||||
scheduler has been started, so their block times should get set to zero
|
||||
within the timer API itself. */
|
||||
* create and start a timer. These timers are being started before the
|
||||
* scheduler has been started, so their block times should get set to zero
|
||||
* within the timer API itself. */
|
||||
xAutoReloadTimers[ xTimer ] = xTimerCreate( "FR Timer", /* Text name to facilitate debugging. The kernel does not use this itself. */
|
||||
( ( xTimer + ( TickType_t ) 1 ) * xBasePeriod ),/* The period for the timer. The plus 1 ensures a period of zero is not specified. */
|
||||
( ( xTimer + ( TickType_t ) 1 ) * xBasePeriod ), /* The period for the timer. The plus 1 ensures a period of zero is not specified. */
|
||||
pdTRUE, /* Auto-reload is set to true. */
|
||||
( void * ) xTimer, /* An identifier for the timer as all the auto-reload timers use the same callback. */
|
||||
prvAutoReloadTimerCallback ); /* The callback to be called when the timer expires. */
|
||||
|
|
@ -301,9 +302,9 @@ TickType_t xTimer;
|
|||
configASSERT( strcmp( pcTimerGetName( xAutoReloadTimers[ xTimer ] ), "FR Timer" ) == 0 );
|
||||
|
||||
/* The scheduler has not yet started, so the block period of
|
||||
portMAX_DELAY should just get set to zero in xTimerStart(). Also,
|
||||
the timer queue is not yet full so xTimerStart() should return
|
||||
pdPASS. */
|
||||
* portMAX_DELAY should just get set to zero in xTimerStart(). Also,
|
||||
* the timer queue is not yet full so xTimerStart() should return
|
||||
* pdPASS. */
|
||||
if( xTimerStart( xAutoReloadTimers[ xTimer ], portMAX_DELAY ) != pdPASS )
|
||||
{
|
||||
xTestStatus = pdFAIL;
|
||||
|
|
@ -313,8 +314,8 @@ TickType_t xTimer;
|
|||
}
|
||||
|
||||
/* The timers queue should now be full, so it should be possible to create
|
||||
another timer, but not possible to start it (the timer queue will not get
|
||||
drained until the scheduler has been started. */
|
||||
* another timer, but not possible to start it (the timer queue will not get
|
||||
* drained until the scheduler has been started. */
|
||||
xAutoReloadTimers[ configTIMER_QUEUE_LENGTH ] = xTimerCreate( "FR Timer", /* Text name to facilitate debugging. The kernel does not use this itself. */
|
||||
( configTIMER_QUEUE_LENGTH * xBasePeriod ), /* The period for the timer. */
|
||||
pdTRUE, /* Auto-reload is set to true. */
|
||||
|
|
@ -331,14 +332,14 @@ TickType_t xTimer;
|
|||
if( xTimerStart( xAutoReloadTimers[ xTimer ], portMAX_DELAY ) == pdPASS )
|
||||
{
|
||||
/* This time it would not be expected that the timer could be
|
||||
started at this point. */
|
||||
* started at this point. */
|
||||
xTestStatus = pdFAIL;
|
||||
configASSERT( xTestStatus );
|
||||
}
|
||||
}
|
||||
|
||||
/* Create the timers that are used from the tick interrupt to test the timer
|
||||
API functions that can be called from an ISR. */
|
||||
* API functions that can be called from an ISR. */
|
||||
xISRAutoReloadTimer = xTimerCreate( "ISR AR", /* The text name given to the timer. */
|
||||
0xffff, /* The timer is not given a period yet - this will be done from the tick hook, but a period of 0 is invalid. */
|
||||
pdTRUE, /* This is an auto-reload timer. */
|
||||
|
|
@ -361,15 +362,15 @@ TickType_t xTimer;
|
|||
|
||||
static void prvTest2_CheckTaskAndTimersInitialState( void )
|
||||
{
|
||||
uint8_t ucTimer;
|
||||
uint8_t ucTimer;
|
||||
|
||||
/* Ensure all the timers are in their expected initial state. This depends
|
||||
on the timer service task having a higher priority than this task.
|
||||
|
||||
auto-reload timers 0 to ( configTIMER_QUEUE_LENGTH - 1 ) should now be active,
|
||||
and auto-reload timer configTIMER_QUEUE_LENGTH should not yet be active (it
|
||||
could not be started prior to the scheduler being started when it was
|
||||
created). */
|
||||
* on the timer service task having a higher priority than this task.
|
||||
*
|
||||
* auto-reload timers 0 to ( configTIMER_QUEUE_LENGTH - 1 ) should now be active,
|
||||
* and auto-reload timer configTIMER_QUEUE_LENGTH should not yet be active (it
|
||||
* could not be started prior to the scheduler being started when it was
|
||||
* created). */
|
||||
for( ucTimer = 0; ucTimer < ( uint8_t ) configTIMER_QUEUE_LENGTH; ucTimer++ )
|
||||
{
|
||||
if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) == pdFALSE )
|
||||
|
|
@ -389,31 +390,31 @@ uint8_t ucTimer;
|
|||
|
||||
static void prvTest3_CheckAutoReloadExpireRates( void )
|
||||
{
|
||||
uint8_t ucMaxAllowableValue, ucMinAllowableValue, ucTimer;
|
||||
TickType_t xBlockPeriod, xTimerPeriod, xExpectedNumber;
|
||||
UBaseType_t uxOriginalPriority;
|
||||
uint8_t ucMaxAllowableValue, ucMinAllowableValue, ucTimer;
|
||||
TickType_t xBlockPeriod, xTimerPeriod, xExpectedNumber;
|
||||
UBaseType_t uxOriginalPriority;
|
||||
|
||||
/* Check the auto-reload timers expire at the expected rates. Do this at a
|
||||
high priority for maximum accuracy. This is ok as most of the time is spent
|
||||
in the Blocked state. */
|
||||
* high priority for maximum accuracy. This is ok as most of the time is spent
|
||||
* in the Blocked state. */
|
||||
uxOriginalPriority = uxTaskPriorityGet( NULL );
|
||||
vTaskPrioritySet( NULL, ( configMAX_PRIORITIES - 1 ) );
|
||||
|
||||
/* Delaying for configTIMER_QUEUE_LENGTH * xBasePeriod ticks should allow
|
||||
all the auto-reload timers to expire at least once. */
|
||||
* all the auto-reload timers to expire at least once. */
|
||||
xBlockPeriod = ( ( TickType_t ) configTIMER_QUEUE_LENGTH ) * xBasePeriod;
|
||||
vTaskDelay( xBlockPeriod );
|
||||
|
||||
/* Check that all the auto-reload timers have called their callback
|
||||
function the expected number of times. */
|
||||
* function the expected number of times. */
|
||||
for( ucTimer = 0; ucTimer < ( uint8_t ) configTIMER_QUEUE_LENGTH; ucTimer++ )
|
||||
{
|
||||
/* The expected number of expires is equal to the block period divided
|
||||
by the timer period. */
|
||||
* by the timer period. */
|
||||
xTimerPeriod = ( ( ( TickType_t ) ucTimer + ( TickType_t ) 1 ) * xBasePeriod );
|
||||
xExpectedNumber = xBlockPeriod / xTimerPeriod;
|
||||
|
||||
ucMaxAllowableValue = ( ( uint8_t ) xExpectedNumber ) ;
|
||||
ucMaxAllowableValue = ( ( uint8_t ) xExpectedNumber );
|
||||
ucMinAllowableValue = ( uint8_t ) ( ( uint8_t ) xExpectedNumber - ( uint8_t ) 1 ); /* Weird casting to try and please all compilers. */
|
||||
|
||||
if( ( ucAutoReloadTimerCounters[ ucTimer ] < ucMinAllowableValue ) ||
|
||||
|
|
@ -431,7 +432,7 @@ UBaseType_t uxOriginalPriority;
|
|||
if( xTestStatus == pdPASS )
|
||||
{
|
||||
/* No errors have been reported so increment the loop counter so the
|
||||
check task knows this task is still running. */
|
||||
* check task knows this task is still running. */
|
||||
ulLoopCounter++;
|
||||
}
|
||||
}
|
||||
|
|
@ -439,10 +440,10 @@ UBaseType_t uxOriginalPriority;
|
|||
|
||||
static void prvTest4_CheckAutoReloadTimersCanBeStopped( void )
|
||||
{
|
||||
uint8_t ucTimer;
|
||||
uint8_t ucTimer;
|
||||
|
||||
/* Check the auto-reload timers can be stopped correctly, and correctly
|
||||
report their state. */
|
||||
* report their state. */
|
||||
|
||||
/* Stop all the active timers. */
|
||||
for( ucTimer = 0; ucTimer < ( uint8_t ) configTIMER_QUEUE_LENGTH; ucTimer++ )
|
||||
|
|
@ -455,8 +456,8 @@ uint8_t ucTimer;
|
|||
}
|
||||
|
||||
/* Now stop the timer. This will appear to happen immediately to
|
||||
this task because this task is running at a priority below the
|
||||
timer service task. */
|
||||
* this task because this task is running at a priority below the
|
||||
* timer service task. */
|
||||
xTimerStop( xAutoReloadTimers[ ucTimer ], tmrdemoDONT_BLOCK );
|
||||
|
||||
/* The timer should now be inactive. */
|
||||
|
|
@ -470,9 +471,9 @@ uint8_t ucTimer;
|
|||
taskENTER_CRITICAL();
|
||||
{
|
||||
/* The timer in array position configTIMER_QUEUE_LENGTH should not
|
||||
be active. The critical section is used to ensure the timer does
|
||||
not call its callback between the next line running and the array
|
||||
being cleared back to zero, as that would mask an error condition. */
|
||||
* be active. The critical section is used to ensure the timer does
|
||||
* not call its callback between the next line running and the array
|
||||
* being cleared back to zero, as that would mask an error condition. */
|
||||
if( ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH ] != ( uint8_t ) 0 )
|
||||
{
|
||||
xTestStatus = pdFAIL;
|
||||
|
|
@ -485,8 +486,9 @@ uint8_t ucTimer;
|
|||
taskEXIT_CRITICAL();
|
||||
|
||||
/* The timers are now all inactive, so this time, after delaying, none
|
||||
of the callback counters should have incremented. */
|
||||
* of the callback counters should have incremented. */
|
||||
vTaskDelay( ( ( TickType_t ) configTIMER_QUEUE_LENGTH ) * xBasePeriod );
|
||||
|
||||
for( ucTimer = 0; ucTimer < ( uint8_t ) configTIMER_QUEUE_LENGTH; ucTimer++ )
|
||||
{
|
||||
if( ucAutoReloadTimerCounters[ ucTimer ] != ( uint8_t ) 0 )
|
||||
|
|
@ -499,7 +501,7 @@ uint8_t ucTimer;
|
|||
if( xTestStatus == pdPASS )
|
||||
{
|
||||
/* No errors have been reported so increment the loop counter so
|
||||
the check task knows this task is still running. */
|
||||
* the check task knows this task is still running. */
|
||||
ulLoopCounter++;
|
||||
}
|
||||
}
|
||||
|
|
@ -508,7 +510,7 @@ uint8_t ucTimer;
|
|||
static void prvTest5_CheckBasicOneShotTimerBehaviour( void )
|
||||
{
|
||||
/* Check the one-shot timer only calls its callback once after it has been
|
||||
started, and that it reports its state correctly. */
|
||||
* started, and that it reports its state correctly. */
|
||||
|
||||
/* The one-shot timer should not be active yet. */
|
||||
if( xTimerIsTimerActive( xOneShotTimer ) != pdFALSE )
|
||||
|
|
@ -525,6 +527,7 @@ static void prvTest5_CheckBasicOneShotTimerBehaviour( void )
|
|||
|
||||
/* Start the one-shot timer and check that it reports its state correctly. */
|
||||
xTimerStart( xOneShotTimer, tmrdemoDONT_BLOCK );
|
||||
|
||||
if( xTimerIsTimerActive( xOneShotTimer ) == pdFALSE )
|
||||
{
|
||||
xTestStatus = pdFAIL;
|
||||
|
|
@ -532,8 +535,8 @@ static void prvTest5_CheckBasicOneShotTimerBehaviour( void )
|
|||
}
|
||||
|
||||
/* Delay for three times as long as the one-shot timer period, then check
|
||||
to ensure it has only called its callback once, and is now not in the
|
||||
active state. */
|
||||
* to ensure it has only called its callback once, and is now not in the
|
||||
* active state. */
|
||||
vTaskDelay( tmrdemoONE_SHOT_TIMER_PERIOD * ( TickType_t ) 3 );
|
||||
|
||||
if( xTimerIsTimerActive( xOneShotTimer ) != pdFALSE )
|
||||
|
|
@ -556,7 +559,7 @@ static void prvTest5_CheckBasicOneShotTimerBehaviour( void )
|
|||
if( xTestStatus == pdPASS )
|
||||
{
|
||||
/* No errors have been reported so increment the loop counter so the
|
||||
check task knows this task is still running. */
|
||||
* check task knows this task is still running. */
|
||||
ulLoopCounter++;
|
||||
}
|
||||
}
|
||||
|
|
@ -564,12 +567,13 @@ static void prvTest5_CheckBasicOneShotTimerBehaviour( void )
|
|||
|
||||
static void prvTest6_CheckAutoReloadResetBehaviour( void )
|
||||
{
|
||||
uint8_t ucTimer;
|
||||
uint8_t ucTimer;
|
||||
|
||||
/* Check timer reset behaviour. */
|
||||
|
||||
/* Restart the one-shot timer and check it reports its status correctly. */
|
||||
xTimerStart( xOneShotTimer, tmrdemoDONT_BLOCK );
|
||||
|
||||
if( xTimerIsTimerActive( xOneShotTimer ) == pdFALSE )
|
||||
{
|
||||
xTestStatus = pdFAIL;
|
||||
|
|
@ -577,8 +581,9 @@ uint8_t ucTimer;
|
|||
}
|
||||
|
||||
/* Restart one of the auto-reload timers and check that it reports its
|
||||
status correctly. */
|
||||
* status correctly. */
|
||||
xTimerStart( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ], tmrdemoDONT_BLOCK );
|
||||
|
||||
if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ] ) == pdFALSE )
|
||||
{
|
||||
xTestStatus = pdFAIL;
|
||||
|
|
@ -588,12 +593,12 @@ uint8_t ucTimer;
|
|||
for( ucTimer = 0; ucTimer < tmrdemoNUM_TIMER_RESETS; ucTimer++ )
|
||||
{
|
||||
/* Delay for half as long as the one-shot timer period, then reset it.
|
||||
It should never expire while this is done, so its callback count should
|
||||
never increment. */
|
||||
* It should never expire while this is done, so its callback count should
|
||||
* never increment. */
|
||||
vTaskDelay( tmrdemoONE_SHOT_TIMER_PERIOD / 2 );
|
||||
|
||||
/* Check both running timers are still active, but have not called their
|
||||
callback functions. */
|
||||
* callback functions. */
|
||||
if( xTimerIsTimerActive( xOneShotTimer ) == pdFALSE )
|
||||
{
|
||||
xTestStatus = pdFAIL;
|
||||
|
|
@ -625,7 +630,7 @@ uint8_t ucTimer;
|
|||
if( xTestStatus == pdPASS )
|
||||
{
|
||||
/* No errors have been reported so increment the loop counter so
|
||||
the check task knows this task is still running. */
|
||||
* the check task knows this task is still running. */
|
||||
ulLoopCounter++;
|
||||
}
|
||||
}
|
||||
|
|
@ -634,7 +639,7 @@ uint8_t ucTimer;
|
|||
vTaskDelay( ( ( TickType_t ) configTIMER_QUEUE_LENGTH ) * xBasePeriod );
|
||||
|
||||
/* The timers were not reset during the above delay period so should now
|
||||
both have called their callback functions. */
|
||||
* both have called their callback functions. */
|
||||
if( ucOneShotTimerCounter != ( uint8_t ) 1 )
|
||||
{
|
||||
xTestStatus = pdFAIL;
|
||||
|
|
@ -648,7 +653,7 @@ uint8_t ucTimer;
|
|||
}
|
||||
|
||||
/* The one-shot timer should no longer be active, while the auto-reload
|
||||
timer should still be active. */
|
||||
* timer should still be active. */
|
||||
if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ] ) == pdFALSE )
|
||||
{
|
||||
xTestStatus = pdFAIL;
|
||||
|
|
@ -671,14 +676,14 @@ uint8_t ucTimer;
|
|||
}
|
||||
|
||||
/* Clear the timer callback counts, ready for another iteration of these
|
||||
tests. */
|
||||
* tests. */
|
||||
ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH - 1 ] = ( uint8_t ) 0;
|
||||
ucOneShotTimerCounter = ( uint8_t ) 0;
|
||||
|
||||
if( xTestStatus == pdPASS )
|
||||
{
|
||||
/* No errors have been reported so increment the loop counter so the check
|
||||
task knows this task is still running. */
|
||||
* task knows this task is still running. */
|
||||
ulLoopCounter++;
|
||||
}
|
||||
}
|
||||
|
|
@ -687,7 +692,7 @@ uint8_t ucTimer;
|
|||
static void prvTest7_CheckBacklogBehaviour( void )
|
||||
{
|
||||
/* Use the first auto-reload timer to test stopping a timer from a
|
||||
backlogged callback. */
|
||||
* backlogged callback. */
|
||||
|
||||
/* The timer has not been started yet! */
|
||||
if( xTimerIsTimerActive( xAutoReloadTimers[ 0 ] ) != pdFALSE )
|
||||
|
|
@ -700,11 +705,11 @@ static void prvTest7_CheckBacklogBehaviour( void )
|
|||
ucIsStopNeededInTimerZeroCallback = ( uint8_t ) pdTRUE;
|
||||
|
||||
/* Now start the timer. This will appear to happen immediately to
|
||||
this task because this task is running at a priority below the timer
|
||||
service task. Use a timer period of one tick so the call to
|
||||
xTaskCatchUpTicks() below has minimal impact on other tests that might
|
||||
be running. */
|
||||
#define tmrdemoBACKLOG_TIMER_PERIOD ( ( TickType_t ) 1 )
|
||||
* this task because this task is running at a priority below the timer
|
||||
* service task. Use a timer period of one tick so the call to
|
||||
* xTaskCatchUpTicks() below has minimal impact on other tests that might
|
||||
* be running. */
|
||||
#define tmrdemoBACKLOG_TIMER_PERIOD ( ( TickType_t ) 1 )
|
||||
xTimerChangePeriod( xAutoReloadTimers[ 0 ], tmrdemoBACKLOG_TIMER_PERIOD, tmrdemoDONT_BLOCK );
|
||||
|
||||
/* The timer should now be active. */
|
||||
|
|
@ -715,9 +720,9 @@ static void prvTest7_CheckBacklogBehaviour( void )
|
|||
}
|
||||
|
||||
/* Arrange for the callback to execute late enough that it will execute
|
||||
twice, back-to-back. The timer must handle the stop request properly
|
||||
in spite of the backlog of callbacks. */
|
||||
#define tmrdemoEXPECTED_BACKLOG_EXPIRES ( ( TickType_t ) 2 )
|
||||
* twice, back-to-back. The timer must handle the stop request properly
|
||||
* in spite of the backlog of callbacks. */
|
||||
#define tmrdemoEXPECTED_BACKLOG_EXPIRES ( ( TickType_t ) 2 )
|
||||
xTaskCatchUpTicks( tmrdemoBACKLOG_TIMER_PERIOD * tmrdemoEXPECTED_BACKLOG_EXPIRES );
|
||||
|
||||
/* The timer should now be inactive. */
|
||||
|
|
@ -737,7 +742,7 @@ static void prvTest7_CheckBacklogBehaviour( void )
|
|||
if( xTestStatus == pdPASS )
|
||||
{
|
||||
/* No errors have been reported so increment the loop counter so the check
|
||||
task knows this task is still running. */
|
||||
* task knows this task is still running. */
|
||||
ulLoopCounter++;
|
||||
}
|
||||
}
|
||||
|
|
@ -745,7 +750,7 @@ static void prvTest7_CheckBacklogBehaviour( void )
|
|||
|
||||
static void prvResetStartConditionsForNextIteration( void )
|
||||
{
|
||||
uint8_t ucTimer;
|
||||
uint8_t ucTimer;
|
||||
|
||||
/* Start the timers again to start all the tests over again. */
|
||||
|
||||
|
|
@ -760,8 +765,8 @@ uint8_t ucTimer;
|
|||
}
|
||||
|
||||
/* Now start the timer. This will appear to happen immediately to
|
||||
this task because this task is running at a priority below the timer
|
||||
service task. */
|
||||
* this task because this task is running at a priority below the timer
|
||||
* service task. */
|
||||
xTimerStart( xAutoReloadTimers[ ucTimer ], tmrdemoDONT_BLOCK );
|
||||
|
||||
/* The timer should now be active. */
|
||||
|
|
@ -775,7 +780,7 @@ uint8_t ucTimer;
|
|||
if( xTestStatus == pdPASS )
|
||||
{
|
||||
/* No errors have been reported so increment the loop counter so the
|
||||
check task knows this task is still running. */
|
||||
* check task knows this task is still running. */
|
||||
ulLoopCounter++;
|
||||
}
|
||||
}
|
||||
|
|
@ -783,42 +788,43 @@ uint8_t ucTimer;
|
|||
|
||||
void vTimerPeriodicISRTests( void )
|
||||
{
|
||||
static TickType_t uxTick = ( TickType_t ) -1;
|
||||
static TickType_t uxTick = ( TickType_t ) -1;
|
||||
|
||||
#if ( configTIMER_TASK_PRIORITY != ( configMAX_PRIORITIES - 1 ) )
|
||||
|
||||
#if( configTIMER_TASK_PRIORITY != ( configMAX_PRIORITIES - 1 ) )
|
||||
/* The timer service task is not the highest priority task, so it cannot
|
||||
be assumed that timings will be exact. Timers should never call their
|
||||
callback before their expiry time, but a margin is permissible for calling
|
||||
their callback after their expiry time. If exact timing is required then
|
||||
configTIMER_TASK_PRIORITY must be set to ensure the timer service task
|
||||
is the highest priority task in the system.
|
||||
|
||||
This function is called from the tick hook. The tick hook is called
|
||||
even when the scheduler is suspended. Therefore it is possible that the
|
||||
uxTick count maintained in this function is temporarily ahead of the tick
|
||||
count maintained by the kernel. When this is the case a message posted from
|
||||
this function will assume a time stamp in advance of the real time stamp,
|
||||
which can result in a timer being processed before this function expects it
|
||||
to. For example, if the kernel's tick count was 100, and uxTick was 102,
|
||||
then this function will not expect the timer to have expired until the
|
||||
kernel's tick count is (102 + xBasePeriod), whereas in reality the timer
|
||||
will expire when the kernel's tick count is (100 + xBasePeriod). For this
|
||||
reason xMargin is used as an allowable margin for premature timer expires
|
||||
as well as late timer expires. */
|
||||
* be assumed that timings will be exact. Timers should never call their
|
||||
* callback before their expiry time, but a margin is permissible for calling
|
||||
* their callback after their expiry time. If exact timing is required then
|
||||
* configTIMER_TASK_PRIORITY must be set to ensure the timer service task
|
||||
* is the highest priority task in the system.
|
||||
*
|
||||
* This function is called from the tick hook. The tick hook is called
|
||||
* even when the scheduler is suspended. Therefore it is possible that the
|
||||
* uxTick count maintained in this function is temporarily ahead of the tick
|
||||
* count maintained by the kernel. When this is the case a message posted from
|
||||
* this function will assume a time stamp in advance of the real time stamp,
|
||||
* which can result in a timer being processed before this function expects it
|
||||
* to. For example, if the kernel's tick count was 100, and uxTick was 102,
|
||||
* then this function will not expect the timer to have expired until the
|
||||
* kernel's tick count is (102 + xBasePeriod), whereas in reality the timer
|
||||
* will expire when the kernel's tick count is (100 + xBasePeriod). For this
|
||||
* reason xMargin is used as an allowable margin for premature timer expires
|
||||
* as well as late timer expires. */
|
||||
#ifdef _WINDOWS_
|
||||
/* Windows is not real real time. */
|
||||
const TickType_t xMargin = 20;
|
||||
#else
|
||||
const TickType_t xMargin = 6;
|
||||
#endif /* _WINDOWS_ */
|
||||
#else
|
||||
#else
|
||||
#ifdef _WINDOWS_
|
||||
/* Windows is not real real time. */
|
||||
const TickType_t xMargin = 20;
|
||||
#else
|
||||
const TickType_t xMargin = 4;
|
||||
#endif /* _WINDOWS_ */
|
||||
#endif
|
||||
#endif /* if ( configTIMER_TASK_PRIORITY != ( configMAX_PRIORITIES - 1 ) ) */
|
||||
|
||||
|
||||
uxTick++;
|
||||
|
|
@ -826,13 +832,13 @@ static TickType_t uxTick = ( TickType_t ) -1;
|
|||
if( uxTick == 0 )
|
||||
{
|
||||
/* The timers will have been created, but not started. Start them now
|
||||
by setting their period. */
|
||||
* by setting their period. */
|
||||
ucISRAutoReloadTimerCounter = 0;
|
||||
ucISROneShotTimerCounter = 0;
|
||||
|
||||
/* It is possible that the timer task has not yet made room in the
|
||||
timer queue. If the timers cannot be started then reset uxTick so
|
||||
another attempt is made later. */
|
||||
* timer queue. If the timers cannot be started then reset uxTick so
|
||||
* another attempt is made later. */
|
||||
uxTick = ( TickType_t ) -1;
|
||||
|
||||
/* Try starting first timer. */
|
||||
|
|
@ -842,13 +848,13 @@ static TickType_t uxTick = ( TickType_t ) -1;
|
|||
if( xTimerChangePeriodFromISR( xISROneShotTimer, xBasePeriod, NULL ) == pdPASS )
|
||||
{
|
||||
/* Both timers were started, so set the uxTick back to its
|
||||
proper value. */
|
||||
* proper value. */
|
||||
uxTick = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Second timer could not be started, so stop the first one
|
||||
again. */
|
||||
* again. */
|
||||
xTimerStopFromISR( xISRAutoReloadTimer, NULL );
|
||||
}
|
||||
}
|
||||
|
|
@ -865,7 +871,7 @@ static TickType_t uxTick = ( TickType_t ) -1;
|
|||
else if( uxTick == ( xBasePeriod + xMargin ) )
|
||||
{
|
||||
/* Both timers should now have expired once. The auto-reload timer will
|
||||
still be active, but the one-shot timer should now have stopped. */
|
||||
* still be active, but the one-shot timer should now have stopped. */
|
||||
if( ( ucISRAutoReloadTimerCounter != 1 ) || ( ucISROneShotTimerCounter != 1 ) )
|
||||
{
|
||||
xTestStatus = pdFAIL;
|
||||
|
|
@ -875,8 +881,8 @@ static TickType_t uxTick = ( TickType_t ) -1;
|
|||
else if( uxTick == ( ( 2 * xBasePeriod ) - xMargin ) )
|
||||
{
|
||||
/* The auto-reload timer will still be active, but the one-shot timer
|
||||
should now have stopped - however, at this time neither of the timers
|
||||
should have expired again since the last test. */
|
||||
* should now have stopped - however, at this time neither of the timers
|
||||
* should have expired again since the last test. */
|
||||
if( ( ucISRAutoReloadTimerCounter != 1 ) || ( ucISROneShotTimerCounter != 1 ) )
|
||||
{
|
||||
xTestStatus = pdFAIL;
|
||||
|
|
@ -886,8 +892,8 @@ static TickType_t uxTick = ( TickType_t ) -1;
|
|||
else if( uxTick == ( ( 2 * xBasePeriod ) + xMargin ) )
|
||||
{
|
||||
/* The auto-reload timer will still be active, but the one-shot timer
|
||||
should now have stopped. At this time the auto-reload timer should have
|
||||
expired again, but the one-shot timer count should not have changed. */
|
||||
* should now have stopped. At this time the auto-reload timer should have
|
||||
* expired again, but the one-shot timer count should not have changed. */
|
||||
if( ucISRAutoReloadTimerCounter != 2 )
|
||||
{
|
||||
xTestStatus = pdFAIL;
|
||||
|
|
@ -903,8 +909,8 @@ static TickType_t uxTick = ( TickType_t ) -1;
|
|||
else if( uxTick == ( ( 2 * xBasePeriod ) + ( xBasePeriod >> ( TickType_t ) 2U ) ) )
|
||||
{
|
||||
/* The auto-reload timer will still be active, but the one-shot timer
|
||||
should now have stopped. Again though, at this time, neither timer call
|
||||
back should have been called since the last test. */
|
||||
* should now have stopped. Again though, at this time, neither timer call
|
||||
* back should have been called since the last test. */
|
||||
if( ucISRAutoReloadTimerCounter != 2 )
|
||||
{
|
||||
xTestStatus = pdFAIL;
|
||||
|
|
@ -925,8 +931,8 @@ static TickType_t uxTick = ( TickType_t ) -1;
|
|||
else if( uxTick == ( ( 3 * xBasePeriod ) + xMargin ) )
|
||||
{
|
||||
/* The auto-reload timer and one-shot timer will be active. At
|
||||
this time the auto-reload timer should have expired again, but the one
|
||||
shot timer count should not have changed yet. */
|
||||
* this time the auto-reload timer should have expired again, but the one
|
||||
* shot timer count should not have changed yet. */
|
||||
if( ucISRAutoReloadTimerCounter != 3 )
|
||||
{
|
||||
xTestStatus = pdFAIL;
|
||||
|
|
@ -940,14 +946,14 @@ static TickType_t uxTick = ( TickType_t ) -1;
|
|||
}
|
||||
|
||||
/* Now stop the auto-reload timer. The one-shot timer was started
|
||||
a few ticks ago. */
|
||||
* a few ticks ago. */
|
||||
xTimerStopFromISR( xISRAutoReloadTimer, NULL );
|
||||
}
|
||||
else if( uxTick == ( 4 * ( xBasePeriod - xMargin ) ) )
|
||||
{
|
||||
/* The auto-reload timer is now stopped, and the one-shot timer is
|
||||
active, but at this time neither timer should have expired since the
|
||||
last test. */
|
||||
* active, but at this time neither timer should have expired since the
|
||||
* last test. */
|
||||
if( ucISRAutoReloadTimerCounter != 3 )
|
||||
{
|
||||
xTestStatus = pdFAIL;
|
||||
|
|
@ -963,8 +969,8 @@ static TickType_t uxTick = ( TickType_t ) -1;
|
|||
else if( uxTick == ( ( 4 * xBasePeriod ) + xMargin ) )
|
||||
{
|
||||
/* The auto-reload timer is now stopped, and the one-shot timer is
|
||||
active. The one-shot timer should have expired again, but the auto
|
||||
reload timer should not have executed its callback. */
|
||||
* active. The one-shot timer should have expired again, but the auto
|
||||
* reload timer should not have executed its callback. */
|
||||
if( ucISRAutoReloadTimerCounter != 3 )
|
||||
{
|
||||
xTestStatus = pdFAIL;
|
||||
|
|
@ -980,8 +986,8 @@ static TickType_t uxTick = ( TickType_t ) -1;
|
|||
else if( uxTick == ( 8 * xBasePeriod ) )
|
||||
{
|
||||
/* The auto-reload timer is now stopped, and the one-shot timer has
|
||||
already expired and then stopped itself. Both callback counters should
|
||||
not have incremented since the last test. */
|
||||
* already expired and then stopped itself. Both callback counters should
|
||||
* not have incremented since the last test. */
|
||||
if( ucISRAutoReloadTimerCounter != 3 )
|
||||
{
|
||||
xTestStatus = pdFAIL;
|
||||
|
|
@ -1000,8 +1006,8 @@ static TickType_t uxTick = ( TickType_t ) -1;
|
|||
else if( uxTick == ( ( 9 * xBasePeriod ) - xMargin ) )
|
||||
{
|
||||
/* Only the one-shot timer should be running, but it should not have
|
||||
expired since the last test. Check the callback counters have not
|
||||
incremented, then reset the one-shot timer again. */
|
||||
* expired since the last test. Check the callback counters have not
|
||||
* incremented, then reset the one-shot timer again. */
|
||||
if( ucISRAutoReloadTimerCounter != 3 )
|
||||
{
|
||||
xTestStatus = pdFAIL;
|
||||
|
|
@ -1019,8 +1025,8 @@ static TickType_t uxTick = ( TickType_t ) -1;
|
|||
else if( uxTick == ( ( 10 * xBasePeriod ) - ( 2 * xMargin ) ) )
|
||||
{
|
||||
/* Only the one-shot timer should be running, but it should not have
|
||||
expired since the last test. Check the callback counters have not
|
||||
incremented, then reset the one-shot timer again. */
|
||||
* expired since the last test. Check the callback counters have not
|
||||
* incremented, then reset the one-shot timer again. */
|
||||
if( ucISRAutoReloadTimerCounter != 3 )
|
||||
{
|
||||
xTestStatus = pdFAIL;
|
||||
|
|
@ -1038,8 +1044,8 @@ static TickType_t uxTick = ( TickType_t ) -1;
|
|||
else if( uxTick == ( ( 11 * xBasePeriod ) - ( 3 * xMargin ) ) )
|
||||
{
|
||||
/* Only the one-shot timer should be running, but it should not have
|
||||
expired since the last test. Check the callback counters have not
|
||||
incremented, then reset the one-shot timer once again. */
|
||||
* expired since the last test. Check the callback counters have not
|
||||
* incremented, then reset the one-shot timer once again. */
|
||||
if( ucISRAutoReloadTimerCounter != 3 )
|
||||
{
|
||||
xTestStatus = pdFAIL;
|
||||
|
|
@ -1057,10 +1063,10 @@ static TickType_t uxTick = ( TickType_t ) -1;
|
|||
else if( uxTick == ( ( 12 * xBasePeriod ) - ( 2 * xMargin ) ) )
|
||||
{
|
||||
/* Only the one-shot timer should have been running and this time it
|
||||
should have expired. Check its callback count has been incremented.
|
||||
The auto-reload timer is still not running so should still have the same
|
||||
count value. This time the one-shot timer is not reset so should not
|
||||
restart from its expiry period again. */
|
||||
* should have expired. Check its callback count has been incremented.
|
||||
* The auto-reload timer is still not running so should still have the same
|
||||
* count value. This time the one-shot timer is not reset so should not
|
||||
* restart from its expiry period again. */
|
||||
if( ucISRAutoReloadTimerCounter != 3 )
|
||||
{
|
||||
xTestStatus = pdFAIL;
|
||||
|
|
@ -1076,8 +1082,8 @@ static TickType_t uxTick = ( TickType_t ) -1;
|
|||
else if( uxTick == ( 15 * xBasePeriod ) )
|
||||
{
|
||||
/* Neither timer should be running now. Check neither callback count
|
||||
has incremented, then go back to the start to run these tests all
|
||||
over again. */
|
||||
* has incremented, then go back to the start to run these tests all
|
||||
* over again. */
|
||||
if( ucISRAutoReloadTimerCounter != 3 )
|
||||
{
|
||||
xTestStatus = pdFAIL;
|
||||
|
|
@ -1099,15 +1105,16 @@ static TickType_t uxTick = ( TickType_t ) -1;
|
|||
|
||||
static void prvAutoReloadTimerCallback( TimerHandle_t pxExpiredTimer )
|
||||
{
|
||||
size_t uxTimerID;
|
||||
size_t uxTimerID;
|
||||
|
||||
uxTimerID = ( size_t ) pvTimerGetTimerID( pxExpiredTimer );
|
||||
|
||||
if( uxTimerID <= ( configTIMER_QUEUE_LENGTH + 1 ) )
|
||||
{
|
||||
( ucAutoReloadTimerCounters[ uxTimerID ] )++;
|
||||
|
||||
/* Stop timer ID 0 if requested. */
|
||||
if ( ( uxTimerID == ( size_t ) 0 ) && ( ucIsStopNeededInTimerZeroCallback == ( uint8_t ) pdTRUE ) )
|
||||
if( ( uxTimerID == ( size_t ) 0 ) && ( ucIsStopNeededInTimerZeroCallback == ( uint8_t ) pdTRUE ) )
|
||||
{
|
||||
xTimerStop( pxExpiredTimer, tmrdemoDONT_BLOCK );
|
||||
ucIsStopNeededInTimerZeroCallback = ( uint8_t ) pdFALSE;
|
||||
|
|
@ -1125,18 +1132,18 @@ size_t uxTimerID;
|
|||
static void prvOneShotTimerCallback( TimerHandle_t pxExpiredTimer )
|
||||
{
|
||||
/* A count is kept of the number of times this callback function is executed.
|
||||
The count is stored as the timer's ID. This is only done to test the
|
||||
vTimerSetTimerID() function. */
|
||||
static size_t uxCallCount = 0;
|
||||
size_t uxLastCallCount;
|
||||
* The count is stored as the timer's ID. This is only done to test the
|
||||
* vTimerSetTimerID() function. */
|
||||
static size_t uxCallCount = 0;
|
||||
size_t uxLastCallCount;
|
||||
|
||||
/* Obtain the timer's ID, which should be a count of the number of times
|
||||
this callback function has been executed. */
|
||||
* this callback function has been executed. */
|
||||
uxLastCallCount = ( size_t ) pvTimerGetTimerID( pxExpiredTimer );
|
||||
configASSERT( uxLastCallCount == uxCallCount );
|
||||
|
||||
/* Increment the call count, then save it back as the timer's ID. This is
|
||||
only done to test the vTimerSetTimerID() API function. */
|
||||
* only done to test the vTimerSetTimerID() API function. */
|
||||
uxLastCallCount++;
|
||||
vTimerSetTimerID( pxExpiredTimer, ( void * ) uxLastCallCount );
|
||||
uxCallCount++;
|
||||
|
|
@ -1148,7 +1155,7 @@ size_t uxLastCallCount;
|
|||
static void prvISRAutoReloadTimerCallback( TimerHandle_t pxExpiredTimer )
|
||||
{
|
||||
/* The parameter is not used in this case as only one timer uses this
|
||||
callback function. */
|
||||
* callback function. */
|
||||
( void ) pxExpiredTimer;
|
||||
|
||||
ucISRAutoReloadTimerCounter++;
|
||||
|
|
@ -1158,13 +1165,9 @@ static void prvISRAutoReloadTimerCallback( TimerHandle_t pxExpiredTimer )
|
|||
static void prvISROneShotTimerCallback( TimerHandle_t pxExpiredTimer )
|
||||
{
|
||||
/* The parameter is not used in this case as only one timer uses this
|
||||
callback function. */
|
||||
* callback function. */
|
||||
( void ) pxExpiredTimer;
|
||||
|
||||
ucISROneShotTimerCounter++;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@
|
|||
#define bktRUN_INDICATOR ( ( UBaseType_t ) 0x55 )
|
||||
|
||||
/* In case the demo does not have software timers enabled, as this file uses
|
||||
the configTIMER_TASK_PRIORITY setting. */
|
||||
* the configTIMER_TASK_PRIORITY setting. */
|
||||
#ifndef configTIMER_TASK_PRIORITY
|
||||
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
|
||||
#endif
|
||||
|
|
@ -72,8 +72,8 @@ the configTIMER_TASK_PRIORITY setting. */
|
|||
/*
|
||||
* The two test tasks. Their behaviour is commented within the functions.
|
||||
*/
|
||||
static void vPrimaryBlockTimeTestTask( void *pvParameters );
|
||||
static void vSecondaryBlockTimeTestTask( void *pvParameters );
|
||||
static void vPrimaryBlockTimeTestTask( void * pvParameters );
|
||||
static void vSecondaryBlockTimeTestTask( void * pvParameters );
|
||||
|
||||
/*
|
||||
* Very basic tests to verify the block times are as expected.
|
||||
|
|
@ -86,7 +86,7 @@ static void prvBasicDelayTests( void );
|
|||
static QueueHandle_t xTestQueue;
|
||||
|
||||
/* Handle to the secondary task is required by the primary task for calls
|
||||
to vTaskSuspend/Resume(). */
|
||||
* to vTaskSuspend/Resume(). */
|
||||
static TaskHandle_t xSecondary;
|
||||
|
||||
/* Used to ensure that tasks are still executing without error. */
|
||||
|
|
@ -94,7 +94,7 @@ static volatile BaseType_t xPrimaryCycles = 0, xSecondaryCycles = 0;
|
|||
static volatile BaseType_t xErrorOccurred = pdFALSE;
|
||||
|
||||
/* Provides a simple mechanism for the primary task to know when the
|
||||
secondary task has executed. */
|
||||
* secondary task has executed. */
|
||||
static volatile UBaseType_t xRunIndicator;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
|
@ -107,11 +107,11 @@ void vCreateBlockTimeTasks( void )
|
|||
if( xTestQueue != NULL )
|
||||
{
|
||||
/* vQueueAddToRegistry() adds the queue to the queue registry, if one
|
||||
is in use. The queue registry is provided as a means for kernel aware
|
||||
debuggers to locate queues 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 defined to be less than 1. */
|
||||
* is in use. The queue registry is provided as a means for kernel aware
|
||||
* debuggers to locate queues 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 defined to be less than 1. */
|
||||
vQueueAddToRegistry( xTestQueue, "Block_Time_Queue" );
|
||||
|
||||
/* Create the two test tasks. */
|
||||
|
|
@ -121,37 +121,36 @@ void vCreateBlockTimeTasks( void )
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vPrimaryBlockTimeTestTask( void *pvParameters )
|
||||
static void vPrimaryBlockTimeTestTask( void * pvParameters )
|
||||
{
|
||||
BaseType_t xItem, xData;
|
||||
TickType_t xTimeWhenBlocking;
|
||||
TickType_t xTimeToBlock, xBlockedTime;
|
||||
BaseType_t xItem, xData;
|
||||
TickType_t xTimeWhenBlocking;
|
||||
TickType_t xTimeToBlock, xBlockedTime;
|
||||
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/*********************************************************************
|
||||
Test 0
|
||||
|
||||
Basic vTaskDelay() and vTaskDelayUntil() tests. */
|
||||
* Test 0
|
||||
*
|
||||
* Basic vTaskDelay() and vTaskDelayUntil() tests. */
|
||||
prvBasicDelayTests();
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
Test 1
|
||||
|
||||
Simple block time wakeup test on queue receives. */
|
||||
* Test 1
|
||||
*
|
||||
* Simple block time wakeup test on queue receives. */
|
||||
for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
|
||||
{
|
||||
/* The queue is empty. Attempt to read from the queue using a block
|
||||
time. When we wake, ensure the delta in time is as expected. */
|
||||
* time. When we wake, ensure the delta in time is as expected. */
|
||||
xTimeToBlock = ( TickType_t ) ( bktPRIMARY_BLOCK_TIME << xItem );
|
||||
|
||||
xTimeWhenBlocking = xTaskGetTickCount();
|
||||
|
||||
/* We should unblock after xTimeToBlock having not received
|
||||
anything on the queue. */
|
||||
* anything on the queue. */
|
||||
if( xQueueReceive( xTestQueue, &xData, xTimeToBlock ) != errQUEUE_EMPTY )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
|
|
@ -169,18 +168,18 @@ TickType_t xTimeToBlock, xBlockedTime;
|
|||
if( xBlockedTime > ( xTimeToBlock + bktALLOWABLE_MARGIN ) )
|
||||
{
|
||||
/* Should not have blocked for longer than we requested,
|
||||
although we would not necessarily run as soon as we were
|
||||
unblocked so a margin is allowed. */
|
||||
* although we would not necessarily run as soon as we were
|
||||
* unblocked so a margin is allowed. */
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
Test 2
|
||||
|
||||
Simple block time wakeup test on queue sends.
|
||||
|
||||
First fill the queue. It should be empty so all sends should pass. */
|
||||
* Test 2
|
||||
*
|
||||
* Simple block time wakeup test on queue sends.
|
||||
*
|
||||
* First fill the queue. It should be empty so all sends should pass. */
|
||||
for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
|
||||
{
|
||||
if( xQueueSend( xTestQueue, &xItem, bktDONT_BLOCK ) != pdPASS )
|
||||
|
|
@ -196,13 +195,13 @@ TickType_t xTimeToBlock, xBlockedTime;
|
|||
for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
|
||||
{
|
||||
/* The queue is full. Attempt to write to the queue using a block
|
||||
time. When we wake, ensure the delta in time is as expected. */
|
||||
* time. When we wake, ensure the delta in time is as expected. */
|
||||
xTimeToBlock = ( TickType_t ) ( bktPRIMARY_BLOCK_TIME << xItem );
|
||||
|
||||
xTimeWhenBlocking = xTaskGetTickCount();
|
||||
|
||||
/* We should unblock after xTimeToBlock having not received
|
||||
anything on the queue. */
|
||||
* anything on the queue. */
|
||||
if( xQueueSend( xTestQueue, &xItem, xTimeToBlock ) != errQUEUE_FULL )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
|
|
@ -220,24 +219,24 @@ TickType_t xTimeToBlock, xBlockedTime;
|
|||
if( xBlockedTime > ( xTimeToBlock + bktALLOWABLE_MARGIN ) )
|
||||
{
|
||||
/* Should not have blocked for longer than we requested,
|
||||
although we would not necessarily run as soon as we were
|
||||
unblocked so a margin is allowed. */
|
||||
* although we would not necessarily run as soon as we were
|
||||
* unblocked so a margin is allowed. */
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
Test 3
|
||||
|
||||
Wake the other task, it will block attempting to post to the queue.
|
||||
When we read from the queue the other task will wake, but before it
|
||||
can run we will post to the queue again. When the other task runs it
|
||||
will find the queue still full, even though it was woken. It should
|
||||
recognise that its block time has not expired and return to block for
|
||||
the remains of its block time.
|
||||
|
||||
Wake the other task so it blocks attempting to post to the already
|
||||
full queue. */
|
||||
* Test 3
|
||||
*
|
||||
* Wake the other task, it will block attempting to post to the queue.
|
||||
* When we read from the queue the other task will wake, but before it
|
||||
* can run we will post to the queue again. When the other task runs it
|
||||
* will find the queue still full, even though it was woken. It should
|
||||
* recognise that its block time has not expired and return to block for
|
||||
* the remains of its block time.
|
||||
*
|
||||
* Wake the other task so it blocks attempting to post to the already
|
||||
* full queue. */
|
||||
xRunIndicator = 0;
|
||||
vTaskResume( xSecondary );
|
||||
|
||||
|
|
@ -247,6 +246,7 @@ TickType_t xTimeToBlock, xBlockedTime;
|
|||
/* The other task has not yet executed. */
|
||||
vTaskDelay( bktSHORT_WAIT );
|
||||
}
|
||||
|
||||
/* Make sure the other task is blocked on the queue. */
|
||||
vTaskDelay( bktSHORT_WAIT );
|
||||
xRunIndicator = 0;
|
||||
|
|
@ -254,15 +254,15 @@ TickType_t xTimeToBlock, xBlockedTime;
|
|||
for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
|
||||
{
|
||||
/* Now when we make space on the queue the other task should wake
|
||||
but not execute as this task has higher priority. */
|
||||
* but not execute as this task has higher priority. */
|
||||
if( xQueueReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
/* Now fill the queue again before the other task gets a chance to
|
||||
execute. If the other task had executed we would find the queue
|
||||
full ourselves, and the other task have set xRunIndicator. */
|
||||
* execute. If the other task had executed we would find the queue
|
||||
* full ourselves, and the other task have set xRunIndicator. */
|
||||
if( xQueueSend( xTestQueue, &xItem, bktDONT_BLOCK ) != pdPASS )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
|
|
@ -275,15 +275,15 @@ TickType_t xTimeToBlock, xBlockedTime;
|
|||
}
|
||||
|
||||
/* Raise the priority of the other task so it executes and blocks
|
||||
on the queue again. */
|
||||
* on the queue again. */
|
||||
vTaskPrioritySet( xSecondary, bktPRIMARY_PRIORITY + 2 );
|
||||
|
||||
/* The other task should now have re-blocked without exiting the
|
||||
queue function. */
|
||||
* queue function. */
|
||||
if( xRunIndicator == bktRUN_INDICATOR )
|
||||
{
|
||||
/* The other task should not have executed outside of the
|
||||
queue function. */
|
||||
* queue function. */
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
|
|
@ -292,22 +292,22 @@ TickType_t xTimeToBlock, xBlockedTime;
|
|||
}
|
||||
|
||||
/* Let the other task timeout. When it unblockes it will check that it
|
||||
unblocked at the correct time, then suspend itself. */
|
||||
* unblocked at the correct time, then suspend itself. */
|
||||
while( xRunIndicator != bktRUN_INDICATOR )
|
||||
{
|
||||
vTaskDelay( bktSHORT_WAIT );
|
||||
}
|
||||
|
||||
vTaskDelay( bktSHORT_WAIT );
|
||||
xRunIndicator = 0;
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
Test 4
|
||||
|
||||
As per test 3 - but with the send and receive the other way around.
|
||||
The other task blocks attempting to read from the queue.
|
||||
|
||||
Empty the queue. We should find that it is full. */
|
||||
* Test 4
|
||||
*
|
||||
* As per test 3 - but with the send and receive the other way around.
|
||||
* The other task blocks attempting to read from the queue.
|
||||
*
|
||||
* Empty the queue. We should find that it is full. */
|
||||
for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
|
||||
{
|
||||
if( xQueueReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )
|
||||
|
|
@ -317,7 +317,7 @@ TickType_t xTimeToBlock, xBlockedTime;
|
|||
}
|
||||
|
||||
/* Wake the other task so it blocks attempting to read from the
|
||||
already empty queue. */
|
||||
* already empty queue. */
|
||||
vTaskResume( xSecondary );
|
||||
|
||||
/* We need to wait a little to ensure the other task executes. */
|
||||
|
|
@ -325,21 +325,22 @@ TickType_t xTimeToBlock, xBlockedTime;
|
|||
{
|
||||
vTaskDelay( bktSHORT_WAIT );
|
||||
}
|
||||
|
||||
vTaskDelay( bktSHORT_WAIT );
|
||||
xRunIndicator = 0;
|
||||
|
||||
for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
|
||||
{
|
||||
/* Now when we place an item on the queue the other task should
|
||||
wake but not execute as this task has higher priority. */
|
||||
* wake but not execute as this task has higher priority. */
|
||||
if( xQueueSend( xTestQueue, &xItem, bktDONT_BLOCK ) != pdPASS )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
/* Now empty the queue again before the other task gets a chance to
|
||||
execute. If the other task had executed we would find the queue
|
||||
empty ourselves, and the other task would be suspended. */
|
||||
* execute. If the other task had executed we would find the queue
|
||||
* empty ourselves, and the other task would be suspended. */
|
||||
if( xQueueReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
|
|
@ -352,26 +353,28 @@ TickType_t xTimeToBlock, xBlockedTime;
|
|||
}
|
||||
|
||||
/* Raise the priority of the other task so it executes and blocks
|
||||
on the queue again. */
|
||||
* on the queue again. */
|
||||
vTaskPrioritySet( xSecondary, bktPRIMARY_PRIORITY + 2 );
|
||||
|
||||
/* The other task should now have re-blocked without exiting the
|
||||
queue function. */
|
||||
* queue function. */
|
||||
if( xRunIndicator == bktRUN_INDICATOR )
|
||||
{
|
||||
/* The other task should not have executed outside of the
|
||||
queue function. */
|
||||
* queue function. */
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
vTaskPrioritySet( xSecondary, bktSECONDARY_PRIORITY );
|
||||
}
|
||||
|
||||
/* Let the other task timeout. When it unblockes it will check that it
|
||||
unblocked at the correct time, then suspend itself. */
|
||||
* unblocked at the correct time, then suspend itself. */
|
||||
while( xRunIndicator != bktRUN_INDICATOR )
|
||||
{
|
||||
vTaskDelay( bktSHORT_WAIT );
|
||||
}
|
||||
|
||||
vTaskDelay( bktSHORT_WAIT );
|
||||
|
||||
xPrimaryCycles++;
|
||||
|
|
@ -379,33 +382,34 @@ TickType_t xTimeToBlock, xBlockedTime;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vSecondaryBlockTimeTestTask( void *pvParameters )
|
||||
static void vSecondaryBlockTimeTestTask( void * pvParameters )
|
||||
{
|
||||
TickType_t xTimeWhenBlocking, xBlockedTime;
|
||||
BaseType_t xData;
|
||||
TickType_t xTimeWhenBlocking, xBlockedTime;
|
||||
BaseType_t xData;
|
||||
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/*********************************************************************
|
||||
Test 0, 1 and 2
|
||||
|
||||
This task does not participate in these tests. */
|
||||
* Test 0, 1 and 2
|
||||
*
|
||||
* This task does not participate in these tests. */
|
||||
vTaskSuspend( NULL );
|
||||
|
||||
/*********************************************************************
|
||||
Test 3
|
||||
|
||||
The first thing we do is attempt to read from the queue. It should be
|
||||
full so we block. Note the time before we block so we can check the
|
||||
wake time is as per that expected. */
|
||||
* Test 3
|
||||
*
|
||||
* The first thing we do is attempt to read from the queue. It should be
|
||||
* full so we block. Note the time before we block so we can check the
|
||||
* wake time is as per that expected. */
|
||||
xTimeWhenBlocking = xTaskGetTickCount();
|
||||
|
||||
/* We should unblock after bktTIME_TO_BLOCK having not sent anything to
|
||||
the queue. */
|
||||
* the queue. */
|
||||
xData = 0;
|
||||
xRunIndicator = bktRUN_INDICATOR;
|
||||
|
||||
if( xQueueSend( xTestQueue, &xData, bktTIME_TO_BLOCK ) != errQUEUE_FULL )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
|
|
@ -421,8 +425,8 @@ BaseType_t xData;
|
|||
}
|
||||
|
||||
/* We should of not blocked for much longer than bktALLOWABLE_MARGIN
|
||||
either. A margin is permitted as we would not necessarily run as
|
||||
soon as we unblocked. */
|
||||
* either. A margin is permitted as we would not necessarily run as
|
||||
* soon as we unblocked. */
|
||||
if( xBlockedTime > ( bktTIME_TO_BLOCK + bktALLOWABLE_MARGIN ) )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
|
|
@ -433,14 +437,15 @@ BaseType_t xData;
|
|||
vTaskSuspend( NULL );
|
||||
|
||||
/*********************************************************************
|
||||
Test 4
|
||||
|
||||
As per test three, but with the send and receive reversed. */
|
||||
* Test 4
|
||||
*
|
||||
* As per test three, but with the send and receive reversed. */
|
||||
xTimeWhenBlocking = xTaskGetTickCount();
|
||||
|
||||
/* We should unblock after bktTIME_TO_BLOCK having not received
|
||||
anything on the queue. */
|
||||
* anything on the queue. */
|
||||
xRunIndicator = bktRUN_INDICATOR;
|
||||
|
||||
if( xQueueReceive( xTestQueue, &xData, bktTIME_TO_BLOCK ) != errQUEUE_EMPTY )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
|
|
@ -455,8 +460,8 @@ BaseType_t xData;
|
|||
}
|
||||
|
||||
/* We should of not blocked for much longer than bktALLOWABLE_MARGIN
|
||||
either. A margin is permitted as we would not necessarily run as soon
|
||||
as we unblocked. */
|
||||
* either. A margin is permitted as we would not necessarily run as soon
|
||||
* as we unblocked. */
|
||||
if( xBlockedTime > ( bktTIME_TO_BLOCK + bktALLOWABLE_MARGIN ) )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
|
|
@ -471,22 +476,22 @@ BaseType_t xData;
|
|||
|
||||
static void prvBasicDelayTests( void )
|
||||
{
|
||||
TickType_t xPreTime, xPostTime, x, xLastUnblockTime, xExpectedUnblockTime;
|
||||
const TickType_t xPeriod = 75, xCycles = 5, xAllowableMargin = ( bktALLOWABLE_MARGIN >> 1 ), xHalfPeriod = xPeriod / ( TickType_t ) 2;
|
||||
BaseType_t xDidBlock;
|
||||
TickType_t xPreTime, xPostTime, x, xLastUnblockTime, xExpectedUnblockTime;
|
||||
const TickType_t xPeriod = 75, xCycles = 5, xAllowableMargin = ( bktALLOWABLE_MARGIN >> 1 ), xHalfPeriod = xPeriod / ( TickType_t ) 2;
|
||||
BaseType_t xDidBlock;
|
||||
|
||||
/* Temporarily increase priority so the timing is more accurate, but not so
|
||||
high as to disrupt the timer tests. */
|
||||
* high as to disrupt the timer tests. */
|
||||
vTaskPrioritySet( NULL, configTIMER_TASK_PRIORITY - 1 );
|
||||
|
||||
/* Crude check to too see that vTaskDelay() blocks for the expected
|
||||
period. */
|
||||
* period. */
|
||||
xPreTime = xTaskGetTickCount();
|
||||
vTaskDelay( bktTIME_TO_BLOCK );
|
||||
xPostTime = xTaskGetTickCount();
|
||||
|
||||
/* The priority is higher, so the allowable margin is halved when compared
|
||||
to the other tests in this file. */
|
||||
* to the other tests in this file. */
|
||||
if( ( xPostTime - xPreTime ) > ( bktTIME_TO_BLOCK + xAllowableMargin ) )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
|
|
@ -499,7 +504,7 @@ BaseType_t xDidBlock;
|
|||
for( x = 0; x < xCycles; x++ )
|
||||
{
|
||||
/* Calculate the next expected unblock time from the time taken before
|
||||
this loop was entered. */
|
||||
* this loop was entered. */
|
||||
xExpectedUnblockTime = xPostTime + ( x * xPeriod );
|
||||
|
||||
vTaskDelayUntil( &xLastUnblockTime, xPeriod );
|
||||
|
|
@ -513,26 +518,29 @@ BaseType_t xDidBlock;
|
|||
}
|
||||
|
||||
/* Crude tests for return value of xTaskDelayUntil(). First a standard block
|
||||
should return that the task does block. */
|
||||
* should return that the task does block. */
|
||||
xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
|
||||
|
||||
if( xDidBlock != pdTRUE )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
/* Now delay a few ticks so repeating the above block period will not block for
|
||||
the full amount of time, but will still block. */
|
||||
* the full amount of time, but will still block. */
|
||||
vTaskDelay( xHalfPeriod );
|
||||
xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
|
||||
|
||||
if( xDidBlock != pdTRUE )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
/* This time block for longer than xPeriod before calling xTaskDelayUntil() so
|
||||
the call to xTaskDelayUntil() should not block. */
|
||||
* the call to xTaskDelayUntil() should not block. */
|
||||
vTaskDelay( xPeriod );
|
||||
xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
|
||||
|
||||
if( xDidBlock != pdFALSE )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
|
|
@ -540,15 +548,17 @@ BaseType_t xDidBlock;
|
|||
|
||||
/* Catch up. */
|
||||
xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
|
||||
|
||||
if( xDidBlock != pdTRUE )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
/* Again block for slightly longer than a period so ensure the time is in the
|
||||
past next time xTaskDelayUntil() gets called. */
|
||||
* past next time xTaskDelayUntil() gets called. */
|
||||
vTaskDelay( xPeriod + xAllowableMargin );
|
||||
xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
|
||||
|
||||
if( xDidBlock != pdFALSE )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
|
|
@ -561,11 +571,11 @@ BaseType_t xDidBlock;
|
|||
|
||||
BaseType_t xAreBlockTimeTestTasksStillRunning( void )
|
||||
{
|
||||
static BaseType_t xLastPrimaryCycleCount = 0, xLastSecondaryCycleCount = 0;
|
||||
BaseType_t xReturn = pdPASS;
|
||||
static BaseType_t xLastPrimaryCycleCount = 0, xLastSecondaryCycleCount = 0;
|
||||
BaseType_t xReturn = pdPASS;
|
||||
|
||||
/* Have both tasks performed at least one cycle since this function was
|
||||
last called? */
|
||||
* last called? */
|
||||
if( xPrimaryCycles == xLastPrimaryCycleCount )
|
||||
{
|
||||
xReturn = pdFAIL;
|
||||
|
|
|
|||
|
|
@ -73,13 +73,13 @@
|
|||
#define comTOTAL_PERMISSIBLE_ERRORS ( 2 )
|
||||
|
||||
/* The Tx task will transmit the sequence of characters at a pseudo random
|
||||
interval. This is the maximum and minimum block time between sends. */
|
||||
* interval. This is the maximum and minimum block time between sends. */
|
||||
#define comTX_MAX_BLOCK_TIME ( ( TickType_t ) 0x96 )
|
||||
#define comTX_MIN_BLOCK_TIME ( ( TickType_t ) 0x32 )
|
||||
#define comOFFSET_TIME ( ( TickType_t ) 3 )
|
||||
|
||||
/* We should find that each character can be queued for Tx immediately and we
|
||||
don't have to block to send. */
|
||||
* don't have to block to send. */
|
||||
#define comNO_BLOCK ( ( TickType_t ) 0 )
|
||||
|
||||
/* The Rx task will block on the Rx queue for a long period. */
|
||||
|
|
@ -102,18 +102,20 @@ static portTASK_FUNCTION_PROTO( vComTxTask, pvParameters );
|
|||
static portTASK_FUNCTION_PROTO( vComRxTask, pvParameters );
|
||||
|
||||
/* The LED that should be toggled by the Rx and Tx tasks. The Rx task will
|
||||
toggle LED ( uxBaseLED + comRX_LED_OFFSET). The Tx task will toggle LED
|
||||
( uxBaseLED + comTX_LED_OFFSET ). */
|
||||
* toggle LED ( uxBaseLED + comRX_LED_OFFSET). The Tx task will toggle LED
|
||||
* ( uxBaseLED + comTX_LED_OFFSET ). */
|
||||
static UBaseType_t uxBaseLED = 0;
|
||||
|
||||
/* Check variable used to ensure no error have occurred. The Rx task will
|
||||
increment this variable after every successfully received sequence. If at any
|
||||
time the sequence is incorrect the the variable will stop being incremented. */
|
||||
* increment this variable after every successfully received sequence. If at any
|
||||
* time the sequence is incorrect the the variable will stop being incremented. */
|
||||
static volatile UBaseType_t uxRxLoops = comINITIAL_RX_COUNT_VALUE;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vAltStartComTestTasks( UBaseType_t uxPriority, uint32_t ulBaudRate, UBaseType_t uxLED )
|
||||
void vAltStartComTestTasks( UBaseType_t uxPriority,
|
||||
uint32_t ulBaudRate,
|
||||
UBaseType_t uxLED )
|
||||
{
|
||||
/* Initialise the com port then spawn the Rx and Tx tasks. */
|
||||
uxBaseLED = uxLED;
|
||||
|
|
@ -127,16 +129,16 @@ void vAltStartComTestTasks( UBaseType_t uxPriority, uint32_t ulBaudRate, UBaseTy
|
|||
|
||||
static portTASK_FUNCTION( vComTxTask, pvParameters )
|
||||
{
|
||||
char cByteToSend;
|
||||
TickType_t xTimeToWait;
|
||||
char cByteToSend;
|
||||
TickType_t xTimeToWait;
|
||||
|
||||
/* Just to stop compiler warnings. */
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Simply transmit a sequence of characters from comFIRST_BYTE to
|
||||
comLAST_BYTE. */
|
||||
* comLAST_BYTE. */
|
||||
for( cByteToSend = comFIRST_BYTE; cByteToSend <= comLAST_BYTE; cByteToSend++ )
|
||||
{
|
||||
if( xSerialPutChar( xPort, cByteToSend, comNO_BLOCK ) == pdPASS )
|
||||
|
|
@ -149,8 +151,8 @@ TickType_t xTimeToWait;
|
|||
vParTestSetLED( uxBaseLED + comTX_LED_OFFSET, pdFALSE );
|
||||
|
||||
/* We have posted all the characters in the string - wait before
|
||||
re-sending. Wait a pseudo-random time as this will provide a better
|
||||
test. */
|
||||
* re-sending. Wait a pseudo-random time as this will provide a better
|
||||
* test. */
|
||||
xTimeToWait = xTaskGetTickCount() + comOFFSET_TIME;
|
||||
|
||||
/* Make sure we don't wait too long... */
|
||||
|
|
@ -169,25 +171,25 @@ TickType_t xTimeToWait;
|
|||
|
||||
static portTASK_FUNCTION( vComRxTask, pvParameters )
|
||||
{
|
||||
signed char cExpectedByte, cByteRxed;
|
||||
BaseType_t xResyncRequired = pdFALSE, xErrorOccurred = pdFALSE;
|
||||
signed char cExpectedByte, cByteRxed;
|
||||
BaseType_t xResyncRequired = pdFALSE, xErrorOccurred = pdFALSE;
|
||||
|
||||
/* Just to stop compiler warnings. */
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* We expect to receive the characters from comFIRST_BYTE to
|
||||
comLAST_BYTE in an incrementing order. Loop to receive each byte. */
|
||||
* comLAST_BYTE in an incrementing order. Loop to receive each byte. */
|
||||
for( cExpectedByte = comFIRST_BYTE; cExpectedByte <= comLAST_BYTE; cExpectedByte++ )
|
||||
{
|
||||
/* Block on the queue that contains received bytes until a byte is
|
||||
available. */
|
||||
* available. */
|
||||
if( xSerialGetChar( xPort, &cByteRxed, comRX_BLOCK_TIME ) )
|
||||
{
|
||||
/* Was this the byte we were expecting? If so, toggle the LED,
|
||||
otherwise we are out on sync and should break out of the loop
|
||||
until the expected character sequence is about to restart. */
|
||||
* otherwise we are out on sync and should break out of the loop
|
||||
* until the expected character sequence is about to restart. */
|
||||
if( cByteRxed == cExpectedByte )
|
||||
{
|
||||
vParTestToggleLED( uxBaseLED + comRX_LED_OFFSET );
|
||||
|
|
@ -204,8 +206,8 @@ BaseType_t xResyncRequired = pdFALSE, xErrorOccurred = pdFALSE;
|
|||
vParTestSetLED( uxBaseLED + comRX_LED_OFFSET, pdFALSE );
|
||||
|
||||
/* Did we break out of the loop because the characters were received in
|
||||
an unexpected order? If so wait here until the character sequence is
|
||||
about to restart. */
|
||||
* an unexpected order? If so wait here until the character sequence is
|
||||
* about to restart. */
|
||||
if( xResyncRequired == pdTRUE )
|
||||
{
|
||||
while( cByteRxed != comLAST_BYTE )
|
||||
|
|
@ -215,9 +217,9 @@ BaseType_t xResyncRequired = pdFALSE, xErrorOccurred = pdFALSE;
|
|||
}
|
||||
|
||||
/* Note that an error occurred which caused us to have to resync.
|
||||
We use this to stop incrementing the loop counter so
|
||||
sAreComTestTasksStillRunning() will return false - indicating an
|
||||
error. */
|
||||
* We use this to stop incrementing the loop counter so
|
||||
* sAreComTestTasksStillRunning() will return false - indicating an
|
||||
* error. */
|
||||
xErrorOccurred++;
|
||||
|
||||
/* We have now resynced with the Tx task and can continue. */
|
||||
|
|
@ -228,11 +230,11 @@ BaseType_t xResyncRequired = pdFALSE, xErrorOccurred = pdFALSE;
|
|||
if( xErrorOccurred < comTOTAL_PERMISSIBLE_ERRORS )
|
||||
{
|
||||
/* Increment the count of successful loops. As error
|
||||
occurring (i.e. an unexpected character being received) will
|
||||
prevent this counter being incremented for the rest of the
|
||||
execution. Don't worry about mutual exclusion on this
|
||||
variable - it doesn't really matter as we just want it
|
||||
to change. */
|
||||
* occurring (i.e. an unexpected character being received) will
|
||||
* prevent this counter being incremented for the rest of the
|
||||
* execution. Don't worry about mutual exclusion on this
|
||||
* variable - it doesn't really matter as we just want it
|
||||
* to change. */
|
||||
uxRxLoops++;
|
||||
}
|
||||
}
|
||||
|
|
@ -242,11 +244,11 @@ BaseType_t xResyncRequired = pdFALSE, xErrorOccurred = pdFALSE;
|
|||
|
||||
BaseType_t xAreComTestTasksStillRunning( void )
|
||||
{
|
||||
BaseType_t xReturn;
|
||||
BaseType_t xReturn;
|
||||
|
||||
/* If the count of successful reception loops has not changed than at
|
||||
some time an error occurred (i.e. a character was received out of sequence)
|
||||
and we will return false. */
|
||||
* some time an error occurred (i.e. a character was received out of sequence)
|
||||
* and we will return false. */
|
||||
if( uxRxLoops == comINITIAL_RX_COUNT_VALUE )
|
||||
{
|
||||
xReturn = pdFALSE;
|
||||
|
|
@ -257,9 +259,8 @@ BaseType_t xReturn;
|
|||
}
|
||||
|
||||
/* Reset the count of successful Rx loops. When this function is called
|
||||
again we expect this to have been incremented. */
|
||||
* again we expect this to have been incremented. */
|
||||
uxRxLoops = comINITIAL_RX_COUNT_VALUE;
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -78,8 +78,8 @@
|
|||
#define comRX_LED_OFFSET ( 1 )
|
||||
|
||||
/* The Tx timer transmits the sequence of characters at a pseudo random
|
||||
interval that is capped between comTX_MAX_BLOCK_TIME and
|
||||
comTX_MIN_BLOCK_TIME. */
|
||||
* interval that is capped between comTX_MAX_BLOCK_TIME and
|
||||
* comTX_MIN_BLOCK_TIME. */
|
||||
#define comTX_MAX_BLOCK_TIME ( ( TickType_t ) 0x96 )
|
||||
#define comTX_MIN_BLOCK_TIME ( ( TickType_t ) 0x32 )
|
||||
#define comOFFSET_TIME ( ( TickType_t ) 3 )
|
||||
|
|
@ -89,10 +89,10 @@ comTX_MIN_BLOCK_TIME. */
|
|||
#define comtstWAITING_END_OF_STRING 1
|
||||
|
||||
/* A short delay in ticks - this delay is used to allow the Rx queue to fill up
|
||||
a bit so more than one character can be processed at a time. This is relative
|
||||
to comTX_MIN_BLOCK_TIME to ensure it is never longer than the shortest gap
|
||||
between transmissions. It could be worked out more scientifically from the
|
||||
baud rate being used. */
|
||||
* a bit so more than one character can be processed at a time. This is relative
|
||||
* to comTX_MIN_BLOCK_TIME to ensure it is never longer than the shortest gap
|
||||
* between transmissions. It could be worked out more scientifically from the
|
||||
* baud rate being used. */
|
||||
#define comSHORT_DELAY ( comTX_MIN_BLOCK_TIME >> ( TickType_t ) 2 )
|
||||
|
||||
/* The string that is transmitted and received. */
|
||||
|
|
@ -105,50 +105,52 @@ baud rate being used. */
|
|||
static xComPortHandle xPort = NULL;
|
||||
|
||||
/* The callback function allocated to the transmit timer, as described in the
|
||||
comments at the top of this file. */
|
||||
* comments at the top of this file. */
|
||||
static void prvComTxTimerCallback( TimerHandle_t xTimer );
|
||||
|
||||
/* The receive task as described in the comments at the top of this file. */
|
||||
static void vComRxTask( void *pvParameters );
|
||||
static void vComRxTask( void * pvParameters );
|
||||
|
||||
/* The Rx task will toggle LED ( uxBaseLED + comRX_LED_OFFSET). The Tx task
|
||||
will toggle LED ( uxBaseLED + comTX_LED_OFFSET ). */
|
||||
* will toggle LED ( uxBaseLED + comTX_LED_OFFSET ). */
|
||||
static UBaseType_t uxBaseLED = 0;
|
||||
|
||||
/* The Rx task toggles uxRxLoops on each successful iteration of its defined
|
||||
function - provided no errors have ever been latched. If this variable stops
|
||||
incrementing, then an error has occurred. */
|
||||
* function - provided no errors have ever been latched. If this variable stops
|
||||
* incrementing, then an error has occurred. */
|
||||
static volatile UBaseType_t uxRxLoops = 0UL;
|
||||
|
||||
/* The timer used to periodically transmit the string. This is the timer that
|
||||
has prvComTxTimerCallback allocated to it as its callback function. */
|
||||
* has prvComTxTimerCallback allocated to it as its callback function. */
|
||||
static TimerHandle_t xTxTimer = NULL;
|
||||
|
||||
/* The string length is held at file scope so the Tx timer does not need to
|
||||
calculate it each time it executes. */
|
||||
* calculate it each time it executes. */
|
||||
static size_t xStringLength = 0U;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vStartComTestStringsTasks( UBaseType_t uxPriority, uint32_t ulBaudRate, UBaseType_t uxLED )
|
||||
void vStartComTestStringsTasks( UBaseType_t uxPriority,
|
||||
uint32_t ulBaudRate,
|
||||
UBaseType_t uxLED )
|
||||
{
|
||||
/* Store values that are used at run time. */
|
||||
uxBaseLED = uxLED;
|
||||
|
||||
/* Calculate the string length here, rather than each time the Tx timer
|
||||
executes. */
|
||||
* executes. */
|
||||
xStringLength = strlen( comTRANSACTED_STRING );
|
||||
|
||||
/* Include the null terminator in the string length as this is used to
|
||||
detect the end of the string in the Rx task. */
|
||||
* detect the end of the string in the Rx task. */
|
||||
xStringLength++;
|
||||
|
||||
/* Initialise the com port, then spawn the Rx task and create the Tx
|
||||
timer. */
|
||||
* timer. */
|
||||
xSerialPortInitMinimal( ulBaudRate, ( xStringLength * 2U ) );
|
||||
|
||||
/* Create the Rx task and the Tx timer. The timer is started from the
|
||||
Rx task. */
|
||||
* Rx task. */
|
||||
xTaskCreate( vComRxTask, "COMRx", comSTACK_SIZE, NULL, uxPriority, ( TaskHandle_t * ) NULL );
|
||||
xTxTimer = xTimerCreate( "TxTimer", comTX_MIN_BLOCK_TIME, pdFALSE, NULL, prvComTxTimerCallback );
|
||||
configASSERT( xTxTimer );
|
||||
|
|
@ -157,19 +159,19 @@ void vStartComTestStringsTasks( UBaseType_t uxPriority, uint32_t ulBaudRate, UBa
|
|||
|
||||
static void prvComTxTimerCallback( TimerHandle_t xTimer )
|
||||
{
|
||||
TickType_t xTimeToWait;
|
||||
TickType_t xTimeToWait;
|
||||
|
||||
/* The parameter is not used in this case. */
|
||||
( void ) xTimer;
|
||||
|
||||
/* Send the string. How this is actually performed depends on the
|
||||
sample driver provided with this demo. However - as this is a timer,
|
||||
it executes in the context of the timer task and therefore must not
|
||||
block. */
|
||||
* sample driver provided with this demo. However - as this is a timer,
|
||||
* it executes in the context of the timer task and therefore must not
|
||||
* block. */
|
||||
vSerialPutString( xPort, comTRANSACTED_STRING, xStringLength );
|
||||
|
||||
/* Toggle an LED to give a visible indication that another transmission
|
||||
has been performed. */
|
||||
* has been performed. */
|
||||
vParTestToggleLED( uxBaseLED + comTX_LED_OFFSET );
|
||||
|
||||
/* Wait a pseudo random time before sending the string again. */
|
||||
|
|
@ -185,76 +187,79 @@ TickType_t xTimeToWait;
|
|||
}
|
||||
|
||||
/* Reset the timer to run again xTimeToWait ticks from now. This function
|
||||
is called from the context of the timer task, so the block time must not
|
||||
be anything other than zero. */
|
||||
* is called from the context of the timer task, so the block time must not
|
||||
* be anything other than zero. */
|
||||
xTimerChangePeriod( xTxTimer, xTimeToWait, comtstDONT_BLOCK );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vComRxTask( void *pvParameters )
|
||||
static void vComRxTask( void * pvParameters )
|
||||
{
|
||||
BaseType_t xState = comtstWAITING_START_OF_STRING, xErrorOccurred = pdFALSE;
|
||||
char *pcExpectedByte, cRxedChar;
|
||||
const xComPortHandle xPort = NULL;
|
||||
BaseType_t xState = comtstWAITING_START_OF_STRING, xErrorOccurred = pdFALSE;
|
||||
char * pcExpectedByte, cRxedChar;
|
||||
const xComPortHandle xPort = NULL;
|
||||
|
||||
/* The parameter is not used in this example. */
|
||||
( void ) pvParameters;
|
||||
|
||||
/* Start the Tx timer. This only needs to be started once, as it will
|
||||
reset itself thereafter. */
|
||||
* reset itself thereafter. */
|
||||
xTimerStart( xTxTimer, portMAX_DELAY );
|
||||
|
||||
/* The first expected Rx character is the first in the string that is
|
||||
transmitted. */
|
||||
* transmitted. */
|
||||
pcExpectedByte = comTRANSACTED_STRING;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Wait for the next character. */
|
||||
if( xSerialGetChar( xPort, &cRxedChar, ( comTX_MAX_BLOCK_TIME * 2 ) ) == pdFALSE )
|
||||
{
|
||||
/* A character definitely should have been received by now. As a
|
||||
character was not received an error must have occurred (which might
|
||||
just be that the loopback connector is not fitted). */
|
||||
* character was not received an error must have occurred (which might
|
||||
* just be that the loopback connector is not fitted). */
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
switch( xState )
|
||||
{
|
||||
case comtstWAITING_START_OF_STRING:
|
||||
|
||||
if( cRxedChar == *pcExpectedByte )
|
||||
{
|
||||
/* The received character was the first character of the
|
||||
string. Move to the next state to check each character
|
||||
as it comes in until the entire string has been received. */
|
||||
* string. Move to the next state to check each character
|
||||
* as it comes in until the entire string has been received. */
|
||||
xState = comtstWAITING_END_OF_STRING;
|
||||
pcExpectedByte++;
|
||||
|
||||
/* Block for a short period. This just allows the Rx queue
|
||||
to contain more than one character, and therefore prevent
|
||||
thrashing reads to the queue, and repetitive context
|
||||
switches as each character is received. */
|
||||
* to contain more than one character, and therefore prevent
|
||||
* thrashing reads to the queue, and repetitive context
|
||||
* switches as each character is received. */
|
||||
vTaskDelay( comSHORT_DELAY );
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case comtstWAITING_END_OF_STRING:
|
||||
|
||||
if( cRxedChar == *pcExpectedByte )
|
||||
{
|
||||
/* The received character was the expected character. Was
|
||||
it the last character in the string - i.e. the null
|
||||
terminator? */
|
||||
* it the last character in the string - i.e. the null
|
||||
* terminator? */
|
||||
if( cRxedChar == 0x00 )
|
||||
{
|
||||
/* The entire string has been received. If no errors
|
||||
have been latched, then increment the loop counter to
|
||||
show this task is still healthy. */
|
||||
* have been latched, then increment the loop counter to
|
||||
* show this task is still healthy. */
|
||||
if( xErrorOccurred == pdFALSE )
|
||||
{
|
||||
uxRxLoops++;
|
||||
|
||||
/* Toggle an LED to give a visible sign that a
|
||||
complete string has been received. */
|
||||
* complete string has been received. */
|
||||
vParTestToggleLED( uxBaseLED + comRX_LED_OFFSET );
|
||||
}
|
||||
|
||||
|
|
@ -273,11 +278,13 @@ const xComPortHandle xPort = NULL;
|
|||
/* The character received was not that expected. */
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
/* Should not get here. Stop the Rx loop counter from
|
||||
incrementing to latch the error. */
|
||||
* incrementing to latch the error. */
|
||||
xErrorOccurred = pdTRUE;
|
||||
break;
|
||||
}
|
||||
|
|
@ -287,11 +294,11 @@ const xComPortHandle xPort = NULL;
|
|||
|
||||
BaseType_t xAreComTestTasksStillRunning( void )
|
||||
{
|
||||
BaseType_t xReturn;
|
||||
BaseType_t xReturn;
|
||||
|
||||
/* If the count of successful reception loops has not changed than at
|
||||
some time an error occurred (i.e. a character was received out of sequence)
|
||||
and false is returned. */
|
||||
* some time an error occurred (i.e. a character was received out of sequence)
|
||||
* and false is returned. */
|
||||
if( uxRxLoops == 0UL )
|
||||
{
|
||||
xReturn = pdFALSE;
|
||||
|
|
@ -302,9 +309,8 @@ BaseType_t xReturn;
|
|||
}
|
||||
|
||||
/* Reset the count of successful Rx loops. When this function is called
|
||||
again it should have been incremented again. */
|
||||
* again it should have been incremented again. */
|
||||
uxRxLoops = 0UL;
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,21 +42,21 @@
|
|||
#define countMAX_COUNT_VALUE ( 200 )
|
||||
|
||||
/* Constants used to indicate whether or not the semaphore should have been
|
||||
created with its maximum count value, or its minimum count value. These
|
||||
numbers are used to ensure that the pointers passed in as the task parameters
|
||||
are valid. */
|
||||
* created with its maximum count value, or its minimum count value. These
|
||||
* numbers are used to ensure that the pointers passed in as the task parameters
|
||||
* are valid. */
|
||||
#define countSTART_AT_MAX_COUNT ( 0xaa )
|
||||
#define countSTART_AT_ZERO ( 0x55 )
|
||||
|
||||
/* Two tasks are created for the test. One uses a semaphore created with its
|
||||
count value set to the maximum, and one with the count value set to zero. */
|
||||
* count value set to the maximum, and one with the count value set to zero. */
|
||||
#define countNUM_TEST_TASKS ( 2 )
|
||||
#define countDONT_BLOCK ( 0 )
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Flag that will be latched to pdTRUE should any unexpected behaviour be
|
||||
detected in any of the tasks. */
|
||||
* detected in any of the tasks. */
|
||||
static volatile BaseType_t xErrorDetected = pdFALSE;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
|
@ -67,19 +67,21 @@ static volatile BaseType_t xErrorDetected = pdFALSE;
|
|||
* 'take' is inspected, with an error being flagged if it is found not to be
|
||||
* the expected result.
|
||||
*/
|
||||
static void prvCountingSemaphoreTask( void *pvParameters );
|
||||
static void prvCountingSemaphoreTask( void * pvParameters );
|
||||
|
||||
/*
|
||||
* Utility function to increment the semaphore count value up from zero to
|
||||
* countMAX_COUNT_VALUE.
|
||||
*/
|
||||
static void prvIncrementSemaphoreCount( SemaphoreHandle_t xSemaphore, volatile UBaseType_t *puxLoopCounter );
|
||||
static void prvIncrementSemaphoreCount( SemaphoreHandle_t xSemaphore,
|
||||
volatile UBaseType_t * puxLoopCounter );
|
||||
|
||||
/*
|
||||
* Utility function to decrement the semaphore count value up from
|
||||
* countMAX_COUNT_VALUE to zero.
|
||||
*/
|
||||
static void prvDecrementSemaphoreCount( SemaphoreHandle_t xSemaphore, volatile UBaseType_t *puxLoopCounter );
|
||||
static void prvDecrementSemaphoreCount( SemaphoreHandle_t xSemaphore,
|
||||
volatile UBaseType_t * puxLoopCounter );
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
|
|
@ -90,12 +92,12 @@ typedef struct COUNT_SEM_STRUCT
|
|||
SemaphoreHandle_t xSemaphore;
|
||||
|
||||
/* Set to countSTART_AT_MAX_COUNT if the semaphore should be created with
|
||||
its count value set to its max count value, or countSTART_AT_ZERO if it
|
||||
should have been created with its count value set to 0. */
|
||||
* its count value set to its max count value, or countSTART_AT_ZERO if it
|
||||
* should have been created with its count value set to 0. */
|
||||
UBaseType_t uxExpectedStartCount;
|
||||
|
||||
/* Incremented on each cycle of the demo task. Used to detect a stalled
|
||||
task. */
|
||||
* task. */
|
||||
volatile UBaseType_t uxLoopCounter;
|
||||
} xCountSemStruct;
|
||||
|
||||
|
|
@ -107,8 +109,8 @@ static xCountSemStruct xParameters[ countNUM_TEST_TASKS ];
|
|||
void vStartCountingSemaphoreTasks( void )
|
||||
{
|
||||
/* Create the semaphores that we are going to use for the test/demo. The
|
||||
first should be created such that it starts at its maximum count value,
|
||||
the second should be created such that it starts with a count value of zero. */
|
||||
* first should be created such that it starts at its maximum count value,
|
||||
* the second should be created such that it starts with a count value of zero. */
|
||||
xParameters[ 0 ].xSemaphore = xSemaphoreCreateCounting( countMAX_COUNT_VALUE, countMAX_COUNT_VALUE );
|
||||
xParameters[ 0 ].uxExpectedStartCount = countSTART_AT_MAX_COUNT;
|
||||
xParameters[ 0 ].uxLoopCounter = 0;
|
||||
|
|
@ -121,11 +123,11 @@ void vStartCountingSemaphoreTasks( void )
|
|||
if( ( xParameters[ 0 ].xSemaphore != NULL ) || ( xParameters[ 1 ].xSemaphore != NULL ) )
|
||||
{
|
||||
/* vQueueAddToRegistry() adds the semaphore to the registry, if one is
|
||||
in use. The registry is provided as a means for kernel aware
|
||||
debuggers to locate semaphores 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 defined to be less than 1. */
|
||||
* in use. The registry is provided as a means for kernel aware
|
||||
* debuggers to locate semaphores 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 defined to be less than 1. */
|
||||
vQueueAddToRegistry( ( QueueHandle_t ) xParameters[ 0 ].xSemaphore, "Counting_Sem_1" );
|
||||
vQueueAddToRegistry( ( QueueHandle_t ) xParameters[ 1 ].xSemaphore, "Counting_Sem_2" );
|
||||
|
||||
|
|
@ -136,12 +138,13 @@ void vStartCountingSemaphoreTasks( void )
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvDecrementSemaphoreCount( SemaphoreHandle_t xSemaphore, volatile UBaseType_t *puxLoopCounter )
|
||||
static void prvDecrementSemaphoreCount( SemaphoreHandle_t xSemaphore,
|
||||
volatile UBaseType_t * puxLoopCounter )
|
||||
{
|
||||
UBaseType_t ux;
|
||||
UBaseType_t ux;
|
||||
|
||||
/* If the semaphore count is at its maximum then we should not be able to
|
||||
'give' the semaphore. */
|
||||
* 'give' the semaphore. */
|
||||
if( xSemaphoreGive( xSemaphore ) == pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -166,8 +169,9 @@ UBaseType_t ux;
|
|||
#endif
|
||||
|
||||
/* If the semaphore count is zero then we should not be able to 'take'
|
||||
the semaphore. */
|
||||
* the semaphore. */
|
||||
configASSERT( uxSemaphoreGetCount( xSemaphore ) == 0 );
|
||||
|
||||
if( xSemaphoreTake( xSemaphore, countDONT_BLOCK ) == pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -175,12 +179,13 @@ UBaseType_t ux;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvIncrementSemaphoreCount( SemaphoreHandle_t xSemaphore, volatile UBaseType_t *puxLoopCounter )
|
||||
static void prvIncrementSemaphoreCount( SemaphoreHandle_t xSemaphore,
|
||||
volatile UBaseType_t * puxLoopCounter )
|
||||
{
|
||||
UBaseType_t ux;
|
||||
UBaseType_t ux;
|
||||
|
||||
/* If the semaphore count is zero then we should not be able to 'take'
|
||||
the semaphore. */
|
||||
* the semaphore. */
|
||||
if( xSemaphoreTake( xSemaphore, countDONT_BLOCK ) == pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -205,7 +210,7 @@ UBaseType_t ux;
|
|||
#endif
|
||||
|
||||
/* If the semaphore count is at its maximum then we should not be able to
|
||||
'give' the semaphore. */
|
||||
* 'give' the semaphore. */
|
||||
if( xSemaphoreGive( xSemaphore ) == pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
|
|
@ -213,9 +218,9 @@ UBaseType_t ux;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvCountingSemaphoreTask( void *pvParameters )
|
||||
static void prvCountingSemaphoreTask( void * pvParameters )
|
||||
{
|
||||
xCountSemStruct *pxParameter;
|
||||
xCountSemStruct * pxParameter;
|
||||
|
||||
#ifdef USE_STDIO
|
||||
void vPrintDisplayMessage( const char * const * ppcMessageToSend );
|
||||
|
|
@ -230,20 +235,20 @@ xCountSemStruct *pxParameter;
|
|||
pxParameter = ( xCountSemStruct * ) pvParameters;
|
||||
|
||||
/* Did we expect to find the semaphore already at its max count value, or
|
||||
at zero? */
|
||||
* at zero? */
|
||||
if( pxParameter->uxExpectedStartCount == countSTART_AT_MAX_COUNT )
|
||||
{
|
||||
prvDecrementSemaphoreCount( pxParameter->xSemaphore, &( pxParameter->uxLoopCounter ) );
|
||||
}
|
||||
|
||||
/* Now we expect the semaphore count to be 0, so this time there is an
|
||||
error if we can take the semaphore. */
|
||||
* error if we can take the semaphore. */
|
||||
if( xSemaphoreTake( pxParameter->xSemaphore, 0 ) == pdPASS )
|
||||
{
|
||||
xErrorDetected = pdTRUE;
|
||||
}
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
prvIncrementSemaphoreCount( pxParameter->xSemaphore, &( pxParameter->uxLoopCounter ) );
|
||||
prvDecrementSemaphoreCount( pxParameter->xSemaphore, &( pxParameter->uxLoopCounter ) );
|
||||
|
|
@ -253,11 +258,11 @@ xCountSemStruct *pxParameter;
|
|||
|
||||
BaseType_t xAreCountingSemaphoreTasksStillRunning( void )
|
||||
{
|
||||
static UBaseType_t uxLastCount0 = 0, uxLastCount1 = 0;
|
||||
BaseType_t xReturn = pdPASS;
|
||||
static UBaseType_t uxLastCount0 = 0, uxLastCount1 = 0;
|
||||
BaseType_t xReturn = pdPASS;
|
||||
|
||||
/* Return fail if any 'give' or 'take' did not result in the expected
|
||||
behaviour. */
|
||||
* behaviour. */
|
||||
if( xErrorDetected != pdFALSE )
|
||||
{
|
||||
xReturn = pdFAIL;
|
||||
|
|
@ -284,5 +289,3 @@ BaseType_t xReturn = pdPASS;
|
|||
|
||||
return xReturn;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@
|
|||
#include "crflash.h"
|
||||
|
||||
/* The queue should only need to be of length 1. See the description at the
|
||||
top of the file. */
|
||||
* top of the file. */
|
||||
#define crfQUEUE_LENGTH 1
|
||||
|
||||
#define crfFIXED_DELAY_PRIORITY 0
|
||||
|
|
@ -71,7 +71,7 @@ top of the file. */
|
|||
#define crfFLASH_INDEX 0
|
||||
|
||||
/* Don't allow more than crfMAX_FLASH_TASKS 'fixed delay' co-routines to be
|
||||
created. */
|
||||
* created. */
|
||||
#define crfMAX_FLASH_TASKS 8
|
||||
|
||||
/* We don't want to block when posting to the queue. */
|
||||
|
|
@ -80,15 +80,17 @@ created. */
|
|||
/*
|
||||
* The 'fixed delay' co-routine as described at the top of the file.
|
||||
*/
|
||||
static void prvFixedDelayCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex );
|
||||
static void prvFixedDelayCoRoutine( CoRoutineHandle_t xHandle,
|
||||
UBaseType_t uxIndex );
|
||||
|
||||
/*
|
||||
* The 'flash' co-routine as described at the top of the file.
|
||||
*/
|
||||
static void prvFlashCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex );
|
||||
static void prvFlashCoRoutine( CoRoutineHandle_t xHandle,
|
||||
UBaseType_t uxIndex );
|
||||
|
||||
/* The queue used to pass data between the 'fixed delay' co-routines and the
|
||||
'flash' co-routine. */
|
||||
* 'flash' co-routine. */
|
||||
static QueueHandle_t xFlashQueue;
|
||||
|
||||
/* This will be set to pdFALSE if we detect an error. */
|
||||
|
|
@ -101,7 +103,7 @@ static BaseType_t xCoRoutineFlashStatus = pdPASS;
|
|||
*/
|
||||
void vStartFlashCoRoutines( UBaseType_t uxNumberToCreate )
|
||||
{
|
||||
UBaseType_t uxIndex;
|
||||
UBaseType_t uxIndex;
|
||||
|
||||
if( uxNumberToCreate > crfMAX_FLASH_TASKS )
|
||||
{
|
||||
|
|
@ -125,36 +127,41 @@ UBaseType_t uxIndex;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvFixedDelayCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
|
||||
static void prvFixedDelayCoRoutine( CoRoutineHandle_t xHandle,
|
||||
UBaseType_t uxIndex )
|
||||
{
|
||||
/* Even though this is a co-routine the xResult variable does not need to be
|
||||
static as we do not need it to maintain its state between blocks. */
|
||||
BaseType_t xResult;
|
||||
* static as we do not need it to maintain its state between blocks. */
|
||||
BaseType_t xResult;
|
||||
|
||||
/* The uxIndex parameter of the co-routine function is used as an index into
|
||||
the xFlashRates array to obtain the delay period to use. */
|
||||
static const TickType_t xFlashRates[ crfMAX_FLASH_TASKS ] = { 150 / portTICK_PERIOD_MS,
|
||||
* the xFlashRates array to obtain the delay period to use. */
|
||||
static const TickType_t xFlashRates[ crfMAX_FLASH_TASKS ] =
|
||||
{
|
||||
150 / portTICK_PERIOD_MS,
|
||||
200 / portTICK_PERIOD_MS,
|
||||
250 / portTICK_PERIOD_MS,
|
||||
300 / portTICK_PERIOD_MS,
|
||||
350 / portTICK_PERIOD_MS,
|
||||
400 / portTICK_PERIOD_MS,
|
||||
450 / portTICK_PERIOD_MS,
|
||||
500 / portTICK_PERIOD_MS };
|
||||
500 / portTICK_PERIOD_MS
|
||||
};
|
||||
|
||||
/* Co-routines MUST start with a call to crSTART. */
|
||||
crSTART( xHandle );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Post our uxIndex value onto the queue. This is used as the LED to
|
||||
flash. */
|
||||
* flash. */
|
||||
crQUEUE_SEND( xHandle, xFlashQueue, ( void * ) &uxIndex, crfPOSTING_BLOCK_TIME, &xResult );
|
||||
|
||||
if( xResult != pdPASS )
|
||||
{
|
||||
/* For the reasons stated at the top of the file we should always
|
||||
find that we can post to the queue. If we could not then an error
|
||||
has occurred. */
|
||||
* find that we can post to the queue. If we could not then an error
|
||||
* has occurred. */
|
||||
xCoRoutineFlashStatus = pdFAIL;
|
||||
}
|
||||
|
||||
|
|
@ -166,18 +173,19 @@ static const TickType_t xFlashRates[ crfMAX_FLASH_TASKS ] = { 150 / portTICK_PER
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvFlashCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
|
||||
static void prvFlashCoRoutine( CoRoutineHandle_t xHandle,
|
||||
UBaseType_t uxIndex )
|
||||
{
|
||||
/* Even though this is a co-routine the variable do not need to be
|
||||
static as we do not need it to maintain their state between blocks. */
|
||||
BaseType_t xResult;
|
||||
UBaseType_t uxLEDToFlash;
|
||||
* static as we do not need it to maintain their state between blocks. */
|
||||
BaseType_t xResult;
|
||||
UBaseType_t uxLEDToFlash;
|
||||
|
||||
/* Co-routines MUST start with a call to crSTART. */
|
||||
crSTART( xHandle );
|
||||
( void ) uxIndex;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Block to wait for the number of the LED to flash. */
|
||||
crQUEUE_RECEIVE( xHandle, xFlashQueue, &uxLEDToFlash, portMAX_DELAY, &xResult );
|
||||
|
|
@ -202,7 +210,6 @@ UBaseType_t uxLEDToFlash;
|
|||
BaseType_t xAreFlashCoRoutinesStillRunning( void )
|
||||
{
|
||||
/* Return pdPASS or pdFAIL depending on whether an error has been detected
|
||||
or not. */
|
||||
* or not. */
|
||||
return xCoRoutineFlashStatus;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@
|
|||
#define hookNUM_HOOK_CO_ROUTINES ( 4 )
|
||||
|
||||
/* The number of times the tick hook should be called before a character is
|
||||
posted to the 'hook' co-routines. */
|
||||
* posted to the 'hook' co-routines. */
|
||||
#define hookTICK_CALLS_BEFORE_POST ( 500 )
|
||||
|
||||
/* There should never be more than one item in any queue at any time. */
|
||||
|
|
@ -70,14 +70,15 @@ posted to the 'hook' co-routines. */
|
|||
#define hookNO_BLOCK_TIME ( 0 )
|
||||
|
||||
/* The priority relative to other co-routines (rather than tasks) that the
|
||||
'hook' co-routines should take. */
|
||||
* 'hook' co-routines should take. */
|
||||
#define mainHOOK_CR_PRIORITY ( 1 )
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
* The co-routine function itself.
|
||||
*/
|
||||
static void prvHookCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex );
|
||||
static void prvHookCoRoutine( CoRoutineHandle_t xHandle,
|
||||
UBaseType_t uxIndex );
|
||||
|
||||
|
||||
/*
|
||||
|
|
@ -90,13 +91,13 @@ void vApplicationTickHook( void );
|
|||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Queues used to send data FROM a co-routine TO the tick hook function.
|
||||
The hook functions received (Rx's) on these queues. One queue per
|
||||
'hook' co-routine. */
|
||||
* The hook functions received (Rx's) on these queues. One queue per
|
||||
* 'hook' co-routine. */
|
||||
static QueueHandle_t xHookRxQueues[ hookNUM_HOOK_CO_ROUTINES ];
|
||||
|
||||
/* Queues used to send data FROM the tick hook TO a co-routine function.
|
||||
The hood function transmits (Tx's) on these queues. One queue per
|
||||
'hook' co-routine. */
|
||||
* The hood function transmits (Tx's) on these queues. One queue per
|
||||
* 'hook' co-routine. */
|
||||
static QueueHandle_t xHookTxQueues[ hookNUM_HOOK_CO_ROUTINES ];
|
||||
|
||||
/* Set to true if an error is detected at any time. */
|
||||
|
|
@ -106,17 +107,17 @@ static BaseType_t xCoRoutineErrorDetected = pdFALSE;
|
|||
|
||||
void vStartHookCoRoutines( void )
|
||||
{
|
||||
UBaseType_t uxIndex, uxValueToPost = 0;
|
||||
UBaseType_t uxIndex, uxValueToPost = 0;
|
||||
|
||||
for( uxIndex = 0; uxIndex < hookNUM_HOOK_CO_ROUTINES; uxIndex++ )
|
||||
{
|
||||
/* Create a queue to transmit to and receive from each 'hook'
|
||||
co-routine. */
|
||||
* co-routine. */
|
||||
xHookRxQueues[ uxIndex ] = xQueueCreate( hookHOOK_QUEUE_LENGTH, sizeof( UBaseType_t ) );
|
||||
xHookTxQueues[ uxIndex ] = xQueueCreate( hookHOOK_QUEUE_LENGTH, sizeof( UBaseType_t ) );
|
||||
|
||||
/* To start things off the tick hook function expects the queue it
|
||||
uses to receive data to contain a value. */
|
||||
* uses to receive data to contain a value. */
|
||||
xQueueSend( xHookRxQueues[ uxIndex ], &uxValueToPost, hookNO_BLOCK_TIME );
|
||||
|
||||
/* Create the 'hook' co-routine itself. */
|
||||
|
|
@ -128,11 +129,12 @@ UBaseType_t uxIndex, uxValueToPost = 0;
|
|||
static UBaseType_t uxCallCounter = 0, uxNumberToPost = 0;
|
||||
void vApplicationTickHook( void )
|
||||
{
|
||||
UBaseType_t uxReceivedNumber;
|
||||
BaseType_t xIndex, xCoRoutineWoken;
|
||||
UBaseType_t uxReceivedNumber;
|
||||
BaseType_t xIndex, xCoRoutineWoken;
|
||||
|
||||
/* Is it time to talk to the 'hook' co-routines again? */
|
||||
uxCallCounter++;
|
||||
|
||||
if( uxCallCounter >= hookTICK_CALLS_BEFORE_POST )
|
||||
{
|
||||
uxCallCounter = 0;
|
||||
|
|
@ -140,16 +142,17 @@ BaseType_t xIndex, xCoRoutineWoken;
|
|||
for( xIndex = 0; xIndex < hookNUM_HOOK_CO_ROUTINES; xIndex++ )
|
||||
{
|
||||
xCoRoutineWoken = pdFALSE;
|
||||
|
||||
if( crQUEUE_RECEIVE_FROM_ISR( xHookRxQueues[ xIndex ], &uxReceivedNumber, &xCoRoutineWoken ) != pdPASS )
|
||||
{
|
||||
/* There is no reason why we would not expect the queue to
|
||||
contain a value. */
|
||||
* contain a value. */
|
||||
xCoRoutineErrorDetected = pdTRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Each queue used to receive data from the 'hook' co-routines
|
||||
should contain the number we last posted to the same co-routine. */
|
||||
* should contain the number we last posted to the same co-routine. */
|
||||
if( uxReceivedNumber != uxNumberToPost )
|
||||
{
|
||||
xCoRoutineErrorDetected = pdTRUE;
|
||||
|
|
@ -171,7 +174,7 @@ BaseType_t xIndex, xCoRoutineWoken;
|
|||
if( crQUEUE_SEND_FROM_ISR( xHookTxQueues[ xIndex ], &uxNumberToPost, pdFALSE ) != pdTRUE )
|
||||
{
|
||||
/* Posting to the queue should have woken the co-routine that
|
||||
was blocked on the queue. */
|
||||
* was blocked on the queue. */
|
||||
xCoRoutineErrorDetected = pdTRUE;
|
||||
}
|
||||
}
|
||||
|
|
@ -179,22 +182,23 @@ BaseType_t xIndex, xCoRoutineWoken;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvHookCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
|
||||
static void prvHookCoRoutine( CoRoutineHandle_t xHandle,
|
||||
UBaseType_t uxIndex )
|
||||
{
|
||||
static UBaseType_t uxReceivedValue[ hookNUM_HOOK_CO_ROUTINES ];
|
||||
BaseType_t xResult;
|
||||
static UBaseType_t uxReceivedValue[ hookNUM_HOOK_CO_ROUTINES ];
|
||||
BaseType_t xResult;
|
||||
|
||||
/* Each co-routine MUST start with a call to crSTART(); */
|
||||
crSTART( xHandle );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Wait to receive a value from the tick hook. */
|
||||
xResult = pdFAIL;
|
||||
crQUEUE_RECEIVE( xHandle, xHookTxQueues[ uxIndex ], &( uxReceivedValue[ uxIndex ] ), portMAX_DELAY, &xResult );
|
||||
|
||||
/* There is no reason why we should not have received something on
|
||||
the queue. */
|
||||
* the queue. */
|
||||
if( xResult != pdPASS )
|
||||
{
|
||||
xCoRoutineErrorDetected = pdTRUE;
|
||||
|
|
@ -203,10 +207,11 @@ BaseType_t xResult;
|
|||
/* Send the same number back to the idle hook so it can verify it. */
|
||||
xResult = pdFAIL;
|
||||
crQUEUE_SEND( xHandle, xHookRxQueues[ uxIndex ], &( uxReceivedValue[ uxIndex ] ), hookNO_BLOCK_TIME, &xResult );
|
||||
|
||||
if( xResult != pdPASS )
|
||||
{
|
||||
/* There is no reason why we should not have been able to post to
|
||||
the queue. */
|
||||
* the queue. */
|
||||
xCoRoutineErrorDetected = pdTRUE;
|
||||
}
|
||||
}
|
||||
|
|
@ -227,6 +232,3 @@ BaseType_t xAreHookCoRoutinesStillRunning( void )
|
|||
return pdTRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -57,30 +57,30 @@
|
|||
#define deathSTACK_SIZE ( configMINIMAL_STACK_SIZE + 60 )
|
||||
|
||||
/* The task originally created which is responsible for periodically dynamically
|
||||
creating another four tasks. */
|
||||
* creating another four tasks. */
|
||||
static portTASK_FUNCTION_PROTO( vCreateTasks, pvParameters );
|
||||
|
||||
/* The task function of the dynamically created tasks. */
|
||||
static portTASK_FUNCTION_PROTO( vSuicidalTask, pvParameters );
|
||||
|
||||
/* A variable which is incremented every time the dynamic tasks are created. This
|
||||
is used to check that the task is still running. */
|
||||
* is used to check that the task is still running. */
|
||||
static volatile uint16_t usCreationCount = 0;
|
||||
|
||||
/* Used to store the number of tasks that were originally running so the creator
|
||||
task can tell if any of the suicidal tasks have failed to die.
|
||||
*/
|
||||
* task can tell if any of the suicidal tasks have failed to die.
|
||||
*/
|
||||
static volatile UBaseType_t uxTasksRunningAtStart = 0;
|
||||
|
||||
/* When a task deletes itself, it stack and TCB are cleaned up by the Idle task.
|
||||
Under heavy load the idle task might not get much processing time, so it would
|
||||
be legitimate for several tasks to remain undeleted for a short period. There
|
||||
may also be a few other unexpected tasks if, for example, the tasks that test
|
||||
static allocation are also being used. */
|
||||
* Under heavy load the idle task might not get much processing time, so it would
|
||||
* be legitimate for several tasks to remain undeleted for a short period. There
|
||||
* may also be a few other unexpected tasks if, for example, the tasks that test
|
||||
* static allocation are also being used. */
|
||||
static const UBaseType_t uxMaxNumberOfExtraTasksRunning = 3;
|
||||
|
||||
/* Used to store a handle to the task that should be killed by a suicidal task,
|
||||
before it kills itself. */
|
||||
* before it kills itself. */
|
||||
TaskHandle_t xCreatedTask;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
|
@ -93,9 +93,9 @@ void vCreateSuicidalTasks( UBaseType_t uxPriority )
|
|||
|
||||
static portTASK_FUNCTION( vSuicidalTask, pvParameters )
|
||||
{
|
||||
volatile long l1, l2;
|
||||
TaskHandle_t xTaskToKill;
|
||||
const TickType_t xDelay = pdMS_TO_TICKS( ( TickType_t ) 200 );
|
||||
volatile long l1, l2;
|
||||
TaskHandle_t xTaskToKill;
|
||||
const TickType_t xDelay = pdMS_TO_TICKS( ( TickType_t ) 200 );
|
||||
|
||||
/* Test deletion of a task's secure context, if any. */
|
||||
portALLOCATE_SECURE_CONTEXT( configMINIMAL_SECURE_STACK_SIZE );
|
||||
|
|
@ -103,16 +103,16 @@ const TickType_t xDelay = pdMS_TO_TICKS( ( TickType_t ) 200 );
|
|||
if( pvParameters != NULL )
|
||||
{
|
||||
/* This task is periodically created four times. Two created tasks are
|
||||
passed a handle to the other task so it can kill it before killing itself.
|
||||
The other task is passed in null. */
|
||||
xTaskToKill = *( TaskHandle_t* )pvParameters;
|
||||
* passed a handle to the other task so it can kill it before killing itself.
|
||||
* The other task is passed in null. */
|
||||
xTaskToKill = *( TaskHandle_t * ) pvParameters;
|
||||
}
|
||||
else
|
||||
{
|
||||
xTaskToKill = NULL;
|
||||
}
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Do something random just to use some stack and registers. */
|
||||
l1 = 2;
|
||||
|
|
@ -132,25 +132,25 @@ const TickType_t xDelay = pdMS_TO_TICKS( ( TickType_t ) 200 );
|
|||
vTaskDelete( NULL );
|
||||
}
|
||||
}
|
||||
}/*lint !e818 !e550 Function prototype must be as per standard for task functions. */
|
||||
} /*lint !e818 !e550 Function prototype must be as per standard for task functions. */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static portTASK_FUNCTION( vCreateTasks, pvParameters )
|
||||
{
|
||||
const TickType_t xDelay = pdMS_TO_TICKS( ( TickType_t ) 1000 );
|
||||
UBaseType_t uxPriority;
|
||||
const TickType_t xDelay = pdMS_TO_TICKS( ( TickType_t ) 1000 );
|
||||
UBaseType_t uxPriority;
|
||||
|
||||
/* Remove compiler warning about unused parameter. */
|
||||
( void ) pvParameters;
|
||||
|
||||
/* Delay at the start to ensure tasks created by other demos have been
|
||||
created before storing the current number of tasks. */
|
||||
* created before storing the current number of tasks. */
|
||||
vTaskDelay( xDelay );
|
||||
uxTasksRunningAtStart = ( UBaseType_t ) uxTaskGetNumberOfTasks();
|
||||
|
||||
uxPriority = uxTaskPriorityGet( NULL );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Just loop round, delaying then creating the four suicidal tasks. */
|
||||
vTaskDelay( xDelay );
|
||||
|
|
@ -166,12 +166,12 @@ UBaseType_t uxPriority;
|
|||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* This is called to check that the creator task is still running and that there
|
||||
are not any more than four extra tasks. */
|
||||
* are not any more than four extra tasks. */
|
||||
BaseType_t xIsCreateTaskStillRunning( void )
|
||||
{
|
||||
static uint16_t usLastCreationCount = 0xfff;
|
||||
BaseType_t xReturn = pdTRUE;
|
||||
static UBaseType_t uxTasksRunningNow;
|
||||
static uint16_t usLastCreationCount = 0xfff;
|
||||
BaseType_t xReturn = pdTRUE;
|
||||
static UBaseType_t uxTasksRunningNow;
|
||||
|
||||
if( usLastCreationCount == usCreationCount )
|
||||
{
|
||||
|
|
@ -199,5 +199,3 @@ static UBaseType_t uxTasksRunningNow;
|
|||
|
||||
return xReturn;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -118,17 +118,17 @@ static portTASK_FUNCTION_PROTO( vQueueSendWhenSuspendedTask, pvParameters );
|
|||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* 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 TaskHandle_t xContinuousIncrementHandle, xLimitedIncrementHandle;
|
||||
|
||||
/* 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 uint32_t ulCounter;
|
||||
|
||||
/* Variables used to check that the tasks are still operating without error.
|
||||
Each complete iteration of the controller task increments this variable
|
||||
provided no errors have been found. The variable maintaining the same value
|
||||
is therefore indication of an error. */
|
||||
* Each complete iteration of the controller task increments this variable
|
||||
* provided no errors have been found. The variable maintaining the same value
|
||||
* is therefore indication of an error. */
|
||||
static volatile uint16_t usCheckVariable = ( uint16_t ) 0;
|
||||
static volatile BaseType_t xSuspendedQueueSendError = pdFALSE;
|
||||
static volatile BaseType_t xSuspendedQueueReceiveError = pdFALSE;
|
||||
|
|
@ -137,11 +137,12 @@ static volatile BaseType_t xSuspendedQueueReceiveError = pdFALSE;
|
|||
QueueHandle_t xSuspendedTestQueue;
|
||||
|
||||
/* The value the queue receive task expects to receive next. This is file
|
||||
scope so xAreDynamicPriorityTasksStillRunning() can ensure it is still
|
||||
incrementing. */
|
||||
* scope so xAreDynamicPriorityTasksStillRunning() can ensure it is still
|
||||
* incrementing. */
|
||||
static uint32_t ulExpectedValue = ( uint32_t ) 0;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
* Start the three tasks as described at the top of the file.
|
||||
* Note that the limited count task is given a higher priority.
|
||||
|
|
@ -153,11 +154,11 @@ void vStartDynamicPriorityTasks( void )
|
|||
if( xSuspendedTestQueue != NULL )
|
||||
{
|
||||
/* vQueueAddToRegistry() adds the queue to the queue registry, if one is
|
||||
in use. The queue registry is provided as a means for kernel aware
|
||||
debuggers to locate queues 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
|
||||
defined to be less than 1. */
|
||||
* in use. The queue registry is provided as a means for kernel aware
|
||||
* debuggers to locate queues 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
|
||||
* defined to be less than 1. */
|
||||
vQueueAddToRegistry( xSuspendedTestQueue, "Suspended_Test_Queue" );
|
||||
|
||||
xTaskCreate( vContinuousIncrementTask, "CNT_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY, &xContinuousIncrementHandle );
|
||||
|
|
@ -175,17 +176,17 @@ void vStartDynamicPriorityTasks( void )
|
|||
*/
|
||||
static portTASK_FUNCTION( vLimitedIncrementTask, pvParameters )
|
||||
{
|
||||
volatile uint32_t *pulCounter;
|
||||
volatile uint32_t * pulCounter;
|
||||
|
||||
/* Take a pointer to the shared variable from the parameters passed into
|
||||
the task. */
|
||||
* the task. */
|
||||
pulCounter = ( volatile uint32_t * ) pvParameters;
|
||||
|
||||
/* This will run before the control task, so the first thing it does is
|
||||
suspend - the control task will resume it when ready. */
|
||||
* suspend - the control task will resume it when ready. */
|
||||
vTaskSuspend( NULL );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Just count up to a value then suspend. */
|
||||
( *pulCounter )++;
|
||||
|
|
@ -204,21 +205,21 @@ volatile uint32_t *pulCounter;
|
|||
*/
|
||||
static portTASK_FUNCTION( vContinuousIncrementTask, pvParameters )
|
||||
{
|
||||
volatile uint32_t *pulCounter;
|
||||
UBaseType_t uxOurPriority;
|
||||
volatile uint32_t * pulCounter;
|
||||
UBaseType_t uxOurPriority;
|
||||
|
||||
/* Take a pointer to the shared variable from the parameters passed into
|
||||
the task. */
|
||||
* the task. */
|
||||
pulCounter = ( volatile uint32_t * ) pvParameters;
|
||||
|
||||
/* Query our priority so we can raise it when exclusive access to the
|
||||
shared variable is required. */
|
||||
* shared variable is required. */
|
||||
uxOurPriority = uxTaskPriorityGet( NULL );
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Raise the priority above the controller task to ensure a context
|
||||
switch does not occur while the variable is being accessed. */
|
||||
* switch does not occur while the variable is being accessed. */
|
||||
vTaskPrioritySet( NULL, uxOurPriority + 1 );
|
||||
{
|
||||
configASSERT( ( uxTaskPriorityGet( NULL ) == ( uxOurPriority + 1 ) ) );
|
||||
|
|
@ -226,7 +227,7 @@ UBaseType_t uxOurPriority;
|
|||
}
|
||||
vTaskPrioritySet( NULL, uxOurPriority );
|
||||
|
||||
#if( configUSE_PREEMPTION == 0 )
|
||||
#if ( configUSE_PREEMPTION == 0 )
|
||||
taskYIELD();
|
||||
#endif
|
||||
|
||||
|
|
@ -240,14 +241,14 @@ UBaseType_t uxOurPriority;
|
|||
*/
|
||||
static portTASK_FUNCTION( vCounterControlTask, pvParameters )
|
||||
{
|
||||
uint32_t ulLastCounter;
|
||||
short sLoops;
|
||||
short sError = pdFALSE;
|
||||
uint32_t ulLastCounter;
|
||||
short sLoops;
|
||||
short sError = pdFALSE;
|
||||
|
||||
/* Just to stop warning messages. */
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Start with the counter at zero. */
|
||||
ulCounter = ( uint32_t ) 0;
|
||||
|
|
@ -258,12 +259,12 @@ short sError = pdFALSE;
|
|||
for( sLoops = 0; sLoops < priLOOPS; sLoops++ )
|
||||
{
|
||||
/* Suspend the continuous count task so we can take a mirror of the
|
||||
shared variable without risk of corruption. This is not really
|
||||
needed as the other task raises its priority above this task's
|
||||
priority. */
|
||||
* shared variable without risk of corruption. This is not really
|
||||
* needed as the other task raises its priority above this task's
|
||||
* priority. */
|
||||
vTaskSuspend( xContinuousIncrementHandle );
|
||||
{
|
||||
#if( INCLUDE_eTaskGetState == 1 )
|
||||
#if ( INCLUDE_eTaskGetState == 1 )
|
||||
{
|
||||
configASSERT( eTaskGetState( xContinuousIncrementHandle ) == eSuspended );
|
||||
}
|
||||
|
|
@ -273,11 +274,11 @@ short sError = pdFALSE;
|
|||
}
|
||||
vTaskResume( xContinuousIncrementHandle );
|
||||
|
||||
#if( configUSE_PREEMPTION == 0 )
|
||||
#if ( configUSE_PREEMPTION == 0 )
|
||||
taskYIELD();
|
||||
#endif
|
||||
|
||||
#if( INCLUDE_eTaskGetState == 1 )
|
||||
#if ( INCLUDE_eTaskGetState == 1 )
|
||||
{
|
||||
configASSERT( eTaskGetState( xContinuousIncrementHandle ) == eReady );
|
||||
}
|
||||
|
|
@ -287,14 +288,14 @@ short sError = pdFALSE;
|
|||
vTaskDelay( priSLEEP_TIME );
|
||||
|
||||
/* Check the shared variable again. This time to ensure mutual
|
||||
exclusion the whole scheduler will be locked. This is just for
|
||||
demo purposes! */
|
||||
* exclusion the whole scheduler will be locked. This is just for
|
||||
* demo purposes! */
|
||||
vTaskSuspendAll();
|
||||
{
|
||||
if( ulLastCounter == ulCounter )
|
||||
{
|
||||
/* The shared variable has not changed. There is a problem
|
||||
with the continuous count task so flag an error. */
|
||||
* with the continuous count task so flag an error. */
|
||||
sError = pdTRUE;
|
||||
}
|
||||
}
|
||||
|
|
@ -304,30 +305,30 @@ short sError = pdFALSE;
|
|||
/* Second section: */
|
||||
|
||||
/* Suspend the continuous counter task so it stops accessing the shared
|
||||
variable. */
|
||||
* variable. */
|
||||
vTaskSuspend( xContinuousIncrementHandle );
|
||||
|
||||
/* Reset the variable. */
|
||||
ulCounter = ( uint32_t ) 0;
|
||||
|
||||
#if( INCLUDE_eTaskGetState == 1 )
|
||||
#if ( INCLUDE_eTaskGetState == 1 )
|
||||
{
|
||||
configASSERT( eTaskGetState( xLimitedIncrementHandle ) == eSuspended );
|
||||
}
|
||||
#endif /* INCLUDE_eTaskGetState */
|
||||
|
||||
/* Resume the limited count task which has a higher priority than us.
|
||||
We should therefore not return from this call until the limited count
|
||||
task has suspended itself with a known value in the counter variable. */
|
||||
* We should therefore not return from this call until the limited count
|
||||
* task has suspended itself with a known value in the counter variable. */
|
||||
vTaskResume( xLimitedIncrementHandle );
|
||||
|
||||
#if( configUSE_PREEMPTION == 0 )
|
||||
#if ( configUSE_PREEMPTION == 0 )
|
||||
taskYIELD();
|
||||
#endif
|
||||
|
||||
/* This task should not run again until xLimitedIncrementHandle has
|
||||
suspended itself. */
|
||||
#if( INCLUDE_eTaskGetState == 1 )
|
||||
* suspended itself. */
|
||||
#if ( INCLUDE_eTaskGetState == 1 )
|
||||
{
|
||||
configASSERT( eTaskGetState( xLimitedIncrementHandle ) == eSuspended );
|
||||
}
|
||||
|
|
@ -350,7 +351,7 @@ short sError = pdFALSE;
|
|||
/* Resume the continuous count task and do it all again. */
|
||||
vTaskResume( xContinuousIncrementHandle );
|
||||
|
||||
#if( configUSE_PREEMPTION == 0 )
|
||||
#if ( configUSE_PREEMPTION == 0 )
|
||||
taskYIELD();
|
||||
#endif
|
||||
}
|
||||
|
|
@ -359,12 +360,12 @@ short sError = pdFALSE;
|
|||
|
||||
static portTASK_FUNCTION( vQueueSendWhenSuspendedTask, pvParameters )
|
||||
{
|
||||
static uint32_t ulValueToSend = ( uint32_t ) 0;
|
||||
static uint32_t ulValueToSend = ( uint32_t ) 0;
|
||||
|
||||
/* Just to stop warning messages. */
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
vTaskSuspendAll();
|
||||
{
|
||||
|
|
@ -385,27 +386,28 @@ static uint32_t ulValueToSend = ( uint32_t ) 0;
|
|||
|
||||
static portTASK_FUNCTION( vQueueReceiveWhenSuspendedTask, pvParameters )
|
||||
{
|
||||
uint32_t ulReceivedValue;
|
||||
BaseType_t xGotValue;
|
||||
uint32_t ulReceivedValue;
|
||||
BaseType_t xGotValue;
|
||||
|
||||
/* Just to stop warning messages. */
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
do
|
||||
{
|
||||
/* Suspending the scheduler here is fairly pointless and
|
||||
undesirable for a normal application. It is done here purely
|
||||
to test the scheduler. The inner xTaskResumeAll() should
|
||||
never return pdTRUE as the scheduler is still locked by the
|
||||
outer call. */
|
||||
* undesirable for a normal application. It is done here purely
|
||||
* to test the scheduler. The inner xTaskResumeAll() should
|
||||
* never return pdTRUE as the scheduler is still locked by the
|
||||
* outer call. */
|
||||
vTaskSuspendAll();
|
||||
{
|
||||
vTaskSuspendAll();
|
||||
{
|
||||
xGotValue = xQueueReceive( xSuspendedTestQueue, ( void * ) &ulReceivedValue, priNO_BLOCK );
|
||||
}
|
||||
|
||||
if( xTaskResumeAll() != pdFALSE )
|
||||
{
|
||||
xSuspendedQueueReceiveError = pdTRUE;
|
||||
|
|
@ -418,7 +420,6 @@ BaseType_t xGotValue;
|
|||
taskYIELD();
|
||||
}
|
||||
#endif
|
||||
|
||||
} while( xGotValue == pdFALSE );
|
||||
|
||||
if( ulReceivedValue != ulExpectedValue )
|
||||
|
|
@ -429,8 +430,8 @@ BaseType_t xGotValue;
|
|||
if( xSuspendedQueueReceiveError != pdTRUE )
|
||||
{
|
||||
/* Only increment the variable if an error has not occurred. This
|
||||
allows xAreDynamicPriorityTasksStillRunning() to check for stalled
|
||||
tasks as well as explicit errors. */
|
||||
* allows xAreDynamicPriorityTasksStillRunning() to check for stalled
|
||||
* tasks as well as explicit errors. */
|
||||
++ulExpectedValue;
|
||||
}
|
||||
}
|
||||
|
|
@ -441,13 +442,13 @@ BaseType_t xGotValue;
|
|||
BaseType_t xAreDynamicPriorityTasksStillRunning( void )
|
||||
{
|
||||
/* Keep a history of the check variables so we know if it has been incremented
|
||||
since the last call. */
|
||||
static uint16_t usLastTaskCheck = ( uint16_t ) 0;
|
||||
static uint32_t ulLastExpectedValue = ( uint32_t ) 0U;
|
||||
BaseType_t xReturn = pdTRUE;
|
||||
* since the last call. */
|
||||
static uint16_t usLastTaskCheck = ( uint16_t ) 0;
|
||||
static uint32_t ulLastExpectedValue = ( uint32_t ) 0U;
|
||||
BaseType_t xReturn = pdTRUE;
|
||||
|
||||
/* Check the tasks are still running by ensuring the check variable
|
||||
is still incrementing. */
|
||||
* is still incrementing. */
|
||||
|
||||
if( usCheckVariable == usLastTaskCheck )
|
||||
{
|
||||
|
|
@ -458,7 +459,7 @@ BaseType_t xReturn = pdTRUE;
|
|||
if( ulExpectedValue == ulLastExpectedValue )
|
||||
{
|
||||
/* The value being received by the queue receive task has not
|
||||
incremented so an error exists. */
|
||||
* incremented so an error exists. */
|
||||
xReturn = pdFALSE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@
|
|||
#define ledFLASH_RATE_BASE ( ( TickType_t ) 333 )
|
||||
|
||||
/* Variable used by the created tasks to calculate the LED number to use, and
|
||||
the rate at which they should flash the LED. */
|
||||
* the rate at which they should flash the LED. */
|
||||
static volatile UBaseType_t uxFlashTaskNumber = 0;
|
||||
|
||||
/* The task that is created three times. */
|
||||
|
|
@ -64,7 +64,7 @@ static portTASK_FUNCTION_PROTO( vLEDFlashTask, pvParameters );
|
|||
|
||||
void vStartLEDFlashTasks( UBaseType_t uxPriority )
|
||||
{
|
||||
BaseType_t xLEDTask;
|
||||
BaseType_t xLEDTask;
|
||||
|
||||
/* Create the three tasks. */
|
||||
for( xLEDTask = 0; xLEDTask < ledNUMBER_OF_LEDS; ++xLEDTask )
|
||||
|
|
@ -77,8 +77,8 @@ BaseType_t xLEDTask;
|
|||
|
||||
static portTASK_FUNCTION( vLEDFlashTask, pvParameters )
|
||||
{
|
||||
TickType_t xFlashRate, xLastFlashTime;
|
||||
UBaseType_t uxLED;
|
||||
TickType_t xFlashRate, xLastFlashTime;
|
||||
UBaseType_t uxLED;
|
||||
|
||||
/* The parameters are not used. */
|
||||
( void ) pvParameters;
|
||||
|
|
@ -98,14 +98,14 @@ UBaseType_t uxLED;
|
|||
xFlashRate /= portTICK_PERIOD_MS;
|
||||
|
||||
/* We will turn the LED on and off again in the delay period, so each
|
||||
delay is only half the total period. */
|
||||
* delay is only half the total period. */
|
||||
xFlashRate /= ( TickType_t ) 2;
|
||||
|
||||
/* We need to initialise xLastFlashTime prior to the first call to
|
||||
vTaskDelayUntil(). */
|
||||
* vTaskDelayUntil(). */
|
||||
xLastFlashTime = xTaskGetTickCount();
|
||||
|
||||
for(;;)
|
||||
for( ; ; )
|
||||
{
|
||||
/* Delay for half the flash period then turn the LED on. */
|
||||
vTaskDelayUntil( &xLastFlashTime, xFlashRate );
|
||||
|
|
@ -116,4 +116,3 @@ UBaseType_t uxLED;
|
|||
vParTestToggleLED( uxLED );
|
||||
}
|
||||
} /*lint !e715 !e818 !e830 Function definition must be standard for task creation. */
|
||||
|
||||
|
|
|
|||
|
|
@ -57,25 +57,25 @@ static void prvLEDTimerCallback( TimerHandle_t xTimer );
|
|||
|
||||
void vStartLEDFlashTimers( UBaseType_t uxNumberOfLEDs )
|
||||
{
|
||||
UBaseType_t uxLEDTimer;
|
||||
TimerHandle_t xTimer;
|
||||
UBaseType_t uxLEDTimer;
|
||||
TimerHandle_t xTimer;
|
||||
|
||||
/* Create and start the requested number of timers. */
|
||||
for( uxLEDTimer = 0; uxLEDTimer < uxNumberOfLEDs; ++uxLEDTimer )
|
||||
{
|
||||
/* Create the timer. */
|
||||
xTimer = xTimerCreate( "Flasher", /* A text name, purely to help debugging. */
|
||||
ledFLASH_RATE_BASE * ( uxLEDTimer + 1 ),/* The timer period, which is a multiple of ledFLASH_RATE_BASE. */
|
||||
ledFLASH_RATE_BASE * ( uxLEDTimer + 1 ), /* The timer period, which is a multiple of ledFLASH_RATE_BASE. */
|
||||
pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
|
||||
( void * ) uxLEDTimer, /* The ID is used to identify the timer within the timer callback function, as each timer uses the same callback. */
|
||||
prvLEDTimerCallback /* Each timer uses the same callback. */
|
||||
);
|
||||
|
||||
/* If the timer was created successfully, attempt to start it. If the
|
||||
scheduler has not yet been started then the timer command queue must
|
||||
be long enough to hold each command sent to it until such time that the
|
||||
scheduler is started. The timer command queue length is set by
|
||||
configTIMER_QUEUE_LENGTH in FreeRTOSConfig.h. */
|
||||
* scheduler has not yet been started then the timer command queue must
|
||||
* be long enough to hold each command sent to it until such time that the
|
||||
* scheduler is started. The timer command queue length is set by
|
||||
* configTIMER_QUEUE_LENGTH in FreeRTOSConfig.h. */
|
||||
if( xTimer != NULL )
|
||||
{
|
||||
xTimerStart( xTimer, ledDONT_BLOCK );
|
||||
|
|
@ -86,13 +86,11 @@ TimerHandle_t xTimer;
|
|||
|
||||
static void prvLEDTimerCallback( TimerHandle_t xTimer )
|
||||
{
|
||||
BaseType_t xTimerID;
|
||||
BaseType_t xTimerID;
|
||||
|
||||
/* The timer ID is used to identify the timer that has actually expired as
|
||||
each timer uses the same callback. The ID is then also used as the number
|
||||
of the LED that is to be toggled. */
|
||||
* each timer uses the same callback. The ID is then also used as the number
|
||||
* of the LED that is to be toggled. */
|
||||
xTimerID = ( BaseType_t ) pvTimerGetTimerID( xTimer );
|
||||
vParTestToggleLED( xTimerID );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -56,14 +56,14 @@
|
|||
#define mathNUMBER_OF_TASKS ( 4 )
|
||||
|
||||
/* Four tasks, each of which performs a different floating point calculation.
|
||||
Each of the four is created twice. */
|
||||
* Each of the four is created twice. */
|
||||
static portTASK_FUNCTION_PROTO( vCompetingMathTask1, pvParameters );
|
||||
static portTASK_FUNCTION_PROTO( vCompetingMathTask2, pvParameters );
|
||||
static portTASK_FUNCTION_PROTO( vCompetingMathTask3, pvParameters );
|
||||
static portTASK_FUNCTION_PROTO( vCompetingMathTask4, pvParameters );
|
||||
|
||||
/* These variables are used to check that all the tasks are still running. If a
|
||||
task gets a calculation wrong it will stop setting its check variable. */
|
||||
* task gets a calculation wrong it will stop setting its check variable. */
|
||||
static uint16_t usTaskCheck[ mathNUMBER_OF_TASKS ] = { ( uint16_t ) 0 };
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
|
@ -79,14 +79,14 @@ void vStartMathTasks( UBaseType_t uxPriority )
|
|||
|
||||
static portTASK_FUNCTION( vCompetingMathTask1, pvParameters )
|
||||
{
|
||||
volatile portDOUBLE d1, d2, d3, d4;
|
||||
volatile uint16_t *pusTaskCheckVariable;
|
||||
volatile portDOUBLE dAnswer;
|
||||
short sError = pdFALSE;
|
||||
volatile portDOUBLE d1, d2, d3, d4;
|
||||
volatile uint16_t * pusTaskCheckVariable;
|
||||
volatile portDOUBLE dAnswer;
|
||||
short sError = pdFALSE;
|
||||
|
||||
/* Some ports require that tasks that use a hardware floating point unit
|
||||
tell the kernel that they require a floating point context before any
|
||||
floating point instructions are executed. */
|
||||
* tell the kernel that they require a floating point context before any
|
||||
* floating point instructions are executed. */
|
||||
portTASK_USES_FLOATING_POINT();
|
||||
|
||||
d1 = 123.4567;
|
||||
|
|
@ -96,11 +96,11 @@ short sError = pdFALSE;
|
|||
dAnswer = ( d1 + d2 ) * d3;
|
||||
|
||||
/* The variable this task increments to show it is still running is passed in
|
||||
as the parameter. */
|
||||
* as the parameter. */
|
||||
pusTaskCheckVariable = ( volatile uint16_t * ) pvParameters;
|
||||
|
||||
/* Keep performing a calculation and checking the result against a constant. */
|
||||
for(;;)
|
||||
for( ; ; )
|
||||
{
|
||||
d1 = 123.4567;
|
||||
d2 = 2345.6789;
|
||||
|
|
@ -113,7 +113,7 @@ short sError = pdFALSE;
|
|||
#endif
|
||||
|
||||
/* If the calculation does not match the expected constant, stop the
|
||||
increment of the check variable. */
|
||||
* increment of the check variable. */
|
||||
if( fabs( d4 - dAnswer ) > 0.001 )
|
||||
{
|
||||
sError = pdTRUE;
|
||||
|
|
@ -122,29 +122,28 @@ short sError = pdFALSE;
|
|||
if( sError == pdFALSE )
|
||||
{
|
||||
/* If the calculation has always been correct then set set the check
|
||||
variable. The check variable will get set to pdFALSE each time
|
||||
xAreMathsTaskStillRunning() is executed. */
|
||||
* variable. The check variable will get set to pdFALSE each time
|
||||
* xAreMathsTaskStillRunning() is executed. */
|
||||
( *pusTaskCheckVariable ) = pdTRUE;
|
||||
}
|
||||
|
||||
#if configUSE_PREEMPTION == 0
|
||||
taskYIELD();
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static portTASK_FUNCTION( vCompetingMathTask2, pvParameters )
|
||||
{
|
||||
volatile portDOUBLE d1, d2, d3, d4;
|
||||
volatile uint16_t *pusTaskCheckVariable;
|
||||
volatile portDOUBLE dAnswer;
|
||||
short sError = pdFALSE;
|
||||
volatile portDOUBLE d1, d2, d3, d4;
|
||||
volatile uint16_t * pusTaskCheckVariable;
|
||||
volatile portDOUBLE dAnswer;
|
||||
short sError = pdFALSE;
|
||||
|
||||
/* Some ports require that tasks that use a hardware floating point unit
|
||||
tell the kernel that they require a floating point context before any
|
||||
floating point instructions are executed. */
|
||||
* tell the kernel that they require a floating point context before any
|
||||
* floating point instructions are executed. */
|
||||
portTASK_USES_FLOATING_POINT();
|
||||
|
||||
d1 = -389.38;
|
||||
|
|
@ -155,11 +154,11 @@ short sError = pdFALSE;
|
|||
|
||||
|
||||
/* The variable this task increments to show it is still running is passed in
|
||||
as the parameter. */
|
||||
* as the parameter. */
|
||||
pusTaskCheckVariable = ( volatile uint16_t * ) pvParameters;
|
||||
|
||||
/* Keep performing a calculation and checking the result against a constant. */
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
d1 = -389.38;
|
||||
d2 = 32498.2;
|
||||
|
|
@ -172,7 +171,7 @@ short sError = pdFALSE;
|
|||
#endif
|
||||
|
||||
/* If the calculation does not match the expected constant, stop the
|
||||
increment of the check variable. */
|
||||
* increment of the check variable. */
|
||||
if( fabs( d4 - dAnswer ) > 0.001 )
|
||||
{
|
||||
sError = pdTRUE;
|
||||
|
|
@ -181,8 +180,8 @@ short sError = pdFALSE;
|
|||
if( sError == pdFALSE )
|
||||
{
|
||||
/* If the calculation has always been correct then set set the check
|
||||
variable. The check variable will get set to pdFALSE each time
|
||||
xAreMathsTaskStillRunning() is executed. */
|
||||
* variable. The check variable will get set to pdFALSE each time
|
||||
* xAreMathsTaskStillRunning() is executed. */
|
||||
( *pusTaskCheckVariable ) = pdTRUE;
|
||||
}
|
||||
|
||||
|
|
@ -195,27 +194,27 @@ short sError = pdFALSE;
|
|||
|
||||
static portTASK_FUNCTION( vCompetingMathTask3, pvParameters )
|
||||
{
|
||||
volatile portDOUBLE *pdArray, dTotal1, dTotal2, dDifference;
|
||||
volatile uint16_t *pusTaskCheckVariable;
|
||||
const size_t xArraySize = 10;
|
||||
size_t xPosition;
|
||||
short sError = pdFALSE;
|
||||
volatile portDOUBLE * pdArray, dTotal1, dTotal2, dDifference;
|
||||
volatile uint16_t * pusTaskCheckVariable;
|
||||
const size_t xArraySize = 10;
|
||||
size_t xPosition;
|
||||
short sError = pdFALSE;
|
||||
|
||||
/* Some ports require that tasks that use a hardware floating point unit
|
||||
tell the kernel that they require a floating point context before any
|
||||
floating point instructions are executed. */
|
||||
* tell the kernel that they require a floating point context before any
|
||||
* floating point instructions are executed. */
|
||||
portTASK_USES_FLOATING_POINT();
|
||||
|
||||
/* The variable this task increments to show it is still running is passed in
|
||||
as the parameter. */
|
||||
* as the parameter. */
|
||||
pusTaskCheckVariable = ( volatile uint16_t * ) pvParameters;
|
||||
|
||||
pdArray = ( portDOUBLE * ) pvPortMalloc( xArraySize * sizeof( portDOUBLE ) );
|
||||
|
||||
/* Keep filling an array, keeping a running total of the values placed in the
|
||||
array. Then run through the array adding up all the values. If the two totals
|
||||
do not match, stop the check variable from incrementing. */
|
||||
for( ;; )
|
||||
* array. Then run through the array adding up all the values. If the two totals
|
||||
* do not match, stop the check variable from incrementing. */
|
||||
for( ; ; )
|
||||
{
|
||||
dTotal1 = 0.0;
|
||||
dTotal2 = 0.0;
|
||||
|
|
@ -236,6 +235,7 @@ short sError = pdFALSE;
|
|||
}
|
||||
|
||||
dDifference = dTotal1 - dTotal2;
|
||||
|
||||
if( fabs( dDifference ) > 0.001 )
|
||||
{
|
||||
sError = pdTRUE;
|
||||
|
|
@ -248,8 +248,8 @@ short sError = pdFALSE;
|
|||
if( sError == pdFALSE )
|
||||
{
|
||||
/* If the calculation has always been correct then set set the check
|
||||
variable. The check variable will get set to pdFALSE each time
|
||||
xAreMathsTaskStillRunning() is executed. */
|
||||
* variable. The check variable will get set to pdFALSE each time
|
||||
* xAreMathsTaskStillRunning() is executed. */
|
||||
( *pusTaskCheckVariable ) = pdTRUE;
|
||||
}
|
||||
}
|
||||
|
|
@ -258,27 +258,27 @@ short sError = pdFALSE;
|
|||
|
||||
static portTASK_FUNCTION( vCompetingMathTask4, pvParameters )
|
||||
{
|
||||
volatile portDOUBLE *pdArray, dTotal1, dTotal2, dDifference;
|
||||
volatile uint16_t *pusTaskCheckVariable;
|
||||
const size_t xArraySize = 10;
|
||||
size_t xPosition;
|
||||
short sError = pdFALSE;
|
||||
volatile portDOUBLE * pdArray, dTotal1, dTotal2, dDifference;
|
||||
volatile uint16_t * pusTaskCheckVariable;
|
||||
const size_t xArraySize = 10;
|
||||
size_t xPosition;
|
||||
short sError = pdFALSE;
|
||||
|
||||
/* Some ports require that tasks that use a hardware floating point unit
|
||||
tell the kernel that they require a floating point context before any
|
||||
floating point instructions are executed. */
|
||||
* tell the kernel that they require a floating point context before any
|
||||
* floating point instructions are executed. */
|
||||
portTASK_USES_FLOATING_POINT();
|
||||
|
||||
/* The variable this task increments to show it is still running is passed in
|
||||
as the parameter. */
|
||||
* as the parameter. */
|
||||
pusTaskCheckVariable = ( volatile uint16_t * ) pvParameters;
|
||||
|
||||
pdArray = ( portDOUBLE * ) pvPortMalloc( xArraySize * sizeof( portDOUBLE ) );
|
||||
|
||||
/* Keep filling an array, keeping a running total of the values placed in the
|
||||
array. Then run through the array adding up all the values. If the two totals
|
||||
do not match, stop the check variable from incrementing. */
|
||||
for( ;; )
|
||||
* array. Then run through the array adding up all the values. If the two totals
|
||||
* do not match, stop the check variable from incrementing. */
|
||||
for( ; ; )
|
||||
{
|
||||
dTotal1 = 0.0;
|
||||
dTotal2 = 0.0;
|
||||
|
|
@ -299,6 +299,7 @@ short sError = pdFALSE;
|
|||
}
|
||||
|
||||
dDifference = dTotal1 - dTotal2;
|
||||
|
||||
if( fabs( dDifference ) > 0.001 )
|
||||
{
|
||||
sError = pdTRUE;
|
||||
|
|
@ -311,8 +312,8 @@ short sError = pdFALSE;
|
|||
if( sError == pdFALSE )
|
||||
{
|
||||
/* If the calculation has always been correct then set set the check
|
||||
variable. The check variable will get set to pdFALSE each time
|
||||
xAreMathsTaskStillRunning() is executed. */
|
||||
* variable. The check variable will get set to pdFALSE each time
|
||||
* xAreMathsTaskStillRunning() is executed. */
|
||||
( *pusTaskCheckVariable ) = pdTRUE;
|
||||
}
|
||||
}
|
||||
|
|
@ -322,28 +323,25 @@ short sError = pdFALSE;
|
|||
/* This is called to check that all the created tasks are still running. */
|
||||
BaseType_t xAreMathsTaskStillRunning( void )
|
||||
{
|
||||
BaseType_t xReturn = pdPASS, xTask;
|
||||
BaseType_t xReturn = pdPASS, xTask;
|
||||
|
||||
/* Check the maths tasks are still running by ensuring their check variables
|
||||
have been set to pdPASS. */
|
||||
* have been set to pdPASS. */
|
||||
for( xTask = 0; xTask < mathNUMBER_OF_TASKS; xTask++ )
|
||||
{
|
||||
if( usTaskCheck[ xTask ] != pdTRUE )
|
||||
{
|
||||
/* The check has not been set so the associated task has either
|
||||
stalled or detected an error. */
|
||||
* stalled or detected an error. */
|
||||
xReturn = pdFAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Reset the variable so it can be checked again the next time this
|
||||
function is executed. */
|
||||
* function is executed. */
|
||||
usTaskCheck[ xTask ] = pdFALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -54,21 +54,21 @@
|
|||
#define intgNUMBER_OF_TASKS ( 1 )
|
||||
|
||||
/* The task function. Repeatedly performs a 32 bit calculation, checking the
|
||||
result against the expected result. If the result is incorrect then the
|
||||
context switch must have caused some corruption. */
|
||||
* result against the expected result. If the result is incorrect then the
|
||||
* context switch must have caused some corruption. */
|
||||
static portTASK_FUNCTION_PROTO( vCompeteingIntMathTask, pvParameters );
|
||||
|
||||
/* Variables that are set to true within the calculation task to indicate
|
||||
that the task is still executing. The check task sets the variable back to
|
||||
false, flagging an error if the variable is still false the next time it
|
||||
is called. */
|
||||
* that the task is still executing. The check task sets the variable back to
|
||||
* false, flagging an error if the variable is still false the next time it
|
||||
* is called. */
|
||||
static BaseType_t xTaskCheck[ intgNUMBER_OF_TASKS ] = { ( BaseType_t ) pdFALSE };
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vStartIntegerMathTasks( UBaseType_t uxPriority )
|
||||
{
|
||||
short sTask;
|
||||
short sTask;
|
||||
|
||||
for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
|
||||
{
|
||||
|
|
@ -80,21 +80,21 @@ short sTask;
|
|||
static portTASK_FUNCTION( vCompeteingIntMathTask, pvParameters )
|
||||
{
|
||||
/* These variables are all effectively set to constants so they are volatile to
|
||||
ensure the compiler does not just get rid of them. */
|
||||
volatile long lValue;
|
||||
short sError = pdFALSE;
|
||||
volatile BaseType_t *pxTaskHasExecuted;
|
||||
* ensure the compiler does not just get rid of them. */
|
||||
volatile long lValue;
|
||||
short sError = pdFALSE;
|
||||
volatile BaseType_t * pxTaskHasExecuted;
|
||||
|
||||
/* Set a pointer to the variable we are going to set to true each
|
||||
iteration. This is also a good test of the parameter passing mechanism
|
||||
within each port. */
|
||||
* iteration. This is also a good test of the parameter passing mechanism
|
||||
* within each port. */
|
||||
pxTaskHasExecuted = ( volatile BaseType_t * ) pvParameters;
|
||||
|
||||
/* Keep performing a calculation and checking the result against a constant. */
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Perform the calculation. This will store partial value in
|
||||
registers, resulting in a good test of the context switch mechanism. */
|
||||
* registers, resulting in a good test of the context switch mechanism. */
|
||||
lValue = intgCONST1;
|
||||
lValue += intgCONST2;
|
||||
|
||||
|
|
@ -110,8 +110,8 @@ volatile BaseType_t *pxTaskHasExecuted;
|
|||
lValue /= intgCONST4;
|
||||
|
||||
/* If the calculation is found to be incorrect we stop setting the
|
||||
TaskHasExecuted variable so the check task can see an error has
|
||||
occurred. */
|
||||
* TaskHasExecuted variable so the check task can see an error has
|
||||
* occurred. */
|
||||
if( lValue != intgEXPECTED_ANSWER ) /*lint !e774 volatile used to prevent this being optimised out. */
|
||||
{
|
||||
sError = pdTRUE;
|
||||
|
|
@ -120,8 +120,8 @@ volatile BaseType_t *pxTaskHasExecuted;
|
|||
if( sError == pdFALSE )
|
||||
{
|
||||
/* We have not encountered any errors, so set the flag that show
|
||||
we are still executing. This will be periodically cleared by
|
||||
the check task. */
|
||||
* we are still executing. This will be periodically cleared by
|
||||
* the check task. */
|
||||
portENTER_CRITICAL();
|
||||
*pxTaskHasExecuted = pdTRUE;
|
||||
portEXIT_CRITICAL();
|
||||
|
|
@ -140,11 +140,11 @@ volatile BaseType_t *pxTaskHasExecuted;
|
|||
/* This is called to check that all the created tasks are still running. */
|
||||
BaseType_t xAreIntegerMathsTaskStillRunning( void )
|
||||
{
|
||||
BaseType_t xReturn = pdTRUE;
|
||||
short sTask;
|
||||
BaseType_t xReturn = pdTRUE;
|
||||
short sTask;
|
||||
|
||||
/* Check the maths tasks are still running by ensuring their check variables
|
||||
are still being set to true. */
|
||||
* are still being set to true. */
|
||||
for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
|
||||
{
|
||||
if( xTaskCheck[ sTask ] == pdFALSE )
|
||||
|
|
@ -154,10 +154,9 @@ short sTask;
|
|||
}
|
||||
|
||||
/* Reset the check variable so we can tell if it has been set by
|
||||
the next time around. */
|
||||
* the next time around. */
|
||||
xTaskCheck[ sTask ] = pdFALSE;
|
||||
}
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,40 +26,40 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
The tasks defined on this page demonstrate the use of recursive mutexes.
|
||||
|
||||
For recursive mutex functionality the created mutex should be created using
|
||||
xSemaphoreCreateRecursiveMutex(), then be manipulated
|
||||
using the xSemaphoreTakeRecursive() and xSemaphoreGiveRecursive() API
|
||||
functions.
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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.
|
||||
*/
|
||||
* The tasks defined on this page demonstrate the use of recursive mutexes.
|
||||
*
|
||||
* For recursive mutex functionality the created mutex should be created using
|
||||
* xSemaphoreCreateRecursiveMutex(), then be manipulated
|
||||
* using the xSemaphoreTakeRecursive() and xSemaphoreGiveRecursive() API
|
||||
* functions.
|
||||
*
|
||||
* 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
|
||||
* 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
|
||||
* 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
|
||||
* 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
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* Scheduler include files. */
|
||||
#include "FreeRTOS.h"
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
#include "recmutex.h"
|
||||
|
||||
/* Priorities assigned to the three tasks. recmuCONTROLLING_TASK_PRIORITY can
|
||||
be overridden by a definition in FreeRTOSConfig.h. */
|
||||
* be overridden by a definition in FreeRTOSConfig.h. */
|
||||
#ifndef recmuCONTROLLING_TASK_PRIORITY
|
||||
#define recmuCONTROLLING_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
|
||||
#endif
|
||||
|
|
@ -90,9 +90,9 @@ be overridden by a definition in FreeRTOSConfig.h. */
|
|||
#endif
|
||||
|
||||
/* The three tasks as described at the top of this file. */
|
||||
static void prvRecursiveMutexControllingTask( void *pvParameters );
|
||||
static void prvRecursiveMutexBlockingTask( void *pvParameters );
|
||||
static void prvRecursiveMutexPollingTask( void *pvParameters );
|
||||
static void prvRecursiveMutexControllingTask( void * pvParameters );
|
||||
static void prvRecursiveMutexBlockingTask( void * pvParameters );
|
||||
static void prvRecursiveMutexPollingTask( void * pvParameters );
|
||||
|
||||
/* The mutex used by the demo. */
|
||||
static SemaphoreHandle_t xMutex;
|
||||
|
|
@ -102,7 +102,7 @@ static volatile BaseType_t xErrorOccurred = pdFALSE, xControllingIsSuspended = p
|
|||
static volatile UBaseType_t uxControllingCycles = 0, uxBlockingCycles = 0, uxPollingCycles = 0;
|
||||
|
||||
/* Handles of the two higher priority tasks, required so they can be resumed
|
||||
(unsuspended). */
|
||||
* (unsuspended). */
|
||||
static TaskHandle_t xControllingTaskHandle, xBlockingTaskHandle;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
|
@ -116,11 +116,11 @@ void vStartRecursiveMutexTasks( void )
|
|||
if( xMutex != NULL )
|
||||
{
|
||||
/* vQueueAddToRegistry() adds the mutex to the registry, if one is
|
||||
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
|
||||
defined to be less than 1. */
|
||||
* 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
|
||||
* defined to be less than 1. */
|
||||
vQueueAddToRegistry( ( QueueHandle_t ) xMutex, "Recursive_Mutex" );
|
||||
|
||||
xTaskCreate( prvRecursiveMutexControllingTask, "Rec1", recmuRECURSIVE_MUTEX_TEST_TASK_STACK_SIZE, NULL, recmuCONTROLLING_TASK_PRIORITY, &xControllingTaskHandle );
|
||||
|
|
@ -130,19 +130,19 @@ void vStartRecursiveMutexTasks( void )
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvRecursiveMutexControllingTask( void *pvParameters )
|
||||
static void prvRecursiveMutexControllingTask( void * pvParameters )
|
||||
{
|
||||
UBaseType_t ux;
|
||||
UBaseType_t ux;
|
||||
|
||||
/* Just to remove compiler warning. */
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Should not be able to 'give' the mutex, as we have not yet 'taken'
|
||||
it. The first time through, the mutex will not have been used yet,
|
||||
subsequent times through, at this point the mutex will be held by the
|
||||
polling task. */
|
||||
* it. The first time through, the mutex will not have been used yet,
|
||||
* subsequent times through, at this point the mutex will be held by the
|
||||
* polling task. */
|
||||
if( xSemaphoreGiveRecursive( xMutex ) == pdPASS )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
|
|
@ -151,24 +151,24 @@ UBaseType_t ux;
|
|||
for( ux = 0; ux < recmuMAX_COUNT; 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
|
||||
the priority of this task. In this case the block time must be
|
||||
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. */
|
||||
* 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
|
||||
* the priority of this task. In this case the block time must be
|
||||
* 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, recmu15ms_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
|
||||
block time is specified) as the mutex is held by this task. */
|
||||
* other demo tasks) are able to execute to ensure they either block
|
||||
* (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 );
|
||||
}
|
||||
|
||||
|
|
@ -176,33 +176,33 @@ UBaseType_t ux;
|
|||
for( ux = 0; ux < recmuMAX_COUNT; ux++ )
|
||||
{
|
||||
/* Ensure the other task attempting to access the mutex (and the
|
||||
other demo tasks) are able to execute. */
|
||||
* other demo tasks) are able to execute. */
|
||||
vTaskDelay( recmuSHORT_DELAY );
|
||||
|
||||
/* We should now be able to give the mutex as many times as we
|
||||
took it. When the mutex is available again the Blocking task
|
||||
should be unblocked but not run because it has a lower priority
|
||||
than this task. The polling task should also not run at this point
|
||||
as it too has a lower priority than this task. */
|
||||
* took it. When the mutex is available again the Blocking task
|
||||
* should be unblocked but not run because it has a lower priority
|
||||
* than this task. The polling task should also not run at this point
|
||||
* as it too has a lower priority than this task. */
|
||||
if( xSemaphoreGiveRecursive( xMutex ) != pdPASS )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
#if( configUSE_PREEMPTION == 0 )
|
||||
#if ( configUSE_PREEMPTION == 0 )
|
||||
taskYIELD();
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Having given it back the same number of times as it was taken, we
|
||||
should no longer be the mutex owner, so the next give should fail. */
|
||||
* should no longer be the mutex owner, so the next give should fail. */
|
||||
if( xSemaphoreGiveRecursive( xMutex ) == pdPASS )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
/* Keep count of the number of cycles this task has performed so a
|
||||
stall can be detected. */
|
||||
* stall can be detected. */
|
||||
uxControllingCycles++;
|
||||
|
||||
/* Suspend ourselves so the blocking task can execute. */
|
||||
|
|
@ -213,32 +213,32 @@ UBaseType_t ux;
|
|||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvRecursiveMutexBlockingTask( void *pvParameters )
|
||||
static void prvRecursiveMutexBlockingTask( void * pvParameters )
|
||||
{
|
||||
/* Just to remove compiler warning. */
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* 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. 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). */
|
||||
* 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. 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 )
|
||||
{
|
||||
/* Did not expect to execute until the controlling task was
|
||||
suspended. */
|
||||
* suspended. */
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Give the mutex back before suspending ourselves to allow
|
||||
the polling task to obtain the mutex. */
|
||||
* the polling task to obtain the mutex. */
|
||||
if( xSemaphoreGiveRecursive( xMutex ) != pdPASS )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
|
|
@ -252,36 +252,36 @@ static void prvRecursiveMutexBlockingTask( void *pvParameters )
|
|||
else
|
||||
{
|
||||
/* We should not leave the xSemaphoreTakeRecursive() function
|
||||
until the mutex was obtained. */
|
||||
* until the mutex was obtained. */
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
/* The controlling and blocking tasks should be in lock step. */
|
||||
if( uxControllingCycles != (UBaseType_t) ( uxBlockingCycles + 1 ) )
|
||||
if( uxControllingCycles != ( UBaseType_t ) ( uxBlockingCycles + 1 ) )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
/* Keep count of the number of cycles this task has performed so a
|
||||
stall can be detected. */
|
||||
* stall can be detected. */
|
||||
uxBlockingCycles++;
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvRecursiveMutexPollingTask( void *pvParameters )
|
||||
static void prvRecursiveMutexPollingTask( void * pvParameters )
|
||||
{
|
||||
/* Just to remove compiler warning. */
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Keep attempting to obtain the mutex. It should only be obtained when
|
||||
the blocking task has suspended itself, which in turn should only
|
||||
happen when the controlling task is also suspended. */
|
||||
* the blocking task has suspended itself, which in turn should only
|
||||
* happen when the controlling task is also suspended. */
|
||||
if( xSemaphoreTakeRecursive( xMutex, recmuNO_DELAY ) == pdPASS )
|
||||
{
|
||||
#if( INCLUDE_eTaskGetState == 1 )
|
||||
#if ( INCLUDE_eTaskGetState == 1 )
|
||||
{
|
||||
configASSERT( eTaskGetState( xControllingTaskHandle ) == eSuspended );
|
||||
configASSERT( eTaskGetState( xBlockingTaskHandle ) == eSuspended );
|
||||
|
|
@ -296,43 +296,43 @@ static void prvRecursiveMutexPollingTask( void *pvParameters )
|
|||
else
|
||||
{
|
||||
/* Keep count of the number of cycles this task has performed
|
||||
so a stall can be detected. */
|
||||
* so a stall can be detected. */
|
||||
uxPollingCycles++;
|
||||
|
||||
/* We can resume the other tasks here even though they have a
|
||||
higher priority than the polling task. When they execute they
|
||||
will attempt to obtain the mutex but fail because the polling
|
||||
task is still the mutex holder. The polling task (this task)
|
||||
will then inherit the higher priority. The Blocking task will
|
||||
block indefinitely when it attempts to obtain the mutex, the
|
||||
Controlling task will only block for a fixed period and an
|
||||
error will be latched if the polling task has not returned the
|
||||
mutex by the time this fixed period has expired. */
|
||||
* higher priority than the polling task. When they execute they
|
||||
* will attempt to obtain the mutex but fail because the polling
|
||||
* task is still the mutex holder. The polling task (this task)
|
||||
* will then inherit the higher priority. The Blocking task will
|
||||
* block indefinitely when it attempts to obtain the mutex, the
|
||||
* Controlling task will only block for a fixed period and an
|
||||
* error will be latched if the polling task has not returned the
|
||||
* mutex by the time this fixed period has expired. */
|
||||
vTaskResume( xBlockingTaskHandle );
|
||||
#if( configUSE_PREEMPTION == 0 )
|
||||
#if ( configUSE_PREEMPTION == 0 )
|
||||
taskYIELD();
|
||||
#endif
|
||||
|
||||
vTaskResume( xControllingTaskHandle );
|
||||
#if( configUSE_PREEMPTION == 0 )
|
||||
#if ( configUSE_PREEMPTION == 0 )
|
||||
taskYIELD();
|
||||
#endif
|
||||
|
||||
/* The other two tasks should now have executed and no longer
|
||||
be suspended. */
|
||||
* be suspended. */
|
||||
if( ( xBlockingIsSuspended == pdTRUE ) || ( xControllingIsSuspended == pdTRUE ) )
|
||||
{
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
#if( INCLUDE_uxTaskPriorityGet == 1 )
|
||||
#if ( INCLUDE_uxTaskPriorityGet == 1 )
|
||||
{
|
||||
/* Check priority inherited. */
|
||||
configASSERT( uxTaskPriorityGet( NULL ) == recmuCONTROLLING_TASK_PRIORITY );
|
||||
}
|
||||
#endif /* INCLUDE_uxTaskPriorityGet */
|
||||
|
||||
#if( INCLUDE_eTaskGetState == 1 )
|
||||
#if ( INCLUDE_eTaskGetState == 1 )
|
||||
{
|
||||
configASSERT( eTaskGetState( xControllingTaskHandle ) == eBlocked );
|
||||
configASSERT( eTaskGetState( xBlockingTaskHandle ) == eBlocked );
|
||||
|
|
@ -345,7 +345,7 @@ static void prvRecursiveMutexPollingTask( void *pvParameters )
|
|||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
#if( INCLUDE_uxTaskPriorityGet == 1 )
|
||||
#if ( INCLUDE_uxTaskPriorityGet == 1 )
|
||||
{
|
||||
/* Check priority disinherited. */
|
||||
configASSERT( uxTaskPriorityGet( NULL ) == recmuPOLLING_TASK_PRIORITY );
|
||||
|
|
@ -366,8 +366,8 @@ static void prvRecursiveMutexPollingTask( void *pvParameters )
|
|||
/* This is called to check that all the created tasks are still running. */
|
||||
BaseType_t xAreRecursiveMutexTasksStillRunning( void )
|
||||
{
|
||||
BaseType_t xReturn;
|
||||
static UBaseType_t uxLastControllingCycles = 0, uxLastBlockingCycles = 0, uxLastPollingCycles = 0;
|
||||
BaseType_t xReturn;
|
||||
static UBaseType_t uxLastControllingCycles = 0, uxLastBlockingCycles = 0, uxLastPollingCycles = 0;
|
||||
|
||||
/* Is the controlling task still cycling? */
|
||||
if( uxLastControllingCycles == uxControllingCycles )
|
||||
|
|
@ -410,7 +410,3 @@ static UBaseType_t uxLastControllingCycles = 0, uxLastBlockingCycles = 0, uxLast
|
|||
|
||||
return xReturn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ static portTASK_FUNCTION_PROTO( prvSemaphoreTest, pvParameters );
|
|||
typedef struct SEMAPHORE_PARAMETERS
|
||||
{
|
||||
SemaphoreHandle_t xSemaphore;
|
||||
volatile uint32_t *pulSharedVariable;
|
||||
volatile uint32_t * pulSharedVariable;
|
||||
TickType_t xBlockTime;
|
||||
} xSemaphoreParameters;
|
||||
|
||||
|
|
@ -88,8 +88,8 @@ static volatile short sNextCheckVariable = 0;
|
|||
|
||||
void vStartSemaphoreTasks( UBaseType_t uxPriority )
|
||||
{
|
||||
xSemaphoreParameters *pxFirstSemaphoreParameters, *pxSecondSemaphoreParameters;
|
||||
const TickType_t xBlockTime = ( TickType_t ) 100;
|
||||
xSemaphoreParameters * pxFirstSemaphoreParameters, * pxSecondSemaphoreParameters;
|
||||
const TickType_t xBlockTime = ( TickType_t ) 100;
|
||||
|
||||
/* Create the structure used to pass parameters to the first two tasks. */
|
||||
pxFirstSemaphoreParameters = ( xSemaphoreParameters * ) pvPortMalloc( sizeof( xSemaphoreParameters ) );
|
||||
|
|
@ -117,18 +117,19 @@ const TickType_t xBlockTime = ( TickType_t ) 100;
|
|||
xTaskCreate( prvSemaphoreTest, "PolSEM2", semtstSTACK_SIZE, ( void * ) pxFirstSemaphoreParameters, tskIDLE_PRIORITY, ( TaskHandle_t * ) NULL );
|
||||
|
||||
/* vQueueAddToRegistry() adds the semaphore to the registry, if one
|
||||
is in use. The registry is provided as a means for kernel aware
|
||||
debuggers to locate semaphores 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 defined to be less than 1. */
|
||||
* is in use. The registry is provided as a means for kernel aware
|
||||
* debuggers to locate semaphores 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 defined to be less than 1. */
|
||||
vQueueAddToRegistry( ( QueueHandle_t ) pxFirstSemaphoreParameters->xSemaphore, "Counting_Sem_1" );
|
||||
}
|
||||
}
|
||||
|
||||
/* Do exactly the same to create the second set of tasks, only this time
|
||||
provide a block time for the semaphore calls. */
|
||||
* provide a block time for the semaphore calls. */
|
||||
pxSecondSemaphoreParameters = ( xSemaphoreParameters * ) pvPortMalloc( sizeof( xSemaphoreParameters ) );
|
||||
|
||||
if( pxSecondSemaphoreParameters != NULL )
|
||||
{
|
||||
pxSecondSemaphoreParameters->xSemaphore = xSemaphoreCreateBinary();
|
||||
|
|
@ -145,11 +146,11 @@ const TickType_t xBlockTime = ( TickType_t ) 100;
|
|||
xTaskCreate( prvSemaphoreTest, "BlkSEM2", semtstSTACK_SIZE, ( void * ) pxSecondSemaphoreParameters, uxPriority, ( TaskHandle_t * ) NULL );
|
||||
|
||||
/* vQueueAddToRegistry() adds the semaphore to the registry, if one
|
||||
is in use. The registry is provided as a means for kernel aware
|
||||
debuggers to locate semaphores 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 defined to be less than 1. */
|
||||
* is in use. The registry is provided as a means for kernel aware
|
||||
* debuggers to locate semaphores 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 defined to be less than 1. */
|
||||
vQueueAddToRegistry( ( QueueHandle_t ) pxSecondSemaphoreParameters->xSemaphore, "Counting_Sem_2" );
|
||||
}
|
||||
}
|
||||
|
|
@ -158,25 +159,25 @@ const TickType_t xBlockTime = ( TickType_t ) 100;
|
|||
|
||||
static portTASK_FUNCTION( prvSemaphoreTest, pvParameters )
|
||||
{
|
||||
xSemaphoreParameters *pxParameters;
|
||||
volatile uint32_t *pulSharedVariable, ulExpectedValue;
|
||||
uint32_t ulCounter;
|
||||
short sError = pdFALSE, sCheckVariableToUse;
|
||||
xSemaphoreParameters * pxParameters;
|
||||
volatile uint32_t * pulSharedVariable, ulExpectedValue;
|
||||
uint32_t ulCounter;
|
||||
short sError = pdFALSE, sCheckVariableToUse;
|
||||
|
||||
/* See which check variable to use. sNextCheckVariable is not semaphore
|
||||
protected! */
|
||||
* protected! */
|
||||
portENTER_CRITICAL();
|
||||
sCheckVariableToUse = sNextCheckVariable;
|
||||
sNextCheckVariable++;
|
||||
portEXIT_CRITICAL();
|
||||
|
||||
/* A structure is passed in as the parameter. This contains the shared
|
||||
variable being guarded. */
|
||||
* variable being guarded. */
|
||||
pxParameters = ( xSemaphoreParameters * ) pvParameters;
|
||||
pulSharedVariable = pxParameters->pulSharedVariable;
|
||||
|
||||
/* If we are blocking we use a much higher count to ensure loads of context
|
||||
switches occur during the count. */
|
||||
* switches occur during the count. */
|
||||
if( pxParameters->xBlockTime > ( TickType_t ) 0 )
|
||||
{
|
||||
ulExpectedValue = semtstBLOCKING_EXPECTED_VALUE;
|
||||
|
|
@ -186,25 +187,26 @@ short sError = pdFALSE, sCheckVariableToUse;
|
|||
ulExpectedValue = semtstNON_BLOCKING_EXPECTED_VALUE;
|
||||
}
|
||||
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
/* Try to obtain the semaphore. */
|
||||
if( xSemaphoreTake( pxParameters->xSemaphore, pxParameters->xBlockTime ) == pdPASS )
|
||||
{
|
||||
/* We have the semaphore and so expect any other tasks using the
|
||||
shared variable to have left it in the state we expect to find
|
||||
it. */
|
||||
* shared variable to have left it in the state we expect to find
|
||||
* it. */
|
||||
if( *pulSharedVariable != ulExpectedValue )
|
||||
{
|
||||
sError = pdTRUE;
|
||||
}
|
||||
|
||||
/* Clear the variable, then count it back up to the expected value
|
||||
before releasing the semaphore. Would expect a context switch or
|
||||
two during this time. */
|
||||
* before releasing the semaphore. Would expect a context switch or
|
||||
* two during this time. */
|
||||
for( ulCounter = ( uint32_t ) 0; ulCounter <= ulExpectedValue; ulCounter++ )
|
||||
{
|
||||
*pulSharedVariable = ulCounter;
|
||||
|
||||
if( *pulSharedVariable != ulCounter )
|
||||
{
|
||||
sError = pdTRUE;
|
||||
|
|
@ -212,7 +214,7 @@ short sError = pdFALSE, sCheckVariableToUse;
|
|||
}
|
||||
|
||||
/* Release the semaphore, and if no errors have occurred increment the check
|
||||
variable. */
|
||||
* variable. */
|
||||
if( xSemaphoreGive( pxParameters->xSemaphore ) == pdFALSE )
|
||||
{
|
||||
sError = pdTRUE;
|
||||
|
|
@ -227,23 +229,22 @@ short sError = pdFALSE, sCheckVariableToUse;
|
|||
}
|
||||
|
||||
/* If we have a block time then we are running at a priority higher
|
||||
than the idle priority. This task takes a long time to complete
|
||||
a cycle (deliberately so to test the guarding) so will be starving
|
||||
out lower priority tasks. Block for some time to allow give lower
|
||||
priority tasks some processor time. */
|
||||
* than the idle priority. This task takes a long time to complete
|
||||
* a cycle (deliberately so to test the guarding) so will be starving
|
||||
* out lower priority tasks. Block for some time to allow give lower
|
||||
* priority tasks some processor time. */
|
||||
if( pxParameters->xBlockTime != ( TickType_t ) 0 )
|
||||
{
|
||||
vTaskDelay( pxParameters->xBlockTime * semtstDELAY_FACTOR );
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if( pxParameters->xBlockTime == ( TickType_t ) 0 )
|
||||
{
|
||||
/* We have not got the semaphore yet, so no point using the
|
||||
processor. We are not blocking when attempting to obtain the
|
||||
semaphore. */
|
||||
* processor. We are not blocking when attempting to obtain the
|
||||
* semaphore. */
|
||||
taskYIELD();
|
||||
}
|
||||
}
|
||||
|
|
@ -254,8 +255,8 @@ short sError = pdFALSE, sCheckVariableToUse;
|
|||
/* This is called to check that all the created tasks are still running. */
|
||||
BaseType_t xAreSemaphoreTasksStillRunning( void )
|
||||
{
|
||||
static short sLastCheckVariables[ semtstNUM_TASKS ] = { 0 };
|
||||
BaseType_t xTask, xReturn = pdTRUE;
|
||||
static short sLastCheckVariables[ semtstNUM_TASKS ] = { 0 };
|
||||
BaseType_t xTask, xReturn = pdTRUE;
|
||||
|
||||
for( xTask = 0; xTask < semtstNUM_TASKS; xTask++ )
|
||||
{
|
||||
|
|
@ -269,4 +270,3 @@ BaseType_t xTask, xReturn = pdTRUE;
|
|||
|
||||
return xReturn;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,15 +52,15 @@
|
|||
#define mathNUMBER_OF_TASKS ( 8 )
|
||||
|
||||
/* Four tasks, each of which performs a different floating point calculation.
|
||||
Each of the four is created twice. */
|
||||
* Each of the four is created twice. */
|
||||
static portTASK_FUNCTION_PROTO( vCompetingMathTask1, pvParameters );
|
||||
static portTASK_FUNCTION_PROTO( vCompetingMathTask2, pvParameters );
|
||||
static portTASK_FUNCTION_PROTO( vCompetingMathTask3, pvParameters );
|
||||
static portTASK_FUNCTION_PROTO( vCompetingMathTask4, pvParameters );
|
||||
|
||||
/* These variables are used to check that all the tasks are still running. If a
|
||||
task gets a calculation wrong it will
|
||||
stop incrementing its check variable. */
|
||||
* task gets a calculation wrong it will
|
||||
* stop incrementing its check variable. */
|
||||
static volatile uint16_t usTaskCheck[ mathNUMBER_OF_TASKS ] = { ( uint16_t ) 0 };
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
|
@ -80,10 +80,10 @@ void vStartMathTasks( UBaseType_t uxPriority )
|
|||
|
||||
static portTASK_FUNCTION( vCompetingMathTask1, pvParameters )
|
||||
{
|
||||
volatile float f1, f2, f3, f4;
|
||||
volatile uint16_t *pusTaskCheckVariable;
|
||||
volatile float fAnswer;
|
||||
short sError = pdFALSE;
|
||||
volatile float f1, f2, f3, f4;
|
||||
volatile uint16_t * pusTaskCheckVariable;
|
||||
volatile float fAnswer;
|
||||
short sError = pdFALSE;
|
||||
|
||||
f1 = 123.4567F;
|
||||
f2 = 2345.6789F;
|
||||
|
|
@ -92,11 +92,11 @@ short sError = pdFALSE;
|
|||
fAnswer = ( f1 + f2 ) * f3;
|
||||
|
||||
/* The variable this task increments to show it is still running is passed in
|
||||
as the parameter. */
|
||||
* as the parameter. */
|
||||
pusTaskCheckVariable = ( uint16_t * ) pvParameters;
|
||||
|
||||
/* Keep performing a calculation and checking the result against a constant. */
|
||||
for(;;)
|
||||
for( ; ; )
|
||||
{
|
||||
f1 = 123.4567F;
|
||||
f2 = 2345.6789F;
|
||||
|
|
@ -109,7 +109,7 @@ short sError = pdFALSE;
|
|||
#endif
|
||||
|
||||
/* If the calculation does not match the expected constant, stop the
|
||||
increment of the check variable. */
|
||||
* increment of the check variable. */
|
||||
if( fabs( f4 - fAnswer ) > 0.001F )
|
||||
{
|
||||
sError = pdTRUE;
|
||||
|
|
@ -118,24 +118,23 @@ short sError = pdFALSE;
|
|||
if( sError == pdFALSE )
|
||||
{
|
||||
/* If the calculation has always been correct, increment the check
|
||||
variable so we know this task is still running okay. */
|
||||
* variable so we know this task is still running okay. */
|
||||
( *pusTaskCheckVariable )++;
|
||||
}
|
||||
|
||||
#if configUSE_PREEMPTION == 0
|
||||
taskYIELD();
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static portTASK_FUNCTION( vCompetingMathTask2, pvParameters )
|
||||
{
|
||||
volatile float f1, f2, f3, f4;
|
||||
volatile uint16_t *pusTaskCheckVariable;
|
||||
volatile float fAnswer;
|
||||
short sError = pdFALSE;
|
||||
volatile float f1, f2, f3, f4;
|
||||
volatile uint16_t * pusTaskCheckVariable;
|
||||
volatile float fAnswer;
|
||||
short sError = pdFALSE;
|
||||
|
||||
f1 = -389.38F;
|
||||
f2 = 32498.2F;
|
||||
|
|
@ -145,11 +144,11 @@ short sError = pdFALSE;
|
|||
|
||||
|
||||
/* The variable this task increments to show it is still running is passed in
|
||||
as the parameter. */
|
||||
* as the parameter. */
|
||||
pusTaskCheckVariable = ( uint16_t * ) pvParameters;
|
||||
|
||||
/* Keep performing a calculation and checking the result against a constant. */
|
||||
for( ;; )
|
||||
for( ; ; )
|
||||
{
|
||||
f1 = -389.38F;
|
||||
f2 = 32498.2F;
|
||||
|
|
@ -162,7 +161,7 @@ short sError = pdFALSE;
|
|||
#endif
|
||||
|
||||
/* If the calculation does not match the expected constant, stop the
|
||||
increment of the check variable. */
|
||||
* increment of the check variable. */
|
||||
if( fabs( f4 - fAnswer ) > 0.001F )
|
||||
{
|
||||
sError = pdTRUE;
|
||||
|
|
@ -171,8 +170,8 @@ short sError = pdFALSE;
|
|||
if( sError == pdFALSE )
|
||||
{
|
||||
/* If the calculation has always been correct, increment the check
|
||||
variable so we know
|
||||
this task is still running okay. */
|
||||
* variable so we know
|
||||
* this task is still running okay. */
|
||||
( *pusTaskCheckVariable )++;
|
||||
}
|
||||
|
||||
|
|
@ -185,22 +184,22 @@ short sError = pdFALSE;
|
|||
|
||||
static portTASK_FUNCTION( vCompetingMathTask3, pvParameters )
|
||||
{
|
||||
volatile float *pfArray, fTotal1, fTotal2, fDifference, fPosition;
|
||||
volatile uint16_t *pusTaskCheckVariable;
|
||||
const size_t xArraySize = 10;
|
||||
size_t xPosition;
|
||||
short sError = pdFALSE;
|
||||
volatile float * pfArray, fTotal1, fTotal2, fDifference, fPosition;
|
||||
volatile uint16_t * pusTaskCheckVariable;
|
||||
const size_t xArraySize = 10;
|
||||
size_t xPosition;
|
||||
short sError = pdFALSE;
|
||||
|
||||
/* The variable this task increments to show it is still running is passed in
|
||||
as the parameter. */
|
||||
* as the parameter. */
|
||||
pusTaskCheckVariable = ( uint16_t * ) pvParameters;
|
||||
|
||||
pfArray = ( float * ) pvPortMalloc( xArraySize * sizeof( float ) );
|
||||
|
||||
/* Keep filling an array, keeping a running total of the values placed in the
|
||||
array. Then run through the array adding up all the values. If the two totals
|
||||
do not match, stop the check variable from incrementing. */
|
||||
for( ;; )
|
||||
* array. Then run through the array adding up all the values. If the two totals
|
||||
* do not match, stop the check variable from incrementing. */
|
||||
for( ; ; )
|
||||
{
|
||||
fTotal1 = 0.0F;
|
||||
fTotal2 = 0.0F;
|
||||
|
|
@ -222,6 +221,7 @@ short sError = pdFALSE;
|
|||
}
|
||||
|
||||
fDifference = fTotal1 - fTotal2;
|
||||
|
||||
if( fabs( fDifference ) > 0.001F )
|
||||
{
|
||||
sError = pdTRUE;
|
||||
|
|
@ -234,7 +234,7 @@ short sError = pdFALSE;
|
|||
if( sError == pdFALSE )
|
||||
{
|
||||
/* If the calculation has always been correct, increment the check
|
||||
variable so we know this task is still running okay. */
|
||||
* variable so we know this task is still running okay. */
|
||||
( *pusTaskCheckVariable )++;
|
||||
}
|
||||
}
|
||||
|
|
@ -243,22 +243,22 @@ short sError = pdFALSE;
|
|||
|
||||
static portTASK_FUNCTION( vCompetingMathTask4, pvParameters )
|
||||
{
|
||||
volatile float *pfArray, fTotal1, fTotal2, fDifference, fPosition;
|
||||
volatile uint16_t *pusTaskCheckVariable;
|
||||
const size_t xArraySize = 10;
|
||||
size_t xPosition;
|
||||
short sError = pdFALSE;
|
||||
volatile float * pfArray, fTotal1, fTotal2, fDifference, fPosition;
|
||||
volatile uint16_t * pusTaskCheckVariable;
|
||||
const size_t xArraySize = 10;
|
||||
size_t xPosition;
|
||||
short sError = pdFALSE;
|
||||
|
||||
/* The variable this task increments to show it is still running is passed in
|
||||
as the parameter. */
|
||||
* as the parameter. */
|
||||
pusTaskCheckVariable = ( uint16_t * ) pvParameters;
|
||||
|
||||
pfArray = ( float * ) pvPortMalloc( xArraySize * sizeof( float ) );
|
||||
|
||||
/* Keep filling an array, keeping a running total of the values placed in the
|
||||
array. Then run through the array adding up all the values. If the two totals
|
||||
do not match, stop the check variable from incrementing. */
|
||||
for( ;; )
|
||||
* array. Then run through the array adding up all the values. If the two totals
|
||||
* do not match, stop the check variable from incrementing. */
|
||||
for( ; ; )
|
||||
{
|
||||
fTotal1 = 0.0F;
|
||||
fTotal2 = 0.0F;
|
||||
|
|
@ -280,6 +280,7 @@ short sError = pdFALSE;
|
|||
}
|
||||
|
||||
fDifference = fTotal1 - fTotal2;
|
||||
|
||||
if( fabs( fDifference ) > 0.001F )
|
||||
{
|
||||
sError = pdTRUE;
|
||||
|
|
@ -292,7 +293,7 @@ short sError = pdFALSE;
|
|||
if( sError == pdFALSE )
|
||||
{
|
||||
/* If the calculation has always been correct, increment the check
|
||||
variable so we know this task is still running okay. */
|
||||
* variable so we know this task is still running okay. */
|
||||
( *pusTaskCheckVariable )++;
|
||||
}
|
||||
}
|
||||
|
|
@ -303,12 +304,12 @@ short sError = pdFALSE;
|
|||
BaseType_t xAreMathsTaskStillRunning( void )
|
||||
{
|
||||
/* Keep a history of the check variables so we know if they have been incremented
|
||||
since the last call. */
|
||||
static uint16_t usLastTaskCheck[ mathNUMBER_OF_TASKS ] = { ( uint16_t ) 0 };
|
||||
BaseType_t xReturn = pdTRUE, xTask;
|
||||
* since the last call. */
|
||||
static uint16_t usLastTaskCheck[ mathNUMBER_OF_TASKS ] = { ( uint16_t ) 0 };
|
||||
BaseType_t xReturn = pdTRUE, xTask;
|
||||
|
||||
/* Check the maths tasks are still running by ensuring their check variables
|
||||
are still incrementing. */
|
||||
* are still incrementing. */
|
||||
for( xTask = 0; xTask < mathNUMBER_OF_TASKS; xTask++ )
|
||||
{
|
||||
if( usTaskCheck[ xTask ] == usLastTaskCheck[ xTask ] )
|
||||
|
|
@ -322,6 +323,3 @@ BaseType_t xReturn = pdTRUE, xTask;
|
|||
|
||||
return xReturn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -32,5 +32,3 @@ void vCreateAbortDelayTasks( void );
|
|||
BaseType_t xAreAbortDelayTestTasksStillRunning( void );
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -32,5 +32,3 @@ void vStartBlockingQueueTasks( UBaseType_t uxPriority );
|
|||
BaseType_t xAreBlockingQueuesStillRunning( void );
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -41,4 +41,3 @@ BaseType_t xAreEventGroupTasksStillRunning( void );
|
|||
void vPeriodicEventGroupsProcessing( void );
|
||||
|
||||
#endif /* EVENT_GROUPS_DEMO_H */
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,3 @@ BaseType_t xAreGenericQueueTasksStillRunning( void );
|
|||
void vMutexISRInteractionTest( void );
|
||||
|
||||
#endif /* GEN_Q_TEST_H */
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -34,9 +34,3 @@ BaseType_t xFirstTimerHandler( void );
|
|||
BaseType_t xSecondTimerHandler( void );
|
||||
|
||||
#endif /* QUEUE_ACCESS_TEST */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,3 @@ BaseType_t xAreInterruptSemaphoreTasksStillRunning( void );
|
|||
void vInterruptSemaphorePeriodicTest( void );
|
||||
|
||||
#endif /* INT_SEM_TEST_H */
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,3 @@ void vStartMessageBufferTasks( configSTACK_DEPTH_TYPE xStackSize );
|
|||
BaseType_t xAreMessageBufferTasksStillRunning( void );
|
||||
|
||||
#endif /* MESSAGE_BUFFER_TEST_H */
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -32,5 +32,3 @@ void vStartPolledQueueTasks( UBaseType_t uxPriority );
|
|||
BaseType_t xArePollingQueuesStillRunning( void );
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,3 @@ void vStartQueuePeekTasks( void );
|
|||
BaseType_t xAreQueuePeekTasksStillRunning( void );
|
||||
|
||||
#endif /* Q_PEEK_TEST_H */
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -33,5 +33,3 @@ BaseType_t xIsQueueOverwriteTaskStillRunning( void );
|
|||
void vQueueOverwritePeriodicISRDemo( void );
|
||||
|
||||
#endif /* QUEUE_OVERWRITE_H */
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -33,5 +33,3 @@ BaseType_t xAreQueueSetTasksStillRunning( void );
|
|||
void vQueueSetAccessQueueSetFromISR( void );
|
||||
|
||||
#endif /* QUEUE_WAIT_MULTIPLE_H */
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -33,5 +33,3 @@ BaseType_t xAreQueueSetPollTasksStillRunning( void );
|
|||
void vQueueSetPollingInterruptAccess( void );
|
||||
|
||||
#endif /* QUEUE_SET_POLLING_H */
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,3 @@ void vStartStaticallyAllocatedTasks( void );
|
|||
BaseType_t xAreStaticAllocationTasksStillRunning( void );
|
||||
|
||||
#endif /* STATIC_ALLOCATION_H */
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,3 @@ BaseType_t xAreStreamBufferTasksStillRunning( void );
|
|||
void vPeriodicStreamBufferProcessing( void );
|
||||
|
||||
#endif /* STREAM_BUFFER_TEST_H */
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,3 @@ BaseType_t xAreTaskNotificationTasksStillRunning( void );
|
|||
void xNotifyTaskFromISR( void );
|
||||
|
||||
#endif /* TASK_NOTIFY_H */
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,3 @@ BaseType_t xAreTaskNotificationArrayTasksStillRunning( void );
|
|||
void xNotifyArrayTaskFromISR( void );
|
||||
|
||||
#endif /* TASK_NOTIFY_ARRAY_H */
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,3 @@ void vTimerPeriodicISRTests( void );
|
|||
void vTimerDemoIncludeBacklogTests( BaseType_t includeBacklogTests );
|
||||
|
||||
#endif /* TIMER_DEMO_H */
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -32,5 +32,3 @@ void vCreateBlockTimeTasks( void );
|
|||
BaseType_t xAreBlockTimeTestTasksStillRunning( void );
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -28,10 +28,13 @@
|
|||
#ifndef COMTEST_H
|
||||
#define COMTEST_H
|
||||
|
||||
void vAltStartComTestTasks( UBaseType_t uxPriority, uint32_t ulBaudRate, UBaseType_t uxLED );
|
||||
void vStartComTestTasks( UBaseType_t uxPriority, eCOMPort ePort, eBaud eBaudRate );
|
||||
void vAltStartComTestTasks( UBaseType_t uxPriority,
|
||||
uint32_t ulBaudRate,
|
||||
UBaseType_t uxLED );
|
||||
void vStartComTestTasks( UBaseType_t uxPriority,
|
||||
eCOMPort ePort,
|
||||
eBaud eBaudRate );
|
||||
BaseType_t xAreComTestTasksStillRunning( void );
|
||||
void vComTestUnsuspendTask( void );
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* ifndef COMTEST_H */
|
||||
|
|
|
|||
|
|
@ -28,8 +28,9 @@
|
|||
#ifndef COMTEST_H
|
||||
#define COMTEST_H
|
||||
|
||||
void vAltStartComTestTasks( UBaseType_t uxPriority, uint32_t ulBaudRate, UBaseType_t uxLED );
|
||||
void vAltStartComTestTasks( UBaseType_t uxPriority,
|
||||
uint32_t ulBaudRate,
|
||||
UBaseType_t uxLED );
|
||||
BaseType_t xAreComTestTasksStillRunning( void );
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,9 @@
|
|||
#ifndef COMTEST_STRINGS_H
|
||||
#define COMTEST_STRINGS_H
|
||||
|
||||
void vStartComTestStringsTasks( UBaseType_t uxPriority, uint32_t ulBaudRate, UBaseType_t uxLED );
|
||||
void vStartComTestStringsTasks( UBaseType_t uxPriority,
|
||||
uint32_t ulBaudRate,
|
||||
UBaseType_t uxLED );
|
||||
BaseType_t xAreComTestTasksStillRunning( void );
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -32,4 +32,3 @@ void vStartCountingSemaphoreTasks( void );
|
|||
BaseType_t xAreCountingSemaphoreTasksStillRunning( void );
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -44,4 +44,3 @@ void vStartFlashCoRoutines( UBaseType_t uxPriority );
|
|||
BaseType_t xAreFlashCoRoutinesStillRunning( void );
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -40,4 +40,3 @@ void vStartHookCoRoutines( void );
|
|||
BaseType_t xAreHookCoRoutinesStillRunning( void );
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -32,5 +32,3 @@ void vCreateSuicidalTasks( UBaseType_t uxPriority );
|
|||
BaseType_t xIsCreateTaskStillRunning( void );
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -32,5 +32,3 @@ void vStartDynamicPriorityTasks( void );
|
|||
BaseType_t xAreDynamicPriorityTasksStillRunning( void );
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
void vDisplayMessage( const char * const pcMessageToPrint );
|
||||
void vWriteMessageToDisk( const char * const pcMessage );
|
||||
void vWriteBufferToDisk( const char * const pcBuffer, uint32_t ulBufferLength );
|
||||
void vWriteBufferToDisk( const char * const pcBuffer,
|
||||
uint32_t ulBufferLength );
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -31,4 +31,3 @@
|
|||
void vStartLEDFlashTasks( UBaseType_t uxPriority );
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -32,5 +32,3 @@ void vStartMathTasks( UBaseType_t uxPriority );
|
|||
BaseType_t xAreMathsTaskStillRunning( void );
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -32,5 +32,3 @@ void vStartIntegerMathTasks( UBaseType_t uxPriority );
|
|||
BaseType_t xAreIntegerMathsTaskStillRunning( void );
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -32,5 +32,3 @@ void vStartMultiEventTasks( void );
|
|||
BaseType_t xAreMultiEventTasksStillRunning( void );
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@
|
|||
#define partstDEFAULT_PORT_ADDRESS ( ( uint16_t ) 0x378 )
|
||||
|
||||
void vParTestInitialise( void );
|
||||
void vParTestSetLED( UBaseType_t uxLED, BaseType_t xValue );
|
||||
void vParTestSetLED( UBaseType_t uxLED,
|
||||
BaseType_t xValue );
|
||||
void vParTestToggleLED( UBaseType_t uxLED );
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -30,8 +30,6 @@
|
|||
|
||||
void vPrintInitialise( void );
|
||||
void vPrintDisplayMessage( const char * const * pcMessageToSend );
|
||||
const char *pcPrintGetNextMessage( TickType_t xPrintRate );
|
||||
const char * pcPrintGetNextMessage( TickType_t xPrintRate );
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -32,4 +32,3 @@ void vStartRecursiveMutexTasks( void );
|
|||
BaseType_t xAreRecursiveMutexTasksStillRunning( void );
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -32,4 +32,3 @@ void vStartSemaphoreTasks( UBaseType_t uxPriority );
|
|||
BaseType_t xAreSemaphoreTasksStillRunning( void );
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -86,13 +86,24 @@ typedef enum
|
|||
ser115200
|
||||
} eBaud;
|
||||
|
||||
xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength );
|
||||
xComPortHandle xSerialPortInit( eCOMPort ePort, eBaud eWantedBaud, eParity eWantedParity, eDataBits eWantedDataBits, eStopBits eWantedStopBits, unsigned portBASE_TYPE uxBufferLength );
|
||||
void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength );
|
||||
signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, TickType_t xBlockTime );
|
||||
signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, TickType_t xBlockTime );
|
||||
xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud,
|
||||
unsigned portBASE_TYPE uxQueueLength );
|
||||
xComPortHandle xSerialPortInit( eCOMPort ePort,
|
||||
eBaud eWantedBaud,
|
||||
eParity eWantedParity,
|
||||
eDataBits eWantedDataBits,
|
||||
eStopBits eWantedStopBits,
|
||||
unsigned portBASE_TYPE uxBufferLength );
|
||||
void vSerialPutString( xComPortHandle pxPort,
|
||||
const signed char * const pcString,
|
||||
unsigned short usStringLength );
|
||||
signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort,
|
||||
signed char * pcRxedChar,
|
||||
TickType_t xBlockTime );
|
||||
signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort,
|
||||
signed char cOutChar,
|
||||
TickType_t xBlockTime );
|
||||
portBASE_TYPE xSerialWaitForSemaphore( xComPortHandle xPort );
|
||||
void vSerialClose( xComPortHandle xPort );
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* ifndef SERIAL_COMMS_H */
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ FreeRTOS port, and contains its own readme file.
|
|||
See [FreeRTOS/SourceOrganization](http://www.freertos.org/a00017.html) for full details of the directory structure and information on locating the files you require.
|
||||
|
||||
The easiest way to use FreeRTOS is to start with one of the pre-configured demo
|
||||
application projects (found in the FreeRTOS/Demo directory). That way you will
|
||||
application projects (found in the FreeRTOS/Demo directory). That way you will
|
||||
have the correct FreeRTOS source files included, and the correct include paths
|
||||
configured.
|
||||
Once a demo application is building and executing you can remove
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
eFrameProcessingResult_t publicProcessIPPacket( IPPacket_t * const pxIPPacket, NetworkBufferDescriptor_t * const pxNetworkBuffer ) {
|
||||
prvProcessIPPacket(pxIPPacket, pxNetworkBuffer);
|
||||
eFrameProcessingResult_t publicProcessIPPacket( IPPacket_t * const pxIPPacket,
|
||||
NetworkBufferDescriptor_t * const pxNetworkBuffer )
|
||||
{
|
||||
prvProcessIPPacket( pxIPPacket, pxNetworkBuffer );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,20 @@
|
|||
int32_t publicTCPPrepareSend( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer, UBaseType_t uxOptionsLength ) {
|
||||
int32_t publicTCPPrepareSend( FreeRTOS_Socket_t * pxSocket,
|
||||
NetworkBufferDescriptor_t ** ppxNetworkBuffer,
|
||||
UBaseType_t uxOptionsLength )
|
||||
{
|
||||
prvTCPPrepareSend( pxSocket, ppxNetworkBuffer, uxOptionsLength );
|
||||
}
|
||||
|
||||
BaseType_t publicTCPHandleState( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer ) {
|
||||
prvTCPHandleState(pxSocket, ppxNetworkBuffer);
|
||||
BaseType_t publicTCPHandleState( FreeRTOS_Socket_t * pxSocket,
|
||||
NetworkBufferDescriptor_t ** ppxNetworkBuffer )
|
||||
{
|
||||
prvTCPHandleState( pxSocket, ppxNetworkBuffer );
|
||||
}
|
||||
|
||||
void publicTCPReturnPacket( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer,
|
||||
uint32_t ulLen, BaseType_t xReleaseAfterSend ) {
|
||||
prvTCPReturnPacket(pxSocket, pxNetworkBuffer, ulLen, xReleaseAfterSend );
|
||||
void publicTCPReturnPacket( FreeRTOS_Socket_t * pxSocket,
|
||||
NetworkBufferDescriptor_t * pxNetworkBuffer,
|
||||
uint32_t ulLen,
|
||||
BaseType_t xReleaseAfterSend )
|
||||
{
|
||||
prvTCPReturnPacket( pxSocket, pxNetworkBuffer, ulLen, xReleaseAfterSend );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,144 +3,170 @@
|
|||
#include "queue_datastructure.h"
|
||||
|
||||
#ifndef CBMC_OBJECT_BITS
|
||||
#define CBMC_OBJECT_BITS 7
|
||||
#define CBMC_OBJECT_BITS 7
|
||||
#endif
|
||||
|
||||
#ifndef CBMC_OBJECT_MAX_SIZE
|
||||
#define CBMC_OBJECT_MAX_SIZE (UINT32_MAX>>(CBMC_OBJECT_BITS+1))
|
||||
#define CBMC_OBJECT_MAX_SIZE ( UINT32_MAX >> ( CBMC_OBJECT_BITS + 1 ) )
|
||||
#endif
|
||||
|
||||
/* Using prvCopyDataToQueue together with prvNotifyQueueSetContainer
|
||||
leads to a problem space explosion. Therefore, we use this stub
|
||||
and a sepearted proof on prvCopyDataToQueue to deal with it.
|
||||
As prvNotifyQueueSetContainer is disabled if configUSE_QUEUE_SETS != 1,
|
||||
in other cases the original implementation should be used. */
|
||||
#if( configUSE_QUEUE_SETS == 1 )
|
||||
BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue, const void *pvItemToQueue, const BaseType_t xPosition )
|
||||
* leads to a problem space explosion. Therefore, we use this stub
|
||||
* and a sepearted proof on prvCopyDataToQueue to deal with it.
|
||||
* As prvNotifyQueueSetContainer is disabled if configUSE_QUEUE_SETS != 1,
|
||||
* in other cases the original implementation should be used. */
|
||||
#if ( configUSE_QUEUE_SETS == 1 )
|
||||
BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
|
||||
const void * pvItemToQueue,
|
||||
const BaseType_t xPosition )
|
||||
{
|
||||
if(pxQueue->uxItemSize > ( UBaseType_t ) 0)
|
||||
if( pxQueue->uxItemSize > ( UBaseType_t ) 0 )
|
||||
{
|
||||
__CPROVER_assert(__CPROVER_r_ok(pvItemToQueue, ( size_t ) pxQueue->uxItemSize), "pvItemToQueue region must be readable");
|
||||
if(xPosition == queueSEND_TO_BACK){
|
||||
__CPROVER_assert(__CPROVER_w_ok(( void * ) pxQueue->pcWriteTo, ( size_t ) pxQueue->uxItemSize), "pxQueue->pcWriteTo region must be writable");
|
||||
}else{
|
||||
__CPROVER_assert(__CPROVER_w_ok(( void * ) pxQueue->u.xQueue.pcReadFrom, ( size_t ) pxQueue->uxItemSize), "pxQueue->u.xQueue.pcReadFrom region must be writable");
|
||||
__CPROVER_assert( __CPROVER_r_ok( pvItemToQueue, ( size_t ) pxQueue->uxItemSize ), "pvItemToQueue region must be readable" );
|
||||
|
||||
if( xPosition == queueSEND_TO_BACK )
|
||||
{
|
||||
__CPROVER_assert( __CPROVER_w_ok( ( void * ) pxQueue->pcWriteTo, ( size_t ) pxQueue->uxItemSize ), "pxQueue->pcWriteTo region must be writable" );
|
||||
}
|
||||
else
|
||||
{
|
||||
__CPROVER_assert( __CPROVER_w_ok( ( void * ) pxQueue->u.xQueue.pcReadFrom, ( size_t ) pxQueue->uxItemSize ), "pxQueue->u.xQueue.pcReadFrom region must be writable" );
|
||||
}
|
||||
|
||||
return pdFALSE;
|
||||
}else
|
||||
}
|
||||
else
|
||||
{
|
||||
return nondet_BaseType_t();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif /* if ( configUSE_QUEUE_SETS == 1 ) */
|
||||
|
||||
/* xQueueCreateSet is compiled out if configUSE_QUEUE_SETS != 1.*/
|
||||
#if( configUSE_QUEUE_SETS == 1 )
|
||||
#if ( configUSE_QUEUE_SETS == 1 )
|
||||
QueueSetHandle_t xUnconstrainedQueueSet()
|
||||
{
|
||||
UBaseType_t uxEventQueueLength = 2;
|
||||
QueueSetHandle_t xSet = xQueueCreateSet(uxEventQueueLength);
|
||||
QueueSetHandle_t xSet = xQueueCreateSet( uxEventQueueLength );
|
||||
|
||||
if( xSet )
|
||||
{
|
||||
xSet->cTxLock = nondet_int8_t();
|
||||
__CPROVER_assume(xSet->cTxLock != 127);
|
||||
__CPROVER_assume( xSet->cTxLock != 127 );
|
||||
xSet->cRxLock = nondet_int8_t();
|
||||
xSet->uxMessagesWaiting = nondet_UBaseType_t();
|
||||
xSet->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
|
||||
|
||||
/* This is an invariant checked with a couple of asserts in the code base.
|
||||
If it is false from the beginning, the CBMC proofs are not able to succeed*/
|
||||
__CPROVER_assume(xSet->uxMessagesWaiting < xSet->uxLength);
|
||||
* If it is false from the beginning, the CBMC proofs are not able to succeed*/
|
||||
__CPROVER_assume( xSet->uxMessagesWaiting < xSet->uxLength );
|
||||
xSet->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
|
||||
}
|
||||
|
||||
return xSet;
|
||||
}
|
||||
#endif
|
||||
#endif /* if ( configUSE_QUEUE_SETS == 1 ) */
|
||||
|
||||
/* Create a mostly unconstrained Queue but bound the max item size.
|
||||
This is required for performance reasons in CBMC at the moment. */
|
||||
QueueHandle_t xUnconstrainedQueueBoundedItemSize( UBaseType_t uxItemSizeBound ) {
|
||||
* This is required for performance reasons in CBMC at the moment. */
|
||||
QueueHandle_t xUnconstrainedQueueBoundedItemSize( UBaseType_t uxItemSizeBound )
|
||||
{
|
||||
UBaseType_t uxQueueLength;
|
||||
UBaseType_t uxItemSize;
|
||||
uint8_t ucQueueType;
|
||||
__CPROVER_assume(uxQueueLength > 0);
|
||||
__CPROVER_assume(uxItemSize < uxItemSizeBound);
|
||||
|
||||
// QueueGenericCreate method does not check for multiplication overflow
|
||||
__CPROVER_assume( uxQueueLength > 0 );
|
||||
__CPROVER_assume( uxItemSize < uxItemSizeBound );
|
||||
|
||||
/* QueueGenericCreate method does not check for multiplication overflow */
|
||||
size_t uxQueueStorageSize;
|
||||
__CPROVER_assume(uxQueueStorageSize < CBMC_OBJECT_MAX_SIZE);
|
||||
__CPROVER_assume(uxItemSize < uxQueueStorageSize/uxQueueLength);
|
||||
__CPROVER_assume( uxQueueStorageSize < CBMC_OBJECT_MAX_SIZE );
|
||||
__CPROVER_assume( uxItemSize < uxQueueStorageSize / uxQueueLength );
|
||||
|
||||
QueueHandle_t xQueue =
|
||||
xQueueGenericCreate(uxQueueLength, uxItemSize, ucQueueType);
|
||||
if(xQueue){
|
||||
xQueueGenericCreate( uxQueueLength, uxItemSize, ucQueueType );
|
||||
|
||||
if( xQueue )
|
||||
{
|
||||
xQueue->cTxLock = nondet_int8_t();
|
||||
__CPROVER_assume(xQueue->cTxLock != 127);
|
||||
__CPROVER_assume( xQueue->cTxLock != 127 );
|
||||
xQueue->cRxLock = nondet_int8_t();
|
||||
__CPROVER_assume(xQueue->cRxLock != 127);
|
||||
__CPROVER_assume( xQueue->cRxLock != 127 );
|
||||
xQueue->uxMessagesWaiting = nondet_UBaseType_t();
|
||||
|
||||
/* This is an invariant checked with a couple of asserts in the code base.
|
||||
If it is false from the beginning, the CBMC proofs are not able to succeed*/
|
||||
__CPROVER_assume(xQueue->uxMessagesWaiting < xQueue->uxLength);
|
||||
* If it is false from the beginning, the CBMC proofs are not able to succeed*/
|
||||
__CPROVER_assume( xQueue->uxMessagesWaiting < xQueue->uxLength );
|
||||
xQueue->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
|
||||
xQueue->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
|
||||
#if( configUSE_QUEUE_SETS == 1)
|
||||
xQueueAddToSet(xQueue, xUnconstrainedQueueSet());
|
||||
#if ( configUSE_QUEUE_SETS == 1 )
|
||||
xQueueAddToSet( xQueue, xUnconstrainedQueueSet() );
|
||||
#endif
|
||||
}
|
||||
|
||||
return xQueue;
|
||||
}
|
||||
|
||||
/* Create a mostly unconstrained Queue */
|
||||
QueueHandle_t xUnconstrainedQueue( void ) {
|
||||
QueueHandle_t xUnconstrainedQueue( void )
|
||||
{
|
||||
UBaseType_t uxQueueLength;
|
||||
UBaseType_t uxItemSize;
|
||||
uint8_t ucQueueType;
|
||||
|
||||
__CPROVER_assume(uxQueueLength > 0);
|
||||
__CPROVER_assume( uxQueueLength > 0 );
|
||||
|
||||
// QueueGenericCreate method does not check for multiplication overflow
|
||||
/* QueueGenericCreate method does not check for multiplication overflow */
|
||||
size_t uxQueueStorageSize;
|
||||
__CPROVER_assume(uxQueueStorageSize < CBMC_OBJECT_MAX_SIZE);
|
||||
__CPROVER_assume(uxItemSize < uxQueueStorageSize/uxQueueLength);
|
||||
__CPROVER_assume( uxQueueStorageSize < CBMC_OBJECT_MAX_SIZE );
|
||||
__CPROVER_assume( uxItemSize < uxQueueStorageSize / uxQueueLength );
|
||||
|
||||
QueueHandle_t xQueue =
|
||||
xQueueGenericCreate(uxQueueLength, uxItemSize, ucQueueType);
|
||||
xQueueGenericCreate( uxQueueLength, uxItemSize, ucQueueType );
|
||||
|
||||
if(xQueue){
|
||||
if( xQueue )
|
||||
{
|
||||
xQueue->cTxLock = nondet_int8_t();
|
||||
__CPROVER_assume(xQueue->cTxLock != 127);
|
||||
__CPROVER_assume( xQueue->cTxLock != 127 );
|
||||
xQueue->cRxLock = nondet_int8_t();
|
||||
xQueue->uxMessagesWaiting = nondet_UBaseType_t();
|
||||
|
||||
/* This is an invariant checked with a couple of asserts in the code base.
|
||||
If it is false from the beginning, the CBMC proofs are not able to succeed*/
|
||||
__CPROVER_assume(xQueue->uxMessagesWaiting < xQueue->uxLength);
|
||||
* If it is false from the beginning, the CBMC proofs are not able to succeed*/
|
||||
__CPROVER_assume( xQueue->uxMessagesWaiting < xQueue->uxLength );
|
||||
xQueue->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
|
||||
xQueue->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
|
||||
#if( configUSE_QUEUE_SETS == 1)
|
||||
xQueueAddToSet(xQueue, xUnconstrainedQueueSet());
|
||||
#if ( configUSE_QUEUE_SETS == 1 )
|
||||
xQueueAddToSet( xQueue, xUnconstrainedQueueSet() );
|
||||
#endif
|
||||
}
|
||||
|
||||
return xQueue;
|
||||
}
|
||||
|
||||
/* Create a mostly unconstrained Mutex */
|
||||
QueueHandle_t xUnconstrainedMutex( void ) {
|
||||
QueueHandle_t xUnconstrainedMutex( void )
|
||||
{
|
||||
uint8_t ucQueueType;
|
||||
QueueHandle_t xQueue =
|
||||
xQueueCreateMutex(ucQueueType);
|
||||
if(xQueue){
|
||||
xQueueCreateMutex( ucQueueType );
|
||||
|
||||
if( xQueue )
|
||||
{
|
||||
xQueue->cTxLock = nondet_int8_t();
|
||||
__CPROVER_assume(xQueue->cTxLock != 127);
|
||||
__CPROVER_assume( xQueue->cTxLock != 127 );
|
||||
xQueue->cRxLock = nondet_int8_t();
|
||||
xQueue->uxMessagesWaiting = nondet_UBaseType_t();
|
||||
|
||||
/* This is an invariant checked with a couple of asserts in the code base.
|
||||
If it is false from the beginning, the CBMC proofs are not able to succeed*/
|
||||
__CPROVER_assume(xQueue->uxMessagesWaiting < xQueue->uxLength);
|
||||
* If it is false from the beginning, the CBMC proofs are not able to succeed*/
|
||||
__CPROVER_assume( xQueue->uxMessagesWaiting < xQueue->uxLength );
|
||||
xQueue->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
|
||||
xQueue->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
|
||||
#if( configUSE_QUEUE_SETS == 1)
|
||||
xQueueAddToSet(xQueue, xUnconstrainedQueueSet());
|
||||
#if ( configUSE_QUEUE_SETS == 1 )
|
||||
xQueueAddToSet( xQueue, xUnconstrainedQueueSet() );
|
||||
#endif
|
||||
}
|
||||
|
||||
return xQueue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "task.h"
|
||||
|
||||
BaseType_t xState;
|
||||
void vInitTaskCheckForTimeOut(BaseType_t maxCounter, BaseType_t maxCounter_limit);
|
||||
void vInitTaskCheckForTimeOut( BaseType_t maxCounter,
|
||||
BaseType_t maxCounter_limit );
|
||||
|
||||
#endif /* INC_TASK_STUBS_H */
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@
|
|||
extern void vAssertCalled( const char * pcFile,
|
||||
uint32_t ulLine );
|
||||
#ifndef configASSERT
|
||||
#define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled( __FILE__, __LINE__ )
|
||||
#define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled( __FILE__, __LINE__ )
|
||||
#endif
|
||||
|
||||
/* Remove logging in formal verification */
|
||||
|
|
|
|||
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
FreeRTOS V202104.00
|
||||
Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
http://aws.amazon.com/freertos
|
||||
http://www.FreeRTOS.org
|
||||
*/
|
||||
* FreeRTOS V202104.00
|
||||
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://aws.amazon.com/freertos
|
||||
* http://www.FreeRTOS.org
|
||||
*/
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@
|
|||
#endif
|
||||
|
||||
/* 5 is a magic number, but we need some number here as a default value.
|
||||
This value is used to bound any loop depending on xTaskCheckForTimeOut
|
||||
as a loop bound. It should be overwritten in the Makefile.json adapting
|
||||
to the performance requirements of the harness. */
|
||||
* This value is used to bound any loop depending on xTaskCheckForTimeOut
|
||||
* as a loop bound. It should be overwritten in the Makefile.json adapting
|
||||
* to the performance requirements of the harness. */
|
||||
#ifndef TASK_STUB_COUNTER_LIMIT
|
||||
#define TASK_STUB_COUNTER_LIMIT 5;
|
||||
#endif
|
||||
|
|
@ -24,19 +24,23 @@ BaseType_t xTaskGetSchedulerState( void )
|
|||
}
|
||||
|
||||
/* This function is another method apart from overwritting the defines to init the max
|
||||
loop bound. */
|
||||
void vInitTaskCheckForTimeOut(BaseType_t maxCounter, BaseType_t maxCounter_limit)
|
||||
* loop bound. */
|
||||
void vInitTaskCheckForTimeOut( BaseType_t maxCounter,
|
||||
BaseType_t maxCounter_limit )
|
||||
{
|
||||
xCounter = maxCounter;
|
||||
xCounterLimit = maxCounter_limit;
|
||||
}
|
||||
|
||||
/* This is mostly called in a loop. For CBMC, we have to bound the loop
|
||||
to a max limits of calls. Therefore this Stub models a nondet timeout in
|
||||
max TASK_STUB_COUNTER_LIMIT iterations.*/
|
||||
BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait ) {
|
||||
* to a max limits of calls. Therefore this Stub models a nondet timeout in
|
||||
* max TASK_STUB_COUNTER_LIMIT iterations.*/
|
||||
BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut,
|
||||
TickType_t * const pxTicksToWait )
|
||||
{
|
||||
++xCounter;
|
||||
if(xCounter == xCounterLimit)
|
||||
|
||||
if( xCounter == xCounterLimit )
|
||||
{
|
||||
return pdTRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,8 +31,9 @@
|
|||
|
||||
#include "cbmc.h"
|
||||
|
||||
void harness() {
|
||||
void harness()
|
||||
{
|
||||
uint8_t ucQueueType;
|
||||
|
||||
xQueueCreateMutex(ucQueueType);
|
||||
xQueueCreateMutex( ucQueueType );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,36 +41,48 @@
|
|||
#define QUEUE_SEND_BOUND 4
|
||||
#endif
|
||||
|
||||
#if( configUSE_QUEUE_SETS == 0 )
|
||||
BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue, const void *pvItemToQueue, const BaseType_t xPosition )
|
||||
{
|
||||
if(pxQueue->uxItemSize > ( UBaseType_t ) 0)
|
||||
#if ( configUSE_QUEUE_SETS == 0 )
|
||||
BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
|
||||
const void * pvItemToQueue,
|
||||
const BaseType_t xPosition )
|
||||
{
|
||||
__CPROVER_assert(__CPROVER_r_ok(pvItemToQueue, ( size_t ) pxQueue->uxItemSize), "pvItemToQueue region must be readable");
|
||||
if(xPosition == queueSEND_TO_BACK){
|
||||
__CPROVER_assert(__CPROVER_w_ok(( void * ) pxQueue->pcWriteTo, ( size_t ) pxQueue->uxItemSize), "pxQueue->pcWriteTo region must be writable");
|
||||
}else{
|
||||
__CPROVER_assert(__CPROVER_w_ok(( void * ) pxQueue->u.xQueue.pcReadFrom, ( size_t ) pxQueue->uxItemSize), "pxQueue->u.xQueue.pcReadFrom region must be writable");
|
||||
if( pxQueue->uxItemSize > ( UBaseType_t ) 0 )
|
||||
{
|
||||
__CPROVER_assert( __CPROVER_r_ok( pvItemToQueue, ( size_t ) pxQueue->uxItemSize ), "pvItemToQueue region must be readable" );
|
||||
|
||||
if( xPosition == queueSEND_TO_BACK )
|
||||
{
|
||||
__CPROVER_assert( __CPROVER_w_ok( ( void * ) pxQueue->pcWriteTo, ( size_t ) pxQueue->uxItemSize ), "pxQueue->pcWriteTo region must be writable" );
|
||||
}
|
||||
else
|
||||
{
|
||||
__CPROVER_assert( __CPROVER_w_ok( ( void * ) pxQueue->u.xQueue.pcReadFrom, ( size_t ) pxQueue->uxItemSize ), "pxQueue->u.xQueue.pcReadFrom region must be writable" );
|
||||
}
|
||||
|
||||
return pdFALSE;
|
||||
}else
|
||||
}
|
||||
else
|
||||
{
|
||||
return nondet_BaseType_t();
|
||||
}
|
||||
}
|
||||
#else
|
||||
}
|
||||
#else /* if ( configUSE_QUEUE_SETS == 0 ) */
|
||||
BaseType_t prvNotifyQueueSetContainer( const Queue_t * const pxQueue )
|
||||
{
|
||||
Queue_t *pxQueueSetContainer = pxQueue->pxQueueSetContainer;
|
||||
Queue_t * pxQueueSetContainer = pxQueue->pxQueueSetContainer;
|
||||
|
||||
configASSERT( pxQueueSetContainer );
|
||||
}
|
||||
|
||||
void prvUnlockQueue( Queue_t * const pxQueue ) {
|
||||
void prvUnlockQueue( Queue_t * const pxQueue )
|
||||
{
|
||||
configASSERT( pxQueue );
|
||||
|
||||
if( pxQueue->pxQueueSetContainer != NULL )
|
||||
{
|
||||
prvNotifyQueueSetContainer(pxQueue);
|
||||
prvNotifyQueueSetContainer( pxQueue );
|
||||
}
|
||||
|
||||
listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) );
|
||||
pxQueue->cTxLock = queueUNLOCKED;
|
||||
|
||||
|
|
@ -78,50 +90,56 @@ BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue, const void *pvItemToQueu
|
|||
pxQueue->cRxLock = queueUNLOCKED;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /* if ( configUSE_QUEUE_SETS == 0 ) */
|
||||
|
||||
void harness(){
|
||||
//Initialise the tasksStubs
|
||||
vInitTaskCheckForTimeOut(0, QUEUE_SEND_BOUND - 1);
|
||||
void harness()
|
||||
{
|
||||
/*Initialise the tasksStubs */
|
||||
vInitTaskCheckForTimeOut( 0, QUEUE_SEND_BOUND - 1 );
|
||||
xState = nondet_basetype();
|
||||
QueueHandle_t xQueue =
|
||||
xUnconstrainedQueueBoundedItemSize(2);
|
||||
xUnconstrainedQueueBoundedItemSize( 2 );
|
||||
|
||||
TickType_t xTicksToWait;
|
||||
if(xState == taskSCHEDULER_SUSPENDED){
|
||||
|
||||
if( xState == taskSCHEDULER_SUSPENDED )
|
||||
{
|
||||
xTicksToWait = 0;
|
||||
}
|
||||
|
||||
if(xQueue){
|
||||
void *pvItemToQueue = pvPortMalloc(xQueue->uxItemSize);
|
||||
if( xQueue )
|
||||
{
|
||||
void * pvItemToQueue = pvPortMalloc( xQueue->uxItemSize );
|
||||
BaseType_t xCopyPosition;
|
||||
|
||||
if(xCopyPosition == queueOVERWRITE){
|
||||
if( xCopyPosition == queueOVERWRITE )
|
||||
{
|
||||
xQueue->uxLength = 1;
|
||||
}
|
||||
|
||||
if(xQueue->uxItemSize == 0)
|
||||
if( xQueue->uxItemSize == 0 )
|
||||
{
|
||||
/* uxQueue->xQueueType is a pointer to the head of the queue storage area.
|
||||
If an item has a sice, this pointer must not be modified after init.
|
||||
Otherwise some of the write statements will fail. */
|
||||
* If an item has a sice, this pointer must not be modified after init.
|
||||
* Otherwise some of the write statements will fail. */
|
||||
xQueue->uxQueueType = nondet_int8_t();
|
||||
pvItemToQueue = 0;
|
||||
}
|
||||
|
||||
/* This code checks explicitly for violations of the pxQueue->uxMessagesWaiting < pxQueue->uxLength
|
||||
invariant. */
|
||||
* invariant. */
|
||||
xQueue->uxMessagesWaiting = nondet_UBaseType_t();
|
||||
|
||||
/* These values are decremented during a while loop interacting with task.c.
|
||||
This interaction is currently abstracted away.*/
|
||||
* This interaction is currently abstracted away.*/
|
||||
xQueue->cTxLock = LOCK_BOUND - 1;
|
||||
xQueue->cRxLock = LOCK_BOUND - 1;
|
||||
|
||||
if(!pvItemToQueue){
|
||||
if( !pvItemToQueue )
|
||||
{
|
||||
xQueue->uxItemSize = 0;
|
||||
}
|
||||
|
||||
xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, xCopyPosition );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,50 +36,67 @@
|
|||
#define ITEM_BOUND 10
|
||||
#endif
|
||||
|
||||
#if( configUSE_QUEUE_SETS == 0 )
|
||||
BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue, const void *pvItemToQueue, const BaseType_t xPosition )
|
||||
#if ( configUSE_QUEUE_SETS == 0 )
|
||||
BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
|
||||
const void * pvItemToQueue,
|
||||
const BaseType_t xPosition )
|
||||
{
|
||||
if(pxQueue->uxItemSize > ( UBaseType_t ) 0)
|
||||
if( pxQueue->uxItemSize > ( UBaseType_t ) 0 )
|
||||
{
|
||||
__CPROVER_assert(__CPROVER_r_ok(pvItemToQueue, ( size_t ) pxQueue->uxItemSize), "pvItemToQueue region must be readable");
|
||||
if(xPosition == queueSEND_TO_BACK){
|
||||
__CPROVER_assert(__CPROVER_w_ok(( void * ) pxQueue->pcWriteTo, ( size_t ) pxQueue->uxItemSize), "pxQueue->pcWriteTo region must be writable");
|
||||
}else{
|
||||
__CPROVER_assert(__CPROVER_w_ok(( void * ) pxQueue->u.xQueue.pcReadFrom, ( size_t ) pxQueue->uxItemSize), "pxQueue->u.xQueue.pcReadFrom region must be writable");
|
||||
__CPROVER_assert( __CPROVER_r_ok( pvItemToQueue, ( size_t ) pxQueue->uxItemSize ), "pvItemToQueue region must be readable" );
|
||||
|
||||
if( xPosition == queueSEND_TO_BACK )
|
||||
{
|
||||
__CPROVER_assert( __CPROVER_w_ok( ( void * ) pxQueue->pcWriteTo, ( size_t ) pxQueue->uxItemSize ), "pxQueue->pcWriteTo region must be writable" );
|
||||
}
|
||||
else
|
||||
{
|
||||
__CPROVER_assert( __CPROVER_w_ok( ( void * ) pxQueue->u.xQueue.pcReadFrom, ( size_t ) pxQueue->uxItemSize ), "pxQueue->u.xQueue.pcReadFrom region must be writable" );
|
||||
}
|
||||
|
||||
return pdFALSE;
|
||||
}else
|
||||
}
|
||||
else
|
||||
{
|
||||
return nondet_BaseType_t();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif /* if ( configUSE_QUEUE_SETS == 0 ) */
|
||||
|
||||
void harness(){
|
||||
QueueHandle_t xQueue = xUnconstrainedQueueBoundedItemSize(ITEM_BOUND);
|
||||
void harness()
|
||||
{
|
||||
QueueHandle_t xQueue = xUnconstrainedQueueBoundedItemSize( ITEM_BOUND );
|
||||
|
||||
|
||||
if( xQueue ){
|
||||
void *pvItemToQueue = pvPortMalloc(xQueue->uxItemSize);
|
||||
BaseType_t *xHigherPriorityTaskWoken = pvPortMalloc(sizeof(BaseType_t));
|
||||
if( xQueue )
|
||||
{
|
||||
void * pvItemToQueue = pvPortMalloc( xQueue->uxItemSize );
|
||||
BaseType_t * xHigherPriorityTaskWoken = pvPortMalloc( sizeof( BaseType_t ) );
|
||||
BaseType_t xCopyPosition;
|
||||
if(xQueue->uxItemSize == 0)
|
||||
|
||||
if( xQueue->uxItemSize == 0 )
|
||||
{
|
||||
/* uxQueue->xQueueType is a pointer to the head of the queue storage area.
|
||||
If an item has a size, this pointer must not be modified after init.
|
||||
Otherwise some of the write statements will fail. */
|
||||
* If an item has a size, this pointer must not be modified after init.
|
||||
* Otherwise some of the write statements will fail. */
|
||||
xQueue->uxQueueType = nondet_int8_t();
|
||||
pvItemToQueue = 0;
|
||||
}
|
||||
|
||||
/* This code checks explicitly for violations of the pxQueue->uxMessagesWaiting < pxQueue->uxLength
|
||||
invariant. */
|
||||
* invariant. */
|
||||
xQueue->uxMessagesWaiting = nondet_UBaseType_t();
|
||||
if(!pvItemToQueue){
|
||||
|
||||
if( !pvItemToQueue )
|
||||
{
|
||||
xQueue->uxItemSize = 0;
|
||||
}
|
||||
if(xCopyPosition == 2 ){
|
||||
__CPROVER_assume(xQueue->uxLength == 1);
|
||||
|
||||
if( xCopyPosition == 2 )
|
||||
{
|
||||
__CPROVER_assume( xQueue->uxLength == 1 );
|
||||
}
|
||||
|
||||
xQueueGenericSendFromISR( xQueue, pvItemToQueue, xHigherPriorityTaskWoken, xCopyPosition );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,10 +32,13 @@
|
|||
|
||||
#include "cbmc.h"
|
||||
|
||||
void harness() {
|
||||
void harness()
|
||||
{
|
||||
QueueHandle_t xSemaphore = xUnconstrainedQueue();
|
||||
if (xSemaphore) {
|
||||
|
||||
if( xSemaphore )
|
||||
{
|
||||
xSemaphore->uxQueueType = nondet_uint8_t();
|
||||
xQueueGetMutexHolder(xSemaphore);
|
||||
xQueueGetMutexHolder( xSemaphore );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,10 +32,12 @@
|
|||
|
||||
#include "cbmc.h"
|
||||
|
||||
void harness(){
|
||||
QueueHandle_t xSemaphore = pvPortMalloc(sizeof(Queue_t));
|
||||
if (xSemaphore) {
|
||||
void harness()
|
||||
{
|
||||
QueueHandle_t xSemaphore = pvPortMalloc( sizeof( Queue_t ) );
|
||||
|
||||
if( xSemaphore )
|
||||
{
|
||||
xQueueGetMutexHolderFromISR( xSemaphore );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue