2 * FreeRTOS Kernel V10.1.0
\r
3 * Copyright (C) 2018 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 * See http://www.FreeRTOS.org/RTOS_Intel_Quark_Galileo_GCC.html for usage
\r
44 * main_full() creates all the demo application tasks and software timers, then
\r
45 * starts the scheduler. The web documentation provides more details of the
\r
46 * standard demo application tasks, which provide no particular functionality,
\r
47 * but do provide a good example of how to use the FreeRTOS API.
\r
49 * In addition to the standard demo tasks, the following tasks and tests are
\r
50 * defined and/or created within this file:
\r
52 * "Reg test" tasks - These fill both the core and floating point registers with
\r
53 * known values, then check that each register maintains its expected value for
\r
54 * the lifetime of the task. Each task uses a different set of values. The reg
\r
55 * test tasks execute with a very low priority, so get preempted very
\r
56 * frequently. A register containing an unexpected value is indicative of an
\r
57 * error in the context switching mechanism.
\r
59 * "Check" task - The check task period is set to five seconds. The task checks
\r
60 * that all the standard demo tasks, and the register check tasks, are not only
\r
61 * still executing, but are executing without reporting any errors. The check
\r
62 * task toggles an LED on each iteration. If the LED toggles every 5 seconds
\r
63 * then no errors have been found. If the LED toggles every 1 second then a
\r
64 * potential error has been detected.
\r
67 /* Standard includes. */
\r
73 /* FreeRTOS includes. */
\r
74 #include "FreeRTOS.h"
\r
78 /* Standard demo includes. */
\r
79 #include "blocktim.h"
\r
80 #include "flash_timer.h"
\r
81 #include "semtest.h"
\r
82 #include "GenQTest.h"
\r
84 #include "countsem.h"
\r
85 #include "dynamic.h"
\r
86 #include "QueueOverwrite.h"
\r
87 #include "QueueSet.h"
\r
88 #include "recmutex.h"
\r
89 #include "EventGroupsDemo.h"
\r
91 #include "TimerDemo.h"
\r
94 #include "TaskNotify.h"
\r
95 #include "IntQueue.h"
\r
97 /* Galileo includes. */
\r
98 #include "galileo_support.h"
\r
100 /* The rate at which the check task cycles if no errors have been detected, and
\r
101 if a [potential] error has been detected. Increasing the toggle rate in the
\r
102 presense of an error gives visual feedback of the system status. */
\r
103 #define mainNO_ERROR_CHECK_TASK_PERIOD pdMS_TO_TICKS( 5000UL )
\r
104 #define mainERROR_CHECK_TASK_PERIOD pdMS_TO_TICKS( 1000UL )
\r
106 /* The priorities of the various demo application tasks. */
\r
107 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
108 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
109 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
110 #define mainQUEUE_OVERWRITE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
111 #define mainMATHS_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
113 /* The base period used by the timer test tasks. */
\r
114 #define mainTIMER_TEST_PERIOD ( 50 )
\r
116 /* Parameters that are passed into the check tasks for no other purpose other
\r
117 than to check the port does this correctly. */
\r
118 #define mainREG_TEST_1_PARAMETER ( 0x12345678UL )
\r
119 #define mainREG_TEST_2_PARAMETER ( 0x87654321UL )
\r
121 /*-----------------------------------------------------------*/
\r
124 * The function that implements the check task, as described at the top of this
\r
127 static void prvCheckTask( void *pvParameters );
\r
130 * Entry points for the register check tasks, as described at the top of this
\r
133 static void prvRegTest1Entry( void *pvParameters );
\r
134 static void prvRegTest2Entry( void *pvParameters );
\r
137 * The implementation of the register check tasks, which are implemented in
\r
138 * RegTest.S. These functions are called by prvRegTest1Entry() and
\r
139 * prvRegTest2Entry() respectively.
\r
141 extern void vRegTest1( void );
\r
142 extern void vRegTest2( void );
\r
144 /*-----------------------------------------------------------*/
\r
146 /* Constants used by the register check tasks when checking the FPU registers. */
\r
147 const double dRegTest1_st7 = 7.0, dRegTest1_st6 = 6.0, dRegTest1_st5 = 5.0, dRegTest1_st4 = 4.0, dRegTest1_st3 = 3.0, dRegTest1_st2 = 2.0, dRegTest1_st1 = 1.0;
\r
148 const double dRegTest2_st7 = 700.0, dRegTest2_st6 = 600.0, dRegTest2_st5 = 500.0, dRegTest2_st4 = 400.0, dRegTest2_st3 = 300.0, dRegTest2_st2 = 200.0, dRegTest2_st1 = 100.0;
\r
150 /* Counters used by the register check tasks to indicate that they are still
\r
151 executing without having discovered any errors. */
\r
152 volatile uint32_t ulRegTest1Counter, ulRegTest2Counter;
\r
153 volatile uint32_t ulCheckLoops = 0;
\r
155 /*-----------------------------------------------------------*/
\r
157 /* See http://www.FreeRTOS.org/RTOS_Intel_Quark_Galileo_GCC.html for usage
\r
159 void main_full( void )
\r
161 /* Create all the other standard demo tasks. */
\r
162 vCreateBlockTimeTasks();
\r
163 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
164 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
165 vStartQueuePeekTasks();
\r
166 vStartCountingSemaphoreTasks();
\r
167 vStartDynamicPriorityTasks();
\r
168 vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_TASK_PRIORITY );
\r
169 vStartQueueSetTasks();
\r
170 vStartRecursiveMutexTasks();
\r
171 vStartEventGroupTasks();
\r
172 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );
\r
173 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
174 vStartTaskNotifyTask();
\r
175 vStartInterruptQueueTasks();
\r
177 #if configSUPPORT_FPU == 1
\r
179 vStartMathTasks( mainMATHS_TASK_PRIORITY );
\r
181 #endif /* configSUPPORT_FPU */
\r
183 /* Create the 'check' task, as described at the top of this file. */
\r
184 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE * 2, NULL, configMAX_PRIORITIES - 1, NULL );
\r
186 /* Create the register test tasks, as described at the top of this file. */
\r
187 xTaskCreate( prvRegTest1Entry, "Reg1", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_1_PARAMETER, tskIDLE_PRIORITY, NULL );
\r
188 xTaskCreate( prvRegTest2Entry, "Reg2", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_2_PARAMETER, tskIDLE_PRIORITY, NULL );
\r
190 /* Death tasks must be created last as they check the number of tasks
\r
191 running against the number of tasks expected to be running as part of their
\r
193 vCreateSuicidalTasks( tskIDLE_PRIORITY );
\r
195 /* Display HPET Information (Disable in HPET.H). */
\r
196 vCreateHPETInfoUpdateTask();
\r
198 /* Start the scheduler itself. */
\r
199 vTaskStartScheduler();
\r
201 /* If all is well, the scheduler will now be running, and the following line
\r
202 will never be reached. If the following line does execute, then there was
\r
203 insufficient FreeRTOS heap memory available for the idle and/or timer tasks
\r
204 to be created. See the memory management section on the FreeRTOS web site
\r
205 for more details. */
\r
208 /*-----------------------------------------------------------*/
\r
210 static void prvRegTest1Entry( void *pvParameters )
\r
212 /* Remove compiler warning if configASSERT() is not defined. */
\r
213 ( void ) pvParameters;
\r
215 /* Check the parameter is passed in correctly. */
\r
216 configASSERT( ( ( uint32_t) pvParameters ) == mainREG_TEST_1_PARAMETER );
\r
218 /* Tell FreeRTOS that this task needs a floating point context. */
\r
219 portTASK_USES_FLOATING_POINT();
\r
221 /* Call the assembly file routine that performs the 'reg test' functionality
\r
222 as described at the top of this file. */
\r
225 /*-----------------------------------------------------------*/
\r
227 static void prvRegTest2Entry( void *pvParameters )
\r
229 /* Remove compiler warning if configASSERT() is not defined. */
\r
230 ( void ) pvParameters;
\r
232 /* Check the parameter is passed in correctly. */
\r
233 configASSERT( ( ( uint32_t) pvParameters ) == mainREG_TEST_2_PARAMETER );
\r
235 /* Tell FreeRTOS that this task needs a floating point context. */
\r
236 portTASK_USES_FLOATING_POINT();
\r
238 /* Call the assembly file routine that performs the 'reg test' functionality
\r
239 as described at the top of this file. */
\r
242 /*-----------------------------------------------------------*/
\r
244 static void prvCheckTask( void *pvParameters )
\r
246 uint32_t ulLastRegTest1Counter = 0UL, ulLastRegTest2Counter = 0UL;
\r
247 uint32_t ulErrorOccurred, ulElapsedTimeInSeconds = 0UL;
\r
248 TickType_t xLastExpireTime, xBlockTime = mainNO_ERROR_CHECK_TASK_PERIOD;
\r
249 BaseType_t xErrorFlag = pdFALSE;
\r
251 /* Avoid compiler warnings. */
\r
252 ( void ) pvParameters;
\r
254 /* Initialise the last expire time to the current time. */
\r
255 xLastExpireTime = xTaskGetTickCount();
\r
257 /* Message to wait for an update - first update won't happen for X seconds. */
\r
258 g_printf_rcc( 5, 2, DEFAULT_SCREEN_COLOR, "Starting task check loop - Please wait for a status update." );
\r
259 g_printf_rcc( 6, 2, DEFAULT_SCREEN_COLOR, "No task errors encountered." );
\r
263 vTaskDelayUntil( &xLastExpireTime, xBlockTime );
\r
264 ulElapsedTimeInSeconds += xBlockTime;
\r
266 /* Have any of the standard demo tasks detected an error in their
\r
267 operation? If so, latch the offending test in a bit map so it can be
\r
268 printed to the terminal. Once one error has occurred the cycle rate is
\r
269 increased to increase the rate at which the LED toggles, which can cause
\r
270 further errors to be detected (as some tests will not expect the
\r
271 increased cycle rate). */
\r
273 ulErrorOccurred = 0UL;
\r
275 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
277 ulErrorOccurred |= ( 0x01UL << 0UL );
\r
280 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
282 ulErrorOccurred |= ( 0x01UL << 1UL );
\r
285 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
287 ulErrorOccurred |= ( 0x01UL << 2UL );
\r
290 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
292 ulErrorOccurred |= ( 0x01UL << 3UL );
\r
295 if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
\r
297 ulErrorOccurred |= ( 0x01UL << 4UL );
\r
300 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
302 ulErrorOccurred |= ( 0x01UL << 5UL );
\r
305 if( xIsQueueOverwriteTaskStillRunning() != pdTRUE )
\r
307 ulErrorOccurred |= ( 0x01UL << 6UL );
\r
310 if( xAreQueueSetTasksStillRunning() != pdTRUE )
\r
312 ulErrorOccurred |= ( 0x01UL << 7UL );
\r
315 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
317 ulErrorOccurred |= ( 0x01UL << 8UL );
\r
320 if( xAreEventGroupTasksStillRunning() != pdTRUE )
\r
322 ulErrorOccurred |= ( 0x01UL << 9UL );
\r
325 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
327 ulErrorOccurred |= ( 0x01UL << 10UL );
\r
330 if( xAreTimerDemoTasksStillRunning( xBlockTime ) != pdTRUE )
\r
332 ulErrorOccurred |= ( 0x01UL << 11UL );
\r
335 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
337 ulErrorOccurred |= ( 0x01UL << 12UL );
\r
340 if( xAreTaskNotificationTasksStillRunning() != pdTRUE )
\r
342 ulErrorOccurred |= ( 1UL << 13UL );
\r
345 if( xAreIntQueueTasksStillRunning() != pdTRUE )
\r
347 ulErrorOccurred |= ( 1UL << 14UL );
\r
350 #if configSUPPORT_FPU == 1
\r
352 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
354 ulErrorOccurred |= ( 0x01UL << 15UL );
\r
357 #endif /* configSUPPORT_FPU */
\r
359 /* Check the register test tasks are still looping. */
\r
360 if( ulRegTest1Counter == ulLastRegTest1Counter )
\r
362 ulErrorOccurred |= ( 0x01UL << 16UL );
\r
366 ulLastRegTest1Counter = ulRegTest1Counter;
\r
369 if( ulRegTest2Counter == ulLastRegTest2Counter )
\r
371 ulErrorOccurred |= ( 0x01UL << 17UL );
\r
375 ulLastRegTest2Counter = ulRegTest2Counter;
\r
378 if( ulErrorOccurred != 0UL )
\r
380 /* Decrease the block time, which will increase the rate at
\r
381 which the LED blinks - and in so doing - give visual feedback of
\r
382 the error status. */
\r
383 xBlockTime = mainERROR_CHECK_TASK_PERIOD;
\r
386 /* Print the hex bit pattern, time, and the loop number - just to make
\r
387 sure the task is still cycling. */
\r
388 g_printf_rcc( 5, 2, DEFAULT_SCREEN_COLOR,
\r
389 "Status code: 0x%08x at task check time : %8ds, loop #: %8d\r",
\r
390 ulErrorOccurred, ( ulElapsedTimeInSeconds / 1000 ), ( ulCheckLoops + 1 ) );
\r
392 /* Print the current free heap size and the minimum ever free heap
\r
394 g_printf_rcc( 6, 2, DEFAULT_SCREEN_COLOR,
\r
395 "Current free heap: %d bytes, Min. free heap: %d bytes\r",
\r
396 xPortGetFreeHeapSize(), xPortGetMinimumEverFreeHeapSize() );
\r
398 /* Show the first error that occurred on a separate line. */
\r
399 if( ( xErrorFlag == pdFALSE ) && ( ulErrorOccurred != pdFALSE ) )
\r
401 xErrorFlag = pdTRUE;
\r
402 g_printf_rcc( 7, 2, ANSI_COLOR_RED,
\r
403 "Error code: 0x%08x at check time : %8ds (First Error), loop#: %8d \r",
\r
404 ulErrorOccurred, ( ulElapsedTimeInSeconds / 1000 ), ( ulCheckLoops + 1 ) );
\r
407 /* Flash the LED */
\r
410 /* Crude Overflow check to keep printf() statements <= 8 digits long */
\r
412 if( ulCheckLoops > 10000000UL )
\r
414 ulCheckLoops = 0UL;
\r
418 /*-----------------------------------------------------------*/
\r