2 FreeRTOS V8.2.3 - Copyright (C) 2015 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
71 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
72 * documentation provides more details of the standard demo application tasks.
\r
74 * A "Check" task is created in addition to the standard demo tasks. This
\r
75 * only executes every three seconds but has a high priority to ensure it gets
\r
76 * processor time. Its main function is to check that all the standard demo
\r
77 * tasks are still operational. If everything is running as expected then the
\r
78 * check task will toggle an LED every 3 seconds. An error being discovered in
\r
79 * any task will cause the toggle rate to increase to 500ms.
\r
83 /* FreeRTOS includes. */
\r
84 #include "FreeRTOS.h"
\r
87 /* Standard demo includes. */
\r
89 #include "blocktim.h"
\r
90 #include "countsem.h"
\r
92 #include "dynamic.h"
\r
93 #include "GenQTest.h"
\r
94 #include "integer.h"
\r
97 #include "recmutex.h"
\r
98 #include "semtest.h"
\r
99 #include "ParTest.h"
\r
100 #include "comtest2.h"
\r
102 /* Standard includes. */
\r
105 /* Atmel library includes. */
\r
106 #include <pio/pio.h>
\r
108 /* Priorities for the demo application tasks. */
\r
109 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
110 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 0 )
\r
111 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
112 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 0 )
\r
113 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
114 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
115 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
117 /* The period of the check task both in and out of the presense of an error. */
\r
118 #define mainNO_ERROR_PERIOD ( 5000 / portTICK_PERIOD_MS )
\r
119 #define mainERROR_PERIOD ( 500 / portTICK_PERIOD_MS );
\r
121 /* Constants used by the ComTest task. */
\r
122 #define mainCOM_TEST_BAUD_RATE ( 38400 )
\r
123 #define mainCOM_TEST_LED ( LED_DS1 )
\r
125 /*-----------------------------------------------------------*/
\r
127 /* Simple hardware setup required by the demo. */
\r
128 static void prvSetupHardware( void );
\r
130 /* The check task as described at the top of this file. */
\r
131 static void prvCheckTask( void *pvParameters );
\r
133 /*-----------------------------------------------------------*/
\r
136 /* Perform any hardware setup necessary to run the demo. */
\r
137 prvSetupHardware();
\r
139 /* First create the 'standard demo' tasks. These exist just to to
\r
140 demonstrate API functions being used and test the kernel port. More
\r
141 information is provided on the FreeRTOS.org WEB site. */
\r
142 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
143 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
144 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
145 vStartDynamicPriorityTasks();
\r
146 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
147 vCreateBlockTimeTasks();
\r
148 vStartCountingSemaphoreTasks();
\r
149 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
150 vStartQueuePeekTasks();
\r
151 vStartRecursiveMutexTasks();
\r
152 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
154 /* Create the check task - this is the task that checks all the other tasks
\r
155 are executing as expected and without reporting any errors. */
\r
156 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );
\r
158 /* The death demo tasks must be started last as the sanity checks performed
\r
159 require knowledge of the number of other tasks in the system. */
\r
160 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
162 /* Start the scheduler. From this point on the execution will be under
\r
163 the control of the kernel. */
\r
164 vTaskStartScheduler();
\r
166 /* Will only get here if there was insufficient heap availale for the
\r
167 idle task to be created. */
\r
170 /*-----------------------------------------------------------*/
\r
172 static void prvCheckTask( void * pvParameters )
\r
174 TickType_t xNextWakeTime, xPeriod = mainNO_ERROR_PERIOD;
\r
175 static volatile unsigned long ulErrorCode = 0UL;
\r
177 /* Just to remove the compiler warning. */
\r
178 ( void ) pvParameters;
\r
180 /* Initialise xNextWakeTime prior to its first use. From this point on
\r
181 the value of the variable is handled automatically by the kernel. */
\r
182 xNextWakeTime = xTaskGetTickCount();
\r
186 /* Delay until it is time for this task to execute again. */
\r
187 vTaskDelayUntil( &xNextWakeTime, xPeriod );
\r
189 /* Check all the other tasks in the system - latch any reported errors
\r
190 into the ulErrorCode variable. */
\r
191 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
193 ulErrorCode |= 0x01UL;
\r
196 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
198 ulErrorCode |= 0x02UL;
\r
201 if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
\r
203 ulErrorCode |= 0x04UL;
\r
206 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
208 ulErrorCode |= 0x08UL;
\r
211 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
213 ulErrorCode |= 0x10UL;
\r
216 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
218 ulErrorCode |= 0x20UL;
\r
221 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
223 ulErrorCode |= 0x40UL;
\r
226 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
228 ulErrorCode |= 0x80UL;
\r
231 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
233 ulErrorCode |= 0x100UL;
\r
236 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
238 ulErrorCode |= 0x200UL;
\r
241 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
243 ulErrorCode |= 0x400UL;
\r
246 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
248 ulErrorCode |= 0x800UL;
\r
251 /* Reduce the block period and in so doing increase the frequency at
\r
252 which this task executes if any errors have been latched. The increased
\r
253 frequency causes the LED toggle rate to increase and so gives some
\r
254 visual feedback that an error has occurred. */
\r
255 if( ulErrorCode != 0x00 )
\r
257 xPeriod = mainERROR_PERIOD;
\r
260 /* Finally toggle the LED. */
\r
261 vParTestToggleLED( LED_POWER );
\r
264 /*-----------------------------------------------------------*/
\r
266 static void prvSetupHardware( void )
\r
268 const Pin xPins[] = { PIN_USART0_RXD, PIN_USART0_TXD };
\r
270 /* Setup the LED outputs. */
\r
271 vParTestInitialise();
\r
273 /* Setup the pins for the UART. */
\r
274 PIO_Configure( xPins, PIO_LISTSIZE( xPins ) );
\r