2 FreeRTOS V7.5.1 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
66 NOTE : Tasks run in System mode and the scheduler runs in Supervisor mode.
\r
67 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
68 called. The demo applications included in the FreeRTOS.org download switch
\r
69 to supervisor mode prior to main being called. If you are not using one of
\r
70 these demo application projects then ensure Supervisor mode is used.
\r
74 * This demo includes a (basic) USB mouse driver and a WEB server. It is
\r
75 * targeted for the AT91SAM7X EK prototyping board which includes a small
\r
76 * joystick to provide the mouse inputs. The WEB interface provides some basic
\r
77 * interactivity through the use of a check box to turn on and off an LED.
\r
79 * main() creates the WEB server, USB, and a set of the standard demo tasks
\r
80 * before starting the scheduler. See the online FreeRTOS.org documentation
\r
81 * for more information on the standard demo tasks.
\r
83 * LEDs D1 to D3 are controlled by the standard 'flash' tasks - each will
\r
84 * toggle at a different fixed frequency.
\r
86 * A tick hook function is used to monitor the standard demo tasks - with LED
\r
87 * D4 being used to indicate the system status. D4 toggling every 5 seconds
\r
88 * indicates that all the standard demo tasks are executing without error. The
\r
89 * toggle rate increasing to 500ms is indicative of an error having been found
\r
90 * in at least one demo task.
\r
92 * See the online documentation page that accompanies this demo for full setup
\r
93 * and usage information.
\r
96 /* Standard includes. */
\r
99 /* Scheduler includes. */
\r
100 #include "FreeRTOS.h"
\r
103 /* Demo application includes. */
\r
104 #include "partest.h"
\r
105 #include "USBSample.h"
\r
106 #include "uIP_Task.h"
\r
107 #include "BlockQ.h"
\r
108 #include "blocktim.h"
\r
111 #include "dynamic.h"
\r
113 /* Priorities for the demo application tasks. */
\r
114 #define mainUIP_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
115 #define mainUSB_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
116 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
117 #define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
118 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
120 /* The task allocated to the uIP task is large to account for its use of the
\r
121 sprintf() library function. Use of a cut down printf() library would allow
\r
122 the stack usage to be greatly reduced. */
\r
123 #define mainUIP_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 6 )
\r
125 /* The LED toggle by the tick hook should an error have been found in a task. */
\r
126 #define mainERROR_LED ( 3 )
\r
128 /*-----------------------------------------------------------*/
\r
131 * Configure the processor for use with the Atmel demo board. Setup is minimal
\r
132 * as the low level init function (called from the startup asm file) takes care
\r
135 static void prvSetupHardware( void );
\r
137 /*-----------------------------------------------------------*/
\r
140 * Starts all the other tasks, then starts the scheduler.
\r
144 /* Setup any hardware that has not already been configured by the low
\r
145 level init routines. */
\r
146 prvSetupHardware();
\r
148 /* Start the task that handles the TCP/IP and WEB server functionality. */
\r
149 xTaskCreate( vuIP_Task, "uIP", mainUIP_TASK_STACK_SIZE, NULL, mainUIP_PRIORITY, NULL );
\r
151 /* Also start the USB demo which is just for the SAM7. */
\r
152 vStartUSBTask( mainUSB_PRIORITY );
\r
154 /* Start the standard demo tasks. */
\r
155 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
156 vCreateBlockTimeTasks();
\r
157 vStartLEDFlashTasks( mainFLASH_PRIORITY );
\r
158 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
159 vStartQueuePeekTasks();
\r
160 vStartDynamicPriorityTasks();
\r
162 /* Start the scheduler.
\r
164 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
165 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
166 called. The demo applications included in the FreeRTOS.org download switch
\r
167 to supervisor mode prior to main being called. If you are not using one of
\r
168 these demo application projects then ensure Supervisor mode is used here. */
\r
170 vTaskStartScheduler();
\r
172 /* We should never get here as control is now taken by the scheduler. */
\r
175 /*-----------------------------------------------------------*/
\r
177 static void prvSetupHardware( void )
\r
179 portDISABLE_INTERRUPTS();
\r
181 /* When using the JTAG debugger the hardware is not always initialised to
\r
182 the correct default state. This line just ensures that this does not
\r
183 cause all interrupts to be masked at the start. */
\r
184 AT91C_BASE_AIC->AIC_EOICR = 0;
\r
186 /* Most setup is performed by the low level init function called from the
\r
187 startup asm file. */
\r
189 /* Enable the peripheral clock. */
\r
190 AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;
\r
191 AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOB;
\r
192 AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_EMAC;
\r
194 /* Initialise the LED outputs for use by the demo application tasks. */
\r
195 vParTestInitialise();
\r
197 /*-----------------------------------------------------------*/
\r
199 void vApplicationTickHook( void )
\r
201 static unsigned long ulCallCount = 0, ulErrorFound = pdFALSE;
\r
203 /* The rate at which LED D4 will toggle if an error has been found in one or
\r
204 more of the standard demo tasks. */
\r
205 const unsigned long ulErrorFlashRate = 500 / portTICK_RATE_MS;
\r
207 /* The rate at which LED D4 will toggle if no errors have been found in any
\r
208 of the standard demo tasks. */
\r
209 const unsigned long ulNoErrorCheckRate = 5000 / portTICK_RATE_MS;
\r
213 if( ulErrorFound != pdFALSE )
\r
215 /* We have already found an error, so flash the LED with the appropriate
\r
217 if( ulCallCount > ulErrorFlashRate )
\r
220 vParTestToggleLED( mainERROR_LED );
\r
225 if( ulCallCount > ulNoErrorCheckRate )
\r
229 /* We have not yet found an error. Check all the demo tasks to ensure
\r
230 this is still the case. */
\r
232 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
234 ulErrorFound |= 0x01;
\r
237 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
239 ulErrorFound |= 0x02;
\r
242 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
244 ulErrorFound |= 0x04;
\r
247 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
249 ulErrorFound |= 0x08;
\r
252 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
254 ulErrorFound |= 0x10;
\r
257 vParTestToggleLED( mainERROR_LED );
\r