www.pudn.com > 51_00_OS.rar > OS_core.h, change:2006-02-24,size:2039b


/******************************************************* 
本程序只供学习使用,未经作者许可,不得用于其它任何用途 
 
OS_core.h file 
 
Created by Computer-lov 
Date: 2005.10.27 
 
Edit date:2006.2.24 
 
Version V1.0 
Copyright(C) Computer-lov 2005-2015 
All rigths reserved 
 
******************************************************/ 
 
#ifndef __OS_CORE_H__ 
#define __OS_CORE_H__ 
 
#define OS_Resource_Lack           0x0100 
#define OS_Task_Not_Exist          0x0200 
#define OS_Task_Cannot_Be_Killed   0x0300 
#define OS_Successful              0x0000 
 
//需要CPU统计,则定义此宏 
#define CPU_STAT 
 
 
//最大任务数 
//修改MAX_TASK可改变最大任务数,注意:现在最多可支持8个任务 
#define MAX_TASK 5 
 
//堆栈深度 
#define S_DEPTH 0x1B 
 
//保存切换任务时软件压栈字节数 
#define Num_PUSH_bytes 13 
 
//程序控制块结构 
typedef struct  
{ 
 unsigned char Task_SP;       //任务堆栈指针 
 unsigned char Priority;      //优先级,值越小,优先级越高 
 unsigned char Suspend;       //任务挂起标志 
 unsigned char Delay;         //延迟时钟节拍数 
 unsigned char data * MSG;         //消息指针 
}PCB; 
 
 
extern idata volatile PCB OS_pcb[MAX_TASK]; 
extern volatile unsigned char OS_Current_ID; 
extern volatile unsigned char OS_Running; 
extern volatile unsigned int OS_Run_Time; 
extern volatile unsigned char OS_Task_List; 
extern volatile unsigned char OS_En_Cr_Count; 
 
void OS_Init(void); 
unsigned int OS_Task_Create(unsigned char,unsigned int,unsigned char); 
unsigned int OS_Task_Kill(unsigned char); 
void OS_Delay(unsigned char); 
void OS_Suspend(void); 
unsigned char OS_Wait_Msg(unsigned char); 
void OS_Start(void); 
 
 
//发送消息 
#define OS_Send_Msg(sender,receiver,msg) if(receiver!=0){*(OS_pcb[(receiver)].MSG)=(msg);OS_pcb[(receiver)].Suspend=0;OS_Task_Switch();} 
 
#define OS_Enter_Critical()   EA=0;OS_En_Cr_Count++;                        /*进入临界段*/ 
#define OS_Exit_Critical()    if(OS_En_Cr_Count>=1){OS_En_Cr_Count--;if(OS_En_Cr_Count==0)EA=1;}  /*退出临界段*/ 
//上面两个必须配对使用,否则中断可能被关闭 
 
#endif