Embedded OS Case Study: TinyOS

Size: px
Start display at page:

Download "Embedded OS Case Study: TinyOS"

Transcription

1 Embedded OS Case Study: TinyOS Open-source development environment Simple (and tiny) operating system TinyOS Programming language and model nesc Set of services Principal elements Scheduler/event model of concurrency Software components for efficient modularity Software encapsulation for resources of sensor networks CSE Winter 2007 Case Study: TinyOS 1

2 TinyOS History Motivation create Unix analog (circa 1969) Uniform programming language: C Uniform device abstractions Open source: grow with different developers/needs Support creation of many tools Created at UC Berkeley 1st version written by Jason Hill in 2000 Large part of development moved to Intel Research Berkeley in Smart Dust, Inc. founded in 2002 Large deployments Great Duck Island (GDI) Center for Embedded Network Sensing (CENS) CSE Winter 2007 Case Study: TinyOS 2

3 TinyOS Design Goals Support networked embedded systems Asleep most of the time, but remain vigilant to stimuli Bursts of events and operations Support UCB mote hardware Power, sensing, computation, communication Easy to port to evolving platforms Support technological advances Keep scaling down Smaller, cheaper, lower power CSE Winter 2007 Case Study: TinyOS 3

4 TinyOS Design Options Can t use existing RTOS s Microkernel architecture VxWorks, PocketPC, PalmOS Execution similar to desktop systems PDA s, cell phones, embedded PC s More than a order of magnitude too heavyweight and slow Energy hogs CSE Winter 2007 Case Study: TinyOS 4

5 TinyOS Design Conclusion Similar to building networking interfaces Data driven execution Manage large # of concurrent data flows Manage large # of outstanding events Add: managing application data processing Conclusion: need a multi-threading engine Extremely efficient Extremely simple CSE Winter 2007 Case Study: TinyOS 5

6 TinyOS Kernel Design Two-level scheduling structure Events Small amount of processing to be done in a timely manner E.g. timer, ADC interrupts Can interrupt longer running tasks Tasks Not time critical Larger amount of processing E.g. computing the average of a set of readings in an array Run to completion with respect to other tasks Only need a single stack CSE Winter 2007 Case Study: TinyOS 6

7 TinyOS Concurrency Model Tasks FIFO queue Interrupts Two-level of concurrency: tasks and interrupts CSE Winter 2007 Case Study: TinyOS 7

8 TinyOS Concurrency Model (cont d) Tasks FIFO queue Placed on queue by: Application Other tasks Self-queued Interrupt service routine Run-to-completion No other tasks can run until completed Interruptable, but any new tasks go to end of queue Interrupts Stop running task Post new tasks to queue CSE Winter 2007 Case Study: TinyOS 8

9 TinyOS Concurrency Model (cont d) Two-levels of concurrency Possible conflicts between interrupts and tasks Atomic statements atomic Asynchronous service routines (as opposed to synchronous tasks) Race conditions detected by compiler Can generated false positives CSE Winter 2007 Case Study: TinyOS 9

10 TinyOS Programming Model Separation of construction and composition Programs are built out of components Specification of component behavior in terms of a set of interfaces Components specify interfaces they use and provide Components are statically wired to each other via their interfaces This increases runtime efficiency by enabling compiler optimizations Finite-state-machine-like specifications Thread of control passes into a component through its interfaces to another component CSE Winter 2007 Case Study: TinyOS 10

11 TinyOS Basic Constructs Commands Events Cause action to be initiated Notify action has occurred Generated by external interrupts Call back to provide results from previous command Tasks Background computation Not time critical Application event command Component event command Hardware Interface task task task CSE Winter 2007 Case Study: TinyOS 11

12 Flow of Events and Commands Fountain of events leading to commands and tasks (which in turn issue may issue other commands that may cause other events, ) task to get out of async tasks events commands interrupts Software Hardware CSE Winter 2007 Case Study: TinyOS 12

13 TinyOS File Types Interfaces (xxx.nc) Specifies functionality to outside world what commands can be called what events need handling Module (xxxm.nc) Code implementation Code for Interface functions Configuration (xxxc.nc) Wiring of components When top level app, drop C from filename xxx.nc interfacea.nc comp1c.nc (wires) interfaceb.nc main.nc interfacem.nc interfacem.nc app.nc (wires) interfacea.nc interfacea.nc comp2m.nc (code) interfaceb.nc comp3m.nc (code) CSE Winter 2007 Case Study: TinyOS 13

14 The nesc Language nesc: networks of embedded sensors C Compiler for applications that run on UCB motes Built on top of avg-gcc nesc uses the filename extension ".nc Static Language No dynamic memory (no malloc) No function pointers No heap Influenced by Java Includes task FIFO scheduler Designed to foster code reuse Modules per application range from 8 to 67, mean of 24*** Average lines of code in a module only 120*** Advantages of eliminating monolithic programs Code can be reused more easily Number of errors should decrease TinyOS kernel (C) TinyOS libs (nesc) Application (nesc) nesc Compiler Application & TinyOS (C) C Compiler Application Executable ***The NesC Language: A Holistic Approach to Network of Embedded Systems. David Gay, Phil Levis, Rob von Behren, Matt Welsh, Eric Brewer, and David Culler. Proceedings of Programming Language Design and Implementation (PLDI) 2003, June CSE Winter 2007 Case Study: TinyOS 14

15 Commands Commands are issued with call call Timer.start(TIMER_REPEAT, 1000); Cause action to be initiated Bounded amount of work Does not block Act similarly to a function call Execution of a command is immediate CSE Winter 2007 Case Study: TinyOS 15

16 Events Events are called with signal signal ByteComm.txByteReady(SUCCESS); Used to notify a component an action has occurred Lowest-level events triggered by hardware interrupts Bounded amount of work Do not block Act similarly to a function call Execution of a event is immediate CSE Winter 2007 Case Study: TinyOS 16

17 Tasks Tasks are queued with post post radioencodethread(); Used for longer running operations Pre-empted by events Initiated by interrupts Tasks run to completion Not pre-empted by other tasks Example tasks High level calculate aggregate of sensor readings Low level encode radio packet for transmission, calculate CRC CSE Winter 2007 Case Study: TinyOS 17

18 Components Two types of components in nesc: Module Configuration A component provides and uses Interfaces CSE Winter 2007 Case Study: TinyOS 18

19 Module Provides application code Contains C-like code Must implement the provides interfaces Implement the commands it provides Make sure to actually signal Must implement the uses interfaces Implement the events that need to be handled call commands as needed CSE Winter 2007 Case Study: TinyOS 19

20 Configuration A configuration is a component that "wires" other components together. Configurations are used to assemble other components together Connects interfaces used by components to interfaces provided by others. CSE Winter 2007 Case Study: TinyOS 20

21 Interfaces Bi-directional multi-function interaction channel between two components Allows a single interface to represent a complex event E.g., a registration of some event, followed by a callback Critical for non-blocking operation provides interfaces Represent the functionality that the component provides to its user Service commands implemented command functions Issue events signal to user for passing data or signalling done uses interfaces Represent the functionality that the component needs from a provider Service events implement event handling Issue commands ask provider to do something CSE Winter 2007 Case Study: TinyOS 21

22 Application Consists of one or more components, wired together to form a runnable program Single top-level configuration that specifies the set of components in the application and how they connect to one another Connection (wire) to main component to start execution Must implement init, start, and stop commands CSE Winter 2007 Case Study: TinyOS 22

23 Components/Wiring Directed wire (an arrow: -> ) connects components Only 2 components at a time point-to-point Connection is across compatible interfaces A <- B is equivalent to B -> A [component using interface] -> [component providing interface] [interface] -> [implementation] = can be used to wire a component directly to the top-level object s interfaces Typically used in a configuration file to use a sub-component directly Unused system components excluded from compilation CSE Winter 2007 Case Study: TinyOS 23

24 Blink Application What the executable does: 1. Main initializes and starts the application 2. BlinkM initializes ClockC s rate at 1Hz 3. ClockC continuously signals BlinkM at a rate of 1 Hz 4. BlinkM commands LedsC red led to toggle each time it receives a signal from ClockC tos/system/main.nc tos/interfaces/stdcontrol.nc tos/interfaces/stdcontrol.nc BlinkM.nc Note: The StdControl interface is similar to state machines (init, start, stop); used extensively throughout TinyOS apps & libs tos/interfaces/timer.nc tos/interfaces/leds.nc tos/interfaces/singletimer.nc tos/interfaces/timer.nc tos/interfaces/leds.nc tos/system/timerc.nc tos/system/ledsc.nc CSE Winter 2007 Case Study: TinyOS 24

25 Blink.nc configuration Blink implementation components Main, BlinkM, SingleTimer, LedsC; Main.StdControl -> SingleTimer.StdControl; Main.StdControl -> BlinkM.StdControl; BlinkM.Timer -> SingleTimer.Timer; BlinkM.Leds -> LedsC.Leds; CSE Winter 2007 Case Study: TinyOS 25

26 StdControl.nc interface StdControl command result_t init(); command result_t start(); command result_t stop(); CSE Winter 2007 Case Study: TinyOS 26

27 BlinkM.nc BlinkM.nc module BlinkM provides interface StdControl; uses interface Timer; interface Leds; implementation command result_t StdControl.init() call Leds.init(); command result_t StdControl.start() return call Timer.start(TIMER_REPEAT, 1000); command result_t StdControl.stop() return call Timer.stop(); event result_t Timer.fired() call Leds.redToggle(); CSE Winter 2007 Case Study: TinyOS 27

28 SingleTimer.nc (should have been SingleTimerC.nc) Parameterized interfaces allows a component to provide multiple instances of an interface that are parameterized by a value Timer implements one level of indirection to actual timer functions Timer module supports many interfaces This module simply creates one unique timer interface and wires it up By wiring Timer to a separate instance of the Timer interface provided by TimerC, each component can effectively get its own "private" timer Uses a compile-time constant function unique() to ensure index is unique configuration SingleTimer provides interface Timer; provides interface StdControl; implementation components TimerC; Timer = TimerC.Timer[unique("Timer")]; StdControl = TimerC.StdControl; CSE Winter 2007 Case Study: TinyOS 28

29 Blink.nc without SingleTimer configuration Blink implementation components Main, BlinkM, TimerC, LedsC; Main.StdControl -> TimerC.StdControl; Main.StdControl -> BlinkM.StdControl; BlinkM.Timer -> TimerC.Timer[unique("Timer")]; BlinkM.Leds -> LedsC.Leds; CSE Winter 2007 Case Study: TinyOS 29

30 Timer.nc interface Timer command result_t start(char type, uint32_t interval); command result_t stop(); event result_t fired(); CSE Winter 2007 Case Study: TinyOS 30

31 TimerC.nc Implementation of multiple timer interfaces to a single shared timer Each interface is named Each interface connects to one other module CSE Winter 2007 Case Study: TinyOS 31

32 Leds.nc (partial) interface Leds /** * Initialize the LEDs; among other things, initialization turns them all off. */ async command result_t init(); /** * Turn the red LED on. */ async command result_t redon(); /** * Turn the red LED off. */ async command result_t redoff(); /** * Toggle the red LED. If it was on, turn it off. If it was off, * turn it on. */ async command result_t redtoggle();... CSE Winter 2007 Case Study: TinyOS 32

33 LedsC.nc (partial) module LedsC provides interface Leds; implementation uint8_t ledson; enum RED_BIT = 1, GREEN_BIT = 2, YELLOW_BIT = 4 ; async command result_t Leds.init() atomic ledson = 0; dbg(dbg_boot, "LEDS: initialized.\n"); TOSH_MAKE_RED_LED_OUTPUT(); TOSH_MAKE_YELLOW_LED_OUTPUT(); TOSH_MAKE_GREEN_LED_OUTPUT(); TOSH_SET_RED_LED_PIN(); TOSH_SET_YELLOW_LED_PIN(); TOSH_SET_GREEN_LED_PIN(); async command result_t Leds.redOn() dbg(dbg_led, "LEDS: Red on.\n"); atomic TOSH_CLR_RED_LED_PIN(); ledson = RED_BIT; async command result_t Leds.redOff() dbg(dbg_led, "LEDS: Red off.\n"); atomic TOSH_SET_RED_LED_PIN(); ledson &= ~RED_BIT; async command result_t Leds.redToggle() result_t rval; atomic if (ledson & RED_BIT) rval = call Leds.redOff(); else rval = call Leds.redOn(); return rval;... CSE Winter 2007 Case Study: TinyOS 33

34 static inline void TOSH_SET_PIN_DIRECTIONS(void ) static inline void HPLPowerManagementM$doAdjustment(void) Blink Compiled TOSH_MAKE_RED_LED_OUTPUT(); inline static result_t TimerM$Clock$setRate(char arg_0xa33adc0, char uint8_t foo; arg_0xa33af00) TOSH_MAKE_YELLOW_LED_OUTPUT(); uint8_t mcu; unsigned char result; TOSH_MAKE_GREEN_LED_OUTPUT(); foo = HPLPowerManagementM$getPowerLevel(); result = HPLClock$Clock$setRate(arg_0xa33adc0, arg_0xa33af00); TOSH_MAKE_CC_CHP_OUT_INPUT(); mcu = * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char return result; inline static result_t BlinkM$Leds$redToggle(void) *)(0x35 + 0x20); TOSH_MAKE_PW7_OUTPUT(); unsigned char result; mcu &= 0xe3; TOSH_MAKE_PW6_OUTPUT(); static inline result_t TimerM$StdControl$init(void) if (foo == HPLPowerManagementM$EXT_STANDBY foo == result = LedsC$Leds$redToggle(); TOSH_MAKE_PW5_OUTPUT(); HPLPowerManagementM$POWER_SAVE) return result; TOSH_MAKE_PW4_OUTPUT(); TimerM$mState = 0; mcu = HPLPowerManagementM$IDLE; TOSH_MAKE_PW3_OUTPUT(); TimerM$setIntervalFlag = 0; while ((* (volatile unsigned char *)(unsigned int )& * (volatile static inline result_t BlinkM$Timer$fired(void) TOSH_MAKE_PW2_OUTPUT(); unsigned char *)(0x30 + 0x20) & 0x7)!= 0) TimerM$queue_head = TimerM$queue_tail = -1; TOSH_MAKE_PW1_OUTPUT(); asm volatile ("nop"); TimerM$queue_size = 0; BlinkM$Leds$redToggle(); TOSH_MAKE_PW0_OUTPUT(); TimerM$mScale = 3; int main(void); TOSH_MAKE_CC_PALE_OUTPUT(); mcu &= 0xe3; TimerM$mInterval = TimerM$maxTimerInterval; static result_t PotM$HPLPot$finalise(void); TOSH_MAKE_CC_PDATA_OUTPUT(); return TimerM$Clock$setRate(TimerM$mInterval, TimerM$mScale); static inline result_t TimerM$Timer$default$fired(uint8_t id) static result_t PotM$HPLPot$decrease(void); TOSH_MAKE_CC_PCLK_OUTPUT(); mcu = foo; static result_t PotM$HPLPot$increase(void); TOSH_MAKE_MISO_INPUT(); * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char inline static result_t RealMain$StdControl$init(void) static inline void TOSH_SET_GREEN_LED_PIN(void) *)(0x35 + 0x20) = mcu; uint8_t PotM$potSetting; TOSH_MAKE_SPI_OC1C_INPUT(); unsigned char result; * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char static inline void PotM$setPot(uint8_t value); TOSH_MAKE_SERIAL_ID_INPUT(); #define dbg(mode, format,...) ((void)0) result = TimerM$StdControl$init(); *)(0x35 + 0x20) = 1 << 5; inline static result_t TimerM$Timer$fired(uint8_t arg_0xa31d660) * (volatile unsigned char *)(unsigned int )& * (volatile unsigned static inline result_t PotM$Pot$init(uint8_t initialsetting); TOSH_CLR_SERIAL_ID_PIN(); char *)(0x1B + 0x20) #define dbg_clear(mode, format,...) ((void)0) = 1 << 1; result = rcombine(result, BlinkM$StdControl$init()); unsigned char result; static inline result_t HPLPotC$Pot$decrease(void); TOSH_MAKE_FLASH_SELECT_OUTPUT(); #define dbg_active(mode) 0 return result; static inline void nesc_enable_interrupt(void) switch (arg_0xa31d660) static inline result_t HPLPotC$Pot$increase(void); TOSH_MAKE_FLASH_OUT_OUTPUT(); typedef signed char int8_t; static inline void TOSH_SET_YELLOW_LED_PIN(void) case 0: typedef long long TOS_dbg_mode; static inline result_t HPLPotC$Pot$finalise(void); TOSH_MAKE_FLASH_CLK_OUTPUT(); typedef unsigned char uint8_t; inline static uint8_t TimerM$PowerManagement$adjustPower(void) asm volatile ("sei"); result = BlinkM$Timer$fired(); enum nesc_unnamed4251 static inline result_t HPLInit$init(void); TOSH_SET_FLASH_SELECT_PIN(); typedef int int16_t; * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x1B + 0x20) unsigned char result; static inline void TOSH_wait(void) break; DBG_ALL = ~0ULL, static result_t BlinkM$Leds$init(void); = 1 << 0; TOSH_SET_RED_LED_PIN(); typedef unsigned int uint16_t; result = HPLPowerManagementM$PowerManagement$adjustPower(); default: DBG_BOOT = 1ULL << 0, static result_t BlinkM$Leds$redToggle(void); TOSH_SET_YELLOW_LED_PIN(); typedef long int32_t; return result; asm volatile ("nop"); result = TimerM$Timer$default$fired(arg_0xa31d660); DBG_CLOCK = 1ULL << 1, static result_t BlinkM$Timer$start(char arg_0xa2fd578, static uint32_t inline arg_0xa2fd6d0); void TOSH_SET_RED_LED_PIN(void) TOSH_SET_GREEN_LED_PIN(); typedef unsigned long uint32_t; asm volatile ("nop"); DBG_TASK = 1ULL << 2, static inline result_t BlinkM$StdControl$init(void); typedef long long int64_t; static inline void HPLClock$Clock$setInterval(uint8_t value) static inline void TOSH_sleep(void) return result; DBG_SCHED = 1ULL << 3, static inline result_t BlinkM$StdControl$start(void); * (volatile unsigned char *)(unsigned int )& * (volatile unsigned static char inline *)(0x1B result_t + 0x20) HPLInit$init(void) typedef unsigned long long uint64_t; = 1 << 2; DBG_SENSOR = 1ULL << 4, static inline result_t BlinkM$Timer$fired(void); typedef int16_t intptr_t; * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char * (volatile unsigned char *)(unsigned int )& * (volatile unsigned static char inline uint8_t TimerM$dequeue(void) DBG_LED = 1ULL << 5, static uint8_t TimerM$PowerManagement$adjustPower(void); TOSH_SET_PIN_DIRECTIONS(); *)(0x31 + 0x20) = value; *)(0x35 + 0x20) = 1 << 5; typedef uint16_t uintptr_t; static inline void TOSH_SET_FLASH_SELECT_PIN(void) DBG_CRYPTO = 1ULL << 6, static void TimerM$Clock$setInterval(uint8_t arg_0xa33b8c0); asm volatile ("sleep"); typedef unsigned int size_t; if (TimerM$queue_size == 0) DBG_ROUTE = 1ULL << 7, static uint8_t TimerM$Clock$readCounter(void); inline static void TimerM$Clock$setInterval(uint8_t arg_0xa33b8c0) inline void nesc_atomic_end( nesc_atomic_t oldsreg) typedef int wchar_t; return NUM_TIMERS; * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x1B + 0x20) DBG_AM = 1ULL << 8, static result_t TimerM$Clock$setRate(char arg_0xa33adc0, char arg_0xa33af00); typedef struct nesc_unnamed4242 = 1 << 3; inline static result_t RealMain$hardwareInit(void) HPLClock$Clock$setInterval(arg_0xa33b8c0); DBG_CRC = 1ULL << 9, static result_t TimerM$Timer$fired(uint8_t arg_0xa31d660); unsigned char result; int quot; * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x3F + 0x20) = oldsreg; if (TimerM$queue_head == NUM_TIMERS - 1) DBG_PACKET = 1ULL << 10, uint32_t TimerM$mState; result = HPLInit$init(); int rem; static inline void TOSH_MAKE_FLASH_CLK_OUTPUT(void) static inline uint8_t HPLClock$Clock$readCounter(void) TimerM$queue_head = -1; DBG_ENCODE = 1ULL << 11, uint8_t TimerM$setIntervalFlag; return result; div_t; inline nesc_atomic_t nesc_atomic_start(void ) DBG_RADIO = 1ULL << 12, uint8_t TimerM$mScale; typedef struct nesc_unnamed4243 * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x11 + 0x20) return * (volatile unsigned char *)(unsigned int )& * (volatile unsigned DBG_LOG = 1ULL << 13, uint8_t TimerM$mInterval; = 1 << 5; char *)(0x32 + 0x20); TimerM$queue_head++; static inline result_t HPLPotC$Pot$finalise(void) long quot; DBG_ADC = 1ULL << 14, nesc_atomic_t result = * (volatile unsigned char *)(unsigned int )& TimerM$queue_size--; * int8_t TimerM$queue_head; (volatile unsigned char *)(0x3F + 0x20); long rem; return TimerM$queue[(uint8_t )TimerM$queue_head]; DBG_I2C = 1ULL << 15, static inline void TOSH_MAKE_FLASH_OUT_OUTPUT(void) inline static uint8_t TimerM$Clock$readCounter(void) int8_t TimerM$queue_tail; asm volatile ("cli"); ldiv_t; DBG_UART = 1ULL << 16, uint8_t TimerM$queue_size; unsigned char result; return result; typedef int (* compar_fn_t)(const void *, const void *); static inline void TimerM$signalOneTimer(void) DBG_PROG = 1ULL << 17, uint8_t TimerM$queue[NUM_TIMERS]; * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x11 + 0x20) result = HPLClock$Clock$readCounter(); inline static result_t PotM$HPLPot$finalise(void) typedef int ptrdiff_t; = 1 << 3; return result; DBG_SOUNDER = 1ULL << 18, struct TimerM$timer_s unsigned char result; static inline bool TOSH_run_next_task(void) typedef unsigned char bool; uint8_t itimer = TimerM$dequeue(); DBG_TIME = 1ULL << 19, uint8_t type; result = HPLPotC$Pot$finalise(); enum nesc_unnamed4244 static inline void TOSH_MAKE_FLASH_SELECT_OUTPUT(void) if (itimer < NUM_TIMERS) static inline result_t TimerM$Timer$start(uint8_t id, char type, uint32_t DBG_SIM = 1ULL << 21, int32_t ticks; return result; FALSE = 0, interval) nesc_atomic_t finterruptflags; TimerM$Timer$fired(itimer); DBG_QUEUE = 1ULL << 22, int32_t ticksleft; TRUE = 1 * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x1A + 0x20) uint8_t old_full; DBG_SIMRADIO = 1ULL << 23, TimerM$mTimerList[NUM_TIMERS]; = 1 << 3; static inline result_t HPLPotC$Pot$increase(void) ; uint8_t diff; void (*func)(void ); DBG_HARD = 1ULL << 24, enum TimerM$ nesc_unnamed4257 enum nesc_unnamed4245 if (id >= NUM_TIMERS) if (TOSH_sched_full == TOSH_sched_free) static inline void TimerM$enqueue(uint8_t value) DBG_MEM = 1ULL << 25, TimerM$maxTimerInterval = 230 static inline void TOSH_CLR_SERIAL_ID_PIN(void) FAIL = 0, return FAIL; return 0; DBG_USR1 = 1ULL << 27, ; SUCCESS = 1 else if (TimerM$queue_tail == NUM_TIMERS - 1) DBG_USR2 = 1ULL << 28, static inline result_t TimerM$StdControl$init(void); * (volatile unsigned char *)(unsigned int )& * (volatile unsigned inline char static *)(0x1B result_t + 0x20) PotM$HPLPot$increase(void) ; if (type > 1) finterruptflags = nesc_atomic_start(); TimerM$queue_tail = -1; &= ~(1 << 4); DBG_USR3 = 1ULL << 29, static inline result_t TimerM$StdControl$start(void); unsigned char result; static inline uint8_t rcombine(uint8_t r1, uint8_t r2); return FAIL; old_full = TOSH_sched_full; DBG_TEMP = 1ULL << 30, static inline result_t TimerM$Timer$start(uint8_t id, char type, result = HPLPotC$Pot$increase(); typedef uint8_t result_t; TOSH_sched_full++; TimerM$queue_tail++; DBG_ERROR = 1ULL << 31, static inline void TOSH_MAKE_SERIAL_ID_INPUT(void) uint32_t interval); return result; static inline result_t rcombine(result_t r1, result_t r2); TimerM$mTimerList[id].ticks = interval; TOSH_sched_full &= TOSH_TASK_BITMASK; TimerM$queue_size++; DBG_NONE = 0, static void TimerM$adjustInterval(void); enum nesc_unnamed4246 TimerM$mTimerList[id].type = type; func = TOSH_queue[(int )old_full].tp; TimerM$queue[(uint8_t )TimerM$queue_tail] = value; * (volatile unsigned char *)(unsigned int )& * (volatile unsigned DBG_DEFAULT = DBG_ALL static inline result_t TimerM$Timer$default$fired(uint8_t id); static char inline *)(0x1A result_t + 0x20) HPLPotC$Pot$decrease(void) NULL = 0x0 &= ~(1 << 4); nesc_atomic_t nesc_atomic = nesc_atomic_start(); TOSH_queue[(int )old_full].tp = 0; ; static inline void TimerM$enqueue(uint8_t value); ; nesc_atomic_end(finterruptflags); static inline void TimerM$HandleFire(void) typedef struct nesc_unnamed4252 static inline uint8_t TimerM$dequeue(void); typedef void attribute(( progmem )) prog_void; static inline void TOSH_MAKE_SPI_OC1C_INPUT(void) diff = TimerM$Clock$readCounter(); func(); void (*tp)(void); static inline void TimerM$signalOneTimer(void); typedef char attribute(( progmem )) prog_char; interval += diff; return 1; uint8_t i; TOSH_sched_entry_T; static inline void TimerM$HandleFire(void); inline static result_t PotM$HPLPot$decrease(void) typedef unsigned char attribute(( progmem )) prog_uchar; * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x17 + 0x20) TimerM$mTimerList[id].ticksLeft = interval; TimerM$setIntervalFlag = 1; enum nesc_unnamed4253 static inline result_t TimerM$Clock$fire(void); &= ~(1 << 7); unsigned char result; typedef int attribute(( progmem )) prog_int; TimerM$mState = 0x1 << id; if (TimerM$mState) TOSH_MAX_TASKS = 8, static result_t HPLClock$Clock$fire(void); result = HPLPotC$Pot$decrease(); typedef long attribute(( progmem )) prog_long; if (interval < TimerM$mInterval) static inline void TOSH_run_task(void) for (i = 0; i < NUM_TIMERS; i++) TOSH_TASK_BITMASK = TOSH_MAX_TASKS - 1 uint8_t HPLClock$set_flag; static inline void TOSH_MAKE_MISO_INPUT(void) return result; typedef long long attribute(( progmem )) prog_long_long; TimerM$mInterval = interval; if (TimerM$mState & (0x1 << i)) ; uint8_t HPLClock$mscale; enum nesc_unnamed4247 TimerM$Clock$setInterval(TimerM$mInterval); while (TOSH_run_next_task()) ; TimerM$mTimerList[i].ticksLeft -= TimerM$mInterval + 1; TOSH_sched_entry_T TOSH_queue[TOSH_MAX_TASKS]; uint8_t HPLClock$nextScale; * (volatile unsigned char *)(unsigned int )& * (volatile unsigned static char inline *)(0x17 void + PotM$setPot(uint8_t 0x20) value) TOSH_period16 = 0x00, TimerM$setIntervalFlag = 0; TOSH_sleep(); if (TimerM$mTimerList[i].ticksLeft <= 2) &= ~(1 << 3); volatile uint8_t TOSH_sched_full; uint8_t HPLClock$minterval; TOSH_period32 = 0x01, TimerM$PowerManagement$adjustPower(); TOSH_wait(); if (TimerM$mTimerList[i].type == TIMER_REPEAT) volatile uint8_t TOSH_sched_free; static inline void HPLClock$Clock$setInterval(uint8_t value); uint8_t i; TOSH_period64 = 0x02, TimerM$mTimerList[i].ticksLeft += TimerM$mTimerList[i].ticks; static inline void TOSH_MAKE_CC_PCLK_OUTPUT(void) static inline void TOSH_wait(void ); static inline uint8_t HPLClock$Clock$readCounter(void); for (i = 0; i < 151; i++) TOSH_period128 = 0x03, static void TimerM$adjustInterval(void) static inline void TOSH_sleep(void ); static inline result_t HPLClock$Clock$setRate(char interval, char scale); PotM$HPLPot$decrease(); TOSH_period256 = 0x04, nesc_atomic_end( nesc_atomic); else * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x11 + 0x20) static inline void TOSH_sched_init(void ); void attribute((interrupt)) vector_15(void); for (i = 0; i < value; i++) TOSH_period512 = 0x05, = 1 << 6; uint8_t i; bool TOS_post(void (*tp)(void)); bool HPLPowerManagementM$disabled = TRUE; PotM$HPLPot$increase(); TOSH_period1024 = 0x06, uint8_t val = TimerM$maxTimerInterval; TimerM$mState &= ~(0x1 << i); static inline bool TOSH_run_next_task(void); enum HPLPowerManagementM$ nesc_unnamed4258 PotM$HPLPot$finalise(); TOSH_period2048 = 0x07 static inline void TOSH_MAKE_CC_PDATA_OUTPUT(void) inline static result_t BlinkM$Timer$start(char arg_0xa2fd578, uint32_t if (TimerM$mState) static inline void TOSH_run_task(void); HPLPowerManagementM$IDLE = 0, PotM$potSetting = value; arg_0xa2fd6d0) ; for (i = 0; i < NUM_TIMERS; i++) TimerM$enqueue(i); enum nesc_unnamed4254 HPLPowerManagementM$ADC_NR = 1 << 3, unsigned char result; if (TimerM$mState & (0x1 << i) && TimerM$mTimerList[i].ticksLeft < static inline void TOSH_wait(void); * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x11 + 0x20) TOS_post(TimerM$signalOneTimer); TIMER_REPEAT = 0, HPLPowerManagementM$POWER_DOWN = 1 << 4, = 1 << 7; static inline result_t PotM$Pot$init(uint8_t initialsetting) result = TimerM$Timer$start(0, arg_0xa2fd578, arg_0xa2fd6d0); val) static inline void TOSH_sleep(void); TIMER_ONE_SHOT = 1, HPLPowerManagementM$POWER_SAVE = (1 << 3) + (1 << 4), return result; val = TimerM$mTimerList[i].ticksLeft; typedef uint8_t nesc_atomic_t; NUM_TIMERS = 1 HPLPowerManagementM$STANDBY = (1 << 2) + (1 << 4), static inline void TOSH_MAKE_CC_PALE_OUTPUT(void) PotM$setPot(initialSetting); inline nesc_atomic_t nesc_atomic_start(void ); ; HPLPowerManagementM$EXT_STANDBY = (1 << 3) + (1 << 4) + (1 << 2) static inline result_t BlinkM$StdControl$start(void) inline void nesc_atomic_end( nesc_atomic_t oldsreg); enum nesc_unnamed4255 ; * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x11 + 0x20) nesc_atomic_t nesc_atomic = nesc_atomic_start(); static inline void nesc_enable_interrupt(void); = 1 << 4; TimerM$adjustInterval(); TOS_I1000PS = 32, TOS_S1000PS = 1, static inline uint8_t HPLPowerManagementM$getPowerLevel(void); inline static result_t RealMain$Pot$init(uint8_t arg_0xa2ce970) return BlinkM$Timer$start(TIMER_REPEAT, 1000); static inline void TOSH_SET_RED_LED_PIN(void); TOS_I100PS = 40, TOS_S100PS = 2, static inline void HPLPowerManagementM$doAdjustment(void); unsigned char result; TimerM$mInterval = val; static inline void TOSH_CLR_RED_LED_PIN(void); static inline void TOSH_MAKE_PW0_OUTPUT(void) static inline result_t TimerM$Clock$fire(void) TOS_I10PS = 101, TOS_S10PS = 3, static uint8_t HPLPowerManagementM$PowerManagement$adjustPower(void); result = PotM$Pot$init(arg_0xa2ce970); static inline result_t TimerM$StdControl$start(void) TimerM$Clock$setInterval(TimerM$mInterval); static inline void TOSH_MAKE_RED_LED_OUTPUT(void); TOS_I1024PS = 0, TOS_S1024PS = 3, uint8_t LedsC$ledsOn; return result; TimerM$setIntervalFlag = 0; static inline void TOSH_SET_GREEN_LED_PIN(void); * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x14 + 0x20) TOS_post(TimerM$HandleFire); TOS_I512PS = 1, TOS_S512PS = 3, enum LedsC$ nesc_unnamed4259 = 1 << 0; static inline void TOSH_MAKE_GREEN_LED_OUTPUT(void); TOS_I256PS = 3, TOS_S256PS = 3, LedsC$RED_BIT = 1, static inline void TOSH_sched_init(void ) nesc_atomic_end( nesc_atomic); static inline void TOSH_SET_YELLOW_LED_PIN(void); TOS_I128PS = 7, TOS_S128PS = 3, LedsC$GREEN_BIT = 2, static inline void TOSH_MAKE_PW1_OUTPUT(void) inline static result_t RealMain$StdControl$start(void) static inline void TOSH_MAKE_YELLOW_LED_OUTPUT(void); inline static result_t HPLClock$Clock$fire(void) TOS_I64PS = 15, TOS_S64PS = 3, LedsC$YELLOW_BIT = 4 TOSH_sched_free = 0; unsigned char result; else static inline void TOSH_CLR_SERIAL_ID_PIN(void); unsigned char result; TOS_I32PS = 31, TOS_S32PS = 3, ; * (volatile unsigned char *)(unsigned int )& * (volatile unsigned TOSH_sched_full char *)(0x14 = + 0; result = TimerM$StdControl$start(); nesc_atomic_t nesc_atomic = nesc_atomic_start(); 0x20) static inline void TOSH_MAKE_SERIAL_ID_INPUT(void); result = TimerM$Clock$fire(); TOS_I16PS = 63, TOS_S16PS = 3, = 1 << 1; static inline result_t LedsC$Leds$init(void); result = rcombine(result, BlinkM$StdControl$start()); static inline void TOSH_MAKE_CC_CHP_OUT_INPUT(void); return result; TOS_I8PS = 127, TOS_S8PS = 3, static inline result_t LedsC$Leds$redOn(void); static inline result_t rcombine(result_t r1, result_t r2) return result; TimerM$mInterval = TimerM$maxTimerInterval; static inline void TOSH_MAKE_CC_PDATA_OUTPUT(void); TOS_I4PS = 255, TOS_S4PS = 3, static inline void TOSH_MAKE_PW2_OUTPUT(void) static inline result_t LedsC$Leds$redOff(void); TimerM$Clock$setInterval(TimerM$mInterval); static inline void TOSH_MAKE_CC_PCLK_OUTPUT(void); bool TOS_post(void (*tp)(void)) TOS_I2PS = 15, TOS_S2PS = 7, static inline result_t LedsC$Leds$redToggle(void); return r1 == FAIL? FAIL : r2; static inline uint8_t HPLPowerManagementM$getPowerLevel(void) TimerM$setIntervalFlag = 0; static inline void TOSH_MAKE_CC_PALE_OUTPUT(void); TOS_I1PS = 31, TOS_S1PS = 7, * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x14 + 0x20) static inline void TOSH_SET_FLASH_SELECT_PIN(void); = 1 << 2; nesc_atomic_t finterruptflags; TOS_I0PS = 0, TOS_S0PS = 0 static inline uint8_t diff; nesc_atomic_end( nesc_atomic); static inline void TOSH_MAKE_FLASH_SELECT_OUTPUT(void); uint8_t tmp; ; result_t LedsC$Leds$init(void) if (* (volatile unsigned char *)(unsigned int )& * (volatile unsigned char static inline void TOSH_MAKE_FLASH_CLK_OUTPUT(void); static inline void TOSH_MAKE_PW3_OUTPUT(void) *)(0x37 + 0x20) & ~((1 << 1) (1 << 0))) finterruptflags = nesc_atomic_start(); TimerM$PowerManagement$adjustPower(); enum nesc_unnamed4256 static inline void TOSH_MAKE_FLASH_OUT_OUTPUT(void); return HPLPowerManagementM$IDLE; tmp = TOSH_sched_free; DEFAULT_SCALE = 3, DEFAULT_INTERVAL = 127 nesc_atomic_t nesc_atomic = nesc_atomic_start(); static inline void TOSH_MAKE_MISO_INPUT(void); * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x14 + 0x20) TOSH_sched_free++; static inline void TOSH_CLR_RED_LED_PIN(void) ; = 1 << 3; static inline void TOSH_MAKE_SPI_OC1C_INPUT(void); else TOSH_sched_free &= TOSH_TASK_BITMASK; static result_t PotM$Pot$init(uint8_t arg_0xa2ce970); LedsC$ledsOn = 0; static inline void TOSH_MAKE_PW0_OUTPUT(void); if (* (volatile unsigned char *)(unsigned int )& * (volatile unsigned char if (TOSH_sched_free!= TOSH_sched_full) * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char static result_t HPLPotC$Pot$finalise(void); static inline void TOSH_MAKE_PW4_OUTPUT(void) TOSH_SET_RED_LED_PIN(); *)(0x0D + 0x20) & (1 << 7)) static inline void TOSH_MAKE_PW1_OUTPUT(void); *)(0x1B + 0x20) &= ~(1 << 2); nesc_atomic_end(finterruptflags); static result_t HPLPotC$Pot$decrease(void); TOSH_SET_YELLOW_LED_PIN(); return HPLPowerManagementM$IDLE; static inline void TOSH_MAKE_PW2_OUTPUT(void); TOSH_queue[tmp].tp = tp; static result_t HPLPotC$Pot$increase(void); * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char TOSH_SET_GREEN_LED_PIN(); *)(0x14 + 0x20) static inline void TOSH_MAKE_PW3_OUTPUT(void); static inline result_t LedsC$Leds$redOn(void) return TRUE; static uint8_t HPLPowerManagementM$PowerManagement$adjustPower(void) = 1 << 4; static result_t HPLInit$init(void); else static inline void TOSH_MAKE_PW4_OUTPUT(void); static result_t BlinkM$StdControl$init(void); nesc_atomic_end( nesc_atomic); if (* (volatile unsigned char *)(unsigned int )& * (volatile unsigned static inline void TOSH_MAKE_PW5_OUTPUT(void); nesc_atomic_t nesc_atomic = nesc_atomic_start(); else uint8_t mcu; static inline void TOSH_MAKE_PW5_OUTPUT(void) static result_t BlinkM$StdControl$start(void); char *)(0x06 + 0x20) & (1 << 7)) static inline void TOSH_MAKE_PW6_OUTPUT(void); TOSH_sched_free = tmp; if (!HPLPowerManagementM$disabled) static result_t BlinkM$Timer$fired(void); return HPLPowerManagementM$ADC_NR; static inline void TOSH_MAKE_PW7_OUTPUT(void); TOSH_CLR_RED_LED_PIN(); nesc_atomic_end(finterruptflags); TOS_post(HPLPowerManagementM$doAdjustment); * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x14 + 0x20) static result_t TimerM$Clock$fire(void); inline static result_t BlinkM$Leds$init(void) static inline void TOSH_SET_PIN_DIRECTIONS(void ); = 1 << 5; LedsC$ledsOn = LedsC$RED_BIT; return FALSE; static result_t TimerM$StdControl$init(void); unsigned char result; else enum nesc_unnamed4248 else static result_t TimerM$StdControl$start(void); result = LedsC$Leds$init(); if (* (volatile unsigned char *)(unsigned int )& * (volatile unsigned TOSH_ADC_PORTMAPSIZE = 12 static inline void TOSH_MAKE_PW6_OUTPUT(void) char *)(0x37 + 0x20) & ((1 << 1) (1 << 0))) nesc_atomic_end( nesc_atomic); static result_t TimerM$Timer$default$fired(uint8_t arg_0xa31d660); return result; ; diff = * (volatile unsigned char *)(unsigned int )& * (volatile int main(void) mcu = * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char static result_t TimerM$Timer$start(uint8_t arg_0xa31d660, char arg_0xa2fd578, *)(0x35 + 0x20); unsigned char *)(0x31 + 0x20) - * (volatile unsigned char enum nesc_unnamed4249 * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x14 + 0x20) uint32_t arg_0xa2fd6d0); = 1 << 6; static inline result_t BlinkM$StdControl$init(void) *)(unsigned int )& * (volatile unsigned char *)(0x32 + mcu &= 0xe3; TOSH_ACTUAL_CC_RSSI_PORT = 0, 0x20); static inline result_t LedsC$Leds$redOff(void) RealMain$hardwareInit(); static void HPLClock$Clock$setInterval(uint8_t arg_0xa33b8c0); mcu = HPLPowerManagementM$IDLE; TOSH_ACTUAL_VOLTAGE_PORT = 7, if (diff < 16) RealMain$Pot$init(10); static uint8_t HPLClock$Clock$readCounter(void); static inline void TOSH_MAKE_PW7_OUTPUT(void) BlinkM$Leds$init(); * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char TOSH_ACTUAL_BANDGAP_PORT = 30, return HPLPowerManagementM$EXT_STANDBY; nesc_atomic_t nesc_atomic = nesc_atomic_start(); TOSH_sched_init(); *)(0x35 + 0x20) = mcu; static result_t HPLClock$Clock$setRate(char arg_0xa33adc0, char arg_0xa33af00); TOSH_ACTUAL_GND_PORT = 31 RealMain$StdControl$init(); * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char static uint8_t HPLPowerManagementM$PowerManagement$adjustPower(void); * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x14 + 0x20) *)(0x35 + 0x20) = 1 << 5; ; return HPLPowerManagementM$POWER_SAVE; TOSH_SET_RED_LED_PIN(); RealMain$StdControl$start(); static result_t LedsC$Leds$init(void); = 1 << 7; static inline result_t HPLClock$Clock$setRate(char interval, char scale) enum nesc_unnamed4250 LedsC$ledsOn &= ~LedsC$RED_BIT; nesc_enable_interrupt(); static result_t LedsC$Leds$redOff(void); return 0; TOS_ADC_CC_RSSI_PORT = 0, static result_t LedsC$Leds$redToggle(void); static inline void TOSH_MAKE_CC_CHP_OUT_INPUT(void) else while (1) scale &= 0x7; TOS_ADC_VOLTAGE_PORT = 7, nesc_atomic_end( nesc_atomic); TOSH_run_task(); static result_t LedsC$Leds$redOn(void); scale = 0x8; void attribute((interrupt)) vector_15(void) TOS_ADC_BANDGAP_PORT = 10, return HPLPowerManagementM$POWER_DOWN; static result_t RealMain$hardwareInit(void); * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x1A + 0x20) &= ~(1 << 6); nesc_atomic_t nesc_atomic = nesc_atomic_start(); TOS_ADC_GND_PORT = 11 static result_t RealMain$Pot$init(uint8_t arg_0xa2ce970); ; nesc_atomic_t nesc_atomic = nesc_atomic_start(); static inline result_t LedsC$Leds$redToggle(void) static result_t RealMain$StdControl$init(void); static inline void TOSH_MAKE_GREEN_LED_OUTPUT(void) * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char static result_t RealMain$StdControl$start(void); *)(0x37 + 0x20) &= ~(1 << 0); if (HPLClock$set_flag) result_t rval; * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x1A + 0x20) *)(0x37 + 0x20) &= ~(1 << 1); nesc_atomic_t nesc_atomic = nesc_atomic_start(); HPLClock$mscale = HPLClock$nextScale; = 1 << 1; * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char HPLClock$nextScale = 0x8; *)(0x30 + 0x20) = 1 << 3; * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char if (LedsC$ledsOn & LedsC$RED_BIT) static inline void TOSH_MAKE_YELLOW_LED_OUTPUT(void) * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x33 + 0x20) = HPLClock$nextScale; *)(0x33 + 0x20) = scale; rval = LedsC$Leds$redOff(); * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char else * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x1A + 0x20) * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x32 + 0x20) = 0; = 1 << 0; rval = LedsC$Leds$redOn(); *)(0x31 + 0x20) = HPLClock$minterval; * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char HPLClock$set_flag = 0; *)(0x31 + 0x20) = interval; static inline void TOSH_MAKE_RED_LED_OUTPUT(void) * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x37 + 0x20) = 1 << 1; nesc_atomic_end( nesc_atomic); * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x1A + 0x20) return rval; nesc_atomic_end( nesc_atomic); = 1 << 2; nesc_atomic_end( nesc_atomic); HPLClock$Clock$fire(); 1K lines of C (another 1K lines of comments) = ~1.5K bytes of assembly code CSE Winter 2007 Case Study: TinyOS 34

35 Blink Compiled a small piece static inline result_t LedsC$Leds$redToggle(void) result_t rval; nesc_atomic_t nesc_atomic = nesc_atomic_start(); if (LedsC$ledsOn & LedsC$RED_BIT) rval = LedsC$Leds$redOff(); else rval = LedsC$Leds$redOn(); nesc_atomic_end( nesc_atomic); return rval; inline static result_t BlinkM$Leds$redToggle(void) unsigned char result; result = LedsC$Leds$redToggle(); return result; static inline result_t BlinkM$Timer$fired(void) BlinkM$Leds$redToggle(); static inline result_t LedsC$Leds$redOn(void) nesc_atomic_t nesc_atomic = nesc_atomic_start(); TOSH_CLR_RED_LED_PIN(); LedsC$ledsOn = LedsC$RED_BIT; nesc_atomic_end( nesc_atomic); static inline result_t LedsC$Leds$redOff(void) nesc_atomic_t nesc_atomic = nesc_atomic_start(); TOSH_SET_RED_LED_PIN(); LedsC$ledsOn &= ~LedsC$RED_BIT; nesc_atomic_end( nesc_atomic); CSE Winter 2007 Case Study: TinyOS 35

36 Concurrency Model Asynchronous Code (AC) Any code that is reachable from an interrupt handler Synchronous Code (SC) Any code that is ONLY reachable from a task Boot sequence Potential race conditions Asynchronous Code and Synchronous Code Asynchronous Code and Asynchronous Code Non-preemption eliminates data races among tasks nesc reports potential data races to the programmer at compile time (new with version 1.1) Use atomic statement when needed async keyword is used to declare asynchronous code to compiler CSE Winter 2007 Case Study: TinyOS 36

37 Commands, Events, and Tasks... status = call CmdName(args)... command CmdName(args)... return status; event EvtName (args)... return status;... post TskName(); status = signal EvtName(args)... task void TskName... CSE Winter 2007 Case Study: TinyOS 37

38 Split Phase Operations Component1 Event or task call command, try again if not OK Event handler Check success flag (OK, failed, etc.) Component2 Command post task and return OK, or return busy Task task executes and signals completion with event Phase I call command with parameters command either posts task to do real work or signals busy and to try again later Phase II task completes and uses event (with return parameters) to signal completion event handler checks for success (may cause re-issue of command if failed) CSE Winter 2007 Case Study: TinyOS 38

39 Example configuration CntToLeds implementation components Main, Counter, IntToLeds, TimerC; Main.StdControl -> IntToLeds.StdControl; Main.StdControl -> Counter.StdControl; Main.StdControl -> TimerC.StdControl; Counter.Timer -> TimerC.Timer[unique("Timer")]; Counter.IntOutput -> IntToLeds.IntOutput; M ain.nc StdControl.nc StdControl.nc Counter.nc Timer.nc IntOutput.nc StdControl.nc TimerC.nc Timer.nc IntOutput.nc IntToLeds.nc StdControl.nc CSE Winter 2007 Case Study: TinyOS 39

40 Exercise Which of the following goes inside the module you are implementing if we assume you are the user of the interface? NOTE: Not all of these choices are exposed through an interface. Assume those that are not exposed are implemented in your module. post taska( ); call commandb(args); signal eventc(args); taska implementation commandb implementation eventc implementation CSE Winter 2007 Case Study: TinyOS 40

41 Sense Application SenseM.nc module SenseM provides interface StdControl; uses interface Timer; Sense.nc interface ADC; interface StdControl as ADCControl; configuration Sense interface Leds; implementation cont d components Main, SenseM, LedsC, TimerC, DemoSensorC as Sensor; Main.StdControl -> Sensor.StdControl; Main.StdControl -> TimerC.StdControl; Main.StdControl -> SenseM.StdControl; SenseM.ADC -> Sensor.ADC; SenseM.ADCControl -> Sensor.StdControl; SenseM.Leds -> LedsC.Leds; SenseM.Timer -> TimerC.Timer[unique("Timer")]; DemoSensorC.nc configuration DemoSensorC provides interface ADC; provides interface StdControl; implementation components Photo as Sensor; StdControl = Sensor; ADC = Sensor; CSE Winter 2007 Case Study: TinyOS 41

42 SenseM.nc cont d implementation /* Module scoped method. Displays the lowest 3 bits to the LEDs, with RED being the most signficant and YELLOW being the least significant */ result_t display(uint16_t value) if (value &1) call Leds.yellowOn(); else call Leds.yellowOff(); if (value &2) call Leds.greenOn(); else call Leds.greenOff(); if (value &4) call Leds.redOn(); else call Leds.redOff(); command result_t StdControl.init() return call Leds.init(); command result_t StdControl.start() return call Timer.start(TIMER_REPEAT, 500); command result_t StdControl.stop() return call Timer.stop(); event result_t Timer.fired() return call ADC.getData(); async event result_t ADC.dataReady(uint16_t data) display(7-((data>>7) &0x7)); CSE Winter 2007 Case Study: TinyOS 42

43 Sense Application Using Task module SenseTaskM provides interface StdControl; uses interface Timer; SenseTask.nc interface ADC; interface Leds; configuration SenseTask implementation cont d components Main, SenseTaskM, LedsC, TimerC, DemoSensorC as Sensor; Main.StdControl -> TimerC; Main.StdControl -> Sensor; Main.StdControl -> SenseTaskM; SenseM.nc SenseTaskM.Timer -> TimerC.Timer[unique("Timer")]; SenseTaskM.ADC -> Sensor; SenseTaskM.Leds -> LedsC; CSE Winter 2007 Case Study: TinyOS 43

44 SenseTaskM.nc implementation enum log2size = 3, // log2 of buffer size size=1 << log2size, // circular buffer size sizemask=size - 1, // bit mask ; int8_t head; // head index int16_t rdata[size]; // circular buffer inline void putdata(int16_t val) int16_t p; atomic p = head; head = (p+1) & sizemask; rdata[p] = val; result_t display(uint16_t value) if (value &1) call Leds.yellowOn(); else call Leds.yellowOff(); if (value &2) call Leds.greenOn(); else call Leds.greenOff(); if (value &4) call Leds.redOn(); else call Leds.redOff(); task void processdata() int16_t i, sum=0; atomic for (i=0; i<size; i++) sum += (rdata[i] >> 7); display(sum >> log2size); command result_t StdControl.init() atomic head = 0; return call Leds.init(); command result_t StdControl.start() return call Timer.start(TIMER_REPEAT, 500); command result_t StdControl.stop() return call Timer.stop(); event result_t Timer.fired() return call ADC.getData(); async event result_t ADC.dataReady(uint16_t data) putdata(data); post processdata(); CSE Winter 2007 Case Study: TinyOS 44

45 A More Extensive Application application Route map Router Sensor Application Active Messages bit byte packet Radio Packet Radio Byte RFM Serial Packet UART Temp ADC Photo Clocks SW HW CSE Winter 2007 Case Study: TinyOS 45

TinyOS an operating system for sensor nets

TinyOS an operating system for sensor nets TinyOS an operating system for sensor nets Embedded operating systems How do they differ from desktop operating systems? Event-based programming model How is concurrency handled? How are resource conflicts

More information

% #!" # !" #$ (# ( ' (# (

% #! # ! #$ (# ( ' (# ( Embedded operating systems How do they differ from desktop operating systems? Event-based programming model How is concurrency handled? How are resource conflicts managed? Programming in TinyOS What new

More information

TinyOS an operating system for sensor nets. Embedded Operating Systems

TinyOS an operating system for sensor nets. Embedded Operating Systems TinyOS an operating system for sensor nets Embedded operating systems How do they differ from desktop operating systems? Event-based programming model How is concurrency handled? How are resource conflicts

More information

Programming TinyOS. Lesson 2. Execution Flow. Tasks. commands. Events generated by interrupts preempt tasks Tasks do not preempt tasks

Programming TinyOS. Lesson 2. Execution Flow. Tasks. commands. Events generated by interrupts preempt tasks Tasks do not preempt tasks Programming TinyOS Lesson 2 Some of the content from these slides were adapted from the Crossbow Tutorials and from the TinyOS website from Mobsys Tutorials Execution Flow Tasks events commands Hardware

More information

Mobile and Ubiquitous Computing Routing Protocols. Niki Trigoni

Mobile and Ubiquitous Computing Routing Protocols. Niki Trigoni Mobile and Ubiquitous Computing Routing Protocols Niki Trigoni www.dcs.bbk.ac.uk/~niki niki@dcs.bbk.ac.uk Overview Intro to routing in ad-hoc networks Routing methods Link-State Distance-Vector Distance-vector

More information

Programming TinyOS. Lesson 3. Basic Structure. Main.nc

Programming TinyOS. Lesson 3. Basic Structure. Main.nc Programming TinyOS Lesson 3 Some of the content from these slides were adapted from the Crossbow Tutorials and from the TinyOS website from Mobsys Tutorials Main.nc Basic Structure Interfaces (xxx.nc)

More information

Introduction to Programming Motes

Introduction to Programming Motes Introduction to Programming Motes Mohamed M. El Wakil http://mohamed.elwakil.net mohamed.elwakil@wmich.edu Wireless Sensornets (WiSe) Laboratory Department of Computer Science Western Michigan University

More information

Sensor Network Application Development ZIGBEE CONCEPTS 0

Sensor Network Application Development ZIGBEE CONCEPTS 0 Sensor Network Application Development ZIGBEE CONCEPTS 0 Cruise Summerschool Johannes Kepler University November 5-7, 2007, Linz / Austria Dipl.-Ing. riener@pervasive.jku.at Overview Structure of this

More information

nesc Prof. Chenyang Lu How should network msg be handled? Too much memory for buffering and threads

nesc Prof. Chenyang Lu How should network msg be handled? Too much memory for buffering and threads nesc Prof. Chenyang Lu CSE 521S 1 How should network msg be handled? Socket/TCP/IP? Too much memory for buffering and threads Data buffered in network stack until application threads read it Application

More information

nesc Ø Programming language for TinyOS and applications Ø Support TinyOS components Ø Whole-program analysis at compile time Ø Static language

nesc Ø Programming language for TinyOS and applications Ø Support TinyOS components Ø Whole-program analysis at compile time Ø Static language nesc Ø Programming language for TinyOS and applications Ø Support TinyOS components Ø Whole-program analysis at compile time q Improve robustness: detect race conditions q Optimization: function inlining

More information

Programming Sensor Networks

Programming Sensor Networks Programming Sensor Networks Distributed Computing Group Nicolas Burri Pascal von Rickenbach Overview TinyOS Platform Program Development Current Projects MOBILE COMPUTING 2 Sensor Nodes System Constraints

More information

Mobile and Ubiquitous Computing TinyOS application example. Niki Trigoni

Mobile and Ubiquitous Computing TinyOS application example. Niki Trigoni Mobile and Ubiquitous Computing TinyOS application example Niki Trigoni www.dcs.bbk.ac.uk/~niki niki@dcs.bbk.ac.uk Application Consider an application with the following functionality: The gateway node

More information

TinyOS. Jan S. Rellermeyer

TinyOS. Jan S. Rellermeyer TinyOS Jan S. Rellermeyer jrellermeyer@student.ethz.ch Overview Motivation Hardware TinyOS Architecture Component Based Programming nesc TinyOS Scheduling Tiny Active Messaging TinyOS Multi Hop Routing

More information

Self-Organization in Autonomous Sensor/Actuator Networks [SelfOrg]

Self-Organization in Autonomous Sensor/Actuator Networks [SelfOrg] Self-Organization in Autonomous Sensor/Actuator Networks [SelfOrg] Dr.-Ing. Falko Dressler Computer Networks and Communication Systems Department of Computer Sciences University of Erlangen-Nürnberg http://www7.informatik.uni-erlangen.de/~dressler/

More information

Politecnico di Milano Advanced Network Technologies Laboratory. Internet of Things. TinyOS Programming and TOSSIM (and Cooja)

Politecnico di Milano Advanced Network Technologies Laboratory. Internet of Things. TinyOS Programming and TOSSIM (and Cooja) Politecnico di Milano Advanced Network Technologies Laboratory Internet of Things TinyOS Programming and TOSSIM (and Cooja) 19 March 2018 Agenda Playing with TinyOS Programming and components Blink Application

More information

Group Members: Chetan Fegade Nikhil Mascarenhas. Mentor: Dr. Yann Hang Lee

Group Members: Chetan Fegade Nikhil Mascarenhas. Mentor: Dr. Yann Hang Lee Group Members: Chetan Fegade Nikhil Mascarenhas Mentor: Dr. Yann Hang Lee 1. Introduction 2. TinyGALS programming model 3. TinyOS 4. NesC 5. Middleware 6. Conclusion 7. References 8. Q & A Event driven

More information

Sensor Network Application Development ZIGBEE CONCEPTS 2

Sensor Network Application Development ZIGBEE CONCEPTS 2 Sensor Network Application Development ZIGBEE CONCEPTS 2 Cruise Summerschool Johannes Kepler University November 5-7, 2007, Linz / Austria Dipl.-Ing. riener@pervasive.jku.at Overview Structure of this

More information

TinyOS. Lecture Overview. UC Berkeley Family of Motes. Mica2 and Mica2Dot. MTS300CA Sensor Board. Programming Board (MIB510) 1.

TinyOS. Lecture Overview. UC Berkeley Family of Motes. Mica2 and Mica2Dot. MTS300CA Sensor Board. Programming Board (MIB510) 1. Lecture Overview TinyOS Computer Network Programming Wenyuan Xu 1 2 UC Berkeley Family of Motes Mica2 and Mica2Dot ATmega128 CPU Self-programming 128KB Instruction EEPROM 4KB Data EEPROM Chipcon CC1000

More information

Motivation. Introduction to Wireless Sensor Networks. Office Building Fire. EEC173B Lecture:

Motivation. Introduction to Wireless Sensor Networks. Office Building Fire. EEC173B Lecture: EEC173B Lecture: Introduction to Wireless Sensor Networks Leo Szumel lpszumel@ucdavis.edu 3/22/2006 Image credit: www.dho.edu.tr/enstitunet/snetsim Motivation The standard networking problem: How to move

More information

WSN PLATFORMS, HARDWARE & SOFTWARE. Murat Demirbas SUNY Buffalo

WSN PLATFORMS, HARDWARE & SOFTWARE. Murat Demirbas SUNY Buffalo WSN PLATFORMS, HARDWARE & SOFTWARE Murat Demirbas SUNY Buffalo 1 Last lecture: Why use WSNs Ease of deployment: Wireless communication means no need for a communication infrastructure setup Low-cost of

More information

CS434/534: Topics in Networked (Networking) Systems

CS434/534: Topics in Networked (Networking) Systems CS434/534: Topics in Networked (Networking) Systems WSN/Mobile Systems Yang (Richard) Yang Computer Science Department Yale University 208A Watson Email: yry@cs.yale.edu http://zoo.cs.yale.edu/classes/cs434/

More information

Wireless Sensor Networks (WSN)

Wireless Sensor Networks (WSN) Wireless Sensor Networks (WSN) Operating Systems M. Schölzel Operating System Tasks Traditional OS Controlling and protecting access to resources (memory, I/O, computing resources) managing their allocation

More information

TinyOS. Wireless Sensor Networks

TinyOS. Wireless Sensor Networks TinyOS Laboratorio di Sistemi Wireless Ing. Telematica Università Kore Enna Ing. A. Leonardi Wireless Sensor Networks The number of nodes can be very high Nodes are densely deployed Low cost, low power

More information

Politecnico di Milano Advanced Network Technologies Laboratory. TinyOS

Politecnico di Milano Advanced Network Technologies Laboratory. TinyOS Politecnico di Milano Advanced Network Technologies Laboratory TinyOS Politecnico di Milano Advanced Network Technologies Laboratory A Bit of Context on WSNs Technology, Applications and Sensor Nodes WSN

More information

Sensors Network Simulators

Sensors Network Simulators Sensors Network Simulators Sensing Networking Qing Fang 10/14/05 Computation This Talk Not on how to run various network simulators Instead What differentiates various simulators Brief structures of the

More information

WSN Programming. Introduction. Olaf Landsiedel

WSN Programming. Introduction. Olaf Landsiedel WSN Programming Introduction Olaf Landsiedel Programming WSNs What do we need to write software for WSNs? (or: for any system, like your laptop, cell phone?) Programming language With compiler, etc. OS

More information

Porting TinyOS on to BTnodes

Porting TinyOS on to BTnodes Porting TinyOS on to BTnodes Attila Dogan-Kinali Winter Term 2004/2005 Student Thesis SA-2005-07 Supervisors: Jan Beutel, Matthias Dyer, Prof. Dr. Lothar Thiele Contents 1: Introduction 1 2: Related Work

More information

Politecnico di Milano Advanced Network Technologies Laboratory. Internet of Things. TinyOS Programming and TOSSIM

Politecnico di Milano Advanced Network Technologies Laboratory. Internet of Things. TinyOS Programming and TOSSIM Politecnico di Milano Advanced Network Technologies Laboratory Internet of Things TinyOS Programming and TOSSIM 11 April 2011 Agenda Playing with TinyOS Programming and components Blink Application Using

More information

BaseStation Based on GenericComm. Aly El-Osery Electrical Engineering Dept. New Mexico Tech Socorro, NM

BaseStation Based on GenericComm. Aly El-Osery Electrical Engineering Dept. New Mexico Tech Socorro, NM BaseStation Based on GenericComm Aly El-Osery Electrical Engineering Dept. New Mexico Tech Socorro, NM Scenario Have a node send a message to the basestation. Basestation forwards message to UART. Basestation

More information

Politecnico di Milano Advanced Network Technologies Laboratory. Internet of Things. TinyOS Programming and TOSSIM (and Cooja)

Politecnico di Milano Advanced Network Technologies Laboratory. Internet of Things. TinyOS Programming and TOSSIM (and Cooja) Politecnico di Milano Advanced Network Technologies Laboratory Internet of Things TinyOS Programming and TOSSIM (and Cooja) 20 April 2015 Agenda o Playing with TinyOS n Programming and components n Blink

More information

WSN Programming. Introduction. Olaf Landsiedel. Programming WSNs. ! What do we need to write software for WSNs?! Programming language

WSN Programming. Introduction. Olaf Landsiedel. Programming WSNs. ! What do we need to write software for WSNs?! Programming language WSN Programming Introduction Lecture 2 Olaf Landsiedel Programming WSNs! What do we need to write software for WSNs?! Programming language " With compiler, etc.! OS / runtime libraries " Access to system

More information

Übersicht. Laufzeitumgebungen Fallstudie TinyOS

Übersicht. Laufzeitumgebungen Fallstudie TinyOS Übersicht Beispielanwendungen Sensor-Hardware und Netzarchitektur Herausforderungen und Methoden MAC-Layer-Fallstudie IEEE 802.15.4 Energieeffiziente MAC-Layer WSN-Programmierung Laufzeitumgebungen Fallstudie

More information

System Architecture Directions for Networked Sensors. Jason Hill et. al. A Presentation by Dhyanesh Narayanan MS, CS (Systems)

System Architecture Directions for Networked Sensors. Jason Hill et. al. A Presentation by Dhyanesh Narayanan MS, CS (Systems) System Architecture Directions for Networked Sensors Jason Hill et. al. A Presentation by Dhyanesh Narayanan MS, CS (Systems) Sensor Networks Key Enablers Moore s s Law: More CPU Less Size Less Cost Systems

More information

Sensors as Software. TinyOS. TinyOS. Dario Rossi Motivation

Sensors as Software. TinyOS. TinyOS. Dario Rossi Motivation Sensors as Software Dario Rossi dario.rossi@polito.it Motivation Sensor networks Radically new computing environments Rapidly evolving hardware technology The key missing technology is system software

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

Operating systems for embedded systems. Embedded Operating Systems

Operating systems for embedded systems. Embedded Operating Systems Operating systems for embedded systems Embedded operating systems How do they differ from desktop operating systems? Programming model Process-based Event-based How is concurrency handled? How are resource

More information

Static Analysis of Embedded C

Static Analysis of Embedded C Static Analysis of Embedded C John Regehr University of Utah Joint work with Nathan Cooprider Motivating Platform: TinyOS Embedded software for wireless sensor network nodes Has lots of SW components for

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

Sensor Networks. Part 3: TinyOS. CATT Short Course, March 11, 2005 Mark Coates Mike Rabbat. Operating Systems 101

Sensor Networks. Part 3: TinyOS. CATT Short Course, March 11, 2005 Mark Coates Mike Rabbat. Operating Systems 101 Sensor Networks Part 3: TinyOS CATT Short Course, March 11, 2005 Mark Coates Mike Rabbat 1 Operating Systems 101 operating system (äp ǝr āt ing sis tǝm) n. 1 software that controls the operation of a computer

More information

EVENT DRIVEN SENSOR SYSTEMS

EVENT DRIVEN SENSOR SYSTEMS EVENT DRIVEN SENSOR SYSTEMS GROUP MEMBERS > 1. CHETAN FEGADE 1205166348 2. NIKHIL MASCARENHAS 1204752753 MENTOR > Dr. YANN-HANG LEE Submitted on December 11, 2012 2 INDEX 1. Introduction 3 2. TinyOS...

More information

Incremental Network Programming for Wireless Sensors. IEEE SECON 2004 Jaein Jeong and David Culler UC Berkeley, EECS

Incremental Network Programming for Wireless Sensors. IEEE SECON 2004 Jaein Jeong and David Culler UC Berkeley, EECS Incremental Network ming for Wireless Sensors IEEE SECON 2004 Jaein Jeong and David Culler UC Berkeley, EECS Introduction Loading to Wireless Sensors In System ming Most Common. ming time is in proportion

More information

Operating systems for embedded systems

Operating systems for embedded systems Operating systems for embedded systems Embedded operating systems How do they differ from desktop operating systems? Programming model Process-based Event-based How is concurrency handled? How are resource

More information

SpiNNaker Application Programming Interface (API)

SpiNNaker Application Programming Interface (API) SpiNNaker Application Programming Interface (API) Version 2.0.0 10 March 2016 Application programming interface (API) Event-driven programming model The SpiNNaker API programming model is a simple, event-driven

More information

System Architecture Directions for Networked Sensors[1]

System Architecture Directions for Networked Sensors[1] System Architecture Directions for Networked Sensors[1] Secure Sensor Networks Seminar presentation Eric Anderson System Architecture Directions for Networked Sensors[1] p. 1 Outline Sensor Network Characteristics

More information

Bluetooth low energy Protocol Stack

Bluetooth low energy Protocol Stack APPLICATION NOTE R01AN2768EJ0130 Rev.1.30 Introduction This manual describes how to develop an application using the Bluetooth low energy software (hereafter called BLE software), and overview of RWKE

More information

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

CprE 288 Introduction to Embedded Systems Exam 1 Review.  1 CprE 288 Introduction to Embedded Systems Exam 1 Review http://class.ece.iastate.edu/cpre288 1 Overview of Today s Lecture Announcements Exam 1 Review http://class.ece.iastate.edu/cpre288 2 Announcements

More information

COMP 7860 Embedded Real- Time Systems: Threads

COMP 7860 Embedded Real- Time Systems: Threads COMP 7860 Embedded Real- Time Systems: Threads Jacky Baltes Autonomous Agents Lab University of Manitoba Winnipeg, Canada R3T 2N2 Email: jacky@cs.umanitoba.ca WWW: http://www.cs.umanitoba.ca/~jacky http://aalab.cs.umanitoba.ca

More information

Lecture 15: I/O Devices & Drivers

Lecture 15: I/O Devices & Drivers CS 422/522 Design & Implementation of Operating Systems Lecture 15: I/O Devices & Drivers Zhong Shao Dept. of Computer Science Yale University Acknowledgement: some slides are taken from previous versions

More information

Threads and Concurrency

