SlideShare a Scribd company logo
1 of 25
Contiki Libraries
Contiki ringbuf
• Interrupt-safe way to pass bytes from
interrupt to non-interrupt code
• Ring buffer size must be even power of
two
• Ring buffer can only pass bytes (uint8_t)
ringbuf
Void ringbuf_init (struct ringbuf *r,
uint8_t *a, uint8_t size_power_of_two);
int ringbuf_put (struct ringbuf *r, uint8_t c);
int ringbuf_get (struct ringbuf *r);
int ringbuf_size (struct ringbuf *r);
int ringbuf_elements (struct ringbuf *r);
The list library
• Convenient way to keep arbitrary structs on a
list
• Only requirement is a ->next pointer at
beginning of the struct
• Example:
struct my_data {
struct my_data *next;
int some_data;
uint8_t more_data[8];
}
The list library
The list library
void list_init (list_t list)
Initialize a list.
void *list_head (list_t list)
Get a pointer to the first element of a list.
void list_push (list_t list, void *item)
Add an item to the start of the list.
void *list_pop (list_t list)
Remove the first object on a list.
void *list_item_next (void *item)
Get the next item following this item.
The list library
#include "lib/list.h"
struct example_list_struct {
struct *next;
int number;
};
LIST(example_list);
static void my_function(void) {
struct example_list_struct *s;
list_init(example_list);

list_add(example_list, &element1);
list_add(example_list, &element2);
for(s = list_head(example_list); s != NULL; s = list_item_next(s)) {
printf("List element number %dn", s->number);
}
}
The memb library
• Manage a chunk of memory
• A fixed set of structs that can be allocated
and deallocated
• Size of set specified at compile time
The memb library
• MEMB(name, structure, num)

– Declare a memory block.
• void memb_init(struct memb *m)

– Initialize a memory block.
• void *memb_alloc(struct memb *m)

– Allocate a memory block.
• int memb_free(struct memb *m, void *ptr)

– Free a memory block.
The memb library
struct my_structure {
int a, b;
}

MEMB(my_mem, struct my_structure, NUM_STRUCTS);
static void my_function(void) {
memb_init(&my_mem);

struct my_structure *s = memb_alloc(&my_mem);
memb_free(s);
}
Memory allocation with a list
• Typical usage pattern:
– Allocate memory from memb
– Maintain on a list

• Makes it easy to keep track of things to
deallocate them later
Memory allocation with a list
struct example_num {
struct example_num *next;
int num;
};
#define MAX_NUMS 16
LIST(num_table);
MEMB(num_mem, struct example_num, MAX_NUMS);
void init_num(void) {
memb_init(&num_mem);
list_init(neighbor_table);
}
Memory allocation with a list
void add_num(int num) {
e = memb_alloc(&neighbor_mem);
if(e != NULL) {
e->num = num;
list_add(num_table, e);
}
}
struct example_num {
void remove_num(struct example_num *e) {
list_remove(num_table, e);
memb_free(&num_mem, e);
}
Memory allocation with a list
struct example_num *find_num(int num) {
struct example_num *n;
for(n = list_head(num_table); n != NULL; n = list_element_next(n)) {
if(n->num == num) {
return n;
}
}
return NULL;
}
The mmem library
• Managed memory allcator
• Maintains a fragmentation-free memory
area
• Sometimes useful
• Somewhat tricky to use
The mmem library
The mmem library
• MMEM_PTR(m)
– Provide a pointer to managed memory.

• int mmem_alloc(struct mmem *m,
unsigned int size)
– Allocated managed memory.

• void mmem_free(struct mmem *)
– Free managed memory.

• void mmem_init(void)
– Initialize the managed memory library.
The lower layers of the netstack
The radio driver
• Input
– Read packet from the radio into packetbuf
– Call NETSTACK_RDC.input();

• Output
– Prepare radio for sending
• NETSTACK_RADIO.prepare()

– Send the packet
• NETSTACK_RADIO.transmit()
Radio driver gotchas
• Radio driver works in two layers
– Interrupt context
– Contiki context

• SPI bus must be protected
– Disable interrupts during an SPI transfer

• Radio core must be protected
– Maintain flag to avoid interrupts when radio
driver is active
Radio driver energy estimator
• The Contiki energest module keeps track
of energy consumption
–
–
–
–

ENERGEST_ON(ENERGEST_TYPE_LISTEN);
ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
ENERGEST_ON(ENERGEST_TYPE_TRANSMIT);
ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT);
queuebufs
• “Enough” queuebufs are needed
• Difficult to say beforehand how many that
is
• Trial and error may be needed
Hands-on: HTTP POST
Build big-red-button.c as a
firmware image
•
•
•
•
•

