]> git.sur5r.net Git - freertos/blob - Demo/ARM7_AT91SAM7X256_Eclipse/RTOSDemo/main.c
Prepare files for export (MicroBlaze project).
[freertos] / Demo / ARM7_AT91SAM7X256_Eclipse / RTOSDemo / 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  * This demo includes a (basic) USB mouse driver and a WEB server.  It is\r
64  * targeted for the AT91SAM7X EK prototyping board which includes a small\r
65  * joystick to provide the mouse inputs.  The WEB interface provides some basic\r
66  * interactivity through the use of a check box to turn on and off an LED.\r
67  *\r
68  * main() creates the WEB server, USB, and a set of the standard demo tasks\r
69  * before starting the scheduler.  See the online FreeRTOS.org documentation \r
70  * for more information on the standard demo tasks.  \r
71  *\r
72  * LEDs D1 to D3 are controlled by the standard 'flash' tasks - each will \r
73  * toggle at a different fixed frequency.\r
74  *\r
75  * A tick hook function is used to monitor the standard demo tasks - with LED\r
76  * D4 being used to indicate the system status.  D4 toggling every 5 seconds\r
77  * indicates that all the standard demo tasks are executing without error.  The\r
78  * toggle rate increasing to 500ms is indicative of an error having been found\r
79  * in at least one demo task.\r
80  *\r
81  * See the online documentation page that accompanies this demo for full setup\r
82  * and usage information.\r
83  */\r
84 \r
85 /* Standard includes. */\r
86 #include <stdlib.h>\r
87 \r
88 /* Scheduler includes. */\r
89 #include "FreeRTOS.h"\r
90 #include "task.h"\r
91 \r
92 /* Demo application includes. */\r
93 #include "partest.h"\r
94 #include "USBSample.h"\r
95 #include "uIP_Task.h"\r
96 #include "BlockQ.h"\r
97 #include "blocktim.h"\r
98 #include "flash.h"\r
99 #include "QPeek.h"\r
100 #include "dynamic.h"\r
101 \r
102 /* Priorities for the demo application tasks. */\r
103 #define mainUIP_PRIORITY                                        ( tskIDLE_PRIORITY + 2 )\r
104 #define mainUSB_PRIORITY                                        ( tskIDLE_PRIORITY + 2 )\r
105 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 1 )\r
106 #define mainFLASH_PRIORITY                  ( tskIDLE_PRIORITY + 2 )\r
107 #define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY ) \r
108 \r
109 /* The task allocated to the uIP task is large to account for its use of the\r
110 sprintf() library function.  Use of a cut down printf() library would allow\r
111 the stack usage to be greatly reduced. */\r
112 #define mainUIP_TASK_STACK_SIZE         ( configMINIMAL_STACK_SIZE * 6 )\r
113 \r
114 /* The LED toggle by the tick hook should an error have been found in a task. */\r
115 #define mainERROR_LED                                           ( 3 )\r
116 \r
117 /*-----------------------------------------------------------*/\r
118 \r
119 /*\r
120  * Configure the processor for use with the Atmel demo board.  Setup is minimal\r
121  * as the low level init function (called from the startup asm file) takes care\r
122  * of most things.\r
123  */\r
124 static void prvSetupHardware( void );\r
125 \r
126 /*-----------------------------------------------------------*/\r
127 \r
128 /*\r
129  * Starts all the other tasks, then starts the scheduler.\r
130  */\r
131 int main( void )\r
132 {\r
133         /* Setup any hardware that has not already been configured by the low\r
134         level init routines. */\r
135         prvSetupHardware();\r
136 \r
137         /* Start the task that handles the TCP/IP and WEB server functionality. */\r
138     xTaskCreate( vuIP_Task, "uIP", mainUIP_TASK_STACK_SIZE, NULL, mainUIP_PRIORITY, NULL );\r
139         \r
140         /* Also start the USB demo which is just for the SAM7. */\r
141     vStartUSBTask( mainUSB_PRIORITY );\r
142         \r
143         /* Start the standard demo tasks. */\r
144         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
145     vCreateBlockTimeTasks();\r
146     vStartLEDFlashTasks( mainFLASH_PRIORITY );\r
147     vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
148     vStartQueuePeekTasks();   \r
149     vStartDynamicPriorityTasks();\r
150 \r
151         /* Start the scheduler.\r
152 \r
153         NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.\r
154         The processor MUST be in supervisor mode when vTaskStartScheduler is\r
155         called.  The demo applications included in the FreeRTOS.org download switch\r
156         to supervisor mode prior to main being called.  If you are not using one of\r
157         these demo application projects then ensure Supervisor mode is used here. */\r
158 \r
159         vTaskStartScheduler();\r
160 \r
161         /* We should never get here as control is now taken by the scheduler. */\r
162         return 0;\r
163 }\r
164 /*-----------------------------------------------------------*/\r
165 \r
166 static void prvSetupHardware( void )\r
167 {\r
168         portDISABLE_INTERRUPTS();\r
169         \r
170         /* When using the JTAG debugger the hardware is not always initialised to\r
171         the correct default state.  This line just ensures that this does not\r
172         cause all interrupts to be masked at the start. */\r
173         AT91C_BASE_AIC->AIC_EOICR = 0;\r
174         \r
175         /* Most setup is performed by the low level init function called from the\r
176         startup asm file. */\r
177 \r
178         /* Enable the peripheral clock. */\r
179     AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;\r
180     AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOB;\r
181         AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_EMAC;\r
182 \r
183         /* Initialise the LED outputs for use by the demo application tasks. */\r
184         vParTestInitialise();\r
185 }\r
186 /*-----------------------------------------------------------*/\r
187 \r
188 void vApplicationTickHook( void )\r
189 {\r
190 static unsigned long ulCallCount = 0, ulErrorFound = pdFALSE;\r
191 \r
192 /* The rate at which LED D4 will toggle if an error has been found in one or \r
193 more of the standard demo tasks. */\r
194 const unsigned long ulErrorFlashRate = 500 / portTICK_RATE_MS;\r
195 \r
196 /* The rate at which LED D4 will toggle if no errors have been found in any\r
197 of the standard demo tasks. */\r
198 const unsigned long ulNoErrorCheckRate = 5000 / portTICK_RATE_MS;\r
199 \r
200         ulCallCount++;\r
201 \r
202         if( ulErrorFound != pdFALSE )\r
203         {\r
204                 /* We have already found an error, so flash the LED with the appropriate\r
205                 frequency. */\r
206                 if( ulCallCount > ulErrorFlashRate )\r
207                 {\r
208                         ulCallCount = 0;\r
209                         vParTestToggleLED( mainERROR_LED );\r
210                 }\r
211         }\r
212         else\r
213         {\r
214                 if( ulCallCount > ulNoErrorCheckRate )\r
215                 {\r
216                         ulCallCount = 0;\r
217                         \r
218                         /* We have not yet found an error.  Check all the demo tasks to ensure\r
219                         this is still the case. */\r
220                         \r
221                         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
222                         {\r
223                                 ulErrorFound |= 0x01;\r
224                         }\r
225                         \r
226                         if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
227                         {\r
228                                 ulErrorFound |= 0x02;\r
229                         }\r
230         \r
231                         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
232                         {\r
233                                 ulErrorFound |= 0x04;\r
234                         }\r
235                         \r
236                         if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
237                         {\r
238                                 ulErrorFound |= 0x08;\r
239                         }\r
240                         \r
241                         if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
242                         {\r
243                                 ulErrorFound |= 0x10;\r
244                         }\r
245                         \r
246                         vParTestToggleLED( mainERROR_LED );\r
247                 }\r
248         }\r
249 }\r
250 \r
251 \r
252 \r
253 \r