mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-04-20 05:21:59 -04:00
Add in example vQueueAddToRegistry() calls.
This commit is contained in:
parent
15881cdf39
commit
a5f3797949
|
@ -102,6 +102,15 @@ void vCreateAltBlockTimeTasks( void )
|
||||||
/* Create the queue on which the two tasks block. */
|
/* Create the queue on which the two tasks block. */
|
||||||
xTestQueue = xQueueCreate( bktQUEUE_LENGTH, sizeof( portBASE_TYPE ) );
|
xTestQueue = xQueueCreate( bktQUEUE_LENGTH, sizeof( portBASE_TYPE ) );
|
||||||
|
|
||||||
|
/* 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, ( signed portCHAR * ) "AltBlockQueue" );
|
||||||
|
|
||||||
|
|
||||||
/* Create the two test tasks. */
|
/* Create the two test tasks. */
|
||||||
xTaskCreate( vPrimaryBlockTimeTestTask, ( signed portCHAR * )"FBTest1", configMINIMAL_STACK_SIZE, NULL, bktPRIMARY_PRIORITY, NULL );
|
xTaskCreate( vPrimaryBlockTimeTestTask, ( signed portCHAR * )"FBTest1", configMINIMAL_STACK_SIZE, NULL, bktPRIMARY_PRIORITY, NULL );
|
||||||
xTaskCreate( vSecondaryBlockTimeTestTask, ( signed portCHAR * )"FBTest2", configMINIMAL_STACK_SIZE, NULL, bktSECONDARY_PRIORITY, &xSecondary );
|
xTaskCreate( vSecondaryBlockTimeTestTask, ( signed portCHAR * )"FBTest2", configMINIMAL_STACK_SIZE, NULL, bktSECONDARY_PRIORITY, &xSecondary );
|
||||||
|
|
|
@ -112,6 +112,15 @@ static xQueueHandle xPolledQueue;
|
||||||
/* Create the queue used by the producer and consumer. */
|
/* Create the queue used by the producer and consumer. */
|
||||||
xPolledQueue = xQueueCreate( pollqQUEUE_SIZE, ( unsigned portBASE_TYPE ) sizeof( unsigned portSHORT ) );
|
xPolledQueue = xQueueCreate( pollqQUEUE_SIZE, ( unsigned portBASE_TYPE ) sizeof( unsigned portSHORT ) );
|
||||||
|
|
||||||
|
/* 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, ( signed portCHAR * ) "AltPollQueue" );
|
||||||
|
|
||||||
|
|
||||||
/* Spawn the producer and consumer. */
|
/* Spawn the producer and consumer. */
|
||||||
xTaskCreate( vPolledQueueConsumer, ( signed portCHAR * ) "QConsNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, ( xTaskHandle * ) NULL );
|
xTaskCreate( vPolledQueueConsumer, ( signed portCHAR * ) "QConsNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, ( xTaskHandle * ) NULL );
|
||||||
xTaskCreate( vPolledQueueProducer, ( signed portCHAR * ) "QProdNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, ( xTaskHandle * ) NULL );
|
xTaskCreate( vPolledQueueProducer, ( signed portCHAR * ) "QProdNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, ( xTaskHandle * ) NULL );
|
||||||
|
|
|
@ -132,6 +132,14 @@ xSemaphoreHandle xMutex;
|
||||||
prvSendFrontAndBackTest demo. */
|
prvSendFrontAndBackTest demo. */
|
||||||
xQueue = xQueueCreate( genqQUEUE_LENGTH, sizeof( unsigned portLONG ) );
|
xQueue = xQueueCreate( genqQUEUE_LENGTH, sizeof( unsigned portLONG ) );
|
||||||
|
|
||||||
|
/* 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, ( signed portCHAR * ) "Alt_Gen_Test_Queue" );
|
||||||
|
|
||||||
/* Create the demo task and pass it the queue just created. We are
|
/* Create the demo task and pass it the queue just created. We are
|
||||||
passing the queue handle by value so it does not matter that it is
|
passing the queue handle by value so it does not matter that it is
|
||||||
declared on the stack here. */
|
declared on the stack here. */
|
||||||
|
@ -140,6 +148,14 @@ xSemaphoreHandle xMutex;
|
||||||
/* Create the mutex used by the prvMutexTest task. */
|
/* Create the mutex used by the prvMutexTest task. */
|
||||||
xMutex = xSemaphoreCreateMutex();
|
xMutex = xSemaphoreCreateMutex();
|
||||||
|
|
||||||
|
/* 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( ( xQueueHandle ) xMutex, ( signed portCHAR * ) "Alt_Q_Mutex" );
|
||||||
|
|
||||||
/* Create the mutex demo tasks and pass it the mutex just created. We are
|
/* Create the mutex demo tasks and pass it the mutex just created. We are
|
||||||
passing the mutex handle by value so it does not matter that it is declared
|
passing the mutex handle by value so it does not matter that it is declared
|
||||||
on the stack here. */
|
on the stack here. */
|
||||||
|
|
|
@ -134,6 +134,14 @@ xSemaphoreHandle xMutex;
|
||||||
prvSendFrontAndBackTest demo. */
|
prvSendFrontAndBackTest demo. */
|
||||||
xQueue = xQueueCreate( genqQUEUE_LENGTH, sizeof( unsigned portLONG ) );
|
xQueue = xQueueCreate( genqQUEUE_LENGTH, sizeof( unsigned portLONG ) );
|
||||||
|
|
||||||
|
/* 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, ( signed portCHAR * ) "Gen_Queue_Test" );
|
||||||
|
|
||||||
/* Create the demo task and pass it the queue just created. We are
|
/* Create the demo task and pass it the queue just created. We are
|
||||||
passing the queue handle by value so it does not matter that it is
|
passing the queue handle by value so it does not matter that it is
|
||||||
declared on the stack here. */
|
declared on the stack here. */
|
||||||
|
@ -142,6 +150,14 @@ xSemaphoreHandle xMutex;
|
||||||
/* Create the mutex used by the prvMutexTest task. */
|
/* Create the mutex used by the prvMutexTest task. */
|
||||||
xMutex = xSemaphoreCreateMutex();
|
xMutex = xSemaphoreCreateMutex();
|
||||||
|
|
||||||
|
/* vQueueAddToRegistry() adds the mutex to the registry, if one is
|
||||||
|
in use. The registry is provided as a means for kernel aware
|
||||||
|
debuggers to locate mutexes and has no purpose if a kernel aware debugger
|
||||||
|
is not being used. The call to vQueueAddToRegistry() will be removed
|
||||||
|
by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is
|
||||||
|
defined to be less than 1. */
|
||||||
|
vQueueAddToRegistry( ( xQueueHandle ) xMutex, ( signed portCHAR * ) "Gen_Queue_Mutex" );
|
||||||
|
|
||||||
/* Create the mutex demo tasks and pass it the mutex just created. We are
|
/* Create the mutex demo tasks and pass it the mutex just created. We are
|
||||||
passing the mutex handle by value so it does not matter that it is declared
|
passing the mutex handle by value so it does not matter that it is declared
|
||||||
on the stack here. */
|
on the stack here. */
|
||||||
|
|
|
@ -218,6 +218,16 @@ void vStartInterruptQueueTasks( void )
|
||||||
interrupts. */
|
interrupts. */
|
||||||
xNormallyFullQueue = xQueueCreate( intqQUEUE_LENGTH, ( unsigned portBASE_TYPE ) sizeof( unsigned portBASE_TYPE ) );
|
xNormallyFullQueue = xQueueCreate( intqQUEUE_LENGTH, ( unsigned portBASE_TYPE ) sizeof( unsigned portBASE_TYPE ) );
|
||||||
xNormallyEmptyQueue = xQueueCreate( intqQUEUE_LENGTH, ( unsigned portBASE_TYPE ) sizeof( unsigned portBASE_TYPE ) );
|
xNormallyEmptyQueue = xQueueCreate( intqQUEUE_LENGTH, ( unsigned portBASE_TYPE ) sizeof( unsigned portBASE_TYPE ) );
|
||||||
|
|
||||||
|
/* 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( xNormallyFullQueue, ( signed portCHAR * ) "NormallyFull" );
|
||||||
|
vQueueAddToRegistry( xNormallyEmptyQueue, ( signed portCHAR * ) "NormallyEmpty" );
|
||||||
|
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
|
@ -114,6 +114,14 @@ static xQueueHandle xPolledQueue;
|
||||||
/* Create the queue used by the producer and consumer. */
|
/* Create the queue used by the producer and consumer. */
|
||||||
xPolledQueue = xQueueCreate( pollqQUEUE_SIZE, ( unsigned portBASE_TYPE ) sizeof( unsigned portSHORT ) );
|
xPolledQueue = xQueueCreate( pollqQUEUE_SIZE, ( unsigned portBASE_TYPE ) sizeof( unsigned portSHORT ) );
|
||||||
|
|
||||||
|
/* 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, ( signed portCHAR * ) "Poll_Test_Queue" );
|
||||||
|
|
||||||
/* Spawn the producer and consumer. */
|
/* Spawn the producer and consumer. */
|
||||||
xTaskCreate( vPolledQueueConsumer, ( signed portCHAR * ) "QConsNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, ( xTaskHandle * ) NULL );
|
xTaskCreate( vPolledQueueConsumer, ( signed portCHAR * ) "QConsNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, ( xTaskHandle * ) NULL );
|
||||||
xTaskCreate( vPolledQueueProducer, ( signed portCHAR * ) "QProdNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, ( xTaskHandle * ) NULL );
|
xTaskCreate( vPolledQueueProducer, ( signed portCHAR * ) "QProdNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, ( xTaskHandle * ) NULL );
|
||||||
|
|
|
@ -1,434 +1,442 @@
|
||||||
/*
|
/*
|
||||||
FreeRTOS.org V5.0.0 - Copyright (C) 2003-2008 Richard Barry.
|
FreeRTOS.org V5.0.0 - Copyright (C) 2003-2008 Richard Barry.
|
||||||
|
|
||||||
This file is part of the FreeRTOS.org distribution.
|
This file is part of the FreeRTOS.org distribution.
|
||||||
|
|
||||||
FreeRTOS.org is free software; you can redistribute it and/or modify
|
FreeRTOS.org is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
FreeRTOS.org is distributed in the hope that it will be useful,
|
FreeRTOS.org is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with FreeRTOS.org; if not, write to the Free Software
|
along with FreeRTOS.org; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
A special exception to the GPL can be applied should you wish to distribute
|
A special exception to the GPL can be applied should you wish to distribute
|
||||||
a combined work that includes FreeRTOS.org, without being obliged to provide
|
a combined work that includes FreeRTOS.org, without being obliged to provide
|
||||||
the source code for any proprietary components. See the licensing section
|
the source code for any proprietary components. See the licensing section
|
||||||
of http://www.FreeRTOS.org for full details of how and when the exception
|
of http://www.FreeRTOS.org for full details of how and when the exception
|
||||||
can be applied.
|
can be applied.
|
||||||
|
|
||||||
***************************************************************************
|
***************************************************************************
|
||||||
***************************************************************************
|
***************************************************************************
|
||||||
* *
|
* *
|
||||||
* SAVE TIME AND MONEY! We can port FreeRTOS.org to your own hardware, *
|
* SAVE TIME AND MONEY! We can port FreeRTOS.org to your own hardware, *
|
||||||
* and even write all or part of your application on your behalf. *
|
* and even write all or part of your application on your behalf. *
|
||||||
* See http://www.OpenRTOS.com for details of the services we provide to *
|
* See http://www.OpenRTOS.com for details of the services we provide to *
|
||||||
* expedite your project. *
|
* expedite your project. *
|
||||||
* *
|
* *
|
||||||
***************************************************************************
|
***************************************************************************
|
||||||
***************************************************************************
|
***************************************************************************
|
||||||
|
|
||||||
Please ensure to read the configuration and relevant port sections of the
|
Please ensure to read the configuration and relevant port sections of the
|
||||||
online documentation.
|
online documentation.
|
||||||
|
|
||||||
http://www.FreeRTOS.org - Documentation, latest information, license and
|
http://www.FreeRTOS.org - Documentation, latest information, license and
|
||||||
contact details.
|
contact details.
|
||||||
|
|
||||||
http://www.SafeRTOS.com - A version that is certified for use in safety
|
http://www.SafeRTOS.com - A version that is certified for use in safety
|
||||||
critical systems.
|
critical systems.
|
||||||
|
|
||||||
http://www.OpenRTOS.com - Commercial support, development, porting,
|
http://www.OpenRTOS.com - Commercial support, development, porting,
|
||||||
licensing and training services.
|
licensing and training services.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Tests the behaviour when data is peeked from a queue when there are
|
* Tests the behaviour when data is peeked from a queue when there are
|
||||||
* multiple tasks blocked on the queue.
|
* multiple tasks blocked on the queue.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/* Scheduler include files. */
|
/* Scheduler include files. */
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
#include "semphr.h"
|
#include "semphr.h"
|
||||||
|
|
||||||
/* Demo program include files. */
|
/* Demo program include files. */
|
||||||
#include "QPeek.h"
|
#include "QPeek.h"
|
||||||
|
|
||||||
#define qpeekQUEUE_LENGTH ( 5 )
|
#define qpeekQUEUE_LENGTH ( 5 )
|
||||||
#define qpeekNO_BLOCK ( 0 )
|
#define qpeekNO_BLOCK ( 0 )
|
||||||
#define qpeekSHORT_DELAY ( 10 )
|
#define qpeekSHORT_DELAY ( 10 )
|
||||||
|
|
||||||
#define qpeekLOW_PRIORITY ( tskIDLE_PRIORITY + 0 )
|
#define qpeekLOW_PRIORITY ( tskIDLE_PRIORITY + 0 )
|
||||||
#define qpeekMEDIUM_PRIORITY ( tskIDLE_PRIORITY + 1 )
|
#define qpeekMEDIUM_PRIORITY ( tskIDLE_PRIORITY + 1 )
|
||||||
#define qpeekHIGH_PRIORITY ( tskIDLE_PRIORITY + 2 )
|
#define qpeekHIGH_PRIORITY ( tskIDLE_PRIORITY + 2 )
|
||||||
#define qpeekHIGHEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
|
#define qpeekHIGHEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The following three tasks are used to demonstrate the peeking behaviour.
|
* The following three tasks are used to demonstrate the peeking behaviour.
|
||||||
* Each task is given a different priority to demonstrate the order in which
|
* Each task is given a different priority to demonstrate the order in which
|
||||||
* tasks are woken as data is peeked from a queue.
|
* tasks are woken as data is peeked from a queue.
|
||||||
*/
|
*/
|
||||||
static void prvLowPriorityPeekTask( void *pvParameters );
|
static void prvLowPriorityPeekTask( void *pvParameters );
|
||||||
static void prvMediumPriorityPeekTask( void *pvParameters );
|
static void prvMediumPriorityPeekTask( void *pvParameters );
|
||||||
static void prvHighPriorityPeekTask( void *pvParameters );
|
static void prvHighPriorityPeekTask( void *pvParameters );
|
||||||
static void prvHighestPriorityPeekTask( void *pvParameters );
|
static void prvHighestPriorityPeekTask( void *pvParameters );
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/* Flag that will be latched to pdTRUE should any unexpected behaviour be
|
/* 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 portBASE_TYPE xErrorDetected = pdFALSE;
|
static volatile portBASE_TYPE xErrorDetected = pdFALSE;
|
||||||
|
|
||||||
/* Counter that is incremented on each cycle of a test. This is used to
|
/* 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 unsigned portLONG ulLoopCounter = 0;
|
static volatile unsigned portLONG ulLoopCounter = 0;
|
||||||
|
|
||||||
/* Handles to the test tasks. */
|
/* Handles to the test tasks. */
|
||||||
xTaskHandle xMediumPriorityTask, xHighPriorityTask, xHighestPriorityTask;
|
xTaskHandle xMediumPriorityTask, xHighPriorityTask, xHighestPriorityTask;
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void vStartQueuePeekTasks( void )
|
void vStartQueuePeekTasks( void )
|
||||||
{
|
{
|
||||||
xQueueHandle xQueue;
|
xQueueHandle xQueue;
|
||||||
|
|
||||||
/* Create the queue that we are going to use for the test/demo. */
|
/* Create the queue that we are going to use for the test/demo. */
|
||||||
xQueue = xQueueCreate( qpeekQUEUE_LENGTH, sizeof( unsigned portLONG ) );
|
xQueue = xQueueCreate( qpeekQUEUE_LENGTH, sizeof( unsigned portLONG ) );
|
||||||
|
|
||||||
/* Create the demo tasks and pass it the queue just created. We are
|
/* vQueueAddToRegistry() adds the queue to the queue registry, if one is
|
||||||
passing the queue handle by value so it does not matter that it is declared
|
in use. The queue registry is provided as a means for kernel aware
|
||||||
on the stack here. */
|
debuggers to locate queues and has no purpose if a kernel aware debugger
|
||||||
xTaskCreate( prvLowPriorityPeekTask, ( signed portCHAR * )"PeekL", configMINIMAL_STACK_SIZE, ( void * ) xQueue, qpeekLOW_PRIORITY, NULL );
|
is not being used. The call to vQueueAddToRegistry() will be removed
|
||||||
xTaskCreate( prvMediumPriorityPeekTask, ( signed portCHAR * )"PeekM", configMINIMAL_STACK_SIZE, ( void * ) xQueue, qpeekMEDIUM_PRIORITY, &xMediumPriorityTask );
|
by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is
|
||||||
xTaskCreate( prvHighPriorityPeekTask, ( signed portCHAR * )"PeekH1", configMINIMAL_STACK_SIZE, ( void * ) xQueue, qpeekHIGH_PRIORITY, &xHighPriorityTask );
|
defined to be less than 1. */
|
||||||
xTaskCreate( prvHighestPriorityPeekTask, ( signed portCHAR * )"PeekH2", configMINIMAL_STACK_SIZE, ( void * ) xQueue, qpeekHIGHEST_PRIORITY, &xHighestPriorityTask );
|
vQueueAddToRegistry( xQueue, ( signed portCHAR * ) "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
|
||||||
static void prvHighestPriorityPeekTask( void *pvParameters )
|
on the stack here. */
|
||||||
{
|
xTaskCreate( prvLowPriorityPeekTask, ( signed portCHAR * )"PeekL", configMINIMAL_STACK_SIZE, ( void * ) xQueue, qpeekLOW_PRIORITY, NULL );
|
||||||
xQueueHandle xQueue = ( xQueueHandle ) pvParameters;
|
xTaskCreate( prvMediumPriorityPeekTask, ( signed portCHAR * )"PeekM", configMINIMAL_STACK_SIZE, ( void * ) xQueue, qpeekMEDIUM_PRIORITY, &xMediumPriorityTask );
|
||||||
unsigned portLONG ulValue;
|
xTaskCreate( prvHighPriorityPeekTask, ( signed portCHAR * )"PeekH1", configMINIMAL_STACK_SIZE, ( void * ) xQueue, qpeekHIGH_PRIORITY, &xHighPriorityTask );
|
||||||
|
xTaskCreate( prvHighestPriorityPeekTask, ( signed portCHAR * )"PeekH2", configMINIMAL_STACK_SIZE, ( void * ) xQueue, qpeekHIGHEST_PRIORITY, &xHighestPriorityTask );
|
||||||
#ifdef USE_STDIO
|
}
|
||||||
{
|
/*-----------------------------------------------------------*/
|
||||||
void vPrintDisplayMessage( const portCHAR * const * ppcMessageToSend );
|
|
||||||
|
static void prvHighestPriorityPeekTask( void *pvParameters )
|
||||||
const portCHAR * const pcTaskStartMsg = "Queue peek test started.\r\n";
|
{
|
||||||
|
xQueueHandle xQueue = ( xQueueHandle ) pvParameters;
|
||||||
/* Queue a message for printing to say the task has started. */
|
unsigned portLONG ulValue;
|
||||||
vPrintDisplayMessage( &pcTaskStartMsg );
|
|
||||||
}
|
#ifdef USE_STDIO
|
||||||
#endif
|
{
|
||||||
|
void vPrintDisplayMessage( const portCHAR * const * ppcMessageToSend );
|
||||||
for( ;; )
|
|
||||||
{
|
const portCHAR * const pcTaskStartMsg = "Queue peek test started.\r\n";
|
||||||
/* Try peeking from the queue. The queue should be empty so we will
|
|
||||||
block, allowing the high priority task to execute. */
|
/* Queue a message for printing to say the task has started. */
|
||||||
if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
|
vPrintDisplayMessage( &pcTaskStartMsg );
|
||||||
{
|
}
|
||||||
/* We expected to have received something by the time we unblock. */
|
#endif
|
||||||
xErrorDetected = pdTRUE;
|
|
||||||
}
|
for( ;; )
|
||||||
|
{
|
||||||
/* When we reach here the high and medium priority tasks should still
|
/* Try peeking from the queue. The queue should be empty so we will
|
||||||
be blocked on the queue. We unblocked because the low priority task
|
block, allowing the high priority task to execute. */
|
||||||
wrote a value to the queue, which we should have peeked. Peeking the
|
if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
|
||||||
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
|
/* We expected to have received something by the time we unblock. */
|
||||||
yet executed. */
|
xErrorDetected = pdTRUE;
|
||||||
if( ulValue != 0x11223344 )
|
}
|
||||||
{
|
|
||||||
/* We did not receive the expected value. */
|
/* When we reach here the high and medium priority tasks should still
|
||||||
xErrorDetected = pdTRUE;
|
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
|
||||||
if( uxQueueMessagesWaiting( xQueue ) != 1 )
|
the high priority task should then have also been unblocked, but not
|
||||||
{
|
yet executed. */
|
||||||
/* The message should have been left on the queue. */
|
if( ulValue != 0x11223344 )
|
||||||
xErrorDetected = pdTRUE;
|
{
|
||||||
}
|
/* We did not receive the expected 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. */
|
if( uxQueueMessagesWaiting( xQueue ) != 1 )
|
||||||
ulValue = 0;
|
{
|
||||||
if( xQueueReceive( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
|
/* The message should have been left on the queue. */
|
||||||
{
|
xErrorDetected = pdTRUE;
|
||||||
/* 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
|
||||||
if( ulValue != 0x11223344 )
|
blocked state. */
|
||||||
{
|
ulValue = 0;
|
||||||
/* We did not receive the expected value - which should have been
|
if( xQueueReceive( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
|
||||||
the same value as was peeked. */
|
{
|
||||||
xErrorDetected = pdTRUE;
|
/* 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( ulValue != 0x11223344 )
|
||||||
if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
|
{
|
||||||
{
|
/* We did not receive the expected value - which should have been
|
||||||
/* We expected to have received something by the time we unblock. */
|
the same value as was peeked. */
|
||||||
xErrorDetected = pdTRUE;
|
xErrorDetected = pdTRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* When we get here the low priority task should have again written to the
|
/* Now we will block again as the queue is once more empty. The low
|
||||||
queue. */
|
priority task can then execute again. */
|
||||||
if( ulValue != 0x01234567 )
|
if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
|
||||||
{
|
{
|
||||||
/* We did not receive the expected value. */
|
/* We expected to have received something by the time we unblock. */
|
||||||
xErrorDetected = pdTRUE;
|
xErrorDetected = pdTRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( uxQueueMessagesWaiting( xQueue ) != 1 )
|
/* When we get here the low priority task should have again written to the
|
||||||
{
|
queue. */
|
||||||
/* The message should have been left on the queue. */
|
if( ulValue != 0x01234567 )
|
||||||
xErrorDetected = pdTRUE;
|
{
|
||||||
}
|
/* 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
|
if( uxQueueMessagesWaiting( xQueue ) != 1 )
|
||||||
in the queue. */
|
{
|
||||||
vTaskSuspend( NULL );
|
/* The message should have been left on the queue. */
|
||||||
|
xErrorDetected = pdTRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/* This time we are going to do the same as the above test, but the
|
/* We only peeked the data, so suspending ourselves now should enable
|
||||||
high priority task is going to receive the data, rather than peek it.
|
the high priority task to also peek the data. The high priority task
|
||||||
This means that the medium priority task should never peek the value. */
|
will have been unblocked when we peeked the data as we left the data
|
||||||
if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
|
in the queue. */
|
||||||
{
|
vTaskSuspend( NULL );
|
||||||
xErrorDetected = pdTRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( ulValue != 0xaabbaabb )
|
/* 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.
|
||||||
xErrorDetected = pdTRUE;
|
This means that the medium priority task should never peek the value. */
|
||||||
}
|
if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
|
||||||
|
{
|
||||||
vTaskSuspend( NULL );
|
xErrorDetected = pdTRUE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
/*-----------------------------------------------------------*/
|
if( ulValue != 0xaabbaabb )
|
||||||
|
{
|
||||||
static void prvHighPriorityPeekTask( void *pvParameters )
|
xErrorDetected = pdTRUE;
|
||||||
{
|
}
|
||||||
xQueueHandle xQueue = ( xQueueHandle ) pvParameters;
|
|
||||||
unsigned portLONG ulValue;
|
vTaskSuspend( NULL );
|
||||||
|
}
|
||||||
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
|
static void prvHighPriorityPeekTask( void *pvParameters )
|
||||||
and highest priority tasks will then be blocked on the queue. */
|
{
|
||||||
if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
|
xQueueHandle xQueue = ( xQueueHandle ) pvParameters;
|
||||||
{
|
unsigned portLONG ulValue;
|
||||||
/* 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
|
||||||
/* When we get here the highest priority task should have peeked the data
|
block, allowing the medium priority task to execute. Both the high
|
||||||
(unblocking this task) then suspended (allowing this task to also peek
|
and highest priority tasks will then be blocked on the queue. */
|
||||||
the data). */
|
if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
|
||||||
if( ulValue != 0x01234567 )
|
{
|
||||||
{
|
/* We expected to have received something by the time we unblock. */
|
||||||
/* We did not receive the expected value. */
|
xErrorDetected = pdTRUE;
|
||||||
xErrorDetected = pdTRUE;
|
}
|
||||||
}
|
|
||||||
|
/* When we get here the highest priority task should have peeked the data
|
||||||
if( uxQueueMessagesWaiting( xQueue ) != 1 )
|
(unblocking this task) then suspended (allowing this task to also peek
|
||||||
{
|
the data). */
|
||||||
/* The message should have been left on the queue. */
|
if( ulValue != 0x01234567 )
|
||||||
xErrorDetected = pdTRUE;
|
{
|
||||||
}
|
/* We did not receive the expected value. */
|
||||||
|
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
|
if( uxQueueMessagesWaiting( xQueue ) != 1 )
|
||||||
in the queue. */
|
{
|
||||||
vTaskSuspend( NULL );
|
/* The message should have been left on the queue. */
|
||||||
|
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. */
|
/* We only peeked the data, so suspending ourselves now should enable
|
||||||
if( xQueueReceive( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
|
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
|
||||||
xErrorDetected = pdTRUE;
|
in the queue. */
|
||||||
}
|
vTaskSuspend( NULL );
|
||||||
|
|
||||||
if( ulValue != 0xaabbaabb )
|
|
||||||
{
|
/* This time we are going actually receive the value, so the medium
|
||||||
xErrorDetected = pdTRUE;
|
priority task will never peek the data - we removed it from the queue. */
|
||||||
}
|
if( xQueueReceive( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
|
||||||
|
{
|
||||||
vTaskSuspend( NULL );
|
xErrorDetected = pdTRUE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
/*-----------------------------------------------------------*/
|
if( ulValue != 0xaabbaabb )
|
||||||
|
{
|
||||||
static void prvMediumPriorityPeekTask( void *pvParameters )
|
xErrorDetected = pdTRUE;
|
||||||
{
|
}
|
||||||
xQueueHandle xQueue = ( xQueueHandle ) pvParameters;
|
|
||||||
unsigned portLONG ulValue;
|
vTaskSuspend( NULL );
|
||||||
|
}
|
||||||
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
|
static void prvMediumPriorityPeekTask( void *pvParameters )
|
||||||
and medium priority tasks will then all be blocked on the queue. */
|
{
|
||||||
if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
|
xQueueHandle xQueue = ( xQueueHandle ) pvParameters;
|
||||||
{
|
unsigned portLONG ulValue;
|
||||||
/* 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
|
||||||
/* When we get here the high priority task should have peeked the data
|
block, allowing the low priority task to execute. The highest, high
|
||||||
(unblocking this task) then suspended (allowing this task to also peek
|
and medium priority tasks will then all be blocked on the queue. */
|
||||||
the data). */
|
if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
|
||||||
if( ulValue != 0x01234567 )
|
{
|
||||||
{
|
/* We expected to have received something by the time we unblock. */
|
||||||
/* We did not receive the expected value. */
|
xErrorDetected = pdTRUE;
|
||||||
xErrorDetected = pdTRUE;
|
}
|
||||||
}
|
|
||||||
|
/* When we get here the high priority task should have peeked the data
|
||||||
if( uxQueueMessagesWaiting( xQueue ) != 1 )
|
(unblocking this task) then suspended (allowing this task to also peek
|
||||||
{
|
the data). */
|
||||||
/* The message should have been left on the queue. */
|
if( ulValue != 0x01234567 )
|
||||||
xErrorDetected = pdTRUE;
|
{
|
||||||
}
|
/* We did not receive the expected value. */
|
||||||
|
xErrorDetected = pdTRUE;
|
||||||
/* Just so we know the test is still running. */
|
}
|
||||||
ulLoopCounter++;
|
|
||||||
|
if( uxQueueMessagesWaiting( xQueue ) != 1 )
|
||||||
/* Now we can suspend ourselves so the low priority task can execute
|
{
|
||||||
again. */
|
/* The message should have been left on the queue. */
|
||||||
vTaskSuspend( NULL );
|
xErrorDetected = pdTRUE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
/*-----------------------------------------------------------*/
|
/* Just so we know the test is still running. */
|
||||||
|
ulLoopCounter++;
|
||||||
static void prvLowPriorityPeekTask( void *pvParameters )
|
|
||||||
{
|
/* Now we can suspend ourselves so the low priority task can execute
|
||||||
xQueueHandle xQueue = ( xQueueHandle ) pvParameters;
|
again. */
|
||||||
unsigned portLONG ulValue;
|
vTaskSuspend( NULL );
|
||||||
|
}
|
||||||
for( ;; )
|
}
|
||||||
{
|
/*-----------------------------------------------------------*/
|
||||||
/* Write some data to the queue. This should unblock the highest
|
|
||||||
priority task that is waiting to peek data from the queue. */
|
static void prvLowPriorityPeekTask( void *pvParameters )
|
||||||
ulValue = 0x11223344;
|
{
|
||||||
if( xQueueSendToBack( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
|
xQueueHandle xQueue = ( xQueueHandle ) pvParameters;
|
||||||
{
|
unsigned portLONG ulValue;
|
||||||
/* We were expecting the queue to be empty so we should not of
|
|
||||||
had a problem writing to the queue. */
|
for( ;; )
|
||||||
xErrorDetected = pdTRUE;
|
{
|
||||||
}
|
/* Write some data to the queue. This should unblock the highest
|
||||||
|
priority task that is waiting to peek data from the queue. */
|
||||||
/* By the time we get here the data should have been removed from
|
ulValue = 0x11223344;
|
||||||
the queue. */
|
if( xQueueSendToBack( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
|
||||||
if( uxQueueMessagesWaiting( xQueue ) != 0 )
|
{
|
||||||
{
|
/* We were expecting the queue to be empty so we should not of
|
||||||
xErrorDetected = pdTRUE;
|
had a problem writing to the queue. */
|
||||||
}
|
xErrorDetected = pdTRUE;
|
||||||
|
}
|
||||||
/* Write another value to the queue, again waking the highest priority
|
|
||||||
task that is blocked on the queue. */
|
/* By the time we get here the data should have been removed from
|
||||||
ulValue = 0x01234567;
|
the queue. */
|
||||||
if( xQueueSendToBack( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
|
if( uxQueueMessagesWaiting( xQueue ) != 0 )
|
||||||
{
|
{
|
||||||
/* We were expecting the queue to be empty so we should not of
|
xErrorDetected = pdTRUE;
|
||||||
had a problem writing to the queue. */
|
}
|
||||||
xErrorDetected = pdTRUE;
|
|
||||||
}
|
/* Write another value to the queue, again waking the highest priority
|
||||||
|
task that is blocked on the queue. */
|
||||||
/* All the other tasks should now have successfully peeked the data.
|
ulValue = 0x01234567;
|
||||||
The data is still in the queue so we should be able to receive it. */
|
if( xQueueSendToBack( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
|
||||||
ulValue = 0;
|
{
|
||||||
if( xQueueReceive( 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. */
|
||||||
/* We expected to receive the data. */
|
xErrorDetected = pdTRUE;
|
||||||
xErrorDetected = pdTRUE;
|
}
|
||||||
}
|
|
||||||
|
/* All the other tasks should now have successfully peeked the data.
|
||||||
if( ulValue != 0x01234567 )
|
The data is still in the queue so we should be able to receive it. */
|
||||||
{
|
ulValue = 0;
|
||||||
/* We did not receive the expected value. */
|
if( xQueueReceive( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
|
||||||
}
|
{
|
||||||
|
/* We expected to receive the data. */
|
||||||
/* Lets just delay a while as this is an intensive test as we don't
|
xErrorDetected = pdTRUE;
|
||||||
want to starve other tests of processing time. */
|
}
|
||||||
vTaskDelay( qpeekSHORT_DELAY );
|
|
||||||
|
if( ulValue != 0x01234567 )
|
||||||
/* 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
|
/* We did not receive the expected value. */
|
||||||
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. */
|
/* Lets just delay a while as this is an intensive test as we don't
|
||||||
vTaskResume( xMediumPriorityTask );
|
want to starve other tests of processing time. */
|
||||||
vTaskResume( xHighPriorityTask );
|
vTaskDelay( qpeekSHORT_DELAY );
|
||||||
vTaskResume( xHighestPriorityTask );
|
|
||||||
|
/* Unsuspend the other tasks so we can repeat the test - this time
|
||||||
ulValue = 0xaabbaabb;
|
however not all the other tasks will peek the data as the high
|
||||||
if( xQueueSendToFront( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
|
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
|
||||||
/* We were expecting the queue to be empty so we should not of
|
makes no difference to the result. */
|
||||||
had a problem writing to the queue. */
|
vTaskResume( xMediumPriorityTask );
|
||||||
xErrorDetected = pdTRUE;
|
vTaskResume( xHighPriorityTask );
|
||||||
}
|
vTaskResume( xHighestPriorityTask );
|
||||||
|
|
||||||
/* This time we should find that the queue is empty. The high priority
|
ulValue = 0xaabbaabb;
|
||||||
task actually removed the data rather than just peeking it. */
|
if( xQueueSendToFront( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
|
||||||
if( xQueuePeek( xQueue, &ulValue, qpeekNO_BLOCK ) != errQUEUE_EMPTY )
|
{
|
||||||
{
|
/* We were expecting the queue to be empty so we should not of
|
||||||
/* We expected to receive the data. */
|
had a problem writing to the queue. */
|
||||||
xErrorDetected = pdTRUE;
|
xErrorDetected = pdTRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unsuspend the highest and high priority tasks so we can go back
|
/* This time we should find that the queue is empty. The high priority
|
||||||
and repeat the whole thing. The medium priority task should not be
|
task actually removed the data rather than just peeking it. */
|
||||||
suspended as it was not able to peek the data in this last case. */
|
if( xQueuePeek( xQueue, &ulValue, qpeekNO_BLOCK ) != errQUEUE_EMPTY )
|
||||||
vTaskResume( xHighPriorityTask );
|
{
|
||||||
vTaskResume( xHighestPriorityTask );
|
/* We expected to receive the data. */
|
||||||
|
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 );
|
/* 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 );
|
||||||
/* This is called to check that all the created tasks are still running. */
|
|
||||||
portBASE_TYPE xAreQueuePeekTasksStillRunning( void )
|
/* Lets just delay a while as this is an intensive test as we don't
|
||||||
{
|
want to starve other tests of processing time. */
|
||||||
static unsigned portLONG ulLastLoopCounter = 0;
|
vTaskDelay( qpeekSHORT_DELAY );
|
||||||
|
}
|
||||||
/* If the demo task is still running then we expect the loopcounter to
|
}
|
||||||
have incremented since this function was last called. */
|
/*-----------------------------------------------------------*/
|
||||||
if( ulLastLoopCounter == ulLoopCounter )
|
|
||||||
{
|
/* This is called to check that all the created tasks are still running. */
|
||||||
xErrorDetected = pdTRUE;
|
portBASE_TYPE xAreQueuePeekTasksStillRunning( void )
|
||||||
}
|
{
|
||||||
|
static unsigned portLONG ulLastLoopCounter = 0;
|
||||||
ulLastLoopCounter = ulLoopCounter;
|
|
||||||
|
/* If the demo task is still running then we expect the loopcounter to
|
||||||
/* Errors detected in the task itself will have latched xErrorDetected
|
have incremented since this function was last called. */
|
||||||
to true. */
|
if( ulLastLoopCounter == ulLoopCounter )
|
||||||
|
{
|
||||||
return !xErrorDetected;
|
xErrorDetected = pdTRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ulLastLoopCounter = ulLoopCounter;
|
||||||
|
|
||||||
|
/* Errors detected in the task itself will have latched xErrorDetected
|
||||||
|
to true. */
|
||||||
|
|
||||||
|
return !xErrorDetected;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,476 +1,484 @@
|
||||||
/*
|
/*
|
||||||
FreeRTOS.org V5.0.0 - Copyright (C) 2003-2008 Richard Barry.
|
FreeRTOS.org V5.0.0 - Copyright (C) 2003-2008 Richard Barry.
|
||||||
|
|
||||||
This file is part of the FreeRTOS.org distribution.
|
This file is part of the FreeRTOS.org distribution.
|
||||||
|
|
||||||
FreeRTOS.org is free software; you can redistribute it and/or modify
|
FreeRTOS.org is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
FreeRTOS.org is distributed in the hope that it will be useful,
|
FreeRTOS.org is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with FreeRTOS.org; if not, write to the Free Software
|
along with FreeRTOS.org; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
A special exception to the GPL can be applied should you wish to distribute
|
A special exception to the GPL can be applied should you wish to distribute
|
||||||
a combined work that includes FreeRTOS.org, without being obliged to provide
|
a combined work that includes FreeRTOS.org, without being obliged to provide
|
||||||
the source code for any proprietary components. See the licensing section
|
the source code for any proprietary components. See the licensing section
|
||||||
of http://www.FreeRTOS.org for full details of how and when the exception
|
of http://www.FreeRTOS.org for full details of how and when the exception
|
||||||
can be applied.
|
can be applied.
|
||||||
|
|
||||||
***************************************************************************
|
***************************************************************************
|
||||||
***************************************************************************
|
***************************************************************************
|
||||||
* *
|
* *
|
||||||
* SAVE TIME AND MONEY! We can port FreeRTOS.org to your own hardware, *
|
* SAVE TIME AND MONEY! We can port FreeRTOS.org to your own hardware, *
|
||||||
* and even write all or part of your application on your behalf. *
|
* and even write all or part of your application on your behalf. *
|
||||||
* See http://www.OpenRTOS.com for details of the services we provide to *
|
* See http://www.OpenRTOS.com for details of the services we provide to *
|
||||||
* expedite your project. *
|
* expedite your project. *
|
||||||
* *
|
* *
|
||||||
***************************************************************************
|
***************************************************************************
|
||||||
***************************************************************************
|
***************************************************************************
|
||||||
|
|
||||||
Please ensure to read the configuration and relevant port sections of the
|
Please ensure to read the configuration and relevant port sections of the
|
||||||
online documentation.
|
online documentation.
|
||||||
|
|
||||||
http://www.FreeRTOS.org - Documentation, latest information, license and
|
http://www.FreeRTOS.org - Documentation, latest information, license and
|
||||||
contact details.
|
contact details.
|
||||||
|
|
||||||
http://www.SafeRTOS.com - A version that is certified for use in safety
|
http://www.SafeRTOS.com - A version that is certified for use in safety
|
||||||
critical systems.
|
critical systems.
|
||||||
|
|
||||||
http://www.OpenRTOS.com - Commercial support, development, porting,
|
http://www.OpenRTOS.com - Commercial support, development, porting,
|
||||||
licensing and training services.
|
licensing and training services.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file contains some test scenarios that ensure tasks do not exit queue
|
* This file contains some test scenarios that ensure tasks do not exit queue
|
||||||
* send or receive functions prematurely. A description of the tests is
|
* send or receive functions prematurely. A description of the tests is
|
||||||
* included within the code.
|
* included within the code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Kernel includes. */
|
/* Kernel includes. */
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
|
|
||||||
/* Demo includes. */
|
/* Demo includes. */
|
||||||
#include "blocktim.h"
|
#include "blocktim.h"
|
||||||
|
|
||||||
/* Task priorities. */
|
/* Task priorities. */
|
||||||
#define bktPRIMARY_PRIORITY ( 3 )
|
#define bktPRIMARY_PRIORITY ( 3 )
|
||||||
#define bktSECONDARY_PRIORITY ( 2 )
|
#define bktSECONDARY_PRIORITY ( 2 )
|
||||||
|
|
||||||
/* Task behaviour. */
|
/* Task behaviour. */
|
||||||
#define bktQUEUE_LENGTH ( 5 )
|
#define bktQUEUE_LENGTH ( 5 )
|
||||||
#define bktSHORT_WAIT ( ( ( portTickType ) 20 ) / portTICK_RATE_MS )
|
#define bktSHORT_WAIT ( ( ( portTickType ) 20 ) / portTICK_RATE_MS )
|
||||||
#define bktPRIMARY_BLOCK_TIME ( 10 )
|
#define bktPRIMARY_BLOCK_TIME ( 10 )
|
||||||
#define bktALLOWABLE_MARGIN ( 15 )
|
#define bktALLOWABLE_MARGIN ( 15 )
|
||||||
#define bktTIME_TO_BLOCK ( 175 )
|
#define bktTIME_TO_BLOCK ( 175 )
|
||||||
#define bktDONT_BLOCK ( ( portTickType ) 0 )
|
#define bktDONT_BLOCK ( ( portTickType ) 0 )
|
||||||
#define bktRUN_INDICATOR ( ( unsigned portBASE_TYPE ) 0x55 )
|
#define bktRUN_INDICATOR ( ( unsigned portBASE_TYPE ) 0x55 )
|
||||||
|
|
||||||
/* The queue on which the tasks block. */
|
/* The queue on which the tasks block. */
|
||||||
static xQueueHandle xTestQueue;
|
static xQueueHandle xTestQueue;
|
||||||
|
|
||||||
/* Handle to the secondary task is required by the primary task for calls
|
/* Handle to the secondary task is required by the primary task for calls
|
||||||
to vTaskSuspend/Resume(). */
|
to vTaskSuspend/Resume(). */
|
||||||
static xTaskHandle xSecondary;
|
static xTaskHandle xSecondary;
|
||||||
|
|
||||||
/* Used to ensure that tasks are still executing without error. */
|
/* Used to ensure that tasks are still executing without error. */
|
||||||
static volatile portBASE_TYPE xPrimaryCycles = 0, xSecondaryCycles = 0;
|
static volatile portBASE_TYPE xPrimaryCycles = 0, xSecondaryCycles = 0;
|
||||||
static volatile portBASE_TYPE xErrorOccurred = pdFALSE;
|
static volatile portBASE_TYPE xErrorOccurred = pdFALSE;
|
||||||
|
|
||||||
/* Provides a simple mechanism for the primary task to know when the
|
/* Provides a simple mechanism for the primary task to know when the
|
||||||
secondary task has executed. */
|
secondary task has executed. */
|
||||||
static volatile unsigned portBASE_TYPE xRunIndicator;
|
static volatile unsigned portBASE_TYPE xRunIndicator;
|
||||||
|
|
||||||
/* The two test tasks. Their behaviour is commented within the files. */
|
/* The two test tasks. Their behaviour is commented within the files. */
|
||||||
static void vPrimaryBlockTimeTestTask( void *pvParameters );
|
static void vPrimaryBlockTimeTestTask( void *pvParameters );
|
||||||
static void vSecondaryBlockTimeTestTask( void *pvParameters );
|
static void vSecondaryBlockTimeTestTask( void *pvParameters );
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void vCreateBlockTimeTasks( void )
|
void vCreateBlockTimeTasks( void )
|
||||||
{
|
{
|
||||||
/* Create the queue on which the two tasks block. */
|
/* Create the queue on which the two tasks block. */
|
||||||
xTestQueue = xQueueCreate( bktQUEUE_LENGTH, sizeof( portBASE_TYPE ) );
|
xTestQueue = xQueueCreate( bktQUEUE_LENGTH, sizeof( portBASE_TYPE ) );
|
||||||
|
|
||||||
/* Create the two test tasks. */
|
/* vQueueAddToRegistry() adds the queue to the queue registry, if one is
|
||||||
xTaskCreate( vPrimaryBlockTimeTestTask, ( signed portCHAR * )"BTest1", configMINIMAL_STACK_SIZE, NULL, bktPRIMARY_PRIORITY, NULL );
|
in use. The queue registry is provided as a means for kernel aware
|
||||||
xTaskCreate( vSecondaryBlockTimeTestTask, ( signed portCHAR * )"BTest2", configMINIMAL_STACK_SIZE, NULL, bktSECONDARY_PRIORITY, &xSecondary );
|
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. */
|
||||||
static void vPrimaryBlockTimeTestTask( void *pvParameters )
|
vQueueAddToRegistry( xTestQueue, ( signed portCHAR * ) "Block_Time_Queue" );
|
||||||
{
|
|
||||||
portBASE_TYPE xItem, xData;
|
/* Create the two test tasks. */
|
||||||
portTickType xTimeWhenBlocking;
|
xTaskCreate( vPrimaryBlockTimeTestTask, ( signed portCHAR * )"BTest1", configMINIMAL_STACK_SIZE, NULL, bktPRIMARY_PRIORITY, NULL );
|
||||||
portTickType xTimeToBlock, xBlockedTime;
|
xTaskCreate( vSecondaryBlockTimeTestTask, ( signed portCHAR * )"BTest2", configMINIMAL_STACK_SIZE, NULL, bktSECONDARY_PRIORITY, &xSecondary );
|
||||||
|
}
|
||||||
( void ) pvParameters;
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
for( ;; )
|
static void vPrimaryBlockTimeTestTask( void *pvParameters )
|
||||||
{
|
{
|
||||||
/*********************************************************************
|
portBASE_TYPE xItem, xData;
|
||||||
Test 1
|
portTickType xTimeWhenBlocking;
|
||||||
|
portTickType xTimeToBlock, xBlockedTime;
|
||||||
Simple block time wakeup test on queue receives. */
|
|
||||||
for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
|
( void ) pvParameters;
|
||||||
{
|
|
||||||
/* The queue is empty. Attempt to read from the queue using a block
|
for( ;; )
|
||||||
time. When we wake, ensure the delta in time is as expected. */
|
{
|
||||||
xTimeToBlock = bktPRIMARY_BLOCK_TIME << xItem;
|
/*********************************************************************
|
||||||
|
Test 1
|
||||||
xTimeWhenBlocking = xTaskGetTickCount();
|
|
||||||
|
Simple block time wakeup test on queue receives. */
|
||||||
/* We should unblock after xTimeToBlock having not received
|
for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
|
||||||
anything on the queue. */
|
{
|
||||||
if( xQueueReceive( xTestQueue, &xData, xTimeToBlock ) != errQUEUE_EMPTY )
|
/* 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. */
|
||||||
xErrorOccurred = pdTRUE;
|
xTimeToBlock = bktPRIMARY_BLOCK_TIME << xItem;
|
||||||
}
|
|
||||||
|
xTimeWhenBlocking = xTaskGetTickCount();
|
||||||
/* How long were we blocked for? */
|
|
||||||
xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
|
/* We should unblock after xTimeToBlock having not received
|
||||||
|
anything on the queue. */
|
||||||
if( xBlockedTime < xTimeToBlock )
|
if( xQueueReceive( xTestQueue, &xData, xTimeToBlock ) != errQUEUE_EMPTY )
|
||||||
{
|
{
|
||||||
/* Should not have blocked for less than we requested. */
|
xErrorOccurred = pdTRUE;
|
||||||
xErrorOccurred = pdTRUE;
|
}
|
||||||
}
|
|
||||||
|
/* How long were we blocked for? */
|
||||||
if( xBlockedTime > ( xTimeToBlock + bktALLOWABLE_MARGIN ) )
|
xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
|
||||||
{
|
|
||||||
/* Should not have blocked for longer than we requested,
|
if( xBlockedTime < xTimeToBlock )
|
||||||
although we would not necessarily run as soon as we were
|
{
|
||||||
unblocked so a margin is allowed. */
|
/* Should not have blocked for less than we requested. */
|
||||||
xErrorOccurred = pdTRUE;
|
xErrorOccurred = pdTRUE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if( xBlockedTime > ( xTimeToBlock + bktALLOWABLE_MARGIN ) )
|
||||||
/*********************************************************************
|
{
|
||||||
Test 2
|
/* Should not have blocked for longer than we requested,
|
||||||
|
although we would not necessarily run as soon as we were
|
||||||
Simple block time wakeup test on queue sends.
|
unblocked so a margin is allowed. */
|
||||||
|
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 )
|
/*********************************************************************
|
||||||
{
|
Test 2
|
||||||
xErrorOccurred = pdTRUE;
|
|
||||||
}
|
Simple block time wakeup test on queue sends.
|
||||||
|
|
||||||
#if configUSE_PREEMPTION == 0
|
First fill the queue. It should be empty so all sends should pass. */
|
||||||
taskYIELD();
|
for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
|
||||||
#endif
|
{
|
||||||
}
|
if( xQueueSend( xTestQueue, &xItem, bktDONT_BLOCK ) != pdPASS )
|
||||||
|
{
|
||||||
for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
|
xErrorOccurred = pdTRUE;
|
||||||
{
|
}
|
||||||
/* 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. */
|
#if configUSE_PREEMPTION == 0
|
||||||
xTimeToBlock = bktPRIMARY_BLOCK_TIME << xItem;
|
taskYIELD();
|
||||||
|
#endif
|
||||||
xTimeWhenBlocking = xTaskGetTickCount();
|
}
|
||||||
|
|
||||||
/* We should unblock after xTimeToBlock having not received
|
for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
|
||||||
anything on the queue. */
|
{
|
||||||
if( xQueueSend( xTestQueue, &xItem, xTimeToBlock ) != errQUEUE_FULL )
|
/* 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. */
|
||||||
xErrorOccurred = pdTRUE;
|
xTimeToBlock = bktPRIMARY_BLOCK_TIME << xItem;
|
||||||
}
|
|
||||||
|
xTimeWhenBlocking = xTaskGetTickCount();
|
||||||
/* How long were we blocked for? */
|
|
||||||
xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
|
/* We should unblock after xTimeToBlock having not received
|
||||||
|
anything on the queue. */
|
||||||
if( xBlockedTime < xTimeToBlock )
|
if( xQueueSend( xTestQueue, &xItem, xTimeToBlock ) != errQUEUE_FULL )
|
||||||
{
|
{
|
||||||
/* Should not have blocked for less than we requested. */
|
xErrorOccurred = pdTRUE;
|
||||||
xErrorOccurred = pdTRUE;
|
}
|
||||||
}
|
|
||||||
|
/* How long were we blocked for? */
|
||||||
if( xBlockedTime > ( xTimeToBlock + bktALLOWABLE_MARGIN ) )
|
xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
|
||||||
{
|
|
||||||
/* Should not have blocked for longer than we requested,
|
if( xBlockedTime < xTimeToBlock )
|
||||||
although we would not necessarily run as soon as we were
|
{
|
||||||
unblocked so a margin is allowed. */
|
/* Should not have blocked for less than we requested. */
|
||||||
xErrorOccurred = pdTRUE;
|
xErrorOccurred = pdTRUE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if( xBlockedTime > ( xTimeToBlock + bktALLOWABLE_MARGIN ) )
|
||||||
/*********************************************************************
|
{
|
||||||
Test 3
|
/* Should not have blocked for longer than we requested,
|
||||||
|
although we would not necessarily run as soon as we were
|
||||||
Wake the other task, it will block attempting to post to the queue.
|
unblocked so a margin is allowed. */
|
||||||
When we read from the queue the other task will wake, but before it
|
xErrorOccurred = pdTRUE;
|
||||||
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.
|
/*********************************************************************
|
||||||
|
Test 3
|
||||||
Wake the other task so it blocks attempting to post to the already
|
|
||||||
full queue. */
|
Wake the other task, it will block attempting to post to the queue.
|
||||||
xRunIndicator = 0;
|
When we read from the queue the other task will wake, but before it
|
||||||
vTaskResume( xSecondary );
|
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
|
||||||
/* We need to wait a little to ensure the other task executes. */
|
recognise that its block time has not expired and return to block for
|
||||||
while( xRunIndicator != bktRUN_INDICATOR )
|
the remains of its block time.
|
||||||
{
|
|
||||||
/* The other task has not yet executed. */
|
Wake the other task so it blocks attempting to post to the already
|
||||||
vTaskDelay( bktSHORT_WAIT );
|
full queue. */
|
||||||
}
|
xRunIndicator = 0;
|
||||||
/* Make sure the other task is blocked on the queue. */
|
vTaskResume( xSecondary );
|
||||||
vTaskDelay( bktSHORT_WAIT );
|
|
||||||
xRunIndicator = 0;
|
/* We need to wait a little to ensure the other task executes. */
|
||||||
|
while( xRunIndicator != bktRUN_INDICATOR )
|
||||||
for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
|
{
|
||||||
{
|
/* The other task has not yet executed. */
|
||||||
/* Now when we make space on the queue the other task should wake
|
vTaskDelay( bktSHORT_WAIT );
|
||||||
but not execute as this task has higher priority. */
|
}
|
||||||
if( xQueueReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )
|
/* Make sure the other task is blocked on the queue. */
|
||||||
{
|
vTaskDelay( bktSHORT_WAIT );
|
||||||
xErrorOccurred = pdTRUE;
|
xRunIndicator = 0;
|
||||||
}
|
|
||||||
|
for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
|
||||||
/* 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
|
/* Now when we make space on the queue the other task should wake
|
||||||
full ourselves, and the other task have set xRunIndicator. */
|
but not execute as this task has higher priority. */
|
||||||
if( xQueueSend( xTestQueue, &xItem, bktDONT_BLOCK ) != pdPASS )
|
if( xQueueReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )
|
||||||
{
|
{
|
||||||
xErrorOccurred = pdTRUE;
|
xErrorOccurred = pdTRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( xRunIndicator == bktRUN_INDICATOR )
|
/* 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
|
||||||
/* The other task should not have executed. */
|
full ourselves, and the other task have set xRunIndicator. */
|
||||||
xErrorOccurred = pdTRUE;
|
if( xQueueSend( xTestQueue, &xItem, 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 );
|
if( xRunIndicator == bktRUN_INDICATOR )
|
||||||
|
{
|
||||||
/* The other task should now have re-blocked without exiting the
|
/* The other task should not have executed. */
|
||||||
queue function. */
|
xErrorOccurred = pdTRUE;
|
||||||
if( xRunIndicator == bktRUN_INDICATOR )
|
}
|
||||||
{
|
|
||||||
/* The other task should not have executed outside of the
|
/* Raise the priority of the other task so it executes and blocks
|
||||||
queue function. */
|
on the queue again. */
|
||||||
xErrorOccurred = pdTRUE;
|
vTaskPrioritySet( xSecondary, bktPRIMARY_PRIORITY + 2 );
|
||||||
}
|
|
||||||
|
/* The other task should now have re-blocked without exiting the
|
||||||
/* Set the priority back down. */
|
queue function. */
|
||||||
vTaskPrioritySet( xSecondary, bktSECONDARY_PRIORITY );
|
if( xRunIndicator == bktRUN_INDICATOR )
|
||||||
}
|
{
|
||||||
|
/* The other task should not have executed outside of the
|
||||||
/* Let the other task timeout. When it unblockes it will check that it
|
queue function. */
|
||||||
unblocked at the correct time, then suspend itself. */
|
xErrorOccurred = pdTRUE;
|
||||||
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 )
|
||||||
Test 4
|
{
|
||||||
|
vTaskDelay( bktSHORT_WAIT );
|
||||||
As per test 3 - but with the send and receive the other way around.
|
}
|
||||||
The other task blocks attempting to read from the queue.
|
vTaskDelay( bktSHORT_WAIT );
|
||||||
|
xRunIndicator = 0;
|
||||||
Empty the queue. We should find that it is full. */
|
|
||||||
for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
|
|
||||||
{
|
/*********************************************************************
|
||||||
if( xQueueReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )
|
Test 4
|
||||||
{
|
|
||||||
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.
|
||||||
}
|
|
||||||
|
Empty the queue. We should find that it is full. */
|
||||||
/* Wake the other task so it blocks attempting to read from the
|
for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
|
||||||
already empty queue. */
|
{
|
||||||
vTaskResume( xSecondary );
|
if( xQueueReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )
|
||||||
|
{
|
||||||
/* We need to wait a little to ensure the other task executes. */
|
xErrorOccurred = pdTRUE;
|
||||||
while( xRunIndicator != bktRUN_INDICATOR )
|
}
|
||||||
{
|
}
|
||||||
vTaskDelay( bktSHORT_WAIT );
|
|
||||||
}
|
/* Wake the other task so it blocks attempting to read from the
|
||||||
vTaskDelay( bktSHORT_WAIT );
|
already empty queue. */
|
||||||
xRunIndicator = 0;
|
vTaskResume( xSecondary );
|
||||||
|
|
||||||
for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
|
/* We need to wait a little to ensure the other task executes. */
|
||||||
{
|
while( xRunIndicator != bktRUN_INDICATOR )
|
||||||
/* Now when we place an item on the queue the other task should
|
{
|
||||||
wake but not execute as this task has higher priority. */
|
vTaskDelay( bktSHORT_WAIT );
|
||||||
if( xQueueSend( xTestQueue, &xItem, bktDONT_BLOCK ) != pdPASS )
|
}
|
||||||
{
|
vTaskDelay( bktSHORT_WAIT );
|
||||||
xErrorOccurred = pdTRUE;
|
xRunIndicator = 0;
|
||||||
}
|
|
||||||
|
for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
|
||||||
/* 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
|
/* Now when we place an item on the queue the other task should
|
||||||
empty ourselves, and the other task would be suspended. */
|
wake but not execute as this task has higher priority. */
|
||||||
if( xQueueReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )
|
if( xQueueSend( xTestQueue, &xItem, bktDONT_BLOCK ) != pdPASS )
|
||||||
{
|
{
|
||||||
xErrorOccurred = pdTRUE;
|
xErrorOccurred = pdTRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( xRunIndicator == bktRUN_INDICATOR )
|
/* 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
|
||||||
/* The other task should not have executed. */
|
empty ourselves, and the other task would be suspended. */
|
||||||
xErrorOccurred = pdTRUE;
|
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 );
|
if( xRunIndicator == bktRUN_INDICATOR )
|
||||||
|
{
|
||||||
/* The other task should now have re-blocked without exiting the
|
/* The other task should not have executed. */
|
||||||
queue function. */
|
xErrorOccurred = pdTRUE;
|
||||||
if( xRunIndicator == bktRUN_INDICATOR )
|
}
|
||||||
{
|
|
||||||
/* The other task should not have executed outside of the
|
/* Raise the priority of the other task so it executes and blocks
|
||||||
queue function. */
|
on the queue again. */
|
||||||
xErrorOccurred = pdTRUE;
|
vTaskPrioritySet( xSecondary, bktPRIMARY_PRIORITY + 2 );
|
||||||
}
|
|
||||||
vTaskPrioritySet( xSecondary, bktSECONDARY_PRIORITY );
|
/* The other task should now have re-blocked without exiting the
|
||||||
}
|
queue function. */
|
||||||
|
if( xRunIndicator == bktRUN_INDICATOR )
|
||||||
/* Let the other task timeout. When it unblockes it will check that it
|
{
|
||||||
unblocked at the correct time, then suspend itself. */
|
/* The other task should not have executed outside of the
|
||||||
while( xRunIndicator != bktRUN_INDICATOR )
|
queue function. */
|
||||||
{
|
xErrorOccurred = pdTRUE;
|
||||||
vTaskDelay( bktSHORT_WAIT );
|
}
|
||||||
}
|
vTaskPrioritySet( xSecondary, bktSECONDARY_PRIORITY );
|
||||||
vTaskDelay( bktSHORT_WAIT );
|
}
|
||||||
|
|
||||||
xPrimaryCycles++;
|
/* 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 );
|
||||||
static void vSecondaryBlockTimeTestTask( void *pvParameters )
|
}
|
||||||
{
|
vTaskDelay( bktSHORT_WAIT );
|
||||||
portTickType xTimeWhenBlocking, xBlockedTime;
|
|
||||||
portBASE_TYPE xData;
|
xPrimaryCycles++;
|
||||||
|
}
|
||||||
( void ) pvParameters;
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
for( ;; )
|
|
||||||
{
|
static void vSecondaryBlockTimeTestTask( void *pvParameters )
|
||||||
/*********************************************************************
|
{
|
||||||
Test 1 and 2
|
portTickType xTimeWhenBlocking, xBlockedTime;
|
||||||
|
portBASE_TYPE xData;
|
||||||
This task does does not participate in these tests. */
|
|
||||||
vTaskSuspend( NULL );
|
( void ) pvParameters;
|
||||||
|
|
||||||
/*********************************************************************
|
for( ;; )
|
||||||
Test 3
|
{
|
||||||
|
/*********************************************************************
|
||||||
The first thing we do is attempt to read from the queue. It should be
|
Test 1 and 2
|
||||||
full so we block. Note the time before we block so we can check the
|
|
||||||
wake time is as per that expected. */
|
This task does does not participate in these tests. */
|
||||||
xTimeWhenBlocking = xTaskGetTickCount();
|
vTaskSuspend( NULL );
|
||||||
|
|
||||||
/* We should unblock after bktTIME_TO_BLOCK having not received
|
/*********************************************************************
|
||||||
anything on the queue. */
|
Test 3
|
||||||
xData = 0;
|
|
||||||
xRunIndicator = bktRUN_INDICATOR;
|
The first thing we do is attempt to read from the queue. It should be
|
||||||
if( xQueueSend( xTestQueue, &xData, bktTIME_TO_BLOCK ) != errQUEUE_FULL )
|
full so we block. Note the time before we block so we can check the
|
||||||
{
|
wake time is as per that expected. */
|
||||||
xErrorOccurred = pdTRUE;
|
xTimeWhenBlocking = xTaskGetTickCount();
|
||||||
}
|
|
||||||
|
/* We should unblock after bktTIME_TO_BLOCK having not received
|
||||||
/* How long were we inside the send function? */
|
anything on the queue. */
|
||||||
xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
|
xData = 0;
|
||||||
|
xRunIndicator = bktRUN_INDICATOR;
|
||||||
/* We should not have blocked for less time than bktTIME_TO_BLOCK. */
|
if( xQueueSend( xTestQueue, &xData, bktTIME_TO_BLOCK ) != errQUEUE_FULL )
|
||||||
if( xBlockedTime < bktTIME_TO_BLOCK )
|
{
|
||||||
{
|
xErrorOccurred = pdTRUE;
|
||||||
xErrorOccurred = pdTRUE;
|
}
|
||||||
}
|
|
||||||
|
/* How long were we inside the send function? */
|
||||||
/* We should of not blocked for much longer than bktALLOWABLE_MARGIN
|
xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
|
||||||
either. A margin is permitted as we would not necessarily run as
|
|
||||||
soon as we unblocked. */
|
/* We should not have blocked for less time than bktTIME_TO_BLOCK. */
|
||||||
if( xBlockedTime > ( bktTIME_TO_BLOCK + bktALLOWABLE_MARGIN ) )
|
if( xBlockedTime < bktTIME_TO_BLOCK )
|
||||||
{
|
{
|
||||||
xErrorOccurred = pdTRUE;
|
xErrorOccurred = pdTRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Suspend ready for test 3. */
|
/* We should of not blocked for much longer than bktALLOWABLE_MARGIN
|
||||||
xRunIndicator = bktRUN_INDICATOR;
|
either. A margin is permitted as we would not necessarily run as
|
||||||
vTaskSuspend( NULL );
|
soon as we unblocked. */
|
||||||
|
if( xBlockedTime > ( bktTIME_TO_BLOCK + bktALLOWABLE_MARGIN ) )
|
||||||
/*********************************************************************
|
{
|
||||||
Test 4
|
xErrorOccurred = pdTRUE;
|
||||||
|
}
|
||||||
As per test three, but with the send and receive reversed. */
|
|
||||||
xTimeWhenBlocking = xTaskGetTickCount();
|
/* Suspend ready for test 3. */
|
||||||
|
xRunIndicator = bktRUN_INDICATOR;
|
||||||
/* We should unblock after bktTIME_TO_BLOCK having not received
|
vTaskSuspend( NULL );
|
||||||
anything on the queue. */
|
|
||||||
xRunIndicator = bktRUN_INDICATOR;
|
/*********************************************************************
|
||||||
if( xQueueReceive( xTestQueue, &xData, bktTIME_TO_BLOCK ) != errQUEUE_EMPTY )
|
Test 4
|
||||||
{
|
|
||||||
xErrorOccurred = pdTRUE;
|
As per test three, but with the send and receive reversed. */
|
||||||
}
|
xTimeWhenBlocking = xTaskGetTickCount();
|
||||||
|
|
||||||
xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
|
/* We should unblock after bktTIME_TO_BLOCK having not received
|
||||||
|
anything on the queue. */
|
||||||
/* We should not have blocked for less time than bktTIME_TO_BLOCK. */
|
xRunIndicator = bktRUN_INDICATOR;
|
||||||
if( xBlockedTime < bktTIME_TO_BLOCK )
|
if( xQueueReceive( xTestQueue, &xData, bktTIME_TO_BLOCK ) != errQUEUE_EMPTY )
|
||||||
{
|
{
|
||||||
xErrorOccurred = pdTRUE;
|
xErrorOccurred = pdTRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We should of not blocked for much longer than bktALLOWABLE_MARGIN
|
xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
|
||||||
either. A margin is permitted as we would not necessarily run as soon
|
|
||||||
as we unblocked. */
|
/* We should not have blocked for less time than bktTIME_TO_BLOCK. */
|
||||||
if( xBlockedTime > ( bktTIME_TO_BLOCK + bktALLOWABLE_MARGIN ) )
|
if( xBlockedTime < bktTIME_TO_BLOCK )
|
||||||
{
|
{
|
||||||
xErrorOccurred = pdTRUE;
|
xErrorOccurred = pdTRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
xRunIndicator = bktRUN_INDICATOR;
|
/* We should of not blocked for much longer than bktALLOWABLE_MARGIN
|
||||||
|
either. A margin is permitted as we would not necessarily run as soon
|
||||||
xSecondaryCycles++;
|
as we unblocked. */
|
||||||
}
|
if( xBlockedTime > ( bktTIME_TO_BLOCK + bktALLOWABLE_MARGIN ) )
|
||||||
}
|
{
|
||||||
/*-----------------------------------------------------------*/
|
xErrorOccurred = pdTRUE;
|
||||||
|
}
|
||||||
portBASE_TYPE xAreBlockTimeTestTasksStillRunning( void )
|
|
||||||
{
|
xRunIndicator = bktRUN_INDICATOR;
|
||||||
static portBASE_TYPE xLastPrimaryCycleCount = 0, xLastSecondaryCycleCount = 0;
|
|
||||||
portBASE_TYPE xReturn = pdPASS;
|
xSecondaryCycles++;
|
||||||
|
}
|
||||||
/* Have both tasks performed at least one cycle since this function was
|
}
|
||||||
last called? */
|
/*-----------------------------------------------------------*/
|
||||||
if( xPrimaryCycles == xLastPrimaryCycleCount )
|
|
||||||
{
|
portBASE_TYPE xAreBlockTimeTestTasksStillRunning( void )
|
||||||
xReturn = pdFAIL;
|
{
|
||||||
}
|
static portBASE_TYPE xLastPrimaryCycleCount = 0, xLastSecondaryCycleCount = 0;
|
||||||
|
portBASE_TYPE xReturn = pdPASS;
|
||||||
if( xSecondaryCycles == xLastSecondaryCycleCount )
|
|
||||||
{
|
/* Have both tasks performed at least one cycle since this function was
|
||||||
xReturn = pdFAIL;
|
last called? */
|
||||||
}
|
if( xPrimaryCycles == xLastPrimaryCycleCount )
|
||||||
|
{
|
||||||
if( xErrorOccurred == pdTRUE )
|
xReturn = pdFAIL;
|
||||||
{
|
}
|
||||||
xReturn = pdFAIL;
|
|
||||||
}
|
if( xSecondaryCycles == xLastSecondaryCycleCount )
|
||||||
|
{
|
||||||
xLastSecondaryCycleCount = xSecondaryCycles;
|
xReturn = pdFAIL;
|
||||||
xLastPrimaryCycleCount = xPrimaryCycles;
|
}
|
||||||
|
|
||||||
return xReturn;
|
if( xErrorOccurred == pdTRUE )
|
||||||
}
|
{
|
||||||
|
xReturn = pdFAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
xLastSecondaryCycleCount = xSecondaryCycles;
|
||||||
|
xLastPrimaryCycleCount = xPrimaryCycles;
|
||||||
|
|
||||||
|
return xReturn;
|
||||||
|
}
|
||||||
|
|
|
@ -138,6 +138,16 @@ void vStartCountingSemaphoreTasks( void )
|
||||||
xParameters[ 1 ].xSemaphore = xSemaphoreCreateCounting( countMAX_COUNT_VALUE, 0 );
|
xParameters[ 1 ].xSemaphore = xSemaphoreCreateCounting( countMAX_COUNT_VALUE, 0 );
|
||||||
xParameters[ 1 ].uxExpectedStartCount = 0;
|
xParameters[ 1 ].uxExpectedStartCount = 0;
|
||||||
xParameters[ 1 ].uxLoopCounter = 0;
|
xParameters[ 1 ].uxLoopCounter = 0;
|
||||||
|
|
||||||
|
/* 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( ( xQueueHandle ) xParameters[ 0 ].xSemaphore, ( signed portCHAR * ) "Counting_Sem_1" );
|
||||||
|
vQueueAddToRegistry( ( xQueueHandle ) xParameters[ 1 ].xSemaphore, ( signed portCHAR * ) "Counting_Sem_2" );
|
||||||
|
|
||||||
|
|
||||||
/* Were the semaphores created? */
|
/* Were the semaphores created? */
|
||||||
if( ( xParameters[ 0 ].xSemaphore != NULL ) || ( xParameters[ 1 ].xSemaphore != NULL ) )
|
if( ( xParameters[ 0 ].xSemaphore != NULL ) || ( xParameters[ 1 ].xSemaphore != NULL ) )
|
||||||
|
|
|
@ -1,414 +1,423 @@
|
||||||
/*
|
/*
|
||||||
FreeRTOS.org V5.0.0 - Copyright (C) 2003-2008 Richard Barry.
|
FreeRTOS.org V5.0.0 - Copyright (C) 2003-2008 Richard Barry.
|
||||||
|
|
||||||
This file is part of the FreeRTOS.org distribution.
|
This file is part of the FreeRTOS.org distribution.
|
||||||
|
|
||||||
FreeRTOS.org is free software; you can redistribute it and/or modify
|
FreeRTOS.org is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
FreeRTOS.org is distributed in the hope that it will be useful,
|
FreeRTOS.org is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with FreeRTOS.org; if not, write to the Free Software
|
along with FreeRTOS.org; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
A special exception to the GPL can be applied should you wish to distribute
|
A special exception to the GPL can be applied should you wish to distribute
|
||||||
a combined work that includes FreeRTOS.org, without being obliged to provide
|
a combined work that includes FreeRTOS.org, without being obliged to provide
|
||||||
the source code for any proprietary components. See the licensing section
|
the source code for any proprietary components. See the licensing section
|
||||||
of http://www.FreeRTOS.org for full details of how and when the exception
|
of http://www.FreeRTOS.org for full details of how and when the exception
|
||||||
can be applied.
|
can be applied.
|
||||||
|
|
||||||
***************************************************************************
|
***************************************************************************
|
||||||
***************************************************************************
|
***************************************************************************
|
||||||
* *
|
* *
|
||||||
* SAVE TIME AND MONEY! We can port FreeRTOS.org to your own hardware, *
|
* SAVE TIME AND MONEY! We can port FreeRTOS.org to your own hardware, *
|
||||||
* and even write all or part of your application on your behalf. *
|
* and even write all or part of your application on your behalf. *
|
||||||
* See http://www.OpenRTOS.com for details of the services we provide to *
|
* See http://www.OpenRTOS.com for details of the services we provide to *
|
||||||
* expedite your project. *
|
* expedite your project. *
|
||||||
* *
|
* *
|
||||||
***************************************************************************
|
***************************************************************************
|
||||||
***************************************************************************
|
***************************************************************************
|
||||||
|
|
||||||
Please ensure to read the configuration and relevant port sections of the
|
Please ensure to read the configuration and relevant port sections of the
|
||||||
online documentation.
|
online documentation.
|
||||||
|
|
||||||
http://www.FreeRTOS.org - Documentation, latest information, license and
|
http://www.FreeRTOS.org - Documentation, latest information, license and
|
||||||
contact details.
|
contact details.
|
||||||
|
|
||||||
http://www.SafeRTOS.com - A version that is certified for use in safety
|
http://www.SafeRTOS.com - A version that is certified for use in safety
|
||||||
critical systems.
|
critical systems.
|
||||||
|
|
||||||
http://www.OpenRTOS.com - Commercial support, development, porting,
|
http://www.OpenRTOS.com - Commercial support, development, porting,
|
||||||
licensing and training services.
|
licensing and training services.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The first test creates three tasks - two counter tasks (one continuous count
|
* The first test creates three tasks - two counter tasks (one continuous count
|
||||||
* and one limited count) and one controller. A "count" variable is shared
|
* and one limited count) and one controller. A "count" variable is shared
|
||||||
* between all three tasks. The two counter tasks should never be in a "ready"
|
* between all three tasks. The two counter tasks should never be in a "ready"
|
||||||
* state at the same time. The controller task runs at the same priority as
|
* state at the same time. The controller task runs at the same priority as
|
||||||
* the continuous count task, and at a lower priority than the limited count
|
* the continuous count task, and at a lower priority than the limited count
|
||||||
* task.
|
* task.
|
||||||
*
|
*
|
||||||
* One counter task loops indefinitely, incrementing the shared count variable
|
* One counter task loops indefinitely, incrementing the shared count variable
|
||||||
* on each iteration. To ensure it has exclusive access to the variable it
|
* on each iteration. To ensure it has exclusive access to the variable it
|
||||||
* raises it's priority above that of the controller task before each
|
* raises it's priority above that of the controller task before each
|
||||||
* increment, lowering it again to it's original priority before starting the
|
* increment, lowering it again to it's original priority before starting the
|
||||||
* next iteration.
|
* next iteration.
|
||||||
*
|
*
|
||||||
* The other counter task increments the shared count variable on each
|
* The other counter task increments the shared count variable on each
|
||||||
* iteration of it's loop until the count has reached a limit of 0xff - at
|
* iteration of it's loop until the count has reached a limit of 0xff - at
|
||||||
* which point it suspends itself. It will not start a new loop until the
|
* which point it suspends itself. It will not start a new loop until the
|
||||||
* controller task has made it "ready" again by calling vTaskResume ().
|
* controller task has made it "ready" again by calling vTaskResume ().
|
||||||
* This second counter task operates at a higher priority than controller
|
* This second counter task operates at a higher priority than controller
|
||||||
* task so does not need to worry about mutual exclusion of the counter
|
* task so does not need to worry about mutual exclusion of the counter
|
||||||
* variable.
|
* variable.
|
||||||
*
|
*
|
||||||
* The controller task is in two sections. The first section controls and
|
* The controller task is in two sections. The first section controls and
|
||||||
* monitors the continuous count task. When this section is operational the
|
* monitors the continuous count task. When this section is operational the
|
||||||
* limited count task is suspended. Likewise, the second section controls
|
* limited count task is suspended. Likewise, the second section controls
|
||||||
* and monitors the limited count task. When this section is operational the
|
* and monitors the limited count task. When this section is operational the
|
||||||
* continuous count task is suspended.
|
* continuous count task is suspended.
|
||||||
*
|
*
|
||||||
* In the first section the controller task first takes a copy of the shared
|
* In the first section the controller task first takes a copy of the shared
|
||||||
* count variable. To ensure mutual exclusion on the count variable it
|
* count variable. To ensure mutual exclusion on the count variable it
|
||||||
* suspends the continuous count task, resuming it again when the copy has been
|
* suspends the continuous count task, resuming it again when the copy has been
|
||||||
* taken. The controller task then sleeps for a fixed period - during which
|
* taken. The controller task then sleeps for a fixed period - during which
|
||||||
* the continuous count task will execute and increment the shared variable.
|
* the continuous count task will execute and increment the shared variable.
|
||||||
* When the controller task wakes it checks that the continuous count task
|
* When the controller task wakes it checks that the continuous count task
|
||||||
* has executed by comparing the copy of the shared variable with its current
|
* has executed by comparing the copy of the shared variable with its current
|
||||||
* value. This time, to ensure mutual exclusion, the scheduler itself is
|
* value. This time, to ensure mutual exclusion, the scheduler itself is
|
||||||
* suspended with a call to vTaskSuspendAll (). This is for demonstration
|
* suspended with a call to vTaskSuspendAll (). This is for demonstration
|
||||||
* purposes only and is not a recommended technique due to its inefficiency.
|
* purposes only and is not a recommended technique due to its inefficiency.
|
||||||
*
|
*
|
||||||
* After a fixed number of iterations the controller task suspends the
|
* After a fixed number of iterations the controller task suspends the
|
||||||
* continuous count task, and moves on to its second section.
|
* continuous count task, and moves on to its second section.
|
||||||
*
|
*
|
||||||
* At the start of the second section the shared variable is cleared to zero.
|
* At the start of the second section the shared variable is cleared to zero.
|
||||||
* The limited count task is then woken from it's suspension by a call to
|
* The limited count task is then woken from it's suspension by a call to
|
||||||
* vTaskResume (). As this counter task operates at a higher priority than
|
* vTaskResume (). As this counter task operates at a higher priority than
|
||||||
* the controller task the controller task should not run again until the
|
* the controller task the controller task should not run again until the
|
||||||
* shared variable has been counted up to the limited value causing the counter
|
* shared variable has been counted up to the limited value causing the counter
|
||||||
* task to suspend itself. The next line after vTaskResume () is therefore
|
* task to suspend itself. The next line after vTaskResume () is therefore
|
||||||
* a check on the shared variable to ensure everything is as expected.
|
* a check on the shared variable to ensure everything is as expected.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* The second test consists of a couple of very simple tasks that post onto a
|
* The second test consists of a couple of very simple tasks that post onto a
|
||||||
* queue while the scheduler is suspended. This test was added to test parts
|
* queue while the scheduler is suspended. This test was added to test parts
|
||||||
* of the scheduler not exercised by the first test.
|
* of the scheduler not exercised by the first test.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/* Scheduler include files. */
|
/* Scheduler include files. */
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
#include "semphr.h"
|
#include "semphr.h"
|
||||||
|
|
||||||
/* Demo app include files. */
|
/* Demo app include files. */
|
||||||
#include "dynamic.h"
|
#include "dynamic.h"
|
||||||
|
|
||||||
/* Function that implements the "limited count" task as described above. */
|
/* Function that implements the "limited count" task as described above. */
|
||||||
static portTASK_FUNCTION_PROTO( vLimitedIncrementTask, pvParameters );
|
static portTASK_FUNCTION_PROTO( vLimitedIncrementTask, pvParameters );
|
||||||
|
|
||||||
/* Function that implements the "continuous count" task as described above. */
|
/* Function that implements the "continuous count" task as described above. */
|
||||||
static portTASK_FUNCTION_PROTO( vContinuousIncrementTask, pvParameters );
|
static portTASK_FUNCTION_PROTO( vContinuousIncrementTask, pvParameters );
|
||||||
|
|
||||||
/* Function that implements the controller task as described above. */
|
/* Function that implements the controller task as described above. */
|
||||||
static portTASK_FUNCTION_PROTO( vCounterControlTask, pvParameters );
|
static portTASK_FUNCTION_PROTO( vCounterControlTask, pvParameters );
|
||||||
|
|
||||||
static portTASK_FUNCTION_PROTO( vQueueReceiveWhenSuspendedTask, pvParameters );
|
static portTASK_FUNCTION_PROTO( vQueueReceiveWhenSuspendedTask, pvParameters );
|
||||||
static portTASK_FUNCTION_PROTO( vQueueSendWhenSuspendedTask, pvParameters );
|
static portTASK_FUNCTION_PROTO( vQueueSendWhenSuspendedTask, pvParameters );
|
||||||
|
|
||||||
/* Demo task specific constants. */
|
/* Demo task specific constants. */
|
||||||
#define priSTACK_SIZE ( configMINIMAL_STACK_SIZE )
|
#define priSTACK_SIZE ( configMINIMAL_STACK_SIZE )
|
||||||
#define priSLEEP_TIME ( ( portTickType ) 128 / portTICK_RATE_MS )
|
#define priSLEEP_TIME ( ( portTickType ) 128 / portTICK_RATE_MS )
|
||||||
#define priLOOPS ( 5 )
|
#define priLOOPS ( 5 )
|
||||||
#define priMAX_COUNT ( ( unsigned portLONG ) 0xff )
|
#define priMAX_COUNT ( ( unsigned portLONG ) 0xff )
|
||||||
#define priNO_BLOCK ( ( portTickType ) 0 )
|
#define priNO_BLOCK ( ( portTickType ) 0 )
|
||||||
#define priSUSPENDED_QUEUE_LENGTH ( 1 )
|
#define priSUSPENDED_QUEUE_LENGTH ( 1 )
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/* Handles to the two counter tasks. These could be passed in as parameters
|
/* Handles to the two counter tasks. These could be passed in as parameters
|
||||||
to the controller task to prevent them having to be file scope. */
|
to the controller task to prevent them having to be file scope. */
|
||||||
static xTaskHandle xContinousIncrementHandle, xLimitedIncrementHandle;
|
static xTaskHandle xContinousIncrementHandle, xLimitedIncrementHandle;
|
||||||
|
|
||||||
/* The shared counter variable. This is passed in as a parameter to the two
|
/* The shared counter variable. This is passed in as a parameter to the two
|
||||||
counter variables for demonstration purposes. */
|
counter variables for demonstration purposes. */
|
||||||
static unsigned portLONG ulCounter;
|
static unsigned portLONG ulCounter;
|
||||||
|
|
||||||
/* Variables used to check that the tasks are still operating without error.
|
/* Variables used to check that the tasks are still operating without error.
|
||||||
Each complete iteration of the controller task increments this variable
|
Each complete iteration of the controller task increments this variable
|
||||||
provided no errors have been found. The variable maintaining the same value
|
provided no errors have been found. The variable maintaining the same value
|
||||||
is therefore indication of an error. */
|
is therefore indication of an error. */
|
||||||
static volatile unsigned portSHORT usCheckVariable = ( unsigned portSHORT ) 0;
|
static volatile unsigned portSHORT usCheckVariable = ( unsigned portSHORT ) 0;
|
||||||
static volatile portBASE_TYPE xSuspendedQueueSendError = pdFALSE;
|
static volatile portBASE_TYPE xSuspendedQueueSendError = pdFALSE;
|
||||||
static volatile portBASE_TYPE xSuspendedQueueReceiveError = pdFALSE;
|
static volatile portBASE_TYPE xSuspendedQueueReceiveError = pdFALSE;
|
||||||
|
|
||||||
/* Queue used by the second test. */
|
/* Queue used by the second test. */
|
||||||
xQueueHandle xSuspendedTestQueue;
|
xQueueHandle xSuspendedTestQueue;
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
/*
|
/*
|
||||||
* Start the three tasks as described at the top of the file.
|
* Start the three tasks as described at the top of the file.
|
||||||
* Note that the limited count task is given a higher priority.
|
* Note that the limited count task is given a higher priority.
|
||||||
*/
|
*/
|
||||||
void vStartDynamicPriorityTasks( void )
|
void vStartDynamicPriorityTasks( void )
|
||||||
{
|
{
|
||||||
xSuspendedTestQueue = xQueueCreate( priSUSPENDED_QUEUE_LENGTH, sizeof( unsigned portLONG ) );
|
xSuspendedTestQueue = xQueueCreate( priSUSPENDED_QUEUE_LENGTH, sizeof( unsigned portLONG ) );
|
||||||
xTaskCreate( vContinuousIncrementTask, ( signed portCHAR * ) "CNT_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY, &xContinousIncrementHandle );
|
|
||||||
xTaskCreate( vLimitedIncrementTask, ( signed portCHAR * ) "LIM_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY + 1, &xLimitedIncrementHandle );
|
/* vQueueAddToRegistry() adds the queue to the queue registry, if one is
|
||||||
xTaskCreate( vCounterControlTask, ( signed portCHAR * ) "C_CTRL", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
|
in use. The queue registry is provided as a means for kernel aware
|
||||||
xTaskCreate( vQueueSendWhenSuspendedTask, ( signed portCHAR * ) "SUSP_TX", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
|
debuggers to locate queues and has no purpose if a kernel aware debugger
|
||||||
xTaskCreate( vQueueReceiveWhenSuspendedTask, ( signed portCHAR * ) "SUSP_RX", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
|
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, ( signed portCHAR * ) "Suspended_Test_Queue" );
|
||||||
/*
|
|
||||||
* Just loops around incrementing the shared variable until the limit has been
|
xTaskCreate( vContinuousIncrementTask, ( signed portCHAR * ) "CNT_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY, &xContinousIncrementHandle );
|
||||||
* reached. Once the limit has been reached it suspends itself.
|
xTaskCreate( vLimitedIncrementTask, ( signed portCHAR * ) "LIM_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY + 1, &xLimitedIncrementHandle );
|
||||||
*/
|
xTaskCreate( vCounterControlTask, ( signed portCHAR * ) "C_CTRL", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
|
||||||
static portTASK_FUNCTION( vLimitedIncrementTask, pvParameters )
|
xTaskCreate( vQueueSendWhenSuspendedTask, ( signed portCHAR * ) "SUSP_TX", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
|
||||||
{
|
xTaskCreate( vQueueReceiveWhenSuspendedTask, ( signed portCHAR * ) "SUSP_RX", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
|
||||||
unsigned portLONG *pulCounter;
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
/* Take a pointer to the shared variable from the parameters passed into
|
|
||||||
the task. */
|
/*
|
||||||
pulCounter = ( unsigned portLONG * ) pvParameters;
|
* Just loops around incrementing the shared variable until the limit has been
|
||||||
|
* reached. Once the limit has been reached it suspends itself.
|
||||||
/* This will run before the control task, so the first thing it does is
|
*/
|
||||||
suspend - the control task will resume it when ready. */
|
static portTASK_FUNCTION( vLimitedIncrementTask, pvParameters )
|
||||||
vTaskSuspend( NULL );
|
{
|
||||||
|
unsigned portLONG *pulCounter;
|
||||||
for( ;; )
|
|
||||||
{
|
/* Take a pointer to the shared variable from the parameters passed into
|
||||||
/* Just count up to a value then suspend. */
|
the task. */
|
||||||
( *pulCounter )++;
|
pulCounter = ( unsigned portLONG * ) pvParameters;
|
||||||
|
|
||||||
if( *pulCounter >= priMAX_COUNT )
|
/* 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 );
|
vTaskSuspend( NULL );
|
||||||
}
|
|
||||||
}
|
for( ;; )
|
||||||
}
|
{
|
||||||
/*-----------------------------------------------------------*/
|
/* Just count up to a value then suspend. */
|
||||||
|
( *pulCounter )++;
|
||||||
/*
|
|
||||||
* Just keep counting the shared variable up. The control task will suspend
|
if( *pulCounter >= priMAX_COUNT )
|
||||||
* this task when it wants.
|
{
|
||||||
*/
|
vTaskSuspend( NULL );
|
||||||
static portTASK_FUNCTION( vContinuousIncrementTask, pvParameters )
|
}
|
||||||
{
|
}
|
||||||
unsigned portLONG *pulCounter;
|
}
|
||||||
unsigned portBASE_TYPE uxOurPriority;
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/* Take a pointer to the shared variable from the parameters passed into
|
/*
|
||||||
the task. */
|
* Just keep counting the shared variable up. The control task will suspend
|
||||||
pulCounter = ( unsigned portLONG * ) pvParameters;
|
* this task when it wants.
|
||||||
|
*/
|
||||||
/* Query our priority so we can raise it when exclusive access to the
|
static portTASK_FUNCTION( vContinuousIncrementTask, pvParameters )
|
||||||
shared variable is required. */
|
{
|
||||||
uxOurPriority = uxTaskPriorityGet( NULL );
|
unsigned portLONG *pulCounter;
|
||||||
|
unsigned portBASE_TYPE uxOurPriority;
|
||||||
for( ;; )
|
|
||||||
{
|
/* Take a pointer to the shared variable from the parameters passed into
|
||||||
/* Raise our priority above the controller task to ensure a context
|
the task. */
|
||||||
switch does not occur while we are accessing this variable. */
|
pulCounter = ( unsigned portLONG * ) pvParameters;
|
||||||
vTaskPrioritySet( NULL, uxOurPriority + 1 );
|
|
||||||
( *pulCounter )++;
|
/* Query our priority so we can raise it when exclusive access to the
|
||||||
vTaskPrioritySet( NULL, uxOurPriority );
|
shared variable is required. */
|
||||||
}
|
uxOurPriority = uxTaskPriorityGet( NULL );
|
||||||
}
|
|
||||||
/*-----------------------------------------------------------*/
|
for( ;; )
|
||||||
|
{
|
||||||
/*
|
/* Raise our priority above the controller task to ensure a context
|
||||||
* Controller task as described above.
|
switch does not occur while we are accessing this variable. */
|
||||||
*/
|
vTaskPrioritySet( NULL, uxOurPriority + 1 );
|
||||||
static portTASK_FUNCTION( vCounterControlTask, pvParameters )
|
( *pulCounter )++;
|
||||||
{
|
vTaskPrioritySet( NULL, uxOurPriority );
|
||||||
unsigned portLONG ulLastCounter;
|
}
|
||||||
portSHORT sLoops;
|
}
|
||||||
portSHORT sError = pdFALSE;
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/* Just to stop warning messages. */
|
/*
|
||||||
( void ) pvParameters;
|
* Controller task as described above.
|
||||||
|
*/
|
||||||
for( ;; )
|
static portTASK_FUNCTION( vCounterControlTask, pvParameters )
|
||||||
{
|
{
|
||||||
/* Start with the counter at zero. */
|
unsigned portLONG ulLastCounter;
|
||||||
ulCounter = ( unsigned portLONG ) 0;
|
portSHORT sLoops;
|
||||||
|
portSHORT sError = pdFALSE;
|
||||||
/* First section : */
|
|
||||||
|
/* Just to stop warning messages. */
|
||||||
/* Check the continuous count task is running. */
|
( void ) pvParameters;
|
||||||
for( sLoops = 0; sLoops < priLOOPS; sLoops++ )
|
|
||||||
{
|
for( ;; )
|
||||||
/* Suspend the continuous count task so we can take a mirror of the
|
{
|
||||||
shared variable without risk of corruption. */
|
/* Start with the counter at zero. */
|
||||||
vTaskSuspend( xContinousIncrementHandle );
|
ulCounter = ( unsigned portLONG ) 0;
|
||||||
ulLastCounter = ulCounter;
|
|
||||||
vTaskResume( xContinousIncrementHandle );
|
/* First section : */
|
||||||
|
|
||||||
/* Now delay to ensure the other task has processor time. */
|
/* Check the continuous count task is running. */
|
||||||
vTaskDelay( priSLEEP_TIME );
|
for( sLoops = 0; sLoops < priLOOPS; sLoops++ )
|
||||||
|
{
|
||||||
/* Check the shared variable again. This time to ensure mutual
|
/* Suspend the continuous count task so we can take a mirror of the
|
||||||
exclusion the whole scheduler will be locked. This is just for
|
shared variable without risk of corruption. */
|
||||||
demo purposes! */
|
vTaskSuspend( xContinousIncrementHandle );
|
||||||
vTaskSuspendAll();
|
ulLastCounter = ulCounter;
|
||||||
{
|
vTaskResume( xContinousIncrementHandle );
|
||||||
if( ulLastCounter == ulCounter )
|
|
||||||
{
|
/* Now delay to ensure the other task has processor time. */
|
||||||
/* The shared variable has not changed. There is a problem
|
vTaskDelay( priSLEEP_TIME );
|
||||||
with the continuous count task so flag an error. */
|
|
||||||
sError = pdTRUE;
|
/* Check the shared variable again. This time to ensure mutual
|
||||||
}
|
exclusion the whole scheduler will be locked. This is just for
|
||||||
}
|
demo purposes! */
|
||||||
xTaskResumeAll();
|
vTaskSuspendAll();
|
||||||
}
|
{
|
||||||
|
if( ulLastCounter == ulCounter )
|
||||||
|
{
|
||||||
/* Second section: */
|
/* The shared variable has not changed. There is a problem
|
||||||
|
with the continuous count task so flag an error. */
|
||||||
/* Suspend the continuous counter task so it stops accessing the shared variable. */
|
sError = pdTRUE;
|
||||||
vTaskSuspend( xContinousIncrementHandle );
|
}
|
||||||
|
}
|
||||||
/* Reset the variable. */
|
xTaskResumeAll();
|
||||||
ulCounter = ( unsigned portLONG ) 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
|
/* Second section: */
|
||||||
task has suspended itself with a known value in the counter variable. */
|
|
||||||
vTaskResume( xLimitedIncrementHandle );
|
/* Suspend the continuous counter task so it stops accessing the shared variable. */
|
||||||
|
vTaskSuspend( xContinousIncrementHandle );
|
||||||
/* Does the counter variable have the expected value? */
|
|
||||||
if( ulCounter != priMAX_COUNT )
|
/* Reset the variable. */
|
||||||
{
|
ulCounter = ( unsigned portLONG ) 0;
|
||||||
sError = pdTRUE;
|
|
||||||
}
|
/* Resume the limited count task which has a higher priority than us.
|
||||||
|
We should therefore not return from this call until the limited count
|
||||||
if( sError == pdFALSE )
|
task has suspended itself with a known value in the counter variable. */
|
||||||
{
|
vTaskResume( xLimitedIncrementHandle );
|
||||||
/* If no errors have occurred then increment the check variable. */
|
|
||||||
portENTER_CRITICAL();
|
/* Does the counter variable have the expected value? */
|
||||||
usCheckVariable++;
|
if( ulCounter != priMAX_COUNT )
|
||||||
portEXIT_CRITICAL();
|
{
|
||||||
}
|
sError = pdTRUE;
|
||||||
|
}
|
||||||
/* Resume the continuous count task and do it all again. */
|
|
||||||
vTaskResume( xContinousIncrementHandle );
|
if( sError == pdFALSE )
|
||||||
}
|
{
|
||||||
}
|
/* If no errors have occurred then increment the check variable. */
|
||||||
/*-----------------------------------------------------------*/
|
portENTER_CRITICAL();
|
||||||
|
usCheckVariable++;
|
||||||
static portTASK_FUNCTION( vQueueSendWhenSuspendedTask, pvParameters )
|
portEXIT_CRITICAL();
|
||||||
{
|
}
|
||||||
static unsigned portLONG ulValueToSend = ( unsigned portLONG ) 0;
|
|
||||||
|
/* Resume the continuous count task and do it all again. */
|
||||||
/* Just to stop warning messages. */
|
vTaskResume( xContinousIncrementHandle );
|
||||||
( void ) pvParameters;
|
}
|
||||||
|
}
|
||||||
for( ;; )
|
/*-----------------------------------------------------------*/
|
||||||
{
|
|
||||||
vTaskSuspendAll();
|
static portTASK_FUNCTION( vQueueSendWhenSuspendedTask, pvParameters )
|
||||||
{
|
{
|
||||||
/* We must not block while the scheduler is suspended! */
|
static unsigned portLONG ulValueToSend = ( unsigned portLONG ) 0;
|
||||||
if( xQueueSend( xSuspendedTestQueue, ( void * ) &ulValueToSend, priNO_BLOCK ) != pdTRUE )
|
|
||||||
{
|
/* Just to stop warning messages. */
|
||||||
xSuspendedQueueSendError = pdTRUE;
|
( void ) pvParameters;
|
||||||
}
|
|
||||||
}
|
for( ;; )
|
||||||
xTaskResumeAll();
|
{
|
||||||
|
vTaskSuspendAll();
|
||||||
vTaskDelay( priSLEEP_TIME );
|
{
|
||||||
|
/* We must not block while the scheduler is suspended! */
|
||||||
++ulValueToSend;
|
if( xQueueSend( xSuspendedTestQueue, ( void * ) &ulValueToSend, priNO_BLOCK ) != pdTRUE )
|
||||||
}
|
{
|
||||||
}
|
xSuspendedQueueSendError = pdTRUE;
|
||||||
/*-----------------------------------------------------------*/
|
}
|
||||||
|
}
|
||||||
static portTASK_FUNCTION( vQueueReceiveWhenSuspendedTask, pvParameters )
|
xTaskResumeAll();
|
||||||
{
|
|
||||||
static unsigned portLONG ulExpectedValue = ( unsigned portLONG ) 0, ulReceivedValue;
|
vTaskDelay( priSLEEP_TIME );
|
||||||
portBASE_TYPE xGotValue;
|
|
||||||
|
++ulValueToSend;
|
||||||
/* Just to stop warning messages. */
|
}
|
||||||
( void ) pvParameters;
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
for( ;; )
|
|
||||||
{
|
static portTASK_FUNCTION( vQueueReceiveWhenSuspendedTask, pvParameters )
|
||||||
do
|
{
|
||||||
{
|
static unsigned portLONG ulExpectedValue = ( unsigned portLONG ) 0, ulReceivedValue;
|
||||||
/* Suspending the scheduler here is fairly pointless and
|
portBASE_TYPE xGotValue;
|
||||||
undesirable for a normal application. It is done here purely
|
|
||||||
to test the scheduler. The inner xTaskResumeAll() should
|
/* Just to stop warning messages. */
|
||||||
never return pdTRUE as the scheduler is still locked by the
|
( void ) pvParameters;
|
||||||
outer call. */
|
|
||||||
vTaskSuspendAll();
|
for( ;; )
|
||||||
{
|
{
|
||||||
vTaskSuspendAll();
|
do
|
||||||
{
|
{
|
||||||
xGotValue = xQueueReceive( xSuspendedTestQueue, ( void * ) &ulReceivedValue, priNO_BLOCK );
|
/* Suspending the scheduler here is fairly pointless and
|
||||||
}
|
undesirable for a normal application. It is done here purely
|
||||||
if( xTaskResumeAll() )
|
to test the scheduler. The inner xTaskResumeAll() should
|
||||||
{
|
never return pdTRUE as the scheduler is still locked by the
|
||||||
xSuspendedQueueReceiveError = pdTRUE;
|
outer call. */
|
||||||
}
|
vTaskSuspendAll();
|
||||||
}
|
{
|
||||||
xTaskResumeAll();
|
vTaskSuspendAll();
|
||||||
|
{
|
||||||
#if configUSE_PREEMPTION == 0
|
xGotValue = xQueueReceive( xSuspendedTestQueue, ( void * ) &ulReceivedValue, priNO_BLOCK );
|
||||||
{
|
}
|
||||||
taskYIELD();
|
if( xTaskResumeAll() )
|
||||||
}
|
{
|
||||||
#endif
|
xSuspendedQueueReceiveError = pdTRUE;
|
||||||
|
}
|
||||||
} while( xGotValue == pdFALSE );
|
}
|
||||||
|
xTaskResumeAll();
|
||||||
if( ulReceivedValue != ulExpectedValue )
|
|
||||||
{
|
#if configUSE_PREEMPTION == 0
|
||||||
xSuspendedQueueReceiveError = pdTRUE;
|
{
|
||||||
}
|
taskYIELD();
|
||||||
|
}
|
||||||
++ulExpectedValue;
|
#endif
|
||||||
}
|
|
||||||
}
|
} while( xGotValue == pdFALSE );
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
if( ulReceivedValue != ulExpectedValue )
|
||||||
/* Called to check that all the created tasks are still running without error. */
|
{
|
||||||
portBASE_TYPE xAreDynamicPriorityTasksStillRunning( void )
|
xSuspendedQueueReceiveError = pdTRUE;
|
||||||
{
|
}
|
||||||
/* Keep a history of the check variables so we know if it has been incremented
|
|
||||||
since the last call. */
|
++ulExpectedValue;
|
||||||
static unsigned portSHORT usLastTaskCheck = ( unsigned portSHORT ) 0;
|
}
|
||||||
portBASE_TYPE xReturn = pdTRUE;
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
/* Check the tasks are still running by ensuring the check variable
|
|
||||||
is still incrementing. */
|
/* Called to check that all the created tasks are still running without error. */
|
||||||
|
portBASE_TYPE xAreDynamicPriorityTasksStillRunning( void )
|
||||||
if( usCheckVariable == usLastTaskCheck )
|
{
|
||||||
{
|
/* Keep a history of the check variables so we know if it has been incremented
|
||||||
/* The check has not incremented so an error exists. */
|
since the last call. */
|
||||||
xReturn = pdFALSE;
|
static unsigned portSHORT usLastTaskCheck = ( unsigned portSHORT ) 0;
|
||||||
}
|
portBASE_TYPE xReturn = pdTRUE;
|
||||||
|
|
||||||
if( xSuspendedQueueSendError == pdTRUE )
|
/* Check the tasks are still running by ensuring the check variable
|
||||||
{
|
is still incrementing. */
|
||||||
xReturn = pdFALSE;
|
|
||||||
}
|
if( usCheckVariable == usLastTaskCheck )
|
||||||
|
{
|
||||||
if( xSuspendedQueueReceiveError == pdTRUE )
|
/* The check has not incremented so an error exists. */
|
||||||
{
|
xReturn = pdFALSE;
|
||||||
xReturn = pdFALSE;
|
}
|
||||||
}
|
|
||||||
|
if( xSuspendedQueueSendError == pdTRUE )
|
||||||
usLastTaskCheck = usCheckVariable;
|
{
|
||||||
return xReturn;
|
xReturn = pdFALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( xSuspendedQueueReceiveError == pdTRUE )
|
||||||
|
{
|
||||||
|
xReturn = pdFALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
usLastTaskCheck = usCheckVariable;
|
||||||
|
return xReturn;
|
||||||
|
}
|
||||||
|
|
|
@ -126,7 +126,16 @@ void vStartRecursiveMutexTasks( void )
|
||||||
{
|
{
|
||||||
/* Just creates the mutex and the three tasks. */
|
/* Just creates the mutex and the three tasks. */
|
||||||
|
|
||||||
xMutex = xSemaphoreCreateRecursiveMutex();
|
xMutex = xSemaphoreCreateRecursiveMutex();
|
||||||
|
|
||||||
|
/* 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( ( xQueueHandle ) xMutex, ( signed portCHAR * ) "Recursive_Mutex" );
|
||||||
|
|
||||||
|
|
||||||
if( xMutex != NULL )
|
if( xMutex != NULL )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue