2 * FreeRTOS Kernel V10.2.1
\r
3 * Copyright (C) 2019 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.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
28 /******************************************************************************
\r
29 * NOTE 1: This project provides two demo applications. A simple blinky style
\r
30 * project, and a more comprehensive test and demo application. The
\r
31 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select
\r
32 * between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY
\r
33 * in main.c. This file implements the comprehensive test and demo version.
\r
35 * NOTE 2: This file only contains the source code that is specific to the
\r
36 * full demo. Generic functions, such FreeRTOS hook functions, and functions
\r
37 * required to configure the hardware, are defined in main.c.
\r
39 ******************************************************************************
\r
41 * main_full() creates all the demo application tasks and software timers, then
\r
42 * starts the scheduler. The web documentation provides more details of the
\r
43 * standard demo application tasks, which provide no particular functionality,
\r
44 * but do provide a good example of how to use the FreeRTOS API.
\r
46 * In addition to the standard demo tasks, the following tasks and tests are
\r
47 * defined and/or created within this file:
\r
49 * "Reg test" tasks - These fill both the core registers with known values, then
\r
50 * check that each register maintains its expected value for the lifetime of the
\r
51 * task. Each task uses a different set of values. The reg test tasks execute
\r
52 * with a very low priority, so get preempted very frequently. A register
\r
53 * containing an unexpected value is indicative of an error in the context
\r
54 * switching mechanism.
\r
56 * "Check" task - The check executes every three seconds. It checks that all
\r
57 * the standard demo tasks, and the register check tasks, are not only still
\r
58 * executing, but are executing without reporting any errors. If the check task
\r
59 * discovers that a task has either stalled, or reported an error, then it
\r
60 * prints an error message to the UART, otherwise it prints "Pass.".
\r
63 /* Standard includes. */
\r
68 /* Kernel includes. */
\r
69 #include "FreeRTOS.h"
\r
74 /* Standard demo application includes. */
\r
75 #include "dynamic.h"
\r
76 #include "blocktim.h"
\r
77 #include "GenQTest.h"
\r
78 #include "recmutex.h"
\r
79 #include "TimerDemo.h"
\r
80 #include "EventGroupsDemo.h"
\r
81 #include "TaskNotify.h"
\r
82 #include "AbortDelay.h"
\r
83 #include "countsem.h"
\r
85 #include "MessageBufferDemo.h"
\r
86 #include "StreamBufferDemo.h"
\r
87 #include "StreamBufferInterrupt.h"
\r
89 /* Priorities for the demo application tasks. */
\r
90 #define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
\r
91 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3UL )
\r
93 /* The period of the check task, in ms, converted to ticks using the
\r
94 pdMS_TO_TICKS() macro. mainNO_ERROR_CHECK_TASK_PERIOD is used if no errors have
\r
95 been found, mainERROR_CHECK_TASK_PERIOD is used if an error has been found. */
\r
96 #define mainNO_ERROR_CHECK_TASK_PERIOD pdMS_TO_TICKS( 3000UL )
\r
97 #define mainERROR_CHECK_TASK_PERIOD pdMS_TO_TICKS( 500UL )
\r
99 /* Parameters that are passed into the register check tasks solely for the
\r
100 purpose of ensuring parameters are passed into tasks correctly. */
\r
101 #define mainREG_TEST_TASK_1_PARAMETER ( ( void * ) 0x12345678 )
\r
102 #define mainREG_TEST_TASK_2_PARAMETER ( ( void * ) 0x87654321 )
\r
104 /* The base period used by the timer test tasks. */
\r
105 #define mainTIMER_TEST_PERIOD ( 50 )
\r
107 /* The size of the stack allocated to the check task (as described in the
\r
108 comments at the top of this file. */
\r
109 #define mainCHECK_TASK_STACK_SIZE_WORDS 160
\r
111 /* Size of the stacks to allocated for the register check tasks. */
\r
112 #define mainREG_TEST_STACK_SIZE_WORDS 90
\r
114 /*-----------------------------------------------------------*/
\r
117 * Called by main() to run the full demo (as opposed to the blinky demo) when
\r
118 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
\r
120 void main_full( void );
\r
123 * The check task, as described at the top of this file.
\r
125 static void prvCheckTask( void *pvParameters );
\r
128 * Register check tasks as described at the top of this file. The nature of
\r
129 * these files necessitates that they are written in an assembly file, but the
\r
130 * entry points are kept in the C file for the convenience of checking the task
\r
133 static void prvRegTestTaskEntry1( void *pvParameters );
\r
134 extern void vRegTest1Implementation( void );
\r
135 static void prvRegTestTaskEntry2( void *pvParameters );
\r
136 extern void vRegTest2Implementation( void );
\r
139 * Tick hook used by the full demo, which includes code that interacts with
\r
140 * some of the tests.
\r
142 void vFullDemoTickHook( void );
\r
144 /*-----------------------------------------------------------*/
\r
146 /* The following two variables are used to communicate the status of the
\r
147 register check tasks to the check task. If the variables keep incrementing,
\r
148 then the register check tasks have not discovered any errors. If a variable
\r
149 stops incrementing, then an error has been found. */
\r
150 uint32_t ulRegTest1LoopCounter = 0UL, ulRegTest2LoopCounter = 0UL;
\r
151 volatile uint32_t *pulRegTest1LoopCounter = &ulRegTest1LoopCounter;
\r
152 volatile uint32_t *pulRegTest2LoopCounter = &ulRegTest2LoopCounter;
\r
153 /*-----------------------------------------------------------*/
\r
155 void main_full( void )
\r
157 /* Start all the other standard demo/test tasks. They have no particular
\r
158 functionality, but do demonstrate how to use the FreeRTOS API and test the
\r
160 vCreateBlockTimeTasks();
\r
161 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );
\r
162 vStartDynamicPriorityTasks();
\r
163 // vStartMessageBufferTasks( configMINIMAL_STACK_SIZE );
\r
164 vStartTaskNotifyTask();
\r
166 /* Create the register check tasks, as described at the top of this file.
\r
167 Use xTaskCreateStatic() to create a task using only statically allocated
\r
169 xTaskCreate( prvRegTestTaskEntry1, /* The function that implements the task. */
\r
170 "Reg1", /* The name of the task. */
\r
171 mainREG_TEST_STACK_SIZE_WORDS, /* Size of stack to allocate for the task - in words not bytes!. */
\r
172 mainREG_TEST_TASK_1_PARAMETER, /* Parameter passed into the task. */
\r
173 tskIDLE_PRIORITY, /* Priority of the task. */
\r
174 NULL ); /* Can be used to pass out a handle to the created task. */
\r
175 xTaskCreate( prvRegTestTaskEntry2, "Reg2", mainREG_TEST_STACK_SIZE_WORDS, mainREG_TEST_TASK_2_PARAMETER, tskIDLE_PRIORITY, NULL );
\r
177 /* Create the task that performs the 'check' functionality, as described at
\r
178 the top of this file. */
\r
179 xTaskCreate( prvCheckTask, "Check", mainCHECK_TASK_STACK_SIZE_WORDS, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
181 /* Start the scheduler. */
\r
182 vTaskStartScheduler();
\r
184 /* If all is well, the scheduler will now be running, and the following
\r
185 line will never be reached. If the following line does execute, then
\r
186 there was insufficient FreeRTOS heap memory available for the Idle and/or
\r
187 timer tasks to be created. See the memory management section on the
\r
188 FreeRTOS web site for more details on the FreeRTOS heap
\r
189 http://www.freertos.org/a00111.html. */
\r
192 /*-----------------------------------------------------------*/
\r
193 volatile uint32_t ulCheckTaskCycles = 0;
\r
194 static volatile TaskStatus_t xTaskStatus[ 15 ];
\r
195 static void prvCheckTask( void *pvParameters )
\r
197 TickType_t xDelayPeriod = mainNO_ERROR_CHECK_TASK_PERIOD;
\r
198 TickType_t xLastExecutionTime;
\r
199 uint32_t ulLastRegTest1Value = 0, ulLastRegTest2Value = 0;
\r
200 char * const pcPassMessage = ".";
\r
201 char * pcStatusMessage = pcPassMessage;
\r
202 extern void vToggleLED( void );
\r
204 /* Just to stop compiler warnings. */
\r
205 ( void ) pvParameters;
\r
207 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
208 works correctly. */
\r
209 xLastExecutionTime = xTaskGetTickCount();
\r
211 /* Cycle for ever, delaying then checking all the other tasks are still
\r
212 operating without error. The onboard LED is toggled on each iteration.
\r
213 If an error is detected then the delay period is decreased from
\r
214 mainNO_ERROR_CHECK_TASK_PERIOD to mainERROR_CHECK_TASK_PERIOD. This has the
\r
215 effect of increasing the rate at which the onboard LED toggles, and in so
\r
216 doing gives visual feedback of the system status. */
\r
219 /* Delay until it is time to execute again. */
\r
220 vTaskDelayUntil( &xLastExecutionTime, xDelayPeriod );
\r
222 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
223 that they are all still running, and that none have detected an error. */
\r
224 if( xAreDynamicPriorityTasksStillRunning() == pdFALSE )
\r
226 pcStatusMessage = "ERROR: Dynamic priority demo/tests.\r\n";
\r
229 if( xAreBlockTimeTestTasksStillRunning() == pdFALSE )
\r
231 pcStatusMessage = "ERROR: Block time demo/tests.\r\n";
\r
234 if( xAreTimerDemoTasksStillRunning( ( TickType_t ) xDelayPeriod ) == pdFALSE )
\r
236 pcStatusMessage = "ERROR: Timer demo/tests.\r\n";
\r
239 if( xAreTaskNotificationTasksStillRunning() == pdFALSE )
\r
241 pcStatusMessage = "ERROR: Task notification demo/tests.\r\n";
\r
244 // if( xAreMessageBufferTasksStillRunning() == pdFALSE )
\r
246 // pcStatusMessage = "ERROR: Message buffer.\r\n";
\r
249 /* Check that the register test 1 task is still running. */
\r
250 if( ulLastRegTest1Value == ulRegTest1LoopCounter )
\r
252 pcStatusMessage = "ERROR: Register test 1.\r\n";
\r
254 ulLastRegTest1Value = ulRegTest1LoopCounter;
\r
256 /* Check that the register test 2 task is still running. */
\r
257 if( ulLastRegTest2Value == ulRegTest2LoopCounter )
\r
259 pcStatusMessage = "ERROR: Register test 2.\r\n";
\r
261 ulLastRegTest2Value = ulRegTest2LoopCounter;
\r
263 /* Write the status message to the UART and toggle the LED to show the
\r
264 system status if the UART is not connected. */
\r
267 /* If an error has been found then increase the LED toggle rate by
\r
268 increasing the cycle frequency. */
\r
269 if( pcStatusMessage != pcPassMessage )
\r
271 xDelayPeriod = mainERROR_CHECK_TASK_PERIOD;
\r
272 write( STDOUT_FILENO, pcStatusMessage, strlen( pcStatusMessage ) );
\r
275 ulCheckTaskCycles++;
\r
277 // uxTaskGetSystemState( xTaskStatus, sizeof( xTaskStatus ) / sizeof( TaskStatus_t ), NULL );
\r
278 __asm volatile( "NOP" );
\r
281 /*-----------------------------------------------------------*/
\r
283 static void prvRegTestTaskEntry1( void *pvParameters )
\r
285 /* Although the regtest task is written in assembler, its entry point is
\r
286 written in C for convenience of checking the task parameter is being passed
\r
288 if( pvParameters == mainREG_TEST_TASK_1_PARAMETER )
\r
290 /* Start the part of the test that is written in assembler. */
\r
291 vRegTest1Implementation();
\r
294 /* The following line will only execute if the task parameter is found to
\r
295 be incorrect. The check task will detect that the regtest loop counter is
\r
296 not being incremented and flag an error. */
\r
297 vTaskDelete( NULL );
\r
299 /*-----------------------------------------------------------*/
\r
301 static void prvRegTestTaskEntry2( void *pvParameters )
\r
303 /* Although the regtest task is written in assembler, its entry point is
\r
304 written in C for convenience of checking the task parameter is being passed
\r
306 if( pvParameters == mainREG_TEST_TASK_2_PARAMETER )
\r
308 /* Start the part of the test that is written in assembler. */
\r
309 vRegTest2Implementation();
\r
312 /* The following line will only execute if the task parameter is found to
\r
313 be incorrect. The check task will detect that the regtest loop counter is
\r
314 not being incremented and flag an error. */
\r
315 vTaskDelete( NULL );
\r
317 /*-----------------------------------------------------------*/
\r
319 void vFullDemoTickHook( void )
\r
321 /* Called from vApplicationTickHook() when the project is configured to
\r
322 build the full test/demo applications. */
\r
324 /* The full demo includes a software timer demo/test that requires
\r
325 prodding periodically from the tick interrupt. */
\r
326 // vTimerPeriodicISRTests();
\r
328 /* Use task notifications from an interrupt. */
\r
329 xNotifyTaskFromISR();
\r
331 /*-----------------------------------------------------------*/
\r