TinyOS Tutorial Jianping Wang (merge several tutorials found online)
-
Upload
claire-turner -
Category
Documents
-
view
216 -
download
0
Transcript of TinyOS Tutorial Jianping Wang (merge several tutorials found online)
![Page 1: TinyOS Tutorial Jianping Wang (merge several tutorials found online)](https://reader030.fdocuments.in/reader030/viewer/2022032707/56649e195503460f94b06577/html5/thumbnails/1.jpg)
TinyOS Tutorial
Jianping Wang(merge several tutorials found online)
![Page 2: TinyOS Tutorial Jianping Wang (merge several tutorials found online)](https://reader030.fdocuments.in/reader030/viewer/2022032707/56649e195503460f94b06577/html5/thumbnails/2.jpg)
TinyOS• TinyOS is an open source operation system
designed for wireless embedded sensor network. It is not a operation for general purpose.
Official website: http://www.tinyos.net/• It features a component-based architecture which
enables rapid development while minimizing code size.
• Supported platforms include Linux RedHat9.0, Windows 2000/XP with Cygwin.
![Page 3: TinyOS Tutorial Jianping Wang (merge several tutorials found online)](https://reader030.fdocuments.in/reader030/viewer/2022032707/56649e195503460f94b06577/html5/thumbnails/3.jpg)
TinyOS versions• 1.0 (Oct 2002)• 1.1 (Sep 2003)• 1.1.1 (Nov 2003) add a new routing module MintRoute,
a new ADC interface.• 1.1.3 (Jan 2004) add B-Mac, a new MAC layer w/
CSMA with collision, etc.• 1.1.4 (Feb 2004) add Tython, which is a TOSSIM (a
TinyOS simulator) scripting environment.• 1.1.5 (Mar 2004) make improvements and bugs fixes to
Tython.• 1.1.6 (May 2004) support PageEEPROM component, a
new make system, for PC platform.• 1.1.7 (July 2004) supports MicaZ and Telos.• 1.1.8 (Oct 2004) support TinyOS network programming
components: Delug, NetProg and TOSBoot.
![Page 4: TinyOS Tutorial Jianping Wang (merge several tutorials found online)](https://reader030.fdocuments.in/reader030/viewer/2022032707/56649e195503460f94b06577/html5/thumbnails/4.jpg)
Serial-line communication in TinyOS• The protocol is based on the PPP in HDLC-like framing
described in RFC-1662.• Components:
• FramerM – provides core framing protocol• FramerAcm – implements ACK processing for inbound packets• UARTFramedPacket – A configuration component incorporating
FrameM and FrameAckM• Applications
• TOBase (apps/TOBase) – simple bridge between serial and wireless chanels
• TransparentBase (apps/TransparentBase) – bridge identical to TOBase but doesn’t check group ID
• GenericBase (apps/GenericBase) – legacy bridge w/o framing or flow control
• Host Tools• net.tinyos.packet.PacketSource (Interface)• Net.tinyos.packet.PhoenixSource (Class)• Net.tinyos.SerialForwarder (Application)
![Page 5: TinyOS Tutorial Jianping Wang (merge several tutorials found online)](https://reader030.fdocuments.in/reader030/viewer/2022032707/56649e195503460f94b06577/html5/thumbnails/5.jpg)
Different platforms need different solutions
Capabili
tie
s
Size, Power Consumption, Cost
MICA Mote
MK - II
StarGate
Spec
Software: atmel tools, java, perl
Highly constrained (memory, cpu, storage, power)
Solutions: TinyOS,…
![Page 6: TinyOS Tutorial Jianping Wang (merge several tutorials found online)](https://reader030.fdocuments.in/reader030/viewer/2022032707/56649e195503460f94b06577/html5/thumbnails/6.jpg)
Environment/Tools
2.25 in
1.25 in
Microphone
AccelerometerLightSensor
TemperatureSensor
Sounder Magnetometer
![Page 7: TinyOS Tutorial Jianping Wang (merge several tutorials found online)](https://reader030.fdocuments.in/reader030/viewer/2022032707/56649e195503460f94b06577/html5/thumbnails/7.jpg)
Environment/Tools
• download TOS distribution and Java JDK from:– http://www.tinyos.net/download.html
• directory structure, after installation:– c:\tinyos\cygwin – installation directory– \opt\tiny-1.x\contrib\xbow\apps {cnt_to_leds, cnt_to_rfm,
sense, …}– \opt\tiny-1.x\docs {connector.pdf, tossim.pdf, …}– \opt\tiny-1.x\tools {toscheck, inject, verify, …}– \opt\tiny-1.x\tos {shared/system components, …}
![Page 8: TinyOS Tutorial Jianping Wang (merge several tutorials found online)](https://reader030.fdocuments.in/reader030/viewer/2022032707/56649e195503460f94b06577/html5/thumbnails/8.jpg)
Environment/Tools
• verify the software installation:– ~\tools\toscheck.exe
• verify the hardware is working:– ~\apps\mica_hardware_verify\make mica– install the mote into the board. Red LED on.– ~\apps\mica_hardware_verify\make mica install.1– ~\apps\mica_hardware_verify\java hardware_check COM1
![Page 9: TinyOS Tutorial Jianping Wang (merge several tutorials found online)](https://reader030.fdocuments.in/reader030/viewer/2022032707/56649e195503460f94b06577/html5/thumbnails/9.jpg)
• TinyOS 1.0 libraries and components are written in an extension of C, called nesC
• Applications are too!– just additional components composed with the
OS components• Provides syntax for TinyOS concurrency and storage
model– commands, events, tasks– local frame variable
• Rich Compositional Support– separation of definition and linkage– robustness through narrow interfaces and reuse– interpositioning
Programming TinyOs
![Page 10: TinyOS Tutorial Jianping Wang (merge several tutorials found online)](https://reader030.fdocuments.in/reader030/viewer/2022032707/56649e195503460f94b06577/html5/thumbnails/10.jpg)
• A TinyOS application consists of one or more components.
• A component provides and uses interfaces.– A interface defines a set of functions called
commands.• There are two types of components in nesC:
– Modules. It implements application code.– Configurations. It assemble other components
together, called wiring.
TinyOs Components (1)
![Page 11: TinyOS Tutorial Jianping Wang (merge several tutorials found online)](https://reader030.fdocuments.in/reader030/viewer/2022032707/56649e195503460f94b06577/html5/thumbnails/11.jpg)
TinyOs Components (2)
• Component interface:– commands accepts (implemented)– commands uses– events accepts (implemented)– events uses
• Component implementation– functions that implement interface– frame: internal state– tasks: concurrency control
Internal Tasks
Messaging Component
Internal State
Commands Events
![Page 12: TinyOS Tutorial Jianping Wang (merge several tutorials found online)](https://reader030.fdocuments.in/reader030/viewer/2022032707/56649e195503460f94b06577/html5/thumbnails/12.jpg)
• A component specifies a set of interfaces by which it is connected to other components
– provides a set of interfaces to others– uses a set of interfaces provided by others
• Interfaces are bi-directional– include commands and events
• Interface methods are the external namespace of the component
Timer Component
StdControl Timer
Clock
provides
uses
provides
interface StdControl;
interface Timer:
uses
interface Clock
TinyOs Components (3)
![Page 13: TinyOS Tutorial Jianping Wang (merge several tutorials found online)](https://reader030.fdocuments.in/reader030/viewer/2022032707/56649e195503460f94b06577/html5/thumbnails/13.jpg)
• TinyOS executes only one program consisting of a set of components.
• Two type threads:– Task– Hardware event handler
• Tasks are scheduled to executed and put into a single queue. A task doesn’t preempt another task.
• Hardware event handlers are executed in response to a hardware interrupt. They may preempt the execution of a task and other hardware handler.
– The events and commands executed as part of a hardware event handler must be declared as async.
TinyOs Concurrency Model
![Page 14: TinyOS Tutorial Jianping Wang (merge several tutorials found online)](https://reader030.fdocuments.in/reader030/viewer/2022032707/56649e195503460f94b06577/html5/thumbnails/14.jpg)
Issues/Comments
• System perspective:– simplistic FIFO scheduling -> no real-time guarantees – bounded number of pending tasks– no “process” management -> resource allocation
problematic, e.g. shared resources– software level “bit manipulation”. HW implementation
can provide speed-up and power saving
![Page 15: TinyOS Tutorial Jianping Wang (merge several tutorials found online)](https://reader030.fdocuments.in/reader030/viewer/2022032707/56649e195503460f94b06577/html5/thumbnails/15.jpg)
5/5/2003 MobiSys Tutorial, San Francisco 15
TinyOS Application• TinyOS (TOS) = application/binary image, executable on an TinyOS (TOS) = application/binary image, executable on an
ATmega processorATmega processor• event-driven architectureevent-driven architecture• single-shared stacksingle-shared stack• no kernel, no process management, no memory management, no kernel, no process management, no memory management,
no virtual memoryno virtual memory• 2-level scheduling2-level scheduling• simple FIFO scheduler, part of the mainsimple FIFO scheduler, part of the main
![Page 16: TinyOS Tutorial Jianping Wang (merge several tutorials found online)](https://reader030.fdocuments.in/reader030/viewer/2022032707/56649e195503460f94b06577/html5/thumbnails/16.jpg)
Application = Graph of Components
RFM
Radio byte
Radio Packet
UART
Serial Packet
ADC
Temp photo
Active Messages
clocks
bit
by
tep
ac
ke
t
Route map router sensor appln
ap
pli
ca
tio
n
HW
SWExample: ad hoc, multi-hop routing of photo sensor readings
3450 B code 226 B data
Graph of cooperatingstate machines on shared stack
![Page 17: TinyOS Tutorial Jianping Wang (merge several tutorials found online)](https://reader030.fdocuments.in/reader030/viewer/2022032707/56649e195503460f94b06577/html5/thumbnails/17.jpg)
Application = Graph of Components+Scheduler
• TOS application = graph of components + scheduler
CommunicationActuating Sensing Communication
Application (User Components)
Main (includes Scheduler)
Hardware Abstractions
• main {
// component initialization
while(1) {
while(more_tasks) schedule_task;
sleep;
} // while
} // main
![Page 18: TinyOS Tutorial Jianping Wang (merge several tutorials found online)](https://reader030.fdocuments.in/reader030/viewer/2022032707/56649e195503460f94b06577/html5/thumbnails/18.jpg)
TOS Execution Model• commands request action
– ack/nack at every boundary– call cmd or post task
• events notify occurrence– HW intrpt at lowest level– may signal events– call cmds– post tasks
• Tasks provide logical concurrency– preempted by events
RFM
Radio byte
Radio Packet
bit
by
tep
ac
ke
t
event-driven bit-pump
event-driven byte-pump
event-driven packet-pump
message-event driven
active message
application comp
encode/decode
crc
data processing
![Page 19: TinyOS Tutorial Jianping Wang (merge several tutorials found online)](https://reader030.fdocuments.in/reader030/viewer/2022032707/56649e195503460f94b06577/html5/thumbnails/19.jpg)
Dynamics of Events and Threads
bit event filtered at byte layer
bit event => end of byte =>
end of packet => end of msg send
thread posted to start
send next message
radio takes clock events to detect recv
![Page 20: TinyOS Tutorial Jianping Wang (merge several tutorials found online)](https://reader030.fdocuments.in/reader030/viewer/2022032707/56649e195503460f94b06577/html5/thumbnails/20.jpg)
Event-Driven Sensor Access Pattern
• clock event handler initiates data collection
• sensor signals data ready event
• data event handler calls output command
• device sleeps or handles other activity while waiting
• conservative send/ack at component boundary
command result_t StdControl.start() {
return call Timer.start(TIMER_REPEAT, 200);
}
event result_t Timer.fired() {
return call sensor.getData();
}
event result_t sensor.dataReady(uint16_t data) {
display(data)
return SUCCESS;
}
SENSE
Timer Photo LED
![Page 21: TinyOS Tutorial Jianping Wang (merge several tutorials found online)](https://reader030.fdocuments.in/reader030/viewer/2022032707/56649e195503460f94b06577/html5/thumbnails/21.jpg)
TinyOS Commands and Events{... status = call CmdName(args)...}
command CmdName(args) {...return status;}
{... status = signal EvtName(args)...}
event EvtName)(args) {...return status;}
![Page 22: TinyOS Tutorial Jianping Wang (merge several tutorials found online)](https://reader030.fdocuments.in/reader030/viewer/2022032707/56649e195503460f94b06577/html5/thumbnails/22.jpg)
TinyOS Execution Contexts
• Events generated by interrupts preempt tasks• Tasks do not preempt tasks• Both essential process state transitions
Hardware
Interrupts
eve
nts
commands
Tasks
![Page 23: TinyOS Tutorial Jianping Wang (merge several tutorials found online)](https://reader030.fdocuments.in/reader030/viewer/2022032707/56649e195503460f94b06577/html5/thumbnails/23.jpg)
TASKS
• provide concurrency internal to a component– longer running operations
• are preempted by events• able to perform operations beyond event context• may call commands• may signal events• not preempted by tasks
{...post TskName();...}
task void TskName {...}