Make and Compile lessons for Tinyos

转载 2012年03月27日 04:42:32

Lesson 13: TinyOS Toolchain
Last updated October 29 2006

This lesson describes the details of the TinyOS toolchain, includingthe build system, how to create your own Makefile, and how to find outmore information on the various tools included with TinyOS.

TinyOS Build System

As you saw in Lesson 1, TinyOS applicationsare built using a somewhat unconventional application of the make tool. For instance, in the apps/Blink directory,
$ make mica2
compiles Blink for the mica2 platform,
$ make mica2 install
compiles and installs (using the default parallel port programmer) Blinkfor the mica2, and
$ make mica2 reinstall mib510,/dev/ttyS0
installs the previously compiled mica2 version of Blink using the MIB510serial port programmer connected to serial port /dev/ttyS0.

As these examples show, the TinyOS build system is controlled by passingarguments to make that specify the target platform, the desired action, and various options. These arguments can be categorised as follows:

  • Target platform: one of the supported TinyOS platforms, e.g., mica2,telosb, tinynode. A target platform is always required,except when using the clean action.

  • Action: the action to perform. By default, the action is to compilethe application in the current directory, but you can also specify:
    • help: display a help message for the target platform.
    • install,N: compile and install. The N argument is optional and specifies the mote id (default 1).
    • reinstall,N: install only (fails if the application wasn't previously compiled). N is as for install.
    • clean: remove compiled application for all platforms.
    • sim: compile for the simulation environment for the specified platform (see Lesson 11 for details).
    Example: to compile for simulation for the micaz:
    $ make micaz sim
  • Compilation option: you can change the way compilation proceeds byspecifying:
    • debug: compile for debugging. This enables debugging, and turns off optimisations (e.g., inlining) that make debugging difficult.
    • debugopt: compile for debugging, but leave optimisations enabled. This can be necessary if compiling with debug gives code that is too slow, or if the bug only shows up when optimisation is enabled.
    • verbose: enable a lot of extra output, showing all commands executed by make 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).
    • wiring, nowiring: 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 telosb

    Additionally, you can pass additional compilation options by setting the CFLAGS environment variable when you invoke make. For instance, to compile apps/RadioCountoToLeds 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 writing Makefiles below).

  • Installation option: some platforms have multiple programmers, andsome programmers require options (e.g., to specify which serial portto use). The programmer is specified by including its name amongst themake arguments. Known programmers include bsl formsp430-based platforms and avrisp (STK500), dapa (MIB500and earlier), mib510 (MIB510) and eprb (MIB600) for micafamily motes.

    Arguments to the programmer are specified with a comma after theprogrammer 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 inyour mote documentation.

Customising the Build System

You may find that you are often specifying the same options, e.g., thatyour mib510 programmer is always connected to /dev/ttyS1 or that youwant to use channel 12 of the CC2420 radio rather than the defaultTinyOS 2 channel (26). To do this, put the following lines
MIB510 ?= /dev/ttyS1
in a file called Makelocal in the support/makedirectory. If you now compile in apps/RadioCountToLeds, youwill see:
$ make micaz install mib510
    compiling RadioCountToLedsAppC to a micaz binary
ncc -o build/micaz/main.exe -Os -DCC2420_DEF_CHANNEL=12 ... -lm
    compiled RadioCountToLedsAppC to build/micaz/main.exe
    installing micaz binary using mib510
uisp -dprog=mib510 -dserial=/dev/ttyS1 ...
The definition of PFLAGS passes an option to the nesCcompiler telling it to define the C preprocessor symbolCC2420_DEF_CHANNEL to 12. The CC2420 radio stack checksthe value of this symbol when setting its default channel.

The definition of MIB510 sets the value of theargument to the mib510 installation option, i.e.,

$ make micaz install mib510 
is now equivalent to
$ make micaz install mib510,/dev/ttyS1 
Note that the assignment to MIB510 was written using the ?=operator. If you just use regular assignment (=), then thevalue in Makelocal will override any value you specifyon the command line (which is probably not what you want...).

Makelocal can contain definitions for any makevariables used by the build system. Unless you understand the details ofhow this works, we recommend you restrict yourselves to defining:

  • PFLAGS: extra options to pass to the nesC compiler. Most often used to define preprocessor symbols as seen above.
  • X: set the argument for make argument x, e.g., MIB510 as seen above. You can, e.g., set the default mote id to 12 by adding INSTALL ?= 12 and REINSTALL ?= 12 to Makelocal.

