Exemple #1
0
/**
 * @fn halBoardInit
 * @brief
 * Initialize the hardware target board. After this initialization, you can run your 
 * application or startup the operating system(OS).
 *
 * @param   none
 * @return  none
 */
void target_init(void)
{
    /* @todo I think you should place disable interrupts here. */

	hal_init( NULL, NULL );
    mcu_init();
    hal_disable_interrupts();
    
    rtl_init( (void*)dbio_open(9600), (TiFunDebugIoPutChar)dbio_putchar, (TiFunDebugIoGetChar)dbio_getchar, 
        hal_assert_report );

	/*
    MCU_IO_OUTPUT(HAL_BOARD_IO_LED_1_PORT, HAL_BOARD_IO_LED_1_PIN, 0);
    MCU_IO_OUTPUT(HAL_BOARD_IO_LED_2_PORT, HAL_BOARD_IO_LED_2_PIN, 0);
    MCU_IO_OUTPUT(HAL_BOARD_IO_LED_3_PORT, HAL_BOARD_IO_LED_3_PIN, 0);
    MCU_IO_OUTPUT(HAL_BOARD_IO_LED_4_PORT, HAL_BOARD_IO_LED_4_PIN, 0);

    MCU_IO_INPUT(HAL_BOARD_IO_BTN_1_PORT, HAL_BOARD_IO_BTN_1_PIN, MCU_IO_TRISTATE);
    MCU_IO_INPUT(HAL_BOARD_IO_BTN_2_PORT, HAL_BOARD_IO_BTN_2_PIN, MCU_IO_TRISTATE);

    halLcdSpiInit();
    halLcdInit();
    halAssyInit();
				  
	*/
}
Exemple #2
0
static int rtl8169_eth_probe(struct udevice *dev)
{
	struct pci_child_platdata *pplat = dev_get_parent_platdata(dev);
	struct rtl8169_private *priv = dev_get_priv(dev);
	struct eth_pdata *plat = dev_get_platdata(dev);
	u32 iobase;
	int region;
	int ret;

	debug("rtl8169: REALTEK RTL8169 @0x%x\n", iobase);
	switch (pplat->device) {
	case 0x8168:
		region = 2;
		break;
	default:
		region = 1;
		break;
	}
	dm_pci_read_config32(dev, PCI_BASE_ADDRESS_0 + region * 4, &iobase);
	iobase &= ~0xf;
	priv->iobase = (int)dm_pci_mem_to_phys(dev, iobase);

	ret = rtl_init(priv->iobase, dev->name, plat->enetaddr);
	if (ret < 0) {
		printf(pr_fmt("failed to initialize card: %d\n"), ret);
		return ret;
	}

	return 0;
}
Exemple #3
0
// auto_rtl_start - initialises RTL in AUTO flight mode
void Copter::auto_rtl_start()
{
    auto_mode = Auto_RTL;

    // call regular rtl flight mode initialisation and ask it to ignore checks
    rtl_init(true);
}
Exemple #4
0
int rtl8169_initialize(bd_t *bis)
{
	pci_dev_t devno;
	int card_number = 0;
	struct eth_device *dev;
	u32 iobase;
	int idx=0;

	while(1){
		unsigned int region;
		u16 device;

		/* Find RTL8169 */
		if ((devno = pci_find_devices(supported, idx++)) < 0)
			break;

		pci_read_config_word(devno, PCI_DEVICE_ID, &device);
		switch (device) {
		case 0x8168:
			region = 2;
			break;

		default:
			region = 1;
			break;
		}

		pci_read_config_dword(devno, PCI_BASE_ADDRESS_0 + (region * 4), &iobase);
		iobase &= ~0xf;

		debug ("rtl8169: REALTEK RTL8169 @0x%x\n", iobase);

		dev = (struct eth_device *)malloc(sizeof *dev);
		if (!dev) {
			printf("Can not allocate memory of rtl8169\n");
			break;
		}

		memset(dev, 0, sizeof(*dev));
		sprintf (dev->name, "RTL8169#%d", card_number);

		dev->priv = (void *) devno;
		dev->iobase = (int)pci_mem_to_phys(devno, iobase);

		dev->init = rtl_reset;
		dev->halt = rtl_halt;
		dev->send = rtl_send;
		dev->recv = rtl_recv;

		eth_register (dev);

		rtl_init(dev, bis);

		card_number++;
	}
	return card_number;
}
Exemple #5
0
/**
 * @fn halBoardInit
 * @brief
 * Initialize the hardware target board. After this initialization, you can run your
 * application or startup the operating system(OS).
 *
 * @param   none
 * @return  none
 */
void target_init(void)
{
    /* @todo I think you should place disable interrupts here. */

    hal_init( NULL, NULL );
    mcu_init();
    hal_disable_interrupts();

    rtl_init( (void*)dbio_open(9600), (TiFunDebugIoPutChar)dbio_putchar, (TiFunDebugIoGetChar)dbio_getchar,
              hal_assert_report );
}
Exemple #6
0
int main(int argc,char *argv[])
{
	signal	(SIGPIPE,SIG_IGN);

	rtl_init();
	rtl_tracemutex();
	rtl_tracelevel(2);
	MainTbPoll	= rtl_pollInit();

	AwZclInitProto();

	ZclUdpBind();
	MainLoop();
	return	0;
}
Exemple #7
0
int bb_init() 
{
    vuc * const g28 = REGC(0xa1000000);
    vus * const g216 = REGS(0xa1000000);
    vul * const g232 = REGL(0xa1000000);
    
    int i;
    unsigned int tmp;
        
    /* Initialize the "GAPS" PCI glue controller.
       It ain't pretty but it works. */
    g232[0x1418/4] = 0x5a14a501;		/* M */
    i = 10000;
    while (!(g232[0x1418/4] & 1) && i > 0)
	i--;
    if (!(g232[0x1418/4] & 1)) {
	return -1;
    }
    g232[0x1420/4] = 0x01000000;
    g232[0x1424/4] = 0x01000000;
    g232[0x1428/4] = 0x01840000;		/* DMA Base */
    g232[0x142c/4] = 0x01840000 + 32*1024;	/* DMA End */
    g232[0x1414/4] = 0x00000001;
    g232[0x1434/4] = 0x00000001;
    
    /* Configure PCI bridge (very very hacky). If we wanted to be proper,
       we ought to implement a full PCI subsystem. In this case that is
       ridiculous for accessing a single card that will probably never
       change. Considering that the DC is now out of production officially,
       there is a VERY good chance it will never change. */
    g216[0x1606/2] = 0xf900;
    g232[0x1630/4] = 0x00000000;
    g28[0x163c] = 0x00;
    g28[0x160d] = 0xf0;
    (void)g216[0x04/2];
    g216[0x1604/2] = 0x0006;
    g232[0x1614/4] = 0x01000000;
    (void)g28[0x1650];

    rtl_init();

    return 0;
}
Exemple #8
0
bool rtl_handler(const void *in, register_stack *stack)
{
    const exception_table_entry *passed;
    uint32 intr;

    passed = (exception_table_entry *) in;

    /* STAGE: First, identify and clear out the interrupts. We don't want it
        to *keep* yelling at us. */
    intr = RTL_IO_SHORT(RTL_INTRSTATUS);
    RTL_IO_SHORT(RTL_INTRSTATUS) = intr;

    /* STAGE: Check if we received packets. */
    if (intr & RTL_INT_RX_OK)
        rtl_rx_all();

#ifdef DEBUG_RTL8139C
    /* STAGE: These are handled by the chip because I told it too. I'll warn
        myself anyway, though. */
    if (intr & RTL_INT_RXFIFO_OVERFLOW)
        ubc_serial_write_str("[UBC] RTL8193c FIFO overflow!\r\n");
#endif

    /* STAGE: Handle overflows relatively harshly. I'm taking this solution
        from the BSD guys, though. I'm willing to bet they have a little
        experience in this. */
    if (intr & RTL_INT_RXBUF_OVERFLOW)
    {
#ifdef RTL_OVERFLOW_BSD
        rtl_init();     /* I'm taking a page out of the BSD book... */
#else   /* handle it Linux style. */
        rtl_stop();
        
        rtl_info.cur_rx = RTL_IO_SHORT(RTL_RXBUFHEAD) % RX_BUFFER_LEN;
        RTL_IO_SHORT(RTL_RXBUFTAIL) = rtl_info.cur_rx - RX_BUFFER_THRESHOLD;

        rtl_start();
#endif
    }

    /* STAGE: Return from the handler */
    return TRUE;
}
int rtl8169_initialize(bd_t *bis)
{
	pci_dev_t devno;
	int card_number = 0;
	struct eth_device *dev;
	u32 iobase;
	int idx=0;

	while(1){
		/* Find RTL8169 */
		if ((devno = pci_find_devices(supported, idx++)) < 0)
			break;

		pci_read_config_dword(devno, PCI_BASE_ADDRESS_1, &iobase);
		iobase &= ~0xf;

		debug ("rtl8169: REALTEK RTL8169 @0x%x\n", iobase);

		dev = (struct eth_device *)malloc(sizeof *dev);

		sprintf (dev->name, "RTL8169#%d", card_number);

		dev->priv = (void *) devno;
		dev->iobase = (int)pci_mem_to_phys(devno, iobase);

		dev->init = rtl_reset;
		dev->halt = rtl_halt;
		dev->send = rtl_send;
		dev->recv = rtl_recv;

		eth_register (dev);

		rtl_init(dev, bis);

		card_number++;
	}
	return card_number;
}
Exemple #10
0
void Task1()
{
  uint8_t j, i;
  uint8_t *local_rx_buf;
  uint8_t length,slot;
  int8_t rssi;
  uint8_t cnt;
  uint16_t counter;
  volatile nrk_time_t t;
  printf( "Task1 PID=%d\r\n",nrk_get_pid());
  counter=0;
  cnt=0;
 

//  nrk_led_set(0);
  rtl_init (RTL_MOBILE);
  rtl_set_schedule( RTL_RX, MY_RX_SLOT, 1 );
  //rtl_set_schedule( RTL_RX, 12, 1 );
  rtl_set_schedule( RTL_TX, MY_TX_SLOT, 1 );
//  rtl_set_contention( 8, 1 );
  rtl_start();
  
  rtl_rx_pkt_set_buffer(rx_buf, RF_MAX_PAYLOAD_SIZE);
 
  while(!rtl_ready())  nrk_wait_until_next_period(); 
  nrk_led_clr(0);
  
  while(1) {

          if( rtl_rx_pkt_check()!=0 )
               {
                   nrk_led_set(BLUE_LED);
                   local_rx_buf=rtl_rx_pkt_get(&length, &rssi, &slot);
                   printf( "Got Packet on slot %d %d: ",slot,length );
                   for(i=PKT_DATA_START; i<length; i++ )
                   {
                        printf( "%c",local_rx_buf[i] );
                   }
                   nrk_kprintf( PSTR("\r\n") );
                   rtl_rx_pkt_release();
                   nrk_led_clr(BLUE_LED);
               }

          if( rtl_tx_pkt_check(MY_TX_SLOT)!=0 )
               {
                  printf( "Pending on slot %d\r\n",MY_TX_SLOT );
               }
          else {
                nrk_led_set(GREEN_LED);
                cnt++;
                sprintf( &tx_buf[PKT_DATA_START], "Hello World %d", cnt );
                length=strlen(&tx_buf[PKT_DATA_START])+PKT_DATA_START;
                rtl_tx_pkt( tx_buf, length, MY_TX_SLOT );
                printf( "Sending Packet on slot %d\r\n",MY_TX_SLOT );
                nrk_led_clr(GREEN_LED);
               }

          rtl_wait_until_rx_or_tx();


        }


}
Exemple #11
0
// set_mode - change flight mode and perform any necessary initialisation
// optional force parameter used to force the flight mode change (used only first time mode is set)
// returns true if mode was successfully set
// ACRO, STABILIZE, ALTHOLD, LAND, DRIFT and SPORT can always be set successfully but the return state of other flight modes should be checked and the caller should deal with failures appropriately
bool Copter::set_mode(control_mode_t mode, mode_reason_t reason)
{
    // boolean to record if flight mode could be set
    bool success = false;
    bool ignore_checks = !motors.armed();   // allow switching to any mode if disarmed.  We rely on the arming check to perform

    // return immediately if we are already in the desired mode
    if (mode == control_mode) {
        prev_control_mode = control_mode;
        prev_control_mode_reason = control_mode_reason;

        control_mode_reason = reason;
        return true;
    }

    switch(mode) {
        case ACRO:
            #if FRAME_CONFIG == HELI_FRAME
                success = heli_acro_init(ignore_checks);
            #else
                success = acro_init(ignore_checks);
            #endif
            break;

        case STABILIZE:
            #if FRAME_CONFIG == HELI_FRAME
                success = heli_stabilize_init(ignore_checks);
            #else
                success = stabilize_init(ignore_checks);
            #endif
            break;

        case ALT_HOLD:
            success = althold_init(ignore_checks);
            break;

        case AUTO:
            success = auto_init(ignore_checks);
            break;

        case CIRCLE:
            success = circle_init(ignore_checks);
            break;

        case LOITER:
            success = loiter_init(ignore_checks);
            break;

        case GUIDED:
            success = guided_init(ignore_checks);
            break;

        case LAND:
            success = land_init(ignore_checks);
            break;

        case RTL:
            success = rtl_init(ignore_checks);
            break;

        case DRIFT:
            success = drift_init(ignore_checks);
            break;

        case SPORT:
            success = sport_init(ignore_checks);
            break;

        case ALT_POS:
        	success = altpos_init(ignore_checks);
        	break;

        case FLIP:
            success = flip_init(ignore_checks);
            break;

#if AUTOTUNE_ENABLED == ENABLED
        case AUTOTUNE:
            success = autotune_init(ignore_checks);
            break;
#endif

#if POSHOLD_ENABLED == ENABLED
        case POSHOLD:
            success = poshold_init(ignore_checks);
            break;
#endif

        case BRAKE:
            success = brake_init(ignore_checks);
            break;

        case THROW:
            success = throw_init(ignore_checks);
            break;

        case AVOID_ADSB:
            success = avoid_adsb_init(ignore_checks);
            break;

        case GUIDED_NOGPS:
            success = guided_nogps_init(ignore_checks);
            break;

        default:
            success = false;
            break;
    }

    // update flight mode
    if (success) {
        // perform any cleanup required by previous flight mode
        exit_mode(control_mode, mode);
        
        prev_control_mode = control_mode;
        prev_control_mode_reason = control_mode_reason;

        control_mode = mode;
        control_mode_reason = reason;
        DataFlash.Log_Write_Mode(control_mode, control_mode_reason);

        adsb.set_is_auto_mode((mode == AUTO) || (mode == RTL) || (mode == GUIDED));

#if AC_FENCE == ENABLED
        // pilot requested flight mode change during a fence breach indicates pilot is attempting to manually recover
        // this flight mode change could be automatic (i.e. fence, battery, GPS or GCS failsafe)
        // but it should be harmless to disable the fence temporarily in these situations as well
        fence.manual_recovery_start();
#endif
    }else{
        // Log error that we failed to enter desired flight mode
        Log_Write_Error(ERROR_SUBSYSTEM_FLIGHT_MODE,mode);
    }

    // update notify object
    if (success) {
        notify_flight_mode(control_mode);
    }

    // return success or failure
    return success;
}
Exemple #12
0
void dbo_open( uint16 baudrate )
{
    dbio_open( baudrate );
    rtl_init( (void*)&g_dbio, (TiFunDebugIoPutChar)dbio_putchar, (TiFunDebugIoGetChar)dbio_getchar, 
        hal_assert_report );
}
Exemple #13
0
void dbio_init()
{
    dbio_open( 9600 );
    rtl_init( (void*)&g_dbio, (TiFunDebugIoPutChar)dbio_putchar, (TiFunDebugIoGetChar)dbio_getchar, 
        hal_assert_report );
}
Exemple #14
0
void Task1()
{
	int8_t rssi, slot,length; //all parameters recieved along with an rx

	printf( "Task1 PID=%d\r\n",nrk_get_pid());
	printf( "Node ID=%d\r\n",NODE_ID);

	nrk_led_set(RED_LED); 

	rtl_init (RTL_COORDINATOR);
	rtl_set_channel(MY_CHANNEL);

	rtl_set_schedule( RTL_RX, NODE_2_RX_SLOT, 1 );
	rtl_set_schedule( RTL_RX, NODE_3_RX_SLOT, 1 );
	rtl_set_schedule( RTL_TX, MY_TX_SLOT, 1 );
	//rtl_set_tx_power(MAX_POWER);
	rtl_rx_pkt_set_buffer(rx_buf, RF_MAX_PAYLOAD_SIZE); //to limit payload size
	rtl_start();
	
	while(!rtl_ready())  nrk_wait_until_next_period();  

	
	while(1)
	{
		
		if( rtl_tx_pkt_check(MY_TX_SLOT)!=0 )
		{
			//printf("Pending TX");
		}
		else
		{
                	nrk_time_get(&currentTime);
                	if(currentTime.secs-exchangeTime.secs>EXCHANGE_INTERVAL)
                	{
                		//TODO:Data to be transmitted
                		int8_t length;
				//sprintf( &tx_buf[PKT_DATA_START],"",);
				length = sprintf(&tx_buf[PKT_DATA_START], "%-+5d%-+5d",myX,myY); //TODO: Data
				printf ("(%s) is the result of our sprintf, which is %d characters long",tx_buf,length);
				length=length+PKT_DATA_START+1;
				printf("Sending: ");
/*				for(int i=PKT_DATA_START; i<length; i++ )*/
/*				{*/
/*					printf("%c",tx_buf[i] );*/
/*				}*/
/*				printf("\n\r");*/
				addToTXBuffer(tx_buf,length);
				nrk_time_get(&exchangeTime);
                	}
			fetchTxBuffer(); //Actual Transmit
               		nrk_led_toggle(BLUE_LED);
		}
		if( rtl_rx_pkt_check()!=0 )
		{
			int8_t senderNode;
			nrk_led_set(ORANGE_LED);
                   	uint8_t *local_rx_buf;
                   	local_rx_buf=rtl_rx_pkt_get(&length, &rssi, &slot);
                   	printf( "Got Packet on slot %d %d: ",slot,length );
                   	senderNode=slot/2;
                   	if(senderNode==0)
                   	{
                   		int li = atoi (&local_rx_buf[NODE_ID]);
				printf ("\nXrecd=%d",li);
				myX=li;
				li = atoi (&local_rx_buf[NODE_ID+5]);
				printf ("\nYrecd=%d",li);
				myY=li;
			}
                   	else
                   	{
                   		int li = atoi (&local_rx_buf[NODE_ID]);
				printf ("\nXrecd=%d",li);
				X[senderNode]=li;
				li = atoi (&local_rx_buf[NODE_ID+5]);
				printf ("\nYrecd=%d",li);
				Y[senderNode]=li;
                   	}
                   	
		}
		rtl_wait_until_rx_or_tx();
	}
}
Exemple #15
0
int main(void)
{
	uint16 value, count;
	uint8 len;
	char * request;
	char * response;
    char * payload;
	char * msg = "welcome to node...";

	TiTimerAdapter * timeradapter;
	TiTimerManager * vtm;
	TiTimer * mac_timer;
	TiCc2420Adapter * cc;
	TiFrameRxTxInterface * rxtx;
	TiNioAcceptor * nac;
    TiAloha * mac;
	TiAdcAdapter * adc;
	TiLumSensor * lum;
	TiDataTreeNetwork * dtp;
	TiFrame * rxbuf;
	TiFrame * txbuf;

	target_init();

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

	rtl_init( (void *)dbio_open(38400), (TiFunDebugIoPutChar)dbio_putchar, (TiFunDebugIoGetChar)dbio_getchar, hal_assert_report );
	dbc_write( msg, strlen(msg) );

	timeradapter   = timer_construct( (void *)(&m_timeradapter), sizeof(m_timeradapter) );
	vtm            = vtm_construct( (void*)&m_vtm, sizeof(m_vtm) );
	cc             = cc2420_construct( (char *)(&m_cc), sizeof(TiCc2420Adapter) );
	nac            = nac_construct( &m_nacmem[0], NAC_SIZE );
	mac            = aloha_construct( (char *)(&m_aloha), sizeof(TiAloha) );
	dtp            = dtp_construct( (char *)(&m_dtp), sizeof(TiDataTreeNetwork) );
	adc            = adc_construct( (void *)&m_adc, sizeof(TiAdcAdapter) );
	lum            = lum_construct( (void *)&m_lum, sizeof(TiLumSensor) );
	txbuf          = frame_open( (char*)(&m_txbuf), FRAME_HOPESIZE(MAX_IEEE802FRAME154_SIZE), 3, 20, 0 );
	rxbuf          = frame_open( (char*)(&m_rxbuf), FRAME_HOPESIZE(MAX_IEEE802FRAME154_SIZE), 3, 20, 0 );
	// timeradapter is used by the vtm(virtual timer manager). vtm require to enable the 
	// period interrupt modal of vtm

	//timeradapter   = timer_open( timeradapter, 0, NULL, NULL, 0x01 ); 
	vtm            = vtm_open( vtm, timeradapter, CONFIG_VTM_RESOLUTION );
	cc             = cc2420_open(cc, 0, NULL, NULL, 0x00 );
	rxtx           = cc2420_interface( cc, &m_rxtx );
	mac_timer      = vtm_apply( vtm );
	mac_timer      = vti_open( mac_timer, NULL, mac_timer);
	hal_assert( rxtx != NULL );
	nac            = nac_open( nac, rxtx, CONFIG_NIOACCEPTOR_RXQUE_CAPACITY, CONFIG_NIOACCEPTOR_TXQUE_CAPACITY);
	hal_assert( nac != NULL ); 
    

	mac             = aloha_open( mac, rxtx,nac, CONFIG_NODE_CHANNEL, CONFIG_NODE_PANID, CONFIG_NODE_ADDRESS,mac_timer, NULL, NULL,0x01);

	adc            = adc_open( adc, 0, NULL, NULL, 0 );
	lum            = lum_open( lum, 0, adc );
	
	dtp            = dtp_open( dtp, mac, CONFIG_NODE_ADDRESS, NULL, NULL, 0x00 );


	//todo

	cc2420_setchannel( cc, CONFIG_NODE_CHANNEL );
	cc2420_setrxmode( cc );							            // enable RX mode
	cc2420_setpanid( cc, CONFIG_NODE_PANID  );					// network identifier, seems no use in sniffer mode
	cc2420_setshortaddress( cc, CONFIG_NODE_ADDRESS );	// in network address, seems no use in sniffer mode
	cc2420_enable_autoack( cc );

	//todo
	
	cc2420_settxpower( cc, CC2420_POWER_1);//cc2420_settxpower( cc, CC2420_POWER_2);
	cc2420_enable_autoack( cc );

	
//	ledtune        = ledtune_construct( (void*)(&m_ledtune), sizeof(m_ledtune), vti );
//	ledtune        = ledtune_open( ledtune );

	/* assert: all the above open() functions return non NULL values */

	hal_assert((timeradapter != NULL) && (cc != NULL) && (mac != NULL) && (adc != NULL) && (lum != NULL)
		&& (rxbuf != NULL) && (txbuf != NULL) && (dtp != NULL));

	hal_enable_interrupts();

    dtp->state = DTP_STATE_IDLE;//todo for testing 临时用这一句必须删掉

	//todo for testing
   
	//dtp->root = 0x01;//todo for testing
	//dtp->parent = 0x03;//todo for testing
   /*
	while ( 1)//todo for testing
	{
		
		response = frame_startptr( txbuf );

		value = lum_value( lum ); 
		payload = DTP_PAYLOAD_PTR(response);
		payload[0] = 0x13;
		payload[1] = 0x14;
		if (dtp_send_response(dtp, txbuf, 0x01) > 0)
		{ 
			led_toggle( LED_RED);//todo for testing
			
		}

        dtp_evolve( dtp, NULL );
		
		hal_delay( 2000);//todo for testing

	}

     */




	while(1)
	{
		/* Only the following two kinds of frames will be put into "rxbuf" by dtp_recv()
		 * - broadcast frames. the destination address of these frames are 0xFFFF.
		 * - destination is the current node. 
		 */
		//dbo_putchar(0x33);


		len = dtp_recv( dtp, rxbuf, 0x00 );
		if (len > 0)
		{   
            
  		    //ieee802frame154_dump( rxbuf);

			request = frame_startptr( rxbuf );

			switch (DTP_CMDTYPE(request))
			{
			/* if the frame is DTP_DATA_REQUEST, then the node will measure the data and 
			 * encapsulate the data into the txbuf, which is a TiOpenFrame and sent it back.
			 */


		

			case DTP_DATA_REQUEST:
				//payload = DTP_PAYLOAD_PTR( frame_startptr(txbuf) );
				//ledtune_write( ledtune, MAKE_WORD(payload[1], payload[0]) );

				// response frame = PHY Length 1B 
				//	+ Frame Control 2B 
				//	+ Sequence No 1B
				//	+ Destination Pan & Address 4B 
				//	+ Source Pan & Address 4B 
				//	+ DTP Section 15B

				//opf_cast( txbuf, 50, OPF_DEF_FRAMECONTROL_DATA_ACK );
				response = frame_startptr( txbuf );

				value = lum_value( lum );
				DTP_SET_MAX_HOPCOUNT( response,0x03);//todo for testing
				payload = DTP_PAYLOAD_PTR(response);

                //payload[0] = 0x17;//todo 第三个节点数据
				//payload[1] = 0x18;//todo 第三个节点数据

			    //payload[1] = 0x13;
				//payload[2] = 0x14;

				payload[1] = 0x15;//todo 另一个节点
			    payload[2] = 0x16;//todo 另一个节点

				/* call dtp_send_response() to send the data in txbuf out.
				 * 
				 * modified by zhangwei on 20091230
				 *	- Bug fix. In the past, there's no delay between two adjacent 
				 * dtp_send_response() calls. This policy is too ambitious and this
				 * node will occupy the whole time so that the other nodes will lost 
				 * chances to send, or encounter much higher frame collision probabilities. 
				 * so I add a little time delay here. 
				 *    Attention the delay time here shouldn't be too large because
				 * we don't want the hal_delay() to occupy all the CPU time. If this 
				 * occurs, it may lead to unnecessary frame lossing. 
				 */
				// try some times until the RESPONSE is successfully sent

			
               
                for (count=0; count<10; count++)
                {   
					//hal_delay( 500);
					if (dtp_send_response(dtp, txbuf, 0x03) > 0)
                    { 
                        led_toggle( LED_RED);//todo for testing
						break;
                    }
					//hal_delay( 50 );
				}
                
				break;


			default:
			    //hal_assert(false);
                break;
			}
		}
        nac_evolve( nac,NULL);//todo for tesitng
		aloha_evolve( mac,NULL);//todo for testing
		dtp_evolve( dtp, NULL );
		hal_delay( 50 );
	}
}
Exemple #16
0
void tinymac_recvnode(void)
{
    TiCc2420Adapter * cc;
    TiFrameRxTxInterface * rxtx;;
    TiTinyMAC * mac;
	TiTimerAdapter   *timer;
	TiFrame * rxbuf;
	char * msg = "welcome to tinymac recv test...";
    int len=0;

	target_init();

    // flash the led to indicate the software is successfully running now.
    //
	led_open();
	led_on( LED_ALL );
	hal_delay( 500 );
	led_off( LED_ALL );
	led_on( LED_RED );

    // initialize the runtime library for debugging input/output and assertion
    // hal_assert_report is defined in module "hal_assert"
    //
	//dbo_open( 38400 );
    rtl_init( (void *)dbio_open(38400), (TiFunDebugIoPutChar)dbio_putchar, (TiFunDebugIoGetChar)dbio_getchar, hal_assert_report );
    dbc_putchar( 0xF0 );
    dbc_mem( msg, strlen(msg) );

	cc = cc2420_construct( (void *)(&m_cc), sizeof(TiCc2420Adapter) );
    mac = tinymac_construct((char *)(&m_tiny), sizeof(TiTinyMAC));
    timer= timer_construct((char *)(&m_timer),sizeof(TiTimerAdapter));

	#ifdef CONFIG_TSET_LISTENER
	// cc = cc2420_open( cc, 0, _aloha_listener, NULL, 0x00 );
    cc = cc2420_open( cc, 0, tinymac_evolve, mac, 0x00 );
    rxtx = cc2420_interface( cc, &m_rxtx );
	mac = tinymac_open( mac, rxtx, CONFIG_CHANNEL, CONFIG_PANID, CONFIG_LOCAL_ADDRESS, 
        timer, _tinymac_listener, NULL,0x00 );
	#endif

    #ifndef CONFIG_TSET_LISTENER
    cc = cc2420_open( cc, 0, NULL, NULL, 0x00 );
    rxtx = cc2420_interface( cc, &m_rxtx );
	mac = tinymac_open( mac, rxtx, CONFIG_CHANNEL, CONFIG_PANID, CONFIG_LOCAL_ADDRESS, NULL, NULL,0x00 );
	#endif
 
	cc2420_setchannel( cc, CONFIG_CHANNEL );
	cc2420_setrxmode( cc );							            // enable RX mode
	cc2420_setpanid( cc, CONFIG_PANID );					// network identifier, seems no use in sniffer mode
	cc2420_setshortaddress( cc, CONFIG_LOCAL_ADDRESS );	// in network address, seems no use in sniffer mode
	cc2420_enable_autoack( cc );

	#ifdef CONFIG_TEST_ADDRESSRECOGNITION
	cc2420_enable_addrdecode( cc );
	#else	
	cc2420_disable_addrdecode( cc );
	#endif

	#ifdef CONFIG_TEST_ACK
	cc2420_enable_autoack( cc );
	#endif
 
    rxbuf = frame_open( (char*)(&m_rxbufmem), FRAME_HOPESIZE(MAX_IEEE802FRAME154_SIZE), 3, 20, 0 );

    #ifdef CONFIG_TEST_ACK
    //fcf = OPF_DEF_FRAMECONTROL_DATA_ACK; 
	#else
    //fcf = OPF_DEF_FRAMECONTROL_DATA_NOACK; 
	#endif


    hal_enable_interrupts();

	/* Wait for listener action. The listener function will be called by the TiCc2420Adapter
	 * object when a frame arrives */
	#ifdef CONFIG_TEST_LISTENER	
	while (1) {}
	#endif
    
	/* Query the TiCc2420Adapter object if there's no listener */
	#ifndef CONFIG_TEST_LISTENER
	while(1) 
	{	
        frame_reset( rxbuf, 3, 20, 0 );

        len = tinymac_recv( mac, rxbuf, 0x00 );
		if (len > 0)
		{   
			dbc_putchar( 0xF3 );
            dbc_mem( frame_startptr(rxbuf), frame_length(rxbuf) );

            //frame_moveouter( rxbuf );
            //_output_frame( rxbuf, NULL );
            //frame_moveinner( rxbuf );

			led_off( LED_RED );

			/* warning: You shouldn't wait too long in the while loop, or else 
			 * you may encounter frame loss. However, the program should still 
			 * work properly even the delay time is an arbitrary value. No error 
			 * are allowed in this case. 
			 */
			//hal_delay( 500 );
			led_toggle( LED_RED );
			//hal_delay( 500 );
        }

		tinymac_evolve(mac, NULL );
	}
	#endif

    frame_close( rxbuf );
    tinymac_close( mac );
    cc2420_close( cc );
}
Exemple #17
0
void Task1()
{
  uint8_t j, i;
  char *local_rx_buf;
  uint8_t cnt,cont;
  int8_t rssi;
  uint8_t length,slot;
  uint16_t counter;
  volatile nrk_time_t t;
	uint16_t tx_count, rx_count;
  printf( "Task1 PID=%d, MOBILE\r\n",nrk_get_pid());
  counter=0;
  cnt=0;
  cont=0;
	uint8_t val,fd,fd2,buf[2],buf2[2];
	uint16_t adc_int,adc_int2,light,temp;
  uint8_t k,l,m,n;	
  //rtl_init (RTL_COORDINATOR);
  rtl_init (RTL_MOBILE);
	rtl_set_schedule( RTL_TX, MY_TX_SLOT, 1 );
	rtl_set_schedule( RTL_RX, MY_RX_SLOT1, 1);
	//rtl_set_schedule( RTL_RX, MY_RX_SLOT2, 1);
//  rtl_set_contention(8,1);
  rtl_start();
  
  rtl_rx_pkt_set_buffer(rx_buf, RF_MAX_PAYLOAD_SIZE);
  nrk_kprintf( PSTR("start done\r\n") );
  while(!rtl_ready())  nrk_wait_until_next_period(); 
	tx_count = 0;
	rx_count = 0;
  while(1) {	
		if (tx_count >= 250) {
			printf("Transmissions: %d \r\n", tx_count);
			printf("Receptions: %d \r\n", rx_count);
		}
		if (tx_count < 250) {
			
		/*fd = nrk_open(FIREFLY_SENSOR_BASIC,READ);
		wait_ms(1);
		val = nrk_set_status(fd,SENSOR_SELECT,LIGHT);
		val = nrk_set_status(fd2,SENSOR_SELECT,TEMP);
		val = nrk_read(fd , &buf[0] , 2);
		val = nrk_read(fd2 , &buf2[0] , 2);
		adc_int = buf[0] + (buf[1]<<8);
		adc_int2 = buf2[0] + (buf2[1]<<8);
		light = adc_int;
		temp = adc_int2;
		k = light & 0xFF;
		l = (light >> 8) & 0xFF;
		m = temp & 0xFF;
		n = (temp >> 8) & 0xFF;*/
	  if( rtl_rx_pkt_check()!=0 )
     {
       nrk_led_set(BLUE_LED);
		   local_rx_buf=rtl_rx_pkt_get(&length, &rssi, &slot);
       printf( "Got Packet on slot %d %d: ",slot,length );
			 rx_count++;
      for(i=PKT_DATA_START; i<length; i++ )
       {
				printf( "%c",local_rx_buf[i] );
       }
       printf("\r\n");
			 rtl_rx_pkt_release();
       nrk_led_clr(BLUE_LED);
			} 
	  if( rtl_tx_pkt_check(MY_TX_SLOT)!=0 )
	  {
			printf( "Pending on slot %d\r\n",MY_TX_SLOT );
		}
	  else {
		nrk_led_set(RED_LED);
    cnt++;
    sprintf( &tx_buf[PKT_DATA_START], "Mobile1 %d", cnt);
		//printf(" %d %d %d %d \r\n",k,l,m,n);
		/*tx_buf[PKT_DATA_START] = k;
		tx_buf[PKT_DATA_START+1] = ' ';
		tx_buf[PKT_DATA_START+2] = l;
		tx_buf[PKT_DATA_START+3] = ' ';
		tx_buf[PKT_DATA_START+4] = m;
		tx_buf[PKT_DATA_START+5] = ' ';
		tx_buf[PKT_DATA_START+6] = n;*/
		length=strlen(&tx_buf[PKT_DATA_START])+PKT_DATA_START;
		rtl_tx_pkt( tx_buf, length, MY_TX_SLOT );
		printf( "Sending Packet on slot %d\r\n",MY_TX_SLOT);
		tx_count++;
		nrk_led_clr(RED_LED);
	  }	  
	  //nrk_wait_until_next_period(); 
	  rtl_wait_until_rx_or_tx();
  	}
	}
		
}
Exemple #18
0
int main(int argc, char **argv)
{
	pthread_t rtl_thread; 
	pthread_t fm_thread;
	char cert_path[1024];
	char key_path[1024];
	int n = 0;
	int use_ssl = 0;
	struct libwebsocket_context *context;
	int opts = 0;
	char interface_name[128] = "";
	const char *iface = NULL;
	int syslog_options = LOG_PID | LOG_PERROR;
	unsigned int oldus = 0;
	struct lws_context_creation_info info;

	int debug_level = 7;

	memset(&info, 0, sizeof info);
	info.port = PORT;

	rtl_init(DEV_INDEX);
	transfer.buf = NULL;
 	transfer.block_id = 0;

	spectrum = init_spectrum(FFT_POINTS);
        spectrum_temp_buffer = malloc(FFT_POINTS*2*4);
	send_buffer = malloc(LWS_SEND_BUFFER_PRE_PADDING + SEND_BUFFER_SIZE + LWS_SEND_BUFFER_POST_PADDING);
	while (n >= 0) {
		n = getopt_long(argc, argv, "i:hsp:d:Dr:", options, NULL);
		if (n < 0)
			continue;
		switch (n) {
		case 'd':
			debug_level = atoi(optarg);
			break;
		case 's':
			use_ssl = 1;
			break;
		case 'p':
			info.port = atoi(optarg);
			break;
		case 'i':
			strncpy(interface_name, optarg, sizeof interface_name);
			interface_name[(sizeof interface_name) - 1] = '\0';
			iface = interface_name;
			break;
		case 'r':
			resource_path = optarg;
			printf("Setting resource path to \"%s\"\n", resource_path);
			break;
		case 'h':
			fprintf(stderr, "Usage: rtl-ws-server "
					"[--port=<p>] [--ssl] "
					"[-d <log bitfield>] "
					"[--resource_path <path>]\n");
			exit(1);
		}
	}

	signal(SIGINT, sighandler);

	/* we will only try to log things according to our debug_level */
	setlogmask(LOG_UPTO (LOG_DEBUG));
	openlog("lwsts", syslog_options, LOG_DAEMON);

	/* tell the library what debug level to emit and to send it to syslog */
	lws_set_log_level(debug_level, lwsl_emit_syslog);

	info.iface = iface;
	info.protocols = protocols;
	info.extensions = libwebsocket_get_internal_extensions();

	if (!use_ssl) {
		info.ssl_cert_filepath = NULL;
		info.ssl_private_key_filepath = NULL;
	} else {
		if (strlen(resource_path) > sizeof(cert_path) - 32) {
			lwsl_err("resource path too long\n");
			return -1;
		}
		sprintf(cert_path, "%s/libwebsockets-test-server.pem",
								resource_path);
		if (strlen(resource_path) > sizeof(key_path) - 32) {
			lwsl_err("resource path too long\n");
			return -1;
		}
		sprintf(key_path, "%s/libwebsockets-test-server.key.pem",
								resource_path);

		info.ssl_cert_filepath = cert_path;
		info.ssl_private_key_filepath = key_path;
	}
	info.gid = -1;
	info.uid = -1;
	info.options = opts;

	context = libwebsocket_create_context(&info);
	if (context == NULL) {
		lwsl_err("libwebsocket init failed\n");
		return -1;
	}

	n = 0;
	pthread_mutex_init(&data_mutex, NULL);
	pthread_create(&rtl_thread, NULL, rtl_worker, NULL);
	pthread_create(&fm_thread, NULL, fm_worker, NULL);

	while (n >= 0 && !force_exit) {
		n = libwebsocket_service(context, 50);
	}
	force_exit = 1;
	usleep(100);

	libwebsocket_context_destroy(context);

	lwsl_notice("rtl-ws-server exited\n");

	closelog();

	rtl_close();

	pthread_mutex_destroy(&data_mutex);
	pthread_exit(NULL);

	if (transfer.buf != NULL) {
		free(transfer.buf);
		transfer.buf = NULL;
		transfer.block_id = 0;
	}

	free(send_buffer);
	free_spectrum(spectrum);
    free(spectrum_temp_buffer);
	return 0;
}
Exemple #19
0
void recvnode(void)
{
    TiCc2420Adapter * cc;
    TiFrameRxTxInterface * rxtx;
	TiNioAcceptor * nac;
    TiAloha * mac;
	TiTimerAdapter   *timer;
	TiTimerManager * vtm;
	TiTimer * mac_timer;
	TiFrame * rxbuf;
	char * msg = "welcome to aloha recv test...";
	int len=0;
	target_init();

    // flash the led to indicate the software is successfully running now.
    //
	led_open();
	led_on( LED_ALL );
	hal_delay( 500 );
	led_off( LED_ALL );
	//led_on( LED_RED );

    // initialize the runtime library for debugging input/output and assertion
    // hal_assert_report is defined in module "hal_assert"
    //
	//dbo_open( 38400 );
    rtl_init( (void *)dbio_open(38400), (TiFunDebugIoPutChar)dbio_putchar, (TiFunDebugIoGetChar)dbio_getchar, hal_assert_report );
    dbc_putchar( 0xF0 );
    dbc_mem( msg, strlen(msg) );

	cc = cc2420_construct( (void *)(&m_cc), sizeof(TiCc2420Adapter) );
	nac = nac_construct( &m_nacmem[0], NAC_SIZE );
    mac = aloha_construct( (char *)(&m_aloha), sizeof(TiAloha) );
    timer= timer_construct(( char *)(&m_timer),sizeof(TiTimerAdapter));
	vtm = vtm_construct( (void*)&m_vtm, sizeof(m_vtm) );
    timer = timer_open( timer, 2, NULL, NULL, 0x00 ); 
	vtm = vtm_open( vtm, timer, VTM_RESOLUTION );
	mac_timer = vtm_apply( vtm );
	vti_open( mac_timer, NULL, NULL );

	#ifdef CONFIG_TSET_LISTENER
	// cc = cc2420_open( cc, 0, _aloha_listener, NULL, 0x00 );
    cc = cc2420_open( cc, 0, aloha_evolve, mac, 0x00 );
    rxtx = cc2420_interface( cc, &m_rxtx );
	mac = aloha_open( mac, rxtx, CONFIG_ALOHA_CHANNEL, CONFIG_ALOHA_PANID, CONFIG_ALOHA_LOCAL_ADDRESS, 
        mac_timer, _aloha_listener, NULL,0x00 );
	#endif

    #ifndef CONFIG_TSET_LISTENER
    cc = cc2420_open( cc, 0, NULL, NULL, 0x00 );
    rxtx = cc2420_interface( cc, &m_rxtx );
	nac_open( nac, rxtx, CONFIG_NIOACCEPTOR_RXQUE_CAPACITY, CONFIG_NIOACCEPTOR_TXQUE_CAPACITY);
	mac = aloha_open( mac, rxtx, nac,CONFIG_ALOHA_CHANNEL, CONFIG_ALOHA_PANID, CONFIG_ALOHA_LOCAL_ADDRESS, 
        mac_timer, NULL, NULL,0x00 );
	#endif
 
	cc2420_setchannel( cc, CONFIG_ALOHA_CHANNEL );
	cc2420_setrxmode( cc );							            // enable RX mode
	cc2420_setpanid( cc, CONFIG_ALOHA_PANID );					// network identifier, seems no use in sniffer mode
	cc2420_setshortaddress( cc, CONFIG_ALOHA_LOCAL_ADDRESS );	// in network address, seems no use in sniffer mode
	cc2420_enable_autoack( cc );
	cc2420_settxpower( cc, CC2420_POWER_1);//cc2420_settxpower( cc, CC2420_POWER_2);CC2420_POWER_1

	#ifdef CONFIG_TEST_ADDRESSRECOGNITION
	cc2420_enable_addrdecode( cc );
	#else	
	cc2420_disable_addrdecode( cc );
	#endif

	#ifdef CONFIG_TEST_ACK
	cc2420_enable_autoack( cc );
	#endif
 
    rxbuf = frame_open( (char*)(&m_rxbufmem), FRAME_HOPESIZE(MAX_IEEE802FRAME154_SIZE), 3, 20, 0 );
    dbc_putchar(0x11);

    #ifdef CONFIG_TEST_ACK
    //fcf = OPF_DEF_FRAMECONTROL_DATA_ACK; 
	#else
    //fcf = OPF_DEF_FRAMECONTROL_DATA_NOACK; 
	#endif


    hal_enable_interrupts();

	/* Wait for listener action. The listener function will be called by the TiCc2420Adapter
	 * object when a frame arrives */
	#ifdef CONFIG_TEST_LISTENER	
	while (1) {}
	#endif
    
	/* Query the TiCc2420Adapter object if there's no listener */
	#ifndef CONFIG_TEST_LISTENER
	while(1) 
	{	
		char * ptr;//todo for testing
        frame_reset( rxbuf, 3, 20, 0 );
		len = aloha_recv( mac, rxbuf, 0x00 );        
		if (len > 0)
		{   
            frame_moveouter( rxbuf );
            _output_frame( rxbuf, NULL );
           frame_moveinner( rxbuf );
			/*
			dbc_write( frame_startptr( rxbuf),frame_length( rxbuf));//todo for testing
            ptr = frame_startptr( rxbuf);//todo for testing
			dbc_putchar( 0xff);//todo for testing
			dbc_uint8( ptr[ (frame_length( rxbuf)-2)]);//todo for testing
			dbc_putchar( 0xff);//todo for testing
            frame_moveinner( rxbuf );//todo for testing*/
			//led_off( LED_RED );

			/* warning: You shouldn't wait too long in the while loop, or else 
			 * you may encounter frame loss. However, the program should still 
			 * work properly even the delay time is an arbitrary value. No error 
			 * are allowed in this case. 
			 */
			//hal_delay( 500 );
			led_toggle( LED_RED );
		
        }

		aloha_evolve(mac, NULL );
	}
	#endif

    frame_close( rxbuf );
    aloha_close( mac );
    cc2420_close( cc );
}
Exemple #20
0
void Task1()
{
  uint8_t j, i;
  uint8_t *local_rx_buf;
  uint8_t cnt;
  int8_t rssi;
  uint8_t length,slot;
  uint16_t counter;
  volatile nrk_time_t t;
  printf( "Task1 PID=%d\r\n",nrk_get_pid());
  counter=0;
  cnt=0;

#ifdef COORDINATOR
  nrk_kprintf( PSTR( "Coordinator\r\n")); 
  rtl_init (RTL_COORDINATOR);
  nrk_led_set(RED_LED);  
#else
  nrk_kprintf( PSTR( "Mobile\r\n")); 
  rtl_init (RTL_MOBILE);
#endif

  printf( "Node %d ",NODE_ID );
  printf( "TX %d ",MY_TX_SLOT);
  printf( "RX %d\r\n",MY_RX_SLOT);

  rtl_set_schedule( RTL_TX, MY_TX_SLOT, 1 ); 
  rtl_set_schedule( RTL_RX, MY_RX_SLOT, 1 ); 
  
  rtl_start();
  
  rtl_rx_pkt_set_buffer(rx_buf, RF_MAX_PAYLOAD_SIZE);
  nrk_kprintf( PSTR("start done\r\n") );
  while(!rtl_ready())  nrk_wait_until_next_period(); 
  while(1) {
	

#if NODE_ID==1 
          
		if( rtl_tx_pkt_check(MY_TX_SLOT)!=0 )
	       		{
		  		printf( "Pending on slot %d\r\n",MY_TX_SLOT );
	       		}
	  	else 	{
	       			nrk_led_set(2);
                		cnt++;
                		sprintf( &tx_buf[PKT_DATA_START], "Hello World %d", cnt );
                		length=strlen(&tx_buf[PKT_DATA_START])+PKT_DATA_START+1;
                		rtl_tx_pkt( tx_buf, length, MY_TX_SLOT );
                		printf( "Sending Packet on slot %d\r\n",MY_TX_SLOT );
                		nrk_led_clr(2);

			}
	
#else 
	  if( rtl_rx_pkt_check()!=0 )
               {
                   nrk_led_set(1);
		   local_rx_buf=rtl_rx_pkt_get(&length, &rssi, &slot);
                   printf( "Got Packet on slot %d %d: ",slot,length );
                   for(i=PKT_DATA_START; i<length; i++ )
                   {
			// copy the rx buffer to the tx buffer
			// tx_buf[i]=local_rx_buf[i];
                        printf( "%c",local_rx_buf[i] );
                   }
                   nrk_kprintf( PSTR("\r\n") );
               
		if( rtl_tx_pkt_check(MY_TX_SLOT)!=0 )
	       		{
		  	printf( "Pending on slot %d\r\n",MY_TX_SLOT );
	       		}
	  	else 	{
			nrk_led_set(2);
			sprintf( &tx_buf[PKT_DATA_START], "%s %d",&local_rx_buf[PKT_DATA_START], NODE_ID );
                	length=strlen(&tx_buf[PKT_DATA_START])+PKT_DATA_START+1;
			rtl_tx_pkt( tx_buf, length, MY_TX_SLOT );
			printf( "Sending [%d] %s\r\n",length, &tx_buf[PKT_DATA_START] );
			//printf( "Sending Packet on slot %d\r\n",MY_TX_SLOT );
			nrk_led_clr(2);
	       		}
                   rtl_rx_pkt_release();
                   nrk_led_clr(1);
		}
#endif 
	  	
	 
	  rtl_wait_until_rx_or_tx();

	  
  	}
}
Exemple #21
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 );
		}*/
		
	}
}