2 FreeRTOS.org V4.1.3 - copyright (C) 2003-2006 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 See http://www.FreeRTOS.org for documentation, latest information, license
\r
28 and contact details. Please ensure to read the configuration and relevant
\r
29 port sections of the online documentation.
\r
30 ***************************************************************************
\r
34 * Creates all the application tasks, then starts the scheduler.
\r
36 * A task is also created called "uIP". This executes the uIP stack and small
\r
37 * WEB server sample. All the other tasks are from the set of standard
\r
38 * demo tasks. The WEB documentation provides more details of the standard
\r
39 * demo application tasks.
\r
41 * Main.c also creates a task called "Check". This only executes every three
\r
42 * seconds but has the highest priority so is guaranteed to get processor time.
\r
43 * Its main function is to check the status of all the other demo application
\r
44 * tasks. LED mainCHECK_LED is toggled every three seconds by the check task
\r
45 * should no error conditions be detected in any of the standard demo tasks.
\r
46 * The toggle rate increasing to 500ms indicates that at least one error has
\r
51 /* Standard includes. */
\r
55 /* Scheduler includes. */
\r
56 #include "FreeRTOS.h"
\r
59 /* Demo application includes. */
\r
60 #include "partest.h"
\r
62 #include "dynamic.h"
\r
63 #include "semtest.h"
\r
65 #include "integer.h"
\r
69 #include "uip_task.h"
\r
71 /*-----------------------------------------------------------*/
\r
73 /* Priorities/stacks for the demo application tasks. */
\r
74 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
75 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
76 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
77 #define mainUIP_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
78 #define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
79 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
80 #define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
81 #define mainUIP_TASK_STACK_SIZE ( 250 )
\r
83 /* The rate at which the on board LED will toggle when there is/is not an
\r
85 #define mainNO_ERROR_FLASH_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
86 #define mainERROR_FLASH_PERIOD ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
88 /* The LED used by the check task to indicate the system status. */
\r
89 #define mainCHECK_LED ( 3 )
\r
90 /*-----------------------------------------------------------*/
\r
93 * Checks that all the demo application tasks are still executing without error
\r
94 * - as described at the top of the file.
\r
96 static portLONG prvCheckOtherTasksAreStillRunning( void );
\r
99 * The task that executes at the highest priority and calls
\r
100 * prvCheckOtherTasksAreStillRunning(). See the description at the top
\r
103 static void vErrorChecks( void *pvParameters );
\r
106 * Configure the processor for use with the Atmel demo board. This is very
\r
107 * minimal as most of the setup is performed in the startup code.
\r
109 static void prvSetupHardware( void );
\r
111 /*-----------------------------------------------------------*/
\r
114 * Starts all the other tasks, then starts the scheduler.
\r
118 /* Configure the processor. */
\r
119 prvSetupHardware();
\r
121 /* Setup the port used to flash the LED's. */
\r
122 vParTestInitialise();
\r
124 /* Start the task that handles the TCP/IP and WEB server functionality. */
\r
125 xTaskCreate( vuIP_TASK, "uIP", mainUIP_TASK_STACK_SIZE, NULL, mainUIP_PRIORITY, NULL );
\r
127 /* Start the demo/test application tasks. These are created in addition
\r
128 to the TCP/IP task for demonstration and test purposes. */
\r
129 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
130 vStartDynamicPriorityTasks();
\r
131 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
132 vStartLEDFlashTasks( mainFLASH_PRIORITY );
\r
133 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
134 vStartMathTasks( tskIDLE_PRIORITY );
\r
135 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
137 /* Start the check task - which is defined in this file. */
\r
138 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
140 /* Must be last to get created. */
\r
141 vCreateSuicidalTasks( mainDEATH_PRIORITY );
\r
143 /* Now all the tasks have been started - start the scheduler. */
\r
144 vTaskStartScheduler();
\r
146 /* Should never reach here because the tasks should now be executing! */
\r
149 /*-----------------------------------------------------------*/
\r
151 static void prvSetupHardware( void )
\r
153 /* When using the JTAG debugger the hardware is not always initialised to
\r
154 the correct default state. This line just ensures that this does not
\r
155 cause all interrupts to be masked at the start. */
\r
156 AT91C_BASE_AIC->AIC_EOICR = 0;
\r
158 /* Most setup is performed by the low level init function called from the
\r
161 Configure the PIO Lines corresponding to LED1 to LED4 to be outputs as
\r
162 well as the UART Tx line. */
\r
163 AT91F_PIO_CfgOutput( AT91C_BASE_PIOB, LED_MASK );
\r
165 /* Enable the peripheral clock. */
\r
166 AT91F_PMC_EnablePeriphClock( AT91C_BASE_PMC, 1 << AT91C_ID_PIOA );
\r
167 AT91F_PMC_EnablePeriphClock( AT91C_BASE_PMC, 1 << AT91C_ID_PIOB ) ;
\r
168 AT91F_PMC_EnablePeriphClock( AT91C_BASE_PMC, 1 << AT91C_ID_EMAC ) ;
\r
170 /*-----------------------------------------------------------*/
\r
172 static void vErrorChecks( void *pvParameters )
\r
174 portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
\r
175 portTickType xLastWakeTime;
\r
177 /* Initialise xLastWakeTime to ensure the first call to vTaskDelayUntil()
\r
178 functions correctly. */
\r
179 xLastWakeTime = xTaskGetTickCount();
\r
181 /* Cycle for ever, delaying then checking all the other tasks are still
\r
182 operating without error. If an error is detected then the delay period
\r
183 is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
\r
184 the Check LED flash rate will increase. */
\r
187 /* Delay until it is time to execute again. The delay period is
\r
188 shorter following an error. */
\r
189 vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );
\r
191 /* Check all the standard demo application tasks are executing without
\r
193 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
195 /* An error has been detected in one of the tasks - flash faster. */
\r
196 xDelayPeriod = mainERROR_FLASH_PERIOD;
\r
199 vParTestToggleLED( mainCHECK_LED );
\r
202 /*-----------------------------------------------------------*/
\r
204 static portLONG prvCheckOtherTasksAreStillRunning( void )
\r
206 portLONG lReturn = ( portLONG ) pdPASS;
\r
209 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
210 that they are all still running, and that none of them have detected
\r
213 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
215 lReturn = ( portLONG ) pdFAIL;
\r
218 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
220 lReturn = ( portLONG ) pdFAIL;
\r
223 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
225 lReturn = ( portLONG ) pdFAIL;
\r
228 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
230 lReturn = ( portLONG ) pdFAIL;
\r
233 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
235 lReturn = ( portLONG ) pdFAIL;
\r
238 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
240 lReturn = ( portLONG ) pdFAIL;
\r
243 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
245 lReturn = ( portLONG ) pdFAIL;
\r