SlideShare a Scribd company logo
1 of 24
TinyOS Programming
By: R Jayampathi Sampath
nesC (network embedded system C)
• necC is a component-based C dialect.
• nesC application consists of one or more
components wired.
• Use a purely local namespace.
• There are two types of components:
– modules
• provide the implementation of one or more
interfaces.
– configurations
• used to wire other components together.
Contd.
• Components define two scopes.
– Specification (signature)
• names of interfaces it provides (implements) and names of
interfaces it uses (calls).
– Implementation
• implementation of commands and events.
module configuration
module
{
…..//provide and uses
interfaces
…
}
implementation{
…..//executable code
…
}
configuration
{
…..//provide and uses
interfaces
…
}
implementation{
…..//wire components
…
}
Modules and State
• Modules:
– are executable codes.
– must implement every command of interfaces it provides and
every event of interfaces it uses.
– can declare state variables. Any state of a components is
private.
– Ex: uint8_t counter = 0;
8 bits 16 bits 32 bits 64 bits
signed int8_t int16_t int32_t int64_t
unsigned uint8_t uint16_t uint32_t uint64_t
BilinkC.nc
module BilnkC
{
uses interface Timer<TMilli> as Timer0;
uses interface Timer<TMilli> as Timer1;
uses interface Timer<TMilli> as Timer2;
uses interface Leds;
uses interface Boot;
}
Implementation
{
event void Boot.booted()
{
call Timer0.startPeriodic(250);
call Timer1.startPeriodic(500);
call Timer1.startPeriodic(1000);
}
event void Timer0.fired(){
call Leds.led0Toggle();
}
event void Timer1.fired(){
call Leds.led1Toggle();
}
event void Timer2.fired()
{
call Leds.led2Toggle();
}
}
BlinkAppC.nc
configuration BlinkC
{
}
Implementation
{
components MainC, BlinkC, LedsC;
components new TimerMillic() as Timer0;
components new TimerMillic() as Timer0;
components new TimerMillic() as Timer0;
BlinkC ->MainC.Boot;
BlinkC.Timer0 -> Timer0;
BlinkC.Timer1 -> Timer1;
BlinkC.Timer2 -> Timer2;
BlinkC.Leds -> LedsC;
}
nesC uses arrows to bind interfaces to one another.
The right arrow (A->B) as "A wires to B"
Interfaces, Commands and Events
• if a component uses an interface, it can call the interface's
commands and must implement handlers for its events.
• Invoking an interface command requires the call keyword, and
invoking an interface event requires the signal keyword.
• Ex
Timer.nc:
interface Timer
{
// basic interface
command void startPeriodic( uint32_t dt );
command void startOneShot( uint32_t dt );
command void stop();
event void fired();
// extended interface omitted (all commands)
}
Internal
Functions
• Component's private
function for its own
internal use.
• Similar to C function.
• Can’t invoke directly.
• Can freely call
commands or signal
events.
module BlinkC {
uses interface Timer<TMilli> as Timer0;
uses interface Timer<TMilli> as Timer1;
uses interface Timer<TMilli> as Timer2;
uses interface Leds;
uses interface Boot;
}
implementation {
void startTimers() {
call Timer0.startPeriodic( 250 );
call Timer1.startPeriodic( 500 );
call Timer2.startPeriodic( 1000 );
}
event void Boot.booted() {
startTimers();
}
.
.
.
}
•Ex:
Split-Phase Operations
• Hardware is almost always split-phase (non blocking/asynchronous).
• In split-phase completion of a request is a callback.
– ADC
• synchronous operation:
– Magnetometer.
– samples periodically.
– when queried gives a cached value. (it can return the result immediately)
• make everything synchronous through threads is not possible.
• Solution :
– Operations that are split-phase in hardware are split-phase in software.
– Introduce interfaces that are bidirectional
ADC
S/W
Start Sample
Interrupts
when
complete
Read the
value
Split-Phase Operations
(Contd.)
ADC
Down call
Start the operation
Up call
signals the operation is complete
• Down call - command
• Up call - event
Split-Phase Operations
(Contd.)
• Split-phase interfaces enable a TinyOS component to easily start several
operations at once and have them execute in parallel.
• split-phase operations can save memory.
• Ex: The command Timer.startOneShot is an example of a split-phase call.
The user of the Timer inteface calls the command, which returns
immediately. Some time later (specified by the argument), the component
providing Timer signals Timer.fired. In a system with blocking calls, a
program might use sleep():
Interfaces with Arguments
• Interfaces can take types as arguments.
• wiring providers and users of interfaces that have type
arguments, they types must match.
• used to enforce type checking.
Module Implementation
Tasks
• Consider magnetometer/ADC example:
– depending on split-phase operations means that the
magnetometer driver has to issue a callback.
– it could just signal the event from within the call.
– signaling an event from within a command is
generally a bad idea.
• might cause a very long call loop.
• corrupt memory and crash the program.
– needs a way to schedule a function to be called later
(like an interrupt).
– can do this is with a task.
Tasks (Contd.)
• Task
– A module can post a task to the TinyOS scheduler.
– doesn’t take any parameters.
– A component posts a task to the TinyOS scheduler with the
post keyword: post
– only one task runs at any time. and TinyOS doesn’t interrupt
one task to run another.
– Implies that tasks should usually be reasonably short.
Tasks (Contd.)
• Ex:
event void Timer.fired() {
call Read.read();
}
event void RawRead.readDone(error_t err, uint16_t val) {
if (err == SUCCESS) {
lastVal = val;
filterVal *= 9;
filterVal /= 10;
filterVal += lastVal / 10;
}
}
command error_t Read.read() {
post readDoneTask();
return SUCCESS;
}
task void readDoneTask() {
signal Read.readDone(SUCCESS, filterVal);
}
• When Read.read is called, posts readDoneTask and returns immediately.
At some point later, TinyOS runs the task, which signals Read.readDone.
Tasks (Contd.)
• Why?
– Synchronous code runs in a single execution context
and does not have any kind of pre-emption.
– sync code runs for a long time.
– A component needs to be able to split a large
computation into smaller parts, which can be
executed one at a time.
• Task
– A task is function which a component tells TinyOS to
run later, rather than now.
Concurrency
• Tasks allow software components to emulate the split-
phase behavior of hardware.
• They also provide a mechanism to manage pre-emption
in the system.
• In nesC and TinyOS, functions that can run
preemptively labeled with the async keyword.
• async function can’t call a command or event that isn’t
async.
• By default, commands and events are sync.
• A task post is an async operation, while a task running
is sync.
Concurrency (Contd.)
• Can’t make everything
async because of race
condition.
• Ex: consider the
command, toggle, which
flips the state bit and
returns the new one:
• Solutions:
– Keep code synchronous
when you can.
– functionality through
atomic statements.
Concurrency (Contd.)
• The atomic block
promises that these
variables can be read
and written atomically
• this does not promise
that the atomic block
won’t be preempted
– with atomic blocks, two
code segments that do not
share any of the same
variables can preempt one
another
Concurrency (Contd.)
• An atomic block involves some kind of
execution (e.g.. disabling an interrupt), so
unnecessary atomics are a waste of CPU
cycles.
• an atomic block does have a CPU cost,
so you want to minimize how many you
have.
• shorter atomic blocks delay interrupts less
and so improve system concurrency.
Allocation
• the only way that components can share state is
through function calls.
• two basic ways that components can pass
parameters: by value and by reference (pointer).
• every pointer should have a clear owner, and
only the owner can modify the corresponding
memory.
• abstract data types (ADTs) in TinyOS are
usually represented one of two ways:
– Generic modules
– Through an interface with by-reference commands.
Allocation (An Example)
• Generic module, Ex
– many TinyOS components needs to maintain bit vectors, and so in tos/system there’s a
generic module BitVectorC that takes the number of bits as a parameter:
– This component allocates the bit vector internally and provides the BitVector
interface to access it:
Allocation (Contd.)
– in BitVector, it’s possible that, after a bit has been
fetched for get() but before it returns, an interrupt
fires whose handler calls set() on that same bit.
– you should call get() from within an atomic section.
• passing a parameter by reference,
– this is easy, as all of its commands are synchronous:
no code that can preempt the call (async).
References
• TinyOS Documentation Wiki (URL:
http://docs.tinyos.net/index.php/Main_
).
• TinyOS Programing (URL:
http://www.tinyos.net/tinyos
2.x/doc/pdf/tinyos
programming.pdf)

More Related Content

What's hot

Real-Time Scheduling Algorithms
Real-Time Scheduling AlgorithmsReal-Time Scheduling Algorithms
Real-Time Scheduling AlgorithmsAJAL A J
 
Java Concurrency in Practice
Java Concurrency in PracticeJava Concurrency in Practice
Java Concurrency in PracticeAlina Dolgikh
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with javaHoang Nguyen
 
Concurrency bug identification through kernel panic log (english)
Concurrency bug identification through kernel panic log (english)Concurrency bug identification through kernel panic log (english)
Concurrency bug identification through kernel panic log (english)Sneeker Yeh
 
Java Multithreading Using Executors Framework
Java Multithreading Using Executors FrameworkJava Multithreading Using Executors Framework
Java Multithreading Using Executors FrameworkArun Mehra
 
Linux Preempt-RT Internals
Linux Preempt-RT InternalsLinux Preempt-RT Internals
Linux Preempt-RT Internals哲豪 康哲豪
 
Advanced debugging on ARM Cortex devices such as STM32, Kinetis, LPC, etc.
Advanced debugging on ARM Cortex devices such as STM32, Kinetis, LPC, etc.Advanced debugging on ARM Cortex devices such as STM32, Kinetis, LPC, etc.
Advanced debugging on ARM Cortex devices such as STM32, Kinetis, LPC, etc.Atollic
 
OS Process and Thread Concepts
OS Process and Thread ConceptsOS Process and Thread Concepts
OS Process and Thread Conceptssgpraju
 
Intel processor trace - What are Recorded?
Intel processor trace - What are Recorded?Intel processor trace - What are Recorded?
Intel processor trace - What are Recorded?Pipat Methavanitpong
 

What's hot (14)

Real time-embedded-system-lec-02
Real time-embedded-system-lec-02Real time-embedded-system-lec-02
Real time-embedded-system-lec-02
 
Real-Time Scheduling Algorithms
Real-Time Scheduling AlgorithmsReal-Time Scheduling Algorithms
Real-Time Scheduling Algorithms
 
Java Concurrency in Practice
Java Concurrency in PracticeJava Concurrency in Practice
Java Concurrency in Practice
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with java
 
Concurrency bug identification through kernel panic log (english)
Concurrency bug identification through kernel panic log (english)Concurrency bug identification through kernel panic log (english)
Concurrency bug identification through kernel panic log (english)
 
Breakpoints
BreakpointsBreakpoints
Breakpoints
 
Java Multithreading Using Executors Framework
Java Multithreading Using Executors FrameworkJava Multithreading Using Executors Framework
Java Multithreading Using Executors Framework
 
Esl basics
Esl basicsEsl basics
Esl basics
 
Linux Preempt-RT Internals
Linux Preempt-RT InternalsLinux Preempt-RT Internals
Linux Preempt-RT Internals
 
Advanced debugging on ARM Cortex devices such as STM32, Kinetis, LPC, etc.
Advanced debugging on ARM Cortex devices such as STM32, Kinetis, LPC, etc.Advanced debugging on ARM Cortex devices such as STM32, Kinetis, LPC, etc.
Advanced debugging on ARM Cortex devices such as STM32, Kinetis, LPC, etc.
 
OS Process and Thread Concepts
OS Process and Thread ConceptsOS Process and Thread Concepts
OS Process and Thread Concepts
 
Multi-Threading
Multi-ThreadingMulti-Threading
Multi-Threading
 
Intel processor trace - What are Recorded?
Intel processor trace - What are Recorded?Intel processor trace - What are Recorded?
Intel processor trace - What are Recorded?
 
Preempt_rt realtime patch
Preempt_rt realtime patchPreempt_rt realtime patch
Preempt_rt realtime patch
 

Viewers also liked

TinyOS 2.1 tutorial at IPSN 2009
TinyOS 2.1 tutorial at IPSN 2009TinyOS 2.1 tutorial at IPSN 2009
TinyOS 2.1 tutorial at IPSN 2009gnawali
 
Tiny os
Tiny osTiny os
Tiny osAcad
 
Intoduction to TinyOS, nesC and TOSSIM
Intoduction to TinyOS, nesC and TOSSIMIntoduction to TinyOS, nesC and TOSSIM
Intoduction to TinyOS, nesC and TOSSIMPrakhar Bansal
 
Free Download Powerpoint Slides
Free Download Powerpoint SlidesFree Download Powerpoint Slides
Free Download Powerpoint SlidesGeorge
 
Slideshare Powerpoint presentation
Slideshare Powerpoint presentationSlideshare Powerpoint presentation
Slideshare Powerpoint presentationelliehood
 

Viewers also liked (8)

TinyOS 2.1 tutorial at IPSN 2009
TinyOS 2.1 tutorial at IPSN 2009TinyOS 2.1 tutorial at IPSN 2009
TinyOS 2.1 tutorial at IPSN 2009
 
Tiny os
Tiny osTiny os
Tiny os
 
TinyOS Course 03: Radio Communication
TinyOS Course 03: Radio CommunicationTinyOS Course 03: Radio Communication
TinyOS Course 03: Radio Communication
 
Intoduction to TinyOS, nesC and TOSSIM
Intoduction to TinyOS, nesC and TOSSIMIntoduction to TinyOS, nesC and TOSSIM
Intoduction to TinyOS, nesC and TOSSIM
 
TinyOS
TinyOSTinyOS
TinyOS
 
Free Download Powerpoint Slides
Free Download Powerpoint SlidesFree Download Powerpoint Slides
Free Download Powerpoint Slides
 
Slideshare Powerpoint presentation
Slideshare Powerpoint presentationSlideshare Powerpoint presentation
Slideshare Powerpoint presentation
 
Slideshare ppt
Slideshare pptSlideshare ppt
Slideshare ppt
 

Similar to 0903 1

Building the Internet of Things with Thingsquare and Contiki - day 2 part 1
Building the Internet of Things with Thingsquare and Contiki - day 2 part 1Building the Internet of Things with Thingsquare and Contiki - day 2 part 1
Building the Internet of Things with Thingsquare and Contiki - day 2 part 1Adam Dunkels
 
Control unit design
Control unit designControl unit design
Control unit designDhaval Bagal
 
Azure Function Workflow
Azure Function WorkflowAzure Function Workflow
Azure Function WorkflowAndrea Tosato
 
RTOS implementation
RTOS implementationRTOS implementation
RTOS implementationRajan Kumar
 
MULTI-THREADING in python appalication.pptx
MULTI-THREADING in python appalication.pptxMULTI-THREADING in python appalication.pptx
MULTI-THREADING in python appalication.pptxSaiDhanushM
 
Ekon25 mORMot 2 Server-Side Notifications
Ekon25 mORMot 2 Server-Side NotificationsEkon25 mORMot 2 Server-Side Notifications
Ekon25 mORMot 2 Server-Side NotificationsArnaud Bouchez
 
Introduction to embedded system
Introduction to embedded systemIntroduction to embedded system
Introduction to embedded systemajitsaraf123
 
[2017/2018] AADL - Architecture Analysis and Design Language
[2017/2018] AADL - Architecture Analysis and Design Language[2017/2018] AADL - Architecture Analysis and Design Language
[2017/2018] AADL - Architecture Analysis and Design LanguageIvano Malavolta
 
introduction to embedded system presentation
introduction to embedded system presentationintroduction to embedded system presentation
introduction to embedded system presentationAmr Rashed
 
Implementation of a Deadline Monotonic algorithm for aperiodic traffic schedu...
Implementation of a Deadline Monotonic algorithm for aperiodic traffic schedu...Implementation of a Deadline Monotonic algorithm for aperiodic traffic schedu...
Implementation of a Deadline Monotonic algorithm for aperiodic traffic schedu...Andrea Tino
 

Similar to 0903 1 (20)

Nesc tutorial
Nesc tutorialNesc tutorial
Nesc tutorial
 
Tos tutorial
Tos tutorialTos tutorial
Tos tutorial
 
6. TinyOS_2.pdf
6. TinyOS_2.pdf6. TinyOS_2.pdf
6. TinyOS_2.pdf
 
Building the Internet of Things with Thingsquare and Contiki - day 2 part 1
Building the Internet of Things with Thingsquare and Contiki - day 2 part 1Building the Internet of Things with Thingsquare and Contiki - day 2 part 1
Building the Internet of Things with Thingsquare and Contiki - day 2 part 1
 
Control unit design
Control unit designControl unit design
Control unit design
 
Scheduling Thread
Scheduling  ThreadScheduling  Thread
Scheduling Thread
 
Azure Function Workflow
Azure Function WorkflowAzure Function Workflow
Azure Function Workflow
 
RTOS implementation
RTOS implementationRTOS implementation
RTOS implementation
 
MULTI-THREADING in python appalication.pptx
MULTI-THREADING in python appalication.pptxMULTI-THREADING in python appalication.pptx
MULTI-THREADING in python appalication.pptx
 
Operating System lab
Operating System labOperating System lab
Operating System lab
 
Autosar Basics hand book_v1
Autosar Basics  hand book_v1Autosar Basics  hand book_v1
Autosar Basics hand book_v1
 
Ekon25 mORMot 2 Server-Side Notifications
Ekon25 mORMot 2 Server-Side NotificationsEkon25 mORMot 2 Server-Side Notifications
Ekon25 mORMot 2 Server-Side Notifications
 
RTOS - Real Time Operating Systems
RTOS - Real Time Operating SystemsRTOS - Real Time Operating Systems
RTOS - Real Time Operating Systems
 
Introduction to embedded system
Introduction to embedded systemIntroduction to embedded system
Introduction to embedded system
 
embedded C.pptx
embedded C.pptxembedded C.pptx
embedded C.pptx
 
Cc module 3.pptx
Cc module 3.pptxCc module 3.pptx
Cc module 3.pptx
 
PILOT Session for Embedded Systems
PILOT Session for Embedded Systems PILOT Session for Embedded Systems
PILOT Session for Embedded Systems
 
[2017/2018] AADL - Architecture Analysis and Design Language
[2017/2018] AADL - Architecture Analysis and Design Language[2017/2018] AADL - Architecture Analysis and Design Language
[2017/2018] AADL - Architecture Analysis and Design Language
 
introduction to embedded system presentation
introduction to embedded system presentationintroduction to embedded system presentation
introduction to embedded system presentation
 
Implementation of a Deadline Monotonic algorithm for aperiodic traffic schedu...
Implementation of a Deadline Monotonic algorithm for aperiodic traffic schedu...Implementation of a Deadline Monotonic algorithm for aperiodic traffic schedu...
Implementation of a Deadline Monotonic algorithm for aperiodic traffic schedu...
 

Recently uploaded

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

0903 1

  • 1. TinyOS Programming By: R Jayampathi Sampath
  • 2. nesC (network embedded system C) • necC is a component-based C dialect. • nesC application consists of one or more components wired. • Use a purely local namespace. • There are two types of components: – modules • provide the implementation of one or more interfaces. – configurations • used to wire other components together.
  • 3. Contd. • Components define two scopes. – Specification (signature) • names of interfaces it provides (implements) and names of interfaces it uses (calls). – Implementation • implementation of commands and events. module configuration module { …..//provide and uses interfaces … } implementation{ …..//executable code … } configuration { …..//provide and uses interfaces … } implementation{ …..//wire components … }
  • 4. Modules and State • Modules: – are executable codes. – must implement every command of interfaces it provides and every event of interfaces it uses. – can declare state variables. Any state of a components is private. – Ex: uint8_t counter = 0; 8 bits 16 bits 32 bits 64 bits signed int8_t int16_t int32_t int64_t unsigned uint8_t uint16_t uint32_t uint64_t
  • 5. BilinkC.nc module BilnkC { uses interface Timer<TMilli> as Timer0; uses interface Timer<TMilli> as Timer1; uses interface Timer<TMilli> as Timer2; uses interface Leds; uses interface Boot; } Implementation { event void Boot.booted() { call Timer0.startPeriodic(250); call Timer1.startPeriodic(500); call Timer1.startPeriodic(1000); } event void Timer0.fired(){ call Leds.led0Toggle(); } event void Timer1.fired(){ call Leds.led1Toggle(); } event void Timer2.fired() { call Leds.led2Toggle(); } } BlinkAppC.nc configuration BlinkC { } Implementation { components MainC, BlinkC, LedsC; components new TimerMillic() as Timer0; components new TimerMillic() as Timer0; components new TimerMillic() as Timer0; BlinkC ->MainC.Boot; BlinkC.Timer0 -> Timer0; BlinkC.Timer1 -> Timer1; BlinkC.Timer2 -> Timer2; BlinkC.Leds -> LedsC; } nesC uses arrows to bind interfaces to one another. The right arrow (A->B) as "A wires to B"
  • 6. Interfaces, Commands and Events • if a component uses an interface, it can call the interface's commands and must implement handlers for its events. • Invoking an interface command requires the call keyword, and invoking an interface event requires the signal keyword. • Ex Timer.nc: interface Timer { // basic interface command void startPeriodic( uint32_t dt ); command void startOneShot( uint32_t dt ); command void stop(); event void fired(); // extended interface omitted (all commands) }
  • 7. Internal Functions • Component's private function for its own internal use. • Similar to C function. • Can’t invoke directly. • Can freely call commands or signal events. module BlinkC { uses interface Timer<TMilli> as Timer0; uses interface Timer<TMilli> as Timer1; uses interface Timer<TMilli> as Timer2; uses interface Leds; uses interface Boot; } implementation { void startTimers() { call Timer0.startPeriodic( 250 ); call Timer1.startPeriodic( 500 ); call Timer2.startPeriodic( 1000 ); } event void Boot.booted() { startTimers(); } . . . } •Ex:
  • 8. Split-Phase Operations • Hardware is almost always split-phase (non blocking/asynchronous). • In split-phase completion of a request is a callback. – ADC • synchronous operation: – Magnetometer. – samples periodically. – when queried gives a cached value. (it can return the result immediately) • make everything synchronous through threads is not possible. • Solution : – Operations that are split-phase in hardware are split-phase in software. – Introduce interfaces that are bidirectional ADC S/W Start Sample Interrupts when complete Read the value
  • 9. Split-Phase Operations (Contd.) ADC Down call Start the operation Up call signals the operation is complete • Down call - command • Up call - event
  • 10. Split-Phase Operations (Contd.) • Split-phase interfaces enable a TinyOS component to easily start several operations at once and have them execute in parallel. • split-phase operations can save memory. • Ex: The command Timer.startOneShot is an example of a split-phase call. The user of the Timer inteface calls the command, which returns immediately. Some time later (specified by the argument), the component providing Timer signals Timer.fired. In a system with blocking calls, a program might use sleep():
  • 11. Interfaces with Arguments • Interfaces can take types as arguments. • wiring providers and users of interfaces that have type arguments, they types must match. • used to enforce type checking.
  • 13. Tasks • Consider magnetometer/ADC example: – depending on split-phase operations means that the magnetometer driver has to issue a callback. – it could just signal the event from within the call. – signaling an event from within a command is generally a bad idea. • might cause a very long call loop. • corrupt memory and crash the program. – needs a way to schedule a function to be called later (like an interrupt). – can do this is with a task.
  • 14. Tasks (Contd.) • Task – A module can post a task to the TinyOS scheduler. – doesn’t take any parameters. – A component posts a task to the TinyOS scheduler with the post keyword: post – only one task runs at any time. and TinyOS doesn’t interrupt one task to run another. – Implies that tasks should usually be reasonably short.
  • 15. Tasks (Contd.) • Ex: event void Timer.fired() { call Read.read(); } event void RawRead.readDone(error_t err, uint16_t val) { if (err == SUCCESS) { lastVal = val; filterVal *= 9; filterVal /= 10; filterVal += lastVal / 10; } } command error_t Read.read() { post readDoneTask(); return SUCCESS; } task void readDoneTask() { signal Read.readDone(SUCCESS, filterVal); } • When Read.read is called, posts readDoneTask and returns immediately. At some point later, TinyOS runs the task, which signals Read.readDone.
  • 16. Tasks (Contd.) • Why? – Synchronous code runs in a single execution context and does not have any kind of pre-emption. – sync code runs for a long time. – A component needs to be able to split a large computation into smaller parts, which can be executed one at a time. • Task – A task is function which a component tells TinyOS to run later, rather than now.
  • 17. Concurrency • Tasks allow software components to emulate the split- phase behavior of hardware. • They also provide a mechanism to manage pre-emption in the system. • In nesC and TinyOS, functions that can run preemptively labeled with the async keyword. • async function can’t call a command or event that isn’t async. • By default, commands and events are sync. • A task post is an async operation, while a task running is sync.
  • 18. Concurrency (Contd.) • Can’t make everything async because of race condition. • Ex: consider the command, toggle, which flips the state bit and returns the new one: • Solutions: – Keep code synchronous when you can. – functionality through atomic statements.
  • 19. Concurrency (Contd.) • The atomic block promises that these variables can be read and written atomically • this does not promise that the atomic block won’t be preempted – with atomic blocks, two code segments that do not share any of the same variables can preempt one another
  • 20. Concurrency (Contd.) • An atomic block involves some kind of execution (e.g.. disabling an interrupt), so unnecessary atomics are a waste of CPU cycles. • an atomic block does have a CPU cost, so you want to minimize how many you have. • shorter atomic blocks delay interrupts less and so improve system concurrency.
  • 21. Allocation • the only way that components can share state is through function calls. • two basic ways that components can pass parameters: by value and by reference (pointer). • every pointer should have a clear owner, and only the owner can modify the corresponding memory. • abstract data types (ADTs) in TinyOS are usually represented one of two ways: – Generic modules – Through an interface with by-reference commands.
  • 22. Allocation (An Example) • Generic module, Ex – many TinyOS components needs to maintain bit vectors, and so in tos/system there’s a generic module BitVectorC that takes the number of bits as a parameter: – This component allocates the bit vector internally and provides the BitVector interface to access it:
  • 23. Allocation (Contd.) – in BitVector, it’s possible that, after a bit has been fetched for get() but before it returns, an interrupt fires whose handler calls set() on that same bit. – you should call get() from within an atomic section. • passing a parameter by reference, – this is easy, as all of its commands are synchronous: no code that can preempt the call (async).
  • 24. References • TinyOS Documentation Wiki (URL: http://docs.tinyos.net/index.php/Main_ ). • TinyOS Programing (URL: http://www.tinyos.net/tinyos 2.x/doc/pdf/tinyos programming.pdf)