diff options
author | richardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2> | 2013-06-27 14:25:17 +0000 |
---|---|---|
committer | richardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2> | 2013-06-27 14:25:17 +0000 |
commit | aac213c7d8e8ff163f7ec0a955f22a8b646356b2 (patch) | |
tree | 4735dc1e39920ad95c7d09f93e50a265441d2036 /FreeRTOS/Demo | |
parent | e3d8468fd7d0502384b0fa10762ee68fa640d822 (diff) | |
download | freertos-aac213c7d8e8ff163f7ec0a955f22a8b646356b2.tar.gz |
Add xQueueOverwriteFromISR() and update the QueueOverwrite.c to demonstrate its use.
git-svn-id: http://svn.code.sf.net/p/freertos/code/trunk@1954 1d2547de-c912-0410-9cb9-b8ca96c0e9e2
Diffstat (limited to 'FreeRTOS/Demo')
-rw-r--r-- | FreeRTOS/Demo/Common/Minimal/QueueOverwrite.c | 93 | ||||
-rw-r--r-- | FreeRTOS/Demo/Common/include/QueueOverwrite.h | 1 | ||||
-rw-r--r-- | FreeRTOS/Demo/WIN32-MSVC/main.c | 3 |
3 files changed, 85 insertions, 12 deletions
diff --git a/FreeRTOS/Demo/Common/Minimal/QueueOverwrite.c b/FreeRTOS/Demo/Common/Minimal/QueueOverwrite.c index e554201bd..e33dcdbff 100644 --- a/FreeRTOS/Demo/Common/Minimal/QueueOverwrite.c +++ b/FreeRTOS/Demo/Common/Minimal/QueueOverwrite.c @@ -98,18 +98,33 @@ static void prvQueueOverwriteTask( void *pvParameters ); prvQueueOverwriteTask() has not found any errors. */
static unsigned long ulLoopCounter = 0;
+/* Set to pdFALSE if an error is discovered by the
+vQueueOverwritePeriodicISRDemo() function. */
+static portBASE_TYPE xISRTestStatus = pdPASS;
+
+/* The queue that is accessed from the ISR. The queue accessed by the task is
+created inside the task itself. */
+static xQueueHandle xISRQueue = NULL;
+
/*-----------------------------------------------------------*/
void vStartQueueOverwriteTask( unsigned portBASE_TYPE uxPriority )
{
- /* Create the test task. */
+const unsigned portBASE_TYPE uxQueueLength = 1;
+
+ /* Create the queue used by the ISR. xQueueOverwriteFromISR() should only
+ be used on queues that have a length of 1. */
+ xISRQueue = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( unsigned long ) );
+
+ /* Create the test task. The queue used by the test task is created inside
+ the task itself. */
xTaskCreate( prvQueueOverwriteTask, ( signed char * ) "QOver", configMINIMAL_STACK_SIZE, NULL, uxPriority, ( xTaskHandle * ) NULL );
}
/*-----------------------------------------------------------*/
static void prvQueueOverwriteTask( void *pvParameters )
{
-xQueueHandle xQueue;
+xQueueHandle xTaskQueue;
const unsigned portBASE_TYPE uxQueueLength = 1;
unsigned long ulValue, ulStatus = pdPASS, x;
@@ -118,18 +133,18 @@ unsigned long ulValue, ulStatus = pdPASS, x; /* Create the queue. xQueueOverwrite() should only be used on queues that
have a length of 1. */
- xQueue = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( unsigned long ) );
- configASSERT( xQueue );
+ xTaskQueue = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( unsigned long ) );
+ configASSERT( xTaskQueue );
for( ;; )
{
/* The queue is empty. Writing to the queue then reading from the queue
should return the item written. */
ulValue = 10;
- xQueueOverwrite( xQueue, &ulValue );
+ xQueueOverwrite( xTaskQueue, &ulValue );
ulValue = 0;
- xQueueReceive( xQueue, &ulValue, qoDONT_BLOCK );
+ xQueueReceive( xTaskQueue, &ulValue, qoDONT_BLOCK );
if( ulValue != 10 )
{
@@ -141,27 +156,27 @@ unsigned long ulValue, ulStatus = pdPASS, x; for( x = 0; x < qoLOOPS; x++ )
{
/* Write to the queue. */
- xQueueOverwrite( xQueue, &x );
+ xQueueOverwrite( xTaskQueue, &x );
/* Check the value in the queue is that written, even though the
queue was not necessarily empty. */
- xQueuePeek( xQueue, &ulValue, qoDONT_BLOCK );
+ xQueuePeek( xTaskQueue, &ulValue, qoDONT_BLOCK );
if( ulValue != x )
{
ulStatus = pdFAIL;
}
/* There should always be one item in the queue. */
- if( uxQueueMessagesWaiting( xQueue ) != uxQueueLength )
+ if( uxQueueMessagesWaiting( xTaskQueue ) != uxQueueLength )
{
ulStatus = pdFAIL;
}
}
/* Empty the queue again. */
- xQueueReceive( xQueue, &ulValue, qoDONT_BLOCK );
+ xQueueReceive( xTaskQueue, &ulValue, qoDONT_BLOCK );
- if( uxQueueMessagesWaiting( xQueue ) != 0 )
+ if( uxQueueMessagesWaiting( xTaskQueue ) != 0 )
{
ulStatus = pdFAIL;
}
@@ -180,7 +195,11 @@ portBASE_TYPE xIsQueueOverwriteTaskStillRunning( void ) {
portBASE_TYPE xReturn;
- if( ulLoopCounter > 0 )
+ if( xISRTestStatus != pdPASS )
+ {
+ xReturn = pdFAIL;
+ }
+ else if( ulLoopCounter > 0 )
{
xReturn = pdPASS;
}
@@ -194,4 +213,54 @@ portBASE_TYPE xReturn; return xReturn;
}
+/*-----------------------------------------------------------*/
+
+void vQueueOverwritePeriodicISRDemo( void )
+{
+static unsigned long ulCallCount = 0;
+const unsigned long ulTx1 = 10UL, ulTx2 = 20UL, ulNumberOfSwitchCases = 3UL;
+unsigned long ulRx;
+
+ /* This function should be called from an interrupt, such as the tick hook
+ function vApplicationTickHook(). */
+
+ configASSERT( xISRQueue );
+
+ switch( ulCallCount )
+ {
+ case 0:
+ /* The queue is empty. Write ulTx1 to the queue. In this demo the
+ last parameter is not used because there are no tasks blocked on
+ this queue. */
+ xQueueOverwriteFromISR( xISRQueue, &ulTx1, NULL );
+ break;
+
+ case 1:
+ /* The queue already holds ulTx1. Overwrite the value in the queue
+ with ulTx2. */
+ xQueueOverwriteFromISR( xISRQueue, &ulTx2, NULL );
+ break;
+
+ case 2:
+ /* Read from the queue to empty the queue again. The value read
+ should be ulTx2. */
+ xQueueReceiveFromISR( xISRQueue, &ulRx, NULL );
+
+ if( ulRx != ulTx2 )
+ {
+ xISRTestStatus = pdFAIL;
+ }
+ break;
+ }
+
+ /* Run the next case in the switch statement above next time this function
+ is called. */
+ ulCallCount++;
+
+ if( ulCallCount >= ulNumberOfSwitchCases )
+ {
+ /* Go back to the start. */
+ ulCallCount = 0;
+ }
+}
diff --git a/FreeRTOS/Demo/Common/include/QueueOverwrite.h b/FreeRTOS/Demo/Common/include/QueueOverwrite.h index c4fba5ffb..fc1231229 100644 --- a/FreeRTOS/Demo/Common/include/QueueOverwrite.h +++ b/FreeRTOS/Demo/Common/include/QueueOverwrite.h @@ -77,6 +77,7 @@ void vStartQueueOverwriteTask( unsigned portBASE_TYPE uxPriority );
portBASE_TYPE xIsQueueOverwriteTaskStillRunning( void );
+void vQueueOverwritePeriodicISRDemo( void );
#endif /* QUEUE_OVERWRITE_H */
diff --git a/FreeRTOS/Demo/WIN32-MSVC/main.c b/FreeRTOS/Demo/WIN32-MSVC/main.c index 0dc4dcd45..b57938c7b 100644 --- a/FreeRTOS/Demo/WIN32-MSVC/main.c +++ b/FreeRTOS/Demo/WIN32-MSVC/main.c @@ -411,6 +411,9 @@ void vApplicationTickHook( void ) can be called from an ISR. */
vTimerPeriodicISRTests();
+ /* Call the periodic queue overwrite from ISR demo. */
+ vQueueOverwritePeriodicISRDemo();
+
/* Write to a queue that is in use as part of the queue set demo to
demonstrate using queue sets from an ISR. */
vQueueSetAccessQueueSetFromISR();
|