2 FreeRTOS V5.4.0 - Copyright (C) 2003-2009 Richard Barry.
\r
4 This file is part of the FreeRTOS distribution.
\r
6 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
7 the terms of the GNU General Public License (version 2) as published by the
\r
8 Free Software Foundation and modified by the FreeRTOS exception.
\r
9 **NOTE** The exception to the GPL is included to allow you to distribute a
\r
10 combined work that includes FreeRTOS without being obliged to provide the
\r
11 source code for proprietary components outside of the FreeRTOS kernel.
\r
12 Alternative commercial license and support terms are also available upon
\r
13 request. See the licensing section of http://www.FreeRTOS.org for full
\r
16 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
21 You should have received a copy of the GNU General Public License along
\r
22 with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
\r
23 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
26 ***************************************************************************
\r
28 * Looking for a quick start? Then check out the FreeRTOS eBook! *
\r
29 * See http://www.FreeRTOS.org/Documentation for details *
\r
31 ***************************************************************************
\r
35 Please ensure to read the configuration and relevant port sections of the
\r
36 online documentation.
\r
38 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
41 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
44 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
45 licensing and training services.
\r
49 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
50 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
51 called. The demo applications included in the FreeRTOS.org download switch
\r
52 to supervisor mode prior to main being called. If you are not using one of
\r
53 these demo application projects then ensure Supervisor mode is used.
\r
58 * Creates all the application tasks, then starts the scheduler.
\r
60 * A task defined by the function vBasicWEBServer is created. This executes
\r
61 * the lwIP stack and basic WEB server sample. A task defined by the function
\r
62 * vUSBCDCTask. This executes the USB to serial CDC example. All the other
\r
63 * tasks are from the set of standard demo tasks. The WEB documentation
\r
64 * provides more details of the standard demo application tasks.
\r
66 * Main.c also creates a task called "Check". This only executes every three
\r
67 * seconds but has the highest priority so is guaranteed to get processor time.
\r
68 * Its main function is to check the status of all the other demo application
\r
69 * tasks. LED mainCHECK_LED is toggled every three seconds by the check task
\r
70 * should no error conditions be detected in any of the standard demo tasks.
\r
71 * The toggle rate increasing to 500ms indicates that at least one error has
\r
74 * Main.c includes an idle hook function that simply periodically sends data
\r
75 * to the USB task for transmission.
\r
81 + Modified the stack sizes used by some tasks to permit use of the
\r
82 command line GCC tools.
\r
85 /* Library includes. */
\r
89 /* Scheduler includes. */
\r
90 #include "FreeRTOS.h"
\r
93 /* Demo application includes. */
\r
94 #include "partest.h"
\r
96 #include "semtest.h"
\r
98 #include "integer.h"
\r
100 #include "BasicWEB.h"
\r
101 #include "USB-CDC.h"
\r
103 /* lwIP includes. */
\r
104 #include "lwip/api.h"
\r
106 /* Hardware specific headers. */
\r
108 #include "AT91SAM7X256.h"
\r
110 /* Priorities/stacks for the various tasks within the demo application. */
\r
111 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
112 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
113 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
114 #define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
115 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
116 #define mainWEBSERVER_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
117 #define mainUSB_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
118 #define mainUSB_TASK_STACK ( 200 )
\r
120 /* The rate at which the on board LED will toggle when there is/is not an
\r
122 #define mainNO_ERROR_FLASH_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
123 #define mainERROR_FLASH_PERIOD ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
125 /* The rate at which the idle hook sends data to the USB port. */
\r
126 #define mainUSB_TX_FREQUENCY ( 100 / portTICK_RATE_MS )
\r
128 /* The string that is transmitted down the USB port. */
\r
129 #define mainFIRST_TX_CHAR 'a'
\r
130 #define mainLAST_TX_CHAR 'z'
\r
132 /* The LED used by the check task to indicate the system status. */
\r
133 #define mainCHECK_LED ( 3 )
\r
134 /*-----------------------------------------------------------*/
\r
137 * Checks that all the demo application tasks are still executing without error
\r
138 * - as described at the top of the file.
\r
140 static portLONG prvCheckOtherTasksAreStillRunning( void );
\r
143 * The task that executes at the highest priority and calls
\r
144 * prvCheckOtherTasksAreStillRunning(). See the description at the top
\r
147 static void vErrorChecks( void *pvParameters );
\r
150 * Configure the processor for use with the Atmel demo board. This is very
\r
151 * minimal as most of the setup is performed in the startup code.
\r
153 static void prvSetupHardware( void );
\r
156 * The idle hook is just used to stream data to the USB port.
\r
158 void vApplicationIdleHook( void );
\r
159 /*-----------------------------------------------------------*/
\r
162 * Setup hardware then start all the demo application tasks.
\r
166 /* Setup the ports. */
\r
167 prvSetupHardware();
\r
169 /* Setup the IO required for the LED's. */
\r
170 vParTestInitialise();
\r
175 /* Create the lwIP task. This uses the lwIP RTOS abstraction layer.*/
\r
176 sys_thread_new( vBasicWEBServer, ( void * ) NULL, mainWEBSERVER_PRIORITY );
\r
178 /* Create the demo USB CDC task. */
\r
179 xTaskCreate( vUSBCDCTask, ( signed portCHAR * ) "USB", mainUSB_TASK_STACK, NULL, mainUSB_PRIORITY, NULL );
\r
181 /* Create the standard demo application tasks. */
\r
182 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
183 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
184 vStartLEDFlashTasks( mainFLASH_PRIORITY );
\r
185 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
186 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
188 /* Start the check task - which is defined in this file. */
\r
189 xTaskCreate( vErrorChecks, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
191 /* Finally, start the scheduler.
\r
193 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
194 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
195 called. The demo applications included in the FreeRTOS.org download switch
\r
196 to supervisor mode prior to main being called. If you are not using one of
\r
197 these demo application projects then ensure Supervisor mode is used here. */
\r
198 vTaskStartScheduler();
\r
200 /* Should never get here! */
\r
203 /*-----------------------------------------------------------*/
\r
206 static void prvSetupHardware( void )
\r
208 /* When using the JTAG debugger the hardware is not always initialised to
\r
209 the correct default state. This line just ensures that this does not
\r
210 cause all interrupts to be masked at the start. */
\r
211 AT91C_BASE_AIC->AIC_EOICR = 0;
\r
213 /* Most setup is performed by the low level init function called from the
\r
216 Configure the PIO Lines corresponding to LED1 to LED4 to be outputs as
\r
217 well as the UART Tx line. */
\r
218 AT91C_BASE_PIOB->PIO_PER = LED_MASK; // Set in PIO mode
\r
219 AT91C_BASE_PIOB->PIO_OER = LED_MASK; // Configure in Output
\r
222 /* Enable the peripheral clock. */
\r
223 AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;
\r
224 AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOB;
\r
225 AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_EMAC;
\r
227 /*-----------------------------------------------------------*/
\r
229 static void vErrorChecks( void *pvParameters )
\r
231 portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
\r
232 portTickType xLastWakeTime;
\r
234 /* The parameters are not used. */
\r
235 ( void ) pvParameters;
\r
237 /* Initialise xLastWakeTime to ensure the first call to vTaskDelayUntil()
\r
238 functions correctly. */
\r
239 xLastWakeTime = xTaskGetTickCount();
\r
241 /* Cycle for ever, delaying then checking all the other tasks are still
\r
242 operating without error. If an error is detected then the delay period
\r
243 is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
\r
244 the Check LED flash rate will increase. */
\r
247 /* Delay until it is time to execute again. The delay period is
\r
248 shorter following an error. */
\r
249 vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );
\r
251 /* Check all the standard demo application tasks are executing without
\r
253 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
255 /* An error has been detected in one of the tasks - flash faster. */
\r
256 xDelayPeriod = mainERROR_FLASH_PERIOD;
\r
259 vParTestToggleLED( mainCHECK_LED );
\r
262 /*-----------------------------------------------------------*/
\r
264 static portLONG prvCheckOtherTasksAreStillRunning( void )
\r
266 portLONG lReturn = ( portLONG ) pdPASS;
\r
268 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
269 that they are all still running, and that none of them have detected
\r
272 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
274 lReturn = ( portLONG ) pdFAIL;
\r
277 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
279 lReturn = ( portLONG ) pdFAIL;
\r
282 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
284 lReturn = ( portLONG ) pdFAIL;
\r
287 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
289 lReturn = ( portLONG ) pdFAIL;
\r
294 /*-----------------------------------------------------------*/
\r
296 void vApplicationIdleHook( void )
\r
298 static portTickType xLastTx = 0;
\r
301 /* The idle hook simply sends a string of characters to the USB port.
\r
302 The characters will be buffered and sent once the port is connected. */
\r
303 if( ( xTaskGetTickCount() - xLastTx ) > mainUSB_TX_FREQUENCY )
\r
305 xLastTx = xTaskGetTickCount();
\r
306 for( cTxByte = mainFIRST_TX_CHAR; cTxByte <= mainLAST_TX_CHAR; cTxByte++ )
\r
308 vUSBSendByte( cTxByte );
\r