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

📄 ticktimer.c

📁 这是CodeWarrior环境下基于freescale单片机上的实时操作系统代码.
💻 C
字号:
#include <hidef.h>		 	/* for EnableInterrupts macro */
#include <MC9S08GB60.h> 	/* include peripheral declarations */
#include "TickTimer.h"

#include "FreeRTOS.h"		/* The one and only FreeRTOS.h */


static unsigned short cThisTimerInc = (unsigned short)(TIMER_INPUT_CLK/1000);

/*
*******************************************************************************
*
*
*
*******************************************************************************
*/
unsigned char TickTimer_Enable (void)
{
	TPM1C0SC |= 0x40;	/* Enable Input Compare IRQ */
	
	return 0;
}



/*
*******************************************************************************
*
* This function configures the TPM1 Channel 0 to generate the RTOS tick at 
* the frequency specified within FreeRTOSConfig.h.
*
*******************************************************************************
*/
signed char TickTimer_SetFreqHz (short Freq)
{	
#if (TIMER_PRESCALER_SET < 0) || (TIMER_PRESCALER_SET > 7)
	#error TIMER_PRESCALER_SET value MUST be more than 1 and less than 7
#endif

	cThisTimerInc = (unsigned short)(TIMER_INPUT_CLK/Freq/(1 << TIMER_PRESCALER_SET));
		
	TPM1SC = (0x08 | TIMER_PRESCALER_SET);	/* Prescaler set to TIMER_PRESCALER_SET, 
	                                           Bus clk as source, no Ovr IRQs */
	TPM1C0VH = (cThisTimerInc >> 8);
	TPM1C0VL = (cThisTimerInc & 0xFF);
	
	TPM1C0SC = 0x10;	/* Channel as Output Compare, Software Compare Only, Disable Compare IRQ */

	return 0;
}




/*
*******************************************************************************
*
* RTOS tick interrupt service routine.  If the cooperative scheduler is 
* being used then this simply increments the tick count.  If the 
* preemptive scheduler is being used a context switch can occur.
*
*******************************************************************************
*/

#pragma TRAP_PROC SAVE_NO_REGS
__interrupt 5 void TickTimer_Interrupt (void)
{
	TPM1C0V += cThisTimerInc;

   	TPM1C0SC &= (~0x80);						/* Reset interrupt request flag */
	
	#if configUSE_PREEMPTION == 1
	{
		/* A context switch might happen so save the context. */
		portSAVE_CONTEXT();

		/* Increment the tick ... */
		vTaskIncrementTick();

		/* ... then see if the new tick value has necessitated a
		context switch. */
		vTaskSwitchContext();

		/* Restore the context of a task - which may be a different task
		to that interrupted. */
		portRESTORE_CONTEXT();	
	}
	#else
	{
		vTaskIncrementTick();
	}
	#endif
}


⌨️ 快捷键说明

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