2 FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd.
\r
4 This file is part of the FreeRTOS distribution.
\r
6 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
7 the terms of the GNU General Public License (version 2) as published by the
\r
8 Free Software Foundation and modified by the FreeRTOS exception.
\r
9 **NOTE** The exception to the GPL is included to allow you to distribute a
\r
10 combined work that includes FreeRTOS without being obliged to provide the
\r
11 source code for proprietary components outside of the FreeRTOS kernel.
\r
12 Alternative commercial license and support terms are also available upon
\r
13 request. See the licensing section of http://www.FreeRTOS.org for full
\r
16 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
21 You should have received a copy of the GNU General Public License along
\r
22 with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
\r
23 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
26 ***************************************************************************
\r
28 * The FreeRTOS eBook and reference manual are available to purchase for a *
\r
29 * small fee. Help yourself get started quickly while also helping the *
\r
30 * FreeRTOS project! See http://www.FreeRTOS.org/Documentation for details *
\r
32 ***************************************************************************
\r
36 Please ensure to read the configuration and relevant port sections of the
\r
37 online documentation.
\r
39 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
42 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
45 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
46 licensing and training services.
\r
50 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
51 * documentation provides more details of the standard demo application tasks.
\r
52 * In addition to the standard demo tasks, the following tasks and tests are
\r
53 * defined and/or created within this file:
\r
55 * "Check" task - This only executes every three seconds but has a high priority
\r
56 * to ensure it gets processor time. Its main function is to check that all the
\r
57 * standard demo tasks are still operational. If everything is running as
\r
58 * expected then the check task will toggle an LED every 3 seconds. An error
\r
59 * being discovered in any task will cause the toggle rate to increase to 500ms.
\r
61 * "Reg test" tasks - These fill the registers with known values, then check
\r
62 * that each register still contains its expected value. Each task uses
\r
63 * different values. The tasks run with very low priority so get preempted very
\r
64 * frequently. A register containing an unexpected value is indicative of an
\r
65 * error in the context switching mechanism.
\r
69 /* Standard include files. */
\r
73 /* Scheduler include files. */
\r
74 #include "FreeRTOS.h"
\r
77 /* Demo file headers. */
\r
78 #include <intrinsics.h>
\r
82 #include "partest.h"
\r
83 #include "semtest.h"
\r
85 #include "GenQTest.h"
\r
87 #include "recmutex.h"
\r
88 #include "comtest2.h"
\r
91 * Priority definitions for most of the tasks in the demo application. Some
\r
92 * tasks just use the idle priority.
\r
94 #define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
95 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
96 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
97 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
98 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
99 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
100 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
101 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
102 #define mainCOMTEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
104 /* Passed into the check task just as a test that the parameter passing
\r
105 mechanism is working correctly. */
\r
106 #define mainCHECK_PARAMETER ( ( void * ) 0x12345678 )
\r
108 /* The period between executions of the check task. */
\r
109 #define mainNO_ERROR_DELAY ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
110 #define mainERROR_DELAY ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
112 /* There are no spare LEDs for the comtest tasks, so this is just set to an
\r
114 #define mainCOMTEST_LED ( 4 )
\r
116 /* The baud rate used by the comtest task. */
\r
117 #define mainBAUD_RATE ( 9600 )
\r
119 /*-----------------------------------------------------------*/
\r
121 /* The implementation of the 'check' task as described at the top of this file. */
\r
122 static void prvCheckTask( void *pvParameters );
\r
124 /* Just sets up the LED outputs. Most generic setup is done in
\r
125 __low_level_init(). */
\r
126 static void prvSetupHardware( void );
\r
128 /* The RegTest functions as described at the top of this file. */
\r
129 extern void vRegTest1( void *pvParameters );
\r
130 extern void vRegTest2( void *pvParameters );
\r
132 /* A variable that will get set to fail if a RegTest task finds an error. The
\r
133 variable is inspected by the 'Check' task. */
\r
134 static volatile portLONG lRegTestStatus = pdPASS;
\r
136 /*-----------------------------------------------------------*/
\r
138 /* Create all the demo tasks then start the scheduler. */
\r
141 /* Just sets up the LED outputs. */
\r
142 prvSetupHardware();
\r
144 /* Standard demo tasks. */
\r
145 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
146 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
147 vStartQueuePeekTasks();
\r
149 /* Create the check task as described at the top of this file. */
\r
150 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, mainCHECK_PARAMETER, mainCHECK_TASK_PRIORITY, NULL );
\r
152 /* Create the RegTest tasks as described at the top of this file. */
\r
153 xTaskCreate( vRegTest1, "Reg1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
154 xTaskCreate( vRegTest2, "Reg2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
156 #ifdef __IAR_V850ES_Fx3__
\r
158 /* The extra IO required for the com test and led flashing tasks is only
\r
159 available on the application board, not the target boards. */
\r
160 vAltStartComTestTasks( mainCOMTEST_PRIORITY, mainBAUD_RATE, mainCOMTEST_LED );
\r
161 vStartLEDFlashTasks( mainFLASH_PRIORITY );
\r
163 /* The Fx3 also has enough RAM to run loads more tasks. */
\r
164 vStartRecursiveMutexTasks();
\r
165 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
166 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
170 /* The suicide tasks must be created last as they need to know how many
\r
171 tasks were running prior to their creation in order to ascertain whether
\r
172 or not the correct/expected number of tasks are running at any given time. */
\r
173 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
175 /* Start the scheduler. */
\r
176 vTaskStartScheduler();
\r
178 /* If this line is reached then vTaskStartScheduler() returned because there
\r
179 was insufficient heap memory remaining for the idle task to be created. */
\r
182 /*-----------------------------------------------------------*/
\r
184 static void prvCheckTask( void *pvParameters )
\r
186 portTickType xDelayPeriod = mainNO_ERROR_DELAY, xLastWakeTime;
\r
187 unsigned portBASE_TYPE uxLEDToUse = 0;
\r
189 /* Ensure parameter is passed in correctly. */
\r
190 if( pvParameters != mainCHECK_PARAMETER )
\r
192 xDelayPeriod = mainERROR_DELAY;
\r
195 /* Initialise xLastWakeTime before it is used. After this point it is not
\r
196 written to directly. */
\r
197 xLastWakeTime = xTaskGetTickCount();
\r
199 /* Cycle for ever, delaying then checking all the other tasks are still
\r
200 operating without error. */
\r
203 /* Wait until it is time to check all the other tasks again. */
\r
204 vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );
\r
206 if( lRegTestStatus != pdPASS )
\r
208 xDelayPeriod = mainERROR_DELAY;
\r
211 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
213 xDelayPeriod = mainERROR_DELAY;
\r
216 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
218 xDelayPeriod = mainERROR_DELAY;
\r
221 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
223 xDelayPeriod = mainERROR_DELAY;
\r
226 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
228 xDelayPeriod = mainERROR_DELAY;
\r
231 /* The Fx3 runs more tasks, so more checks are performed. */
\r
232 #ifdef __IAR_V850ES_Fx3__
\r
234 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
236 xDelayPeriod = mainERROR_DELAY;
\r
239 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
241 xDelayPeriod = mainERROR_DELAY;
\r
244 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
246 xDelayPeriod = mainERROR_DELAY;
\r
249 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
251 xDelayPeriod = mainERROR_DELAY;
\r
254 /* The application board has more LEDs and uses the flash tasks
\r
255 so the check task instead uses LED3 as LED3 is still spare. */
\r
260 /* Toggle the LED. The toggle rate will depend on whether or not an
\r
261 error has been found in any tasks. */
\r
262 vParTestToggleLED( uxLEDToUse );
\r
265 /*-----------------------------------------------------------*/
\r
267 static void prvSetupHardware( void )
\r
269 /* Setup the LED outputs. */
\r
270 vParTestInitialise();
\r
272 /* Any additional hardware configuration can be added here. */
\r
274 /*-----------------------------------------------------------*/
\r
276 void vApplicationStackOverflowHook( void )
\r
278 /* This will be called if a task overflows its stack. pxCurrentTCB
\r
279 can be inspected to see which is the offending task. */
\r
282 /*-----------------------------------------------------------*/
\r
284 void vRegTestFailed( void )
\r
286 /* Called by the RegTest tasks if an error is found. lRegTestStatus is
\r
287 inspected by the check task. */
\r
288 lRegTestStatus = pdFAIL;
\r
290 /* Do not return from here as the reg test tasks clobber all registers so
\r
291 function calls may not function correctly. */
\r