Copy big-red-button.c from demo.thsq.io
Compile and upload on the hardware
Connect the button
Sniff the packets on screen
Code walk-through
More

http://thingsquare.com

More Related Content

What's hot

Presentation about arrays
Presentation about arraysPresentation about arrays
Presentation about arraysslave of Allah
 
Pointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationPointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationRabin BK
 
Dynamic memory Allocation in c language
Dynamic memory Allocation in c languageDynamic memory Allocation in c language
Dynamic memory Allocation in c languagekiran Patel
 
Dynamic Memory allocation
Dynamic Memory allocationDynamic Memory allocation
Dynamic Memory allocationGrishma Rajput
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in clavanya marichamy
 
TF.data & Eager Execution
TF.data & Eager ExecutionTF.data & Eager Execution
TF.data & Eager ExecutionModulabs
 
Dynamic Memory Allocation(DMA)
Dynamic Memory Allocation(DMA)Dynamic Memory Allocation(DMA)
Dynamic Memory Allocation(DMA)Kamal Acharya
 
Clojure - Revenge of the Verbs
Clojure - Revenge of the VerbsClojure - Revenge of the Verbs
Clojure - Revenge of the VerbsTim Lossen
 
tf.data: TensorFlow Input Pipeline
tf.data: TensorFlow Input Pipelinetf.data: TensorFlow Input Pipeline
tf.data: TensorFlow Input PipelineAlluxio, Inc.
 

What's hot (13)

C dynamic ppt
C dynamic pptC dynamic ppt
C dynamic ppt
 
Pf presntation
Pf presntationPf presntation
Pf presntation
 
Presentation about arrays
Presentation about arraysPresentation about arrays
Presentation about arrays
 
Pointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationPointers and Dynamic Memory Allocation
Pointers and Dynamic Memory Allocation
 
Dynamic memory Allocation in c language
Dynamic memory Allocation in c languageDynamic memory Allocation in c language
Dynamic memory Allocation in c language
 
Dynamic Memory allocation
Dynamic Memory allocationDynamic Memory allocation
Dynamic Memory allocation
 
7.basic array
7.basic array7.basic array
7.basic array
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
 
TF.data & Eager Execution
TF.data & Eager ExecutionTF.data & Eager Execution
TF.data & Eager Execution
 
Complier
ComplierComplier
Complier
 
Dynamic Memory Allocation(DMA)
Dynamic Memory Allocation(DMA)Dynamic Memory Allocation(DMA)
Dynamic Memory Allocation(DMA)
 
Clojure - Revenge of the Verbs
Clojure - Revenge of the VerbsClojure - Revenge of the Verbs
Clojure - Revenge of the Verbs
 
tf.data: TensorFlow Input Pipeline
tf.data: TensorFlow Input Pipelinetf.data: TensorFlow Input Pipeline
tf.data: TensorFlow Input Pipeline
 

Viewers also liked

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 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
 
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
 
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
 
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
 
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
 
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
 
Implementing Lightweight Networking
Implementing Lightweight NetworkingImplementing Lightweight Networking
Implementing Lightweight Networkingguest6972eaf
 
Introduction to Tiny OS
Introduction to Tiny OSIntroduction to Tiny OS
Introduction to Tiny OSSudharsan S
 

Viewers also liked (16)

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 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 ...
 
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
 
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...
 
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 Presentation
Contiki PresentationContiki Presentation
Contiki Presentation
 
Contiki Operating system tutorial
Contiki Operating system tutorialContiki Operating system tutorial
Contiki Operating system tutorial
 
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
 
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
 
Implementing Lightweight Networking
Implementing Lightweight NetworkingImplementing Lightweight Networking
Implementing Lightweight Networking
 
Implementing Lightweight Networking
Implementing Lightweight NetworkingImplementing Lightweight Networking
Implementing Lightweight Networking
 
Introduction to Tiny OS
Introduction to Tiny OSIntroduction to Tiny OS
Introduction to Tiny OS
 

Similar to Advanced Internet of Things firmware engineering with Thingsquare and Contiki - day 1, part 3

Laboratory 04 Circularly Linked ListDownload the following files.docx
Laboratory 04 Circularly Linked ListDownload the following files.docxLaboratory 04 Circularly Linked ListDownload the following files.docx
Laboratory 04 Circularly Linked ListDownload the following files.docxfestockton
 
