6LoWPAN Book Course Exercises (PPT)

4,700 views
4,516 views

Published on

0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,700
On SlideShare
0
From Embeds
0
Number of Embeds
27
Actions
Shares
0
Downloads
405
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide
  • Higher powered ARM and Xscale processors are blurring the boundry between uC and CPU. They still integrate lots of peripherals, but tend to have an MMU and run almost full OS.
  • Flash memory of NOR and NAND type.
  • Last slide on uC issues.
  • 6LoWPAN Book Course Exercises (PPT)

    1. 1. 6LoWPAN: The Wireless Embedded Internet Companion Exercise Slides Zach Shelby, Martti Huttunen This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA Figures on slides with book symbol from 6LoWPAN: The Wireless Embedded Internet, Shelby & Bormann, ISBN: 978-0-470-74799-5, (c) 2009 John Wiley & Sons Ltd
    2. 2. The Book <ul><li>6LoWPAN: The Wireless Embedded Internet </li></ul><ul><li>by Zach Shelby, Carsten Bormann </li></ul><ul><li>Length: 254 pages </li></ul><ul><li>Publisher: John Wiley & Sons </li></ul><ul><li> http://www.6lowpan.net </li></ul><ul><li>Companion web-site with blog, full companion course slides and exercises </li></ul>
    3. 3. Outline <ul><li>Introduction </li></ul><ul><li>Embedded Devices </li></ul><ul><li>Operating Systems </li></ul><ul><li>Embedded Development </li></ul><ul><li>6LoWPAN Implementation Issues </li></ul><ul><li>Exercise Hardware </li></ul><ul><li>Contiki & uIP </li></ul><ul><li>Exercises </li></ul>
    4. 4. Introduction
    5. 5. Embedded Meets Wireless <ul><li>Microcontrollers are everywhere in embedded systems </li></ul><ul><ul><li>appliances, watches, toys, cameras, industrial control, mobile phones, sensors, cars, automation </li></ul></ul><ul><li>Microcontroller vs. microprocessor market </li></ul><ul><ul><li>15 x more microcontroller units sold yearly (8 billion) </li></ul></ul><ul><ul><li>20 billion vs 43 billion USD market by 2009 </li></ul></ul><ul><li>Possibilities of wireless are endless </li></ul><ul><ul><li>802.15.4 chips to 150 million unit sales by 2009 </li></ul></ul><ul><li>Embedded systems have special characteristics </li></ul><ul><li>Academic community very computer science and protocol driven, often ignoring </li></ul><ul><ul><li>Physical layer realities </li></ul></ul><ul><ul><li>Embedded system operation </li></ul></ul><ul><ul><li>Real-time capabilities </li></ul></ul>
    6. 6. Embedded Devices
    7. 7. Device Architecture <ul><li>Microcontroller and program code </li></ul><ul><li>Power supply </li></ul><ul><ul><li>Power management </li></ul></ul><ul><ul><li>Renewable energy? </li></ul></ul><ul><li>Memory (RAM, FLASH) </li></ul><ul><li>Sensors </li></ul><ul><li>Actuators </li></ul><ul><li>Communication </li></ul><ul><li>Input/output </li></ul><ul><li>Part of a larger system? </li></ul>
    8. 8. Microcontroller <ul><li>Main processing units of embedded devices </li></ul><ul><li>Special purpose and highly integrated </li></ul><ul><ul><li>Integrated RAM, ROM, I/O, peripherals </li></ul></ul><ul><ul><li>Extremely good power to performance ratio </li></ul></ul><ul><ul><li>Cheap, typically 0.25 - 10.00 USD </li></ul></ul><ul><li>Executes programs including embedded system control, measurement & communications </li></ul><ul><ul><li>Usually time-critical requiring guarantees </li></ul></ul><ul><ul><li>Real-time performance a common requirement </li></ul></ul><ul><ul><ul><li>Pre-emptive scheduled tasks </li></ul></ul></ul><ul><ul><ul><li>Queues and semaphores </li></ul></ul></ul>
    9. 9. Example: MSP430 <ul><li>Texas Instruments mixed-signal uC </li></ul><ul><li>16-bit RISC </li></ul><ul><li>ROM: 1-60 kB </li></ul><ul><li>RAM: Up to 10 kB </li></ul><ul><li>Analogue </li></ul><ul><ul><li>12 bit ADC & DAC </li></ul></ul><ul><ul><li>LCD driver </li></ul></ul><ul><li>Digital </li></ul><ul><ul><li>USART x 2 </li></ul></ul><ul><ul><li>DMA controller </li></ul></ul><ul><ul><li>Timers </li></ul></ul>
    10. 10. Example: Atmel AVR <ul><li>Atmel AVR family </li></ul><ul><li>8-bit RISC </li></ul><ul><li>RAM: Up to 4 kB </li></ul><ul><li>ROM: Up to 128 kB </li></ul><ul><li>Analogue </li></ul><ul><ul><li>ADC </li></ul></ul><ul><ul><li>PWM </li></ul></ul><ul><li>Digital </li></ul><ul><ul><li>USARTs </li></ul></ul><ul><ul><li>Timers </li></ul></ul>
    11. 11. Memory <ul><li>Random access memory (RAM) </li></ul><ul><ul><li>Included on-board in microcontrollers </li></ul></ul><ul><ul><li>Often the most valuable resource </li></ul></ul><ul><li>Read-only memory (ROM) </li></ul><ul><ul><li>Usually actually implemented with NOR flash memory </li></ul></ul><ul><li>Flash </li></ul><ul><ul><li>Eraseable programmable memory </li></ul></ul><ul><ul><li>Can be read/written in blocks </li></ul></ul><ul><ul><li>Slow during the write process </li></ul></ul><ul><ul><li>Consumes power of course! </li></ul></ul><ul><li>External memory </li></ul><ul><ul><li>External memory supported by some microcontrollers </li></ul></ul><ul><ul><li>Serial flash always supported </li></ul></ul>
    12. 12. Common Bus Interfaces <ul><li>Digital and analogue I/O </li></ul><ul><ul><li>Accessed by port and pin number (e.g. P1.3) </li></ul></ul><ul><ul><li>Some pins are also connected to interrupts </li></ul></ul><ul><li>UART </li></ul><ul><ul><li>Asynchronous serial bus </li></ul></ul><ul><ul><li>After level translation it is an RS232 bus </li></ul></ul><ul><ul><li>Usually kbps up to 1 mbps </li></ul></ul><ul><li>SPI (serial peripheral interface) </li></ul><ul><ul><li>Synchronous serial bus </li></ul></ul><ul><ul><li>Reliable with speeds of several Mbps </li></ul></ul><ul><li>I 2 C (inter-integrated circuit) bus </li></ul><ul><ul><li>2-wire bus with data and clock </li></ul></ul><ul><li>Parallel bus </li></ul><ul><ul><li>Implemented with X-bit width </li></ul></ul><ul><ul><li>X-bit address and clock signals </li></ul></ul>
    13. 13. Communications <ul><li>Embedded devices are autonomous but most often part of a larger system </li></ul><ul><li>Thus communications interfaces are very important in the embedded world </li></ul><ul><li>Wired interfaces </li></ul><ul><ul><li>Serial: RS232, RS485 </li></ul></ul><ul><ul><li>LAN: Ethernet </li></ul></ul><ul><ul><li>Industrial: Modbus, Profibus, Lontalk, CAN </li></ul></ul><ul><li>Wireless interfaces </li></ul><ul><ul><li>Low-power: IEEE 802.15.4 (ZigBee, ISA100, Wireless HART) </li></ul></ul><ul><ul><li>WLAN: WiFi </li></ul></ul><ul><ul><li>WAN: GPRS, WiMax </li></ul></ul>
    14. 14. Transceivers <ul><li>Modern embedded communications chips are transceivers: they combine half-duplex transmission and reception. </li></ul><ul><li>Transceivers integrate varying functionality, from a bare analogue interface to the whole digital baseband and key MAC functions. </li></ul>
    15. 15. Important Characteristics <ul><li>Level of digital integration </li></ul><ul><li>Power consumption and efficiency </li></ul><ul><ul><li>Transition speeds and consumption </li></ul></ul><ul><ul><li>Levels of sleep </li></ul></ul><ul><li>Carrier frequency and data rate </li></ul><ul><li>Modulation </li></ul><ul><li>Error coding capabilities </li></ul><ul><li>Noise figure and receiver sensitivity </li></ul><ul><li>Received signal strength indicator (RSSI) </li></ul><ul><li>Support for upper layers </li></ul><ul><li>Data and control interface characteristics </li></ul>
    16. 16. Example: RFM TR1000 <ul><li>Proprietary radio at 916 MHz </li></ul><ul><li>OOK and ASK modulation </li></ul><ul><li>30 kbps (OOK) or 115.2 kbps (ASK) operation </li></ul><ul><li>Signal strength indicator </li></ul><ul><li>Provides bit interface </li></ul><ul><li>Not included: </li></ul><ul><ul><li>Synchronization </li></ul></ul><ul><ul><li>Framing </li></ul></ul><ul><ul><li>Encoding </li></ul></ul><ul><ul><li>Decoding </li></ul></ul>
    17. 17. Example: CC2420 <ul><li>IEEE 802.15.4 compliant radio </li></ul><ul><li>2.4 GHz band using DSSS at 250 kbps </li></ul><ul><li>Integrated voltage regulator </li></ul><ul><li>Integrated digital baseband and MAC functions </li></ul><ul><ul><li>Clear channel assessment </li></ul></ul><ul><ul><li>Energy detection (RSSI) </li></ul></ul><ul><ul><li>Synchronization </li></ul></ul><ul><ul><li>Framing </li></ul></ul><ul><ul><li>Encryption/authentication </li></ul></ul><ul><ul><li>Retransmission (CSMA) </li></ul></ul>
    18. 18. Example: CC2430 <ul><li>System-on-a-chip solution </li></ul><ul><li>Integrated 8051 microcontroller </li></ul><ul><ul><li>32 MHz Clock Speed </li></ul></ul><ul><ul><li>ADC, DAC, IOs, 2 UARTs etc. </li></ul></ul><ul><ul><li>8 kB of RAM, up to 128 kB of ROM </li></ul></ul><ul><li>Integrated IEEE 802.15.4 radio, like the CC2420 </li></ul><ul><li>Power consumption 10-12 mA higher than the CC2420, coming from the 8051 microcontroller </li></ul><ul><li>Saves cost, only about 1 EUR more expensive than the CC2420 </li></ul><ul><li>Internal DMA makes radio and UART performance better than with a uC + CC2420 solution </li></ul>
    19. 19. Power Consumption <ul><li>Radio power consumption critical to consider </li></ul><ul><li>Power output level </li></ul><ul><ul><li>Limited savings effect </li></ul></ul><ul><ul><li>Optimal power difficult </li></ul></ul><ul><ul><li>Must be considered globally </li></ul></ul><ul><li>Transition times </li></ul><ul><ul><li>Each transition costs </li></ul></ul><ul><ul><li>Power equal to RX mode </li></ul></ul><ul><ul><li>Should be accounted for </li></ul></ul>
    20. 20. Power Consumption <ul><li>A simple approximation for power consumption: </li></ul><ul><ul><li>= Time that takes to go from sleep state to awake state </li></ul></ul><ul><ul><li>= Transmitter setup time, i.e. time it takes for the transmitter to be ready </li></ul></ul><ul><ul><li>= Time in the Tx state </li></ul></ul><ul><ul><li>= Receiver setup time, i.e. time it takes for the receiver to be ready </li></ul></ul><ul><ul><li>= Time in the Rx state </li></ul></ul><ul><ul><li>= Time in the idle state </li></ul></ul><ul><ul><li>= Time in the sleep state </li></ul></ul><ul><ul><li>= Average number of times per frame that the transmitter is used </li></ul></ul><ul><ul><li>= Average number of times per frame that the receiver is used </li></ul></ul><ul><ul><li>= Duration of the time frame </li></ul></ul><ul><ul><li>= Power used in the Tx state </li></ul></ul><ul><ul><li>= Power used in the Rx state </li></ul></ul><ul><ul><li>= Power used in the idle state </li></ul></ul><ul><ul><li>= Power used in the sleep state </li></ul></ul><ul><ul><li>= Average power used by the transceiver </li></ul></ul>
    21. 21. Sensors & Actuators <ul><li>Sensors measure real-world phenomena and convert them to electrical form </li></ul><ul><ul><li>Analogue sensors require an ADC </li></ul></ul><ul><ul><li>Digital sensors use e.g. I2C or SPI interfaces </li></ul></ul><ul><ul><li>Human interface can also be a sensor (button) </li></ul></ul><ul><li>IEEE 1451 standard becoming important </li></ul><ul><ul><li>Defines standard interfaces and auto-configuration </li></ul></ul><ul><ul><li>Also some protocol specifications </li></ul></ul><ul><li>Actuators convert an electrical signal to some action </li></ul><ul><ul><li>Analogue and digital interfaces both common </li></ul></ul><ul><ul><li>A motor servo is a good example </li></ul></ul>
    22. 22. Operating Systems
    23. 23. Real-time Operating Systems <ul><li>Library vs. operating system </li></ul><ul><ul><li>Operating system manages all resources </li></ul></ul><ul><li>Embedded systems have pre-defined tasks </li></ul><ul><ul><li>Designed to optimize size, cost, efficiency etc. </li></ul></ul><ul><li>Real-time </li></ul><ul><ul><li>Real-time OS provides tools to meet deadlines </li></ul></ul><ul><ul><li>Pre-emptive, queues, semaphores </li></ul></ul><ul><li>Concurrency </li></ul><ul><ul><li>Execution flows (tasks) able to run simultaneously </li></ul></ul><ul><ul><li>Threads and processes </li></ul></ul><ul><li>Sockets and APIs </li></ul>
    24. 24. Real-time Issues <ul><li>Wireless embedded systems usually are real-time </li></ul><ul><ul><li>Watch, robot, building sensor, control node </li></ul></ul><ul><li>A RTOS only facilitates real-time system creation </li></ul><ul><ul><li>Still requires correct software development </li></ul></ul><ul><li>RTOS is not necessarily high performance </li></ul><ul><ul><li>Can meet general system deadlines (soft real-time) </li></ul></ul><ul><ul><li>or deterministically (hard real-time) </li></ul></ul><ul><li>Deadlines can be met using </li></ul><ul><ul><li>Specialized pre-emptive scheduling algorithms </li></ul></ul><ul><ul><li>Proper inter-task design & communication </li></ul></ul><ul><ul><li>Semaphores and queues to avoid racing </li></ul></ul>
    25. 25. Real-time Issues
    26. 26. Concurrency <ul><li>Concurrency occurs when two or more execution flows run simultaneously </li></ul><ul><li>It introduces many problems such as </li></ul><ul><ul><li>Race conditions from shared resources </li></ul></ul><ul><ul><li>Deadlock and starvation </li></ul></ul><ul><li>OS needs to coordinate between tasks </li></ul><ul><ul><li>Data exchange, memory, execution, resources </li></ul></ul><ul><li>There are two main techniques </li></ul><ul><ul><li>Process based </li></ul></ul><ul><ul><ul><li>CPU time split between execution tasks </li></ul></ul></ul><ul><ul><ul><li>Embedded systems typically use lighter threads </li></ul></ul></ul><ul><ul><li>Event based </li></ul></ul>
    27. 27. Concurrency <ul><li>Process based </li></ul><ul><li>Event based </li></ul>
    28. 28. OS Examples <ul><li>Example embedded operating systems </li></ul><ul><ul><li>Contiki ( www.sics.se/~adam/contiki) </li></ul></ul><ul><ul><li>FreeRTOS ( www. freertos .org ) </li></ul></ul><ul><ul><li>TinyOS ( www. tinyos .org ) </li></ul></ul><ul><ul><li>and thousands of others... </li></ul></ul><ul><li>For higher powered MCUs (e.g. ARMs) </li></ul><ul><ul><li>VX Works </li></ul></ul><ul><ul><li>Microcontroller Linux (Android, Maemo etc.) </li></ul></ul><ul><ul><li>Windows CE </li></ul></ul><ul><ul><li>Symbian </li></ul></ul>
    29. 29. Embedded Development
    30. 30. Embedded Development Compiler Linker Programmer Sources Objects Binary
    31. 31. Embedded Development <ul><li>Software resides in system non-volatile memory </li></ul><ul><ul><li>External or internal flash/eeprom/prom memories </li></ul></ul><ul><ul><li>Modern microcontrollers are capable of writing the internal flash memory run-time and often do not have an external memory bus </li></ul></ul><ul><li>Development is done outside the system </li></ul><ul><li>Cross-compilers are used to create binary files </li></ul><ul><ul><li>Cross-compiler creates binary files for a different architecture than it is running on </li></ul></ul><ul><ul><li>Various commercial and free compilers available </li></ul></ul><ul><li>System is programmed by uploading the binary </li></ul><ul><ul><li>In-system programming tools or external flashers </li></ul></ul>
    32. 32. Cross-compiler Environments <ul><li>Integrated development environments (IDEs)‏ </li></ul><ul><ul><li>Commercial compilers are usually of this type </li></ul></ul><ul><ul><li>Usually dependent on a specific OS (Windows)‏ </li></ul></ul><ul><ul><li>Integrate a text editor, compiler tools and project management along with C library </li></ul></ul><ul><ul><li>System programmer tool usually tightly integrated </li></ul></ul><ul><ul><li>Also open-source IDEs available </li></ul></ul><ul><ul><ul><li>Open-source IDEs usually employ “plugin” architecture </li></ul></ul></ul><ul><ul><ul><li>General-purpose extensible environments </li></ul></ul></ul><ul><ul><ul><li>Include scripting tools for running any command line tools: compilers, linkers, external editors and programmers </li></ul></ul></ul><ul><ul><ul><li>Example: Eclipse (implemented in Java) </li></ul></ul></ul>
    33. 33. Cross-compiler Environments <ul><li>Command line utilities </li></ul><ul><ul><li>Separate compiler/linker, editor and project management tools, architecture-dependent C library </li></ul></ul><ul><li>Project management: make </li></ul><ul><ul><li>make is an automated software building tool </li></ul></ul><ul><ul><li>Based on target-dependency-operation style blocks </li></ul></ul><ul><ul><li>Allows use of project templates and separate platform build rules by using “include files” </li></ul></ul><ul><ul><li>Most common way of managing open-source software projects </li></ul></ul><ul><ul><li>automake and autoconf tools extend functionality to platform-independent software development </li></ul></ul>
    34. 34. Cross-compiler Environments <ul><li>Command line compilers </li></ul><ul><ul><li>most common is gcc: available for a multitude of microcontroller and -processor architectures </li></ul></ul><ul><ul><li>sdcc: Small Device C Compiler: PICs, 8051's etc. </li></ul></ul><ul><ul><li>single-architecture compilers </li></ul></ul><ul><li>System programming tools </li></ul><ul><ul><li>usually specific to a single microcontroller family </li></ul></ul><ul><ul><li>vary greatly in their ease of use and interface type </li></ul></ul><ul><ul><li>most require some sort of programming cable or a programmer device to upload software </li></ul></ul><ul><ul><li>dependent on the microcontroller programming algorithm </li></ul></ul><ul><ul><ul><li>standard buses (SPI, UART, JTAG) vs. proprietary buses </li></ul></ul></ul>
    35. 35. Cross-compiler Environments <ul><li>Command-line tools vs. (commercial) IDEs </li></ul><ul><ul><li>IDEs are easily accessible: single installer, single GUI </li></ul></ul><ul><ul><li>Commercial IDEs vary greatly in usability, standards compliance and are (usually) tied to a single architecture -> bad portability </li></ul></ul><ul><ul><li>Most commercial IDEs don't really support templates </li></ul></ul><ul><ul><ul><li>Programmer must go through various dialogs to create a new project </li></ul></ul></ul><ul><ul><ul><li>Often project files can not just be copied (contain directory paths and such) and may be binary format </li></ul></ul></ul><ul><ul><li>Command line tools have a steeper learning curve </li></ul></ul><ul><ul><ul><li>Once learned, applicable to most architectures </li></ul></ul></ul><ul><ul><ul><li>Higher flexibility and ease of duplicating projects </li></ul></ul></ul>
    36. 36. Cross-compiler Issues <ul><li>Portability </li></ul><ul><ul><li>Header files may not follow standard naming </li></ul></ul><ul><ul><li>Hardware-specific header files might not be automatically selected </li></ul></ul><ul><ul><ul><li>Most commercial IDEs use different names for each different hardware model -> difficulties in portability </li></ul></ul></ul><ul><ul><ul><li>gcc e.g. uses internal macros for model selection -> easier portability via environment variables, no header changes </li></ul></ul></ul><ul><li>Hardware register access and interrupt handlers </li></ul><ul><ul><li>Interrupt handler declaration is compiler-dependent </li></ul></ul><ul><ul><ul><li>Declaration format is not standardized </li></ul></ul></ul><ul><ul><ul><li>Can be worked around via macros (in most cases)‏ </li></ul></ul></ul><ul><ul><li>Some compilers (and C libraries) require I/O macros </li></ul></ul><ul><ul><ul><li>gcc ports implement direct register access modes </li></ul></ul></ul>
    37. 37. Open-source Tools <ul><li>Various text editors available: nedit, emacs, vi ... </li></ul><ul><li>Project build system: make </li></ul><ul><li>Compilers/linkers: binutils & gcc, sdcc </li></ul><ul><ul><li>binutils: as, ld, objcopy, size etc. </li></ul></ul><ul><ul><li>gcc: c compiler; uses binutils to create binary files </li></ul></ul><ul><li>Standard C libraries </li></ul><ul><ul><li>Provide necessary development headers and object files for linking and memory mapping </li></ul></ul><ul><ul><li>msp430-libc for MSP430, avr-libc for AVR </li></ul></ul><ul><li>Programmers </li></ul><ul><ul><li>AVR: uisp, avrdude </li></ul></ul><ul><ul><li>MSP430: msp430-bsl, msp430-jtag </li></ul></ul><ul><ul><li>CC2430: nano_programmer </li></ul></ul><ul><li>IDE: Eclipse </li></ul>
    38. 38. SDCC Compiler <ul><li>Simple Device C Compiler </li></ul><ul><li>http://www.sdcc.org </li></ul><ul><li>Specialized in 8051, PIC, HC08 etc. microcontrollers </li></ul><ul><ul><li>Has CC2430 and CC2510 support </li></ul></ul><ul><li>sdcc application handles both compilation and linking </li></ul><ul><li>Uses make build environment </li></ul><ul><li>Compatible with Eclipse </li></ul><ul><li>Support for banking (needed in 8051 with 64k+ ROM) </li></ul><ul><ul><li>Thanks to Peter Kuhar for banking support </li></ul></ul>
    39. 39. 6LoWPAN Implementation Issues
    40. 40. Chip Models <ul><li>How to integrate 6LoPWAN into an embedded device? </li></ul><ul><li>Challenges: </li></ul><ul><ul><li>Lack of standard interfaces (no USB or PCMCIA) </li></ul></ul><ul><ul><li>No standard operating systems (if any!) </li></ul></ul><ul><ul><li>Power consumption limitations </li></ul></ul><ul><ul><li>Price limitations </li></ul></ul><ul><li>Models for integrating 6LoWPAN include SoC, two-chip or network processor </li></ul><ul><li>System-on-a-chip model </li></ul><ul><ul><li>Everything on one chip </li></ul></ul><ul><ul><ul><li>+ Maximum integration </li></ul></ul></ul><ul><ul><ul><li>+ Minimum price and size </li></ul></ul></ul><ul><ul><ul><li>- Longer, more difficult development </li></ul></ul></ul><ul><ul><ul><li>- Little if any portability </li></ul></ul></ul>
    41. 41. Chip Models <ul><li>Two-chip solution </li></ul><ul><ul><li>Separate radio transceiver </li></ul></ul><ul><ul><ul><li>+ Free choice of uC </li></ul></ul></ul><ul><ul><ul><li>+ More portability </li></ul></ul></ul><ul><ul><ul><li>- More expensive </li></ul></ul></ul><ul><ul><ul><li>- App integration with stack </li></ul></ul></ul><ul><li>Network processor solution </li></ul><ul><ul><li>Network stack on the radio </li></ul></ul><ul><ul><ul><li>+ Free choice of uC </li></ul></ul></ul><ul><ul><ul><li>+ Application independent of </li></ul></ul></ul><ul><ul><ul><li>the stack </li></ul></ul></ul><ul><ul><ul><li>+ Easy integration </li></ul></ul></ul><ul><ul><ul><li>- More expensive </li></ul></ul></ul>
    42. 42. Contiki uIPv6 <ul><li>Popular embedded OS for small microcontrollers </li></ul><ul><ul><li>MSP430, AVR, PIC, 8051 etc. </li></ul></ul><ul><li>http://www.sics.se/contiki </li></ul><ul><li>Standard C-based </li></ul><ul><li>Portable applications </li></ul><ul><li>Lightweight protothreads </li></ul><ul><li>uIPv6 Stack </li></ul><ul><ul><li>Full IPv6 support </li></ul></ul><ul><ul><li>RFC4944 + 6lowpan-hc </li></ul></ul><ul><ul><li>UDP, TCP, ICMPv6 </li></ul></ul><ul><li>Great for research </li></ul>
    43. 43. <ul><li>Sensinode’s commercial 6LoWPAN stack </li></ul><ul><li>Network processor model </li></ul><ul><ul><li>NAP interface over UART </li></ul></ul><ul><li>Optimized for SoC radios </li></ul><ul><ul><li>TI CC2430, CC2530 </li></ul></ul><ul><ul><li>TI CC1110 </li></ul></ul><ul><ul><li>Portable </li></ul></ul><ul><li>IPv6/6LoWPAN stack </li></ul><ul><ul><li>UDP, ICMPv6 </li></ul></ul><ul><ul><li>RFC4944, 6lowpan-hc </li></ul></ul><ul><ul><li>6lowpan-nd </li></ul></ul><ul><ul><li>NanoMesh IP routing </li></ul></ul>NanoStack 2.0
    44. 44. Router Integration <ul><li>Edge Routers interconnect the </li></ul><ul><li>IPv6 world and 6LoWPAN </li></ul><ul><li>An ER needs to implement: </li></ul><ul><ul><li>6LoWPAN interface(s) </li></ul></ul><ul><ul><li>6LoWPAN adaptation </li></ul></ul><ul><ul><li>Simple 6LoWPAN-ND </li></ul></ul><ul><ul><li>A full IPv6 protocol stack </li></ul></ul><ul><li>Other typical features include: </li></ul><ul><ul><li>IPv4 support and tunneling </li></ul></ul><ul><ul><li>Application proxy techniques </li></ul></ul><ul><ul><li>Extended LoWPAN support </li></ul></ul><ul><ul><li>A firewall </li></ul></ul><ul><ul><li>Management </li></ul></ul>
    45. 45. Example Exercise Hardware
    46. 46. Exercise Hardware <ul><li>NanoRouter USB 2.4GHz </li></ul><ul><ul><li>Serial USB device </li></ul></ul><ul><ul><li>NanoStack 2.0 </li></ul></ul><ul><ul><li>High-power amplifier </li></ul></ul><ul><li>NanoSensor 2.4GHz </li></ul><ul><ul><li>Demo sensor node </li></ul></ul><ul><ul><li>Rechargeable batteries </li></ul></ul><ul><ul><li>3-axis accelerometer </li></ul></ul><ul><ul><li>Light sensor </li></ul></ul><ul><ul><li>D-connector for external sensors </li></ul></ul><ul><li>Support for either NanoStack or Contiki </li></ul>
    47. 47. NanoSensor D-connector <ul><li>Standard 9-pin D-connector for sensor expansion </li></ul><ul><li>D-connector pin-out: </li></ul><ul><ul><ul><li>1 = 3.3V in/out </li></ul></ul></ul><ul><ul><ul><li>2 = Digital I/O or programmer connection </li></ul></ul></ul><ul><ul><ul><li>3 = Analog switch control. 1=external I/O in use </li></ul></ul></ul><ul><ul><ul><li>4 = Reset </li></ul></ul></ul><ul><ul><ul><li>5 = Ground </li></ul></ul></ul><ul><ul><ul><li>6 = A/D (Digital I/O). P0_0 </li></ul></ul></ul><ul><ul><ul><li>7 = Digital I/O (P2_1) or programming connection </li></ul></ul></ul><ul><ul><ul><li>8 = UART out (from RC module) </li></ul></ul></ul><ul><ul><ul><li>9 = UART in (to RC module) </li></ul></ul></ul>
    48. 48. Contiki
    49. 49. What is Contiki? <ul><li>Contiki is an open-source operating system/protocol stack for embedded systems </li></ul><ul><li>Highly portable and reasonably compact </li></ul><ul><li>Protocol stack configuration customizable </li></ul><ul><li>Originally created by Adam Dunkels, developer of the uIP stack </li></ul><ul><li>http://www. sics . se/contiki </li></ul>
    50. 50. Contiki processes <ul><li>Contiki core is event-driven </li></ul><ul><ul><li>Interrupts and HW drivers generate events </li></ul></ul><ul><ul><li>Events are dispatched to event handlers by the Contiki core </li></ul></ul><ul><ul><li>Event handlers must return control to core as soon as possible </li></ul></ul><ul><ul><li>Co-operative multitasking </li></ul></ul><ul><li>Basic processes are implemented using protothreads </li></ul><ul><ul><li>Easier to create sequential operations </li></ul></ul><ul><ul><li>An abstraction to avoid complex state-machine programming </li></ul></ul><ul><ul><ul><li>In more complex applications, the amount of states may be huge </li></ul></ul></ul>
    51. 51. Contiki execution models <ul><li>Contiki offers multiple execution models </li></ul><ul><li>Protothreads: thread-like event handlers </li></ul><ul><ul><li>Allow thread-like structures without the requirement of additional stacks </li></ul></ul><ul><ul><li>Limits process structure: no switch/case structures allowed </li></ul></ul><ul><ul><li>May not use local variables </li></ul></ul><ul><li>Multi-threading model available </li></ul><ul><ul><li>For more powerful systems </li></ul></ul><ul><ul><li>Allows structured application design </li></ul></ul>
    52. 52. Contiki processes <ul><li>Contiki core is event-driven </li></ul><ul><ul><li>Interrupts and HW drivers generate events </li></ul></ul><ul><ul><li>Events are dispatched to event handlers by the Contiki core </li></ul></ul><ul><ul><li>Event handlers must return control to core as soon as possible </li></ul></ul><ul><ul><li>Co-operative multitasking </li></ul></ul><ul><li>Basic processes are implemented using protothreads </li></ul><ul><ul><li>Easier to create sequential operations </li></ul></ul><ul><ul><li>An abstraction to avoid complex state-machine programming </li></ul></ul><ul><ul><ul><li>In more complex applications, the amount of states may be huge </li></ul></ul></ul>
    53. 53. Contiki processes: An example <ul><li>/* Declare the process */ </li></ul><ul><li>PROCESS(hello_world_process, “Hello world”); </li></ul><ul><li>/* Make the process start when the module is loaded */ </li></ul><ul><li>AUTOSTART_PROCESSES(&hello_world_process); </li></ul><ul><li>/* Define the process code */ </li></ul><ul><li>PROCESS_THREAD(hello_world_process, ev, data) { </li></ul><ul><li>PROCESS_BEGIN(); /* Must always come first */ </li></ul><ul><li>printf(“Hello, world! ”); /* Initialization code goes here */ </li></ul><ul><li>while(1) { /* Loop for ever */ </li></ul><ul><li>PROCESS_WAIT_EVENT(); /* Wait for something to happen */ </li></ul><ul><li>} </li></ul><ul><li>PROCESS_END(); /* Must always come last */ </li></ul><ul><li>} </li></ul>
    54. 54. Contiki processes: Notes <ul><li>A process may not use switch-case constructs </li></ul><ul><ul><li>A limitation of the protothread model </li></ul></ul><ul><ul><li>Complex state structures and switches should be subroutines </li></ul></ul><ul><li>A process may not declare local variables </li></ul><ul><ul><li>Variables will lose their values at any event waiting call </li></ul></ul><ul><ul><li>All variables required by the main process must be static </li></ul></ul><ul><li>Effects on application design </li></ul><ul><ul><li>The main process thread should only contain sequences between event waits </li></ul></ul><ul><ul><li>All operations should be done in subroutines </li></ul></ul>
    55. 55. Contiki events <ul><li>process_post(&process, eventno, evdata); </li></ul><ul><ul><li>Process will be invoked later </li></ul></ul><ul><li>process_post_synch(&process, evno, evdata); </li></ul><ul><ul><li>Process will be invoked now </li></ul></ul><ul><ul><li>Must not be called from an interrupt (device driver) </li></ul></ul><ul><li>process_poll(&process); </li></ul><ul><ul><li>Sends a PROCESS_EVENT_POLL event to the process </li></ul></ul><ul><ul><li>Can be called from an interrupt </li></ul></ul><ul><li>Using events </li></ul><ul><li>PROCESS_THREAD(rf_test_process, ev, data) { </li></ul><ul><li>while(1) { </li></ul><ul><li>PROCESS_WAIT_EVENT(); </li></ul><ul><li>if (ev == EVENT_PRINT) printf(“%s”, data); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
    56. 56. Contiki timers <ul><li>Contiki has two main timer types; etimer and rtimer </li></ul><ul><li>Etimer: generates timed events </li></ul><ul><li>Declarations: </li></ul><ul><li>static struct etimer et; </li></ul><ul><li>In main process: </li></ul><ul><li>while(1) { </li></ul><ul><li>etimer_set(&et, CLOCK_SECOND); </li></ul><ul><li>PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); </li></ul><ul><li>etimer_reset(&et); </li></ul><ul><li>} </li></ul><ul><li>Rtimer: uses callback function </li></ul><ul><ul><li>Callback executed after specified time </li></ul></ul><ul><li>rtimer_set(&rt, time, 0 , &callback_function, void *argument); </li></ul>
    57. 57. Contiki Protocol Stacks <ul><li>Contiki has 2 different protocol stacks: uIP and Rime </li></ul><ul><li>uIP provides a full TCP/IP stack </li></ul><ul><ul><li>For interfaces that allow protocol overhead </li></ul></ul><ul><ul><li>Ethernet devices </li></ul></ul><ul><ul><li>Serial line IP </li></ul></ul><ul><ul><li>Includes IPv4 and IPv6/6LoWPAN support </li></ul></ul><ul><li>Rime provides compressed header support </li></ul><ul><ul><li>Application may use MAC layer only </li></ul></ul><ul><li>Protocol stacks may be interconnected </li></ul><ul><ul><li>uIP data can be transmitted over Rime and vice versa </li></ul></ul>
    58. 58. The Rime protocol stack <ul><li>Separate modules for protocol parsing and state machines </li></ul><ul><ul><li>Rime contains the protocol operation modules </li></ul></ul><ul><ul><li>Chameleon contains protocol parsing modules </li></ul></ul><ul><li>Rime startup: an example </li></ul><ul><ul><li>Configure Rime to use sicslowmac over cc2430 rf </li></ul></ul><ul><ul><li>Startup is done in platform main function: platform/sensinode/contiki-sensinode-main.c </li></ul></ul><ul><li>rime_init(sicslowmac_init(&cc2430_rf_driver)); </li></ul><ul><li>set_rime_addr(); //this function reads MAC from flash and places </li></ul><ul><li>//it to Rime address </li></ul>
    59. 59. Rime: Receiving <ul><li>Setting up Rime receiving: broadcast </li></ul><ul><ul><li>Set up a callback function </li></ul></ul><ul><li>Declarations: </li></ul><ul><li>static struct broadcast_conn bc; </li></ul><ul><li>static const struct broadcast_callbacks broadcast_callbacks = {recv_bc}; </li></ul><ul><li>The callback definition: </li></ul><ul><li>static void </li></ul><ul><li>recv_bc(struct broadcast_conn *c, rimeaddr_t *from); </li></ul><ul><li>In main process: </li></ul><ul><li>broadcast_open(&bc, 128, &broadcast_callbacks); </li></ul><ul><li>Unicast receive in a similar manner </li></ul>
    60. 60. Rime: Sending <ul><li>Sending broadcast data using Rime </li></ul><ul><li>Declarations: </li></ul><ul><li>static struct broadcast_conn bc; </li></ul><ul><li>In main process: </li></ul><ul><li>packetbuf_copyfrom(&quot;Hello everyone&quot;, 14); </li></ul><ul><li>broadcast_send(&bc); </li></ul><ul><li>Sending unicast data using Rime </li></ul><ul><li>Declarations: </li></ul><ul><li>static struct unicast_conn uc; </li></ul><ul><li>In your function: </li></ul><ul><li>rimeaddr_t *addr; </li></ul><ul><li>addr.u8[0] = first_address_byte; </li></ul><ul><li>addr.u8[1] = second_address_byte; </li></ul><ul><li>packetbuf_copyfrom(&quot;Hello you&quot;, 9); </li></ul><ul><li>unicast_send(&uc, &addr); </li></ul>
    61. 61. Creating Contiki Ports <ul><li>First step: see if your cpu already has code </li></ul><ul><ul><li>If yes, configure your platform to use it </li></ul></ul><ul><ul><li>If not, see other cpu directories for implementation models </li></ul></ul><ul><li>Second step: see if your hardware is close to other platforms </li></ul><ul><ul><li>If yes, copy code from example platform and modify </li></ul></ul><ul><ul><li>If not, see other platforms for minimal model </li></ul></ul><ul><li>Create a test application </li></ul><ul><ul><li>Start with LEDs in platform/myplatform/contiki-myplatform-main.c </li></ul></ul><ul><ul><li>Use for loops to make sure that your compiler works </li></ul></ul><ul><ul><li>Continue by adding printf's to see if your UART works </li></ul></ul><ul><li>First real application </li></ul><ul><ul><li>Create an etimer for your test process: flash LEDs, print info </li></ul></ul><ul><ul><li>Try different timeouts to see if your clocks are correct </li></ul></ul><ul><li>Add more drivers and try them out </li></ul>
    62. 62. Exercises
    63. 63. Contiki Basics <ul><li>Create your own Contiki “Hello World” application using /examples/sensinode as an example. Compile and run it on the CC2430 target platform </li></ul><ul><li>Create two parallel Contiki processes, each controlling a different LED </li></ul>
    64. 64. Contiki Advanced <ul><li>Use an etimer to set a timer event for your own process after a certain period (for example to flash a LED). </li></ul><ul><li>Make two processes, and use process events between them. </li></ul><ul><li>Make a Contiki application to read the NanoSensor accelerometer and light sensors using the ADC on the CC2430. Convert the values using the sensor data sheets and print them out periodically. </li></ul><ul><li>Make Contiki sensor libraries for the NanoSensor buttons and sensors (using code from above) and use them to print events. </li></ul>
    65. 65. Contiki uIP <ul><li>Make an application which uses uIP protosockets, and spawns protothreads to handle both UDP and TCP sockets. </li></ul><ul><li>Make a client application and a server application which communicate between each other over UDP. </li></ul><ul><li>Design a publish/subscribe protocol implementation over UDP/6LoWPAN using the MQTT-S specification (simplified). Implement Publisher, Subscriber and Broker applications. </li></ul><ul><li>Use MQTT-S to publish and subscribe to NanoSensor buttons and sensor values. </li></ul>

    ×