每个平台都需要自己的文件夹存放相关驱动代码,位于tos/platforms/目录中。
$cd /opt/tinyos-2.1.2/tos/platforms
$mkdir yamp
每个平台目录都必须包含名为 的文件,包含该平台的基本编译参数。
tos/platforms/yamp/.platform :
- # Includes that should take precedence come first. Platforms come before
- # chips because they may override files. These must be specified as
- # @includes instead of -I's to @opts, otherwise the %T won't be processed
- # by ncc.
- push( @includes, qw(
- %T/chips/cc2420
- %T/chips/msp430
- %T/chips/msp430/adc12
- %T/chips/msp430/dma
- %T/chips/msp430/pins
- %T/chips/msp430/timer
- %T/chips/msp430/usart
- %T/chips/msp430/sensors
- %T/lib/timer
- %T/lib/serial
- %T/lib/power
- ) );
- @opts = qw(
- -gcc=msp430-gcc
- -mmcu=msp430f1611
- -fnesc-target=msp430
- -fnesc-no-debug
- -fnesc-scheduler=TinySchedulerC,TinySchedulerC.TaskBasic,TaskBasic,TaskBasic,runTask,postTask
- );
当编译基于该平台的应用程序时,编译器会默认地包含该文件。文件中可以定义相关平台的常量、引脚名称或者包含一些头文件。
tos/platforms/yamp/hardware.h :
- #ifndef _H_hardware_h
- #define _H_hardware_h
- #include "msp430hardware.h"
- // LEDs
- TOSH_ASSIGN_PIN(RED_LED, 5, 4);
- TOSH_ASSIGN_PIN(GREEN_LED, 5, 5);
- TOSH_ASSIGN_PIN(YELLOW_LED, 5, 6);
- // UART pins
- TOSH_ASSIGN_PIN(SOMI0, 3, 2);
- TOSH_ASSIGN_PIN(SIMO0, 3, 1);
- TOSH_ASSIGN_PIN(UCLK0, 3, 3);
- TOSH_ASSIGN_PIN(UTXD0, 3, 4);
- TOSH_ASSIGN_PIN(URXD0, 3, 5);
- TOSH_ASSIGN_PIN(UTXD1, 3, 6);
- TOSH_ASSIGN_PIN(URXD1, 3, 7);
- TOSH_ASSIGN_PIN(UCLK1, 5, 3);
- TOSH_ASSIGN_PIN(SOMI1, 5, 2);
- TOSH_ASSIGN_PIN(SIMO1, 5, 1);
- #endif // _H_hardware_h
引入 msp430hardware.h 头文件实现一些微处理器的重要功能,如休眠、atomic代码块的中断禁用;宏指令重新定义管脚名称。 TOSH_ASSIGN_PIN(RED_LED, 5, 4); RED_LED (红色LED灯)被绑定到5.4号通道I/O口。
$cd /opt/tinyos-2.1.2/tos/platforms/yamp
$touch platform.h
每个平台必须有一个名为“platform.h”的文件,即使内容为空。
此时进入app/Null,编译环境:
error显示系统无法识别yamp平台。
support/make/yamp.target :
- PLATFORM = yamp
- $(call TOSMake_include_platform,msp)
- yamp: $(BUILD_DEPS)
- @:
再次测试编译环境:
系统已经识别yamp平台,但是找不到PlatformC组件。在系统启动过程中,特定的硬件的初始化直接由每个平台的PlatformC组件处理,提供Init接口。所以每个平台必须定义该组件。
tos/platforms/yamp/PlatformP.nc :
- /*$ID:PlatformP.nc, v 1.0, 2013-3-29
- *
- *The yamp portion which is an imaginary mote is mote-specific.It has a MSP430
- * microcontroller and a CC2420 radio transceiver.
- *
- *@author Nick
- */
- #include "hardware.h"
- module PlatformP{
- provides interface Init;
- uses interface Init as Msp430ClockInit;
- uses interface Init as LedsInit;
- }
- implementation {
- command error_t Init.init() {
- call Msp430ClockInit.init();
- call LedsInit.init();
- return SUCCESS;
- }
- default command error_t LedsInit.init() {
- return SUCCESS;
- }
- }
tos/platforms/yamp/PlatformC.nc :
- /*$ID:PlatformC.nc, v 1.0, 2013-3-29
- *
- *The yamp portion which is an imaginary mote is mote-specific.
- *
- *@author Nick
- */
- #include "hardware.h"
- configuration PlatformC
- {
- provides interface Init;
- }
- implementation
- {
- components PlatformP,Msp430ClockC;
- Init = PlatformP;
- PlatformP.Msp430ClockInit -> Msp430ClockC.Init;
- }
再次测试编译环境:
用yamp平台测试Blink程序
error显示在编译LedC组件时无法找到PlatformLedsC组件。PlatformLedsC组件时平台相关组件,通常一个LED灯连接到微处理器一个
I/O引脚,由引脚的输出电平觉得点亮和关闭,在不同的硬件平台上,每个LED灯连接到微处理器的引脚是不同的,所以LED得开关必须根据具体
的硬件平台实现。
tos/platforms/yamp/PlatformLedsC.nc :
- /*$ID:PlatformLedsC.nc, v 1.0, 2013-3-29
- *
- *"PlatformLedsC" is a platform-specific component.Thus we need to define this
- * component for the yamp platform.The PlatformLedsC configuration provides
- * three GeneralIO interfaces and an Init.
- *
- *@author Nick
- */
- #include "hardware.h"
- configuration PlatformLedsC {
- provides interface GeneralIO as Led0;
- provides interface GeneralIO as Led1;
- provides interface GeneralIO as Led2;
- uses interface Init;
- }
- implementation
- {
- components
- HplMsp430GeneralIOC as GeneralIOC,
- new Msp430GpioC() as Led0Impl,
- new Msp430GpioC() as Led1Impl,
- new Msp430GpioC() as Led2Impl;
- components PlatformP;
- Init = PlatformP.LedsInit;
- Led0 = Led0Impl;
- Led0Impl -> GeneralIOC.Port54;
- Led1 = Led1Impl;
- Led1Impl -> GeneralIOC.Port55;
- Led2 = Led2Impl;
- Led2Impl -> GeneralIOC.Port56;
- }
3个LED灯分别被连接到MSP430的5.4、5.5、5.6三个引脚。
再次编译Blink程序: