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

📄 portmacro.h

📁 FreeRTOS is a portable, open source, mini Real Time Kernel - a free to download and royalty free RTO
💻 H
📖 第 1 页 / 共 2 页
字号:
/*
	FreeRTOS.org V5.2.0 - Copyright (C) 2003-2009 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 (version 2) as published
	by the Free Software Foundation and modified by the FreeRTOS exception.

	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 is included to allow you 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.


	***************************************************************************
	*                                                                         *
	* Get the FreeRTOS eBook!  See http://www.FreeRTOS.org/Documentation      *
	*                                                                         *
	* This is a concise, step by step, 'hands on' guide that describes both   *
	* general multitasking concepts and FreeRTOS specifics. It presents and   *
	* explains numerous examples that are written using the FreeRTOS API.     *
	* Full source code for all the examples is provided in an accompanying    *
	* .zip file.                                                              *
	*                                                                         *
	***************************************************************************

	1 tab == 4 spaces!

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

/* 
Changes from V3.0.0

Changes from V3.0.1
*/
#ifndef PORTMACRO_H
#define PORTMACRO_H

#if !defined(_SERIES) || _SERIES != 18
	#error "WizC supports FreeRTOS on the Microchip PIC18-series only"
#endif

#if !defined(QUICKCALL) || QUICKCALL != 1
	#error "QuickCall must be enabled (see ProjectOptions/Optimisations)"
#endif

#include <stddef.h>
#include <pic.h>

#define portCHAR		char
#define portFLOAT		float
#define portDOUBLE		portFLOAT
#define portLONG		long
#define portSHORT		short
#define portSTACK_TYPE	unsigned char
#define portBASE_TYPE	char

#if( configUSE_16_BIT_TICKS == 1 )
	typedef unsigned portSHORT portTickType;
	#define portMAX_DELAY ( portTickType )	( 0xFFFF )
#else
	typedef unsigned portLONG portTickType;
	#define portMAX_DELAY ( portTickType )	( 0xFFFFFFFF )
#endif

#define portBYTE_ALIGNMENT			1

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

/*
 * Constant used for context switch macro when we require the interrupt 
 * enable state to be forced when the interrupted task is switched back in.
 */
#define portINTERRUPTS_FORCED				(0x01)

/*
 * Constant used for context switch macro when we require the interrupt 
 * enable state to be unchanged when the interrupted task is switched back in.
 */
#define portINTERRUPTS_UNCHANGED			(0x00)

/* Initial interrupt enable state for newly created tasks.  This value is
 * used when a task switches in for the first time.
 */
#define portINTERRUPTS_INITIAL_STATE		(portINTERRUPTS_FORCED)

/*
 * Macros to modify the global interrupt enable bit in INTCON.
 */
#define portDISABLE_INTERRUPTS()	\
	do								\
	{								\
		bGIE=0;						\
	} while(bGIE)	// MicroChip recommends this check!
	
#define portENABLE_INTERRUPTS()		\
	do								\
	{								\
		bGIE=1;						\
	} while(0)

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

/*
 * Critical section macros.
 */
extern unsigned portCHAR ucCriticalNesting;

#define portNO_CRITICAL_SECTION_NESTING		( ( unsigned portCHAR ) 0 )

#define portENTER_CRITICAL()										\
	do																\
	{																\
		portDISABLE_INTERRUPTS();									\
																	\
		/*															\
		 * Now interrupts are disabled ucCriticalNesting			\
		 * can be accessed directly. Increment						\
		 * ucCriticalNesting to keep a count of how					\
		 * many times portENTER_CRITICAL() has been called. 		\
		 */															\
		ucCriticalNesting++;										\
	} while(0)

#define portEXIT_CRITICAL()											\
	do																\
	{																\
		if(ucCriticalNesting > portNO_CRITICAL_SECTION_NESTING)		\
		{															\
			/*														\
			 * Decrement the nesting count as we are leaving a		\
			 * critical section.									\
			 */														\
			ucCriticalNesting--;									\
		}															\
																	\
		/*															\
		 * If the nesting level has reached zero then				\
		 * interrupts should be re-enabled.							\
		 */															\
		if( ucCriticalNesting == portNO_CRITICAL_SECTION_NESTING )	\
		{															\
			portENABLE_INTERRUPTS();								\
		}															\
	} while(0)

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

/*
 * The minimal stacksize is calculated on the first reference of
 * portMINIMAL_STACK_SIZE. Some input to this calculation is
 * compiletime determined, other input is port-defined (see port.c)
 */
extern unsigned portSHORT usPortCALCULATE_MINIMAL_STACK_SIZE( void );
extern unsigned portSHORT usCalcMinStackSize;

#define portMINIMAL_STACK_SIZE					\
	((usCalcMinStackSize == 0)					\
		? usPortCALCULATE_MINIMAL_STACK_SIZE()	\
		: usCalcMinStackSize )

/*
 * WizC uses a downgrowing stack
 */
#define portSTACK_GROWTH			( -1 )

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

/*
 * Macro's that pushes all the registers that make up the context of a task onto
 * the stack, then saves the new top of stack into the TCB. TOSU and TBLPTRU
 * are only saved/restored on devices with more than 64kB (32k Words) ROM.
 * 
 * The stackpointer is helt by WizC in FSR2 and points to the first free byte.
 * WizC uses a "downgrowing" stack. There is no framepointer.
 *
 * We keep track of the interruptstatus using ucCriticalNesting. When this
 * value equals zero, interrupts have to be enabled upon exit from the
 * portRESTORE_CONTEXT macro.
 * 
 * If this is called from an ISR then the interrupt enable bits must have been 
 * set for the ISR to ever get called.  Therefore we want to save
 * ucCriticalNesting with value zero. This means the interrupts will again be
 * re-enabled when the interrupted task is switched back in.
 *
 * If this is called from a manual context switch (i.e. from a call to yield),
 * then we want to keep the current value of ucCritialNesting so it is restored
 * with its current value. This allows a yield from within a critical section.
 *
 * The compiler uses some locations at the bottom of RAM for temporary
 * storage. The compiler may also have been instructed to optimize
 * function-parameters and local variables to global storage. The compiler
 * uses an area called LocOpt for this wizC feature.
 * The total overheadstorage has to be saved in it's entirety as part of
 * a task context. These macro's store/restore from data address 0x0000 to
 * (OVERHEADPAGE0-LOCOPTSIZE+MAXLOCOPTSIZE - 1).
 * OVERHEADPAGE0, LOCOPTSIZE and MAXLOCOPTSIZE are compiler-generated
 * assembler definitions.
 */

#define	portSAVE_CONTEXT( ucInterruptForced )						\

⌨️ 快捷键说明

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