2 FreeRTOS.org V5.0.0 - Copyright (C) 2003-2008 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
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 ***************************************************************************
\r
29 * SAVE TIME AND MONEY! We can port FreeRTOS.org to your own hardware, *
\r
30 * and even write all or part of your application on your behalf. *
\r
31 * See http://www.OpenRTOS.com for details of the services we provide to *
\r
32 * expedite your project. *
\r
34 ***************************************************************************
\r
35 ***************************************************************************
\r
37 Please ensure to read the configuration and relevant port sections of the
\r
38 online documentation.
\r
40 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
43 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
46 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
47 licensing and training services.
\r
51 * Creates all the application tasks, then starts the scheduler.
\r
53 * A task is also created called "uIP". This executes the uIP stack and small
\r
54 * WEB server sample. All the other tasks are from the set of standard
\r
55 * demo tasks. The WEB documentation provides more details of the standard
\r
56 * demo application tasks.
\r
58 * Main.c also creates a task called "Check". This only executes every three
\r
59 * seconds but has the highest priority so is guaranteed to get processor time.
\r
60 * Its main function is to check the status of all the other demo application
\r
61 * tasks. LED mainCHECK_LED is toggled every three seconds by the check task
\r
62 * should no error conditions be detected in any of the standard demo tasks.
\r
63 * The toggle rate increasing to 500ms indicates that at least one error has
\r
68 /* Standard includes. */
\r
72 /* Scheduler includes. */
\r
73 #include "FreeRTOS.h"
\r
76 /* Demo application includes. */
\r
77 #include "partest.h"
\r
79 #include "dynamic.h"
\r
80 #include "semtest.h"
\r
82 #include "integer.h"
\r
86 #include "uip_task.h"
\r
88 /*-----------------------------------------------------------*/
\r
90 /* Priorities/stacks for the demo application tasks. */
\r
91 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
92 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
93 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
94 #define mainUIP_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
95 #define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
96 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
97 #define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
98 #define mainUIP_TASK_STACK_SIZE ( 250 )
\r
100 /* The rate at which the on board LED will toggle when there is/is not an
\r
102 #define mainNO_ERROR_FLASH_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
103 #define mainERROR_FLASH_PERIOD ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
105 /* The LED used by the check task to indicate the system status. */
\r
106 #define mainCHECK_LED ( 3 )
\r
107 /*-----------------------------------------------------------*/
\r
110 * Checks that all the demo application tasks are still executing without error
\r
111 * - as described at the top of the file.
\r
113 static portLONG prvCheckOtherTasksAreStillRunning( void );
\r
116 * The task that executes at the highest priority and calls
\r
117 * prvCheckOtherTasksAreStillRunning(). See the description at the top
\r
120 static void vErrorChecks( void *pvParameters );
\r
123 * Configure the processor for use with the Atmel demo board. This is very
\r
124 * minimal as most of the setup is performed in the startup code.
\r
126 static void prvSetupHardware( void );
\r
128 /*-----------------------------------------------------------*/
\r
131 * Starts all the other tasks, then starts the scheduler.
\r
135 /* Configure the processor. */
\r
136 prvSetupHardware();
\r
138 /* Setup the port used to flash the LED's. */
\r
139 vParTestInitialise();
\r
141 /* Start the task that handles the TCP/IP and WEB server functionality. */
\r
142 xTaskCreate( vuIP_TASK, "uIP", mainUIP_TASK_STACK_SIZE, NULL, mainUIP_PRIORITY, NULL );
\r
144 /* Start the demo/test application tasks. These are created in addition
\r
145 to the TCP/IP task for demonstration and test purposes. */
\r
146 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
147 vStartDynamicPriorityTasks();
\r
148 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
149 vStartLEDFlashTasks( mainFLASH_PRIORITY );
\r
150 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
151 vStartMathTasks( tskIDLE_PRIORITY );
\r
152 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
154 /* Start the check task - which is defined in this file. */
\r
155 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
157 /* Must be last to get created. */
\r
158 vCreateSuicidalTasks( mainDEATH_PRIORITY );
\r
160 /* Now all the tasks have been started - start the scheduler. */
\r
161 vTaskStartScheduler();
\r
163 /* Should never reach here because the tasks should now be executing! */
\r
166 /*-----------------------------------------------------------*/
\r
168 static void prvSetupHardware( void )
\r
170 /* When using the JTAG debugger the hardware is not always initialised to
\r
171 the correct default state. This line just ensures that this does not
\r
172 cause all interrupts to be masked at the start. */
\r
173 AT91C_BASE_AIC->AIC_EOICR = 0;
\r
175 /* Most setup is performed by the low level init function called from the
\r
178 Configure the PIO Lines corresponding to LED1 to LED4 to be outputs as
\r
179 well as the UART Tx line. */
\r
180 AT91F_PIO_CfgOutput( AT91C_BASE_PIOB, LED_MASK );
\r
182 /* Enable the peripheral clock. */
\r
183 AT91F_PMC_EnablePeriphClock( AT91C_BASE_PMC, 1 << AT91C_ID_PIOA );
\r
184 AT91F_PMC_EnablePeriphClock( AT91C_BASE_PMC, 1 << AT91C_ID_PIOB ) ;
\r
185 AT91F_PMC_EnablePeriphClock( AT91C_BASE_PMC, 1 << AT91C_ID_EMAC ) ;
\r
187 /*-----------------------------------------------------------*/
\r
189 static void vErrorChecks( void *pvParameters )
\r
191 portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
\r
192 portTickType xLastWakeTime;
\r
194 /* Initialise xLastWakeTime to ensure the first call to vTaskDelayUntil()
\r
195 functions correctly. */
\r
196 xLastWakeTime = xTaskGetTickCount();
\r
198 /* Cycle for ever, delaying then checking all the other tasks are still
\r
199 operating without error. If an error is detected then the delay period
\r
200 is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
\r
201 the Check LED flash rate will increase. */
\r
204 /* Delay until it is time to execute again. The delay period is
\r
205 shorter following an error. */
\r
206 vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );
\r
208 /* Check all the standard demo application tasks are executing without
\r
210 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
212 /* An error has been detected in one of the tasks - flash faster. */
\r
213 xDelayPeriod = mainERROR_FLASH_PERIOD;
\r
216 vParTestToggleLED( mainCHECK_LED );
\r
219 /*-----------------------------------------------------------*/
\r
221 static portLONG prvCheckOtherTasksAreStillRunning( void )
\r
223 portLONG lReturn = ( portLONG ) pdPASS;
\r
226 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
227 that they are all still running, and that none of them have detected
\r
230 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
232 lReturn = ( portLONG ) pdFAIL;
\r
235 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
237 lReturn = ( portLONG ) pdFAIL;
\r
240 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
242 lReturn = ( portLONG ) pdFAIL;
\r
245 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
247 lReturn = ( portLONG ) pdFAIL;
\r
250 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
252 lReturn = ( portLONG ) pdFAIL;
\r
255 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
257 lReturn = ( portLONG ) pdFAIL;
\r
260 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
262 lReturn = ( portLONG ) pdFAIL;
\r