2 FreeRTOS V7.5.1 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
66 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
67 * documentation provides more details of the standard demo application tasks.
\r
68 * In addition to the standard demo tasks, the following tasks and tests are
\r
69 * defined and/or created within this file:
\r
71 * "Check" task - This only executes every three seconds but has a high priority
\r
72 * to ensure it gets processor time. Its main function is to check that all the
\r
73 * standard demo tasks are still operational. If everything is running as
\r
74 * expected then the check task will toggle an LED every 3 seconds. An error
\r
75 * being discovered in any task will cause the toggle rate to increase to 500ms.
\r
77 * "Reg test" tasks - These fill the registers with known values, then check
\r
78 * that each register still contains its expected value. Each task uses
\r
79 * different values. The tasks run with very low priority so get preempted very
\r
80 * frequently. A register containing an unexpected value is indicative of an
\r
81 * error in the context switching mechanism.
\r
85 /* Standard include files. */
\r
89 /* Scheduler include files. */
\r
90 #include "FreeRTOS.h"
\r
93 /* Demo file headers. */
\r
94 #include <intrinsics.h>
\r
98 #include "partest.h"
\r
99 #include "semtest.h"
\r
101 #include "GenQTest.h"
\r
103 #include "recmutex.h"
\r
104 #include "comtest2.h"
\r
107 * Priority definitions for most of the tasks in the demo application. Some
\r
108 * tasks just use the idle priority.
\r
110 #define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
111 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
112 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
113 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
114 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
115 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
116 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
117 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
118 #define mainCOMTEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
120 /* Passed into the check task just as a test that the parameter passing
\r
121 mechanism is working correctly. */
\r
122 #define mainCHECK_PARAMETER ( ( void * ) 0x12345678 )
\r
124 /* The period between executions of the check task. */
\r
125 #define mainNO_ERROR_DELAY ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
126 #define mainERROR_DELAY ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
128 /* There are no spare LEDs for the comtest tasks, so this is just set to an
\r
130 #define mainCOMTEST_LED ( 4 )
\r
132 /* The baud rate used by the comtest task. */
\r
133 #define mainBAUD_RATE ( 9600 )
\r
135 /*-----------------------------------------------------------*/
\r
137 /* The implementation of the 'check' task as described at the top of this file. */
\r
138 static void prvCheckTask( void *pvParameters );
\r
140 /* Just sets up the LED outputs. Most generic setup is done in
\r
141 __low_level_init(). */
\r
142 static void prvSetupHardware( void );
\r
144 /* The RegTest functions as described at the top of this file. */
\r
145 extern void vRegTest1( void *pvParameters );
\r
146 extern void vRegTest2( void *pvParameters );
\r
148 /* A variable that will get set to fail if a RegTest task finds an error. The
\r
149 variable is inspected by the 'Check' task. */
\r
150 static volatile portLONG lRegTestStatus = pdPASS;
\r
152 /*-----------------------------------------------------------*/
\r
154 /* Create all the demo tasks then start the scheduler. */
\r
157 /* Just sets up the LED outputs. */
\r
158 prvSetupHardware();
\r
160 /* Standard demo tasks. */
\r
161 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
162 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
163 vStartQueuePeekTasks();
\r
165 /* Create the check task as described at the top of this file. */
\r
166 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, mainCHECK_PARAMETER, mainCHECK_TASK_PRIORITY, NULL );
\r
168 /* Create the RegTest tasks as described at the top of this file. */
\r
169 xTaskCreate( vRegTest1, "Reg1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
170 xTaskCreate( vRegTest2, "Reg2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
172 #ifdef __IAR_V850ES_Fx3__
\r
174 /* The extra IO required for the com test and led flashing tasks is only
\r
175 available on the application board, not the target boards. */
\r
176 vAltStartComTestTasks( mainCOMTEST_PRIORITY, mainBAUD_RATE, mainCOMTEST_LED );
\r
177 vStartLEDFlashTasks( mainFLASH_PRIORITY );
\r
179 /* The Fx3 also has enough RAM to run loads more tasks. */
\r
180 vStartRecursiveMutexTasks();
\r
181 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
182 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
186 /* The suicide tasks must be created last as they need to know how many
\r
187 tasks were running prior to their creation in order to ascertain whether
\r
188 or not the correct/expected number of tasks are running at any given time. */
\r
189 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
191 /* Start the scheduler. */
\r
192 vTaskStartScheduler();
\r
194 /* If this line is reached then vTaskStartScheduler() returned because there
\r
195 was insufficient heap memory remaining for the idle task to be created. */
\r
198 /*-----------------------------------------------------------*/
\r
200 static void prvCheckTask( void *pvParameters )
\r
202 portTickType xDelayPeriod = mainNO_ERROR_DELAY, xLastWakeTime;
\r
203 unsigned portBASE_TYPE uxLEDToUse = 0;
\r
205 /* Ensure parameter is passed in correctly. */
\r
206 if( pvParameters != mainCHECK_PARAMETER )
\r
208 xDelayPeriod = mainERROR_DELAY;
\r
211 /* Initialise xLastWakeTime before it is used. After this point it is not
\r
212 written to directly. */
\r
213 xLastWakeTime = xTaskGetTickCount();
\r
215 /* Cycle for ever, delaying then checking all the other tasks are still
\r
216 operating without error. */
\r
219 /* Wait until it is time to check all the other tasks again. */
\r
220 vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );
\r
222 if( lRegTestStatus != pdPASS )
\r
224 xDelayPeriod = mainERROR_DELAY;
\r
227 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
229 xDelayPeriod = mainERROR_DELAY;
\r
232 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
234 xDelayPeriod = mainERROR_DELAY;
\r
237 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
239 xDelayPeriod = mainERROR_DELAY;
\r
242 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
244 xDelayPeriod = mainERROR_DELAY;
\r
247 /* The Fx3 runs more tasks, so more checks are performed. */
\r
248 #ifdef __IAR_V850ES_Fx3__
\r
250 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
252 xDelayPeriod = mainERROR_DELAY;
\r
255 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
257 xDelayPeriod = mainERROR_DELAY;
\r
260 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
262 xDelayPeriod = mainERROR_DELAY;
\r
265 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
267 xDelayPeriod = mainERROR_DELAY;
\r
270 /* The application board has more LEDs and uses the flash tasks
\r
271 so the check task instead uses LED3 as LED3 is still spare. */
\r
276 /* Toggle the LED. The toggle rate will depend on whether or not an
\r
277 error has been found in any tasks. */
\r
278 vParTestToggleLED( uxLEDToUse );
\r
281 /*-----------------------------------------------------------*/
\r
283 static void prvSetupHardware( void )
\r
285 /* Setup the LED outputs. */
\r
286 vParTestInitialise();
\r
288 /* Any additional hardware configuration can be added here. */
\r
290 /*-----------------------------------------------------------*/
\r
292 void vApplicationStackOverflowHook( void )
\r
294 /* This will be called if a task overflows its stack. pxCurrentTCB
\r
295 can be inspected to see which is the offending task. */
\r
298 /*-----------------------------------------------------------*/
\r
300 void vRegTestFailed( void )
\r
302 /* Called by the RegTest tasks if an error is found. lRegTestStatus is
\r
303 inspected by the check task. */
\r
304 lRegTestStatus = pdFAIL;
\r
306 /* Do not return from here as the reg test tasks clobber all registers so
\r
307 function calls may not function correctly. */
\r