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

📄 stc.c

📁 nucleusPlus是一个优秀的多任务调度内核
💻 C
字号:
#include "tc_defs.h"
#include "tc_extr.h"
#include "tm_defs.h"
#include "tm_extr.h"
#include "er_extr.h"                 /* Error handling function  */
#include "st_extr.h"

#define ST_IDLE_CYCLE	2

UNSIGNED STD_Idle_Count;
UNSIGNED STD_Idle_Saved_Count;
UNSIGNED STD_Idle_Full_Count;
UNSIGNED STD_Idle_ratio;

TC_TCB	STD_Idle_Task;
TM_APP_TCB	STD_Idle_Timer;

VOID *STD_Idle_Task_Stack_Ptr;//idle task stack starting addr, NOTE: it is initialized in INT_Initialize(int.s)

extern VOID STT_Lock_Interrupt(VOID);
extern VOID STT_Restore_Interrupt(VOID);
extern VOID STT_Idle_Loop(VOID);

VOID STC_Initialize(VOID);
VOID    STC_Idle_Task(UNSIGNED argc, VOID *argv);
void STC_Idle_Cycle(UNSIGNED id);

VOID STC_Initialize(VOID)
{

	UNSIGNED status;
	STD_Idle_Count = 0;
	STD_Idle_Saved_Count = 0;
	STD_Idle_Full_Count = 0;
	STD_Idle_ratio = 0;
	
	status =  TCC_Create_Task((NU_TASK *)&STD_Idle_Task, "IDLE TSK",
			STC_Idle_Task, 0, (VOID *)NU_NULL, 
			STD_Idle_Task_Stack_Ptr, 1024,0, 0, 
		        NU_PREEMPT, NU_START);

	status = TMS_Create_Timer(&STD_Idle_Timer, "T-Idle", STC_Idle_Cycle, 
			0, 10, ST_IDLE_CYCLE*NU_PLUS_Ticks_Per_Second, NU_ENABLE_TIMER);


}


UNSIGNED STC_Get_Idle_Ratio(VOID)
{
	return STD_Idle_ratio;
}

UNSIGNED STC_Get_Current_Cnt(VOID)
{
	return STD_Idle_Saved_Count;
}

UNSIGNED STC_Get_Idle_Cnt(VOID)
{
	return STD_Idle_Full_Count;
}

VOID    STC_Idle_Task(UNSIGNED argc, VOID *argv)
{
	STT_Idle_Loop();
}


void STC_Idle_Cycle(UNSIGNED id)
{
	if (STD_Idle_Full_Count>1)
	{
		STD_Idle_Saved_Count = STD_Idle_Count;
		STD_Idle_Count = 0;
		STD_Idle_ratio = STD_Idle_Saved_Count*100;
		STD_Idle_ratio/=STD_Idle_Full_Count;
	}
	else if (STD_Idle_Full_Count == 1)
	{
		STD_Idle_Full_Count = STD_Idle_Count;
		STD_Idle_Count = 0;
		TCS_Change_Priority(&STD_Idle_Task,255);
	}
	else
	{
		STD_Idle_Full_Count = 1;
		STD_Idle_Count = 0;
	}
}

⌨️ 快捷键说明

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