//#if MAIN_EN >0
/*******************************************************
系统测试
******************************************************/
#include "core.h"
#include "at89x52.h"
#define LED1 P1_4
#define ON_LED1() LED1=0
#define OFF_LED1() LED1=1
//堆栈深度
#define TASK_STACK_SIZE 20
#define IDLE_STACK_SIZE 18
unsigned char idata Task_idle_Stack[IDLE_STACK_SIZE];
unsigned char idata Task_1_Stack[TASK_STACK_SIZE];
unsigned char idata Task_2_Stack[TASK_STACK_SIZE];
//CPU使用率
volatile unsigned char idata OS_CPU_USER_RATIO;
void task_idle(void);
void task_1(void);
void task_2(void);
//非实时系统切换函数演示
void nRT_TWS(unsigned char next)
{
//可以自己写这个函数
OSPrioHighRdy=next;
OS_Task_Switch();
}
/////////////////////////////////////空闲任务,优先级最低///////////////////////////////////
void task_idle(void)
{
#ifdef RT_OS_EN
//任务中尽量使用static申明局部变量,避免变量被分配到相同的地址
static unsigned long int total_count;
static unsigned long int current_count;
static unsigned char time,j;
total_count=0;
current_count=0;
time=(unsigned char)OS_Run_Time; //初始化time
while(time==(unsigned char)OS_Run_Time); //等待,直到OS_Run_Time的值改变了
time=(unsigned char)OS_Run_Time; //保存这时的时间
if(OS_MODO) //如果需要CPU使用率统计
{
while(1)
{
if((unsigned char)OS_Run_Time-time>=100) //共统计1秒钟的时间
{
j=(total_count-current_count)/(total_count);
break;
}
total_count++; //累加CPU资源
}
for(j=0;j<OS_MAX_TASK;j++) //将挂起的任务唤醒
{
OS_pcb[j].Suspend=0; //如果不需要CPU使用率统计,则任务初始不挂起
OSRdyList|=1<< OS_pcb[j].Priority;
}
}
while(1) //死循环
{
if(OS_MODO) //如果需要统计CPU使用率
while(1)
{
//测量100个时钟节拍的CPU资源,然后跟没有其它任务运行时的CPU资源比较
if((unsigned char)OS_Run_Time-time>=100)
{
//计算比率
j=(total_count-current_count)/(total_count/100);
//将计算结果保存
OS_CPU_USER_RATIO=j;
current_count=0; //清0
time=(unsigned char)OS_Run_Time;
while(time==(unsigned char)OS_Run_Time);
time=(unsigned char)OS_Run_Time; //重新开始统计
break;
}
current_count++; //累加CPU资源
}
}
#else
for(;;) nRT_TWS(0);
#endif
}
///////////////////////////////////// 任务1 //////////////////////////
void task_1(void)
{
for(;;)
{
#ifdef RT_OS_EN
OS_Delay(INFINITE_LOOP-1);
#else
nRT_TWS(1);
#endif
}
}
//////////////////////////////// 任务2 ////////////////////////////////////
unsigned long tims;
void task_2(void)
{
for(;;)
{
#ifdef RT_OS_EN
OS_Delay(150);
ON_LED1(); //开LED1
OS_Delay(150);
OFF_LED1(); //关LED1
#else
ON_LED1(); //开LED1
nRT_TWS(7);
OFF_LED1(); //关LED1
#endif
tims++;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////主函数//////////////////////////////////////////////////////
void main(void)
{
EA=0; //关中
T2CON=0x00; //定时器自动重装模式
T2MOD=0x00;
RCAP2H=0xB1;
RCAP2L=0xE0; //24M晶振 定时时间为10ms
OS_Init(1); //OS初始化
//参数意义 优先级 任务入口地址 堆栈地址 消息指针
OS_Task_Create(LOW_IDLE_PRIORITY,(unsigned int)(&task_idle),&Task_idle_Stack[0]); //任务0初始化
OS_Task_Create(0, (unsigned int)(&task_1), &Task_1_Stack[0]); //任务2初始化
OS_Task_Create(1, (unsigned int)(&task_2), &Task_2_Stack[0]); //任务3初始化
#ifdef RT_OS_EN
ET2=1; //定时器2开中断
TR2=1; //启动定时器2
#endif
OS_Start(); //OS开始调度
}
//#endif
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
OS51_scheduler.rar (17个子文件)
OS51_scheduler
LIB_TEST
LIB_TEST.M51 23KB
TestMain.OBJ 10KB
LIB_TEST 13KB
osLIB_TEST.uvopt 5KB
LIB_TEST.plg 23KB
DGLIBD.LIB 6KB
LIB_TEST_Uv2.Bak 2KB
osLIB_TEST.uvgui.Administrator 88KB
osLIB_TEST.uvproj 14KB
Core.H 4KB
LIB_TEST.uvgui.Administrator 89KB
TestMain.LST 8KB
LIB_TEST.lnp 65B
LIB_TEST_Opt.Bak 1KB
LIB_TEST.build_log.htm 1KB
TestMain.c 4KB
LIB_TEST.uvopt 7KB
共 17 条
- 1
资源评论
Yorange988
- 粉丝: 0
- 资源: 38
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功