2 FreeRTOS.org V5.3.1 - Copyright (C) 2003-2009 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify it
\r
7 under the terms of the GNU General Public License (version 2) as published
\r
8 by the Free Software Foundation and modified by the FreeRTOS exception.
\r
9 **NOTE** The exception to the GPL is included to allow you to distribute a
\r
10 combined work that includes FreeRTOS.org without being obliged to provide
\r
11 the source code for any proprietary components. Alternative commercial
\r
12 license and support terms are also available upon request. See the
\r
13 licensing section of http://www.FreeRTOS.org for full details.
\r
15 FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT
\r
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
20 You should have received a copy of the GNU General Public License along
\r
21 with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59
\r
22 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
25 ***************************************************************************
\r
27 * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *
\r
29 * This is a concise, step by step, 'hands on' guide that describes both *
\r
30 * general multitasking concepts and FreeRTOS specifics. It presents and *
\r
31 * explains numerous examples that are written using the FreeRTOS API. *
\r
32 * Full source code for all the examples is provided in an accompanying *
\r
35 ***************************************************************************
\r
39 Please ensure to read the configuration and relevant port sections of the
\r
40 online documentation.
\r
42 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
45 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
48 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
49 licensing and training services.
\r
53 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
54 * documentation provides more details of the standard demo application tasks.
\r
56 * A "Check" task is created in addition to the standard demo tasks. This
\r
57 * only executes every three seconds but has a high priority to ensure it gets
\r
58 * processor time. Its main function is to check that all the standard demo
\r
59 * tasks are still operational. If everything is running as expected then the
\r
60 * check task will toggle an LED every 3 seconds. An error being discovered in
\r
61 * any task will cause the toggle rate to increase to 500ms.
\r
65 /* FreeRTOS includes. */
\r
66 #include "FreeRTOS.h"
\r
69 /* Standard demo includes. */
\r
71 #include "blocktim.h"
\r
72 #include "countsem.h"
\r
74 #include "dynamic.h"
\r
75 #include "GenQTest.h"
\r
76 #include "integer.h"
\r
79 #include "recmutex.h"
\r
80 #include "semtest.h"
\r
81 #include "ParTest.h"
\r
82 #include "comtest2.h"
\r
84 /* Standard includes. */
\r
87 /* Atmel library includes. */
\r
88 #include <pio/pio.h>
\r
90 /* Priorities for the demo application tasks. */
\r
91 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
92 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 0 )
\r
93 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
94 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 0 )
\r
95 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
96 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
97 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
99 /* The period of the check task both in and out of the presense of an error. */
\r
100 #define mainNO_ERROR_PERIOD ( 5000 / portTICK_RATE_MS )
\r
101 #define mainERROR_PERIOD ( 500 / portTICK_RATE_MS );
\r
103 /* Constants used by the ComTest task. */
\r
104 #define mainCOM_TEST_BAUD_RATE ( 38400 )
\r
105 #define mainCOM_TEST_LED ( LED_DS1 )
\r
107 /*-----------------------------------------------------------*/
\r
109 /* Simple hardware setup required by the demo. */
\r
110 static void prvSetupHardware( void );
\r
112 /* The check task as described at the top of this file. */
\r
113 static void prvCheckTask( void *pvParameters );
\r
115 /*-----------------------------------------------------------*/
\r
118 /* Perform any hardware setup necessary to run the demo. */
\r
119 prvSetupHardware();
\r
121 /* First create the 'standard demo' tasks. These exist just to to
\r
122 demonstrate API functions being used and test the kernel port. More
\r
123 information is provided on the FreeRTOS.org WEB site. */
\r
124 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
125 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
126 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
127 vStartDynamicPriorityTasks();
\r
128 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
129 vCreateBlockTimeTasks();
\r
130 vStartCountingSemaphoreTasks();
\r
131 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
132 vStartQueuePeekTasks();
\r
133 vStartRecursiveMutexTasks();
\r
134 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
136 /* Create the check task - this is the task that checks all the other tasks
\r
137 are executing as expected and without reporting any errors. */
\r
138 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );
\r
140 /* The death demo tasks must be started last as the sanity checks performed
\r
141 require knowledge of the number of other tasks in the system. */
\r
142 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
144 /* Start the scheduler. From this point on the execution will be under
\r
145 the control of the kernel. */
\r
146 vTaskStartScheduler();
\r
148 /* Will only get here if there was insufficient heap availale for the
\r
149 idle task to be created. */
\r
152 /*-----------------------------------------------------------*/
\r
154 static void prvCheckTask( void * pvParameters )
\r
156 portTickType xNextWakeTime, xPeriod = mainNO_ERROR_PERIOD;
\r
157 static volatile unsigned portLONG ulErrorCode = 0UL;
\r
159 /* Just to remove the compiler warning. */
\r
160 ( void ) pvParameters;
\r
162 /* Initialise xNextWakeTime prior to its first use. From this point on
\r
163 the value of the variable is handled automatically by the kernel. */
\r
164 xNextWakeTime = xTaskGetTickCount();
\r
168 /* Delay until it is time for this task to execute again. */
\r
169 vTaskDelayUntil( &xNextWakeTime, xPeriod );
\r
171 /* Check all the other tasks in the system - latch any reported errors
\r
172 into the ulErrorCode variable. */
\r
173 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
175 ulErrorCode |= 0x01UL;
\r
178 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
180 ulErrorCode |= 0x02UL;
\r
183 if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
\r
185 ulErrorCode |= 0x04UL;
\r
188 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
190 ulErrorCode |= 0x08UL;
\r
193 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
195 ulErrorCode |= 0x10UL;
\r
198 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
200 ulErrorCode |= 0x20UL;
\r
203 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
205 ulErrorCode |= 0x40UL;
\r
208 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
210 ulErrorCode |= 0x80UL;
\r
213 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
215 ulErrorCode |= 0x100UL;
\r
218 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
220 ulErrorCode |= 0x200UL;
\r
223 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
225 ulErrorCode |= 0x400UL;
\r
228 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
230 ulErrorCode |= 0x800UL;
\r
233 /* Reduce the block period and in so doing increase the frequency at
\r
234 which this task executes if any errors have been latched. The increased
\r
235 frequency causes the LED toggle rate to increase and so gives some
\r
236 visual feedback that an error has occurred. */
\r
237 if( ulErrorCode != 0x00 )
\r
239 xPeriod = mainERROR_PERIOD;
\r
242 /* Finally toggle the LED. */
\r
243 vParTestToggleLED( LED_POWER );
\r
246 /*-----------------------------------------------------------*/
\r
248 static void prvSetupHardware( void )
\r
250 const Pin xPins[] = { PIN_USART0_RXD, PIN_USART0_TXD };
\r
252 /* Setup the LED outputs. */
\r
253 vParTestInitialise();
\r
255 /* Setup the pins for the UART. */
\r
256 PIO_Configure( xPins, PIO_LISTSIZE( xPins ) );
\r