TinyOS Study

Download Report

Transcript TinyOS Study

http://csca.chungbuk.ac.kr
Embedded System Lab
Lesson 1 : Getting Started with TinyOS and nesC
(Hanback’s zigbeX & TinyOS ver.1.1.7)
Embedded System Lab.
2007. 1. 11
HyounSoo. Kim
ChungBuk National University
Presentation by HyounSoo. Kim
http://csca.chungbuk.ac.kr
Embedded System Lab
Contents
1
Introduction to TinyOS
2
Installation and Configuration - zigbeX
3
Example : Blink
①
Introduction to Blink
② Main & RealMain Component
③
Blink Component
④
SingleTimer Component
4
TinyOS Simulation - TinyViz
5
Fusing the application - PonyProg2000
1 / 18
ChungBuk National University
Presentation by HyounSoo. Kim
http://csca.chungbuk.ac.kr
Embedded System Lab
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
2 / 18
ChungBuk National University
Presentation by HyounSoo. Kim
http://csca.chungbuk.ac.kr
Embedded System Lab
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 on
their 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 and
the commands they provide
ChungBuk National University
3 / 18
Presentation by HyounSoo. Kim
http://csca.chungbuk.ac.kr
Embedded System Lab
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 is
a 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
4 / 18
ChungBuk National University
Presentation by HyounSoo. Kim
http://csca.chungbuk.ac.kr
Embedded System Lab
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


Commands:


Flow downwards, Control returns to caller
Events:


Forms a hierarchy
Flow upwards, Control returns to signaler
Events can call Commands but not vice versa
5 / 18
ChungBuk National University
Presentation by HyounSoo. Kim
http://csca.chungbuk.ac.kr
Embedded System Lab
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
6 / 18
ChungBuk National University
Presentation by HyounSoo. Kim
http://csca.chungbuk.ac.kr
Embedded System Lab
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
7 / 18
ChungBuk National University
Presentation by HyounSoo. Kim
http://csca.chungbuk.ac.kr
Embedded System Lab
3. Example : Blink
① Introduction to Blink (1 of 2)


"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 프로그램에 대한 구현을 제공한 모듈
8 / 18
ChungBuk National University
Presentation by HyounSoo. Kim
http://csca.chungbuk.ac.kr
Embedded System Lab
3. Example : Blink
① Introduction to Blink (2 of 2)

Overview
RealMain
Pot
HardwareInit
Pot
Init
PotC
HPLInit
Interface(provides)
StdControl
Component
Interface(uses)
Main
StdControl
Pot
PotM
StdControl
BlinkM
HPLPot
Leds
HPLPot
Leds
HPLPotC
Timer
Timer
LedsC
StdControl
Timer
SingleTimer
StdControl
TimerC
Timer
StdControl
TimerM
Leds
PowerManagement
Leds
PowerManagement
NoLeds
HPLPowerManagementM
Clock
Clock
StdControl
ClockC
Clock
StdControl
HPLClock
ChungBuk National University
9 / 18
Presentation by HyounSoo. Kim
http://csca.chungbuk.ac.kr
Embedded System Lab
3. Example : Blink
② Main & RealMain Component

RealMain

RealMain
StdControl
Main.nc
Main

tos/system/Main.nc

TinyOS application에서 맨 처음 수행되는 콤포넌트
HardwareInit
Pot
Init
Pot
HPLInit
PotC
StdControl

Main.StdControl.init() 이 최초로 호출되고, 다음에

Main.StdControl.start() 가 실행된다.
Pot
PotM
HPLPot
HPLPot
HPLPotC
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
ChungBuk National University
10 / 18
Presentation by HyounSoo. Kim
http://csca.chungbuk.ac.kr
Embedded System Lab
3. Example : Blink
③ Blink Component (1 of 3)

Blink.nc
Main
StdControl
configuration Blink {
}
// no external interfaces
StdControl
BlinkM
implementation {
components Main, BlinkM, SingleTimer, LedsC;
Main.StdControl -> BlinkM.StdControl;
Main.StdControl -> SingleTimer.StdControl;
BlinkM.Timer -> SingleTimer.Timer;
BlinkM.Leds -> LedsC;
}

Interface StdControl

tos/interfaces/StdControl.nc

init(): 초기화될 때

