A Task Dispatcher for Embedded Systems
by Ron Kreymborgi



Listing One
InitMulti();
QueTask(TaskA);
while (TRUE) {
   Dispatch();
   }



Listing Two
TurnLedOn(){
   if (switchOn) {
      outp(PORTB,0x01);
      QueTask(TurnLedOff);
      }
   else
      ReRunMe(0);
}
TurnLedOff() {
   if (!switchOn) {
      outp(PORTB,0x00);
      QueTask(TurnLedOn);
      }
   else
      ReRunMe(0);
}


Listing Three
CheckRunMotor() {
   if (flag) {
      StartMotor();
      QueDelay(StopMotor, 80);
      }
   else
      ReRunMe(0);
}


Listing Four
TurnLedOn(){
   if (switchOn) {
      Led = 1;
      LedOn();
      QueTask(TurnLedOff);
      }
   else
      ReRunMe(1);
}
TurnLedOff() {
   if (!switchOn) {
      Led = 0;
      QueTask(TurnLedOn);
      }
   else
      ReRunMe(1);
}
LedOn() {
   outp(PORTB, 0x01);
   QueDelay(LedOff, 8);
}

LedOff() {
   outp(PORTB, 0x00);
   if (Led)
      QueDelay(LedOn, 20);
}





Listing Five
int state;
void CheckSwitch(void) {
   int val;
   val = inp(PIND);
   if (val ^ state)
      QueDelay(CheckSwState, 3);
   else
      ReRunMe(1);
}
void CheckSwState(void) {
   int val;
   val = inp(PIND);
   if (val ^ state) {
      state = val;
      ChangedFlag = 1;
      }
   QueDelay(CheckSwitch, 3);
}

Listing Six
struct {
   char   status;
   int    delay;
   void   (*tpntr)();
   char   next;
   } task[TOTALTASKS+1];


2


