📄 main.c
字号:
/*
FreeRTOS.org V5.0.0 - Copyright (C) 2003-2008 Richard Barry.
This file is part of the FreeRTOS.org distribution.
FreeRTOS.org is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FreeRTOS.org is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FreeRTOS.org; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
A special exception to the GPL can be applied should you wish to distribute
a combined work that includes FreeRTOS.org, without being obliged to provide
the source code for any proprietary components. See the licensing section
of http://www.FreeRTOS.org for full details of how and when the exception
can be applied.
***************************************************************************
***************************************************************************
* *
* SAVE TIME AND MONEY! We can port FreeRTOS.org to your own hardware, *
* and even write all or part of your application on your behalf. *
* See http://www.OpenRTOS.com for details of the services we provide to *
* expedite your project. *
* *
***************************************************************************
***************************************************************************
Please ensure to read the configuration and relevant port sections of the
online documentation.
http://www.FreeRTOS.org - Documentation, latest information, license and
contact details.
http://www.SafeRTOS.com - A version that is certified for use in safety
critical systems.
http://www.OpenRTOS.com - Commercial support, development, porting,
licensing and training services.
*/
/*
* Creates all the demo application tasks, then starts the scheduler. The WEB
* documentation provides more details of the standard demo application tasks.
*
* In addition to the standard tasks, main() creates two "Register Check"
* tasks. These tasks write known values into every general purpose register,
* then check each register to ensure it still contains the expected (written)
* value. The register check tasks operate at the idle priority so will get
* repeatedly preempted. A register being found to contain an incorrect value
* following such a preemption would be indicative of an error in the context
* switch mechanism.
*
* Main.c also creates a task called "Check". This only executes every three
* seconds but has the highest priority so is guaranteed to get processor time.
* Its main function is to check that all the other tasks are still operational.
* Each task (other than the "flash" tasks) maintains a unique count that is
* incremented each time the task successfully completes its function. Should
* any error occur within such a task the count is permanently halted. The
* check task inspects the count of each task to ensure it has changed since
* the last time the check task executed. If all the count variables have
* changed all the tasks are still executing error free, and the check task
* toggles the onboard LED. Should any task contain an error at any time
* the LED toggle rate will change from 3 seconds to 500ms.
*
*/
/* Scheduler includes. */
#include "FreeRTOS.h"
#include "task.h"
/* Demo application includes. */
#include "partest.h"
#include "flash.h"
#include "comtest2.h"
#include "integer.h"
#include "semtest.h"
#include "BlockQ.h"
#include "dynamic.h"
#include "PollQ.h"
/* Hardware library includes. */
#include <xintc.h>
/* The rate at which the 'check' LED will flash when no errors have been
detected. */
#define mainNO_ERROR_CHECK_PERIOD 3000
/* The rate at which the 'check' LED will flash when an error has been
detected in one of the demo tasks. */
#define mainERROR_CHECK_PERIOD 500
/* Demo application task priorities. */
#define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
#define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
#define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
#define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
#define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
/* Software cannot influence the BAUD rate used by the simple UART
implementation. */
#define mainBAUD_RATE 0
/* The LED flashed by the 'check' task to indicate the system status. */
#define mainCHECK_TASK_LED 3
/* The first LED flashed by the COM port test tasks. LED mainCOM_TEST_LED + 1
will also be used. */
#define mainCOM_TEST_LED 4
/* The register test task does not make any function calls so does not require
much stack at all. */
#define mainTINY_STACK 70
/*
* The task that executes at the highest priority and calls
* prvCheckOtherTasksAreStillRunning(). See the description at the top
* of the file.
*/
static void vErrorChecks( void *pvParameters );
/*
* Checks that all the demo application tasks are still executing without error
* - as described at the top of the file.
*/
static portBASE_TYPE prvCheckOtherTasksAreStillRunning( void );
/*
* The register test task as described at the top of this file.
*/
static void vRegisterTest( void *pvParameters );
/*
* Perform any necessary hardware configuration.
*/
static void prvSetupHardware( void );
/* Set to pdFAIL should an error be discovered in the register test tasks. */
static unsigned portLONG ulRegisterTestStatus = pdPASS;
const unsigned portLONG *pulStatusAddr = &ulRegisterTestStatus;
/*-----------------------------------------------------------*/
/*
* Create all the demo tasks - then start the scheduler.
*/
int main (void)
{
/* When re-starting a debug session (rather than cold booting) we want
to ensure the installed interrupt handlers do not execute until after the
scheduler has been started. */
portDISABLE_INTERRUPTS();
prvSetupHardware();
/* Start the standard demo application tasks. */
vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainBAUD_RATE, mainCOM_TEST_LED );
vStartIntegerMathTasks( tskIDLE_PRIORITY );
vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
vStartDynamicPriorityTasks();
vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
/* Create two register check tasks - using a different parameter for each.
The parameter is used to generate the known values written to the registers. */
#if configUSE_PREEMPTION == 1
xTaskCreate( vRegisterTest, "Reg1", mainTINY_STACK, ( void * ) 10, tskIDLE_PRIORITY, NULL );
xTaskCreate( vRegisterTest, "Reg2", mainTINY_STACK, ( void * ) 20, tskIDLE_PRIORITY, NULL );
#endif
/* Create the 'check' task that is defined in this file. */
xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
/* Finally start the scheduler. */
vTaskStartScheduler();
/* Should not get here as the processor is now under control of the
scheduler! */
return 0;
}
/*-----------------------------------------------------------*/
static void vErrorChecks( void *pvParameters )
{
portTickType xDelayPeriod = mainNO_ERROR_CHECK_PERIOD;
/* The parameters are not used. */
( void ) pvParameters;
/* Cycle for ever, delaying then checking all the other tasks are still
operating without error. The delay period used will depend on whether
or not an error has been discovered in one of the demo tasks. */
for( ;; )
{
vTaskDelay( xDelayPeriod );
if( !prvCheckOtherTasksAreStillRunning() )
{
/* An error has been found. Shorten the delay period to make
the LED flash faster. */
xDelayPeriod = mainERROR_CHECK_PERIOD;
}
vParTestToggleLED( mainCHECK_TASK_LED );
}
}
/*-----------------------------------------------------------*/
static portBASE_TYPE prvCheckOtherTasksAreStillRunning( void )
{
static portBASE_TYPE xAllTestsPass = pdTRUE;
/* Return pdFALSE if any demo application task set has encountered
an error. */
if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -