TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

25
TinyOS Dhanshree Nimje Smita Khartad

Transcript of TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

Page 1: TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

TinyOS

Dhanshree Nimje

Smita Khartad

TinyOS - Design Design

What is TinyOSTinyOS is a highly modular softwareenvironment tailored to the requirements ofNetwork Sensors stressing efficiencymodularity and concurrency

bull Capable of fine grained concurrency (event-driven architecture)bull1048633Small physical size

bull Fewer context switches (FIFOnon-preemptable scheduling)

bull1048633Efficient Resource Utilization (Get done quickly and sleep)

bull1048633Highly Modular

TinyOS - Features

Event-driven architecture Lower layer sends events to higher layer Low overheadndash No busy -wait cycles

Interrupt drivenTwo kinds of interrupt 10486331048633 Clock 10486331048633 Radio

Component driven programming model 10486331048633 Size - 400 bytes 10486331048633 Extremely flexible component graph Single Single-shared stack shared stack

Features Contd

Network management - Active Messaging

No kernel process management virtual memory

File management - Matchbox

2-level FIFO schedulerndash events and tasks

Complete integration with hardware

Hardware Kits

Two Board Sandwich Main CPU board with Radio

Communication 1048633 Secondary Sensor Board 1048633 Allows for expansion and customization 1048633 Current sensors include Acceleration Magnetic Field Temperature Pressure Humidity Light and RF Signal

Strength 1048633 Can control RF transmission

strength amp Sense Reception Strength

Hardware Abstraction

LED (pin numberingHW wiring) CLOCK (counter interrupt) UART (baud rate control transfer) ADC (ADC interrupt handling) RFM (abstracts bit level timing

RFM specific control logic)

Communication stack

building up from the RFM bit level

bit level abstracts away radio specifics

byte level radio component collects individual bits into bytes

packet level constructs packets from bytes

messaging layer interprets packets as messages

Sensor stack

photo and temperature sensing components sits on top of ADC component typical request data wait for data event

TinyOS component model

Component interface commands accepts

(implemented) commands uses events accepts (implemented) events uses

Component implementation functions that implement

interface frame internal state tasks concurrency control

Programming Model

comp1C code

comp3

comp4

ComponentsComponentscompcomp specification specificationCC behaviour behaviourdescdesc select and select and wirewire

specificationspecificationaccepts accepts commandscommandsuses uses commandscommandssignals signals eventseventshandles handles eventsevents

comp2desc

applicationdesc

Scheduler Scheduler 2-level scheduling (events and tasks) single shared stack used by events and function calls

TasksTasks are preemptable by eventsare preemptable by events may call commandsmay call commands may signal eventsmay signal events not preempted by tasksnot preempted by tasks

Events ndash Events ndash Time critical Shorter duration (hand off to task if need be) Interrupts task Last-in first-out semantics (no priority among events) lowest level events support by hardware interruptlowest level events support by hardware interrupt

TinyOS Two-level Scheduling

Tasks do intensive computations Unpreemptable FIFO

scheduling Bounded number of

pending tasks Events handle interrupts

Interrupts trigger lowest level events

Events can signal events call commands or post tasks

Two priorities Eventcommand Tasks

How to handle multiple data flows Datainterrupt are handled by interruptevent

Respond to it quickly A sequence of non-blockingeventcommand (function calls) through the componentgraph eg get bit out of radio hw before it gets lost

Post tasks for long computations eg encoding

bull Assumption long computation are not urgent New events preempt tasks to handle newdata

Receiving a message

What are tasks

Requirement of realtime OS bounded delays between events

Event handler should run to completion within a short duration

If a lot of computation is involved in an event handler we defer execution How Implementing it as a task and scheduling it for later

execution TinyOS has simple FIFO scheduler using which tasks

are scheduled On occurrence of an event a task that is executing is

preempted

Data Memory Model

STATIC memory allocation No heap (malloc) No function pointers

Global variables Available on a per-frame basis

Local variables Saved on the stack Declared within a method

Application

Is the OS with some specific functionality Application is interrupt driven List of interrupts handled depend on list of hardware

components included in the application (eg clock and receiver)

Waits for interrupts On occurrence of interrupt calls interrupt handler

HardwareInterrupts

ISRInterruptHandler

invokes Calls

A Complete Application

Example Inter-Node Communication Sender

Receiver

Message Buffer Ownership

bullTransmission AM gains ownership of the buffer until sendDone(hellip) is signaledbull Reception Applicationrsquos event handler gains ownershipof the buffer but it must return a free buffer for the nextmessage

Potentially Nasty Bug 1

Whatrsquos wrong with the codeSymptom data saved in globalData is lost Reason Racecondition betweentwo tasksSolution Use aqueue or never relyon inter-taskcommunication

uint8_t globalDatatask void processData() call SendDatasend(globalData)command result_t Foobar(uint8_t data) globalData = datapost processData()

Potentially Nasty Bug 2

Whatrsquos wrong with the code

Symptom messageis corruptReason TOS_Msgis allocated in thestack lost whenfunction returns Solution DeclareTOS_Msg msg incomponentrsquos frame

command result_t Foobar(uint8_t data) TOS_Msg msgFooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)

Potentially Nasty Bug 3

Whatrsquos wrong withthe codeSymptom somemessages are lostReason Racecondition betweentwo componentstrying to sharenetwork stack (whichis split-phase) Solution Use aqueue to storepending messages

command result_t Foobar(uint8_t data) FooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)Component

Component 2 command result_t Goobar(uint8_t data) GooData goo = (GooData)msgdatagoodata = datacall SendMsgsend(0x02 sizeof(GooData)ampmsg)

THANK YOU

Page 2: TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

TinyOS - Design Design

What is TinyOSTinyOS is a highly modular softwareenvironment tailored to the requirements ofNetwork Sensors stressing efficiencymodularity and concurrency

bull Capable of fine grained concurrency (event-driven architecture)bull1048633Small physical size

bull Fewer context switches (FIFOnon-preemptable scheduling)

bull1048633Efficient Resource Utilization (Get done quickly and sleep)

bull1048633Highly Modular

TinyOS - Features

Event-driven architecture Lower layer sends events to higher layer Low overheadndash No busy -wait cycles

Interrupt drivenTwo kinds of interrupt 10486331048633 Clock 10486331048633 Radio

Component driven programming model 10486331048633 Size - 400 bytes 10486331048633 Extremely flexible component graph Single Single-shared stack shared stack

Features Contd

Network management - Active Messaging

No kernel process management virtual memory

File management - Matchbox

2-level FIFO schedulerndash events and tasks

Complete integration with hardware

Hardware Kits

Two Board Sandwich Main CPU board with Radio

Communication 1048633 Secondary Sensor Board 1048633 Allows for expansion and customization 1048633 Current sensors include Acceleration Magnetic Field Temperature Pressure Humidity Light and RF Signal

Strength 1048633 Can control RF transmission

strength amp Sense Reception Strength

Hardware Abstraction

LED (pin numberingHW wiring) CLOCK (counter interrupt) UART (baud rate control transfer) ADC (ADC interrupt handling) RFM (abstracts bit level timing

RFM specific control logic)

Communication stack

building up from the RFM bit level

bit level abstracts away radio specifics

byte level radio component collects individual bits into bytes

packet level constructs packets from bytes

messaging layer interprets packets as messages

Sensor stack

photo and temperature sensing components sits on top of ADC component typical request data wait for data event

TinyOS component model

Component interface commands accepts

(implemented) commands uses events accepts (implemented) events uses

Component implementation functions that implement

interface frame internal state tasks concurrency control

Programming Model

comp1C code

comp3

comp4

ComponentsComponentscompcomp specification specificationCC behaviour behaviourdescdesc select and select and wirewire

specificationspecificationaccepts accepts commandscommandsuses uses commandscommandssignals signals eventseventshandles handles eventsevents

comp2desc

applicationdesc

Scheduler Scheduler 2-level scheduling (events and tasks) single shared stack used by events and function calls

TasksTasks are preemptable by eventsare preemptable by events may call commandsmay call commands may signal eventsmay signal events not preempted by tasksnot preempted by tasks

Events ndash Events ndash Time critical Shorter duration (hand off to task if need be) Interrupts task Last-in first-out semantics (no priority among events) lowest level events support by hardware interruptlowest level events support by hardware interrupt

TinyOS Two-level Scheduling

Tasks do intensive computations Unpreemptable FIFO

scheduling Bounded number of

pending tasks Events handle interrupts

Interrupts trigger lowest level events

Events can signal events call commands or post tasks

Two priorities Eventcommand Tasks

How to handle multiple data flows Datainterrupt are handled by interruptevent

Respond to it quickly A sequence of non-blockingeventcommand (function calls) through the componentgraph eg get bit out of radio hw before it gets lost

Post tasks for long computations eg encoding

bull Assumption long computation are not urgent New events preempt tasks to handle newdata

Receiving a message

What are tasks

Requirement of realtime OS bounded delays between events

Event handler should run to completion within a short duration

If a lot of computation is involved in an event handler we defer execution How Implementing it as a task and scheduling it for later

execution TinyOS has simple FIFO scheduler using which tasks

