示例#1
0
int
channel_clear(void)
{
	  int cca;
	  int radio_was_off = 0;
	  PRINTF("CCA\n");
	  /* If the radio is locked by an underlying thread (because we are
	     being invoked through an interrupt), we preted that the coast is
	     clear (i.e., no packet is currently being transmitted by a
	     neighbor). */
	  if(locked) {
	    return 1;
	  }

	  GET_LOCK();
	  if(!receive_on) {
	    radio_was_off = 1;
	    cc2520_on();
	  }
	  /* Make sure that the radio really got turned on. */
	  if(!receive_on) {
	    RELEASE_LOCK();
	    if(radio_was_off) {
	      cc2520_off();
	    }
	    return 1;
	  }
	  cca = cc2520ll_channel_clear();
	  if(radio_was_off) {
	    cc2520_off();
	  }
	  RELEASE_LOCK();
	  return cca;
}
示例#2
0
文件: cc2520.c 项目: 1uk3/contiki
/*---------------------------------------------------------------------------*/
int
cc2520_rssi(void)
{
  int rssi;
  int radio_was_off = 0;

  if(locked) {
    return 0;
  }

  GET_LOCK();

  if(!receive_on) {
    radio_was_off = 1;
    cc2520_on();
  }
  BUSYWAIT_UNTIL(status() & BV(CC2520_RSSI_VALID), RTIMER_SECOND / 100);

  rssi = (int)((signed char)getreg(CC2520_RSSI));

  if(radio_was_off) {
    cc2520_off();
  }
  RELEASE_LOCK();
  return rssi;
}
示例#3
0
文件: cc2520.c 项目: 1uk3/contiki
/*---------------------------------------------------------------------------*/
static int
cc2520_cca(void)
{
  int cca;
  int radio_was_off = 0;

  /* If the radio is locked by an underlying thread (because we are
     being invoked through an interrupt), we preted that the coast is
     clear (i.e., no packet is currently being transmitted by a
     neighbor). */
  if(locked) {
    return 1;
  }

  GET_LOCK();
  if(!receive_on) {
    radio_was_off = 1;
    cc2520_on();
  }

  /* Make sure that the radio really got turned on. */
  if(!receive_on) {
    RELEASE_LOCK();
    if(radio_was_off) {
      cc2520_off();
    }
    return 1;
  }

  BUSYWAIT_UNTIL(status() & BV(CC2520_RSSI_VALID), RTIMER_SECOND / 100);

  cca = CC2520_CCA_IS_1;

  if(radio_was_off) {
    cc2520_off();
  }
  RELEASE_LOCK();
  return cca;
}