setjmp构建简单协作式多任务系统
int creat_tsk(void(*entry)(int argc,void *argv),int argc,void *argv,int stksize);
#define WAITFOR(condition)do{
setjmp(tcb[tskid].env);
if(!(condition)){
tskid++;
if(tskid>=task_num)tskid=0;
longijmp(tcb[tskid].env,1);
}
}while(0)
(2)co-os.c文件清单
#include "co-os.h"
#if defined(X86_VC6)||defined(X86_BC5)
#define SAVE_SP(p) _asm mov p,esp
#define RESTORE_SP(p) _asm mov esp,p
#elif defined(AVR_GCC)
#include<io.h>
#define SAVE_SP(p) p=(int*)SP
#define RESTORE_SP(p) SP=(int)p
#elif defined(M68K_SDS)
#define SAVE_SP(p) asm("MOVE.L A7,{"#p"}")
#define RESTORE_SP(p) asm("MOVE.L {"#p"},A7")
#endif
TCB tcb[MAX_TSK];
Int task_num=1;
Int tskid;
Static int stktop,oldsp;
Void init_coos(int mainstk){
SAVE_SP(stktop);
stktop=stktop+sizeof(void(*)(void))/sizeof(int)
-(mainstk+sizeof(int)-1)/sizeof(int);
}
int creat_tsk(void(*entry)(int argc,void *argv),
int argc,void *argv,int stksize){
if(task_num>=MAX_TSK)terurn-1;
SAVE_SP(oldsp);
RESTORE_SP(stktop);
《setjmp构建简单协作式多任务系统(第3页)》