2 FreeRTOS V6.0.2 - Copyright (C) 2010 Real Time Engineers Ltd.
\r
4 ***************************************************************************
\r
8 * + New to FreeRTOS, *
\r
9 * + Wanting to learn FreeRTOS or multitasking in general quickly *
\r
10 * + Looking for basic training, *
\r
11 * + Wanting to improve your FreeRTOS skills and productivity *
\r
13 * then take a look at the FreeRTOS eBook *
\r
15 * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
\r
16 * http://www.FreeRTOS.org/Documentation *
\r
18 * A pdf reference manual is also available. Both are usually delivered *
\r
19 * to your inbox within 20 minutes to two hours when purchased between 8am *
\r
20 * and 8pm GMT (although please allow up to 24 hours in case of *
\r
21 * exceptional circumstances). Thank you for your support! *
\r
23 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 ***NOTE*** The exception to the GPL is included to allow you to distribute
\r
31 a combined work that includes FreeRTOS without being obliged to provide the
\r
32 source code for proprietary components outside of the FreeRTOS kernel.
\r
33 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
34 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
35 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
55 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
56 * documentation provides more details of the standard demo application tasks.
\r
58 * A "Check" task is created in addition to the standard demo tasks. This
\r
59 * only executes every three seconds but has a high priority to ensure it gets
\r
60 * processor time. Its main function is to check that all the standard demo
\r
61 * tasks are still operational. If everything is running as expected then the
\r
62 * check task will toggle an LED every 3 seconds. An error being discovered in
\r
63 * any task will cause the toggle rate to increase to 500ms.
\r
67 /* FreeRTOS includes. */
\r
68 #include "FreeRTOS.h"
\r
71 /* Standard demo includes. */
\r
73 #include "blocktim.h"
\r
74 #include "countsem.h"
\r
76 #include "dynamic.h"
\r
77 #include "GenQTest.h"
\r
78 #include "integer.h"
\r
81 #include "recmutex.h"
\r
82 #include "semtest.h"
\r
83 #include "ParTest.h"
\r
84 #include "comtest2.h"
\r
86 /* Standard includes. */
\r
89 /* Atmel library includes. */
\r
90 #include <pio/pio.h>
\r
92 /* Priorities for the demo application tasks. */
\r
93 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
94 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 0 )
\r
95 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
96 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 0 )
\r
97 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
98 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
99 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
101 /* The period of the check task both in and out of the presense of an error. */
\r
102 #define mainNO_ERROR_PERIOD ( 5000 / portTICK_RATE_MS )
\r
103 #define mainERROR_PERIOD ( 500 / portTICK_RATE_MS );
\r
105 /* Constants used by the ComTest task. */
\r
106 #define mainCOM_TEST_BAUD_RATE ( 38400 )
\r
107 #define mainCOM_TEST_LED ( LED_DS1 )
\r
109 /*-----------------------------------------------------------*/
\r
111 /* Simple hardware setup required by the demo. */
\r
112 static void prvSetupHardware( void );
\r
114 /* The check task as described at the top of this file. */
\r
115 static void prvCheckTask( void *pvParameters );
\r
117 /*-----------------------------------------------------------*/
\r
120 /* Perform any hardware setup necessary to run the demo. */
\r
121 prvSetupHardware();
\r
123 /* First create the 'standard demo' tasks. These exist just to to
\r
124 demonstrate API functions being used and test the kernel port. More
\r
125 information is provided on the FreeRTOS.org WEB site. */
\r
126 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
127 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
128 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
129 vStartDynamicPriorityTasks();
\r
130 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
131 vCreateBlockTimeTasks();
\r
132 vStartCountingSemaphoreTasks();
\r
133 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
134 vStartQueuePeekTasks();
\r
135 vStartRecursiveMutexTasks();
\r
136 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
138 /* Create the check task - this is the task that checks all the other tasks
\r
139 are executing as expected and without reporting any errors. */
\r
140 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );
\r
142 /* The death demo tasks must be started last as the sanity checks performed
\r
143 require knowledge of the number of other tasks in the system. */
\r
144 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
146 /* Start the scheduler. From this point on the execution will be under
\r
147 the control of the kernel. */
\r
148 vTaskStartScheduler();
\r
150 /* Will only get here if there was insufficient heap availale for the
\r
151 idle task to be created. */
\r
154 /*-----------------------------------------------------------*/
\r
156 static void prvCheckTask( void * pvParameters )
\r
158 portTickType xNextWakeTime, xPeriod = mainNO_ERROR_PERIOD;
\r
159 static volatile unsigned long ulErrorCode = 0UL;
\r
161 /* Just to remove the compiler warning. */
\r
162 ( void ) pvParameters;
\r
164 /* Initialise xNextWakeTime prior to its first use. From this point on
\r
165 the value of the variable is handled automatically by the kernel. */
\r
166 xNextWakeTime = xTaskGetTickCount();
\r
170 /* Delay until it is time for this task to execute again. */
\r
171 vTaskDelayUntil( &xNextWakeTime, xPeriod );
\r
173 /* Check all the other tasks in the system - latch any reported errors
\r
174 into the ulErrorCode variable. */
\r
175 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
177 ulErrorCode |= 0x01UL;
\r
180 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
182 ulErrorCode |= 0x02UL;
\r
185 if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
\r
187 ulErrorCode |= 0x04UL;
\r
190 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
192 ulErrorCode |= 0x08UL;
\r
195 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
197 ulErrorCode |= 0x10UL;
\r
200 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
202 ulErrorCode |= 0x20UL;
\r
205 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
207 ulErrorCode |= 0x40UL;
\r
210 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
212 ulErrorCode |= 0x80UL;
\r
215 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
217 ulErrorCode |= 0x100UL;
\r
220 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
222 ulErrorCode |= 0x200UL;
\r
225 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
227 ulErrorCode |= 0x400UL;
\r
230 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
232 ulErrorCode |= 0x800UL;
\r
235 /* Reduce the block period and in so doing increase the frequency at
\r
236 which this task executes if any errors have been latched. The increased
\r
237 frequency causes the LED toggle rate to increase and so gives some
\r
238 visual feedback that an error has occurred. */
\r
239 if( ulErrorCode != 0x00 )
\r
241 xPeriod = mainERROR_PERIOD;
\r
244 /* Finally toggle the LED. */
\r
245 vParTestToggleLED( LED_POWER );
\r
248 /*-----------------------------------------------------------*/
\r
250 static void prvSetupHardware( void )
\r
252 const Pin xPins[] = { PIN_USART0_RXD, PIN_USART0_TXD };
\r
254 /* Setup the LED outputs. */
\r
255 vParTestInitialise();
\r
257 /* Setup the pins for the UART. */
\r
258 PIO_Configure( xPins, PIO_LISTSIZE( xPins ) );
\r