Contiki OS Sharvil Patel, Michael Ray, Emily Rowland 1 Agenda ● Introduction to Contiki with History ● Components ● Applications ● Conclusion 2 Introduction ● Real-time operating system ● Specializes in Internet of Things (IoT) https://github.com/lab11/atum ● Low power oriented ● Open-source (github.com/contiki-os) ○ ● Easy/Fast rapid development ○ ● Free in commercial and noncommercial applications Developed in C 16 supported hardware platforms http://www.ofrei.com/images/multi-draincell.jpg 3 Specifications ● Extremely lightweight ○ 10 kB of RAM ○ 30 kB of ROM ○ Fully functional system including GUI requires 30 kB of RAM ■ Linux uses 1 MB! 4 History ● Created in 2002 by Adam Dunkels Ph.D. ○ Author of the uIP stack, Rime, protothreads ○ Founder of Thingsquare ● Now developed by a worldwide team ○ TI, Atmel, Cisco, Oxford University, SAP, etc, & you! 5 Applications ● City sound monitoring ● Street lights ● Networked electrical power meters ● Industrial monitoring ● Remote house monitoring ● Radiation monitoring ● ATUM 6 OS components ● Processes ● Power awareness ● Protothreads ● Sleepy routers ● Communication stacks ● Cooja networking simulator ● Full IP networking ● Coffee - flash file system ● Memory allocation ● Rime stack ● Timers ● Watchdog 7 Processes All programs in Contiki are processes There are cooperative and preemptive contexts https://github.com/contiki-os/contiki/wiki/Processes#The_Process_Thread 8 Protothreads ● Mix of event-driven and multithreaded programming mechanisms ○ ● ● Kernel invokes a process’ protothread in response to an event Non-preemptive ○ Blocking event-handlers ○ Context switches only available on blocking operations Stackless ○ ● http://dunkels.com/adam/pt/ Global variables are required for preserving variables across context switches http://dunkels.com/adam/pt/expansion.html 9 Protothreads (continued) ● Extremely lightweight ○ Overhead: 2 bytes (plus no stack) ● Portable ○ Can be used with/without an OS https://github.com/contiki-os/contiki ○ Pure C code (macros) 10 Communication Stacks Lightest Rime ● 4 types ● Rime uIP 6LoWPAN Heaviest IPv4 http://dunkels.com/adam/dunkels07rime. pdfhttps://github.com/adamdunkels/uip ● ○ Lightweight communication stack ○ When full IPv6 networking is overkill ○ Simple operations (single message sending) ○ Layered stack uIP ○ TCP/IP stack ○ Meant for 8 bit and 16 bit devices ○ Very low RAM and overhead code 11 Communication Stacks (continued) ● Lightest Rime uIP ● 6LoWPAN Heaviest IPv4 IPv6 Ready certification ○ Developed by Cisco ○ Smallest IPv6 stack when it was created 6LoWPAN ○ IPv6 over Low power Wireless Personal Area Networks ○ Specializes in low power IPv6 communication ○ Allows send/receive over IEEE 802.15.4 ■ http://www.ti.com/lsds/ti/wireless_connectivity/6lowpan/overview.page http://www.tldp.org/HOWTO/Multicast-HOWTO-2.html ● Same network as Zigbee Capabilities: UDP, TCP, HTTP 12 Memory Allocation ● 3 types ○ memb memory block ■ Static memory struct ■ Most common ■ Lightweight ○ mmem managed memory, ○ malloc - standard C library https://github.com/contiki-os/contiki/wiki/Memory-allocation 13 Timers ● Uses: time elapsed, low power wake up, real time scheduling ○ Timer & STimer ■ ○ Etimer ■ ○ Timed events, repeated Ctimer ■ ○ Set, reset, check expiration manually, time remaining Call a function when expired Rtimer ■ For real-time tasks, preemptive 14 Power awareness ● Designed for small systems and to last on a pair of AA for years ○ Dr. Kevin Fu ● Provides mechanisms for energy management and system power consumption ● Uses timers to figure out where more energy was spent 15 Sleepy routers ● Power saving feature ● When devices are used as relay-nodes, or routers, in wireless networks, Contiki allows these nodes to sleep between packets 16 Cooja networking simulator ● Simulates Contiki nodes ● Emulated node ○ ● Complete hardware emulation Cooja node ○ Contiki code executed in the simulator ● Java node ● Uses: https://github.com/contiki-os/contiki ○ Swarm intelligence ○ Indoor localization http://www.contiki-os.org/start.html 17 Applications 18 Applications -- Koubachi Garden Sensor Wireless, connected garden sensor Data on water, temperature, and light WiFi Connected 2 AA Batteries http://www.koubachi.com Push notifications and lookup database 19 Applications -- LIFX Color Changing Lights Adjusts color, warmth, brightness and intensity Can be set to adjust via schedule Connects with: Apps, IFTTT, Nest Products, Samsung SmartThings, Amazon Echo, and others http://www.lifx.com Contiki: Wireless connectivity 20 Applications -- Life of a Badger Sensor Collars with Microcontrollers running Contiki “Detailing badger behavior and locations underground was impossible” - Dr. Andrew Markham Data sent wirelessly http://www.bbc.com/news/t echnology-13751740 Researchers using network maps of collar nodes 21 ATUM ● Created here at U of M ○ ● ● Available in lab for our final projects Project requirements: ○ “Connected” - network enabled ○ Low power ○ Responsive ○ Small https://github.com/lab11/atum Uses: ○ Timer (for PWM) ○ Protothreads ○ Interrupts 22 Questions? 23 Resources Getting Started http://www.contiki-os.org http://www.eecs.umich.edu/courses/eecs373/Lec/RTOS_short.pdf https://github.com/contiki-os/contiki Protothreads http://dunkels.com/adam/pt/expansion.html https://engineering.purdue.edu/dcsl/reading/2009/rpanta-protothread.pdf Networking https://github.com/adamdunkels/uip http://dunkels.com/adam/dunkels07rime.pdf http://www.tldp.org/HOWTO/Multicast-HOWTO-2.html http://www.ti.com/lsds/ti/wireless_connectivity/6lowpan/overview.page 24 Bibliography http://www.contiki-os.org http://contiki-os.blogspot.com http://www.thingsquare.com/customers/ http://www.lifx.com http://www.eecs.umich.edu/courses/eecs373/Lec/RTOS_short.pdf http://www.koubachi.com http://www.bbc.com/news/technology-13751740 https://github.com/adamdunkels/uip http://dunkels.com/adam/dunkels07rime.pdf https://engineering.purdue.edu/dcsl/reading/2009/rpanta-protothread.pdf 25 mmem and malloc heap memory allocators mmem is byte aligned, memcpy() or packed must be used malloc is the same as defined in stdlib.h https://github.com/contiki-os/contiki/wiki/Memory-allocation 26