2 FreeRTOS V8.0.0:rc1 - Copyright (C) 2014 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 * This demo application file demonstrates the use of queues to pass data
\r
68 * between co-routines.
\r
70 * N represents the number of 'fixed delay' co-routines that are created and
\r
71 * is set during initialisation.
\r
73 * N 'fixed delay' co-routines are created that just block for a fixed
\r
74 * period then post the number of an LED onto a queue. Each such co-routine
\r
75 * uses a different block period. A single 'flash' co-routine is also created
\r
76 * that blocks on the same queue, waiting for the number of the next LED it
\r
77 * should flash. Upon receiving a number it simply toggle the instructed LED
\r
78 * then blocks on the queue once more. In this manner each LED from LED 0 to
\r
79 * LED N-1 is caused to flash at a different rate.
\r
81 * The 'fixed delay' co-routines are created with co-routine priority 0. The
\r
82 * flash co-routine is created with co-routine priority 1. This means that
\r
83 * the queue should never contain more than a single item. This is because
\r
84 * posting to the queue will unblock the 'flash' co-routine, and as this has
\r
85 * a priority greater than the tasks posting to the queue it is guaranteed to
\r
86 * have emptied the queue and blocked once again before the queue can contain
\r
87 * any more date. An error is indicated if an attempt to post data to the
\r
88 * queue fails - indicating that the queue is already full.
\r
92 /* Scheduler includes. */
\r
93 #include "FreeRTOS.h"
\r
94 #include "croutine.h"
\r
97 /* Demo application includes. */
\r
98 #include "partest.h"
\r
99 #include "crflash.h"
\r
101 /* The queue should only need to be of length 1. See the description at the
\r
102 top of the file. */
\r
103 #define crfQUEUE_LENGTH 1
\r
105 #define crfFIXED_DELAY_PRIORITY 0
\r
106 #define crfFLASH_PRIORITY 1
\r
108 /* Only one flash co-routine is created so the index is not significant. */
\r
109 #define crfFLASH_INDEX 0
\r
111 /* Don't allow more than crfMAX_FLASH_TASKS 'fixed delay' co-routines to be
\r
113 #define crfMAX_FLASH_TASKS 8
\r
115 /* We don't want to block when posting to the queue. */
\r
116 #define crfPOSTING_BLOCK_TIME 0
\r
118 /* Added by MPi, this define is added in order to make the vParTestToggleLED()
\r
119 work. This basically differentiates the PDR09 from PDR00. 7-seg display LEDs connected
\r
120 to PDR09 (SEG1) are used by the prvFlashCoRoutine() and PDR00 (SEG2) are used by tasks. */
\r
121 #define PDR00_Offset 8
\r
124 * The 'fixed delay' co-routine as described at the top of the file.
\r
126 static void prvFixedDelayCoRoutine( CoRoutineHandle_t xHandle, unsigned portBASE_TYPE uxIndex );
\r
129 * The 'flash' co-routine as described at the top of the file.
\r
131 static void prvFlashCoRoutine( CoRoutineHandle_t xHandle, unsigned portBASE_TYPE uxIndex );
\r
133 /* The queue used to pass data between the 'fixed delay' co-routines and the
\r
134 'flash' co-routine. */
\r
135 static QueueHandle_t xFlashQueue;
\r
137 /* This will be set to pdFALSE if we detect an error. */
\r
138 static unsigned portBASE_TYPE uxCoRoutineFlashStatus = pdPASS;
\r
140 /*-----------------------------------------------------------*/
\r
143 * See the header file for details.
\r
145 void vStartFlashCoRoutines( unsigned portBASE_TYPE uxNumberToCreate )
\r
147 unsigned portBASE_TYPE uxIndex;
\r
149 if( uxNumberToCreate > crfMAX_FLASH_TASKS )
\r
151 uxNumberToCreate = crfMAX_FLASH_TASKS;
\r
154 /* Create the queue used to pass data between the co-routines. */
\r
155 xFlashQueue = xQueueCreate( crfQUEUE_LENGTH, sizeof( unsigned portBASE_TYPE ) );
\r
159 /* Create uxNumberToCreate 'fixed delay' co-routines. */
\r
160 for( uxIndex = 0; uxIndex < uxNumberToCreate; uxIndex++ )
\r
162 xCoRoutineCreate( prvFixedDelayCoRoutine, crfFIXED_DELAY_PRIORITY, uxIndex );
\r
165 /* Create the 'flash' co-routine. */
\r
166 xCoRoutineCreate( prvFlashCoRoutine, crfFLASH_PRIORITY, crfFLASH_INDEX );
\r
169 /*-----------------------------------------------------------*/
\r
171 static void prvFixedDelayCoRoutine( CoRoutineHandle_t xHandle, unsigned portBASE_TYPE uxIndex )
\r
173 /* Even though this is a co-routine the xResult variable does not need to be
\r
174 static as we do not need it to maintain its state between blocks. */
\r
175 signed portBASE_TYPE xResult;
\r
176 /* The uxIndex parameter of the co-routine function is used as an index into
\r
177 the xFlashRates array to obtain the delay period to use. */
\r
178 static const TickType_t xFlashRates[ crfMAX_FLASH_TASKS ] = { 150 / portTICK_PERIOD_MS,
\r
179 200 / portTICK_PERIOD_MS,
\r
180 250 / portTICK_PERIOD_MS,
\r
181 300 / portTICK_PERIOD_MS,
\r
182 350 / portTICK_PERIOD_MS,
\r
183 400 / portTICK_PERIOD_MS,
\r
184 450 / portTICK_PERIOD_MS,
\r
185 500 / portTICK_PERIOD_MS };
\r
187 /* Co-routines MUST start with a call to crSTART. */
\r
188 crSTART( xHandle );
\r
192 /* Post our uxIndex value onto the queue. This is used as the LED to
\r
194 crQUEUE_SEND( xHandle, xFlashQueue, ( void * ) &uxIndex, crfPOSTING_BLOCK_TIME, &xResult );
\r
196 if( xResult != pdPASS )
\r
198 /* For the reasons stated at the top of the file we should always
\r
199 find that we can post to the queue. If we could not then an error
\r
201 uxCoRoutineFlashStatus = pdFAIL;
\r
204 crDELAY( xHandle, xFlashRates[ uxIndex ] );
\r
207 /* Co-routines MUST end with a call to crEND. */
\r
210 /*-----------------------------------------------------------*/
\r
212 static void prvFlashCoRoutine( CoRoutineHandle_t xHandle, unsigned portBASE_TYPE uxIndex )
\r
214 /* Even though this is a co-routine the variable do not need to be
\r
215 static as we do not need it to maintain their state between blocks. */
\r
216 signed portBASE_TYPE xResult;
\r
217 unsigned portBASE_TYPE uxLEDToFlash;
\r
219 /* Co-routines MUST start with a call to crSTART. */
\r
220 crSTART( xHandle );
\r
225 /* Block to wait for the number of the LED to flash. */
\r
226 crQUEUE_RECEIVE( xHandle, xFlashQueue, &uxLEDToFlash, portMAX_DELAY, &xResult );
\r
228 if( xResult != pdPASS )
\r
230 /* We would not expect to wake unless we received something. */
\r
231 uxCoRoutineFlashStatus = pdFAIL;
\r
235 /* We received the number of an LED to flash - flash it! */
\r
236 /* Added by MPi, PDR00_Offset is added in order to make the
\r
237 vParTestToggleLED() work. */
\r
238 vParTestToggleLED( uxLEDToFlash + PDR00_Offset );
\r
242 /* Co-routines MUST end with a call to crEND. */
\r
245 /*-----------------------------------------------------------*/
\r
247 portBASE_TYPE xAreFlashCoRoutinesStillRunning( void )
\r
249 /* Return pdPASS or pdFAIL depending on whether an error has been detected
\r
251 return uxCoRoutineFlashStatus;
\r