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