Boomerang Measure Time

From TinyOS Wiki
Revision as of 11:01, 6 April 2011 by Martinvilu (talk | contribs) (Added to the "Boomerang" Category)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

To measure elapsed time between events in Boomerang, use the LocalTime interface.

There are three basic time precisions available millisecond, 30us (32kHz), and microsecond. They are available in the components CounterMilliC, Counter32khzC, and CounterMicroC. For Tmote platforms, the millisecond and 32kHz clocks operate even when the MCU goes into low power mode, which is often in TinyOS -- so they are suitable for all forms of timing. The microsecond clock turns off when the MCU goes into low power mode, so it is only suitable for timing between events within a single task.

The LocalTime interface

 interface LocalTime<precision_tag> {
   async command uint32_t get();
 }

Example code

 configuration MyAppC {
 }
 implementation {
   components MyAppP;
   components CounterMilliC;
   MyAppP.LocalTime -> CounterMilliC;
 }
 module MyAppP {
   uses interface LocalTime<TMilli>;
 }
 implementation {
   task void some_task() {
     // ...
     t = call LocalTime.get();
     // ...
   }
 }

See TinyOS TEP 102 Timers for more information.

Update for Boomerang 2.0.3 and later

The microsecond timer now requires you first allocate the resource with the resource interfaces provided by an instance of TimerMicroResourceC before using CounterMicroC, like in this code fragment. This only applies to the microsecond timer; there is no change for the millisecond and 32kHz timers.

configuration MyAppC {
}
implementation {
  //...
  components new TimerMicroResourceC();
  MyAppP.TimerMicroResource -> TimerMicroResourceC;
}
module MyAppP {
  //...
  uses interface Resource as TimerMicroResource;
  uses interface LocalTime<TMicro>;
}
implementation {
  //...
  void fun() {
    call TimerMicroResource.request();
  }
  event void TimerMicroResource.granted() {
    benchmark_fun(); //uses LocalTime<TMicro>
    call TimerMicroResource.release();
  }
}