I resolve...the arbitration of the bus is already implemented...damn...I
must only use the components as the bus wasn't shared.
Thank to all....

2010/9/21 Massimo Marra <[email protected]>

> Hi,
> I have some problem about Arbitration of the Usart Bus.
>
> I'm using Tmote Sky (telosb) on TinyOS version 2.1.1
>
> I want to use it to send message via CC2420 and the pin UART0TX too.
> I already read TEP 108 and lesson number 8 of the tutorial section.
>
> I try to implement a simple application (modify of BlinkToRadio
> Application) in witch I try to send every 200ms a message ONLY through
> the radio.
> So I request the resource0 every 200ms from a periodic Timer, and
> release it in the sendDone event handler.
> BUT I NEVER RECEIVE THE "SENDDONE" EVENT...and I don't understand
> why...anybody can help me?
> Is possible that the operating system is not able to understand at whom
> send back the "sendDone" event.
> In this application moreover the bus is never really disputed...
>
> Is the wiring correct?
>
> Only if i set the TIMER_PERIOD greater (for example 5000ms) and release
> the resource after the "send" calling (and so before the "sendDone"
> event) I receive the SendDone....I'm in trouble...please help me!!
>
> I hope that the resource to use the radio is correct (Msp430Spi0C).
>
> Here I put My code...try to run it!
> Thanks a lot
>
> Massimo Marra
>
>
>
> -----------------------------BlinkToRadio.h---------------------------------------------
>  #ifndef BLINKTORADIO_H
>  #define BLINKTORADIO_H
>
>  enum {
>      TIMER_PERIOD_MILLI = 200,
>    AM_BLINKTORADIOMSG = 6
>  };
>
>
>  typedef nx_struct BlinkToRadioMsg {
>     nx_uint16_t nodeId;
>     nx_uint8_t byte1;
>     nx_uint8_t byte2;
>     nx_uint8_t byte3;
>     nx_uint8_t data[2];
>  }BlinkToRadioMsg;
>
>
> #endif
>
>
>
>
>
>
> -----------------------------BlinkToRadioAppC.nc---------------------------------------------
> #include "Timer.h"
> #include "BlinkToRadio.h"
> #include "msp430usart.h"
>
>  configuration BlinkToRadioAppC {
>  }
>  implementation {
>    components MainC;
>    components LedsC;
>    components BlinkToRadioC as App;
>    components new TimerMilliC() as Timer0;
>    components CC2420TimeSyncMessageC;
>       *    components new Msp430Spi0C() as Radio;
>
>
>    App.Boot -> MainC;
>    App.Leds -> LedsC;
>    App.Timer0 -> Timer0;
>
>     App.Receive-> CC2420TimeSyncMessageC.Receive[AM_BLINKTORADIOMSG];
>      App.AMControl->CC2420TimeSyncMessageC.SplitControl;
>      App.Packet->CC2420TimeSyncMessageC.Packet;
>       App.AMPacket->CC2420TimeSyncMessageC.AMPacket;
>     App.TimeSyncPacket -> CC2420TimeSyncMessageC.TimeSyncPacket32khz;
>       App.TimeSyncAMSend ->
> CC2420TimeSyncMessageC.TimeSyncAMSend32khz[AM_BLINKTORADIOMSG];
>
>     App.Resource0->Radio;
>
> }
>
>
>
>
>
>
>
> -----------------------------BlinkToRadioC.nc---------------------------------------------
> #include <Timer.h>
>  #include "BlinkToRadio.h"
> #include "printf.h"
>
>  module BlinkToRadioC {
>    uses interface Boot;
>    uses interface Leds;
>    uses interface Timer<TMilli> as Timer0;
>
>    uses interface Packet;
>    uses interface AMPacket;
>    uses interface TimeSyncPacket<T32khz,uint32_t>;
>    uses interface TimeSyncAMSend<T32khz,uint32_t>;
>    uses interface SplitControl as AMControl;
>    uses interface Receive;
>
>     //Resource Arbitrated
>     uses interface Resource as Resource0;
>
>     provides {
>      interface Msp430SpiConfigure;
>     }
>
>  }
>  implementation {
>    uint8_t byte1= 0;
>    uint8_t byte2= 0;
>    uint8_t byte3= 0;
>
>    bool busy = FALSE;
>    message_t pkt;
>    BlinkToRadioMsg* outPtr;
>
>
> msp430_spi_union_config_t msp430_spi_default_config = {
>   {
>     ubr : 0x0002,
>     ssel : 0x02,
>     clen : 1,
>     listen : 0,
>     mm : 1,
>     ckph : 1,
>     ckpl : 0,
>     stc : 1
>   }
> };
>
>
>     async command msp430_spi_union_config_t* Msp430SpiConfigure.getConfig()
>     {
>         return &msp430_spi_default_config;
>     }
>
>
>    event void Boot.booted() {
>      call AMControl.start();
>      //set three random values
>      byte1=(uint8_t)23;
>      byte2=(uint8_t)129;
>      byte3=(uint8_t)55;
>      outPtr = (BlinkToRadioMsg*) (call Packet.getPayload(&pkt, 0));
>      call Timer0.startPeriodic(TIMER_PERIOD_MILLI);
>     }
>
>    event void AMControl.startDone(error_t err) {
>        if (err == FAIL) {
>          call AMControl.start();
>          }
>    }
>
>    event void AMControl.stopDone(error_t err){}
>
>      event void Timer0.fired(){
>          //The resource Spi is requested every 200ms
>          call Resource0.request();
>        }
>
>    event void TimeSyncAMSend.sendDone(message_t* msg, error_t error){
>            //Here I release the resource
>            call Resource0.release();
>            busy=FALSE;
>            if (error == FAIL){
>                call Leds.led2On();
>                printf("\ndendDone() event COMPLETE! (send fail))\n\n");
>              printfflush();
>                }
>            if (&pkt == msg) {
>                printf("\ndendDone() event COMPLETE! (send fail))\n\n");
>              printfflush();
>            }
>    }
>
>    event message_t* Receive.receive(message_t* msg, void* payload,
> uint8_t len){return msg;}
>
>
>
>     task void sendRadioMsg(){
>         if (!busy){
>         atomic{ //call TimeSyncAMSend.send(am_addr_t addr, message_t *msg,
> uint8_t len, size_type event_time)
>             if (call TimeSyncAMSend.send(AM_BROADCAST_ADDR, &pkt,
> sizeof(BlinkToRadioMsg), 300) == SUCCESS) //300 is a unimportant value!
>              {
>                 busy = TRUE;
>                  printf("The radio want to try to send the Msg.\n");
>                  printfflush();
>                  }else {
>                      printf("send call FAIL!.\n");
>                      printfflush();
>                      call Leds.led0On();}
>         }
>         }else{
>             //do nothing
>             printf("System are waiting for a SendDone event..\n");
>             printfflush();
>             }
>     }
>
>     event void Resource0.granted(){
>         atomic{
>                byte1=((byte1+1)%255);
>                byte2=((byte2+1)%255);
>                byte3=((byte3+1)%255);
>                }
>           outPtr->nodeId = TOS_NODE_ID;
>          outPtr->byte1 = byte1;
>          outPtr->byte2 = byte2;
>          outPtr->byte3 = byte3;
>          //Try to send the message
>          post sendRadioMsg();
>
>     }
>
> }
>
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to