| 1 |
583 |
jeremybenn |
/*
|
| 2 |
|
|
FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd.
|
| 3 |
|
|
|
| 4 |
|
|
***************************************************************************
|
| 5 |
|
|
* *
|
| 6 |
|
|
* If you are: *
|
| 7 |
|
|
* *
|
| 8 |
|
|
* + New to FreeRTOS, *
|
| 9 |
|
|
* + Wanting to learn FreeRTOS or multitasking in general quickly *
|
| 10 |
|
|
* + Looking for basic training, *
|
| 11 |
|
|
* + Wanting to improve your FreeRTOS skills and productivity *
|
| 12 |
|
|
* *
|
| 13 |
|
|
* then take a look at the FreeRTOS books - available as PDF or paperback *
|
| 14 |
|
|
* *
|
| 15 |
|
|
* "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
|
| 16 |
|
|
* http://www.FreeRTOS.org/Documentation *
|
| 17 |
|
|
* *
|
| 18 |
|
|
* A pdf reference manual is also available. Both are usually delivered *
|
| 19 |
|
|
* to your inbox within 20 minutes to two hours when purchased between 8am *
|
| 20 |
|
|
* and 8pm GMT (although please allow up to 24 hours in case of *
|
| 21 |
|
|
* exceptional circumstances). Thank you for your support! *
|
| 22 |
|
|
* *
|
| 23 |
|
|
***************************************************************************
|
| 24 |
|
|
|
| 25 |
|
|
This file is part of the FreeRTOS distribution.
|
| 26 |
|
|
|
| 27 |
|
|
FreeRTOS is free software; you can redistribute it and/or modify it under
|
| 28 |
|
|
the terms of the GNU General Public License (version 2) as published by the
|
| 29 |
|
|
Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
|
| 30 |
|
|
***NOTE*** The exception to the GPL is included to allow you to distribute
|
| 31 |
|
|
a combined work that includes FreeRTOS without being obliged to provide the
|
| 32 |
|
|
source code for proprietary components outside of the FreeRTOS kernel.
|
| 33 |
|
|
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
|
| 34 |
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
| 35 |
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
| 36 |
|
|
more details. You should have received a copy of the GNU General Public
|
| 37 |
|
|
License and the FreeRTOS license exception along with FreeRTOS; if not it
|
| 38 |
|
|
can be viewed here: http://www.freertos.org/a00114.html and also obtained
|
| 39 |
|
|
by writing to Richard Barry, contact details for whom are available on the
|
| 40 |
|
|
FreeRTOS WEB site.
|
| 41 |
|
|
|
| 42 |
|
|
1 tab == 4 spaces!
|
| 43 |
|
|
|
| 44 |
|
|
http://www.FreeRTOS.org - Documentation, latest information, license and
|
| 45 |
|
|
contact details.
|
| 46 |
|
|
|
| 47 |
|
|
http://www.SafeRTOS.com - A version that is certified for use in safety
|
| 48 |
|
|
critical systems.
|
| 49 |
|
|
|
| 50 |
|
|
http://www.OpenRTOS.com - Commercial support, development, porting,
|
| 51 |
|
|
licensing and training services.
|
| 52 |
|
|
*/
|
| 53 |
|
|
|
| 54 |
|
|
/*
|
| 55 |
|
|
* Creates all the application tasks, then starts the scheduler.
|
| 56 |
|
|
*
|
| 57 |
|
|
* A task is also created called "uIP". This executes the uIP stack and small
|
| 58 |
|
|
* WEB server sample. All the other tasks are from the set of standard
|
| 59 |
|
|
* demo tasks. The WEB documentation provides more details of the standard
|
| 60 |
|
|
* demo application tasks.
|
| 61 |
|
|
*
|
| 62 |
|
|
* Main.c also creates a task called "Check". This only executes every three
|
| 63 |
|
|
* seconds but has the highest priority so is guaranteed to get processor time.
|
| 64 |
|
|
* Its main function is to check the status of all the other demo application
|
| 65 |
|
|
* tasks. LED mainCHECK_LED is toggled every three seconds by the check task
|
| 66 |
|
|
* should no error conditions be detected in any of the standard demo tasks.
|
| 67 |
|
|
* The toggle rate increasing to 500ms indicates that at least one error has
|
| 68 |
|
|
* been detected.
|
| 69 |
|
|
*/
|
| 70 |
|
|
|
| 71 |
|
|
|
| 72 |
|
|
/* Standard includes. */
|
| 73 |
|
|
#include <stdlib.h>
|
| 74 |
|
|
#include <string.h>
|
| 75 |
|
|
|
| 76 |
|
|
/* Scheduler includes. */
|
| 77 |
|
|
#include "FreeRTOS.h"
|
| 78 |
|
|
#include "task.h"
|
| 79 |
|
|
|
| 80 |
|
|
/* Demo application includes. */
|
| 81 |
|
|
#include "partest.h"
|
| 82 |
|
|
#include "PollQ.h"
|
| 83 |
|
|
#include "dynamic.h"
|
| 84 |
|
|
#include "semtest.h"
|
| 85 |
|
|
#include "flash.h"
|
| 86 |
|
|
#include "integer.h"
|
| 87 |
|
|
#include "flop.h"
|
| 88 |
|
|
#include "BlockQ.h"
|
| 89 |
|
|
#include "death.h"
|
| 90 |
|
|
#include "uip_task.h"
|
| 91 |
|
|
|
| 92 |
|
|
/*-----------------------------------------------------------*/
|
| 93 |
|
|
|
| 94 |
|
|
/* Priorities/stacks for the demo application tasks. */
|
| 95 |
|
|
#define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 )
|
| 96 |
|
|
#define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
|
| 97 |
|
|
#define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
|
| 98 |
|
|
#define mainUIP_PRIORITY ( tskIDLE_PRIORITY + 3 )
|
| 99 |
|
|
#define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 2 )
|
| 100 |
|
|
#define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 1 )
|
| 101 |
|
|
#define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 2 )
|
| 102 |
|
|
#define mainUIP_TASK_STACK_SIZE ( 250 )
|
| 103 |
|
|
|
| 104 |
|
|
/* The rate at which the on board LED will toggle when there is/is not an
|
| 105 |
|
|
error. */
|
| 106 |
|
|
#define mainNO_ERROR_FLASH_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
|
| 107 |
|
|
#define mainERROR_FLASH_PERIOD ( ( portTickType ) 500 / portTICK_RATE_MS )
|
| 108 |
|
|
|
| 109 |
|
|
/* The LED used by the check task to indicate the system status. */
|
| 110 |
|
|
#define mainCHECK_LED ( 3 )
|
| 111 |
|
|
/*-----------------------------------------------------------*/
|
| 112 |
|
|
|
| 113 |
|
|
/*
|
| 114 |
|
|
* Checks that all the demo application tasks are still executing without error
|
| 115 |
|
|
* - as described at the top of the file.
|
| 116 |
|
|
*/
|
| 117 |
|
|
static long prvCheckOtherTasksAreStillRunning( void );
|
| 118 |
|
|
|
| 119 |
|
|
/*
|
| 120 |
|
|
* The task that executes at the highest priority and calls
|
| 121 |
|
|
* prvCheckOtherTasksAreStillRunning(). See the description at the top
|
| 122 |
|
|
* of the file.
|
| 123 |
|
|
*/
|
| 124 |
|
|
static void vErrorChecks( void *pvParameters );
|
| 125 |
|
|
|
| 126 |
|
|
/*
|
| 127 |
|
|
* Configure the processor for use with the Atmel demo board. This is very
|
| 128 |
|
|
* minimal as most of the setup is performed in the startup code.
|
| 129 |
|
|
*/
|
| 130 |
|
|
static void prvSetupHardware( void );
|
| 131 |
|
|
|
| 132 |
|
|
/*-----------------------------------------------------------*/
|
| 133 |
|
|
|
| 134 |
|
|
/*
|
| 135 |
|
|
* Starts all the other tasks, then starts the scheduler.
|
| 136 |
|
|
*/
|
| 137 |
|
|
int main( void )
|
| 138 |
|
|
{
|
| 139 |
|
|
/* Configure the processor. */
|
| 140 |
|
|
prvSetupHardware();
|
| 141 |
|
|
|
| 142 |
|
|
/* Setup the port used to flash the LED's. */
|
| 143 |
|
|
vParTestInitialise();
|
| 144 |
|
|
|
| 145 |
|
|
/* Start the task that handles the TCP/IP and WEB server functionality. */
|
| 146 |
|
|
xTaskCreate( vuIP_TASK, "uIP", mainUIP_TASK_STACK_SIZE, NULL, mainUIP_PRIORITY, NULL );
|
| 147 |
|
|
|
| 148 |
|
|
/* Start the demo/test application tasks. These are created in addition
|
| 149 |
|
|
to the TCP/IP task for demonstration and test purposes. */
|
| 150 |
|
|
vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
|
| 151 |
|
|
vStartDynamicPriorityTasks();
|
| 152 |
|
|
vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
|
| 153 |
|
|
vStartLEDFlashTasks( mainFLASH_PRIORITY );
|
| 154 |
|
|
vStartIntegerMathTasks( tskIDLE_PRIORITY );
|
| 155 |
|
|
vStartMathTasks( tskIDLE_PRIORITY );
|
| 156 |
|
|
vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
|
| 157 |
|
|
|
| 158 |
|
|
/* Start the check task - which is defined in this file. */
|
| 159 |
|
|
xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
|
| 160 |
|
|
|
| 161 |
|
|
/* Must be last to get created. */
|
| 162 |
|
|
vCreateSuicidalTasks( mainDEATH_PRIORITY );
|
| 163 |
|
|
|
| 164 |
|
|
/* Now all the tasks have been started - start the scheduler. */
|
| 165 |
|
|
vTaskStartScheduler();
|
| 166 |
|
|
|
| 167 |
|
|
/* Should never reach here because the tasks should now be executing! */
|
| 168 |
|
|
return 0;
|
| 169 |
|
|
}
|
| 170 |
|
|
/*-----------------------------------------------------------*/
|
| 171 |
|
|
|
| 172 |
|
|
static void prvSetupHardware( void )
|
| 173 |
|
|
{
|
| 174 |
|
|
/* When using the JTAG debugger the hardware is not always initialised to
|
| 175 |
|
|
the correct default state. This line just ensures that this does not
|
| 176 |
|
|
cause all interrupts to be masked at the start. */
|
| 177 |
|
|
AT91C_BASE_AIC->AIC_EOICR = 0;
|
| 178 |
|
|
|
| 179 |
|
|
/* Most setup is performed by the low level init function called from the
|
| 180 |
|
|
startup asm file.
|
| 181 |
|
|
|
| 182 |
|
|
Configure the PIO Lines corresponding to LED1 to LED4 to be outputs as
|
| 183 |
|
|
well as the UART Tx line. */
|
| 184 |
|
|
AT91F_PIO_CfgOutput( AT91C_BASE_PIOB, LED_MASK );
|
| 185 |
|
|
|
| 186 |
|
|
/* Enable the peripheral clock. */
|
| 187 |
|
|
AT91F_PMC_EnablePeriphClock( AT91C_BASE_PMC, 1 << AT91C_ID_PIOA );
|
| 188 |
|
|
AT91F_PMC_EnablePeriphClock( AT91C_BASE_PMC, 1 << AT91C_ID_PIOB ) ;
|
| 189 |
|
|
AT91F_PMC_EnablePeriphClock( AT91C_BASE_PMC, 1 << AT91C_ID_EMAC ) ;
|
| 190 |
|
|
}
|
| 191 |
|
|
/*-----------------------------------------------------------*/
|
| 192 |
|
|
|
| 193 |
|
|
static void vErrorChecks( void *pvParameters )
|
| 194 |
|
|
{
|
| 195 |
|
|
portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
|
| 196 |
|
|
portTickType xLastWakeTime;
|
| 197 |
|
|
|
| 198 |
|
|
/* Initialise xLastWakeTime to ensure the first call to vTaskDelayUntil()
|
| 199 |
|
|
functions correctly. */
|
| 200 |
|
|
xLastWakeTime = xTaskGetTickCount();
|
| 201 |
|
|
|
| 202 |
|
|
/* Cycle for ever, delaying then checking all the other tasks are still
|
| 203 |
|
|
operating without error. If an error is detected then the delay period
|
| 204 |
|
|
is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
|
| 205 |
|
|
the Check LED flash rate will increase. */
|
| 206 |
|
|
for( ;; )
|
| 207 |
|
|
{
|
| 208 |
|
|
/* Delay until it is time to execute again. The delay period is
|
| 209 |
|
|
shorter following an error. */
|
| 210 |
|
|
vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );
|
| 211 |
|
|
|
| 212 |
|
|
/* Check all the standard demo application tasks are executing without
|
| 213 |
|
|
error. */
|
| 214 |
|
|
if( prvCheckOtherTasksAreStillRunning() != pdPASS )
|
| 215 |
|
|
{
|
| 216 |
|
|
/* An error has been detected in one of the tasks - flash faster. */
|
| 217 |
|
|
xDelayPeriod = mainERROR_FLASH_PERIOD;
|
| 218 |
|
|
}
|
| 219 |
|
|
|
| 220 |
|
|
vParTestToggleLED( mainCHECK_LED );
|
| 221 |
|
|
}
|
| 222 |
|
|
}
|
| 223 |
|
|
/*-----------------------------------------------------------*/
|
| 224 |
|
|
|
| 225 |
|
|
static long prvCheckOtherTasksAreStillRunning( void )
|
| 226 |
|
|
{
|
| 227 |
|
|
long lReturn = ( long ) pdPASS;
|
| 228 |
|
|
|
| 229 |
|
|
|
| 230 |
|
|
/* Check all the demo tasks (other than the flash tasks) to ensure
|
| 231 |
|
|
that they are all still running, and that none of them have detected
|
| 232 |
|
|
an error. */
|
| 233 |
|
|
|
| 234 |
|
|
if( xArePollingQueuesStillRunning() != pdTRUE )
|
| 235 |
|
|
{
|
| 236 |
|
|
lReturn = ( long ) pdFAIL;
|
| 237 |
|
|
}
|
| 238 |
|
|
|
| 239 |
|
|
if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
|
| 240 |
|
|
{
|
| 241 |
|
|
lReturn = ( long ) pdFAIL;
|
| 242 |
|
|
}
|
| 243 |
|
|
|
| 244 |
|
|
if( xAreSemaphoreTasksStillRunning() != pdTRUE )
|
| 245 |
|
|
{
|
| 246 |
|
|
lReturn = ( long ) pdFAIL;
|
| 247 |
|
|
}
|
| 248 |
|
|
|
| 249 |
|
|
if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
|
| 250 |
|
|
{
|
| 251 |
|
|
lReturn = ( long ) pdFAIL;
|
| 252 |
|
|
}
|
| 253 |
|
|
|
| 254 |
|
|
if( xAreMathsTaskStillRunning() != pdTRUE )
|
| 255 |
|
|
{
|
| 256 |
|
|
lReturn = ( long ) pdFAIL;
|
| 257 |
|
|
}
|
| 258 |
|
|
|
| 259 |
|
|
if( xAreBlockingQueuesStillRunning() != pdTRUE )
|
| 260 |
|
|
{
|
| 261 |
|
|
lReturn = ( long ) pdFAIL;
|
| 262 |
|
|
}
|
| 263 |
|
|
|
| 264 |
|
|
if( xIsCreateTaskStillRunning() != pdTRUE )
|
| 265 |
|
|
{
|
| 266 |
|
|
lReturn = ( long ) pdFAIL;
|
| 267 |
|
|
}
|
| 268 |
|
|
|
| 269 |
|
|
return lReturn;
|
| 270 |
|
|
}
|
| 271 |
|
|
|
| 272 |
|
|
|
| 273 |
|
|
|