2 FreeRTOS V5.4.2 - Copyright (C) 2009 Real Time Engineers Ltd.
\r
4 This file is part of the FreeRTOS distribution.
\r
6 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
7 the terms of the GNU General Public License (version 2) as published by the
\r
8 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 without being obliged to provide the
\r
11 source code for proprietary components outside of the FreeRTOS kernel.
\r
12 Alternative commercial license and support terms are also available upon
\r
13 request. See the licensing section of http://www.FreeRTOS.org for full
\r
16 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
21 You should have received a copy of the GNU General Public License along
\r
22 with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
\r
23 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
26 ***************************************************************************
\r
28 * Looking for a quick start? Then check out the FreeRTOS eBook! *
\r
29 * See http://www.FreeRTOS.org/Documentation for details *
\r
31 ***************************************************************************
\r
35 Please ensure to read the configuration and relevant port sections of the
\r
36 online documentation.
\r
38 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
41 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
44 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
45 licensing and training services.
\r
49 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
50 * documentation provides more details of the standard demo application tasks.
\r
52 * A "Check" task is created in addition to the standard demo tasks. This
\r
53 * only executes every three seconds but has a high priority to ensure it gets
\r
54 * processor time. Its main function is to check that all the standard demo
\r
55 * tasks are still operational. If everything is running as expected then the
\r
56 * check task will toggle an LED every 3 seconds. An error being discovered in
\r
57 * any task will cause the toggle rate to increase to 500ms.
\r
61 /* FreeRTOS includes. */
\r
62 #include "FreeRTOS.h"
\r
65 /* Standard demo includes. */
\r
67 #include "blocktim.h"
\r
68 #include "countsem.h"
\r
70 #include "dynamic.h"
\r
71 #include "GenQTest.h"
\r
72 #include "integer.h"
\r
75 #include "recmutex.h"
\r
76 #include "semtest.h"
\r
77 #include "ParTest.h"
\r
78 #include "comtest2.h"
\r
80 /* Standard includes. */
\r
83 /* Atmel library includes. */
\r
84 #include <pio/pio.h>
\r
86 /* Priorities for the demo application tasks. */
\r
87 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
88 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 0 )
\r
89 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
90 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 0 )
\r
91 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
92 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
93 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
95 /* The period of the check task both in and out of the presense of an error. */
\r
96 #define mainNO_ERROR_PERIOD ( 5000 / portTICK_RATE_MS )
\r
97 #define mainERROR_PERIOD ( 500 / portTICK_RATE_MS );
\r
99 /* Constants used by the ComTest task. */
\r
100 #define mainCOM_TEST_BAUD_RATE ( 38400 )
\r
101 #define mainCOM_TEST_LED ( LED_DS1 )
\r
103 /*-----------------------------------------------------------*/
\r
105 /* Simple hardware setup required by the demo. */
\r
106 static void prvSetupHardware( void );
\r
108 /* The check task as described at the top of this file. */
\r
109 static void prvCheckTask( void *pvParameters );
\r
111 /*-----------------------------------------------------------*/
\r
114 /* Perform any hardware setup necessary to run the demo. */
\r
115 prvSetupHardware();
\r
117 /* First create the 'standard demo' tasks. These exist just to to
\r
118 demonstrate API functions being used and test the kernel port. More
\r
119 information is provided on the FreeRTOS.org WEB site. */
\r
120 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
121 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
122 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
123 vStartDynamicPriorityTasks();
\r
124 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
125 vCreateBlockTimeTasks();
\r
126 vStartCountingSemaphoreTasks();
\r
127 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
128 vStartQueuePeekTasks();
\r
129 vStartRecursiveMutexTasks();
\r
130 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
132 /* Create the check task - this is the task that checks all the other tasks
\r
133 are executing as expected and without reporting any errors. */
\r
134 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );
\r
136 /* The death demo tasks must be started last as the sanity checks performed
\r
137 require knowledge of the number of other tasks in the system. */
\r
138 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
140 /* Start the scheduler. From this point on the execution will be under
\r
141 the control of the kernel. */
\r
142 vTaskStartScheduler();
\r
144 /* Will only get here if there was insufficient heap availale for the
\r
145 idle task to be created. */
\r
148 /*-----------------------------------------------------------*/
\r
150 static void prvCheckTask( void * pvParameters )
\r
152 portTickType xNextWakeTime, xPeriod = mainNO_ERROR_PERIOD;
\r
153 static volatile unsigned portLONG ulErrorCode = 0UL;
\r
155 /* Just to remove the compiler warning. */
\r
156 ( void ) pvParameters;
\r
158 /* Initialise xNextWakeTime prior to its first use. From this point on
\r
159 the value of the variable is handled automatically by the kernel. */
\r
160 xNextWakeTime = xTaskGetTickCount();
\r
164 /* Delay until it is time for this task to execute again. */
\r
165 vTaskDelayUntil( &xNextWakeTime, xPeriod );
\r
167 /* Check all the other tasks in the system - latch any reported errors
\r
168 into the ulErrorCode variable. */
\r
169 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
171 ulErrorCode |= 0x01UL;
\r
174 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
176 ulErrorCode |= 0x02UL;
\r
179 if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
\r
181 ulErrorCode |= 0x04UL;
\r
184 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
186 ulErrorCode |= 0x08UL;
\r
189 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
191 ulErrorCode |= 0x10UL;
\r
194 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
196 ulErrorCode |= 0x20UL;
\r
199 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
201 ulErrorCode |= 0x40UL;
\r
204 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
206 ulErrorCode |= 0x80UL;
\r
209 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
211 ulErrorCode |= 0x100UL;
\r
214 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
216 ulErrorCode |= 0x200UL;
\r
219 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
221 ulErrorCode |= 0x400UL;
\r
224 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
226 ulErrorCode |= 0x800UL;
\r
229 /* Reduce the block period and in so doing increase the frequency at
\r
230 which this task executes if any errors have been latched. The increased
\r
231 frequency causes the LED toggle rate to increase and so gives some
\r
232 visual feedback that an error has occurred. */
\r
233 if( ulErrorCode != 0x00 )
\r
235 xPeriod = mainERROR_PERIOD;
\r
238 /* Finally toggle the LED. */
\r
239 vParTestToggleLED( LED_POWER );
\r
242 /*-----------------------------------------------------------*/
\r
244 static void prvSetupHardware( void )
\r
246 const Pin xPins[] = { PIN_USART0_RXD, PIN_USART0_TXD };
\r
248 /* Setup the LED outputs. */
\r
249 vParTestInitialise();
\r
251 /* Setup the pins for the UART. */
\r
252 PIO_Configure( xPins, PIO_LISTSIZE( xPins ) );
\r