A Quick on TinyOS - University of Rochester

Download Report

Transcript A Quick on TinyOS - University of Rochester

A Quick Note on TinyOS
Chris Merlin
Group Meeting
January 21st, 2009
Outline




TinyOS: What Is It?
TOSSIM, The TinyOS Simulator
Dynamic Memory Allocation in TinyOS
Concluding Remarks
TinyOS: What is it?
TOSSIM, the TinyOS Simulator
Dynamic Memory Allocation in TinyOS
TinyOS: A Quick Reminder


A Simple and stripped down operating
system for motes
nesC language



C Based
For component-based programming
Maybe a quarter million programmers in
the world
TinyOS: What is it?
TOSSIM, the TinyOS Simulator
Dynamic Memory Allocation in TinyOS
(…2)


TinyOS: A Quick Reminder
Components: black boxes whose input and
output functions are known (interfaces)
Configurations:



assemble other components together
link interfaces used by components to providers
Modules:


TinyOS: What is it?
Provide application code
Use and provide interfaces
TOSSIM, the TinyOS Simulator
Dynamic Memory Allocation in TinyOS
(…3)





TinyOS: A Quick Reminder
Consider a module called Application that
needs to turn LEDs on and off
The Leds interface provides functions to
turn on/off, initialize, toggle LEDs
Application would like to use that interface
LedsC is a component that provides Leds
interface
Application.Leds -> LedsC.Leds;
TinyOS: What is it?
TOSSIM, the TinyOS Simulator
Dynamic Memory Allocation in TinyOS
Outline




TinyOS: What Is It?
TOSSIM, The TinyOS Simulator
Dynamic Memory Allocation in TinyOS
Concluding Remarks
TinyOS: What is it?
TOSSIM, the TinyOS Simulator
Dynamic Memory Allocation in TinyOS
TOSSIM: Generalities

Simulator:



What it does:



Built with make pc
Runs with DBG=[name], build/pc/main.exe
[options]
Displays traces
Emulates mote+radio behavior
What it doesn’t do:


TinyOS: What is it?
Model radio propagation
Model power drain / energy consumption
TOSSIM, the TinyOS Simulator
Dynamic Memory Allocation in TinyOS
Compiling and Running a
Simulation

Execute: build/pc/main.exe [options]
num_nodes
-b=<sec>: time over which motes boot
-l=<scale>: runs sim. at <scale> times real time
-r=<radio>: radio model: simple, static, lossy
-rf=<file>: input file for lossy model
-t=<time>: runs sim. for <time> virtual seconds
num_nodes: number of nodes
TinyOS: What is it?
TOSSIM, the TinyOS Simulator
Dynamic Memory Allocation in TinyOS
The Lossy Radio Model

Input file can specify links’ bit error rates
Lossy radio model can help create multihop networks of nodes

<mote ID>:<mote ID>:ber

1
1
1
0
0
1
TinyOS: What is it?
1
TOSSIM, the TinyOS Simulator
Dynamic Memory Allocation in TinyOS
Outline




TinyOS: What Is It?
TOSSIM, The TinyOS Simulator
Dynamic Memory Allocation in TinyOS
Concluding Remarks
TinyOS: What is it?
TOSSIM, the TinyOS Simulator
Dynamic Memory Allocation in TinyOS
Dynamic Memory Allocation



“TinyOS does not allow dynamic memory
allocation”
True: malloc will occasionally crash,
realloc not supported on real motes
False: malloc, realloc, free all work fine
in TOSSIM. MemAlloc provides some
DMA for real motes
TinyOS: What is it?
TOSSIM, the TinyOS Simulator
Dynamic Memory Allocation in TinyOS
Memory Model of TinyOS


Simplicity of TinyOS allows only static
mem. alloc (no management of dynamic
heap)
malloc must find space of appropriate
size: can be resource consuming, esp.
when mem. very fragmented
TinyOS: What is it?
TOSSIM, the TinyOS Simulator
Dynamic Memory Allocation in TinyOS
MemAlloc


MemAlloc is provided by TinyAlloc
Some commands are:





allocate(HandlePtr hptr, int size):
allocate memory region of size
reallocate(Handle h, int size)
free(Handle h)
However, MemAlloc is split-phase
Events:


TinyOS: What is it?
allocComplete(HandlePtr hptr, result_t
outcome): indicate an allocation has completed
reallocComplete(Handle h, result_t
outcome)
TOSSIM, the TinyOS Simulator
Dynamic Memory Allocation in TinyOS
MemAlloc Example



TinyAlloc implements managed heap:
simple array of handles
Memory regions are referenced indirectly
by another array
Double dereferencing is needed
Handle array;
call MemAlloc.allocate(&array, 2*sizeof(ArrayEntry));
ArrayEntry *entry = (ArrayEntry*)(*array+sizeof(ArrayEntry))
TinyOS: What is it?
TOSSIM, the TinyOS Simulator
Dynamic Memory Allocation in TinyOS
Outline




TinyOS: What Is It?
TOSSIM, The TinyOS Simulator
Dynamic Memory Allocation in TinyOS
Concluding Remarks
TinyOS: What is it?
TOSSIM, the TinyOS Simulator
Dynamic Memory Allocation in TinyOS
Remarks


If you have suggestions, pieces of code to
add, let me know
Compiled in Tutorial on WCNG website /
my Academic page