]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/ARM7_AT91SAM7X256_Eclipse/RTOSDemo/main.c
Update version numbers in preparation for V8.2.0 release candidate 1.
[freertos] / FreeRTOS / Demo / ARM7_AT91SAM7X256_Eclipse / RTOSDemo / main.c
1 /*\r
2     FreeRTOS V8.2.0rc1 - Copyright (C) 2014 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
12 \r
13     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
14     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
15     >>!   obliged to provide the source code for proprietary components     !<<\r
16     >>!   outside of the FreeRTOS kernel.                                   !<<\r
17 \r
18     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
19     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
20     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
21     link: http://www.freertos.org/a00114.html\r
22 \r
23     1 tab == 4 spaces!\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    Having a problem?  Start by reading the FAQ "My application does   *\r
28      *    not run, what could be wrong?".  Have you defined configASSERT()?  *\r
29      *                                                                       *\r
30      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
31      *                                                                       *\r
32     ***************************************************************************\r
33 \r
34     ***************************************************************************\r
35      *                                                                       *\r
36      *    FreeRTOS provides completely free yet professionally developed,    *\r
37      *    robust, strictly quality controlled, supported, and cross          *\r
38      *    platform software that is more than just the market leader, it     *\r
39      *    is the industry's de facto standard.                               *\r
40      *                                                                       *\r
41      *    Help yourself get started quickly while simultaneously helping     *\r
42      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
43      *    tutorial book, reference manual, or both:                          *\r
44      *    http://www.FreeRTOS.org/Documentation                              *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     ***************************************************************************\r
49      *                                                                       *\r
50      *   Investing in training allows your team to be as productive as       *\r
51      *   possible as early as possible, lowering your overall development    *\r
52      *   cost, and enabling you to bring a more robust product to market     *\r
53      *   earlier than would otherwise be possible.  Richard Barry is both    *\r
54      *   the architect and key author of FreeRTOS, and so also the world's   *\r
55      *   leading authority on what is the world's most popular real time     *\r
56      *   kernel for deeply embedded MCU designs.  Obtaining your training    *\r
57      *   from Richard ensures your team will gain directly from his in-depth *\r
58      *   product knowledge and years of usage experience.  Contact Real Time *\r
59      *   Engineers Ltd to enquire about the FreeRTOS Masterclass, presented  *\r
60      *   by Richard Barry:  http://www.FreeRTOS.org/contact\r
61      *                                                                       *\r
62     ***************************************************************************\r
63 \r
64     ***************************************************************************\r
65      *                                                                       *\r
66      *    You are receiving this top quality software for free.  Please play *\r
67      *    fair and reciprocate by reporting any suspected issues and         *\r
68      *    participating in the community forum:                              *\r
69      *    http://www.FreeRTOS.org/support                                    *\r
70      *                                                                       *\r
71      *    Thank you!                                                         *\r
72      *                                                                       *\r
73     ***************************************************************************\r
74 \r
75     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
76     license and Real Time Engineers Ltd. contact details.\r
77 \r
78     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
79     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
80     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
81 \r
82     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
83     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
84 \r
85     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
86     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
87     licenses offer ticketed support, indemnification and commercial middleware.\r
88 \r
89     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
90     engineered and independently SIL3 certified version for use in safety and\r
91     mission critical applications that require provable dependability.\r
92 \r
93     1 tab == 4 spaces!\r
94 */\r
95 \r
96 /*\r
97         NOTE : Tasks run in System mode and the scheduler runs in Supervisor mode.\r
98         The processor MUST be in supervisor mode when vTaskStartScheduler is\r
99         called.  The demo applications included in the FreeRTOS.org download switch\r
100         to supervisor mode prior to main being called.  If you are not using one of\r
101         these demo application projects then ensure Supervisor mode is used.\r
102 */\r
103 \r
104 /*\r
105  * This demo includes a (basic) USB mouse driver and a WEB server.  It is\r
106  * targeted for the AT91SAM7X EK prototyping board which includes a small\r
107  * joystick to provide the mouse inputs.  The WEB interface provides some basic\r
108  * interactivity through the use of a check box to turn on and off an LED.\r
109  *\r
110  * main() creates the WEB server, USB, and a set of the standard demo tasks\r
111  * before starting the scheduler.  See the online FreeRTOS.org documentation \r
112  * for more information on the standard demo tasks.  \r
113  *\r
114  * LEDs D1 to D3 are controlled by the standard 'flash' tasks - each will \r
115  * toggle at a different fixed frequency.\r
116  *\r
117  * A tick hook function is used to monitor the standard demo tasks - with LED\r
118  * D4 being used to indicate the system status.  D4 toggling every 5 seconds\r
119  * indicates that all the standard demo tasks are executing without error.  The\r
120  * toggle rate increasing to 500ms is indicative of an error having been found\r
121  * in at least one demo task.\r
122  *\r
123  * See the online documentation page that accompanies this demo for full setup\r
124  * and usage information.\r
125  */\r
126 \r
127 /* Standard includes. */\r
128 #include <stdlib.h>\r
129 \r
130 /* Scheduler includes. */\r
131 #include "FreeRTOS.h"\r
132 #include "task.h"\r
133 \r
134 /* Demo application includes. */\r
135 #include "partest.h"\r
136 #include "USBSample.h"\r
137 #include "uIP_Task.h"\r
138 #include "BlockQ.h"\r
139 #include "blocktim.h"\r
140 #include "flash.h"\r
141 #include "QPeek.h"\r
142 #include "dynamic.h"\r
143 \r
144 /* Priorities for the demo application tasks. */\r
145 #define mainUIP_PRIORITY                                        ( tskIDLE_PRIORITY + 2 )\r
146 #define mainUSB_PRIORITY                                        ( tskIDLE_PRIORITY + 2 )\r
147 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 1 )\r
148 #define mainFLASH_PRIORITY                  ( tskIDLE_PRIORITY + 2 )\r
149 #define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY ) \r
150 \r
151 /* The task allocated to the uIP task is large to account for its use of the\r
152 sprintf() library function.  Use of a cut down printf() library would allow\r
153 the stack usage to be greatly reduced. */\r
154 #define mainUIP_TASK_STACK_SIZE         ( configMINIMAL_STACK_SIZE * 6 )\r
155 \r
156 /* The LED toggle by the tick hook should an error have been found in a task. */\r
157 #define mainERROR_LED                                           ( 3 )\r
158 \r
159 /*-----------------------------------------------------------*/\r
160 \r
161 /*\r
162  * Configure the processor for use with the Atmel demo board.  Setup is minimal\r
163  * as the low level init function (called from the startup asm file) takes care\r
164  * of most things.\r
165  */\r
166 static void prvSetupHardware( void );\r
167 \r
168 /*-----------------------------------------------------------*/\r
169 \r
170 /*\r
171  * Starts all the other tasks, then starts the scheduler.\r
172  */\r
173 int main( void )\r
174 {\r
175         /* Setup any hardware that has not already been configured by the low\r
176         level init routines. */\r
177         prvSetupHardware();\r
178 \r
179         /* Start the task that handles the TCP/IP and WEB server functionality. */\r
180     xTaskCreate( vuIP_Task, "uIP", mainUIP_TASK_STACK_SIZE, NULL, mainUIP_PRIORITY, NULL );\r
181         \r
182         /* Also start the USB demo which is just for the SAM7. */\r
183     vStartUSBTask( mainUSB_PRIORITY );\r
184         \r
185         /* Start the standard demo tasks. */\r
186         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
187     vCreateBlockTimeTasks();\r
188     vStartLEDFlashTasks( mainFLASH_PRIORITY );\r
189     vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
190     vStartQueuePeekTasks();   \r
191     vStartDynamicPriorityTasks();\r
192 \r
193         /* Start the scheduler.\r
194 \r
195         NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.\r
196         The processor MUST be in supervisor mode when vTaskStartScheduler is\r
197         called.  The demo applications included in the FreeRTOS.org download switch\r
198         to supervisor mode prior to main being called.  If you are not using one of\r
199         these demo application projects then ensure Supervisor mode is used here. */\r
200 \r
201         vTaskStartScheduler();\r
202 \r
203         /* We should never get here as control is now taken by the scheduler. */\r
204         return 0;\r
205 }\r
206 /*-----------------------------------------------------------*/\r
207 \r
208 static void prvSetupHardware( void )\r
209 {\r
210         portDISABLE_INTERRUPTS();\r
211         \r
212         /* When using the JTAG debugger the hardware is not always initialised to\r
213         the correct default state.  This line just ensures that this does not\r
214         cause all interrupts to be masked at the start. */\r
215         AT91C_BASE_AIC->AIC_EOICR = 0;\r
216         \r
217         /* Most setup is performed by the low level init function called from the\r
218         startup asm file. */\r
219 \r
220         /* Enable the peripheral clock. */\r
221     AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;\r
222     AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOB;\r
223         AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_EMAC;\r
224 \r
225         /* Initialise the LED outputs for use by the demo application tasks. */\r
226         vParTestInitialise();\r
227 }\r
228 /*-----------------------------------------------------------*/\r
229 \r
230 void vApplicationTickHook( void )\r
231 {\r
232 static unsigned long ulCallCount = 0, ulErrorFound = pdFALSE;\r
233 \r
234 /* The rate at which LED D4 will toggle if an error has been found in one or \r
235 more of the standard demo tasks. */\r
236 const unsigned long ulErrorFlashRate = 500 / portTICK_PERIOD_MS;\r
237 \r
238 /* The rate at which LED D4 will toggle if no errors have been found in any\r
239 of the standard demo tasks. */\r
240 const unsigned long ulNoErrorCheckRate = 5000 / portTICK_PERIOD_MS;\r
241 \r
242         ulCallCount++;\r
243 \r
244         if( ulErrorFound != pdFALSE )\r
245         {\r
246                 /* We have already found an error, so flash the LED with the appropriate\r
247                 frequency. */\r
248                 if( ulCallCount > ulErrorFlashRate )\r
249                 {\r
250                         ulCallCount = 0;\r
251                         vParTestToggleLED( mainERROR_LED );\r
252                 }\r
253         }\r
254         else\r
255         {\r
256                 if( ulCallCount > ulNoErrorCheckRate )\r
257                 {\r
258                         ulCallCount = 0;\r
259                         \r
260                         /* We have not yet found an error.  Check all the demo tasks to ensure\r
261                         this is still the case. */\r
262                         \r
263                         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
264                         {\r
265                                 ulErrorFound |= 0x01;\r
266                         }\r
267                         \r
268                         if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
269                         {\r
270                                 ulErrorFound |= 0x02;\r
271                         }\r
272         \r
273                         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
274                         {\r
275                                 ulErrorFound |= 0x04;\r
276                         }\r
277                         \r
278                         if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
279                         {\r
280                                 ulErrorFound |= 0x08;\r
281                         }\r
282                         \r
283                         if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
284                         {\r
285                                 ulErrorFound |= 0x10;\r
286                         }\r
287                         \r
288                         vParTestToggleLED( mainERROR_LED );\r
289                 }\r
290         }\r
291 }\r
292 \r
293 \r
294 \r
295 \r