are scheduled On occurrence of an event a task that is executing is

preempted

Data Memory Model

STATIC memory allocation No heap (malloc) No function pointers

Global variables Available on a per-frame basis

Local variables Saved on the stack Declared within a method

Application

Is the OS with some specific functionality Application is interrupt driven List of interrupts handled depend on list of hardware

components included in the application (eg clock and receiver)

Waits for interrupts On occurrence of interrupt calls interrupt handler

HardwareInterrupts

ISRInterruptHandler

invokes Calls

A Complete Application

Example Inter-Node Communication Sender

Receiver

Message Buffer Ownership

bullTransmission AM gains ownership of the buffer until sendDone(hellip) is signaledbull Reception Applicationrsquos event handler gains ownershipof the buffer but it must return a free buffer for the nextmessage

Potentially Nasty Bug 1

Whatrsquos wrong with the codeSymptom data saved in globalData is lost Reason Racecondition betweentwo tasksSolution Use aqueue or never relyon inter-taskcommunication

uint8_t globalDatatask void processData() call SendDatasend(globalData)command result_t Foobar(uint8_t data) globalData = datapost processData()

Potentially Nasty Bug 2

Whatrsquos wrong with the code

Symptom messageis corruptReason TOS_Msgis allocated in thestack lost whenfunction returns Solution DeclareTOS_Msg msg incomponentrsquos frame

command result_t Foobar(uint8_t data) TOS_Msg msgFooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)

Potentially Nasty Bug 3

Whatrsquos wrong withthe codeSymptom somemessages are lostReason Racecondition betweentwo componentstrying to sharenetwork stack (whichis split-phase) Solution Use aqueue to storepending messages

command result_t Foobar(uint8_t data) FooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)Component

Component 2 command result_t Goobar(uint8_t data) GooData goo = (GooData)msgdatagoodata = datacall SendMsgsend(0x02 sizeof(GooData)ampmsg)

THANK YOU

Page 3: TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

What is TinyOSTinyOS is a highly modular softwareenvironment tailored to the requirements ofNetwork Sensors stressing efficiencymodularity and concurrency

bull Capable of fine grained concurrency (event-driven architecture)bull1048633Small physical size

bull Fewer context switches (FIFOnon-preemptable scheduling)

bull1048633Efficient Resource Utilization (Get done quickly and sleep)

bull1048633Highly Modular

TinyOS - Features

Event-driven architecture Lower layer sends events to higher layer Low overheadndash No busy -wait cycles

Interrupt drivenTwo kinds of interrupt 10486331048633 Clock 10486331048633 Radio

Component driven programming model 10486331048633 Size - 400 bytes 10486331048633 Extremely flexible component graph Single Single-shared stack shared stack

Features Contd

Network management - Active Messaging

No kernel process management virtual memory

File management - Matchbox

2-level FIFO schedulerndash events and tasks

Complete integration with hardware

Hardware Kits

Two Board Sandwich Main CPU board with Radio

Communication 1048633 Secondary Sensor Board 1048633 Allows for expansion and customization 1048633 Current sensors include Acceleration Magnetic Field Temperature Pressure Humidity Light and RF Signal

Strength 1048633 Can control RF transmission

strength amp Sense Reception Strength

Hardware Abstraction

LED (pin numberingHW wiring) CLOCK (counter interrupt) UART (baud rate control transfer) ADC (ADC interrupt handling) RFM (abstracts bit level timing

RFM specific control logic)

Communication stack

building up from the RFM bit level

bit level abstracts away radio specifics

byte level radio component collects individual bits into bytes

packet level constructs packets from bytes

messaging layer interprets packets as messages

Sensor stack

photo and temperature sensing components sits on top of ADC component typical request data wait for data event

TinyOS component model

Component interface commands accepts

(implemented) commands uses events accepts (implemented) events uses

Component implementation functions that implement

interface frame internal state tasks concurrency control

Programming Model

comp1C code

comp3

comp4

ComponentsComponentscompcomp specification specificationCC behaviour behaviourdescdesc select and select and wirewire

specificationspecificationaccepts accepts commandscommandsuses uses commandscommandssignals signals eventseventshandles handles eventsevents

comp2desc

applicationdesc

Scheduler Scheduler 2-level scheduling (events and tasks) single shared stack used by events and function calls

TasksTasks are preemptable by eventsare preemptable by events may call commandsmay call commands may signal eventsmay signal events not preempted by tasksnot preempted by tasks

Events ndash Events ndash Time critical Shorter duration (hand off to task if need be) Interrupts task Last-in first-out semantics (no priority among events) lowest level events support by hardware interruptlowest level events support by hardware interrupt

TinyOS Two-level Scheduling

Tasks do intensive computations Unpreemptable FIFO

scheduling Bounded number of

pending tasks Events handle interrupts

Interrupts trigger lowest level events

Events can signal events call commands or post tasks

Two priorities Eventcommand Tasks

How to handle multiple data flows Datainterrupt are handled by interruptevent

Respond to it quickly A sequence of non-blockingeventcommand (function calls) through the componentgraph eg get bit out of radio hw before it gets lost

Post tasks for long computations eg encoding

bull Assumption long computation are not urgent New events preempt tasks to handle newdata

Receiving a message

What are tasks

Requirement of realtime OS bounded delays between events

Event handler should run to completion within a short duration

If a lot of computation is involved in an event handler we defer execution How Implementing it as a task and scheduling it for later

execution TinyOS has simple FIFO scheduler using which tasks

are scheduled On occurrence of an event a task that is executing is

preempted

Data Memory Model

STATIC memory allocation No heap (malloc) No function pointers

Global variables Available on a per-frame basis

Local variables Saved on the stack Declared within a method

Application

Is the OS with some specific functionality Application is interrupt driven List of interrupts handled depend on list of hardware

components included in the application (eg clock and receiver)

Waits for interrupts On occurrence of interrupt calls interrupt handler

HardwareInterrupts

ISRInterruptHandler

invokes Calls

A Complete Application

Example Inter-Node Communication Sender

Receiver

Message Buffer Ownership

bullTransmission AM gains ownership of the buffer until sendDone(hellip) is signaledbull Reception Applicationrsquos event handler gains ownershipof the buffer but it must return a free buffer for the nextmessage

Potentially Nasty Bug 1

Whatrsquos wrong with the codeSymptom data saved in globalData is lost Reason Racecondition betweentwo tasksSolution Use aqueue or never relyon inter-taskcommunication

uint8_t globalDatatask void processData() call SendDatasend(globalData)command result_t Foobar(uint8_t data) globalData = datapost processData()

Potentially Nasty Bug 2

Whatrsquos wrong with the code

Symptom messageis corruptReason TOS_Msgis allocated in thestack lost whenfunction returns Solution DeclareTOS_Msg msg incomponentrsquos frame

command result_t Foobar(uint8_t data) TOS_Msg msgFooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)

Potentially Nasty Bug 3

Whatrsquos wrong withthe codeSymptom somemessages are lostReason Racecondition betweentwo componentstrying to sharenetwork stack (whichis split-phase) Solution Use aqueue to storepending messages

command result_t Foobar(uint8_t data) FooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)Component

Component 2 command result_t Goobar(uint8_t data) GooData goo = (GooData)msgdatagoodata = datacall SendMsgsend(0x02 sizeof(GooData)ampmsg)

THANK YOU

Page 4: TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

TinyOS - Features

Event-driven architecture Lower layer sends events to higher layer Low overheadndash No busy -wait cycles

Interrupt drivenTwo kinds of interrupt 10486331048633 Clock 10486331048633 Radio

Component driven programming model 10486331048633 Size - 400 bytes 10486331048633 Extremely flexible component graph Single Single-shared stack shared stack

Features Contd

Network management - Active Messaging

No kernel process management virtual memory

File management - Matchbox

2-level FIFO schedulerndash events and tasks

Complete integration with hardware

Hardware Kits

Two Board Sandwich Main CPU board with Radio

Communication 1048633 Secondary Sensor Board 1048633 Allows for expansion and customization 1048633 Current sensors include Acceleration Magnetic Field Temperature Pressure Humidity Light and RF Signal

Strength 1048633 Can control RF transmission

strength amp Sense Reception Strength

Hardware Abstraction

LED (pin numberingHW wiring) CLOCK (counter interrupt) UART (baud rate control transfer) ADC (ADC interrupt handling) RFM (abstracts bit level timing

RFM specific control logic)

Communication stack

building up from the RFM bit level

bit level abstracts away radio specifics

byte level radio component collects individual bits into bytes

packet level constructs packets from bytes

messaging layer interprets packets as messages

Sensor stack

photo and temperature sensing components sits on top of ADC component typical request data wait for data event

TinyOS component model

Component interface commands accepts

(implemented) commands uses events accepts (implemented) events uses

Component implementation functions that implement

interface frame internal state tasks concurrency control

Programming Model

comp1C code

comp3

comp4

ComponentsComponentscompcomp specification specificationCC behaviour behaviourdescdesc select and select and wirewire

specificationspecificationaccepts accepts commandscommandsuses uses commandscommandssignals signals eventseventshandles handles eventsevents

