]> git.sur5r.net Git - freertos/blob - Demo/ARM7_AT91SAM7X256_Eclipse/RTOSDemo/main.c
Prepare for V5.3.1 release.
[freertos] / Demo / ARM7_AT91SAM7X256_Eclipse / RTOSDemo / main.c
1 /*\r
2         FreeRTOS.org V5.3.1 - Copyright (C) 2003-2009 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS.org distribution.\r
5 \r
6         FreeRTOS.org is free software; you can redistribute it and/or modify it\r
7         under the terms of the GNU General Public License (version 2) as published\r
8         by the Free Software Foundation and modified by the FreeRTOS exception.\r
9         **NOTE** The exception to the GPL is included to allow you to distribute a\r
10         combined work that includes FreeRTOS.org without being obliged to provide\r
11         the source code for any proprietary components.  Alternative commercial\r
12         license and support terms are also available upon request.  See the \r
13         licensing section of http://www.FreeRTOS.org for full details.\r
14 \r
15         FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT\r
16         ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
17         FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
18         more details.\r
19 \r
20         You should have received a copy of the GNU General Public License along\r
21         with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59\r
22         Temple Place, Suite 330, Boston, MA  02111-1307  USA.\r
23 \r
24 \r
25         ***************************************************************************\r
26         *                                                                         *\r
27         * Get the FreeRTOS eBook!  See http://www.FreeRTOS.org/Documentation      *\r
28         *                                                                         *\r
29         * This is a concise, step by step, 'hands on' guide that describes both   *\r
30         * general multitasking concepts and FreeRTOS specifics. It presents and   *\r
31         * explains numerous examples that are written using the FreeRTOS API.     *\r
32         * Full source code for all the examples is provided in an accompanying    *\r
33         * .zip file.                                                              *\r
34         *                                                                         *\r
35         ***************************************************************************\r
36 \r
37         1 tab == 4 spaces!\r
38 \r
39         Please ensure to read the configuration and relevant port sections of the\r
40         online documentation.\r
41 \r
42         http://www.FreeRTOS.org - Documentation, latest information, license and\r
43         contact details.\r
44 \r
45         http://www.SafeRTOS.com - A version that is certified for use in safety\r
46         critical systems.\r
47 \r
48         http://www.OpenRTOS.com - Commercial support, development, porting,\r
49         licensing and training services.\r
50 */\r
51 \r
52 /*\r
53         NOTE : Tasks run in System mode and the scheduler runs in Supervisor mode.\r
54         The processor MUST be in supervisor mode when vTaskStartScheduler is\r
55         called.  The demo applications included in the FreeRTOS.org download switch\r
56         to supervisor mode prior to main being called.  If you are not using one of\r
57         these demo application projects then ensure Supervisor mode is used.\r
58 */\r
59 \r
60 /*\r
61  * This demo includes a (basic) USB mouse driver and a WEB server.  It is\r
62  * targeted for the AT91SAM7X EK prototyping board which includes a small\r
63  * joystick to provide the mouse inputs.  The WEB interface provides some basic\r
64  * interactivity through the use of a check box to turn on and off an LED.\r
65  *\r
66  * main() creates the WEB server, USB, and a set of the standard demo tasks\r
67  * before starting the scheduler.  See the online FreeRTOS.org documentation \r
68  * for more information on the standard demo tasks.  \r
69  *\r
70  * LEDs D1 to D3 are controlled by the standard 'flash' tasks - each will \r
71  * toggle at a different fixed frequency.\r
72  *\r
73  * A tick hook function is used to monitor the standard demo tasks - with LED\r
74  * D4 being used to indicate the system status.  D4 toggling every 5 seconds\r
75  * indicates that all the standard demo tasks are executing without error.  The\r
76  * toggle rate increasing to 500ms is indicative of an error having been found\r
77  * in at least one demo task.\r
78  *\r
79  * See the online documentation page that accompanies this demo for full setup\r
80  * and usage information.\r
81  */\r
82 \r
83 /* Standard includes. */\r
84 #include <stdlib.h>\r
85 \r
86 /* Scheduler includes. */\r
87 #include "FreeRTOS.h"\r
88 #include "task.h"\r
89 \r
90 /* Demo application includes. */\r
91 #include "partest.h"\r
92 #include "USBSample.h"\r
93 #include "uip_task.h"\r
94 #include "BlockQ.h"\r
95 #include "blocktim.h"\r
96 #include "flash.h"\r
97 #include "QPeek.h"\r
98 #include "dynamic.h"\r
99 \r
100 /* Priorities for the demo application tasks. */\r
101 #define mainUIP_PRIORITY                                        ( tskIDLE_PRIORITY + 2 )\r
102 #define mainUSB_PRIORITY                                        ( tskIDLE_PRIORITY + 2 )\r
103 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 1 )\r
104 #define mainFLASH_PRIORITY                  ( tskIDLE_PRIORITY + 2 )\r
105 #define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY ) \r
106 \r
107 /* The task allocated to the uIP task is large to account for its use of the\r
108 sprintf() library function.  Use of a cut down printf() library would allow\r
109 the stack usage to be greatly reduced. */\r
110 #define mainUIP_TASK_STACK_SIZE         ( configMINIMAL_STACK_SIZE * 6 )\r
111 \r
112 /* The LED toggle by the tick hook should an error have been found in a task. */\r
113 #define mainERROR_LED                                           ( 3 )\r
114 \r
115 /*-----------------------------------------------------------*/\r
116 \r
117 /*\r
118  * Configure the processor for use with the Atmel demo board.  Setup is minimal\r
119  * as the low level init function (called from the startup asm file) takes care\r
120  * of most things.\r
121  */\r
122 static void prvSetupHardware( void );\r
123 \r
124 /*-----------------------------------------------------------*/\r
125 \r
126 /*\r
127  * Starts all the other tasks, then starts the scheduler.\r
128  */\r
129 int main( void )\r
130 {\r
131         /* Setup any hardware that has not already been configured by the low\r
132         level init routines. */\r
133         prvSetupHardware();\r
134 \r
135         /* Start the task that handles the TCP/IP and WEB server functionality. */\r
136     xTaskCreate( vuIP_Task, "uIP", mainUIP_TASK_STACK_SIZE, NULL, mainUIP_PRIORITY, NULL );\r
137         \r
138         /* Also start the USB demo which is just for the SAM7. */\r
139     vStartUSBTask( mainUSB_PRIORITY );\r
140         \r
141         /* Start the standard demo tasks. */\r
142         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
143     vCreateBlockTimeTasks();\r
144     vStartLEDFlashTasks( mainFLASH_PRIORITY );\r
145     vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
146     vStartQueuePeekTasks();   \r
147     vStartDynamicPriorityTasks();\r
148 \r
149         /* Start the scheduler.\r
150 \r
151         NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.\r
152         The processor MUST be in supervisor mode when vTaskStartScheduler is\r
153         called.  The demo applications included in the FreeRTOS.org download switch\r
154         to supervisor mode prior to main being called.  If you are not using one of\r
155         these demo application projects then ensure Supervisor mode is used here. */\r
156 \r
157         vTaskStartScheduler();\r
158 \r
159         /* We should never get here as control is now taken by the scheduler. */\r
160         return 0;\r
161 }\r
162 /*-----------------------------------------------------------*/\r
163 \r
164 static void prvSetupHardware( void )\r
165 {\r
166         portDISABLE_INTERRUPTS();\r
167         \r
168         /* When using the JTAG debugger the hardware is not always initialised to\r
169         the correct default state.  This line just ensures that this does not\r
170         cause all interrupts to be masked at the start. */\r
171         AT91C_BASE_AIC->AIC_EOICR = 0;\r
172         \r
173         /* Most setup is performed by the low level init function called from the\r
174         startup asm file. */\r
175 \r
176         /* Enable the peripheral clock. */\r
177     AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;\r
178     AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOB;\r
179         AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_EMAC;\r
180 \r
181         /* Initialise the LED outputs for use by the demo application tasks. */\r
182         vParTestInitialise();\r
183 }\r
184 /*-----------------------------------------------------------*/\r
185 \r
186 void vApplicationTickHook( void )\r
187 {\r
188 static unsigned portLONG ulCallCount = 0, ulErrorFound = pdFALSE;\r
189 \r
190 /* The rate at which LED D4 will toggle if an error has been found in one or \r
191 more of the standard demo tasks. */\r
192 const unsigned portLONG ulErrorFlashRate = 500 / portTICK_RATE_MS;\r
193 \r
194 /* The rate at which LED D4 will toggle if no errors have been found in any\r
195 of the standard demo tasks. */\r
196 const unsigned portLONG ulNoErrorCheckRate = 5000 / portTICK_RATE_MS;\r
197 \r
198         ulCallCount++;\r
199 \r
200         if( ulErrorFound != pdFALSE )\r
201         {\r
202                 /* We have already found an error, so flash the LED with the appropriate\r
203                 frequency. */\r
204                 if( ulCallCount > ulErrorFlashRate )\r
205                 {\r
206                         ulCallCount = 0;\r
207                         vParTestToggleLED( mainERROR_LED );\r
208                 }\r
209         }\r
210         else\r
211         {\r
212                 if( ulCallCount > ulNoErrorCheckRate )\r
213                 {\r
214                         ulCallCount = 0;\r
215                         \r
216                         /* We have not yet found an error.  Check all the demo tasks to ensure\r
217                         this is still the case. */\r
218                         \r
219                         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
220                         {\r
221                                 ulErrorFound |= 0x01;\r
222                         }\r
223                         \r
224                         if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
225                         {\r
226                                 ulErrorFound |= 0x02;\r
227                         }\r
228         \r
229                         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
230                         {\r
231                                 ulErrorFound |= 0x04;\r
232                         }\r
233                         \r
234                         if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
235                         {\r
236                                 ulErrorFound |= 0x08;\r
237                         }\r
238                         \r
239                         if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
240                         {\r
241                                 ulErrorFound |= 0x10;\r
242                         }\r
243                         \r
244                         vParTestToggleLED( mainERROR_LED );\r
245                 }\r
246         }\r
247 }\r
248 \r
249 \r
250 \r
251 \r