]> git.sur5r.net Git - freertos/blob - Demo/uIP_Demo_IAR_ARM7/main.c
Update to V5.4.1
[freertos] / Demo / uIP_Demo_IAR_ARM7 / main.c
1 /*\r
2         FreeRTOS V5.4.1 - Copyright (C) 2009 Real Time Engineers Ltd.\r
3 \r
4         This file is part of the FreeRTOS distribution.\r
5 \r
6         FreeRTOS is free software; you can redistribute it and/or modify it     under \r
7         the terms of the GNU General Public License (version 2) as published by the \r
8         Free Software Foundation and modified by the FreeRTOS exception.\r
9         **NOTE** The exception to the GPL is included to allow you to distribute a\r
10         combined work that includes FreeRTOS without being obliged to provide the \r
11         source code for proprietary components outside of the FreeRTOS kernel.  \r
12         Alternative commercial license and support terms are also available upon \r
13         request.  See the licensing section of http://www.FreeRTOS.org for full \r
14         license details.\r
15 \r
16         FreeRTOS is distributed in the hope that it will be useful,     but WITHOUT\r
17         ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
18         FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
19         more details.\r
20 \r
21         You should have received a copy of the GNU General Public License along\r
22         with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59\r
23         Temple Place, Suite 330, Boston, MA  02111-1307  USA.\r
24 \r
25 \r
26         ***************************************************************************\r
27         *                                                                         *\r
28         * Looking for a quick start?  Then check out the FreeRTOS eBook!          *\r
29         * See http://www.FreeRTOS.org/Documentation for details                   *\r
30         *                                                                         *\r
31         ***************************************************************************\r
32 \r
33         1 tab == 4 spaces!\r
34 \r
35         Please ensure to read the configuration and relevant port sections of the\r
36         online documentation.\r
37 \r
38         http://www.FreeRTOS.org - Documentation, latest information, license and\r
39         contact details.\r
40 \r
41         http://www.SafeRTOS.com - A version that is certified for use in safety\r
42         critical systems.\r
43 \r
44         http://www.OpenRTOS.com - Commercial support, development, porting,\r
45         licensing and training services.\r
46 */\r
47 \r
48 /*\r
49  * Creates all the application tasks, then starts the scheduler.\r
50  *\r
51  * A task is also created called "uIP".  This executes the uIP stack and small\r
52  * WEB server sample.  All the other tasks are from the set of standard\r
53  * demo tasks.  The WEB documentation provides more details of the standard\r
54  * demo application tasks.\r
55  *\r
56  * Main.c also creates a task called "Check".  This only executes every three\r
57  * seconds but has the highest priority so is guaranteed to get processor time.\r
58  * Its main function is to check the status of all the other demo application\r
59  * tasks.  LED mainCHECK_LED is toggled every three seconds by the check task\r
60  * should no error conditions be detected in any of the standard demo tasks.\r
61  * The toggle rate increasing to 500ms indicates that at least one error has\r
62  * been detected.\r
63  */\r
64 \r
65 \r
66 /* Standard includes. */\r
67 #include <stdlib.h>\r
68 #include <string.h>\r
69 \r
70 /* Scheduler includes. */\r
71 #include "FreeRTOS.h"\r
72 #include "task.h"\r
73 \r
74 /* Demo application includes. */\r
75 #include "partest.h"\r
76 #include "PollQ.h"\r
77 #include "dynamic.h"\r
78 #include "semtest.h"\r
79 #include "flash.h"\r
80 #include "integer.h"\r
81 #include "flop.h"\r
82 #include "BlockQ.h"\r
83 #include "death.h"\r
84 #include "uip_task.h"\r
85 \r
86 /*-----------------------------------------------------------*/\r
87 \r
88 /* Priorities/stacks for the demo application tasks. */\r
89 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
90 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 3 )\r
91 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
92 #define mainUIP_PRIORITY                        ( tskIDLE_PRIORITY + 3 )\r
93 #define mainFLASH_PRIORITY                      ( tskIDLE_PRIORITY + 2 )\r
94 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 1 )\r
95 #define mainDEATH_PRIORITY                      ( tskIDLE_PRIORITY + 2 )\r
96 #define mainUIP_TASK_STACK_SIZE         ( 250 )\r
97 \r
98 /* The rate at which the on board LED will toggle when there is/is not an\r
99 error. */\r
100 #define mainNO_ERROR_FLASH_PERIOD       ( ( portTickType ) 3000 / portTICK_RATE_MS  )\r
101 #define mainERROR_FLASH_PERIOD          ( ( portTickType ) 500 / portTICK_RATE_MS  )\r
102 \r
103 /* The LED used by the check task to indicate the system status. */\r
104 #define mainCHECK_LED                           ( 3 )\r
105 /*-----------------------------------------------------------*/\r
106 \r
107 /*\r
108  * Checks that all the demo application tasks are still executing without error\r
109  * - as described at the top of the file.\r
110  */\r
111 static portLONG prvCheckOtherTasksAreStillRunning( void );\r
112 \r
113 /*\r
114  * The task that executes at the highest priority and calls\r
115  * prvCheckOtherTasksAreStillRunning().  See the description at the top\r
116  * of the file.\r
117  */\r
118 static void vErrorChecks( void *pvParameters );\r
119 \r
120 /*\r
121  * Configure the processor for use with the Atmel demo board.  This is very\r
122  * minimal as most of the setup is performed in the startup code.\r
123  */\r
124 static void prvSetupHardware( void );\r
125 \r
126 /*-----------------------------------------------------------*/\r
127 \r
128 /*\r
129  * Starts all the other tasks, then starts the scheduler.\r
130  */\r
131 int main( void )\r
132 {\r
133         /* Configure the processor. */\r
134         prvSetupHardware();\r
135 \r
136         /* Setup the port used to flash the LED's. */\r
137         vParTestInitialise();\r
138 \r
139         /* Start the task that handles the TCP/IP and WEB server functionality. */\r
140     xTaskCreate( vuIP_TASK, "uIP", mainUIP_TASK_STACK_SIZE, NULL, mainUIP_PRIORITY, NULL );\r
141         \r
142         /* Start the demo/test application tasks.  These are created in addition\r
143         to the TCP/IP task for demonstration and test purposes. */\r
144         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
145         vStartDynamicPriorityTasks();\r
146         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
147         vStartLEDFlashTasks( mainFLASH_PRIORITY );\r
148         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
149         vStartMathTasks( tskIDLE_PRIORITY );\r
150         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
151 \r
152         /* Start the check task - which is defined in this file. */     \r
153     xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
154 \r
155         /* Must be last to get created. */\r
156         vCreateSuicidalTasks( mainDEATH_PRIORITY );\r
157 \r
158         /* Now all the tasks have been started - start the scheduler. */\r
159         vTaskStartScheduler();\r
160 \r
161         /* Should never reach here because the tasks should now be executing! */\r
162         return 0;\r
163 }\r
164 /*-----------------------------------------------------------*/\r
165 \r
166 static void prvSetupHardware( void )\r
167 {\r
168         /* When using the JTAG debugger the hardware is not always initialised to\r
169         the correct default state.  This line just ensures that this does not\r
170         cause all interrupts to be masked at the start. */\r
171         AT91C_BASE_AIC->AIC_EOICR = 0;\r
172         \r
173         /* Most setup is performed by the low level init function called from the\r
174         startup asm file.\r
175 \r
176         Configure the PIO Lines corresponding to LED1 to LED4 to be outputs as\r
177         well as the UART Tx line. */\r
178         AT91F_PIO_CfgOutput( AT91C_BASE_PIOB, LED_MASK );\r
179 \r
180         /* Enable the peripheral clock. */\r
181         AT91F_PMC_EnablePeriphClock( AT91C_BASE_PMC, 1 << AT91C_ID_PIOA );\r
182         AT91F_PMC_EnablePeriphClock( AT91C_BASE_PMC, 1 << AT91C_ID_PIOB ) ;\r
183         AT91F_PMC_EnablePeriphClock( AT91C_BASE_PMC, 1 << AT91C_ID_EMAC ) ;\r
184 }\r
185 /*-----------------------------------------------------------*/\r
186 \r
187 static void vErrorChecks( void *pvParameters )\r
188 {\r
189 portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;\r
190 portTickType xLastWakeTime;\r
191 \r
192         /* Initialise xLastWakeTime to ensure the first call to vTaskDelayUntil()\r
193         functions correctly. */\r
194         xLastWakeTime = xTaskGetTickCount();\r
195 \r
196         /* Cycle for ever, delaying then checking all the other tasks are still\r
197         operating without error.  If an error is detected then the delay period\r
198         is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so\r
199         the Check LED flash rate will increase. */\r
200         for( ;; )\r
201         {\r
202                 /* Delay until it is time to execute again.  The delay period is\r
203                 shorter following an error. */\r
204                 vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );\r
205         \r
206                 /* Check all the standard demo application tasks are executing without\r
207                 error.  */\r
208                 if( prvCheckOtherTasksAreStillRunning() != pdPASS )\r
209                 {\r
210                         /* An error has been detected in one of the tasks - flash faster. */\r
211                         xDelayPeriod = mainERROR_FLASH_PERIOD;\r
212                 }\r
213 \r
214                 vParTestToggleLED( mainCHECK_LED );\r
215         }\r
216 }\r
217 /*-----------------------------------------------------------*/\r
218 \r
219 static portLONG prvCheckOtherTasksAreStillRunning( void )\r
220 {\r
221 portLONG lReturn = ( portLONG ) pdPASS;\r
222 \r
223 \r
224         /* Check all the demo tasks (other than the flash tasks) to ensure\r
225         that they are all still running, and that none of them have detected\r
226         an error. */\r
227 \r
228         if( xArePollingQueuesStillRunning() != pdTRUE )\r
229         {\r
230                 lReturn = ( portLONG ) pdFAIL;\r
231         }\r
232 \r
233         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
234         {\r
235                 lReturn = ( portLONG ) pdFAIL;\r
236         }\r
237 \r
238         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
239         {\r
240                 lReturn = ( portLONG ) pdFAIL;\r
241         }\r
242 \r
243         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
244         {\r
245                 lReturn = ( portLONG ) pdFAIL;\r
246         }\r
247 \r
248         if( xAreMathsTaskStillRunning() != pdTRUE )\r
249         {\r
250                 lReturn = ( portLONG ) pdFAIL;\r
251         }\r
252 \r
253         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
254         {\r
255                 lReturn = ( portLONG ) pdFAIL;\r
256         }\r
257 \r
258         if( xIsCreateTaskStillRunning() != pdTRUE )\r
259         {\r
260                 lReturn = ( portLONG ) pdFAIL;\r
261         }\r
262 \r
263         return lReturn;\r
264 }\r
265 \r
266 \r
267 \r