Date post: | 01-Jan-2016 |
Category: |
Documents |
Upload: | delphine-manella |
View: | 57 times |
Download: | 0 times |
Presentation by HyounSoo. Kim
Embedded System LabEmbedded System Lab
ChungBuk National University
http://csca.chungbuk.ac.kr
Lesson 1 : Getting Started with TinyOS and nesC(Hanback’s zigbeX & TinyOS ver.1.1.7)
Embedded System Lab.
HyounSoo. Kim2007. 1. 11
Presentation by HyounSoo. Kim
Embedded System LabEmbedded System Lab
ChungBuk National University
http://csca.chungbuk.ac.kr
2 / 18
ContentsContentsContentsContents
11 Introduction to TinyOSIntroduction to TinyOSIntroduction to TinyOSIntroduction to TinyOS
22 Installation and Configuration Installation and Configuration - zigbeX- zigbeXInstallation and Configuration Installation and Configuration - zigbeX- zigbeX
33 Example : BlinkExample : BlinkExample : BlinkExample : Blink
① Introduction to BlinkIntroduction to Blink
② Main & RealMain ComponentMain & RealMain Component
③ Blink ComponentBlink Component
④ SingleTimer ComponentSingleTimer Component
44 TinyOS Simulation - TinyVizTinyOS Simulation - TinyVizTinyOS Simulation - TinyVizTinyOS Simulation - TinyViz
55 Fusing the application - PonyProg2000Fusing the application - PonyProg2000Fusing the application - PonyProg2000Fusing the application - PonyProg2000
Presentation by HyounSoo. Kim
Embedded System LabEmbedded System Lab
ChungBuk National University
http://csca.chungbuk.ac.kr
3 / 18
1. Introduction to TinyOS (1 of 4)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
StackStack
FreeFree
GlobalGlobal
4KB4KB
Presentation by HyounSoo. Kim
Embedded System LabEmbedded System Lab
ChungBuk National University
http://csca.chungbuk.ac.kr
4 / 18
1. Introduction to TinyOS (2 of 4)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
Presentation by HyounSoo. Kim
Embedded System LabEmbedded System Lab
ChungBuk National University
http://csca.chungbuk.ac.kr
5 / 18
1. Introduction to TinyOS (3 of 4)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
Presentation by HyounSoo. Kim
Embedded System LabEmbedded System Lab
ChungBuk National University
http://csca.chungbuk.ac.kr
6 / 18
1. Introduction to TinyOS (4 of 4)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
Presentation by HyounSoo. Kim
Embedded System LabEmbedded System Lab
ChungBuk National University
http://csca.chungbuk.ac.kr
7 / 18
2. Installation and Configuration - zigbeX (1 of 2)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
Presentation by HyounSoo. Kim
Embedded System LabEmbedded System Lab
ChungBuk National University
http://csca.chungbuk.ac.kr
8 / 18
2. Installation and Configuration - zigbeX (2 of 2)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
Presentation by HyounSoo. Kim
Embedded System LabEmbedded System Lab
ChungBuk National University
http://csca.chungbuk.ac.kr
9 / 18
3. Example : Blink3. 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 프로그램에 대한 구현을 제공한 모듈
① Introduction to Blink Introduction to Blink (1 of 2)(1 of 2)
Presentation by HyounSoo. Kim
Embedded System LabEmbedded System Lab
ChungBuk National University
http://csca.chungbuk.ac.kr
10 / 18
3. Example : Blink3. Example : Blink Overview
① Introduction to BlinkIntroduction to Blink (2 of 2)(2 of 2)
RealMain
StdControlHardwareInitPot
HPLPotC
HPLPot
PotM
HPLPot
Pot
PotC
Pot
HPLInit
Init
Main
StdControl
BlinkM
Timer
StdControl
Leds
LedsC
Leds
SingleTimer
Timer StdControl
TimerC
Timer StdControl
TimerM
Timer StdControl
Leds ClockPowerManagement
NoLeds
Leds
ClockC
Clock StdControl
HPLPowerManagementM
PowerManagement
HPLClock
Clock StdControl
Component
Interface(uses)
Interface(provides)
Presentation by HyounSoo. Kim
Embedded System LabEmbedded System Lab
ChungBuk National University
http://csca.chungbuk.ac.kr
11 / 18
② Main & RealMain ComponentMain & RealMain Component
3. Example : Blink3. 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
RealMain
StdControl HardwareInit Pot
HPLPotC
HPLPot
PotM
HPLPot
Pot
PotC
Pot
HPLInit
Init
Main
StdControl
Presentation by HyounSoo. Kim
Embedded System LabEmbedded System Lab
ChungBuk National University
http://csca.chungbuk.ac.kr
12 / 18
③ Blink ComponentBlink Component (1 of 3)(1 of 3)
3. Example : Blink3. 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
}
Main
StdControl
BlinkM
Timer
StdControl
Leds
LedsC
Leds
SingleTimer
Timer StdControl
interface StdControl { command result_t init(); command result_t start(); command result_t stop();}
Interface StdControl tos/interfaces/StdControl.nc
init(): 초기화될 때
start(): 최초로 실행될 때
stop(): 실행이 중지될 때 init start
StdControl
stop
Presentation by HyounSoo. Kim
Embedded System LabEmbedded System Lab
ChungBuk National University
http://csca.chungbuk.ac.kr
13 / 18
③ Blink ComponentBlink Component (2 of 3)(2 of 3)
3. Example : Blink3. 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; }
}
Main
StdControl
BlinkM
Timer
StdControl
Leds
LedsC
Leds
SingleTimer
Timer StdControl
provides:
Implements the StdControl interface.
uses:
Timer 와 Leds 가 제공하는 command 를 호출할 수 있다 .
Timer 와 Leds 가 제공하는 events 를 구현하여야 한다 .
Presentation by HyounSoo. Kim
Embedded System LabEmbedded System Lab
ChungBuk National University
http://csca.chungbuk.ac.kr
14 / 18
③ Blink ComponentBlink Component (3 of 3)(3 of 3)
3. Example : Blink3. 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 비트의 값으로 설정}
Main
StdControl
BlinkM
Timer
StdControl
Leds
LedsC
Leds
SingleTimer
Timer StdControl
Presentation by HyounSoo. Kim
Embedded System LabEmbedded System Lab
ChungBuk National University
http://csca.chungbuk.ac.kr
15 / 18
④ SingleTimer ComponentSingleTimer Component (1 of 2)(1 of 2)
3. Example : Blink3. Example : Blink SingleTimer.nc
configuration SingleTimer {
provides interface Timer;provides interface StdControl;
}
implementation {
components TimerC;Timer = TimerC.Timer[unique("Timer")];StdControl = TimerC;
}
SingleTimer
Timer StdControl
TimerC
Timer StdControl
TimerM
Timer[id] StdControl
Leds ClockPowerManagement
NoLeds
Leds
ClockC
Clock StdControl
HPLPowerMangementM
PowerManagement
HPLClock
Clock StdControl
TimerCconfiguration TimerC { provides interface Timer[uint8_t id]; provides interface StdControl;}implementation { ... }
Presentation by HyounSoo. Kim
Embedded System LabEmbedded System Lab
ChungBuk National University
http://csca.chungbuk.ac.kr
16 / 18
④ SingleTimer ComponentSingleTimer Component (2 of 2)(2 of 2)
3. Example : Blink3. Example : Blink
includes Timer;interface Timer { command result_t start(char type, uint32_t interval); command result_t stop(); event result_t fired();}
Timer Interface
start stop fired
Timer
two types of timer TIMER_REPEAT TIMER_ONE_SHOT
Interval (miliseconds) 시간이 지나면 fired event 발생
event 는 사용자 (uses) 측에서 구현
SingleTimer
Timer StdControl
TimerC
Timer StdControl
TimerM
Timer[id] StdControl
Leds ClockPowerManagement
NoLeds
Leds
ClockC
Clock StdControl
HPLPowerMangementM
PowerManagement
HPLClock
Clock StdControl
Presentation by HyounSoo. Kim
Embedded System LabEmbedded System Lab
ChungBuk National University
http://csca.chungbuk.ac.kr
17 / 18
4. TinyOS Simulation - TinyViz (1 of 2)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 으로 실행
Presentation by HyounSoo. Kim
Embedded System LabEmbedded System Lab
ChungBuk National University
http://csca.chungbuk.ac.kr
18 / 18
4. TinyOS Simulation - TinyViz (2 of 2)4. TinyOS Simulation - TinyViz (2 of 2)
Running the TinyViz
Delay Delay 설정설정 시작 시작 or or 멈춤멈춤
motemote
Presentation by HyounSoo. Kim
Embedded System LabEmbedded System Lab
ChungBuk National University
http://csca.chungbuk.ac.kr
19 / 18
5. Fusing the application - PonyProg20005. Fusing the application - PonyProg2000
PonyProg2000 Setup
I/O port setup Probe
File Open Fusing
Presentation by HyounSoo. Kim
Embedded System LabEmbedded System Lab
ChungBuk National University
http://csca.chungbuk.ac.kr
E N D