コード例 #1
0
ファイル: bmac.c プロジェクト: jonleung/AccelPlot
void bmac_nw_task ()
{
int8_t v;
int8_t e;
uint8_t backoff;
nrk_sig_mask_t event;

while(bmac_started()==0) nrk_wait_until_next_period();

//register the signal after bmac_init has been called
v=nrk_signal_register(bmac_enable_signal); 
if(v==NRK_ERROR) nrk_kprintf( PSTR("Failed to register signal\r\n"));
backoff=0;
    while (1) {
    #ifdef NRK_SW_WDT
	#ifdef BMAC_SW_WDT_ID
	nrk_sw_wdt_update(BMAC_SW_WDT_ID);
	#endif
    #endif
	if(is_enabled ) { 
	v=1;
	if(rx_buf_empty==1) v=_bmac_channel_check();
	// If the buffer is full, signal the receiving task again.
	else e=nrk_event_signal (bmac_rx_pkt_signal);
	// bmac_channel check turns on radio, don't turn off if
	// data is coming.
		if(v==0)
			{
			if(_bmac_rx()==1)
			  {
				e=nrk_event_signal (bmac_rx_pkt_signal);
				//if(e==NRK_ERROR) {
				//	nrk_kprintf( PSTR("bmac rx pkt signal failed\r\n"));
				//	printf( "errno: %u \r\n",nrk_errno_get() );
				//}
			  }
			  //else nrk_kprintf( PSTR("Pkt failed, buf could be corrupt\r\n" ));
			} 
		if(/*rx_buf_empty==1 &&*/ tx_data_ready==1)
			{
				rf_rx_off(); 
				_bmac_tx();
			}
	//do {
		nrk_wait(_bmac_check_period); 
	//	if(rx_buf_empty!=1)  nrk_event_signal (bmac_rx_pkt_signal);
	//} while(rx_buf_empty!=1);
	} else {
		event=0;
		do {
		v=nrk_signal_register(bmac_enable_signal); 
    		event=nrk_event_wait (SIG(bmac_enable_signal));
		} while((event & SIG(bmac_enable_signal))==0);
	}
	//nrk_wait_until_next_period();
	}

}
コード例 #2
0
ファイル: bmac.cpp プロジェクト: ESE519/EVM-2013
void bmac_nw_task()
{
	int8_t v;
	int8_t e;
	uint8_t backoff;
	nrk_sig_mask_t event;
	
	while(bmac_started() == 0) {
		nrk_wait_until_next_period();
	}
	
	while(1) {
		
		if(is_enabled)
		{
		v = 1;
		rf_rx_on();
		if(rx_buf_empty) {
				v = _bmac_channel_check();
		} else {
			e = nrk_event_signal(bmac_rx_pkt_signal); // Mb
			// Should signal user task here as a "reminder"
		}
		
		if(v == 0) {
				// Channel detected as busy, attept to Rx
			_bmac_rx();
				// Should signal user task here to notify of Rx 
		}
		else if(tx_data_ready) {
			// Only try to Tx if the channel is free
			rf_rx_off(); // Mb
			_bmac_tx();
		}
		
		//rf_rx_off(); // Mb
		nrk_wait(_bmac_check_period);
		
		}
	else
	{
			event =0;
			do
			{
				v = nrk_signal_register(bmac_enable_signal);
				event = nrk_event_wait(SIG(bmac_enable_signal));
			}
			while((event & SIG(bmac_enable_signal))==0);
	}
			
		
	}
}