Threads and Concurrency Threads and Concurrency 1 Threads and Concurrency key concepts threads, concurrent execution, timesharing, context switch, interrupts, preemption reading Three Easy Pieces: Chapter 26 (Concurrency and

More information

Threads and Concurrency

Threads and Concurrency Threads and Concurrency 1 Threads and Concurrency key concepts threads, concurrent execution, timesharing, context switch, interrupts, preemption reading Three Easy Pieces: Chapter 26 (Concurrency and

More information

Designing Responsive and Real-Time Systems

Designing Responsive and Real-Time Systems Designing Responsive and Real-Time Systems Chapter 10 Renesas Electronics America Inc. Embedded Systems using the RX63N Rev. 1.0 00000-A Learning Objectives Most Embedded Systems have multiple real time

More information

Common Computer-System and OS Structures

Common Computer-System and OS Structures Common Computer-System and OS Structures Computer System Operation I/O Structure Storage Structure Storage Hierarchy Hardware Protection General System Architecture Oct-03 1 Computer-System Architecture

More information

The Emergence of Networking Abstractions and Techniques in TinyOS

The Emergence of Networking Abstractions and Techniques in TinyOS The Emergence of Networking Abstractions and Techniques in TinyOS CS295-1 Paper Presentation Mert Akdere 10.12.2005 Outline Problem Statement & Motivation Background Information TinyOS HW Platforms Sample

More information

The Emergence of Networking Abstractions and Techniques in TinyOS

The Emergence of Networking Abstractions and Techniques in TinyOS The Emergence of Networking Abstractions and Techniques in TinyOS Sam Madden MIT CSAIL madden@csail.mit.edu With Phil Levis, David Gay, Joe Polastre, Rob Szewczyk, Alec Woo, Eric Brewer, and David Culler

More information

This application note describes the specification of the JPEG codec unit (in the following, JCU) driver of SH7268/SH7269.

This application note describes the specification of the JPEG codec unit (in the following, JCU) driver of SH7268/SH7269. APPLICATION NOTE SH7268/7269 Group JPEG Codec Unit "JCU" Sample Driver R01AN2338EJ0104 Rev. 1.04 Introduction This application note describes the specification of the JPEG codec unit (in the following,

More information

The nesc Language: A Holistic Approach to Networked Embedded Systems

The nesc Language: A Holistic Approach to Networked Embedded Systems The nesc Language: A Holistic Approach to Networked Embedded Systems David Gay dgay@intel-research.net Matt Welsh mdw@intel-research.net http://nescc.sourceforge.net Philip Levis pal@cs.berkeley.edu Eric

More information

What we will learn. Threaded Systems: Threads. Threads. Threads. Bag of functions & procedures ST OS. AUCs. Threads. AUCs. Processes MT OS MP OS

What we will learn. Threaded Systems: Threads. Threads. Threads. Bag of functions & procedures ST OS. AUCs. Threads. AUCs. Processes MT OS MP OS What we will learn Threaded Systems: Threads A thread-driven approach is attractive in sensor networks for many of the same reasons that it has been adopted for PDAs, laptops, and servers. In a thread-driven

More information

Embedded Systems. 5. Operating Systems. Lothar Thiele. Computer Engineering and Networks Laboratory

Embedded Systems. 5. Operating Systems. Lothar Thiele. Computer Engineering and Networks Laboratory Embedded Systems 5. Operating Systems Lothar Thiele Computer Engineering and Networks Laboratory Embedded Operating Systems 5 2 Embedded Operating System (OS) Why an operating system (OS) at all? Same

More information

Technology Perspective

Technology Perspective Wireless Embedded Systems and Networking Foundations of IP-based Ubiquitous Sensor Networks Operating Systems for Communication-Centric Devices TinyOS-based IP-WSNs David E. Culler University of California,

More information

Sensor Networks. Dr. Sumi Helal & Jeff King CEN 5531

Sensor Networks. Dr. Sumi Helal & Jeff King CEN 5531 Sensor Networks CEN 5531 Slides adopted from presentations by Kirill Mechitov, David Culler, Joseph Polastre, Robert Szewczyk, Cory Sharp. Dr. Sumi Helal & Jeff King Computer & Information Science & Engineering

More information

AC OB S. Multi-threaded FW framework (OS) for embedded ARM systems Torsten Jaekel, June 2014

AC OB S. Multi-threaded FW framework (OS) for embedded ARM systems Torsten Jaekel, June 2014 AC OB S Multi-threaded FW framework (OS) for embedded ARM systems Torsten Jaekel, June 2014 ACOBS ACtive OBject (operating) System Simplified FW System for Multi-Threading on ARM embedded systems ACOBS

More information

CS3733: Operating Systems

CS3733: Operating Systems Outline CS3733: Operating Systems Topics: Synchronization, Critical Sections and Semaphores (SGG Chapter 6) Instructor: Dr. Tongping Liu 1 Memory Model of Multithreaded Programs Synchronization for coordinated

More information

Embedded Software TI2726 B. 4. Interrupts. Koen Langendoen. Embedded Software Group

Embedded Software TI2726 B. 4. Interrupts. Koen Langendoen. Embedded Software Group Embedded Software 4. Interrupts TI2726 B Koen Langendoen Embedded Software Group What is an Interrupt? Asynchronous signal from hardware Synchronous signal from software Indicates the need for attention

More information

Fundamental concept in computation Interrupt execution of a program to handle an event

Fundamental concept in computation Interrupt execution of a program to handle an event Interrupts Fundamental concept in computation Interrupt execution of a program to handle an event Don t have to rely on program relinquishing control Can code program without worrying about others Issues

More information

C Programming Review CSC 4320/6320

C Programming Review CSC 4320/6320 C Programming Review CSC 4320/6320 Overview Introduction C program Structure Keywords & C Types Input & Output Arrays Functions Pointers Structures LinkedList Dynamic Memory Allocation Macro Compile &

More information

Interrupts & Interrupt Service Routines (ISRs)

Interrupts & Interrupt Service Routines (ISRs) ECE3411 Fall 2015 Lecture 2c. Interrupts & Interrupt Service Routines (ISRs) Marten van Dijk, Syed Kamran Haider Department of Electrical & Computer Engineering University of Connecticut Email: vandijk,

More information

OCF for resource-constrained environments

OCF for resource-constrained environments October 11 13, 2016 Berlin, Germany OCF for resource-constrained environments Kishen Maloor, Intel 1 Outline Introduction Brief background in OCF Core Constrained environment charactertics IoTivity-Constrained

More information

Wireless Sensor Networks. Introduction to the Laboratory

Wireless Sensor Networks. Introduction to the Laboratory Wireless Sensor Networks Introduction to the Laboratory c.buratti@unibo.it +39 051 20 93147 Office Hours: Tuesday 3 5 pm @ Main Building, third floor Credits: 6 Outline MC1322x Devices IAR Embedded workbench

More information

Lecture 3. Introduction to Real-Time kernels. Real-Time Systems

Lecture 3. Introduction to Real-Time kernels. Real-Time Systems Real-Time Systems Lecture 3 Introduction to Real-Time kernels Task States Generic architecture of Real-Time kernels Typical structures and functions of Real-Time kernels Last lecture (2) Computational

More information

EL6483: Brief Overview of C Programming Language

EL6483: Brief Overview of C Programming Language EL6483: Brief Overview of C Programming Language EL6483 Spring 2016 EL6483 EL6483: Brief Overview of C Programming Language Spring 2016 1 / 30 Preprocessor macros, Syntax for comments Macro definitions

More information

Incremental Network Programming for Wireless Sensors

Incremental Network Programming for Wireless Sensors Incremental Network Programming for Wireless Sensors Jaein Jeong Electrical Engineering and Computer Sciences University of California at Berkeley Technical Report No. UCB/EECS-2005-17 http://www.eecs.berkeley.edu/pubs/techrpts/2005/eecs-2005-17.html

More information

Introduction to TinyOS

Introduction to TinyOS Fakultät Informatik Institut für Systemarchitektur Professur Rechnernetze Introduction to TinyOS Jianjun Wen 21.04.2016 Outline Hardware Platforms Introduction to TinyOS Environment Setup Project of This

More information

Embedded Systems Programming - PA8001

Embedded Systems Programming - PA8001 Embedded Systems Programming - PA8001 http://bit.ly/15mmqf7 Lecture 5 Mohammad Mousavi m.r.mousavi@hh.se Center for Research on Embedded Systems School of Information Science, Computer and Electrical Engineering

More information

Final Exam. 11 May 2018, 120 minutes, 26 questions, 100 points

Final Exam. 11 May 2018, 120 minutes, 26 questions, 100 points Name: CS520 Final Exam 11 May 2018, 120 minutes, 26 questions, 100 points The exam is closed book and notes. Please keep all electronic devices turned off and out of reach. Note that a question may require

More information

Lecture Topics. Announcements. Today: Operating System Overview (Stallings, chapter , ) Next: Processes (Stallings, chapter

Lecture Topics. Announcements. Today: Operating System Overview (Stallings, chapter , ) Next: Processes (Stallings, chapter Lecture Topics Today: Operating System Overview (Stallings, chapter 2.1-2.4, 2.8-2.10) Next: Processes (Stallings, chapter 3.1-3.6) 1 Announcements Consulting hours posted Self-Study Exercise #3 posted

More information

Tokens, Expressions and Control Structures

Tokens, Expressions and Control Structures 3 Tokens, Expressions and Control Structures Tokens Keywords Identifiers Data types User-defined types Derived types Symbolic constants Declaration of variables Initialization Reference variables Type

More information

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor CS 261 Fall 2017 Mike Lam, Professor C Introduction Variables, Memory Model, Pointers, and Debugging The C Language Systems language originally developed for Unix Imperative, compiled language with static

More information

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - III Processes. Louisiana State University. Processes. September 1 st, 2009

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - III Processes. Louisiana State University. Processes. September 1 st, 2009 CSC 4103 - Operating Systems Fall 2009 Lecture - III Processes Tevfik Ko!ar Louisiana State University September 1 st, 2009 1 Roadmap Processes Basic Concepts Process Creation Process Termination Context

More information

Hardware OS & OS- Application interface

Hardware OS & OS- Application interface CS 4410 Operating Systems Hardware OS & OS- Application interface Summer 2013 Cornell University 1 Today How my device becomes useful for the user? HW-OS interface Device controller Device driver Interrupts

More information

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu History and Evolution of Programming Languages 1. Explain the relationship between machine

More information

Simulation of Sensor Network

Simulation of Sensor Network Simulation of Sensor Network The NS 2 & The nesc NS 2 based SensorSim & TOSSIM for Mote Contents 1. Sensor Network Simulator 2. About the NS 2 3. NS 2 Primer 4. NS 2 based SensorSim 5. About the nesc 6.

More information

Enabling Networked Sensors

Enabling Networked Sensors Politecnico di Milano Advanced Network Technologies Laboratory Enabling Networked Sensors A Primer on TinyOS Ing. Matteo Cesana Office: DEI 3 Floor Room 335 Email: cesana@elet.polimi.it Phone: 0223993695

More information

CS C Primer. Tyler Szepesi. January 16, 2013

CS C Primer. Tyler Szepesi. January 16, 2013 January 16, 2013 Topics 1 Why C? 2 Data Types 3 Memory 4 Files 5 Endianness 6 Resources Why C? C is exteremely flexible and gives control to the programmer Allows users to break rigid rules, which are

More information

CMPE-013/L. Introduction to C Programming

CMPE-013/L. Introduction to C Programming CMPE-013/L Introduction to C Programming Bryant Wenborg Mairs Spring 2014 What we will cover in 13/L Embedded C on a microcontroller Specific issues with microcontrollers Peripheral usage Reading documentation

More information

CS 160: Interactive Programming

CS 160: Interactive Programming CS 160: Interactive Programming Professor John Canny 3/8/2006 1 Outline Callbacks and Delegates Multi-threaded programming Model-view controller 3/8/2006 2 Callbacks Your code Myclass data method1 method2

More information

The Big Picture So Far. Chapter 4: Processes

The Big Picture So Far. Chapter 4: Processes The Big Picture So Far HW Abstraction Processor Memory IO devices File system Distributed systems Example OS Services Process management, protection, synchronization Memory Protection, management, VM Interrupt

More information

! The Process Control Block (PCB) " is included in the context,

! The Process Control Block (PCB)  is included in the context, CSE 421/521 - Operating Systems Fall 2012 Lecture - III Processes Tevfik Koşar Roadmap Processes Basic Concepts Process Creation Process Termination Context Switching Process Queues Process Scheduling

More information

Asynchronous Events on Linux

Asynchronous Events on Linux Asynchronous Events on Linux Frederic.Rossi@Ericsson.CA Open System Lab Systems Research June 25, 2002 Ericsson Research Canada Introduction Linux performs well as a general purpose OS but doesn t satisfy

More information

8032 MCU + Soft Modules. c = rcvdata; // get the keyboard scan code

8032 MCU + Soft Modules. c = rcvdata; // get the keyboard scan code 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 { 0x25, 0x66 }, // "4" { 0x2E, 0x6D }, // "5" { 0x36, 0x7D }, // "6" { 0x3D, 0x07 }, // "7" { 0x3E, 0x7F }, // "8" { 0x46,

More information

Advanced use of the C language

Advanced use of the C language Advanced use of the C language Content Why to use C language Differences from Java Object oriented programming in C Usage of C preprocessor Coding standards Compiler optimizations C99 and C11 Standards

More information

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology exam Embedded Software TI2726-B January 28, 2019 13.30-15.00 This exam (6 pages) consists of 60 True/False

More information

Towards a Resilient Operating System for Wireless Sensor Networks

Towards a Resilient Operating System for Wireless Sensor Networks Towards a Resilient Operating System for Wireless Sensor Networks Hyoseung Kim Hojung Cha Yonsei University, Korea 2006. 6. 1. Hyoseung Kim hskim@cs.yonsei.ac.kr Motivation (1) Problems: Application errors

More information

Chapter 3: Processes. Operating System Concepts 8th Edition, modified by Stewart Weiss

Chapter 3: Processes. Operating System Concepts 8th Edition, modified by Stewart Weiss Chapter 3: Processes Operating System Concepts 8 Edition, Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication

More information

Lecture #17 Concurrency Embedded System Engineering Philip Koopman Monday, 21-March-2016 Example application Remote Keyless Entry

Lecture #17 Concurrency Embedded System Engineering Philip Koopman Monday, 21-March-2016 Example application Remote Keyless Entry Lecture #17 Concurrency 18-348 Embedded System Engineering Philip Koopman Monday, 21-March-2016 Electrical& Computer ENGINEERING Copyright 2006-2016, Philip Koopman, All Rights Reserved Example application

More information

Lecture #17 Concurrency Embedded System Engineering Philip Koopman Monday, 21-March-2016

Lecture #17 Concurrency Embedded System Engineering Philip Koopman Monday, 21-March-2016 Lecture #17 Concurrency 18-348 Embedded System Engineering Philip Koopman Monday, 21-March-2016 Electrical& Computer ENGINEERING Copyright 2006-2016, Philip Koopman, All Rights Reserved Example application

More information

Lectures 5-6: Introduction to C

Lectures 5-6: Introduction to C Lectures 5-6: Introduction to C Motivation: C is both a high and a low-level language Very useful for systems programming Faster than Java This intro assumes knowledge of Java Focus is on differences Most

More information

Bare Metal Application Design, Interrupts & Timers

Bare Metal Application Design, Interrupts & Timers Topics 1) How does hardware notify software of an event? Bare Metal Application Design, Interrupts & Timers 2) What architectural design is used for bare metal? 3) How can we get accurate timing? 4) How

More information

Inter-Context Control-Flow Graph for NesC, with Improved Split-Phase Handling

Inter-Context Control-Flow Graph for NesC, with Improved Split-Phase Handling Inter-Context Control-Flow Graph for NesC, with Improved Split-Phase Handling Arne Wichmann Institute for Software Systems July 30, 2010 Abstract Control-flow graphs (CFG) are a common intermediate representation

More information

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology exam Embedded Software TI2726-B January 29, 2018 13.30-15.00 This exam (6 pages) consists of 60 True/False

More information

A Deterministic Concurrent Language for Embedded Systems

A Deterministic Concurrent Language for Embedded Systems A Deterministic Concurrent Language for Embedded Systems Stephen A. Edwards Columbia University Joint work with Olivier Tardieu SHIM:A Deterministic Concurrent Language for Embedded Systems p. 1/38 Definition

More information