[Tinyos-help] Task is not interrupted by timer event

Reichmann, Juergen Juergen.Reichmann at siemens.com
Tue Apr 3 04:08:35 PDT 2007


Hi,

I wrote the following test code for checking different TinyOS 1.x behaviours. The timer fires every 6 seconds. During the event handle routine I switch the green led on for 1 second, post the testTask and end with switching on the yellow led for 1 second. Inside the testTask I switch on the red led for also 1 second.

I tested this code on telosb hardware. The behaviour is correct:

Green light on
Waiting about 1 second
Green light off
Yellow light on
Waiting about 1 second
Yellow light off
Red light on
Waiting about 1 second
Red light off

I.e., the task is scheduled correct after the fired event is processed.

module TestMoteM
{
  provides interface StdControl;
  uses interface Timer;
  uses interface Leds;
}

implementation
{
  command result_t StdControl.init()
  {
  	call Leds.init();
    return SUCCESS;
  }


  command result_t StdControl.start()
  {
    call Timer.start (TIMER_REPEAT, 6000);
    return SUCCESS;
  }


  command result_t StdControl.stop()
  {
    call Timer.stop();
    return SUCCESS;
  }


  void wait(uint16_t s)
  {
    uint16_t i, j;

    for (j=0; j<s; j++)
      for (i=0; i<50; i++)
        TOSH_uwait(10000);
  }


  task void testTask()
  {
    call Leds.redOn();
    wait(1);
    call Leds.redOff();
  }


  event result_t Timer.fired()
  {
    call Leds.greenOn();
    wait(1);
    call Leds.greenOff();

    post testTask();

    call Leds.yellowOn();
    wait(1);
    call Leds.yellowOff();

    return SUCCESS;
  }
}


In the second test case I changed the testTask as follows:

  task void testTask()
  {
    call Leds.redOn();
    wait(10);
    call Leds.redOff();
  }

I.e. the red light is on for about 10 seconds during the testTask is running.

What I would expect is that during the red light of the testTask is on, the Timer fires again (because the timer delay is shorter than task processing length), the new fired event interrupts the testTask, and the green light goes on. But this doesn't happen. The new fired event is processed after the testTask is finished.

Is this behaviour correct? By which kind of events the testTask would be interrupted? Or is anything in principle wrong in my code?

Best regards,

Jürgen


-- 
Jürgen Reichmann
Siemens AG, CT SE 2
D-81730 Munich, Germany      
Phone: +49 (0) 89 636 45455
Email: juergen.reichmann at siemens.com

Siemens Aktiengesellschaft: Vorsitzender des Aufsichtsrats: Heinrich v. Pierer;
Vorstand: Klaus Kleinfeld, Vorsitzender; Johannes Feldmayer, Joe Kaeser, Rudi Lamprecht, Eduardo Montes, Jürgen Radomski, Erich R. Reinhardt, Hermann Requardt, Uriel J. Sharef, Klaus Wucherer Sitz der Gesellschaft: Berlin und München
Registergericht: Berlin Charlottenburg, HRB 12300, München, HRB 6684 WEEE-Reg.-Nr. DE 23691322



More information about the Tinyos-help mailing list