common.h 1.2 KB

1234567891011121314151617181920
  1. #ifndef _COMMON_H
  2. #define _COMMON_H
  3. #include "stm8s103f.h"
  4. typedef unsigned int uint;
  5. typedef unsigned char uchar;
  6. #define MAXTASKS 5
  7. extern volatile unsigned short timers[MAXTASKS];
  8. #define _SS static unsigned char _lc=0; switch(_lc){default:
  9. #define _EE ;}; _lc=0; return 65535;
  10. #define WAITX(tickets) do { _lc=(__LINE__%255)+1; return (tickets) ;case (__LINE__%255)+1:;} while(0);
  11. #define WAITUNTIL(A) do { while(!(A)) WaitX(1);} while(0);
  12. #define RUNTASK(TaskName,TaskID) do { if (timers[TaskID]==0) { unsigned short d=TaskName(); while(timers[TaskID]!=d) timers[TaskID]=d;} } while(0);
  13. #define RUNTASKA(TaskName,TaskID) do { if (timers[TaskID]==0) {unsigned short d=TaskName(); while(timers[TaskID]!=d) timers[TaskID]=d; continue;} }while(0); //前面的任务优先保证执行
  14. #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);
  15. #define INITTASKS() do {unsigned char i; for(i=MAXTASKS;i>0 ;i--) timers[i-1]=0; } while(0);
  16. #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);
  17. #endif