2 FreeRTOS V8.0.0:rc1 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
28 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
29 >>! the source code for proprietary components outside of the FreeRTOS
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
67 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
68 * documentation provides more details of the standard demo application tasks.
\r
70 * A "Check" task is created in addition to the standard demo tasks. This
\r
71 * only executes every three seconds but has a high priority to ensure it gets
\r
72 * processor time. Its main function is to check that all the standard demo
\r
73 * tasks are still operational. If everything is running as expected then the
\r
74 * check task will toggle an LED every 3 seconds. An error being discovered in
\r
75 * any task will cause the toggle rate to increase to 500ms.
\r
79 /* FreeRTOS includes. */
\r
80 #include "FreeRTOS.h"
\r
83 /* Standard demo includes. */
\r
85 #include "blocktim.h"
\r
86 #include "countsem.h"
\r
88 #include "dynamic.h"
\r
89 #include "GenQTest.h"
\r
90 #include "integer.h"
\r
93 #include "recmutex.h"
\r
94 #include "semtest.h"
\r
95 #include "ParTest.h"
\r
96 #include "comtest2.h"
\r
98 /* Standard includes. */
\r
101 /* Atmel library includes. */
\r
102 #include <pio/pio.h>
\r
104 /* Priorities for the demo application tasks. */
\r
105 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
106 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 0 )
\r
107 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
108 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 0 )
\r
109 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
110 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
111 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
113 /* The period of the check task both in and out of the presense of an error. */
\r
114 #define mainNO_ERROR_PERIOD ( 5000 / portTICK_RATE_MS )
\r
115 #define mainERROR_PERIOD ( 500 / portTICK_RATE_MS );
\r
117 /* Constants used by the ComTest task. */
\r
118 #define mainCOM_TEST_BAUD_RATE ( 38400 )
\r
119 #define mainCOM_TEST_LED ( LED_DS1 )
\r
121 /*-----------------------------------------------------------*/
\r
123 /* Simple hardware setup required by the demo. */
\r
124 static void prvSetupHardware( void );
\r
126 /* The check task as described at the top of this file. */
\r
127 static void prvCheckTask( void *pvParameters );
\r
129 /*-----------------------------------------------------------*/
\r
132 /* Perform any hardware setup necessary to run the demo. */
\r
133 prvSetupHardware();
\r
135 /* First create the 'standard demo' tasks. These exist just to to
\r
136 demonstrate API functions being used and test the kernel port. More
\r
137 information is provided on the FreeRTOS.org WEB site. */
\r
138 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
139 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
140 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
141 vStartDynamicPriorityTasks();
\r
142 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
143 vCreateBlockTimeTasks();
\r
144 vStartCountingSemaphoreTasks();
\r
145 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
146 vStartQueuePeekTasks();
\r
147 vStartRecursiveMutexTasks();
\r
148 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
150 /* Create the check task - this is the task that checks all the other tasks
\r
151 are executing as expected and without reporting any errors. */
\r
152 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );
\r
154 /* The death demo tasks must be started last as the sanity checks performed
\r
155 require knowledge of the number of other tasks in the system. */
\r
156 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
158 /* Start the scheduler. From this point on the execution will be under
\r
159 the control of the kernel. */
\r
160 vTaskStartScheduler();
\r
162 /* Will only get here if there was insufficient heap availale for the
\r
163 idle task to be created. */
\r
166 /*-----------------------------------------------------------*/
\r
168 static void prvCheckTask( void * pvParameters )
\r
170 portTickType xNextWakeTime, xPeriod = mainNO_ERROR_PERIOD;
\r
171 static volatile unsigned long ulErrorCode = 0UL;
\r
173 /* Just to remove the compiler warning. */
\r
174 ( void ) pvParameters;
\r
176 /* Initialise xNextWakeTime prior to its first use. From this point on
\r
177 the value of the variable is handled automatically by the kernel. */
\r
178 xNextWakeTime = xTaskGetTickCount();
\r
182 /* Delay until it is time for this task to execute again. */
\r
183 vTaskDelayUntil( &xNextWakeTime, xPeriod );
\r
185 /* Check all the other tasks in the system - latch any reported errors
\r
186 into the ulErrorCode variable. */
\r
187 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
189 ulErrorCode |= 0x01UL;
\r
192 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
194 ulErrorCode |= 0x02UL;
\r
197 if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
\r
199 ulErrorCode |= 0x04UL;
\r
202 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
204 ulErrorCode |= 0x08UL;
\r
207 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
209 ulErrorCode |= 0x10UL;
\r
212 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
214 ulErrorCode |= 0x20UL;
\r
217 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
219 ulErrorCode |= 0x40UL;
\r
222 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
224 ulErrorCode |= 0x80UL;
\r
227 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
229 ulErrorCode |= 0x100UL;
\r
232 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
234 ulErrorCode |= 0x200UL;
\r
237 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
239 ulErrorCode |= 0x400UL;
\r
242 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
244 ulErrorCode |= 0x800UL;
\r
247 /* Reduce the block period and in so doing increase the frequency at
\r
248 which this task executes if any errors have been latched. The increased
\r
249 frequency causes the LED toggle rate to increase and so gives some
\r
250 visual feedback that an error has occurred. */
\r
251 if( ulErrorCode != 0x00 )
\r
253 xPeriod = mainERROR_PERIOD;
\r
256 /* Finally toggle the LED. */
\r
257 vParTestToggleLED( LED_POWER );
\r
260 /*-----------------------------------------------------------*/
\r
262 static void prvSetupHardware( void )
\r
264 const Pin xPins[] = { PIN_USART0_RXD, PIN_USART0_TXD };
\r
266 /* Setup the LED outputs. */
\r
267 vParTestInitialise();
\r
269 /* Setup the pins for the UART. */
\r
270 PIO_Configure( xPins, PIO_LISTSIZE( xPins ) );
\r