Пример #1
0
void main(void)
{
    int i, j;
    audio = audio_open(AUDIO_1);
    leds  = led_open(LEDS);
    led_set_all_on_intensity(leds, 0);
    led_turn_all_on(leds);

    while (1)
    {
        // get audio to left and right buffers for processing.
        get_audio(stereo_buf, AUDIO_BUF_SIZE);
        for (i = 0, j = 0; i < AUDIO_BUF_SIZE ; i++, j++)
        {
          audio_buf_r[j] = stereo_buf[i++];
          audio_buf_l[j] = stereo_buf[i];
        }

        // Loop left and right channels through.
        put_audio(stereo_buf, AUDIO_BUF_SIZE);

        // Get the D.C. average value of the wavelet.
        intensity_l = abs_ave(audio_buf_l, AUDIO_BUF_SIZE/2);
        intensity_r = abs_ave(audio_buf_r, AUDIO_BUF_SIZE/2);

        // Set VU meter on LEDS
        update_intensity(intensity_l, LEFT);
        update_intensity(intensity_r, RIGHT);
    }
}
Пример #2
0
void recvnode2(void)
{
    TiCc2420Adapter * cc;
	TiUartAdapter * uart;
	char * msg = "welcome to recvnode...";

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

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

	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, _cc2420_listener, cc, 0x00 );
	
	cc2420_setchannel( cc, DEFAULT_CHANNEL );
	cc2420_setrxmode( cc );							//Enable RX
	cc2420_disable_addrdecode( cc );					//使能地址译码
	cc2420_setpanid( cc, PANID );					//网络标识
	cc2420_setshortaddress( cc, LOCAL_ADDRESS );	//网内标识
	cc2420_enable_autoack(cc);
	#ifdef TEST_ACK
	cc2420_enable_autoack(cc);
	#endif
	hal_enable_interrupts();
 
	while(1) {};
}
Пример #3
0
void _ledremote(void)
{
    TiCc2420Adapter * cc;
	TiUartAdapter * uart;
	TiOpenFrame * opf;
	TiTimerAdapter *timer;

	char * msg = "welcome to _ledremote...";

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

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

    timer = timer_construct( (void *)&g_timer, sizeof(g_timer) );
    timer_open( timer, 0, on_timer_expired, NULL, 0x01 ); 
    timer_setinterval( timer, 8, 1 );
	timer_start( timer );

	dbo_open(38400);


	uart = uart_construct( (void *)(&g_uart), sizeof(TiUartAdapter) );
	uart_open( uart, 0, 38400, 8, 1, 0x00 );
	uart_write( uart, msg, strlen(msg), 0x00 );

	cc = cc2420_construct( (void *)(&g_cc), sizeof(TiCc2420Adapter) );
	cc2420_open( cc, 0, _cc2420_listener, cc, 0x00 );
	cc2420_setchannel( cc, DEFAULT_CHANNEL );
	cc2420_enable_addrdecode( cc );				    //使能地址译码
	cc2420_setpanid( cc, PANID );				    //网络标识
	cc2420_setshortaddress( cc, LOCAL_ADDRESS );    //网内标识
	cc2420_enable_autoack(cc);

	opf = opf_open( (void *)(&g_opfmem), sizeof(g_opfmem), OPF_FRAMECONTROL_UNKNOWN, OPF_DEF_OPTION );

	hal_enable_interrupts();
 
	while(1) {};
}
Пример #4
0
void CLCD::setled(int red, int green)
{
	static unsigned char col = '0'; /* need to remember the state. 1 == blue, 2 == red */
	int leds[3] = { -1, green, red };
	int i;
	char s[3];
	int fd = led_open();
	if (fd < 0)
		return;
	for (i = 1; i <= 2; i++)
	{
		if (leds[i] == -1)	/* don't touch */
			continue;
		col &= ~(i);		/* clear the bit... */
		if (leds[i])
			col |= i;	/* ...and set it again */
	}
	sprintf(s, "%c\n", col);
	write(fd, s, 3);
	close(fd);
	//printf("%s(%d, %d): %c\n", __func__, red, green, col);
}
Пример #5
0
void main (void)
{
    // Connect to our drivers for the TFT, touch sensor.
    tft_touch = touchscreen_open(TOUCHSCREEN_1);
    ptr = pointer_open(POINTER_1);
    display = graphics_open(GRAPHICS_1);
    canvas = graphics_get_visible_canvas(display);
    leds = led_open(DRV_LED_1);
    led_turn_all_off(leds);

    // Clear screen
    graphics_fill_canvas(canvas, BLACK);
    graphics_set_visible_canvas(display, canvas);

    // Update display and turn off LEDs
    while(!graphics_visible_canvas_is_set(display));

    // Set up and calibrate touch screen.
    touchscreen_set_callback(tft_touch, draw_mark, canvas);
    while(!touchscreen_calibrate(tft_touch, 320, 240))
    {
        set_all_leds(0xFF0000); // If Touchscreen can't calibrate RED ALERT!
    }
    led_turn_all_off(leds);

    // Put colormap on TFT
    graphics_draw_bitmap(canvas, bmp, 0, 0, 320, 240, 0);
    graphics_set_visible_canvas(display, canvas);

    // Start picking colors!
    while(1)
    {
        if (pointer_update(ptr, pointer_state))
        {
            set_all_leds(graphics_get_pixel(canvas, pointer_state->x, pointer_state->y));
        }
    }
}
Пример #6
0
void main(void)
{
    int i, j;
    audio = audio_open(AUDIO_1);
    leds  = led_open(LEDS);
    while (1)
    {
        // get audio to left and right buffers for processing.
        get_audio(stereo_buf, AUDIO_BUF_SIZE);
        for (i = 0, j = 0; i < AUDIO_BUF_SIZE ; i++, j++)
        {
          audio_buf_r[j] = stereo_buf[i++];
          audio_buf_l[j] = stereo_buf[i];
        }

        // Loop left and right channels through.
        put_audio(stereo_buf, AUDIO_BUF_SIZE);

        // Put the D.C. average value of the wavelet on LEDs
        update_intensity(abs_ave(audio_buf_l, AUDIO_BUF_SIZE/2),LEFT);
        update_intensity(abs_ave(audio_buf_r, AUDIO_BUF_SIZE/2),RIGHT);
    }
}
Пример #7
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 );
	}
}
Пример #8
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 );
}
Пример #9
0
void led_test( void )
{     
	int i;

    target_init();

    led_open();
	led_on( LED_ALL );
	hal_delay( 1000 );
	
	/* testing each single LED */

	led_off( LED_ALL ); 
	i=0;
	while (i<3)
	{
		led_off(LED_RED) ; 
	    hal_delay(300);
	    led_on(LED_RED) ; 
	    hal_delay(300);
	    i++;
    }
    led_off( LED_RED );
	
	i=0;
	while (i<3)
 	{
	    led_off(LED_GREEN) ; 
	    hal_delay(300);
	    led_on(LED_GREEN) ; 
	    hal_delay(300);
	    i++;
    }
    led_off( LED_GREEN );
    
	i=0;
    while (i<3)
 	{
	    led_off(LED_YELLOW) ; 
	    hal_delay(300);
	    led_on(LED_YELLOW) ; 
	    hal_delay(300);
	    i++;
	}
    led_off( LED_YELLOW );

	/* test the LEDs at the same time */
	
	led_off( LED_ALL ); 
	i = 0;
	while (i<3)
	{
		led_toggle( LED_RED ); 
		led_toggle( LED_YELLOW ); 
		led_toggle( LED_GREEN ); 
	    hal_delay(500);
		i++;
	}

	/* testing LED twinkle 
     * there's a infinite loop in led_twinkle, so it will never come out*/

	led_off( LED_ALL ); 
    // led_twinkle( LED_RED, 300, 5 );
    // led_off( LED_RED );
	led_twinkle( LED_YELLOW, 300, 5 );
    led_off( LED_YELLOW );
    // led_twinkle( LED_GREEN, 300, 5 );
    // led_off( LED_GREEN );
}
Пример #10
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 );
}
Пример #11
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 );
		}*/
		
	}
}
Пример #12
0
void broadrecvnode(void)
{
    TiCc2420Adapter * cc;
	TiUartAdapter * uart;
    TiAloha * mac;
	TiOpenFrame * opf;
	TiTimerAdapter   *timer;
	char * msg = "welcome to aloha recv test...";
    #ifndef CONFIG_TEST_LISTENER
  
    #endif

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

	led_open();
	led_on( LED_RED );
	dbo_open( 0, 38400 );

	cc = cc2420_construct( (void *)(&m_cc), sizeof(TiCc2420Adapter) );
	uart = uart_construct( (void *)(&m_uart), sizeof(TiUartAdapter) );
    mac = aloha_construct( (char *)(&m_aloha), sizeof(TiAloha) );
    timer= timer_construct(( char *)(&m_timer),sizeof(TiTimerAdapter));

	uart_open( uart, 0, 38400, 8, 1, 0x00 );
	uart_write( uart, msg, strlen(msg), 0x00 );
	#ifdef CONFIG_TSET_LISTENER
	cc = cc2420_open( cc, 0, _aloha_listener, NULL, 0x00 );
	#else
    cc = cc2420_open( cc, 0, NULL, NULL, 0x00 );
	#endif


	#ifdef CONFIG_TEST_LISTENER
	mac = aloha_open( mac, cc,DEFAULT_CHANNEL,PANID,LOCAL_ADDRESS,timer, _aloha_listener, NULL,0x00 );
	#else
	mac = aloha_open( mac, cc,DEFAULT_CHANNEL,PANID,LOCAL_ADDRESS,timer,NULL, NULL,0x00 );
	#endif
 
 	cc2420_enable_autoack( cc );
	
	cc2420_enable_addrdecode( cc );
 
    opf = opf_open( (void *)(&m_rxbufmem), sizeof(m_rxbufmem), OPF_FRAMECONTROL_UNKNOWN, OPF_DEF_OPTION );

    hal_enable_interrupts();

	#ifdef CONFIG_TEST_LISTENER	
	while (1) {}
	#endif
    
	/* Query the TiCc2420Adapter object if there's no listener */
	#ifndef CONFIG_TEST_LISTENER
	while(1) 
	{
	
       	len = aloha_recv( mac, opf, 0x00 );
		if (len > 0)
		{   
			_output_openframe( opf,&m_uart);
			//led_off( LED_RED );

			led_toggle( LED_RED );
        }
	}
	#endif
}