#ifndef _COMMON_H #define _COMMON_H #include "stm8s103f.h" typedef unsigned int uint; typedef unsigned char uchar; #define MAXTASKS 5 extern volatile unsigned short timers[MAXTASKS]; #define _SS static unsigned char _lc=0; switch(_lc){default: #define _EE ;}; _lc=0; return 65535; #define WAITX(tickets) do { _lc=(__LINE__%255)+1; return (tickets) ;case (__LINE__%255)+1:;} while(0); #define WAITUNTIL(A) do { while(!(A)) WaitX(1);} while(0); #define RUNTASK(TaskName,TaskID) do { if (timers[TaskID]==0) { unsigned short d=TaskName(); while(timers[TaskID]!=d) timers[TaskID]=d;} } while(0); #define RUNTASKA(TaskName,TaskID) do { if (timers[TaskID]==0) {unsigned short d=TaskName(); while(timers[TaskID]!=d) timers[TaskID]=d; continue;} }while(0); //前面的任务优先保证执行 #define CallSub(SubTaskName) do {unsigned short currdt; _lc=(__LINE__%255)+1; return 0; case (__LINE__%255)+1: currdt=SubTaskName(); if(currdt!=65535) return currdt;} while(0); #define INITTASKS() do {unsigned char i; for(i=MAXTASKS;i>0 ;i--) timers[i-1]=0; } while(0); #define UPDATETIMERS() do{unsigned char i; for(i=MAXTASKS;i>0 ;i--){if((timers[i-1]!=0)&&(timers[i-1]!=65535)) timers[i-1]--;}} while(0); #endif