a glance to tiny os n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
A Glance to Tiny OS PowerPoint Presentation
Download Presentation
A Glance to Tiny OS

Loading in 2 Seconds...

play fullscreen
1 / 41

A Glance to Tiny OS - PowerPoint PPT Presentation


  • 202 Views
  • Uploaded on

A Glance to Tiny OS. Presented by Shanshan Chen OU-TCOM March, 2008. Outline. Introduction NesC programming TinyOS structure A case study of sample code. Introduction. What is TinyOS. An open source Operation system for embedded system Developed by UC Berkeley

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'A Glance to Tiny OS' - Olivia


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
a glance to tiny os

A Glance to Tiny OS

Presented by Shanshan Chen

OU-TCOM

March, 2008

outline
Outline
  • Introduction
  • NesC programming
  • TinyOS structure
  • A case study of sample code
what is tinyos
What is TinyOS
  • An open source Operation system for embedded system
  • Developed by UC Berkeley
  • Now mainly used in Wireless Sensor Networks
  • Component – Based Architecture
what is mote
What is mote?

Mote is known as a sensor node in wireless sensor networks (Chiefly North America)

hardware crossbow set
Hardware—Crossbow set

Mica suite, Tranceiver

Programming board

AD converters

Base-station node

hardware others
Hardware -- others

Sentilla Moteiv Tmote

Crossbow Cricket Mote

A location aware version of the popular MICA2 low-power Processor/Radio module

advantages of tinyos
Advantages of TinyOS
  • Essential Reason—Component based
  • Each core code can be less than 400 bytes which will be easily implemented in Sensor system with memory limits
  • Thus saving the room for the operation of management of the whole network
  • Does Open source count? – Definitely YES
  • Not a standard yet, but obviously widely spreaded
what is crossbow s business
What is Crossbow’s business?
  • Over 10 different kinds of sensor system for various customer’s need
  • The consumers (mostly Engineering academic units) can focus on the application of the sensor system without being bothered by transmission issues
  • To buy or not to buy?
what is nesc
What is NesC

A C-like language,an extension of C , and

designed to embody the structuring concepts and

execution model of TinyOS

source file nc type component
Source file (.nc) type-- Component
  • Components : the basic building blocks for NesC applications
    • modules
    • configurations
  • Module— embody the code programming, providing and using interfaces
  • Configuration— combining components and modules together, can provide and use interfaces
source file type nc interface
Source file type (.nc) -- Interface
  • Interface: used to provide an abstract definition of the interaction of two components (the user and the provider)
  • An interface contains no actual code or wiring
  • Declares commands--that the interface's provider must implement,
  • Declares events -- interface's user must implement
  • NesC interfaces specify two directions
common components
Common Components
  • - AD conversion
  • - Random numbers
  • - Cryptography - Routing
  • - File System
  • - Serial Communication
  • - LED control
  • - Timers
  • - Memory allocation
  • - Watchdog
  • - Data logging
  • - Sensor Board Input
modules and configuration
Modules and 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.Leds;

}

module BlinkM {

provides {

interface StdControl;

}

uses {

interface Timer;

interface Leds;

}

}

implementation of blinkm
Implementation of BlinkM

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;

}

}

how to interface
How to interface

interface StdControl {

command result_t init();

command result_t start();

command result_t stop();

}

//provider

  • Timer.nc
  • interface Timer {command result_t start(char type, uint32_t interval);
  • command result_t stop();
  •  event result_t fired();} //user
is that all things behind the source code
Is that all?(Things behind the source code)
  • Makefile

include Makefile.component

include $(TOSROOT)/apps/MakeXbowlocal

include $(MAKERULES)

  • Makefile.component

COMPONENT=Blink

SENSORBOARD=mts310

structure
Structure
  • A module implements an interface
  • Components provide and use interfaces
  • A configuration links or “wires” the internal and external interfaces
  • An application consists of a top-level configuration and all associated modules
firmware structure

Actuating

Sensing

Active Message

Communication

Firmware structure

Main (includes Scheduler)

Application (User Components)

ADC, CLOCK, I2C, LEDS, PHOTO, UART, RFM

Mote Hardware

tinyos scheduling
TinyOS scheduling
  • Concurrency model – two threads
    • Hardware event handler (higher priority)
    • Task (lower priority)
  • Tasks
    • Time flexible
    • Longer background processing jobs
    • Atomic with respect to other tasks (single threaded)
    • Preempted by event
  • Hardware event handlers
    • Time critical
    • Shorter duration (hand off to task if need be)
    • Interrupts task and other hardware handler.
    • Last-in first-out semantics (no priority among events)
    • executed in response to a hardware interrupt
hardware event handler
Hardware Event Handler
  • Events must only do a small amount of work before completing, because events always run to completion and cannot be preempted
  • Hardware event handlers are executed in response to a hardware interrupt and also runs to completion, but may preempt the execution of a task or other hardware event handler.
  • Commands and events that are executed as part of a hardware event handler must be declared with the async keyword.
event sample
Event sample