comp2desc

applicationdesc

Scheduler Scheduler 2-level scheduling (events and tasks) single shared stack used by events and function calls

TasksTasks are preemptable by eventsare preemptable by events may call commandsmay call commands may signal eventsmay signal events not preempted by tasksnot preempted by tasks

Events ndash Events ndash Time critical Shorter duration (hand off to task if need be) Interrupts task Last-in first-out semantics (no priority among events) lowest level events support by hardware interruptlowest level events support by hardware interrupt

TinyOS Two-level Scheduling

Tasks do intensive computations Unpreemptable FIFO

scheduling Bounded number of

pending tasks Events handle interrupts

Interrupts trigger lowest level events

Events can signal events call commands or post tasks

Two priorities Eventcommand Tasks

How to handle multiple data flows Datainterrupt are handled by interruptevent

Respond to it quickly A sequence of non-blockingeventcommand (function calls) through the componentgraph eg get bit out of radio hw before it gets lost

Post tasks for long computations eg encoding

bull Assumption long computation are not urgent New events preempt tasks to handle newdata

Receiving a message

What are tasks

Requirement of realtime OS bounded delays between events

Event handler should run to completion within a short duration

If a lot of computation is involved in an event handler we defer execution How Implementing it as a task and scheduling it for later

execution TinyOS has simple FIFO scheduler using which tasks

are scheduled On occurrence of an event a task that is executing is

preempted

Data Memory Model

STATIC memory allocation No heap (malloc) No function pointers

Global variables Available on a per-frame basis

Local variables Saved on the stack Declared within a method

Application

Is the OS with some specific functionality Application is interrupt driven List of interrupts handled depend on list of hardware

components included in the application (eg clock and receiver)

Waits for interrupts On occurrence of interrupt calls interrupt handler

HardwareInterrupts

ISRInterruptHandler

invokes Calls

A Complete Application

Example Inter-Node Communication Sender

Receiver

Message Buffer Ownership

bullTransmission AM gains ownership of the buffer until sendDone(hellip) is signaledbull Reception Applicationrsquos event handler gains ownershipof the buffer but it must return a free buffer for the nextmessage

Potentially Nasty Bug 1

Whatrsquos wrong with the codeSymptom data saved in globalData is lost Reason Racecondition betweentwo tasksSolution Use aqueue or never relyon inter-taskcommunication

uint8_t globalDatatask void processData() call SendDatasend(globalData)command result_t Foobar(uint8_t data) globalData = datapost processData()

Potentially Nasty Bug 2

Whatrsquos wrong with the code

Symptom messageis corruptReason TOS_Msgis allocated in thestack lost whenfunction returns Solution DeclareTOS_Msg msg incomponentrsquos frame

command result_t Foobar(uint8_t data) TOS_Msg msgFooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)

Potentially Nasty Bug 3

Whatrsquos wrong withthe codeSymptom somemessages are lostReason Racecondition betweentwo componentstrying to sharenetwork stack (whichis split-phase) Solution Use aqueue to storepending messages

command result_t Foobar(uint8_t data) FooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)Component

Component 2 command result_t Goobar(uint8_t data) GooData goo = (GooData)msgdatagoodata = datacall SendMsgsend(0x02 sizeof(GooData)ampmsg)

THANK YOU

Page 5: TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

Features Contd

Network management - Active Messaging

No kernel process management virtual memory

File management - Matchbox

2-level FIFO schedulerndash events and tasks

Complete integration with hardware

Hardware Kits

Two Board Sandwich Main CPU board with Radio

Communication 1048633 Secondary Sensor Board 1048633 Allows for expansion and customization 1048633 Current sensors include Acceleration Magnetic Field Temperature Pressure Humidity Light and RF Signal

Strength 1048633 Can control RF transmission

strength amp Sense Reception Strength

Hardware Abstraction

LED (pin numberingHW wiring) CLOCK (counter interrupt) UART (baud rate control transfer) ADC (ADC interrupt handling) RFM (abstracts bit level timing

RFM specific control logic)

Communication stack

building up from the RFM bit level

bit level abstracts away radio specifics

byte level radio component collects individual bits into bytes

packet level constructs packets from bytes

messaging layer interprets packets as messages

Sensor stack

photo and temperature sensing components sits on top of ADC component typical request data wait for data event

TinyOS component model

Component interface commands accepts

(implemented) commands uses events accepts (implemented) events uses

Component implementation functions that implement

interface frame internal state tasks concurrency control

Programming Model

comp1C code

comp3

comp4

ComponentsComponentscompcomp specification specificationCC behaviour behaviourdescdesc select and select and wirewire

specificationspecificationaccepts accepts commandscommandsuses uses commandscommandssignals signals eventseventshandles handles eventsevents

comp2desc

applicationdesc

Scheduler Scheduler 2-level scheduling (events and tasks) single shared stack used by events and function calls

TasksTasks are preemptable by eventsare preemptable by events may call commandsmay call commands may signal eventsmay signal events not preempted by tasksnot preempted by tasks

Events ndash Events ndash Time critical Shorter duration (hand off to task if need be) Interrupts task Last-in first-out semantics (no priority among events) lowest level events support by hardware interruptlowest level events support by hardware interrupt

TinyOS Two-level Scheduling

Tasks do intensive computations Unpreemptable FIFO

scheduling Bounded number of

pending tasks Events handle interrupts

Interrupts trigger lowest level events

Events can signal events call commands or post tasks

Two priorities Eventcommand Tasks

How to handle multiple data flows Datainterrupt are handled by interruptevent

Respond to it quickly A sequence of non-blockingeventcommand (function calls) through the componentgraph eg get bit out of radio hw before it gets lost

Post tasks for long computations eg encoding

bull Assumption long computation are not urgent New events preempt tasks to handle newdata

Receiving a message

What are tasks

Requirement of realtime OS bounded delays between events

Event handler should run to completion within a short duration

If a lot of computation is involved in an event handler we defer execution How Implementing it as a task and scheduling it for later

execution TinyOS has simple FIFO scheduler using which tasks

are scheduled On occurrence of an event a task that is executing is

preempted

Data Memory Model

STATIC memory allocation No heap (malloc) No function pointers

Global variables Available on a per-frame basis

Local variables Saved on the stack Declared within a method

Application

Is the OS with some specific functionality Application is interrupt driven List of interrupts handled depend on list of hardware

components included in the application (eg clock and receiver)

Waits for interrupts On occurrence of interrupt calls interrupt handler

HardwareInterrupts

ISRInterruptHandler

invokes Calls

A Complete Application

Example Inter-Node Communication Sender

Receiver

Message Buffer Ownership

bullTransmission AM gains ownership of the buffer until sendDone(hellip) is signaledbull Reception Applicationrsquos event handler gains ownershipof the buffer but it must return a free buffer for the nextmessage

Potentially Nasty Bug 1

Whatrsquos wrong with the codeSymptom data saved in globalData is lost Reason Racecondition betweentwo tasksSolution Use aqueue or never relyon inter-taskcommunication

uint8_t globalDatatask void processData() call SendDatasend(globalData)command result_t Foobar(uint8_t data) globalData = datapost processData()

Potentially Nasty Bug 2

Whatrsquos wrong with the code

Symptom messageis corruptReason TOS_Msgis allocated in thestack lost whenfunction returns Solution DeclareTOS_Msg msg incomponentrsquos frame

command result_t Foobar(uint8_t data) TOS_Msg msgFooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)

Potentially Nasty Bug 3

Whatrsquos wrong withthe codeSymptom somemessages are lostReason Racecondition betweentwo componentstrying to sharenetwork stack (whichis split-phase) Solution Use aqueue to storepending messages

command result_t Foobar(uint8_t data) FooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)Component

Component 2 command result_t Goobar(uint8_t data) GooData goo = (GooData)msgdatagoodata = datacall SendMsgsend(0x02 sizeof(GooData)ampmsg)

THANK YOU

Page 6: TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

Hardware Kits

Two Board Sandwich Main CPU board with Radio

Communication 1048633 Secondary Sensor Board 1048633 Allows for expansion and customization 1048633 Current sensors include Acceleration Magnetic Field Temperature Pressure Humidity Light and RF Signal

Strength 1048633 Can control RF transmission

strength amp Sense Reception Strength

Hardware Abstraction

LED (pin numberingHW wiring) CLOCK (counter interrupt) UART (baud rate control transfer) ADC (ADC interrupt handling) RFM (abstracts bit level timing

RFM specific control logic)

Communication stack

building up from the RFM bit level

bit level abstracts away radio specifics

byte level radio component collects individual bits into bytes

packet level constructs packets from bytes

messaging layer interprets packets as messages

Sensor stack

photo and temperature sensing components sits on top of ADC component typical request data wait for data event

TinyOS component model

Component interface commands accepts

(implemented) commands uses events accepts (implemented) events uses

Component implementation functions that implement

interface frame internal state tasks concurrency control

Programming Model

comp1C code

comp3

comp4

ComponentsComponentscompcomp specification specificationCC behaviour behaviourdescdesc select and select and wirewire

