Ejemplo n.º 1
0
void radio_stop(void)
{
    if(radio_status == FMRADIO_OFF)
        return;

    radio_off();
} /* radio_stop */
Ejemplo n.º 2
0
void radio_init(void)
{
    tuner_init();
    radio_off();
#ifdef HAVE_ALBUMART
    radioart_init(false);
#endif
}
Ejemplo n.º 3
0
void radio_rfOff() {
   // change state
   radio_vars.state = RADIOSTATE_TURNING_OFF;
   radio_off();
   // wiggle debug pin
   debugpins_radio_clr();
   leds_radio_off();
   //enable radio interrupts
   disable_radio_interrupts();
   
   // change state
   radio_vars.state = RADIOSTATE_RFOFF;
}
Ejemplo n.º 4
0
/*---------------------------------------------------------------------------*/
static char
plb_powercycle(void)
{

  PRINT_P("plb_powercycle [sr:%d cw:%d]\n",send_req,c_wait);

  PT_BEGIN(&pt);
  while(1) {
    // check on/send state
    if(send_req == 1 && c_wait==1){
    	PRINTF("plb_powercycle send DATA <start>\n");
    	send_req = 0;	//avoid repeat sending
    	plb_send_data(sent_callback, sent_ptr);
    	PRINTF("plb_powercycle send DATA <end>\n");
    	radio_off();
    	NETSTACK_MAC.input();
    }

    /* on */
    radio_on();
    rtimer_set(&rt, RTIMER_NOW() + PC_ON_TIME, 1,
	       (void (*)(struct rtimer *, void *))plb_powercycle, NULL);
    PT_YIELD(&pt);

    /* off */
    if(wait_packet == 0){
      radio_off();
    }
    else if (wait_packet > 0)
    {
    	wait_packet = 0;
    }
    rtimer_set(&rt, RTIMER_NOW() + PC_OFF_TIME, 1,
	       (void (*)(struct rtimer *, void *))plb_powercycle, NULL);
    PT_YIELD(&pt);
  }
  PT_END(&pt);
}
Ejemplo n.º 5
0
/*---------------------------------------------------------------------------*/
static char
plb_send_strobe(rimeaddr_t *dst, int *acked, uint8_t type)
{
  PRINTF("plb_send_strobe  [dst: %u.%u] [type: %x]\n",dst->u8[0],dst->u8[1],type);

  uint8_t strobe[MAX_STROBE_SIZE];
  int strobe_len = 0;
  rtimer_clock_t wt;

  // Make PLB header
  packetbuf_clear();
  if( (strobe_len = plb_create_header(dst,type)) < 0 ){
    return -1;
  }

  // Make packet -> strobe
  strobe_len = strobe_len +1;	// assign space for packet type
  if( strobe_len > (int)sizeof(strobe)) {
    /* Failed to send */
    PRINTF("plb: send failed, too large header\n");
    return -1;
  }
  memcpy(strobe, packetbuf_hdrptr(), strobe_len);

  /* Send beacon and wait ack : STROBE_NUM_MAX times */
  int strobe_num = 0;
  radio_on();

  while((strobe_num < STROBE_NUM_MAX) && ((*acked) == 0)){
    PRINTF("plb_send_strobe : strobe %d\n",strobe_num);

#if DEBUG_PACKET
    print_packet(strobe, strobe_len);
#endif

    if(NETSTACK_RADIO.send(strobe, strobe_len) != RADIO_TX_OK){
      return -1;
    }
    strobe_num ++;

    (*acked) = plb_wait_ack(type);
    if(*acked){
      PRINTF("ack! return: %d\n", *acked);
    }
  }
  radio_off();
  return 0;
}
Ejemplo n.º 6
0
void nrf_tx(char data) {
	char tmp = nrf_read(NRF_FIFO_STATUS);
	if(tmp & NRF_STAT_TX_FULL) {
		return;
	}
	radio_on();
	spi_csl();
	spi_send(NRF_TX);
	spi_send(data);
	spi_csh();
	nrf_ceh();
	//start transmission (pulse CE > 10us)
	__delay_cycles(20);
	nrf_cel();
	__delay_cycles(1000);
	radio_off();
}
Ejemplo n.º 7
0
/*---------------------------------------------------------------------------*/
static void
plb_send_ack(uint8_t type){

	uint8_t ack[MAX_ACK_SIZE];
	int ack_len = 0;

	//set address from input packet
	addr_ack.u8[0]=packetbuf_addr(PACKETBUF_ADDR_SENDER)->u8[0];
	addr_ack.u8[1]=packetbuf_addr(PACKETBUF_ADDR_SENDER)->u8[1];

	PRINTF("plb_send_ack [dst: %u.%u] [type: %x]\n",  addr_ack.u8[0], addr_ack.u8[1], type);

	packetbuf_clear();
	if ((ack_len = plb_create_header(&addr_ack, type)) < 0) {
		PRINTF("ERROR: plb_create_header ");
		return;
	}
	ack_len++;


	//Make ack frame//
	if (ack_len > (int) sizeof(ack)) {
		// Failed to send //
		PRINTF("plb: send failed, too large header\n");
		return;
	}

	memcpy(ack, packetbuf_hdrptr(), ack_len);

	// Send beacon and wait ack : STROBE_NUM_MAX times //
	radio_on();

#if DEBUG_PACKET
	print_packet(ack, ack_len);
#endif

	if (NETSTACK_RADIO.send(ack, ack_len) != RADIO_TX_OK) {
		PRINTF("ERROR: plb ack send");
		return;
	}
	radio_off();
	return;
}
Ejemplo n.º 8
0
void radio_setFrequency(uint8_t frequency) {

   // change state
   radio_vars.state = RADIOSTATE_SETTING_FREQUENCY;

   radio_off();
   // configure the radio to the right frequecy
   if((frequency < CC2538_RF_CHANNEL_MIN) || (frequency > CC2538_RF_CHANNEL_MAX)) {
	  while(1);
      return;
    }

    /* Changes to FREQCTRL take effect after the next recalibration */
   HWREG(RFCORE_XREG_FREQCTRL) = (CC2538_RF_CHANNEL_MIN
        + (frequency - CC2538_RF_CHANNEL_MIN) * CC2538_RF_CHANNEL_SPACING);

   radio_on();
   
   // change state
   radio_vars.state = RADIOSTATE_FREQUENCY_SET;
}
Ejemplo n.º 9
0
/*---------------------------------------------------------------------------*/
static int
plb_send_data(mac_callback_t sent, void *ptr)
{

	PRINTF("plb_send_data\n");

	int ret; //what is it? JJH
	int last_sent_ok = 0;
	int acked;
	int temp=0;

	acked = 0;

	if(packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE)==0) //if packet_type ==0, DATA JJH_START
	{
		plb_send_strobe(packetbuf_addr(PACKETBUF_ADDR_NEXT),&acked,PREAMBLE);
		if(acked==1)
		{
			PRINTF("plb_send_data DATA_PREAMBLE_ACKED!\n");
			packetbuf_clear();
			packetbuf_copyfrom(dataptr_temp,temp_len);
			if (plb_create_header(packetbuf_addr(PACKETBUF_ADDR_NEXT),DATA) < 0)
			{
				PRINTF("ERROR: plb_create_header ");
				return -1; //ERROR case : -1
			}
//			hold_time(INTER_PACKET_INTERVAL * 5000); //future
			radio_on();
			PRINTF("plb_send_data send DATA packet\n");
			print_packet(packetbuf_hdrptr(), packetbuf_totlen());

			if(NETSTACK_RADIO.send(packetbuf_hdrptr(), packetbuf_totlen())!=RADIO_TX_OK)
			{
				PRINTF("plb_send_data DATA error!\n");
				return -1; //ERROR case
				ret = MAC_TX_ERR;
			}
			acked=plb_wait_data_ack(DATA); //just once?

			if(acked==1) //data ack received
			{
				PRINTF("plb_send_data DATA_ACKED!\n");
				last_sent_ok=1;
				ret=MAC_TX_OK;
			}
			else if(!acked)
			{
				PRINTF("plb_send_data DATA error: no ack!\n");
				ret=MAC_TX_ERR;
			}
			//sent connect
			mac_call_sent_callback(sent, ptr, ret, 1);
			radio_off();
			packetbuf_clear(); // add kdw
			return last_sent_ok;
		}
		else if(acked==2)//if receive preamble ack data
		{
			PRINTF("PREAMBLE ACK DATA RECEIVED!\n");
		}
		else//do not receive any ack, do nothing
		{
			PRINTF("DO NOT RECEIVED PREAMBLE ACK : error!!!\n");
		}

	}//JJH_END

	return 0;
}
Ejemplo n.º 10
0
void radio_tx_finish()
{
    radio_tx_data(radio_tx_crc);
    radio_off();
    ei();
}
Ejemplo n.º 11
0
void nrf_init_radio(void) {
    nrf_write(NRF_SETUP_RETR, SETUP_RETR); //no auto retransmit
	nrf_write(NRF_CONFIG, CONFIG);
    radio_off();
}
Ejemplo n.º 12
0
void radio_init() {

   // clear variables
   memset(&radio_vars,0,sizeof(radio_vars_t));
   
   // change state
   radio_vars.state          = RADIOSTATE_STOPPED;
   //flush fifos
   CC2538_RF_CSP_ISFLUSHRX();
   CC2538_RF_CSP_ISFLUSHTX();

   radio_off();

   //disable radio interrupts
   disable_radio_interrupts();

   /* This CORR_THR value should be changed to 0x14 before attempting RX. Testing has shown that
      * too many false frames are received if the reset value is used. Make it more likely to detect
      * sync by removing the requirement that both symbols in the SFD must have a correlation value
      * above the correlation threshold, and make sync word detection less likely by raising the
      * correlation threshold.
      */
   HWREG(RFCORE_XREG_MDMCTRL1) = 0x14;
   /* tuning adjustments for optimal radio performance; details available in datasheet */

   HWREG(RFCORE_XREG_RXCTRL) = 0x3F;
   /* Adjust current in synthesizer; details available in datasheet. */
   HWREG(RFCORE_XREG_FSCTRL) = 0x55;

     /* Makes sync word detection less likely by requiring two zero symbols before the sync word.
      * details available in datasheet.
      */
   HWREG(RFCORE_XREG_MDMCTRL0) = 0x85;

   /* Adjust current in VCO; details available in datasheet. */
   HWREG(RFCORE_XREG_FSCAL1) = 0x01;
   /* Adjust target value for AGC control loop; details available in datasheet. */
   HWREG(RFCORE_XREG_AGCCTRL1) = 0x15;


   /* Tune ADC performance, details available in datasheet. */
   HWREG(RFCORE_XREG_ADCTEST0) = 0x10;
   HWREG(RFCORE_XREG_ADCTEST1) = 0x0E;
   HWREG(RFCORE_XREG_ADCTEST2) = 0x03;

   //update CCA register to -81db as indicated by manual.. won't be used..
   HWREG(RFCORE_XREG_CCACTRL0) = 0xF8;
   /*
    * Changes from default values
    * See User Guide, section "Register Settings Update"
    */
   HWREG(RFCORE_XREG_TXFILTCFG) = 0x09;    /** TX anti-aliasing filter bandwidth */
   HWREG(RFCORE_XREG_AGCCTRL1) = 0x15;     /** AGC target value */
   HWREG(ANA_REGS_O_IVCTRL) = 0x0B;        /** Bias currents */

   /* disable the CSPT register compare function */
   HWREG(RFCORE_XREG_CSPT) = 0xFFUL;
   /*
    * Defaults:
    * Auto CRC; Append RSSI, CRC-OK and Corr. Val.; CRC calculation;
    * RX and TX modes with FIFOs
    */
   HWREG(RFCORE_XREG_FRMCTRL0) = RFCORE_XREG_FRMCTRL0_AUTOCRC;

   //poipoi disable frame filtering by now.. sniffer mode.
   HWREG(RFCORE_XREG_FRMFILT0) &= ~RFCORE_XREG_FRMFILT0_FRAME_FILTER_EN;

   /* Disable source address matching and autopend */
   HWREG(RFCORE_XREG_SRCMATCH) = 0;

     /* MAX FIFOP threshold */
   HWREG(RFCORE_XREG_FIFOPCTRL) = CC2538_RF_MAX_PACKET_LEN;

   HWREG(RFCORE_XREG_TXPOWER) = CC2538_RF_TX_POWER;
   HWREG(RFCORE_XREG_FREQCTRL) = CC2538_RF_CHANNEL_MIN;

   /* Enable RF interrupts  see page 751  */
//      enable_radio_interrupts();

   //register interrupt
   IntRegister(INT_RFCORERTX, radio_isr);
   IntRegister(INT_RFCOREERR, radio_error_isr);

   IntPrioritySet(INT_RFCORERTX, HAL_INT_PRIOR_MAC);
   IntPrioritySet(INT_RFCOREERR, HAL_INT_PRIOR_MAC);

   IntEnable(INT_RFCORERTX);


     /* Enable all RF Error interrupts */
   HWREG(RFCORE_XREG_RFERRM) = RFCORE_XREG_RFERRM_RFERRM_M; //all errors
   IntEnable(INT_RFCOREERR);
   //radio_on();
   // change state
   radio_vars.state          = RADIOSTATE_RFOFF;
}
Ejemplo n.º 13
0
void start_radio_off(void)
{
	radio_off(-1);
}
Ejemplo n.º 14
0
void start_radio_off_1(void)
{
	radio_off(1);
}
Ejemplo n.º 15
0
void start_radio_off_0(void)
{
	radio_off(0);
}