2 FreeRTOS V7.5.3 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
28 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
29 >>! the source code for proprietary components outside of the FreeRTOS
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
67 NOTE : Tasks run in System mode and the scheduler runs in Supervisor mode.
\r
68 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
69 called. The demo applications included in the FreeRTOS.org download switch
\r
70 to supervisor mode prior to main being called. If you are not using one of
\r
71 these demo application projects then ensure Supervisor mode is used.
\r
75 * This demo includes a (basic) USB mouse driver and a WEB server. It is
\r
76 * targeted for the AT91SAM7X EK prototyping board which includes a small
\r
77 * joystick to provide the mouse inputs. The WEB interface provides some basic
\r
78 * interactivity through the use of a check box to turn on and off an LED.
\r
80 * main() creates the WEB server, USB, and a set of the standard demo tasks
\r
81 * before starting the scheduler. See the online FreeRTOS.org documentation
\r
82 * for more information on the standard demo tasks.
\r
84 * LEDs D1 to D3 are controlled by the standard 'flash' tasks - each will
\r
85 * toggle at a different fixed frequency.
\r
87 * A tick hook function is used to monitor the standard demo tasks - with LED
\r
88 * D4 being used to indicate the system status. D4 toggling every 5 seconds
\r
89 * indicates that all the standard demo tasks are executing without error. The
\r
90 * toggle rate increasing to 500ms is indicative of an error having been found
\r
91 * in at least one demo task.
\r
93 * See the online documentation page that accompanies this demo for full setup
\r
94 * and usage information.
\r
97 /* Standard includes. */
\r
100 /* Scheduler includes. */
\r
101 #include "FreeRTOS.h"
\r
104 /* Demo application includes. */
\r
105 #include "partest.h"
\r
106 #include "USBSample.h"
\r
107 #include "uIP_Task.h"
\r
108 #include "BlockQ.h"
\r
109 #include "blocktim.h"
\r
112 #include "dynamic.h"
\r
114 /* Priorities for the demo application tasks. */
\r
115 #define mainUIP_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
116 #define mainUSB_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
117 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
118 #define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
119 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
121 /* The task allocated to the uIP task is large to account for its use of the
\r
122 sprintf() library function. Use of a cut down printf() library would allow
\r
123 the stack usage to be greatly reduced. */
\r
124 #define mainUIP_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 6 )
\r
126 /* The LED toggle by the tick hook should an error have been found in a task. */
\r
127 #define mainERROR_LED ( 3 )
\r
129 /*-----------------------------------------------------------*/
\r
132 * Configure the processor for use with the Atmel demo board. Setup is minimal
\r
133 * as the low level init function (called from the startup asm file) takes care
\r
136 static void prvSetupHardware( void );
\r
138 /*-----------------------------------------------------------*/
\r
141 * Starts all the other tasks, then starts the scheduler.
\r
145 /* Setup any hardware that has not already been configured by the low
\r
146 level init routines. */
\r
147 prvSetupHardware();
\r
149 /* Start the task that handles the TCP/IP and WEB server functionality. */
\r
150 xTaskCreate( vuIP_Task, "uIP", mainUIP_TASK_STACK_SIZE, NULL, mainUIP_PRIORITY, NULL );
\r
152 /* Also start the USB demo which is just for the SAM7. */
\r
153 vStartUSBTask( mainUSB_PRIORITY );
\r
155 /* Start the standard demo tasks. */
\r
156 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
157 vCreateBlockTimeTasks();
\r
158 vStartLEDFlashTasks( mainFLASH_PRIORITY );
\r
159 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
160 vStartQueuePeekTasks();
\r
161 vStartDynamicPriorityTasks();
\r
163 /* Start the scheduler.
\r
165 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
166 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
167 called. The demo applications included in the FreeRTOS.org download switch
\r
168 to supervisor mode prior to main being called. If you are not using one of
\r
169 these demo application projects then ensure Supervisor mode is used here. */
\r
171 vTaskStartScheduler();
\r
173 /* We should never get here as control is now taken by the scheduler. */
\r
176 /*-----------------------------------------------------------*/
\r
178 static void prvSetupHardware( void )
\r
180 portDISABLE_INTERRUPTS();
\r
182 /* When using the JTAG debugger the hardware is not always initialised to
\r
183 the correct default state. This line just ensures that this does not
\r
184 cause all interrupts to be masked at the start. */
\r
185 AT91C_BASE_AIC->AIC_EOICR = 0;
\r
187 /* Most setup is performed by the low level init function called from the
\r
188 startup asm file. */
\r
190 /* Enable the peripheral clock. */
\r
191 AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;
\r
192 AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOB;
\r
193 AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_EMAC;
\r
195 /* Initialise the LED outputs for use by the demo application tasks. */
\r
196 vParTestInitialise();
\r
198 /*-----------------------------------------------------------*/
\r
200 void vApplicationTickHook( void )
\r
202 static unsigned long ulCallCount = 0, ulErrorFound = pdFALSE;
\r
204 /* The rate at which LED D4 will toggle if an error has been found in one or
\r
205 more of the standard demo tasks. */
\r
206 const unsigned long ulErrorFlashRate = 500 / portTICK_RATE_MS;
\r
208 /* The rate at which LED D4 will toggle if no errors have been found in any
\r
209 of the standard demo tasks. */
\r
210 const unsigned long ulNoErrorCheckRate = 5000 / portTICK_RATE_MS;
\r
214 if( ulErrorFound != pdFALSE )
\r
216 /* We have already found an error, so flash the LED with the appropriate
\r
218 if( ulCallCount > ulErrorFlashRate )
\r
221 vParTestToggleLED( mainERROR_LED );
\r
226 if( ulCallCount > ulNoErrorCheckRate )
\r
230 /* We have not yet found an error. Check all the demo tasks to ensure
\r
231 this is still the case. */
\r
233 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
235 ulErrorFound |= 0x01;
\r
238 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
240 ulErrorFound |= 0x02;
\r
243 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
245 ulErrorFound |= 0x04;
\r
248 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
250 ulErrorFound |= 0x08;
\r
253 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
255 ulErrorFound |= 0x10;
\r
258 vParTestToggleLED( mainERROR_LED );
\r