specificationspecificationaccepts accepts commandscommandsuses uses commandscommandssignals signals eventseventshandles handles eventsevents

comp2desc

applicationdesc

Scheduler Scheduler 2-level scheduling (events and tasks) single shared stack used by events and function calls

TasksTasks are preemptable by eventsare preemptable by events may call commandsmay call commands may signal eventsmay signal events not preempted by tasksnot preempted by tasks

Events ndash Events ndash Time critical Shorter duration (hand off to task if need be) Interrupts task Last-in first-out semantics (no priority among events) lowest level events support by hardware interruptlowest level events support by hardware interrupt

TinyOS Two-level Scheduling

Tasks do intensive computations Unpreemptable FIFO

scheduling Bounded number of

pending tasks Events handle interrupts

Interrupts trigger lowest level events

Events can signal events call commands or post tasks

Two priorities Eventcommand Tasks

How to handle multiple data flows Datainterrupt are handled by interruptevent

Respond to it quickly A sequence of non-blockingeventcommand (function calls) through the componentgraph eg get bit out of radio hw before it gets lost

Post tasks for long computations eg encoding

bull Assumption long computation are not urgent New events preempt tasks to handle newdata

Receiving a message

What are tasks

Requirement of realtime OS bounded delays between events

Event handler should run to completion within a short duration

If a lot of computation is involved in an event handler we defer execution How Implementing it as a task and scheduling it for later

execution TinyOS has simple FIFO scheduler using which tasks

are scheduled On occurrence of an event a task that is executing is

preempted

Data Memory Model

STATIC memory allocation No heap (malloc) No function pointers

Global variables Available on a per-frame basis

Local variables Saved on the stack Declared within a method

Application

Is the OS with some specific functionality Application is interrupt driven List of interrupts handled depend on list of hardware

components included in the application (eg clock and receiver)

Waits for interrupts On occurrence of interrupt calls interrupt handler

HardwareInterrupts

ISRInterruptHandler

invokes Calls

A Complete Application

Example Inter-Node Communication Sender

Receiver

Message Buffer Ownership

bullTransmission AM gains ownership of the buffer until sendDone(hellip) is signaledbull Reception Applicationrsquos event handler gains ownershipof the buffer but it must return a free buffer for the nextmessage

Potentially Nasty Bug 1

Whatrsquos wrong with the codeSymptom data saved in globalData is lost Reason Racecondition betweentwo tasksSolution Use aqueue or never relyon inter-taskcommunication

uint8_t globalDatatask void processData() call SendDatasend(globalData)command result_t Foobar(uint8_t data) globalData = datapost processData()

Potentially Nasty Bug 2

Whatrsquos wrong with the code

Symptom messageis corruptReason TOS_Msgis allocated in thestack lost whenfunction returns Solution DeclareTOS_Msg msg incomponentrsquos frame

command result_t Foobar(uint8_t data) TOS_Msg msgFooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)

Potentially Nasty Bug 3

Whatrsquos wrong withthe codeSymptom somemessages are lostReason Racecondition betweentwo componentstrying to sharenetwork stack (whichis split-phase) Solution Use aqueue to storepending messages

command result_t Foobar(uint8_t data) FooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)Component

Component 2 command result_t Goobar(uint8_t data) GooData goo = (GooData)msgdatagoodata = datacall SendMsgsend(0x02 sizeof(GooData)ampmsg)

THANK YOU

Page 7: TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

Hardware Abstraction

LED (pin numberingHW wiring) CLOCK (counter interrupt) UART (baud rate control transfer) ADC (ADC interrupt handling) RFM (abstracts bit level timing

RFM specific control logic)

Communication stack

building up from the RFM bit level

bit level abstracts away radio specifics

byte level radio component collects individual bits into bytes

packet level constructs packets from bytes

messaging layer interprets packets as messages

Sensor stack

photo and temperature sensing components sits on top of ADC component typical request data wait for data event

TinyOS component model

Component interface commands accepts

(implemented) commands uses events accepts (implemented) events uses

Component implementation functions that implement

interface frame internal state tasks concurrency control

Programming Model

comp1C code

comp3

comp4

ComponentsComponentscompcomp specification specificationCC behaviour behaviourdescdesc select and select and wirewire

specificationspecificationaccepts accepts commandscommandsuses uses commandscommandssignals signals eventseventshandles handles eventsevents

comp2desc

applicationdesc

Scheduler Scheduler 2-level scheduling (events and tasks) single shared stack used by events and function calls

TasksTasks are preemptable by eventsare preemptable by events may call commandsmay call commands may signal eventsmay signal events not preempted by tasksnot preempted by tasks

Events ndash Events ndash Time critical Shorter duration (hand off to task if need be) Interrupts task Last-in first-out semantics (no priority among events) lowest level events support by hardware interruptlowest level events support by hardware interrupt

TinyOS Two-level Scheduling

Tasks do intensive computations Unpreemptable FIFO

scheduling Bounded number of

pending tasks Events handle interrupts

Interrupts trigger lowest level events

Events can signal events call commands or post tasks

Two priorities Eventcommand Tasks

How to handle multiple data flows Datainterrupt are handled by interruptevent

Respond to it quickly A sequence of non-blockingeventcommand (function calls) through the componentgraph eg get bit out of radio hw before it gets lost

Post tasks for long computations eg encoding

bull Assumption long computation are not urgent New events preempt tasks to handle newdata

Receiving a message

What are tasks

Requirement of realtime OS bounded delays between events

Event handler should run to completion within a short duration

If a lot of computation is involved in an event handler we defer execution How Implementing it as a task and scheduling it for later

execution TinyOS has simple FIFO scheduler using which tasks

are scheduled On occurrence of an event a task that is executing is

preempted

Data Memory Model

STATIC memory allocation No heap (malloc) No function pointers

Global variables Available on a per-frame basis

Local variables Saved on the stack Declared within a method

Application

Is the OS with some specific functionality Application is interrupt driven List of interrupts handled depend on list of hardware

components included in the application (eg clock and receiver)

Waits for interrupts On occurrence of interrupt calls interrupt handler

HardwareInterrupts

ISRInterruptHandler

invokes Calls

A Complete Application

Example Inter-Node Communication Sender

Receiver

Message Buffer Ownership

bullTransmission AM gains ownership of the buffer until sendDone(hellip) is signaledbull Reception Applicationrsquos event handler gains ownershipof the buffer but it must return a free buffer for the nextmessage

Potentially Nasty Bug 1

Whatrsquos wrong with the codeSymptom data saved in globalData is lost Reason Racecondition betweentwo tasksSolution Use aqueue or never relyon inter-taskcommunication

uint8_t globalDatatask void processData() call SendDatasend(globalData)command result_t Foobar(uint8_t data) globalData = datapost processData()

Potentially Nasty Bug 2

Whatrsquos wrong with the code

Symptom messageis corruptReason TOS_Msgis allocated in thestack lost whenfunction returns Solution DeclareTOS_Msg msg incomponentrsquos frame

command result_t Foobar(uint8_t data) TOS_Msg msgFooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)

Potentially Nasty Bug 3

Whatrsquos wrong withthe codeSymptom somemessages are lostReason Racecondition betweentwo componentstrying to sharenetwork stack (whichis split-phase) Solution Use aqueue to storepending messages

command result_t Foobar(uint8_t data) FooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)Component

Component 2 command result_t Goobar(uint8_t data) GooData goo = (GooData)msgdatagoodata = datacall SendMsgsend(0x02 sizeof(GooData)ampmsg)

THANK YOU

Page 8: TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

Communication stack

building up from the RFM bit level

bit level abstracts away radio specifics

byte level radio component collects individual bits into bytes

packet level constructs packets from bytes

messaging layer interprets packets as messages

Sensor stack

photo and temperature sensing components sits on top of ADC component typical request data wait for data event

TinyOS component model

Component interface commands accepts

(implemented) commands uses events accepts (implemented) events uses

Component implementation functions that implement

interface frame internal state tasks concurrency control

Programming Model

comp1C code

comp3

comp4

ComponentsComponentscompcomp specification specificationCC behaviour behaviourdescdesc select and select and wirewire

specificationspecificationaccepts accepts commandscommandsuses uses commandscommandssignals signals eventseventshandles handles eventsevents

comp2desc

applicationdesc

Scheduler Scheduler 2-level scheduling (events and tasks) single shared stack used by events and function calls

TasksTasks are preemptable by eventsare preemptable by events may call commandsmay call commands may signal eventsmay signal events not preempted by tasksnot preempted by tasks

Events ndash Events ndash Time critical Shorter duration (hand off to task if need be) Interrupts task Last-in first-out semantics (no priority among events) lowest level events support by hardware interruptlowest level events support by hardware interrupt

TinyOS Two-level Scheduling

Tasks do intensive computations Unpreemptable FIFO

scheduling Bounded number of

pending tasks Events handle interrupts

Interrupts trigger lowest level events

Events can signal events call commands or post tasks

Two priorities Eventcommand Tasks

How to handle multiple data flows Datainterrupt are handled by interruptevent

Respond to it quickly A sequence of non-blockingeventcommand (function calls) through the componentgraph eg get bit out of radio hw before it gets lost

