2 FreeRTOS V7.1.1 - 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
77 * Creates all the application tasks, then starts the scheduler.
\r
79 * A task defined by the function vBasicWEBServer is created. This executes
\r
80 * the lwIP stack and basic WEB server sample. A task defined by the function
\r
81 * vUSBCDCTask. This executes the USB to serial CDC example. All the other
\r
82 * tasks are from the set of standard demo tasks. The WEB documentation
\r
83 * provides more details of the standard demo application tasks.
\r
85 * Main.c also creates a task called "Check". This only executes every three
\r
86 * seconds but has the highest priority so is guaranteed to get processor time.
\r
87 * Its main function is to check the status of all the other demo application
\r
88 * tasks. LED mainCHECK_LED is toggled every three seconds by the check task
\r
89 * should no error conditions be detected in any of the standard demo tasks.
\r
90 * The toggle rate increasing to 500ms indicates that at least one error has
\r
93 * Main.c includes an idle hook function that simply periodically sends data
\r
94 * to the USB task for transmission.
\r
100 + Modified the stack sizes used by some tasks to permit use of the
\r
101 command line GCC tools.
\r
104 /* Library includes. */
\r
105 #include <string.h>
\r
108 /* Scheduler includes. */
\r
109 #include "FreeRTOS.h"
\r
112 /* Demo application includes. */
\r
113 #include "partest.h"
\r
115 #include "semtest.h"
\r
117 #include "integer.h"
\r
118 #include "BlockQ.h"
\r
119 #include "BasicWEB.h"
\r
120 #include "USB-CDC.h"
\r
122 /* lwIP includes. */
\r
123 #include "lwip/api.h"
\r
125 /* Hardware specific headers. */
\r
127 #include "AT91SAM7X256.h"
\r
129 /* Priorities/stacks for the various tasks within the demo application. */
\r
130 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
131 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
132 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
133 #define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
134 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
135 #define mainWEBSERVER_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
136 #define mainUSB_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
137 #define mainUSB_TASK_STACK ( 200 )
\r
139 /* The rate at which the on board LED will toggle when there is/is not an
\r
141 #define mainNO_ERROR_FLASH_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
142 #define mainERROR_FLASH_PERIOD ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
144 /* The rate at which the idle hook sends data to the USB port. */
\r
145 #define mainUSB_TX_FREQUENCY ( 100 / portTICK_RATE_MS )
\r
147 /* The string that is transmitted down the USB port. */
\r
148 #define mainFIRST_TX_CHAR 'a'
\r
149 #define mainLAST_TX_CHAR 'z'
\r
151 /* The LED used by the check task to indicate the system status. */
\r
152 #define mainCHECK_LED ( 3 )
\r
153 /*-----------------------------------------------------------*/
\r
156 * Checks that all the demo application tasks are still executing without error
\r
157 * - as described at the top of the file.
\r
159 static long prvCheckOtherTasksAreStillRunning( void );
\r
162 * The task that executes at the highest priority and calls
\r
163 * prvCheckOtherTasksAreStillRunning(). See the description at the top
\r
166 static void vErrorChecks( void *pvParameters );
\r
169 * Configure the processor for use with the Atmel demo board. This is very
\r
170 * minimal as most of the setup is performed in the startup code.
\r
172 static void prvSetupHardware( void );
\r
175 * The idle hook is just used to stream data to the USB port.
\r
177 void vApplicationIdleHook( void );
\r
178 /*-----------------------------------------------------------*/
\r
181 * Setup hardware then start all the demo application tasks.
\r
185 /* Setup the ports. */
\r
186 prvSetupHardware();
\r
188 /* Setup the IO required for the LED's. */
\r
189 vParTestInitialise();
\r
194 /* Create the lwIP task. This uses the lwIP RTOS abstraction layer.*/
\r
195 sys_thread_new( vBasicWEBServer, ( void * ) NULL, mainWEBSERVER_PRIORITY );
\r
197 /* Create the demo USB CDC task. */
\r
198 xTaskCreate( vUSBCDCTask, ( signed char * ) "USB", mainUSB_TASK_STACK, NULL, mainUSB_PRIORITY, NULL );
\r
200 /* Create the standard demo application tasks. */
\r
201 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
202 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
203 vStartLEDFlashTasks( mainFLASH_PRIORITY );
\r
204 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
205 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
207 /* Start the check task - which is defined in this file. */
\r
208 xTaskCreate( vErrorChecks, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
210 /* Finally, start the scheduler.
\r
212 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
213 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
214 called. The demo applications included in the FreeRTOS.org download switch
\r
215 to supervisor mode prior to main being called. If you are not using one of
\r
216 these demo application projects then ensure Supervisor mode is used here. */
\r
217 vTaskStartScheduler();
\r
219 /* Should never get here! */
\r
222 /*-----------------------------------------------------------*/
\r
225 static void prvSetupHardware( void )
\r
227 /* When using the JTAG debugger the hardware is not always initialised to
\r
228 the correct default state. This line just ensures that this does not
\r
229 cause all interrupts to be masked at the start. */
\r
230 AT91C_BASE_AIC->AIC_EOICR = 0;
\r
232 /* Most setup is performed by the low level init function called from the
\r
235 Configure the PIO Lines corresponding to LED1 to LED4 to be outputs as
\r
236 well as the UART Tx line. */
\r
237 AT91C_BASE_PIOB->PIO_PER = LED_MASK; // Set in PIO mode
\r
238 AT91C_BASE_PIOB->PIO_OER = LED_MASK; // Configure in Output
\r
241 /* Enable the peripheral clock. */
\r
242 AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;
\r
243 AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOB;
\r
244 AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_EMAC;
\r
246 /*-----------------------------------------------------------*/
\r
248 static void vErrorChecks( void *pvParameters )
\r
250 portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
\r
251 portTickType xLastWakeTime;
\r
253 /* The parameters are not used. */
\r
254 ( void ) pvParameters;
\r
256 /* Initialise xLastWakeTime to ensure the first call to vTaskDelayUntil()
\r
257 functions correctly. */
\r
258 xLastWakeTime = xTaskGetTickCount();
\r
260 /* Cycle for ever, delaying then checking all the other tasks are still
\r
261 operating without error. If an error is detected then the delay period
\r
262 is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
\r
263 the Check LED flash rate will increase. */
\r
266 /* Delay until it is time to execute again. The delay period is
\r
267 shorter following an error. */
\r
268 vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );
\r
270 /* Check all the standard demo application tasks are executing without
\r
272 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
274 /* An error has been detected in one of the tasks - flash faster. */
\r
275 xDelayPeriod = mainERROR_FLASH_PERIOD;
\r
278 vParTestToggleLED( mainCHECK_LED );
\r
281 /*-----------------------------------------------------------*/
\r
283 static long prvCheckOtherTasksAreStillRunning( void )
\r
285 long lReturn = ( long ) pdPASS;
\r
287 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
288 that they are all still running, and that none of them have detected
\r
291 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
293 lReturn = ( long ) pdFAIL;
\r
296 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
298 lReturn = ( long ) pdFAIL;
\r
301 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
303 lReturn = ( long ) pdFAIL;
\r
306 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
308 lReturn = ( long ) pdFAIL;
\r
313 /*-----------------------------------------------------------*/
\r
315 void vApplicationIdleHook( void )
\r
317 static portTickType xLastTx = 0;
\r
320 /* The idle hook simply sends a string of characters to the USB port.
\r
321 The characters will be buffered and sent once the port is connected. */
\r
322 if( ( xTaskGetTickCount() - xLastTx ) > mainUSB_TX_FREQUENCY )
\r
324 xLastTx = xTaskGetTickCount();
\r
325 for( cTxByte = mainFIRST_TX_CHAR; cTxByte <= mainLAST_TX_CHAR; cTxByte++ )
\r
327 vUSBSendByte( cTxByte );
\r