implementaion {

result_t display(unit16_t value){

if (value &1) call Leds.yellowOn();

else call Leds.yellowOff();

if (value &2) call Leds.greenOn();

else call Leds.greenOff();

if (value &4) call Leds.redOn();

else call Leds.redOff();

return SUCCESS;

}

module SenseM {

provides {

interface Timer;

interface ADC;

interface StdControl as ADCControl;

interface Leds;

}

}

event sample contd
Event Sample contd

command result_tStdControl.init() {

return rcombine(call ADCControl.init(),call Leds.init());

}

command result_tStdControl.start() {

return rcombine(call Timer.start(TIMER_REPEAT,500)

}

command result_tStdControl.stop() {

return call Timer.stop();

}

event sample contd1
Event Sample contd

event result_tTimer.fired () {

return call ADC.getData();

}

async event result_t ADC.dataReady(unit16_t data) {

display(7-((data>>7)&0x7));

return SUCCESS;

}

}

slide29
Task
  • Tasks are atomic with respect to other tasks
  • Run-to-completion semantic allows to have single stack for currently running process
  • Tasks simulate concurrency, they are asynchronous with respect to events
  • Tasks must never block or spin-wait
  • Tasks are usually used to perform longer processing operations, such as background data processing, that can be preempted by events.
slide30

Some time after the event completes (there may be other tasks pending for execution),

the processData() task will run. It computes the sum of the recent ADC samples and displays the upper three bits of the sum on the LEDs.

To dispatch a task for (later) execution, use the syntax

post taskname();

Task
  • Task example

task void processData() {

int16_t i, sum=0;

atomic {

for (i=0; i < size; i++)

sum += (rdata[i] >> 7);

}

display(sum >> log2size);

}

  • SenseTaskM.nc // ADC data ready event handler
  • async event result_t ADC.dataReady(uint16_t data)
  • {
  • putdata(data);
  • post processData();
  • return SUCCESS;
  • }
query in tinyos
Query in TinyOS
  • TinyDB – Database in TinyOS
  • Need for data analysis in WSN (power, )
  • All tasks related to data processing is the work of TinyDB
  • TinyDB is a query processing system for extracting information
  • Providing SQL-like interface
slide32

A Case study of

sample code

a sensing code sample
A sensing code sample
  • a simple sensor application that takes light intensity readings (from the sensor board's photo sensor)
  • displays those readings on the LEDs
  • that reads a value from the light sensor and displays the lower 3 bits of the value on the LEDs.
  • The application configuration is found in Sense.nc and the implementation module in SenseM.nc.
sensem nc
SenseM.nc

implementaion {

result_t display(unit16_t value){

if (value &1) call Leds.yellowOn();

else call Leds.yellowOff();

if (value &2) call Leds.greenOn();

else call Leds.greenOff();

if (value &4) call Leds.redOn();

else call Leds.redOff();

return SUCCESS;

}

module SenseM {

provides {

interface Timer;

interface ADC;

interface StdControl as ADCControl;

interface Leds;

}

}

sensem nccontd
SenseM.nccontd

command result_tStdControl.init() {

return rcombine(call ADCControl.init(),call Leds.init());

}

command result_tStdControl.start() {

return rcombine(call Timer.start(TIMER_REPEAT,500)

}

command result_tStdControl.stop() {

return call Timer.stop();

}

sensem nc contd
SenseM.nc contd

event result_tTimer.fired () {

return call ADC.getData();

}

async event result_t ADC.dataReady(unit16_t data) {

display(7-((data>>7)&0x7));

return SUCCESS;

}

}

sense nc configuration
Sense.nc configuration

configuration Sense {

// this module does not provide any interface

}

implementation {

components Main, SenseM, LedsC, TimerC, Photo;

Main.StdControl -> SenseM;

SenseM.ADC -> Photo;

SenseM.ADCControl -> Photo;

SenseM.Leds -> LedsC; SenseM.Timer -> TimerC.Timer[unique("Timer")];

}

set up the coding environment
Set up the coding environment
  • You can do it in linux/cygwin for sure
  • Also there are easier ways : Moteworks + Programmers Notepad
  • Install Moteworks
  • Configure the system variables
  • Meet some sample codes!
now try the code
Now try the code!
  • (Makefile)
  • Compiling: Make Mica2/Micaz/Mica2 Dots/Micaz Dots
  • Code is compiled when you see “ writing TOS image”
  • Shell command: make <platform> re|install,<n> <programmer>,<port>
  • E.g. “make micaz install,38 mib510,com1”
  • Code is installed when you see “Uploading: flash” line complete without errors
  • NOTE: You need to be in the .nc of the app file you want to compile and program before you can execute shell commands from Programmer’s Notepad
linux environment
Linux environment

Convert NesC into C

and compile to exec

Modify exec with

platform-specific

options

Set the mote ID

Reprogram the

mote

conclusion
Conclusion
  • TinyOS is a runtime environment for NesC running on mote hardware
    • – Performs some resource management
    • – Selected components are linked into the program at compile time