Upload
esther-whitehead
View
238
Download
0
Embed Size (px)
Citation preview
HANBACKELECTRONICS CO., LTD.
저자권 보호됨
TinyOS & NesC
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 2
TinyOS
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 3
TinyOS• TinyOS (TOS) = OS image runable on
atmega128
• event-driven structure
• Single stack
• TinyOS Limitation– No Kernel– No Dynamic Memory Management– No use of virtual memeory
• Simple FIFO scheduler implemented in the Main Component
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 4
TinyOS Directory
• /opt/tinyos-1.x
TinyOS folder
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 5
NesC
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 6
Component Model Language
• NesC charateristics– Component Model Language composes several blocked
components into a executable module by wiring each component at compile time
– The purpose of NesC is to generate small size code only for the targeted sensor application.
– Syntax is similar to C but some differences
NesC features
type component
developement easier than C - component wiring
Code size very small – optimal for tiny embedded devices
limitation No Dynamic Memory
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 7
NesC Terms. NesC terms
Application A single program running on the sensor board
Component
Component – basic block of NesC; configuration & module
Interface - Interface provided to connect to components. Each com,ponent can use multiple interfaces. By usinh the interface, “command” & “message” are handled. Wiring is connecting two components.
Configuration – Declare a new component and built-in components and describing wiring methods (use or provide) .
Module – Implementing part using components
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 8
Component
• Component interface:– Function implementation– Function Call– Response handling by event triggers– Event triggering
• Component consists – Definition of Interface– Configuration – Module
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 9
Interface
• Interface– Provided & used by component .– Interface is defined with command & event
Command Event
Command is an implementable function in module. It is called by ‘call' command.
Event to use must be implemented in a upper component. It is useful when it passes information(event). It is called by ‘signal’ command.
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 10
Interface Example
• Description
• Example (Timer.nc)
interface identifier { command result_t function_name prototype event result_t function_name prototype }
interface Timer { command result_t start (char type, uint32_t interval); command result_t stop (); event result_t fired (); }
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 11
Command - Call
• Command– C’s function – Inner component call by command– Must be declared in interface
• Call by “Call” command– call Timer.stop()
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 12
Event - Signal
• Event
– Call by “Signal” command• signal Timer.fired();
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 13
Component – configuration
• Configuration File– Configuration describes components to provide and use
components
configuration identifier { *identifier : the name of component provides { interface interface_name1 } } implementation { components identifierM, com1, com2 ... interface_name1 = identifierM.interface_name1 identifierM.interface_name2 -> com1.interface_name3 com1.interface_name3 <- identifierM.interface_name2 }
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 14
Wiring between Components
• Wiring: <‐, ‐>, = – Interface 1 = interface 2
Same interface– Interface1 ‐> interface2
Used at interface1, implemented at interface2– Interface1 <‐ interface2
Interface2 ‐> interface1 (same)
• Once wired, “command, event & interface” are available.
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 15
Configuration Example
• Example (TimerC.nc)
configuration TimerC { provides { ... interface Timer; } } implementation { components TimerM, ClockC, ... ; ... TimerM.Clock -> ClockC.Clock; ... }
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 16
Component - module
• Module – Module examples (both are OK)
module identifier { provides { interface a; interface b; } uses { interface x; interface y; } } implementation { ... ... }
module identifier {
provides interface a; provides interface b; uses interface x; uses interface y;
} implementation { ... ... }
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 17
Module Example
• Example (TimerM.nc)
module TimerM { provides { interface StdControl; interface Timer; } uses interface Clock; } implementation {
command result_t Timer.start(…) { ... } command result_t Timer.stop() { ... } event void Clock.tick() { ... } }
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 18
Task & Event• Scheduling
– 2-level scheduling (events and tasks)– single shared stack, used by events and function calls
• Task:– Preemptive for event– Function call– Signal 을 발생– Non-Preemptive with other tasks
• Event – process for interrupt handlingINTERRUPT(_output_compare2_)() { // Hardware Timer Event Handler
TOS_SIGNAL_EVENT(CLOCK_FIRE_EVENT)(); // Software event … }
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 19
async ,atomic
• async– The task runs asynchronously
• atomic– Global variable for handling race condition
problem
atomic { sharedvar = sharedvar+1;
}
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 20
Tinyos Directory
/opt/tinyos-1.x/apps/contrib
/zigbex/tools/tos
interfaces system flatform sensorboards lib types
Driver and app. examples
Java & make platform
interfacesHw related common
componentsComponents for platdorm
Components for sensor board
Lib.
TinyOS’s MSG headers
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 21
NesC Programming
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 22
nesC Programming
application:configuration
comp1:module
comp3
comp4comp2:configuration
• Components:– Consists
- module: C lang.- configuration:
select and wire– interfaces
- provides interface- uses interface
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 23
nesC Programming• Types of Component:
– configuration: connection with using components– module: implement “interface operation “ and
“event handler “
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 24
nesC Programming• Configuration’s wiring:
• Configuration examples:
C1
C2
C3
C2
C3
configuration app { }implementation { components c1, c2, c3;
c1 -> c2; c2.out -> c3.triangle;c3 <- c2.side;
}
component c2c3 { provides interface triangle t1;}implementation { components c2, c3;
t1 -> c2.in;c2.out -> c3.triangle;c3 <- c2.side;
}
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 25
nesC Programming Language
•modules:module C1 { uses interface triangle;} implementation { ... }
module C2 { provides interface triangle in; uses { interface triangle out; interface rectangle side; }} implementation { ... }
module C3 { provides interface triangle; provides interface rectangle;} implementation { ... }
C1
C2
C3
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 26
nesC Blink example
blink.nc (configuration)
configuration Blink {}implementation { components Main, BlinkM, TimerC, LedsC; Main.StdControl -> TimerC.StdControl; Main.StdControl -> BlinkM.StdControl; BlinkM.Timer -> TimerC.Timer[unique("Timer")]; BlinkM.Leds -> LedsC;}
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 27
nesC Blink example
blinkM.nc (module)
module BlinkM { provides { interface StdControl; } uses { interface Timer as Timer; interface Leds; }} implementation { command result_t StdControl.init() { call Leds.init(); return SUCCESS;} command result_t StdControl.start() { call Timer.start(TIMER_REPEAT, 1000); return SUCCESS; } command result_t StdControl.stop() { call Timer.stop(); return SUCCESS; } event result_t Timer.fired() { call Leds.redToggle(); return SUCCESS; }}
HANBACKELECTRONICS CO., LTD.
저자권 보호됨23年 4月 20日 28
BlinkM <->LedsCmodule BlinkM{ provides { interface StdControl; } uses { interface Timer as Timer; interface Leds; }}implementation { command result_t StdControl.init() { call Leds.init(); return SUCCESS; } command result_t StdControl.start() { call Timer.start(TIMER_REPEAT, 1000); return SUCCESS; } StdControl.stop() { call Timer.stop(); return SUCCESS; } event result_t Timer.fired() { call Leds.redToggle(); return SUCCESS; }}
module LedsC { provides interface Leds;}implementation{ uint8_t ledsOn; enum { RED_BIT = 1, GREEN_BIT = 2, YELLOW_BIT = 4 }; async command result_t Leds.init() { … return SUCCESS; } async command result_t Leds.redOn() {…} async command result_t Leds.redOff() {…} async command result_t Leds.redToggle() {…} …. async command uint8_t Leds.get() {…} async command result_t Leds.set(uint8_t ledsNum) {…}}