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