2 FreeRTOS V8.2.0rc1 - Copyright (C) 2014 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 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
14 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
15 >>! obliged to provide the source code for proprietary components !<<
\r
16 >>! outside of the FreeRTOS kernel. !<<
\r
18 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
19 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
20 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
21 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * Having a problem? Start by reading the FAQ "My application does *
\r
28 * not run, what could be wrong?". Have you defined configASSERT()? *
\r
30 * http://www.FreeRTOS.org/FAQHelp.html *
\r
32 ***************************************************************************
\r
34 ***************************************************************************
\r
36 * FreeRTOS provides completely free yet professionally developed, *
\r
37 * robust, strictly quality controlled, supported, and cross *
\r
38 * platform software that is more than just the market leader, it *
\r
39 * is the industry's de facto standard. *
\r
41 * Help yourself get started quickly while simultaneously helping *
\r
42 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
43 * tutorial book, reference manual, or both: *
\r
44 * http://www.FreeRTOS.org/Documentation *
\r
46 ***************************************************************************
\r
48 ***************************************************************************
\r
50 * Investing in training allows your team to be as productive as *
\r
51 * possible as early as possible, lowering your overall development *
\r
52 * cost, and enabling you to bring a more robust product to market *
\r
53 * earlier than would otherwise be possible. Richard Barry is both *
\r
54 * the architect and key author of FreeRTOS, and so also the world's *
\r
55 * leading authority on what is the world's most popular real time *
\r
56 * kernel for deeply embedded MCU designs. Obtaining your training *
\r
57 * from Richard ensures your team will gain directly from his in-depth *
\r
58 * product knowledge and years of usage experience. Contact Real Time *
\r
59 * Engineers Ltd to enquire about the FreeRTOS Masterclass, presented *
\r
60 * by Richard Barry: http://www.FreeRTOS.org/contact
\r
62 ***************************************************************************
\r
64 ***************************************************************************
\r
66 * You are receiving this top quality software for free. Please play *
\r
67 * fair and reciprocate by reporting any suspected issues and *
\r
68 * participating in the community forum: *
\r
69 * http://www.FreeRTOS.org/support *
\r
73 ***************************************************************************
\r
75 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
76 license and Real Time Engineers Ltd. contact details.
\r
78 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
79 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
80 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
82 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
83 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
85 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
86 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
87 licenses offer ticketed support, indemnification and commercial middleware.
\r
89 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
90 engineered and independently SIL3 certified version for use in safety and
\r
91 mission critical applications that require provable dependability.
\r
97 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
98 * documentation provides more details of the standard demo application tasks.
\r
99 * In addition to the standard demo tasks, the following tasks and tests are
\r
100 * defined and/or created within this file:
\r
102 * "Check" task - This only executes every three seconds but has a high priority
\r
103 * to ensure it gets processor time. Its main function is to check that all the
\r
104 * standard demo tasks are still operational. If everything is running as
\r
105 * expected then the check task will toggle an LED every 3 seconds. An error
\r
106 * being discovered in any task will cause the toggle rate to increase to 500ms.
\r
108 * "Reg test" tasks - These fill the registers with known values, then check
\r
109 * that each register still contains its expected value. Each task uses
\r
110 * different values. The tasks run with very low priority so get preempted very
\r
111 * frequently. A register containing an unexpected value is indicative of an
\r
112 * error in the context switching mechanism.
\r
116 /* Standard include files. */
\r
117 #include <stdlib.h>
\r
118 #include <string.h>
\r
120 /* Scheduler include files. */
\r
121 #include "FreeRTOS.h"
\r
124 /* Demo file headers. */
\r
125 #include <intrinsics.h>
\r
126 #include "BlockQ.h"
\r
129 #include "partest.h"
\r
130 #include "semtest.h"
\r
132 #include "GenQTest.h"
\r
134 #include "recmutex.h"
\r
135 #include "comtest2.h"
\r
138 * Priority definitions for most of the tasks in the demo application. Some
\r
139 * tasks just use the idle priority.
\r
141 #define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
142 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
143 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
144 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
145 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
146 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
147 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
148 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
149 #define mainCOMTEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
151 /* Passed into the check task just as a test that the parameter passing
\r
152 mechanism is working correctly. */
\r
153 #define mainCHECK_PARAMETER ( ( void * ) 0x12345678 )
\r
155 /* The period between executions of the check task. */
\r
156 #define mainNO_ERROR_DELAY ( ( TickType_t ) 3000 / portTICK_PERIOD_MS )
\r
157 #define mainERROR_DELAY ( ( TickType_t ) 500 / portTICK_PERIOD_MS )
\r
159 /* There are no spare LEDs for the comtest tasks, so this is just set to an
\r
161 #define mainCOMTEST_LED ( 4 )
\r
163 /* The baud rate used by the comtest task. */
\r
164 #define mainBAUD_RATE ( 9600 )
\r
166 /*-----------------------------------------------------------*/
\r
168 /* The implementation of the 'check' task as described at the top of this file. */
\r
169 static void prvCheckTask( void *pvParameters );
\r
171 /* Just sets up the LED outputs. Most generic setup is done in
\r
172 __low_level_init(). */
\r
173 static void prvSetupHardware( void );
\r
175 /* The RegTest functions as described at the top of this file. */
\r
176 extern void vRegTest1( void *pvParameters );
\r
177 extern void vRegTest2( void *pvParameters );
\r
179 /* A variable that will get set to fail if a RegTest task finds an error. The
\r
180 variable is inspected by the 'Check' task. */
\r
181 static volatile long lRegTestStatus = pdPASS;
\r
183 /*-----------------------------------------------------------*/
\r
185 /* Create all the demo tasks then start the scheduler. */
\r
188 /* Just sets up the LED outputs. */
\r
189 prvSetupHardware();
\r
191 /* Standard demo tasks. */
\r
192 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
193 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
194 vStartQueuePeekTasks();
\r
196 /* Create the check task as described at the top of this file. */
\r
197 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, mainCHECK_PARAMETER, mainCHECK_TASK_PRIORITY, NULL );
\r
199 /* Create the RegTest tasks as described at the top of this file. */
\r
200 xTaskCreate( vRegTest1, "Reg1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
201 xTaskCreate( vRegTest2, "Reg2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
203 #ifdef __IAR_V850ES_Fx3__
\r
205 /* The extra IO required for the com test and led flashing tasks is only
\r
206 available on the application board, not the target boards. */
\r
207 vAltStartComTestTasks( mainCOMTEST_PRIORITY, mainBAUD_RATE, mainCOMTEST_LED );
\r
208 vStartLEDFlashTasks( mainFLASH_PRIORITY );
\r
210 /* The Fx3 also has enough RAM to run loads more tasks. */
\r
211 vStartRecursiveMutexTasks();
\r
212 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
213 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
217 /* The suicide tasks must be created last as they need to know how many
\r
218 tasks were running prior to their creation in order to ascertain whether
\r
219 or not the correct/expected number of tasks are running at any given time. */
\r
220 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
222 /* Start the scheduler. */
\r
223 vTaskStartScheduler();
\r
225 /* If this line is reached then vTaskStartScheduler() returned because there
\r
226 was insufficient heap memory remaining for the idle task to be created. */
\r
229 /*-----------------------------------------------------------*/
\r
231 static void prvCheckTask( void *pvParameters )
\r
233 TickType_t xDelayPeriod = mainNO_ERROR_DELAY, xLastWakeTime;
\r
234 unsigned portBASE_TYPE uxLEDToUse = 0;
\r
236 /* Ensure parameter is passed in correctly. */
\r
237 if( pvParameters != mainCHECK_PARAMETER )
\r
239 xDelayPeriod = mainERROR_DELAY;
\r
242 /* Initialise xLastWakeTime before it is used. After this point it is not
\r
243 written to directly. */
\r
244 xLastWakeTime = xTaskGetTickCount();
\r
246 /* Cycle for ever, delaying then checking all the other tasks are still
\r
247 operating without error. */
\r
250 /* Wait until it is time to check all the other tasks again. */
\r
251 vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );
\r
253 if( lRegTestStatus != pdPASS )
\r
255 xDelayPeriod = mainERROR_DELAY;
\r
258 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
260 xDelayPeriod = mainERROR_DELAY;
\r
263 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
265 xDelayPeriod = mainERROR_DELAY;
\r
268 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
270 xDelayPeriod = mainERROR_DELAY;
\r
273 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
275 xDelayPeriod = mainERROR_DELAY;
\r
278 /* The Fx3 runs more tasks, so more checks are performed. */
\r
279 #ifdef __IAR_V850ES_Fx3__
\r
281 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
283 xDelayPeriod = mainERROR_DELAY;
\r
286 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
288 xDelayPeriod = mainERROR_DELAY;
\r
291 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
293 xDelayPeriod = mainERROR_DELAY;
\r
296 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
298 xDelayPeriod = mainERROR_DELAY;
\r
301 /* The application board has more LEDs and uses the flash tasks
\r
302 so the check task instead uses LED3 as LED3 is still spare. */
\r
307 /* Toggle the LED. The toggle rate will depend on whether or not an
\r
308 error has been found in any tasks. */
\r
309 vParTestToggleLED( uxLEDToUse );
\r
312 /*-----------------------------------------------------------*/
\r
314 static void prvSetupHardware( void )
\r
316 /* Setup the LED outputs. */
\r
317 vParTestInitialise();
\r
319 /* Any additional hardware configuration can be added here. */
\r
321 /*-----------------------------------------------------------*/
\r
323 void vApplicationStackOverflowHook( void )
\r
325 /* This will be called if a task overflows its stack. pxCurrentTCB
\r
326 can be inspected to see which is the offending task. */
\r
329 /*-----------------------------------------------------------*/
\r
331 void vRegTestFailed( void )
\r
333 /* Called by the RegTest tasks if an error is found. lRegTestStatus is
\r
334 inspected by the check task. */
\r
335 lRegTestStatus = pdFAIL;
\r
337 /* Do not return from here as the reg test tasks clobber all registers so
\r
338 function calls may not function correctly. */
\r