Mido,

In general, there is no preemption of any kind in vanilla tinyos.  There 
are interrupts which can disrupt the normal execution of a program, 
these are usually denoted by the "async" keyword.  There is only a 
single thread of execution so if one event or task takes a very long 
time, it will delay other tasks.

If you want to execute a very long computation (without backlogging 
events) it would be best to split it up into many different parts and 
execute each one as a task.  That way the task is executed as soon as 
processor becomes idle.

You may want to reference 
http://docs.tinyos.net/index.php/Modules_and_the_TinyOS_Execution_Model 
for more details.

There have been some attempts at preemption: 
http://www.tinyos.net/scoop/story/2007/7/9/10921/69539 and TOSTHREADS 
are among them if preemption is required for your purposes.

-Paul

On 1/2/2010 12:12 PM, Mido wrote:
> Hi,
>
>
> I'd always assumed that events can preempt events.
>
> For example, in the below code, the event AMSend.sendDone should preempt
> Timer1.fired (as Timer1.fired runs for a long time).
>
> However, this is not happening.
> Things do not change when I move the code inside Timer1.fired to a task, and
> post this task from Timer1.fired.
>
> So, do events preempt other events?
>
> One more question:
> Section 1.2.1 of the TinyOS programming book (2nd edition), mentions
> "Low-level interrupt code".
> How can I find the interrupt code that is related certain events such as
> Timer.fired, AMSend.sendDone, and Sensor.readDone.
>
> Thanks.
>
>
> event void Boot.booted() {call AMControl.start(); }
> event void AMControl.startDone(error_t err) {if (err == SUCCESS) {call
> Timer0.startPeriodic(900); call Timer1.startPeriodic(1000); } else {call
> AMControl.start();} }
> event void AMControl.stopDone(error_t err) { }
> event void Timer0.fired()
> {
> if (!busy)
> {
>       BlinkToRadioMsg* btrpkt = (BlinkToRadioMsg*)(call
> Packet.getPayload(&pkt, NULL));
>       btrpkt->nodeid = TOS_NODE_ID;
>       btrpkt->counter = counter;
>       if (call AMSend.send(AM_BROADCAST_ADDR,&pkt,
> sizeof(BlinkToRadioMsg)) == SUCCESS) {busy = TRUE;}
> }
> }
> event void AMSend.sendDone(message_t* msg, error_t error) {   if (&pkt ==
> msg) {busy = FALSE;}}
> event void Sensor.readDone(error_t result, uint16_t data)  {}
>
> event void Timer1.fired()
> {
> t=269;p=40;
> for (t=0;t<100;t++){for (i=0;i<10000;i++){n+=p;n=0;n*=p+5;}}call
> Leds.led0Toggle();
> }
>
> _______________________________________________
> Tinyos-help mailing list
> Tinyos-help@millennium.berkeley.edu
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>    
_______________________________________________
Tinyos-help mailing list
Tinyos-help@millennium.berkeley.edu
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to