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