Beispiel #1
0
//------------------------------------------------------------------------------
//      void main (void)
//
//      DESCRIPTION:
//              Startup routine and main loop
//------------------------------------------------------------------------------
int main (void)
{
    uint8_t i,length;
    uint32_t cnt;

    nrk_setup_ports(); 
    nrk_setup_uart (UART_BAUDRATE_115K2);
 
    printf( "Basic TX...\r\n" ); 
    nrk_led_set(0); 
    nrk_led_set(1); 
    nrk_led_clr(2); 
    nrk_led_clr(3); 
/*
	    while(1) {
		   
				for(i=0; i<40; i++ )
					halWait(10000);
		    nrk_led_toggle(1);

	    }

*/

    rfRxInfo.pPayload = rx_buf;
    rfRxInfo.max_length = RF_MAX_PAYLOAD_SIZE;
		nrk_int_enable();
    rf_init (&rfRxInfo, 26, 0x2420, 0x1214);
    cnt=0;
    while(1){
	  		DPDS1 |= 0x3;
			DDRG |= 0x1;
			PORTG |= 0x1;
			DDRE|=0xE0;
			PORTE|=0xE0;
    		rfTxInfo.pPayload=tx_buf;
    		sprintf( tx_buf, "%lu", cnt); 
    		rfTxInfo.length= strlen(tx_buf) + 1;
				rfTxInfo.destAddr = 0x1215;
				rfTxInfo.cca = 0;
				rfTxInfo.ackRequest = 0;
				
				printf( "Sending\r\n" );
	//			nrk_gpio_set(NRK_DEBUG_0);
				if(rf_tx_packet(&rfTxInfo) != 1)
					printf("--- RF_TX ERROR ---\r\n");
	//			nrk_gpio_clr(NRK_DEBUG_0);
				cnt++;
		
				for(i=0; i<10; i++ )
					halWait(10000);
				nrk_led_toggle(RED_LED);
		}

}
Beispiel #2
0
int8_t _bmac_tx()
{
uint8_t v,backoff, backoff_count;
uint16_t b;

#ifdef DEBUG
nrk_kprintf( PSTR("_bmac_tx()\r\n"));
#endif
if(cca_active)
{

// Add random time here to stop nodes from synchronizing with eachother
b=_nrk_time_to_ticks(&_bmac_check_period);
b=b/((rand()%10)+1);
//printf( "waiting %d\r\n",b );
nrk_wait_until_ticks(b);
//nrk_wait_ticks(b);

	backoff_count=1;
	do{
	v=_bmac_channel_check();
	rf_rx_off(); 
	if(v==1) break;
	// Channel is busy
	backoff=rand()%(_b_pow(backoff_count));
			#ifdef DEBUG
			printf( "backoff %d\r\n",backoff );
			#endif
//	printf( "backoff %d\r\n",backoff );
	nrk_wait_until_next_n_periods(backoff);
	backoff_count++;
	if(backoff_count>6) backoff_count=6; // cap it at 64	
	b=_nrk_time_to_ticks(&_bmac_check_period);
	b=b/((rand()%10)+1);
//	printf( "waiting %d\r\n",b );
	nrk_wait_until_ticks(b);
//	nrk_wait_ticks(b);

	} while(v==0);
}

	rf_test_mode();
	rf_carrier_on(); 
	nrk_wait(_bmac_check_period);
	//nrk_wait_until_next_period();
	rf_carrier_off(); 
	rf_data_mode();
	// send packet
	rf_rx_off();
	pkt_got_ack=rf_tx_packet (&bmac_rfTxInfo);
	rf_rx_off(); 	
tx_data_ready=0;
nrk_event_signal (bmac_tx_pkt_done_signal);
return NRK_OK;
}
Beispiel #3
0
//------------------------------------------------------------------------------
//      void main (void)
//
//      DESCRIPTION:
//              Startup routine and main loop
//------------------------------------------------------------------------------
int main (void)
{
    uint8_t cnt,i,length;

    nrk_setup_ports(); 
    nrk_setup_uart (UART_BAUDRATE_115K2);
 
    printf( "Basic TX...\r\n" ); 
    nrk_led_set(0); 
    nrk_led_set(1); 
    nrk_led_clr(2); 
    nrk_led_clr(3); 
/*
	    while(1) {
		   
				for(i=0; i<40; i++ )
					halWait(10000);
		    nrk_led_toggle(1);

	    }

*/

    rfRxInfo.pPayload = rx_buf;
    rfRxInfo.max_length = RF_MAX_PAYLOAD_SIZE;
		nrk_int_enable();
    rf_init (&rfRxInfo, 13, 0x2420, 0x1214);
    cnt=0;
    while(1){
				nrk_led_set(GREEN_LED);
    		rfTxInfo.pPayload=tx_buf;
    		sprintf( tx_buf, "This is my string counter %d", cnt); 
    		rfTxInfo.length= strlen(tx_buf) + 1;
				rfTxInfo.destAddr = 0x1215;
				rfTxInfo.cca = 0;
				rfTxInfo.ackRequest = 0;
				
				printf( "Sending\r\n" );
				nrk_gpio_set(NRK_DEBUG_0);
				if(rf_tx_packet(&rfTxInfo) != 1)
					printf("--- RF_TX ERROR ---\r\n");
				nrk_gpio_clr(NRK_DEBUG_0);
				cnt++;
		
				for(i=0; i<80; i++ )
					halWait(10000);
				nrk_led_clr(GREEN_LED);
				for(i=0; i<20; i++ )
					halWait(10000);
		}

}
Beispiel #4
0
void Task3 ()
{
  int8_t v;
 
  uint8_t pckts=0;
  printf ("radio stuff Task3 PID=%d\r\n", nrk_get_pid ());


  while (slip_started () != 1)
    nrk_wait_until_next_period ();

  while (1) {

    v = slip_rx (slip_rx_buf, MAX_SLIP_BUF);
		
		printf("nanork@ bytesread %d\n",v);
		//for (i=0;i<v;i++) printf("<%d>",slip_rx_buf[i]);
		//printf("\n");

    if (v > HDR_SIZE) {

      ack_buf[0] = 'Z';
			ack_buf[1] = slip_rx_buf[1];
			ack_buf[2] = slip_rx_buf[2];
    	while(uart_tx_busy==1) nrk_wait_until_next_period();
      uart_tx_busy=1;
      slip_tx (ack_buf, 3);
      uart_tx_busy=0;
      
   

      rfTxInfo.pPayload = slip_rx_buf;
      rfTxInfo.length= v;
      rfTxInfo.destAddr = 0xFFFF;
      rfTxInfo.cca = 0;
      rfTxInfo.ackRequest = 0;

    	nrk_led_toggle (RED_LED);
      pckts++;
      PORTG=0x1;
      
      if(rf_tx_packet(&rfTxInfo) != 1) {
          printf("--- RF_TX ERROR ---\r\n");
          nrk_spin_wait_us(10000);
        } 

     
  	}

  }
}
Beispiel #5
0
int8_t _bmac_tx()
{
	uint8_t v,result, backoff, backoff_count;
	uint16_t b;
	
	if(cca_active) {
				// Add random time here to stop nodes from synchronizing with eachother
				b=_nrk_time_to_ticks(&_bmac_check_period);
        b=b/((rand()%10)+1);
				//printf( "waiting %d\r\n",b );
        nrk_wait_until_ticks(b);
				//nrk_wait_ticks(b);

        backoff_count=1;
        do
        {
            v=_bmac_channel_check();
            rf_rx_off();
            if(v==1) break;
            // Channel is busy
            backoff=rand()%(_b_pow(backoff_count));
						
						//	printf( "backoff %d\r\n",backoff );
            nrk_wait_until_next_n_periods(backoff);
            backoff_count++;
            if(backoff_count>6) backoff_count=6; // cap it at 64
            b=_nrk_time_to_ticks(&_bmac_check_period);
            b=b/((rand()%10)+1);
						//	printf( "waiting %d\r\n",b );
            nrk_wait_until_ticks(b);
						//	nrk_wait_ticks(b);
					}
        while(v==0);
    }
	
	// Give check_period worth of channel activity
	rf_test_mode();
	rf_carrier_on();
	nrk_wait(_bmac_check_period);
	rf_carrier_off();
	rf_data_mode();
		
		rf_rx_off();
		pkt_got_ack = rf_tx_packet(&bmac_rfTxInfo);
		rf_rx_off();
		tx_data_ready = 0;
	// Should signal user task here that Tx is done
	return NRK_OK;
}
Beispiel #6
0
//------------------------------------------------------------------------------
//      void main (void)
//
//      DESCRIPTION:
//              Startup routine and main loop
//------------------------------------------------------------------------------
int main (void)
{
    uint8_t cnt,i,length;

    nrk_setup_ports(); 
    nrk_setup_uart (UART_BAUDRATE_115K2);
 
    printf( "Basic TX...\r\n" ); 
    nrk_led_clr(0); 
    nrk_led_clr(1); 
    nrk_led_clr(2); 
    nrk_led_clr(3); 

    nrk_gpio_set(NRK_DEBUG_0);
    nrk_gpio_set(NRK_DEBUG_1);

    rfRxInfo.pPayload = rx_buf;
    rfRxInfo.max_length = RF_MAX_PAYLOAD_SIZE;
    rf_init (&rfRxInfo, 25, 0x2420, 0x1215);
    cnt=0;
    while(1)
	{
		nrk_led_set(1);
    		rfTxInfo.pPayload=tx_buf;
    		sprintf( tx_buf, "This is my string counter %d", cnt); 
    		rfTxInfo.length=strlen(&tx_buf);
    		rfTxInfo.cca=0;
		nrk_gpio_set(NRK_DEBUG_0);
		printf( "Sending\r\n" );
		rf_tx_packet (&rfTxInfo);
		nrk_gpio_clr(NRK_DEBUG_0);
		cnt++;
		for(i=0; i<10; i++ )
			halWait(10000);
		nrk_led_clr(1);
		for(i=0; i<10; i++ )
			halWait(10000);
	}


}