2 FreeRTOS V9.0.1 - Copyright (C) 2017 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
70 /******************************************************************************
\r
71 * NOTE 1: This project provides two demo applications. A simple blinky style
\r
72 * project, and a more comprehensive test and demo application. The
\r
73 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select
\r
74 * between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY
\r
75 * in main.c. This file implements the comprehensive test and demo version.
\r
77 * NOTE 2: This file only contains the source code that is specific to the
\r
78 * full demo. Generic functions, such FreeRTOS hook functions, and functions
\r
79 * required to configure the hardware, are defined in main.c.
\r
81 ******************************************************************************
\r
83 * See http://www.FreeRTOS.org/RTOS_Intel_Quark_Galileo_GCC.html for usage
\r
86 * main_full() creates all the demo application tasks and software timers, then
\r
87 * starts the scheduler. The web documentation provides more details of the
\r
88 * standard demo application tasks, which provide no particular functionality,
\r
89 * but do provide a good example of how to use the FreeRTOS API.
\r
91 * In addition to the standard demo tasks, the following tasks and tests are
\r
92 * defined and/or created within this file:
\r
94 * "Reg test" tasks - These fill both the core and floating point registers with
\r
95 * known values, then check that each register maintains its expected value for
\r
96 * the lifetime of the task. Each task uses a different set of values. The reg
\r
97 * test tasks execute with a very low priority, so get preempted very
\r
98 * frequently. A register containing an unexpected value is indicative of an
\r
99 * error in the context switching mechanism.
\r
101 * "Check" task - The check task period is set to five seconds. The task checks
\r
102 * that all the standard demo tasks, and the register check tasks, are not only
\r
103 * still executing, but are executing without reporting any errors. The check
\r
104 * task toggles an LED on each iteration. If the LED toggles every 5 seconds
\r
105 * then no errors have been found. If the LED toggles every 1 second then a
\r
106 * potential error has been detected.
\r
109 /* Standard includes. */
\r
111 #include <stdlib.h>
\r
112 #include <string.h>
\r
113 #include <stdint.h>
\r
115 /* FreeRTOS includes. */
\r
116 #include "FreeRTOS.h"
\r
118 #include "timers.h"
\r
120 /* Standard demo includes. */
\r
121 #include "blocktim.h"
\r
122 #include "flash_timer.h"
\r
123 #include "semtest.h"
\r
124 #include "GenQTest.h"
\r
126 #include "countsem.h"
\r
127 #include "dynamic.h"
\r
128 #include "QueueOverwrite.h"
\r
129 #include "QueueSet.h"
\r
130 #include "recmutex.h"
\r
131 #include "EventGroupsDemo.h"
\r
133 #include "TimerDemo.h"
\r
134 #include "BlockQ.h"
\r
136 #include "TaskNotify.h"
\r
137 #include "IntQueue.h"
\r
139 /* Galileo includes. */
\r
140 #include "galileo_support.h"
\r
142 /* The rate at which the check task cycles if no errors have been detected, and
\r
143 if a [potential] error has been detected. Increasing the toggle rate in the
\r
144 presense of an error gives visual feedback of the system status. */
\r
145 #define mainNO_ERROR_CHECK_TASK_PERIOD pdMS_TO_TICKS( 5000UL )
\r
146 #define mainERROR_CHECK_TASK_PERIOD pdMS_TO_TICKS( 1000UL )
\r
148 /* The priorities of the various demo application tasks. */
\r
149 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
150 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
151 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
152 #define mainQUEUE_OVERWRITE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
153 #define mainMATHS_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
155 /* The base period used by the timer test tasks. */
\r
156 #define mainTIMER_TEST_PERIOD ( 50 )
\r
158 /* Parameters that are passed into the check tasks for no other purpose other
\r
159 than to check the port does this correctly. */
\r
160 #define mainREG_TEST_1_PARAMETER ( 0x12345678UL )
\r
161 #define mainREG_TEST_2_PARAMETER ( 0x87654321UL )
\r
163 /*-----------------------------------------------------------*/
\r
166 * The function that implements the check task, as described at the top of this
\r
169 static void prvCheckTask( void *pvParameters );
\r
172 * Entry points for the register check tasks, as described at the top of this
\r
175 static void prvRegTest1Entry( void *pvParameters );
\r
176 static void prvRegTest2Entry( void *pvParameters );
\r
179 * The implementation of the register check tasks, which are implemented in
\r
180 * RegTest.S. These functions are called by prvRegTest1Entry() and
\r
181 * prvRegTest2Entry() respectively.
\r
183 extern void vRegTest1( void );
\r
184 extern void vRegTest2( void );
\r
186 /*-----------------------------------------------------------*/
\r
188 /* Constants used by the register check tasks when checking the FPU registers. */
\r
189 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
190 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
192 /* Counters used by the register check tasks to indicate that they are still
\r
193 executing without having discovered any errors. */
\r
194 volatile uint32_t ulRegTest1Counter, ulRegTest2Counter;
\r
195 volatile uint32_t ulCheckLoops = 0;
\r
197 /*-----------------------------------------------------------*/
\r
199 /* See http://www.FreeRTOS.org/RTOS_Intel_Quark_Galileo_GCC.html for usage
\r
201 void main_full( void )
\r
203 /* Create all the other standard demo tasks. */
\r
204 vCreateBlockTimeTasks();
\r
205 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
206 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
207 vStartQueuePeekTasks();
\r
208 vStartCountingSemaphoreTasks();
\r
209 vStartDynamicPriorityTasks();
\r
210 vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_TASK_PRIORITY );
\r
211 vStartQueueSetTasks();
\r
212 vStartRecursiveMutexTasks();
\r
213 vStartEventGroupTasks();
\r
214 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );
\r
215 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
216 vStartTaskNotifyTask();
\r
217 vStartInterruptQueueTasks();
\r
219 #if configSUPPORT_FPU == 1
\r
221 vStartMathTasks( mainMATHS_TASK_PRIORITY );
\r
223 #endif /* configSUPPORT_FPU */
\r
225 /* Create the 'check' task, as described at the top of this file. */
\r
226 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE * 2, NULL, configMAX_PRIORITIES - 1, NULL );
\r
228 /* Create the register test tasks, as described at the top of this file. */
\r
229 xTaskCreate( prvRegTest1Entry, "Reg1", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_1_PARAMETER, tskIDLE_PRIORITY, NULL );
\r
230 xTaskCreate( prvRegTest2Entry, "Reg2", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_2_PARAMETER, tskIDLE_PRIORITY, NULL );
\r
232 /* Death tasks must be created last as they check the number of tasks
\r
233 running against the number of tasks expected to be running as part of their
\r
235 vCreateSuicidalTasks( tskIDLE_PRIORITY );
\r
237 /* Display HPET Information (Disable in HPET.H). */
\r
238 vCreateHPETInfoUpdateTask();
\r
240 /* Start the scheduler itself. */
\r
241 vTaskStartScheduler();
\r
243 /* If all is well, the scheduler will now be running, and the following line
\r
244 will never be reached. If the following line does execute, then there was
\r
245 insufficient FreeRTOS heap memory available for the idle and/or timer tasks
\r
246 to be created. See the memory management section on the FreeRTOS web site
\r
247 for more details. */
\r
250 /*-----------------------------------------------------------*/
\r
252 static void prvRegTest1Entry( void *pvParameters )
\r
254 /* Remove compiler warning if configASSERT() is not defined. */
\r
255 ( void ) pvParameters;
\r
257 /* Check the parameter is passed in correctly. */
\r
258 configASSERT( ( ( uint32_t) pvParameters ) == mainREG_TEST_1_PARAMETER );
\r
260 /* Tell FreeRTOS that this task needs a floating point context. */
\r
261 portTASK_USES_FLOATING_POINT();
\r
263 /* Call the assembly file routine that performs the 'reg test' functionality
\r
264 as described at the top of this file. */
\r
267 /*-----------------------------------------------------------*/
\r
269 static void prvRegTest2Entry( void *pvParameters )
\r
271 /* Remove compiler warning if configASSERT() is not defined. */
\r
272 ( void ) pvParameters;
\r
274 /* Check the parameter is passed in correctly. */
\r
275 configASSERT( ( ( uint32_t) pvParameters ) == mainREG_TEST_2_PARAMETER );
\r
277 /* Tell FreeRTOS that this task needs a floating point context. */
\r
278 portTASK_USES_FLOATING_POINT();
\r
280 /* Call the assembly file routine that performs the 'reg test' functionality
\r
281 as described at the top of this file. */
\r
284 /*-----------------------------------------------------------*/
\r
286 static void prvCheckTask( void *pvParameters )
\r
288 uint32_t ulLastRegTest1Counter = 0UL, ulLastRegTest2Counter = 0UL;
\r
289 uint32_t ulErrorOccurred, ulElapsedTimeInSeconds = 0UL;
\r
290 TickType_t xLastExpireTime, xBlockTime = mainNO_ERROR_CHECK_TASK_PERIOD;
\r
291 BaseType_t xErrorFlag = pdFALSE;
\r
293 /* Avoid compiler warnings. */
\r
294 ( void ) pvParameters;
\r
296 /* Initialise the last expire time to the current time. */
\r
297 xLastExpireTime = xTaskGetTickCount();
\r
299 /* Message to wait for an update - first update won't happen for X seconds. */
\r
300 g_printf_rcc( 5, 2, DEFAULT_SCREEN_COLOR, "Starting task check loop - Please wait for a status update." );
\r
301 g_printf_rcc( 6, 2, DEFAULT_SCREEN_COLOR, "No task errors encountered." );
\r
305 vTaskDelayUntil( &xLastExpireTime, xBlockTime );
\r
306 ulElapsedTimeInSeconds += xBlockTime;
\r
308 /* Have any of the standard demo tasks detected an error in their
\r
309 operation? If so, latch the offending test in a bit map so it can be
\r
310 printed to the terminal. Once one error has occurred the cycle rate is
\r
311 increased to increase the rate at which the LED toggles, which can cause
\r
312 further errors to be detected (as some tests will not expect the
\r
313 increased cycle rate). */
\r
315 ulErrorOccurred = 0UL;
\r
317 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
319 ulErrorOccurred |= ( 0x01UL << 0UL );
\r
322 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
324 ulErrorOccurred |= ( 0x01UL << 1UL );
\r
327 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
329 ulErrorOccurred |= ( 0x01UL << 2UL );
\r
332 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
334 ulErrorOccurred |= ( 0x01UL << 3UL );
\r
337 if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
\r
339 ulErrorOccurred |= ( 0x01UL << 4UL );
\r
342 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
344 ulErrorOccurred |= ( 0x01UL << 5UL );
\r
347 if( xIsQueueOverwriteTaskStillRunning() != pdTRUE )
\r
349 ulErrorOccurred |= ( 0x01UL << 6UL );
\r
352 if( xAreQueueSetTasksStillRunning() != pdTRUE )
\r
354 ulErrorOccurred |= ( 0x01UL << 7UL );
\r
357 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
359 ulErrorOccurred |= ( 0x01UL << 8UL );
\r
362 if( xAreEventGroupTasksStillRunning() != pdTRUE )
\r
364 ulErrorOccurred |= ( 0x01UL << 9UL );
\r
367 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
369 ulErrorOccurred |= ( 0x01UL << 10UL );
\r
372 if( xAreTimerDemoTasksStillRunning( xBlockTime ) != pdTRUE )
\r
374 ulErrorOccurred |= ( 0x01UL << 11UL );
\r
377 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
379 ulErrorOccurred |= ( 0x01UL << 12UL );
\r
382 if( xAreTaskNotificationTasksStillRunning() != pdTRUE )
\r
384 ulErrorOccurred |= ( 1UL << 13UL );
\r
387 if( xAreIntQueueTasksStillRunning() != pdTRUE )
\r
389 ulErrorOccurred |= ( 1UL << 14UL );
\r
392 #if configSUPPORT_FPU == 1
\r
394 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
396 ulErrorOccurred |= ( 0x01UL << 15UL );
\r
399 #endif /* configSUPPORT_FPU */
\r
401 /* Check the register test tasks are still looping. */
\r
402 if( ulRegTest1Counter == ulLastRegTest1Counter )
\r
404 ulErrorOccurred |= ( 0x01UL << 16UL );
\r
408 ulLastRegTest1Counter = ulRegTest1Counter;
\r
411 if( ulRegTest2Counter == ulLastRegTest2Counter )
\r
413 ulErrorOccurred |= ( 0x01UL << 17UL );
\r
417 ulLastRegTest2Counter = ulRegTest2Counter;
\r
420 if( ulErrorOccurred != 0UL )
\r
422 /* Decrease the block time, which will increase the rate at
\r
423 which the LED blinks - and in so doing - give visual feedback of
\r
424 the error status. */
\r
425 xBlockTime = mainERROR_CHECK_TASK_PERIOD;
\r
428 /* Print the hex bit pattern, time, and the loop number - just to make
\r
429 sure the task is still cycling. */
\r
430 g_printf_rcc( 5, 2, DEFAULT_SCREEN_COLOR,
\r
431 "Status code: 0x%08x at task check time : %8ds, loop #: %8d\r",
\r
432 ulErrorOccurred, ( ulElapsedTimeInSeconds / 1000 ), ( ulCheckLoops + 1 ) );
\r
434 /* Print the current free heap size and the minimum ever free heap
\r
436 g_printf_rcc( 6, 2, DEFAULT_SCREEN_COLOR,
\r
437 "Current free heap: %d bytes, Min. free heap: %d bytes\r",
\r
438 xPortGetFreeHeapSize(), xPortGetMinimumEverFreeHeapSize() );
\r
440 /* Show the first error that occurred on a separate line. */
\r
441 if( ( xErrorFlag == pdFALSE ) && ( ulErrorOccurred != pdFALSE ) )
\r
443 xErrorFlag = pdTRUE;
\r
444 g_printf_rcc( 7, 2, ANSI_COLOR_RED,
\r
445 "Error code: 0x%08x at check time : %8ds (First Error), loop#: %8d \r",
\r
446 ulErrorOccurred, ( ulElapsedTimeInSeconds / 1000 ), ( ulCheckLoops + 1 ) );
\r
449 /* Flash the LED */
\r
452 /* Crude Overflow check to keep printf() statements <= 8 digits long */
\r
454 if( ulCheckLoops > 10000000UL )
\r
456 ulCheckLoops = 0UL;
\r
460 /*-----------------------------------------------------------*/
\r