Some useful preprocessor symbols that you can define with PFLAGS include:

  • DEFINED_TOS_AM_ADDRESS: the motes group id (default is 0x22).
  • CC2420_DEF_CHANNEL: CC2420 channel (default is 26).
  • CC1K_DEF_FREQ: CC1000 frequency (default is 434.845MHz).
  • TOSH_DATA_LENGTH: radio packet payload length (default 28).

Application Makefiles

To use the build system with your application, you must create a makefile(a file called Makefile) which contains at the minimum:
include $(MAKERULES)
where TopLevelComponent is the name of the top-level componentof your application.

TinyOS applications commonly also need to specify some options to thenesC compiler, and build some extra files alongside the TinyOSapplication. We will see examples of both, by looking at, and making asmall change to, the apps/RadioCountToLeds application.

The RadioCountToLeds Makefile uses mig (see Lesson 4) to build files describing the layoutof its messages, for use with python and Java tools:

BUILD_EXTRA_DEPS = RadioCountMsg.class RadioCountToLeds.h
	mig python -target=$(PLATFORM) $(CFLAGS) -python-classname=RadioCountMsg RadioCountToLeds.h RadioCountMsg -o $@

	javac RadioCountToLeds.h
	mig java -target=$(PLATFORM) $(CFLAGS) -java-classname=RadioCountMsg RadioCountToLeds.h RadioCountMsg -o $@

include $(MAKERULES)
The first and last line of this Makefile are the basic lines present inall TinyOS Makefiles; the line in bold defining BUILD_EXTRA_DEPSspecifies some additional make targets to build alongside themain TinyOS application (if you are not familiar with make, this may be agood time to read a make tutorial, e.g., thisone).

When you compile RadioCountToLeds for the first time, you will see thatthe two extra targets, and RadioCountMsg.class, are automatically created:

$ make mica2
mkdir -p build/mica2
mig python -target=mica2  -python-classname=RadioCountMsg RadioCountToLeds.h RadioCountMsg -o
mig java -target=mica2  -java-classname=RadioCountMsg RadioCountToLeds.h RadioCountMsg -o
    compiling RadioCountToLedsAppC to a mica2 binary
As this Makefile is written, these generated files are not deleted whenyou execute make clean. Fix this by adding the following line:
to apps/RadioCountToLeds/Makefile. This defines the CLEAN_EXTRAmake variable to be the same as BUILD_EXTRA_DEPS, with RadioCountMsg.javaadded to the end. The build system's clean target deletes all filesin CLEAN_EXTRA:
$ make clean
rm -rf build RadioCountMsg.class
rm -rf TOSSIM.pyc
Finally, to see how to pass options to the nesC compiler, we will changeRadioCountToLeds's source code to set the message sending period basedon the preprocessor symbol SEND_PERIOD. Change the line that reads
 call MilliTimer.startPeriodic(1000);
 call MilliTimer.startPeriodic(SEND_PERIOD);
and add the following line to RadioCountToLeds's Makefile:
Note the use of += when defining CFLAGS: this allows the userto also pass options to nesC when invoking make as we saw above (env CFLAGS=x make ...).

Now compiling RadioCountToLeds gives:

$ make mica2
    compiling RadioCountToLedsAppC to a mica2 binary
ncc -o build/mica2/main.exe ... -DSEND_PERIOD=2000 ... -lm
    compiled RadioCountToLedsAppC to build/mica2/main.exe

TinyOS Tools

The TinyOS build system is designed to make it easier to write Makefilesfor applications that support multiple platforms, programmers, etc ina uniform way. However, it's use is not compulsory, and all the tools itis built on can be used in your own build system (e.g., your own Makefileor simple build script). Below we show how to build and install theRadioCountToLeds application for a micaz with the mib510 programmerusing just a few commands.

First, we compile (the main component ofthe application) using the nesC compiler, ncc:

