Hi,
I am using tmote sky hardware and tinyos-2.x
I have connected output of proximity sensor (digital output 0v-3v) as interrupt 
on port 27.
But as the output of poximity sensor goes low to high tmote is getting hang.
I am sending my code.
Please any one help me to solve the problem.

Thanks

1. BlinkToRadio.h
#ifndef BLINKTORADIO_H
#define BLINKTORADIO_H

enum {
  AM_BLINKTORADIO = 6,
  TIMER_PERIOD_MILLI = 3000,
  STATE_TIME = 50
};

typedef nx_struct BlinkToRadioMsg {
  nx_uint16_t nodeid;
  nx_uint16_t portid[2];
} BlinkToRadioMsg;

#endif

2. BlinkToRadioAppC.nc

#include <Timer.h>
#include "BlinkToRadio.h"

configuration BlinkToRadioAppC {
}
implementation {
  components MainC;
  components LedsC;
  components HplMsp430InterruptC;
  components BlinkToRadioC as App;
  components new TimerMilliC() as Timer0;
  components ActiveMessageC;
  components new AMSenderC(AM_BLINKTORADIO);
  components new DemoSensorC() as Sensor;

  App.Boot -> MainC;
  App.Leds -> LedsC;
  App.Timer0 -> Timer0;
  App.PORTa ->HplMsp430InterruptC.Port27;
  App.Packet -> AMSenderC;
  App.AMPacket -> AMSenderC;
  App.AMControl -> ActiveMessageC;
  App.AMSend -> AMSenderC;
  App.Read -> Sensor;
}

3. BlinkToRadioC.nc

#include <Timer.h>
#include "BlinkToRadio.h"

module BlinkToRadioC {
  uses interface Boot;
  uses interface Leds;
  uses interface Timer<TMilli> as Timer0;
  uses interface HplMsp430Interrupt as PORTa;
  uses interface Read<uint16_t>;
  uses interface Packet;
  uses interface AMPacket;
  uses interface AMSend;
  uses interface SplitControl as AMControl;
}
implementation {

    message_t pkt;
    bool busy ;
    BlinkToRadioMsg* btrpkt;

    task void portFiredTask();
    
     void portFired(){
        
        if (!busy) {
                  btrpkt = (BlinkToRadioMsg*)(call Packet.getPayload(&pkt, 
NULL));
                  btrpkt->nodeid = TOS_NODE_ID;
            btrpkt->portid[0] = 1;
            call Read.read();
        }
        
    }

    void sendarr(){
    
        if (call AMSend.send(AM_BROADCAST_ADDR, &pkt, sizeof(BlinkToRadioMsg)) 
== SUCCESS) {
                atomic{
                busy = TRUE;
            }
              }
    }

    task void portFiredTask(){ portFired();}

    event void Boot.booted() {
        atomic{
            busy = FALSE;
            call PORTa.enable();
            call PORTa.edge(TRUE);
        
        }        
        call AMControl.start();
      }

    event void AMControl.startDone(error_t err) {
            if (err == SUCCESS) {
            call Timer0.startPeriodic(TIMER_PERIOD_MILLI);
            }
            else {
                  call AMControl.start();
            }
      }

      event void AMControl.stopDone(error_t err) {
      }


     async event void PORTa.fired()
     {
        call Leds.led2Toggle();
        post portFiredTask();
        
    }

    event void Timer0.fired() {
        call Leds.led1Toggle();
        atomic{
            if (!busy) {
                  btrpkt = (BlinkToRadioMsg*)(call Packet.getPayload(&pkt, 
NULL));
                  btrpkt->nodeid = TOS_NODE_ID;
            btrpkt->portid[0] = 0;
            call Read.read();
            }
        }
    }

 
    event void Read.readDone(error_t result, uint16_t data) {
        if (result == SUCCESS)
           {    
            atomic{
                btrpkt->portid[2] = data;
            }
            sendarr();
          }
    }

      event void AMSend.sendDone(message_t* msg, error_t err) {
            if (&pkt == msg) {
        call Leds.led0Toggle();
            atomic{
                      busy = FALSE;
                call PORTa.clear();
            }
            }
      }

}


Gaurav Mathur 
D-54 Karakoram Hostel
IIT Delhi
Ph. 9911809832
Email : 
[EMAIL PROTECTED]
[EMAIL PROTECTED]





      
____________________________________________________________________________________
You rock. That's why Blockbuster's offering you one month of Blockbuster Total 
Access, No Cost.  
http://tc.deals.yahoo.com/tc/blockbuster/text5.com
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to