📄 tinyos toolchain - tinyos documentation wiki.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0049)http://docs.tinyos.net/index.php/TinyOS_Toolchain -->
<HTML lang=en dir=ltr xml:lang="en"
xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>TinyOS Toolchain - TinyOS Documentation Wiki</TITLE>
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
<META
content="TinyOS Toolchain,Getting Started with TinyOS,Mote-PC serial communication and SerialForwarder,Network Protocols,Platforms,TOSSIM,TinyOS Tutorials"
name=keywords><LINK href="/favicon.ico" rel="shortcut icon"><LINK
title="TinyOS Documentation Wiki (English)" href="/opensearch_desc.php"
type=application/opensearchdescription+xml rel=search>
<STYLE type=text/css media="screen, projection">@import url( /skins/common/shared.css?97 );
@import url( /skins/monobook/main.css?97 );
</STYLE>
<LINK media=print
href="TinyOS Toolchain - TinyOS Documentation Wiki.files/commonPrint.css"
type=text/css rel=stylesheet><!--[if lt IE 5.5000]><style type="text/css">@import "/skins/monobook/IE50Fixes.css?97";</style><![endif]--><!--[if IE 5.5000]><style type="text/css">@import "/skins/monobook/IE55Fixes.css?97";</style><![endif]--><!--[if IE 6]>
<STYLE type=text/css>@import url( /skins/monobook/IE60Fixes.css?97 );
</STYLE>
<![endif]--><!--[if IE 7]><style type="text/css">@import "/skins/monobook/IE70Fixes.css?97";</style><![endif]--><!--[if lt IE 7]>
<SCRIPT src="TinyOS Toolchain - TinyOS Documentation Wiki.files/IEFixes.js"
type=text/javascript></SCRIPT>
<META http-equiv=imagetoolbar content=no><![endif]-->
<SCRIPT type=text/javascript>/*<![CDATA[*/var skin = "monobook";var stylepath = "/skins";var wgArticlePath = "/index.php/$1";var wgScriptPath = "";var wgScript = "/index.php";var wgServer = "http://docs.tinyos.net";var wgCanonicalNamespace = "";var wgCanonicalSpecialPageName = false;var wgNamespaceNumber = 0;var wgPageName = "TinyOS_Toolchain";var wgTitle = "TinyOS Toolchain";var wgAction = "view";var wgRestrictionEdit = [];var wgRestrictionMove = [];var wgArticleId = "18";var wgIsArticle = true;var wgUserName = null;var wgUserGroups = null;var wgUserLanguage = "en";var wgContentLanguage = "en";var wgBreakFrames = false;var wgCurRevisionId = "297";/*]]>*/</SCRIPT>
<SCRIPT src="TinyOS Toolchain - TinyOS Documentation Wiki.files/wikibits.js"
type=text/javascript><!-- wikibits js --></SCRIPT>
<SCRIPT src="TinyOS Toolchain - TinyOS Documentation Wiki.files/index.php"
type=text/javascript><!-- site js --></SCRIPT>
<STYLE type=text/css>@import url( /index.php?title=MediaWiki:Common.css&usemsgcache=yes&action=raw&ctype=text/css&smaxage=18000 );
@import url( /index.php?title=MediaWiki:Monobook.css&usemsgcache=yes&action=raw&ctype=text/css&smaxage=18000 );
@import url( /index.php?title=-&action=raw&gen=css&maxage=18000 );
</STYLE>
<!-- Head Scripts -->
<SCRIPT src="TinyOS Toolchain - TinyOS Documentation Wiki.files/ajax.js"
type=text/javascript></SCRIPT>
<META content="MSHTML 6.00.2900.3268" name=GENERATOR></HEAD>
<BODY class="mediawiki ns-0 ltr page-TinyOS_Toolchain">
<DIV id=globalWrapper>
<DIV id=column-content>
<DIV id=content><A id=top name=top></A>
<H1 class=firstHeading>TinyOS Toolchain</H1>
<DIV id=bodyContent>
<H3 id=siteSub>From TinyOS Documentation Wiki</H3>
<DIV id=contentSub></DIV>
<DIV id=jump-to-nav>Jump to: <A
href="http://docs.tinyos.net/index.php/TinyOS_Toolchain#column-one">navigation</A>,
<A
href="http://docs.tinyos.net/index.php/TinyOS_Toolchain#searchInput">search</A></DIV><!-- start content -->
<P>This lesson describes the details of the TinyOS toolchain, including the
build system, how to create your own Makefile, and how to find out more
information on the various tools included with TinyOS. </P>
<TABLE class=toc id=toc summary=Contents>
<TBODY>
<TR>
<TD>
<DIV id=toctitle>
<H2>Contents</H2></DIV>
<UL>
<LI class=toclevel-1><A
href="http://docs.tinyos.net/index.php/TinyOS_Toolchain#TinyOS_Build_System"><SPAN
class=tocnumber>1</SPAN> <SPAN class=toctext>TinyOS Build
System</SPAN></A>
<LI class=toclevel-1><A
href="http://docs.tinyos.net/index.php/TinyOS_Toolchain#Customising_the_Build_System"><SPAN
class=tocnumber>2</SPAN> <SPAN class=toctext>Customising the Build
System</SPAN></A>
<LI class=toclevel-1><A
href="http://docs.tinyos.net/index.php/TinyOS_Toolchain#Application_Makefiles"><SPAN
class=tocnumber>3</SPAN> <SPAN class=toctext>Application
Makefiles</SPAN></A>
<LI class=toclevel-1><A
href="http://docs.tinyos.net/index.php/TinyOS_Toolchain#TinyOS_Tools"><SPAN
class=tocnumber>4</SPAN> <SPAN class=toctext>TinyOS Tools</SPAN></A>
<LI class=toclevel-1><A
href="http://docs.tinyos.net/index.php/TinyOS_Toolchain#Related_Documentation"><SPAN
class=tocnumber>5</SPAN> <SPAN class=toctext>Related
Documentation</SPAN></A> </LI></UL></TD></TR></TBODY></TABLE>
<SCRIPT type=text/javascript> if (window.showTocToggle) { var tocShowText = "show"; var tocHideText = "hide"; showTocToggle(); } </SCRIPT>
<A name=TinyOS_Build_System></A>
<H1><SPAN class=mw-headline>TinyOS Build System</SPAN></H1>
<P>As you saw in <A title="Getting Started with TinyOS"
href="http://docs.tinyos.net/index.php/Getting_Started_with_TinyOS">Lesson
1</A>, TinyOS applications are built using a somewhat unconventional application
of the <I>make</I> tool. For instance, in the <CODE>apps/Blink</CODE> directory,
</P><PRE>$ make mica2
</PRE>
<P>compiles Blink for the mica2 platform, </P><PRE>$ make mica2 install
</PRE>
<P>compiles and installs (using the default parallel port programmer) Blink for
the mica2, and </P><PRE>$ make mica2 reinstall mib510,/dev/ttyS0
</PRE>
<P>installs the previously compiled mica2 version of Blink using the MIB510
serial port programmer connected to serial port /dev/ttyS0. </P>
<P>As these examples show, the TinyOS build system is controlled by passing
arguments to make that specify the target platform, the desired action, and
various options. These arguments can be categorised as follows: </P>
<UL>
<LI>Target platform: one of the supported TinyOS platforms, e.g.,
<B>mica2</B>, <B>telosb</B>, <B>tinynode</B>. A target platform is always
required, except when using the <B>clean</B> action.
<LI>Action: the action to perform. By default, the action is to compile the
application in the current directory, but you can also specify:
<UL>
<LI><B>help</B>: display a help message for the target platform.
<LI><B>install,<I>N</I></B>: compile and install. The <I>N</I> argument is
optional and specifies the mote id (default 1).
<LI><B>reinstall,<I>N</I></B>: install only (fails if the application wasn't
previously compiled). <I>N</I> is as for <B>install</B>.
<LI><B>clean</B>: remove compiled application for all platforms.
<LI><B>sim</B>: compile for the simulation environment for the specified
platform (see <A title=TOSSIM
href="http://docs.tinyos.net/index.php/TOSSIM">Lesson 11</A> for details).
Example: to compile for simulation for the micaz: $ make micaz sim </LI></UL>
<LI>Compilation option: you can change the way compilation proceeds by
specifying:
<UL>
<LI><B>debug</B>: compile for debugging. This enables debugging, and turns
off optimisations (e.g., inlining) that make debugging difficult.
<LI><B>debugopt</B>: compile for debugging, but leave optimisations enabled.
This can be necessary if compiling with <B>debug</B> gives code that is too
slow, or if the bug only shows up when optimisation is enabled.
<LI><B>verbose</B>: enable a lot of extra output, showing all commands
executed by <I>make</I> and the details of the nesC compilation including
the full path of all files loaded. This can be helpful in tracking down
problems (e.g., when the wrong version of a component is loaded).
<LI><B>wiring</B>, <B>nowiring</B>: enable or disable the use of the
nescc-wiring to check the wiring annotations in a nesC program. See the
nescc-wiring man page for more details. Example: to do a verbose compilation
with debugging on the telosb: $ make debug verbose telosbAdditionally, you
can pass additional compilation options by setting the CFLAGS environment
variable when you invoke make. For instance, to compile
<CODE>apps/RadioCountoToLeds</CODE> for a mica2 with a 900MHz radio set to
~916.5MHz, you would do: $ env CFLAGS="-DCC1K_DEF_FREQ=916534800" make mica2
Note that this will not work with applications whose Makefile defines CFLAGS
(but this practice is discouraged, see the section on <A title=""
href="http://docs.tinyos.net/index.php/TinyOS_Toolchain#Application_Makefiles">writing
Makefiles</A> below). </LI></UL>
<LI>Installation option: some platforms have multiple programmers, and some
programmers require options (e.g., to specify which serial port to use). The
programmer is specified by including its name amongst the <I>make</I>
arguments. Known programmers include <B>bsl</B> for msp430-based platforms and
<B>avrisp</B> (STK500), <B>dapa</B> (MIB500 and earlier), <B>mib510</B>
(MIB510) and <B>eprb</B> (MIB600) for mica family motes. Arguments to the
programmer are specified with a comma after the programmer name, e.g., $ make
mica2dot reinstall mib510,/dev/ttyUSB1 $ make telosb reinstall
bsl,/dev/ttyUSB1 to specify that the programmer is connected to serial port
/dev/ttyUSB1. More details on the programmers and their options can be found
in your mote documentation. </LI></UL><A name=Customising_the_Build_System></A>
<H1><SPAN class=mw-headline>Customising the Build System</SPAN></H1>
<P>You may find that you are often specifying the same options, e.g., that your
mib510 programmer is always connected to /dev/ttyS1 or that you want to use
channel 12 of the CC2420 radio rather than the default TinyOS 2 channel (26). To
do this, put the following lines </P><PRE>MIB510 ?= /dev/ttyS1
PFLAGS = -DCC2420_DEF_CHANNEL=12
</PRE>
<P>in a file called <CODE>Makelocal</CODE> in the <CODE>support/make</CODE>
directory. If you now compile in <CODE>apps/RadioCountToLeds</CODE>, you will
see: </P><PRE>$ make micaz install mib510
compiling RadioCountToLedsAppC to a micaz binary
ncc -o build/micaz/main.exe -Os <B>-DCC2420_DEF_CHANNEL=12</B> ... RadioCountToLedsAppC.nc -lm
compiled RadioCountToLedsAppC to build/micaz/main.exe
...
installing micaz binary using mib510
uisp -dprog=mib510 <B>-dserial=/dev/ttyS1</B> ...
</PRE>
<P>The definition of <CODE>PFLAGS</CODE> passes an option to the nesC compiler
telling it to define the C preprocessor symbol <CODE>CC2420_DEF_CHANNEL</CODE>
to 12. The CC2420 radio stack checks the value of this symbol when setting its
default channel. </P>
<P>The definition of <CODE>MIB510</CODE> sets the value of the argument to the
<B>mib510</B> installation option, i.e., </P><PRE>$ make micaz install mib510
</PRE>
<P>is now equivalent to </P><PRE>$ make micaz install mib510,/dev/ttyS1
</PRE>
<P>Note that the assignment to MIB510 was written using the <CODE>?=</CODE>
operator. If you just use regular assignment (<CODE>=</CODE>), then the value in
<CODE>Makelocal</CODE> will override any value you specify on the command line
(which is probably not what you want...). </P>
<P><CODE>Makelocal</CODE> can contain definitions for any <I>make</I> variables
used by the build system. Unless you understand the details of how this works,
we recommend you restrict yourselves to defining: </P>
<UL>
<LI><CODE>PFLAGS</CODE>: extra options to pass to the nesC compiler. Most
often used to define preprocessor symbols as seen above.
<LI><CODE><I>X</I></CODE>: set the argument for <I>make</I> argument <I>x</I>,
e.g., <CODE>MIB510</CODE> as seen above. You can, e.g., set the default mote
id to 12 by adding <CODE>INSTALL ?= 12</CODE> and <CODE>REINSTALL ?=
12</CODE> to <CODE>Makelocal</CODE>. </LI></UL>
<P>Some useful preprocessor symbols that you can define with <CODE>PFLAGS</CODE>
include: </P>
<UL>
<LI>DEFINED_TOS_AM_ADDRESS: the motes group id (default is 0x22).
<LI>CC2420_DEF_CHANNEL: CC2420 channel (default is 26).
<LI>CC1K_DEF_FREQ: CC1000 frequency (default is 434.845MHz).
<LI>TOSH_DATA_LENGTH: radio packet payload length (default 28). </LI></UL><A
name=Application_Makefiles></A>
<H1><SPAN class=mw-headline>Application Makefiles</SPAN></H1>
<P>To use the build system with your application, you must create a makefile (a
file called <CODE>Makefile</CODE>) which contains at the minimum: </P><PRE>COMPONENT=<I>TopLevelComponent</I>
include $(MAKERULES)
</PRE>
<P>where <I>TopLevelComponent</I> is the name of the top-level component of your
application. </P>
<P>TinyOS applications commonly also need to specify some options to the nesC
compiler, and build some extra files alongside the TinyOS application. We will
see examples of both, by looking at, and making a small change to, the
<CODE>apps/RadioCountToLeds</CODE> application. </P>
<P>The RadioCountToLeds Makefile uses <CODE>mig</CODE> (see <A
title="Mote-PC serial communication and SerialForwarder"
href="http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder">Lesson
4</A>) to build files describing the layout of its messages, for use with python
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -