1 / 21

Operating Systems for Sensor Nodes

Operating Systems for Sensor Nodes. Chih-Chieh Han Simonhan@ee.ucla.edu. Embedded Software Development. Cross-compiler A compiler which runs on one platform and produces code for another. Javac: compile java source into java bytecode Avr-gcc: compile C source into avr instructions

Télécharger la présentation

Operating Systems for Sensor Nodes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Operating Systems for Sensor Nodes Chih-Chieh Han Simonhan@ee.ucla.edu

  2. Embedded Software Development • Cross-compiler • A compiler which runs on one platform and produces code for another. • Javac: compile java source into java bytecode • Avr-gcc: compile C source into avr instructions • Tool-chain • Compiler + binutils (linker, assembler) + libraries. • Development cycle • Coding • Cross-compile • Upload binary • Testing

  3. sensors actuators storage network Characteristics of Network Sensors • Small physical size and low power consumption • Concurrency-intensive operation • multiple flows, not wait-command-respond • Limited Physical Parallelism and Controller Hierarchy • primitive direct-to-device interface • Asynchronous and synchronous devices • Diversity in Design and Usage • application specific, not general purpose • huge device variation => efficient modularity => migration across HW/SW boundary • Robust Operation • numerous, unattended, critical => narrow interfaces

  4. msg_rec(type, data) msg_send_done) Tiny OS Concepts • Scheduler + Graph of Components • constrained two-level scheduling model: threads + events • Component: • Commands, • Event Handlers • Frame (storage) • Tasks (concurrency) • Constrained Storage Model • frame per component, shared stack, no heap • Very lean multithreading • Efficient Layering Events Commands send_msg(addr, type, data) power(mode) init Messaging Component internal thread Internal State TX_packet(buf) Power(mode) TX_packet_done (success) init RX_packet_done (buffer)

  5. Application = Graph of Components Route map router sensor appln application Active Messages Serial Packet Radio Packet packet Temp photo SW Example: ad hoc, multi-hop routing of photo sensor readings HW UART Radio byte ADC byte 3450 B code 226 B data clocks RFM bit Graph of cooperating state machines on shared stack

  6. Programming TinyOS • TinyOS 1.0 is written in an extension of C, called nesC • Applications are too! • just additional components composed with the OS components • Provides syntax for TinyOS concurrency and storage model • commands, events, tasks • local frame variable • Rich Compositional Support • separation of definition and linkage • robustness through narrow interfaces and reuse • interpositioning • Whole system analysis and optimization

  7. Event-Driven Sensor Access Pattern command result_t StdControl.start() { return call Timer.start(TIMER_REPEAT, 200); } event result_t Timer.fired() { return call sensor.getData(); } event result_t sensor.dataReady(uint16_t data) { display(data) return SUCCESS; } • clock event handler initiates data collection • sensor signals data ready event • data event handler calls output command • device sleeps or handles other activity while waiting • conservative send/ack at component boundary SENSE LED Photo Timer

  8. { ... status = call CmdName(args) ... } command CmdName(args) { ... return status; } event EvtName)(args) { ... return status; } { ... status = signal EvtName(args) ... } TinyOS Commands and Events

  9. Tasks events commands Interrupts Hardware TinyOS Execution Contexts • Events generated by interrupts preempt tasks • Tasks do not preempt tasks • Both essential process state transitions

  10. TASKS • provide concurrency internal to a component • longer running operations • are preempted by events • able to perform operations beyond event context • may call commands • may signal events • not preempted by tasks { ... post TskName(); ... } task void TskName { ... }

  11. Components A component specifies a set of interfaces by which it is connected to other components • provides a set of interfaces to others • uses a set of interfaces provided by others • Modules • provide code that implements one or more interfaces and internal behavior • Configurations • link together components to yield new component • Interface • logically related set of commands and events • Interfaces are bi-directional (include commands and events)

  12. provides StdControl Timer Component Leds Clock uses Example Application: Blink module BlinkM { provides { interface StdControl; } uses { interface Clock; interface Leds; } } // Continued next page Clock.nc interface Clock { event result_t fire(); command result_t setRate(char interval, char scale); } StdControl.nc interface StdControl { command result_t init(); command result_t start(); command result_t stop(); }

  13. Module implementation implementation { bool state; command result_t StdControl.init() { state = FALSE; return SUCCESS; } command result_t StdControl.start() { return call Clock.setRate(TOS_I1PS, TOS_S1PS); } command result_t StdControl.stop() { return call Clock.setRate(TOS_I0PS, TOS_S0PS); } event result_t Clock.fire() { state = !state; if (state) call Leds.redOn(); else call Leds.redOff(); return SUCCESS; } }

  14. Main StdControl Blink LedsC ClockC Leds Clock Top level configuration • Configuration wires all components together • Arrows bind interfaces (on the left) to implementation (on the right) configuration Blink { // this module does not provide any interface } implementation { components Main, BlinkM, ClockC, LedsC; Main.StdControl -> BlinkM.StdControl; BlinkM.Clock -> ClockC.Clock; BlinkM.Leds -> LedsC.Leds; }

  15. Compiling, Installing and Running • Compiling: % make mica • Installing: % make mica install • Running: % Live Demo!

  16. PALOS • TinyOS drawbacks • A brand new programming language • No notion of traditional task • PALOS • Written in standard C. • Multi-tasking (Event-Driven) • Each tasks is a routine which processes events that are stored in event queues • Supports Inter-task Communication • By queuing events to other tasks, the data between tasks can be exchanged • Flexible event handling • Handle multiple events or partial events

  17. PALOS Tasks • A task belongs to the palos main control loop • Each task has an entry in palos task table (along with eventQs)

  18. Inter-task Communication • Events are exchanged using the service provided by PALOS core

  19. PALOS example: Blink Task UCHAR myID; StopWatch_Event eventQ[EVENTQ_SIZE]; CHAR Blink(void *ev) { StopWatch_Event *event = (StopWatch_Event *)ev; switch(event->timerID) { case(1): redToggle(); break; case(2): yellowToggle(); StopWatch_Start(myID, 2, TIMER_ONE_SHOT, 5000); break; } return PALOSTASK_DONE; }

  20. PALOS example: Blink Task void globalInitTask(){ SYS_Init(); UART0_Init(); LED_INIT; printf("init\r\n"); myID = palosTask_register(StopWatch_Init, Blink, 0, 0, 0, false, sizeof(StopWatch_Event), EVENTQ_SIZE, (void *)eventQ); } void globalInitSched() { StopWatch_Start(myID, 1, TIMER_REPEAT, 1000); StopWatch_Start(myID, 2, TIMER_ONE_SHOT, 5000); }

  21. References • http://www.tinyos.net/tos/ • http://sourceforge.net/projects/tinyos/ • http://sourceforge.net/projects/palos/

More Related