UNIT 3a.pptx
UNIT 3a.pptxUNIT 3a.pptx
UNIT 3a.pptxjack881
 
exp2-sparse.pptx
exp2-sparse.pptxexp2-sparse.pptx
exp2-sparse.pptxSharika Tr
 
Ctutorial-Pointers 1.ppt
Ctutorial-Pointers 1.pptCtutorial-Pointers 1.ppt
Ctutorial-Pointers 1.pptDEEPAK948083
 
Array , Structure and Basic Algorithms.pptx
Array , Structure and Basic Algorithms.pptxArray , Structure and Basic Algorithms.pptx
Array , Structure and Basic Algorithms.pptxMrNikhilMohanShinde
 
Pointers and Memory Allocation ESC101.pptx
Pointers and Memory Allocation ESC101.pptxPointers and Memory Allocation ESC101.pptx
Pointers and Memory Allocation ESC101.pptxkrishna50blogging
 
11 Introduction to lists.pptx
11 Introduction to lists.pptx11 Introduction to lists.pptx
11 Introduction to lists.pptxssuser8e50d8
 
L 5 Numpy final ppt kirti.pptx
L 5 Numpy final ppt kirti.pptxL 5 Numpy final ppt kirti.pptx
L 5 Numpy final ppt kirti.pptxKirti Verma
 
Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptx
Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptxQ-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptx
Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptxkalai75
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2Prerna Sharma
 
C programming day#2.
C programming day#2.C programming day#2.
C programming day#2.Mohamed Fawzy
 

Similar to Advanced Internet of Things firmware engineering with Thingsquare and Contiki - day 1, part 3 (20)

ch08.ppt
ch08.pptch08.ppt
ch08.ppt
 
Laboratory 04 Circularly Linked ListDownload the following files.docx
Laboratory 04 Circularly Linked ListDownload the following files.docxLaboratory 04 Circularly Linked ListDownload the following files.docx
Laboratory 04 Circularly Linked ListDownload the following files.docx
 
UNIT 3a.pptx
UNIT 3a.pptxUNIT 3a.pptx
UNIT 3a.pptx
 
exp2-sparse.pptx
exp2-sparse.pptxexp2-sparse.pptx
exp2-sparse.pptx
 
PYTHON.pptx
PYTHON.pptxPYTHON.pptx
PYTHON.pptx
 
06 linked list
06 linked list06 linked list
06 linked list
 
dynamic-allocation.pdf
dynamic-allocation.pdfdynamic-allocation.pdf
dynamic-allocation.pdf
 
Ctutorial-Pointers 1.ppt
Ctutorial-Pointers 1.pptCtutorial-Pointers 1.ppt
Ctutorial-Pointers 1.ppt
 
Array , Structure and Basic Algorithms.pptx
Array , Structure and Basic Algorithms.pptxArray , Structure and Basic Algorithms.pptx
Array , Structure and Basic Algorithms.pptx
 
C Programming - Refresher - Part III
C Programming - Refresher - Part IIIC Programming - Refresher - Part III
C Programming - Refresher - Part III
 
Pointers and Memory Allocation ESC101.pptx
Pointers and Memory Allocation ESC101.pptxPointers and Memory Allocation ESC101.pptx
Pointers and Memory Allocation ESC101.pptx
 
C language introduction
C language introduction C language introduction
C language introduction
 
11 Introduction to lists.pptx
11 Introduction to lists.pptx11 Introduction to lists.pptx
11 Introduction to lists.pptx
 
Chp4(ref dynamic)
Chp4(ref dynamic)Chp4(ref dynamic)
Chp4(ref dynamic)
 
L 5 Numpy final ppt kirti.pptx
L 5 Numpy final ppt kirti.pptxL 5 Numpy final ppt kirti.pptx
L 5 Numpy final ppt kirti.pptx
 
Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptx
Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptxQ-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptx
Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptx
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2
 
Introduction linked list
Introduction linked listIntroduction linked list
Introduction linked list
 
C programming day#2.
C programming day#2.C programming day#2.
C programming day#2.
 
NumPy.pptx
NumPy.pptxNumPy.pptx
NumPy.pptx
 

Recently uploaded

Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 

Recently uploaded (20)

Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 

