2 FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\r
13 * Purchasing FreeRTOS documentation will not only help you, by *
\r
14 * ensuring you get running as quickly as possible and with an *
\r
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
16 * the FreeRTOS project to continue with its mission of providing *
\r
17 * professional grade, cross platform, de facto standard solutions *
\r
18 * for microcontrollers - completely free of charge! *
\r
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\r
29 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
30 the terms of the GNU General Public License (version 2) as published by the
\r
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
33 >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
\r
34 distribute a combined work that includes FreeRTOS without being obliged to
\r
35 provide the source code for proprietary components outside of the FreeRTOS
\r
38 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
39 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
40 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
41 details. You should have received a copy of the GNU General Public License
\r
42 and the FreeRTOS license exception along with FreeRTOS; if not itcan be
\r
43 viewed here: http://www.freertos.org/a00114.html and also obtained by
\r
44 writing to Real Time Engineers Ltd., contact details for whom are available
\r
45 on the FreeRTOS WEB site.
\r
49 ***************************************************************************
\r
51 * Having a problem? Start by reading the FAQ "My application does *
\r
52 * not run, what could be wrong?" *
\r
54 * http://www.FreeRTOS.org/FAQHelp.html *
\r
56 ***************************************************************************
\r
59 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
60 license and Real Time Engineers Ltd. contact details.
\r
62 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
63 including FreeRTOS+Trace - an indispensable productivity tool, and our new
\r
64 fully thread aware and reentrant UDP/IP stack.
\r
66 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
67 Integrity Systems, who sell the code with commercial support,
\r
68 indemnification and middleware, under the OpenRTOS brand.
\r
70 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
71 engineered and independently SIL3 certified version for use in safety and
\r
72 mission critical applications that require provable dependability.
\r
76 * Creates all the application tasks, then starts the scheduler.
\r
78 * A task is also created called "uIP". This executes the uIP stack and small
\r
79 * WEB server sample. All the other tasks are from the set of standard
\r
80 * demo tasks. The WEB documentation provides more details of the standard
\r
81 * demo application tasks.
\r
83 * Main.c also creates a task called "Check". This only executes every three
\r
84 * seconds but has the highest priority so is guaranteed to get processor time.
\r
85 * Its main function is to check the status of all the other demo application
\r
86 * tasks. LED mainCHECK_LED is toggled every three seconds by the check task
\r
87 * should no error conditions be detected in any of the standard demo tasks.
\r
88 * The toggle rate increasing to 500ms indicates that at least one error has
\r
93 /* Standard includes. */
\r
97 /* Scheduler includes. */
\r
98 #include "FreeRTOS.h"
\r
101 /* Demo application includes. */
\r
102 #include "partest.h"
\r
104 #include "dynamic.h"
\r
105 #include "semtest.h"
\r
107 #include "integer.h"
\r
109 #include "BlockQ.h"
\r
111 #include "uip_task.h"
\r
113 /*-----------------------------------------------------------*/
\r
115 /* Priorities/stacks for the demo application tasks. */
\r
116 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
117 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
118 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
119 #define mainUIP_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
120 #define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
121 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
122 #define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
123 #define mainUIP_TASK_STACK_SIZE ( 250 )
\r
125 /* The rate at which the on board LED will toggle when there is/is not an
\r
127 #define mainNO_ERROR_FLASH_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
128 #define mainERROR_FLASH_PERIOD ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
130 /* The LED used by the check task to indicate the system status. */
\r
131 #define mainCHECK_LED ( 3 )
\r
132 /*-----------------------------------------------------------*/
\r
135 * Checks that all the demo application tasks are still executing without error
\r
136 * - as described at the top of the file.
\r
138 static long prvCheckOtherTasksAreStillRunning( void );
\r
141 * The task that executes at the highest priority and calls
\r
142 * prvCheckOtherTasksAreStillRunning(). See the description at the top
\r
145 static void vErrorChecks( void *pvParameters );
\r
148 * Configure the processor for use with the Atmel demo board. This is very
\r
149 * minimal as most of the setup is performed in the startup code.
\r
151 static void prvSetupHardware( void );
\r
153 /*-----------------------------------------------------------*/
\r
156 * Starts all the other tasks, then starts the scheduler.
\r
160 /* Configure the processor. */
\r
161 prvSetupHardware();
\r
163 /* Setup the port used to flash the LED's. */
\r
164 vParTestInitialise();
\r
166 /* Start the task that handles the TCP/IP and WEB server functionality. */
\r
167 xTaskCreate( vuIP_TASK, "uIP", mainUIP_TASK_STACK_SIZE, NULL, mainUIP_PRIORITY, NULL );
\r
169 /* Start the demo/test application tasks. These are created in addition
\r
170 to the TCP/IP task for demonstration and test purposes. */
\r
171 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
172 vStartDynamicPriorityTasks();
\r
173 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
174 vStartLEDFlashTasks( mainFLASH_PRIORITY );
\r
175 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
176 vStartMathTasks( tskIDLE_PRIORITY );
\r
177 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
179 /* Start the check task - which is defined in this file. */
\r
180 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
182 /* Must be last to get created. */
\r
183 vCreateSuicidalTasks( mainDEATH_PRIORITY );
\r
185 /* Now all the tasks have been started - start the scheduler. */
\r
186 vTaskStartScheduler();
\r
188 /* Should never reach here because the tasks should now be executing! */
\r
191 /*-----------------------------------------------------------*/
\r
193 static void prvSetupHardware( void )
\r
195 /* When using the JTAG debugger the hardware is not always initialised to
\r
196 the correct default state. This line just ensures that this does not
\r
197 cause all interrupts to be masked at the start. */
\r
198 AT91C_BASE_AIC->AIC_EOICR = 0;
\r
200 /* Most setup is performed by the low level init function called from the
\r
203 Configure the PIO Lines corresponding to LED1 to LED4 to be outputs as
\r
204 well as the UART Tx line. */
\r
205 AT91F_PIO_CfgOutput( AT91C_BASE_PIOB, LED_MASK );
\r
207 /* Enable the peripheral clock. */
\r
208 AT91F_PMC_EnablePeriphClock( AT91C_BASE_PMC, 1 << AT91C_ID_PIOA );
\r
209 AT91F_PMC_EnablePeriphClock( AT91C_BASE_PMC, 1 << AT91C_ID_PIOB ) ;
\r
210 AT91F_PMC_EnablePeriphClock( AT91C_BASE_PMC, 1 << AT91C_ID_EMAC ) ;
\r
212 /*-----------------------------------------------------------*/
\r
214 static void vErrorChecks( void *pvParameters )
\r
216 portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
\r
217 portTickType xLastWakeTime;
\r
219 /* Initialise xLastWakeTime to ensure the first call to vTaskDelayUntil()
\r
220 functions correctly. */
\r
221 xLastWakeTime = xTaskGetTickCount();
\r
223 /* Cycle for ever, delaying then checking all the other tasks are still
\r
224 operating without error. If an error is detected then the delay period
\r
225 is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
\r
226 the Check LED flash rate will increase. */
\r
229 /* Delay until it is time to execute again. The delay period is
\r
230 shorter following an error. */
\r
231 vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );
\r
233 /* Check all the standard demo application tasks are executing without
\r
235 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
237 /* An error has been detected in one of the tasks - flash faster. */
\r
238 xDelayPeriod = mainERROR_FLASH_PERIOD;
\r
241 vParTestToggleLED( mainCHECK_LED );
\r
244 /*-----------------------------------------------------------*/
\r
246 static long prvCheckOtherTasksAreStillRunning( void )
\r
248 long lReturn = ( long ) pdPASS;
\r
251 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
252 that they are all still running, and that none of them have detected
\r
255 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
257 lReturn = ( long ) pdFAIL;
\r
260 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
262 lReturn = ( long ) pdFAIL;
\r
265 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
267 lReturn = ( long ) pdFAIL;
\r
270 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
272 lReturn = ( long ) pdFAIL;
\r
275 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
277 lReturn = ( long ) pdFAIL;
\r
280 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
282 lReturn = ( long ) pdFAIL;
\r
285 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
287 lReturn = ( long ) pdFAIL;
\r