title: Contiki delay in seconds
body: <p>I am trying to develop a contiki piece of code in which I need to wait for three seconds for a transducer output. Although this may sound quite un-transducer like, at development time, I want to simulate the behavior at human readable speeds and hence I need to set the timer to say 3 seconds.</p>
  
  <p>The contiki timer <a href="http://contiki.sourceforge.net/docs/2.6/a01664.html" rel="nofollow noreferrer">library</a> is pretty well <a href="https://github.com/contiki-os/contiki/wiki/Timers" rel="nofollow noreferrer">documented</a> and has a good series of examples which mention the creation, setting and resetting of the timer. However, if I have code like the following:</p>
  
  <pre><code>timer_set(&amp;transducerOutputWaitTimer);
  bool if_blk_executed;
  if(timer_expired(&amp;&amp;transducerOutputWaitTimer)){
      if_blk_executed = true;
      //do something
  }
  if(if_blk_executed)
     printf("Sunrise");
  else
     printf("It is not dawned yet");
  </code></pre>
  
  <p>Now the expiry is not immediately triggered after the timer is set. So the if block is never executed. Effectively it will never dawn.</p>
  
  <p>Now there are two ways in which I can get the system to wait. One, by adding a while loop on the timer like this:
     while(!timer_expired(&amp;&amp;transducerOutputWaitTimer)){};
     //do something</p>
  
  <p>or
     cpu_delay_usecs{mytimerdur_in_secs*10^6*};
     //do something</p>
  
  <p>I do not see that either approaches are elegant. While one wastes CPU cycles, the other enforces an unnecessarily large computation.</p>
  
  <p>Is there any better way? I know that clock</p>
  
  <p>Attached to this question are the following two:</p>
  
  <ol>
  <li><p>How can I trigger one Contiki protothread from another? If I can do this, I can get the interrupt that causes the transducerOutput to invoke a process from which I can trigger the etimer and process events.</p></li>
  <li><p>What exactly does the CPU delay mean? Does this mean that the entire CPU clock cycles get held back for the given duration? If yes, how are other processes running currently in the system affected?</p></li>
  </ol>
  
  <p><strong>Updates</strong>
  Update 1: the while method did not work. The code possibly went into an infinite loop.
  Update 2: I tried with a clock_delay(3*CLOCK_SECOND) approach after setting my timer. It worked. However, in this case, why do I need the timer method at all?</p>
  
  <p>Update 3 (This changes the context of the answer, hence adding this comment as per the suggestion)</p>
  
  <p>My Timer needs to be used outside a process in a different void function. In that case, I need to use the timer() library rather than the etimer (which is specific to a process. So how do I get my method to wait for the desired time in such cases? </p>