Embedded Network Programming nes C Tiny OS Networking
Embedded Network Programming nes. C, Tiny. OS, Networking, Microcontrollers Jonathan Hui University of California, Berkeley 2008 EECS 194 -5 1
Outline • Quick overview of – Microcontrollers – Tiny. OS • Lab – – 2008 nes. C Programming Language Embedded sockets interface Sensor/actuator drivers Texas Instruments MSP 430 EECS 194 -5 2
Computer Systems • Traditional systems: separate chips • Microcontroller: integrate on single chip Mote MCU CPU Timer Network Peripherals Memory 2008 EECS 194 -5 Storage 3
Microcontrollers 48 K ROM 10 K RAM 250 kbps 2008 EECS 194 -5 4
Mote Characteristics • Limited resources – RAM, ROM, Computation, Energy Wakeup, do work as quickly as possible, sleep • Hardware modules operate concurrently – No parallel execution of code (not Core 2 Duos!) Asynchronous operation is first class • Diverse application requirements Efficient modularity • Robust operation – Numerous, unattended, critical Predictable operation 2008 EECS 194 -5 5
Tiny. OS Basics • What is an OS? – Manages sharing of resources (hardware and software) – Interface to access those resources • Tiny. OS Basics Web Server – System Graph of components – Components • Provides interfaces • Uses interfaces Network – Interfaces • Commands • Events Link 2008 EECS 194 -5 6
Tiny. OS IPv 6 Network Kernel • Network Kernel – Manages communication and storage – Scheduler (decides when to signal events) Application IPv 6 Network Kernel Radio 2008 Timer Flash EECS 194 -5 Driver Driver Sensors Sensor Actuator 7
Event-Based Execution • All execution occurs in event handlers – Events do not preempt each other • Commands – Get information from underlying components • Get current time – Configure underlying components • Start timer (will cause a future event) • Bind socket to a port – Helper functions • Format an IPv 6 address 2008 EECS 194 -5 8
Example Flow • event void Boot. booted() { call Timer. start. Periodic(100); } Event: Boot – Command: Start timer • event void Timer. fired() { call Udp. sendto(buf, len, &to); } Event: Timer fired – Command: Send message • event void Udp. recvfrom(void *buf, uint 16_t len, sockaddr_in 6_t *from) { call Leds. led 0 Toggle(); } Event: Message received – Command: Toggle an LED Toggle LED 2008 Send Msg Start Timer System Init … Sleep … Radio Transmit … Sleep … EECS 194 -5 Radio Receive 9
What’s Happening Underneath? • MCU hardware modules operate concurrently Must handle events in a timely manner • Hardware events preempt application events – Allows system to operate asynchronously from app – Tasks are used to signal application events – Kernel scheduler executes tasks one-by-one … Sleep … Radio Transmit … Sleep … EECS 194 -5 Toggle LED 2008 Send Msg Start Timer System Init = HW Timer Overflow Radio Receive 10
That’s a Start • We’ll learn lots more in lab! 2008 EECS 194 -5 11
- Slides: 11