Advanced Internet of Things firmware engineering with Thingsquare and Contiki - day 1, part 3

  • 2. Contiki ringbuf • Interrupt-safe way to pass bytes from interrupt to non-interrupt code • Ring buffer size must be even power of two • Ring buffer can only pass bytes (uint8_t)
  • 3. ringbuf Void ringbuf_init (struct ringbuf *r, uint8_t *a, uint8_t size_power_of_two); int ringbuf_put (struct ringbuf *r, uint8_t c); int ringbuf_get (struct ringbuf *r); int ringbuf_size (struct ringbuf *r); int ringbuf_elements (struct ringbuf *r);
  • 4. The list library • Convenient way to keep arbitrary structs on a list • Only requirement is a ->next pointer at beginning of the struct • Example: struct my_data { struct my_data *next; int some_data; uint8_t more_data[8]; }
  • 6. The list library void list_init (list_t list) Initialize a list. void *list_head (list_t list) Get a pointer to the first element of a list. void list_push (list_t list, void *item) Add an item to the start of the list. void *list_pop (list_t list) Remove the first object on a list. void *list_item_next (void *item) Get the next item following this item.
  • 7. The list library #include "lib/list.h" struct example_list_struct { struct *next; int number; }; LIST(example_list); static void my_function(void) { struct example_list_struct *s; list_init(example_list); list_add(example_list, &element1); list_add(example_list, &element2); for(s = list_head(example_list); s != NULL; s = list_item_next(s)) { printf("List element number %dn", s->number); } }
  • 8. The memb library • Manage a chunk of memory • A fixed set of structs that can be allocated and deallocated • Size of set specified at compile time
  • 9. The memb library • MEMB(name, structure, num) – Declare a memory block. • void memb_init(struct memb *m) – Initialize a memory block. • void *memb_alloc(struct memb *m) – Allocate a memory block. • int memb_free(struct memb *m, void *ptr) – Free a memory block.
  • 10. The memb library struct my_structure { int a, b; } MEMB(my_mem, struct my_structure, NUM_STRUCTS); static void my_function(void) { memb_init(&my_mem); struct my_structure *s = memb_alloc(&my_mem); memb_free(s); }
  • 11. Memory allocation with a list • Typical usage pattern: – Allocate memory from memb – Maintain on a list • Makes it easy to keep track of things to deallocate them later
  • 12. Memory allocation with a list struct example_num { struct example_num *next; int num; }; #define MAX_NUMS 16 LIST(num_table); MEMB(num_mem, struct example_num, MAX_NUMS); void init_num(void) { memb_init(&num_mem); list_init(neighbor_table); }
  • 13. Memory allocation with a list void add_num(int num) { e = memb_alloc(&neighbor_mem); if(e != NULL) { e->num = num; list_add(num_table, e); } } struct example_num { void remove_num(struct example_num *e) { list_remove(num_table, e); memb_free(&num_mem, e); }
  • 14. Memory allocation with a list struct example_num *find_num(int num) { struct example_num *n; for(n = list_head(num_table); n != NULL; n = list_element_next(n)) { if(n->num == num) { return n; } } return NULL; }
  • 15. The mmem library • Managed memory allcator • Maintains a fragmentation-free memory area • Sometimes useful • Somewhat tricky to use
  • 17. The mmem library • MMEM_PTR(m) – Provide a pointer to managed memory. • int mmem_alloc(struct mmem *m, unsigned int size) – Allocated managed memory. • void mmem_free(struct mmem *) – Free managed memory. • void mmem_init(void) – Initialize the managed memory library.
  • 18. The lower layers of the netstack
  • 19. The radio driver • Input – Read packet from the radio into packetbuf – Call NETSTACK_RDC.input(); • Output – Prepare radio for sending • NETSTACK_RADIO.prepare() – Send the packet • NETSTACK_RADIO.transmit()
  • 20. Radio driver gotchas • Radio driver works in two layers – Interrupt context – Contiki context • SPI bus must be protected – Disable interrupts during an SPI transfer • Radio core must be protected – Maintain flag to avoid interrupts when radio driver is active
  • 21. Radio driver energy estimator • The Contiki energest module keeps track of energy consumption – – – – ENERGEST_ON(ENERGEST_TYPE_LISTEN); ENERGEST_OFF(ENERGEST_TYPE_LISTEN); ENERGEST_ON(ENERGEST_TYPE_TRANSMIT); ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT);
  • 22. queuebufs • “Enough” queuebufs are needed • Difficult to say beforehand how many that is • Trial and error may be needed
  • 24. Build big-red-button.c as a firmware image • • • • • Copy big-red-button.c from demo.thsq.io Compile and upload on the hardware Connect the button Sniff the packets on screen Code walk-through