⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 自己修改的PIC24ExplDemo上面的FREERTOS例程很实用! 可以供初学之学习
💻 C
字号:
/*
	FreeRTOS.org V4.2.1 - Copyright (C) 2003-2007 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.

	***************************************************************************
	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.

	Also see http://www.SafeRTOS.com for an IEC 61508 compliant version along
	with commercial development and support options.
	***************************************************************************
*/

/* Standard includes. */
#include <stdio.h>

/* Scheduler includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "croutine.h"

/* Demo application includes. */
#include "partest.h"
#include "lcd.h"

#if USE_PLL == 1

	_CONFIG2( POSCMOD_HS & OSCIOFNC_OFF & FCKSM_CSDCMD & FNOSC_PRIPLL & IESO_ON );
	_CONFIG1(JTAGEN_OFF & GCP_OFF & GWRP_OFF & FWDTEN_OFF);

#else

	_CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2) 
	_CONFIG2( FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_HS & FNOSC_PRI)

#endif

/*-----------------------------------------------------------*/

/* The LED used by the flash task. */
#define mainFLASH_TASK_LED	( 0 )

/*-----------------------------------------------------------*/

/*
 * Setup the processor ready for the demo.
 */
static void prvSetupHardware( void );

/*
 * A task that just periodically toggles an LED.  
 */
static void prvFlashTask( void *pvParameters );

/*
 * A task that does not yield.  It increments a counter and checks
 * for latched button inputs.
 */
static void prvNonBlockingTask( void *pvParameters );

/*
 * Returns true if a button push has been latched.
 */
extern portSHORT sButtonHasBeenPushed( void );

/*-----------------------------------------------------------*/

/* The queue used to send messages to the LCD task. */
static xQueueHandle xLCDQueue;

/* The counter that is incremented by the non blocking task. */
unsigned portLONG ulCounter = 0UL;

/*-----------------------------------------------------------*/

/*
 * Create the demo tasks then start the scheduler.
 */
int main( void )
{
	/* Configure any hardware required for this demo. */
	prvSetupHardware();

	/* This is the simple task that just periodically flashes an LED. */
	xTaskCreate( prvFlashTask, ( signed portCHAR * ) "LED", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );

	/* This task looks for latched button pushes.  It runs at the same 
	priroity as the task that flashes the LED.  It does	not yield, so 
	raising its priority will starve out prvFlashTask, causing the LED 
	to stop toggling. */
	xTaskCreate( prvNonBlockingTask, ( signed portCHAR * ) "NB", configMINIMAL_STACK_SIZE * 3, NULL, tskIDLE_PRIORITY, NULL );

	/* Start the task that will control the LCD.  This returns the handle
	to the queue used to write text out to the task. */
	xLCDQueue = xStartLCDTask();

	/* Finally start the scheduler. */
	vTaskStartScheduler();

	/* Will only reach here if there is insufficient heap available to start
	the scheduler. */
	return 0;
}
/*-----------------------------------------------------------*/

static void prvSetupHardware( void )
{
	/* Setup the digital IO for the LED's. */
	vParTestInitialise();
}
/*-----------------------------------------------------------*/

static void prvFlashTask( void *pvParameters )
{
const portTickType xDelayPeriod = 250 / portTICK_RATE_MS;

	for( ;; )
	{
		vTaskDelay( xDelayPeriod );
		vParTestToggleLED( mainFLASH_TASK_LED );
	}
}
/*-----------------------------------------------------------*/

static void prvNonBlockingTask( void *pvParameters )
{
xLCDMessage xDisplayMsg;
static portCHAR cBuffer[ 12 ];

	xDisplayMsg.xMinDisplayTime = 0;
	xDisplayMsg.pcMessage = cBuffer;

	for( ;; )
	{
		/* This task does not yield! */
		ulCounter++;

		if( sButtonHasBeenPushed() )
		{
			/* Send a message to the LCD that shows the current 
			counter value. */
			sprintf( cBuffer, "0x%lx", ulCounter );
			xQueueSend( xLCDQueue, &xDisplayMsg, 0 );
		}
	}
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -