Esempio n. 1
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(cc2420_process, ev, data)
{
  int len;
  PROCESS_BEGIN();

  PRINTF("cc2420_process: started\n");

  while(1) {
    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
#if CC2420_TIMETABLE_PROFILING
    TIMETABLE_TIMESTAMP(cc2420_timetable, "poll");
#endif /* CC2420_TIMETABLE_PROFILING */
    
    PRINTF("cc2420_process: calling receiver callback\n");

    packetbuf_clear();
    packetbuf_set_attr(PACKETBUF_ATTR_TIMESTAMP, last_packet_timestamp);
    len = cc2420_read(packetbuf_dataptr(), PACKETBUF_SIZE);
    
    packetbuf_set_datalen(len);
    
    NETSTACK_RDC.input();
#if CC2420_TIMETABLE_PROFILING
    TIMETABLE_TIMESTAMP(cc2420_timetable, "end");
    timetable_aggregate_compute_detailed(&aggregate_time,
                                         &cc2420_timetable);
      timetable_clear(&cc2420_timetable);
#endif /* CC2420_TIMETABLE_PROFILING */
  }

  PROCESS_END();
}
Esempio n. 2
0
void echonode(void)
{
    TiCc2420Adapter * cc;
	TiUartAdapter * uart;
	char * msg = "welcome to echonode...";
	uint8 buf[BUF_SIZE];
	uint8 len;

	target_init();
	HAL_SET_PIN_DIRECTIONS();
	wdt_disable();

	led_on(LED_ALL);
	
	hal_delay( 500 );
	led_off( LED_ALL );

	cc = cc2420_construct( (void *)(&g_cc), sizeof(TiCc2420Adapter) );
	uart = uart_construct( (void *)(&g_uart), sizeof(TiUartAdapter) );

	uart_open( uart, 0, 38400, 8, 1, 0x00 );
	uart_write( uart, msg, strlen(msg), 0x00 );
	cc2420_open( cc, 0, NULL, NULL, 0x00 );

	cc2420_setchannel( cc, DEFAULT_CHANNEL );
	cc2420_setrxmode( cc );							// Enable RX
	cc2420_enable_addrdecode( cc );					// 使能地址译码
	cc2420_setpanid( cc, PANID );					// 网络标识
	cc2420_setshortaddress( cc, LOCAL_ADDRESS );	// 网内标识

	hal_enable_interrupts();
 
	while(1) 
	{   
	   
		cc2420_evolve( cc );
		len = cc2420_read( cc, (char*)(&buf[0]), BUF_SIZE, 0x00 );
		if (len > 6)
		{
			uart_putchar( uart, '>' );
            
           

			// switch source address and destination address
			_change(buf[3], buf[7]);
			_change(buf[4], buf[8]);
			_change(buf[5], buf[9]);
			_change(buf[6], buf[10]);
	  
			buf[29] = 56; // simulate data read from sensor
			cc2420_write( cc, (char*)(&buf[0]), len, 0x00 );
			hal_delay( 10 );
		
			// @attention
			// You needn't call cc2420_setrxmode() here, because the hal_cc2420 
			// module will handle it inside. 
			// cc2420_setrxmode( cc ); 
		}
	}
}
Esempio n. 3
0
void _cc2420_listener( void * owner, TiEvent * e )
{
	TiCc2420Adapter * cc = &g_cc;
	char buf[BUF_SIZE];
    uint8 len=0;
	led_toggle( LED_RED );
	while (1)
	{
		len = cc2420_read(cc, &buf[0], BUF_SIZE, 0x00);

		//dbo_putchar( 0x22 );
		//dbo_putchar( len );
		if (len> 0)
		{
			dbo_putchar('>');
			dbo_n8toa(len);
			dbo_putchar(':');
			for(int i=0;i<len;i++)
			{
				dbo_n8toa( buf[i] );
				dbo_putchar(' ');
			}
			dbo_putchar( '\r' );
			dbo_putchar( '\n' );
		}
		else 
			break;
	}
}
Esempio n. 4
0
void _cc2420_listener( void * owner, TiEvent * e )
{
	TiCc2420Adapter * cc = &g_cc;
    TiOpenFrame * opf = (TiOpenFrame *)(&g_opfmem[0]);
    uint8 len=0;

	while (1)
	{
		// If there're more than 1 frames pending inside cc2420 adapter object, then
		// you should repeat to call cc2420_read() until it returns 0. 
		//
		len = cc2420_read(cc, (char*)opf_buffer(opf), opf_size(opf), 0x00);
		if (len > 0)
		{
			opf_set_datalen( opf, len );
			_output_openframe( opf , NULL );
		}
		else 
			break;
	}
}
Esempio n. 5
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(cc2420_process, ev, data)
{
  int len;
  PROCESS_BEGIN();

  PRINTF("cc2420_process: started\n");

  while(1) {
    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);

    PRINTF("cc2420_process: calling receiver callback\n");

    packetbuf_clear();
    packetbuf_set_attr(PACKETBUF_ATTR_TIMESTAMP, last_packet_timestamp);
    len = cc2420_read(packetbuf_dataptr(), PACKETBUF_SIZE);
    
    packetbuf_set_datalen(len);
    
    NETSTACK_RDC.input();
  }

  PROCESS_END();
}
Esempio n. 6
0
//#if (TEST_CHOICE == 1)
void recvnode1(void)
{
    TiCc2420Adapter * cc;
	char * msg = "welcome to recvnode...";
	TiFrame * rxbuf;
	uint8 len;

	target_init();
	HAL_SET_PIN_DIRECTIONS();
	wdt_disable();

	led_open();
	led_on( LED_RED );
	hal_delay( 500 );
	led_off( LED_ALL );
	rtl_init( (void *)dbio_open(38400), (TiFunDebugIoPutChar)dbio_putchar, (TiFunDebugIoGetChar)dbio_getchar, hal_assert_report );
	dbc_mem( msg, strlen(msg) );
	cc = cc2420_construct( (void *)(&g_cc), sizeof(TiCc2420Adapter) );

	cc2420_open( cc, 0, NULL, NULL, 0x00 );
	
	cc2420_setchannel( cc, DEFAULT_CHANNEL );
	cc2420_setrxmode( cc );							//Enable RX
	cc2420_enable_addrdecode( cc );					//使能地址译码
	//cc2420_disable_addrdecode(cc);
	#ifdef TEST_ACK
	cc2420_enable_autoack(cc);
	#endif

	cc2420_setpanid( cc, PANID );					//网络标识
	cc2420_setshortaddress( cc, LOCAL_ADDRESS );	//网内标识

	rxbuf = frame_open( (char*)(&m_rxbuf), FRAME_HOPESIZE(MAX_IEEE802FRAME154_SIZE), 0, 0, 0 );

	hal_enable_interrupts();	
	// when use this scan mode to receive data, interrupt should be disable; otherwise the data will be
	// read twice and in the second time there are no data actually which leads to a assert.
 	// Attention: in this scan mode, MCU always try to read and in my  test it is faster than the transmission of data. 
	// Thus, after 4 times, there no data at all, and the MCU still want to read, which lead to an assert. So we'd better
	// not use this scan mode.
    
	while(1) 
	{
		frame_reset( rxbuf,0,0,0);
		
		cc2420_evolve( cc );

		//len = cc2420_read( cc, frame_startptr( rxbuf), frame_capacity( rxbuf), 0x00 );
		len = cc2420_read( cc, frame_startptr(rxbuf), frame_capacity(rxbuf), 0x00 );
        if ( len)
        {
			frame_setlength( rxbuf,len);
			dbc_write( frame_startptr( rxbuf), len );
			led_toggle( LED_GREEN);
        }
		
		//len = cc2420_read( cc, (char*)(&buf[0]), BUF_SIZE, 0x00 );
	/*	if (len >= 5)
		{
			// output this frame to the computer through uart
			dbo_write( (char*)(&buf[0]), len );
		}*/
		
	}
}