29.11.2012 Views

t - SICS

t - SICS

t - SICS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Radio on<br />

Radio off<br />

Protothreads-based implementation<br />

t 0<br />

t awake<br />

t wait_max<br />

t sleep<br />

Communication left…<br />

int protothread(struct pt *pt) {<br />

PT_BEGIN(pt);<br />

while(1) {<br />

radio_on();<br />

timer = t_awake;<br />

PT_WAIT_UNTIL(pt, expired(timer));<br />

timer = t_sleep;<br />

if(!comm_complete()) {<br />

wait_timer = t_wait_max;<br />

PT_WAIT_UNTIL(pt, comm_complete()<br />

|| expired(wait_timer));<br />

}<br />

radio off();<br />

PT_WAIT_UNTIL(pt, expired(timer));<br />

}<br />

PT_END(pt);<br />

}<br />

• Code uses structured programming (if and while), mechanisms<br />

evident from code<br />

→Protothreads make Contiki code nice

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!