2 * FreeRTOS Kernel V10.0.0
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
30 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
31 * documentation provides more details of the standard demo application tasks.
\r
32 * In addition to the standard demo tasks, the following tasks and tests are
\r
33 * defined and/or created within this file:
\r
35 * "Check" task - This only executes every three seconds but has a high priority
\r
36 * to ensure it gets processor time. Its main function is to check that all the
\r
37 * standard demo tasks are still operational. If everything is running as
\r
38 * expected then the check task will toggle an LED every 3 seconds. An error
\r
39 * being discovered in any task will cause the toggle rate to increase to 500ms.
\r
41 * "Reg test" tasks - These fill the registers with known values, then check
\r
42 * that each register still contains its expected value. Each task uses
\r
43 * different values. The tasks run with very low priority so get preempted very
\r
44 * frequently. A register containing an unexpected value is indicative of an
\r
45 * error in the context switching mechanism.
\r
49 /* Standard include files. */
\r
53 /* Scheduler include files. */
\r
54 #include "FreeRTOS.h"
\r
57 /* Demo file headers. */
\r
58 #include <intrinsics.h>
\r
62 #include "partest.h"
\r
63 #include "semtest.h"
\r
65 #include "GenQTest.h"
\r
67 #include "recmutex.h"
\r
68 #include "comtest2.h"
\r
71 * Priority definitions for most of the tasks in the demo application. Some
\r
72 * tasks just use the idle priority.
\r
74 #define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
75 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
76 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
77 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
78 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
79 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
80 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
81 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
82 #define mainCOMTEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
84 /* Passed into the check task just as a test that the parameter passing
\r
85 mechanism is working correctly. */
\r
86 #define mainCHECK_PARAMETER ( ( void * ) 0x12345678 )
\r
88 /* The period between executions of the check task. */
\r
89 #define mainNO_ERROR_DELAY ( ( TickType_t ) 3000 / portTICK_PERIOD_MS )
\r
90 #define mainERROR_DELAY ( ( TickType_t ) 500 / portTICK_PERIOD_MS )
\r
92 /* There are no spare LEDs for the comtest tasks, so this is just set to an
\r
94 #define mainCOMTEST_LED ( 4 )
\r
96 /* The baud rate used by the comtest task. */
\r
97 #define mainBAUD_RATE ( 9600 )
\r
99 /*-----------------------------------------------------------*/
\r
101 /* The implementation of the 'check' task as described at the top of this file. */
\r
102 static void prvCheckTask( void *pvParameters );
\r
104 /* Just sets up the LED outputs. Most generic setup is done in
\r
105 __low_level_init(). */
\r
106 static void prvSetupHardware( void );
\r
108 /* The RegTest functions as described at the top of this file. */
\r
109 extern void vRegTest1( void *pvParameters );
\r
110 extern void vRegTest2( void *pvParameters );
\r
112 /* A variable that will get set to fail if a RegTest task finds an error. The
\r
113 variable is inspected by the 'Check' task. */
\r
114 static volatile long lRegTestStatus = pdPASS;
\r
116 /*-----------------------------------------------------------*/
\r
118 /* Create all the demo tasks then start the scheduler. */
\r
121 /* Just sets up the LED outputs. */
\r
122 prvSetupHardware();
\r
124 /* Standard demo tasks. */
\r
125 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
126 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
127 vStartQueuePeekTasks();
\r
129 /* Create the check task as described at the top of this file. */
\r
130 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, mainCHECK_PARAMETER, mainCHECK_TASK_PRIORITY, NULL );
\r
132 /* Create the RegTest tasks as described at the top of this file. */
\r
133 xTaskCreate( vRegTest1, "Reg1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
134 xTaskCreate( vRegTest2, "Reg2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
136 #ifdef __IAR_V850ES_Fx3__
\r
138 /* The extra IO required for the com test and led flashing tasks is only
\r
139 available on the application board, not the target boards. */
\r
140 vAltStartComTestTasks( mainCOMTEST_PRIORITY, mainBAUD_RATE, mainCOMTEST_LED );
\r
141 vStartLEDFlashTasks( mainFLASH_PRIORITY );
\r
143 /* The Fx3 also has enough RAM to run loads more tasks. */
\r
144 vStartRecursiveMutexTasks();
\r
145 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
146 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
150 /* The suicide tasks must be created last as they need to know how many
\r
151 tasks were running prior to their creation in order to ascertain whether
\r
152 or not the correct/expected number of tasks are running at any given time. */
\r
153 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
155 /* Start the scheduler. */
\r
156 vTaskStartScheduler();
\r
158 /* If this line is reached then vTaskStartScheduler() returned because there
\r
159 was insufficient heap memory remaining for the idle task to be created. */
\r
162 /*-----------------------------------------------------------*/
\r
164 static void prvCheckTask( void *pvParameters )
\r
166 TickType_t xDelayPeriod = mainNO_ERROR_DELAY, xLastWakeTime;
\r
167 unsigned portBASE_TYPE uxLEDToUse = 0;
\r
169 /* Ensure parameter is passed in correctly. */
\r
170 if( pvParameters != mainCHECK_PARAMETER )
\r
172 xDelayPeriod = mainERROR_DELAY;
\r
175 /* Initialise xLastWakeTime before it is used. After this point it is not
\r
176 written to directly. */
\r
177 xLastWakeTime = xTaskGetTickCount();
\r
179 /* Cycle for ever, delaying then checking all the other tasks are still
\r
180 operating without error. */
\r
183 /* Wait until it is time to check all the other tasks again. */
\r
184 vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );
\r
186 if( lRegTestStatus != pdPASS )
\r
188 xDelayPeriod = mainERROR_DELAY;
\r
191 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
193 xDelayPeriod = mainERROR_DELAY;
\r
196 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
198 xDelayPeriod = mainERROR_DELAY;
\r
201 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
203 xDelayPeriod = mainERROR_DELAY;
\r
206 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
208 xDelayPeriod = mainERROR_DELAY;
\r
211 /* The Fx3 runs more tasks, so more checks are performed. */
\r
212 #ifdef __IAR_V850ES_Fx3__
\r
214 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
216 xDelayPeriod = mainERROR_DELAY;
\r
219 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
221 xDelayPeriod = mainERROR_DELAY;
\r
224 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
226 xDelayPeriod = mainERROR_DELAY;
\r
229 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
231 xDelayPeriod = mainERROR_DELAY;
\r
234 /* The application board has more LEDs and uses the flash tasks
\r
235 so the check task instead uses LED3 as LED3 is still spare. */
\r
240 /* Toggle the LED. The toggle rate will depend on whether or not an
\r
241 error has been found in any tasks. */
\r
242 vParTestToggleLED( uxLEDToUse );
\r
245 /*-----------------------------------------------------------*/
\r
247 static void prvSetupHardware( void )
\r
249 /* Setup the LED outputs. */
\r
250 vParTestInitialise();
\r
252 /* Any additional hardware configuration can be added here. */
\r
254 /*-----------------------------------------------------------*/
\r
256 void vApplicationStackOverflowHook( void )
\r
258 /* This will be called if a task overflows its stack. pxCurrentTCB
\r
259 can be inspected to see which is the offending task. */
\r
262 /*-----------------------------------------------------------*/
\r
264 void vRegTestFailed( void )
\r
266 /* Called by the RegTest tasks if an error is found. lRegTestStatus is
\r
267 inspected by the check task. */
\r
268 lRegTestStatus = pdFAIL;
\r
270 /* Do not return from here as the reg test tasks clobber all registers so
\r
271 function calls may not function correctly. */
\r