<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://wsn.cse.wustl.edu/index.php?action=history&amp;feed=atom&amp;title=Contiki_-_Understanding_the_code</id>
	<title>Contiki - Understanding the code - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://wsn.cse.wustl.edu/index.php?action=history&amp;feed=atom&amp;title=Contiki_-_Understanding_the_code"/>
	<link rel="alternate" type="text/html" href="http://wsn.cse.wustl.edu/index.php?title=Contiki_-_Understanding_the_code&amp;action=history"/>
	<updated>2026-11-16T00:14:54Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.4</generator>
	<entry>
		<id>http://wsn.cse.wustl.edu/index.php?title=Contiki_-_Understanding_the_code&amp;diff=4062&amp;oldid=prev</id>
		<title>Guillaume: /* Create a protothread */</title>
		<link rel="alternate" type="text/html" href="http://wsn.cse.wustl.edu/index.php?title=Contiki_-_Understanding_the_code&amp;diff=4062&amp;oldid=prev"/>
		<updated>2017-05-03T03:54:48Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Create a protothread&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 03:54, 3 May 2017&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l43&quot; &gt;Line 43:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 43:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Some rules must be known: do not use switch into a protothread; some times you can have unexpected results.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Some rules must be known: do not use switch into a protothread; some times you can have unexpected results.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Do not block a protothread more than &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;some ms &lt;/del&gt;(check the documentation for more details).&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Do not block a protothread more than &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;a few milliseconds &lt;/ins&gt;(check the documentation for more details).&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Working with a protothread ==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Working with a protothread ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Guillaume</name></author>
		
	</entry>
	<entry>
		<id>http://wsn.cse.wustl.edu/index.php?title=Contiki_-_Understanding_the_code&amp;diff=4050&amp;oldid=prev</id>
		<title>Guillaume: /* Working with a protothread */</title>
		<link rel="alternate" type="text/html" href="http://wsn.cse.wustl.edu/index.php?title=Contiki_-_Understanding_the_code&amp;diff=4050&amp;oldid=prev"/>
		<updated>2017-04-25T21:28:20Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Working with a protothread&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 21:28, 25 April 2017&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l110&quot; &gt;Line 110:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 110:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;We will create an event timer that will trigger our function.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;We will create an event timer that will trigger our function.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;To wait for the timer we have two choices (only if we use &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;only &lt;/del&gt;1 timer)&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;To wait for the timer we have two choices (only if we use 1 timer)&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;:&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* PROCESS_WAIT_UNTIL(PROCESS_EVENT_TIMER) we wait until &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;an &lt;/del&gt;timer event is triggered.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* PROCESS_WAIT_UNTIL(PROCESS_EVENT_TIMER) we wait until &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;a &lt;/ins&gt;timer event is triggered.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;periodic_timer)) we wait until this timer has expired.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;periodic_timer)) we wait until this timer has expired.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Let's choose the second option as it is the best one in case you manipulate multiple etimers in the same PROCESS.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Let's choose the second option as it is the best one in case you manipulate multiple etimers in the same PROCESS.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;PROCESS(MyProcess);&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;PROCESS_THREAD(MyProcess, ev, data)&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;PROCESS_THREAD(MyProcess, ev, data)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Guillaume</name></author>
		
	</entry>
	<entry>
		<id>http://wsn.cse.wustl.edu/index.php?title=Contiki_-_Understanding_the_code&amp;diff=4049&amp;oldid=prev</id>
		<title>Guillaume: Created page with &quot;= Contiki description =  The Contiki folder contains various directories. Here are the ones you will be interested in if you want to develop your Contiki app:  * app: contains...&quot;</title>
		<link rel="alternate" type="text/html" href="http://wsn.cse.wustl.edu/index.php?title=Contiki_-_Understanding_the_code&amp;diff=4049&amp;oldid=prev"/>
		<updated>2017-04-25T21:25:46Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;= Contiki description =  The Contiki folder contains various directories. Here are the ones you will be interested in if you want to develop your Contiki app:  * app: contains...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Contiki description =&lt;br /&gt;
&lt;br /&gt;
The Contiki folder contains various directories. Here are the ones you will be interested in if you want to develop your Contiki app:&lt;br /&gt;
&lt;br /&gt;
* app: contains apps you can include to you project and use in your code&lt;br /&gt;
* core: contains the code part of ContikiOS (net stack, serial, radio, process, timers...)&lt;br /&gt;
* cpu: contains the code related to each unique CPU&lt;br /&gt;
* platform: contains the code related to the platform you use (2 different platforms can share the same CPU)&lt;br /&gt;
* lib: some extra libraries&lt;br /&gt;
* examples: a list of interesting examples of how to use most of the functionalities and apps available on ContikiOS&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Contiki code =&lt;br /&gt;
&lt;br /&gt;
== Protothreads ==&lt;br /&gt;
&lt;br /&gt;
ContikiOS runs with protothreads, an event based system with non blocking functions. Indeed if a function comes to block the system a watchdog will force the reset of the platform.&lt;br /&gt;
&lt;br /&gt;
== Create a protothread ==&lt;br /&gt;
&lt;br /&gt;
To create a protothread it's easy:&lt;br /&gt;
&lt;br /&gt;
* Create the variable:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PROCESS(MyProcess, &amp;quot;Optional name that can be ignored at compilation time (saves ROM memory)&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Create the thread:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PROCESS_THREAD(MyProcess, ev, data)&lt;br /&gt;
{&lt;br /&gt;
    PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
    // Your code&lt;br /&gt;
&lt;br /&gt;
    PROCESS_END();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Additionally you can add it to a header file for external access&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PROCESS_NAME(MyProcess);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some rules must be known: do not use switch into a protothread; some times you can have unexpected results.&lt;br /&gt;
&lt;br /&gt;
Do not block a protothread more than some ms (check the documentation for more details).&lt;br /&gt;
&lt;br /&gt;
== Working with a protothread ==&lt;br /&gt;
&lt;br /&gt;
Now that we have the skeleton of our protothread we need to be able to work with it.&lt;br /&gt;
&lt;br /&gt;
You must know that a protothread is a function that exits at some point to continue working later. If you want to save variables from one event to another you must declare static variables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PROCESS_THREAD(MyProcess, ev, data)&lt;br /&gt;
{&lt;br /&gt;
    // Declare your static variables&lt;br /&gt;
    static int a;&lt;br /&gt;
&lt;br /&gt;
    PROCESS_BEGIN();&lt;br /&gt;
    // Initialize them AFTER PROCESS_BEGIN();&lt;br /&gt;
    // (you can also declare them static here)&lt;br /&gt;
    a = 0; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    PROCESS_END();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next step is to continue using this PROCESS as long as we need it. For that, usually, the PROCESS contains a while(1) loop.&lt;br /&gt;
&lt;br /&gt;
But in order not to block the PROCESS we need to add one of the following functions:&lt;br /&gt;
&lt;br /&gt;
* PROCESS_WAIT_EVENT(): waits until ANY event occurs, you can then manually sort which event it was with the ev variable.&lt;br /&gt;
* PROCESS_WAIT_EVENT_UNTIL(condition): waits until THIS condition is true.&lt;br /&gt;
* PROCESS_PAUSE(): pauses the process and emits a PAUSE event to continue at this point after the execution of other processes.&lt;br /&gt;
* PROCESS_WAIT_UNTIL(event): wait until event is triggered.&lt;br /&gt;
* PROCESS_WAIT_WHILE(event): wait while event is triggered.&lt;br /&gt;
&lt;br /&gt;
There are some other functions you might want to use such as:&lt;br /&gt;
&lt;br /&gt;
* PROCESS_EXIT() to exit the current running process&lt;br /&gt;
* process_post(struct process *p, process_event_t ev, process_data_t data): to post a asynchronous event (the process will wait its turn)&lt;br /&gt;
* process_post_synch(struct process *p, process_event_t ev, process_data_t data): to post a synchronous event (the process will be immediately called)&lt;br /&gt;
&lt;br /&gt;
Simply speaking our code looks like this now:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PROCESS_THREAD(MyProcess, ev, data)&lt;br /&gt;
{&lt;br /&gt;
    // Declare your static variables&lt;br /&gt;
    static int a;&lt;br /&gt;
&lt;br /&gt;
    PROCESS_BEGIN();&lt;br /&gt;
    // Initialize them AFTER PROCESS_BEGIN();&lt;br /&gt;
    // (you can also declare them static here)&lt;br /&gt;
    a = 0; &lt;br /&gt;
&lt;br /&gt;
    while(1)&lt;br /&gt;
    {&lt;br /&gt;
        PROCESS_WAIT_EVENT();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    PROCESS_END();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now to go further we want to create a hello world PROCESS that will print &amp;quot;Hello world %d!&amp;quot; with %d being the variable a incremented each second.&lt;br /&gt;
&lt;br /&gt;
We will create an event timer that will trigger our function.&lt;br /&gt;
&lt;br /&gt;
To wait for the timer we have two choices (only if we use only 1 timer)&lt;br /&gt;
&lt;br /&gt;
* PROCESS_WAIT_UNTIL(PROCESS_EVENT_TIMER) we wait until an timer event is triggered.&lt;br /&gt;
* PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;periodic_timer)) we wait until this timer has expired.&lt;br /&gt;
&lt;br /&gt;
Let's choose the second option as it is the best one in case you manipulate multiple etimers in the same PROCESS.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PROCESS_THREAD(MyProcess, ev, data)&lt;br /&gt;
{&lt;br /&gt;
    // Declare your static variables&lt;br /&gt;
    static int a;&lt;br /&gt;
    static struct etimer periodic_timer;&lt;br /&gt;
&lt;br /&gt;
    PROCESS_BEGIN();&lt;br /&gt;
    // Initialize them AFTER PROCESS_BEGIN();&lt;br /&gt;
    // (you can also declare them static here)&lt;br /&gt;
    a = 0;&lt;br /&gt;
&lt;br /&gt;
    // CLOCK_SECONDS gives the number of counts to get to 1s. THOSE ARE NOT MILLISECONDS (e.g. some are 128 tics / second)&lt;br /&gt;
    etimer_set(&amp;amp;periodic_timer, CLOCK_SECOND*1);&lt;br /&gt;
&lt;br /&gt;
    while(1)&lt;br /&gt;
    {&lt;br /&gt;
        PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;periodic_timer));&lt;br /&gt;
        // And we don't forget to reset the timer:&lt;br /&gt;
        etimer_reset(&amp;amp;periodic_timer);&lt;br /&gt;
&lt;br /&gt;
        printf(&amp;quot;Hello world %d!&amp;quot;, a++);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    PROCESS_END();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Advanced use ==&lt;br /&gt;
&lt;br /&gt;
Many more functions and possibilities are available. For that you may want to take a look at:&lt;br /&gt;
* The documentating (you should generate your own doxygen documentation using the contiki folder)&lt;br /&gt;
* Taking a look at the files in core/sys (process.h for the protothreads)&lt;/div&gt;</summary>
		<author><name>Guillaume</name></author>
		
	</entry>
</feed>