2 FreeRTOS V7.3.0 - Copyright (C) 2012 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
32 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
33 distribute a combined work that includes FreeRTOS without being obliged to
\r
34 provide the source code for proprietary components outside of the FreeRTOS
\r
35 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
36 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
37 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
38 more details. You should have received a copy of the GNU General Public
\r
39 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
40 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
41 by writing to Richard Barry, contact details for whom are available on the
\r
46 ***************************************************************************
\r
48 * Having a problem? Start by reading the FAQ "My application does *
\r
49 * not run, what could be wrong?" *
\r
51 * http://www.FreeRTOS.org/FAQHelp.html *
\r
53 ***************************************************************************
\r
56 http://www.FreeRTOS.org - Documentation, training, latest versions, license
\r
57 and contact details.
\r
59 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
60 including FreeRTOS+Trace - an indispensable productivity tool.
\r
62 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
63 the code with commercial support, indemnification, and middleware, under
\r
64 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
65 provide a safety engineered and independently SIL3 certified version under
\r
66 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
70 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
71 * documentation provides more details of the standard demo application tasks.
\r
72 * In addition to the standard demo tasks, the following tasks and tests are
\r
73 * defined and/or created within this file:
\r
75 * "Check" task - This only executes every three seconds but has a high priority
\r
76 * to ensure it gets processor time. Its main function is to check that all the
\r
77 * standard demo tasks are still operational. If everything is running as
\r
78 * expected then the check task will toggle an LED every 3 seconds. An error
\r
79 * being discovered in any task will cause the toggle rate to increase to 500ms.
\r
81 * "Reg test" tasks - These fill the registers with known values, then check
\r
82 * that each register still contains its expected value. Each task uses
\r
83 * different values. The tasks run with very low priority so get preempted very
\r
84 * frequently. A register containing an unexpected value is indicative of an
\r
85 * error in the context switching mechanism.
\r
89 /* Standard include files. */
\r
93 /* Scheduler include files. */
\r
94 #include "FreeRTOS.h"
\r
97 /* Demo file headers. */
\r
98 #include <intrinsics.h>
\r
102 #include "partest.h"
\r
103 #include "semtest.h"
\r
105 #include "GenQTest.h"
\r
107 #include "recmutex.h"
\r
108 #include "comtest2.h"
\r
111 * Priority definitions for most of the tasks in the demo application. Some
\r
112 * tasks just use the idle priority.
\r
114 #define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
115 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
116 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
117 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
118 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
119 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
120 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
121 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
122 #define mainCOMTEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
124 /* Passed into the check task just as a test that the parameter passing
\r
125 mechanism is working correctly. */
\r
126 #define mainCHECK_PARAMETER ( ( void * ) 0x12345678 )
\r
128 /* The period between executions of the check task. */
\r
129 #define mainNO_ERROR_DELAY ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
130 #define mainERROR_DELAY ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
132 /* There are no spare LEDs for the comtest tasks, so this is just set to an
\r
134 #define mainCOMTEST_LED ( 4 )
\r
136 /* The baud rate used by the comtest task. */
\r
137 #define mainBAUD_RATE ( 9600 )
\r
139 /*-----------------------------------------------------------*/
\r
141 /* The implementation of the 'check' task as described at the top of this file. */
\r
142 static void prvCheckTask( void *pvParameters );
\r
144 /* Just sets up the LED outputs. Most generic setup is done in
\r
145 __low_level_init(). */
\r
146 static void prvSetupHardware( void );
\r
148 /* The RegTest functions as described at the top of this file. */
\r
149 extern void vRegTest1( void *pvParameters );
\r
150 extern void vRegTest2( void *pvParameters );
\r
152 /* A variable that will get set to fail if a RegTest task finds an error. The
\r
153 variable is inspected by the 'Check' task. */
\r
154 static volatile portLONG lRegTestStatus = pdPASS;
\r
156 /*-----------------------------------------------------------*/
\r
158 /* Create all the demo tasks then start the scheduler. */
\r
161 /* Just sets up the LED outputs. */
\r
162 prvSetupHardware();
\r
164 /* Standard demo tasks. */
\r
165 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
166 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
167 vStartQueuePeekTasks();
\r
169 /* Create the check task as described at the top of this file. */
\r
170 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, mainCHECK_PARAMETER, mainCHECK_TASK_PRIORITY, NULL );
\r
172 /* Create the RegTest tasks as described at the top of this file. */
\r
173 xTaskCreate( vRegTest1, "Reg1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
174 xTaskCreate( vRegTest2, "Reg2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
176 #ifdef __IAR_V850ES_Fx3__
\r
178 /* The extra IO required for the com test and led flashing tasks is only
\r
179 available on the application board, not the target boards. */
\r
180 vAltStartComTestTasks( mainCOMTEST_PRIORITY, mainBAUD_RATE, mainCOMTEST_LED );
\r
181 vStartLEDFlashTasks( mainFLASH_PRIORITY );
\r
183 /* The Fx3 also has enough RAM to run loads more tasks. */
\r
184 vStartRecursiveMutexTasks();
\r
185 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
186 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
190 /* The suicide tasks must be created last as they need to know how many
\r
191 tasks were running prior to their creation in order to ascertain whether
\r
192 or not the correct/expected number of tasks are running at any given time. */
\r
193 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
195 /* Start the scheduler. */
\r
196 vTaskStartScheduler();
\r
198 /* If this line is reached then vTaskStartScheduler() returned because there
\r
199 was insufficient heap memory remaining for the idle task to be created. */
\r
202 /*-----------------------------------------------------------*/
\r
204 static void prvCheckTask( void *pvParameters )
\r
206 portTickType xDelayPeriod = mainNO_ERROR_DELAY, xLastWakeTime;
\r
207 unsigned portBASE_TYPE uxLEDToUse = 0;
\r
209 /* Ensure parameter is passed in correctly. */
\r
210 if( pvParameters != mainCHECK_PARAMETER )
\r
212 xDelayPeriod = mainERROR_DELAY;
\r
215 /* Initialise xLastWakeTime before it is used. After this point it is not
\r
216 written to directly. */
\r
217 xLastWakeTime = xTaskGetTickCount();
\r
219 /* Cycle for ever, delaying then checking all the other tasks are still
\r
220 operating without error. */
\r
223 /* Wait until it is time to check all the other tasks again. */
\r
224 vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );
\r
226 if( lRegTestStatus != pdPASS )
\r
228 xDelayPeriod = mainERROR_DELAY;
\r
231 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
233 xDelayPeriod = mainERROR_DELAY;
\r
236 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
238 xDelayPeriod = mainERROR_DELAY;
\r
241 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
243 xDelayPeriod = mainERROR_DELAY;
\r
246 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
248 xDelayPeriod = mainERROR_DELAY;
\r
251 /* The Fx3 runs more tasks, so more checks are performed. */
\r
252 #ifdef __IAR_V850ES_Fx3__
\r
254 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
256 xDelayPeriod = mainERROR_DELAY;
\r
259 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
261 xDelayPeriod = mainERROR_DELAY;
\r
264 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
266 xDelayPeriod = mainERROR_DELAY;
\r
269 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
271 xDelayPeriod = mainERROR_DELAY;
\r
274 /* The application board has more LEDs and uses the flash tasks
\r
275 so the check task instead uses LED3 as LED3 is still spare. */
\r
280 /* Toggle the LED. The toggle rate will depend on whether or not an
\r
281 error has been found in any tasks. */
\r
282 vParTestToggleLED( uxLEDToUse );
\r
285 /*-----------------------------------------------------------*/
\r
287 static void prvSetupHardware( void )
\r
289 /* Setup the LED outputs. */
\r
290 vParTestInitialise();
\r
292 /* Any additional hardware configuration can be added here. */
\r
294 /*-----------------------------------------------------------*/
\r
296 void vApplicationStackOverflowHook( void )
\r
298 /* This will be called if a task overflows its stack. pxCurrentTCB
\r
299 can be inspected to see which is the offending task. */
\r
302 /*-----------------------------------------------------------*/
\r
304 void vRegTestFailed( void )
\r
306 /* Called by the RegTest tasks if an error is found. lRegTestStatus is
\r
307 inspected by the check task. */
\r
308 lRegTestStatus = pdFAIL;
\r
310 /* Do not return from here as the reg test tasks clobber all registers so
\r
311 function calls may not function correctly. */
\r