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