2 FreeRTOS V7.5.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
66 * Basic task to demonstrate the xQueueOverwrite() function. See the comments
\r
67 * in the function itself.
\r
70 /* Scheduler include files. */
\r
71 #include "FreeRTOS.h"
\r
75 /* Demo program include files. */
\r
76 #include "QueueOverwrite.h"
\r
78 /* A block time of 0 just means "don't block". */
\r
79 #define qoDONT_BLOCK 0
\r
81 /* Number of times to overwrite the value in the queue. */
\r
84 /* The task that uses the queue. */
\r
85 static void prvQueueOverwriteTask( void *pvParameters );
\r
87 /* Variable that is incremented on each loop of prvQueueOverwriteTask() provided
\r
88 prvQueueOverwriteTask() has not found any errors. */
\r
89 static unsigned long ulLoopCounter = 0;
\r
91 /* Set to pdFALSE if an error is discovered by the
\r
92 vQueueOverwritePeriodicISRDemo() function. */
\r
93 static portBASE_TYPE xISRTestStatus = pdPASS;
\r
95 /* The queue that is accessed from the ISR. The queue accessed by the task is
\r
96 created inside the task itself. */
\r
97 static xQueueHandle xISRQueue = NULL;
\r
99 /*-----------------------------------------------------------*/
\r
101 void vStartQueueOverwriteTask( unsigned portBASE_TYPE uxPriority )
\r
103 const unsigned portBASE_TYPE uxQueueLength = 1;
\r
105 /* Create the queue used by the ISR. xQueueOverwriteFromISR() should only
\r
106 be used on queues that have a length of 1. */
\r
107 xISRQueue = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( unsigned long ) );
\r
109 /* Create the test task. The queue used by the test task is created inside
\r
110 the task itself. */
\r
111 xTaskCreate( prvQueueOverwriteTask, ( signed char * ) "QOver", configMINIMAL_STACK_SIZE, NULL, uxPriority, ( xTaskHandle * ) NULL );
\r
113 /*-----------------------------------------------------------*/
\r
115 static void prvQueueOverwriteTask( void *pvParameters )
\r
117 xQueueHandle xTaskQueue;
\r
118 const unsigned portBASE_TYPE uxQueueLength = 1;
\r
119 unsigned long ulValue, ulStatus = pdPASS, x;
\r
121 /* The parameter is not used. */
\r
122 ( void ) pvParameters;
\r
124 /* Create the queue. xQueueOverwrite() should only be used on queues that
\r
125 have a length of 1. */
\r
126 xTaskQueue = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( unsigned long ) );
\r
127 configASSERT( xTaskQueue );
\r
131 /* The queue is empty. Writing to the queue then reading from the queue
\r
132 should return the item written. */
\r
134 xQueueOverwrite( xTaskQueue, &ulValue );
\r
137 xQueueReceive( xTaskQueue, &ulValue, qoDONT_BLOCK );
\r
139 if( ulValue != 10 )
\r
144 /* Now try writing to the queue several times. Each time the value
\r
145 in the queue should get overwritten. */
\r
146 for( x = 0; x < qoLOOPS; x++ )
\r
148 /* Write to the queue. */
\r
149 xQueueOverwrite( xTaskQueue, &x );
\r
151 /* Check the value in the queue is that written, even though the
\r
152 queue was not necessarily empty. */
\r
153 xQueuePeek( xTaskQueue, &ulValue, qoDONT_BLOCK );
\r
159 /* There should always be one item in the queue. */
\r
160 if( uxQueueMessagesWaiting( xTaskQueue ) != uxQueueLength )
\r
166 /* Empty the queue again. */
\r
167 xQueueReceive( xTaskQueue, &ulValue, qoDONT_BLOCK );
\r
169 if( uxQueueMessagesWaiting( xTaskQueue ) != 0 )
\r
174 if( ulStatus != pdFAIL )
\r
176 /* Increment a counter to show this task is still running without
\r
182 /*-----------------------------------------------------------*/
\r
184 portBASE_TYPE xIsQueueOverwriteTaskStillRunning( void )
\r
186 portBASE_TYPE xReturn;
\r
188 if( xISRTestStatus != pdPASS )
\r
192 else if( ulLoopCounter > 0 )
\r
198 /* The task has either stalled of discovered an error. */
\r
206 /*-----------------------------------------------------------*/
\r
208 void vQueueOverwritePeriodicISRDemo( void )
\r
210 static unsigned long ulCallCount = 0;
\r
211 const unsigned long ulTx1 = 10UL, ulTx2 = 20UL, ulNumberOfSwitchCases = 3UL;
\r
212 unsigned long ulRx;
\r
214 /* This function should be called from an interrupt, such as the tick hook
\r
215 function vApplicationTickHook(). */
\r
217 configASSERT( xISRQueue );
\r
219 switch( ulCallCount )
\r
222 /* The queue is empty. Write ulTx1 to the queue. In this demo the
\r
223 last parameter is not used because there are no tasks blocked on
\r
225 xQueueOverwriteFromISR( xISRQueue, &ulTx1, NULL );
\r
227 /* Peek the queue to check it holds the expected value. */
\r
228 xQueuePeekFromISR( xISRQueue, &ulRx );
\r
229 if( ulRx != ulTx1 )
\r
231 xISRTestStatus = pdFAIL;
\r
236 /* The queue already holds ulTx1. Overwrite the value in the queue
\r
238 xQueueOverwriteFromISR( xISRQueue, &ulTx2, NULL );
\r
242 /* Read from the queue to empty the queue again. The value read
\r
243 should be ulTx2. */
\r
244 xQueueReceiveFromISR( xISRQueue, &ulRx, NULL );
\r
246 if( ulRx != ulTx2 )
\r
248 xISRTestStatus = pdFAIL;
\r
253 /* Run the next case in the switch statement above next time this function
\r
257 if( ulCallCount >= ulNumberOfSwitchCases )
\r
259 /* Go back to the start. */
\r