How to restart the timer?

If you have a simple question and just want an answer.
gkrusi
Junior Member
Posts: 7
Joined: Mon May 26, 2014 10:32 pm

How to restart the timer?

Post by gkrusi »

1.) Is it possible to set the timer to 0 or specific value?

2.) Is it possible to stop/pause the timer counting? Or at least stop it from triggering the interrupt in switch statment with timerafter function?

 

 

Thank you for answers!

Gregor Krušič



richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Post by richard »

It's not possible to either stop a timer / reset the counter to a particular value. Instead of resetting the counter to zero I'd suggest maintaining an offset variable that you add to the timer value. Instead of stopping the timer you could use a boolean guard on the case to decide whether to wait for events on the timer, for example:

select {
 // Only wait for events on the timer if t_enabled is non-zero.
 case t_enabled => t :> time:
   ...
   break;
}

One thing worth mentioning is that currently all timers on the same tile return the same time which can be useful when coordinating actions across multiple tasks. If timers could be stopped / reset then you would lose this property.