2 FreeRTOS V8.2.3 - Copyright (C) 2015 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
71 * Basic task to demonstrate the xQueueOverwrite() function. See the comments
\r
72 * in the function itself.
\r
75 /* Scheduler include files. */
\r
76 #include "FreeRTOS.h"
\r
80 /* Demo program include files. */
\r
81 #include "QueueOverwrite.h"
\r
83 /* A block time of 0 just means "don't block". */
\r
84 #define qoDONT_BLOCK 0
\r
86 /* Number of times to overwrite the value in the queue. */
\r
89 /* The task that uses the queue. */
\r
90 static void prvQueueOverwriteTask( void *pvParameters );
\r
92 /* Variable that is incremented on each loop of prvQueueOverwriteTask() provided
\r
93 prvQueueOverwriteTask() has not found any errors. */
\r
94 static uint32_t ulLoopCounter = 0;
\r
96 /* Set to pdFALSE if an error is discovered by the
\r
97 vQueueOverwritePeriodicISRDemo() function. */
\r
98 static BaseType_t xISRTestStatus = pdPASS;
\r
100 /* The queue that is accessed from the ISR. The queue accessed by the task is
\r
101 created inside the task itself. */
\r
102 static QueueHandle_t xISRQueue = NULL;
\r
104 /*-----------------------------------------------------------*/
\r
106 void vStartQueueOverwriteTask( UBaseType_t uxPriority )
\r
108 const UBaseType_t uxQueueLength = 1;
\r
110 /* Create the queue used by the ISR. xQueueOverwriteFromISR() should only
\r
111 be used on queues that have a length of 1. */
\r
112 xISRQueue = xQueueCreate( uxQueueLength, ( UBaseType_t ) sizeof( uint32_t ) );
\r
114 /* Create the test task. The queue used by the test task is created inside
\r
115 the task itself. */
\r
116 xTaskCreate( prvQueueOverwriteTask, "QOver", configMINIMAL_STACK_SIZE, NULL, uxPriority, ( TaskHandle_t * ) NULL );
\r
118 /*-----------------------------------------------------------*/
\r
120 static void prvQueueOverwriteTask( void *pvParameters )
\r
122 QueueHandle_t xTaskQueue;
\r
123 const UBaseType_t uxQueueLength = 1;
\r
124 uint32_t ulValue, ulStatus = pdPASS, x;
\r
126 /* The parameter is not used. */
\r
127 ( void ) pvParameters;
\r
129 /* Create the queue. xQueueOverwrite() should only be used on queues that
\r
130 have a length of 1. */
\r
131 xTaskQueue = xQueueCreate( uxQueueLength, ( UBaseType_t ) sizeof( uint32_t ) );
\r
132 configASSERT( xTaskQueue );
\r
136 /* The queue is empty. Writing to the queue then reading from the queue
\r
137 should return the item written. */
\r
139 xQueueOverwrite( xTaskQueue, &ulValue );
\r
142 xQueueReceive( xTaskQueue, &ulValue, qoDONT_BLOCK );
\r
144 if( ulValue != 10 )
\r
149 /* Now try writing to the queue several times. Each time the value
\r
150 in the queue should get overwritten. */
\r
151 for( x = 0; x < qoLOOPS; x++ )
\r
153 /* Write to the queue. */
\r
154 xQueueOverwrite( xTaskQueue, &x );
\r
156 /* Check the value in the queue is that written, even though the
\r
157 queue was not necessarily empty. */
\r
158 xQueuePeek( xTaskQueue, &ulValue, qoDONT_BLOCK );
\r
164 /* There should always be one item in the queue. */
\r
165 if( uxQueueMessagesWaiting( xTaskQueue ) != uxQueueLength )
\r
171 /* Empty the queue again. */
\r
172 xQueueReceive( xTaskQueue, &ulValue, qoDONT_BLOCK );
\r
174 if( uxQueueMessagesWaiting( xTaskQueue ) != 0 )
\r
179 if( ulStatus != pdFAIL )
\r
181 /* Increment a counter to show this task is still running without
\r
186 #if( configUSE_PREEMPTION == 0 )
\r
191 /*-----------------------------------------------------------*/
\r
193 BaseType_t xIsQueueOverwriteTaskStillRunning( void )
\r
195 BaseType_t xReturn;
\r
197 if( xISRTestStatus != pdPASS )
\r
201 else if( ulLoopCounter > 0 )
\r
207 /* The task has either stalled of discovered an error. */
\r
215 /*-----------------------------------------------------------*/
\r
217 void vQueueOverwritePeriodicISRDemo( void )
\r
219 static uint32_t ulCallCount = 0;
\r
220 const uint32_t ulTx1 = 10UL, ulTx2 = 20UL, ulNumberOfSwitchCases = 3UL;
\r
223 /* This function should be called from an interrupt, such as the tick hook
\r
224 function vApplicationTickHook(). */
\r
226 configASSERT( xISRQueue );
\r
228 switch( ulCallCount )
\r
231 /* The queue is empty. Write ulTx1 to the queue. In this demo the
\r
232 last parameter is not used because there are no tasks blocked on
\r
234 xQueueOverwriteFromISR( xISRQueue, &ulTx1, NULL );
\r
236 /* Peek the queue to check it holds the expected value. */
\r
237 xQueuePeekFromISR( xISRQueue, &ulRx );
\r
238 if( ulRx != ulTx1 )
\r
240 xISRTestStatus = pdFAIL;
\r
245 /* The queue already holds ulTx1. Overwrite the value in the queue
\r
247 xQueueOverwriteFromISR( xISRQueue, &ulTx2, NULL );
\r
251 /* Read from the queue to empty the queue again. The value read
\r
252 should be ulTx2. */
\r
253 xQueueReceiveFromISR( xISRQueue, &ulRx, NULL );
\r
255 if( ulRx != ulTx2 )
\r
257 xISRTestStatus = pdFAIL;
\r
262 /* Run the next case in the switch statement above next time this function
\r
266 if( ulCallCount >= ulNumberOfSwitchCases )
\r
268 /* Go back to the start. */
\r