Post tasks for long computations eg encoding

bull Assumption long computation are not urgent New events preempt tasks to handle newdata

Receiving a message

What are tasks

Requirement of realtime OS bounded delays between events

Event handler should run to completion within a short duration

If a lot of computation is involved in an event handler we defer execution How Implementing it as a task and scheduling it for later

execution TinyOS has simple FIFO scheduler using which tasks

are scheduled On occurrence of an event a task that is executing is

preempted

Data Memory Model

STATIC memory allocation No heap (malloc) No function pointers

Global variables Available on a per-frame basis

Local variables Saved on the stack Declared within a method

Application

Is the OS with some specific functionality Application is interrupt driven List of interrupts handled depend on list of hardware

components included in the application (eg clock and receiver)

Waits for interrupts On occurrence of interrupt calls interrupt handler

HardwareInterrupts

ISRInterruptHandler

invokes Calls

A Complete Application

Example Inter-Node Communication Sender

Receiver

Message Buffer Ownership

bullTransmission AM gains ownership of the buffer until sendDone(hellip) is signaledbull Reception Applicationrsquos event handler gains ownershipof the buffer but it must return a free buffer for the nextmessage

Potentially Nasty Bug 1

Whatrsquos wrong with the codeSymptom data saved in globalData is lost Reason Racecondition betweentwo tasksSolution Use aqueue or never relyon inter-taskcommunication

uint8_t globalDatatask void processData() call SendDatasend(globalData)command result_t Foobar(uint8_t data) globalData = datapost processData()

Potentially Nasty Bug 2

Whatrsquos wrong with the code

Symptom messageis corruptReason TOS_Msgis allocated in thestack lost whenfunction returns Solution DeclareTOS_Msg msg incomponentrsquos frame

command result_t Foobar(uint8_t data) TOS_Msg msgFooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)

Potentially Nasty Bug 3

Whatrsquos wrong withthe codeSymptom somemessages are lostReason Racecondition betweentwo componentstrying to sharenetwork stack (whichis split-phase) Solution Use aqueue to storepending messages

command result_t Foobar(uint8_t data) FooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)Component

Component 2 command result_t Goobar(uint8_t data) GooData goo = (GooData)msgdatagoodata = datacall SendMsgsend(0x02 sizeof(GooData)ampmsg)

THANK YOU

Page 9: TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

Sensor stack

photo and temperature sensing components sits on top of ADC component typical request data wait for data event

TinyOS component model

Component interface commands accepts

(implemented) commands uses events accepts (implemented) events uses

Component implementation functions that implement

interface frame internal state tasks concurrency control

Programming Model

comp1C code

comp3

comp4

ComponentsComponentscompcomp specification specificationCC behaviour behaviourdescdesc select and select and wirewire

specificationspecificationaccepts accepts commandscommandsuses uses commandscommandssignals signals eventseventshandles handles eventsevents

comp2desc

applicationdesc

Scheduler Scheduler 2-level scheduling (events and tasks) single shared stack used by events and function calls

TasksTasks are preemptable by eventsare preemptable by events may call commandsmay call commands may signal eventsmay signal events not preempted by tasksnot preempted by tasks

Events ndash Events ndash Time critical Shorter duration (hand off to task if need be) Interrupts task Last-in first-out semantics (no priority among events) lowest level events support by hardware interruptlowest level events support by hardware interrupt

TinyOS Two-level Scheduling

Tasks do intensive computations Unpreemptable FIFO

scheduling Bounded number of

pending tasks Events handle interrupts

Interrupts trigger lowest level events

Events can signal events call commands or post tasks

Two priorities Eventcommand Tasks

How to handle multiple data flows Datainterrupt are handled by interruptevent

Respond to it quickly A sequence of non-blockingeventcommand (function calls) through the componentgraph eg get bit out of radio hw before it gets lost

Post tasks for long computations eg encoding

bull Assumption long computation are not urgent New events preempt tasks to handle newdata

Receiving a message

What are tasks

Requirement of realtime OS bounded delays between events

Event handler should run to completion within a short duration

If a lot of computation is involved in an event handler we defer execution How Implementing it as a task and scheduling it for later

execution TinyOS has simple FIFO scheduler using which tasks

are scheduled On occurrence of an event a task that is executing is

preempted

Data Memory Model

STATIC memory allocation No heap (malloc) No function pointers

Global variables Available on a per-frame basis

Local variables Saved on the stack Declared within a method

Application

Is the OS with some specific functionality Application is interrupt driven List of interrupts handled depend on list of hardware

components included in the application (eg clock and receiver)

Waits for interrupts On occurrence of interrupt calls interrupt handler

HardwareInterrupts

ISRInterruptHandler

invokes Calls

A Complete Application

Example Inter-Node Communication Sender

Receiver

Message Buffer Ownership

bullTransmission AM gains ownership of the buffer until sendDone(hellip) is signaledbull Reception Applicationrsquos event handler gains ownershipof the buffer but it must return a free buffer for the nextmessage

Potentially Nasty Bug 1

Whatrsquos wrong with the codeSymptom data saved in globalData is lost Reason Racecondition betweentwo tasksSolution Use aqueue or never relyon inter-taskcommunication

uint8_t globalDatatask void processData() call SendDatasend(globalData)command result_t Foobar(uint8_t data) globalData = datapost processData()

Potentially Nasty Bug 2

Whatrsquos wrong with the code

Symptom messageis corruptReason TOS_Msgis allocated in thestack lost whenfunction returns Solution DeclareTOS_Msg msg incomponentrsquos frame

command result_t Foobar(uint8_t data) TOS_Msg msgFooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)

Potentially Nasty Bug 3

Whatrsquos wrong withthe codeSymptom somemessages are lostReason Racecondition betweentwo componentstrying to sharenetwork stack (whichis split-phase) Solution Use aqueue to storepending messages

command result_t Foobar(uint8_t data) FooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)Component

Component 2 command result_t Goobar(uint8_t data) GooData goo = (GooData)msgdatagoodata = datacall SendMsgsend(0x02 sizeof(GooData)ampmsg)

THANK YOU

Page 10: TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

TinyOS component model

Component interface commands accepts

(implemented) commands uses events accepts (implemented) events uses

Component implementation functions that implement

interface frame internal state tasks concurrency control

Programming Model

comp1C code

comp3

comp4

ComponentsComponentscompcomp specification specificationCC behaviour behaviourdescdesc select and select and wirewire

specificationspecificationaccepts accepts commandscommandsuses uses commandscommandssignals signals eventseventshandles handles eventsevents

comp2desc

applicationdesc

Scheduler Scheduler 2-level scheduling (events and tasks) single shared stack used by events and function calls

TasksTasks are preemptable by eventsare preemptable by events may call commandsmay call commands may signal eventsmay signal events not preempted by tasksnot preempted by tasks

Events ndash Events ndash Time critical Shorter duration (hand off to task if need be) Interrupts task Last-in first-out semantics (no priority among events) lowest level events support by hardware interruptlowest level events support by hardware interrupt

TinyOS Two-level Scheduling

Tasks do intensive computations Unpreemptable FIFO

scheduling Bounded number of

pending tasks Events handle interrupts

Interrupts trigger lowest level events

Events can signal events call commands or post tasks

Two priorities Eventcommand Tasks

How to handle multiple data flows Datainterrupt are handled by interruptevent

Respond to it quickly A sequence of non-blockingeventcommand (function calls) through the componentgraph eg get bit out of radio hw before it gets lost

Post tasks for long computations eg encoding

bull Assumption long computation are not urgent New events preempt tasks to handle newdata

Receiving a message

What are tasks

Requirement of realtime OS bounded delays between events

Event handler should run to completion within a short duration

If a lot of computation is involved in an event handler we defer execution How Implementing it as a task and scheduling it for later

execution TinyOS has simple FIFO scheduler using which tasks

are scheduled On occurrence of an event a task that is executing is

preempted

Data Memory Model

STATIC memory allocation No heap (malloc) No function pointers

Global variables Available on a per-frame basis

Local variables Saved on the stack Declared within a method

Application

Is the OS with some specific functionality Application is interrupt driven List of interrupts handled depend on list of hardware

components included in the application (eg clock and receiver)

Waits for interrupts On occurrence of interrupt calls interrupt handler

HardwareInterrupts

ISRInterruptHandler

invokes Calls

A Complete Application

Example Inter-Node Communication Sender

Receiver

Message Buffer Ownership

bullTransmission AM gains ownership of the buffer until sendDone(hellip) is signaledbull Reception Applicationrsquos event handler gains ownershipof the buffer but it must return a free buffer for the nextmessage

Potentially Nasty Bug 1

Whatrsquos wrong with the codeSymptom data saved in globalData is lost Reason Racecondition betweentwo tasksSolution Use aqueue or never relyon inter-taskcommunication

uint8_t globalDatatask void processData() call SendDatasend(globalData)command result_t Foobar(uint8_t data) globalData = datapost processData()

Potentially Nasty Bug 2

Whatrsquos wrong with the code

Symptom messageis corruptReason TOS_Msgis allocated in thestack lost whenfunction returns Solution DeclareTOS_Msg msg incomponentrsquos frame

