| 1 |
577 |
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 |
|
|
NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
|
| 56 |
|
|
The processor MUST be in supervisor mode when vTaskStartScheduler is
|
| 57 |
|
|
called. The demo applications included in the FreeRTOS.org download switch
|
| 58 |
|
|
to supervisor mode prior to main being called. If you are not using one of
|
| 59 |
|
|
these demo application projects then ensure Supervisor mode is used.
|
| 60 |
|
|
*/
|
| 61 |
|
|
|
| 62 |
|
|
/*
|
| 63 |
|
|
* Creates all the demo application tasks, then starts the scheduler. The WEB
|
| 64 |
|
|
* documentation provides more details of the demo application tasks. The SAM7
|
| 65 |
|
|
* includes a sample USB that emulates a Joystick input to a USB host.
|
| 66 |
|
|
*
|
| 67 |
|
|
* Main.c also creates a task called "Check". This only executes every three
|
| 68 |
|
|
* seconds but has the highest priority so is guaranteed to get processor time.
|
| 69 |
|
|
* Its main function is to check that all the other tasks are still operational.
|
| 70 |
|
|
* Each task (other than the "flash" tasks) maintains a unique count that is
|
| 71 |
|
|
* incremented each time the task successfully completes its function. Should
|
| 72 |
|
|
* any error occur within such a task the count is permanently halted. The
|
| 73 |
|
|
* check task inspects the count of each task to ensure it has changed since
|
| 74 |
|
|
* the last time the check task executed. If all the count variables have
|
| 75 |
|
|
* changed all the tasks are still executing error free, and the check task
|
| 76 |
|
|
* toggles the onboard LED. Should any task contain an error at any time
|
| 77 |
|
|
* the LED toggle rate will change from 3 seconds to 500ms.
|
| 78 |
|
|
*
|
| 79 |
|
|
*/
|
| 80 |
|
|
|
| 81 |
|
|
/* Standard includes. */
|
| 82 |
|
|
#include <stdlib.h>
|
| 83 |
|
|
|
| 84 |
|
|
/* Scheduler includes. */
|
| 85 |
|
|
#include "FreeRTOS.h"
|
| 86 |
|
|
#include "task.h"
|
| 87 |
|
|
|
| 88 |
|
|
/* Demo application includes. */
|
| 89 |
|
|
#include "flash.h"
|
| 90 |
|
|
#include "integer.h"
|
| 91 |
|
|
#include "PollQ.h"
|
| 92 |
|
|
#include "BlockQ.h"
|
| 93 |
|
|
#include "semtest.h"
|
| 94 |
|
|
#include "dynamic.h"
|
| 95 |
|
|
#include "partest.h"
|
| 96 |
|
|
#include "comtest2.h"
|
| 97 |
|
|
#include "USB/USBSample.h"
|
| 98 |
|
|
|
| 99 |
|
|
/* Priorities for the demo application tasks. */
|
| 100 |
|
|
#define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
|
| 101 |
|
|
#define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
|
| 102 |
|
|
#define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
|
| 103 |
|
|
#define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
|
| 104 |
|
|
#define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
|
| 105 |
|
|
#define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
|
| 106 |
|
|
#define mainUSB_PRIORITY ( tskIDLE_PRIORITY + 2 )
|
| 107 |
|
|
|
| 108 |
|
|
/* Constants required by the 'Check' task. */
|
| 109 |
|
|
#define mainNO_ERROR_FLASH_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
|
| 110 |
|
|
#define mainERROR_FLASH_PERIOD ( ( portTickType ) 500 / portTICK_RATE_MS )
|
| 111 |
|
|
#define mainCHECK_TASK_LED ( 3 )
|
| 112 |
|
|
|
| 113 |
|
|
/* Constants for the ComTest tasks. */
|
| 114 |
|
|
#define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 115200 )
|
| 115 |
|
|
#define mainCOM_TEST_LED ( 4 ) /* Off the board. */
|
| 116 |
|
|
|
| 117 |
|
|
/*
|
| 118 |
|
|
* The task that executes at the highest priority and calls
|
| 119 |
|
|
* prvCheckOtherTasksAreStillRunning(). See the description at the top
|
| 120 |
|
|
* of the file.
|
| 121 |
|
|
*/
|
| 122 |
|
|
static void vErrorChecks( void *pvParameters );
|
| 123 |
|
|
|
| 124 |
|
|
/*
|
| 125 |
|
|
* Configure the processor for use with the Atmel demo board. Setup is minimal
|
| 126 |
|
|
* as the low level init function (called from the startup asm file) takes care
|
| 127 |
|
|
* of most things.
|
| 128 |
|
|
*/
|
| 129 |
|
|
static void prvSetupHardware( void );
|
| 130 |
|
|
|
| 131 |
|
|
/*
|
| 132 |
|
|
* Checks that all the demo application tasks are still executing without error
|
| 133 |
|
|
* - as described at the top of the file.
|
| 134 |
|
|
*/
|
| 135 |
|
|
static long prvCheckOtherTasksAreStillRunning( void );
|
| 136 |
|
|
|
| 137 |
|
|
|
| 138 |
|
|
/*-----------------------------------------------------------*/
|
| 139 |
|
|
|
| 140 |
|
|
/*
|
| 141 |
|
|
* Starts all the other tasks, then starts the scheduler.
|
| 142 |
|
|
*/
|
| 143 |
|
|
void main( void )
|
| 144 |
|
|
{
|
| 145 |
|
|
/* Setup any hardware that has not already been configured by the low
|
| 146 |
|
|
level init routines. */
|
| 147 |
|
|
prvSetupHardware();
|
| 148 |
|
|
|
| 149 |
|
|
/* Initialise the LED outputs for use by the demo application tasks. */
|
| 150 |
|
|
vParTestInitialise();
|
| 151 |
|
|
|
| 152 |
|
|
/* Start all the standard demo application tasks. */
|
| 153 |
|
|
vStartIntegerMathTasks( tskIDLE_PRIORITY );
|
| 154 |
|
|
vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
|
| 155 |
|
|
vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
|
| 156 |
|
|
vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
|
| 157 |
|
|
vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
|
| 158 |
|
|
vStartDynamicPriorityTasks();
|
| 159 |
|
|
vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
|
| 160 |
|
|
|
| 161 |
|
|
/* Also start the USB demo which is just for the SAM7. */
|
| 162 |
|
|
xTaskCreate( vUSBDemoTask, "USB", configMINIMAL_STACK_SIZE, NULL, mainUSB_PRIORITY, NULL );
|
| 163 |
|
|
|
| 164 |
|
|
/* Start the check task - which is defined in this file. */
|
| 165 |
|
|
xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
|
| 166 |
|
|
|
| 167 |
|
|
/* Start the scheduler.
|
| 168 |
|
|
|
| 169 |
|
|
NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
|
| 170 |
|
|
The processor MUST be in supervisor mode when vTaskStartScheduler is
|
| 171 |
|
|
called. The demo applications included in the FreeRTOS.org download switch
|
| 172 |
|
|
to supervisor mode prior to main being called. If you are not using one of
|
| 173 |
|
|
these demo application projects then ensure Supervisor mode is used here. */
|
| 174 |
|
|
|
| 175 |
|
|
vTaskStartScheduler();
|
| 176 |
|
|
|
| 177 |
|
|
/* We should never get here as control is now taken by the scheduler. */
|
| 178 |
|
|
return;
|
| 179 |
|
|
}
|
| 180 |
|
|
/*-----------------------------------------------------------*/
|
| 181 |
|
|
|
| 182 |
|
|
static void prvSetupHardware( void )
|
| 183 |
|
|
{
|
| 184 |
|
|
/* When using the JTAG debugger the hardware is not always initialised to
|
| 185 |
|
|
the correct default state. This line just ensures that this does not
|
| 186 |
|
|
cause all interrupts to be masked at the start. */
|
| 187 |
|
|
AT91C_BASE_AIC->AIC_EOICR = 0;
|
| 188 |
|
|
|
| 189 |
|
|
/* Most setup is performed by the low level init function called from the
|
| 190 |
|
|
startup asm file. */
|
| 191 |
|
|
|
| 192 |
|
|
/* Configure the PIO Lines corresponding to LED1 to LED4 to be outputs as
|
| 193 |
|
|
well as the UART Tx line. */
|
| 194 |
|
|
AT91F_PIO_CfgOutput( AT91C_BASE_PIOA, LED_MASK );
|
| 195 |
|
|
|
| 196 |
|
|
/* Enable the peripheral clock. */
|
| 197 |
|
|
AT91F_PMC_EnablePeriphClock( AT91C_BASE_PMC, 1 << AT91C_ID_PIOA );
|
| 198 |
|
|
}
|
| 199 |
|
|
/*-----------------------------------------------------------*/
|
| 200 |
|
|
|
| 201 |
|
|
static void vErrorChecks( void *pvParameters )
|
| 202 |
|
|
{
|
| 203 |
|
|
portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
|
| 204 |
|
|
|
| 205 |
|
|
/* The parameters are not used in this task. */
|
| 206 |
|
|
( void ) pvParameters;
|
| 207 |
|
|
|
| 208 |
|
|
/* Cycle for ever, delaying then checking all the other tasks are still
|
| 209 |
|
|
operating without error. If an error is detected then the delay period
|
| 210 |
|
|
is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
|
| 211 |
|
|
the on board LED flash rate will increase. */
|
| 212 |
|
|
|
| 213 |
|
|
for( ;; )
|
| 214 |
|
|
{
|
| 215 |
|
|
/* Delay until it is time to execute again. */
|
| 216 |
|
|
vTaskDelay( xDelayPeriod );
|
| 217 |
|
|
|
| 218 |
|
|
/* Check all the standard demo application tasks are executing without
|
| 219 |
|
|
error. */
|
| 220 |
|
|
if( prvCheckOtherTasksAreStillRunning() != pdPASS )
|
| 221 |
|
|
{
|
| 222 |
|
|
/* An error has been detected in one of the tasks - flash faster. */
|
| 223 |
|
|
xDelayPeriod = mainERROR_FLASH_PERIOD;
|
| 224 |
|
|
}
|
| 225 |
|
|
|
| 226 |
|
|
vParTestToggleLED( mainCHECK_TASK_LED );
|
| 227 |
|
|
}
|
| 228 |
|
|
}
|
| 229 |
|
|
/*-----------------------------------------------------------*/
|
| 230 |
|
|
|
| 231 |
|
|
static long prvCheckOtherTasksAreStillRunning( void )
|
| 232 |
|
|
{
|
| 233 |
|
|
long lReturn = ( long ) pdPASS;
|
| 234 |
|
|
|
| 235 |
|
|
/* Check all the demo tasks (other than the flash tasks) to ensure
|
| 236 |
|
|
that they are all still running, and that none of them have detected
|
| 237 |
|
|
an error. */
|
| 238 |
|
|
|
| 239 |
|
|
if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
|
| 240 |
|
|
{
|
| 241 |
|
|
lReturn = ( long ) pdFAIL;
|
| 242 |
|
|
}
|
| 243 |
|
|
|
| 244 |
|
|
if( xArePollingQueuesStillRunning() != pdTRUE )
|
| 245 |
|
|
{
|
| 246 |
|
|
lReturn = ( long ) pdFAIL;
|
| 247 |
|
|
}
|
| 248 |
|
|
|
| 249 |
|
|
if( xAreSemaphoreTasksStillRunning() != pdTRUE )
|
| 250 |
|
|
{
|
| 251 |
|
|
lReturn = ( long ) pdFAIL;
|
| 252 |
|
|
}
|
| 253 |
|
|
|
| 254 |
|
|
if( xAreBlockingQueuesStillRunning() != pdTRUE )
|
| 255 |
|
|
{
|
| 256 |
|
|
lReturn = ( long ) pdFAIL;
|
| 257 |
|
|
}
|
| 258 |
|
|
|
| 259 |
|
|
if( xAreComTestTasksStillRunning() != pdTRUE )
|
| 260 |
|
|
{
|
| 261 |
|
|
lReturn = ( long ) pdFAIL;
|
| 262 |
|
|
}
|
| 263 |
|
|
|
| 264 |
|
|
if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
|
| 265 |
|
|
{
|
| 266 |
|
|
lReturn = ( long ) pdFAIL;
|
| 267 |
|
|
}
|
| 268 |
|
|
|
| 269 |
|
|
return lReturn;
|
| 270 |
|
|
}
|
| 271 |
|
|
/*-----------------------------------------------------------*/
|
| 272 |
|
|
|
| 273 |
|
|
|