The problem is that you are calling a blocking call from within event
based code, which is illegal:

You need to move line 20 (i.e. call BAMControl.start(); ) into one of
the thread execution contexts, or alternatively call a nonblocking
version of the AMControl.start() function from within Boot.booted().

I've attacked a fully functioning application with this fix, that alos
removes some of the iterations from the for loops on lines 44-50 so
you can actually see the led from that thread blinking.

Kevin


On Fri, Jan 15, 2010 at 8:50 AM, Kevin Klues <[email protected]> wrote:
> I'll take a look at this early next week.
>
> Kevin
>
> On Wed, Jan 13, 2010 at 4:33 PM, Mido <[email protected]> wrote:
>> In the 2nd paragraph of section 3.2 of [1], it is mentioned that there are
>> two ways for an event to wake up.
>> I've tested the first one (when a blocking call is issued) by using the
>> attached code (lines #41, and #64), and indeed the event Timer0.fired
>> interleaves with the thread code block.
>>
>> The second way states that when an interrupt handler posts a task,
>> TOSThreads must context switch to TinyOS thread and execute all pending
>> tasks.
>> However, when the blocking calls are removed, and a long-running loop is
>> added (line #45), the event Timer0.fired did NOT interleave with the thread
>> code.
>>
>> My understanding is that when the HW timer fires, its interrupt handler is
>> invoked, and that interrupt handler preempts any running code (taks, events,
>> thread code, or even other interrupt handlers). The timer interrupt handler
>> shall post a task. That task shall signal the event (e.g. Timer0.event).
>> Since the thread code has the lowest priority, the interrupt handler, the
>> task and the event should all run to completion before the thread code is
>> resumed. But, this is not happening.
>>
>> Is there something that I'm missing?
>>
>> Thanks.
>>
>> [1] TOSThreads: Thread-safe and Non-invasive Preemption in TinyOS
>>
>>
>> Code:
>> 01 typedef struct MsgPayloadStruc
>> 02 {
>> 03      nx_uint16_t SenderID;
>> 04      nx_uint16_t Count;
>> 05 } MsgPayloadStruct;
>> 06 module Msgs {
>> 07      uses {
>> 08              interface Boot; interface Leds;
>> 09              interface Timer<TMilli> as Timer0;
>> 10              interface Thread as SendThread;
>> 11              interface Thread as RecvThread;
>> 12              interface BlockingStdControl as BAMControl;
>> 13              interface BlockingAMSend as BAMSend;
>> 14              interface BlockingReceive as BAMRecv;
>> 15      }
>> 16 }
>> 17 implementation {
>> 18      event void Boot.booted()
>> 19      {
>> 20              call BAMControl.start();
>> 21              call Timer0.startPeriodic(50);
>> 22              if (TOS_NODE_ID==0)
>> 23              call RecvThread.start(NULL);
>> 24              else
>> 25              call SendThread.start(NULL);
>> 26      }
>> 27      event void Timer0.fired()
>> 28      {
>> 29              call Leds.led0Toggle();
>> 30      }
>> 31      event void SendThread.run(void* arg)
>> 32      {
>> 33              MsgPayloadStruct* MsgPayload;
>> 34              message_t Msg;
>> 35              uint32_t i,t,p;
>> 36              uint32_t s;
>> 37              MsgPayload = call
>> BAMSend.getPayload(&Msg,sizeof(MsgPayloadStruct));
>> 38              MsgPayload->Count=0;
>> 39              for(;;)
>> 40              {
>> 41                      //MsgPayload = call
>> BAMSend.getPayload(&Msg,sizeof(MsgPayloadStruct));
>> 42                      MsgPayload->SenderID=TOS_NODE_ID;
>> 43                      if (MsgPayload->Count>=100) MsgPayload->Count=0;
>> else MsgPayload->Count++;
>> 44
>> 45                      for (p=0;p<100000;p++){for (i=0;i<100000;i++) {for
>> (t=0;t<100000;t++){s=i+t-p;}}}
>> 46                      //call BAMSend.send(AM_BROADCAST_ADDR, &Msg,
>> sizeof(MsgPayloadStruct));
>> 47                        call Leds.led1Toggle();
>> 48                      call SendThread.sleep(200);
>> 49              }
>> 50      }
>> 51
>> 52      event void RecvThread.run(void* arg) {
>> 53              MsgPayloadStruct* MsgPayload;
>> 54              message_t Msg;
>> 55              for(;;)
>> 56              {
>> 57                      if(call BAMRecv.receive(&Msg, 500) == SUCCESS)
>> 58                      {
>> 59                              MsgPayload = call
>> BAMRecv.getPayload(&Msg,sizeof(MsgPayloadStruct));
>> 60                              call Leds.led2Toggle();
>> 61                      }
>> 62                      call RecvThread.sleep(500);
>> 63              }
>> 64      }
>> 65 }
>>
>> _______________________________________________
>> Tinyos-help mailing list
>> [email protected]
>> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>>
>
>
>
> --
> ~Kevin
>



-- 
~Kevin

Attachment: TestMsgs.tar.gz
Description: GNU Zip compressed data

_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to