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
29 /******************************************************************************
\r
30 * NOTE 1: This project provides two demo applications. A simple blinky style
\r
31 * project, and a more comprehensive test and demo application. The
\r
32 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select
\r
33 * between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY
\r
34 * in main.c. This file implements the comprehensive test and demo version.
\r
36 * NOTE 2: This file only contains the source code that is specific to the
\r
37 * full demo. Generic functions, such FreeRTOS hook functions, and functions
\r
38 * required to configure the hardware, are defined in main.c.
\r
40 ******************************************************************************
\r
42 * See http://www.FreeRTOS.org/RTOS_Intel_Quark_Galileo_GCC.html for usage
\r
45 * main_full() creates all the demo application tasks and software timers, then
\r
46 * starts the scheduler. The web documentation provides more details of the
\r
47 * standard demo application tasks, which provide no particular functionality,
\r
48 * but do provide a good example of how to use the FreeRTOS API.
\r
50 * In addition to the standard demo tasks, the following tasks and tests are
\r
51 * defined and/or created within this file:
\r
53 * "Reg test" tasks - These fill both the core and floating point registers with
\r
54 * known values, then check that each register maintains its expected value for
\r
55 * the lifetime of the task. Each task uses a different set of values. The reg
\r
56 * test tasks execute with a very low priority, so get preempted very
\r
57 * frequently. A register containing an unexpected value is indicative of an
\r
58 * error in the context switching mechanism.
\r
60 * "Check" task - The check task period is set to five seconds. The task checks
\r
61 * that all the standard demo tasks, and the register check tasks, are not only
\r
62 * still executing, but are executing without reporting any errors. The check
\r
63 * task toggles an LED on each iteration. If the LED toggles every 5 seconds
\r
64 * then no errors have been found. If the LED toggles every 1 second then a
\r
65 * potential error has been detected.
\r
68 /* Standard includes. */
\r
74 /* FreeRTOS includes. */
\r
75 #include "FreeRTOS.h"
\r
79 /* Standard demo includes. */
\r
80 #include "blocktim.h"
\r
81 #include "flash_timer.h"
\r
82 #include "semtest.h"
\r
83 #include "GenQTest.h"
\r
85 #include "countsem.h"
\r
86 #include "dynamic.h"
\r
87 #include "QueueOverwrite.h"
\r
88 #include "QueueSet.h"
\r
89 #include "recmutex.h"
\r
90 #include "EventGroupsDemo.h"
\r
92 #include "TimerDemo.h"
\r
95 #include "TaskNotify.h"
\r
96 #include "IntQueue.h"
\r
98 /* Galileo includes. */
\r
99 #include "galileo_support.h"
\r
101 /* The rate at which the check task cycles if no errors have been detected, and
\r
102 if a [potential] error has been detected. Increasing the toggle rate in the
\r
103 presense of an error gives visual feedback of the system status. */
\r
104 #define mainNO_ERROR_CHECK_TASK_PERIOD pdMS_TO_TICKS( 5000UL )
\r
105 #define mainERROR_CHECK_TASK_PERIOD pdMS_TO_TICKS( 1000UL )
\r
107 /* The priorities of the various demo application tasks. */
\r
108 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
109 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
110 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
111 #define mainQUEUE_OVERWRITE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
112 #define mainMATHS_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
114 /* The base period used by the timer test tasks. */
\r
115 #define mainTIMER_TEST_PERIOD ( 50 )
\r
117 /* Parameters that are passed into the check tasks for no other purpose other
\r
118 than to check the port does this correctly. */
\r
119 #define mainREG_TEST_1_PARAMETER ( 0x12345678UL )
\r
120 #define mainREG_TEST_2_PARAMETER ( 0x87654321UL )
\r
122 /*-----------------------------------------------------------*/
\r
125 * The function that implements the check task, as described at the top of this
\r
128 static void prvCheckTask( void *pvParameters );
\r
131 * Entry points for the register check tasks, as described at the top of this
\r
134 static void prvRegTest1Entry( void *pvParameters );
\r
135 static void prvRegTest2Entry( void *pvParameters );
\r
138 * The implementation of the register check tasks, which are implemented in
\r
139 * RegTest.S. These functions are called by prvRegTest1Entry() and
\r
140 * prvRegTest2Entry() respectively.
\r
142 extern void vRegTest1( void );
\r
143 extern void vRegTest2( void );
\r
145 /*-----------------------------------------------------------*/
\r
147 /* Constants used by the register check tasks when checking the FPU registers. */
\r
148 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
149 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
151 /* Counters used by the register check tasks to indicate that they are still
\r
152 executing without having discovered any errors. */
\r
153 volatile uint32_t ulRegTest1Counter, ulRegTest2Counter;
\r
154 volatile uint32_t ulCheckLoops = 0;
\r
156 /*-----------------------------------------------------------*/
\r
158 /* See http://www.FreeRTOS.org/RTOS_Intel_Quark_Galileo_GCC.html for usage
\r
160 void main_full( void )
\r
162 /* Create all the other standard demo tasks. */
\r
163 vCreateBlockTimeTasks();
\r
164 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
165 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
166 vStartQueuePeekTasks();
\r
167 vStartCountingSemaphoreTasks();
\r
168 vStartDynamicPriorityTasks();
\r
169 vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_TASK_PRIORITY );
\r
170 vStartQueueSetTasks();
\r
171 vStartRecursiveMutexTasks();
\r
172 vStartEventGroupTasks();
\r
173 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );
\r
174 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
175 vStartTaskNotifyTask();
\r
176 vStartInterruptQueueTasks();
\r
178 #if configSUPPORT_FPU == 1
\r
180 vStartMathTasks( mainMATHS_TASK_PRIORITY );
\r
182 #endif /* configSUPPORT_FPU */
\r
184 /* Create the 'check' task, as described at the top of this file. */
\r
185 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE * 2, NULL, configMAX_PRIORITIES - 1, NULL );
\r
187 /* Create the register test tasks, as described at the top of this file. */
\r
188 xTaskCreate( prvRegTest1Entry, "Reg1", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_1_PARAMETER, tskIDLE_PRIORITY, NULL );
\r
189 xTaskCreate( prvRegTest2Entry, "Reg2", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_2_PARAMETER, tskIDLE_PRIORITY, NULL );
\r
191 /* Death tasks must be created last as they check the number of tasks
\r
192 running against the number of tasks expected to be running as part of their
\r
194 vCreateSuicidalTasks( tskIDLE_PRIORITY );
\r
196 /* Display HPET Information (Disable in HPET.H). */
\r
197 vCreateHPETInfoUpdateTask();
\r
199 /* Start the scheduler itself. */
\r
200 vTaskStartScheduler();
\r
202 /* If all is well, the scheduler will now be running, and the following line
\r
203 will never be reached. If the following line does execute, then there was
\r
204 insufficient FreeRTOS heap memory available for the idle and/or timer tasks
\r
205 to be created. See the memory management section on the FreeRTOS web site
\r
206 for more details. */
\r
209 /*-----------------------------------------------------------*/
\r
211 static void prvRegTest1Entry( void *pvParameters )
\r
213 /* Remove compiler warning if configASSERT() is not defined. */
\r
214 ( void ) pvParameters;
\r
216 /* Check the parameter is passed in correctly. */
\r
217 configASSERT( ( ( uint32_t) pvParameters ) == mainREG_TEST_1_PARAMETER );
\r
219 /* Tell FreeRTOS that this task needs a floating point context. */
\r
220 portTASK_USES_FLOATING_POINT();
\r
222 /* Call the assembly file routine that performs the 'reg test' functionality
\r
223 as described at the top of this file. */
\r
226 /*-----------------------------------------------------------*/
\r
228 static void prvRegTest2Entry( void *pvParameters )
\r
230 /* Remove compiler warning if configASSERT() is not defined. */
\r
231 ( void ) pvParameters;
\r
233 /* Check the parameter is passed in correctly. */
\r
234 configASSERT( ( ( uint32_t) pvParameters ) == mainREG_TEST_2_PARAMETER );
\r
236 /* Tell FreeRTOS that this task needs a floating point context. */
\r
237 portTASK_USES_FLOATING_POINT();
\r
239 /* Call the assembly file routine that performs the 'reg test' functionality
\r
240 as described at the top of this file. */
\r
243 /*-----------------------------------------------------------*/
\r
245 static void prvCheckTask( void *pvParameters )
\r
247 uint32_t ulLastRegTest1Counter = 0UL, ulLastRegTest2Counter = 0UL;
\r
248 uint32_t ulErrorOccurred, ulElapsedTimeInSeconds = 0UL;
\r
249 TickType_t xLastExpireTime, xBlockTime = mainNO_ERROR_CHECK_TASK_PERIOD;
\r
250 BaseType_t xErrorFlag = pdFALSE;
\r
252 /* Avoid compiler warnings. */
\r
253 ( void ) pvParameters;
\r
255 /* Initialise the last expire time to the current time. */
\r
256 xLastExpireTime = xTaskGetTickCount();
\r
258 /* Message to wait for an update - first update won't happen for X seconds. */
\r
259 g_printf_rcc( 5, 2, DEFAULT_SCREEN_COLOR, "Starting task check loop - Please wait for a status update." );
\r
260 g_printf_rcc( 6, 2, DEFAULT_SCREEN_COLOR, "No task errors encountered." );
\r
264 vTaskDelayUntil( &xLastExpireTime, xBlockTime );
\r
265 ulElapsedTimeInSeconds += xBlockTime;
\r
267 /* Have any of the standard demo tasks detected an error in their
\r
268 operation? If so, latch the offending test in a bit map so it can be
\r
269 printed to the terminal. Once one error has occurred the cycle rate is
\r
270 increased to increase the rate at which the LED toggles, which can cause
\r
271 further errors to be detected (as some tests will not expect the
\r
272 increased cycle rate). */
\r
274 ulErrorOccurred = 0UL;
\r
276 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
278 ulErrorOccurred |= ( 0x01UL << 0UL );
\r
281 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
283 ulErrorOccurred |= ( 0x01UL << 1UL );
\r
286 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
288 ulErrorOccurred |= ( 0x01UL << 2UL );
\r
291 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
293 ulErrorOccurred |= ( 0x01UL << 3UL );
\r
296 if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
\r
298 ulErrorOccurred |= ( 0x01UL << 4UL );
\r
301 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
303 ulErrorOccurred |= ( 0x01UL << 5UL );
\r
306 if( xIsQueueOverwriteTaskStillRunning() != pdTRUE )
\r
308 ulErrorOccurred |= ( 0x01UL << 6UL );
\r
311 if( xAreQueueSetTasksStillRunning() != pdTRUE )
\r
313 ulErrorOccurred |= ( 0x01UL << 7UL );
\r
316 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
318 ulErrorOccurred |= ( 0x01UL << 8UL );
\r
321 if( xAreEventGroupTasksStillRunning() != pdTRUE )
\r
323 ulErrorOccurred |= ( 0x01UL << 9UL );
\r
326 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
328 ulErrorOccurred |= ( 0x01UL << 10UL );
\r
331 if( xAreTimerDemoTasksStillRunning( xBlockTime ) != pdTRUE )
\r
333 ulErrorOccurred |= ( 0x01UL << 11UL );
\r
336 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
338 ulErrorOccurred |= ( 0x01UL << 12UL );
\r
341 if( xAreTaskNotificationTasksStillRunning() != pdTRUE )
\r
343 ulErrorOccurred |= ( 1UL << 13UL );
\r
346 if( xAreIntQueueTasksStillRunning() != pdTRUE )
\r
348 ulErrorOccurred |= ( 1UL << 14UL );
\r
351 #if configSUPPORT_FPU == 1
\r
353 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
355 ulErrorOccurred |= ( 0x01UL << 15UL );
\r
358 #endif /* configSUPPORT_FPU */
\r
360 /* Check the register test tasks are still looping. */
\r
361 if( ulRegTest1Counter == ulLastRegTest1Counter )
\r
363 ulErrorOccurred |= ( 0x01UL << 16UL );
\r
367 ulLastRegTest1Counter = ulRegTest1Counter;
\r
370 if( ulRegTest2Counter == ulLastRegTest2Counter )
\r
372 ulErrorOccurred |= ( 0x01UL << 17UL );
\r
376 ulLastRegTest2Counter = ulRegTest2Counter;
\r
379 if( ulErrorOccurred != 0UL )
\r
381 /* Decrease the block time, which will increase the rate at
\r
382 which the LED blinks - and in so doing - give visual feedback of
\r
383 the error status. */
\r
384 xBlockTime = mainERROR_CHECK_TASK_PERIOD;
\r
387 /* Print the hex bit pattern, time, and the loop number - just to make
\r
388 sure the task is still cycling. */
\r
389 g_printf_rcc( 5, 2, DEFAULT_SCREEN_COLOR,
\r
390 "Status code: 0x%08x at task check time : %8ds, loop #: %8d\r",
\r
391 ulErrorOccurred, ( ulElapsedTimeInSeconds / 1000 ), ( ulCheckLoops + 1 ) );
\r
393 /* Print the current free heap size and the minimum ever free heap
\r
395 g_printf_rcc( 6, 2, DEFAULT_SCREEN_COLOR,
\r
396 "Current free heap: %d bytes, Min. free heap: %d bytes\r",
\r
397 xPortGetFreeHeapSize(), xPortGetMinimumEverFreeHeapSize() );
\r
399 /* Show the first error that occurred on a separate line. */
\r
400 if( ( xErrorFlag == pdFALSE ) && ( ulErrorOccurred != pdFALSE ) )
\r
402 xErrorFlag = pdTRUE;
\r
403 g_printf_rcc( 7, 2, ANSI_COLOR_RED,
\r
404 "Error code: 0x%08x at check time : %8ds (First Error), loop#: %8d \r",
\r
405 ulErrorOccurred, ( ulElapsedTimeInSeconds / 1000 ), ( ulCheckLoops + 1 ) );
\r
408 /* Flash the LED */
\r
411 /* Crude Overflow check to keep printf() statements <= 8 digits long */
\r
413 if( ulCheckLoops > 10000000UL )
\r
415 ulCheckLoops = 0UL;
\r
419 /*-----------------------------------------------------------*/
\r