2 FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
66 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
67 * documentation provides more details of the standard demo application tasks.
\r
69 * A "Check" task is created in addition to the standard demo tasks. This
\r
70 * only executes every three seconds but has a high priority to ensure it gets
\r
71 * processor time. Its main function is to check that all the standard demo
\r
72 * tasks are still operational. If everything is running as expected then the
\r
73 * check task will toggle an LED every 3 seconds. An error being discovered in
\r
74 * any task will cause the toggle rate to increase to 500ms.
\r
78 /* FreeRTOS includes. */
\r
79 #include "FreeRTOS.h"
\r
82 /* Standard demo includes. */
\r
84 #include "blocktim.h"
\r
85 #include "countsem.h"
\r
87 #include "dynamic.h"
\r
88 #include "GenQTest.h"
\r
89 #include "integer.h"
\r
92 #include "recmutex.h"
\r
93 #include "semtest.h"
\r
94 #include "ParTest.h"
\r
95 #include "comtest2.h"
\r
97 /* Standard includes. */
\r
100 /* Atmel library includes. */
\r
101 #include <pio/pio.h>
\r
103 /* Priorities for the demo application tasks. */
\r
104 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
105 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 0 )
\r
106 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
107 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 0 )
\r
108 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
109 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
110 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
112 /* The period of the check task both in and out of the presense of an error. */
\r
113 #define mainNO_ERROR_PERIOD ( 5000 / portTICK_RATE_MS )
\r
114 #define mainERROR_PERIOD ( 500 / portTICK_RATE_MS );
\r
116 /* Constants used by the ComTest task. */
\r
117 #define mainCOM_TEST_BAUD_RATE ( 38400 )
\r
118 #define mainCOM_TEST_LED ( LED_DS1 )
\r
120 /*-----------------------------------------------------------*/
\r
122 /* Simple hardware setup required by the demo. */
\r
123 static void prvSetupHardware( void );
\r
125 /* The check task as described at the top of this file. */
\r
126 static void prvCheckTask( void *pvParameters );
\r
128 /*-----------------------------------------------------------*/
\r
131 /* Perform any hardware setup necessary to run the demo. */
\r
132 prvSetupHardware();
\r
134 /* First create the 'standard demo' tasks. These exist just to to
\r
135 demonstrate API functions being used and test the kernel port. More
\r
136 information is provided on the FreeRTOS.org WEB site. */
\r
137 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
138 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
139 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
140 vStartDynamicPriorityTasks();
\r
141 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
142 vCreateBlockTimeTasks();
\r
143 vStartCountingSemaphoreTasks();
\r
144 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
145 vStartQueuePeekTasks();
\r
146 vStartRecursiveMutexTasks();
\r
147 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
149 /* Create the check task - this is the task that checks all the other tasks
\r
150 are executing as expected and without reporting any errors. */
\r
151 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );
\r
153 /* The death demo tasks must be started last as the sanity checks performed
\r
154 require knowledge of the number of other tasks in the system. */
\r
155 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
157 /* Start the scheduler. From this point on the execution will be under
\r
158 the control of the kernel. */
\r
159 vTaskStartScheduler();
\r
161 /* Will only get here if there was insufficient heap availale for the
\r
162 idle task to be created. */
\r
165 /*-----------------------------------------------------------*/
\r
167 static void prvCheckTask( void * pvParameters )
\r
169 portTickType xNextWakeTime, xPeriod = mainNO_ERROR_PERIOD;
\r
170 static volatile unsigned long ulErrorCode = 0UL;
\r
172 /* Just to remove the compiler warning. */
\r
173 ( void ) pvParameters;
\r
175 /* Initialise xNextWakeTime prior to its first use. From this point on
\r
176 the value of the variable is handled automatically by the kernel. */
\r
177 xNextWakeTime = xTaskGetTickCount();
\r
181 /* Delay until it is time for this task to execute again. */
\r
182 vTaskDelayUntil( &xNextWakeTime, xPeriod );
\r
184 /* Check all the other tasks in the system - latch any reported errors
\r
185 into the ulErrorCode variable. */
\r
186 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
188 ulErrorCode |= 0x01UL;
\r
191 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
193 ulErrorCode |= 0x02UL;
\r
196 if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
\r
198 ulErrorCode |= 0x04UL;
\r
201 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
203 ulErrorCode |= 0x08UL;
\r
206 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
208 ulErrorCode |= 0x10UL;
\r
211 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
213 ulErrorCode |= 0x20UL;
\r
216 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
218 ulErrorCode |= 0x40UL;
\r
221 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
223 ulErrorCode |= 0x80UL;
\r
226 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
228 ulErrorCode |= 0x100UL;
\r
231 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
233 ulErrorCode |= 0x200UL;
\r
236 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
238 ulErrorCode |= 0x400UL;
\r
241 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
243 ulErrorCode |= 0x800UL;
\r
246 /* Reduce the block period and in so doing increase the frequency at
\r
247 which this task executes if any errors have been latched. The increased
\r
248 frequency causes the LED toggle rate to increase and so gives some
\r
249 visual feedback that an error has occurred. */
\r
250 if( ulErrorCode != 0x00 )
\r
252 xPeriod = mainERROR_PERIOD;
\r
255 /* Finally toggle the LED. */
\r
256 vParTestToggleLED( LED_POWER );
\r
259 /*-----------------------------------------------------------*/
\r
261 static void prvSetupHardware( void )
\r
263 const Pin xPins[] = { PIN_USART0_RXD, PIN_USART0_TXD };
\r
265 /* Setup the LED outputs. */
\r
266 vParTestInitialise();
\r
268 /* Setup the pins for the UART. */
\r
269 PIO_Configure( xPins, PIO_LISTSIZE( xPins ) );
\r