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