2 FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
7 This file is part of the FreeRTOS distribution.
9 FreeRTOS is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License (version 2) as published by the
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
13 ***************************************************************************
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
15 >>! distribute a combined work that includes FreeRTOS without being !<<
16 >>! obliged to provide the source code for proprietary components !<<
17 >>! outside of the FreeRTOS kernel. !<<
18 ***************************************************************************
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
23 link: http://www.freertos.org/a00114.html
25 ***************************************************************************
27 * FreeRTOS provides completely free yet professionally developed, *
28 * robust, strictly quality controlled, supported, and cross *
29 * platform software that is more than just the market leader, it *
30 * is the industry's de facto standard. *
32 * Help yourself get started quickly while simultaneously helping *
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
34 * tutorial book, reference manual, or both: *
35 * http://www.FreeRTOS.org/Documentation *
37 ***************************************************************************
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
40 the FAQ page "My application does not run, what could be wrong?". Have you
41 defined configASSERT()?
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
44 embedded software for free we request you assist our global community by
45 participating in the support forum.
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
48 be as productive as possible as early as possible. Now you can receive
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50 Ltd, and the world's leading authority on the world's leading RTOS.
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
61 licenses offer ticketed support, indemnification and commercial middleware.
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64 engineered and independently SIL3 certified version for use in safety and
65 mission critical applications that require provable dependability.
71 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
72 The processor MUST be in supervisor mode when vTaskStartScheduler is
73 called. The demo applications included in the FreeRTOS.org download switch
74 to supervisor mode prior to main being called. If you are not using one of
75 these demo application projects then ensure Supervisor mode is used.
80 * Creates all the application tasks, then starts the scheduler.
82 * A task defined by the function vBasicWEBServer is created. This executes
83 * the lwIP stack and basic WEB server sample. A task defined by the function
84 * vUSBCDCTask. This executes the USB to serial CDC example. All the other
85 * tasks are from the set of standard demo tasks. The WEB documentation
86 * provides more details of the standard demo application tasks.
88 * Main.c also creates a task called "Check". This only executes every three
89 * seconds but has the highest priority so is guaranteed to get processor time.
90 * Its main function is to check the status of all the other demo application
91 * tasks. LED mainCHECK_LED is toggled every three seconds by the check task
92 * should no error conditions be detected in any of the standard demo tasks.
93 * The toggle rate increasing to 500ms indicates that at least one error has
96 * Main.c includes an idle hook function that simply periodically sends data
97 * to the USB task for transmission.
103 + Modified the stack sizes used by some tasks to permit use of the
104 command line GCC tools.
107 /* Library includes. */
111 /* Scheduler includes. */
112 #include "FreeRTOS.h"
115 /* Demo application includes. */
122 #include "BasicWEB.h"
126 #include "lwip/api.h"
128 /* Hardware specific headers. */
130 #include "AT91SAM7X256.h"
132 /* Priorities/stacks for the various tasks within the demo application. */
133 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 )
134 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
135 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
136 #define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 2 )
137 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 1 )
138 #define mainWEBSERVER_PRIORITY ( tskIDLE_PRIORITY + 2 )
139 #define mainUSB_PRIORITY ( tskIDLE_PRIORITY + 1 )
140 #define mainUSB_TASK_STACK ( 200 )
142 /* The rate at which the on board LED will toggle when there is/is not an
144 #define mainNO_ERROR_FLASH_PERIOD ( ( TickType_t ) 3000 / portTICK_PERIOD_MS )
145 #define mainERROR_FLASH_PERIOD ( ( TickType_t ) 500 / portTICK_PERIOD_MS )
147 /* The rate at which the idle hook sends data to the USB port. */
148 #define mainUSB_TX_FREQUENCY ( 100 / portTICK_PERIOD_MS )
150 /* The string that is transmitted down the USB port. */
151 #define mainFIRST_TX_CHAR 'a'
152 #define mainLAST_TX_CHAR 'z'
154 /* The LED used by the check task to indicate the system status. */
155 #define mainCHECK_LED ( 3 )
156 /*-----------------------------------------------------------*/
159 * Checks that all the demo application tasks are still executing without error
160 * - as described at the top of the file.
162 static long prvCheckOtherTasksAreStillRunning( void );
165 * The task that executes at the highest priority and calls
166 * prvCheckOtherTasksAreStillRunning(). See the description at the top
169 static void vErrorChecks( void *pvParameters );
172 * Configure the processor for use with the Atmel demo board. This is very
173 * minimal as most of the setup is performed in the startup code.
175 static void prvSetupHardware( void );
178 * The idle hook is just used to stream data to the USB port.
180 void vApplicationIdleHook( void );
181 /*-----------------------------------------------------------*/
184 * Setup hardware then start all the demo application tasks.
188 /* Setup the ports. */
191 /* Setup the IO required for the LED's. */
192 vParTestInitialise();
197 /* Create the lwIP task. This uses the lwIP RTOS abstraction layer.*/
198 sys_thread_new( vBasicWEBServer, ( void * ) NULL, mainWEBSERVER_PRIORITY );
200 /* Create the demo USB CDC task. */
201 xTaskCreate( vUSBCDCTask, "USB", mainUSB_TASK_STACK, NULL, mainUSB_PRIORITY, NULL );
203 /* Create the standard demo application tasks. */
204 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
205 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
206 vStartLEDFlashTasks( mainFLASH_PRIORITY );
207 vStartIntegerMathTasks( tskIDLE_PRIORITY );
208 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
210 /* Start the check task - which is defined in this file. */
211 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
213 /* Finally, start the scheduler.
215 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
216 The processor MUST be in supervisor mode when vTaskStartScheduler is
217 called. The demo applications included in the FreeRTOS.org download switch
218 to supervisor mode prior to main being called. If you are not using one of
219 these demo application projects then ensure Supervisor mode is used here. */
220 vTaskStartScheduler();
222 /* Should never get here! */
225 /*-----------------------------------------------------------*/
228 static void prvSetupHardware( void )
230 /* When using the JTAG debugger the hardware is not always initialised to
231 the correct default state. This line just ensures that this does not
232 cause all interrupts to be masked at the start. */
233 AT91C_BASE_AIC->AIC_EOICR = 0;
235 /* Most setup is performed by the low level init function called from the
238 Configure the PIO Lines corresponding to LED1 to LED4 to be outputs as
239 well as the UART Tx line. */
240 AT91C_BASE_PIOB->PIO_PER = LED_MASK; // Set in PIO mode
241 AT91C_BASE_PIOB->PIO_OER = LED_MASK; // Configure in Output
244 /* Enable the peripheral clock. */
245 AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;
246 AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOB;
247 AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_EMAC;
249 /*-----------------------------------------------------------*/
251 static void vErrorChecks( void *pvParameters )
253 TickType_t xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
254 TickType_t xLastWakeTime;
256 /* The parameters are not used. */
257 ( void ) pvParameters;
259 /* Initialise xLastWakeTime to ensure the first call to vTaskDelayUntil()
260 functions correctly. */
261 xLastWakeTime = xTaskGetTickCount();
263 /* Cycle for ever, delaying then checking all the other tasks are still
264 operating without error. If an error is detected then the delay period
265 is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
266 the Check LED flash rate will increase. */
269 /* Delay until it is time to execute again. The delay period is
270 shorter following an error. */
271 vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );
273 /* Check all the standard demo application tasks are executing without
275 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
277 /* An error has been detected in one of the tasks - flash faster. */
278 xDelayPeriod = mainERROR_FLASH_PERIOD;
281 vParTestToggleLED( mainCHECK_LED );
284 /*-----------------------------------------------------------*/
286 static long prvCheckOtherTasksAreStillRunning( void )
288 long lReturn = ( long ) pdPASS;
290 /* Check all the demo tasks (other than the flash tasks) to ensure
291 that they are all still running, and that none of them have detected
294 if( xArePollingQueuesStillRunning() != pdTRUE )
296 lReturn = ( long ) pdFAIL;
299 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
301 lReturn = ( long ) pdFAIL;
304 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
306 lReturn = ( long ) pdFAIL;
309 if( xAreBlockingQueuesStillRunning() != pdTRUE )
311 lReturn = ( long ) pdFAIL;
316 /*-----------------------------------------------------------*/
318 void vApplicationIdleHook( void )
320 static TickType_t xLastTx = 0;
323 /* The idle hook simply sends a string of characters to the USB port.
324 The characters will be buffered and sent once the port is connected. */
325 if( ( xTaskGetTickCount() - xLastTx ) > mainUSB_TX_FREQUENCY )
327 xLastTx = xTaskGetTickCount();
328 for( cTxByte = mainFIRST_TX_CHAR; cTxByte <= mainLAST_TX_CHAR; cTxByte++ )
330 vUSBSendByte( cTxByte );