]> git.sur5r.net Git - freertos/blob - Demo/WizNET_DEMO_GCC_ARM7/main.c
Comment the new MicroBlaze port layer files.
[freertos] / Demo / WizNET_DEMO_GCC_ARM7 / main.c
1 /*\r
2     FreeRTOS V7.0.1 - Copyright (C) 2011 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     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         NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.\r
56         The processor MUST be in supervisor mode when vTaskStartScheduler is \r
57         called.  The demo applications included in the FreeRTOS.org download switch\r
58         to supervisor mode prior to main being called.  If you are not using one of\r
59         these demo application projects then ensure Supervisor mode is used.\r
60 */\r
61 \r
62 \r
63 /*\r
64  * Program entry point.\r
65  * \r
66  * main() is responsible for setting up the microcontroller peripherals, then\r
67  * starting the demo application tasks.  Once the tasks have been created the\r
68  * scheduler is started and main() should never complete.\r
69  *\r
70  * The demo creates the three standard 'flash' tasks to provide some visual\r
71  * feedback that the system and scheduler are still operating correctly.\r
72  *\r
73  * The HTTP server task operates at the highest priority so will always preempt\r
74  * the flash or idle task on TCP/IP events.\r
75  */\r
76 \r
77 /* Standard includes. */\r
78 #include <stdlib.h>\r
79 \r
80 /* Scheduler include files. */\r
81 #include "FreeRTOS.h"\r
82 #include "semphr.h"\r
83 #include "task.h"\r
84 \r
85 /* Application includes. */\r
86 #include "i2c.h"\r
87 #include "HTTP_Serv.h"\r
88 #include "flash.h"\r
89 #include "partest.h"\r
90 #include "dynamic.h"\r
91 #include "semtest.h"\r
92 #include "PollQ.h"\r
93 #include "BlockQ.h"\r
94 #include "integer.h"\r
95 \r
96 /*-----------------------------------------------------------*/\r
97 \r
98 /* Constants to setup the PLL. */\r
99 #define mainPLL_MUL_4           ( ( unsigned char ) 0x0003 )\r
100 #define mainPLL_DIV_1           ( ( unsigned char ) 0x0000 )\r
101 #define mainPLL_ENABLE          ( ( unsigned char ) 0x0001 )\r
102 #define mainPLL_CONNECT         ( ( unsigned char ) 0x0003 )\r
103 #define mainPLL_FEED_BYTE1      ( ( unsigned char ) 0xaa )\r
104 #define mainPLL_FEED_BYTE2      ( ( unsigned char ) 0x55 )\r
105 #define mainPLL_LOCK            ( ( unsigned long ) 0x0400 )\r
106 \r
107 /* Constants to setup the MAM. */\r
108 #define mainMAM_TIM_3           ( ( unsigned char ) 0x03 )\r
109 #define mainMAM_MODE_FULL       ( ( unsigned char ) 0x02 )\r
110 \r
111 /* Constants to setup the peripheral bus. */\r
112 #define mainBUS_CLK_FULL        ( ( unsigned char ) 0x01 )\r
113 \r
114 /* Constants to setup I/O and processor. */\r
115 #define mainBUS_CLK_FULL        ( ( unsigned char ) 0x01 )\r
116 #define mainLED_TO_OUTPUT       ( ( unsigned long ) 0xff0000 )\r
117 #define mainJTAG_PORT           ( ( unsigned long ) 0x3E0000UL )\r
118 \r
119 /* Priorities for the demo application tasks. */\r
120 #define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
121 #define mainHTTP_TASK_PRIORITY          ( tskIDLE_PRIORITY + 2 )\r
122 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
123 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )\r
124 #define mainERROR_CHECK_PRIORITY        ( tskIDLE_PRIORITY + 1 )\r
125 \r
126 /* Flash rates of the on board LED to indicate the health of the system. */\r
127 #define mainNO_ERROR_DELAY                      ( 3000 )\r
128 #define mainERROR_DELAY                         ( 500 )\r
129 #define mainON_BOARD_LED_BIT            ( ( unsigned long ) 0x80 )\r
130 \r
131 /*-----------------------------------------------------------*/\r
132 \r
133 /*\r
134  * The Olimex demo board has a single built in LED.  This function simply\r
135  * toggles its state. \r
136  */\r
137 void prvToggleOnBoardLED( void );\r
138 \r
139 /*\r
140  * Configure the processor for use with the Olimex demo board.\r
141  */\r
142 static void prvSetupHardware( void );\r
143 \r
144 /*\r
145  * Simply check for errors and toggle the onboard LED.\r
146  */\r
147 static void prvErrorChecks( void *pvParameters );\r
148 \r
149 /*\r
150  * Return true if the demo tasks are executing without error - otherwise \r
151  * return false.\r
152  */\r
153 static void prvMainCheckOtherTasksAreStillRunning( void );\r
154 /*-----------------------------------------------------------*/\r
155 \r
156 /* Flag set by prvMainCheckOtherTasksAreStillExecuting(). */\r
157 long lErrorInTask = pdFALSE;\r
158 \r
159 /*\r
160  * Application entry point:\r
161  * Starts all the other tasks, then starts the scheduler. \r
162  */\r
163 int main( void )\r
164 {\r
165         /* Setup the hardware for use with the Olimex demo board. */\r
166         prvSetupHardware();\r
167 \r
168         /* Start the standard flash tasks so the WEB server is not the only thing \r
169         running. */\r
170         vStartLEDFlashTasks( mainLED_TASK_PRIORITY );\r
171         vStartSemaphoreTasks( tskIDLE_PRIORITY );\r
172         vStartDynamicPriorityTasks();\r
173         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
174         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
175         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
176 \r
177         /* Start the WEB server task and the error check task. */\r
178         xTaskCreate( vHTTPServerTask, ( signed char * ) "HTTP", configMINIMAL_STACK_SIZE, NULL, mainHTTP_TASK_PRIORITY, NULL );\r
179         xTaskCreate( prvErrorChecks, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainERROR_CHECK_PRIORITY, NULL );\r
180         \r
181         /* Now all the tasks have been started - start the scheduler.\r
182 \r
183         NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.\r
184         The processor MUST be in supervisor mode when vTaskStartScheduler is \r
185         called.  The demo applications included in the FreeRTOS.org download switch\r
186         to supervisor mode prior to main being called.  If you are not using one of\r
187         these demo application projects then ensure Supervisor mode is used. */\r
188         vTaskStartScheduler();\r
189 \r
190         /* Should never reach here! */\r
191         return 0;\r
192 }\r
193 /*-----------------------------------------------------------*/\r
194 \r
195 static void prvSetupHardware( void )\r
196 {\r
197         #ifdef RUN_FROM_RAM\r
198                 /* Remap the interrupt vectors to RAM if we are are running from RAM. */\r
199                 SCB_MEMMAP = 2;\r
200         #endif\r
201 \r
202         /* Set all GPIO to output other than the P0.14 (BSL), and the JTAG pins.  \r
203         The JTAG pins are left as input as I'm not sure what will happen if the \r
204         Wiggler is connected after powerup - not that it would be a good idea to\r
205         do that anyway. */\r
206         GPIO_IODIR = ~( mainJTAG_PORT );\r
207 \r
208         /* Setup the PLL to multiply the XTAL input by 4. */\r
209         SCB_PLLCFG = ( mainPLL_MUL_4 | mainPLL_DIV_1 );\r
210 \r
211         /* Activate the PLL by turning it on then feeding the correct sequence of\r
212         bytes. */\r
213         SCB_PLLCON = mainPLL_ENABLE;\r
214         SCB_PLLFEED = mainPLL_FEED_BYTE1;\r
215         SCB_PLLFEED = mainPLL_FEED_BYTE2;\r
216 \r
217         /* Wait for the PLL to lock... */\r
218         while( !( SCB_PLLSTAT & mainPLL_LOCK ) );\r
219 \r
220         /* ...before connecting it using the feed sequence again. */\r
221         SCB_PLLCON = mainPLL_CONNECT;\r
222         SCB_PLLFEED = mainPLL_FEED_BYTE1;\r
223         SCB_PLLFEED = mainPLL_FEED_BYTE2;\r
224 \r
225         /* Setup and turn on the MAM.  Three cycle access is used due to the fast\r
226         PLL used.  It is possible faster overall performance could be obtained by\r
227         tuning the MAM and PLL settings. */\r
228         MAM_TIM = mainMAM_TIM_3;\r
229         MAM_CR = mainMAM_MODE_FULL;\r
230 \r
231         /* Setup the peripheral bus to be the same as the PLL output. */\r
232         SCB_VPBDIV = mainBUS_CLK_FULL;\r
233 \r
234         /* Initialise the i2c peripheral. */\r
235         i2cInit();\r
236 \r
237         /* Initialise the LED's used by the flash tasks. */\r
238         vParTestInitialise();\r
239 }\r
240 /*-----------------------------------------------------------*/\r
241 \r
242 static void prvMainCheckOtherTasksAreStillRunning( void )\r
243 {\r
244         /* Check all the demo tasks (other than the flash tasks) to ensure\r
245         that they are all still running, and that none of them have detected\r
246         an error. */\r
247 \r
248         /* This function is called from more than one task. */\r
249         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
250         {\r
251                 lErrorInTask = pdTRUE;\r
252         }\r
253 \r
254         if( xArePollingQueuesStillRunning() != pdTRUE )\r
255         {\r
256                 lErrorInTask = pdTRUE;\r
257         }\r
258 \r
259         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
260         {\r
261                 lErrorInTask = pdTRUE;\r
262         }\r
263 \r
264         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
265         {\r
266                 lErrorInTask = pdTRUE;\r
267         }\r
268 \r
269         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
270         {\r
271                 lErrorInTask = pdTRUE;\r
272         }\r
273 }\r
274 /*-----------------------------------------------------------*/\r
275 \r
276 void prvToggleOnBoardLED( void )\r
277 {\r
278 unsigned long ulState;\r
279 \r
280         ulState = GPIO0_IOPIN;\r
281         if( ulState & mainON_BOARD_LED_BIT )\r
282         {\r
283                 GPIO_IOCLR = mainON_BOARD_LED_BIT;\r
284         }\r
285         else\r
286         {\r
287                 GPIO_IOSET = mainON_BOARD_LED_BIT;\r
288         }       \r
289 }\r
290 /*-----------------------------------------------------------*/\r
291 \r
292 static void prvErrorChecks( void *pvParameters )\r
293 {\r
294 portTickType xDelay = mainNO_ERROR_DELAY;\r
295 \r
296         /* The parameters are not used. */\r
297         ( void ) pvParameters;\r
298 \r
299         for( ;; )\r
300         {\r
301                 /* How long we delay depends on whether an error has been detected\r
302                 or not.  Therefore the flash rate of the on board LED indicates \r
303                 whether or not an error has occurred. */\r
304                 vTaskDelay( xDelay );\r
305 \r
306                 /* Update the lErrorInTask flag. */\r
307                 prvMainCheckOtherTasksAreStillRunning();\r
308 \r
309                 if( lErrorInTask )\r
310                 {\r
311                         /* An error has been found so reduce the delay period and in so\r
312                         doing speed up the flash rate of the on board LED. */\r
313                         xDelay = mainERROR_DELAY;\r
314                 }\r
315 \r
316                 prvToggleOnBoardLED();\r
317         }\r
318 }\r
319 \r