2 FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\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
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\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
44 ***************************************************************************
\r
46 * Having a problem? Start by reading the FAQ "My application does *
\r
47 * not run, what could be wrong? *
\r
49 * http://www.FreeRTOS.org/FAQHelp.html *
\r
51 ***************************************************************************
\r
54 http://www.FreeRTOS.org - Documentation, training, latest information,
\r
55 license and contact details.
\r
57 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
58 including FreeRTOS+Trace - an indispensable productivity tool.
\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
68 NOTE : Tasks run in System mode and the scheduler runs in Supervisor mode.
\r
69 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
70 called. The demo applications included in the FreeRTOS.org download switch
\r
71 to supervisor mode prior to main being called. If you are not using one of
\r
72 these demo application projects then ensure Supervisor mode is used.
\r
76 * This demo includes a (basic) USB mouse driver and a WEB server. It is
\r
77 * targeted for the AT91SAM7X EK prototyping board which includes a small
\r
78 * joystick to provide the mouse inputs. The WEB interface provides some basic
\r
79 * interactivity through the use of a check box to turn on and off an LED.
\r
81 * main() creates the WEB server, USB, and a set of the standard demo tasks
\r
82 * before starting the scheduler. See the online FreeRTOS.org documentation
\r
83 * for more information on the standard demo tasks.
\r
85 * LEDs D1 to D3 are controlled by the standard 'flash' tasks - each will
\r
86 * toggle at a different fixed frequency.
\r
88 * A tick hook function is used to monitor the standard demo tasks - with LED
\r
89 * D4 being used to indicate the system status. D4 toggling every 5 seconds
\r
90 * indicates that all the standard demo tasks are executing without error. The
\r
91 * toggle rate increasing to 500ms is indicative of an error having been found
\r
92 * in at least one demo task.
\r
94 * See the online documentation page that accompanies this demo for full setup
\r
95 * and usage information.
\r
98 /* Standard includes. */
\r
101 /* Scheduler includes. */
\r
102 #include "FreeRTOS.h"
\r
105 /* Demo application includes. */
\r
106 #include "partest.h"
\r
107 #include "USBSample.h"
\r
108 #include "uIP_Task.h"
\r
109 #include "BlockQ.h"
\r
110 #include "blocktim.h"
\r
113 #include "dynamic.h"
\r
115 /* Priorities for the demo application tasks. */
\r
116 #define mainUIP_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
117 #define mainUSB_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
118 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
119 #define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
120 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
122 /* The task allocated to the uIP task is large to account for its use of the
\r
123 sprintf() library function. Use of a cut down printf() library would allow
\r
124 the stack usage to be greatly reduced. */
\r
125 #define mainUIP_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 6 )
\r
127 /* The LED toggle by the tick hook should an error have been found in a task. */
\r
128 #define mainERROR_LED ( 3 )
\r
130 /*-----------------------------------------------------------*/
\r
133 * Configure the processor for use with the Atmel demo board. Setup is minimal
\r
134 * as the low level init function (called from the startup asm file) takes care
\r
137 static void prvSetupHardware( void );
\r
139 /*-----------------------------------------------------------*/
\r
142 * Starts all the other tasks, then starts the scheduler.
\r
146 /* Setup any hardware that has not already been configured by the low
\r
147 level init routines. */
\r
148 prvSetupHardware();
\r
150 /* Start the task that handles the TCP/IP and WEB server functionality. */
\r
151 xTaskCreate( vuIP_Task, "uIP", mainUIP_TASK_STACK_SIZE, NULL, mainUIP_PRIORITY, NULL );
\r
153 /* Also start the USB demo which is just for the SAM7. */
\r
154 vStartUSBTask( mainUSB_PRIORITY );
\r
156 /* Start the standard demo tasks. */
\r
157 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
158 vCreateBlockTimeTasks();
\r
159 vStartLEDFlashTasks( mainFLASH_PRIORITY );
\r
160 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
161 vStartQueuePeekTasks();
\r
162 vStartDynamicPriorityTasks();
\r
164 /* Start the scheduler.
\r
166 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
167 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
168 called. The demo applications included in the FreeRTOS.org download switch
\r
169 to supervisor mode prior to main being called. If you are not using one of
\r
170 these demo application projects then ensure Supervisor mode is used here. */
\r
172 vTaskStartScheduler();
\r
174 /* We should never get here as control is now taken by the scheduler. */
\r
177 /*-----------------------------------------------------------*/
\r
179 static void prvSetupHardware( void )
\r
181 portDISABLE_INTERRUPTS();
\r
183 /* When using the JTAG debugger the hardware is not always initialised to
\r
184 the correct default state. This line just ensures that this does not
\r
185 cause all interrupts to be masked at the start. */
\r
186 AT91C_BASE_AIC->AIC_EOICR = 0;
\r
188 /* Most setup is performed by the low level init function called from the
\r
189 startup asm file. */
\r
191 /* Enable the peripheral clock. */
\r
192 AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;
\r
193 AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOB;
\r
194 AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_EMAC;
\r
196 /* Initialise the LED outputs for use by the demo application tasks. */
\r
197 vParTestInitialise();
\r
199 /*-----------------------------------------------------------*/
\r
201 void vApplicationTickHook( void )
\r
203 static unsigned long ulCallCount = 0, ulErrorFound = pdFALSE;
\r
205 /* The rate at which LED D4 will toggle if an error has been found in one or
\r
206 more of the standard demo tasks. */
\r
207 const unsigned long ulErrorFlashRate = 500 / portTICK_RATE_MS;
\r
209 /* The rate at which LED D4 will toggle if no errors have been found in any
\r
210 of the standard demo tasks. */
\r
211 const unsigned long ulNoErrorCheckRate = 5000 / portTICK_RATE_MS;
\r
215 if( ulErrorFound != pdFALSE )
\r
217 /* We have already found an error, so flash the LED with the appropriate
\r
219 if( ulCallCount > ulErrorFlashRate )
\r
222 vParTestToggleLED( mainERROR_LED );
\r
227 if( ulCallCount > ulNoErrorCheckRate )
\r
231 /* We have not yet found an error. Check all the demo tasks to ensure
\r
232 this is still the case. */
\r
234 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
236 ulErrorFound |= 0x01;
\r
239 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
241 ulErrorFound |= 0x02;
\r
244 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
246 ulErrorFound |= 0x04;
\r
249 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
251 ulErrorFound |= 0x08;
\r
254 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
256 ulErrorFound |= 0x10;
\r
259 vParTestToggleLED( mainERROR_LED );
\r