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