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