$ ncc -target=micaz -o rcl.exe -Os -finline-limit=100000 -Wnesc-all -Wall
This generates an executable file, rcl.exe. Next, we wantto install this program on a mote with mote id 15. First, we create anew executable, rcl.exe-15, where the variables storing themote's identity are changed to 15, using thetos-set-symbols command:
$ tos-set-symbols rcl.exe rcl.exe-15 TOS_NODE_ID=15 ActiveMessageAddressC\$addr=15
Finally, we install this executable on the micaz using uisp, to a mib510 programmer connected to port /dev/ttyUSB1:
$ uisp -dpart=ATmega128 -dprog=mib510 -dserial=/dev/ttyUSB1 --erase --upload if=rcl.exe-15
Firmware Version: 2.1
Atmel AVR ATmega128 is found.
Uploading: flash
If you wish to follow this route, note two things: first, you can find outwhat commands the build system is executing by passing the -noption to make, which tells it to print rather than execute commands:
$ make -n micaz install.15 mib510
mkdir -p build/micaz
echo "    compiling RadioCountToLedsAppC to a micaz binary"
ncc -o build/micaz/main.exe -Os -finline-limit=100000 -Wall -Wshadow -Wnesc-all -target=micaz -fnesc-cfile=build/micaz/app.c -board=micasb  -fnesc-dump=wiring -fnesc-dump='interfaces(!abstract())' -fnesc-dump='referenced(interfacedefs, components)' -fnesc-dumpfile=build/micaz/wiring-check.xml -lm
nescc-wiring build/micaz/wiring-check.xml
Second, all the commands invoked by the build system should have man pagesdescribing their behaviour and options. For instance, try the followingcommands:
$ man tos-set-symbols
$ man ncc
$ man nescc

Related Documentation

  • mica mote Getting Started Guide at Crossbow
  • telos mote Getting Started Guide for Moteiv
  • Lesson 1 introduced the build system.
  • Lesson 10 describes how to add a new platformto the build system.
  • GNU make man page.
  • man pages for the nesC compiler (man ncc, man nescc) and the variousTinyOS tools.

Previous Lesson  |  Top >


Ubuntu-14.04下安装TinyOS-2.1.2 参考:
  • qiao_yihan
  • qiao_yihan
  • 2015年07月03日 13:28
  • 2329


TinySec可以用TOSSIM仿真出来。          当accesscontrol layer 求得信道的时候,它启动TinySecM。          进行计算,作者使TinySec中...
  • boliangzai
  • boliangzai
  • 2015年10月23日 10:41
  • 199


1.编译程序并烧写至节点中。 在控制台中输入make telosb install,1 bsl,/dev/ttyUSB1 表示将节点编号为1(TOS_NODE_ID = 1),并编译烧写至USB1...
  • qq_21411985
  • qq_21411985
  • 2015年03月29日 22:03
  • 781


TinyOS学习笔记2   2010.8.3 3.测试TinyOS中的Toosim make micaz sim 提示找不到python2.5 查看本机python的版本,我的版本为2.6...
  • guoxuequan
  • guoxuequan
  • 2010年11月26日 15:21
  • 5894

解决在Windows XP SP2下不能显示验证码的方法[注册表文件]

REGEDIT4[HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Internet Explorer/Security]"BlockXBM"=dword:00000000 ...
  • KimSoft
  • KimSoft
  • 2006年06月13日 11:01
  • 2068

IAR 中 Compile、Make和Build的区别

make (常用) 编译,连接当前工程。(编译只编译有改动文件,或者设置变动的文件,工程窗口文件右边会有个*号)  compile  只编译当前源文件。 (不管文件是否改动,或者设置是否变动...
  • ahchai
  • ahchai
  • 2015年03月18日 17:21
  • 3744


  • utnewbear
  • utnewbear
  • 2011年03月17日 11:45
  • 3344

Compile,Make,Build 几种编译命令的区别

Compile、Make和Build的区别   针对Java的开发工具,一般都有Compile、Make和Build三个菜单项,完成的功能的都差不多,但是又有区别。   编译,...
  • luoweile
  • luoweile
  • 2016年11月18日 06:06
  • 784


关于Intellij IDEA菜单项中Compile、Make和Build的区别 前两天试了试NetBeans,在编辑方面感觉还是不太满意,于是又换了大牛同事口中的“神器”——Intellij ID...
  • shenjianxz
  • shenjianxz
  • 2016年05月24日 10:50
  • 884


针对Java的开发工具,一般都有Compile、Make和Build三个菜单项,完成的功能的都差不多,但是又有区别。   编译,是将源代码转换为可执行代码的过程。编译需要指定源文件和编译输...
  • qeshining
  • qeshining
  • 2016年03月21日 13:58
  • 1424
您举报文章:Make and Compile lessons for Tinyos