<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://anrg.usc.edu/contiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Timothy</id>
		<title>Contiki - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="http://anrg.usc.edu/contiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Timothy"/>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php/Special:Contributions/Timothy"/>
		<updated>2026-05-06T06:06:31Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.26.2</generator>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Meeting_Logs&amp;diff=401</id>
		<title>Meeting Logs</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Meeting_Logs&amp;diff=401"/>
				<updated>2014-04-14T20:23:34Z</updated>
		
		<summary type="html">&lt;p&gt;Timothy: /* Apr/11 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Feb/7 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Kwame&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Professor Bhaskar gave us his wishlist. See a brief outline at [[Wishlist]].&lt;br /&gt;
&lt;br /&gt;
We got the Contiki oscilloscope up and running, and played around with it using two motes.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Suvil is going to investigate options for a mailing list and also get the issue with uploading images to the wiki fixed.&lt;br /&gt;
&lt;br /&gt;
Nikhil will set up a Google Drive share for us to use for prototyping our tutorials when appropriate. It would allow for us to collaboratively edit in real-time and provide us all the conveniences of a modern word processor (spell check, etc.) We should probably discuss this more next time.&lt;br /&gt;
&lt;br /&gt;
Yash will spend the time catching up and going through our existing tutorials.&lt;br /&gt;
&lt;br /&gt;
Lakshmi has graciously volunteered to present Cristian&amp;#039;s algorithm to us.&lt;br /&gt;
&lt;br /&gt;
Nikhil, Bhavana, Rahul, and Deepanker will start a new tutorial for using the Oscilloscope.&lt;br /&gt;
&lt;br /&gt;
Kevin will explore methods for on-board data storage on the sky mote, both volatile and non-volatile.&lt;br /&gt;
&lt;br /&gt;
Pedro, Suvil, and Kwame will work on running Contiki on the testbed and starting a tutorial. Also, thinking about how we can refactor some of our theoretical tutorials to be more activity oriented.&lt;br /&gt;
&lt;br /&gt;
Everyone should update their tutorials to include the primary contributors. Perhaps somewhere at the end.&lt;br /&gt;
&lt;br /&gt;
== Feb/14 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Pedro&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Lakshmi presented the paper [[Probabilistic Clock Synchronization http://kom.aau.dk/~rlo/lectures/algoAndArchIII_2009/ChristiansAlgorithm.pdf]]. We had a very interesting discussion about the terms and concepts behind synchronization and clock in network nodes. We might in the future see how this algorithm can be implemented in a WSN or check whether its main ideas are already implemented in the &amp;quot;Implicit network time synchronization&amp;quot;, present in ContikiOS ([http://contiki.sourceforge.net/docs/2.6/a01741.html])&lt;br /&gt;
&lt;br /&gt;
Everyone gave an updated about what have been done during last week. We have some material for two tutorials: the &amp;#039;&amp;#039;Oscilloscope&amp;#039;&amp;#039; and &amp;#039;&amp;#039;Coffee File System&amp;#039;&amp;#039;. This material is yet in the Google Doc create for prototyping and should be posted in the Wiki soon.&lt;br /&gt;
&lt;br /&gt;
Kwame guided the group in the first 4 sessions of ContikiOS Crash Course [[File:Seniot09cccc-notes.pdf]]. We played with LEDs and push button. This example should give a new tutorial on how to use all the sensors/actuators (light, temperature, push button, etc.) on the motes.&lt;br /&gt;
&lt;br /&gt;
We decided that each week one person will be responsible for creating this meeting log, so everyone can keep track of what has been discussed every week. Below we have the expected date of our next meetings and a tentative assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Kevin will give a brief talk about Coffee file system and show us the material he obtained and the tutorial he started to write.&lt;br /&gt;
&lt;br /&gt;
Yash will start to study and collect material about processes and protothreads. He may give a talk about these topics in two weeks.&lt;br /&gt;
&lt;br /&gt;
Nikhil, Bhavana, Rahul, and Deepanker will keep working on the Oscilloscope tutorial.&lt;br /&gt;
&lt;br /&gt;
Pedro and Kwame will start to work on the Tutornet testbed.&lt;br /&gt;
&lt;br /&gt;
Suvil will fix some issues we are facing in the Wiki with code formatting and help us with account creation/setup of the testbed.&lt;br /&gt;
&lt;br /&gt;
== Feb/21 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Suvil&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Kevin gave a presentation about Coffee File System. He showed the main interface and functions that can be used by Tmote Sky. He also showed an example where a node was programmed to create and write 3 different files on Flash Memory and after reboot output the content of the files reading then from the memory. The presentation slides can be found here:[] and the example code can be found here:[]. He started to create a tutorial on Coffee on the shared Doc file and you may create a tutorial about this topic in our Wiki soon.&lt;br /&gt;
&lt;br /&gt;
We went through the example in: examples/rime/example-neighbors.c, suggested by Bhavana. Basically this example makes all node generate beacons and create a list of neighbors of each node. It prints out the list of neighbors with the corresponding RSSI value.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
We should continue to work on the tutorials, trying to polish and review them for final publication.&lt;br /&gt;
&lt;br /&gt;
== Feb/28 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Leo&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Pedro gave a presentation of a few of the features available in the Cooja simulator. Some of what he covered, which will be put in the Cooja tutorial, includes how to build Cooja from the terminal and automatically start a simulation, locate source files for debugging, and use the single-step and breakpoint debugging tools available for debugging each node. Afterwards, we looked at examples-neighbors.c in more detail, noting the size of the data structures and the way certain values were calculated, such as RSSI. Lastly, we briefly looked over some of the Contiki OS files in the documentation and flipped through a comprehensive Contiki presentation here [http://www.ee.kth.se/~mikaelj/wsn_course/contiki-course-kth-9oct2008-draft.pdf].&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Several more tutorials should be done by our next meeting.&lt;br /&gt;
&lt;br /&gt;
== Mar/07 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Nikhil&lt;br /&gt;
&lt;br /&gt;
== Mar/14 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Kwame&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Yash gave a presentation on Processes and Protothreads. The group expressed interest in learning more about the hardware behind the Tmote Sky, such as the TI MSP430 microprocessor and the CC2420 radio. We&amp;#039;ll probably include some of those as the topic of future talks.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Enjoy Spring Break!&lt;br /&gt;
&lt;br /&gt;
== Mar/21 ==&lt;br /&gt;
&lt;br /&gt;
Spring Break, no meeting&lt;br /&gt;
&lt;br /&gt;
== Mar/28 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Deepanker&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
We successfully programmed a multi-hop communication between 5 motes. We also discussed the ways in which motes can talk to each other, namely - unicast, multicast and reliable unicast - and discussed the pros and cons of each with respect to our application.&lt;br /&gt;
&lt;br /&gt;
We discussed a little bit about the connections on the mote, specifically the interaction of MSP430 with CC2420.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Yash will give an introduction to MSP430. Completion of tutorials on wiki and proofreading of the already completed will be done by the people who are assigned the task.&lt;br /&gt;
&lt;br /&gt;
== Apr/04 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Kevin&lt;br /&gt;
Bhavana introduced us how to use Shell in a process. We went through some instructions and source code to understand how it works. Also, we ran an example on the Sky-Mote and tried the Blink instruction. Everything worked good.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Yash will give an introduction to MSP430.&lt;br /&gt;
&lt;br /&gt;
== Apr/11 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Timothy&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting Summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Yash presents the Radio Transceiver:&lt;br /&gt;
&lt;br /&gt;
Gave a brief overview of Tmote hardware&lt;br /&gt;
&lt;br /&gt;
Discussed the radio as main communication module&lt;br /&gt;
&lt;br /&gt;
Gave an overview of QPSK, and how Tmote uses OQPSK to modulate signal&lt;br /&gt;
&lt;br /&gt;
Went over frame format of transmission&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Pedro will present next week, and Kwame the week after. Assigned several new tutorials, agreed to write up Telephone Game as a tutorial.&lt;br /&gt;
&lt;br /&gt;
== Apr/18 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Bhavana&lt;/div&gt;</summary>
		<author><name>Timothy</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Meeting_Logs&amp;diff=400</id>
		<title>Meeting Logs</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Meeting_Logs&amp;diff=400"/>
				<updated>2014-04-14T20:20:08Z</updated>
		
		<summary type="html">&lt;p&gt;Timothy: /* Apr/11 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Feb/7 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Kwame&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Professor Bhaskar gave us his wishlist. See a brief outline at [[Wishlist]].&lt;br /&gt;
&lt;br /&gt;
We got the Contiki oscilloscope up and running, and played around with it using two motes.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Suvil is going to investigate options for a mailing list and also get the issue with uploading images to the wiki fixed.&lt;br /&gt;
&lt;br /&gt;
Nikhil will set up a Google Drive share for us to use for prototyping our tutorials when appropriate. It would allow for us to collaboratively edit in real-time and provide us all the conveniences of a modern word processor (spell check, etc.) We should probably discuss this more next time.&lt;br /&gt;
&lt;br /&gt;
Yash will spend the time catching up and going through our existing tutorials.&lt;br /&gt;
&lt;br /&gt;
Lakshmi has graciously volunteered to present Cristian&amp;#039;s algorithm to us.&lt;br /&gt;
&lt;br /&gt;
Nikhil, Bhavana, Rahul, and Deepanker will start a new tutorial for using the Oscilloscope.&lt;br /&gt;
&lt;br /&gt;
Kevin will explore methods for on-board data storage on the sky mote, both volatile and non-volatile.&lt;br /&gt;
&lt;br /&gt;
Pedro, Suvil, and Kwame will work on running Contiki on the testbed and starting a tutorial. Also, thinking about how we can refactor some of our theoretical tutorials to be more activity oriented.&lt;br /&gt;
&lt;br /&gt;
Everyone should update their tutorials to include the primary contributors. Perhaps somewhere at the end.&lt;br /&gt;
&lt;br /&gt;
== Feb/14 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Pedro&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Lakshmi presented the paper [[Probabilistic Clock Synchronization http://kom.aau.dk/~rlo/lectures/algoAndArchIII_2009/ChristiansAlgorithm.pdf]]. We had a very interesting discussion about the terms and concepts behind synchronization and clock in network nodes. We might in the future see how this algorithm can be implemented in a WSN or check whether its main ideas are already implemented in the &amp;quot;Implicit network time synchronization&amp;quot;, present in ContikiOS ([http://contiki.sourceforge.net/docs/2.6/a01741.html])&lt;br /&gt;
&lt;br /&gt;
Everyone gave an updated about what have been done during last week. We have some material for two tutorials: the &amp;#039;&amp;#039;Oscilloscope&amp;#039;&amp;#039; and &amp;#039;&amp;#039;Coffee File System&amp;#039;&amp;#039;. This material is yet in the Google Doc create for prototyping and should be posted in the Wiki soon.&lt;br /&gt;
&lt;br /&gt;
Kwame guided the group in the first 4 sessions of ContikiOS Crash Course [[File:Seniot09cccc-notes.pdf]]. We played with LEDs and push button. This example should give a new tutorial on how to use all the sensors/actuators (light, temperature, push button, etc.) on the motes.&lt;br /&gt;
&lt;br /&gt;
We decided that each week one person will be responsible for creating this meeting log, so everyone can keep track of what has been discussed every week. Below we have the expected date of our next meetings and a tentative assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Kevin will give a brief talk about Coffee file system and show us the material he obtained and the tutorial he started to write.&lt;br /&gt;
&lt;br /&gt;
Yash will start to study and collect material about processes and protothreads. He may give a talk about these topics in two weeks.&lt;br /&gt;
&lt;br /&gt;
Nikhil, Bhavana, Rahul, and Deepanker will keep working on the Oscilloscope tutorial.&lt;br /&gt;
&lt;br /&gt;
Pedro and Kwame will start to work on the Tutornet testbed.&lt;br /&gt;
&lt;br /&gt;
Suvil will fix some issues we are facing in the Wiki with code formatting and help us with account creation/setup of the testbed.&lt;br /&gt;
&lt;br /&gt;
== Feb/21 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Suvil&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Kevin gave a presentation about Coffee File System. He showed the main interface and functions that can be used by Tmote Sky. He also showed an example where a node was programmed to create and write 3 different files on Flash Memory and after reboot output the content of the files reading then from the memory. The presentation slides can be found here:[] and the example code can be found here:[]. He started to create a tutorial on Coffee on the shared Doc file and you may create a tutorial about this topic in our Wiki soon.&lt;br /&gt;
&lt;br /&gt;
We went through the example in: examples/rime/example-neighbors.c, suggested by Bhavana. Basically this example makes all node generate beacons and create a list of neighbors of each node. It prints out the list of neighbors with the corresponding RSSI value.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
We should continue to work on the tutorials, trying to polish and review them for final publication.&lt;br /&gt;
&lt;br /&gt;
== Feb/28 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Leo&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Pedro gave a presentation of a few of the features available in the Cooja simulator. Some of what he covered, which will be put in the Cooja tutorial, includes how to build Cooja from the terminal and automatically start a simulation, locate source files for debugging, and use the single-step and breakpoint debugging tools available for debugging each node. Afterwards, we looked at examples-neighbors.c in more detail, noting the size of the data structures and the way certain values were calculated, such as RSSI. Lastly, we briefly looked over some of the Contiki OS files in the documentation and flipped through a comprehensive Contiki presentation here [http://www.ee.kth.se/~mikaelj/wsn_course/contiki-course-kth-9oct2008-draft.pdf].&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Several more tutorials should be done by our next meeting.&lt;br /&gt;
&lt;br /&gt;
== Mar/07 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Nikhil&lt;br /&gt;
&lt;br /&gt;
== Mar/14 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Kwame&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Yash gave a presentation on Processes and Protothreads. The group expressed interest in learning more about the hardware behind the Tmote Sky, such as the TI MSP430 microprocessor and the CC2420 radio. We&amp;#039;ll probably include some of those as the topic of future talks.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Enjoy Spring Break!&lt;br /&gt;
&lt;br /&gt;
== Mar/21 ==&lt;br /&gt;
&lt;br /&gt;
Spring Break, no meeting&lt;br /&gt;
&lt;br /&gt;
== Mar/28 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Deepanker&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
We successfully programmed a multi-hop communication between 5 motes. We also discussed the ways in which motes can talk to each other, namely - unicast, multicast and reliable unicast - and discussed the pros and cons of each with respect to our application.&lt;br /&gt;
&lt;br /&gt;
We discussed a little bit about the connections on the mote, specifically the interaction of MSP430 with CC2420.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Yash will give an introduction to MSP430. Completion of tutorials on wiki and proofreading of the already completed will be done by the people who are assigned the task.&lt;br /&gt;
&lt;br /&gt;
== Apr/04 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Kevin&lt;br /&gt;
Bhavana introduced us how to use Shell in a process. We went through some instructions and source code to understand how it works. Also, we ran an example on the Sky-Mote and tried the Blink instruction. Everything worked good.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Yash will give an introduction to MSP430.&lt;br /&gt;
&lt;br /&gt;
== Apr/11 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Timothy&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting Summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Yash presents Radio Transceiver:&lt;br /&gt;
Brief Overview of Tmote hardware&lt;br /&gt;
Radio is main communication module&lt;br /&gt;
Overview of QPSK, Tmote uses OQPSK to modulate signal&lt;br /&gt;
Went over frame format of transmission&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Pedro will present next week, and Kwame the week after. Assigned several new tutorials, agreed to write up Telephone Game as a tutorial.&lt;br /&gt;
&lt;br /&gt;
== Apr/18 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Bhavana&lt;/div&gt;</summary>
		<author><name>Timothy</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Meeting_Logs&amp;diff=399</id>
		<title>Meeting Logs</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Meeting_Logs&amp;diff=399"/>
				<updated>2014-04-14T20:18:58Z</updated>
		
		<summary type="html">&lt;p&gt;Timothy: /* Apr/11 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Feb/7 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Kwame&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Professor Bhaskar gave us his wishlist. See a brief outline at [[Wishlist]].&lt;br /&gt;
&lt;br /&gt;
We got the Contiki oscilloscope up and running, and played around with it using two motes.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Suvil is going to investigate options for a mailing list and also get the issue with uploading images to the wiki fixed.&lt;br /&gt;
&lt;br /&gt;
Nikhil will set up a Google Drive share for us to use for prototyping our tutorials when appropriate. It would allow for us to collaboratively edit in real-time and provide us all the conveniences of a modern word processor (spell check, etc.) We should probably discuss this more next time.&lt;br /&gt;
&lt;br /&gt;
Yash will spend the time catching up and going through our existing tutorials.&lt;br /&gt;
&lt;br /&gt;
Lakshmi has graciously volunteered to present Cristian&amp;#039;s algorithm to us.&lt;br /&gt;
&lt;br /&gt;
Nikhil, Bhavana, Rahul, and Deepanker will start a new tutorial for using the Oscilloscope.&lt;br /&gt;
&lt;br /&gt;
Kevin will explore methods for on-board data storage on the sky mote, both volatile and non-volatile.&lt;br /&gt;
&lt;br /&gt;
Pedro, Suvil, and Kwame will work on running Contiki on the testbed and starting a tutorial. Also, thinking about how we can refactor some of our theoretical tutorials to be more activity oriented.&lt;br /&gt;
&lt;br /&gt;
Everyone should update their tutorials to include the primary contributors. Perhaps somewhere at the end.&lt;br /&gt;
&lt;br /&gt;
== Feb/14 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Pedro&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Lakshmi presented the paper [[Probabilistic Clock Synchronization http://kom.aau.dk/~rlo/lectures/algoAndArchIII_2009/ChristiansAlgorithm.pdf]]. We had a very interesting discussion about the terms and concepts behind synchronization and clock in network nodes. We might in the future see how this algorithm can be implemented in a WSN or check whether its main ideas are already implemented in the &amp;quot;Implicit network time synchronization&amp;quot;, present in ContikiOS ([http://contiki.sourceforge.net/docs/2.6/a01741.html])&lt;br /&gt;
&lt;br /&gt;
Everyone gave an updated about what have been done during last week. We have some material for two tutorials: the &amp;#039;&amp;#039;Oscilloscope&amp;#039;&amp;#039; and &amp;#039;&amp;#039;Coffee File System&amp;#039;&amp;#039;. This material is yet in the Google Doc create for prototyping and should be posted in the Wiki soon.&lt;br /&gt;
&lt;br /&gt;
Kwame guided the group in the first 4 sessions of ContikiOS Crash Course [[File:Seniot09cccc-notes.pdf]]. We played with LEDs and push button. This example should give a new tutorial on how to use all the sensors/actuators (light, temperature, push button, etc.) on the motes.&lt;br /&gt;
&lt;br /&gt;
We decided that each week one person will be responsible for creating this meeting log, so everyone can keep track of what has been discussed every week. Below we have the expected date of our next meetings and a tentative assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Kevin will give a brief talk about Coffee file system and show us the material he obtained and the tutorial he started to write.&lt;br /&gt;
&lt;br /&gt;
Yash will start to study and collect material about processes and protothreads. He may give a talk about these topics in two weeks.&lt;br /&gt;
&lt;br /&gt;
Nikhil, Bhavana, Rahul, and Deepanker will keep working on the Oscilloscope tutorial.&lt;br /&gt;
&lt;br /&gt;
Pedro and Kwame will start to work on the Tutornet testbed.&lt;br /&gt;
&lt;br /&gt;
Suvil will fix some issues we are facing in the Wiki with code formatting and help us with account creation/setup of the testbed.&lt;br /&gt;
&lt;br /&gt;
== Feb/21 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Suvil&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Kevin gave a presentation about Coffee File System. He showed the main interface and functions that can be used by Tmote Sky. He also showed an example where a node was programmed to create and write 3 different files on Flash Memory and after reboot output the content of the files reading then from the memory. The presentation slides can be found here:[] and the example code can be found here:[]. He started to create a tutorial on Coffee on the shared Doc file and you may create a tutorial about this topic in our Wiki soon.&lt;br /&gt;
&lt;br /&gt;
We went through the example in: examples/rime/example-neighbors.c, suggested by Bhavana. Basically this example makes all node generate beacons and create a list of neighbors of each node. It prints out the list of neighbors with the corresponding RSSI value.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
We should continue to work on the tutorials, trying to polish and review them for final publication.&lt;br /&gt;
&lt;br /&gt;
== Feb/28 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Leo&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Pedro gave a presentation of a few of the features available in the Cooja simulator. Some of what he covered, which will be put in the Cooja tutorial, includes how to build Cooja from the terminal and automatically start a simulation, locate source files for debugging, and use the single-step and breakpoint debugging tools available for debugging each node. Afterwards, we looked at examples-neighbors.c in more detail, noting the size of the data structures and the way certain values were calculated, such as RSSI. Lastly, we briefly looked over some of the Contiki OS files in the documentation and flipped through a comprehensive Contiki presentation here [http://www.ee.kth.se/~mikaelj/wsn_course/contiki-course-kth-9oct2008-draft.pdf].&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Several more tutorials should be done by our next meeting.&lt;br /&gt;
&lt;br /&gt;
== Mar/07 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Nikhil&lt;br /&gt;
&lt;br /&gt;
== Mar/14 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Kwame&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Yash gave a presentation on Processes and Protothreads. The group expressed interest in learning more about the hardware behind the Tmote Sky, such as the TI MSP430 microprocessor and the CC2420 radio. We&amp;#039;ll probably include some of those as the topic of future talks.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Enjoy Spring Break!&lt;br /&gt;
&lt;br /&gt;
== Mar/21 ==&lt;br /&gt;
&lt;br /&gt;
Spring Break, no meeting&lt;br /&gt;
&lt;br /&gt;
== Mar/28 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Deepanker&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
We successfully programmed a multi-hop communication between 5 motes. We also discussed the ways in which motes can talk to each other, namely - unicast, multicast and reliable unicast - and discussed the pros and cons of each with respect to our application.&lt;br /&gt;
&lt;br /&gt;
We discussed a little bit about the connections on the mote, specifically the interaction of MSP430 with CC2420.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Yash will give an introduction to MSP430. Completion of tutorials on wiki and proofreading of the already completed will be done by the people who are assigned the task.&lt;br /&gt;
&lt;br /&gt;
== Apr/04 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Kevin&lt;br /&gt;
Bhavana introduced us how to use Shell in a process. We went through some instructions and source code to understand how it works. Also, we ran an example on the Sky-Mote and tried the Blink instruction. Everything worked good.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Yash will give an introduction to MSP430.&lt;br /&gt;
&lt;br /&gt;
== Apr/11 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Timothy&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting Summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Yash presents Radio Transceiver:&lt;br /&gt;
Brief Overview of Tmote hardware&lt;br /&gt;
Radio is main communication module&lt;br /&gt;
Overview of QPSK, Tmote uses OQPSK to modulate signal&lt;br /&gt;
Went over frame format of transmission&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Pedro will present next week, and Kwame the week after. Assigned several new tutorials, agreed to write up Telephone Game as a tutorial.&lt;br /&gt;
&lt;br /&gt;
== Apr/18 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Bhavana&lt;/div&gt;</summary>
		<author><name>Timothy</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Meeting_Logs&amp;diff=398</id>
		<title>Meeting Logs</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Meeting_Logs&amp;diff=398"/>
				<updated>2014-04-14T20:18:14Z</updated>
		
		<summary type="html">&lt;p&gt;Timothy: /* Apr/11 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Feb/7 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Kwame&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Professor Bhaskar gave us his wishlist. See a brief outline at [[Wishlist]].&lt;br /&gt;
&lt;br /&gt;
We got the Contiki oscilloscope up and running, and played around with it using two motes.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Suvil is going to investigate options for a mailing list and also get the issue with uploading images to the wiki fixed.&lt;br /&gt;
&lt;br /&gt;
Nikhil will set up a Google Drive share for us to use for prototyping our tutorials when appropriate. It would allow for us to collaboratively edit in real-time and provide us all the conveniences of a modern word processor (spell check, etc.) We should probably discuss this more next time.&lt;br /&gt;
&lt;br /&gt;
Yash will spend the time catching up and going through our existing tutorials.&lt;br /&gt;
&lt;br /&gt;
Lakshmi has graciously volunteered to present Cristian&amp;#039;s algorithm to us.&lt;br /&gt;
&lt;br /&gt;
Nikhil, Bhavana, Rahul, and Deepanker will start a new tutorial for using the Oscilloscope.&lt;br /&gt;
&lt;br /&gt;
Kevin will explore methods for on-board data storage on the sky mote, both volatile and non-volatile.&lt;br /&gt;
&lt;br /&gt;
Pedro, Suvil, and Kwame will work on running Contiki on the testbed and starting a tutorial. Also, thinking about how we can refactor some of our theoretical tutorials to be more activity oriented.&lt;br /&gt;
&lt;br /&gt;
Everyone should update their tutorials to include the primary contributors. Perhaps somewhere at the end.&lt;br /&gt;
&lt;br /&gt;
== Feb/14 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Pedro&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Lakshmi presented the paper [[Probabilistic Clock Synchronization http://kom.aau.dk/~rlo/lectures/algoAndArchIII_2009/ChristiansAlgorithm.pdf]]. We had a very interesting discussion about the terms and concepts behind synchronization and clock in network nodes. We might in the future see how this algorithm can be implemented in a WSN or check whether its main ideas are already implemented in the &amp;quot;Implicit network time synchronization&amp;quot;, present in ContikiOS ([http://contiki.sourceforge.net/docs/2.6/a01741.html])&lt;br /&gt;
&lt;br /&gt;
Everyone gave an updated about what have been done during last week. We have some material for two tutorials: the &amp;#039;&amp;#039;Oscilloscope&amp;#039;&amp;#039; and &amp;#039;&amp;#039;Coffee File System&amp;#039;&amp;#039;. This material is yet in the Google Doc create for prototyping and should be posted in the Wiki soon.&lt;br /&gt;
&lt;br /&gt;
Kwame guided the group in the first 4 sessions of ContikiOS Crash Course [[File:Seniot09cccc-notes.pdf]]. We played with LEDs and push button. This example should give a new tutorial on how to use all the sensors/actuators (light, temperature, push button, etc.) on the motes.&lt;br /&gt;
&lt;br /&gt;
We decided that each week one person will be responsible for creating this meeting log, so everyone can keep track of what has been discussed every week. Below we have the expected date of our next meetings and a tentative assignment.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Kevin will give a brief talk about Coffee file system and show us the material he obtained and the tutorial he started to write.&lt;br /&gt;
&lt;br /&gt;
Yash will start to study and collect material about processes and protothreads. He may give a talk about these topics in two weeks.&lt;br /&gt;
&lt;br /&gt;
Nikhil, Bhavana, Rahul, and Deepanker will keep working on the Oscilloscope tutorial.&lt;br /&gt;
&lt;br /&gt;
Pedro and Kwame will start to work on the Tutornet testbed.&lt;br /&gt;
&lt;br /&gt;
Suvil will fix some issues we are facing in the Wiki with code formatting and help us with account creation/setup of the testbed.&lt;br /&gt;
&lt;br /&gt;
== Feb/21 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Suvil&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Kevin gave a presentation about Coffee File System. He showed the main interface and functions that can be used by Tmote Sky. He also showed an example where a node was programmed to create and write 3 different files on Flash Memory and after reboot output the content of the files reading then from the memory. The presentation slides can be found here:[] and the example code can be found here:[]. He started to create a tutorial on Coffee on the shared Doc file and you may create a tutorial about this topic in our Wiki soon.&lt;br /&gt;
&lt;br /&gt;
We went through the example in: examples/rime/example-neighbors.c, suggested by Bhavana. Basically this example makes all node generate beacons and create a list of neighbors of each node. It prints out the list of neighbors with the corresponding RSSI value.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
We should continue to work on the tutorials, trying to polish and review them for final publication.&lt;br /&gt;
&lt;br /&gt;
== Feb/28 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Leo&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Pedro gave a presentation of a few of the features available in the Cooja simulator. Some of what he covered, which will be put in the Cooja tutorial, includes how to build Cooja from the terminal and automatically start a simulation, locate source files for debugging, and use the single-step and breakpoint debugging tools available for debugging each node. Afterwards, we looked at examples-neighbors.c in more detail, noting the size of the data structures and the way certain values were calculated, such as RSSI. Lastly, we briefly looked over some of the Contiki OS files in the documentation and flipped through a comprehensive Contiki presentation here [http://www.ee.kth.se/~mikaelj/wsn_course/contiki-course-kth-9oct2008-draft.pdf].&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Several more tutorials should be done by our next meeting.&lt;br /&gt;
&lt;br /&gt;
== Mar/07 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Nikhil&lt;br /&gt;
&lt;br /&gt;
== Mar/14 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Kwame&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Yash gave a presentation on Processes and Protothreads. The group expressed interest in learning more about the hardware behind the Tmote Sky, such as the TI MSP430 microprocessor and the CC2420 radio. We&amp;#039;ll probably include some of those as the topic of future talks.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Enjoy Spring Break!&lt;br /&gt;
&lt;br /&gt;
== Mar/21 ==&lt;br /&gt;
&lt;br /&gt;
Spring Break, no meeting&lt;br /&gt;
&lt;br /&gt;
== Mar/28 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Deepanker&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Meeting summary:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
We successfully programmed a multi-hop communication between 5 motes. We also discussed the ways in which motes can talk to each other, namely - unicast, multicast and reliable unicast - and discussed the pros and cons of each with respect to our application.&lt;br /&gt;
&lt;br /&gt;
We discussed a little bit about the connections on the mote, specifically the interaction of MSP430 with CC2420.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Yash will give an introduction to MSP430. Completion of tutorials on wiki and proofreading of the already completed will be done by the people who are assigned the task.&lt;br /&gt;
&lt;br /&gt;
== Apr/04 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Kevin&lt;br /&gt;
Bhavana introduced us how to use Shell in a process. We went through some instructions and source code to understand how it works. Also, we ran an example on the Sky-Mote and tried the Blink instruction. Everything worked good.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;For next week:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Yash will give an introduction to MSP430.&lt;br /&gt;
&lt;br /&gt;
== Apr/11 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Timothy&lt;br /&gt;
&lt;br /&gt;
Yash presents Radio Transceiver:&lt;br /&gt;
Brief Overview of Tmote hardware&lt;br /&gt;
Radio is main communication module&lt;br /&gt;
Overview of QPSK, Tmote uses OQPSK to modulate signal&lt;br /&gt;
Went over frame format of transmission&lt;br /&gt;
&lt;br /&gt;
Pedro will present next week, and Kwame the week after. Assigned several new tutorials, agreed to write up Telephone Game as a tutorial.&lt;br /&gt;
&lt;br /&gt;
== Apr/18 ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Secretary:&amp;#039;&amp;#039;&amp;#039; Bhavana&lt;/div&gt;</summary>
		<author><name>Timothy</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=304</id>
		<title>Timers</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=304"/>
				<updated>2014-03-06T01:39:39Z</updated>
		
		<summary type="html">&lt;p&gt;Timothy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Timers can be used to control periodic tasks as well as implement sophisticated algorithms. The implementation of each type of timer is platform-dependent and has different properties that make them useful in specific situations; some timers have low granularity (seconds) and overflow once in tens of years, and others provide high granularity (microseconds), but overflow rapidly. There are 5 types of timers provided by Contiki:&lt;br /&gt;
&lt;br /&gt;
* timer&lt;br /&gt;
* stimer&lt;br /&gt;
* ctimer&lt;br /&gt;
* etimer&lt;br /&gt;
* rtimer&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
The functions of all types of timers are located inside folder &amp;#039;&amp;#039;&amp;#039;core/sys/{timer, stimer, ctimer, etimer, rtimer}.{c,h}&amp;#039;&amp;#039;&amp;#039;. A complete documentation of Timers in Contiki can be found [https://github.com/contiki-os/contiki/wiki/Timers here].&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;timer&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;stimer&amp;#039;&amp;#039;&amp;#039; are the most basic types of timers and are used to check if a time interval has passed. They do not notice when the time period has elapsed, so the application needs to check periodically if they have expired. The difference between them is the resolution: &amp;#039;&amp;#039;timers&amp;#039;&amp;#039; use system clock ticks, which gives high granularity (order of microseconds) but short overflow periods (order of seconds). On the other hand, &amp;#039;&amp;#039;stimers&amp;#039;&amp;#039; use seconds to allow much longer time periods (order of years), but has lesser granularity. &lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;etimer&amp;#039;&amp;#039;&amp;#039; provides event timers and are used to schedule events to the processes after a period of time. They are used in Contiki processes to wait for a time period while the rest of the system can work or enter low power mode.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;ctimer&amp;#039;&amp;#039;&amp;#039; provides callback timers and are used to schedule calls to functions after a period of time. Like event timers, they are used to wait for some time while the rest of the system can work or enter low power mode. Since the callback timers call a function when a timer expires, they are especially useful in any code that do not have an explicit Contiki process such as protocol implementations.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;rtimer&amp;#039;&amp;#039;&amp;#039; provides scheduling of real-time tasks. The rtimer library preempts any running Contiki process in order to let the real-time tasks execute at the scheduled time. The real-time tasks are used in time critical codes.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
*Simple implementations of each type of timer&lt;br /&gt;
*Tasks each timer can be used for&lt;br /&gt;
*Some functions in the timer libraries.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Again, we will have to change folders. We will create a new file for this tutorial, but let&amp;#039;s create it in the same directory we&amp;#039;ve been working with, so type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
cd contiki-2.7/examples/rime &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the terminal. For this tutorial, we will be modifying the example-broadcast.c file we have previously used, so type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
cp example-broadcast.c example-timer.c &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into your terminal. You should now see a new file, &amp;quot;example-timer.c&amp;quot; in your directory. Open it up with an editor of your choice (we will use gedit for this tutorial):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
gedit example-timer.c &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
There is currently a working example of an etimer in this code, so before we proceed, let&amp;#039;s understand this. At the beginning of the process, it is declared with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
static struct etimer et; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This creates an etimer instance. Within the while loop, it is set with the function&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
etimer_set(&amp;amp;et, CLOCK_SECOND*4 + random_rand() % (CLOCK_SECOND * 4)); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function takes the arguments: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
etimer_set(struct etimer *et, clock_time_t interval); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and sets the etimer et to expire after interval.&lt;br /&gt;
&lt;br /&gt;
After that, we see the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et)); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
which tells the example_broadcast_process to pause until it receives an event, so the program is essentially giving up system control. When an etimer expires, it posts a PROCESS_EVENT_TIMER event to the example_broadcast_process. So this tells the process to continue and begin running again, as the etimer has expired, and an event has been posted. Now that we understand what the etimer is doing here, let&amp;#039;s incorporate some other timers.&lt;br /&gt;
&lt;br /&gt;
=== Step 3 - Adding a timer ===&lt;br /&gt;
&lt;br /&gt;
To start simply, we are going to use a timer to just print out a message once it expires. Just below&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
static struct etimer et; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
declare a timer with the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
static struct timer t; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Before the while loop, set the timer with the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
timer_set(&amp;amp;t, CLOCK_SECOND * 10); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
This sets the timer to expire after 10 seconds.&lt;br /&gt;
&lt;br /&gt;
Below the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
printf(&amp;quot;broadcast message sent\n&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
add in the code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
if(timer_expired(&amp;amp;t)){&lt;br /&gt;
   printf(&amp;quot;Timer expired\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Now, save and run your code on your Tmote Sky by typing into your terminal:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
make TARGET=sky example-timer.upload &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
If you don&amp;#039;t have a Sky, run this code on Mspsim with the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
make TARGET=sky example-timer.mspsim &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Among the &amp;quot;broadcast message sent&amp;quot; messages, you should see a &amp;quot;Timer expired&amp;quot; notice. This only occurs one time, however. This is because we never reset the timer. So, return to your example-timer.c file. Underneath your printf(&amp;quot;Timer expired\n&amp;quot;) line, add the code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
timer_reset(&amp;amp;t); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will reset the timer to expire again in 10 * CLOCK_SECONDS. Run your code again. You should now see &amp;quot;Timer expired&amp;quot; every few broadcast messages. Now, say we only wanted to send broadcast messages for 30 seconds. Let&amp;#039;s use our timer to exit our process after it expires. Change your original timer_set function to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 timer_set(&amp;amp;t, CLOCK_SECOND * 30); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Now, just delete the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
timer_reset(&amp;amp;t); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
and replace it with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
PROCESS_EXIT(); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again, and it should stop after the timer expires. You have now learned some basic functionality of the timer.&lt;br /&gt;
&lt;br /&gt;
=== Step 4 - Using ctimer ===&lt;br /&gt;
&lt;br /&gt;
Begin by deleting the &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
PROCESS_EXIT(); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
line that you previously wrote. We are going to implement a ctimer and no longer want to exit the process. At the beginning of the process, where you declared the other timers, include the code &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
static struct ctimer ct; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This declares a ctimer, which has the property of calling a function when it expires. In order to do this, we will need to declare a function for it to call! So, just before the start of the process, underneath the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
static struct broadcast_conn broadcast; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declare the following function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static void timer_events(void *ptr){ &lt;br /&gt;
   printf(&amp;quot;Congratulations, you called this function&amp;quot;); &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, go back to the process. Just before the while loop, set the ctimer by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, NULL); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This set function takes in arguments that tell the ctimer which function to call, as well as what to pass into the function (NULL in this case). Run your code. You will see that your function is called one time, but since we never reset the code, it never gets called again. So, let&amp;#039;s reset the ctimer as part of the function. Just before you set the ctimer, include this line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
void *ct_ptr = &amp;amp;ct; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And change your ctimer_set function to read:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, ct_ptr); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now go up to your function, and change it to read like this: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
static void timer_events(void *ptr){&lt;br /&gt;
   printf(&amp;quot;Congratulations, you called this function&amp;quot;);&lt;br /&gt;
   struct ctimer* ct_ptr = ptr;&lt;br /&gt;
   ctimer_reset(ct_ptr);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Now run your code again. The function should be called over and over again. The last thing we will do with this function is learn how to terminate the process from the function, using our same ctimer. To begin, change your c_timer set function to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ctimer_set(&amp;amp;ct, CLOCK_SECOND * 30, timer_events, ct_ptr); &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
so the process runs longer before we exit it. Now go up to your function and delete the ctimer_reset line. Replace it with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
process_exit(&amp;amp;example_broadcast_process); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again. You will see that the example_broadcast_process stops running after 30 seconds, and you have learned how to do this from a function called by a ctimer!&lt;br /&gt;
&lt;br /&gt;
=== Step 5 - Introduction to rtimer===&lt;br /&gt;
&lt;br /&gt;
The rtimer library provides real-time scheduling mechanisms, typically for applications where a response to an external event is extremely time sensitive. Rtimers use absolute system clock time as a reference.&lt;br /&gt;
&lt;br /&gt;
We will modify our original broadcast process with an rtimer, to demonstrate rtimer&amp;#039;s usefulness for calling a function at an absolute time in response to an event. In this case, our etimer produces random, simulated real-time events.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static void function( rtimer *rt, void *ptr) {&lt;br /&gt;
    packetbuf_copyfrom(&amp;quot;Event Occurred&amp;quot;, 15);&lt;br /&gt;
    broadcast_send(&amp;amp;broadcast);&lt;br /&gt;
    printf(&amp;quot;Real Time Task Completed\n&amp;quot;); &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The function &amp;#039;responds&amp;#039; to the scheduling of a real-time task using rtimer, and can be used to answer an external stimulus.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(broadcast_example_process, ev, data) {&lt;br /&gt;
    static struct etimer et;&lt;br /&gt;
    static struct rtimer rt;&lt;br /&gt;
&lt;br /&gt;
    PROCESS_EXIT_HANDLER(broadcast_close(&amp;amp;broadcast);)&lt;br /&gt;
    PROCESS_BEGIN();&lt;br /&gt;
    while (1) {&lt;br /&gt;
        PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;t)); //Real Time Event &lt;br /&gt;
        printf(&amp;quot;Real Time Event Recorded\n&amp;quot;);&lt;br /&gt;
        rtimer_set(&amp;amp;rt, RTIMER_NOW()+RTIMER_ARCH_SECOND,1,function,NULL);&lt;br /&gt;
    }&lt;br /&gt;
    PROCESS_END();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note the setting method for rtimer takes 4 arguments: &lt;br /&gt;
- real-time task (rtimer)&lt;br /&gt;
- time at which task must be completed&lt;br /&gt;
- duration - UNUSED&lt;br /&gt;
- function to call&lt;br /&gt;
- argument for the function, which is NULL in this case.&lt;br /&gt;
&lt;br /&gt;
Upon simulating this code, you will see the rtimer respond almost immediately to each simulated real-time event. However, using the simulation does not allow for some of the features of rtimer, because rtimer is a low level struct that has significant dependence on physical aspects of the hardware. You will notice that replacing &amp;quot;RTIMER_ARCH_SECOND&amp;quot; with &amp;quot;4096*RTIMER_ARCH_SECOND&amp;quot; does not change the delay in simulation.&lt;br /&gt;
&lt;br /&gt;
A complete example of rtimer&amp;#039;s uses that can be run on hardware is &amp;quot;example-rudolph1.c&amp;quot; in rime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
References:&lt;br /&gt;
[https://github.com/contiki-os/contiki/wiki/Timers#wiki-The_Timer_Library]&lt;br /&gt;
[http://contiki.sourceforge.net/docs/2.6/a01673.html]&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Timothy</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=303</id>
		<title>Timers</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=303"/>
				<updated>2014-03-06T01:36:05Z</updated>
		
		<summary type="html">&lt;p&gt;Timothy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Timers can be used to control periodic tasks as well as implement sophisticated algorithms. The implementation of each type of timer is platform-dependent and has different properties that make them useful in specific situations; some timers have low granularity (seconds) and overflow once in tens of years, and others provide high granularity (microseconds), but overflow rapidly. There are 5 types of timers provided by Contiki:&lt;br /&gt;
&lt;br /&gt;
* timer&lt;br /&gt;
* stimer&lt;br /&gt;
* ctimer&lt;br /&gt;
* etimer&lt;br /&gt;
* rtimer&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
The functions of all types of timers are located inside folder &amp;#039;&amp;#039;&amp;#039;core/sys/{timer, stimer, ctimer, etimer, rtimer}.{c,h}&amp;#039;&amp;#039;&amp;#039;. A complete documentation of Timers in Contiki can be found [https://github.com/contiki-os/contiki/wiki/Timers here].&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;timer&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;stimer&amp;#039;&amp;#039;&amp;#039; are the most basic types of timers and are used to check if a time interval has passed. They do not notice when the time period has elapsed, so the application needs to check periodically if they have expired. The difference between them is the resolution: &amp;#039;&amp;#039;timers&amp;#039;&amp;#039; use system clock ticks, which gives high granularity (order of microseconds) but short overflow periods (order of seconds). On the other hand, &amp;#039;&amp;#039;stimers&amp;#039;&amp;#039; use seconds to allow much longer time periods (order of years), but has lesser granularity. &lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;etimer&amp;#039;&amp;#039;&amp;#039; provides event timers and are used to schedule events to the processes after a period of time. They are used in Contiki processes to wait for a time period while the rest of the system can work or enter low power mode.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;ctimer&amp;#039;&amp;#039;&amp;#039; provides callback timers and are used to schedule calls to functions after a period of time. Like event timers, they are used to wait for some time while the rest of the system can work or enter low power mode. Since the callback timers call a function when a timer expires, they are especially useful in any code that do not have an explicit Contiki process such as protocol implementations.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;rtimer&amp;#039;&amp;#039;&amp;#039; provides scheduling of real-time tasks. The rtimer library preempts any running Contiki process in order to let the real-time tasks execute at the scheduled time. The real-time tasks are used in time critical codes.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
*Simple implementations of each type of timer&lt;br /&gt;
*Tasks each timer can be used for&lt;br /&gt;
*Some functions in the timer libraries.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Again, we will have to change folders. We will create a new file for this tutorial, but let&amp;#039;s create it in the same directory we&amp;#039;ve been working with, so type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
cd contiki-2.7/examples/rime &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the terminal. For this tutorial, we will be modifying the example-broadcast.c file we have previously used, so type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
cp example-broadcast.c example-timer.c &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into your terminal. You should now see a new file, &amp;quot;example-timer.c&amp;quot; in your directory. Open it up with an editor of your choice (we will use gedit for this tutorial):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
gedit example-timer.c &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
There is currently a working example of an etimer in this code, so before we proceed, let&amp;#039;s understand this. At the beginning of the process, it is declared with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
static struct etimer et; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This creates an etimer instance. Within the while loop, it is set with the function&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
etimer_set(&amp;amp;et, CLOCK_SECOND*4 + random_rand() % (CLOCK_SECOND * 4)); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function takes the arguments: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
etimer_set(struct etimer *et, clock_time_t interval); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and sets the etimer et to expire after interval.&lt;br /&gt;
&lt;br /&gt;
After that, we see the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et)); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
which tells the example_broadcast_process to pause until it receives an event, so the program is essentially giving up system control. When an etimer expires, it posts a PROCESS_EVENT_TIMER event to the example_broadcast_process. So this tells the process to continue and begin running again, as the etimer has expired, and an event has been posted. Now that we understand what the etimer is doing here, let&amp;#039;s incorporate some other timers.&lt;br /&gt;
&lt;br /&gt;
=== Step 3 - Adding a timer ===&lt;br /&gt;
&lt;br /&gt;
To start simply, we are going to use a timer to just print out a message once it expires. Just below&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
static struct etimer et; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
declare a timer with the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
static struct timer t; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before the while loop, set the timer with the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
timer_set(&amp;amp;t, CLOCK_SECOND * 10); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This sets the timer to expire after 10 seconds.&lt;br /&gt;
&lt;br /&gt;
Below the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
printf(&amp;quot;broadcast message sent\n&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
add in the code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
if(timer_expired(&amp;amp;t)){&lt;br /&gt;
   printf(&amp;quot;Timer expired\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, save and run your code on your Tmote Sky by typing into your terminal:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
make TARGET=sky example-timer.upload &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you don&amp;#039;t have a Sky, run this code on Mspsim with the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
make TARGET=sky example-timer.mspsim &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Among the &amp;quot;broadcast message sent&amp;quot; messages, you should see a &amp;quot;Timer expired&amp;quot; notice. This only occurs one time, however. This is because we never reset the timer. So, return to your example-timer.c file. Underneath your printf(&amp;quot;Timer expired\n&amp;quot;) line, add the code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
timer_reset(&amp;amp;t); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will reset the timer to expire again in 10 * CLOCK_SECONDS. Run your code again. You should now see &amp;quot;Timer expired&amp;quot; every few broadcast messages. Now, say we only wanted to send broadcast messages for 30 seconds. Let&amp;#039;s use our timer to exit our process after it expires. Change your original timer_set function to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 timer_set(&amp;amp;t, CLOCK_SECOND * 30); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Now, just delete the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
timer_reset(&amp;amp;t); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and replace it with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
PROCESS_EXIT(); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again, and it should stop after the timer expires. You have now learned some basic functionality of the timer.&lt;br /&gt;
&lt;br /&gt;
=== Step 4 - Using ctimer ===&lt;br /&gt;
&lt;br /&gt;
Begin by deleting the &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
PROCESS_EXIT(); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
line that you previously wrote. We are going to implement a ctimer and no longer want to exit the process. At the beginning of the process, where you declared the other timers, include the code &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
static struct ctimer ct; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This declares a ctimer, which has the property of calling a function when it expires. In order to do this, we will need to declare a function for it to call! So, just before the start of the process, underneath the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
static struct broadcast_conn broadcast; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declare the following function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static void timer_events(void *ptr){ &lt;br /&gt;
   printf(&amp;quot;Congratulations, you called this function&amp;quot;); &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, go back to the process. Just before the while loop, set the ctimer by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, NULL); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This set function takes in arguments that tell the ctimer which function to call, as well as what to pass into the function (NULL in this case). Run your code. You will see that your function is called one time, but since we never reset the code, it never gets called again. So, let&amp;#039;s reset the ctimer as part of the function. Just before you set the ctimer, include this line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
void *ct_ptr = &amp;amp;ct; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And change your ctimer_set function to read:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, ct_ptr); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now go up to your function, and change it to read like this: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
static void timer_events(void *ptr){&lt;br /&gt;
   printf(&amp;quot;Congratulations, you called this function&amp;quot;);&lt;br /&gt;
   struct ctimer* ct_ptr = ptr;&lt;br /&gt;
   ctimer_reset(ct_ptr);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Now run your code again. The function should be called over and over again. The last thing we will do with this function is learn how to terminate the process from the function, using our same ctimer. To begin, change your c_timer set function to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
ctimer_set(&amp;amp;ct, CLOCK_SECOND * 30, timer_events, ct_ptr); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
so the process runs longer before we exit it. Now go up to your function and delete the ctimer_reset line. Replace it with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
process_exit(&amp;amp;example_broadcast_process); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again. You will see that the example_broadcast_process stops running after 30 seconds, and you have learned how to do this from a function called by a ctimer!&lt;br /&gt;
&lt;br /&gt;
=== Step 5 - Introduction to rtimer===&lt;br /&gt;
&lt;br /&gt;
The rtimer library provides real-time scheduling mechanisms, typically for applications where a response to an external event is extremely time sensitive. Rtimers use absolute system clock time as a reference.&lt;br /&gt;
&lt;br /&gt;
We will modify our original broadcast process with an rtimer, to demonstrate rtimer&amp;#039;s usefulness for calling a function at an absolute time in response to an event. In this case, our etimer produces random, simulated real-time events.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static void function( rtimer *rt, void *ptr) {&lt;br /&gt;
    packetbuf_copyfrom(&amp;quot;Event Occurred&amp;quot;, 15);&lt;br /&gt;
    broadcast_send(&amp;amp;broadcast);&lt;br /&gt;
    printf(&amp;quot;Real Time Task Completed\n&amp;quot;); &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The function &amp;#039;responds&amp;#039; to the scheduling of a real-time task using rtimer, and can be used to answer an external stimulus.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(broadcast_example_process, ev, data) {&lt;br /&gt;
    static struct etimer et;&lt;br /&gt;
    static struct rtimer rt;&lt;br /&gt;
&lt;br /&gt;
    PROCESS_EXIT_HANDLER(broadcast_close(&amp;amp;broadcast);)&lt;br /&gt;
    PROCESS_BEGIN();&lt;br /&gt;
    while (1) {&lt;br /&gt;
        PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;t)); //Real Time Event &lt;br /&gt;
        printf(&amp;quot;Real Time Event Recorded\n&amp;quot;);&lt;br /&gt;
        rtimer_set(&amp;amp;rt, RTIMER_NOW()+RTIMER_ARCH_SECOND,1,function,NULL);&lt;br /&gt;
    }&lt;br /&gt;
    PROCESS_END();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note the setting method for rtimer takes 4 arguments: &lt;br /&gt;
- real-time task (rtimer)&lt;br /&gt;
- time at which task must be completed&lt;br /&gt;
- duration - UNUSED&lt;br /&gt;
- function to call&lt;br /&gt;
- argument for the function, which is NULL in this case.&lt;br /&gt;
&lt;br /&gt;
Upon simulating this code, you will see the rtimer respond almost immediately to each simulated real-time event. However, using the simulation does not allow for some of the features of rtimer, because rtimer is a low level struct that has significant dependence on physical aspects of the hardware. You will notice that replacing &amp;quot;RTIMER_ARCH_SECOND&amp;quot; with &amp;quot;4096*RTIMER_ARCH_SECOND&amp;quot; does not change the delay in simulation.&lt;br /&gt;
&lt;br /&gt;
A complete example of rtimer&amp;#039;s uses that can be run on hardware is &amp;quot;example-rudolph1.c&amp;quot; in rime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
References:&lt;br /&gt;
[https://github.com/contiki-os/contiki/wiki/Timers#wiki-The_Timer_Library]&lt;br /&gt;
[http://contiki.sourceforge.net/docs/2.6/a01673.html]&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Timothy</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=302</id>
		<title>Timers</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=302"/>
				<updated>2014-03-06T01:33:07Z</updated>
		
		<summary type="html">&lt;p&gt;Timothy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Timers can be used to control periodic tasks as well as implement sophisticated algorithms. The implementation of each type of timer is platform-dependent and has different properties that make them useful in specific situations; some timers have low granularity (seconds) and overflow once in tens of years, and others provide high granularity (microseconds), but overflow rapidly. There are 5 types of timers provided by Contiki:&lt;br /&gt;
&lt;br /&gt;
* timer&lt;br /&gt;
* stimer&lt;br /&gt;
* ctimer&lt;br /&gt;
* etimer&lt;br /&gt;
* rtimer&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
The functions of all types of timers are located inside folder &amp;#039;&amp;#039;&amp;#039;core/sys/{timer, stimer, ctimer, etimer, rtimer}.{c,h}&amp;#039;&amp;#039;&amp;#039;. A complete documentation of Timers in Contiki can be found [https://github.com/contiki-os/contiki/wiki/Timers here].&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;timer&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;stimer&amp;#039;&amp;#039;&amp;#039; are the most basic types of timers and are used to check if a time interval has passed. They do not notice when the time period has elapsed, so the application needs to check periodically if they have expired. The difference between them is the resolution: &amp;#039;&amp;#039;timers&amp;#039;&amp;#039; use system clock ticks, which gives high granularity (order of microseconds) but short overflow periods (order of seconds). On the other hand, &amp;#039;&amp;#039;stimers&amp;#039;&amp;#039; use seconds to allow much longer time periods (order of years), but has lesser granularity. &lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;etimer&amp;#039;&amp;#039;&amp;#039; provides event timers and are used to schedule events to the processes after a period of time. They are used in Contiki processes to wait for a time period while the rest of the system can work or enter low power mode.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;ctimer&amp;#039;&amp;#039;&amp;#039; provides callback timers and are used to schedule calls to functions after a period of time. Like event timers, they are used to wait for some time while the rest of the system can work or enter low power mode. Since the callback timers call a function when a timer expires, they are especially useful in any code that do not have an explicit Contiki process such as protocol implementations.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;rtimer&amp;#039;&amp;#039;&amp;#039; provides scheduling of real-time tasks. The rtimer library preempts any running Contiki process in order to let the real-time tasks execute at the scheduled time. The real-time tasks are used in time critical codes.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
*Simple implementations of each type of timer&lt;br /&gt;
*Tasks each timer can be used for&lt;br /&gt;
*Some functions in the timer libraries.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Again, we will have to change folders. We will create a new file for this tutorial, but let&amp;#039;s create it in the same directory we&amp;#039;ve been working with, so type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
cd contiki-2.7/examples/rime &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the terminal. For this tutorial, we will be modifying the example-broadcast.c file we have previously used, so type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
cp example-broadcast.c example-timer.c &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into your terminal. You should now see a new file, &amp;quot;example-timer.c&amp;quot; in your directory. Open it up with an editor of your choice (we will use gedit for this tutorial):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
gedit example-timer.c &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
There is currently a working example of an etimer in this code, so before we proceed, let&amp;#039;s understand this. At the beginning of the process, it is declared with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
static struct etimer et; &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This creates an etimer instance. Within the while loop, it is set with the function&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
etimer_set(&amp;amp;et, CLOCK_SECOND*4 + random_rand() % (CLOCK_SECOND * 4)); &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function takes the arguments: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
etimer_set(struct etimer *et, clock_time_t interval); &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and sets the etimer et to expire after interval.&lt;br /&gt;
&lt;br /&gt;
After that, we see the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et)); &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
which tells the example_broadcast_process to pause until it receives an event, so the program is essentially giving up system control. When an etimer expires, it posts a PROCESS_EVENT_TIMER event to the example_broadcast_process. So this tells the process to continue and begin running again, as the etimer has expired, and an event has been posted. Now that we understand what the etimer is doing here, let&amp;#039;s incorporate some other timers.&lt;br /&gt;
&lt;br /&gt;
=== Step 3 - Adding a timer ===&lt;br /&gt;
&lt;br /&gt;
To start simply, we are going to use a timer to just print out a message once it expires. Just below&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
static struct etimer et; &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
declare a timer with the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
static struct timer t; &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before the while loop, set the timer with the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
timer_set(&amp;amp;t, CLOCK_SECOND * 10); &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This sets the timer to expire after 10 seconds.&lt;br /&gt;
&lt;br /&gt;
Below the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
printf(&amp;quot;broadcast message sent\n&amp;quot;); &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
add in the code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
if(timer_expired(&amp;amp;t)){&lt;br /&gt;
   printf(&amp;quot;Timer expired\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, save and run your code on your Tmote Sky by typing into your terminal:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
make TARGET=sky example-timer.upload &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you don&amp;#039;t have a Sky, run this code on Mspsim with the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
make TARGET=sky example-timer.mspsim &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Among the &amp;quot;broadcast message sent&amp;quot; messages, you should see a &amp;quot;Timer expired&amp;quot; notice. This only occurs one time, however. This is because we never reset the timer. So, return to your example-timer.c file. Underneath your printf(&amp;quot;Timer expired\n&amp;quot;) line, add the code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
timer_reset(&amp;amp;t); &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will reset the timer to expire again in 10 * CLOCK_SECONDS. Run your code again. You should now see &amp;quot;Timer expired&amp;quot; every few broadcast messages. Now, say we only wanted to send broadcast messages for 30 seconds. Let&amp;#039;s use our timer to exit our process after it expires. Change your original timer_set function to:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt; timer_set(&amp;amp;t, CLOCK_SECOND * 30); &amp;lt;/code&amp;gt;&lt;br /&gt;
Now, just delete the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
timer_reset(&amp;amp;t); &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and replace it with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
PROCESS_EXIT(); &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again, and it should stop after the timer expires. You have now learned some basic functionality of the timer.&lt;br /&gt;
&lt;br /&gt;
=== Step 4 - Using ctimer ===&lt;br /&gt;
&lt;br /&gt;
Begin by deleting the &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
PROCESS_EXIT(); &lt;br /&gt;
&amp;lt;/code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
line that you previously wrote. We are going to implement a ctimer and no longer want to exit the process. At the beginning of the process, where you declared the other timers, include the code &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
static struct ctimer ct; &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This declares a ctimer, which has the property of calling a function when it expires. In order to do this, we will need to declare a function for it to call! So, just before the start of the process, underneath the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
static struct broadcast_conn broadcast; &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declare the following function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
static void timer_events(void *ptr){ &lt;br /&gt;
   printf(&amp;quot;Congratulations, you called this function&amp;quot;); &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, go back to the process. Just before the while loop, set the ctimer by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, NULL); &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This set function takes in arguments that tell the ctimer which function to call, as well as what to pass into the function (NULL in this case). Run your code. You will see that your function is called one time, but since we never reset the code, it never gets called again. So, let&amp;#039;s reset the ctimer as part of the function. Just before you set the ctimer, include this line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
void *ct_ptr = &amp;amp;ct; &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And change your ctimer_set function to read:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, ct_ptr); &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now go up to your function, and change it to read like this: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &lt;br /&gt;
static void timer_events(void *ptr){&lt;br /&gt;
   printf(&amp;quot;Congratulations, you called this function&amp;quot;);&lt;br /&gt;
   struct ctimer* ct_ptr = ptr;&lt;br /&gt;
   ctimer_reset(ct_ptr);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Now run your code again. The function should be called over and over again. The last thing we will do with this function is learn how to terminate the process from the function, using our same ctimer. To begin, change your c_timer set function to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 30, timer_events, ct_ptr); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
so the process runs longer before we exit it. Now go up to your function and delete the ctimer_reset line. Replace it with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; process_exit(&amp;amp;example_broadcast_process); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again. You will see that the example_broadcast_process stops running after 30 seconds, and you have learned how to do this from a function called by a ctimer!&lt;br /&gt;
&lt;br /&gt;
=== Step 5 - Introduction to rtimer===&lt;br /&gt;
&lt;br /&gt;
The rtimer library provides real-time scheduling mechanisms, typically for applications where a response to an external event is extremely time sensitive. Rtimers use absolute system clock time as a reference.&lt;br /&gt;
&lt;br /&gt;
We will modify our original broadcast process with an rtimer, to demonstrate rtimer&amp;#039;s usefulness for calling a function at an absolute time in response to an event. In this case, our etimer produces random, simulated real-time events.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static void function( rtimer *rt, void *ptr) {&lt;br /&gt;
    packetbuf_copyfrom(&amp;quot;Event Occurred&amp;quot;, 15);&lt;br /&gt;
    broadcast_send(&amp;amp;broadcast);&lt;br /&gt;
    printf(&amp;quot;Real Time Task Completed\n&amp;quot;); &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The function &amp;#039;responds&amp;#039; to the scheduling of a real-time task using rtimer, and can be used to answer an external stimulus.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(broadcast_example_process, ev, data) {&lt;br /&gt;
    static struct etimer et;&lt;br /&gt;
    static struct rtimer rt;&lt;br /&gt;
&lt;br /&gt;
    PROCESS_EXIT_HANDLER(broadcast_close(&amp;amp;broadcast);)&lt;br /&gt;
    PROCESS_BEGIN();&lt;br /&gt;
    while (1) {&lt;br /&gt;
        PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;t)); //Real Time Event &lt;br /&gt;
        printf(&amp;quot;Real Time Event Recorded\n&amp;quot;);&lt;br /&gt;
        rtimer_set(&amp;amp;rt, RTIMER_NOW()+RTIMER_ARCH_SECOND,1,function,NULL);&lt;br /&gt;
    }&lt;br /&gt;
    PROCESS_END();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note the setting method for rtimer takes 4 arguments: &lt;br /&gt;
- real-time task (rtimer)&lt;br /&gt;
- time at which task must be completed&lt;br /&gt;
- duration - UNUSED&lt;br /&gt;
- function to call&lt;br /&gt;
- argument for the function, which is NULL in this case.&lt;br /&gt;
&lt;br /&gt;
Upon simulating this code, you will see the rtimer respond almost immediately to each simulated real-time event. However, using the simulation does not allow for some of the features of rtimer, because rtimer is a low level struct that has significant dependence on physical aspects of the hardware. You will notice that replacing &amp;quot;RTIMER_ARCH_SECOND&amp;quot; with &amp;quot;4096*RTIMER_ARCH_SECOND&amp;quot; does not change the delay in simulation.&lt;br /&gt;
&lt;br /&gt;
A complete example of rtimer&amp;#039;s uses that can be run on hardware is &amp;quot;example-rudolph1.c&amp;quot; in rime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
References:&lt;br /&gt;
[https://github.com/contiki-os/contiki/wiki/Timers#wiki-The_Timer_Library]&lt;br /&gt;
[http://contiki.sourceforge.net/docs/2.6/a01673.html]&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Timothy</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=301</id>
		<title>Timers</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=301"/>
				<updated>2014-03-06T01:27:12Z</updated>
		
		<summary type="html">&lt;p&gt;Timothy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Timers can be used to control periodic tasks as well as implement sophisticated algorithms. The implementation of each type of timer is platform-dependent and has different properties that make them useful in specific situations; some timers have low granularity (seconds) and overflow once in tens of years, and others provide high granularity (microseconds), but overflow rapidly. There are 5 types of timers provided by Contiki:&lt;br /&gt;
&lt;br /&gt;
* timer&lt;br /&gt;
* stimer&lt;br /&gt;
* ctimer&lt;br /&gt;
* etimer&lt;br /&gt;
* rtimer&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
The functions of all types of timers are located inside folder &amp;#039;&amp;#039;&amp;#039;core/sys/{timer, stimer, ctimer, etimer, rtimer}.{c,h}&amp;#039;&amp;#039;&amp;#039;. A complete documentation of Timers in Contiki can be found [https://github.com/contiki-os/contiki/wiki/Timers here].&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;timer&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;stimer&amp;#039;&amp;#039;&amp;#039; are the most basic types of timers and are used to check if a time interval has passed. They do not notice when the time period has elapsed, so the application needs to check periodically if they have expired. The difference between them is the resolution: &amp;#039;&amp;#039;timers&amp;#039;&amp;#039; use system clock ticks, which gives high granularity (order of microseconds) but short overflow periods (order of seconds). On the other hand, &amp;#039;&amp;#039;stimers&amp;#039;&amp;#039; use seconds to allow much longer time periods (order of years), but has lesser granularity. &lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;etimer&amp;#039;&amp;#039;&amp;#039; provides event timers and are used to schedule events to the processes after a period of time. They are used in Contiki processes to wait for a time period while the rest of the system can work or enter low power mode.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;ctimer&amp;#039;&amp;#039;&amp;#039; provides callback timers and are used to schedule calls to functions after a period of time. Like event timers, they are used to wait for some time while the rest of the system can work or enter low power mode. Since the callback timers call a function when a timer expires, they are especially useful in any code that do not have an explicit Contiki process such as protocol implementations.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;rtimer&amp;#039;&amp;#039;&amp;#039; provides scheduling of real-time tasks. The rtimer library preempts any running Contiki process in order to let the real-time tasks execute at the scheduled time. The real-time tasks are used in time critical codes.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
*Simple implementations of each type of timer&lt;br /&gt;
*Tasks each timer can be used for&lt;br /&gt;
*Some functions in the timer libraries.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Again, we will have to change folders. We will create a new file for this tutorial, but let&amp;#039;s create it in the same directory we&amp;#039;ve been working with, so type&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; cd contiki-2.7/examples/rime &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the terminal. For this tutorial, we will be modifying the example-broadcast.c file we have previously used, so type &lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; cp example-broadcast.c example-timer.c &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into your terminal. You should now see a new file, &amp;quot;example-timer.c&amp;quot; in your directory. Open it up with an editor of your choice (we will use gedit for this tutorial):&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; gedit example-timer.c &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
There is currently a working example of an etimer in this code, so before we proceed, let&amp;#039;s understand this. At the beginning of the process, it is declared with&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; static struct etimer et; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This creates an etimer instance. Within the while loop, it is set with the function&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; etimer_set(&amp;amp;et, CLOCK_SECOND*4 + random_rand() % (CLOCK_SECOND * 4)); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function takes the arguments: &lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; etimer_set(struct etimer *et, clock_time_t interval); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and sets the etimer et to expire after interval.&lt;br /&gt;
&lt;br /&gt;
After that, we see the line: &lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et)); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
which tells the example_broadcast_process to pause until it receives an event, so the program is essentially giving up system control. When an etimer expires, it posts a PROCESS_EVENT_TIMER event to the example_broadcast_process. So this tells the process to continue and begin running again, as the etimer has expired, and an event has been posted. Now that we understand what the etimer is doing here, let&amp;#039;s incorporate some other timers.&lt;br /&gt;
&lt;br /&gt;
=== Step 3 - Adding a timer ===&lt;br /&gt;
&lt;br /&gt;
To start simply, we are going to use a timer to just print out a message once it expires. Just below&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; static struct etimer et; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
declare a timer with the line: &lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; static struct timer t; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before the while loop, set the timer with the line: &lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; timer_set(&amp;amp;t, CLOCK_SECOND * 10); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This sets the timer to expire after 10 seconds.&lt;br /&gt;
&lt;br /&gt;
Below the line&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; printf(&amp;quot;broadcast message sent\n&amp;quot;); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
add in the code:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; if(timer_expired(&amp;amp;t)){&lt;br /&gt;
                                 printf(&amp;quot;Timer expired\n&amp;quot;);&lt;br /&gt;
                             }&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, save and run your code on your Tmote Sky by typing into your terminal:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; make TARGET=sky example-timer.upload &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you don&amp;#039;t have a Sky, run this code on Mspsim with the line&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; make TARGET=sky example-timer.mspsim &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Among the &amp;quot;broadcast message sent&amp;quot; messages, you should see a &amp;quot;Timer expired&amp;quot; notice. This only occurs one time, however. This is because we never reset the timer. So, return to your example-timer.c file. Underneath your printf(&amp;quot;Timer expired\n&amp;quot;) line, add the code&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; timer_reset(&amp;amp;t); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will reset the timer to expire again in 10 * CLOCK_SECONDS. Run your code again. You should now see &amp;quot;Timer expired&amp;quot; every few broadcast messages. Now, say we only wanted to send broadcast messages for 30 seconds. Let&amp;#039;s use our timer to exit our process after it expires. Change your original timer_set function to:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt; timer_set(&amp;amp;t, CLOCK_SECOND * 30); &amp;lt;/code&amp;gt;&lt;br /&gt;
Now, just delete the line&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; timer_reset(&amp;amp;t); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and replace it with&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; PROCESS_EXIT(); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again, and it should stop after the timer expires. You have now learned some basic functionality of the timer.&lt;br /&gt;
&lt;br /&gt;
=== Step 4 - Using ctimer ===&lt;br /&gt;
&lt;br /&gt;
Begin by deleting the &lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; PROCESS_EXIT(); &amp;lt;/code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
line that you previously wrote. We are going to implement a ctimer and no longer want to exit the process. At the beginning of the process, where you declared the other timers, include the code &lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; static struct ctimer ct &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This declares a ctimer, which has the property of calling a function when it expires. In order to do this, we will need to declare a function for it to call! So, just before the start of the process, underneath the line&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; static struct broadcast_conn broadcast; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declare the following function:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; static void timer_events(void *ptr){ &amp;lt;/code&amp;gt;&lt;br /&gt;
::::&amp;lt;code&amp;gt;printf(&amp;quot;Congratulations, you called this function&amp;quot;); &amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, go back to the process. Just before the while loop, set the ctimer by typing&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, NULL); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This set function takes in arguments that tell the ctimer which function to call, as well as what to pass into the function (NULL in this case). Run your code. You will see that your function is called one time, but since we never reset the code, it never gets called again. So, let&amp;#039;s reset the ctimer as part of the function. Just before you set the ctimer, include this line:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; void *ct_ptr = &amp;amp;ct; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And change your ctimer_set function to read:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, ct_ptr); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now go up to your function, and change it to read like this: &lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; static void timer_events(void *ptr){&amp;lt;/code&amp;gt;&lt;br /&gt;
::::&amp;lt;code&amp;gt;printf(&amp;quot;Congratulations, you called this function&amp;quot;);&amp;lt;/code&amp;gt;&lt;br /&gt;
::::&amp;lt;code&amp;gt;struct ctimer* ct_ptr = ptr;&amp;lt;/code&amp;gt;&lt;br /&gt;
::::&amp;lt;code&amp;gt;ctimer_reset(ct_ptr);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;}&amp;lt;/code&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Now run your code again. The function should be called over and over again. The last thing we will do with this function is learn how to terminate the process from the function, using our same ctimer. To begin, change your c_timer set function to&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 30, timer_events, ct_ptr); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
so the process runs longer before we exit it. Now go up to your function and delete the ctimer_reset line. Replace it with:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt; process_exit(&amp;amp;example_broadcast_process); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again. You will see that the example_broadcast_process stops running after 30 seconds, and you have learned how to do this from a function called by a ctimer!&lt;br /&gt;
&lt;br /&gt;
=== Step 5 - Introduction to rtimer===&lt;br /&gt;
&lt;br /&gt;
The rtimer library provides real-time scheduling mechanisms, typically for applications where a response to an external event is extremely time sensitive. Rtimers use absolute system clock time as a reference.&lt;br /&gt;
&lt;br /&gt;
We will modify our original broadcast process with an rtimer, to demonstrate rtimer&amp;#039;s usefulness for calling a function at an absolute time in response to an event. In this case, our etimer produces random, simulated real-time events.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static void function( rtimer *rt, void *ptr) {&lt;br /&gt;
    packetbuf_copyfrom(&amp;quot;Event Occurred&amp;quot;, 15);&lt;br /&gt;
    broadcast_send(&amp;amp;broadcast);&lt;br /&gt;
    printf(&amp;quot;Real Time Task Completed\n&amp;quot;); &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The function &amp;#039;responds&amp;#039; to the scheduling of a real-time task using rtimer, and can be used to answer an external stimulus.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(broadcast_example_process, ev, data) {&lt;br /&gt;
    static struct etimer et;&lt;br /&gt;
    static struct rtimer rt;&lt;br /&gt;
&lt;br /&gt;
    PROCESS_EXIT_HANDLER(broadcast_close(&amp;amp;broadcast);)&lt;br /&gt;
    PROCESS_BEGIN();&lt;br /&gt;
    while (1) {&lt;br /&gt;
        PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;t)); //Real Time Event &lt;br /&gt;
        printf(&amp;quot;Real Time Event Recorded\n&amp;quot;);&lt;br /&gt;
        rtimer_set(&amp;amp;rt, RTIMER_NOW()+RTIMER_ARCH_SECOND,1,function,NULL);&lt;br /&gt;
    }&lt;br /&gt;
    PROCESS_END();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note the setting method for rtimer takes 4 arguments: &lt;br /&gt;
- real-time task (rtimer)&lt;br /&gt;
- time at which task must be completed&lt;br /&gt;
- duration - UNUSED&lt;br /&gt;
- function to call&lt;br /&gt;
- argument for the function, which is NULL in this case.&lt;br /&gt;
&lt;br /&gt;
Upon simulating this code, you will see the rtimer respond almost immediately to each simulated real-time event. However, using the simulation does not allow for some of the features of rtimer, because rtimer is a low level struct that has significant dependence on physical aspects of the hardware. You will notice that replacing &amp;quot;RTIMER_ARCH_SECOND&amp;quot; with &amp;quot;4096*RTIMER_ARCH_SECOND&amp;quot; does not change the delay in simulation.&lt;br /&gt;
&lt;br /&gt;
A complete example of rtimer&amp;#039;s uses that can be run on hardware is &amp;quot;example-rudolph1.c&amp;quot; in rime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
References:&lt;br /&gt;
[https://github.com/contiki-os/contiki/wiki/Timers#wiki-The_Timer_Library]&lt;br /&gt;
[http://contiki.sourceforge.net/docs/2.6/a01673.html]&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Timothy</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=284</id>
		<title>Timers</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=284"/>
				<updated>2014-03-05T06:44:51Z</updated>
		
		<summary type="html">&lt;p&gt;Timothy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Timers can be used to control periodic tasks as well as implement sophisticated algorithms. The implementation of each type of timer is platform-dependent and has different properties that make them useful in specific situations; some timers have low granularity (seconds) and overflow once in tens of years, and others provide high granularity (microseconds), but overflow rapidly. There are 5 types of timers provided by Contiki:&lt;br /&gt;
&lt;br /&gt;
* timer&lt;br /&gt;
* stimer&lt;br /&gt;
* ctimer&lt;br /&gt;
* etimer&lt;br /&gt;
* rtimer&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
The functions of all types of timers are located inside folder &amp;#039;&amp;#039;&amp;#039;core/sys/{timer, stimer, ctimer, etimer, rtimer}.{c,h}&amp;#039;&amp;#039;&amp;#039;. A complete documentation of Timers in Contiki can be found [https://github.com/contiki-os/contiki/wiki/Timers here].&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;timer&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;stimer&amp;#039;&amp;#039;&amp;#039; are the most basic types of timers and are used to check if a time interval has passed. They do not notice when the time period has elapsed, so the application needs to check periodically if they have expired. The difference between them is the resolution: &amp;#039;&amp;#039;timers&amp;#039;&amp;#039; use system clock ticks, which gives high granularity (order of microseconds) but short overflow periods (order of seconds). On the other hand, &amp;#039;&amp;#039;stimers&amp;#039;&amp;#039; use seconds to allow much longer time periods (order of years), but has lesser granularity. &lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;etimer&amp;#039;&amp;#039;&amp;#039; provides event timers and are used to schedule events to the processes after a period of time. They are used in Contiki processes to wait for a time period while the rest of the system can work or enter low power mode.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;ctimer&amp;#039;&amp;#039;&amp;#039; provides callback timers and are used to schedule calls to functions after a period of time. Like event timers, they are used to wait for some time while the rest of the system can work or enter low power mode. Since the callback timers call a function when a timer expires, they are especially useful in any code that do not have an explicit Contiki process such as protocol implementations.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;rtimer&amp;#039;&amp;#039;&amp;#039; provides scheduling of real-time tasks. The rtimer library preempts any running Contiki process in order to let the real-time tasks execute at the scheduled time. The real-time tasks are used in time critical codes.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
*Simple implementations of each type of timer&lt;br /&gt;
*Tasks each timer can be used for&lt;br /&gt;
*Some functions in the timer libraries.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Again, we will have to change folders. We will create a new file for this tutorial, but let&amp;#039;s create it in the same directory we&amp;#039;ve been working with, so type&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; cd contiki-2.7/examples/rime &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the terminal. For this tutorial, we will be modifying the example-broadcast.c file we have previously used, so type &lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; cp example-broadcast.c example-timer.c &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into your terminal. You should now see a new file, &amp;quot;example-timer.c&amp;quot; in your directory. Open it up with an editor of your choice (we will use gedit for this tutorial):&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; edit example-timer.c &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
There is currently a working example of an etimer in this code, so before we proceed, let&amp;#039;s understand this. At the beginning of the process, it is declared with&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; static struct etimer et; &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This creates an etimer instance. Within the while loop, it is set with the function&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; etimer_set(&amp;amp;et, CLOCK_SECOND*4 + random_rand() % (CLOCK_SECOND * 4)); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function takes the arguments: &lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; etimer_set(struct etimer *et, clock_time_t interval); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and sets the etimer et to expire after interval.&lt;br /&gt;
&lt;br /&gt;
After that, we see the line: &lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et)); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
which tells the example_broadcast_process to pause until it receives an event, so the program is essentially giving up system control. When an etimer expires, it posts a PROCESS_EVENT_TIMER event to the example_broadcast_process. So this tells the process to continue and begin running again, as the etimer has expired, and an event has been posted. Now that we understand what the etimer is doing here, let&amp;#039;s incorporate some other timers.&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
To start simply, we are going to use a timer to just print out a message once it expires. Just below&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; static struct etimer et; &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
declare a timer with the line: &lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; static struct timer t; &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before the while loop, set the timer with the line: &lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; timer_set(&amp;amp;t, CLOCK_SECOND * 10); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This sets the timer to expire after 10 seconds.&lt;br /&gt;
&lt;br /&gt;
Below the line&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; printf(&amp;quot;broadcast message sent\n&amp;quot;); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
add in the code:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; if(timer_expired(&amp;amp;t)){&lt;br /&gt;
                                 printf(&amp;quot;Timer expired\n&amp;quot;);&lt;br /&gt;
                             }&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, save and run your code on your Tmote Sky by typing into your terminal:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; make TARGET=sky example-timer.upload &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you don&amp;#039;t have a Sky, run this code on Mspsim with the line&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; make TARGET=sky example-timer.mspsim &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Among the &amp;quot;broadcast message sent&amp;quot; messages, you should see a &amp;quot;Timer expired&amp;quot; notice. This only occurs one time, however. This is because we never reset the timer. So, return to your example-timer.c file. Underneath your printf(&amp;quot;Timer expired\n&amp;quot;) line, add the code&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; timer_reset(&amp;amp;t); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will reset the timer to expire again in 10 * CLOCK_SECONDS. Run your code again. You should now see &amp;quot;Timer expired&amp;quot; every few broadcast messages. Now, say we only wanted to send broadcast messages for 30 seconds. Let&amp;#039;s use our timer to exit our process after it expires. Change your original timer_set function to:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; timer_set(&amp;amp;t, CLOCK_SECOND * 30); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, just delete the line&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; timer_reset(&amp;amp;t); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and replace it with&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_EXIT(); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again, and it should stop after the timer expires. You have now learned some basic functionality of the timer.&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&lt;br /&gt;
Begin by deleting the &lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_EXIT(); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
line that you previously wrote. We are going to implement a ctimer and no longer want to exit the process. At the beginning of the process, where you declared the other timers, include the code &lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; static struct ctimer ct &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This declares a ctimer, which has the property of calling a function when it expires. In order to do this, we will need to declare a function for it to call! So, just before the start of the process, underneath the line&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; static struct broadcast_conn broadcast; &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declare the following function:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; static void timer_events(void *ptr){ &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
::::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;printf(&amp;quot;Congratulations, you called this function&amp;quot;);&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, go back to the process. Just before the while loop, set the ctimer by typing&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, NULL); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This set function takes in arguments that tell the ctimer which function to call, as well as what to pass into the function (NULL in this case). Run your code. You will see that your function is called one time, but since we never reset the code, it never gets called again. So, let&amp;#039;s reset the ctimer as part of the function. Just before you set the ctimer, include this line:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; void *ct_ptr = &amp;amp;ct; &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And change your ctimer_set function to read:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, ct_ptr); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now go up to your function, and change it to read like this: &lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; static void timer_events(void *ptr){&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
::::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;printf(&amp;quot;Congratulations, you called this function&amp;quot;);&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
::::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;struct ctimer* ct_ptr = ptr;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
::::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;ctimer_reset(ct_ptr);&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;} &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Now run your code again. The function should be called over and over again. The last thing we will do with this function is learn how to terminate the process from the function, using our same ctimer. To begin, change your c_timer set function to&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 30, timer_events, ct_ptr); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
so the process runs longer before we exit it. Now go up to your function and delete the ctimer_reset line. Replace it with:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; process_exit(&amp;amp;example_broadcast_process); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again. You will see that the example_broadcast_process stops running after 30 seconds, and you have learned how to do this from a function called by a ctimer!&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Timothy</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=283</id>
		<title>Timers</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=283"/>
				<updated>2014-03-05T06:20:18Z</updated>
		
		<summary type="html">&lt;p&gt;Timothy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Timers can be used to control periodic tasks as well as implement sophisticated algorithms. The implementation of each type of timer is platform-dependent and has different properties that make them useful in specific situations; some timers have low granularity (seconds) and overflow once in tens of years, and others provide high granularity (microseconds), but overflow rapidly. There are 5 types of timers provided by Contiki:&lt;br /&gt;
&lt;br /&gt;
* timer&lt;br /&gt;
* stimer&lt;br /&gt;
* ctimer&lt;br /&gt;
* etimer&lt;br /&gt;
* rtimer&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
The functions of all types of timers are located inside folder &amp;#039;&amp;#039;&amp;#039;core/sys/{timer, stimer, ctimer, etimer, rtimer}.{c,h}&amp;#039;&amp;#039;&amp;#039;. A complete documentation of Timers in Contiki can be found [https://github.com/contiki-os/contiki/wiki/Timers here].&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;timer&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;stimer&amp;#039;&amp;#039;&amp;#039; are the most basic types of timers and are used to check if a time interval has passed. They do not notice when the time period has elapsed, so the application needs to check periodically if they have expired. The difference between them is the resolution: &amp;#039;&amp;#039;timers&amp;#039;&amp;#039; use system clock ticks, which gives high granularity (order of microseconds) but short overflow periods (order of seconds). On the other hand, &amp;#039;&amp;#039;stimers&amp;#039;&amp;#039; use seconds to allow much longer time periods (order of years), but has lesser granularity. &lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;etimer&amp;#039;&amp;#039;&amp;#039; provides event timers and are used to schedule events to the processes after a period of time. They are used in Contiki processes to wait for a time period while the rest of the system can work or enter low power mode.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;ctimer&amp;#039;&amp;#039;&amp;#039; provides callback timers and are used to schedule calls to functions after a period of time. Like event timers, they are used to wait for some time while the rest of the system can work or enter low power mode. Since the callback timers call a function when a timer expires, they are especially useful in any code that do not have an explicit Contiki process such as protocol implementations.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;rtimer&amp;#039;&amp;#039;&amp;#039; provides scheduling of real-time tasks. The rtimer library preempts any running Contiki process in order to let the real-time tasks execute at the scheduled time. The real-time tasks are used in time critical codes.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
*Simple implementations of each type of timer&lt;br /&gt;
*Tasks each timer can be used for&lt;br /&gt;
*Some functions in the timer libraries.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Again, we will have to change folders. We will create a new file for this tutorial, but let&amp;#039;s create it in the same directory we&amp;#039;ve been working with, so type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; cd contiki-2.7/examples/rime &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the terminal. For this tutorial, we will be modifying the example-broadcast.c file we have previously used, so type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; cp example-broadcast.c example-timer.c &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into your terminal. You should now see a new file, &amp;quot;example-timer.c&amp;quot; in your directory. Open it up with an editor of your choice (we will use gedit for this tutorial):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; edit example-timer.c &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
There is currently a working example of an etimer in this code, so before we proceed, let&amp;#039;s understand this. At the beginning of the process, it is declared with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; static struct etimer et; &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This creates an etimer instance. Within the while loop, it is set with the function&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; etimer_set(&amp;amp;et, CLOCK_SECOND*4 + random_rand() % (CLOCK_SECOND * 4)); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function takes the arguments: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; etimer_set(struct etimer *et, clock_time_t interval); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and sets the etimer et to expire after interval.&lt;br /&gt;
&lt;br /&gt;
After that, we see the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et)); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
which tells the example_broadcast_process to pause until it receives an event, so the program is essentially giving up system control. When an etimer expires, it posts a PROCESS_EVENT_TIMER event to the example_broadcast_process. So this tells the process to continue and begin running again, as the etimer has expired, and an event has been posted. Now that we understand what the etimer is doing here, let&amp;#039;s incorporate some other timers.&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
To start simply, we are going to use a timer to just print out a message once it expires. Just below&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; static struct etimer et; &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
declare a timer with the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; static struct timer t; &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before the while loop, set the timer with the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; timer_set(&amp;amp;t, CLOCK_SECOND * 10); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This sets the timer to expire after 10 seconds.&lt;br /&gt;
&lt;br /&gt;
Below the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; printf(&amp;quot;broadcast message sent\n&amp;quot;); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
add in the code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; if(timer_expired(&amp;amp;t)){&lt;br /&gt;
                                 printf(&amp;quot;Timer expired\n&amp;quot;);&lt;br /&gt;
                             }&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, save and run your code on your Tmote Sky by typing into your terminal:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; make TARGET=sky example-timer.upload &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you don&amp;#039;t have a Sky, run this code on Mspsim with the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; make TARGET=sky example-timer.mspsim &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Among the &amp;quot;broadcast message sent&amp;quot; messages, you should see a &amp;quot;Timer expired&amp;quot; notice. This only occurs one time, however. This is because we never reset the timer. So, return to your example-timer.c file. Underneath your printf(&amp;quot;Timer expired\n&amp;quot;) line, add the code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; timer_reset(&amp;amp;t); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will reset the timer to expire again in 10 * CLOCK_SECONDS. Run your code again. You should now see &amp;quot;Timer expired&amp;quot; every few broadcast messages. Now, say we only wanted to send broadcast messages for 30 seconds. Let&amp;#039;s use our timer to exit our process after it expires. Change your original timer_set function to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; timer_set(&amp;amp;t, CLOCK_SECOND * 30); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, just delete the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; timer_reset(&amp;amp;t); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and replace it with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_EXIT(); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again, and it should stop after the timer expires. You have now learned some basic functionality of the timer.&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&lt;br /&gt;
Begin by deleting the &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_EXIT(); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
line that you previously wrote. We are going to implement a ctimer and no longer want to exit the process. At the beginning of the process, where you declared the other timers, include the code &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; static struct ctimer ct &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This declares a ctimer, which has the property of calling a function when it expires. In order to do this, we will need to declare a function for it to call! So, just before the start of the process, underneath the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; static struct broadcast_conn broadcast; &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declare the following function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; static void timer_events(void *ptr){&lt;br /&gt;
                                                printf(&amp;quot;Congratulations, you called this function&amp;quot;);&lt;br /&gt;
                                              }&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, go back to the process. Just before the while loop, set the ctimer by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, NULL); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This set function takes in arguments that tell the ctimer which function to call, as well as what to pass into the function (NULL in this case). Run your code. You will see that your function is called one time, but since we never reset the code, it never gets called again. So, let&amp;#039;s reset the ctimer as part of the function. Just before you set the ctimer, include this line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; void *ct_ptr = &amp;amp;ct; &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And change your ctimer_set function to read:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, ct_ptr); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now go up to your function, and change it to read like this: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; static void timer_events(void *ptr){&lt;br /&gt;
                                                printf(&amp;quot;Congratulations, you called this function&amp;quot;);&lt;br /&gt;
                                                struct ctimer* ct_ptr = ptr;&lt;br /&gt;
                                                ctimer_reset(ct_ptr);&lt;br /&gt;
                                              } &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Now run your code again. The function should be called over and over again. The last thing we will do with this function is learn how to terminate the process from the function, using our same ctimer. To begin, change your c_timer set function to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 30, timer_events, ct_ptr); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
so the process runs longer before we exit it. Now go up to your function and delete the ctimer_reset line. Replace it with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; process_exit(&amp;amp;example_broadcast_process); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again. You will see that the example_broadcast_process stops running after 30 seconds, and you have learned how to do this from a function called by a ctimer!&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Timothy</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=282</id>
		<title>Timers</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=282"/>
				<updated>2014-03-05T05:53:59Z</updated>
		
		<summary type="html">&lt;p&gt;Timothy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Timers can be used to control periodic tasks as well as implement sophisticated algorithms. The implementation of each type of timer is platform-dependent and has different properties that make them useful in specific situations; some timers have low granularity (seconds) and overflow once in tens of years, and others provide high granularity (microseconds), but overflow rapidly. There are 5 types of timers provided by Contiki:&lt;br /&gt;
&lt;br /&gt;
* timer&lt;br /&gt;
* stimer&lt;br /&gt;
* ctimer&lt;br /&gt;
* etimer&lt;br /&gt;
* rtimer&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
The functions of all types of timers are located inside folder &amp;#039;&amp;#039;&amp;#039;core/sys/{timer, stimer, ctimer, etimer, rtimer}.{c,h}&amp;#039;&amp;#039;&amp;#039;. A complete documentation of Timers in Contiki can be found [https://github.com/contiki-os/contiki/wiki/Timers here].&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;timer&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;stimer&amp;#039;&amp;#039;&amp;#039; are the most basic types of timers and are used to check if a time interval has passed. They do not notice when the time period has elapsed, so the application needs to check periodically if they have expired. The difference between them is the resolution: &amp;#039;&amp;#039;timers&amp;#039;&amp;#039; use system clock ticks, which gives high granularity (order of microseconds) but short overflow periods (order of seconds). On the other hand, &amp;#039;&amp;#039;stimers&amp;#039;&amp;#039; use seconds to allow much longer time periods (order of years), but has lesser granularity. &lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;etimer&amp;#039;&amp;#039;&amp;#039; provides event timers and are used to schedule events to the processes after a period of time. They are used in Contiki processes to wait for a time period while the rest of the system can work or enter low power mode.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;ctimer&amp;#039;&amp;#039;&amp;#039; provides callback timers and are used to schedule calls to functions after a period of time. Like event timers, they are used to wait for some time while the rest of the system can work or enter low power mode. Since the callback timers call a function when a timer expires, they are especially useful in any code that do not have an explicit Contiki process such as protocol implementations.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;rtimer&amp;#039;&amp;#039;&amp;#039; provides scheduling of real-time tasks. The rtimer library preempts any running Contiki process in order to let the real-time tasks execute at the scheduled time. The real-time tasks are used in time critical codes.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
*Simple implementations of each type of timer&lt;br /&gt;
*Tasks each timer can be used for&lt;br /&gt;
*Some functions in the timer libraries.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Again, we will have to change folders. We will create a new file for this tutorial, but let&amp;#039;s create it in the same directory we&amp;#039;ve been working with, so type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; cd contiki-2.7/examples/rime &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the terminal. For this tutorial, we will be modifying the example-broadcast.c file we have previously used, so type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; cp example-broadcast.c example-timer.c &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into your terminal. You should now see a new file, &amp;quot;example-timer.c&amp;quot; in your directory. Open it up with an editor of your choice (we will use gedit for this tutorial):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; edit example-timer.c &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
There is currently a working example of an etimer in this code, so before we proceed, let&amp;#039;s understand this. At the beginning of the process, it is declared with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; static struct etimer et; &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This creates an etimer instance. Within the while loop, it is set with the function&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; etimer_set(&amp;amp;et, CLOCK_SECOND*4 + random_rand() % (CLOCK_SECOND * 4)); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function takes the arguments: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; etimer_set(struct etimer *et, clock_time_t interval); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and sets the etimer et to expire after interval.&lt;br /&gt;
&lt;br /&gt;
After that, we see the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et)); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
which tells the example_broadcast_process to pause until it receives an event, so the program is essentially giving up system control. When an etimer expires, it posts a PROCESS_EVENT_TIMER event to the example_broadcast_process. So this tells the process to continue and begin running again, as the etimer has expired, and an event has been posted. Now that we understand what the etimer is doing here, let&amp;#039;s incorporate some other timers.&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
To start simply, we are going to use a timer to just print out a message once it expires. Just below&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; static struct etimer et; &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
declare a timer with the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; static struct timer t; &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before the while loop, set the timer with the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; timer_set(&amp;amp;t, CLOCK_SECOND * 10); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This sets the timer to expire after 10 seconds.&lt;br /&gt;
&lt;br /&gt;
Below the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; printf(&amp;quot;broadcast message sent\n&amp;quot;); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
add in the code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; if(timer_expired(&amp;amp;t)){&lt;br /&gt;
                                 printf(&amp;quot;Timer expired\n&amp;quot;);&lt;br /&gt;
                             }&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, save and run your code on your Tmote Sky by typing into your terminal:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; make TARGET=sky example-timer.upload &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you don&amp;#039;t have a Sky, run this code on Mspsim with the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; make TARGET=sky example-timer.mspsim &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Among the &amp;quot;broadcast message sent&amp;quot; messages, you should see a &amp;quot;Timer expired&amp;quot; notice. This only occurs one time, however. This is because we never reset the timer. So, return to your example-timer.c file. Underneath your printf(&amp;quot;Timer expired\n&amp;quot;) line, add the code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; timer_reset(&amp;amp;t); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will reset the timer to expire again in 10 * CLOCK_SECONDS. Run your code again. You should now see &amp;quot;Timer expired&amp;quot; every few broadcast messages. Now, say we only wanted to send broadcast messages for 30 seconds. Let&amp;#039;s use our timer to exit our process after it expires. Change your original timer_set function to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; timer_set(&amp;amp;t, CLOCK_SECOND * 30); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, just delete the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; timer_reset(&amp;amp;t); &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and replace it with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_EXIT() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again, and it should stop after the timer expires. You have now learned some basic functionality of the timer.&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Timothy</name></author>	</entry>

	</feed>