2 FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\r
13 * Purchasing FreeRTOS documentation will not only help you, by *
\r
14 * ensuring you get running as quickly as possible and with an *
\r
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
16 * the FreeRTOS project to continue with its mission of providing *
\r
17 * professional grade, cross platform, de facto standard solutions *
\r
18 * for microcontrollers - completely free of charge! *
\r
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\r
29 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
30 the terms of the GNU General Public License (version 2) as published by the
\r
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
33 >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
\r
34 distribute a combined work that includes FreeRTOS without being obliged to
\r
35 provide the source code for proprietary components outside of the FreeRTOS
\r
38 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
39 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
40 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
41 details. You should have received a copy of the GNU General Public License
\r
42 and the FreeRTOS license exception along with FreeRTOS; if not itcan be
\r
43 viewed here: http://www.freertos.org/a00114.html and also obtained by
\r
44 writing to Real Time Engineers Ltd., contact details for whom are available
\r
45 on the FreeRTOS WEB site.
\r
49 ***************************************************************************
\r
51 * Having a problem? Start by reading the FAQ "My application does *
\r
52 * not run, what could be wrong?" *
\r
54 * http://www.FreeRTOS.org/FAQHelp.html *
\r
56 ***************************************************************************
\r
59 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
60 license and Real Time Engineers Ltd. contact details.
\r
62 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
63 including FreeRTOS+Trace - an indispensable productivity tool, and our new
\r
64 fully thread aware and reentrant UDP/IP stack.
\r
66 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
67 Integrity Systems, who sell the code with commercial support,
\r
68 indemnification and middleware, under the OpenRTOS brand.
\r
70 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
71 engineered and independently SIL3 certified version for use in safety and
\r
72 mission critical applications that require provable dependability.
\r
76 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
77 * documentation provides more details of the standard demo application tasks.
\r
78 * In addition to the standard demo tasks, the following tasks and tests are
\r
79 * defined and/or created within this file:
\r
81 * "Check" task - This only executes every three seconds but has a high priority
\r
82 * to ensure it gets processor time. Its main function is to check that all the
\r
83 * standard demo tasks are still operational. If everything is running as
\r
84 * expected then the check task will toggle an LED every 3 seconds. An error
\r
85 * being discovered in any task will cause the toggle rate to increase to 500ms.
\r
87 * "Reg test" tasks - These fill the registers with known values, then check
\r
88 * that each register still contains its expected value. Each task uses
\r
89 * different values. The tasks run with very low priority so get preempted very
\r
90 * frequently. A register containing an unexpected value is indicative of an
\r
91 * error in the context switching mechanism.
\r
95 /* Standard include files. */
\r
99 /* Scheduler include files. */
\r
100 #include "FreeRTOS.h"
\r
103 /* Demo file headers. */
\r
104 #include <intrinsics.h>
\r
105 #include "BlockQ.h"
\r
108 #include "partest.h"
\r
109 #include "semtest.h"
\r
111 #include "GenQTest.h"
\r
113 #include "recmutex.h"
\r
114 #include "comtest2.h"
\r
117 * Priority definitions for most of the tasks in the demo application. Some
\r
118 * tasks just use the idle priority.
\r
120 #define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
121 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
122 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
123 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
124 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
125 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
126 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
127 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
128 #define mainCOMTEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
130 /* Passed into the check task just as a test that the parameter passing
\r
131 mechanism is working correctly. */
\r
132 #define mainCHECK_PARAMETER ( ( void * ) 0x12345678 )
\r
134 /* The period between executions of the check task. */
\r
135 #define mainNO_ERROR_DELAY ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
136 #define mainERROR_DELAY ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
138 /* There are no spare LEDs for the comtest tasks, so this is just set to an
\r
140 #define mainCOMTEST_LED ( 4 )
\r
142 /* The baud rate used by the comtest task. */
\r
143 #define mainBAUD_RATE ( 9600 )
\r
145 /*-----------------------------------------------------------*/
\r
147 /* The implementation of the 'check' task as described at the top of this file. */
\r
148 static void prvCheckTask( void *pvParameters );
\r
150 /* Just sets up the LED outputs. Most generic setup is done in
\r
151 __low_level_init(). */
\r
152 static void prvSetupHardware( void );
\r
154 /* The RegTest functions as described at the top of this file. */
\r
155 extern void vRegTest1( void *pvParameters );
\r
156 extern void vRegTest2( void *pvParameters );
\r
158 /* A variable that will get set to fail if a RegTest task finds an error. The
\r
159 variable is inspected by the 'Check' task. */
\r
160 static volatile portLONG lRegTestStatus = pdPASS;
\r
162 /*-----------------------------------------------------------*/
\r
164 /* Create all the demo tasks then start the scheduler. */
\r
167 /* Just sets up the LED outputs. */
\r
168 prvSetupHardware();
\r
170 /* Standard demo tasks. */
\r
171 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
172 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
173 vStartQueuePeekTasks();
\r
175 /* Create the check task as described at the top of this file. */
\r
176 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, mainCHECK_PARAMETER, mainCHECK_TASK_PRIORITY, NULL );
\r
178 /* Create the RegTest tasks as described at the top of this file. */
\r
179 xTaskCreate( vRegTest1, "Reg1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
180 xTaskCreate( vRegTest2, "Reg2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
182 #ifdef __IAR_V850ES_Fx3__
\r
184 /* The extra IO required for the com test and led flashing tasks is only
\r
185 available on the application board, not the target boards. */
\r
186 vAltStartComTestTasks( mainCOMTEST_PRIORITY, mainBAUD_RATE, mainCOMTEST_LED );
\r
187 vStartLEDFlashTasks( mainFLASH_PRIORITY );
\r
189 /* The Fx3 also has enough RAM to run loads more tasks. */
\r
190 vStartRecursiveMutexTasks();
\r
191 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
192 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
196 /* The suicide tasks must be created last as they need to know how many
\r
197 tasks were running prior to their creation in order to ascertain whether
\r
198 or not the correct/expected number of tasks are running at any given time. */
\r
199 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
201 /* Start the scheduler. */
\r
202 vTaskStartScheduler();
\r
204 /* If this line is reached then vTaskStartScheduler() returned because there
\r
205 was insufficient heap memory remaining for the idle task to be created. */
\r
208 /*-----------------------------------------------------------*/
\r
210 static void prvCheckTask( void *pvParameters )
\r
212 portTickType xDelayPeriod = mainNO_ERROR_DELAY, xLastWakeTime;
\r
213 unsigned portBASE_TYPE uxLEDToUse = 0;
\r
215 /* Ensure parameter is passed in correctly. */
\r
216 if( pvParameters != mainCHECK_PARAMETER )
\r
218 xDelayPeriod = mainERROR_DELAY;
\r
221 /* Initialise xLastWakeTime before it is used. After this point it is not
\r
222 written to directly. */
\r
223 xLastWakeTime = xTaskGetTickCount();
\r
225 /* Cycle for ever, delaying then checking all the other tasks are still
\r
226 operating without error. */
\r
229 /* Wait until it is time to check all the other tasks again. */
\r
230 vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );
\r
232 if( lRegTestStatus != pdPASS )
\r
234 xDelayPeriod = mainERROR_DELAY;
\r
237 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
239 xDelayPeriod = mainERROR_DELAY;
\r
242 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
244 xDelayPeriod = mainERROR_DELAY;
\r
247 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
249 xDelayPeriod = mainERROR_DELAY;
\r
252 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
254 xDelayPeriod = mainERROR_DELAY;
\r
257 /* The Fx3 runs more tasks, so more checks are performed. */
\r
258 #ifdef __IAR_V850ES_Fx3__
\r
260 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
262 xDelayPeriod = mainERROR_DELAY;
\r
265 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
267 xDelayPeriod = mainERROR_DELAY;
\r
270 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
272 xDelayPeriod = mainERROR_DELAY;
\r
275 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
277 xDelayPeriod = mainERROR_DELAY;
\r
280 /* The application board has more LEDs and uses the flash tasks
\r
281 so the check task instead uses LED3 as LED3 is still spare. */
\r
286 /* Toggle the LED. The toggle rate will depend on whether or not an
\r
287 error has been found in any tasks. */
\r
288 vParTestToggleLED( uxLEDToUse );
\r
291 /*-----------------------------------------------------------*/
\r
293 static void prvSetupHardware( void )
\r
295 /* Setup the LED outputs. */
\r
296 vParTestInitialise();
\r
298 /* Any additional hardware configuration can be added here. */
\r
300 /*-----------------------------------------------------------*/
\r
302 void vApplicationStackOverflowHook( void )
\r
304 /* This will be called if a task overflows its stack. pxCurrentTCB
\r
305 can be inspected to see which is the offending task. */
\r
308 /*-----------------------------------------------------------*/
\r
310 void vRegTestFailed( void )
\r
312 /* Called by the RegTest tasks if an error is found. lRegTestStatus is
\r
313 inspected by the check task. */
\r
314 lRegTestStatus = pdFAIL;
\r
316 /* Do not return from here as the reg test tasks clobber all registers so
\r
317 function calls may not function correctly. */
\r