📄 flash.c
字号:
/*
FreeRTOS V4.0.1 - Copyright (C) 2003-2006 Richard Barry.
This file is part of the FreeRTOS distribution.
FreeRTOS 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 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; 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, 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.
***************************************************************************
See http://www.FreeRTOS.org for documentation, latest information, license
and contact details. Please ensure to read the configuration and relevant
port sections of the online documentation.
***************************************************************************
*/
/**
* This version of flash .c is for use on systems that have limited stack space
* and no display facilities. The complete version can be found in the
* Demo/Common/Full directory.
*
* Three tasks are created, each of which flash an LED at a different rate. The first
* LED flashes every 200ms, the second every 400ms, the third every 600ms.
*
* The LED flash tasks provide instant visual feedback. They show that the scheduler
* is still operational.
*
* The PC port uses the standard parallel port for outputs, the Flashlite 186 port
* uses IO port F and the AVR port port B.
*
*/
/*
Changes from V2.0.0
+ Delay periods are now specified using variables and constants of
portTickType rather than unsigned portLONG.
Changes from V2.5.5
+ Calls to vTaskDelay() have been replaced with vTaskDelayUntil().
*/
#include <stdlib.h>
/* Scheduler include files. */
#include "..\..\..\Os\include\FreeRTOS.h"
#include "..\..\..\Os\include\task.h"
/* Demo task include files. */
#include "..\include\flash.h"
#define ledSTACK_SIZE configMINIMAL_STACK_SIZE
#define ledNUMBER_OF_LEDS ( 1 )
#define mainON_BOARD_LED_BIT ( ( unsigned portCHAR ) 0x01 )
#define ledFLASH_RATE_BASE ( ( portTickType ) 2000 )
/* Toggle the single genuine built in LED. */
static void prvToggleOnBoardLED( void );
/* The task that is created three times. */
static portTASK_FUNCTION_PROTO( vLEDFlashTask, pvParameters );
/*-----------------------------------------------------------*/
void vStartLEDFlashTask( unsigned portBASE_TYPE uxPriority )
{
signed portBASE_TYPE xLEDTask;
/* Create the three tasks. */
for( xLEDTask = 0; xLEDTask < ledNUMBER_OF_LEDS; ++xLEDTask )
{
/* Spawn the task. */
xTaskCreate( vLEDFlashTask, ( const signed portCHAR * const ) "LED", ledSTACK_SIZE, NULL, uxPriority, ( xTaskHandle * ) NULL );
}
}
/*-----------------------------------------------------------*/
static portTASK_FUNCTION( vLEDFlashTask, pvParameters )
{
portTickType xFlashRate, xLastFlashTime, xCurrentTime;
/* The parameters are not used. */
( void ) pvParameters;
xFlashRate = ledFLASH_RATE_BASE;
/* We need to initialise xLastFlashTime prior to the first call to
vTaskDelayUntil(). */
xLastFlashTime = xTaskGetTickCount();
for( ; ; )
{
/* Delay for half the flash period then turn the LED on. */
// vTaskDelayUntil( &xLastFlashTime, xFlashRate );
volatile unsigned int i;
vTaskDelay( xFlashRate );
xCurrentTime = xTaskGetTickCount();
xLastFlashTime = xCurrentTime + xFlashRate;
while ( xCurrentTime < xLastFlashTime )
{
xCurrentTime = xTaskGetTickCount();
prvToggleOnBoardLED(); // Toggle P1.0 using exclusive-OR
i = 50000; // Delay
do (i--);
while (i != 0);
}
}
}
/*-----------------------------------------------------------*/
static void prvToggleOnBoardLED( void )
{
static unsigned portSHORT sState = pdFALSE;
/* Toggle the state of the single genuine on board LED. */
if( sState )
{
P6OUT |= mainON_BOARD_LED_BIT;
}
else
{
P6OUT &= ~mainON_BOARD_LED_BIT;
}
sState = !sState;
}
/*-----------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -