SlideShare ist ein Scribd-Unternehmen logo
1 von 70
Building Connected Devices
With Thingsquare and Contiki
Day 2
Yesterday
• Learned about how to prototype apps
• Learned about the high-level operation of
the protocols
• Got a bit of background
Today
• Deep-dive into the protocols
• More information about Contiki
Contiki
Contiki: an IoT OS
• Helps application programs
– Processes and concurrency
– Timers
– Memory management
– Networking
– Device drivers
Timers
Time in Contiki
• Two system clocks in Contiki
– Coarse-grained, most often 128 Hz
• CLOCK_SECOND

– Fine-grained, most often 32768 Hz
• RTIMER_SECOND

– Platform dependent
– Power of two for simple math
Timers
• struct timer – coarse
– Passive timer, only keeps track of its expiration
time

• struct etimer – coarse
– Active timer, sends an event when it expires

• struct ctimer – coarse
– Active timer, calls a function when it expires

• struct rtimer – fine
– Real-time timer, calls a function at an exact time
Etimer
• Periodically print the time
static struct etimer etim;
PROCESS_THREAD(my_process, ev, data) {
PROCESS_BEGIN();
while(1) {
printf(”Uptime (seconds): %lun", clock_seconds());
etimer_set(&etim, CLOCK_SECOND);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&etim));
}
PROCESS_END();
}
Ctimer
• Print ”Hello, callback” after 1/8 second.
static struct ctimer callback_timer;
static void
callback(void *data)
{
printf("%sn", (char *) data);
}
void
application(void)
{
ctimer_set(&callback_timer, CLOCK_SECOND / 8, callback,
"Hello, callback!");
return 0;
}
Rtimer
• Sets a hardware interrupt at set time
• Invokes a callback
static struct rtimer rt;
rtimer_set(&rt, /* pointer to rtimer struct */
RTIMER_NOW() + RTIMER_SECOND/100, /* 10ms */
1,
/* duration */
rt_callback, /* callback pointer */
NULL);
/* pointer to data */
Rtimer
• Rtimer callback
static void
rt_callback(struct rtimer *rt, void *data)
{
printf(”callback!n");
}
Hands-on: blink.c
• See the blink.c example on the
Thingsquare cloud
• Uses etimer to blink LEDs
• Note the use of etimer_reset() to provide a
stable timer
Processes and events
Programming concept:
Multithreading
• Threads are given a timeslot to execute
• Paused / continued later by OS scheduler
if not done
• Costly – stack space (RAM), CPU
Programming concept:
Event driven / state machine
• Reactive - events control program flow
– Timers, hardware interrupts, radio, etc

• More kind on resources
• However, callbacks and state variables
makes programming harder
Event driven / state machine
State
machine
• What state?
What event?
Conditions,
transitions,
headaches.
• Event driven is kinder on hw resources..
• Multithreaded is kinder on the programmer..
- can their strengths be combined?
Programming concept:
Protothreads
• Threading without the overhead
– RAM is limited, threads use too much RAM

• Protothreads are event-driven but with a
threaded programming style
• Cooperative scheduling
C-switch expansion
int a_protothread(struct pt *pt) {
PT_BEGIN(pt);

int a_protothread(struct pt *pt) {
switch(pt->lc) { case 0:

PT_WAIT_UNTIL(pt, condition1);

pt->lc = 5; case 5:
if(!condition1) return 0;

if(something) {

if(something) {

PT_WAIT_UNTIL(pt, condition2);

pt->lc = 10; case 10:
if(!condition2) return 0;

}
PT_END(pt);
}

}

Line numbers

}

} return 1;
Six-line implementation
• C compiler pre-processor replaces with switch-case
• very efficient
struct pt { unsigned short lc; };

#define PT_INIT(pt)

pt->lc = 0

#define PT_BEGIN(pt)

switch(pt->lc) { case 0:

#define PT_EXIT(pt)

pt->lc = 0; return 2

#define PT_WAIT_UNTIL(pt, c)

pt->lc = __LINE__; case __LINE__: 
if(!(c)) return 0

#define PT_END(pt)

} pt->lc = 0; return 1
Protothread limitations
• Automatic variables not stored across a
blocking wait
– Workaround: use static local variables instead

• Constraints on the use of switch()
constructs in programs
– Workaround: don’t use switches
Contiki processes
• Contiki processes are very lightweight
– Execution is event-driven
– Can receive events from other processes
– Must not block in busy-wait loop
• while(1) will crash the device

• Contiki processes are protothreads
Contiki processes
#include "contiki.h"
/*---------------------------------------------------*/
PROCESS(hello_world_process, "Hello world process");
AUTOSTART_PROCESSES(&hello_world_process);
/*---------------------------------------------------*/
PROCESS_THREAD(hello_world_process, ev, data)
{
PROCESS_BEGIN();
printf("Hello, worldn");
PROCESS_END();
}
Contiki events
• How to wait for an event
PROCESS_THREAD(first_process, ev, data)
.. ..
PROCESS_WAIT_EVENT_UNTIL(ev == servo_event);
if(data != NULL) {
handle_servo((struct servo_data *) data);
}

• ev contains the event number
• data is a void* to any data
– Can be NULL
Hands-on: blink.c
• See how PROCESS_BEGIN(),
PROCESS_END(),
PROCESS_WAIT_UNTIL() are used
Starvation in Contiki
• Thread scheduling is cooperative
– play nice

• The watchdog is on
– on some platforms unable to turn off

• Don’t hog the CPU
• Long-running, do
– watchdog_periodic();
– PROCESS_WAIT();
Memory management
Contiki memb
struct user_struct {
int a, b;
}
MEMB(block, 10, struct user_struct);
m = memb_alloc(&block);
memb_free(&block, m);
Lists
LIST(a_list);

list_add(a_list, an_element);
an_element = list_pop(a_list):
Networking
Contiki netstacks
• Three network stacks
– IPv6
– IPv4
– Rime
The Contiki netstack
• Four layers
– Network layer

Application
Transport

Network, routing
Adaptation

– MAC layer
– RDC layer
– Radio layer

MAC
Duty cycling
Radio
The Contiki IPv6 netstack
websocket.c, httpsocket.c, coap.c

Application

udp-socket.c, tcpsocket.c

Transport

uip6.c, rpl.c

Network, routing

sicslowpan.c

Adaptation

csma.c

MAC

nullrdc.c, contikimac.c

Duty cycling

cc2538-rf.c

Radio
New Contiki 3.x APIs
• UDP socket
– Send and receive data with UDP
– Callback-based

• TCP socket
– Listen for new connections (server)
– Set up new connections (client)
– Send and receive data
– Callback-based
UDP socket API
int udp_socket_register(struct udp_socket *c,
void *ptr,
udp_socket_input_callback_t receive_callback);
int udp_socket_bind(struct udp_socket *c,
uint16_t local_port);
int udp_socket_connect(struct udp_socket *c,
uip_ipaddr_t *remote_addr,
uint16_t remote_port);
int udp_socket_send(struct udp_socket *c,
const void *data, uint16_t datalen);
int udp_socket_sendto(struct udp_socket *c,
const void *data, uint16_t datalen,
const uip_ipaddr_t *addr, uint16_t port);
UDP socket API
• Connected sockets: only receive data from
the specified host/port
• Receiving data is simple
– Get a pointer along with the callback

• Sending data is simple
– For connected sockets: to the connected
host/port
– Send to any host/port
TCP socket API
• TCP significantly trickier than UDP
– Connections
– Retransmissions
– Buffers
TCP socket API
void tcp_socket_register(struct tcp_socket *s, void *ptr,
uint8_t *input_databuf, int input_databuf_len,
uint8_t *output_databuf, int output_databuf_len,
tcp_socket_input_callback_t input_callback,
tcp_socket_event_callback_t event_callback);
int tcp_socket_connect(struct tcp_socket *s,
uip_ipaddr_t *ipaddr,
uint16_t port);
int tcp_socket_listen(struct tcp_socket *s,
uint16_t port);
int tcp_socket_unlisten(struct tcp_socket *s);

int tcp_socket_send(struct tcp_socket *s,
const uint8_t *dataptr,
int datalen);
int tcp_socket_send_str(struct tcp_socket *s,
const char *strptr);
int tcp_socket_close(struct tcp_socket *s);
TCP socket API
• Caller must provide input and output
buffers
– The caller knows how much data it is going to
be sending and receiving

• Sending data is easy
– Just call the send function

• Receiving data is trickier
– Data may be retained in the buffer
Contiki directories and toolchains
The Contiki directory structure
•

apps/
– Contiki applications

•

core/
– Contiki core code

•

cpu/
– Contiki CPU-specific code

•

doc/
– Contiki documentation

•

examples/
– Contiki examples

•

platform/
– Contiki platform code

•

regression-tests/
– Contiki regression tests

•

tools/
– Contiki tools
Contiki 3.x directories
• dev/
– Device drivers

• More fine-grained control through modules
– New subdirectories under sys/net/
A project directory
• examples/hello-world
– Makefile
• Contains the top-level rules to build the project

– project-conf.h
• Project configuration
• Optional – must be explicitly enabled by Makefile

– hello-world.c
• Project source code file
Toolchain Installation
• Embedded compiler toolchains with built-in
IDE
– IAR

• Gcc
– Compiler
– Linker
– Use external editor (Eclipse, Emacs, vi, …)
Instant Contiki
• Full toolchain installation in a Linux VM
• Runs in VMware Player
• Compile in Instant Contiki, run on the
hardware
Building firmware images
• Use C compiler to compile the full Contiki
source code
• Compile in a project directory
• Need to change something? Re-compile
Contiki firmware images
• In a terminal, go to the project directory

make TARGET=platform file
• This will build the full source code tree for
your project. Eg,
make TARGET=cc2538dk hello-world
Configuration
• Two layers of configuration
– Platform level
• Buffer sizes, radio drivers, etc

– Project level
• RDC mechanisms

• Don’t touch the platform configuration
• Do touch the project configuration
Uploading the firmware
• Some platforms have a convenient way to
upload the firmware
make TARGET=sky hello-world.upload

• Some platforms are significantly trickier
Save target
• If you are using the same target a lot,
make TARGET=cc2538dk savetarget

• Then, simply
make blink.upload
Running as the native target
• Sometimes using the native target is
useful
make TARGET=native hello-world

• Run the program
./hello-world.native
Other commands
• Connect to serial port
make TARGET=exp5438 login
make TARGET=exp5438 COMPORT=COM12 login

• Clean out previous compilation
make TARGET=exp5438 clean

• List available commands
make TARGET=exp5438 help
Cooja
The Cooja Simulator
• Emulation mode
– Run exact same firmware images as run on
hardware
– Slower, more exact

• Native mode
– Run the Contiki code, compiled for the native
system
– Faster, can run (much) larger systems
Running Cooja
• Go to the Cooja directory
– cd tools/cooja
– ant run
The Contiki regression tests
• A great resource for seeing Cooja
simulation setups
• contiki/regression-tests/
More

http://thingsquare.com

Weitere ähnliche Inhalte

Was ist angesagt?

DPDK KNI interface
DPDK KNI interfaceDPDK KNI interface
DPDK KNI interfaceDenys Haryachyy
 
PGConf.ASIA 2019 Bali - Setup a High-Availability and Load Balancing PostgreS...
PGConf.ASIA 2019 Bali - Setup a High-Availability and Load Balancing PostgreS...PGConf.ASIA 2019 Bali - Setup a High-Availability and Load Balancing PostgreS...
PGConf.ASIA 2019 Bali - Setup a High-Availability and Load Balancing PostgreS...Equnix Business Solutions
 
Fight with Metaspace OOM
Fight with Metaspace OOMFight with Metaspace OOM
Fight with Metaspace OOMLeon Chen
 
Where is my bottleneck? Performance troubleshooting in Flink
Where is my bottleneck? Performance troubleshooting in FlinkWhere is my bottleneck? Performance troubleshooting in Flink
Where is my bottleneck? Performance troubleshooting in FlinkFlink Forward
 
NGINX Installation and Tuning
NGINX Installation and TuningNGINX Installation and Tuning
NGINX Installation and TuningNGINX, Inc.
 
Open vSwitch 패킷 처리 구조
Open vSwitch 패킷 처리 구조Open vSwitch 패킷 처리 구조
Open vSwitch 패킷 처리 구조Seung-Hoon Baek
 
Flink Forward Berlin 2018: Stefan Richter - "Tuning Flink for Robustness and ...
Flink Forward Berlin 2018: Stefan Richter - "Tuning Flink for Robustness and ...Flink Forward Berlin 2018: Stefan Richter - "Tuning Flink for Robustness and ...
Flink Forward Berlin 2018: Stefan Richter - "Tuning Flink for Robustness and ...Flink Forward
 
[오픈소스컨설팅]RHEL7/CentOS7 Pacemaker기반-HA시스템구성-v1.0
[오픈소스컨설팅]RHEL7/CentOS7 Pacemaker기반-HA시스템구성-v1.0[오픈소스컨설팅]RHEL7/CentOS7 Pacemaker기반-HA시스템구성-v1.0
[오픈소스컨설팅]RHEL7/CentOS7 Pacemaker기반-HA시스템구성-v1.0Ji-Woong Choi
 
Galera explained 3
Galera explained 3Galera explained 3
Galera explained 3Marco Tusa
 
Stephan Ewen - Scaling to large State
Stephan Ewen - Scaling to large StateStephan Ewen - Scaling to large State
Stephan Ewen - Scaling to large StateFlink Forward
 
Evening out the uneven: dealing with skew in Flink
Evening out the uneven: dealing with skew in FlinkEvening out the uneven: dealing with skew in Flink
Evening out the uneven: dealing with skew in FlinkFlink Forward
 
IBM Spectrum scale object deep dive training
IBM Spectrum scale object  deep dive trainingIBM Spectrum scale object  deep dive training
IBM Spectrum scale object deep dive trainingSmita Raut
 
Contemporary Linux Networking
Contemporary Linux NetworkingContemporary Linux Networking
Contemporary Linux NetworkingMaximilan Wilhelm
 
Concurrency vs parallelism
Concurrency vs parallelismConcurrency vs parallelism
Concurrency vs parallelismYiwei Gong
 
Ibm spectrum scale fundamentals workshop for americas part 5 ess gnr-usecases...
Ibm spectrum scale fundamentals workshop for americas part 5 ess gnr-usecases...Ibm spectrum scale fundamentals workshop for americas part 5 ess gnr-usecases...
Ibm spectrum scale fundamentals workshop for americas part 5 ess gnr-usecases...xKinAnx
 
Spectrum Scale Best Practices by Olaf Weiser
Spectrum Scale Best Practices by Olaf WeiserSpectrum Scale Best Practices by Olaf Weiser
Spectrum Scale Best Practices by Olaf WeiserSandeep Patil
 
gRPC and Microservices
gRPC and MicroservicesgRPC and Microservices
gRPC and MicroservicesJonathan Gomez
 

Was ist angesagt? (20)

DPDK KNI interface
DPDK KNI interfaceDPDK KNI interface
DPDK KNI interface
 
PGConf.ASIA 2019 Bali - Setup a High-Availability and Load Balancing PostgreS...
PGConf.ASIA 2019 Bali - Setup a High-Availability and Load Balancing PostgreS...PGConf.ASIA 2019 Bali - Setup a High-Availability and Load Balancing PostgreS...
PGConf.ASIA 2019 Bali - Setup a High-Availability and Load Balancing PostgreS...
 
Fight with Metaspace OOM
Fight with Metaspace OOMFight with Metaspace OOM
Fight with Metaspace OOM
 
Where is my bottleneck? Performance troubleshooting in Flink
Where is my bottleneck? Performance troubleshooting in FlinkWhere is my bottleneck? Performance troubleshooting in Flink
Where is my bottleneck? Performance troubleshooting in Flink
 
Linux scheduler
Linux schedulerLinux scheduler
Linux scheduler
 
NGINX Installation and Tuning
NGINX Installation and TuningNGINX Installation and Tuning
NGINX Installation and Tuning
 
Open vSwitch 패킷 처리 구조
Open vSwitch 패킷 처리 구조Open vSwitch 패킷 처리 구조
Open vSwitch 패킷 처리 구조
 
Flink Forward Berlin 2018: Stefan Richter - "Tuning Flink for Robustness and ...
Flink Forward Berlin 2018: Stefan Richter - "Tuning Flink for Robustness and ...Flink Forward Berlin 2018: Stefan Richter - "Tuning Flink for Robustness and ...
Flink Forward Berlin 2018: Stefan Richter - "Tuning Flink for Robustness and ...
 
[오픈소스컨설팅]RHEL7/CentOS7 Pacemaker기반-HA시스템구성-v1.0
[오픈소스컨설팅]RHEL7/CentOS7 Pacemaker기반-HA시스템구성-v1.0[오픈소스컨설팅]RHEL7/CentOS7 Pacemaker기반-HA시스템구성-v1.0
[오픈소스컨설팅]RHEL7/CentOS7 Pacemaker기반-HA시스템구성-v1.0
 
Galera explained 3
Galera explained 3Galera explained 3
Galera explained 3
 
Stephan Ewen - Scaling to large State
Stephan Ewen - Scaling to large StateStephan Ewen - Scaling to large State
Stephan Ewen - Scaling to large State
 
Evening out the uneven: dealing with skew in Flink
Evening out the uneven: dealing with skew in FlinkEvening out the uneven: dealing with skew in Flink
Evening out the uneven: dealing with skew in Flink
 
Review of QNX
Review of QNXReview of QNX
Review of QNX
 
IBM Spectrum scale object deep dive training
IBM Spectrum scale object  deep dive trainingIBM Spectrum scale object  deep dive training
IBM Spectrum scale object deep dive training
 
Contemporary Linux Networking
Contemporary Linux NetworkingContemporary Linux Networking
Contemporary Linux Networking
 
Concurrency vs parallelism
Concurrency vs parallelismConcurrency vs parallelism
Concurrency vs parallelism
 
Ibm spectrum scale fundamentals workshop for americas part 5 ess gnr-usecases...
Ibm spectrum scale fundamentals workshop for americas part 5 ess gnr-usecases...Ibm spectrum scale fundamentals workshop for americas part 5 ess gnr-usecases...
Ibm spectrum scale fundamentals workshop for americas part 5 ess gnr-usecases...
 
Spectrum Scale Best Practices by Olaf Weiser
Spectrum Scale Best Practices by Olaf WeiserSpectrum Scale Best Practices by Olaf Weiser
Spectrum Scale Best Practices by Olaf Weiser
 
gRPC and Microservices
gRPC and MicroservicesgRPC and Microservices
gRPC and Microservices
 
Introduction to SLURM
Introduction to SLURMIntroduction to SLURM
Introduction to SLURM
 

Andere mochten auch

Building the Internet of Things with Thingsquare and Contiki - day 1, part 2
Building the Internet of Things with Thingsquare and Contiki - day 1, part 2Building the Internet of Things with Thingsquare and Contiki - day 1, part 2
Building the Internet of Things with Thingsquare and Contiki - day 1, part 2Adam Dunkels
 
Building day 2 upload Building the Internet of Things with Thingsquare and ...
Building day 2   upload Building the Internet of Things with Thingsquare and ...Building day 2   upload Building the Internet of Things with Thingsquare and ...
Building day 2 upload Building the Internet of Things with Thingsquare and ...Adam Dunkels
 
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...Adam Dunkels
 
Building the Internet of Things with Thingsquare and Contiki - day 1, part 3
Building the Internet of Things with Thingsquare and Contiki - day 1, part 3Building the Internet of Things with Thingsquare and Contiki - day 1, part 3
Building the Internet of Things with Thingsquare and Contiki - day 1, part 3Adam Dunkels
 
Building the Internet of Things with Thingsquare and Contiki - day 1, part 1
Building the Internet of Things with Thingsquare and Contiki - day 1, part 1Building the Internet of Things with Thingsquare and Contiki - day 1, part 1
Building the Internet of Things with Thingsquare and Contiki - day 1, part 1Adam Dunkels
 
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...Adam Dunkels
 
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...Adam Dunkels
 
Building the Internet of Things with Thingsquare and Contiki - day 2 part 2
Building the Internet of Things with Thingsquare and Contiki - day 2 part 2Building the Internet of Things with Thingsquare and Contiki - day 2 part 2
Building the Internet of Things with Thingsquare and Contiki - day 2 part 2Adam Dunkels
 
Contiki Operating system tutorial
Contiki Operating system tutorialContiki Operating system tutorial
Contiki Operating system tutorialSalah Amean
 
Contiki Presentation
Contiki PresentationContiki Presentation
Contiki PresentationRahul Dhodapkar
 
Contiki introduction I.
Contiki introduction I.Contiki introduction I.
Contiki introduction I.Dingxin Xu
 
Contiki os timer tutorial
Contiki os timer tutorialContiki os timer tutorial
Contiki os timer tutorialSalah Amean
 
Margary- Comitato InfomobilitĂ 
Margary- Comitato InfomobilitĂ Margary- Comitato InfomobilitĂ 
Margary- Comitato InfomobilitĂ GoWireless
 
Pigni Wlan 2009
Pigni Wlan 2009Pigni Wlan 2009
Pigni Wlan 2009GoWireless
 
CTS Matera - America e caraibi
CTS Matera - America e caraibiCTS Matera - America e caraibi
CTS Matera - America e caraibiGianni Sarra
 
Implementing Lightweight Networking
Implementing Lightweight NetworkingImplementing Lightweight Networking
Implementing Lightweight Networkingguest6972eaf
 
protothread and its usage in contiki OS
protothread and its usage in contiki OSprotothread and its usage in contiki OS
protothread and its usage in contiki OSSalah Amean
 
iBeacon - I vantaggi nel mondo retail
iBeacon - I vantaggi nel mondo retailiBeacon - I vantaggi nel mondo retail
iBeacon - I vantaggi nel mondo retailEmanuele Cucci
 

Andere mochten auch (20)

Building the Internet of Things with Thingsquare and Contiki - day 1, part 2
Building the Internet of Things with Thingsquare and Contiki - day 1, part 2Building the Internet of Things with Thingsquare and Contiki - day 1, part 2
Building the Internet of Things with Thingsquare and Contiki - day 1, part 2
 
Building day 2 upload Building the Internet of Things with Thingsquare and ...
Building day 2   upload Building the Internet of Things with Thingsquare and ...Building day 2   upload Building the Internet of Things with Thingsquare and ...
Building day 2 upload Building the Internet of Things with Thingsquare and ...
 
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
 
Building the Internet of Things with Thingsquare and Contiki - day 1, part 3
Building the Internet of Things with Thingsquare and Contiki - day 1, part 3Building the Internet of Things with Thingsquare and Contiki - day 1, part 3
Building the Internet of Things with Thingsquare and Contiki - day 1, part 3
 
Building the Internet of Things with Thingsquare and Contiki - day 1, part 1
Building the Internet of Things with Thingsquare and Contiki - day 1, part 1Building the Internet of Things with Thingsquare and Contiki - day 1, part 1
Building the Internet of Things with Thingsquare and Contiki - day 1, part 1
 
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
 
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
 
Building the Internet of Things with Thingsquare and Contiki - day 2 part 2
Building the Internet of Things with Thingsquare and Contiki - day 2 part 2Building the Internet of Things with Thingsquare and Contiki - day 2 part 2
Building the Internet of Things with Thingsquare and Contiki - day 2 part 2
 
Contiki Operating system tutorial
Contiki Operating system tutorialContiki Operating system tutorial
Contiki Operating system tutorial
 
Contiki Presentation
Contiki PresentationContiki Presentation
Contiki Presentation
 
Contiki introduction I.
Contiki introduction I.Contiki introduction I.
Contiki introduction I.
 
Contiki os timer tutorial
Contiki os timer tutorialContiki os timer tutorial
Contiki os timer tutorial
 
Margary- Comitato InfomobilitĂ 
Margary- Comitato InfomobilitĂ Margary- Comitato InfomobilitĂ 
Margary- Comitato InfomobilitĂ 
 
Pigni Wlan 2009
Pigni Wlan 2009Pigni Wlan 2009
Pigni Wlan 2009
 
CTS Matera - America e caraibi
CTS Matera - America e caraibiCTS Matera - America e caraibi
CTS Matera - America e caraibi
 
Implementing Lightweight Networking
Implementing Lightweight NetworkingImplementing Lightweight Networking
Implementing Lightweight Networking
 
protothread and its usage in contiki OS
protothread and its usage in contiki OSprotothread and its usage in contiki OS
protothread and its usage in contiki OS
 
iBeacon - I vantaggi nel mondo retail
iBeacon - I vantaggi nel mondo retailiBeacon - I vantaggi nel mondo retail
iBeacon - I vantaggi nel mondo retail
 
Implementing Lightweight Networking
Implementing Lightweight NetworkingImplementing Lightweight Networking
Implementing Lightweight Networking
 
Rpl
Rpl Rpl
Rpl
 

Ähnlich wie Building the Internet of Things with Thingsquare and Contiki - day 2 part 1

Securing IoT Applications
Securing IoT Applications Securing IoT Applications
Securing IoT Applications WSO2
 
Early Software Development through Palladium Emulation
Early Software Development through Palladium EmulationEarly Software Development through Palladium Emulation
Early Software Development through Palladium EmulationRaghav Nayak
 
Embedded_ PPT_4-5 unit_Dr Monika-edited.pptx
Embedded_ PPT_4-5 unit_Dr Monika-edited.pptxEmbedded_ PPT_4-5 unit_Dr Monika-edited.pptx
Embedded_ PPT_4-5 unit_Dr Monika-edited.pptxProfMonikaJain
 
RTOS Material hfffffffffffffffffffffffffffffffffffff
RTOS Material hfffffffffffffffffffffffffffffffffffffRTOS Material hfffffffffffffffffffffffffffffffffffff
RTOS Material hfffffffffffffffffffffffffffffffffffffadugnanegero
 
Debugging Numerical Simulations on Accelerated Architectures - TotalView fo...
 Debugging Numerical Simulations on Accelerated Architectures  - TotalView fo... Debugging Numerical Simulations on Accelerated Architectures  - TotalView fo...
Debugging Numerical Simulations on Accelerated Architectures - TotalView fo...Rogue Wave Software
 
Introduction to embedded System.pptx
Introduction to embedded System.pptxIntroduction to embedded System.pptx
Introduction to embedded System.pptxPratik Gohel
 
SREcon 2016 Performance Checklists for SREs
SREcon 2016 Performance Checklists for SREsSREcon 2016 Performance Checklists for SREs
SREcon 2016 Performance Checklists for SREsBrendan Gregg
 
RINA overview and ongoing research in EC-funded projects, ISO SC6 WG7
RINA overview and ongoing research in EC-funded projects, ISO SC6 WG7RINA overview and ongoing research in EC-funded projects, ISO SC6 WG7
RINA overview and ongoing research in EC-funded projects, ISO SC6 WG7Eleni Trouva
 
Realtime traffic analyser
Realtime traffic analyserRealtime traffic analyser
Realtime traffic analyserAlex Moskvin
 
Monitorama 2015 Netflix Instance Analysis
Monitorama 2015 Netflix Instance AnalysisMonitorama 2015 Netflix Instance Analysis
Monitorama 2015 Netflix Instance AnalysisBrendan Gregg
 
Embedded Intro India05
Embedded Intro India05Embedded Intro India05
Embedded Intro India05Rajesh Gupta
 
Embedded systems
Embedded systemsEmbedded systems
Embedded systemsManju Nathan
 
”Bare-Metal Container" presented at HPCC2016
”Bare-Metal Container" presented at HPCC2016”Bare-Metal Container" presented at HPCC2016
”Bare-Metal Container" presented at HPCC2016Kuniyasu Suzaki
 
Embedded systems notes
Embedded systems notesEmbedded systems notes
Embedded systems notesShikha Sharma
 
Real-Time Systems Intro.pptx
Real-Time Systems Intro.pptxReal-Time Systems Intro.pptx
Real-Time Systems Intro.pptx20EUEE018DEEPAKM
 
Intro to HPC
Intro to HPCIntro to HPC
Intro to HPCWendi Sapp
 
2010 02 instrumentation_and_runtime_measurement
2010 02 instrumentation_and_runtime_measurement2010 02 instrumentation_and_runtime_measurement
2010 02 instrumentation_and_runtime_measurementPTIHPA
 

Ähnlich wie Building the Internet of Things with Thingsquare and Contiki - day 2 part 1 (20)

Mastering Real-time Linux
Mastering Real-time LinuxMastering Real-time Linux
Mastering Real-time Linux
 
Securing IoT Applications
Securing IoT Applications Securing IoT Applications
Securing IoT Applications
 
Ch3 processes
Ch3   processesCh3   processes
Ch3 processes
 
Early Software Development through Palladium Emulation
Early Software Development through Palladium EmulationEarly Software Development through Palladium Emulation
Early Software Development through Palladium Emulation
 
Embedded_ PPT_4-5 unit_Dr Monika-edited.pptx
Embedded_ PPT_4-5 unit_Dr Monika-edited.pptxEmbedded_ PPT_4-5 unit_Dr Monika-edited.pptx
Embedded_ PPT_4-5 unit_Dr Monika-edited.pptx
 
RTOS Material hfffffffffffffffffffffffffffffffffffff
RTOS Material hfffffffffffffffffffffffffffffffffffffRTOS Material hfffffffffffffffffffffffffffffffffffff
RTOS Material hfffffffffffffffffffffffffffffffffffff
 
Debugging Numerical Simulations on Accelerated Architectures - TotalView fo...
 Debugging Numerical Simulations on Accelerated Architectures  - TotalView fo... Debugging Numerical Simulations on Accelerated Architectures  - TotalView fo...
Debugging Numerical Simulations on Accelerated Architectures - TotalView fo...
 
Introduction to embedded System.pptx
Introduction to embedded System.pptxIntroduction to embedded System.pptx
Introduction to embedded System.pptx
 
SREcon 2016 Performance Checklists for SREs
SREcon 2016 Performance Checklists for SREsSREcon 2016 Performance Checklists for SREs
SREcon 2016 Performance Checklists for SREs
 
RINA overview and ongoing research in EC-funded projects, ISO SC6 WG7
RINA overview and ongoing research in EC-funded projects, ISO SC6 WG7RINA overview and ongoing research in EC-funded projects, ISO SC6 WG7
RINA overview and ongoing research in EC-funded projects, ISO SC6 WG7
 
VÌrktøjer udviklet pü AAU til analyse af SCJ programmer
VÌrktøjer udviklet pü AAU til analyse af SCJ programmerVÌrktøjer udviklet pü AAU til analyse af SCJ programmer
VÌrktøjer udviklet pü AAU til analyse af SCJ programmer
 
Realtime traffic analyser
Realtime traffic analyserRealtime traffic analyser
Realtime traffic analyser
 
Monitorama 2015 Netflix Instance Analysis
Monitorama 2015 Netflix Instance AnalysisMonitorama 2015 Netflix Instance Analysis
Monitorama 2015 Netflix Instance Analysis
 
Embedded Intro India05
Embedded Intro India05Embedded Intro India05
Embedded Intro India05
 
Embedded systems
Embedded systemsEmbedded systems
Embedded systems
 
”Bare-Metal Container" presented at HPCC2016
”Bare-Metal Container" presented at HPCC2016”Bare-Metal Container" presented at HPCC2016
”Bare-Metal Container" presented at HPCC2016
 
Embedded systems notes
Embedded systems notesEmbedded systems notes
Embedded systems notes
 
Real-Time Systems Intro.pptx
Real-Time Systems Intro.pptxReal-Time Systems Intro.pptx
Real-Time Systems Intro.pptx
 
Intro to HPC
Intro to HPCIntro to HPC
Intro to HPC
 
2010 02 instrumentation_and_runtime_measurement
2010 02 instrumentation_and_runtime_measurement2010 02 instrumentation_and_runtime_measurement
2010 02 instrumentation_and_runtime_measurement
 

KĂźrzlich hochgeladen

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
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
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel AraĂşjo
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 

KĂźrzlich hochgeladen (20)

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 

Building the Internet of Things with Thingsquare and Contiki - day 2 part 1

  • 1. Building Connected Devices With Thingsquare and Contiki Day 2
  • 2. Yesterday • Learned about how to prototype apps • Learned about the high-level operation of the protocols • Got a bit of background
  • 3. Today • Deep-dive into the protocols • More information about Contiki
  • 5. Contiki: an IoT OS • Helps application programs – Processes and concurrency – Timers – Memory management – Networking – Device drivers
  • 7. Time in Contiki • Two system clocks in Contiki – Coarse-grained, most often 128 Hz • CLOCK_SECOND – Fine-grained, most often 32768 Hz • RTIMER_SECOND – Platform dependent – Power of two for simple math
  • 8. Timers • struct timer – coarse – Passive timer, only keeps track of its expiration time • struct etimer – coarse – Active timer, sends an event when it expires • struct ctimer – coarse – Active timer, calls a function when it expires • struct rtimer – fine – Real-time timer, calls a function at an exact time
  • 9. Etimer • Periodically print the time static struct etimer etim; PROCESS_THREAD(my_process, ev, data) { PROCESS_BEGIN(); while(1) { printf(”Uptime (seconds): %lun", clock_seconds()); etimer_set(&etim, CLOCK_SECOND); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&etim)); } PROCESS_END(); }
  • 10. Ctimer • Print ”Hello, callback” after 1/8 second. static struct ctimer callback_timer; static void callback(void *data) { printf("%sn", (char *) data); } void application(void) { ctimer_set(&callback_timer, CLOCK_SECOND / 8, callback, "Hello, callback!"); return 0; }
  • 11. Rtimer • Sets a hardware interrupt at set time • Invokes a callback static struct rtimer rt; rtimer_set(&rt, /* pointer to rtimer struct */ RTIMER_NOW() + RTIMER_SECOND/100, /* 10ms */ 1, /* duration */ rt_callback, /* callback pointer */ NULL); /* pointer to data */
  • 12. Rtimer • Rtimer callback static void rt_callback(struct rtimer *rt, void *data) { printf(”callback!n"); }
  • 13. Hands-on: blink.c • See the blink.c example on the Thingsquare cloud • Uses etimer to blink LEDs • Note the use of etimer_reset() to provide a stable timer
  • 15. Programming concept: Multithreading • Threads are given a timeslot to execute • Paused / continued later by OS scheduler if not done • Costly – stack space (RAM), CPU
  • 16. Programming concept: Event driven / state machine • Reactive - events control program flow – Timers, hardware interrupts, radio, etc • More kind on resources • However, callbacks and state variables makes programming harder
  • 17. Event driven / state machine
  • 18. State machine • What state? What event? Conditions, transitions, headaches.
  • 19. • Event driven is kinder on hw resources.. • Multithreaded is kinder on the programmer.. - can their strengths be combined?
  • 20. Programming concept: Protothreads • Threading without the overhead – RAM is limited, threads use too much RAM • Protothreads are event-driven but with a threaded programming style • Cooperative scheduling
  • 21. C-switch expansion int a_protothread(struct pt *pt) { PT_BEGIN(pt); int a_protothread(struct pt *pt) { switch(pt->lc) { case 0: PT_WAIT_UNTIL(pt, condition1); pt->lc = 5; case 5: if(!condition1) return 0; if(something) { if(something) { PT_WAIT_UNTIL(pt, condition2); pt->lc = 10; case 10: if(!condition2) return 0; } PT_END(pt); } } Line numbers } } return 1;
  • 22. Six-line implementation • C compiler pre-processor replaces with switch-case • very efficient struct pt { unsigned short lc; }; #define PT_INIT(pt) pt->lc = 0 #define PT_BEGIN(pt) switch(pt->lc) { case 0: #define PT_EXIT(pt) pt->lc = 0; return 2 #define PT_WAIT_UNTIL(pt, c) pt->lc = __LINE__; case __LINE__: if(!(c)) return 0 #define PT_END(pt) } pt->lc = 0; return 1
  • 23. Protothread limitations • Automatic variables not stored across a blocking wait – Workaround: use static local variables instead • Constraints on the use of switch() constructs in programs – Workaround: don’t use switches
  • 24. Contiki processes • Contiki processes are very lightweight – Execution is event-driven – Can receive events from other processes – Must not block in busy-wait loop • while(1) will crash the device • Contiki processes are protothreads
  • 25. Contiki processes #include "contiki.h" /*---------------------------------------------------*/ PROCESS(hello_world_process, "Hello world process"); AUTOSTART_PROCESSES(&hello_world_process); /*---------------------------------------------------*/ PROCESS_THREAD(hello_world_process, ev, data) { PROCESS_BEGIN(); printf("Hello, worldn"); PROCESS_END(); }
  • 26. Contiki events • How to wait for an event PROCESS_THREAD(first_process, ev, data) .. .. PROCESS_WAIT_EVENT_UNTIL(ev == servo_event); if(data != NULL) { handle_servo((struct servo_data *) data); } • ev contains the event number • data is a void* to any data – Can be NULL
  • 27. Hands-on: blink.c • See how PROCESS_BEGIN(), PROCESS_END(), PROCESS_WAIT_UNTIL() are used
  • 28. Starvation in Contiki • Thread scheduling is cooperative – play nice • The watchdog is on – on some platforms unable to turn off • Don’t hog the CPU • Long-running, do – watchdog_periodic(); – PROCESS_WAIT();
  • 30. Contiki memb struct user_struct { int a, b; } MEMB(block, 10, struct user_struct); m = memb_alloc(&block); memb_free(&block, m);
  • 33. Contiki netstacks • Three network stacks – IPv6 – IPv4 – Rime
  • 34. The Contiki netstack • Four layers – Network layer Application Transport Network, routing Adaptation – MAC layer – RDC layer – Radio layer MAC Duty cycling Radio
  • 35. The Contiki IPv6 netstack websocket.c, httpsocket.c, coap.c Application udp-socket.c, tcpsocket.c Transport uip6.c, rpl.c Network, routing sicslowpan.c Adaptation csma.c MAC nullrdc.c, contikimac.c Duty cycling cc2538-rf.c Radio
  • 36. New Contiki 3.x APIs • UDP socket – Send and receive data with UDP – Callback-based • TCP socket – Listen for new connections (server) – Set up new connections (client) – Send and receive data – Callback-based
  • 37. UDP socket API int udp_socket_register(struct udp_socket *c, void *ptr, udp_socket_input_callback_t receive_callback); int udp_socket_bind(struct udp_socket *c, uint16_t local_port); int udp_socket_connect(struct udp_socket *c, uip_ipaddr_t *remote_addr, uint16_t remote_port); int udp_socket_send(struct udp_socket *c, const void *data, uint16_t datalen); int udp_socket_sendto(struct udp_socket *c, const void *data, uint16_t datalen, const uip_ipaddr_t *addr, uint16_t port);
  • 38. UDP socket API • Connected sockets: only receive data from the specified host/port • Receiving data is simple – Get a pointer along with the callback • Sending data is simple – For connected sockets: to the connected host/port – Send to any host/port
  • 39. TCP socket API • TCP significantly trickier than UDP – Connections – Retransmissions – Buffers
  • 40. TCP socket API void tcp_socket_register(struct tcp_socket *s, void *ptr, uint8_t *input_databuf, int input_databuf_len, uint8_t *output_databuf, int output_databuf_len, tcp_socket_input_callback_t input_callback, tcp_socket_event_callback_t event_callback); int tcp_socket_connect(struct tcp_socket *s, uip_ipaddr_t *ipaddr, uint16_t port); int tcp_socket_listen(struct tcp_socket *s, uint16_t port); int tcp_socket_unlisten(struct tcp_socket *s); int tcp_socket_send(struct tcp_socket *s, const uint8_t *dataptr, int datalen); int tcp_socket_send_str(struct tcp_socket *s, const char *strptr); int tcp_socket_close(struct tcp_socket *s);
  • 41. TCP socket API • Caller must provide input and output buffers – The caller knows how much data it is going to be sending and receiving • Sending data is easy – Just call the send function • Receiving data is trickier – Data may be retained in the buffer
  • 43. The Contiki directory structure • apps/ – Contiki applications • core/ – Contiki core code • cpu/ – Contiki CPU-specific code • doc/ – Contiki documentation • examples/ – Contiki examples • platform/ – Contiki platform code • regression-tests/ – Contiki regression tests • tools/ – Contiki tools
  • 44. Contiki 3.x directories • dev/ – Device drivers • More fine-grained control through modules – New subdirectories under sys/net/
  • 45. A project directory • examples/hello-world – Makefile • Contains the top-level rules to build the project – project-conf.h • Project configuration • Optional – must be explicitly enabled by Makefile – hello-world.c • Project source code file
  • 46. Toolchain Installation • Embedded compiler toolchains with built-in IDE – IAR • Gcc – Compiler – Linker – Use external editor (Eclipse, Emacs, vi, …)
  • 47. Instant Contiki • Full toolchain installation in a Linux VM • Runs in VMware Player • Compile in Instant Contiki, run on the hardware
  • 48. Building firmware images • Use C compiler to compile the full Contiki source code • Compile in a project directory • Need to change something? Re-compile
  • 49. Contiki firmware images • In a terminal, go to the project directory make TARGET=platform file • This will build the full source code tree for your project. Eg, make TARGET=cc2538dk hello-world
  • 50. Configuration • Two layers of configuration – Platform level • Buffer sizes, radio drivers, etc – Project level • RDC mechanisms • Don’t touch the platform configuration • Do touch the project configuration
  • 51. Uploading the firmware • Some platforms have a convenient way to upload the firmware make TARGET=sky hello-world.upload • Some platforms are significantly trickier
  • 52. Save target • If you are using the same target a lot, make TARGET=cc2538dk savetarget • Then, simply make blink.upload
  • 53. Running as the native target • Sometimes using the native target is useful make TARGET=native hello-world • Run the program ./hello-world.native
  • 54. Other commands • Connect to serial port make TARGET=exp5438 login make TARGET=exp5438 COMPORT=COM12 login • Clean out previous compilation make TARGET=exp5438 clean • List available commands make TARGET=exp5438 help
  • 55. Cooja
  • 56. The Cooja Simulator • Emulation mode – Run exact same firmware images as run on hardware – Slower, more exact • Native mode – Run the Contiki code, compiled for the native system – Faster, can run (much) larger systems
  • 57.
  • 58. Running Cooja • Go to the Cooja directory – cd tools/cooja – ant run
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69. The Contiki regression tests • A great resource for seeing Cooja simulation setups • contiki/regression-tests/