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