command result_t Foobar(uint8_t data) TOS_Msg msgFooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)

Potentially Nasty Bug 3

Whatrsquos wrong withthe codeSymptom somemessages are lostReason Racecondition betweentwo componentstrying to sharenetwork stack (whichis split-phase) Solution Use aqueue to storepending messages

command result_t Foobar(uint8_t data) FooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)Component

Component 2 command result_t Goobar(uint8_t data) GooData goo = (GooData)msgdatagoodata = datacall SendMsgsend(0x02 sizeof(GooData)ampmsg)

THANK YOU

Page 11: TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

Programming Model

comp1C code

comp3

comp4

ComponentsComponentscompcomp specification specificationCC behaviour behaviourdescdesc select and select and wirewire

specificationspecificationaccepts accepts commandscommandsuses uses commandscommandssignals signals eventseventshandles handles eventsevents

comp2desc

applicationdesc

Scheduler Scheduler 2-level scheduling (events and tasks) single shared stack used by events and function calls

TasksTasks are preemptable by eventsare preemptable by events may call commandsmay call commands may signal eventsmay signal events not preempted by tasksnot preempted by tasks

Events ndash Events ndash Time critical Shorter duration (hand off to task if need be) Interrupts task Last-in first-out semantics (no priority among events) lowest level events support by hardware interruptlowest level events support by hardware interrupt

TinyOS Two-level Scheduling

Tasks do intensive computations Unpreemptable FIFO

scheduling Bounded number of

pending tasks Events handle interrupts

Interrupts trigger lowest level events

Events can signal events call commands or post tasks

Two priorities Eventcommand Tasks

How to handle multiple data flows Datainterrupt are handled by interruptevent

Respond to it quickly A sequence of non-blockingeventcommand (function calls) through the componentgraph eg get bit out of radio hw before it gets lost

Post tasks for long computations eg encoding

bull Assumption long computation are not urgent New events preempt tasks to handle newdata

Receiving a message

What are tasks

Requirement of realtime OS bounded delays between events

Event handler should run to completion within a short duration

If a lot of computation is involved in an event handler we defer execution How Implementing it as a task and scheduling it for later

execution TinyOS has simple FIFO scheduler using which tasks

are scheduled On occurrence of an event a task that is executing is

preempted

Data Memory Model

STATIC memory allocation No heap (malloc) No function pointers

Global variables Available on a per-frame basis

Local variables Saved on the stack Declared within a method

Application

Is the OS with some specific functionality Application is interrupt driven List of interrupts handled depend on list of hardware

components included in the application (eg clock and receiver)

Waits for interrupts On occurrence of interrupt calls interrupt handler

HardwareInterrupts

ISRInterruptHandler

invokes Calls

A Complete Application

Example Inter-Node Communication Sender

Receiver

Message Buffer Ownership

bullTransmission AM gains ownership of the buffer until sendDone(hellip) is signaledbull Reception Applicationrsquos event handler gains ownershipof the buffer but it must return a free buffer for the nextmessage

Potentially Nasty Bug 1

Whatrsquos wrong with the codeSymptom data saved in globalData is lost Reason Racecondition betweentwo tasksSolution Use aqueue or never relyon inter-taskcommunication

uint8_t globalDatatask void processData() call SendDatasend(globalData)command result_t Foobar(uint8_t data) globalData = datapost processData()

Potentially Nasty Bug 2

Whatrsquos wrong with the code

Symptom messageis corruptReason TOS_Msgis allocated in thestack lost whenfunction returns Solution DeclareTOS_Msg msg incomponentrsquos frame

command result_t Foobar(uint8_t data) TOS_Msg msgFooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)

Potentially Nasty Bug 3

Whatrsquos wrong withthe codeSymptom somemessages are lostReason Racecondition betweentwo componentstrying to sharenetwork stack (whichis split-phase) Solution Use aqueue to storepending messages

command result_t Foobar(uint8_t data) FooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)Component

Component 2 command result_t Goobar(uint8_t data) GooData goo = (GooData)msgdatagoodata = datacall SendMsgsend(0x02 sizeof(GooData)ampmsg)

THANK YOU

Page 12: TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

Scheduler Scheduler 2-level scheduling (events and tasks) single shared stack used by events and function calls

TasksTasks are preemptable by eventsare preemptable by events may call commandsmay call commands may signal eventsmay signal events not preempted by tasksnot preempted by tasks

Events ndash Events ndash Time critical Shorter duration (hand off to task if need be) Interrupts task Last-in first-out semantics (no priority among events) lowest level events support by hardware interruptlowest level events support by hardware interrupt

TinyOS Two-level Scheduling

Tasks do intensive computations Unpreemptable FIFO

scheduling Bounded number of

pending tasks Events handle interrupts

Interrupts trigger lowest level events

Events can signal events call commands or post tasks

Two priorities Eventcommand Tasks

How to handle multiple data flows Datainterrupt are handled by interruptevent

Respond to it quickly A sequence of non-blockingeventcommand (function calls) through the componentgraph eg get bit out of radio hw before it gets lost

Post tasks for long computations eg encoding

bull Assumption long computation are not urgent New events preempt tasks to handle newdata

Receiving a message

What are tasks

Requirement of realtime OS bounded delays between events

Event handler should run to completion within a short duration

If a lot of computation is involved in an event handler we defer execution How Implementing it as a task and scheduling it for later

execution TinyOS has simple FIFO scheduler using which tasks

are scheduled On occurrence of an event a task that is executing is

preempted

Data Memory Model

STATIC memory allocation No heap (malloc) No function pointers

Global variables Available on a per-frame basis

Local variables Saved on the stack Declared within a method

Application

Is the OS with some specific functionality Application is interrupt driven List of interrupts handled depend on list of hardware

components included in the application (eg clock and receiver)

Waits for interrupts On occurrence of interrupt calls interrupt handler

HardwareInterrupts

ISRInterruptHandler

invokes Calls

A Complete Application

Example Inter-Node Communication Sender

Receiver

Message Buffer Ownership

bullTransmission AM gains ownership of the buffer until sendDone(hellip) is signaledbull Reception Applicationrsquos event handler gains ownershipof the buffer but it must return a free buffer for the nextmessage

Potentially Nasty Bug 1

Whatrsquos wrong with the codeSymptom data saved in globalData is lost Reason Racecondition betweentwo tasksSolution Use aqueue or never relyon inter-taskcommunication

uint8_t globalDatatask void processData() call SendDatasend(globalData)command result_t Foobar(uint8_t data) globalData = datapost processData()

Potentially Nasty Bug 2

Whatrsquos wrong with the code

Symptom messageis corruptReason TOS_Msgis allocated in thestack lost whenfunction returns Solution DeclareTOS_Msg msg incomponentrsquos frame

command result_t Foobar(uint8_t data) TOS_Msg msgFooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)

Potentially Nasty Bug 3

Whatrsquos wrong withthe codeSymptom somemessages are lostReason Racecondition betweentwo componentstrying to sharenetwork stack (whichis split-phase) Solution Use aqueue to storepending messages

command result_t Foobar(uint8_t data) FooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)Component

Component 2 command result_t Goobar(uint8_t data) GooData goo = (GooData)msgdatagoodata = datacall SendMsgsend(0x02 sizeof(GooData)ampmsg)

THANK YOU

Page 13: TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

TinyOS Two-level Scheduling

Tasks do intensive computations Unpreemptable FIFO

scheduling Bounded number of

pending tasks Events handle interrupts

Interrupts trigger lowest level events

Events can signal events call commands or post tasks

Two priorities Eventcommand Tasks

How to handle multiple data flows Datainterrupt are handled by interruptevent

Respond to it quickly A sequence of non-blockingeventcommand (function calls) through the componentgraph eg get bit out of radio hw before it gets lost

Post tasks for long computations eg encoding

bull Assumption long computation are not urgent New events preempt tasks to handle newdata

Receiving a message

What are tasks

Requirement of realtime OS bounded delays between events

Event handler should run to completion within a short duration

If a lot of computation is involved in an event handler we defer execution How Implementing it as a task and scheduling it for later

execution TinyOS has simple FIFO scheduler using which tasks

are scheduled On occurrence of an event a task that is executing is

preempted

Data Memory Model

STATIC memory allocation No heap (malloc) No function pointers

Global variables Available on a per-frame basis

Local variables Saved on the stack Declared within a method

Application

Is the OS with some specific functionality Application is interrupt driven List of interrupts handled depend on list of hardware

components included in the application (eg clock and receiver)

Waits for interrupts On occurrence of interrupt calls interrupt handler

HardwareInterrupts

ISRInterruptHandler

invokes Calls

A Complete Application

Example Inter-Node Communication Sender

Receiver

Message Buffer Ownership

bullTransmission AM gains ownership of the buffer until sendDone(hellip) is signaledbull Reception Applicationrsquos event handler gains ownershipof the buffer but it must return a free buffer for the nextmessage

Potentially Nasty Bug 1

Whatrsquos wrong with the codeSymptom data saved in globalData is lost Reason Racecondition betweentwo tasksSolution Use aqueue or never relyon inter-taskcommunication

