TinyOS nesC 实验二

Makefile
COMPONENT=BlinkAppC
include $(MAKERULES)

BlinkC.nc
#include "Timer.h"
#define min(a, b) ((a) < (b) ? (a) : (b))

module BlinkC @safe() {
  uses interface Timer<TMilli> as Timer0;
  uses interface Timer<TMilli> as Timer1;
  uses interface Timer<TMilli> as Timer2;
  uses interface Leds;
  uses interface Boot;
} implementation {
  uint32_t i = 0;
   
  event void Boot.booted() {
    call Timer0.startPeriodic(250);
    call Timer1.startPeriodic(500);
    call Timer2.startPeriodic(1000);
  }

  task void computeTask() {
    static uint32_t i = 0;
    uint32_t last = min(i + 10000, 400001);
    do {
      i++;
    } while (i < last);
    if (i >= 400001)
        i = 0;
    else
        post computeTask();
  } 

  event void Timer0.fired() {
    dbg("BlinkC", "Timer 0 fired @ %s.\n", sim_time_string());    
    call Leds.led0Toggle();
    post computeTask();
  }

  event void Timer1.fired() {
    dbg("BlinkC", "Timer 1 fired @ %s \n", sim_time_string());
    call Leds.led1Toggle();
    //post computeTask();
  }

  event void Timer2.fired() {
    dbg("BlinkC", "Timer 2 fired @ %s.\n", sim_time_string());
    call Leds.led2Toggle();
    //post computeTask();
  }
}

BlinkAppC.nc
configuration BlinkAppC {

} implementation {
  components MainC, BlinkC, LedsC;
  components new TimerMilliC() as Timer0;
  components new TimerMilliC() as Timer1;
  components new TimerMilliC() as Timer2;

  BlinkC -> MainC.Boot;
  BlinkC.Timer0 -> Timer0;
  BlinkC.Timer1 -> Timer1;
  BlinkC.Timer2 -> Timer2;
  BlinkC.Leds -> LedsC;
}



你可能感兴趣的:(TinyOS nesC 实验二)