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