uint8_t globalDatatask void processData() call SendDatasend(globalData)command result_t Foobar(uint8_t data) globalData = datapost processData()

Potentially Nasty Bug 2

Whatrsquos wrong with the code

Symptom messageis corruptReason TOS_Msgis allocated in thestack lost whenfunction returns Solution DeclareTOS_Msg msg incomponentrsquos frame

command result_t Foobar(uint8_t data) TOS_Msg msgFooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)

Potentially Nasty Bug 3

Whatrsquos wrong withthe codeSymptom somemessages are lostReason Racecondition betweentwo componentstrying to sharenetwork stack (whichis split-phase) Solution Use aqueue to storepending messages

command result_t Foobar(uint8_t data) FooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)Component

Component 2 command result_t Goobar(uint8_t data) GooData goo = (GooData)msgdatagoodata = datacall SendMsgsend(0x02 sizeof(GooData)ampmsg)

THANK YOU

Page 14: TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

How to handle multiple data flows Datainterrupt are handled by interruptevent

Respond to it quickly A sequence of non-blockingeventcommand (function calls) through the componentgraph eg get bit out of radio hw before it gets lost

Post tasks for long computations eg encoding

bull Assumption long computation are not urgent New events preempt tasks to handle newdata

Receiving a message

What are tasks

Requirement of realtime OS bounded delays between events

Event handler should run to completion within a short duration

If a lot of computation is involved in an event handler we defer execution How Implementing it as a task and scheduling it for later

execution TinyOS has simple FIFO scheduler using which tasks

are scheduled On occurrence of an event a task that is executing is

preempted

Data Memory Model

STATIC memory allocation No heap (malloc) No function pointers

Global variables Available on a per-frame basis

Local variables Saved on the stack Declared within a method

Application

Is the OS with some specific functionality Application is interrupt driven List of interrupts handled depend on list of hardware

components included in the application (eg clock and receiver)

Waits for interrupts On occurrence of interrupt calls interrupt handler

HardwareInterrupts

ISRInterruptHandler

invokes Calls

A Complete Application

Example Inter-Node Communication Sender

Receiver

Message Buffer Ownership

bullTransmission AM gains ownership of the buffer until sendDone(hellip) is signaledbull Reception Applicationrsquos event handler gains ownershipof the buffer but it must return a free buffer for the nextmessage

Potentially Nasty Bug 1

Whatrsquos wrong with the codeSymptom data saved in globalData is lost Reason Racecondition betweentwo tasksSolution Use aqueue or never relyon inter-taskcommunication

uint8_t globalDatatask void processData() call SendDatasend(globalData)command result_t Foobar(uint8_t data) globalData = datapost processData()

Potentially Nasty Bug 2

Whatrsquos wrong with the code

Symptom messageis corruptReason TOS_Msgis allocated in thestack lost whenfunction returns Solution DeclareTOS_Msg msg incomponentrsquos frame

command result_t Foobar(uint8_t data) TOS_Msg msgFooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)

Potentially Nasty Bug 3

Whatrsquos wrong withthe codeSymptom somemessages are lostReason Racecondition betweentwo componentstrying to sharenetwork stack (whichis split-phase) Solution Use aqueue to storepending messages

command result_t Foobar(uint8_t data) FooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)Component

Component 2 command result_t Goobar(uint8_t data) GooData goo = (GooData)msgdatagoodata = datacall SendMsgsend(0x02 sizeof(GooData)ampmsg)

THANK YOU

Page 15: TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

Receiving a message

What are tasks

Requirement of realtime OS bounded delays between events

Event handler should run to completion within a short duration

If a lot of computation is involved in an event handler we defer execution How Implementing it as a task and scheduling it for later

execution TinyOS has simple FIFO scheduler using which tasks

are scheduled On occurrence of an event a task that is executing is

preempted

Data Memory Model

STATIC memory allocation No heap (malloc) No function pointers

Global variables Available on a per-frame basis

Local variables Saved on the stack Declared within a method

Application

Is the OS with some specific functionality Application is interrupt driven List of interrupts handled depend on list of hardware

components included in the application (eg clock and receiver)

Waits for interrupts On occurrence of interrupt calls interrupt handler

HardwareInterrupts

ISRInterruptHandler

invokes Calls

A Complete Application

Example Inter-Node Communication Sender

Receiver

Message Buffer Ownership

bullTransmission AM gains ownership of the buffer until sendDone(hellip) is signaledbull Reception Applicationrsquos event handler gains ownershipof the buffer but it must return a free buffer for the nextmessage

Potentially Nasty Bug 1

Whatrsquos wrong with the codeSymptom data saved in globalData is lost Reason Racecondition betweentwo tasksSolution Use aqueue or never relyon inter-taskcommunication

uint8_t globalDatatask void processData() call SendDatasend(globalData)command result_t Foobar(uint8_t data) globalData = datapost processData()

Potentially Nasty Bug 2

Whatrsquos wrong with the code

Symptom messageis corruptReason TOS_Msgis allocated in thestack lost whenfunction returns Solution DeclareTOS_Msg msg incomponentrsquos frame

command result_t Foobar(uint8_t data) TOS_Msg msgFooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)

Potentially Nasty Bug 3

Whatrsquos wrong withthe codeSymptom somemessages are lostReason Racecondition betweentwo componentstrying to sharenetwork stack (whichis split-phase) Solution Use aqueue to storepending messages

command result_t Foobar(uint8_t data) FooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)Component

Component 2 command result_t Goobar(uint8_t data) GooData goo = (GooData)msgdatagoodata = datacall SendMsgsend(0x02 sizeof(GooData)ampmsg)

THANK YOU

Page 16: TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

What are tasks

Requirement of realtime OS bounded delays between events

Event handler should run to completion within a short duration

If a lot of computation is involved in an event handler we defer execution How Implementing it as a task and scheduling it for later

execution TinyOS has simple FIFO scheduler using which tasks

are scheduled On occurrence of an event a task that is executing is

preempted

Data Memory Model

STATIC memory allocation No heap (malloc) No function pointers

Global variables Available on a per-frame basis

Local variables Saved on the stack Declared within a method

Application

Is the OS with some specific functionality Application is interrupt driven List of interrupts handled depend on list of hardware

components included in the application (eg clock and receiver)

Waits for interrupts On occurrence of interrupt calls interrupt handler

HardwareInterrupts

ISRInterruptHandler

invokes Calls

A Complete Application

Example Inter-Node Communication Sender

Receiver

Message Buffer Ownership

bullTransmission AM gains ownership of the buffer until sendDone(hellip) is signaledbull Reception Applicationrsquos event handler gains ownershipof the buffer but it must return a free buffer for the nextmessage

Potentially Nasty Bug 1

Whatrsquos wrong with the codeSymptom data saved in globalData is lost Reason Racecondition betweentwo tasksSolution Use aqueue or never relyon inter-taskcommunication

uint8_t globalDatatask void processData() call SendDatasend(globalData)command result_t Foobar(uint8_t data) globalData = datapost processData()

Potentially Nasty Bug 2

Whatrsquos wrong with the code

Symptom messageis corruptReason TOS_Msgis allocated in thestack lost whenfunction returns Solution DeclareTOS_Msg msg incomponentrsquos frame

command result_t Foobar(uint8_t data) TOS_Msg msgFooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)

Potentially Nasty Bug 3

Whatrsquos wrong withthe codeSymptom somemessages are lostReason Racecondition betweentwo componentstrying to sharenetwork stack (whichis split-phase) Solution Use aqueue to storepending messages

command result_t Foobar(uint8_t data) FooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)Component

Component 2 command result_t Goobar(uint8_t data) GooData goo = (GooData)msgdatagoodata = datacall SendMsgsend(0x02 sizeof(GooData)ampmsg)

THANK YOU

Page 17: TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

Data Memory Model

STATIC memory allocation No heap (malloc) No function pointers

Global variables Available on a per-frame basis

Local variables Saved on the stack Declared within a method

Application

Is the OS with some specific functionality Application is interrupt driven List of interrupts handled depend on list of hardware

components included in the application (eg clock and receiver)

Waits for interrupts On occurrence of interrupt calls interrupt handler

HardwareInterrupts

ISRInterruptHandler

invokes Calls

A Complete Application

Example Inter-Node Communication Sender

Receiver

Message Buffer Ownership

bullTransmission AM gains ownership of the buffer until sendDone(hellip) is signaledbull Reception Applicationrsquos event handler gains ownershipof the buffer but it must return a free buffer for the nextmessage

Potentially Nasty Bug 1

Whatrsquos wrong with the codeSymptom data saved in globalData is lost Reason Racecondition betweentwo tasksSolution Use aqueue or never relyon inter-taskcommunication

uint8_t globalDatatask void processData() call SendDatasend(globalData)command result_t Foobar(uint8_t data) globalData = datapost processData()

Potentially Nasty Bug 2

Whatrsquos wrong with the code

Symptom messageis corruptReason TOS_Msgis allocated in thestack lost whenfunction returns Solution DeclareTOS_Msg msg incomponentrsquos frame

