2008EECS Embedded Network Programming nesC, TinyOS, Networking, Microcontrollers Jonathan Hui University of California, Berkeley
2008EECS Outline Quick overview of –Microcontrollers –TinyOS Lab –nesC Programming Language –Embedded sockets interface –Sensor/actuator drivers –Texas Instruments MSP430
2008EECS Mote MCU Computer Systems Traditional systems: separate chips Microcontroller: integrate on single chip Timer MemoryStorage CPU Peripherals Network
2008EECS Microcontrollers 48K ROM 10K RAM 250 kbps
2008EECS 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
2008EECS TinyOS Basics What is an OS? –Manages sharing of resources (hardware and software) –Interface to access those resources TinyOS Basics –System Graph of components –Components Provides interfaces Uses interfaces –Interfaces Commands Events Network Link Web Server
2008EECS TinyOS IPv6 Network Kernel Actuator Sensors TimerFlashRadioSensorActuator Network Kernel –Manages communication and storage –Scheduler (decides when to signal events) IPv6 Network Kernel Driver Application
2008EECS 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 IPv6 address
2008EECS Example Flow Event: Boot –Command: Start timer Event: Timer fired –Command: Send message Event: Message received –Command: Toggle an LED event void Boot.booted() { call Timer.startPeriodic(100); } event void Timer.fired() { call Udp.sendto(buf, len, &to); } event void Udp.recvfrom(void *buf, uint16_t len, sockaddr_in6_t *from) { call Leds.led0Toggle(); } Start Timer System Init … Sleep … Send Msg Radio Transmit … Sleep … Radio Receive Toggle LED
2008EECS 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 Start Timer System Init … Sleep … Send Msg Radio Transmit … Sleep … Radio Receive Toggle LED = HW Timer Overflow
2008EECS That’s a Start We’ll learn lots more in lab!