2 FreeRTOS V7.5.3 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
28 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
29 >>! the source code for proprietary components outside of the FreeRTOS
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
67 * Basic task to demonstrate the xQueueOverwrite() function. See the comments
\r
68 * in the function itself.
\r
71 /* Scheduler include files. */
\r
72 #include "FreeRTOS.h"
\r
76 /* Demo program include files. */
\r
77 #include "QueueOverwrite.h"
\r
79 /* A block time of 0 just means "don't block". */
\r
80 #define qoDONT_BLOCK 0
\r
82 /* Number of times to overwrite the value in the queue. */
\r
85 /* The task that uses the queue. */
\r
86 static void prvQueueOverwriteTask( void *pvParameters );
\r
88 /* Variable that is incremented on each loop of prvQueueOverwriteTask() provided
\r
89 prvQueueOverwriteTask() has not found any errors. */
\r
90 static unsigned long ulLoopCounter = 0;
\r
92 /* Set to pdFALSE if an error is discovered by the
\r
93 vQueueOverwritePeriodicISRDemo() function. */
\r
94 static portBASE_TYPE xISRTestStatus = pdPASS;
\r
96 /* The queue that is accessed from the ISR. The queue accessed by the task is
\r
97 created inside the task itself. */
\r
98 static xQueueHandle xISRQueue = NULL;
\r
100 /*-----------------------------------------------------------*/
\r
102 void vStartQueueOverwriteTask( unsigned portBASE_TYPE uxPriority )
\r
104 const unsigned portBASE_TYPE uxQueueLength = 1;
\r
106 /* Create the queue used by the ISR. xQueueOverwriteFromISR() should only
\r
107 be used on queues that have a length of 1. */
\r
108 xISRQueue = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( unsigned long ) );
\r
110 /* Create the test task. The queue used by the test task is created inside
\r
111 the task itself. */
\r
112 xTaskCreate( prvQueueOverwriteTask, ( signed char * ) "QOver", configMINIMAL_STACK_SIZE, NULL, uxPriority, ( xTaskHandle * ) NULL );
\r
114 /*-----------------------------------------------------------*/
\r
116 static void prvQueueOverwriteTask( void *pvParameters )
\r
118 xQueueHandle xTaskQueue;
\r
119 const unsigned portBASE_TYPE uxQueueLength = 1;
\r
120 unsigned long ulValue, ulStatus = pdPASS, x;
\r
122 /* The parameter is not used. */
\r
123 ( void ) pvParameters;
\r
125 /* Create the queue. xQueueOverwrite() should only be used on queues that
\r
126 have a length of 1. */
\r
127 xTaskQueue = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( unsigned long ) );
\r
128 configASSERT( xTaskQueue );
\r
132 /* The queue is empty. Writing to the queue then reading from the queue
\r
133 should return the item written. */
\r
135 xQueueOverwrite( xTaskQueue, &ulValue );
\r
138 xQueueReceive( xTaskQueue, &ulValue, qoDONT_BLOCK );
\r
140 if( ulValue != 10 )
\r
145 /* Now try writing to the queue several times. Each time the value
\r
146 in the queue should get overwritten. */
\r
147 for( x = 0; x < qoLOOPS; x++ )
\r
149 /* Write to the queue. */
\r
150 xQueueOverwrite( xTaskQueue, &x );
\r
152 /* Check the value in the queue is that written, even though the
\r
153 queue was not necessarily empty. */
\r
154 xQueuePeek( xTaskQueue, &ulValue, qoDONT_BLOCK );
\r
160 /* There should always be one item in the queue. */
\r
161 if( uxQueueMessagesWaiting( xTaskQueue ) != uxQueueLength )
\r
167 /* Empty the queue again. */
\r
168 xQueueReceive( xTaskQueue, &ulValue, qoDONT_BLOCK );
\r
170 if( uxQueueMessagesWaiting( xTaskQueue ) != 0 )
\r
175 if( ulStatus != pdFAIL )
\r
177 /* Increment a counter to show this task is still running without
\r
182 #if( configUSE_PREEMPTION == 0 )
\r
187 /*-----------------------------------------------------------*/
\r
189 portBASE_TYPE xIsQueueOverwriteTaskStillRunning( void )
\r
191 portBASE_TYPE xReturn;
\r
193 if( xISRTestStatus != pdPASS )
\r
197 else if( ulLoopCounter > 0 )
\r
203 /* The task has either stalled of discovered an error. */
\r
211 /*-----------------------------------------------------------*/
\r
213 void vQueueOverwritePeriodicISRDemo( void )
\r
215 static unsigned long ulCallCount = 0;
\r
216 const unsigned long ulTx1 = 10UL, ulTx2 = 20UL, ulNumberOfSwitchCases = 3UL;
\r
217 unsigned long ulRx;
\r
219 /* This function should be called from an interrupt, such as the tick hook
\r
220 function vApplicationTickHook(). */
\r
222 configASSERT( xISRQueue );
\r
224 switch( ulCallCount )
\r
227 /* The queue is empty. Write ulTx1 to the queue. In this demo the
\r
228 last parameter is not used because there are no tasks blocked on
\r
230 xQueueOverwriteFromISR( xISRQueue, &ulTx1, NULL );
\r
232 /* Peek the queue to check it holds the expected value. */
\r
233 xQueuePeekFromISR( xISRQueue, &ulRx );
\r
234 if( ulRx != ulTx1 )
\r
236 xISRTestStatus = pdFAIL;
\r
241 /* The queue already holds ulTx1. Overwrite the value in the queue
\r
243 xQueueOverwriteFromISR( xISRQueue, &ulTx2, NULL );
\r
247 /* Read from the queue to empty the queue again. The value read
\r
248 should be ulTx2. */
\r
249 xQueueReceiveFromISR( xISRQueue, &ulRx, NULL );
\r
251 if( ulRx != ulTx2 )
\r
253 xISRTestStatus = pdFAIL;
\r
258 /* Run the next case in the switch statement above next time this function
\r
262 if( ulCallCount >= ulNumberOfSwitchCases )
\r
264 /* Go back to the start. */
\r