command result_t Foobar(uint8_t data) TOS_Msg msgFooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)

Potentially Nasty Bug 3

Whatrsquos wrong withthe codeSymptom somemessages are lostReason Racecondition betweentwo componentstrying to sharenetwork stack (whichis split-phase) Solution Use aqueue to storepending messages

command result_t Foobar(uint8_t data) FooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)Component

Component 2 command result_t Goobar(uint8_t data) GooData goo = (GooData)msgdatagoodata = datacall SendMsgsend(0x02 sizeof(GooData)ampmsg)

THANK YOU

Page 18: TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

Application

Is the OS with some specific functionality Application is interrupt driven List of interrupts handled depend on list of hardware

components included in the application (eg clock and receiver)

Waits for interrupts On occurrence of interrupt calls interrupt handler

HardwareInterrupts

ISRInterruptHandler

invokes Calls

A Complete Application

Example Inter-Node Communication Sender

Receiver

Message Buffer Ownership

bullTransmission AM gains ownership of the buffer until sendDone(hellip) is signaledbull Reception Applicationrsquos event handler gains ownershipof the buffer but it must return a free buffer for the nextmessage

Potentially Nasty Bug 1

Whatrsquos wrong with the codeSymptom data saved in globalData is lost Reason Racecondition betweentwo tasksSolution Use aqueue or never relyon inter-taskcommunication

uint8_t globalDatatask void processData() call SendDatasend(globalData)command result_t Foobar(uint8_t data) globalData = datapost processData()

Potentially Nasty Bug 2

Whatrsquos wrong with the code

Symptom messageis corruptReason TOS_Msgis allocated in thestack lost whenfunction returns Solution DeclareTOS_Msg msg incomponentrsquos frame

command result_t Foobar(uint8_t data) TOS_Msg msgFooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)

Potentially Nasty Bug 3

Whatrsquos wrong withthe codeSymptom somemessages are lostReason Racecondition betweentwo componentstrying to sharenetwork stack (whichis split-phase) Solution Use aqueue to storepending messages

command result_t Foobar(uint8_t data) FooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)Component

Component 2 command result_t Goobar(uint8_t data) GooData goo = (GooData)msgdatagoodata = datacall SendMsgsend(0x02 sizeof(GooData)ampmsg)

THANK YOU

Page 19: TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

A Complete Application

Example Inter-Node Communication Sender

Receiver

Message Buffer Ownership

bullTransmission AM gains ownership of the buffer until sendDone(hellip) is signaledbull Reception Applicationrsquos event handler gains ownershipof the buffer but it must return a free buffer for the nextmessage

Potentially Nasty Bug 1

Whatrsquos wrong with the codeSymptom data saved in globalData is lost Reason Racecondition betweentwo tasksSolution Use aqueue or never relyon inter-taskcommunication

uint8_t globalDatatask void processData() call SendDatasend(globalData)command result_t Foobar(uint8_t data) globalData = datapost processData()

Potentially Nasty Bug 2

Whatrsquos wrong with the code

Symptom messageis corruptReason TOS_Msgis allocated in thestack lost whenfunction returns Solution DeclareTOS_Msg msg incomponentrsquos frame

command result_t Foobar(uint8_t data) TOS_Msg msgFooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)

Potentially Nasty Bug 3

Whatrsquos wrong withthe codeSymptom somemessages are lostReason Racecondition betweentwo componentstrying to sharenetwork stack (whichis split-phase) Solution Use aqueue to storepending messages

command result_t Foobar(uint8_t data) FooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)Component

Component 2 command result_t Goobar(uint8_t data) GooData goo = (GooData)msgdatagoodata = datacall SendMsgsend(0x02 sizeof(GooData)ampmsg)

THANK YOU

Page 20: TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

Example Inter-Node Communication Sender

Receiver

Message Buffer Ownership

bullTransmission AM gains ownership of the buffer until sendDone(hellip) is signaledbull Reception Applicationrsquos event handler gains ownershipof the buffer but it must return a free buffer for the nextmessage

Potentially Nasty Bug 1

Whatrsquos wrong with the codeSymptom data saved in globalData is lost Reason Racecondition betweentwo tasksSolution Use aqueue or never relyon inter-taskcommunication

uint8_t globalDatatask void processData() call SendDatasend(globalData)command result_t Foobar(uint8_t data) globalData = datapost processData()

Potentially Nasty Bug 2

Whatrsquos wrong with the code

Symptom messageis corruptReason TOS_Msgis allocated in thestack lost whenfunction returns Solution DeclareTOS_Msg msg incomponentrsquos frame

command result_t Foobar(uint8_t data) TOS_Msg msgFooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)

Potentially Nasty Bug 3

Whatrsquos wrong withthe codeSymptom somemessages are lostReason Racecondition betweentwo componentstrying to sharenetwork stack (whichis split-phase) Solution Use aqueue to storepending messages

command result_t Foobar(uint8_t data) FooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)Component

Component 2 command result_t Goobar(uint8_t data) GooData goo = (GooData)msgdatagoodata = datacall SendMsgsend(0x02 sizeof(GooData)ampmsg)

THANK YOU

Page 21: TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

Message Buffer Ownership

bullTransmission AM gains ownership of the buffer until sendDone(hellip) is signaledbull Reception Applicationrsquos event handler gains ownershipof the buffer but it must return a free buffer for the nextmessage

Potentially Nasty Bug 1

Whatrsquos wrong with the codeSymptom data saved in globalData is lost Reason Racecondition betweentwo tasksSolution Use aqueue or never relyon inter-taskcommunication

uint8_t globalDatatask void processData() call SendDatasend(globalData)command result_t Foobar(uint8_t data) globalData = datapost processData()

Potentially Nasty Bug 2

Whatrsquos wrong with the code

Symptom messageis corruptReason TOS_Msgis allocated in thestack lost whenfunction returns Solution DeclareTOS_Msg msg incomponentrsquos frame

command result_t Foobar(uint8_t data) TOS_Msg msgFooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)

Potentially Nasty Bug 3

Whatrsquos wrong withthe codeSymptom somemessages are lostReason Racecondition betweentwo componentstrying to sharenetwork stack (whichis split-phase) Solution Use aqueue to storepending messages

command result_t Foobar(uint8_t data) FooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)Component

Component 2 command result_t Goobar(uint8_t data) GooData goo = (GooData)msgdatagoodata = datacall SendMsgsend(0x02 sizeof(GooData)ampmsg)

THANK YOU

Page 22: TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

Potentially Nasty Bug 1

Whatrsquos wrong with the codeSymptom data saved in globalData is lost Reason Racecondition betweentwo tasksSolution Use aqueue or never relyon inter-taskcommunication

uint8_t globalDatatask void processData() call SendDatasend(globalData)command result_t Foobar(uint8_t data) globalData = datapost processData()

Potentially Nasty Bug 2

Whatrsquos wrong with the code

Symptom messageis corruptReason TOS_Msgis allocated in thestack lost whenfunction returns Solution DeclareTOS_Msg msg incomponentrsquos frame

command result_t Foobar(uint8_t data) TOS_Msg msgFooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)

Potentially Nasty Bug 3

Whatrsquos wrong withthe codeSymptom somemessages are lostReason Racecondition betweentwo componentstrying to sharenetwork stack (whichis split-phase) Solution Use aqueue to storepending messages

command result_t Foobar(uint8_t data) FooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)Component

Component 2 command result_t Goobar(uint8_t data) GooData goo = (GooData)msgdatagoodata = datacall SendMsgsend(0x02 sizeof(GooData)ampmsg)

THANK YOU

Page 23: TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

Potentially Nasty Bug 2

Whatrsquos wrong with the code

Symptom messageis corruptReason TOS_Msgis allocated in thestack lost whenfunction returns Solution DeclareTOS_Msg msg incomponentrsquos frame

command result_t Foobar(uint8_t data) TOS_Msg msgFooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)

Potentially Nasty Bug 3

Whatrsquos wrong withthe codeSymptom somemessages are lostReason Racecondition betweentwo componentstrying to sharenetwork stack (whichis split-phase) Solution Use aqueue to storepending messages

command result_t Foobar(uint8_t data) FooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)Component

Component 2 command result_t Goobar(uint8_t data) GooData goo = (GooData)msgdatagoodata = datacall SendMsgsend(0x02 sizeof(GooData)ampmsg)

THANK YOU

Page 24: TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

Potentially Nasty Bug 3

Whatrsquos wrong withthe codeSymptom somemessages are lostReason Racecondition betweentwo componentstrying to sharenetwork stack (whichis split-phase) Solution Use aqueue to storepending messages

command result_t Foobar(uint8_t data) FooData foo = (FooData)msgdatafoodata = datacall SendMsgsend(0x01 sizeof(FooData)ampmsg)Component

Component 2 command result_t Goobar(uint8_t data) GooData goo = (GooData)msgdatagoodata = datacall SendMsgsend(0x02 sizeof(GooData)ampmsg)

THANK YOU

Page 25: TinyOS Dhanshree Nimje Smita Khartad. TinyOS - Design Design.

THANK YOU