[Tinyos-help] Platform specific code sections

Steve McKown rsmckown at yahoo.com
Thu Mar 1 07:48:38 PST 2007


On Thursday 01 March 2007 06:53, Alex Mason wrote:
> I haven't been able to find the answer to this question in the
> documentation, so here goes.  Is it possible to define platform specific
> code within TOS2.x applications?  I for example:
>
> If PLATFORM = Mica2  {
>   ...
>   ...
>   ...
>   }
> Else if PLATFORM = Micaz  {
>   ...
>   ...
>   ...
>   }

The best way to handle platform-specific code is to write components that 
abstract the platform specific behavior.  So for example, MyComponentC 
implements the platform-agnostic MyComponent interface.  Each platform has 
its own MyComponentC.  The code using MyComponentC is now platform agnostic.  
TimerMilliC is a good example of this strategy.

The heart of this concept is documented nicely in TEP2, which documents the 
architectural layering strategy for tos2 code: 
http://tinyos.cvs.sourceforge.net/*checkout*/tinyos/tinyos-2.x/doc/html/tep2.html

The TinyOS build system must be informed so that it can select the right 
MyComponentC.nc file when building for a given platform.  To wedge the code 
in, you could do something easy, like adding this to your Makefile:
	PFLAGS += platforms/$PLATFORM

This would give your application a separate local directory for each platform, 
where you could place platform-specific components.  If you are doing basic 
things and not creating support for new chipsets or platforms, this strategy 
might be good enough.  A more comprehensive strategy would be to follow the 
tos2 example of /opt/tinyos-2.x/tos/{chips,platforms,etc} using the .platform 
file, but this is also far more involved.

All the best,
Steve


More information about the Tinyos-help mailing list