start(): 최초로 실행될 때

stop(): 실행이 중지될 때
Leds
Timer
Leds
Timer
LedsC
StdControl
SingleTimer
// multiple
// implicit
interface StdControl {
command result_t init();
command result_t start();
command result_t stop();
}
StdControl
init
start
stop
11 / 18
ChungBuk National University
Presentation by HyounSoo. Kim
http://csca.chungbuk.ac.kr
Embedded System Lab
3. Example : Blink
③ Blink Component (2 of 3)

BlinkM.nc
Main
module BlinkM {
provides {
// BlinkM이 구현
interface StdControl;
}
uses {
// 인터페이스를 제공하는 모듈이 구현
interface Timer;
interface Leds;
}
}
implementation {
command result_t StdControl.init() {
call Leds.init();
return SUCCESS;
}
StdControl
StdControl
BlinkM
Leds
Timer
Leds
Timer
LedsC
StdControl
SingleTimer
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를 구현하여야 한다.
12 / 18
ChungBuk National University
Presentation by HyounSoo. Kim
http://csca.chungbuk.ac.kr
Embedded System Lab
3. Example : Blink
③ Blink Component (3 of 3)

Interface Leds
Main
StdControl
interface Leds {
async command result_t init();
StdControl
BlinkM
async command result_t redOn();
async command result_t redOff();
async command result_t redToggle();
Leds
Timer
Leds
// 현재 상태와 반대
LedsC
Timer
StdControl
SingleTimer
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();
async command result_t set(uint8_t value);
// 3비트의 값을 읽음
// 3비트의 값으로 설정
}
13 / 18
ChungBuk National University
Presentation by HyounSoo. Kim
http://csca.chungbuk.ac.kr
Embedded System Lab
3. Example : Blink
④ SingleTimer Component (1 of 2)

SingleTimer.nc
Timer
configuration SingleTimer {
StdControl
Timer
SingleTimer
provides interface Timer;
provides interface StdControl;
StdControl
TimerC
Timer[id]
StdControl
TimerM
Leds
PowerManagement
Clock
}
implementation {
components TimerC;
Timer = TimerC.Timer[unique("Timer")];
StdControl = TimerC;
Leds
PowerManagement
NoLeds
HPLPowerMangementM
Clock
StdControl
ClockC
Clock
StdControl
HPLClock
}

TimerC
configuration TimerC {
provides interface Timer[uint8_t id];
provides interface StdControl;
}
implementation { ... }
14 / 18
ChungBuk National University
Presentation by HyounSoo. Kim
http://csca.chungbuk.ac.kr
Embedded System Lab
3. Example : Blink
④ SingleTimer Component (2 of 2)

Timer Interface
includes Timer;
interface Timer {
command result_t start(char type, uint32_t interval);
command result_t stop();
event result_t fired();
}
Timer
StdControl
Timer
SingleTimer
StdControl
TimerC
Timer[id]
StdControl
TimerM
Leds
PowerManagement
Leds
PowerManagement
NoLeds
HPLPowerMangementM
Clock
Clock
StdControl
ClockC
Timer
Clock
start

stop
fired
StdControl
HPLClock
two types of timer

TIMER_REPEAT

TIMER_ONE_SHOT

Interval (miliseconds) 시간이 지나면 fired event 발생

event는 사용자(uses) 측에서 구현
15 / 18
ChungBuk National University
Presentation by HyounSoo. Kim
http://csca.chungbuk.ac.kr
Embedded System Lab
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으로 실행
16 / 18
ChungBuk National University
Presentation by HyounSoo. Kim
http://csca.chungbuk.ac.kr
Embedded System Lab
4. TinyOS Simulation - TinyViz (2 of 2)

Running the TinyViz
Delay 설정
시작 or 멈춤
mote
17 / 18
ChungBuk National University
Presentation by HyounSoo. Kim
Embedded System Lab
http://csca.chungbuk.ac.kr
5. Fusing the application - PonyProg2000

PonyProg2000 Setup

I/O port setup  Probe

File Open  Fusing
18 / 18
ChungBuk National University
Presentation by HyounSoo. Kim
http://csca.chungbuk.ac.kr
Embedded System Lab
END
ChungBuk National University
Presentation by HyounSoo. Kim