2 FreeRTOS V9.0.0 - Copyright (C) 2016 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 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
71 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
72 * documentation provides more details of the standard demo application tasks.
\r
73 * In addition to the standard demo tasks, the following tasks and tests are
\r
74 * defined and/or created within this file:
\r
76 * "Check" task - This only executes every three seconds but has a high priority
\r
77 * to ensure it gets processor time. Its main function is to check that all the
\r
78 * standard demo tasks are still operational. If everything is running as
\r
79 * expected then the check task will toggle an LED every 3 seconds. An error
\r
80 * being discovered in any task will cause the toggle rate to increase to 500ms.
\r
82 * "Reg test" tasks - These fill the registers with known values, then check
\r
83 * that each register still contains its expected value. Each task uses
\r
84 * different values. The tasks run with very low priority so get preempted very
\r
85 * frequently. A register containing an unexpected value is indicative of an
\r
86 * error in the context switching mechanism.
\r
90 /* Standard include files. */
\r
94 /* Scheduler include files. */
\r
95 #include "FreeRTOS.h"
\r
98 /* Demo file headers. */
\r
99 #include <intrinsics.h>
\r
100 #include "BlockQ.h"
\r
103 #include "partest.h"
\r
104 #include "semtest.h"
\r
106 #include "GenQTest.h"
\r
108 #include "recmutex.h"
\r
109 #include "comtest2.h"
\r
112 * Priority definitions for most of the tasks in the demo application. Some
\r
113 * tasks just use the idle priority.
\r
115 #define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
116 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
117 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
118 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
119 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
120 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
121 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
122 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
123 #define mainCOMTEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
125 /* Passed into the check task just as a test that the parameter passing
\r
126 mechanism is working correctly. */
\r
127 #define mainCHECK_PARAMETER ( ( void * ) 0x12345678 )
\r
129 /* The period between executions of the check task. */
\r
130 #define mainNO_ERROR_DELAY ( ( TickType_t ) 3000 / portTICK_PERIOD_MS )
\r
131 #define mainERROR_DELAY ( ( TickType_t ) 500 / portTICK_PERIOD_MS )
\r
133 /* There are no spare LEDs for the comtest tasks, so this is just set to an
\r
135 #define mainCOMTEST_LED ( 4 )
\r
137 /* The baud rate used by the comtest task. */
\r
138 #define mainBAUD_RATE ( 9600 )
\r
140 /*-----------------------------------------------------------*/
\r
142 /* The implementation of the 'check' task as described at the top of this file. */
\r
143 static void prvCheckTask( void *pvParameters );
\r
145 /* Just sets up the LED outputs. Most generic setup is done in
\r
146 __low_level_init(). */
\r
147 static void prvSetupHardware( void );
\r
149 /* The RegTest functions as described at the top of this file. */
\r
150 extern void vRegTest1( void *pvParameters );
\r
151 extern void vRegTest2( void *pvParameters );
\r
153 /* A variable that will get set to fail if a RegTest task finds an error. The
\r
154 variable is inspected by the 'Check' task. */
\r
155 static volatile long lRegTestStatus = pdPASS;
\r
157 /*-----------------------------------------------------------*/
\r
159 /* Create all the demo tasks then start the scheduler. */
\r
162 /* Just sets up the LED outputs. */
\r
163 prvSetupHardware();
\r
165 /* Standard demo tasks. */
\r
166 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
167 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
168 vStartQueuePeekTasks();
\r
170 /* Create the check task as described at the top of this file. */
\r
171 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, mainCHECK_PARAMETER, mainCHECK_TASK_PRIORITY, NULL );
\r
173 /* Create the RegTest tasks as described at the top of this file. */
\r
174 xTaskCreate( vRegTest1, "Reg1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
175 xTaskCreate( vRegTest2, "Reg2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
177 #ifdef __IAR_V850ES_Fx3__
\r
179 /* The extra IO required for the com test and led flashing tasks is only
\r
180 available on the application board, not the target boards. */
\r
181 vAltStartComTestTasks( mainCOMTEST_PRIORITY, mainBAUD_RATE, mainCOMTEST_LED );
\r
182 vStartLEDFlashTasks( mainFLASH_PRIORITY );
\r
184 /* The Fx3 also has enough RAM to run loads more tasks. */
\r
185 vStartRecursiveMutexTasks();
\r
186 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
187 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
191 /* The suicide tasks must be created last as they need to know how many
\r
192 tasks were running prior to their creation in order to ascertain whether
\r
193 or not the correct/expected number of tasks are running at any given time. */
\r
194 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
196 /* Start the scheduler. */
\r
197 vTaskStartScheduler();
\r
199 /* If this line is reached then vTaskStartScheduler() returned because there
\r
200 was insufficient heap memory remaining for the idle task to be created. */
\r
203 /*-----------------------------------------------------------*/
\r
205 static void prvCheckTask( void *pvParameters )
\r
207 TickType_t xDelayPeriod = mainNO_ERROR_DELAY, xLastWakeTime;
\r
208 unsigned portBASE_TYPE uxLEDToUse = 0;
\r
210 /* Ensure parameter is passed in correctly. */
\r
211 if( pvParameters != mainCHECK_PARAMETER )
\r
213 xDelayPeriod = mainERROR_DELAY;
\r
216 /* Initialise xLastWakeTime before it is used. After this point it is not
\r
217 written to directly. */
\r
218 xLastWakeTime = xTaskGetTickCount();
\r
220 /* Cycle for ever, delaying then checking all the other tasks are still
\r
221 operating without error. */
\r
224 /* Wait until it is time to check all the other tasks again. */
\r
225 vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );
\r
227 if( lRegTestStatus != pdPASS )
\r
229 xDelayPeriod = mainERROR_DELAY;
\r
232 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
234 xDelayPeriod = mainERROR_DELAY;
\r
237 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
239 xDelayPeriod = mainERROR_DELAY;
\r
242 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
244 xDelayPeriod = mainERROR_DELAY;
\r
247 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
249 xDelayPeriod = mainERROR_DELAY;
\r
252 /* The Fx3 runs more tasks, so more checks are performed. */
\r
253 #ifdef __IAR_V850ES_Fx3__
\r
255 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
257 xDelayPeriod = mainERROR_DELAY;
\r
260 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
262 xDelayPeriod = mainERROR_DELAY;
\r
265 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
267 xDelayPeriod = mainERROR_DELAY;
\r
270 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
272 xDelayPeriod = mainERROR_DELAY;
\r
275 /* The application board has more LEDs and uses the flash tasks
\r
276 so the check task instead uses LED3 as LED3 is still spare. */
\r
281 /* Toggle the LED. The toggle rate will depend on whether or not an
\r
282 error has been found in any tasks. */
\r
283 vParTestToggleLED( uxLEDToUse );
\r
286 /*-----------------------------------------------------------*/
\r
288 static void prvSetupHardware( void )
\r
290 /* Setup the LED outputs. */
\r
291 vParTestInitialise();
\r
293 /* Any additional hardware configuration can be added here. */
\r
295 /*-----------------------------------------------------------*/
\r
297 void vApplicationStackOverflowHook( void )
\r
299 /* This will be called if a task overflows its stack. pxCurrentTCB
\r
300 can be inspected to see which is the offending task. */
\r
303 /*-----------------------------------------------------------*/
\r
305 void vRegTestFailed( void )
\r
307 /* Called by the RegTest tasks if an error is found. lRegTestStatus is
\r
308 inspected by the check task. */
\r
309 lRegTestStatus = pdFAIL;
\r
311 /* Do not return from here as the reg test tasks clobber all registers so
\r
312 function calls may not function correctly. */
\r