200 likes | 406 Views
TinyOS Tutorial. TinyOS Tutorial. Lesson 1 : Getting Started with TinyOS and nesC (Hanback’s zigbeX & TinyOS ver.1.1.7). Embedded System Lab. 2007. 1. 11. HyounSoo. Kim. Contents. 1. 2. 4. 3. 5. Introduction to TinyOS. Example : Blink. Installation and Configuration - zigbeX.
E N D
TinyOS Tutorial TinyOS Tutorial Lesson 1 : Getting Started with TinyOS and nesC(Hanback’s zigbeX & TinyOS ver.1.1.7) Embedded System Lab. 2007. 1. 11 HyounSoo. Kim
Contents 1 2 4 3 5 Introduction to TinyOS Example : Blink Installation and Configuration - zigbeX TinyOS Simulation - TinyViz Fusing the application - PonyProg2000 ① Introduction to Blink ② Main & RealMain Component ③ Blink Component ④ SingleTimer Component
1. Introduction to TinyOS (1 of 4) • What is TinyOS? • An operation system • An open-source development environment • A programming language and model (NesC) • A set of services • Main Ideology • HURRY UP AND SLEEP!! • Sleep as often as possible to save power • High concurrency, interrupt driven (no polling) • Data Memory Model • Static Memory allocation • Global variables(global) • Local variables(stack) : Declared within a method Stack Free 4KB Global
1. Introduction to TinyOS (2 of 4) • Programming Model • Separation of construction and composition • Programs are built out of components • Each component is specified by an interface • Provides “hooks” for wiring components together • Components are statically wired together based ontheir interfaces : Increases runtime efficiency • Components • Components use and provide interfaces, commands and events • Specified by a component’s interface • The word “interface” has two meanings in TinyOS • Components implement the events they use andthe commands they provide
1. Introduction to TinyOS (3 of 4) • Types of Components • There are two types of components: • Modules: Implement the application behavior • Configurations: Wires components together • A component does not care if another component isa module or configuration • A component may be composed of other components • TinyOS Thread Model • Tasks: • Time flexible • Longer background processing jobs • Atomic with respect to other tasks (single threaded) • Preempted by events
1. Introduction to TinyOS (4 of 4) • TinyOS Thread Model • Events: • Time critical, Interrupt task • Shorter duration (hand off to task if need be) • Last-in first-out semantics (no priority among events) • Component Hierarchy • Components are wired together by connecting users with providers • Forms a hierarchy • Commands: • Flow downwards, Control returns to caller • Events: • Flow upwards, Control returns to signaler • Events can call Commands but not vice versa
2. Installation and Configuration - zigbeX (1 of 2) • Download TinyOS from : • http://www.tinyos.net/dist-1.1.0/tinyos/windows/ • This Version 1.1.7 (or whatever is the latest) • Version release notes available here: • http://www.tinyos.net/tinyos-1.x/doc/ • The install puts TinyOS in C:\Program Files\UCB\ • TinyOS is installed C:\Program Files\UCB\cygwin\opt\tinyos-1.x • Patch the Hanback zigbeX • Connect the Hanback Webpage - http://www.hanback.co.kr • Login 다운로드 유비쿼터스 센서 네트워크 • ZigbeX 프로그램 Version 1.3 다운로드hanback_zigbex_ProgramV1_3.zip • C:\Program Files\UCB\cygwin\opt\ 폴더에 압축을 풀어서 복사 • Cygwin 실행해서 \opt\폴더로 이동 후 Install.sh 실행 ./install.sh
2. Installation and Configuration - zigbeX (2 of 2) • Customizing the Environment • Add aliases to C:\Program Files\UCB\cygwin\etc\profile • alias cdjava="cd /opt/tinyos-1.x/tools/java" • alias cdtos="cd /opt/tinyos-1.x/tos" • alias cdapps="cd /opt/tinyos-1.x/apps“ • The make System • From within the application’s directory: • make (re)install.<node id> <platform> • <node id> is an integer between 0 and 255 • <platform> may be zigbeX, mica2, mica2dot, or all • make <platform> docs • Generates documentation in <tos>/doc/nesdoc/<platform> • make pc • Generates an executable that can be run a pc for simulation • make clean
① Introduction to Blink (1 of 2) 3. Example : Blink • "Blink" • found in apps/Blink in the TinyOS tree. • 1Hz 간격으로 모트의 빨간 LED Toggle(On and Off) • Blink application is composed of two components: • configuration : “Blink.nc” • Blink 프로그램에서 컴포넌트 간의 전체적인 흐름을 이어주는 역할 • module : "BlinkM.nc" • 실질적인 Blink 프로그램에 대한 구현을 제공한 모듈
RealMain Interface(provides) Pot HardwareInit StdControl Component Interface(uses) Pot Init PotC HPLInit Main StdControl Pot StdControl PotM BlinkM ① Introduction to Blink(2 of 2) HPLPot Leds Timer Leds Timer StdControl Timer StdControl LedsC SingleTimer TimerC HPLPot Timer StdControl TimerM HPLPotC Leds PowerManagement Clock PowerManagement Clock StdControl HPLPowerManagementM ClockC Leds Clock StdControl NoLeds HPLClock 3. Example : Blink • Overview
RealMain Pot HardwareInit StdControl Pot Init PotC HPLInit Main StdControl Pot PotM HPLPot ② Main & RealMain Component HPLPot HPLPotC 3. Example : Blink • RealMain • Main.nc • tos/system/Main.nc • TinyOS application에서 맨 처음 수행되는 콤포넌트 • Main.StdControl.init() 이 최초로 호출되고, 다음에 • Main.StdControl.start() 가 실행된다. configuration Main { uses interface StdControl; } implementation { components RealMain, PotC, HPLInit; StdControl = RealMain.StdControl; RealMain.hardwareInit -> HPLInit; RealMain.Pot -> PotC; } ※ TinyOS는 3계층 구조(Hardware Abstraction Architecture – HAA)를 가진다. - HPL : Hardware Presentation Layer - HAL : Hardware Abstraction Layer - HIL : Hardware Independent Layer
Main StdControl StdControl BlinkM Leds Timer Leds Timer StdControl LedsC SingleTimer ③ Blink Component(1 of 3) 3. Example : Blink • Blink.nc configuration Blink { } // no external interfaces implementation{ components Main, BlinkM, SingleTimer, LedsC;Main.StdControl -> BlinkM.StdControl;Main.StdControl -> SingleTimer.StdControl; // multipleBlinkM.Timer -> SingleTimer.Timer;BlinkM.Leds -> LedsC; // implicit } • Interface StdControl • tos/interfaces/StdControl.nc • init(): 초기화될 때 • start(): 최초로 실행될 때 • stop(): 실행이 중지될 때 interface StdControl { command result_t init(); command result_t start(); command result_t stop(); } StdControl init start stop
Main StdControl StdControl BlinkM Leds Timer Leds Timer StdControl LedsC SingleTimer ③ Blink Component(2 of 3) 3. Example : Blink • BlinkM.nc module BlinkM { provides { // BlinkM이 구현 interface StdControl; } uses { // 인터페이스를 제공하는 모듈이 구현 interface Timer; interface Leds; } } implementation{ command result_t StdControl.init() { call Leds.init(); return SUCCESS; } command result_t StdControl.start() { return call Timer.start(TIMER_REPEAT, 1000) ; } command result_t StdControl.stop() { return call Timer.stop(); } event result_t Timer.fired() { call Leds.redToggle(); return SUCCESS; } } • provides: • Implements the StdControl interface. • uses: • Timer와 Leds가 제공하는 command를 호출할 수 있다. • Timer와 Leds가 제공하는 events를 구현하여야 한다.
Main StdControl StdControl BlinkM Leds Timer Leds Timer StdControl LedsC SingleTimer ③ Blink Component(3 of 3) 3. Example : Blink • Interface Leds interface Leds { async command result_t init(); async command result_t redOn(); async command result_t redOff(); async command result_t redToggle(); // 현재 상태와 반대 async command result_t greenOn(); async command result_t greenOff(); async command result_t greenToggle(); async command result_t yellowOn(); async command result_t yellowOff(); async command result_t yellowToggle(); async command uint8_t get(); // 3비트의 값을 읽음 async command result_t set(uint8_t value); // 3비트의 값으로 설정 }
Timer StdControl Timer StdControl SingleTimer TimerC Timer[id] StdControl TimerM Leds PowerManagement Clock PowerManagement Clock StdControl HPLPowerMangementM ClockC Clock StdControl HPLClock ④ SingleTimer Component(1 of 2) Leds NoLeds 3. Example : Blink • SingleTimer.nc configuration SingleTimer { provides interface Timer;provides interface StdControl; } implementation { components TimerC;Timer = TimerC.Timer[unique("Timer")];StdControl = TimerC; } • TimerC configuration TimerC { provides interface Timer[uint8_t id]; provides interface StdControl; } implementation { ... }
Timer StdControl Timer StdControl SingleTimer TimerC Timer[id] StdControl TimerM Leds PowerManagement Clock PowerManagement Clock StdControl HPLPowerMangementM ClockC Clock StdControl HPLClock ④ SingleTimer Component(2 of 2) Timer start stop fired Leds NoLeds 3. Example : Blink • Timer Interface includes Timer; interface Timer { command result_t start(char type, uint32_t interval); command result_t stop(); event result_t fired(); } • two types of timer • TIMER_REPEAT • TIMER_ONE_SHOT • Interval (miliseconds) 시간이 지나면 fired event발생 • event는 사용자(uses) 측에서 구현
4. TinyOS Simulation - TinyViz (1 of 2) • TinyViz - Java Application Program for TinyOS Simulation • Compiling the Blink application • Compile • cd apps/<application> directiry • make <platform> • platform: pc, mica, zigbex • Output • apps/<application>/build/<platform>/ • < Cygwin 1: 먼저 실행> • $ <directory>/main –gui n • csca_cbnu@csca1 /opt/tinyos-1.x/apps/Blink • $ build/pc/main –gui 1 // 1개의 mote를 gui 환경에서 test 하기 위해 실행 • < Cygwin 2: 나중 실행> • $ cd /opt/tinyos-1/tools/java • $ java net/tinyos/sim/TinyViz // TinyViz를 java application으로 실행
4. TinyOS Simulation - TinyViz (2 of 2) • Running the TinyViz Delay 설정 시작 or 멈춤 mote
5. Fusing the application - PonyProg2000 • PonyProg2000 Setup • I/O port setup Probe • File Open Fusing