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:
alfred gedeon 2021-07-22 14:23:48 -07:00 committed by GitHub
parent dd80d615b5
commit ae92d8c6ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
191 changed files with 17540 additions and 17102 deletions

View file

@ -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:

View file

@ -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;
}

View file

@ -32,7 +32,7 @@
/**
* @brief Size of the shared memory region.
*/
#define SHARED_MEMORY_SIZE 32
#define SHARED_MEMORY_SIZE 32
/**
* @brief Memory region shared between two tasks.
@ -74,153 +74,155 @@ static void prvRWAccessTask( void * pvParameters );
static void prvROAccessTask( void * pvParameters )
{
uint8_t ucVal;
uint8_t ucVal;
/* Unused parameters. */
( void ) pvParameters;
/* Unused parameters. */
( void ) pvParameters;
for( ; ; )
{
/* This task has RO access to ucSharedMemory and therefore it can read
* it but cannot modify it. */
ucVal = ucSharedMemory[ 0 ];
for( ; ; )
{
/* This task has RO access to ucSharedMemory and therefore it can read
* it but cannot modify it. */
ucVal = ucSharedMemory[ 0 ];
/* Silent compiler warnings about unused variables. */
( void ) ucVal;
/* Silent compiler warnings about unused variables. */
( void ) ucVal;
/* Since this task has Read Only access to the ucSharedMemory region,
* writing to it results in Memory Fault. Set ucROTaskFaultTracker[ 0 ]
* to 1 to tell the Memory Fault Handler that this is an expected fault.
* The handler will recover from this fault gracefully by jumping to the
* next instruction. */
ucROTaskFaultTracker[ 0 ] = 1;
/* Since this task has Read Only access to the ucSharedMemory region,
* writing to it results in Memory Fault. Set ucROTaskFaultTracker[ 0 ]
* to 1 to tell the Memory Fault Handler that this is an expected fault.
* The handler will recover from this fault gracefully by jumping to the
* next instruction. */
ucROTaskFaultTracker[ 0 ] = 1;
/* Illegal access to generate Memory Fault. */
ucSharedMemory[ 0 ] = 0;
/* Illegal access to generate Memory Fault. */
ucSharedMemory[ 0 ] = 0;
/* Wait for a second. */
vTaskDelay( pdMS_TO_TICKS( 1000 ) );
}
/* Wait for a second. */
vTaskDelay( pdMS_TO_TICKS( 1000 ) );
}
}
/*-----------------------------------------------------------*/
static void prvRWAccessTask( void * pvParameters )
{
/* Unused parameters. */
( void ) pvParameters;
/* Unused parameters. */
( void ) pvParameters;
for( ; ; )
{
/* This task has RW access to ucSharedMemory and therefore can write to
* it. */
ucSharedMemory[ 0 ] = 0;
for( ; ; )
{
/* This task has RW access to ucSharedMemory and therefore can write to
* it. */
ucSharedMemory[ 0 ] = 0;
/* Wait for a second. */
vTaskDelay( pdMS_TO_TICKS( 1000 ) );
}
/* Wait for a second. */
vTaskDelay( pdMS_TO_TICKS( 1000 ) );
}
}
/*-----------------------------------------------------------*/
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 =
{
.pvTaskCode = prvROAccessTask,
.pcName = "ROAccess",
.usStackDepth = configMINIMAL_STACK_SIZE,
.pvParameters = NULL,
.uxPriority = tskIDLE_PRIORITY,
.puxStackBuffer = xROAccessTaskStack,
.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 =
{
.pvTaskCode = prvRWAccessTask,
.pcName = "RWAccess",
.usStackDepth = configMINIMAL_STACK_SIZE,
.pvParameters = NULL,
.uxPriority = tskIDLE_PRIORITY,
.puxStackBuffer = xRWAccessTaskStack,
.xRegions = {
{ ucSharedMemory, 32, tskMPU_REGION_READ_WRITE | tskMPU_REGION_EXECUTE_NEVER },
{ 0, 0, 0 },
{ 0, 0, 0 },
}
};
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 =
{
{ 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 =
{
.pvTaskCode = prvRWAccessTask,
.pcName = "RWAccess",
.usStackDepth = configMINIMAL_STACK_SIZE,
.pvParameters = NULL,
.uxPriority = tskIDLE_PRIORITY,
.puxStackBuffer = xRWAccessTaskStack,
.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 );
/* Create an unprivileged task with RO access to ucSharedMemory. */
xTaskCreateRestricted( &( xROAccessTaskParameters ), NULL );
/* Create an unprivileged task with RW access to ucSharedMemory. */
xTaskCreateRestricted( &( xRWAccessTaskParameters ), NULL );
/* Create an unprivileged task with RW access to ucSharedMemory. */
xTaskCreateRestricted( &( xRWAccessTaskParameters ), NULL );
}
/*-----------------------------------------------------------*/
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 )
{
/* Read program counter. */
ulPC = pulFaultStackAddress[ 6 ];
/* Is this an expected fault? */
if( ucROTaskFaultTracker[ 0 ] == 1 )
{
/* Read program counter. */
ulPC = pulFaultStackAddress[ 6 ];
/* Read the offending instruction. */
usOffendingInstruction = *( uint16_t * )ulPC;
/* Read the offending instruction. */
usOffendingInstruction = *( uint16_t * ) ulPC;
/* From ARM docs:
* If the value of bits[15:11] of the halfword being decoded is one of
* the following, the halfword is the first halfword of a 32-bit
* instruction:
* - 0b11101.
* - 0b11110.
* - 0b11111.
* Otherwise, the halfword is a 16-bit instruction.
*/
/* From ARM docs:
* If the value of bits[15:11] of the halfword being decoded is one of
* the following, the halfword is the first halfword of a 32-bit
* instruction:
* - 0b11101.
* - 0b11110.
* - 0b11111.
* Otherwise, the halfword is a 16-bit instruction.
*/
/* Extract bits[15:11] of the offending instruction. */
usOffendingInstruction = usOffendingInstruction & 0xF800;
usOffendingInstruction = ( usOffendingInstruction >> 11 );
/* Extract bits[15:11] of the offending instruction. */
usOffendingInstruction = usOffendingInstruction & 0xF800;
usOffendingInstruction = ( usOffendingInstruction >> 11 );
/* Determine if the offending instruction is a 32-bit instruction or
* a 16-bit instruction. */
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
* instruction. */
ulPC += 4;
}
else
{
/* Since the offending instruction is a 16-bit instruction,
* increment the program counter by 2 to move to the next
* instruction. */
ulPC += 2;
}
/* Determine if the offending instruction is a 32-bit instruction or
* a 16-bit instruction. */
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
* instruction. */
ulPC += 4;
}
else
{
/* Since the offending instruction is a 16-bit instruction,
* increment the program counter by 2 to move to the next
* instruction. */
ulPC += 2;
}
/* Save the new program counter on the stack. */
pulFaultStackAddress[ 6 ] = ulPC;
/* Save the new program counter on the stack. */
pulFaultStackAddress[ 6 ] = ulPC;
/* Mark the fault as handled. */
ucROTaskFaultTracker[ 0 ] = 0;
}
else
{
/* This is an unexpected fault - loop forever. */
for( ; ; )
{
}
}
/* Mark the fault as handled. */
ucROTaskFaultTracker[ 0 ] = 0;
}
else
{
/* This is an unexpected fault - loop forever. */
for( ; ; )
{
}
}
}
/*-----------------------------------------------------------*/

View file

@ -37,23 +37,23 @@ 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 );
/* Return function pointer with cleared LSB. */
pxNonSecureCallback = ( NonSecureCallback_t ) cmse_nsfptr_create( pxCallback );
/* Invoke the supplied callback. */
pxNonSecureCallback();
/* Invoke the supplied callback. */
pxNonSecureCallback();
/* Increment the secure side counter. */
ulSecureCounter += 1;
/* Increment the secure side counter. */
ulSecureCounter += 1;
/* Return the secure side counter. */
return ulSecureCounter;
/* Return the secure side counter. */
return ulSecureCounter;
}
/*-----------------------------------------------------------*/

View file

@ -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.

View file

@ -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,66 +68,67 @@ static void prvSecureCallingTask( void * pvParameters );
void vStartTZDemo( void )
{
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 = {
{ ulNonSecureCounter, 32, tskMPU_REGION_READ_WRITE | tskMPU_REGION_EXECUTE_NEVER },
{ 0, 0, 0 },
{ 0, 0, 0 },
}
};
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 =
{
{ 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 );
/* Create an unprivileged task which calls secure functions. */
xTaskCreateRestricted( &( xSecureCallingTaskParameters ), NULL );
}
/*-----------------------------------------------------------*/
static void prvCallback( void )
{
/* This function is called from the secure side. Just increment the counter
* here. The check that this counter keeps incrementing is performed in the
* prvSecureCallingTask. */
ulNonSecureCounter[ 0 ] += 1;
/* This function is called from the secure side. Just increment the counter
* here. The check that this counter keeps incrementing is performed in the
* prvSecureCallingTask. */
ulNonSecureCounter[ 0 ] += 1;
}
/*-----------------------------------------------------------*/
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. */
portALLOCATE_SECURE_CONTEXT( configMINIMAL_SECURE_STACK_SIZE );
/* This task calls secure side functions. So allocate a secure context for
* it. */
portALLOCATE_SECURE_CONTEXT( configMINIMAL_SECURE_STACK_SIZE );
for( ; ; )
{
/* Call the secure side function. It does two things:
* - It calls the supplied function (prvCallback) which in turn
* increments the non-secure counter.
* - It increments the secure counter and returns the incremented value.
* Therefore at the end of this function call both the secure and
* non-secure counters must have been incremented.
*/
ulCurrentSecureCounter = NSCFunction( prvCallback );
for( ; ; )
{
/* Call the secure side function. It does two things:
* - It calls the supplied function (prvCallback) which in turn
* increments the non-secure counter.
* - It increments the secure counter and returns the incremented value.
* Therefore at the end of this function call both the secure and
* non-secure counters must have been incremented.
*/
ulCurrentSecureCounter = NSCFunction( prvCallback );
/* Make sure that both the counters are incremented. */
configASSERT( ulCurrentSecureCounter == ulLastSecureCounter + 1 );
configASSERT( ulNonSecureCounter[ 0 ] == ulLastNonSecureCounter + 1 );
/* Make sure that both the counters are incremented. */
configASSERT( ulCurrentSecureCounter == ulLastSecureCounter + 1 );
configASSERT( ulNonSecureCounter[ 0 ] == ulLastNonSecureCounter + 1 );
/* Update the last values for both the counters. */
ulLastSecureCounter = ulCurrentSecureCounter;
ulLastNonSecureCounter = ulNonSecureCounter[ 0 ];
/* Update the last values for both the counters. */
ulLastSecureCounter = ulCurrentSecureCounter;
ulLastNonSecureCounter = ulNonSecureCounter[ 0 ];
/* Wait for a second. */
vTaskDelay( pdMS_TO_TICKS( 1000 ) );
}
/* Wait for a second. */
vTaskDelay( pdMS_TO_TICKS( 1000 ) );
}
}
/*-----------------------------------------------------------*/

View file

@ -53,21 +53,21 @@
*/
/*
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
+ Delay periods are now specified using variables and constants of
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.
*/
* 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
+
+ Delay periods are now specified using variables and constants of
+ 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.
*/
#include <stdlib.h>
@ -81,228 +81,228 @@ Changes from V4.0.2
#include "BlockQ.h"
#include "print.h"
#define blckqSTACK_SIZE ( ( unsigned short ) configMINIMAL_STACK_SIZE )
#define blckqNUM_TASK_SETS ( 3 )
#define blckqSTACK_SIZE ( ( unsigned short ) configMINIMAL_STACK_SIZE )
#define blckqNUM_TASK_SETS ( 3 )
/* Structure used to pass parameters to the blocking queue tasks. */
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. */
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. */
} 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. */
/* Create the first two tasks as described at the top of the file. */
/* First create the structure used to pass parameters to the consumer tasks. */
pxQueueParameters1 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
/* First create the structure used to pass parameters to the consumer tasks. */
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. */
pxQueueParameters1->xQueue = xQueueCreate( uxQueueSize1, ( unsigned portBASE_TYPE ) sizeof( unsigned short ) );
/* Create the queue used by the first two tasks to pass the incrementing number.
* 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;
/* 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. */
pxQueueParameters1->psCheckVariable = &( sBlockingConsumerCount[ 0 ] );
/* Pass in the variable that this task is going to increment so we can check it
* is still running. */
pxQueueParameters1->psCheckVariable = &( sBlockingConsumerCount[ 0 ] );
/* Create the structure used to pass parameters to the producer task. */
pxQueueParameters2 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
/* Create the structure used to pass parameters to the producer task. */
pxQueueParameters2 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
/* Pass the queue to this task also, using the parameter structure. */
pxQueueParameters2->xQueue = pxQueueParameters1->xQueue;
/* Pass the queue to this task also, using the parameter structure. */
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. */
pxQueueParameters2->xBlockTime = xDontBlock;
/* 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. */
pxQueueParameters2->xBlockTime = xDontBlock;
/* Pass in the variable that this task is going to increment so we can check
it is still running. */
pxQueueParameters2->psCheckVariable = &( sBlockingProducerCount[ 0 ] );
/* Pass in the variable that this task is going to increment so we can check
* it is still running. */
pxQueueParameters2->psCheckVariable = &( sBlockingProducerCount[ 0 ] );
/* Note the producer has a lower priority than the consumer when the tasks are
spawned. */
xTaskCreate( vBlockingQueueConsumer, "QConsB1", blckqSTACK_SIZE, ( void * ) pxQueueParameters1, uxPriority, NULL );
xTaskCreate( vBlockingQueueProducer, "QProdB2", blckqSTACK_SIZE, ( void * ) pxQueueParameters2, tskIDLE_PRIORITY, NULL );
/* Note the producer has a lower priority than the consumer when the tasks are
* 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. */
/* Create the second two tasks as described at the top of the file. This uses
* the same mechanism but reverses the task priorities. */
pxQueueParameters3 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
pxQueueParameters3->xQueue = xQueueCreate( uxQueueSize1, ( unsigned portBASE_TYPE ) sizeof( unsigned short ) );
pxQueueParameters3->xBlockTime = xDontBlock;
pxQueueParameters3->psCheckVariable = &( sBlockingProducerCount[ 1 ] );
pxQueueParameters3 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
pxQueueParameters3->xQueue = xQueueCreate( uxQueueSize1, ( unsigned portBASE_TYPE ) sizeof( unsigned short ) );
pxQueueParameters3->xBlockTime = xDontBlock;
pxQueueParameters3->psCheckVariable = &( sBlockingProducerCount[ 1 ] );
pxQueueParameters4 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
pxQueueParameters4->xQueue = pxQueueParameters3->xQueue;
pxQueueParameters4->xBlockTime = xBlockTime;
pxQueueParameters4->psCheckVariable = &( sBlockingConsumerCount[ 1 ] );
pxQueueParameters4 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
pxQueueParameters4->xQueue = pxQueueParameters3->xQueue;
pxQueueParameters4->xBlockTime = xBlockTime;
pxQueueParameters4->psCheckVariable = &( sBlockingConsumerCount[ 1 ] );
xTaskCreate( vBlockingQueueProducer, "QProdB3", blckqSTACK_SIZE, ( void * ) pxQueueParameters3, tskIDLE_PRIORITY, NULL );
xTaskCreate( vBlockingQueueConsumer, "QConsB4", blckqSTACK_SIZE, ( void * ) pxQueueParameters4, uxPriority, NULL );
xTaskCreate( vBlockingQueueProducer, "QProdB3", blckqSTACK_SIZE, ( void * ) pxQueueParameters3, tskIDLE_PRIORITY, NULL );
xTaskCreate( vBlockingQueueConsumer, "QConsB4", blckqSTACK_SIZE, ( void * ) pxQueueParameters4, uxPriority, NULL );
/* 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. */
pxQueueParameters5 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
pxQueueParameters5->xQueue = xQueueCreate( uxQueueSize5, ( unsigned portBASE_TYPE ) sizeof( unsigned short ) );
pxQueueParameters5->xBlockTime = xBlockTime;
pxQueueParameters5->psCheckVariable = &( sBlockingProducerCount[ 2 ] );
/* 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. */
pxQueueParameters5 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
pxQueueParameters5->xQueue = xQueueCreate( uxQueueSize5, ( unsigned portBASE_TYPE ) sizeof( unsigned short ) );
pxQueueParameters5->xBlockTime = xBlockTime;
pxQueueParameters5->psCheckVariable = &( sBlockingProducerCount[ 2 ] );
pxQueueParameters6 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
pxQueueParameters6->xQueue = pxQueueParameters5->xQueue;
pxQueueParameters6->xBlockTime = xBlockTime;
pxQueueParameters6->psCheckVariable = &( sBlockingConsumerCount[ 2 ] );
pxQueueParameters6 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
pxQueueParameters6->xQueue = pxQueueParameters5->xQueue;
pxQueueParameters6->xBlockTime = xBlockTime;
pxQueueParameters6->psCheckVariable = &( sBlockingConsumerCount[ 2 ] );
xTaskCreate( vBlockingQueueProducer, "QProdB5", blckqSTACK_SIZE, ( void * ) pxQueueParameters5, tskIDLE_PRIORITY, NULL );
xTaskCreate( vBlockingQueueConsumer, "QConsB6", blckqSTACK_SIZE, ( void * ) pxQueueParameters6, tskIDLE_PRIORITY, NULL );
xTaskCreate( vBlockingQueueProducer, "QProdB5", blckqSTACK_SIZE, ( void * ) pxQueueParameters5, tskIDLE_PRIORITY, NULL );
xTaskCreate( vBlockingQueueConsumer, "QConsB6", blckqSTACK_SIZE, ( void * ) pxQueueParameters6, tskIDLE_PRIORITY, NULL );
}
/*-----------------------------------------------------------*/
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;
pxQueueParameters = ( xBlockingQueueParameters * ) pvParameters;
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcTaskStartMsg );
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcTaskStartMsg );
for( ;; )
{
if( xQueueSendToBack( pxQueueParameters->xQueue, ( void * ) &usValue, pxQueueParameters->xBlockTime ) != pdPASS )
{
vPrintDisplayMessage( &pcTaskErrorMsg );
sErrorEverOccurred = pdTRUE;
}
else
{
/* We have successfully posted a message, so increment the variable
used to check we are still running. */
if( sErrorEverOccurred == pdFALSE )
{
( *pxQueueParameters->psCheckVariable )++;
}
for( ; ; )
{
if( xQueueSendToBack( pxQueueParameters->xQueue, ( void * ) &usValue, pxQueueParameters->xBlockTime ) != pdPASS )
{
vPrintDisplayMessage( &pcTaskErrorMsg );
sErrorEverOccurred = pdTRUE;
}
else
{
/* We have successfully posted a message, so increment the variable
* 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. */
++usValue;
}
}
/* Increment the variable we are going to post next time round. The
* 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 );
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcTaskStartMsg );
pxQueueParameters = ( xBlockingQueueParameters * ) pvParameters;
pxQueueParameters = ( xBlockingQueueParameters * ) pvParameters;
for( ;; )
{
if( xQueueReceive( pxQueueParameters->xQueue, &usData, pxQueueParameters->xBlockTime ) == pdPASS )
{
if( usData != usExpectedValue )
{
vPrintDisplayMessage( &pcTaskErrorMsg );
for( ; ; )
{
if( xQueueReceive( pxQueueParameters->xQueue, &usData, pxQueueParameters->xBlockTime ) == pdPASS )
{
if( usData != usExpectedValue )
{
vPrintDisplayMessage( &pcTaskErrorMsg );
/* Catch-up. */
usExpectedValue = usData;
/* Catch-up. */
usExpectedValue = usData;
sErrorEverOccurred = pdTRUE;
}
else
{
/* We have successfully received a message, so increment the
variable used to check we are still running. */
if( sErrorEverOccurred == pdFALSE )
{
( *pxQueueParameters->psCheckVariable )++;
}
sErrorEverOccurred = pdTRUE;
}
else
{
/* We have successfully received a message, so increment the
* 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. */
++usExpectedValue;
}
}
}
/* Increment the value we expect to remove from the queue next time
* round. */
++usExpectedValue;
}
}
}
}
/*-----------------------------------------------------------*/
/* 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.
/* 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. */
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++ )
{
if( sBlockingConsumerCount[ xTasks ] == sLastBlockingConsumerCount[ xTasks ] )
{
xReturn = pdFALSE;
}
for( xTasks = 0; xTasks < blckqNUM_TASK_SETS; xTasks++ )
{
if( sBlockingConsumerCount[ xTasks ] == sLastBlockingConsumerCount[ xTasks ] )
{
xReturn = pdFALSE;
}
sLastBlockingConsumerCount[ xTasks ] = sBlockingConsumerCount[ xTasks ];
sLastBlockingConsumerCount[ xTasks ] = sBlockingConsumerCount[ xTasks ];
if( sBlockingProducerCount[ xTasks ] == sLastBlockingProducerCount[ xTasks ] )
{
xReturn = pdFALSE;
}
if( sBlockingProducerCount[ xTasks ] == sLastBlockingProducerCount[ xTasks ] )
{
xReturn = pdFALSE;
}
sLastBlockingProducerCount[ xTasks ] = sBlockingProducerCount[ xTasks ];
}
sLastBlockingProducerCount[ xTasks ] = sBlockingProducerCount[ xTasks ];
}
return xReturn;
return xReturn;
}

View file

@ -53,11 +53,11 @@
*/
/*
Changes from V2.0.0
+ Delay periods are now specified using variables and constants of
TickType_t rather than unsigned long.
*/
* Changes from V2.0.0
*
+ Delay periods are now specified using variables and constants of
+ TickType_t rather than unsigned long.
*/
#include <stdlib.h>
@ -70,13 +70,13 @@ Changes from V2.0.0
/* Demo program include files. */
#include "PollQ.h"
#define pollqSTACK_SIZE ( ( unsigned short ) configMINIMAL_STACK_SIZE )
#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,137 +84,139 @@ 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 ) );
/* Create the queue used by the producer and consumer. */
xPolledQueue = xQueueCreate( uxQueueSize, ( unsigned portBASE_TYPE ) sizeof( unsigned short ) );
/* Spawn the producer and consumer. */
xTaskCreate( vPolledQueueConsumer, "QConsNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, NULL );
xTaskCreate( vPolledQueueProducer, "QProdNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, NULL );
/* Spawn the producer and consumer. */
xTaskCreate( vPolledQueueConsumer, "QConsNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, NULL );
xTaskCreate( vPolledQueueProducer, "QProdNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, NULL );
}
/*-----------------------------------------------------------*/
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 );
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcTaskStartMsg );
/* The queue being used is passed in as the parameter. */
pxQueue = ( QueueHandle_t * ) pvParameters;
/* The queue being used is passed in as the parameter. */
pxQueue = ( QueueHandle_t * ) pvParameters;
for( ;; )
{
for( usLoop = 0; usLoop < usNumToProduce; ++usLoop )
{
/* Send an incrementing number on the queue without blocking. */
if( xQueueSendToBack( *pxQueue, ( void * ) &usValue, ( TickType_t ) 0 ) != pdPASS )
{
/* We should never find the queue full - this is an error. */
vPrintDisplayMessage( &pcTaskErrorMsg );
sError = pdTRUE;
}
else
{
if( sError == pdFALSE )
{
/* If an error has ever been recorded we stop incrementing the
check variable. */
++sPollingProducerCount;
}
for( ; ; )
{
for( usLoop = 0; usLoop < usNumToProduce; ++usLoop )
{
/* Send an incrementing number on the queue without blocking. */
if( xQueueSendToBack( *pxQueue, ( void * ) &usValue, ( TickType_t ) 0 ) != pdPASS )
{
/* We should never find the queue full - this is an error. */
vPrintDisplayMessage( &pcTaskErrorMsg );
sError = pdTRUE;
}
else
{
if( sError == pdFALSE )
{
/* If an error has ever been recorded we stop incrementing the
* check variable. */
++sPollingProducerCount;
}
/* Update the value we are going to post next time around. */
++usValue;
}
}
/* Update the value we are going to post next time around. */
++usValue;
}
}
/* Wait before we start posting again to ensure the consumer runs and
empties the queue. */
vTaskDelay( xDelay );
}
/* Wait before we start posting again to ensure the consumer runs and
* 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 );
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcTaskStartMsg );
/* The queue being used is passed in as the parameter. */
pxQueue = ( QueueHandle_t * ) pvParameters;
/* The queue being used is passed in as the parameter. */
pxQueue = ( QueueHandle_t * ) pvParameters;
for( ;; )
{
/* Loop until the queue is empty. */
while( uxQueueMessagesWaiting( *pxQueue ) )
{
if( xQueueReceive( *pxQueue, &usData, ( TickType_t ) 0 ) == pdPASS )
{
if( usData != usExpectedValue )
{
/* This is not what we expected to receive so an error has
occurred. */
vPrintDisplayMessage( &pcTaskErrorMsg );
sError = pdTRUE;
/* Catch-up to the value we received so our next expected value
should again be correct. */
usExpectedValue = usData;
}
else
{
if( sError == pdFALSE )
{
/* Only increment the check variable if no errors have
occurred. */
++sPollingConsumerCount;
}
}
++usExpectedValue;
}
}
for( ; ; )
{
/* Loop until the queue is empty. */
while( uxQueueMessagesWaiting( *pxQueue ) )
{
if( xQueueReceive( *pxQueue, &usData, ( TickType_t ) 0 ) == pdPASS )
{
if( usData != usExpectedValue )
{
/* This is not what we expected to receive so an error has
* occurred. */
vPrintDisplayMessage( &pcTaskErrorMsg );
sError = pdTRUE;
/* Now the queue is empty we block, allowing the producer to place more
items in the queue. */
vTaskDelay( xDelay );
}
/* Catch-up to the value we received so our next expected value
* should again be correct. */
usExpectedValue = usData;
}
else
{
if( sError == pdFALSE )
{
/* Only increment the check variable if no errors have
* occurred. */
++sPollingConsumerCount;
}
}
++usExpectedValue;
}
}
/* Now the queue is empty we block, allowing the producer to place more
* items in the queue. */
vTaskDelay( xDelay );
}
}
/*-----------------------------------------------------------*/
/* 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 )
)
{
xReturn = pdFALSE;
}
else
{
xReturn = pdTRUE;
}
if( ( sLastPollingConsumerCount == sPollingConsumerCount ) ||
( sLastPollingProducerCount == sPollingProducerCount )
)
{
xReturn = pdFALSE;
}
else
{
xReturn = pdTRUE;
}
sLastPollingConsumerCount = sPollingConsumerCount;
sLastPollingProducerCount = sPollingProducerCount;
sLastPollingConsumerCount = sPollingConsumerCount;
sLastPollingProducerCount = sPollingProducerCount;
return xReturn;
return xReturn;
}

View file

@ -55,36 +55,36 @@
*/
/*
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:
+ 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:
+ Use vSerialPutString() instead of single character puts.
+ Only stop the check variable incrementing after two consecutive errors.
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
+ Delay periods are now specified using variables and constants of
TickType_t rather than unsigned long.
+ Slight modification to task priorities.
*/
* 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:
+
+ 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:
+
+ Use vSerialPutString() instead of single character puts.
+ Only stop the check variable incrementing after two consecutive errors.
+
+ 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
+
+ Delay periods are now specified using variables and constants of
+ TickType_t rather than unsigned long.
+ Slight modification to task priorities.
+
*/
/* Scheduler include files. */
@ -99,34 +99,34 @@ 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. */
#define comTX_MAX_BLOCK_TIME ( ( TickType_t ) 0x15e )
#define comTX_MIN_BLOCK_TIME ( ( TickType_t ) 0xc8 )
* 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 )
#define comMAX_CONSECUTIVE_ERRORS ( 2 )
#define comMAX_CONSECUTIVE_ERRORS ( 2 )
#define comSTACK_SIZE ( ( unsigned short ) 256 )
#define comSTACK_SIZE ( ( unsigned short ) 256 )
#define comRX_RELATIVE_PRIORITY ( 1 )
#define comRX_RELATIVE_PRIORITY ( 1 )
/* Handle to the com port used by both tasks. */
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 );
/* The string that is repeatedly transmitted. */
const char * const pcMessageToExchange = "Send this message over and over again to check communications interrupts. "
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n";
const char * const pcMessageToExchange = "Send this message over and over again to check communications interrupts. "
"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,212 +134,217 @@ 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 );
xTaskCreate( vComTxTask, "COMTx", comSTACK_SIZE, NULL, uxPriority, NULL );
xTaskCreate( vComRxTask, "COMRx", comSTACK_SIZE, NULL, uxPriority + comRX_RELATIVE_PRIORITY, NULL );
xTaskCreate( vSemTestTask, "ISRSem", comSTACK_SIZE, NULL, tskIDLE_PRIORITY, &xSemTestTaskHandle );
/* Initialise the com port then spawn both tasks. */
xPort = xSerialPortInit( ePort, eBaudRate, serNO_PARITY, serBITS_8, serSTOP_1, uxBufferLength );
xTaskCreate( vComTxTask, "COMTx", comSTACK_SIZE, NULL, uxPriority, NULL );
xTaskCreate( vComRxTask, "COMRx", comSTACK_SIZE, NULL, uxPriority + comRX_RELATIVE_PRIORITY, NULL );
xTaskCreate( vSemTestTask, "ISRSem", comSTACK_SIZE, NULL, tskIDLE_PRIORITY, &xSemTestTaskHandle );
}
/*-----------------------------------------------------------*/
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;
/* Stop warnings. */
( void ) pvParameters;
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcTaskStartMsg );
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcTaskStartMsg );
for( ;; )
{
/* Send the string to the serial port. */
vSerialPutString( xPort, pcMessageToExchange, strlen( pcMessageToExchange ) );
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. */
sTxCount++;
/* 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. */
sTxCount++;
xTimeToWait = xTaskGetTickCount();
xTimeToWait = xTaskGetTickCount();
/* Make sure we don't wait too long... */
xTimeToWait %= comTX_MAX_BLOCK_TIME;
/* Make sure we don't wait too long... */
xTimeToWait %= comTX_MAX_BLOCK_TIME;
/* ...but we do want to wait. */
if( xTimeToWait < comTX_MIN_BLOCK_TIME )
{
xTimeToWait = comTX_MIN_BLOCK_TIME;
}
/* ...but we do want to wait. */
if( xTimeToWait < comTX_MIN_BLOCK_TIME )
{
xTimeToWait = comTX_MIN_BLOCK_TIME;
}
vTaskDelay( xTimeToWait );
}
vTaskDelay( 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;
/* Stop warnings. */
( void ) pvParameters;
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcTaskStartMsg );
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcTaskStartMsg );
/* The first expected character is the first character in the string. */
pcExpectedChar = pcMessageToExchange;
sResyncRequired = pdFALSE;
sConsecutiveErrors = 0;
sLatchedError = pdFALSE;
/* The first expected character is the first character in the string. */
pcExpectedChar = pcMessageToExchange;
sResyncRequired = pdFALSE;
sConsecutiveErrors = 0;
sLatchedError = pdFALSE;
for( ;; )
{
/* Receive a message from the com port interrupt routine. If a message is
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. */
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. */
pcExpectedChar = pcMessageToExchange;
sResyncRequired = pdFALSE;
for( ; ; )
{
/* Receive a message from the com port interrupt routine. If a message is
* not yet available the call will block the task. */
xGotChar = xSerialGetChar( xPort, &cRxedChar, xBlockTime );
/* Queue a message for printing to say that we are going to try
again. */
vPrintDisplayMessage( &pcTaskRestartMsg );
if( xGotChar == pdTRUE )
{
if( sResyncRequired == pdTRUE )
{
/* We got out of sequence and are waiting for the start of the next
* 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. */
pcExpectedChar = pcMessageToExchange;
sResyncRequired = pdFALSE;
/* Stop incrementing the check variable, if consecutive errors occur. */
sConsecutiveErrors++;
if( sConsecutiveErrors >= comMAX_CONSECUTIVE_ERRORS )
{
sLatchedError = pdTRUE;
}
}
}
else
{
/* We have received a character, but is it the expected character? */
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. */
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. */
pcExpectedChar++;
if( *pcExpectedChar == '\0' )
{
pcExpectedChar = pcMessageToExchange;
/* Queue a message for printing to say that we are going to try
* again. */
vPrintDisplayMessage( &pcTaskRestartMsg );
/* We have got through the entire string without error. */
sConsecutiveErrors = 0;
}
}
}
/* Stop incrementing the check variable, if consecutive errors occur. */
sConsecutiveErrors++;
/* Increment the count that is used to check that this task is still
running. This is only done if an error has never occurred. */
if( sLatchedError == pdFALSE )
{
sRxCount++;
}
}
else
{
vPrintDisplayMessage( &pcTaskTimeoutMsg );
}
}
if( sConsecutiveErrors >= comMAX_CONSECUTIVE_ERRORS )
{
sLatchedError = pdTRUE;
}
}
}
else
{
/* We have received a character, but is it the expected character? */
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. */
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. */
pcExpectedChar++;
if( *pcExpectedChar == '\0' )
{
pcExpectedChar = pcMessageToExchange;
/* We have got through the entire string without error. */
sConsecutiveErrors = 0;
}
}
}
/* Increment the count that is used to check that this task is still
* running. This is only done if an error has never occurred. */
if( sLatchedError == pdFALSE )
{
sRxCount++;
}
}
else
{
vPrintDisplayMessage( &pcTaskTimeoutMsg );
}
}
} /*lint !e715 !e818 pvParameters is required for a task function even if it is not referenced. */
/*-----------------------------------------------------------*/
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;
/* Stop warnings. */
( void ) pvParameters;
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcTaskStartMsg );
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcTaskStartMsg );
for( ;; )
{
if( xSerialWaitForSemaphore( xPort ) )
{
if( xError == pdFALSE )
{
sSemCount++;
}
}
else
{
xError = pdTRUE;
}
}
for( ; ; )
{
if( xSerialWaitForSemaphore( xPort ) )
{
if( xError == pdFALSE )
{
sSemCount++;
}
}
else
{
xError = pdTRUE;
}
}
} /*lint !e715 !e830 !e818 pvParameters not used but function prototype must be standard for task function. */
/*-----------------------------------------------------------*/
/* 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. */
/* 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. */
if( ( sTxCount == sLastTxCount ) || ( sRxCount == sLastRxCount ) || ( sSemCount == sLastSemCount ) )
{
xReturn = pdFALSE;
}
else
{
xReturn = pdTRUE;
}
if( ( sTxCount == sLastTxCount ) || ( sRxCount == sLastRxCount ) || ( sSemCount == sLastSemCount ) )
{
xReturn = pdFALSE;
}
else
{
xReturn = pdTRUE;
}
sLastTxCount = sTxCount;
sLastRxCount = sRxCount;
sLastSemCount = sSemCount;
sLastTxCount = sTxCount;
sLastRxCount = sRxCount;
sLastSemCount = sSemCount;
return xReturn;
return 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. */
xTaskResumeFromISR( xSemTestTaskHandle );
/* 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. */
xTaskResumeFromISR( xSemTestTaskHandle );
}

View file

@ -44,11 +44,11 @@
*/
/*
Changes from V2.0.0
+ Delay periods are now specified using variables and constants of
TickType_t rather than unsigned long.
*/
* Changes from V2.0.0
*
+ Delay periods are now specified using variables and constants of
+ TickType_t rather than unsigned long.
*/
#include <stdlib.h>
@ -60,66 +60,66 @@ Changes from V2.0.0
#include "death.h"
#include "print.h"
#define deathSTACK_SIZE ( ( unsigned short ) 512 )
#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;
}

View file

@ -91,20 +91,20 @@
*/
/*
Changes from V2.0.0
+ Delay periods are now specified using variables and constants of
TickType_t rather than unsigned long.
+ Added a second, simple test that uses the functions
vQueueReceiveWhenSuspendedTask() and vQueueSendWhenSuspendedTask().
Changes from V3.1.1
+ Added a third simple test that uses the vTaskPrioritySet() function
while the scheduler is suspended.
+ Modified the controller task slightly to test the calling of
vTaskResumeAll() while the scheduler is suspended.
*/
* Changes from V2.0.0
*
+ Delay periods are now specified using variables and constants of
+ TickType_t rather than unsigned long.
+ Added a second, simple test that uses the functions
+ vQueueReceiveWhenSuspendedTask() and vQueueSendWhenSuspendedTask().
+
+ Changes from V3.1.1
+
+ Added a third simple test that uses the vTaskPrioritySet() function
+ while the scheduler is suspended.
+ Modified the controller task slightly to test the calling of
+ vTaskResumeAll() while the scheduler is suspended.
*/
#include <stdlib.h>
@ -127,42 +127,42 @@ 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. */
#define priSTACK_SIZE ( ( unsigned short ) configMINIMAL_STACK_SIZE )
#define priSLEEP_TIME ( ( TickType_t ) 50 )
#define priLOOPS ( 5 )
#define priMAX_COUNT ( ( unsigned long ) 0xff )
#define priNO_BLOCK ( ( TickType_t ) 0 )
#define priSUSPENDED_QUEUE_LENGTH ( 1 )
#define priSTACK_SIZE ( ( unsigned short ) configMINIMAL_STACK_SIZE )
#define priSLEEP_TIME ( ( TickType_t ) 50 )
#define priLOOPS ( 5 )
#define priMAX_COUNT ( ( unsigned long ) 0xff )
#define priNO_BLOCK ( ( TickType_t ) 0 )
#define priSUSPENDED_QUEUE_LENGTH ( 1 )
/*-----------------------------------------------------------*/
/* 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,20 +172,21 @@ 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.
*/
void vStartDynamicPriorityTasks( void )
{
xSuspendedTestQueue = xQueueCreate( priSUSPENDED_QUEUE_LENGTH, sizeof( unsigned long ) );
xTaskCreate( vContinuousIncrementTask, "CONT_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY, &xContinuousIncrementHandle );
xTaskCreate( vLimitedIncrementTask, "LIM_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY + 1, &xLimitedIncrementHandle );
xTaskCreate( vCounterControlTask, "C_CTRL", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
xTaskCreate( vQueueSendWhenSuspendedTask, "SUSP_SEND", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
xTaskCreate( vQueueReceiveWhenSuspendedTask, "SUSP_RECV", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
xTaskCreate( prvChangePriorityWhenSuspendedTask, "1st_P_CHANGE", priSTACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL );
xTaskCreate( prvChangePriorityHelperTask, "2nd_P_CHANGE", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, &xChangePriorityWhenSuspendedHandle );
xSuspendedTestQueue = xQueueCreate( priSUSPENDED_QUEUE_LENGTH, sizeof( unsigned long ) );
xTaskCreate( vContinuousIncrementTask, "CONT_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY, &xContinuousIncrementHandle );
xTaskCreate( vLimitedIncrementTask, "LIM_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY + 1, &xLimitedIncrementHandle );
xTaskCreate( vCounterControlTask, "C_CTRL", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
xTaskCreate( vQueueSendWhenSuspendedTask, "SUSP_SEND", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
xTaskCreate( vQueueReceiveWhenSuspendedTask, "SUSP_RECV", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
xTaskCreate( prvChangePriorityWhenSuspendedTask, "1st_P_CHANGE", priSTACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL );
xTaskCreate( prvChangePriorityHelperTask, "2nd_P_CHANGE", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, &xChangePriorityWhenSuspendedHandle );
}
/*-----------------------------------------------------------*/
@ -195,26 +196,26 @@ 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. */
pulCounter = ( unsigned long * ) pvParameters;
/* Take a pointer to the shared variable from the parameters passed into
* 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. */
vTaskSuspend( NULL );
/* This will run before the control task, so the first thing it does is
* suspend - the control task will resume it when ready. */
vTaskSuspend( NULL );
for( ;; )
{
/* Just count up to a value then suspend. */
( *pulCounter )++;
for( ; ; )
{
/* Just count up to a value then suspend. */
( *pulCounter )++;
if( *pulCounter >= priMAX_COUNT )
{
vTaskSuspend( NULL );
}
}
if( *pulCounter >= priMAX_COUNT )
{
vTaskSuspend( NULL );
}
}
}
/*-----------------------------------------------------------*/
@ -224,29 +225,29 @@ 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. */
pulCounter = ( unsigned long * ) pvParameters;
/* Take a pointer to the shared variable from the parameters passed into
* the task. */
pulCounter = ( unsigned long * ) pvParameters;
/* Query our priority so we can raise it when exclusive access to the
shared variable is required. */
uxOurPriority = uxTaskPriorityGet( NULL );
/* Query our priority so we can raise it when exclusive access to the
* shared variable is required. */
uxOurPriority = uxTaskPriorityGet( NULL );
for( ;; )
{
/* Raise our priority above the controller task to ensure a context
switch does not occur while we are accessing this variable. */
vTaskPrioritySet( NULL, uxOurPriority + 1 );
( *pulCounter )++;
vTaskPrioritySet( NULL, uxOurPriority );
for( ; ; )
{
/* Raise our priority above the controller task to ensure a context
* switch does not occur while we are accessing this variable. */
vTaskPrioritySet( NULL, uxOurPriority + 1 );
( *pulCounter )++;
vTaskPrioritySet( NULL, uxOurPriority );
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
}
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
}
}
/*-----------------------------------------------------------*/
@ -255,285 +256,285 @@ 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;
/* Just to stop warning messages. */
( void ) pvParameters;
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcTaskStartMsg );
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcTaskStartMsg );
for( ;; )
{
/* Start with the counter at zero. */
ulCounter = ( unsigned long ) 0;
for( ; ; )
{
/* Start with the counter at zero. */
ulCounter = ( unsigned long ) 0;
/* First section : */
/* First section : */
/* Check the continuous count task is running. */
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. */
vTaskSuspend( xContinuousIncrementHandle );
ulLastCounter = ulCounter;
vTaskResume( xContinuousIncrementHandle );
/* Check the continuous count task is running. */
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. */
vTaskSuspend( xContinuousIncrementHandle );
ulLastCounter = ulCounter;
vTaskResume( xContinuousIncrementHandle );
/* Now delay to ensure the other task has processor time. */
vTaskDelay( priSLEEP_TIME );
/* Now delay to ensure the other task has processor time. */
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! */
vTaskSuspendAll();
{
if( ulLastCounter == ulCounter )
{
/* The shared variable has not changed. There is a problem
with the continuous count task so flag an error. */
sError = pdTRUE;
xTaskResumeAll();
vPrintDisplayMessage( &pcTaskFailMsg );
vTaskSuspendAll();
}
}
xTaskResumeAll();
}
/* Check the shared variable again. This time to ensure mutual
* 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. */
sError = pdTRUE;
xTaskResumeAll();
vPrintDisplayMessage( &pcTaskFailMsg );
vTaskSuspendAll();
}
}
xTaskResumeAll();
}
/* Second section: */
/* Second section: */
/* Suspend the continuous counter task so it stops accessing the shared variable. */
vTaskSuspend( xContinuousIncrementHandle );
/* Suspend the continuous counter task so it stops accessing the shared variable. */
vTaskSuspend( xContinuousIncrementHandle );
/* Reset the variable. */
ulCounter = ( unsigned long ) 0;
/* Reset the variable. */
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. */
vTaskSuspendAll();
vTaskResume( xLimitedIncrementHandle );
xTaskResumeAll();
/* 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. */
vTaskSuspendAll();
vTaskResume( xLimitedIncrementHandle );
xTaskResumeAll();
/* Does the counter variable have the expected value? */
if( ulCounter != priMAX_COUNT )
{
sError = pdTRUE;
vPrintDisplayMessage( &pcTaskFailMsg );
}
/* Does the counter variable have the expected value? */
if( ulCounter != priMAX_COUNT )
{
sError = pdTRUE;
vPrintDisplayMessage( &pcTaskFailMsg );
}
if( sError == pdFALSE )
{
/* If no errors have occurred then increment the check variable. */
portENTER_CRITICAL();
usCheckVariable++;
portEXIT_CRITICAL();
}
if( sError == pdFALSE )
{
/* If no errors have occurred then increment the check variable. */
portENTER_CRITICAL();
usCheckVariable++;
portEXIT_CRITICAL();
}
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
/* Resume the continuous count task and do it all again. */
vTaskResume( xContinuousIncrementHandle );
}
/* Resume the continuous count task and do it all again. */
vTaskResume( xContinuousIncrementHandle );
}
}
/*-----------------------------------------------------------*/
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;
/* Just to stop warning messages. */
( void ) pvParameters;
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcTaskStartMsg );
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcTaskStartMsg );
for( ;; )
{
vTaskSuspendAll();
{
/* We must not block while the scheduler is suspended! */
if( xQueueSend( xSuspendedTestQueue, ( void * ) &ulValueToSend, priNO_BLOCK ) != pdTRUE )
{
if( xSuspendedQueueSendError == pdFALSE )
{
xTaskResumeAll();
vPrintDisplayMessage( &pcTaskFailMsg );
vTaskSuspendAll();
}
for( ; ; )
{
vTaskSuspendAll();
{
/* We must not block while the scheduler is suspended! */
if( xQueueSend( xSuspendedTestQueue, ( void * ) &ulValueToSend, priNO_BLOCK ) != pdTRUE )
{
if( xSuspendedQueueSendError == pdFALSE )
{
xTaskResumeAll();
vPrintDisplayMessage( &pcTaskFailMsg );
vTaskSuspendAll();
}
xSuspendedQueueSendError = pdTRUE;
}
}
xTaskResumeAll();
xSuspendedQueueSendError = pdTRUE;
}
}
xTaskResumeAll();
vTaskDelay( priSLEEP_TIME );
vTaskDelay( priSLEEP_TIME );
++ulValueToSend;
}
++ulValueToSend;
}
}
/*-----------------------------------------------------------*/
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;
/* Just to stop warning messages. */
( void ) pvParameters;
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcTaskStartMsg );
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcTaskStartMsg );
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. */
vTaskSuspendAll();
{
vTaskSuspendAll();
{
xGotValue = xQueueReceive( xSuspendedTestQueue, ( void * ) &ulReceivedValue, priNO_BLOCK );
}
if( xTaskResumeAll() )
{
xSuspendedQueueReceiveError = pdTRUE;
}
}
xTaskResumeAll();
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. */
vTaskSuspendAll();
{
vTaskSuspendAll();
{
xGotValue = xQueueReceive( xSuspendedTestQueue, ( void * ) &ulReceivedValue, priNO_BLOCK );
}
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
if( xTaskResumeAll() )
{
xSuspendedQueueReceiveError = pdTRUE;
}
}
xTaskResumeAll();
} while( xGotValue == pdFALSE );
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
} while( xGotValue == pdFALSE );
if( ulReceivedValue != ulExpectedValue )
{
if( xSuspendedQueueReceiveError == pdFALSE )
{
vPrintDisplayMessage( &pcTaskFailMsg );
}
xSuspendedQueueReceiveError = pdTRUE;
}
if( ulReceivedValue != ulExpectedValue )
{
if( xSuspendedQueueReceiveError == pdFALSE )
{
vPrintDisplayMessage( &pcTaskFailMsg );
}
++ulExpectedValue;
}
xSuspendedQueueReceiveError = pdTRUE;
}
++ulExpectedValue;
}
}
/*-----------------------------------------------------------*/
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;
/* Just to stop warning messages. */
( void ) pvParameters;
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcTaskStartMsg );
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcTaskStartMsg );
for( ;; )
{
/* Start with the counter at 0 so we know what the counter should be
when we check it next. */
ulPrioritySetCounter = ( unsigned long ) 0;
for( ; ; )
{
/* Start with the counter at 0 so we know what the counter should be
* 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. */
vTaskResume( xChangePriorityWhenSuspendedHandle );
/* Resume the helper task. At this time it has a priority lower than
* ours so no context switch should occur. */
vTaskResume( xChangePriorityWhenSuspendedHandle );
/* Check to ensure the task just resumed has not executed. */
portENTER_CRITICAL();
{
if( ulPrioritySetCounter != ( unsigned long ) 0 )
{
xPriorityRaiseWhenSuspendedError = pdTRUE;
vPrintDisplayMessage( &pcTaskFailMsg );
}
}
portEXIT_CRITICAL();
/* Check to ensure the task just resumed has not executed. */
portENTER_CRITICAL();
{
if( ulPrioritySetCounter != ( unsigned long ) 0 )
{
xPriorityRaiseWhenSuspendedError = pdTRUE;
vPrintDisplayMessage( &pcTaskFailMsg );
}
}
portEXIT_CRITICAL();
/* Now try raising the priority while the scheduler is suspended. */
vTaskSuspendAll();
{
vTaskPrioritySet( xChangePriorityWhenSuspendedHandle, ( configMAX_PRIORITIES - 1 ) );
/* Now try raising the priority while the scheduler is suspended. */
vTaskSuspendAll();
{
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. */
portENTER_CRITICAL();
{
if( ulPrioritySetCounter != ( unsigned long ) 0 )
{
xPriorityRaiseWhenSuspendedError = pdTRUE;
vPrintDisplayMessage( &pcTaskFailMsg );
}
}
portEXIT_CRITICAL();
}
xTaskResumeAll();
/* Again, even though the helper task has a priority greater than
* ours, it should not have executed yet because the scheduler is
* suspended. */
portENTER_CRITICAL();
{
if( ulPrioritySetCounter != ( unsigned long ) 0 )
{
xPriorityRaiseWhenSuspendedError = pdTRUE;
vPrintDisplayMessage( &pcTaskFailMsg );
}
}
portEXIT_CRITICAL();
}
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.
/* 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. */
portENTER_CRITICAL();
{
if( ulPrioritySetCounter != ( unsigned long ) 1 )
{
xPriorityRaiseWhenSuspendedError = pdTRUE;
vPrintDisplayMessage( &pcTaskFailMsg );
}
}
portEXIT_CRITICAL();
We should now always find the counter set to 1. */
portENTER_CRITICAL();
{
if( ulPrioritySetCounter != ( unsigned long ) 1 )
{
xPriorityRaiseWhenSuspendedError = pdTRUE;
vPrintDisplayMessage( &pcTaskFailMsg );
}
}
portEXIT_CRITICAL();
/* Delay until we try this again. */
vTaskDelay( priSLEEP_TIME * 2 );
/* Delay until we try this again. */
vTaskDelay( priSLEEP_TIME * 2 );
/* Set the priority of the helper task back ready for the next
execution of this task. */
vTaskSuspendAll();
vTaskPrioritySet( xChangePriorityWhenSuspendedHandle, tskIDLE_PRIORITY );
xTaskResumeAll();
}
/* Set the priority of the helper task back ready for the next
* execution of this task. */
vTaskSuspendAll();
vTaskPrioritySet( xChangePriorityWhenSuspendedHandle, tskIDLE_PRIORITY );
xTaskResumeAll();
}
}
/*-----------------------------------------------------------*/
static void prvChangePriorityHelperTask( void *pvParameters )
static void prvChangePriorityHelperTask( void * pvParameters )
{
/* Just to stop warning messages. */
( void ) pvParameters;
/* Just to stop warning messages. */
( void ) pvParameters;
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. */
ulPrioritySetCounter++;
vTaskSuspend( NULL );
}
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. */
ulPrioritySetCounter++;
vTaskSuspend( NULL );
}
}
/*-----------------------------------------------------------*/
@ -541,38 +542,34 @@ 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. */
/* Check the tasks are still running by ensuring the check variable
* is still incrementing. */
if( usCheckVariable == usLastTaskCheck )
{
/* The check has not incremented so an error exists. */
xReturn = pdFALSE;
}
if( usCheckVariable == usLastTaskCheck )
{
/* The check has not incremented so an error exists. */
xReturn = pdFALSE;
}
if( xSuspendedQueueSendError == pdTRUE )
{
xReturn = pdFALSE;
}
if( xSuspendedQueueSendError == pdTRUE )
{
xReturn = pdFALSE;
}
if( xSuspendedQueueReceiveError == pdTRUE )
{
xReturn = pdFALSE;
}
if( xSuspendedQueueReceiveError == pdTRUE )
{
xReturn = pdFALSE;
}
if( xPriorityRaiseWhenSuspendedError == pdTRUE )
{
xReturn = pdFALSE;
}
if( xPriorityRaiseWhenSuspendedError == pdTRUE )
{
xReturn = pdFALSE;
}
usLastTaskCheck = usCheckVariable;
return xReturn;
usLastTaskCheck = usCheckVariable;
return xReturn;
}

View file

@ -60,309 +60,310 @@
#include "print.h"
/* Demo specific constants. */
#define evtSTACK_SIZE ( ( unsigned portBASE_TYPE ) configMINIMAL_STACK_SIZE )
#define evtNUM_TASKS ( 4 )
#define evtQUEUE_LENGTH ( ( unsigned portBASE_TYPE ) 3 )
#define evtNO_DELAY 0
#define evtSTACK_SIZE ( ( unsigned portBASE_TYPE ) configMINIMAL_STACK_SIZE )
#define evtNUM_TASKS ( 4 )
#define evtQUEUE_LENGTH ( ( unsigned portBASE_TYPE ) 3 )
#define evtNO_DELAY 0
/* Just indexes used to uniquely identify the tasks. Note that two tasks are
'highest' priority. */
#define evtHIGHEST_PRIORITY_INDEX_2 3
#define evtHIGHEST_PRIORITY_INDEX_1 2
#define evtMEDIUM_PRIORITY_INDEX 1
#define evtLOWEST_PRIORITY_INDEX 0
* '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;
/*-----------------------------------------------------------*/
void vStartMultiEventTasks( void )
{
/* Create the queue to be used for all the communications. */
xQueue = xQueueCreate( evtQUEUE_LENGTH, ( unsigned portBASE_TYPE ) sizeof( unsigned portBASE_TYPE ) );
/* Create the queue to be used for all the communications. */
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. */
xTaskCreate( prvEventControllerTask, "EvntCTRL", evtSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
/* Start the controlling task. This has the idle priority to ensure it is
* 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. */
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 ] ) );
xTaskCreate( prvMultiEventTask, "Event3", evtSTACK_SIZE, ( void * ) &( xTaskCounters[ 3 ] ), 3, &( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_2 ] ) );
/* Start the four event tasks. Note that two have priority 3, one
* 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 ] ) );
xTaskCreate( prvMultiEventTask, "Event3", evtSTACK_SIZE, ( void * ) &( xTaskCounters[ 3 ] ), 3, &( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_2 ] ) );
}
/*-----------------------------------------------------------*/
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;
/* The variable this task will increment is passed in as a parameter. */
pxCounter = ( portBASE_TYPE * ) pvParameters;
vPrintDisplayMessage( &pcTaskStartMsg );
vPrintDisplayMessage( &pcTaskStartMsg );
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. */
( *pxCounter )++;
}
else
{
xHealthStatus = pdFAIL;
}
}
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. */
( *pxCounter )++;
}
else
{
xHealthStatus = pdFAIL;
}
}
}
/*-----------------------------------------------------------*/
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;
/* Just to stop warnings. */
( void ) pvParameters;
vPrintDisplayMessage( &pcTaskStartMsg );
vPrintDisplayMessage( &pcTaskStartMsg );
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. */
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. */
prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_1, 1 );
prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_2, 1 );
prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_1, 1 );
prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_2, 1 );
prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_1, 1 );
prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_1, 1 );
prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_2, 1 );
prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_1, 1 );
prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_2, 1 );
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. */
vTaskSuspend( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_2 ] );
/* For the rest of these tests we don't need the second 'highest'
* 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. */
vTaskSuspend( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
/* 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. */
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. */
prvCheckTaskCounters( evtMEDIUM_PRIORITY_INDEX, 1 );
/* This time, when we post onto the queue we will expect the medium
* 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. */
vTaskSuspendAll();
vTaskResume( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
xTaskResumeAll();
prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_1, 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. */
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. */
vTaskSuspendAll();
vTaskSuspend( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
vTaskSuspend( xCreatedTasks[ evtMEDIUM_PRIORITY_INDEX ] );
xTaskResumeAll();
prvCheckTaskCounters( evtLOWEST_PRIORITY_INDEX, 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. */
vTaskSuspendAll();
vTaskSuspend( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
vTaskSuspend( xCreatedTasks[ evtMEDIUM_PRIORITY_INDEX ] );
xTaskResumeAll();
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. */
/* 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. */
vTaskResume( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_1, 1 );
vTaskResume( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_1, 1 );
vTaskSuspendAll(); /* Just for test. */
vTaskSuspendAll(); /* Just for test. */
vTaskSuspendAll(); /* Just for even more test. */
vTaskSuspend( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
xTaskResumeAll();
xTaskResumeAll();
xTaskResumeAll();
prvCheckTaskCounters( evtLOWEST_PRIORITY_INDEX, 1 );
vTaskSuspendAll(); /* Just for test. */
vTaskSuspendAll(); /* Just for test. */
vTaskSuspendAll(); /* Just for even more test. */
vTaskSuspend( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
xTaskResumeAll();
xTaskResumeAll();
xTaskResumeAll();
prvCheckTaskCounters( evtLOWEST_PRIORITY_INDEX, 1 );
vTaskResume( xCreatedTasks[ evtMEDIUM_PRIORITY_INDEX ] );
prvCheckTaskCounters( evtMEDIUM_PRIORITY_INDEX, 1 );
vTaskResume( xCreatedTasks[ evtMEDIUM_PRIORITY_INDEX ] );
prvCheckTaskCounters( evtMEDIUM_PRIORITY_INDEX, 1 );
vTaskResume( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_1, 1 );
vTaskResume( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_1, 1 );
/* Now a slight change, first suspend all tasks. */
vTaskSuspend( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
vTaskSuspend( xCreatedTasks[ evtMEDIUM_PRIORITY_INDEX ] );
vTaskSuspend( xCreatedTasks[ evtLOWEST_PRIORITY_INDEX ] );
/* Now a slight change, first suspend all tasks. */
vTaskSuspend( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
vTaskSuspend( xCreatedTasks[ evtMEDIUM_PRIORITY_INDEX ] );
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. */
vTaskResume( xCreatedTasks[ evtLOWEST_PRIORITY_INDEX ] );
prvCheckTaskCounters( evtLOWEST_PRIORITY_INDEX, evtQUEUE_LENGTH );
/* 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. */
vTaskResume( xCreatedTasks[ evtLOWEST_PRIORITY_INDEX ] );
prvCheckTaskCounters( evtLOWEST_PRIORITY_INDEX, evtQUEUE_LENGTH );
/* Again suspend all tasks (only the low priority task is not suspended
already). */
vTaskSuspend( xCreatedTasks[ evtLOWEST_PRIORITY_INDEX ] );
/* Again suspend all tasks (only the low priority task is not suspended
* 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. */
vTaskSuspendAll();
{
vTaskResume( xCreatedTasks[ evtLOWEST_PRIORITY_INDEX ] );
vTaskResume( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
/* 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. */
vTaskSuspendAll();
{
vTaskResume( xCreatedTasks[ evtLOWEST_PRIORITY_INDEX ] );
vTaskResume( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
for( xDummy = 0; xDummy < evtQUEUE_LENGTH; xDummy++ )
{
if( xQueueSend( xQueue, &xDummy, evtNO_DELAY ) != pdTRUE )
{
xHealthStatus = pdFAIL;
}
}
for( xDummy = 0; xDummy < evtQUEUE_LENGTH; xDummy++ )
{
if( xQueueSend( xQueue, &xDummy, evtNO_DELAY ) != pdTRUE )
{
xHealthStatus = pdFAIL;
}
}
/* The queue should not have been serviced yet!. The scheduler
is still suspended. */
if( memcmp( ( void * ) xExpectedTaskCounters, ( void * ) xTaskCounters, sizeof( xExpectedTaskCounters ) ) )
{
xHealthStatus = pdFAIL;
}
}
xTaskResumeAll();
/* The queue should not have been serviced yet!. The scheduler
* is still suspended. */
if( memcmp( ( void * ) xExpectedTaskCounters, ( void * ) xTaskCounters, sizeof( xExpectedTaskCounters ) ) )
{
xHealthStatus = pdFAIL;
}
}
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. */
xExpectedTaskCounters[ evtHIGHEST_PRIORITY_INDEX_1 ] += evtQUEUE_LENGTH;
if( memcmp( ( void * ) xExpectedTaskCounters, ( void * ) xTaskCounters, sizeof( xExpectedTaskCounters ) ) )
{
xHealthStatus = pdFAIL;
}
/* 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. */
xExpectedTaskCounters[ evtHIGHEST_PRIORITY_INDEX_1 ] += evtQUEUE_LENGTH;
/* The medium priority and second high priority tasks are still
suspended. Make sure to resume them before starting again. */
vTaskResume( xCreatedTasks[ evtMEDIUM_PRIORITY_INDEX ] );
vTaskResume( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_2 ] );
if( memcmp( ( void * ) xExpectedTaskCounters, ( void * ) xTaskCounters, sizeof( xExpectedTaskCounters ) ) )
{
xHealthStatus = pdFAIL;
}
/* Just keep incrementing to show the task is still executing. */
xCheckVariable++;
}
/* The medium priority and second high priority tasks are still
* suspended. Make sure to resume them before starting again. */
vTaskResume( xCreatedTasks[ evtMEDIUM_PRIORITY_INDEX ] );
vTaskResume( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_2 ] );
/* Just keep incrementing to show the task is still executing. */
xCheckVariable++;
}
}
/*-----------------------------------------------------------*/
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. */
for( xDummy = 0; xDummy < xIncrement; xDummy++ )
{
if( xQueueSend( xQueue, &xDummy, evtNO_DELAY ) != pdTRUE )
{
/* Did not expect to ever find the queue full. */
xHealthStatus = pdFAIL;
}
}
/* Write to the queue the requested number of times. The data written is
* not important. */
for( xDummy = 0; xDummy < xIncrement; xDummy++ )
{
if( xQueueSend( xQueue, &xDummy, evtNO_DELAY ) != pdTRUE )
{
/* Did not expect to ever find the queue full. */
xHealthStatus = pdFAIL;
}
}
/* 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. */
( xExpectedTaskCounters[ xExpectedTask ] ) += xIncrement;
/* 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. */
( 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. */
xHealthStatus = pdFAIL;
}
/* 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. */
xHealthStatus = pdFAIL;
}
}
/*-----------------------------------------------------------*/
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. */
/* Called externally to periodically check that this test is still
* operational. */
if( xPreviousCheckVariable == xCheckVariable )
{
xHealthStatus = pdFAIL;
}
if( xPreviousCheckVariable == xCheckVariable )
{
xHealthStatus = pdFAIL;
}
xPreviousCheckVariable = xCheckVariable;
xPreviousCheckVariable = xCheckVariable;
return xHealthStatus;
return xHealthStatus;
}

View file

@ -42,16 +42,16 @@
*/
/*
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
+ The stack size now uses configMINIMAL_STACK_SIZE.
+ String constants made file scope to decrease stack depth on 8051 port.
*/
* 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
+
+ The stack size now uses configMINIMAL_STACK_SIZE.
+ String constants made file scope to decrease stack depth on 8051 port.
*/
#include <stdlib.h>
@ -64,18 +64,18 @@ Changes from V2.1.1
#include "flash.h"
#include "print.h"
#define ledSTACK_SIZE configMINIMAL_STACK_SIZE
#define ledSTACK_SIZE configMINIMAL_STACK_SIZE
/* Structure used to pass parameters to the LED tasks. */
typedef struct LED_PARAMETERS
{
unsigned portBASE_TYPE uxLED; /*< The output the task should use. */
TickType_t xFlashRate; /*< The rate at which the LED should flash. */
unsigned portBASE_TYPE uxLED; /*< The output the task should use. */
TickType_t xFlashRate; /*< The rate at which the LED should flash. */
} 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,45 +84,44 @@ 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. */
pxLEDParameters = ( xLEDParameters * ) pvPortMalloc( sizeof( xLEDParameters ) );
pxLEDParameters->uxLED = uxLEDTask;
pxLEDParameters->xFlashRate = ( xFlashRate + ( xFlashRate * ( TickType_t ) uxLEDTask ) );
pxLEDParameters->xFlashRate /= portTICK_PERIOD_MS;
/* Create the eight tasks. */
for( uxLEDTask = 0; uxLEDTask < uxNumOfLEDs; ++uxLEDTask )
{
/* Create and complete the structure used to pass parameters to the next
* created task. */
pxLEDParameters = ( xLEDParameters * ) pvPortMalloc( sizeof( xLEDParameters ) );
pxLEDParameters->uxLED = uxLEDTask;
pxLEDParameters->xFlashRate = ( xFlashRate + ( xFlashRate * ( TickType_t ) uxLEDTask ) );
pxLEDParameters->xFlashRate /= portTICK_PERIOD_MS;
/* Spawn the task. */
xTaskCreate( vLEDFlashTask, "LEDx", ledSTACK_SIZE, ( void * ) pxLEDParameters, uxPriority, ( TaskHandle_t * ) NULL );
}
/* Spawn the task. */
xTaskCreate( vLEDFlashTask, "LEDx", ledSTACK_SIZE, ( void * ) pxLEDParameters, uxPriority, ( TaskHandle_t * ) NULL );
}
}
/*-----------------------------------------------------------*/
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 );
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcTaskStartMsg );
pxParameters = ( xLEDParameters * ) pvParameters;
pxParameters = ( xLEDParameters * ) pvParameters;
for(;;)
{
/* Delay for half the flash period then turn the LED on. */
vTaskDelay( pxParameters->xFlashRate / ( TickType_t ) 2 );
vParTestToggleLED( pxParameters->uxLED );
for( ; ; )
{
/* Delay for half the flash period then turn the LED on. */
vTaskDelay( pxParameters->xFlashRate / ( TickType_t ) 2 );
vParTestToggleLED( pxParameters->uxLED );
/* Delay for half the flash period then turn the LED off. */
vTaskDelay( pxParameters->xFlashRate / ( TickType_t ) 2 );
vParTestToggleLED( pxParameters->uxLED );
}
/* Delay for half the flash period then turn the LED off. */
vTaskDelay( pxParameters->xFlashRate / ( TickType_t ) 2 );
vParTestToggleLED( pxParameters->uxLED );
}
}

View file

@ -26,11 +26,11 @@
*/
/*
Changes from V1.2.3
+ The created tasks now include calls to tskYIELD(), allowing them to be used
with the cooperative scheduler.
*/
* Changes from V1.2.3
*
+ The created tasks now include calls to tskYIELD(), allowing them to be used
+ with the cooperative scheduler.
*/
/**
* Creates eight tasks, each of which loops continuously performing an (emulated)
@ -60,246 +60,248 @@ Changes from V1.2.3
/* Demo program include files. */
#include "flop.h"
#define mathSTACK_SIZE ( ( unsigned short ) 512 )
#define mathNUMBER_OF_TASKS ( 8 )
#define mathSTACK_SIZE ( ( unsigned short ) 512 )
#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 };
/*-----------------------------------------------------------*/
void vStartMathTasks( unsigned portBASE_TYPE uxPriority )
{
xTaskCreate( vCompetingMathTask1, "Math1", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 0 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask2, "Math2", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 1 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask3, "Math3", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 2 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask4, "Math4", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 3 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask1, "Math5", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 4 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask2, "Math6", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 5 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask3, "Math7", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 6 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask4, "Math8", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 7 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask1, "Math1", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 0 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask2, "Math2", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 1 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask3, "Math3", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 2 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask4, "Math4", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 3 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask1, "Math5", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 4 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask2, "Math6", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 5 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask3, "Math7", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 6 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask4, "Math8", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 7 ] ), uxPriority, NULL );
}
/*-----------------------------------------------------------*/
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 );
/* 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. */
pusTaskCheckVariable = ( unsigned short * ) pvParameters;
/* The variable this task increments to show it is still running is passed in
* as the parameter. */
pusTaskCheckVariable = ( unsigned short * ) pvParameters;
/* Keep performing a calculation and checking the result against a constant. */
for(;;)
{
d1 = 123.4567;
d2 = 2345.6789;
d3 = -918.222;
/* Keep performing a calculation and checking the result against a constant. */
for( ; ; )
{
d1 = 123.4567;
d2 = 2345.6789;
d3 = -918.222;
d4 = ( d1 + d2 ) * d3;
d4 = ( d1 + d2 ) * d3;
taskYIELD();
taskYIELD();
/* If the calculation does not match the expected constant, stop the
increment of the check variable. */
if( fabs( d4 - dAnswer ) > 0.001 )
{
vPrintDisplayMessage( &pcTaskFailMsg );
sError = pdTRUE;
}
/* If the calculation does not match the expected constant, stop the
* increment of the check variable. */
if( fabs( d4 - dAnswer ) > 0.001 )
{
vPrintDisplayMessage( &pcTaskFailMsg );
sError = pdTRUE;
}
if( sError == pdFALSE )
{
/* If the calculation has always been correct, increment the check
variable so we know this task is still running okay. */
( *pusTaskCheckVariable )++;
}
if( sError == pdFALSE )
{
/* If the calculation has always been correct, increment the check
* variable so we know this task is still running okay. */
( *pusTaskCheckVariable )++;
}
taskYIELD();
}
taskYIELD();
}
}
/*-----------------------------------------------------------*/
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 );
/* 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. */
pusTaskCheckVariable = ( unsigned short * ) pvParameters;
/* The variable this task increments to show it is still running is passed in
* as the parameter. */
pusTaskCheckVariable = ( unsigned short * ) pvParameters;
/* Keep performing a calculation and checking the result against a constant. */
for( ;; )
{
d1 = -389.38;
d2 = 32498.2;
d3 = -2.0001;
/* Keep performing a calculation and checking the result against a constant. */
for( ; ; )
{
d1 = -389.38;
d2 = 32498.2;
d3 = -2.0001;
d4 = ( d1 / d2 ) * d3;
d4 = ( d1 / d2 ) * d3;
taskYIELD();
taskYIELD();
/* If the calculation does not match the expected constant, stop the
increment of the check variable. */
if( fabs( d4 - dAnswer ) > 0.001 )
{
vPrintDisplayMessage( &pcTaskFailMsg );
sError = pdTRUE;
}
/* If the calculation does not match the expected constant, stop the
* increment of the check variable. */
if( fabs( d4 - dAnswer ) > 0.001 )
{
vPrintDisplayMessage( &pcTaskFailMsg );
sError = pdTRUE;
}
if( sError == pdFALSE )
{
/* If the calculation has always been correct, increment the check
variable so we know
this task is still running okay. */
( *pusTaskCheckVariable )++;
}
if( sError == pdFALSE )
{
/* If the calculation has always been correct, increment the check
* variable so we know
* this task is still running okay. */
( *pusTaskCheckVariable )++;
}
taskYIELD();
}
taskYIELD();
}
}
/*-----------------------------------------------------------*/
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 );
/* 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. */
pusTaskCheckVariable = ( unsigned short * ) pvParameters;
/* The variable this task increments to show it is still running is passed in
* as the parameter. */
pusTaskCheckVariable = ( unsigned short * ) pvParameters;
pdArray = ( portDOUBLE * ) pvPortMalloc( ( size_t ) 250 * sizeof( portDOUBLE ) );
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( ;; )
{
dTotal1 = 0.0;
dTotal2 = 0.0;
/* 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( ; ; )
{
dTotal1 = 0.0;
dTotal2 = 0.0;
for( usPosition = 0; usPosition < usArraySize; usPosition++ )
{
pdArray[ usPosition ] = ( portDOUBLE ) usPosition + 5.5;
dTotal1 += ( portDOUBLE ) usPosition + 5.5;
}
for( usPosition = 0; usPosition < usArraySize; usPosition++ )
{
pdArray[ usPosition ] = ( portDOUBLE ) usPosition + 5.5;
dTotal1 += ( portDOUBLE ) usPosition + 5.5;
}
taskYIELD();
taskYIELD();
for( usPosition = 0; usPosition < usArraySize; usPosition++ )
{
dTotal2 += pdArray[ usPosition ];
}
for( usPosition = 0; usPosition < usArraySize; usPosition++ )
{
dTotal2 += pdArray[ usPosition ];
}
dDifference = dTotal1 - dTotal2;
if( fabs( dDifference ) > 0.001 )
{
vPrintDisplayMessage( &pcTaskFailMsg );
sError = pdTRUE;
}
dDifference = dTotal1 - dTotal2;
taskYIELD();
if( fabs( dDifference ) > 0.001 )
{
vPrintDisplayMessage( &pcTaskFailMsg );
sError = pdTRUE;
}
if( sError == pdFALSE )
{
/* If the calculation has always been correct, increment the check
variable so we know this task is still running okay. */
( *pusTaskCheckVariable )++;
}
}
taskYIELD();
if( sError == pdFALSE )
{
/* If the calculation has always been correct, increment the check
* 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 );
/* 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. */
pusTaskCheckVariable = ( unsigned short * ) pvParameters;
/* The variable this task increments to show it is still running is passed in
* as the parameter. */
pusTaskCheckVariable = ( unsigned short * ) pvParameters;
pdArray = ( portDOUBLE * ) pvPortMalloc( ( size_t ) 250 * sizeof( portDOUBLE ) );
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( ;; )
{
dTotal1 = 0.0;
dTotal2 = 0.0;
/* 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( ; ; )
{
dTotal1 = 0.0;
dTotal2 = 0.0;
for( usPosition = 0; usPosition < usArraySize; usPosition++ )
{
pdArray[ usPosition ] = ( portDOUBLE ) usPosition * 12.123;
dTotal1 += ( portDOUBLE ) usPosition * 12.123;
}
for( usPosition = 0; usPosition < usArraySize; usPosition++ )
{
pdArray[ usPosition ] = ( portDOUBLE ) usPosition * 12.123;
dTotal1 += ( portDOUBLE ) usPosition * 12.123;
}
taskYIELD();
taskYIELD();
for( usPosition = 0; usPosition < usArraySize; usPosition++ )
{
dTotal2 += pdArray[ usPosition ];
}
for( usPosition = 0; usPosition < usArraySize; usPosition++ )
{
dTotal2 += pdArray[ usPosition ];
}
dDifference = dTotal1 - dTotal2;
if( fabs( dDifference ) > 0.001 )
{
vPrintDisplayMessage( &pcTaskFailMsg );
sError = pdTRUE;
}
dDifference = dTotal1 - dTotal2;
taskYIELD();
if( fabs( dDifference ) > 0.001 )
{
vPrintDisplayMessage( &pcTaskFailMsg );
sError = pdTRUE;
}
if( sError == pdFALSE )
{
/* If the calculation has always been correct, increment the check
variable so we know this task is still running okay. */
( *pusTaskCheckVariable )++;
}
}
taskYIELD();
if( sError == pdFALSE )
{
/* If the calculation has always been correct, increment the check
* variable so we know this task is still running okay. */
( *pusTaskCheckVariable )++;
}
}
}
/*-----------------------------------------------------------*/
@ -307,25 +309,22 @@ 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. */
for( xTask = 0; xTask < mathNUMBER_OF_TASKS; xTask++ )
{
if( usTaskCheck[ xTask ] == usLastTaskCheck[ xTask ] )
{
/* The check has not incremented so an error exists. */
xReturn = pdFALSE;
}
/* Check the maths tasks are still running by ensuring their check variables
* are still incrementing. */
for( xTask = 0; xTask < mathNUMBER_OF_TASKS; xTask++ )
{
if( usTaskCheck[ xTask ] == usLastTaskCheck[ xTask ] )
{
/* The check has not incremented so an error exists. */
xReturn = pdFALSE;
}
usLastTaskCheck[ xTask ] = usTaskCheck[ xTask ];
}
usLastTaskCheck[ xTask ] = usTaskCheck[ xTask ];
}
return xReturn;
return xReturn;
}

View file

@ -26,11 +26,11 @@
*/
/*
Changes from V1.2.3
+ The created tasks now include calls to tskYIELD(), allowing them to be used
with the cooperative scheduler.
*/
* Changes from V1.2.3
*
+ The created tasks now include calls to tskYIELD(), allowing them to be used
+ 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
+ The constants used in the calculations are larger to ensure the
optimiser does not truncate them to 16 bits.
*/
* Changes from V1.2.1
*
+ The constants used in the calculations are larger to ensure the
+ optimiser does not truncate them to 16 bits.
*/
#include <stdlib.h>
@ -65,240 +65,239 @@ Changes from V1.2.1
/* Demo program include files. */
#include "integer.h"
#define intgSTACK_SIZE ( ( unsigned short ) 256 )
#define intgNUMBER_OF_TASKS ( 8 )
#define intgSTACK_SIZE ( ( unsigned short ) 256 )
#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 };
/*-----------------------------------------------------------*/
void vStartIntegerMathTasks( unsigned portBASE_TYPE uxPriority )
{
xTaskCreate( vCompeteingIntMathTask1, "IntMath1", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 0 ] ), uxPriority, NULL );
xTaskCreate( vCompeteingIntMathTask2, "IntMath2", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 1 ] ), uxPriority, NULL );
xTaskCreate( vCompeteingIntMathTask3, "IntMath3", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 2 ] ), uxPriority, NULL );
xTaskCreate( vCompeteingIntMathTask4, "IntMath4", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 3 ] ), uxPriority, NULL );
xTaskCreate( vCompeteingIntMathTask1, "IntMath5", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 4 ] ), uxPriority, NULL );
xTaskCreate( vCompeteingIntMathTask2, "IntMath6", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 5 ] ), uxPriority, NULL );
xTaskCreate( vCompeteingIntMathTask3, "IntMath7", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 6 ] ), uxPriority, NULL );
xTaskCreate( vCompeteingIntMathTask4, "IntMath8", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 7 ] ), uxPriority, NULL );
xTaskCreate( vCompeteingIntMathTask1, "IntMath1", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 0 ] ), uxPriority, NULL );
xTaskCreate( vCompeteingIntMathTask2, "IntMath2", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 1 ] ), uxPriority, NULL );
xTaskCreate( vCompeteingIntMathTask3, "IntMath3", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 2 ] ), uxPriority, NULL );
xTaskCreate( vCompeteingIntMathTask4, "IntMath4", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 3 ] ), uxPriority, NULL );
xTaskCreate( vCompeteingIntMathTask1, "IntMath5", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 4 ] ), uxPriority, NULL );
xTaskCreate( vCompeteingIntMathTask2, "IntMath6", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 5 ] ), uxPriority, NULL );
xTaskCreate( vCompeteingIntMathTask3, "IntMath7", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 6 ] ), uxPriority, NULL );
xTaskCreate( vCompeteingIntMathTask4, "IntMath8", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 7 ] ), uxPriority, NULL );
}
/*-----------------------------------------------------------*/
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 );
/* 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. */
pusTaskCheckVariable = ( unsigned short * ) pvParameters;
/* The variable this task increments to show it is still running is passed in
* as the parameter. */
pusTaskCheckVariable = ( unsigned short * ) pvParameters;
/* Keep performing a calculation and checking the result against a constant. */
for(;;)
{
l1 = ( long ) 74565L;
l2 = ( long ) 1234567L;
l3 = ( long ) -918L;
/* Keep performing a calculation and checking the result against a constant. */
for( ; ; )
{
l1 = ( long ) 74565L;
l2 = ( long ) 1234567L;
l3 = ( long ) -918L;
l4 = ( l1 + l2 ) * l3;
l4 = ( l1 + l2 ) * l3;
taskYIELD();
taskYIELD();
/* If the calculation does not match the expected constant, stop the
increment of the check variable. */
if( l4 != lAnswer )
{
vPrintDisplayMessage( &pcTaskFailMsg );
sError = pdTRUE;
}
/* If the calculation does not match the expected constant, stop the
* increment of the check variable. */
if( l4 != lAnswer )
{
vPrintDisplayMessage( &pcTaskFailMsg );
sError = pdTRUE;
}
if( sError == pdFALSE )
{
/* If the calculation has always been correct, increment the check
variable so we know this task is still running okay. */
( *pusTaskCheckVariable )++;
}
}
if( sError == pdFALSE )
{
/* If the calculation has always been correct, increment the check
* 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 );
/* 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. */
pusTaskCheckVariable = ( unsigned short * ) pvParameters;
/* The variable this task increments to show it is still running is passed in
* as the parameter. */
pusTaskCheckVariable = ( unsigned short * ) pvParameters;
/* Keep performing a calculation and checking the result against a constant. */
for( ;; )
{
l1 = -389000L;
l2 = 329999L;
l3 = -89L;
/* Keep performing a calculation and checking the result against a constant. */
for( ; ; )
{
l1 = -389000L;
l2 = 329999L;
l3 = -89L;
l4 = ( l1 / l2 ) * l3;
l4 = ( l1 / l2 ) * l3;
taskYIELD();
taskYIELD();
/* If the calculation does not match the expected constant, stop the
increment of the check variable. */
if( l4 != lAnswer )
{
vPrintDisplayMessage( &pcTaskFailMsg );
sError = pdTRUE;
}
/* If the calculation does not match the expected constant, stop the
* increment of the check variable. */
if( l4 != lAnswer )
{
vPrintDisplayMessage( &pcTaskFailMsg );
sError = pdTRUE;
}
if( sError == pdFALSE )
{
/* If the calculation has always been correct, increment the check
variable so we know this task is still running okay. */
( *pusTaskCheckVariable )++;
}
}
if( sError == pdFALSE )
{
/* If the calculation has always been correct, increment the check
* 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 );
/* 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. */
pusTaskCheckVariable = ( unsigned short * ) pvParameters;
/* The variable this task increments to show it is still running is passed in
* 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 ) );
/* 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( ;; )
{
lTotal1 = ( long ) 0;
lTotal2 = ( long ) 0;
/* 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( ; ; )
{
lTotal1 = ( long ) 0;
lTotal2 = ( long ) 0;
for( usPosition = 0; usPosition < usArraySize; usPosition++ )
{
plArray[ usPosition ] = ( long ) usPosition + ( long ) 5;
lTotal1 += ( long ) usPosition + ( long ) 5;
}
for( usPosition = 0; usPosition < usArraySize; usPosition++ )
{
plArray[ usPosition ] = ( long ) usPosition + ( long ) 5;
lTotal1 += ( long ) usPosition + ( long ) 5;
}
taskYIELD();
taskYIELD();
for( usPosition = 0; usPosition < usArraySize; usPosition++ )
{
lTotal2 += plArray[ usPosition ];
}
for( usPosition = 0; usPosition < usArraySize; usPosition++ )
{
lTotal2 += plArray[ usPosition ];
}
if( lTotal1 != lTotal2 )
{
vPrintDisplayMessage( &pcTaskFailMsg );
sError = pdTRUE;
}
if( lTotal1 != lTotal2 )
{
vPrintDisplayMessage( &pcTaskFailMsg );
sError = pdTRUE;
}
taskYIELD();
taskYIELD();
if( sError == pdFALSE )
{
/* If the calculation has always been correct, increment the check
variable so we know this task is still running okay. */
( *pusTaskCheckVariable )++;
}
}
if( sError == pdFALSE )
{
/* If the calculation has always been correct, increment the check
* 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 );
/* 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. */
pusTaskCheckVariable = ( unsigned short * ) pvParameters;
/* The variable this task increments to show it is still running is passed in
* 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 ) );
/* 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( ;; )
{
lTotal1 = ( long ) 0;
lTotal2 = ( long ) 0;
/* 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( ; ; )
{
lTotal1 = ( long ) 0;
lTotal2 = ( long ) 0;
for( usPosition = 0; usPosition < usArraySize; usPosition++ )
{
plArray[ usPosition ] = ( long ) usPosition * ( long ) 12;
lTotal1 += ( long ) usPosition * ( long ) 12;
}
for( usPosition = 0; usPosition < usArraySize; usPosition++ )
{
plArray[ usPosition ] = ( long ) usPosition * ( long ) 12;
lTotal1 += ( long ) usPosition * ( long ) 12;
}
taskYIELD();
taskYIELD();
for( usPosition = 0; usPosition < usArraySize; usPosition++ )
{
lTotal2 += plArray[ usPosition ];
}
for( usPosition = 0; usPosition < usArraySize; usPosition++ )
{
lTotal2 += plArray[ usPosition ];
}
if( lTotal1 != lTotal2 )
{
vPrintDisplayMessage( &pcTaskFailMsg );
sError = pdTRUE;
}
if( lTotal1 != lTotal2 )
{
vPrintDisplayMessage( &pcTaskFailMsg );
sError = pdTRUE;
}
taskYIELD();
taskYIELD();
if( sError == pdFALSE )
{
/* If the calculation has always been correct, increment the check
variable so we know this task is still running okay. */
( *pusTaskCheckVariable )++;
}
}
if( sError == pdFALSE )
{
/* If the calculation has always been correct, increment the check
* variable so we know this task is still running okay. */
( *pusTaskCheckVariable )++;
}
}
}
/*-----------------------------------------------------------*/
@ -306,22 +305,22 @@ 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. */
for( xTask = 0; xTask < intgNUMBER_OF_TASKS; xTask++ )
{
if( usTaskCheck[ xTask ] == usLastTaskCheck[ xTask ] )
{
/* The check has not incremented so an error exists. */
xReturn = pdFALSE;
}
/* Check the maths tasks are still running by ensuring their check variables
* are still incrementing. */
for( xTask = 0; xTask < intgNUMBER_OF_TASKS; xTask++ )
{
if( usTaskCheck[ xTask ] == usLastTaskCheck[ xTask ] )
{
/* The check has not incremented so an error exists. */
xReturn = pdFALSE;
}
usLastTaskCheck[ xTask ] = usTaskCheck[ xTask ];
}
usLastTaskCheck[ xTask ] = usTaskCheck[ xTask ];
}
return xReturn;
return xReturn;
}

View file

@ -50,11 +50,11 @@
*/
/*
Changes from V2.0.0
+ Delay periods are now specified using variables and constants of
TickType_t rather than unsigned long.
*/
* Changes from V2.0.0
*
+ Delay periods are now specified using variables and constants of
+ TickType_t rather than unsigned long.
*/
#include <stdlib.h>
@ -71,36 +71,34 @@ 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 * ) );
/* Create the queue on which errors will be reported. */
xPrintQueue = xQueueCreate( uxQueueSize, ( unsigned portBASE_TYPE ) sizeof( char * ) );
}
/*-----------------------------------------------------------*/
void vPrintDisplayMessage( const char * const * ppcMessageToSend )
{
#ifdef USE_STDIO
xQueueSend( xPrintQueue, ( void * ) ppcMessageToSend, ( TickType_t ) 0 );
#else
/* Stop warnings. */
( void ) ppcMessageToSend;
#endif
#ifdef USE_STDIO
xQueueSend( xPrintQueue, ( void * ) ppcMessageToSend, ( TickType_t ) 0 );
#else
/* Stop warnings. */
( void ) ppcMessageToSend;
#endif
}
/*-----------------------------------------------------------*/
const char *pcPrintGetNextMessage( TickType_t xPrintRate )
const char * pcPrintGetNextMessage( TickType_t xPrintRate )
{
char *pcMessage;
char * pcMessage;
if( xQueueReceive( xPrintQueue, &pcMessage, xPrintRate ) == pdPASS )
{
return pcMessage;
}
else
{
return NULL;
}
if( xQueueReceive( xPrintQueue, &pcMessage, xPrintRate ) == pdPASS )
{
return pcMessage;
}
else
{
return NULL;
}
}

View file

@ -52,24 +52,24 @@
*/
/*
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
+ Delay periods are now specified using variables and constants of
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.
*/
* 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
+
+ Delay periods are now specified using variables and constants of
+ 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>
@ -83,24 +83,24 @@ Changes from V2.1.1
#include "print.h"
/* The value to which the shared variables are counted. */
#define semtstBLOCKING_EXPECTED_VALUE ( ( unsigned long ) 0xfff )
#define semtstNON_BLOCKING_EXPECTED_VALUE ( ( unsigned long ) 0xff )
#define semtstBLOCKING_EXPECTED_VALUE ( ( unsigned long ) 0xfff )
#define semtstNON_BLOCKING_EXPECTED_VALUE ( ( unsigned long ) 0xff )
#define semtstSTACK_SIZE configMINIMAL_STACK_SIZE
#define semtstSTACK_SIZE configMINIMAL_STACK_SIZE
#define semtstNUM_TASKS ( 4 )
#define semtstNUM_TASKS ( 4 )
#define semtstDELAY_FACTOR ( ( TickType_t ) 10 )
#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;
TickType_t xBlockTime;
SemaphoreHandle_t xSemaphore;
volatile unsigned long * pulSharedVariable;
TickType_t xBlockTime;
} xSemaphoreParameters;
/* Variables used to check that all the tasks are still running without errors. */
@ -115,171 +115,172 @@ 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 ) );
/* Create the structure used to pass parameters to the first two tasks. */
pxFirstSemaphoreParameters = ( xSemaphoreParameters * ) pvPortMalloc( sizeof( xSemaphoreParameters ) );
if( pxFirstSemaphoreParameters != NULL )
{
/* Create the semaphore used by the first two tasks. */
vSemaphoreCreateBinary( pxFirstSemaphoreParameters->xSemaphore );
if( pxFirstSemaphoreParameters != NULL )
{
/* Create the semaphore used by the first two tasks. */
vSemaphoreCreateBinary( pxFirstSemaphoreParameters->xSemaphore );
if( pxFirstSemaphoreParameters->xSemaphore != NULL )
{
/* Create the variable which is to be shared by the first two tasks. */
pxFirstSemaphoreParameters->pulSharedVariable = ( unsigned long * ) pvPortMalloc( sizeof( unsigned long ) );
if( pxFirstSemaphoreParameters->xSemaphore != NULL )
{
/* Create the variable which is to be shared by the first two tasks. */
pxFirstSemaphoreParameters->pulSharedVariable = ( unsigned long * ) pvPortMalloc( sizeof( unsigned long ) );
/* Initialise the share variable to the value the tasks expect. */
*( pxFirstSemaphoreParameters->pulSharedVariable ) = semtstNON_BLOCKING_EXPECTED_VALUE;
/* Initialise the share variable to the value the tasks expect. */
*( pxFirstSemaphoreParameters->pulSharedVariable ) = semtstNON_BLOCKING_EXPECTED_VALUE;
/* The first two tasks do not block on semaphore calls. */
pxFirstSemaphoreParameters->xBlockTime = ( TickType_t ) 0;
/* The first two tasks do not block on semaphore calls. */
pxFirstSemaphoreParameters->xBlockTime = ( TickType_t ) 0;
/* Spawn the first two tasks. As they poll they operate at the idle priority. */
xTaskCreate( prvSemaphoreTest, "PolSEM1", semtstSTACK_SIZE, ( void * ) pxFirstSemaphoreParameters, tskIDLE_PRIORITY, ( TaskHandle_t * ) NULL );
xTaskCreate( prvSemaphoreTest, "PolSEM2", semtstSTACK_SIZE, ( void * ) pxFirstSemaphoreParameters, tskIDLE_PRIORITY, ( TaskHandle_t * ) NULL );
}
}
/* Spawn the first two tasks. As they poll they operate at the idle priority. */
xTaskCreate( prvSemaphoreTest, "PolSEM1", semtstSTACK_SIZE, ( void * ) pxFirstSemaphoreParameters, tskIDLE_PRIORITY, ( TaskHandle_t * ) NULL );
xTaskCreate( prvSemaphoreTest, "PolSEM2", semtstSTACK_SIZE, ( void * ) pxFirstSemaphoreParameters, tskIDLE_PRIORITY, ( TaskHandle_t * ) NULL );
}
}
/* Do exactly the same to create the second set of tasks, only this time
provide a block time for the semaphore calls. */
pxSecondSemaphoreParameters = ( xSemaphoreParameters * ) pvPortMalloc( sizeof( xSemaphoreParameters ) );
if( pxSecondSemaphoreParameters != NULL )
{
vSemaphoreCreateBinary( pxSecondSemaphoreParameters->xSemaphore );
/* Do exactly the same to create the second set of tasks, only this time
* provide a block time for the semaphore calls. */
pxSecondSemaphoreParameters = ( xSemaphoreParameters * ) pvPortMalloc( sizeof( xSemaphoreParameters ) );
if( pxSecondSemaphoreParameters->xSemaphore != NULL )
{
pxSecondSemaphoreParameters->pulSharedVariable = ( unsigned long * ) pvPortMalloc( sizeof( unsigned long ) );
*( pxSecondSemaphoreParameters->pulSharedVariable ) = semtstBLOCKING_EXPECTED_VALUE;
pxSecondSemaphoreParameters->xBlockTime = xBlockTime / portTICK_PERIOD_MS;
if( pxSecondSemaphoreParameters != NULL )
{
vSemaphoreCreateBinary( pxSecondSemaphoreParameters->xSemaphore );
xTaskCreate( prvSemaphoreTest, "BlkSEM1", semtstSTACK_SIZE, ( void * ) pxSecondSemaphoreParameters, uxPriority, ( TaskHandle_t * ) NULL );
xTaskCreate( prvSemaphoreTest, "BlkSEM2", semtstSTACK_SIZE, ( void * ) pxSecondSemaphoreParameters, uxPriority, ( TaskHandle_t * ) NULL );
}
}
if( pxSecondSemaphoreParameters->xSemaphore != NULL )
{
pxSecondSemaphoreParameters->pulSharedVariable = ( unsigned long * ) pvPortMalloc( sizeof( unsigned long ) );
*( pxSecondSemaphoreParameters->pulSharedVariable ) = semtstBLOCKING_EXPECTED_VALUE;
pxSecondSemaphoreParameters->xBlockTime = xBlockTime / portTICK_PERIOD_MS;
xTaskCreate( prvSemaphoreTest, "BlkSEM1", semtstSTACK_SIZE, ( void * ) pxSecondSemaphoreParameters, uxPriority, ( TaskHandle_t * ) NULL );
xTaskCreate( prvSemaphoreTest, "BlkSEM2", semtstSTACK_SIZE, ( void * ) pxSecondSemaphoreParameters, uxPriority, ( TaskHandle_t * ) NULL );
}
}
}
/*-----------------------------------------------------------*/
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! */
portENTER_CRITICAL();
sCheckVariableToUse = sNextCheckVariable;
sNextCheckVariable++;
portEXIT_CRITICAL();
/* See which check variable to use. sNextCheckVariable is not semaphore
* protected! */
portENTER_CRITICAL();
sCheckVariableToUse = sNextCheckVariable;
sNextCheckVariable++;
portEXIT_CRITICAL();
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcSemaphoreTaskStart );
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcSemaphoreTaskStart );
/* A structure is passed in as the parameter. This contains the shared
variable being guarded. */
pxParameters = ( xSemaphoreParameters * ) pvParameters;
pulSharedVariable = pxParameters->pulSharedVariable;
/* A structure is passed in as the parameter. This contains the shared
* 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. */
if( pxParameters->xBlockTime > ( TickType_t ) 0 )
{
ulExpectedValue = semtstBLOCKING_EXPECTED_VALUE;
}
else
{
ulExpectedValue = semtstNON_BLOCKING_EXPECTED_VALUE;
}
/* If we are blocking we use a much higher count to ensure loads of context
* switches occur during the count. */
if( pxParameters->xBlockTime > ( TickType_t ) 0 )
{
ulExpectedValue = semtstBLOCKING_EXPECTED_VALUE;
}
else
{
ulExpectedValue = semtstNON_BLOCKING_EXPECTED_VALUE;
}
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. */
if( *pulSharedVariable != ulExpectedValue )
{
vPrintDisplayMessage( &pcPollingSemaphoreTaskError );
sError = pdTRUE;
}
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. */
if( *pulSharedVariable != ulExpectedValue )
{
vPrintDisplayMessage( &pcPollingSemaphoreTaskError );
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. */
for( ulCounter = ( unsigned long ) 0; ulCounter <= ulExpectedValue; ulCounter++ )
{
*pulSharedVariable = ulCounter;
if( *pulSharedVariable != ulCounter )
{
if( sError == pdFALSE )
{
vPrintDisplayMessage( &pcPollingSemaphoreTaskError );
}
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. */
for( ulCounter = ( unsigned long ) 0; ulCounter <= ulExpectedValue; ulCounter++ )
{
*pulSharedVariable = ulCounter;
/* Release the semaphore, and if no errors have occurred increment the check
variable. */
if( xSemaphoreGive( pxParameters->xSemaphore ) == pdFALSE )
{
vPrintDisplayMessage( &pcPollingSemaphoreTaskError );
sError = pdTRUE;
}
if( *pulSharedVariable != ulCounter )
{
if( sError == pdFALSE )
{
vPrintDisplayMessage( &pcPollingSemaphoreTaskError );
}
if( sError == pdFALSE )
{
if( sCheckVariableToUse < semtstNUM_TASKS )
{
( sCheckVariables[ sCheckVariableToUse ] )++;
}
}
sError = pdTRUE;
}
}
/* 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. */
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. */
taskYIELD();
}
}
}
/* Release the semaphore, and if no errors have occurred increment the check
* variable. */
if( xSemaphoreGive( pxParameters->xSemaphore ) == pdFALSE )
{
vPrintDisplayMessage( &pcPollingSemaphoreTaskError );
sError = pdTRUE;
}
if( sError == pdFALSE )
{
if( sCheckVariableToUse < semtstNUM_TASKS )
{
( sCheckVariables[ 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. */
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. */
taskYIELD();
}
}
}
}
/*-----------------------------------------------------------*/
/* 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++ )
{
if( sLastCheckVariables[ xTask ] == sCheckVariables[ xTask ] )
{
xReturn = pdFALSE;
}
for( xTask = 0; xTask < semtstNUM_TASKS; xTask++ )
{
if( sLastCheckVariables[ xTask ] == sCheckVariables[ xTask ] )
{
xReturn = pdFALSE;
}
sLastCheckVariables[ xTask ] = sCheckVariables[ xTask ];
}
sLastCheckVariables[ xTask ] = sCheckVariables[ xTask ];
}
return xReturn;
return xReturn;
}

File diff suppressed because it is too large Load diff

View file

@ -59,232 +59,232 @@
/* Demo program include files. */
#include "BlockQ.h"
#define blckqSTACK_SIZE configMINIMAL_STACK_SIZE
#define blckqNUM_TASK_SETS ( 3 )
#define blckqSTACK_SIZE configMINIMAL_STACK_SIZE
#define blckqNUM_TASK_SETS ( 3 )
#if( configSUPPORT_DYNAMIC_ALLOCATION == 0 )
#error This example cannot be used if dynamic allocation is not allowed.
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 0 )
#error This example cannot be used if dynamic allocation is not allowed.
#endif
/* Structure used to pass parameters to the blocking queue tasks. */
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. */
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. */
} 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. */
/* Create the first two tasks as described at the top of the file. */
/* First create the structure used to pass parameters to the consumer tasks. */
pxQueueParameters1 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
/* First create the structure used to pass parameters to the consumer tasks. */
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. */
pxQueueParameters1->xQueue = xQueueCreate( uxQueueSize1, ( UBaseType_t ) sizeof( uint16_t ) );
/* Create the queue used by the first two tasks to pass the incrementing number.
* 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;
/* 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. */
pxQueueParameters1->psCheckVariable = &( sBlockingConsumerCount[ 0 ] );
/* Pass in the variable that this task is going to increment so we can check it
* is still running. */
pxQueueParameters1->psCheckVariable = &( sBlockingConsumerCount[ 0 ] );
/* Create the structure used to pass parameters to the producer task. */
pxQueueParameters2 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
/* Create the structure used to pass parameters to the producer task. */
pxQueueParameters2 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
/* Pass the queue to this task also, using the parameter structure. */
pxQueueParameters2->xQueue = pxQueueParameters1->xQueue;
/* Pass the queue to this task also, using the parameter structure. */
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. */
pxQueueParameters2->xBlockTime = xDontBlock;
/* 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. */
pxQueueParameters2->xBlockTime = xDontBlock;
/* Pass in the variable that this task is going to increment so we can check
it is still running. */
pxQueueParameters2->psCheckVariable = &( sBlockingProducerCount[ 0 ] );
/* Pass in the variable that this task is going to increment so we can check
* it is still running. */
pxQueueParameters2->psCheckVariable = &( sBlockingProducerCount[ 0 ] );
/* Note the producer has a lower priority than the consumer when the tasks are
spawned. */
xTaskCreate( vBlockingQueueConsumer, "QConsB1", blckqSTACK_SIZE, ( void * ) pxQueueParameters1, uxPriority, NULL );
xTaskCreate( vBlockingQueueProducer, "QProdB2", blckqSTACK_SIZE, ( void * ) pxQueueParameters2, tskIDLE_PRIORITY, NULL );
/* Note the producer has a lower priority than the consumer when the tasks are
* 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. */
/* Create the second two tasks as described at the top of the file. This uses
* the same mechanism but reverses the task priorities. */
pxQueueParameters3 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
pxQueueParameters3->xQueue = xQueueCreate( uxQueueSize1, ( UBaseType_t ) sizeof( uint16_t ) );
pxQueueParameters3->xBlockTime = xDontBlock;
pxQueueParameters3->psCheckVariable = &( sBlockingProducerCount[ 1 ] );
pxQueueParameters3 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
pxQueueParameters3->xQueue = xQueueCreate( uxQueueSize1, ( UBaseType_t ) sizeof( uint16_t ) );
pxQueueParameters3->xBlockTime = xDontBlock;
pxQueueParameters3->psCheckVariable = &( sBlockingProducerCount[ 1 ] );
pxQueueParameters4 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
pxQueueParameters4->xQueue = pxQueueParameters3->xQueue;
pxQueueParameters4->xBlockTime = xBlockTime;
pxQueueParameters4->psCheckVariable = &( sBlockingConsumerCount[ 1 ] );
pxQueueParameters4 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
pxQueueParameters4->xQueue = pxQueueParameters3->xQueue;
pxQueueParameters4->xBlockTime = xBlockTime;
pxQueueParameters4->psCheckVariable = &( sBlockingConsumerCount[ 1 ] );
xTaskCreate( vBlockingQueueConsumer, "QConsB3", blckqSTACK_SIZE, ( void * ) pxQueueParameters3, tskIDLE_PRIORITY, NULL );
xTaskCreate( vBlockingQueueProducer, "QProdB4", blckqSTACK_SIZE, ( void * ) pxQueueParameters4, uxPriority, NULL );
xTaskCreate( vBlockingQueueConsumer, "QConsB3", blckqSTACK_SIZE, ( void * ) pxQueueParameters3, tskIDLE_PRIORITY, NULL );
xTaskCreate( vBlockingQueueProducer, "QProdB4", blckqSTACK_SIZE, ( void * ) pxQueueParameters4, uxPriority, NULL );
/* 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. */
pxQueueParameters5 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
pxQueueParameters5->xQueue = xQueueCreate( uxQueueSize5, ( UBaseType_t ) sizeof( uint16_t ) );
pxQueueParameters5->xBlockTime = xBlockTime;
pxQueueParameters5->psCheckVariable = &( sBlockingProducerCount[ 2 ] );
/* 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. */
pxQueueParameters5 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
pxQueueParameters5->xQueue = xQueueCreate( uxQueueSize5, ( UBaseType_t ) sizeof( uint16_t ) );
pxQueueParameters5->xBlockTime = xBlockTime;
pxQueueParameters5->psCheckVariable = &( sBlockingProducerCount[ 2 ] );
pxQueueParameters6 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
pxQueueParameters6->xQueue = pxQueueParameters5->xQueue;
pxQueueParameters6->xBlockTime = xBlockTime;
pxQueueParameters6->psCheckVariable = &( sBlockingConsumerCount[ 2 ] );
pxQueueParameters6 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
pxQueueParameters6->xQueue = pxQueueParameters5->xQueue;
pxQueueParameters6->xBlockTime = xBlockTime;
pxQueueParameters6->psCheckVariable = &( sBlockingConsumerCount[ 2 ] );
xTaskCreate( vBlockingQueueProducer, "QProdB5", blckqSTACK_SIZE, ( void * ) pxQueueParameters5, tskIDLE_PRIORITY, NULL );
xTaskCreate( vBlockingQueueConsumer, "QConsB6", blckqSTACK_SIZE, ( void * ) pxQueueParameters6, tskIDLE_PRIORITY, NULL );
xTaskCreate( vBlockingQueueProducer, "QProdB5", blckqSTACK_SIZE, ( void * ) pxQueueParameters5, tskIDLE_PRIORITY, NULL );
xTaskCreate( vBlockingQueueConsumer, "QConsB6", blckqSTACK_SIZE, ( void * ) pxQueueParameters6, tskIDLE_PRIORITY, NULL );
}
/*-----------------------------------------------------------*/
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;
pxQueueParameters = ( xBlockingQueueParameters * ) pvParameters;
for( ;; )
{
if( xQueueSend( pxQueueParameters->xQueue, ( void * ) &usValue, pxQueueParameters->xBlockTime ) != pdPASS )
{
sErrorEverOccurred = pdTRUE;
}
else
{
/* We have successfully posted a message, so increment the variable
used to check we are still running. */
if( sErrorEverOccurred == pdFALSE )
{
( *pxQueueParameters->psCheckVariable )++;
}
for( ; ; )
{
if( xQueueSend( pxQueueParameters->xQueue, ( void * ) &usValue, pxQueueParameters->xBlockTime ) != pdPASS )
{
sErrorEverOccurred = pdTRUE;
}
else
{
/* We have successfully posted a message, so increment the variable
* 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. */
++usValue;
/* Increment the variable we are going to post next time round. The
* consumer will expect the numbers to follow in numerical order. */
++usValue;
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
}
}
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
}
}
}
/*-----------------------------------------------------------*/
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;
pxQueueParameters = ( xBlockingQueueParameters * ) pvParameters;
for( ;; )
{
if( xQueueReceive( pxQueueParameters->xQueue, &usData, pxQueueParameters->xBlockTime ) == pdPASS )
{
if( usData != usExpectedValue )
{
/* Catch-up. */
usExpectedValue = usData;
for( ; ; )
{
if( xQueueReceive( pxQueueParameters->xQueue, &usData, pxQueueParameters->xBlockTime ) == pdPASS )
{
if( usData != usExpectedValue )
{
/* Catch-up. */
usExpectedValue = usData;
sErrorEverOccurred = pdTRUE;
}
else
{
/* We have successfully received a message, so increment the
variable used to check we are still running. */
if( sErrorEverOccurred == pdFALSE )
{
( *pxQueueParameters->psCheckVariable )++;
}
sErrorEverOccurred = pdTRUE;
}
else
{
/* We have successfully received a message, so increment the
* 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. */
++usExpectedValue;
}
/* Increment the value we expect to remove from the queue next time
* round. */
++usExpectedValue;
}
#if configUSE_PREEMPTION == 0
{
if( pxQueueParameters->xBlockTime == 0 )
{
taskYIELD();
}
}
#endif
}
}
#if configUSE_PREEMPTION == 0
{
if( pxQueueParameters->xBlockTime == 0 )
{
taskYIELD();
}
}
#endif
}
}
}
/*-----------------------------------------------------------*/
/* 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.
/* 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. */
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++ )
{
if( sBlockingConsumerCount[ xTasks ] == sLastBlockingConsumerCount[ xTasks ] )
{
xReturn = pdFALSE;
}
for( xTasks = 0; xTasks < blckqNUM_TASK_SETS; xTasks++ )
{
if( sBlockingConsumerCount[ xTasks ] == sLastBlockingConsumerCount[ xTasks ] )
{
xReturn = pdFALSE;
}
sLastBlockingConsumerCount[ xTasks ] = sBlockingConsumerCount[ xTasks ];
sLastBlockingConsumerCount[ xTasks ] = sBlockingConsumerCount[ xTasks ];
if( sBlockingProducerCount[ xTasks ] == sLastBlockingProducerCount[ xTasks ] )
{
xReturn = pdFALSE;
}
if( sBlockingProducerCount[ xTasks ] == sLastBlockingProducerCount[ xTasks ] )
{
xReturn = pdFALSE;
}
sLastBlockingProducerCount[ xTasks ] = sBlockingProducerCount[ xTasks ];
}
sLastBlockingProducerCount[ xTasks ] = sBlockingProducerCount[ xTasks ];
}
return xReturn;
return xReturn;
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -44,18 +44,18 @@
/*-----------------------------------------------------------*/
/* The priorities of the test tasks. */
#define intsemMASTER_PRIORITY ( tskIDLE_PRIORITY )
#define intsemSLAVE_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define intsemMASTER_PRIORITY ( tskIDLE_PRIORITY )
#define intsemSLAVE_PRIORITY ( tskIDLE_PRIORITY + 1 )
/* The rate at which the tick hook will give the mutex. */
#define intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS ( 100 )
#define intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS ( 100 )
/* A block time of 0 means 'don't block'. */
#define intsemNO_BLOCK 0
#define intsemNO_BLOCK 0
/* The maximum count value for the counting semaphore given from an
interrupt. */
#define intsemMAX_COUNT 3
* 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. */
@ -130,396 +130,402 @@ const TickType_t xInterruptGivePeriod = pdMS_TO_TICKS( intsemINTERRUPT_MUTEX_GIV
void vStartInterruptSemaphoreTasks( void )
{
/* Create the semaphores that are given from an interrupt. */
xISRMutex = xSemaphoreCreateMutex();
configASSERT( xISRMutex );
xISRCountingSemaphore = xSemaphoreCreateCounting( intsemMAX_COUNT, 0 );
configASSERT( xISRCountingSemaphore );
/* Create the semaphores that are given from an interrupt. */
xISRMutex = xSemaphoreCreateMutex();
configASSERT( xISRMutex );
xISRCountingSemaphore = xSemaphoreCreateCounting( intsemMAX_COUNT, 0 );
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. */
xMasterSlaveMutex = xSemaphoreCreateMutex();
configASSERT( xMasterSlaveMutex );
/* 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. */
xMasterSlaveMutex = xSemaphoreCreateMutex();
configASSERT( xMasterSlaveMutex );
/* Create the tasks that share mutexes between then and with interrupts. */
xTaskCreate( vInterruptMutexSlaveTask, "IntMuS", configMINIMAL_STACK_SIZE, NULL, intsemSLAVE_PRIORITY, &xSlaveHandle );
xTaskCreate( vInterruptMutexMasterTask, "IntMuM", configMINIMAL_STACK_SIZE, NULL, intsemMASTER_PRIORITY, NULL );
/* Create the tasks that share mutexes between then and with interrupts. */
xTaskCreate( vInterruptMutexSlaveTask, "IntMuS", configMINIMAL_STACK_SIZE, NULL, intsemSLAVE_PRIORITY, &xSlaveHandle );
xTaskCreate( vInterruptMutexMasterTask, "IntMuM", configMINIMAL_STACK_SIZE, NULL, intsemMASTER_PRIORITY, NULL );
/* Create the task that blocks on the counting semaphore. */
xTaskCreate( vInterruptCountingSemaphoreTask, "IntCnt", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
/* Create the task that blocks on the counting semaphore. */
xTaskCreate( vInterruptCountingSemaphoreTask, "IntCnt", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
}
/*-----------------------------------------------------------*/
static void vInterruptMutexMasterTask( void *pvParameters )
static void vInterruptMutexMasterTask( void * pvParameters )
{
/* Just to avoid compiler warnings. */
( void ) pvParameters;
/* Just to avoid compiler warnings. */
( void ) pvParameters;
for( ;; )
{
prvTakeAndGiveInTheSameOrder();
for( ; ; )
{
prvTakeAndGiveInTheSameOrder();
/* Ensure not to starve out other tests. */
ulMasterLoops++;
vTaskDelay( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS );
/* Ensure not to starve out other tests. */
ulMasterLoops++;
vTaskDelay( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS );
prvTakeAndGiveInTheOppositeOrder();
prvTakeAndGiveInTheOppositeOrder();
/* Ensure not to starve out other tests. */
ulMasterLoops++;
vTaskDelay( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS );
}
/* Ensure not to starve out other tests. */
ulMasterLoops++;
vTaskDelay( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS );
}
}
/*-----------------------------------------------------------*/
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 )
{
configASSERT( eTaskGetState( xSlaveHandle ) == eSuspended );
}
#endif /* INCLUDE_eTaskGetState */
/* 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 )
{
configASSERT( eTaskGetState( xSlaveHandle ) == eSuspended );
}
#endif /* INCLUDE_eTaskGetState */
if( uxTaskPriorityGet( NULL ) != intsemMASTER_PRIORITY )
{
xErrorDetected = pdTRUE;
}
if( uxTaskPriorityGet( NULL ) != intsemMASTER_PRIORITY )
{
xErrorDetected = pdTRUE;
}
/* Take the semaphore that is shared with the slave. */
if( xSemaphoreTake( xMasterSlaveMutex, intsemNO_BLOCK ) != pdPASS )
{
xErrorDetected = pdTRUE;
}
/* Take the semaphore that is shared with the slave. */
if( xSemaphoreTake( xMasterSlaveMutex, intsemNO_BLOCK ) != pdPASS )
{
xErrorDetected = pdTRUE;
}
/* This task now has the mutex. Unsuspend the slave so it too
attempts to take the mutex. */
vTaskResume( xSlaveHandle );
/* This task now has the mutex. Unsuspend the slave so it too
* 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 )
{
configASSERT( eTaskGetState( xSlaveHandle ) == eBlocked );
}
#endif /* INCLUDE_eTaskGetState */
/* The slave has the higher priority so should now have executed and
* 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. */
if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )
{
xErrorDetected = pdTRUE;
}
/* This task should now have inherited the priority of the slave
* 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. */
xOkToGiveMutex = pdTRUE;
if( xSemaphoreTake( xISRMutex, ( xInterruptGivePeriod * 2 ) ) != pdPASS )
{
xErrorDetected = pdTRUE;
}
xOkToGiveMutex = pdFALSE;
/* Now wait a little longer than the time between ISR gives to also
* obtain the ISR mutex. */
xOkToGiveMutex = pdTRUE;
/* Attempting to take again immediately should fail as the mutex is
already held. */
if( xSemaphoreTake( xISRMutex, intsemNO_BLOCK ) != pdFAIL )
{
xErrorDetected = pdTRUE;
}
if( xSemaphoreTake( xISRMutex, ( xInterruptGivePeriod * 2 ) ) != pdPASS )
{
xErrorDetected = pdTRUE;
}
/* Should still be at the priority of the slave task. */
if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )
{
xErrorDetected = pdTRUE;
}
xOkToGiveMutex = pdFALSE;
/* 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. */
if( xSemaphoreGive( xISRMutex ) != pdPASS )
{
xErrorDetected = pdTRUE;
}
/* Attempting to take again immediately should fail as the mutex is
* already held. */
if( xSemaphoreTake( xISRMutex, intsemNO_BLOCK ) != pdFAIL )
{
xErrorDetected = pdTRUE;
}
if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )
{
xErrorDetected = pdTRUE;
}
/* Should still be at the priority of the slave task. */
if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )
{
xErrorDetected = pdTRUE;
}
/* 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. */
if( xSemaphoreGive( xMasterSlaveMutex ) != pdPASS )
{
xErrorDetected = pdTRUE;
}
/* 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. */
if( xSemaphoreGive( xISRMutex ) != pdPASS )
{
xErrorDetected = pdTRUE;
}
if( uxTaskPriorityGet( NULL ) != intsemMASTER_PRIORITY )
{
xErrorDetected = pdTRUE;
}
if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )
{
xErrorDetected = pdTRUE;
}
#if( INCLUDE_eTaskGetState == 1 )
{
configASSERT( eTaskGetState( xSlaveHandle ) == eSuspended );
}
#endif /* INCLUDE_eTaskGetState */
/* 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. */
if( xSemaphoreGive( xMasterSlaveMutex ) != pdPASS )
{
xErrorDetected = pdTRUE;
}
/* Reset the mutex ready for the next round. */
xQueueReset( xISRMutex );
if( uxTaskPriorityGet( NULL ) != intsemMASTER_PRIORITY )
{
xErrorDetected = pdTRUE;
}
#if ( INCLUDE_eTaskGetState == 1 )
{
configASSERT( eTaskGetState( xSlaveHandle ) == eSuspended );
}
#endif /* INCLUDE_eTaskGetState */
/* Reset the mutex ready for the next round. */
xQueueReset( xISRMutex );
}
/*-----------------------------------------------------------*/
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 )
{
configASSERT( eTaskGetState( xSlaveHandle ) == eSuspended );
}
#endif /* INCLUDE_eTaskGetState */
/* 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 )
{
configASSERT( eTaskGetState( xSlaveHandle ) == eSuspended );
}
#endif /* INCLUDE_eTaskGetState */
if( uxTaskPriorityGet( NULL ) != intsemMASTER_PRIORITY )
{
xErrorDetected = pdTRUE;
}
if( uxTaskPriorityGet( NULL ) != intsemMASTER_PRIORITY )
{
xErrorDetected = pdTRUE;
}
/* Take the semaphore that is shared with the slave. */
if( xSemaphoreTake( xMasterSlaveMutex, intsemNO_BLOCK ) != pdPASS )
{
xErrorDetected = pdTRUE;
}
/* Take the semaphore that is shared with the slave. */
if( xSemaphoreTake( xMasterSlaveMutex, intsemNO_BLOCK ) != pdPASS )
{
xErrorDetected = pdTRUE;
}
/* This task now has the mutex. Unsuspend the slave so it too
attempts to take the mutex. */
vTaskResume( xSlaveHandle );
/* This task now has the mutex. Unsuspend the slave so it too
* 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 )
{
configASSERT( eTaskGetState( xSlaveHandle ) == eBlocked );
}
#endif /* INCLUDE_eTaskGetState */
/* The slave has the higher priority so should now have executed and
* 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. */
if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )
{
xErrorDetected = pdTRUE;
}
/* This task should now have inherited the priority of the slave
* 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. */
xOkToGiveMutex = pdTRUE;
if( xSemaphoreTake( xISRMutex, ( xInterruptGivePeriod * 2 ) ) != pdPASS )
{
xErrorDetected = pdTRUE;
}
xOkToGiveMutex = pdFALSE;
/* Now wait a little longer than the time between ISR gives to also
* obtain the ISR mutex. */
xOkToGiveMutex = pdTRUE;
/* Attempting to take again immediately should fail as the mutex is
already held. */
if( xSemaphoreTake( xISRMutex, intsemNO_BLOCK ) != pdFAIL )
{
xErrorDetected = pdTRUE;
}
if( xSemaphoreTake( xISRMutex, ( xInterruptGivePeriod * 2 ) ) != pdPASS )
{
xErrorDetected = pdTRUE;
}
/* Should still be at the priority of the slave task. */
if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )
{
xErrorDetected = pdTRUE;
}
xOkToGiveMutex = pdFALSE;
/* 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. */
if( xSemaphoreGive( xMasterSlaveMutex ) != pdPASS )
{
xErrorDetected = pdTRUE;
}
/* Attempting to take again immediately should fail as the mutex is
* already held. */
if( xSemaphoreTake( xISRMutex, intsemNO_BLOCK ) != pdFAIL )
{
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. */
if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )
{
xErrorDetected = pdTRUE;
}
/* Should still be at the priority of the slave task. */
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. */
if( xSemaphoreGive( xISRMutex ) != pdPASS )
{
xErrorDetected = pdTRUE;
}
/* 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. */
if( xSemaphoreGive( xMasterSlaveMutex ) != pdPASS )
{
xErrorDetected = pdTRUE;
}
if( uxTaskPriorityGet( NULL ) != intsemMASTER_PRIORITY )
{
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. */
if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )
{
xErrorDetected = pdTRUE;
}
/* Reset the mutex ready for the next round. */
xQueueReset( xISRMutex );
/* Give back the ISR semaphore, which should result in the priority being
* disinherited as it was the last mutex held. */
if( xSemaphoreGive( xISRMutex ) != pdPASS )
{
xErrorDetected = pdTRUE;
}
if( uxTaskPriorityGet( NULL ) != intsemMASTER_PRIORITY )
{
xErrorDetected = pdTRUE;
}
/* Reset the mutex ready for the next round. */
xQueueReset( xISRMutex );
}
/*-----------------------------------------------------------*/
static void vInterruptMutexSlaveTask( void *pvParameters )
static void vInterruptMutexSlaveTask( void * pvParameters )
{
/* Just to avoid compiler warnings. */
( void ) pvParameters;
/* Just to avoid compiler warnings. */
( void ) pvParameters;
for( ;; )
{
/* This task starts by suspending itself so when it executes can be
controlled by the master task. */
vTaskSuspend( NULL );
for( ; ; )
{
/* This task starts by suspending itself so when it executes can be
* 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. */
if( xSemaphoreTake( xMasterSlaveMutex, portMAX_DELAY ) != pdPASS )
{
xErrorDetected = pdTRUE;
}
/* 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. */
if( xSemaphoreTake( xMasterSlaveMutex, portMAX_DELAY ) != pdPASS )
{
xErrorDetected = pdTRUE;
}
if( xSemaphoreGive( xMasterSlaveMutex ) != pdPASS )
{
xErrorDetected = pdTRUE;
}
}
if( xSemaphoreGive( xMasterSlaveMutex ) != pdPASS )
{
xErrorDetected = pdTRUE;
}
}
}
/*-----------------------------------------------------------*/
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;
( void ) pvParameters;
for( ;; )
{
/* Expect to start with the counting semaphore empty. */
if( uxQueueMessagesWaiting( ( QueueHandle_t ) xISRCountingSemaphore ) != 0 )
{
xErrorDetected = pdTRUE;
}
for( ; ; )
{
/* Expect to start with the counting semaphore empty. */
if( uxQueueMessagesWaiting( ( QueueHandle_t ) xISRCountingSemaphore ) != 0 )
{
xErrorDetected = pdTRUE;
}
/* Wait until it is expected that the interrupt will have filled the
counting semaphore. */
xOkToGiveCountingSemaphore = pdTRUE;
vTaskDelay( xDelay );
xOkToGiveCountingSemaphore = pdFALSE;
/* Wait until it is expected that the interrupt will have filled the
* counting semaphore. */
xOkToGiveCountingSemaphore = pdTRUE;
vTaskDelay( xDelay );
xOkToGiveCountingSemaphore = pdFALSE;
/* Now it is expected that the counting semaphore is full. */
if( uxQueueMessagesWaiting( ( QueueHandle_t ) xISRCountingSemaphore ) != intsemMAX_COUNT )
{
xErrorDetected = pdTRUE;
}
/* Now it is expected that the counting semaphore is full. */
if( uxQueueMessagesWaiting( ( QueueHandle_t ) xISRCountingSemaphore ) != intsemMAX_COUNT )
{
xErrorDetected = pdTRUE;
}
if( uxQueueSpacesAvailable( ( QueueHandle_t ) xISRCountingSemaphore ) != 0 )
{
xErrorDetected = pdTRUE;
}
if( uxQueueSpacesAvailable( ( QueueHandle_t ) xISRCountingSemaphore ) != 0 )
{
xErrorDetected = pdTRUE;
}
ulCountingSemaphoreLoops++;
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. */
xCount = 0;
while( xSemaphoreTake( xISRCountingSemaphore, 0 ) == pdPASS )
{
xCount++;
}
/* 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. */
xCount = 0;
if( xCount != intsemMAX_COUNT )
{
xErrorDetected = pdTRUE;
}
while( xSemaphoreTake( xISRCountingSemaphore, 0 ) == pdPASS )
{
xCount++;
}
/* Now raise the priority of this task so it runs immediately that the
semaphore is given from the interrupt. */
vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );
if( xCount != intsemMAX_COUNT )
{
xErrorDetected = pdTRUE;
}
/* Block to wait for the semaphore to be given from the interrupt. */
xOkToGiveCountingSemaphore = pdTRUE;
xSemaphoreTake( xISRCountingSemaphore, portMAX_DELAY );
xSemaphoreTake( xISRCountingSemaphore, portMAX_DELAY );
xOkToGiveCountingSemaphore = pdFALSE;
/* Now raise the priority of this task so it runs immediately that the
* semaphore is given from the interrupt. */
vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );
/* Reset the priority so as not to disturbe other tests too much. */
vTaskPrioritySet( NULL, tskIDLE_PRIORITY );
/* Block to wait for the semaphore to be given from the interrupt. */
xOkToGiveCountingSemaphore = pdTRUE;
xSemaphoreTake( xISRCountingSemaphore, portMAX_DELAY );
xSemaphoreTake( xISRCountingSemaphore, portMAX_DELAY );
xOkToGiveCountingSemaphore = pdFALSE;
ulCountingSemaphoreLoops++;
}
/* Reset the priority so as not to disturbe other tests too much. */
vTaskPrioritySet( NULL, tskIDLE_PRIORITY );
ulCountingSemaphoreLoops++;
}
}
/*-----------------------------------------------------------*/
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. */
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. */
xSemaphoreGiveFromISR( xISRMutex, NULL );
/* 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. */
xTimeNow = xTaskGetTickCountFromISR();
/* Second give attempt should fail. */
configASSERT( xSemaphoreGiveFromISR( xISRMutex, &xHigherPriorityTaskWoken ) == pdFAIL );
}
if( ( ( TickType_t ) ( xTimeNow - xLastGiveTime ) ) >= pdMS_TO_TICKS( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS ) )
{
configASSERT( xISRMutex );
if( xOkToGiveCountingSemaphore != pdFALSE )
{
xSemaphoreGiveFromISR( xISRCountingSemaphore, &xHigherPriorityTaskWoken );
}
xLastGiveTime = xTimeNow;
}
if( xOkToGiveMutex != pdFALSE )
{
/* Null is used as the second parameter in this give, and non-NULL
* in the other gives for code coverage reasons. */
xSemaphoreGiveFromISR( xISRMutex, NULL );
/* Remove compiler warnings about the value being set but not used. */
( void ) xHigherPriorityTaskWoken;
/* Second give attempt should fail. */
configASSERT( xSemaphoreGiveFromISR( xISRMutex, &xHigherPriorityTaskWoken ) == pdFAIL );
}
if( xOkToGiveCountingSemaphore != pdFALSE )
{
xSemaphoreGiveFromISR( xISRCountingSemaphore, &xHigherPriorityTaskWoken );
}
xLastGiveTime = xTimeNow;
}
/* Remove compiler warnings about the value being set but not used. */
( void ) xHigherPriorityTaskWoken;
}
/*-----------------------------------------------------------*/
/* 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. */
if( ulLastMasterLoopCounter == ulMasterLoops )
{
xErrorDetected = pdTRUE;
}
/* If the demo tasks are running then it is expected that the loop counters
* will have changed since this function was last called. */
if( ulLastMasterLoopCounter == ulMasterLoops )
{
xErrorDetected = pdTRUE;
}
ulLastMasterLoopCounter = ulMasterLoops;
ulLastMasterLoopCounter = ulMasterLoops;
if( ulLastCountingSemaphoreLoops == ulCountingSemaphoreLoops )
{
xErrorDetected = pdTRUE;
}
if( ulLastCountingSemaphoreLoops == ulCountingSemaphoreLoops )
{
xErrorDetected = pdTRUE;
}
ulLastCountingSemaphoreLoops = ulCountingSemaphoreLoops++;
ulLastCountingSemaphoreLoops = ulCountingSemaphoreLoops++;
/* Errors detected in the task itself will have latched xErrorDetected
to true. */
/* Errors detected in the task itself will have latched xErrorDetected
* to true. */
return ( BaseType_t ) !xErrorDetected;
return ( BaseType_t ) !xErrorDetected;
}

View file

@ -68,22 +68,22 @@
#include "MessageBufferAMP.h"
/* Enough for 3 4 byte pointers, including the additional 4 bytes per message
overhead of message buffers. */
#define mbaCONTROL_MESSAGE_BUFFER_SIZE ( 24 )
* 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. */
#define mbaTASK_MESSAGE_BUFFER_SIZE ( 60 )
* overhead of message buffers. */
#define mbaTASK_MESSAGE_BUFFER_SIZE ( 60 )
/* The number of instances of prvCoreBTasks that are created. */
#define mbaNUMBER_OF_CORE_B_TASKS 2
#define mbaNUMBER_OF_CORE_B_TASKS 2
/* A block time of 0 simply means, don't block. */
#define mbaDONT_BLOCK 0
#define mbaDONT_BLOCK 0
/* Macro that mimics an interrupt service routine executing by simply calling
the routine inline. */
#define mbaGENERATE_CORE_B_INTERRUPT() prvCoreBInterruptHandler()
* 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,218 +112,217 @@ 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 );
xControlMessageBuffer = xMessageBufferCreate( mbaCONTROL_MESSAGE_BUFFER_SIZE );
xTaskCreate( prvCoreATask, /* The function that implements the task. */
"AMPCoreA", /* Human readable name for the task. */
xStackSize, /* Stack size (in words!). */
NULL, /* Task parameter is not used. */
tskIDLE_PRIORITY, /* The priority at which the task is created. */
NULL ); /* No use for the task handle. */
xTaskCreate( prvCoreATask, /* The function that implements the task. */
"AMPCoreA", /* Human readable name for the task. */
xStackSize, /* Stack size (in words!). */
NULL, /* Task parameter is not used. */
tskIDLE_PRIORITY, /* The priority at which the task is created. */
NULL ); /* No use for the task handle. */
for( x = 0; x < mbaNUMBER_OF_CORE_B_TASKS; x++ )
{
xCoreBMessageBuffers[ x ] = xMessageBufferCreate( mbaTASK_MESSAGE_BUFFER_SIZE );
configASSERT( xCoreBMessageBuffers[ x ] );
for( x = 0; x < mbaNUMBER_OF_CORE_B_TASKS; x++ )
{
xCoreBMessageBuffers[ x ] = xMessageBufferCreate( mbaTASK_MESSAGE_BUFFER_SIZE );
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. */
xTaskCreate( prvCoreBTasks,
"AMPCoreB1",
xStackSize,
( void * ) x,
tskIDLE_PRIORITY + 1,
NULL );
}
/* 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. */
xTaskCreate( prvCoreBTasks,
"AMPCoreB1",
xStackSize,
( void * ) x,
tskIDLE_PRIORITY + 1,
NULL );
}
}
/*-----------------------------------------------------------*/
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;
/* Remove warning about unused parameters. */
( void ) pvParameters;
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. */
sprintf( cString, "%lu", ( unsigned long ) ulNextValue );
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. */
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. */
for( x = 0; x < mbaNUMBER_OF_CORE_B_TASKS; x++ )
{
xMessageBufferSend( /* The message buffer to write to. */
xCoreBMessageBuffers[ x ],
/* The source of the data to send. */
( void * ) cString,
/* The length of the data to send. */
strlen( cString ),
/* The block time, should the buffer be full. */
mbaDONT_BLOCK );
}
/* 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. */
for( x = 0; x < mbaNUMBER_OF_CORE_B_TASKS; x++ )
{
xMessageBufferSend( /* The message buffer to write to. */
xCoreBMessageBuffers[ x ],
/* The source of the data to send. */
( void * ) cString,
/* The length of the data to send. */
strlen( cString ),
/* The block time, should the buffer be full. */
mbaDONT_BLOCK );
}
/* Delay before repeating with a different and potentially different
length string. */
vTaskDelay( xDelay );
ulNextValue++;
}
/* Delay before repeating with a different and potentially different
* 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. */
x = ( BaseType_t ) pvParameters;
configASSERT( x < mbaNUMBER_OF_CORE_B_TASKS );
/* The index into the xCoreBMessageBuffers and ulLoopCounter arrays is
* passed into this task using the task's parameter. */
x = ( BaseType_t ) pvParameters;
configASSERT( x < mbaNUMBER_OF_CORE_B_TASKS );
for( ;; )
{
/* Create the string that is expected to be received this time round. */
sprintf( cExpectedString, "%lu", ( unsigned long ) ulNextValue );
for( ; ; )
{
/* Create the string that is expected to be received this time round. */
sprintf( cExpectedString, "%lu", ( unsigned long ) ulNextValue );
/* Wait to receive the next message from core A. */
memset( cReceivedString, 0x00, sizeof( cReceivedString ) );
xReceivedBytes = xMessageBufferReceive( /* The message buffer to receive from. */
xCoreBMessageBuffers[ x ],
/* Location to store received data. */
cReceivedString,
/* Maximum number of bytes to receive. */
sizeof( cReceivedString ),
/* Ticks to wait if buffer is empty. */
portMAX_DELAY );
/* Wait to receive the next message from core A. */
memset( cReceivedString, 0x00, sizeof( cReceivedString ) );
xReceivedBytes = xMessageBufferReceive( /* The message buffer to receive from. */
xCoreBMessageBuffers[ x ],
/* Location to store received data. */
cReceivedString,
/* Maximum number of bytes to receive. */
sizeof( cReceivedString ),
/* Ticks to wait if buffer is empty. */
portMAX_DELAY );
/* Check the number of bytes received was as expected. */
configASSERT( xReceivedBytes == strlen( cExpectedString ) );
( void ) xReceivedBytes; /* Incase configASSERT() is not defined. */
/* Check the number of bytes received was as expected. */
configASSERT( xReceivedBytes == strlen( cExpectedString ) );
( 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. */
if( strcmp( cReceivedString, cExpectedString ) == 0 )
{
( ulCycleCounters[ x ] )++;
}
else
{
xDemoStatus = pdFAIL;
}
/* If the received string matches that expected then increment the loop
* counter so the check task knows this task is still running. */
if( strcmp( cReceivedString, cExpectedString ) == 0 )
{
( ulCycleCounters[ x ] )++;
}
else
{
xDemoStatus = pdFAIL;
}
/* Expect the next string in sequence the next time around. */
ulNextValue++;
}
/* Expect the next string in sequence the next time around. */
ulNextValue++;
}
}
/*-----------------------------------------------------------*/
/* 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. */
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. */
xMessageBufferSend( xControlMessageBuffer, &xUpdatedBuffer, sizeof( xUpdatedBuffer ), mbaDONT_BLOCK );
/* 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. */
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. */
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. */
mbaGENERATE_CORE_B_INTERRUPT();
}
/* 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. */
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. */
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. */
xMessageBufferSendCompletedFromISR( xUpdatedMessageBuffer, &xHigherPriorityTaskWoken );
}
/* xControlMessageBuffer contains the handle of the message buffer that
* 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. */
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. */
portYIELD_FROM_ISR( 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. */
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. */
for( x = 0; x < mbaNUMBER_OF_CORE_B_TASKS; x++ )
{
if( ulLastCycleCounters[ x ] == ulCycleCounters[ x ] )
{
xDemoStatus = pdFAIL;
}
else
{
ulLastCycleCounters[ x ] = ulCycleCounters[ x ];
}
}
/* Called by the check task to determine the health status of the tasks
* implemented in this demo. */
for( x = 0; x < mbaNUMBER_OF_CORE_B_TASKS; x++ )
{
if( ulLastCycleCounters[ x ] == ulCycleCounters[ x ] )
{
xDemoStatus = pdFAIL;
}
else
{
ulLastCycleCounters[ x ] = ulCycleCounters[ x ];
}
}
return xDemoStatus;
return xDemoStatus;
}

File diff suppressed because it is too large Load diff

View file

@ -49,11 +49,11 @@
*/
/*
Changes from V2.0.0
+ Delay periods are now specified using variables and constants of
TickType_t rather than uint32_t.
*/
* Changes from V2.0.0
*
+ Delay periods are now specified using variables and constants of
+ TickType_t rather than uint32_t.
*/
#include <stdlib.h>
@ -65,13 +65,13 @@ Changes from V2.0.0
/* Demo program include files. */
#include "PollQ.h"
#define pollqSTACK_SIZE configMINIMAL_STACK_SIZE
#define pollqQUEUE_SIZE ( 10 )
#define pollqPRODUCER_DELAY ( pdMS_TO_TICKS( ( TickType_t ) 200 ) )
#define pollqCONSUMER_DELAY ( pollqPRODUCER_DELAY - ( TickType_t ) ( 20 / portTICK_PERIOD_MS ) )
#define pollqNO_DELAY ( ( TickType_t ) 0 )
#define pollqVALUES_TO_PRODUCE ( ( BaseType_t ) 3 )
#define pollqINITIAL_VALUE ( ( BaseType_t ) 0 )
#define pollqSTACK_SIZE configMINIMAL_STACK_SIZE
#define pollqQUEUE_SIZE ( 10 )
#define pollqPRODUCER_DELAY ( pdMS_TO_TICKS( ( TickType_t ) 200 ) )
#define pollqCONSUMER_DELAY ( pollqPRODUCER_DELAY - ( TickType_t ) ( 20 / portTICK_PERIOD_MS ) )
#define pollqNO_DELAY ( ( TickType_t ) 0 )
#define pollqVALUES_TO_PRODUCE ( ( BaseType_t ) 3 )
#define pollqINITIAL_VALUE ( ( BaseType_t ) 0 )
/* The task that posts the incrementing number onto the queue. */
static portTASK_FUNCTION_PROTO( vPolledQueueProducer, pvParameters );
@ -80,144 +80,144 @@ 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 ) );
/* Create the queue used by the producer and consumer. */
xPolledQueue = xQueueCreate( pollqQUEUE_SIZE, ( UBaseType_t ) sizeof( uint16_t ) );
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. */
vQueueAddToRegistry( xPolledQueue, "Poll_Test_Queue" );
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. */
vQueueAddToRegistry( xPolledQueue, "Poll_Test_Queue" );
/* Spawn the producer and consumer. */
xTaskCreate( vPolledQueueConsumer, "QConsNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, ( TaskHandle_t * ) NULL );
xTaskCreate( vPolledQueueProducer, "QProdNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, ( TaskHandle_t * ) NULL );
}
/* Spawn the producer and consumer. */
xTaskCreate( vPolledQueueConsumer, "QConsNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, ( TaskHandle_t * ) NULL );
xTaskCreate( vPolledQueueProducer, "QProdNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, ( TaskHandle_t * ) NULL );
}
}
/*-----------------------------------------------------------*/
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( xLoop = 0; xLoop < pollqVALUES_TO_PRODUCE; xLoop++ )
{
/* Send an incrementing number on the queue without blocking. */
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. */
xError = pdTRUE;
}
else
{
if( xError == pdFALSE )
{
/* If an error has ever been recorded we stop incrementing the
check variable. */
portENTER_CRITICAL();
xPollingProducerCount++;
portEXIT_CRITICAL();
}
for( ; ; )
{
for( xLoop = 0; xLoop < pollqVALUES_TO_PRODUCE; xLoop++ )
{
/* Send an incrementing number on the queue without blocking. */
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. */
xError = pdTRUE;
}
else
{
if( xError == pdFALSE )
{
/* If an error has ever been recorded we stop incrementing the
* check variable. */
portENTER_CRITICAL();
xPollingProducerCount++;
portEXIT_CRITICAL();
}
/* Update the value we are going to post next time around. */
usValue++;
}
}
/* Update the value we are going to post next time around. */
usValue++;
}
}
/* Wait before we start posting again to ensure the consumer runs and
empties the queue. */
vTaskDelay( pollqPRODUCER_DELAY );
}
} /*lint !e818 Function prototype must conform to API. */
/* Wait before we start posting again to ensure the consumer runs and
* empties the queue. */
vTaskDelay( pollqPRODUCER_DELAY );
}
} /*lint !e818 Function prototype must conform to API. */
/*-----------------------------------------------------------*/
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( ;; )
{
/* Loop until the queue is empty. */
while( uxQueueMessagesWaiting( *( ( QueueHandle_t * ) pvParameters ) ) )
{
if( xQueueReceive( *( ( QueueHandle_t * ) pvParameters ), &usData, pollqNO_DELAY ) == pdPASS )
{
if( usData != usExpectedValue )
{
/* This is not what we expected to receive so an error has
occurred. */
xError = pdTRUE;
for( ; ; )
{
/* Loop until the queue is empty. */
while( uxQueueMessagesWaiting( *( ( QueueHandle_t * ) pvParameters ) ) )
{
if( xQueueReceive( *( ( QueueHandle_t * ) pvParameters ), &usData, pollqNO_DELAY ) == pdPASS )
{
if( usData != usExpectedValue )
{
/* This is not what we expected to receive so an error has
* occurred. */
xError = pdTRUE;
/* Catch-up to the value we received so our next expected
value should again be correct. */
usExpectedValue = usData;
}
else
{
if( xError == pdFALSE )
{
/* Only increment the check variable if no errors have
occurred. */
portENTER_CRITICAL();
xPollingConsumerCount++;
portEXIT_CRITICAL();
}
}
/* Catch-up to the value we received so our next expected
* value should again be correct. */
usExpectedValue = usData;
}
else
{
if( xError == pdFALSE )
{
/* Only increment the check variable if no errors have
* occurred. */
portENTER_CRITICAL();
xPollingConsumerCount++;
portEXIT_CRITICAL();
}
}
/* Next time round we would expect the number to be one higher. */
usExpectedValue++;
}
}
/* Next time round we would expect the number to be one higher. */
usExpectedValue++;
}
}
/* Now the queue is empty we block, allowing the producer to place more
items in the queue. */
vTaskDelay( pollqCONSUMER_DELAY );
}
/* Now the queue is empty we block, allowing the producer to place more
* items in the queue. */
vTaskDelay( pollqCONSUMER_DELAY );
}
} /*lint !e818 Function prototype must conform to API. */
/*-----------------------------------------------------------*/
/* 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. */
if( ( xPollingConsumerCount == pollqINITIAL_VALUE ) ||
( xPollingProducerCount == pollqINITIAL_VALUE )
)
{
xReturn = pdFALSE;
}
else
{
xReturn = pdTRUE;
}
/* 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. */
if( ( xPollingConsumerCount == pollqINITIAL_VALUE ) ||
( xPollingProducerCount == pollqINITIAL_VALUE )
)
{
xReturn = pdFALSE;
}
else
{
xReturn = pdTRUE;
}
/* Set the check variables back down so we know if they have been
incremented the next time around. */
xPollingConsumerCount = pollqINITIAL_VALUE;
xPollingProducerCount = pollqINITIAL_VALUE;
/* Set the check variables back down so we know if they have been
* incremented the next time around. */
xPollingConsumerCount = pollqINITIAL_VALUE;
xPollingProducerCount = pollqINITIAL_VALUE;
return xReturn;
return xReturn;
}

View file

@ -43,14 +43,14 @@
/* Demo program include files. */
#include "QPeek.h"
#define qpeekQUEUE_LENGTH ( 5 )
#define qpeekNO_BLOCK ( 0 )
#define qpeekSHORT_DELAY ( 10 )
#define qpeekQUEUE_LENGTH ( 5 )
#define qpeekNO_BLOCK ( 0 )
#define qpeekSHORT_DELAY ( 10 )
#define qpeekLOW_PRIORITY ( tskIDLE_PRIORITY + 0 )
#define qpeekMEDIUM_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define qpeekHIGH_PRIORITY ( tskIDLE_PRIORITY + 2 )
#define qpeekHIGHEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
#define qpeekLOW_PRIORITY ( tskIDLE_PRIORITY + 0 )
#define qpeekMEDIUM_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define qpeekHIGH_PRIORITY ( tskIDLE_PRIORITY + 2 )
#define qpeekHIGHEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
/*-----------------------------------------------------------*/
@ -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,361 +80,362 @@ 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 ) );
/* Create the queue that we are going to use for the test/demo. */
xQueue = xQueueCreate( qpeekQUEUE_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. */
vQueueAddToRegistry( xQueue, "QPeek_Test_Queue" );
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. */
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. */
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 );
xTaskCreate( prvHighestPriorityPeekTask, "PeekH2", configMINIMAL_STACK_SIZE, ( void * ) xQueue, qpeekHIGHEST_PRIORITY, &xHighestPriorityTask );
}
/* 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. */
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 );
xTaskCreate( prvHighestPriorityPeekTask, "PeekH2", configMINIMAL_STACK_SIZE, ( void * ) xQueue, qpeekHIGHEST_PRIORITY, &xHighestPriorityTask );
}
}
/*-----------------------------------------------------------*/
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
{
void vPrintDisplayMessage( const char * const * ppcMessageToSend );
#ifdef USE_STDIO
{
void vPrintDisplayMessage( const char * const * ppcMessageToSend );
const char * const pcTaskStartMsg = "Queue peek test started.\r\n";
const char * const pcTaskStartMsg = "Queue peek test started.\r\n";
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcTaskStartMsg );
}
#endif
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcTaskStartMsg );
}
#endif
for( ;; )
{
/* Try peeking from the queue. The queue should be empty so we will
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. */
xErrorDetected = pdTRUE;
}
for( ; ; )
{
/* Try peeking from the queue. The queue should be empty so we will
* 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. */
xErrorDetected = pdTRUE;
}
/* 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. */
if( ulValue != 0x11223344 )
{
/* We did not receive the expected value. */
xErrorDetected = pdTRUE;
}
/* 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. */
if( ulValue != 0x11223344 )
{
/* We did not receive the expected value. */
xErrorDetected = pdTRUE;
}
if( uxQueueMessagesWaiting( xQueue ) != 1 )
{
/* The message should have been left on the queue. */
xErrorDetected = pdTRUE;
}
if( uxQueueMessagesWaiting( xQueue ) != 1 )
{
/* The message should have been left on the queue. */
xErrorDetected = pdTRUE;
}
/* 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. */
ulValue = 0;
if( xQueueReceive( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
{
/* We expected to receive the value. */
xErrorDetected = pdTRUE;
}
/* 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. */
ulValue = 0;
if( ulValue != 0x11223344 )
{
/* We did not receive the expected value - which should have been
the same value as was peeked. */
xErrorDetected = pdTRUE;
}
if( xQueueReceive( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
{
/* We expected to receive the value. */
xErrorDetected = pdTRUE;
}
/* Now we will block again as the queue is once more empty. The low
priority task can then execute again. */
if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
{
/* We expected to have received something by the time we unblock. */
xErrorDetected = pdTRUE;
}
if( ulValue != 0x11223344 )
{
/* We did not receive the expected value - which should have been
* the same value as was peeked. */
xErrorDetected = pdTRUE;
}
/* When we get here the low priority task should have again written to the
queue. */
if( ulValue != 0x01234567 )
{
/* We did not receive the expected value. */
xErrorDetected = pdTRUE;
}
/* Now we will block again as the queue is once more empty. The low
* priority task can then execute again. */
if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
{
/* We expected to have received something by the time we unblock. */
xErrorDetected = pdTRUE;
}
if( uxQueueMessagesWaiting( xQueue ) != 1 )
{
/* The message should have been left on the queue. */
xErrorDetected = pdTRUE;
}
/* When we get here the low priority task should have again written to the
* queue. */
if( ulValue != 0x01234567 )
{
/* We did not receive the expected value. */
xErrorDetected = pdTRUE;
}
/* 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. */
vTaskSuspend( NULL );
if( uxQueueMessagesWaiting( xQueue ) != 1 )
{
/* The message should have been left on the queue. */
xErrorDetected = pdTRUE;
}
/* 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. */
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. */
if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
{
xErrorDetected = pdTRUE;
}
/* 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. */
if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
{
xErrorDetected = pdTRUE;
}
if( ulValue != 0xaabbaabb )
{
xErrorDetected = pdTRUE;
}
if( ulValue != 0xaabbaabb )
{
xErrorDetected = pdTRUE;
}
vTaskSuspend( NULL );
}
vTaskSuspend( NULL );
}
}
/*-----------------------------------------------------------*/
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( ;; )
{
/* 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. */
if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
{
/* We expected to have received something by the time we unblock. */
xErrorDetected = pdTRUE;
}
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. */
if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
{
/* We expected to have received something by the time we unblock. */
xErrorDetected = pdTRUE;
}
/* 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). */
if( ulValue != 0x01234567 )
{
/* We did not receive the expected value. */
xErrorDetected = pdTRUE;
}
/* 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). */
if( ulValue != 0x01234567 )
{
/* We did not receive the expected value. */
xErrorDetected = pdTRUE;
}
if( uxQueueMessagesWaiting( xQueue ) != 1 )
{
/* The message should have been left on the queue. */
xErrorDetected = pdTRUE;
}
if( uxQueueMessagesWaiting( xQueue ) != 1 )
{
/* The message should have been left on the queue. */
xErrorDetected = pdTRUE;
}
/* 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. */
vTaskSuspend( NULL );
/* 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. */
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. */
if( xQueueReceive( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
{
xErrorDetected = pdTRUE;
}
/* 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. */
if( xQueueReceive( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
{
xErrorDetected = pdTRUE;
}
if( ulValue != 0xaabbaabb )
{
xErrorDetected = pdTRUE;
}
if( ulValue != 0xaabbaabb )
{
xErrorDetected = pdTRUE;
}
vTaskSuspend( NULL );
}
vTaskSuspend( NULL );
}
}
/*-----------------------------------------------------------*/
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( ;; )
{
/* 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. */
if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
{
/* We expected to have received something by the time we unblock. */
xErrorDetected = pdTRUE;
}
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. */
if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
{
/* We expected to have received something by the time we unblock. */
xErrorDetected = pdTRUE;
}
/* 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). */
if( ulValue != 0x01234567 )
{
/* We did not receive the expected value. */
xErrorDetected = pdTRUE;
}
/* 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). */
if( ulValue != 0x01234567 )
{
/* We did not receive the expected value. */
xErrorDetected = pdTRUE;
}
if( uxQueueMessagesWaiting( xQueue ) != 1 )
{
/* The message should have been left on the queue. */
xErrorDetected = pdTRUE;
}
if( uxQueueMessagesWaiting( xQueue ) != 1 )
{
/* The message should have been left on the queue. */
xErrorDetected = pdTRUE;
}
/* Just so we know the test is still running. */
ulLoopCounter++;
/* Just so we know the test is still running. */
ulLoopCounter++;
/* Now we can suspend ourselves so the low priority task can execute
again. */
vTaskSuspend( NULL );
}
/* Now we can suspend ourselves so the low priority task can execute
* 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( ;; )
{
/* Write some data to the queue. This should unblock the highest
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. */
xErrorDetected = pdTRUE;
}
for( ; ; )
{
/* Write some data to the queue. This should unblock the highest
* priority task that is waiting to peek data from the queue. */
ulValue = 0x11223344;
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
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. */
xErrorDetected = pdTRUE;
}
/* By the time we get here the data should have been removed from
the queue. */
if( uxQueueMessagesWaiting( xQueue ) != 0 )
{
xErrorDetected = pdTRUE;
}
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
/* Write another value to the queue, again waking the highest priority
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. */
xErrorDetected = pdTRUE;
}
/* By the time we get here the data should have been removed from
* the queue. */
if( uxQueueMessagesWaiting( xQueue ) != 0 )
{
xErrorDetected = pdTRUE;
}
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
/* Write another value to the queue, again waking the highest priority
* task that is blocked on the queue. */
ulValue = 0x01234567;
/* 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. */
ulValue = 0;
if( xQueueReceive( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
{
/* We expected to receive the data. */
xErrorDetected = pdTRUE;
}
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. */
xErrorDetected = pdTRUE;
}
if( ulValue != 0x01234567 )
{
/* We did not receive the expected value. */
xErrorDetected = pdTRUE;
}
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
/* Lets just delay a while as this is an intensive test as we don't
want to starve other tests of processing time. */
vTaskDelay( qpeekSHORT_DELAY );
/* 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. */
ulValue = 0;
/* 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. */
vTaskResume( xMediumPriorityTask );
vTaskResume( xHighPriorityTask );
vTaskResume( xHighestPriorityTask );
if( xQueueReceive( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
{
/* We expected to receive the data. */
xErrorDetected = pdTRUE;
}
#if( configUSE_PREEMPTION == 0 )
taskYIELD();
#endif
if( ulValue != 0x01234567 )
{
/* We did not receive the expected value. */
xErrorDetected = pdTRUE;
}
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. */
xErrorDetected = pdTRUE;
}
/* Lets just delay a while as this is an intensive test as we don't
* want to starve other tests of processing time. */
vTaskDelay( qpeekSHORT_DELAY );
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
/* 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. */
vTaskResume( xMediumPriorityTask );
vTaskResume( xHighPriorityTask );
vTaskResume( xHighestPriorityTask );
/* This time we should find that the queue is empty. The high priority
task actually removed the data rather than just peeking it. */
if( xQueuePeek( xQueue, &ulValue, qpeekNO_BLOCK ) != errQUEUE_EMPTY )
{
/* We expected to receive the data. */
xErrorDetected = pdTRUE;
}
#if ( configUSE_PREEMPTION == 0 )
taskYIELD();
#endif
/* 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. */
vTaskResume( xHighPriorityTask );
vTaskResume( xHighestPriorityTask );
ulValue = 0xaabbaabb;
/* Lets just delay a while as this is an intensive test as we don't
want to starve other tests of processing time. */
vTaskDelay( qpeekSHORT_DELAY );
}
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. */
xErrorDetected = pdTRUE;
}
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
/* This time we should find that the queue is empty. The high priority
* task actually removed the data rather than just peeking it. */
if( xQueuePeek( xQueue, &ulValue, qpeekNO_BLOCK ) != errQUEUE_EMPTY )
{
/* We expected to receive the data. */
xErrorDetected = pdTRUE;
}
/* 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. */
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. */
vTaskDelay( qpeekSHORT_DELAY );
}
}
/*-----------------------------------------------------------*/
/* 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. */
if( ulLastLoopCounter == ulLoopCounter )
{
xErrorDetected = pdTRUE;
}
/* If the demo task is still running then we expect the loopcounter to
* have incremented since this function was last called. */
if( ulLastLoopCounter == ulLoopCounter )
{
xErrorDetected = pdTRUE;
}
ulLastLoopCounter = ulLoopCounter;
ulLastLoopCounter = ulLoopCounter;
/* Errors detected in the task itself will have latched xErrorDetected
to true. */
/* Errors detected in the task itself will have latched xErrorDetected
* to true. */
return ( BaseType_t ) !xErrorDetected;
return ( BaseType_t ) !xErrorDetected;
}

View file

@ -39,192 +39,198 @@
#include "QueueOverwrite.h"
/* A block time of 0 just means "don't block". */
#define qoDONT_BLOCK 0
#define qoDONT_BLOCK 0
/* Number of times to overwrite the value in the queue. */
#define qoLOOPS 5
#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. */
xISRQueue = xQueueCreate( uxQueueLength, ( UBaseType_t ) sizeof( uint32_t ) );
/* Create the queue used by the ISR. xQueueOverwriteFromISR() should only
* 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. */
xTaskCreate( prvQueueOverwriteTask, "QOver", configMINIMAL_STACK_SIZE, NULL, uxPriority, ( TaskHandle_t * ) NULL );
/* Create the test task. The queue used by the test task is created inside
* 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;
/* The parameter is not used. */
( void ) pvParameters;
/* Create the queue. xQueueOverwrite() should only be used on queues that
have a length of 1. */
xTaskQueue = xQueueCreate( uxQueueLength, ( UBaseType_t ) sizeof( uint32_t ) );
configASSERT( xTaskQueue );
/* Create the queue. xQueueOverwrite() should only be used on queues that
* have a length of 1. */
xTaskQueue = xQueueCreate( uxQueueLength, ( UBaseType_t ) sizeof( uint32_t ) );
configASSERT( xTaskQueue );
for( ;; )
{
/* The queue is empty. Writing to the queue then reading from the queue
should return the item written. */
ulValue = 10;
xQueueOverwrite( xTaskQueue, &ulValue );
for( ; ; )
{
/* The queue is empty. Writing to the queue then reading from the queue
* should return the item written. */
ulValue = 10;
xQueueOverwrite( xTaskQueue, &ulValue );
ulValue = 0;
xQueueReceive( xTaskQueue, &ulValue, qoDONT_BLOCK );
ulValue = 0;
xQueueReceive( xTaskQueue, &ulValue, qoDONT_BLOCK );
if( ulValue != 10 )
{
ulStatus = pdFAIL;
}
if( ulValue != 10 )
{
ulStatus = pdFAIL;
}
/* Now try writing to the queue several times. Each time the value
in the queue should get overwritten. */
for( x = 0; x < qoLOOPS; x++ )
{
/* Write to the queue. */
xQueueOverwrite( xTaskQueue, &x );
/* Now try writing to the queue several times. Each time the value
* 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. */
xQueuePeek( xTaskQueue, &ulValue, qoDONT_BLOCK );
if( ulValue != x )
{
ulStatus = pdFAIL;
}
/* Check the value in the queue is that written, even though the
* queue was not necessarily empty. */
xQueuePeek( xTaskQueue, &ulValue, qoDONT_BLOCK );
/* There should always be one item in the queue. */
if( uxQueueMessagesWaiting( xTaskQueue ) != uxQueueLength )
{
ulStatus = pdFAIL;
}
}
if( ulValue != x )
{
ulStatus = pdFAIL;
}
/* Empty the queue again. */
xQueueReceive( xTaskQueue, &ulValue, qoDONT_BLOCK );
/* There should always be one item in the queue. */
if( uxQueueMessagesWaiting( xTaskQueue ) != uxQueueLength )
{
ulStatus = pdFAIL;
}
}
if( uxQueueMessagesWaiting( xTaskQueue ) != 0 )
{
ulStatus = pdFAIL;
}
/* Empty the queue again. */
xQueueReceive( xTaskQueue, &ulValue, qoDONT_BLOCK );
if( ulStatus != pdFAIL )
{
/* Increment a counter to show this task is still running without
error. */
ulLoopCounter++;
}
if( uxQueueMessagesWaiting( xTaskQueue ) != 0 )
{
ulStatus = pdFAIL;
}
#if( configUSE_PREEMPTION == 0 )
taskYIELD();
#endif
}
if( ulStatus != pdFAIL )
{
/* Increment a counter to show this task is still running without
* error. */
ulLoopCounter++;
}
#if ( configUSE_PREEMPTION == 0 )
taskYIELD();
#endif
}
}
/*-----------------------------------------------------------*/
BaseType_t xIsQueueOverwriteTaskStillRunning( void )
{
BaseType_t xReturn;
BaseType_t xReturn;
if( xISRTestStatus != pdPASS )
{
xReturn = pdFAIL;
}
else if( ulLoopCounter > 0 )
{
xReturn = pdPASS;
}
else
{
/* The task has either stalled of discovered an error. */
xReturn = pdFAIL;
}
if( xISRTestStatus != pdPASS )
{
xReturn = pdFAIL;
}
else if( ulLoopCounter > 0 )
{
xReturn = pdPASS;
}
else
{
/* The task has either stalled of discovered an error. */
xReturn = pdFAIL;
}
ulLoopCounter = 0;
ulLoopCounter = 0;
return xReturn;
return 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(). */
/* This function should be called from an interrupt, such as the tick hook
* function vApplicationTickHook(). */
configASSERT( xISRQueue );
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. */
xQueueOverwriteFromISR( xISRQueue, &ulTx1, NULL );
switch( ulCallCount )
{
case 0:
/* Peek the queue to check it holds the expected value. */
xQueuePeekFromISR( xISRQueue, &ulRx );
if( ulRx != ulTx1 )
{
xISRTestStatus = pdFAIL;
}
break;
/* 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. */
xQueueOverwriteFromISR( xISRQueue, &ulTx1, NULL );
case 1:
/* The queue already holds ulTx1. Overwrite the value in the queue
with ulTx2. */
xQueueOverwriteFromISR( xISRQueue, &ulTx2, NULL );
break;
/* Peek the queue to check it holds the expected value. */
xQueuePeekFromISR( xISRQueue, &ulRx );
case 2:
/* Read from the queue to empty the queue again. The value read
should be ulTx2. */
xQueueReceiveFromISR( xISRQueue, &ulRx, NULL );
if( ulRx != ulTx1 )
{
xISRTestStatus = pdFAIL;
}
if( ulRx != ulTx2 )
{
xISRTestStatus = pdFAIL;
}
break;
}
break;
/* Run the next case in the switch statement above next time this function
is called. */
ulCallCount++;
case 1:
if( ulCallCount >= ulNumberOfSwitchCases )
{
/* Go back to the start. */
ulCallCount = 0;
}
/* The queue already holds ulTx1. Overwrite the value in the queue
* with ulTx2. */
xQueueOverwriteFromISR( xISRQueue, &ulTx2, NULL );
break;
case 2:
/* Read from the queue to empty the queue again. The value read
* 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. */
ulCallCount++;
if( ulCallCount >= ulNumberOfSwitchCases )
{
/* Go back to the start. */
ulCallCount = 0;
}
}

File diff suppressed because it is too large Load diff

View file

@ -51,131 +51,132 @@
/* 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 )
{
/* Create the queue that is added to the set, the set, and add the queue to
the set. */
xQueue = xQueueCreate( setpollQUEUE_LENGTH, sizeof( uint32_t ) );
xQueueSet = xQueueCreateSet( setpollQUEUE_LENGTH );
void vStartQueueSetPollingTask( void )
{
/* Create the queue that is added to the set, the set, and add the queue to
* the set. */
xQueue = xQueueCreate( setpollQUEUE_LENGTH, sizeof( uint32_t ) );
xQueueSet = xQueueCreateSet( setpollQUEUE_LENGTH );
if( ( xQueue != NULL ) && ( xQueueSet != NULL ) )
{
xQueueAddToSet( xQueue, xQueueSet );
if( ( xQueue != NULL ) && ( xQueueSet != NULL ) )
{
xQueueAddToSet( xQueue, xQueueSet );
/* Create the task. */
xTaskCreate( prvQueueSetReceivingTask, "SetPoll", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
}
}
/* 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;
/* Remove compiler warnings. */
( void ) pvParameters;
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. */
xActivatedQueue = xQueueSelectFromSet( xQueueSet, setpollDONT_BLOCK );
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. */
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. */
if( xQueueReceive( xActivatedQueue, &ulReceived, setpollDONT_BLOCK ) != pdPASS )
{
xQueueSetPollStatus = pdFAIL;
}
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. */
if( xQueueReceive( xActivatedQueue, &ulReceived, setpollDONT_BLOCK ) != pdPASS )
{
xQueueSetPollStatus = pdFAIL;
}
if( ulReceived == ulExpected )
{
ulExpected++;
}
else
{
xQueueSetPollStatus = pdFAIL;
}
if( ulReceived == ulExpected )
{
ulExpected++;
}
else
{
xQueueSetPollStatus = pdFAIL;
}
if( xQueueSetPollStatus == pdPASS )
{
ulCycleCounter++;
}
}
}
}
if( xQueueSetPollStatus == pdPASS )
{
ulCycleCounter++;
}
}
}
}
/*-----------------------------------------------------------*/
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. */
ulCallCount++;
if( ulCallCount > queuesetISR_TX_PERIOD )
{
ulCallCount = 0;
/* It is intended that this function is called from the tick hook
* function, so each call is one tick period apart. */
ulCallCount++;
if( xQueueSendFromISR( xQueue, ( void * ) &ulValueToSend, NULL ) == pdPASS )
{
/* Send the next value next time. */
ulValueToSend++;
}
}
}
if( ulCallCount > queuesetISR_TX_PERIOD )
{
ulCallCount = 0;
if( xQueueSendFromISR( xQueue, ( void * ) &ulValueToSend, NULL ) == pdPASS )
{
/* Send the next value next time. */
ulValueToSend++;
}
}
}
/*-----------------------------------------------------------*/
BaseType_t xAreQueueSetPollTasksStillRunning( void )
{
static uint32_t ulLastCycleCounter = 0;
BaseType_t xAreQueueSetPollTasksStillRunning( void )
{
static uint32_t ulLastCycleCounter = 0;
if( ulLastCycleCounter == ulCycleCounter )
{
xQueueSetPollStatus = pdFAIL;
}
if( ulLastCycleCounter == ulCycleCounter )
{
xQueueSetPollStatus = pdFAIL;
}
ulLastCycleCounter = ulCycleCounter;
ulLastCycleCounter = ulCycleCounter;
return xQueueSetPollStatus;
}
return xQueueSetPollStatus;
}
/*-----------------------------------------------------------*/

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -48,13 +48,13 @@
/* Demo app includes. */
#include "StreamBufferInterrupt.h"
#define sbiSTREAM_BUFFER_LENGTH_BYTES ( ( size_t ) 100 )
#define sbiSTREAM_BUFFER_TRIGGER_LEVEL_10 ( ( BaseType_t ) 10 )
#define sbiSTREAM_BUFFER_LENGTH_BYTES ( ( size_t ) 100 )
#define sbiSTREAM_BUFFER_TRIGGER_LEVEL_10 ( ( BaseType_t ) 10 )
/*-----------------------------------------------------------*/
/* Implements the task that receives a stream of bytes from the interrupt. */
static void prvReceivingTask( void *pvParameters );
static void prvReceivingTask( void * pvParameters );
/*-----------------------------------------------------------*/
@ -62,167 +62,168 @@ 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;
/*-----------------------------------------------------------*/
void vStartStreamBufferInterruptDemo( void )
{
/* Create the stream buffer that sends data from the interrupt to the
task, and create the task. */
xStreamBuffer = xStreamBufferCreate( /* The buffer length in bytes. */
sbiSTREAM_BUFFER_LENGTH_BYTES,
/* The stream buffer's trigger level. */
sbiSTREAM_BUFFER_TRIGGER_LEVEL_10 );
/* Create the stream buffer that sends data from the interrupt to the
* task, and create the task. */
xStreamBuffer = xStreamBufferCreate( /* The buffer length in bytes. */
sbiSTREAM_BUFFER_LENGTH_BYTES,
/* The stream buffer's trigger level. */
sbiSTREAM_BUFFER_TRIGGER_LEVEL_10 );
xTaskCreate( prvReceivingTask, /* The function that implements the task. */
"StrIntRx", /* Human readable name for the task. */
configMINIMAL_STACK_SIZE, /* Stack size (in words!). */
NULL, /* Task parameter is not used. */
tskIDLE_PRIORITY + 2, /* The priority at which the task is created. */
NULL ); /* No use for the task handle. */
xTaskCreate( prvReceivingTask, /* The function that implements the task. */
"StrIntRx", /* Human readable name for the task. */
configMINIMAL_STACK_SIZE, /* Stack size (in words!). */
NULL, /* Task parameter is not used. */
tskIDLE_PRIORITY + 2, /* The priority at which the task is created. */
NULL ); /* No use for the task handle. */
}
/*-----------------------------------------------------------*/
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;
/* Remove warning about unused parameters. */
( void ) pvParameters;
/* Make sure the string will fit in the Rx buffer, including the NULL
terminator. */
configASSERT( sizeof( cRxBuffer ) > strlen( pcStringToReceive ) );
/* Make sure the string will fit in the Rx buffer, including the NULL
* terminator. */
configASSERT( sizeof( cRxBuffer ) > strlen( pcStringToReceive ) );
/* Make sure the stream buffer has been created. */
configASSERT( xStreamBuffer != NULL );
/* Make sure the stream buffer has been created. */
configASSERT( xStreamBuffer != NULL );
/* Start with the Rx buffer in a known state. */
memset( cRxBuffer, 0x00, sizeof( cRxBuffer ) );
/* Start with the Rx buffer in a known state. */
memset( cRxBuffer, 0x00, sizeof( cRxBuffer ) );
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. */
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. */
portMAX_DELAY );
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. */
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 ),
/* If xNextByte is 0 then this task is looking for the start of the
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. */
xNextByte++;
}
}
else
{
/* Receiving characters while looking for the end of the string,
which is an 'S'. */
if( cRxBuffer[ xNextByte ] == 'S' )
{
/* The string has now been received. Check its validity. */
if( strcmp( cRxBuffer, pcStringToReceive ) != 0 )
{
xDemoStatus = pdFAIL;
}
/* The time to wait for the next data if the buffer
* is empty. */
portMAX_DELAY );
/* Return to start looking for the beginning of the string
again. */
memset( cRxBuffer, 0x00, sizeof( cRxBuffer ) );
xNextByte = 0;
/* If xNextByte is 0 then this task is looking for the start of the
* 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. */
xNextByte++;
}
}
else
{
/* Receiving characters while looking for the end of the string,
* which is an 'S'. */
if( cRxBuffer[ xNextByte ] == 'S' )
{
/* The string has now been received. Check its validity. */
if( strcmp( cRxBuffer, pcStringToReceive ) != 0 )
{
xDemoStatus = pdFAIL;
}
/* Increment the cycle count as an indication to the check task
that this demo is still running. */
if( xDemoStatus == pdPASS )
{
ulCycleCount++;
}
}
else
{
/* Receive the next character the next time around, while
continuing to look for the end of the string. */
xNextByte++;
/* Return to start looking for the beginning of the string
* again. */
memset( cRxBuffer, 0x00, sizeof( cRxBuffer ) );
xNextByte = 0;
configASSERT( ( size_t ) xNextByte < sizeof( cRxBuffer ) );
}
}
}
/* Increment the cycle count as an indication to the check task
* that this demo is still running. */
if( xDemoStatus == pdPASS )
{
ulCycleCount++;
}
}
else
{
/* Receive the next character the next time around, while
* continuing to look for the end of the string. */
xNextByte++;
configASSERT( ( size_t ) xNextByte < sizeof( cRxBuffer ) );
}
}
}
}
/*-----------------------------------------------------------*/
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;
/* Is it time to write to the stream buffer again? */
xCallCount++;
/* Send the next four bytes to the stream buffer. */
xStreamBufferSendFromISR( xStreamBuffer,
( const void * ) ( pcStringToSend + xNextByteToSend ),
xBytesToSend,
NULL );
if( xCallCount > xCallsBetweenSends )
{
xCallCount = 0;
/* Send the next four bytes the next time around, wrapping to the start
of the string if necessary. */
xNextByteToSend += xBytesToSend;
/* Send the next four bytes to the stream buffer. */
xStreamBufferSendFromISR( xStreamBuffer,
( const void * ) ( pcStringToSend + xNextByteToSend ),
xBytesToSend,
NULL );
if( xNextByteToSend >= strlen( pcStringToSend ) )
{
xNextByteToSend = 0;
}
}
/* Send the next four bytes the next time around, wrapping to the start
* of the string if necessary. */
xNextByteToSend += xBytesToSend;
if( xNextByteToSend >= strlen( pcStringToSend ) )
{
xNextByteToSend = 0;
}
}
}
/*-----------------------------------------------------------*/
BaseType_t xIsInterruptStreamBufferDemoStillRunning( void )
{
uint32_t ulLastCycleCount = 0;
uint32_t ulLastCycleCount = 0;
/* Check the demo is still running. */
if( ulLastCycleCount == ulCycleCount )
{
xDemoStatus = pdFAIL;
}
else
{
ulLastCycleCount = ulCycleCount;
}
/* Check the demo is still running. */
if( ulLastCycleCount == ulCycleCount )
{
xDemoStatus = pdFAIL;
}
else
{
ulLastCycleCount = ulCycleCount;
}
return xDemoStatus;
return xDemoStatus;
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -41,30 +41,30 @@
/* Task priorities and stack sizes. Allow these to be overridden. */
#ifndef bktPRIMARY_PRIORITY
#define bktPRIMARY_PRIORITY ( configMAX_PRIORITIES - 3 )
#define bktPRIMARY_PRIORITY ( configMAX_PRIORITIES - 3 )
#endif
#ifndef bktSECONDARY_PRIORITY
#define bktSECONDARY_PRIORITY ( configMAX_PRIORITIES - 4 )
#define bktSECONDARY_PRIORITY ( configMAX_PRIORITIES - 4 )
#endif
#ifndef bktBLOCK_TIME_TASK_STACK_SIZE
#define bktBLOCK_TIME_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
#define bktBLOCK_TIME_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
#endif
/* Task behaviour. */
#define bktQUEUE_LENGTH ( 5 )
#define bktSHORT_WAIT pdMS_TO_TICKS( ( TickType_t ) 20 )
#define bktPRIMARY_BLOCK_TIME ( 10 )
#define bktALLOWABLE_MARGIN ( 15 )
#define bktTIME_TO_BLOCK ( 175 )
#define bktDONT_BLOCK ( ( TickType_t ) 0 )
#define bktRUN_INDICATOR ( ( UBaseType_t ) 0x55 )
#define bktQUEUE_LENGTH ( 5 )
#define bktSHORT_WAIT pdMS_TO_TICKS( ( TickType_t ) 20 )
#define bktPRIMARY_BLOCK_TIME ( 10 )
#define bktALLOWABLE_MARGIN ( 15 )
#define bktTIME_TO_BLOCK ( 175 )
#define bktDONT_BLOCK ( ( TickType_t ) 0 )
#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 )
#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,495 +94,505 @@ 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;
/*-----------------------------------------------------------*/
void vCreateBlockTimeTasks( void )
{
/* Create the queue on which the two tasks block. */
xTestQueue = xQueueCreate( bktQUEUE_LENGTH, sizeof( BaseType_t ) );
/* Create the queue on which the two tasks block. */
xTestQueue = xQueueCreate( bktQUEUE_LENGTH, sizeof( BaseType_t ) );
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. */
vQueueAddToRegistry( xTestQueue, "Block_Time_Queue" );
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. */
vQueueAddToRegistry( xTestQueue, "Block_Time_Queue" );
/* Create the two test tasks. */
xTaskCreate( vPrimaryBlockTimeTestTask, "BTest1", bktBLOCK_TIME_TASK_STACK_SIZE, NULL, bktPRIMARY_PRIORITY, NULL );
xTaskCreate( vSecondaryBlockTimeTestTask, "BTest2", bktBLOCK_TIME_TASK_STACK_SIZE, NULL, bktSECONDARY_PRIORITY, &xSecondary );
}
/* Create the two test tasks. */
xTaskCreate( vPrimaryBlockTimeTestTask, "BTest1", bktBLOCK_TIME_TASK_STACK_SIZE, NULL, bktPRIMARY_PRIORITY, NULL );
xTaskCreate( vSecondaryBlockTimeTestTask, "BTest2", bktBLOCK_TIME_TASK_STACK_SIZE, NULL, bktSECONDARY_PRIORITY, &xSecondary );
}
}
/*-----------------------------------------------------------*/
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;
( void ) pvParameters;
for( ;; )
{
/*********************************************************************
Test 0
for( ; ; )
{
/*********************************************************************
* Test 0
*
* Basic vTaskDelay() and vTaskDelayUntil() tests. */
prvBasicDelayTests();
Basic vTaskDelay() and vTaskDelayUntil() tests. */
prvBasicDelayTests();
/*********************************************************************
* 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. */
xTimeToBlock = ( TickType_t ) ( bktPRIMARY_BLOCK_TIME << xItem );
xTimeWhenBlocking = xTaskGetTickCount();
/*********************************************************************
Test 1
/* We should unblock after xTimeToBlock having not received
* anything on the queue. */
if( xQueueReceive( xTestQueue, &xData, xTimeToBlock ) != errQUEUE_EMPTY )
{
xErrorOccurred = pdTRUE;
}
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. */
xTimeToBlock = ( TickType_t ) ( bktPRIMARY_BLOCK_TIME << xItem );
/* How long were we blocked for? */
xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
xTimeWhenBlocking = xTaskGetTickCount();
if( xBlockedTime < xTimeToBlock )
{
/* Should not have blocked for less than we requested. */
xErrorOccurred = pdTRUE;
}
/* We should unblock after xTimeToBlock having not received
anything on the queue. */
if( xQueueReceive( xTestQueue, &xData, xTimeToBlock ) != errQUEUE_EMPTY )
{
xErrorOccurred = pdTRUE;
}
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. */
xErrorOccurred = pdTRUE;
}
}
/* How long were we blocked for? */
xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
/*********************************************************************
* 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 )
{
xErrorOccurred = pdTRUE;
}
if( xBlockedTime < xTimeToBlock )
{
/* Should not have blocked for less than we requested. */
xErrorOccurred = pdTRUE;
}
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
}
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. */
xErrorOccurred = pdTRUE;
}
}
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. */
xTimeToBlock = ( TickType_t ) ( bktPRIMARY_BLOCK_TIME << xItem );
/*********************************************************************
Test 2
xTimeWhenBlocking = xTaskGetTickCount();
Simple block time wakeup test on queue sends.
/* We should unblock after xTimeToBlock having not received
* anything on the queue. */
if( xQueueSend( xTestQueue, &xItem, xTimeToBlock ) != errQUEUE_FULL )
{
xErrorOccurred = pdTRUE;
}
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 )
{
xErrorOccurred = pdTRUE;
}
/* How long were we blocked for? */
xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
}
if( xBlockedTime < xTimeToBlock )
{
/* Should not have blocked for less than we requested. */
xErrorOccurred = pdTRUE;
}
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. */
xTimeToBlock = ( TickType_t ) ( bktPRIMARY_BLOCK_TIME << xItem );
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. */
xErrorOccurred = pdTRUE;
}
}
xTimeWhenBlocking = xTaskGetTickCount();
/*********************************************************************
* 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 );
/* We should unblock after xTimeToBlock having not received
anything on the queue. */
if( xQueueSend( xTestQueue, &xItem, xTimeToBlock ) != errQUEUE_FULL )
{
xErrorOccurred = pdTRUE;
}
/* We need to wait a little to ensure the other task executes. */
while( xRunIndicator != bktRUN_INDICATOR )
{
/* The other task has not yet executed. */
vTaskDelay( bktSHORT_WAIT );
}
/* How long were we blocked for? */
xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
/* Make sure the other task is blocked on the queue. */
vTaskDelay( bktSHORT_WAIT );
xRunIndicator = 0;
if( xBlockedTime < xTimeToBlock )
{
/* Should not have blocked for less than we requested. */
xErrorOccurred = pdTRUE;
}
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. */
if( xQueueReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )
{
xErrorOccurred = pdTRUE;
}
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. */
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. */
if( xQueueSend( xTestQueue, &xItem, bktDONT_BLOCK ) != pdPASS )
{
xErrorOccurred = pdTRUE;
}
/*********************************************************************
Test 3
if( xRunIndicator == bktRUN_INDICATOR )
{
/* The other task should not have executed. */
xErrorOccurred = pdTRUE;
}
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.
/* Raise the priority of the other task so it executes and blocks
* on the queue again. */
vTaskPrioritySet( xSecondary, bktPRIMARY_PRIORITY + 2 );
Wake the other task so it blocks attempting to post to the already
full queue. */
xRunIndicator = 0;
vTaskResume( xSecondary );
/* The other task should now have re-blocked without exiting the
* queue function. */
if( xRunIndicator == bktRUN_INDICATOR )
{
/* The other task should not have executed outside of the
* queue function. */
xErrorOccurred = pdTRUE;
}
/* We need to wait a little to ensure the other task executes. */
while( xRunIndicator != bktRUN_INDICATOR )
{
/* 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;
/* Set the priority back down. */
vTaskPrioritySet( xSecondary, bktSECONDARY_PRIORITY );
}
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. */
if( xQueueReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )
{
xErrorOccurred = pdTRUE;
}
/* Let the other task timeout. When it unblockes it will check that it
* unblocked at the correct time, then suspend itself. */
while( xRunIndicator != bktRUN_INDICATOR )
{
vTaskDelay( bktSHORT_WAIT );
}
/* 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. */
if( xQueueSend( xTestQueue, &xItem, bktDONT_BLOCK ) != pdPASS )
{
xErrorOccurred = pdTRUE;
}
vTaskDelay( bktSHORT_WAIT );
xRunIndicator = 0;
if( xRunIndicator == bktRUN_INDICATOR )
{
/* The other task should not have executed. */
xErrorOccurred = pdTRUE;
}
/*********************************************************************
* 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 )
{
xErrorOccurred = pdTRUE;
}
}
/* Raise the priority of the other task so it executes and blocks
on the queue again. */
vTaskPrioritySet( xSecondary, bktPRIMARY_PRIORITY + 2 );
/* Wake the other task so it blocks attempting to read from the
* already empty queue. */
vTaskResume( xSecondary );
/* The other task should now have re-blocked without exiting the
queue function. */
if( xRunIndicator == bktRUN_INDICATOR )
{
/* The other task should not have executed outside of the
queue function. */
xErrorOccurred = pdTRUE;
}
/* We need to wait a little to ensure the other task executes. */
while( xRunIndicator != bktRUN_INDICATOR )
{
vTaskDelay( bktSHORT_WAIT );
}
/* Set the priority back down. */
vTaskPrioritySet( xSecondary, bktSECONDARY_PRIORITY );
}
vTaskDelay( bktSHORT_WAIT );
xRunIndicator = 0;
/* Let the other task timeout. When it unblockes it will check that it
unblocked at the correct time, then suspend itself. */
while( xRunIndicator != bktRUN_INDICATOR )
{
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. */
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. */
if( xQueueReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )
{
xErrorOccurred = pdTRUE;
}
/*********************************************************************
Test 4
if( xRunIndicator == bktRUN_INDICATOR )
{
/* The other task should not have executed. */
xErrorOccurred = pdTRUE;
}
As per test 3 - but with the send and receive the other way around.
The other task blocks attempting to read from the queue.
/* Raise the priority of the other task so it executes and blocks
* on the queue again. */
vTaskPrioritySet( xSecondary, bktPRIMARY_PRIORITY + 2 );
Empty the queue. We should find that it is full. */
for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
{
if( xQueueReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )
{
xErrorOccurred = pdTRUE;
}
}
/* The other task should now have re-blocked without exiting the
* queue function. */
if( xRunIndicator == bktRUN_INDICATOR )
{
/* The other task should not have executed outside of the
* queue function. */
xErrorOccurred = pdTRUE;
}
/* Wake the other task so it blocks attempting to read from the
already empty queue. */
vTaskResume( xSecondary );
vTaskPrioritySet( xSecondary, bktSECONDARY_PRIORITY );
}
/* We need to wait a little to ensure the other task executes. */
while( xRunIndicator != bktRUN_INDICATOR )
{
vTaskDelay( bktSHORT_WAIT );
}
vTaskDelay( bktSHORT_WAIT );
xRunIndicator = 0;
/* Let the other task timeout. When it unblockes it will check that it
* unblocked at the correct time, then suspend itself. */
while( xRunIndicator != bktRUN_INDICATOR )
{
vTaskDelay( bktSHORT_WAIT );
}
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. */
if( xQueueSend( xTestQueue, &xItem, bktDONT_BLOCK ) != pdPASS )
{
xErrorOccurred = pdTRUE;
}
vTaskDelay( bktSHORT_WAIT );
/* 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. */
if( xQueueReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )
{
xErrorOccurred = pdTRUE;
}
if( xRunIndicator == bktRUN_INDICATOR )
{
/* The other task should not have executed. */
xErrorOccurred = pdTRUE;
}
/* Raise the priority of the other task so it executes and blocks
on the queue again. */
vTaskPrioritySet( xSecondary, bktPRIMARY_PRIORITY + 2 );
/* The other task should now have re-blocked without exiting the
queue function. */
if( xRunIndicator == bktRUN_INDICATOR )
{
/* The other task should not have executed outside of the
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. */
while( xRunIndicator != bktRUN_INDICATOR )
{
vTaskDelay( bktSHORT_WAIT );
}
vTaskDelay( bktSHORT_WAIT );
xPrimaryCycles++;
}
xPrimaryCycles++;
}
}
/*-----------------------------------------------------------*/
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;
( void ) pvParameters;
for( ;; )
{
/*********************************************************************
Test 0, 1 and 2
for( ; ; )
{
/*********************************************************************
* Test 0, 1 and 2
*
* This task does not participate in these tests. */
vTaskSuspend( NULL );
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. */
xTimeWhenBlocking = xTaskGetTickCount();
/*********************************************************************
Test 3
/* We should unblock after bktTIME_TO_BLOCK having not sent anything to
* the queue. */
xData = 0;
xRunIndicator = bktRUN_INDICATOR;
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();
if( xQueueSend( xTestQueue, &xData, bktTIME_TO_BLOCK ) != errQUEUE_FULL )
{
xErrorOccurred = pdTRUE;
}
/* We should unblock after bktTIME_TO_BLOCK having not sent anything to
the queue. */
xData = 0;
xRunIndicator = bktRUN_INDICATOR;
if( xQueueSend( xTestQueue, &xData, bktTIME_TO_BLOCK ) != errQUEUE_FULL )
{
xErrorOccurred = pdTRUE;
}
/* How long were we inside the send function? */
xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
/* How long were we inside the send function? */
xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
/* We should not have blocked for less time than bktTIME_TO_BLOCK. */
if( xBlockedTime < bktTIME_TO_BLOCK )
{
xErrorOccurred = pdTRUE;
}
/* We should not have blocked for less time than bktTIME_TO_BLOCK. */
if( xBlockedTime < bktTIME_TO_BLOCK )
{
xErrorOccurred = pdTRUE;
}
/* 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. */
if( xBlockedTime > ( bktTIME_TO_BLOCK + bktALLOWABLE_MARGIN ) )
{
xErrorOccurred = pdTRUE;
}
/* 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. */
if( xBlockedTime > ( bktTIME_TO_BLOCK + bktALLOWABLE_MARGIN ) )
{
xErrorOccurred = pdTRUE;
}
/* Suspend ready for test 3. */
xRunIndicator = bktRUN_INDICATOR;
vTaskSuspend( NULL );
/* Suspend ready for test 3. */
xRunIndicator = bktRUN_INDICATOR;
vTaskSuspend( NULL );
/*********************************************************************
* Test 4
*
* As per test three, but with the send and receive reversed. */
xTimeWhenBlocking = xTaskGetTickCount();
/*********************************************************************
Test 4
/* We should unblock after bktTIME_TO_BLOCK having not received
* anything on the queue. */
xRunIndicator = bktRUN_INDICATOR;
As per test three, but with the send and receive reversed. */
xTimeWhenBlocking = xTaskGetTickCount();
if( xQueueReceive( xTestQueue, &xData, bktTIME_TO_BLOCK ) != errQUEUE_EMPTY )
{
xErrorOccurred = pdTRUE;
}
/* We should unblock after bktTIME_TO_BLOCK having not received
anything on the queue. */
xRunIndicator = bktRUN_INDICATOR;
if( xQueueReceive( xTestQueue, &xData, bktTIME_TO_BLOCK ) != errQUEUE_EMPTY )
{
xErrorOccurred = pdTRUE;
}
xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
/* We should not have blocked for less time than bktTIME_TO_BLOCK. */
if( xBlockedTime < bktTIME_TO_BLOCK )
{
xErrorOccurred = pdTRUE;
}
/* We should not have blocked for less time than bktTIME_TO_BLOCK. */
if( xBlockedTime < bktTIME_TO_BLOCK )
{
xErrorOccurred = pdTRUE;
}
/* 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. */
if( xBlockedTime > ( bktTIME_TO_BLOCK + bktALLOWABLE_MARGIN ) )
{
xErrorOccurred = pdTRUE;
}
/* 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. */
if( xBlockedTime > ( bktTIME_TO_BLOCK + bktALLOWABLE_MARGIN ) )
{
xErrorOccurred = pdTRUE;
}
xRunIndicator = bktRUN_INDICATOR;
xRunIndicator = bktRUN_INDICATOR;
xSecondaryCycles++;
}
xSecondaryCycles++;
}
}
/*-----------------------------------------------------------*/
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. */
vTaskPrioritySet( NULL, configTIMER_TASK_PRIORITY - 1 );
/* Temporarily increase priority so the timing is more accurate, but not so
* 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. */
xPreTime = xTaskGetTickCount();
vTaskDelay( bktTIME_TO_BLOCK );
xPostTime = xTaskGetTickCount();
/* Crude check to too see that vTaskDelay() blocks for the expected
* 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. */
if( ( xPostTime - xPreTime ) > ( bktTIME_TO_BLOCK + xAllowableMargin ) )
{
xErrorOccurred = pdTRUE;
}
/* The priority is higher, so the allowable margin is halved when compared
* to the other tests in this file. */
if( ( xPostTime - xPreTime ) > ( bktTIME_TO_BLOCK + xAllowableMargin ) )
{
xErrorOccurred = pdTRUE;
}
/* Now crude tests to check the vTaskDelayUntil() functionality. */
xPostTime = xTaskGetTickCount();
xLastUnblockTime = xPostTime;
/* Now crude tests to check the vTaskDelayUntil() functionality. */
xPostTime = xTaskGetTickCount();
xLastUnblockTime = xPostTime;
for( x = 0; x < xCycles; x++ )
{
/* Calculate the next expected unblock time from the time taken before
this loop was entered. */
xExpectedUnblockTime = xPostTime + ( x * xPeriod );
for( x = 0; x < xCycles; x++ )
{
/* Calculate the next expected unblock time from the time taken before
* this loop was entered. */
xExpectedUnblockTime = xPostTime + ( x * xPeriod );
vTaskDelayUntil( &xLastUnblockTime, xPeriod );
vTaskDelayUntil( &xLastUnblockTime, xPeriod );
if( ( xTaskGetTickCount() - xExpectedUnblockTime ) > ( bktTIME_TO_BLOCK + xAllowableMargin ) )
{
xErrorOccurred = pdTRUE;
}
if( ( xTaskGetTickCount() - xExpectedUnblockTime ) > ( bktTIME_TO_BLOCK + xAllowableMargin ) )
{
xErrorOccurred = pdTRUE;
}
xPrimaryCycles++;
}
xPrimaryCycles++;
}
/* Crude tests for return value of xTaskDelayUntil(). First a standard block
should return that the task does block. */
xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
if( xDidBlock != pdTRUE )
{
xErrorOccurred = pdTRUE;
}
/* Crude tests for return value of xTaskDelayUntil(). First a standard block
* should return that the task does block. */
xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
/* Now delay a few ticks so repeating the above block period will not block for
the full amount of time, but will still block. */
vTaskDelay( xHalfPeriod );
xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
if( xDidBlock != pdTRUE )
{
xErrorOccurred = pdTRUE;
}
if( xDidBlock != pdTRUE )
{
xErrorOccurred = pdTRUE;
}
/* This time block for longer than xPeriod before calling xTaskDelayUntil() so
the call to xTaskDelayUntil() should not block. */
vTaskDelay( xPeriod );
xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
if( xDidBlock != pdFALSE )
{
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. */
vTaskDelay( xHalfPeriod );
xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
/* Catch up. */
xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
if( xDidBlock != pdTRUE )
{
xErrorOccurred = pdTRUE;
}
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. */
vTaskDelay( xPeriod + xAllowableMargin );
xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
if( xDidBlock != pdFALSE )
{
xErrorOccurred = pdTRUE;
}
/* This time block for longer than xPeriod before calling xTaskDelayUntil() so
* the call to xTaskDelayUntil() should not block. */
vTaskDelay( xPeriod );
xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
/* Reset to the original task priority ready for the other tests. */
vTaskPrioritySet( NULL, bktPRIMARY_PRIORITY );
if( xDidBlock != pdFALSE )
{
xErrorOccurred = pdTRUE;
}
/* 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. */
vTaskDelay( xPeriod + xAllowableMargin );
xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
if( xDidBlock != pdFALSE )
{
xErrorOccurred = pdTRUE;
}
/* Reset to the original task priority ready for the other tests. */
vTaskPrioritySet( NULL, bktPRIMARY_PRIORITY );
}
/*-----------------------------------------------------------*/
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? */
if( xPrimaryCycles == xLastPrimaryCycleCount )
{
xReturn = pdFAIL;
}
/* Have both tasks performed at least one cycle since this function was
* last called? */
if( xPrimaryCycles == xLastPrimaryCycleCount )
{
xReturn = pdFAIL;
}
if( xSecondaryCycles == xLastSecondaryCycleCount )
{
xReturn = pdFAIL;
}
if( xSecondaryCycles == xLastSecondaryCycleCount )
{
xReturn = pdFAIL;
}
if( xErrorOccurred == pdTRUE )
{
xReturn = pdFAIL;
}
if( xErrorOccurred == pdTRUE )
{
xReturn = pdFAIL;
}
xLastSecondaryCycleCount = xSecondaryCycles;
xLastPrimaryCycleCount = xPrimaryCycles;
xLastSecondaryCycleCount = xSecondaryCycles;
xLastPrimaryCycleCount = xPrimaryCycles;
return xReturn;
return xReturn;
}

View file

@ -67,30 +67,30 @@
#include "comtest.h"
#include "partest.h"
#define comSTACK_SIZE configMINIMAL_STACK_SIZE
#define comTX_LED_OFFSET ( 0 )
#define comRX_LED_OFFSET ( 1 )
#define comTOTAL_PERMISSIBLE_ERRORS ( 2 )
#define comSTACK_SIZE configMINIMAL_STACK_SIZE
#define comTX_LED_OFFSET ( 0 )
#define comRX_LED_OFFSET ( 1 )
#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. */
#define comTX_MAX_BLOCK_TIME ( ( TickType_t ) 0x96 )
#define comTX_MIN_BLOCK_TIME ( ( TickType_t ) 0x32 )
#define comOFFSET_TIME ( ( TickType_t ) 3 )
* 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. */
#define comNO_BLOCK ( ( TickType_t ) 0 )
* 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. */
#define comRX_BLOCK_TIME ( ( TickType_t ) 0xffff )
#define comRX_BLOCK_TIME ( ( TickType_t ) 0xffff )
/* The sequence transmitted is from comFIRST_BYTE to and including comLAST_BYTE. */
#define comFIRST_BYTE ( 'A' )
#define comLAST_BYTE ( 'X' )
#define comFIRST_BYTE ( 'A' )
#define comLAST_BYTE ( 'X' )
#define comBUFFER_LEN ( ( UBaseType_t ) ( comLAST_BYTE - comFIRST_BYTE ) + ( UBaseType_t ) 1 )
#define comINITIAL_RX_COUNT_VALUE ( 0 )
#define comBUFFER_LEN ( ( UBaseType_t ) ( comLAST_BYTE - comFIRST_BYTE ) + ( UBaseType_t ) 1 )
#define comINITIAL_RX_COUNT_VALUE ( 0 )
/* Handle to the com port used by both tasks. */
static xComPortHandle xPort = NULL;
@ -102,164 +102,165 @@ 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;
xSerialPortInitMinimal( ulBaudRate, comBUFFER_LEN );
/* Initialise the com port then spawn the Rx and Tx tasks. */
uxBaseLED = uxLED;
xSerialPortInitMinimal( ulBaudRate, comBUFFER_LEN );
/* The Tx task is spawned with a lower priority than the Rx task. */
xTaskCreate( vComTxTask, "COMTx", comSTACK_SIZE, NULL, uxPriority - 1, ( TaskHandle_t * ) NULL );
xTaskCreate( vComRxTask, "COMRx", comSTACK_SIZE, NULL, uxPriority, ( TaskHandle_t * ) NULL );
/* The Tx task is spawned with a lower priority than the Rx task. */
xTaskCreate( vComTxTask, "COMTx", comSTACK_SIZE, NULL, uxPriority - 1, ( TaskHandle_t * ) NULL );
xTaskCreate( vComRxTask, "COMRx", comSTACK_SIZE, NULL, uxPriority, ( TaskHandle_t * ) NULL );
}
/*-----------------------------------------------------------*/
static portTASK_FUNCTION( vComTxTask, pvParameters )
{
char cByteToSend;
TickType_t xTimeToWait;
char cByteToSend;
TickType_t xTimeToWait;
/* Just to stop compiler warnings. */
( void ) pvParameters;
/* Just to stop compiler warnings. */
( void ) pvParameters;
for( ;; )
{
/* Simply transmit a sequence of characters from comFIRST_BYTE to
comLAST_BYTE. */
for( cByteToSend = comFIRST_BYTE; cByteToSend <= comLAST_BYTE; cByteToSend++ )
{
if( xSerialPutChar( xPort, cByteToSend, comNO_BLOCK ) == pdPASS )
{
vParTestToggleLED( uxBaseLED + comTX_LED_OFFSET );
}
}
for( ; ; )
{
/* Simply transmit a sequence of characters from comFIRST_BYTE to
* comLAST_BYTE. */
for( cByteToSend = comFIRST_BYTE; cByteToSend <= comLAST_BYTE; cByteToSend++ )
{
if( xSerialPutChar( xPort, cByteToSend, comNO_BLOCK ) == pdPASS )
{
vParTestToggleLED( uxBaseLED + comTX_LED_OFFSET );
}
}
/* Turn the LED off while we are not doing anything. */
vParTestSetLED( uxBaseLED + comTX_LED_OFFSET, pdFALSE );
/* Turn the LED off while we are not doing anything. */
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. */
xTimeToWait = xTaskGetTickCount() + comOFFSET_TIME;
/* 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. */
xTimeToWait = xTaskGetTickCount() + comOFFSET_TIME;
/* Make sure we don't wait too long... */
xTimeToWait %= comTX_MAX_BLOCK_TIME;
/* Make sure we don't wait too long... */
xTimeToWait %= comTX_MAX_BLOCK_TIME;
/* ...but we do want to wait. */
if( xTimeToWait < comTX_MIN_BLOCK_TIME )
{
xTimeToWait = comTX_MIN_BLOCK_TIME;
}
/* ...but we do want to wait. */
if( xTimeToWait < comTX_MIN_BLOCK_TIME )
{
xTimeToWait = comTX_MIN_BLOCK_TIME;
}
vTaskDelay( xTimeToWait );
}
vTaskDelay( xTimeToWait );
}
} /*lint !e715 !e818 pvParameters is required for a task function even if it is not referenced. */
/*-----------------------------------------------------------*/
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;
/* Just to stop compiler warnings. */
( void ) pvParameters;
for( ;; )
{
/* We expect to receive the characters from comFIRST_BYTE to
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. */
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. */
if( cByteRxed == cExpectedByte )
{
vParTestToggleLED( uxBaseLED + comRX_LED_OFFSET );
}
else
{
xResyncRequired = pdTRUE;
break; /*lint !e960 Non-switch break allowed. */
}
}
}
for( ; ; )
{
/* We expect to receive the characters from comFIRST_BYTE to
* 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. */
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. */
if( cByteRxed == cExpectedByte )
{
vParTestToggleLED( uxBaseLED + comRX_LED_OFFSET );
}
else
{
xResyncRequired = pdTRUE;
break; /*lint !e960 Non-switch break allowed. */
}
}
}
/* Turn the LED off while we are not doing anything. */
vParTestSetLED( uxBaseLED + comRX_LED_OFFSET, pdFALSE );
/* Turn the LED off while we are not doing anything. */
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. */
if( xResyncRequired == pdTRUE )
{
while( cByteRxed != comLAST_BYTE )
{
/* Block until the next char is available. */
xSerialGetChar( xPort, &cByteRxed, comRX_BLOCK_TIME );
}
/* 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. */
if( xResyncRequired == pdTRUE )
{
while( cByteRxed != comLAST_BYTE )
{
/* Block until the next char is available. */
xSerialGetChar( xPort, &cByteRxed, comRX_BLOCK_TIME );
}
/* 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. */
xErrorOccurred++;
/* 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. */
xErrorOccurred++;
/* We have now resynced with the Tx task and can continue. */
xResyncRequired = pdFALSE;
}
else
{
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. */
uxRxLoops++;
}
}
}
/* We have now resynced with the Tx task and can continue. */
xResyncRequired = pdFALSE;
}
else
{
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. */
uxRxLoops++;
}
}
}
} /*lint !e715 !e818 pvParameters is required for a task function even if it is not referenced. */
/*-----------------------------------------------------------*/
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. */
if( uxRxLoops == comINITIAL_RX_COUNT_VALUE )
{
xReturn = pdFALSE;
}
else
{
xReturn = pdTRUE;
}
/* 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. */
if( uxRxLoops == comINITIAL_RX_COUNT_VALUE )
{
xReturn = pdFALSE;
}
else
{
xReturn = pdTRUE;
}
/* Reset the count of successful Rx loops. When this function is called
again we expect this to have been incremented. */
uxRxLoops = comINITIAL_RX_COUNT_VALUE;
/* Reset the count of successful Rx loops. When this function is called
* again we expect this to have been incremented. */
uxRxLoops = comINITIAL_RX_COUNT_VALUE;
return xReturn;
return xReturn;
}

View file

@ -57,11 +57,11 @@
#include "timers.h"
#ifndef configUSE_TIMERS
#error This demo uses timers. configUSE_TIMERS must be set to 1 in FreeRTOSConfig.h.
#error This demo uses timers. configUSE_TIMERS must be set to 1 in FreeRTOSConfig.h.
#endif
#if configUSE_TIMERS != 1
#error This demo uses timers. configUSE_TIMERS must be set to 1 in FreeRTOSConfig.h.
#error This demo uses timers. configUSE_TIMERS must be set to 1 in FreeRTOSConfig.h.
#endif
@ -71,240 +71,246 @@
#include "partest.h"
/* The size of the stack given to the Rx task. */
#define comSTACK_SIZE configMINIMAL_STACK_SIZE
#define comSTACK_SIZE configMINIMAL_STACK_SIZE
/* See the comment above the declaration of the uxBaseLED variable. */
#define comTX_LED_OFFSET ( 0 )
#define comRX_LED_OFFSET ( 1 )
#define comTX_LED_OFFSET ( 0 )
#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. */
#define comTX_MAX_BLOCK_TIME ( ( TickType_t ) 0x96 )
#define comTX_MIN_BLOCK_TIME ( ( TickType_t ) 0x32 )
#define comOFFSET_TIME ( ( TickType_t ) 3 )
* 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 )
/* States for the simple state machine implemented in the Rx task. */
#define comtstWAITING_START_OF_STRING 0
#define comtstWAITING_END_OF_STRING 1
#define comtstWAITING_START_OF_STRING 0
#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. */
#define comSHORT_DELAY ( comTX_MIN_BLOCK_TIME >> ( TickType_t ) 2 )
* 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. */
#define comTRANSACTED_STRING "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
#define comTRANSACTED_STRING "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
/* A block time of 0 simply means "don't block". */
#define comtstDONT_BLOCK ( TickType_t ) 0
#define comtstDONT_BLOCK ( TickType_t ) 0
/* Handle to the com port used by both tasks. */
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;
/* Store values that are used at run time. */
uxBaseLED = uxLED;
/* Calculate the string length here, rather than each time the Tx timer
executes. */
xStringLength = strlen( comTRANSACTED_STRING );
/* Calculate the string length here, rather than each time the Tx timer
* 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. */
xStringLength++;
/* Include the null terminator in the string length as this is used to
* 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. */
xSerialPortInitMinimal( ulBaudRate, ( xStringLength * 2U ) );
/* Initialise the com port, then spawn the Rx task and create the Tx
* timer. */
xSerialPortInitMinimal( ulBaudRate, ( xStringLength * 2U ) );
/* Create the Rx task and the Tx timer. The timer is started from the
Rx task. */
xTaskCreate( vComRxTask, "COMRx", comSTACK_SIZE, NULL, uxPriority, ( TaskHandle_t * ) NULL );
xTxTimer = xTimerCreate( "TxTimer", comTX_MIN_BLOCK_TIME, pdFALSE, NULL, prvComTxTimerCallback );
configASSERT( xTxTimer );
/* Create the Rx task and the Tx timer. The timer is started from the
* Rx task. */
xTaskCreate( vComRxTask, "COMRx", comSTACK_SIZE, NULL, uxPriority, ( TaskHandle_t * ) NULL );
xTxTimer = xTimerCreate( "TxTimer", comTX_MIN_BLOCK_TIME, pdFALSE, NULL, prvComTxTimerCallback );
configASSERT( xTxTimer );
}
/*-----------------------------------------------------------*/
static void prvComTxTimerCallback( TimerHandle_t xTimer )
{
TickType_t xTimeToWait;
TickType_t xTimeToWait;
/* The parameter is not used in this case. */
( void ) xTimer;
/* 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. */
vSerialPutString( xPort, comTRANSACTED_STRING, xStringLength );
/* 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. */
vSerialPutString( xPort, comTRANSACTED_STRING, xStringLength );
/* Toggle an LED to give a visible indication that another transmission
has been performed. */
vParTestToggleLED( uxBaseLED + comTX_LED_OFFSET );
/* Toggle an LED to give a visible indication that another transmission
* has been performed. */
vParTestToggleLED( uxBaseLED + comTX_LED_OFFSET );
/* Wait a pseudo random time before sending the string again. */
xTimeToWait = xTaskGetTickCount() + comOFFSET_TIME;
/* Wait a pseudo random time before sending the string again. */
xTimeToWait = xTaskGetTickCount() + comOFFSET_TIME;
/* Ensure the time to wait is not greater than comTX_MAX_BLOCK_TIME. */
xTimeToWait %= comTX_MAX_BLOCK_TIME;
/* Ensure the time to wait is not greater than comTX_MAX_BLOCK_TIME. */
xTimeToWait %= comTX_MAX_BLOCK_TIME;
/* Ensure the time to wait is not less than comTX_MIN_BLOCK_TIME. */
if( xTimeToWait < comTX_MIN_BLOCK_TIME )
{
xTimeToWait = comTX_MIN_BLOCK_TIME;
}
/* Ensure the time to wait is not less than comTX_MIN_BLOCK_TIME. */
if( xTimeToWait < comTX_MIN_BLOCK_TIME )
{
xTimeToWait = comTX_MIN_BLOCK_TIME;
}
/* 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. */
xTimerChangePeriod( xTxTimer, xTimeToWait, comtstDONT_BLOCK );
/* 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. */
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;
/* 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. */
xTimerStart( xTxTimer, portMAX_DELAY );
/* Start the Tx timer. This only needs to be started once, as it will
* reset itself thereafter. */
xTimerStart( xTxTimer, portMAX_DELAY );
/* The first expected Rx character is the first in the string that is
transmitted. */
pcExpectedByte = comTRANSACTED_STRING;
/* The first expected Rx character is the first in the string that is
* transmitted. */
pcExpectedByte = comTRANSACTED_STRING;
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). */
xErrorOccurred = pdTRUE;
}
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). */
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. */
xState = comtstWAITING_END_OF_STRING;
pcExpectedByte++;
switch( xState )
{
case comtstWAITING_START_OF_STRING:
/* 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. */
vTaskDelay( comSHORT_DELAY );
}
break;
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. */
xState = comtstWAITING_END_OF_STRING;
pcExpectedByte++;
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? */
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. */
if( xErrorOccurred == pdFALSE )
{
uxRxLoops++;
/* 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. */
vTaskDelay( comSHORT_DELAY );
}
/* Toggle an LED to give a visible sign that a
complete string has been received. */
vParTestToggleLED( uxBaseLED + comRX_LED_OFFSET );
}
break;
/* Go back to wait for the start of the next string. */
pcExpectedByte = comTRANSACTED_STRING;
xState = comtstWAITING_START_OF_STRING;
}
else
{
/* Wait for the next character in the string. */
pcExpectedByte++;
}
}
else
{
/* The character received was not that expected. */
xErrorOccurred = pdTRUE;
}
break;
case comtstWAITING_END_OF_STRING:
default:
/* Should not get here. Stop the Rx loop counter from
incrementing to latch the error. */
xErrorOccurred = pdTRUE;
break;
}
}
if( cRxedChar == *pcExpectedByte )
{
/* The received character was the expected character. Was
* 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. */
if( xErrorOccurred == pdFALSE )
{
uxRxLoops++;
/* Toggle an LED to give a visible sign that a
* complete string has been received. */
vParTestToggleLED( uxBaseLED + comRX_LED_OFFSET );
}
/* Go back to wait for the start of the next string. */
pcExpectedByte = comTRANSACTED_STRING;
xState = comtstWAITING_START_OF_STRING;
}
else
{
/* Wait for the next character in the string. */
pcExpectedByte++;
}
}
else
{
/* 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. */
xErrorOccurred = pdTRUE;
break;
}
}
}
/*-----------------------------------------------------------*/
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. */
if( uxRxLoops == 0UL )
{
xReturn = pdFALSE;
}
else
{
xReturn = pdTRUE;
}
/* 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. */
if( uxRxLoops == 0UL )
{
xReturn = pdFALSE;
}
else
{
xReturn = pdTRUE;
}
/* Reset the count of successful Rx loops. When this function is called
again it should have been incremented again. */
uxRxLoops = 0UL;
/* Reset the count of successful Rx loops. When this function is called
* again it should have been incremented again. */
uxRxLoops = 0UL;
return xReturn;
return xReturn;
}

View file

@ -39,24 +39,24 @@
#include "countsem.h"
/* The maximum count value that the semaphore used for the demo can hold. */
#define countMAX_COUNT_VALUE ( 200 )
#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. */
#define countSTART_AT_MAX_COUNT ( 0xaa )
#define countSTART_AT_ZERO ( 0x55 )
* 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. */
#define countNUM_TEST_TASKS ( 2 )
#define countDONT_BLOCK ( 0 )
* 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,36 +67,38 @@ 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 );
/*-----------------------------------------------------------*/
/* The structure that is passed into the task as the task parameter. */
typedef struct COUNT_SEM_STRUCT
{
/* The semaphore to be used for the demo. */
SemaphoreHandle_t xSemaphore;
/* The semaphore to be used for the demo. */
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. */
UBaseType_t uxExpectedStartCount;
/* 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. */
UBaseType_t uxExpectedStartCount;
/* Incremented on each cycle of the demo task. Used to detect a stalled
task. */
volatile UBaseType_t uxLoopCounter;
/* Incremented on each cycle of the demo task. Used to detect a stalled
* task. */
volatile UBaseType_t uxLoopCounter;
} xCountSemStruct;
/* Two structures are defined, one is passed to each test task. */
@ -106,183 +108,184 @@ 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. */
xParameters[ 0 ].xSemaphore = xSemaphoreCreateCounting( countMAX_COUNT_VALUE, countMAX_COUNT_VALUE );
xParameters[ 0 ].uxExpectedStartCount = countSTART_AT_MAX_COUNT;
xParameters[ 0 ].uxLoopCounter = 0;
/* 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. */
xParameters[ 0 ].xSemaphore = xSemaphoreCreateCounting( countMAX_COUNT_VALUE, countMAX_COUNT_VALUE );
xParameters[ 0 ].uxExpectedStartCount = countSTART_AT_MAX_COUNT;
xParameters[ 0 ].uxLoopCounter = 0;
xParameters[ 1 ].xSemaphore = xSemaphoreCreateCounting( countMAX_COUNT_VALUE, 0 );
xParameters[ 1 ].uxExpectedStartCount = 0;
xParameters[ 1 ].uxLoopCounter = 0;
xParameters[ 1 ].xSemaphore = xSemaphoreCreateCounting( countMAX_COUNT_VALUE, 0 );
xParameters[ 1 ].uxExpectedStartCount = 0;
xParameters[ 1 ].uxLoopCounter = 0;
/* Were the semaphores created? */
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. */
vQueueAddToRegistry( ( QueueHandle_t ) xParameters[ 0 ].xSemaphore, "Counting_Sem_1" );
vQueueAddToRegistry( ( QueueHandle_t ) xParameters[ 1 ].xSemaphore, "Counting_Sem_2" );
/* Were the semaphores created? */
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. */
vQueueAddToRegistry( ( QueueHandle_t ) xParameters[ 0 ].xSemaphore, "Counting_Sem_1" );
vQueueAddToRegistry( ( QueueHandle_t ) xParameters[ 1 ].xSemaphore, "Counting_Sem_2" );
/* Create the demo tasks, passing in the semaphore to use as the parameter. */
xTaskCreate( prvCountingSemaphoreTask, "CNT1", configMINIMAL_STACK_SIZE, ( void * ) &( xParameters[ 0 ] ), tskIDLE_PRIORITY, NULL );
xTaskCreate( prvCountingSemaphoreTask, "CNT2", configMINIMAL_STACK_SIZE, ( void * ) &( xParameters[ 1 ] ), tskIDLE_PRIORITY, NULL );
}
/* Create the demo tasks, passing in the semaphore to use as the parameter. */
xTaskCreate( prvCountingSemaphoreTask, "CNT1", configMINIMAL_STACK_SIZE, ( void * ) &( xParameters[ 0 ] ), tskIDLE_PRIORITY, NULL );
xTaskCreate( prvCountingSemaphoreTask, "CNT2", configMINIMAL_STACK_SIZE, ( void * ) &( xParameters[ 1 ] ), tskIDLE_PRIORITY, NULL );
}
}
/*-----------------------------------------------------------*/
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. */
if( xSemaphoreGive( xSemaphore ) == pdPASS )
{
xErrorDetected = pdTRUE;
}
/* If the semaphore count is at its maximum then we should not be able to
* 'give' the semaphore. */
if( xSemaphoreGive( xSemaphore ) == pdPASS )
{
xErrorDetected = pdTRUE;
}
/* We should be able to 'take' the semaphore countMAX_COUNT_VALUE times. */
for( ux = 0; ux < countMAX_COUNT_VALUE; ux++ )
{
configASSERT( uxSemaphoreGetCount( xSemaphore ) == ( countMAX_COUNT_VALUE - ux ) );
/* We should be able to 'take' the semaphore countMAX_COUNT_VALUE times. */
for( ux = 0; ux < countMAX_COUNT_VALUE; ux++ )
{
configASSERT( uxSemaphoreGetCount( xSemaphore ) == ( countMAX_COUNT_VALUE - ux ) );
if( xSemaphoreTake( xSemaphore, countDONT_BLOCK ) != pdPASS )
{
/* We expected to be able to take the semaphore. */
xErrorDetected = pdTRUE;
}
if( xSemaphoreTake( xSemaphore, countDONT_BLOCK ) != pdPASS )
{
/* We expected to be able to take the semaphore. */
xErrorDetected = pdTRUE;
}
( *puxLoopCounter )++;
}
( *puxLoopCounter )++;
}
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
/* If the semaphore count is zero then we should not be able to 'take'
the semaphore. */
configASSERT( uxSemaphoreGetCount( xSemaphore ) == 0 );
if( xSemaphoreTake( xSemaphore, countDONT_BLOCK ) == pdPASS )
{
xErrorDetected = pdTRUE;
}
/* If the semaphore count is zero then we should not be able to 'take'
* the semaphore. */
configASSERT( uxSemaphoreGetCount( xSemaphore ) == 0 );
if( xSemaphoreTake( xSemaphore, countDONT_BLOCK ) == pdPASS )
{
xErrorDetected = pdTRUE;
}
}
/*-----------------------------------------------------------*/
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. */
if( xSemaphoreTake( xSemaphore, countDONT_BLOCK ) == pdPASS )
{
xErrorDetected = pdTRUE;
}
/* If the semaphore count is zero then we should not be able to 'take'
* the semaphore. */
if( xSemaphoreTake( xSemaphore, countDONT_BLOCK ) == pdPASS )
{
xErrorDetected = pdTRUE;
}
/* We should be able to 'give' the semaphore countMAX_COUNT_VALUE times. */
for( ux = 0; ux < countMAX_COUNT_VALUE; ux++ )
{
configASSERT( uxSemaphoreGetCount( xSemaphore ) == ux );
/* We should be able to 'give' the semaphore countMAX_COUNT_VALUE times. */
for( ux = 0; ux < countMAX_COUNT_VALUE; ux++ )
{
configASSERT( uxSemaphoreGetCount( xSemaphore ) == ux );
if( xSemaphoreGive( xSemaphore ) != pdPASS )
{
/* We expected to be able to take the semaphore. */
xErrorDetected = pdTRUE;
}
if( xSemaphoreGive( xSemaphore ) != pdPASS )
{
/* We expected to be able to take the semaphore. */
xErrorDetected = pdTRUE;
}
( *puxLoopCounter )++;
}
( *puxLoopCounter )++;
}
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
/* If the semaphore count is at its maximum then we should not be able to
'give' the semaphore. */
if( xSemaphoreGive( xSemaphore ) == pdPASS )
{
xErrorDetected = pdTRUE;
}
/* If the semaphore count is at its maximum then we should not be able to
* 'give' the semaphore. */
if( xSemaphoreGive( xSemaphore ) == pdPASS )
{
xErrorDetected = pdTRUE;
}
}
/*-----------------------------------------------------------*/
static void prvCountingSemaphoreTask( void *pvParameters )
static void prvCountingSemaphoreTask( void * pvParameters )
{
xCountSemStruct *pxParameter;
xCountSemStruct * pxParameter;
#ifdef USE_STDIO
void vPrintDisplayMessage( const char * const * ppcMessageToSend );
#ifdef USE_STDIO
void vPrintDisplayMessage( const char * const * ppcMessageToSend );
const char * const pcTaskStartMsg = "Counting semaphore demo started.\r\n";
const char * const pcTaskStartMsg = "Counting semaphore demo started.\r\n";
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcTaskStartMsg );
#endif
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcTaskStartMsg );
#endif
/* The semaphore to be used was passed as the parameter. */
pxParameter = ( xCountSemStruct * ) pvParameters;
/* The semaphore to be used was passed as the parameter. */
pxParameter = ( xCountSemStruct * ) pvParameters;
/* Did we expect to find the semaphore already at its max count value, or
at zero? */
if( pxParameter->uxExpectedStartCount == countSTART_AT_MAX_COUNT )
{
prvDecrementSemaphoreCount( pxParameter->xSemaphore, &( pxParameter->uxLoopCounter ) );
}
/* Did we expect to find the semaphore already at its max count value, or
* 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. */
if( xSemaphoreTake( pxParameter->xSemaphore, 0 ) == pdPASS )
{
xErrorDetected = pdTRUE;
}
/* Now we expect the semaphore count to be 0, so this time there is an
* error if we can take the semaphore. */
if( xSemaphoreTake( pxParameter->xSemaphore, 0 ) == pdPASS )
{
xErrorDetected = pdTRUE;
}
for( ;; )
{
prvIncrementSemaphoreCount( pxParameter->xSemaphore, &( pxParameter->uxLoopCounter ) );
prvDecrementSemaphoreCount( pxParameter->xSemaphore, &( pxParameter->uxLoopCounter ) );
}
for( ; ; )
{
prvIncrementSemaphoreCount( pxParameter->xSemaphore, &( pxParameter->uxLoopCounter ) );
prvDecrementSemaphoreCount( pxParameter->xSemaphore, &( pxParameter->uxLoopCounter ) );
}
}
/*-----------------------------------------------------------*/
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. */
if( xErrorDetected != pdFALSE )
{
xReturn = pdFAIL;
}
/* Return fail if any 'give' or 'take' did not result in the expected
* behaviour. */
if( xErrorDetected != pdFALSE )
{
xReturn = pdFAIL;
}
/* Return fail if either task is not still incrementing its loop counter. */
if( uxLastCount0 == xParameters[ 0 ].uxLoopCounter )
{
xReturn = pdFAIL;
}
else
{
uxLastCount0 = xParameters[ 0 ].uxLoopCounter;
}
/* Return fail if either task is not still incrementing its loop counter. */
if( uxLastCount0 == xParameters[ 0 ].uxLoopCounter )
{
xReturn = pdFAIL;
}
else
{
uxLastCount0 = xParameters[ 0 ].uxLoopCounter;
}
if( uxLastCount1 == xParameters[ 1 ].uxLoopCounter )
{
xReturn = pdFAIL;
}
else
{
uxLastCount1 = xParameters[ 1 ].uxLoopCounter;
}
if( uxLastCount1 == xParameters[ 1 ].uxLoopCounter )
{
xReturn = pdFAIL;
}
else
{
uxLastCount1 = xParameters[ 1 ].uxLoopCounter;
}
return xReturn;
return xReturn;
}

View file

@ -61,34 +61,36 @@
#include "crflash.h"
/* The queue should only need to be of length 1. See the description at the
top of the file. */
#define crfQUEUE_LENGTH 1
* top of the file. */
#define crfQUEUE_LENGTH 1
#define crfFIXED_DELAY_PRIORITY 0
#define crfFLASH_PRIORITY 1
#define crfFIXED_DELAY_PRIORITY 0
#define crfFLASH_PRIORITY 1
/* Only one flash co-routine is created so the index is not significant. */
#define crfFLASH_INDEX 0
#define crfFLASH_INDEX 0
/* Don't allow more than crfMAX_FLASH_TASKS 'fixed delay' co-routines to be
created. */
#define crfMAX_FLASH_TASKS 8
* created. */
#define crfMAX_FLASH_TASKS 8
/* We don't want to block when posting to the queue. */
#define crfPOSTING_BLOCK_TIME 0
#define crfPOSTING_BLOCK_TIME 0
/*
* 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,108 +103,113 @@ static BaseType_t xCoRoutineFlashStatus = pdPASS;
*/
void vStartFlashCoRoutines( UBaseType_t uxNumberToCreate )
{
UBaseType_t uxIndex;
UBaseType_t uxIndex;
if( uxNumberToCreate > crfMAX_FLASH_TASKS )
{
uxNumberToCreate = crfMAX_FLASH_TASKS;
}
if( uxNumberToCreate > crfMAX_FLASH_TASKS )
{
uxNumberToCreate = crfMAX_FLASH_TASKS;
}
/* Create the queue used to pass data between the co-routines. */
xFlashQueue = xQueueCreate( crfQUEUE_LENGTH, sizeof( UBaseType_t ) );
/* Create the queue used to pass data between the co-routines. */
xFlashQueue = xQueueCreate( crfQUEUE_LENGTH, sizeof( UBaseType_t ) );
if( xFlashQueue )
{
/* Create uxNumberToCreate 'fixed delay' co-routines. */
for( uxIndex = 0; uxIndex < uxNumberToCreate; uxIndex++ )
{
xCoRoutineCreate( prvFixedDelayCoRoutine, crfFIXED_DELAY_PRIORITY, uxIndex );
}
if( xFlashQueue )
{
/* Create uxNumberToCreate 'fixed delay' co-routines. */
for( uxIndex = 0; uxIndex < uxNumberToCreate; uxIndex++ )
{
xCoRoutineCreate( prvFixedDelayCoRoutine, crfFIXED_DELAY_PRIORITY, uxIndex );
}
/* Create the 'flash' co-routine. */
xCoRoutineCreate( prvFlashCoRoutine, crfFLASH_PRIORITY, crfFLASH_INDEX );
}
/* Create the 'flash' co-routine. */
xCoRoutineCreate( prvFlashCoRoutine, crfFLASH_PRIORITY, crfFLASH_INDEX );
}
}
/*-----------------------------------------------------------*/
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,
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 };
* 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
};
/* Co-routines MUST start with a call to crSTART. */
crSTART( xHandle );
/* Co-routines MUST start with a call to crSTART. */
crSTART( xHandle );
for( ;; )
{
/* Post our uxIndex value onto the queue. This is used as the LED to
flash. */
crQUEUE_SEND( xHandle, xFlashQueue, ( void * ) &uxIndex, crfPOSTING_BLOCK_TIME, &xResult );
for( ; ; )
{
/* Post our uxIndex value onto the queue. This is used as the LED to
* 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. */
xCoRoutineFlashStatus = pdFAIL;
}
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. */
xCoRoutineFlashStatus = pdFAIL;
}
crDELAY( xHandle, xFlashRates[ uxIndex ] );
}
crDELAY( xHandle, xFlashRates[ uxIndex ] );
}
/* Co-routines MUST end with a call to crEND. */
crEND();
/* Co-routines MUST end with a call to crEND. */
crEND();
}
/*-----------------------------------------------------------*/
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;
/* Co-routines MUST start with a call to crSTART. */
crSTART( xHandle );
( void ) uxIndex;
for( ;; )
{
/* Block to wait for the number of the LED to flash. */
crQUEUE_RECEIVE( xHandle, xFlashQueue, &uxLEDToFlash, portMAX_DELAY, &xResult );
for( ; ; )
{
/* Block to wait for the number of the LED to flash. */
crQUEUE_RECEIVE( xHandle, xFlashQueue, &uxLEDToFlash, portMAX_DELAY, &xResult );
if( xResult != pdPASS )
{
/* We would not expect to wake unless we received something. */
xCoRoutineFlashStatus = pdFAIL;
}
else
{
/* We received the number of an LED to flash - flash it! */
vParTestToggleLED( uxLEDToFlash );
}
}
if( xResult != pdPASS )
{
/* We would not expect to wake unless we received something. */
xCoRoutineFlashStatus = pdFAIL;
}
else
{
/* We received the number of an LED to flash - flash it! */
vParTestToggleLED( uxLEDToFlash );
}
}
/* Co-routines MUST end with a call to crEND. */
crEND();
/* Co-routines MUST end with a call to crEND. */
crEND();
}
/*-----------------------------------------------------------*/
BaseType_t xAreFlashCoRoutinesStillRunning( void )
{
/* Return pdPASS or pdFAIL depending on whether an error has been detected
or not. */
return xCoRoutineFlashStatus;
/* Return pdPASS or pdFAIL depending on whether an error has been detected
* or not. */
return xCoRoutineFlashStatus;
}

View file

@ -57,27 +57,28 @@
#include "crhook.h"
/* The number of 'hook' co-routines that are to be created. */
#define hookNUM_HOOK_CO_ROUTINES ( 4 )
#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. */
#define hookTICK_CALLS_BEFORE_POST ( 500 )
* 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. */
#define hookHOOK_QUEUE_LENGTH ( 1 )
#define hookHOOK_QUEUE_LENGTH ( 1 )
/* Don't block when initially posting to the queue. */
#define hookNO_BLOCK_TIME ( 0 )
#define hookNO_BLOCK_TIME ( 0 )
/* The priority relative to other co-routines (rather than tasks) that the
'hook' co-routines should take. */
#define mainHOOK_CR_PRIORITY ( 1 )
* '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,127 +107,128 @@ 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. */
xHookRxQueues[ uxIndex ] = xQueueCreate( hookHOOK_QUEUE_LENGTH, sizeof( UBaseType_t ) );
xHookTxQueues[ uxIndex ] = xQueueCreate( hookHOOK_QUEUE_LENGTH, sizeof( UBaseType_t ) );
for( uxIndex = 0; uxIndex < hookNUM_HOOK_CO_ROUTINES; uxIndex++ )
{
/* Create a queue to transmit to and receive from each 'hook'
* 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. */
xQueueSend( xHookRxQueues[ uxIndex ], &uxValueToPost, hookNO_BLOCK_TIME );
/* To start things off the tick hook function expects the queue it
* uses to receive data to contain a value. */
xQueueSend( xHookRxQueues[ uxIndex ], &uxValueToPost, hookNO_BLOCK_TIME );
/* Create the 'hook' co-routine itself. */
xCoRoutineCreate( prvHookCoRoutine, mainHOOK_CR_PRIORITY, uxIndex );
}
/* Create the 'hook' co-routine itself. */
xCoRoutineCreate( prvHookCoRoutine, mainHOOK_CR_PRIORITY, uxIndex );
}
}
/*-----------------------------------------------------------*/
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;
/* Is it time to talk to the 'hook' co-routines again? */
uxCallCounter++;
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. */
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. */
if( uxReceivedNumber != uxNumberToPost )
{
xCoRoutineErrorDetected = pdTRUE;
}
if( uxCallCounter >= hookTICK_CALLS_BEFORE_POST )
{
uxCallCounter = 0;
/* Nothing should be blocked waiting to post to the queue. */
if( xCoRoutineWoken != pdFALSE )
{
xCoRoutineErrorDetected = pdTRUE;
}
}
}
for( xIndex = 0; xIndex < hookNUM_HOOK_CO_ROUTINES; xIndex++ )
{
xCoRoutineWoken = pdFALSE;
/* Start the next cycle by posting the next number onto each Tx queue. */
uxNumberToPost++;
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. */
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. */
if( uxReceivedNumber != uxNumberToPost )
{
xCoRoutineErrorDetected = pdTRUE;
}
for( xIndex = 0; xIndex < hookNUM_HOOK_CO_ROUTINES; xIndex++ )
{
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. */
xCoRoutineErrorDetected = pdTRUE;
}
}
}
/* Nothing should be blocked waiting to post to the queue. */
if( xCoRoutineWoken != pdFALSE )
{
xCoRoutineErrorDetected = pdTRUE;
}
}
}
/* Start the next cycle by posting the next number onto each Tx queue. */
uxNumberToPost++;
for( xIndex = 0; xIndex < hookNUM_HOOK_CO_ROUTINES; xIndex++ )
{
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. */
xCoRoutineErrorDetected = pdTRUE;
}
}
}
}
/*-----------------------------------------------------------*/
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 );
/* Each co-routine MUST start with a call to crSTART(); */
crSTART( xHandle );
for( ;; )
{
/* Wait to receive a value from the tick hook. */
xResult = pdFAIL;
crQUEUE_RECEIVE( xHandle, xHookTxQueues[ uxIndex ], &( uxReceivedValue[ uxIndex ] ), portMAX_DELAY, &xResult );
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. */
if( xResult != pdPASS )
{
xCoRoutineErrorDetected = pdTRUE;
}
/* There is no reason why we should not have received something on
* the queue. */
if( xResult != pdPASS )
{
xCoRoutineErrorDetected = pdTRUE;
}
/* 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. */
xCoRoutineErrorDetected = pdTRUE;
}
}
/* 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 );
/* Each co-routine MUST end with a call to crEND(). */
crEND();
if( xResult != pdPASS )
{
/* There is no reason why we should not have been able to post to
* the queue. */
xCoRoutineErrorDetected = pdTRUE;
}
}
/* Each co-routine MUST end with a call to crEND(). */
crEND();
}
/*-----------------------------------------------------------*/
BaseType_t xAreHookCoRoutinesStillRunning( void )
{
if( xCoRoutineErrorDetected )
{
return pdFALSE;
}
else
{
return pdTRUE;
}
if( xCoRoutineErrorDetected )
{
return pdFALSE;
}
else
{
return pdTRUE;
}
}

View file

@ -54,150 +54,148 @@
/* Demo program include files. */
#include "death.h"
#define deathSTACK_SIZE ( configMINIMAL_STACK_SIZE + 60 )
#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;
/*-----------------------------------------------------------*/
void vCreateSuicidalTasks( UBaseType_t uxPriority )
{
xTaskCreate( vCreateTasks, "CREATOR", deathSTACK_SIZE, ( void * ) NULL, uxPriority, NULL );
xTaskCreate( vCreateTasks, "CREATOR", deathSTACK_SIZE, ( void * ) NULL, uxPriority, NULL );
}
/*-----------------------------------------------------------*/
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 );
/* Test deletion of a task's secure context, if any. */
portALLOCATE_SECURE_CONTEXT( configMINIMAL_SECURE_STACK_SIZE );
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;
}
else
{
xTaskToKill = NULL;
}
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;
}
else
{
xTaskToKill = NULL;
}
for( ;; )
{
/* Do something random just to use some stack and registers. */
l1 = 2;
l2 = 89;
l2 *= l1;
vTaskDelay( xDelay );
for( ; ; )
{
/* Do something random just to use some stack and registers. */
l1 = 2;
l2 = 89;
l2 *= l1;
vTaskDelay( xDelay );
if( xTaskToKill != NULL )
{
/* Make sure the other task has a go before we delete it. */
vTaskDelay( ( TickType_t ) 0 );
if( xTaskToKill != NULL )
{
/* Make sure the other task has a go before we delete it. */
vTaskDelay( ( TickType_t ) 0 );
/* Kill the other task that was created by vCreateTasks(). */
vTaskDelete( xTaskToKill );
/* Kill the other task that was created by vCreateTasks(). */
vTaskDelete( xTaskToKill );
/* Kill ourselves. */
vTaskDelete( NULL );
}
}
}/*lint !e818 !e550 Function prototype must be as per standard for task functions. */
/* Kill ourselves. */
vTaskDelete( NULL );
}
}
} /*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;
/* 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. */
vTaskDelay( xDelay );
uxTasksRunningAtStart = ( UBaseType_t ) uxTaskGetNumberOfTasks();
/* Delay at the start to ensure tasks created by other demos have been
* created before storing the current number of tasks. */
vTaskDelay( xDelay );
uxTasksRunningAtStart = ( UBaseType_t ) uxTaskGetNumberOfTasks();
uxPriority = uxTaskPriorityGet( NULL );
uxPriority = uxTaskPriorityGet( NULL );
for( ;; )
{
/* Just loop round, delaying then creating the four suicidal tasks. */
vTaskDelay( xDelay );
for( ; ; )
{
/* Just loop round, delaying then creating the four suicidal tasks. */
vTaskDelay( xDelay );
xCreatedTask = NULL;
xCreatedTask = NULL;
xTaskCreate( vSuicidalTask, "SUICID1", configMINIMAL_STACK_SIZE, NULL, uxPriority, &xCreatedTask );
xTaskCreate( vSuicidalTask, "SUICID2", configMINIMAL_STACK_SIZE, &xCreatedTask, uxPriority, NULL );
xTaskCreate( vSuicidalTask, "SUICID1", configMINIMAL_STACK_SIZE, NULL, uxPriority, &xCreatedTask );
xTaskCreate( vSuicidalTask, "SUICID2", configMINIMAL_STACK_SIZE, &xCreatedTask, uxPriority, NULL );
++usCreationCount;
}
++usCreationCount;
}
}
/*-----------------------------------------------------------*/
/* 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 )
{
xReturn = pdFALSE;
}
else
{
usLastCreationCount = usCreationCount;
}
if( usLastCreationCount == usCreationCount )
{
xReturn = pdFALSE;
}
else
{
usLastCreationCount = usCreationCount;
}
uxTasksRunningNow = ( UBaseType_t ) uxTaskGetNumberOfTasks();
uxTasksRunningNow = ( UBaseType_t ) uxTaskGetNumberOfTasks();
if( uxTasksRunningNow < uxTasksRunningAtStart )
{
xReturn = pdFALSE;
}
else if( ( uxTasksRunningNow - uxTasksRunningAtStart ) > uxMaxNumberOfExtraTasksRunning )
{
xReturn = pdFALSE;
}
else
{
/* Everything is okay. */
}
if( uxTasksRunningNow < uxTasksRunningAtStart )
{
xReturn = pdFALSE;
}
else if( ( uxTasksRunningNow - uxTasksRunningAtStart ) > uxMaxNumberOfExtraTasksRunning )
{
xReturn = pdFALSE;
}
else
{
/* Everything is okay. */
}
return xReturn;
return xReturn;
}

View file

@ -106,29 +106,29 @@ static portTASK_FUNCTION_PROTO( vQueueSendWhenSuspendedTask, pvParameters );
/* Demo task specific constants. */
#ifndef priSUSPENDED_RX_TASK_STACK_SIZE
#define priSUSPENDED_RX_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE )
#define priSUSPENDED_RX_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE )
#endif
#define priSTACK_SIZE ( configMINIMAL_STACK_SIZE )
#define priSLEEP_TIME pdMS_TO_TICKS( 128 )
#define priLOOPS ( 5 )
#define priMAX_COUNT ( ( uint32_t ) 0xff )
#define priNO_BLOCK ( ( TickType_t ) 0 )
#define priSUSPENDED_QUEUE_LENGTH ( 1 )
#define priSTACK_SIZE ( configMINIMAL_STACK_SIZE )
#define priSLEEP_TIME pdMS_TO_TICKS( 128 )
#define priLOOPS ( 5 )
#define priMAX_COUNT ( ( uint32_t ) 0xff )
#define priNO_BLOCK ( ( TickType_t ) 0 )
#define priSUSPENDED_QUEUE_LENGTH ( 1 )
/*-----------------------------------------------------------*/
/* 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,35 +137,36 @@ 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.
*/
void vStartDynamicPriorityTasks( void )
{
xSuspendedTestQueue = xQueueCreate( priSUSPENDED_QUEUE_LENGTH, sizeof( uint32_t ) );
xSuspendedTestQueue = xQueueCreate( priSUSPENDED_QUEUE_LENGTH, sizeof( uint32_t ) );
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. */
vQueueAddToRegistry( xSuspendedTestQueue, "Suspended_Test_Queue" );
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. */
vQueueAddToRegistry( xSuspendedTestQueue, "Suspended_Test_Queue" );
xTaskCreate( vContinuousIncrementTask, "CNT_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY, &xContinuousIncrementHandle );
xTaskCreate( vLimitedIncrementTask, "LIM_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY + 1, &xLimitedIncrementHandle );
xTaskCreate( vCounterControlTask, "C_CTRL", priSUSPENDED_RX_TASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
xTaskCreate( vQueueSendWhenSuspendedTask, "SUSP_TX", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
xTaskCreate( vQueueReceiveWhenSuspendedTask, "SUSP_RX", priSUSPENDED_RX_TASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
}
xTaskCreate( vContinuousIncrementTask, "CNT_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY, &xContinuousIncrementHandle );
xTaskCreate( vLimitedIncrementTask, "LIM_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY + 1, &xLimitedIncrementHandle );
xTaskCreate( vCounterControlTask, "C_CTRL", priSUSPENDED_RX_TASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
xTaskCreate( vQueueSendWhenSuspendedTask, "SUSP_TX", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
xTaskCreate( vQueueReceiveWhenSuspendedTask, "SUSP_RX", priSUSPENDED_RX_TASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
}
}
/*-----------------------------------------------------------*/
@ -175,26 +176,26 @@ 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. */
pulCounter = ( volatile uint32_t * ) pvParameters;
/* Take a pointer to the shared variable from the parameters passed into
* 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. */
vTaskSuspend( NULL );
/* This will run before the control task, so the first thing it does is
* suspend - the control task will resume it when ready. */
vTaskSuspend( NULL );
for( ;; )
{
/* Just count up to a value then suspend. */
( *pulCounter )++;
for( ; ; )
{
/* Just count up to a value then suspend. */
( *pulCounter )++;
if( *pulCounter >= priMAX_COUNT )
{
vTaskSuspend( NULL );
}
}
if( *pulCounter >= priMAX_COUNT )
{
vTaskSuspend( NULL );
}
}
}
/*-----------------------------------------------------------*/
@ -204,34 +205,34 @@ 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. */
pulCounter = ( volatile uint32_t * ) pvParameters;
/* Take a pointer to the shared variable from the parameters passed into
* the task. */
pulCounter = ( volatile uint32_t * ) pvParameters;
/* Query our priority so we can raise it when exclusive access to the
shared variable is required. */
uxOurPriority = uxTaskPriorityGet( NULL );
/* Query our priority so we can raise it when exclusive access to the
* shared variable is required. */
uxOurPriority = uxTaskPriorityGet( NULL );
for( ;; )
{
/* Raise the priority above the controller task to ensure a context
switch does not occur while the variable is being accessed. */
vTaskPrioritySet( NULL, uxOurPriority + 1 );
{
configASSERT( ( uxTaskPriorityGet( NULL ) == ( uxOurPriority + 1 ) ) );
( *pulCounter )++;
}
vTaskPrioritySet( NULL, uxOurPriority );
for( ; ; )
{
/* Raise the priority above the controller task to ensure a context
* switch does not occur while the variable is being accessed. */
vTaskPrioritySet( NULL, uxOurPriority + 1 );
{
configASSERT( ( uxTaskPriorityGet( NULL ) == ( uxOurPriority + 1 ) ) );
( *pulCounter )++;
}
vTaskPrioritySet( NULL, uxOurPriority );
#if( configUSE_PREEMPTION == 0 )
taskYIELD();
#endif
#if ( configUSE_PREEMPTION == 0 )
taskYIELD();
#endif
configASSERT( ( uxTaskPriorityGet( NULL ) == uxOurPriority ) );
}
configASSERT( ( uxTaskPriorityGet( NULL ) == uxOurPriority ) );
}
}
/*-----------------------------------------------------------*/
@ -240,200 +241,200 @@ 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;
/* Just to stop warning messages. */
( void ) pvParameters;
for( ;; )
{
/* Start with the counter at zero. */
ulCounter = ( uint32_t ) 0;
for( ; ; )
{
/* Start with the counter at zero. */
ulCounter = ( uint32_t ) 0;
/* First section : */
/* First section : */
/* Check the continuous count task is running. */
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. */
vTaskSuspend( xContinuousIncrementHandle );
{
#if( INCLUDE_eTaskGetState == 1 )
{
configASSERT( eTaskGetState( xContinuousIncrementHandle ) == eSuspended );
}
#endif /* INCLUDE_eTaskGetState */
/* Check the continuous count task is running. */
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. */
vTaskSuspend( xContinuousIncrementHandle );
{
#if ( INCLUDE_eTaskGetState == 1 )
{
configASSERT( eTaskGetState( xContinuousIncrementHandle ) == eSuspended );
}
#endif /* INCLUDE_eTaskGetState */
ulLastCounter = ulCounter;
}
vTaskResume( xContinuousIncrementHandle );
ulLastCounter = ulCounter;
}
vTaskResume( xContinuousIncrementHandle );
#if( configUSE_PREEMPTION == 0 )
taskYIELD();
#endif
#if ( configUSE_PREEMPTION == 0 )
taskYIELD();
#endif
#if( INCLUDE_eTaskGetState == 1 )
{
configASSERT( eTaskGetState( xContinuousIncrementHandle ) == eReady );
}
#endif /* INCLUDE_eTaskGetState */
#if ( INCLUDE_eTaskGetState == 1 )
{
configASSERT( eTaskGetState( xContinuousIncrementHandle ) == eReady );
}
#endif /* INCLUDE_eTaskGetState */
/* Now delay to ensure the other task has processor time. */
vTaskDelay( priSLEEP_TIME );
/* Now delay to ensure the other task has processor time. */
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! */
vTaskSuspendAll();
{
if( ulLastCounter == ulCounter )
{
/* The shared variable has not changed. There is a problem
with the continuous count task so flag an error. */
sError = pdTRUE;
}
}
xTaskResumeAll();
}
/* Check the shared variable again. This time to ensure mutual
* 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. */
sError = pdTRUE;
}
}
xTaskResumeAll();
}
/* Second section: */
/* Second section: */
/* Suspend the continuous counter task so it stops accessing the shared
variable. */
vTaskSuspend( xContinuousIncrementHandle );
/* Suspend the continuous counter task so it stops accessing the shared
* variable. */
vTaskSuspend( xContinuousIncrementHandle );
/* Reset the variable. */
ulCounter = ( uint32_t ) 0;
/* Reset the variable. */
ulCounter = ( uint32_t ) 0;
#if( INCLUDE_eTaskGetState == 1 )
{
configASSERT( eTaskGetState( xLimitedIncrementHandle ) == eSuspended );
}
#endif /* INCLUDE_eTaskGetState */
#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. */
vTaskResume( xLimitedIncrementHandle );
/* 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. */
vTaskResume( xLimitedIncrementHandle );
#if( configUSE_PREEMPTION == 0 )
taskYIELD();
#endif
#if ( configUSE_PREEMPTION == 0 )
taskYIELD();
#endif
/* This task should not run again until xLimitedIncrementHandle has
suspended itself. */
#if( INCLUDE_eTaskGetState == 1 )
{
configASSERT( eTaskGetState( xLimitedIncrementHandle ) == eSuspended );
}
#endif /* INCLUDE_eTaskGetState */
/* This task should not run again until xLimitedIncrementHandle has
* suspended itself. */
#if ( INCLUDE_eTaskGetState == 1 )
{
configASSERT( eTaskGetState( xLimitedIncrementHandle ) == eSuspended );
}
#endif /* INCLUDE_eTaskGetState */
/* Does the counter variable have the expected value? */
if( ulCounter != priMAX_COUNT )
{
sError = pdTRUE;
}
/* Does the counter variable have the expected value? */
if( ulCounter != priMAX_COUNT )
{
sError = pdTRUE;
}
if( sError == pdFALSE )
{
/* If no errors have occurred then increment the check variable. */
portENTER_CRITICAL();
usCheckVariable++;
portEXIT_CRITICAL();
}
if( sError == pdFALSE )
{
/* If no errors have occurred then increment the check variable. */
portENTER_CRITICAL();
usCheckVariable++;
portEXIT_CRITICAL();
}
/* Resume the continuous count task and do it all again. */
vTaskResume( xContinuousIncrementHandle );
/* Resume the continuous count task and do it all again. */
vTaskResume( xContinuousIncrementHandle );
#if( configUSE_PREEMPTION == 0 )
taskYIELD();
#endif
}
#if ( configUSE_PREEMPTION == 0 )
taskYIELD();
#endif
}
}
/*-----------------------------------------------------------*/
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;
/* Just to stop warning messages. */
( void ) pvParameters;
for( ;; )
{
vTaskSuspendAll();
{
/* We must not block while the scheduler is suspended! */
if( xQueueSend( xSuspendedTestQueue, ( void * ) &ulValueToSend, priNO_BLOCK ) != pdTRUE )
{
xSuspendedQueueSendError = pdTRUE;
}
}
xTaskResumeAll();
for( ; ; )
{
vTaskSuspendAll();
{
/* We must not block while the scheduler is suspended! */
if( xQueueSend( xSuspendedTestQueue, ( void * ) &ulValueToSend, priNO_BLOCK ) != pdTRUE )
{
xSuspendedQueueSendError = pdTRUE;
}
}
xTaskResumeAll();
vTaskDelay( priSLEEP_TIME );
vTaskDelay( priSLEEP_TIME );
++ulValueToSend;
}
++ulValueToSend;
}
}
/*-----------------------------------------------------------*/
static portTASK_FUNCTION( vQueueReceiveWhenSuspendedTask, pvParameters )
{
uint32_t ulReceivedValue;
BaseType_t xGotValue;
uint32_t ulReceivedValue;
BaseType_t xGotValue;
/* Just to stop warning messages. */
( void ) pvParameters;
/* Just to stop warning messages. */
( void ) pvParameters;
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. */
vTaskSuspendAll();
{
vTaskSuspendAll();
{
xGotValue = xQueueReceive( xSuspendedTestQueue, ( void * ) &ulReceivedValue, priNO_BLOCK );
}
if( xTaskResumeAll() != pdFALSE )
{
xSuspendedQueueReceiveError = pdTRUE;
}
}
xTaskResumeAll();
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. */
vTaskSuspendAll();
{
vTaskSuspendAll();
{
xGotValue = xQueueReceive( xSuspendedTestQueue, ( void * ) &ulReceivedValue, priNO_BLOCK );
}
#if configUSE_PREEMPTION == 0
{
taskYIELD();
}
#endif
if( xTaskResumeAll() != pdFALSE )
{
xSuspendedQueueReceiveError = pdTRUE;
}
}
xTaskResumeAll();
} while( xGotValue == pdFALSE );
#if configUSE_PREEMPTION == 0
{
taskYIELD();
}
#endif
} while( xGotValue == pdFALSE );
if( ulReceivedValue != ulExpectedValue )
{
xSuspendedQueueReceiveError = pdTRUE;
}
if( ulReceivedValue != ulExpectedValue )
{
xSuspendedQueueReceiveError = pdTRUE;
}
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. */
++ulExpectedValue;
}
}
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. */
++ulExpectedValue;
}
}
}
/*-----------------------------------------------------------*/
@ -441,39 +442,39 @@ 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. */
/* Check the tasks are still running by ensuring the check variable
* is still incrementing. */
if( usCheckVariable == usLastTaskCheck )
{
/* The check has not incremented so an error exists. */
xReturn = pdFALSE;
}
if( usCheckVariable == usLastTaskCheck )
{
/* The check has not incremented so an error exists. */
xReturn = pdFALSE;
}
if( ulExpectedValue == ulLastExpectedValue )
{
/* The value being received by the queue receive task has not
incremented so an error exists. */
xReturn = pdFALSE;
}
if( ulExpectedValue == ulLastExpectedValue )
{
/* The value being received by the queue receive task has not
* incremented so an error exists. */
xReturn = pdFALSE;
}
if( xSuspendedQueueSendError == pdTRUE )
{
xReturn = pdFALSE;
}
if( xSuspendedQueueSendError == pdTRUE )
{
xReturn = pdFALSE;
}
if( xSuspendedQueueReceiveError == pdTRUE )
{
xReturn = pdFALSE;
}
if( xSuspendedQueueReceiveError == pdTRUE )
{
xReturn = pdFALSE;
}
usLastTaskCheck = usCheckVariable;
ulLastExpectedValue = ulExpectedValue;
usLastTaskCheck = usCheckVariable;
ulLastExpectedValue = ulExpectedValue;
return xReturn;
return xReturn;
}

View file

@ -49,12 +49,12 @@
#include "partest.h"
#include "flash.h"
#define ledSTACK_SIZE configMINIMAL_STACK_SIZE
#define ledNUMBER_OF_LEDS ( 3 )
#define ledFLASH_RATE_BASE ( ( TickType_t ) 333 )
#define ledSTACK_SIZE configMINIMAL_STACK_SIZE
#define ledNUMBER_OF_LEDS ( 3 )
#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,56 +64,55 @@ 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 )
{
/* Spawn the task. */
xTaskCreate( vLEDFlashTask, "LEDx", ledSTACK_SIZE, NULL, uxPriority, ( TaskHandle_t * ) NULL );
}
/* Create the three tasks. */
for( xLEDTask = 0; xLEDTask < ledNUMBER_OF_LEDS; ++xLEDTask )
{
/* Spawn the task. */
xTaskCreate( vLEDFlashTask, "LEDx", ledSTACK_SIZE, NULL, uxPriority, ( TaskHandle_t * ) NULL );
}
}
/*-----------------------------------------------------------*/
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;
/* The parameters are not used. */
( void ) pvParameters;
/* Calculate the LED and flash rate. */
portENTER_CRITICAL();
{
/* See which of the eight LED's we should use. */
uxLED = uxFlashTaskNumber;
/* Calculate the LED and flash rate. */
portENTER_CRITICAL();
{
/* See which of the eight LED's we should use. */
uxLED = uxFlashTaskNumber;
/* Update so the next task uses the next LED. */
uxFlashTaskNumber++;
}
portEXIT_CRITICAL();
/* Update so the next task uses the next LED. */
uxFlashTaskNumber++;
}
portEXIT_CRITICAL();
xFlashRate = ledFLASH_RATE_BASE + ( ledFLASH_RATE_BASE * ( TickType_t ) uxLED );
xFlashRate /= portTICK_PERIOD_MS;
xFlashRate = ledFLASH_RATE_BASE + ( ledFLASH_RATE_BASE * ( TickType_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. */
xFlashRate /= ( TickType_t ) 2;
/* We will turn the LED on and off again in the delay period, so each
* delay is only half the total period. */
xFlashRate /= ( TickType_t ) 2;
/* We need to initialise xLastFlashTime prior to the first call to
vTaskDelayUntil(). */
xLastFlashTime = xTaskGetTickCount();
/* We need to initialise xLastFlashTime prior to the first call to
* vTaskDelayUntil(). */
xLastFlashTime = xTaskGetTickCount();
for(;;)
{
/* Delay for half the flash period then turn the LED on. */
vTaskDelayUntil( &xLastFlashTime, xFlashRate );
vParTestToggleLED( uxLED );
for( ; ; )
{
/* Delay for half the flash period then turn the LED on. */
vTaskDelayUntil( &xLastFlashTime, xFlashRate );
vParTestToggleLED( uxLED );
/* Delay for half the flash period then turn the LED off. */
vTaskDelayUntil( &xLastFlashTime, xFlashRate );
vParTestToggleLED( uxLED );
}
/* Delay for half the flash period then turn the LED off. */
vTaskDelayUntil( &xLastFlashTime, xFlashRate );
vParTestToggleLED( uxLED );
}
} /*lint !e715 !e818 !e830 Function definition must be standard for task creation. */

View file

@ -39,10 +39,10 @@
#include "flash_timer.h"
/* The toggle rates are all a multple of ledFLASH_RATE_BASE. */
#define ledFLASH_RATE_BASE ( ( ( TickType_t ) 333 ) / portTICK_PERIOD_MS )
#define ledFLASH_RATE_BASE ( ( ( TickType_t ) 333 ) / portTICK_PERIOD_MS )
/* A block time of zero simple means "don't block". */
#define ledDONT_BLOCK ( ( TickType_t ) 0 )
#define ledDONT_BLOCK ( ( TickType_t ) 0 )
/*-----------------------------------------------------------*/
@ -57,42 +57,40 @@ 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. */
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. */
);
/* 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. */
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. */
if( xTimer != NULL )
{
xTimerStart( xTimer, ledDONT_BLOCK );
}
}
/* 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. */
if( xTimer != NULL )
{
xTimerStart( xTimer, ledDONT_BLOCK );
}
}
}
/*-----------------------------------------------------------*/
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. */
xTimerID = ( BaseType_t ) pvTimerGetTimerID( xTimer );
vParTestToggleLED( 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. */
xTimerID = ( BaseType_t ) pvTimerGetTimerID( xTimer );
vParTestToggleLED( xTimerID );
}

View file

@ -50,300 +50,298 @@
#include "flop.h"
#ifndef mathSTACK_SIZE
#define mathSTACK_SIZE configMINIMAL_STACK_SIZE
#define mathSTACK_SIZE configMINIMAL_STACK_SIZE
#endif
#define mathNUMBER_OF_TASKS ( 4 )
#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 };
/*-----------------------------------------------------------*/
void vStartMathTasks( UBaseType_t uxPriority )
{
xTaskCreate( vCompetingMathTask1, "Math1", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 0 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask2, "Math2", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 1 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask3, "Math3", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 2 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask4, "Math4", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 3 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask1, "Math1", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 0 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask2, "Math2", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 1 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask3, "Math3", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 2 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask4, "Math4", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 3 ] ), uxPriority, NULL );
}
/*-----------------------------------------------------------*/
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. */
portTASK_USES_FLOATING_POINT();
/* 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. */
portTASK_USES_FLOATING_POINT();
d1 = 123.4567;
d2 = 2345.6789;
d3 = -918.222;
d1 = 123.4567;
d2 = 2345.6789;
d3 = -918.222;
dAnswer = ( d1 + d2 ) * d3;
dAnswer = ( d1 + d2 ) * d3;
/* The variable this task increments to show it is still running is passed in
as the parameter. */
pusTaskCheckVariable = ( volatile uint16_t * ) pvParameters;
/* The variable this task increments to show it is still running is passed in
* as the parameter. */
pusTaskCheckVariable = ( volatile uint16_t * ) pvParameters;
/* Keep performing a calculation and checking the result against a constant. */
for(;;)
{
d1 = 123.4567;
d2 = 2345.6789;
d3 = -918.222;
/* Keep performing a calculation and checking the result against a constant. */
for( ; ; )
{
d1 = 123.4567;
d2 = 2345.6789;
d3 = -918.222;
d4 = ( d1 + d2 ) * d3;
d4 = ( d1 + d2 ) * d3;
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
/* If the calculation does not match the expected constant, stop the
increment of the check variable. */
if( fabs( d4 - dAnswer ) > 0.001 )
{
sError = pdTRUE;
}
/* If the calculation does not match the expected constant, stop the
* increment of the check variable. */
if( fabs( d4 - dAnswer ) > 0.001 )
{
sError = pdTRUE;
}
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. */
( *pusTaskCheckVariable ) = pdTRUE;
}
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. */
( *pusTaskCheckVariable ) = pdTRUE;
}
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
}
#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. */
portTASK_USES_FLOATING_POINT();
/* 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. */
portTASK_USES_FLOATING_POINT();
d1 = -389.38;
d2 = 32498.2;
d3 = -2.0001;
d1 = -389.38;
d2 = 32498.2;
d3 = -2.0001;
dAnswer = ( d1 / d2 ) * d3;
dAnswer = ( d1 / d2 ) * d3;
/* The variable this task increments to show it is still running is passed in
as the parameter. */
pusTaskCheckVariable = ( volatile uint16_t * ) pvParameters;
/* The variable this task increments to show it is still running is passed in
* as the parameter. */
pusTaskCheckVariable = ( volatile uint16_t * ) pvParameters;
/* Keep performing a calculation and checking the result against a constant. */
for( ;; )
{
d1 = -389.38;
d2 = 32498.2;
d3 = -2.0001;
/* Keep performing a calculation and checking the result against a constant. */
for( ; ; )
{
d1 = -389.38;
d2 = 32498.2;
d3 = -2.0001;
d4 = ( d1 / d2 ) * d3;
d4 = ( d1 / d2 ) * d3;
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
/* If the calculation does not match the expected constant, stop the
increment of the check variable. */
if( fabs( d4 - dAnswer ) > 0.001 )
{
sError = pdTRUE;
}
/* If the calculation does not match the expected constant, stop the
* increment of the check variable. */
if( fabs( d4 - dAnswer ) > 0.001 )
{
sError = pdTRUE;
}
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. */
( *pusTaskCheckVariable ) = pdTRUE;
}
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. */
( *pusTaskCheckVariable ) = pdTRUE;
}
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
}
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
}
}
/*-----------------------------------------------------------*/
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. */
portTASK_USES_FLOATING_POINT();
/* 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. */
portTASK_USES_FLOATING_POINT();
/* The variable this task increments to show it is still running is passed in
as the parameter. */
pusTaskCheckVariable = ( volatile uint16_t * ) pvParameters;
/* The variable this task increments to show it is still running is passed in
* as the parameter. */
pusTaskCheckVariable = ( volatile uint16_t * ) pvParameters;
pdArray = ( portDOUBLE * ) pvPortMalloc( xArraySize * sizeof( portDOUBLE ) );
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( ;; )
{
dTotal1 = 0.0;
dTotal2 = 0.0;
/* 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( ; ; )
{
dTotal1 = 0.0;
dTotal2 = 0.0;
for( xPosition = 0; xPosition < xArraySize; xPosition++ )
{
pdArray[ xPosition ] = ( portDOUBLE ) xPosition + 5.5;
dTotal1 += ( portDOUBLE ) xPosition + 5.5;
}
for( xPosition = 0; xPosition < xArraySize; xPosition++ )
{
pdArray[ xPosition ] = ( portDOUBLE ) xPosition + 5.5;
dTotal1 += ( portDOUBLE ) xPosition + 5.5;
}
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
for( xPosition = 0; xPosition < xArraySize; xPosition++ )
{
dTotal2 += pdArray[ xPosition ];
}
for( xPosition = 0; xPosition < xArraySize; xPosition++ )
{
dTotal2 += pdArray[ xPosition ];
}
dDifference = dTotal1 - dTotal2;
if( fabs( dDifference ) > 0.001 )
{
sError = pdTRUE;
}
dDifference = dTotal1 - dTotal2;
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
if( fabs( dDifference ) > 0.001 )
{
sError = pdTRUE;
}
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. */
( *pusTaskCheckVariable ) = pdTRUE;
}
}
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
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. */
( *pusTaskCheckVariable ) = pdTRUE;
}
}
}
/*-----------------------------------------------------------*/
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. */
portTASK_USES_FLOATING_POINT();
/* 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. */
portTASK_USES_FLOATING_POINT();
/* The variable this task increments to show it is still running is passed in
as the parameter. */
pusTaskCheckVariable = ( volatile uint16_t * ) pvParameters;
/* The variable this task increments to show it is still running is passed in
* as the parameter. */
pusTaskCheckVariable = ( volatile uint16_t * ) pvParameters;
pdArray = ( portDOUBLE * ) pvPortMalloc( xArraySize * sizeof( portDOUBLE ) );
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( ;; )
{
dTotal1 = 0.0;
dTotal2 = 0.0;
/* 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( ; ; )
{
dTotal1 = 0.0;
dTotal2 = 0.0;
for( xPosition = 0; xPosition < xArraySize; xPosition++ )
{
pdArray[ xPosition ] = ( portDOUBLE ) xPosition * 12.123;
dTotal1 += ( portDOUBLE ) xPosition * 12.123;
}
for( xPosition = 0; xPosition < xArraySize; xPosition++ )
{
pdArray[ xPosition ] = ( portDOUBLE ) xPosition * 12.123;
dTotal1 += ( portDOUBLE ) xPosition * 12.123;
}
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
for( xPosition = 0; xPosition < xArraySize; xPosition++ )
{
dTotal2 += pdArray[ xPosition ];
}
for( xPosition = 0; xPosition < xArraySize; xPosition++ )
{
dTotal2 += pdArray[ xPosition ];
}
dDifference = dTotal1 - dTotal2;
if( fabs( dDifference ) > 0.001 )
{
sError = pdTRUE;
}
dDifference = dTotal1 - dTotal2;
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
if( fabs( dDifference ) > 0.001 )
{
sError = pdTRUE;
}
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. */
( *pusTaskCheckVariable ) = pdTRUE;
}
}
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
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. */
( *pusTaskCheckVariable ) = pdTRUE;
}
}
}
/*-----------------------------------------------------------*/
/* 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. */
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. */
xReturn = pdFAIL;
}
else
{
/* Reset the variable so it can be checked again the next time this
function is executed. */
usTaskCheck[ xTask ] = pdFALSE;
}
}
/* Check the maths tasks are still running by ensuring their check variables
* 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. */
xReturn = pdFAIL;
}
else
{
/* Reset the variable so it can be checked again the next time this
* function is executed. */
usTaskCheck[ xTask ] = pdFALSE;
}
}
return xReturn;
return xReturn;
}

View file

@ -42,122 +42,121 @@
#include "integer.h"
/* The constants used in the calculation. */
#define intgCONST1 ( ( long ) 123 )
#define intgCONST2 ( ( long ) 234567 )
#define intgCONST3 ( ( long ) -3 )
#define intgCONST4 ( ( long ) 7 )
#define intgEXPECTED_ANSWER ( ( ( intgCONST1 + intgCONST2 ) * intgCONST3 ) / intgCONST4 )
#define intgCONST1 ( ( long ) 123 )
#define intgCONST2 ( ( long ) 234567 )
#define intgCONST3 ( ( long ) -3 )
#define intgCONST4 ( ( long ) 7 )
#define intgEXPECTED_ANSWER ( ( ( intgCONST1 + intgCONST2 ) * intgCONST3 ) / intgCONST4 )
#define intgSTACK_SIZE configMINIMAL_STACK_SIZE
#define intgSTACK_SIZE configMINIMAL_STACK_SIZE
/* As this is the minimal version, we will only create one task. */
#define intgNUMBER_OF_TASKS ( 1 )
#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++ )
{
xTaskCreate( vCompeteingIntMathTask, "IntMath", intgSTACK_SIZE, ( void * ) &( xTaskCheck[ sTask ] ), uxPriority, ( TaskHandle_t * ) NULL );
}
for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
{
xTaskCreate( vCompeteingIntMathTask, "IntMath", intgSTACK_SIZE, ( void * ) &( xTaskCheck[ sTask ] ), uxPriority, ( TaskHandle_t * ) NULL );
}
}
/*-----------------------------------------------------------*/
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. */
pxTaskHasExecuted = ( volatile BaseType_t * ) pvParameters;
/* 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. */
pxTaskHasExecuted = ( volatile BaseType_t * ) pvParameters;
/* Keep performing a calculation and checking the result against a constant. */
for( ;; )
{
/* Perform the calculation. This will store partial value in
registers, resulting in a good test of the context switch mechanism. */
lValue = intgCONST1;
lValue += intgCONST2;
/* Keep performing a calculation and checking the result against a constant. */
for( ; ; )
{
/* Perform the calculation. This will store partial value in
* registers, resulting in a good test of the context switch mechanism. */
lValue = intgCONST1;
lValue += intgCONST2;
/* Yield in case cooperative scheduling is being used. */
#if configUSE_PREEMPTION == 0
{
taskYIELD();
}
#endif
/* Yield in case cooperative scheduling is being used. */
#if configUSE_PREEMPTION == 0
{
taskYIELD();
}
#endif
/* Finish off the calculation. */
lValue *= intgCONST3;
lValue /= intgCONST4;
/* Finish off the calculation. */
lValue *= intgCONST3;
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. */
if( lValue != intgEXPECTED_ANSWER ) /*lint !e774 volatile used to prevent this being optimised out. */
{
sError = pdTRUE;
}
/* If the calculation is found to be incorrect we stop setting the
* 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;
}
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. */
portENTER_CRITICAL();
*pxTaskHasExecuted = pdTRUE;
portEXIT_CRITICAL();
}
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. */
portENTER_CRITICAL();
*pxTaskHasExecuted = pdTRUE;
portEXIT_CRITICAL();
}
/* Yield in case cooperative scheduling is being used. */
#if configUSE_PREEMPTION == 0
{
taskYIELD();
}
#endif
}
/* Yield in case cooperative scheduling is being used. */
#if configUSE_PREEMPTION == 0
{
taskYIELD();
}
#endif
}
}
/*-----------------------------------------------------------*/
/* 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. */
for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
{
if( xTaskCheck[ sTask ] == pdFALSE )
{
/* The check has not incremented so an error exists. */
xReturn = pdFALSE;
}
/* Check the maths tasks are still running by ensuring their check variables
* are still being set to true. */
for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
{
if( xTaskCheck[ sTask ] == pdFALSE )
{
/* The check has not incremented so an error exists. */
xReturn = pdFALSE;
}
/* Reset the check variable so we can tell if it has been set by
the next time around. */
xTaskCheck[ sTask ] = pdFALSE;
}
/* Reset the check variable so we can tell if it has been set by
* the next time around. */
xTaskCheck[ sTask ] = pdFALSE;
}
return xReturn;
return xReturn;
}

View file

@ -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,29 +70,29 @@
#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 )
#define recmuCONTROLLING_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
#endif
#define recmuBLOCKING_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define recmuPOLLING_TASK_PRIORITY ( tskIDLE_PRIORITY + 0 )
#define recmuBLOCKING_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define recmuPOLLING_TASK_PRIORITY ( tskIDLE_PRIORITY + 0 )
/* The recursive call depth. */
#define recmuMAX_COUNT ( 10 )
#define recmuMAX_COUNT ( 10 )
/* Misc. */
#define recmuSHORT_DELAY ( pdMS_TO_TICKS( 20 ) )
#define recmuNO_DELAY ( ( TickType_t ) 0 )
#define recmu15ms_DELAY ( pdMS_TO_TICKS( 15 ) )
#define recmuSHORT_DELAY ( pdMS_TO_TICKS( 20 ) )
#define recmuNO_DELAY ( ( TickType_t ) 0 )
#define recmu15ms_DELAY ( pdMS_TO_TICKS( 15 ) )
#ifndef recmuRECURSIVE_MUTEX_TEST_TASK_STACK_SIZE
#define recmuRECURSIVE_MUTEX_TEST_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
#define recmuRECURSIVE_MUTEX_TEST_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
#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,315 +102,311 @@ 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;
/*-----------------------------------------------------------*/
void vStartRecursiveMutexTasks( void )
{
/* Just creates the mutex and the three tasks. */
/* Just creates the mutex and the three tasks. */
xMutex = xSemaphoreCreateRecursiveMutex();
xMutex = xSemaphoreCreateRecursiveMutex();
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. */
vQueueAddToRegistry( ( QueueHandle_t ) xMutex, "Recursive_Mutex" );
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. */
vQueueAddToRegistry( ( QueueHandle_t ) xMutex, "Recursive_Mutex" );
xTaskCreate( prvRecursiveMutexControllingTask, "Rec1", recmuRECURSIVE_MUTEX_TEST_TASK_STACK_SIZE, NULL, recmuCONTROLLING_TASK_PRIORITY, &xControllingTaskHandle );
xTaskCreate( prvRecursiveMutexBlockingTask, "Rec2", recmuRECURSIVE_MUTEX_TEST_TASK_STACK_SIZE, NULL, recmuBLOCKING_TASK_PRIORITY, &xBlockingTaskHandle );
xTaskCreate( prvRecursiveMutexPollingTask, "Rec3", recmuRECURSIVE_MUTEX_TEST_TASK_STACK_SIZE, NULL, recmuPOLLING_TASK_PRIORITY, NULL );
}
xTaskCreate( prvRecursiveMutexControllingTask, "Rec1", recmuRECURSIVE_MUTEX_TEST_TASK_STACK_SIZE, NULL, recmuCONTROLLING_TASK_PRIORITY, &xControllingTaskHandle );
xTaskCreate( prvRecursiveMutexBlockingTask, "Rec2", recmuRECURSIVE_MUTEX_TEST_TASK_STACK_SIZE, NULL, recmuBLOCKING_TASK_PRIORITY, &xBlockingTaskHandle );
xTaskCreate( prvRecursiveMutexPollingTask, "Rec3", recmuRECURSIVE_MUTEX_TEST_TASK_STACK_SIZE, NULL, recmuPOLLING_TASK_PRIORITY, NULL );
}
}
/*-----------------------------------------------------------*/
static void prvRecursiveMutexControllingTask( void *pvParameters )
static void prvRecursiveMutexControllingTask( void * pvParameters )
{
UBaseType_t ux;
UBaseType_t ux;
/* Just to remove compiler warning. */
( void ) pvParameters;
/* Just to remove compiler warning. */
( void ) pvParameters;
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. */
if( xSemaphoreGiveRecursive( xMutex ) == pdPASS )
{
xErrorOccurred = pdTRUE;
}
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. */
if( xSemaphoreGiveRecursive( xMutex ) == pdPASS )
{
xErrorOccurred = pdTRUE;
}
for( ux = 0; ux < recmuMAX_COUNT; ux++ )
{
/* We should now be able to take the mutex as many times as
we like.
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. */
if( xSemaphoreTakeRecursive( xMutex, recmu15ms_DELAY ) != pdPASS )
{
xErrorOccurred = pdTRUE;
}
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. */
vTaskDelay( recmuSHORT_DELAY );
}
/* 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. */
vTaskDelay( recmuSHORT_DELAY );
}
/* For each time we took the mutex, give it back. */
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. */
vTaskDelay( recmuSHORT_DELAY );
/* For each time we took the mutex, give it back. */
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. */
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. */
if( xSemaphoreGiveRecursive( xMutex ) != pdPASS )
{
xErrorOccurred = pdTRUE;
}
/* 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. */
if( xSemaphoreGiveRecursive( xMutex ) != pdPASS )
{
xErrorOccurred = pdTRUE;
}
#if ( configUSE_PREEMPTION == 0 )
taskYIELD();
#endif
}
#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. */
if( xSemaphoreGiveRecursive( xMutex ) == pdPASS )
{
xErrorOccurred = pdTRUE;
}
/* 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. */
if( xSemaphoreGiveRecursive( xMutex ) == pdPASS )
{
xErrorOccurred = pdTRUE;
}
/* Keep count of the number of cycles this task has performed so a
* stall can be detected. */
uxControllingCycles++;
/* Keep count of the number of cycles this task has performed so a
stall can be detected. */
uxControllingCycles++;
/* Suspend ourselves so the blocking task can execute. */
xControllingIsSuspended = pdTRUE;
vTaskSuspend( NULL );
xControllingIsSuspended = pdFALSE;
}
/* Suspend ourselves so the blocking task can execute. */
xControllingIsSuspended = pdTRUE;
vTaskSuspend( NULL );
xControllingIsSuspended = pdFALSE;
}
}
/*-----------------------------------------------------------*/
static void prvRecursiveMutexBlockingTask( void *pvParameters )
static void prvRecursiveMutexBlockingTask( void * pvParameters )
{
/* Just to remove compiler warning. */
( void ) pvParameters;
/* Just to remove compiler warning. */
( void ) pvParameters;
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). */
if( xSemaphoreTakeRecursive( xMutex, ( portMAX_DELAY - 1 ) ) == pdPASS )
{
if( xControllingIsSuspended != pdTRUE )
{
/* Did not expect to execute until the controlling task was
suspended. */
xErrorOccurred = pdTRUE;
}
else
{
/* Give the mutex back before suspending ourselves to allow
the polling task to obtain the mutex. */
if( xSemaphoreGiveRecursive( xMutex ) != pdPASS )
{
xErrorOccurred = pdTRUE;
}
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). */
if( xSemaphoreTakeRecursive( xMutex, ( portMAX_DELAY - 1 ) ) == pdPASS )
{
if( xControllingIsSuspended != pdTRUE )
{
/* Did not expect to execute until the controlling task was
* suspended. */
xErrorOccurred = pdTRUE;
}
else
{
/* Give the mutex back before suspending ourselves to allow
* the polling task to obtain the mutex. */
if( xSemaphoreGiveRecursive( xMutex ) != pdPASS )
{
xErrorOccurred = pdTRUE;
}
xBlockingIsSuspended = pdTRUE;
vTaskSuspend( NULL );
xBlockingIsSuspended = pdFALSE;
}
}
else
{
/* We should not leave the xSemaphoreTakeRecursive() function
until the mutex was obtained. */
xErrorOccurred = pdTRUE;
}
xBlockingIsSuspended = pdTRUE;
vTaskSuspend( NULL );
xBlockingIsSuspended = pdFALSE;
}
}
else
{
/* We should not leave the xSemaphoreTakeRecursive() function
* until the mutex was obtained. */
xErrorOccurred = pdTRUE;
}
/* The controlling and blocking tasks should be in lock step. */
if( uxControllingCycles != (UBaseType_t) ( uxBlockingCycles + 1 ) )
{
xErrorOccurred = pdTRUE;
}
/* The controlling and blocking tasks should be in lock step. */
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. */
uxBlockingCycles++;
}
/* Keep count of the number of cycles this task has performed so a
* stall can be detected. */
uxBlockingCycles++;
}
}
/*-----------------------------------------------------------*/
static void prvRecursiveMutexPollingTask( void *pvParameters )
static void prvRecursiveMutexPollingTask( void * pvParameters )
{
/* Just to remove compiler warning. */
( void ) pvParameters;
/* Just to remove compiler warning. */
( void ) pvParameters;
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. */
if( xSemaphoreTakeRecursive( xMutex, recmuNO_DELAY ) == pdPASS )
{
#if( INCLUDE_eTaskGetState == 1 )
{
configASSERT( eTaskGetState( xControllingTaskHandle ) == eSuspended );
configASSERT( eTaskGetState( xBlockingTaskHandle ) == eSuspended );
}
#endif /* INCLUDE_eTaskGetState */
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. */
if( xSemaphoreTakeRecursive( xMutex, recmuNO_DELAY ) == pdPASS )
{
#if ( INCLUDE_eTaskGetState == 1 )
{
configASSERT( eTaskGetState( xControllingTaskHandle ) == eSuspended );
configASSERT( eTaskGetState( xBlockingTaskHandle ) == eSuspended );
}
#endif /* INCLUDE_eTaskGetState */
/* Is the blocking task suspended? */
if( ( xBlockingIsSuspended != pdTRUE ) || ( xControllingIsSuspended != pdTRUE ) )
{
xErrorOccurred = pdTRUE;
}
else
{
/* Keep count of the number of cycles this task has performed
so a stall can be detected. */
uxPollingCycles++;
/* Is the blocking task suspended? */
if( ( xBlockingIsSuspended != pdTRUE ) || ( xControllingIsSuspended != pdTRUE ) )
{
xErrorOccurred = pdTRUE;
}
else
{
/* Keep count of the number of cycles this task has performed
* 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. */
vTaskResume( xBlockingTaskHandle );
#if( configUSE_PREEMPTION == 0 )
taskYIELD();
#endif
/* 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. */
vTaskResume( xBlockingTaskHandle );
#if ( configUSE_PREEMPTION == 0 )
taskYIELD();
#endif
vTaskResume( xControllingTaskHandle );
#if( configUSE_PREEMPTION == 0 )
taskYIELD();
#endif
vTaskResume( xControllingTaskHandle );
#if ( configUSE_PREEMPTION == 0 )
taskYIELD();
#endif
/* The other two tasks should now have executed and no longer
be suspended. */
if( ( xBlockingIsSuspended == pdTRUE ) || ( xControllingIsSuspended == pdTRUE ) )
{
xErrorOccurred = pdTRUE;
}
/* The other two tasks should now have executed and no longer
* be suspended. */
if( ( xBlockingIsSuspended == pdTRUE ) || ( xControllingIsSuspended == pdTRUE ) )
{
xErrorOccurred = pdTRUE;
}
#if( INCLUDE_uxTaskPriorityGet == 1 )
{
/* Check priority inherited. */
configASSERT( uxTaskPriorityGet( NULL ) == recmuCONTROLLING_TASK_PRIORITY );
}
#endif /* INCLUDE_uxTaskPriorityGet */
#if ( INCLUDE_uxTaskPriorityGet == 1 )
{
/* Check priority inherited. */
configASSERT( uxTaskPriorityGet( NULL ) == recmuCONTROLLING_TASK_PRIORITY );
}
#endif /* INCLUDE_uxTaskPriorityGet */
#if( INCLUDE_eTaskGetState == 1 )
{
configASSERT( eTaskGetState( xControllingTaskHandle ) == eBlocked );
configASSERT( eTaskGetState( xBlockingTaskHandle ) == eBlocked );
}
#endif /* INCLUDE_eTaskGetState */
#if ( INCLUDE_eTaskGetState == 1 )
{
configASSERT( eTaskGetState( xControllingTaskHandle ) == eBlocked );
configASSERT( eTaskGetState( xBlockingTaskHandle ) == eBlocked );
}
#endif /* INCLUDE_eTaskGetState */
/* Release the mutex, disinheriting the higher priority again. */
if( xSemaphoreGiveRecursive( xMutex ) != pdPASS )
{
xErrorOccurred = pdTRUE;
}
/* Release the mutex, disinheriting the higher priority again. */
if( xSemaphoreGiveRecursive( xMutex ) != pdPASS )
{
xErrorOccurred = pdTRUE;
}
#if( INCLUDE_uxTaskPriorityGet == 1 )
{
/* Check priority disinherited. */
configASSERT( uxTaskPriorityGet( NULL ) == recmuPOLLING_TASK_PRIORITY );
}
#endif /* INCLUDE_uxTaskPriorityGet */
}
}
#if ( INCLUDE_uxTaskPriorityGet == 1 )
{
/* Check priority disinherited. */
configASSERT( uxTaskPriorityGet( NULL ) == recmuPOLLING_TASK_PRIORITY );
}
#endif /* INCLUDE_uxTaskPriorityGet */
}
}
#if configUSE_PREEMPTION == 0
{
taskYIELD();
}
#endif
}
#if configUSE_PREEMPTION == 0
{
taskYIELD();
}
#endif
}
}
/*-----------------------------------------------------------*/
/* 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 )
{
xErrorOccurred = pdTRUE;
}
else
{
uxLastControllingCycles = uxControllingCycles;
}
/* Is the controlling task still cycling? */
if( uxLastControllingCycles == uxControllingCycles )
{
xErrorOccurred = pdTRUE;
}
else
{
uxLastControllingCycles = uxControllingCycles;
}
/* Is the blocking task still cycling? */
if( uxLastBlockingCycles == uxBlockingCycles )
{
xErrorOccurred = pdTRUE;
}
else
{
uxLastBlockingCycles = uxBlockingCycles;
}
/* Is the blocking task still cycling? */
if( uxLastBlockingCycles == uxBlockingCycles )
{
xErrorOccurred = pdTRUE;
}
else
{
uxLastBlockingCycles = uxBlockingCycles;
}
/* Is the polling task still cycling? */
if( uxLastPollingCycles == uxPollingCycles )
{
xErrorOccurred = pdTRUE;
}
else
{
uxLastPollingCycles = uxPollingCycles;
}
/* Is the polling task still cycling? */
if( uxLastPollingCycles == uxPollingCycles )
{
xErrorOccurred = pdTRUE;
}
else
{
uxLastPollingCycles = uxPollingCycles;
}
if( xErrorOccurred == pdTRUE )
{
xReturn = pdFAIL;
}
else
{
xReturn = pdPASS;
}
if( xErrorOccurred == pdTRUE )
{
xReturn = pdFAIL;
}
else
{
xReturn = pdPASS;
}
return xReturn;
return xReturn;
}

View file

@ -60,14 +60,14 @@
#include "semtest.h"
/* The value to which the shared variables are counted. */
#define semtstBLOCKING_EXPECTED_VALUE ( ( uint32_t ) 0xfff )
#define semtstNON_BLOCKING_EXPECTED_VALUE ( ( uint32_t ) 0xff )
#define semtstBLOCKING_EXPECTED_VALUE ( ( uint32_t ) 0xfff )
#define semtstNON_BLOCKING_EXPECTED_VALUE ( ( uint32_t ) 0xff )
#define semtstSTACK_SIZE configMINIMAL_STACK_SIZE
#define semtstSTACK_SIZE configMINIMAL_STACK_SIZE
#define semtstNUM_TASKS ( 4 )
#define semtstNUM_TASKS ( 4 )
#define semtstDELAY_FACTOR ( ( TickType_t ) 10 )
#define semtstDELAY_FACTOR ( ( TickType_t ) 10 )
/* The task function as described at the top of the file. */
static portTASK_FUNCTION_PROTO( prvSemaphoreTest, pvParameters );
@ -75,9 +75,9 @@ static portTASK_FUNCTION_PROTO( prvSemaphoreTest, pvParameters );
/* Structure used to pass parameters to each task. */
typedef struct SEMAPHORE_PARAMETERS
{
SemaphoreHandle_t xSemaphore;
volatile uint32_t *pulSharedVariable;
TickType_t xBlockTime;
SemaphoreHandle_t xSemaphore;
volatile uint32_t * pulSharedVariable;
TickType_t xBlockTime;
} xSemaphoreParameters;
/* Variables used to check that all the tasks are still running without errors. */
@ -88,185 +88,185 @@ 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 ) );
/* Create the structure used to pass parameters to the first two tasks. */
pxFirstSemaphoreParameters = ( xSemaphoreParameters * ) pvPortMalloc( sizeof( xSemaphoreParameters ) );
if( pxFirstSemaphoreParameters != NULL )
{
/* Create the semaphore used by the first two tasks. */
pxFirstSemaphoreParameters->xSemaphore = xSemaphoreCreateBinary();
if( pxFirstSemaphoreParameters != NULL )
{
/* Create the semaphore used by the first two tasks. */
pxFirstSemaphoreParameters->xSemaphore = xSemaphoreCreateBinary();
if( pxFirstSemaphoreParameters->xSemaphore != NULL )
{
xSemaphoreGive( pxFirstSemaphoreParameters->xSemaphore );
if( pxFirstSemaphoreParameters->xSemaphore != NULL )
{
xSemaphoreGive( pxFirstSemaphoreParameters->xSemaphore );
/* Create the variable which is to be shared by the first two tasks. */
pxFirstSemaphoreParameters->pulSharedVariable = ( uint32_t * ) pvPortMalloc( sizeof( uint32_t ) );
/* Create the variable which is to be shared by the first two tasks. */
pxFirstSemaphoreParameters->pulSharedVariable = ( uint32_t * ) pvPortMalloc( sizeof( uint32_t ) );
/* Initialise the share variable to the value the tasks expect. */
*( pxFirstSemaphoreParameters->pulSharedVariable ) = semtstNON_BLOCKING_EXPECTED_VALUE;
/* Initialise the share variable to the value the tasks expect. */
*( pxFirstSemaphoreParameters->pulSharedVariable ) = semtstNON_BLOCKING_EXPECTED_VALUE;
/* The first two tasks do not block on semaphore calls. */
pxFirstSemaphoreParameters->xBlockTime = ( TickType_t ) 0;
/* The first two tasks do not block on semaphore calls. */
pxFirstSemaphoreParameters->xBlockTime = ( TickType_t ) 0;
/* Spawn the first two tasks. As they poll they operate at the idle priority. */
xTaskCreate( prvSemaphoreTest, "PolSEM1", semtstSTACK_SIZE, ( void * ) pxFirstSemaphoreParameters, tskIDLE_PRIORITY, ( TaskHandle_t * ) NULL );
xTaskCreate( prvSemaphoreTest, "PolSEM2", semtstSTACK_SIZE, ( void * ) pxFirstSemaphoreParameters, tskIDLE_PRIORITY, ( TaskHandle_t * ) NULL );
/* Spawn the first two tasks. As they poll they operate at the idle priority. */
xTaskCreate( prvSemaphoreTest, "PolSEM1", semtstSTACK_SIZE, ( void * ) pxFirstSemaphoreParameters, tskIDLE_PRIORITY, ( TaskHandle_t * ) NULL );
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. */
vQueueAddToRegistry( ( QueueHandle_t ) pxFirstSemaphoreParameters->xSemaphore, "Counting_Sem_1" );
}
}
/* 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. */
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. */
pxSecondSemaphoreParameters = ( xSemaphoreParameters * ) pvPortMalloc( sizeof( xSemaphoreParameters ) );
if( pxSecondSemaphoreParameters != NULL )
{
pxSecondSemaphoreParameters->xSemaphore = xSemaphoreCreateBinary();
/* Do exactly the same to create the second set of tasks, only this time
* provide a block time for the semaphore calls. */
pxSecondSemaphoreParameters = ( xSemaphoreParameters * ) pvPortMalloc( sizeof( xSemaphoreParameters ) );
if( pxSecondSemaphoreParameters->xSemaphore != NULL )
{
xSemaphoreGive( pxSecondSemaphoreParameters->xSemaphore );
if( pxSecondSemaphoreParameters != NULL )
{
pxSecondSemaphoreParameters->xSemaphore = xSemaphoreCreateBinary();
pxSecondSemaphoreParameters->pulSharedVariable = ( uint32_t * ) pvPortMalloc( sizeof( uint32_t ) );
*( pxSecondSemaphoreParameters->pulSharedVariable ) = semtstBLOCKING_EXPECTED_VALUE;
pxSecondSemaphoreParameters->xBlockTime = xBlockTime / portTICK_PERIOD_MS;
if( pxSecondSemaphoreParameters->xSemaphore != NULL )
{
xSemaphoreGive( pxSecondSemaphoreParameters->xSemaphore );
xTaskCreate( prvSemaphoreTest, "BlkSEM1", semtstSTACK_SIZE, ( void * ) pxSecondSemaphoreParameters, uxPriority, ( TaskHandle_t * ) NULL );
xTaskCreate( prvSemaphoreTest, "BlkSEM2", semtstSTACK_SIZE, ( void * ) pxSecondSemaphoreParameters, uxPriority, ( TaskHandle_t * ) NULL );
pxSecondSemaphoreParameters->pulSharedVariable = ( uint32_t * ) pvPortMalloc( sizeof( uint32_t ) );
*( pxSecondSemaphoreParameters->pulSharedVariable ) = semtstBLOCKING_EXPECTED_VALUE;
pxSecondSemaphoreParameters->xBlockTime = xBlockTime / portTICK_PERIOD_MS;
/* 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. */
vQueueAddToRegistry( ( QueueHandle_t ) pxSecondSemaphoreParameters->xSemaphore, "Counting_Sem_2" );
}
}
xTaskCreate( prvSemaphoreTest, "BlkSEM1", semtstSTACK_SIZE, ( void * ) pxSecondSemaphoreParameters, uxPriority, ( TaskHandle_t * ) NULL );
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. */
vQueueAddToRegistry( ( QueueHandle_t ) pxSecondSemaphoreParameters->xSemaphore, "Counting_Sem_2" );
}
}
}
/*-----------------------------------------------------------*/
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! */
portENTER_CRITICAL();
sCheckVariableToUse = sNextCheckVariable;
sNextCheckVariable++;
portEXIT_CRITICAL();
/* See which check variable to use. sNextCheckVariable is not semaphore
* protected! */
portENTER_CRITICAL();
sCheckVariableToUse = sNextCheckVariable;
sNextCheckVariable++;
portEXIT_CRITICAL();
/* A structure is passed in as the parameter. This contains the shared
variable being guarded. */
pxParameters = ( xSemaphoreParameters * ) pvParameters;
pulSharedVariable = pxParameters->pulSharedVariable;
/* A structure is passed in as the parameter. This contains the shared
* 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. */
if( pxParameters->xBlockTime > ( TickType_t ) 0 )
{
ulExpectedValue = semtstBLOCKING_EXPECTED_VALUE;
}
else
{
ulExpectedValue = semtstNON_BLOCKING_EXPECTED_VALUE;
}
/* If we are blocking we use a much higher count to ensure loads of context
* switches occur during the count. */
if( pxParameters->xBlockTime > ( TickType_t ) 0 )
{
ulExpectedValue = semtstBLOCKING_EXPECTED_VALUE;
}
else
{
ulExpectedValue = semtstNON_BLOCKING_EXPECTED_VALUE;
}
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. */
if( *pulSharedVariable != ulExpectedValue )
{
sError = pdTRUE;
}
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. */
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. */
for( ulCounter = ( uint32_t ) 0; ulCounter <= ulExpectedValue; ulCounter++ )
{
*pulSharedVariable = ulCounter;
if( *pulSharedVariable != ulCounter )
{
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. */
for( ulCounter = ( uint32_t ) 0; ulCounter <= ulExpectedValue; ulCounter++ )
{
*pulSharedVariable = ulCounter;
/* Release the semaphore, and if no errors have occurred increment the check
variable. */
if( xSemaphoreGive( pxParameters->xSemaphore ) == pdFALSE )
{
sError = pdTRUE;
}
if( *pulSharedVariable != ulCounter )
{
sError = pdTRUE;
}
}
if( sError == pdFALSE )
{
if( sCheckVariableToUse < semtstNUM_TASKS )
{
( sCheckVariables[ sCheckVariableToUse ] )++;
}
}
/* Release the semaphore, and if no errors have occurred increment the check
* variable. */
if( xSemaphoreGive( pxParameters->xSemaphore ) == pdFALSE )
{
sError = pdTRUE;
}
/* 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. */
if( pxParameters->xBlockTime != ( TickType_t ) 0 )
{
vTaskDelay( pxParameters->xBlockTime * semtstDELAY_FACTOR );
}
if( sError == pdFALSE )
{
if( sCheckVariableToUse < semtstNUM_TASKS )
{
( sCheckVariables[ sCheckVariableToUse ] )++;
}
}
}
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. */
taskYIELD();
}
}
}
/* 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. */
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. */
taskYIELD();
}
}
}
}
/*-----------------------------------------------------------*/
/* 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++ )
{
if( sLastCheckVariables[ xTask ] == sCheckVariables[ xTask ] )
{
xReturn = pdFALSE;
}
for( xTask = 0; xTask < semtstNUM_TASKS; xTask++ )
{
if( sLastCheckVariables[ xTask ] == sCheckVariables[ xTask ] )
{
xReturn = pdFALSE;
}
sLastCheckVariables[ xTask ] = sCheckVariables[ xTask ];
}
sLastCheckVariables[ xTask ] = sCheckVariables[ xTask ];
}
return xReturn;
return xReturn;
}

View file

@ -48,254 +48,255 @@
/* Demo program include files. */
#include "flop.h"
#define mathSTACK_SIZE configMINIMAL_STACK_SIZE
#define mathNUMBER_OF_TASKS ( 8 )
#define mathSTACK_SIZE configMINIMAL_STACK_SIZE
#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 };
/*-----------------------------------------------------------*/
void vStartMathTasks( UBaseType_t uxPriority )
{
xTaskCreate( vCompetingMathTask1, "Math1", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 0 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask2, "Math2", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 1 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask3, "Math3", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 2 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask4, "Math4", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 3 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask1, "Math5", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 4 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask2, "Math6", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 5 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask3, "Math7", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 6 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask4, "Math8", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 7 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask1, "Math1", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 0 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask2, "Math2", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 1 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask3, "Math3", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 2 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask4, "Math4", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 3 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask1, "Math5", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 4 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask2, "Math6", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 5 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask3, "Math7", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 6 ] ), uxPriority, NULL );
xTaskCreate( vCompetingMathTask4, "Math8", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 7 ] ), uxPriority, NULL );
}
/*-----------------------------------------------------------*/
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;
f3 = -918.222F;
f1 = 123.4567F;
f2 = 2345.6789F;
f3 = -918.222F;
fAnswer = ( f1 + f2 ) * f3;
fAnswer = ( f1 + f2 ) * f3;
/* The variable this task increments to show it is still running is passed in
as the parameter. */
pusTaskCheckVariable = ( uint16_t * ) pvParameters;
/* The variable this task increments to show it is still running is passed in
* as the parameter. */
pusTaskCheckVariable = ( uint16_t * ) pvParameters;
/* Keep performing a calculation and checking the result against a constant. */
for(;;)
{
f1 = 123.4567F;
f2 = 2345.6789F;
f3 = -918.222F;
/* Keep performing a calculation and checking the result against a constant. */
for( ; ; )
{
f1 = 123.4567F;
f2 = 2345.6789F;
f3 = -918.222F;
f4 = ( f1 + f2 ) * f3;
f4 = ( f1 + f2 ) * f3;
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
/* If the calculation does not match the expected constant, stop the
increment of the check variable. */
if( fabs( f4 - fAnswer ) > 0.001F )
{
sError = pdTRUE;
}
/* If the calculation does not match the expected constant, stop the
* increment of the check variable. */
if( fabs( f4 - fAnswer ) > 0.001F )
{
sError = pdTRUE;
}
if( sError == pdFALSE )
{
/* If the calculation has always been correct, increment the check
variable so we know this task is still running okay. */
( *pusTaskCheckVariable )++;
}
if( sError == pdFALSE )
{
/* If the calculation has always been correct, increment the check
* variable so we know this task is still running okay. */
( *pusTaskCheckVariable )++;
}
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
}
#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;
f3 = -2.0001F;
f1 = -389.38F;
f2 = 32498.2F;
f3 = -2.0001F;
fAnswer = ( f1 / f2 ) * f3;
fAnswer = ( f1 / f2 ) * f3;
/* The variable this task increments to show it is still running is passed in
as the parameter. */
pusTaskCheckVariable = ( uint16_t * ) pvParameters;
/* The variable this task increments to show it is still running is passed in
* as the parameter. */
pusTaskCheckVariable = ( uint16_t * ) pvParameters;
/* Keep performing a calculation and checking the result against a constant. */
for( ;; )
{
f1 = -389.38F;
f2 = 32498.2F;
f3 = -2.0001F;
/* Keep performing a calculation and checking the result against a constant. */
for( ; ; )
{
f1 = -389.38F;
f2 = 32498.2F;
f3 = -2.0001F;
f4 = ( f1 / f2 ) * f3;
f4 = ( f1 / f2 ) * f3;
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
/* If the calculation does not match the expected constant, stop the
increment of the check variable. */
if( fabs( f4 - fAnswer ) > 0.001F )
{
sError = pdTRUE;
}
/* If the calculation does not match the expected constant, stop the
* increment of the check variable. */
if( fabs( f4 - fAnswer ) > 0.001F )
{
sError = pdTRUE;
}
if( sError == pdFALSE )
{
/* If the calculation has always been correct, increment the check
variable so we know
this task is still running okay. */
( *pusTaskCheckVariable )++;
}
if( sError == pdFALSE )
{
/* If the calculation has always been correct, increment the check
* variable so we know
* this task is still running okay. */
( *pusTaskCheckVariable )++;
}
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
}
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
}
}
/*-----------------------------------------------------------*/
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. */
pusTaskCheckVariable = ( uint16_t * ) pvParameters;
/* The variable this task increments to show it is still running is passed in
* as the parameter. */
pusTaskCheckVariable = ( uint16_t * ) pvParameters;
pfArray = ( float * ) pvPortMalloc( xArraySize * sizeof( float ) );
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( ;; )
{
fTotal1 = 0.0F;
fTotal2 = 0.0F;
fPosition = 0.0F;
/* 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( ; ; )
{
fTotal1 = 0.0F;
fTotal2 = 0.0F;
fPosition = 0.0F;
for( xPosition = 0; xPosition < xArraySize; xPosition++ )
{
pfArray[ xPosition ] = fPosition + 5.5F;
fTotal1 += fPosition + 5.5F;
}
for( xPosition = 0; xPosition < xArraySize; xPosition++ )
{
pfArray[ xPosition ] = fPosition + 5.5F;
fTotal1 += fPosition + 5.5F;
}
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
for( xPosition = 0; xPosition < xArraySize; xPosition++ )
{
fTotal2 += pfArray[ xPosition ];
}
for( xPosition = 0; xPosition < xArraySize; xPosition++ )
{
fTotal2 += pfArray[ xPosition ];
}
fDifference = fTotal1 - fTotal2;
if( fabs( fDifference ) > 0.001F )
{
sError = pdTRUE;
}
fDifference = fTotal1 - fTotal2;
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
if( fabs( fDifference ) > 0.001F )
{
sError = pdTRUE;
}
if( sError == pdFALSE )
{
/* If the calculation has always been correct, increment the check
variable so we know this task is still running okay. */
( *pusTaskCheckVariable )++;
}
}
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
if( sError == pdFALSE )
{
/* If the calculation has always been correct, increment the check
* variable so we know this task is still running okay. */
( *pusTaskCheckVariable )++;
}
}
}
/*-----------------------------------------------------------*/
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. */
pusTaskCheckVariable = ( uint16_t * ) pvParameters;
/* The variable this task increments to show it is still running is passed in
* as the parameter. */
pusTaskCheckVariable = ( uint16_t * ) pvParameters;
pfArray = ( float * ) pvPortMalloc( xArraySize * sizeof( float ) );
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( ;; )
{
fTotal1 = 0.0F;
fTotal2 = 0.0F;
fPosition = 0.0F;
/* 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( ; ; )
{
fTotal1 = 0.0F;
fTotal2 = 0.0F;
fPosition = 0.0F;
for( xPosition = 0; xPosition < xArraySize; xPosition++ )
{
pfArray[ xPosition ] = fPosition * 12.123F;
fTotal1 += fPosition * 12.123F;
}
for( xPosition = 0; xPosition < xArraySize; xPosition++ )
{
pfArray[ xPosition ] = fPosition * 12.123F;
fTotal1 += fPosition * 12.123F;
}
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
for( xPosition = 0; xPosition < xArraySize; xPosition++ )
{
fTotal2 += pfArray[ xPosition ];
}
for( xPosition = 0; xPosition < xArraySize; xPosition++ )
{
fTotal2 += pfArray[ xPosition ];
}
fDifference = fTotal1 - fTotal2;
if( fabs( fDifference ) > 0.001F )
{
sError = pdTRUE;
}
fDifference = fTotal1 - fTotal2;
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
if( fabs( fDifference ) > 0.001F )
{
sError = pdTRUE;
}
if( sError == pdFALSE )
{
/* If the calculation has always been correct, increment the check
variable so we know this task is still running okay. */
( *pusTaskCheckVariable )++;
}
}
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
if( sError == pdFALSE )
{
/* If the calculation has always been correct, increment the check
* variable so we know this task is still running okay. */
( *pusTaskCheckVariable )++;
}
}
}
/*-----------------------------------------------------------*/
@ -303,25 +304,22 @@ 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. */
for( xTask = 0; xTask < mathNUMBER_OF_TASKS; xTask++ )
{
if( usTaskCheck[ xTask ] == usLastTaskCheck[ xTask ] )
{
/* The check has not incremented so an error exists. */
xReturn = pdFALSE;
}
/* Check the maths tasks are still running by ensuring their check variables
* are still incrementing. */
for( xTask = 0; xTask < mathNUMBER_OF_TASKS; xTask++ )
{
if( usTaskCheck[ xTask ] == usLastTaskCheck[ xTask ] )
{
/* The check has not incremented so an error exists. */
xReturn = pdFALSE;
}
usLastTaskCheck[ xTask ] = usTaskCheck[ xTask ];
}
usLastTaskCheck[ xTask ] = usTaskCheck[ xTask ];
}
return xReturn;
return xReturn;
}

View file

@ -32,5 +32,3 @@ void vCreateAbortDelayTasks( void );
BaseType_t xAreAbortDelayTestTasksStillRunning( void );
#endif

View file

@ -32,5 +32,3 @@ void vStartBlockingQueueTasks( UBaseType_t uxPriority );
BaseType_t xAreBlockingQueuesStillRunning( void );
#endif

View file

@ -41,4 +41,3 @@ BaseType_t xAreEventGroupTasksStillRunning( void );
void vPeriodicEventGroupsProcessing( void );
#endif /* EVENT_GROUPS_DEMO_H */

View file

@ -33,6 +33,3 @@ BaseType_t xAreGenericQueueTasksStillRunning( void );
void vMutexISRInteractionTest( void );
#endif /* GEN_Q_TEST_H */

View file

@ -34,9 +34,3 @@ BaseType_t xFirstTimerHandler( void );
BaseType_t xSecondTimerHandler( void );
#endif /* QUEUE_ACCESS_TEST */

View file

@ -33,6 +33,3 @@ BaseType_t xAreInterruptSemaphoreTasksStillRunning( void );
void vInterruptSemaphorePeriodicTest( void );
#endif /* INT_SEM_TEST_H */

View file

@ -28,10 +28,7 @@
#ifndef MESSAGE_BUFFER_TEST_H
#define MESSAGE_BUFFER_TEST_H
void vStartMessageBufferTasks( configSTACK_DEPTH_TYPE xStackSize );
void vStartMessageBufferTasks( configSTACK_DEPTH_TYPE xStackSize );
BaseType_t xAreMessageBufferTasksStillRunning( void );
#endif /* MESSAGE_BUFFER_TEST_H */

View file

@ -32,5 +32,3 @@ void vStartPolledQueueTasks( UBaseType_t uxPriority );
BaseType_t xArePollingQueuesStillRunning( void );
#endif

View file

@ -32,6 +32,3 @@ void vStartQueuePeekTasks( void );
BaseType_t xAreQueuePeekTasksStillRunning( void );
#endif /* Q_PEEK_TEST_H */

View file

@ -33,5 +33,3 @@ BaseType_t xIsQueueOverwriteTaskStillRunning( void );
void vQueueOverwritePeriodicISRDemo( void );
#endif /* QUEUE_OVERWRITE_H */

View file

@ -33,5 +33,3 @@ BaseType_t xAreQueueSetTasksStillRunning( void );
void vQueueSetAccessQueueSetFromISR( void );
#endif /* QUEUE_WAIT_MULTIPLE_H */

View file

@ -33,5 +33,3 @@ BaseType_t xAreQueueSetPollTasksStillRunning( void );
void vQueueSetPollingInterruptAccess( void );
#endif /* QUEUE_SET_POLLING_H */

View file

@ -28,10 +28,7 @@
#ifndef STATIC_ALLOCATION_H
#define STATIC_ALLOCATION_H
void vStartStaticallyAllocatedTasks( void );
void vStartStaticallyAllocatedTasks( void );
BaseType_t xAreStaticAllocationTasksStillRunning( void );
#endif /* STATIC_ALLOCATION_H */

View file

@ -33,6 +33,3 @@ BaseType_t xAreStreamBufferTasksStillRunning( void );
void vPeriodicStreamBufferProcessing( void );
#endif /* STREAM_BUFFER_TEST_H */

View file

@ -28,11 +28,8 @@
#ifndef TASK_NOTIFY_H
#define TASK_NOTIFY_H
void vStartTaskNotifyTask( void );
void vStartTaskNotifyTask( void );
BaseType_t xAreTaskNotificationTasksStillRunning( void );
void xNotifyTaskFromISR( void );
#endif /* TASK_NOTIFY_H */

View file

@ -28,11 +28,8 @@
#ifndef TASK_NOTIFY_ARRAY_H
#define TASK_NOTIFY_ARRAY_H
void vStartTaskNotifyArrayTask( void );
void vStartTaskNotifyArrayTask( void );
BaseType_t xAreTaskNotificationArrayTasksStillRunning( void );
void xNotifyArrayTaskFromISR( void );
#endif /* TASK_NOTIFY_ARRAY_H */

View file

@ -33,6 +33,3 @@ void vTimerPeriodicISRTests( void );
void vTimerDemoIncludeBacklogTests( BaseType_t includeBacklogTests );
#endif /* TIMER_DEMO_H */

View file

@ -32,5 +32,3 @@ void vCreateBlockTimeTasks( void );
BaseType_t xAreBlockTimeTestTasksStillRunning( void );
#endif

View file

@ -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 */

View file

@ -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

View file

@ -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

View file

@ -32,4 +32,3 @@ void vStartCountingSemaphoreTasks( void );
BaseType_t xAreCountingSemaphoreTasksStillRunning( void );
#endif

View file

@ -44,4 +44,3 @@ void vStartFlashCoRoutines( UBaseType_t uxPriority );
BaseType_t xAreFlashCoRoutinesStillRunning( void );
#endif

View file

@ -40,4 +40,3 @@ void vStartHookCoRoutines( void );
BaseType_t xAreHookCoRoutinesStillRunning( void );
#endif

View file

@ -32,5 +32,3 @@ void vCreateSuicidalTasks( UBaseType_t uxPriority );
BaseType_t xIsCreateTaskStillRunning( void );
#endif

View file

@ -32,5 +32,3 @@ void vStartDynamicPriorityTasks( void );
BaseType_t xAreDynamicPriorityTasksStillRunning( void );
#endif

View file

@ -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

View file

@ -31,4 +31,3 @@
void vStartLEDFlashTasks( UBaseType_t uxPriority );
#endif

View file

@ -32,5 +32,3 @@ void vStartMathTasks( UBaseType_t uxPriority );
BaseType_t xAreMathsTaskStillRunning( void );
#endif

View file

@ -32,5 +32,3 @@ void vStartIntegerMathTasks( UBaseType_t uxPriority );
BaseType_t xAreIntegerMathsTaskStillRunning( void );
#endif

View file

@ -32,5 +32,3 @@ void vStartMultiEventTasks( void );
BaseType_t xAreMultiEventTasksStillRunning( void );
#endif

View file

@ -28,11 +28,11 @@
#ifndef PARTEST_H
#define PARTEST_H
#define partstDEFAULT_PORT_ADDRESS ( ( uint16_t ) 0x378 )
#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

View file

@ -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

View file

@ -32,4 +32,3 @@ void vStartRecursiveMutexTasks( void );
BaseType_t xAreRecursiveMutexTasksStillRunning( void );
#endif

View file

@ -32,4 +32,3 @@ void vStartSemaphoreTasks( UBaseType_t uxPriority );
BaseType_t xAreSemaphoreTasksStillRunning( void );
#endif

View file

@ -32,67 +32,78 @@ typedef void * xComPortHandle;
typedef enum
{
serCOM1,
serCOM2,
serCOM3,
serCOM4,
serCOM5,
serCOM6,
serCOM7,
serCOM8
serCOM1,
serCOM2,
serCOM3,
serCOM4,
serCOM5,
serCOM6,
serCOM7,
serCOM8
} eCOMPort;
typedef enum
{
serNO_PARITY,
serODD_PARITY,
serEVEN_PARITY,
serMARK_PARITY,
serSPACE_PARITY
serNO_PARITY,
serODD_PARITY,
serEVEN_PARITY,
serMARK_PARITY,
serSPACE_PARITY
} eParity;
typedef enum
{
serSTOP_1,
serSTOP_2
serSTOP_1,
serSTOP_2
} eStopBits;
typedef enum
{
serBITS_5,
serBITS_6,
serBITS_7,
serBITS_8
serBITS_5,
serBITS_6,
serBITS_7,
serBITS_8
} eDataBits;
typedef enum
{
ser50,
ser75,
ser110,
ser134,
ser150,
ser200,
ser300,
ser600,
ser1200,
ser1800,
ser2400,
ser4800,
ser9600,
ser19200,
ser38400,
ser57600,
ser115200
ser50,
ser75,
ser110,
ser134,
ser150,
ser200,
ser300,
ser600,
ser1200,
ser1800,
ser2400,
ser4800,
ser9600,
ser19200,
ser38400,
ser57600,
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 */

View file

@ -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

View file

@ -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 );
}

View file

@ -1,12 +1,20 @@
int32_t publicTCPPrepareSend( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer, UBaseType_t uxOptionsLength ) {
prvTCPPrepareSend( pxSocket, ppxNetworkBuffer, 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 );
}

View file

@ -18,12 +18,12 @@
#include "NetworkInterface.h"
/*
* CBMC models a pointer as an object id and an offset into that
* object. The top bits of a pointer encode the object id and the
* remaining bits encode the offset. This means there is a bound on
* the maximum offset into an object in CBMC, and hence a bound on the
* size of objects in CBMC.
*/
* CBMC models a pointer as an object id and an offset into that
* object. The top bits of a pointer encode the object id and the
* remaining bits encode the offset. This means there is a bound on
* the maximum offset into an object in CBMC, and hence a bound on the
* size of objects in CBMC.
*/
#define CBMC_BITS 7
#define CBMC_MAX_OBJECT_SIZE ( 0xFFFFFFFF >> ( CBMC_BITS + 1 ) )
@ -70,19 +70,19 @@ enum CBMC_LOOP_CONDITION
#define __CPROVER_printf2_ptr( str, exp ) { uint8_t * ValueOf_ ## str = ( uint8_t * ) ( exp ); }
/*
* An assertion that pvPortMalloc returns NULL when asked to allocate 0 bytes.
* This assertion is used in some of the TaskPool proofs.
*/
* An assertion that pvPortMalloc returns NULL when asked to allocate 0 bytes.
* This assertion is used in some of the TaskPool proofs.
*/
#define __CPROVER_assert_zero_allocation() \
__CPROVER_assert( pvPortMalloc( 0 ) == NULL, \
"pvPortMalloc allows zero-allocated memory." )
/*
* A stub for pvPortMalloc that nondeterministically chooses to return
* either NULL or an allocation of the requested space. The stub is
* guaranteed to return NULL when asked to allocate 0 bytes.
* This stub is used in some of the TaskPool proofs.
*/
* A stub for pvPortMalloc that nondeterministically chooses to return
* either NULL or an allocation of the requested space. The stub is
* guaranteed to return NULL when asked to allocate 0 bytes.
* This stub is used in some of the TaskPool proofs.
*/
void * pvPortMalloc( size_t xWantedSize )
{
if( xWantedSize == 0 )

View file

@ -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 )
{
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
{
return nondet_BaseType_t();
}
}
#endif
* 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 )
{
__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
{
return nondet_BaseType_t();
}
}
#endif /* if ( configUSE_QUEUE_SETS == 1 ) */
/* xQueueCreateSet is compiled out if configUSE_QUEUE_SETS != 1.*/
#if( configUSE_QUEUE_SETS == 1 )
QueueSetHandle_t xUnconstrainedQueueSet()
{
UBaseType_t uxEventQueueLength = 2;
QueueSetHandle_t xSet = xQueueCreateSet(uxEventQueueLength);
if( xSet )
{
xSet->cTxLock = nondet_int8_t();
__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);
xSet->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
}
return xSet;
}
#endif
#if ( configUSE_QUEUE_SETS == 1 )
QueueSetHandle_t xUnconstrainedQueueSet()
{
UBaseType_t uxEventQueueLength = 2;
QueueSetHandle_t xSet = xQueueCreateSet( uxEventQueueLength );
if( xSet )
{
xSet->cTxLock = nondet_int8_t();
__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 );
xSet->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
}
return xSet;
}
#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 ) {
UBaseType_t uxQueueLength;
UBaseType_t uxItemSize;
uint8_t ucQueueType;
__CPROVER_assume(uxQueueLength > 0);
__CPROVER_assume(uxItemSize < 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;
// 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( uxQueueLength > 0 );
__CPROVER_assume( uxItemSize < uxItemSizeBound );
QueueHandle_t xQueue =
xQueueGenericCreate(uxQueueLength, uxItemSize, ucQueueType);
if(xQueue){
xQueue->cTxLock = nondet_int8_t();
__CPROVER_assume(xQueue->cTxLock != 127);
xQueue->cRxLock = nondet_int8_t();
__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);
xQueue->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
xQueue->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
#if( configUSE_QUEUE_SETS == 1)
xQueueAddToSet(xQueue, xUnconstrainedQueueSet());
#endif
}
return xQueue;
/* QueueGenericCreate method does not check for multiplication overflow */
size_t uxQueueStorageSize;
__CPROVER_assume( uxQueueStorageSize < CBMC_OBJECT_MAX_SIZE );
__CPROVER_assume( uxItemSize < uxQueueStorageSize / uxQueueLength );
QueueHandle_t xQueue =
xQueueGenericCreate( uxQueueLength, uxItemSize, ucQueueType );
if( xQueue )
{
xQueue->cTxLock = nondet_int8_t();
__CPROVER_assume( xQueue->cTxLock != 127 );
xQueue->cRxLock = nondet_int8_t();
__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 );
xQueue->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
xQueue->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
#if ( configUSE_QUEUE_SETS == 1 )
xQueueAddToSet( xQueue, xUnconstrainedQueueSet() );
#endif
}
return xQueue;
}
/* Create a mostly unconstrained Queue */
QueueHandle_t xUnconstrainedQueue( void ) {
UBaseType_t uxQueueLength;
UBaseType_t uxItemSize;
uint8_t ucQueueType;
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
size_t uxQueueStorageSize;
__CPROVER_assume(uxQueueStorageSize < CBMC_OBJECT_MAX_SIZE);
__CPROVER_assume(uxItemSize < uxQueueStorageSize/uxQueueLength);
/* QueueGenericCreate method does not check for multiplication overflow */
size_t uxQueueStorageSize;
__CPROVER_assume( uxQueueStorageSize < CBMC_OBJECT_MAX_SIZE );
__CPROVER_assume( uxItemSize < uxQueueStorageSize / uxQueueLength );
QueueHandle_t xQueue =
xQueueGenericCreate(uxQueueLength, uxItemSize, ucQueueType);
QueueHandle_t xQueue =
xQueueGenericCreate( uxQueueLength, uxItemSize, ucQueueType );
if(xQueue){
xQueue->cTxLock = nondet_int8_t();
__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);
xQueue->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
xQueue->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
#if( configUSE_QUEUE_SETS == 1)
xQueueAddToSet(xQueue, xUnconstrainedQueueSet());
#endif
}
return xQueue;
if( xQueue )
{
xQueue->cTxLock = nondet_int8_t();
__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 );
xQueue->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
xQueue->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
#if ( configUSE_QUEUE_SETS == 1 )
xQueueAddToSet( xQueue, xUnconstrainedQueueSet() );
#endif
}
return xQueue;
}
/* Create a mostly unconstrained Mutex */
QueueHandle_t xUnconstrainedMutex( void ) {
uint8_t ucQueueType;
QueueHandle_t xQueue =
xQueueCreateMutex(ucQueueType);
if(xQueue){
xQueue->cTxLock = nondet_int8_t();
__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);
xQueue->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
xQueue->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
#if( configUSE_QUEUE_SETS == 1)
xQueueAddToSet(xQueue, xUnconstrainedQueueSet());
#endif
}
return xQueue;
QueueHandle_t xUnconstrainedMutex( void )
{
uint8_t ucQueueType;
QueueHandle_t xQueue =
xQueueCreateMutex( ucQueueType );
if( xQueue )
{
xQueue->cTxLock = nondet_int8_t();
__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 );
xQueue->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
xQueue->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
#if ( configUSE_QUEUE_SETS == 1 )
xQueueAddToSet( xQueue, xUnconstrainedQueueSet() );
#endif
}
return xQueue;
}

View file

@ -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 */

View file

@ -53,10 +53,10 @@
#define configIDLE_SHOULD_YIELD 1
#define configUSE_CO_ROUTINES 0
#ifndef configUSE_MUTEXES
#define configUSE_MUTEXES 1
#define configUSE_MUTEXES 1
#endif
#ifndef configUSE_RECURSIVE_MUTEXES
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_RECURSIVE_MUTEXES 1
#endif
#define configQUEUE_REGISTRY_SIZE 0
#define configUSE_APPLICATION_TASK_TAG 1
@ -67,31 +67,31 @@
/* Hook function related definitions. */
#ifndef configUSE_TICK_HOOK
#define configUSE_TICK_HOOK 0
#define configUSE_TICK_HOOK 0
#endif
#define configUSE_IDLE_HOOK 1
#define configUSE_MALLOC_FAILED_HOOK 1
#define configCHECK_FOR_STACK_OVERFLOW 0 /* Not applicable to the Win32 port. */
#define configUSE_IDLE_HOOK 1
#define configUSE_MALLOC_FAILED_HOOK 1
#define configCHECK_FOR_STACK_OVERFLOW 0 /* Not applicable to the Win32 port. */
/* Software timer related definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
#define configTIMER_QUEUE_LENGTH 5
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
#define configTIMER_QUEUE_LENGTH 5
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )
/* Event group related definitions. */
#define configUSE_EVENT_GROUPS 1
#define configUSE_EVENT_GROUPS 1
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* Memory allocation strategy. */
#ifndef configSUPPORT_DYNAMIC_ALLOCATION
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#endif
#ifndef configSUPPORT_STATIC_ALLOCATION
#define configSUPPORT_STATIC_ALLOCATION 1
#define configSUPPORT_STATIC_ALLOCATION 1
#endif
@ -102,13 +102,13 @@
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#ifndef INCLUDE_vTaskSuspend
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskSuspend 1
#endif
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#ifndef INCLUDE_xTaskGetSchedulerState
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTaskGetSchedulerState 1
#endif
#define INCLUDE_xTimerGetTimerTaskHandle 0
#define INCLUDE_xTaskGetIdleTaskHandle 0
@ -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 */

View file

@ -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
*/
/*****************************************************************************
@ -156,19 +156,19 @@ extern uint32_t ulRand();
* cache then the UDP message is replaced by a ARP message that solicits the
* required MAC address information. ipconfigARP_CACHE_ENTRIES defines the maximum
* number of entries that can exist in the ARP table at any one time. */
#define ipconfigARP_CACHE_ENTRIES 6
#define ipconfigARP_CACHE_ENTRIES 6
/* ARP requests that do not result in an ARP response will be re-transmitted a
* maximum of ipconfigMAX_ARP_RETRANSMISSIONS times before the ARP request is
* aborted. */
#define ipconfigMAX_ARP_RETRANSMISSIONS ( 5 )
#define ipconfigMAX_ARP_RETRANSMISSIONS ( 5 )
/* ipconfigMAX_ARP_AGE defines the maximum time between an entry in the ARP
* table being created or refreshed and the entry being removed because it is stale.
* New ARP requests are sent for ARP cache entries that are nearing their maximum
* age. ipconfigMAX_ARP_AGE is specified in tens of seconds, so a value of 150 is
* equal to 1500 seconds (or 25 minutes). */
#define ipconfigMAX_ARP_AGE 150
#define ipconfigMAX_ARP_AGE 150
/* Implementing FreeRTOS_inet_addr() necessitates the use of string handling
* routines, which are relatively large. To save code space the full
@ -180,14 +180,14 @@ extern uint32_t ulRand();
* ipconfigINCLUDE_FULL_INET_ADDR is set to 1 then both FreeRTOS_inet_addr() and
* FreeRTOS_indet_addr_quick() are available. If ipconfigINCLUDE_FULL_INET_ADDR is
* not set to 1 then only FreeRTOS_indet_addr_quick() is available. */
#define ipconfigINCLUDE_FULL_INET_ADDR 1
#define ipconfigINCLUDE_FULL_INET_ADDR 1
/* ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS defines the total number of network buffer that
* are available to the IP stack. The total number of network buffers is limited
* to ensure the total amount of RAM that can be consumed by the IP stack is capped
* to a pre-determinable value. */
#ifndef ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60
#endif
/* A FreeRTOS queue is used to send events from application tasks to the IP

View file

@ -3,15 +3,15 @@
#include "tasksStubs.h"
#ifndef TASK_STUB_COUNTER
#define TASK_STUB_COUNTER 0;
#define TASK_STUB_COUNTER 0;
#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;
#define TASK_STUB_COUNTER_LIMIT 5;
#endif
@ -20,28 +20,32 @@ static BaseType_t xCounterLimit = TASK_STUB_COUNTER_LIMIT;
BaseType_t xTaskGetSchedulerState( void )
{
return xState;
return xState;
}
/* 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;
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 ) {
++xCounter;
if(xCounter == xCounterLimit)
{
return pdTRUE;
}
else
{
return nondet_basetype();
}
* 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 )
{
return pdTRUE;
}
else
{
return nondet_basetype();
}
}

View file

@ -31,8 +31,9 @@
#include "cbmc.h"
void harness() {
uint8_t ucQueueType;
void harness()
{
uint8_t ucQueueType;
xQueueCreateMutex(ucQueueType);
xQueueCreateMutex( ucQueueType );
}

View file

@ -34,94 +34,112 @@
#include "cbmc.h"
#ifndef LOCK_BOUND
#define LOCK_BOUND 4
#define LOCK_BOUND 4
#endif
#ifndef QUEUE_SEND_BOUND
#define QUEUE_SEND_BOUND 4
#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 ( configUSE_QUEUE_SETS == 0 )
BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
const void * pvItemToQueue,
const BaseType_t xPosition )
{
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
{
return nondet_BaseType_t();
}
}
#else /* if ( configUSE_QUEUE_SETS == 0 ) */
BaseType_t prvNotifyQueueSetContainer( const Queue_t * const pxQueue )
{
Queue_t * pxQueueSetContainer = pxQueue->pxQueueSetContainer;
configASSERT( pxQueueSetContainer );
}
void prvUnlockQueue( Queue_t * const pxQueue )
{
configASSERT( pxQueue );
if( pxQueue->pxQueueSetContainer != NULL )
{
prvNotifyQueueSetContainer( pxQueue );
}
listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) );
pxQueue->cTxLock = queueUNLOCKED;
listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) );
pxQueue->cRxLock = queueUNLOCKED;
}
#endif /* if ( configUSE_QUEUE_SETS == 0 ) */
void harness()
{
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
{
return nondet_BaseType_t();
}
/*Initialise the tasksStubs */
vInitTaskCheckForTimeOut( 0, QUEUE_SEND_BOUND - 1 );
xState = nondet_basetype();
QueueHandle_t xQueue =
xUnconstrainedQueueBoundedItemSize( 2 );
TickType_t xTicksToWait;
if( xState == taskSCHEDULER_SUSPENDED )
{
xTicksToWait = 0;
}
if( xQueue )
{
void * pvItemToQueue = pvPortMalloc( xQueue->uxItemSize );
BaseType_t xCopyPosition;
if( xCopyPosition == queueOVERWRITE )
{
xQueue->uxLength = 1;
}
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. */
xQueue->uxQueueType = nondet_int8_t();
pvItemToQueue = 0;
}
/* This code checks explicitly for violations of the pxQueue->uxMessagesWaiting < pxQueue->uxLength
* invariant. */
xQueue->uxMessagesWaiting = nondet_UBaseType_t();
/* These values are decremented during a while loop interacting with task.c.
* This interaction is currently abstracted away.*/
xQueue->cTxLock = LOCK_BOUND - 1;
xQueue->cRxLock = LOCK_BOUND - 1;
if( !pvItemToQueue )
{
xQueue->uxItemSize = 0;
}
xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, xCopyPosition );
}
}
#else
BaseType_t prvNotifyQueueSetContainer( const Queue_t * const pxQueue )
{
Queue_t *pxQueueSetContainer = pxQueue->pxQueueSetContainer;
configASSERT( pxQueueSetContainer );
}
void prvUnlockQueue( Queue_t * const pxQueue ) {
configASSERT( pxQueue );
if( pxQueue->pxQueueSetContainer != NULL )
{
prvNotifyQueueSetContainer(pxQueue);
}
listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) );
pxQueue->cTxLock = queueUNLOCKED;
listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) );
pxQueue->cRxLock = queueUNLOCKED;
}
#endif
void harness(){
//Initialise the tasksStubs
vInitTaskCheckForTimeOut(0, QUEUE_SEND_BOUND - 1);
xState = nondet_basetype();
QueueHandle_t xQueue =
xUnconstrainedQueueBoundedItemSize(2);
TickType_t xTicksToWait;
if(xState == taskSCHEDULER_SUSPENDED){
xTicksToWait = 0;
}
if(xQueue){
void *pvItemToQueue = pvPortMalloc(xQueue->uxItemSize);
BaseType_t xCopyPosition;
if(xCopyPosition == queueOVERWRITE){
xQueue->uxLength = 1;
}
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. */
xQueue->uxQueueType = nondet_int8_t();
pvItemToQueue = 0;
}
/* This code checks explicitly for violations of the pxQueue->uxMessagesWaiting < pxQueue->uxLength
invariant. */
xQueue->uxMessagesWaiting = nondet_UBaseType_t();
/* These values are decremented during a while loop interacting with task.c.
This interaction is currently abstracted away.*/
xQueue->cTxLock = LOCK_BOUND - 1;
xQueue->cRxLock = LOCK_BOUND - 1;
if(!pvItemToQueue){
xQueue->uxItemSize = 0;
}
xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, xCopyPosition );
}
}

View file

@ -33,53 +33,70 @@
#include "cbmc.h"
#ifndef ITEM_BOUND
#define ITEM_BOUND 10
#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(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
{
return nondet_BaseType_t();
}
}
#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 )
{
__CPROVER_assert( __CPROVER_r_ok( pvItemToQueue, ( size_t ) pxQueue->uxItemSize ), "pvItemToQueue region must be readable" );
void harness(){
QueueHandle_t xQueue = xUnconstrainedQueueBoundedItemSize(ITEM_BOUND);
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
{
return nondet_BaseType_t();
}
}
#endif /* if ( configUSE_QUEUE_SETS == 0 ) */
void harness()
{
QueueHandle_t xQueue = xUnconstrainedQueueBoundedItemSize( ITEM_BOUND );
if( xQueue ){
void *pvItemToQueue = pvPortMalloc(xQueue->uxItemSize);
BaseType_t *xHigherPriorityTaskWoken = pvPortMalloc(sizeof(BaseType_t));
BaseType_t xCopyPosition;
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. */
xQueue->uxQueueType = nondet_int8_t();
pvItemToQueue = 0;
}
/* This code checks explicitly for violations of the pxQueue->uxMessagesWaiting < pxQueue->uxLength
invariant. */
xQueue->uxMessagesWaiting = nondet_UBaseType_t();
if(!pvItemToQueue){
xQueue->uxItemSize = 0;
}
if(xCopyPosition == 2 ){
__CPROVER_assume(xQueue->uxLength == 1);
}
xQueueGenericSendFromISR( xQueue, pvItemToQueue, xHigherPriorityTaskWoken, xCopyPosition );
}
if( xQueue )
{
void * pvItemToQueue = pvPortMalloc( xQueue->uxItemSize );
BaseType_t * xHigherPriorityTaskWoken = pvPortMalloc( sizeof( BaseType_t ) );
BaseType_t xCopyPosition;
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. */
xQueue->uxQueueType = nondet_int8_t();
pvItemToQueue = 0;
}
/* This code checks explicitly for violations of the pxQueue->uxMessagesWaiting < pxQueue->uxLength
* invariant. */
xQueue->uxMessagesWaiting = nondet_UBaseType_t();
if( !pvItemToQueue )
{
xQueue->uxItemSize = 0;
}
if( xCopyPosition == 2 )
{
__CPROVER_assume( xQueue->uxLength == 1 );
}
xQueueGenericSendFromISR( xQueue, pvItemToQueue, xHigherPriorityTaskWoken, xCopyPosition );
}
}

View file

@ -32,10 +32,13 @@
#include "cbmc.h"
void harness() {
QueueHandle_t xSemaphore = xUnconstrainedQueue();
if (xSemaphore) {
xSemaphore->uxQueueType = nondet_uint8_t();
xQueueGetMutexHolder(xSemaphore);
}
void harness()
{
QueueHandle_t xSemaphore = xUnconstrainedQueue();
if( xSemaphore )
{
xSemaphore->uxQueueType = nondet_uint8_t();
xQueueGetMutexHolder( xSemaphore );
}
}

Some files were not shown because too many files have changed in this diff Show more