例程目录tinyos-main-release_tinyos_2_1_2\apps\cc2538_Test\blink,包含三个文件:Makefile,BlinkAppC.nc,BlinkC.nc
下面将通过该例程讲解TinyOS nesC的语法:
1,TinyOS的nesC文件分为四种,除了Makefile后缀为.nc文件,Makefile,configuration,module,interface,当然C语言的c,cpp,h文件TinyOS支持,可以去博客看一下TinyOS如何使用C文件
2,关键字介绍: components provides uses call post task as async signal
1,Makefile
COMPONENT=BlinkAppC
CFLAGS += -DUSE_TIMER_HANDLER
include $(MAKERULES)
configuration对应即为BlinkAppC.nc文件
moudle对应为BlinkC.nc文件
Makefile的基础写法:
COMPONENT=xx
...
include $(MAKERULES)
COMPONENT(configuration的名称,注意components关键字的区别)
include $(MAKERULES) 指定makerules,MAKERULES是环境变量,可以打开shell 输入: echo $MAKERULES查看
include $(MAKERULES) 指定makerules,MAKERULES是环境变量,可以打开shell 输入: echo $MAKERULES查看
2,BlinkApp.nc(TinyOS的configration文件)
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;
}
学习configuration的基础语法,当完成编写后对于使用者调用它就是components BlinkAppC;
configuration的代码结构为
configuration xxC{
... //1区
}
implementation{
... //2区
}
*注意xxC的名称应和xx.nc的名称保持一致;
components--只有configration文件和module文件可以作为components,注意和Makefile的COMPONENT的区别
*1区应该编写
provides interface xx;
uses interface xx;
provides