Embedded Network Programming

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