retval_t commhub_sync(){ retval_t rv; frame_t cmd = DECLARE_FRAME_BYTES(CMD_F_SYNC_H, CMD_F_SYNC_L); frame_t answer = DECLARE_FRAME_SPACE(2); uint16_t response; uint8_t i; for (i=0; i < F_RESYNC_TIMES; ++i){ frame_reset(&cmd); frame_reset(&answer); rv = channel_transact(ch_fpga_ctrl, &cmd, 0, &answer); SUCCESS_OR_RETURN(rv); frame_reset_for_reading(&answer); frame_get_u16(&answer, &response); if (response == F_SYNC_RESPONSE) { return RV_SUCCESS; } } return RV_TIMEOUT; }
void binary_save_frame (BinaryData *binary, unsigned long int start_offset, unsigned long int cur_offset) { char bmp_filename[1024]; static unsigned int frame_id = 0; sprintf (bmp_filename, "%s/%s/%d_%s_FFT_0x%lx-0x%lx.bmp", binary->output_folder, binary->path, frame_id++, binary->name, start_offset, cur_offset); // Convert frame to complex matrix and compute FFT COMPLEX **c = frame_to_complex (binary->frame); FFT2D (c, binary->frame->size, binary->frame->size, 1); // Output to bmp bmpfile_t *bmp = complex_to_bmp (c, binary->frame->size); bmp_save (bmp, bmp_filename); // Cleaning bmp_destroy (bmp); frame_reset (binary->frame); }
// process() is called to process the button, which amounts to: // If mouse is over button, hilight it // If highlighted and mouse button down, flag button as down // If hotkey pressed, flag button as down // If hotkey_if_focus pressed, and button has focus, flag button as down // Set various BF_JUST_* flags if events changed from last frame // void UI_BUTTON::process(int focus) { int mouse_on_me, old_flags; old_flags = m_flags; frame_reset(); // check mouse over control and handle hilighting state mouse_on_me = is_mouse_on(); // if gadget is disabled, force button up and return if (disabled_flag) { if (old_flags & BF_DOWN){ m_flags |= BF_JUST_RELEASED; } if (!hidden && !my_wnd->use_hack_to_get_around_stupid_problem_flag) { if (mouse_on_me && B1_JUST_PRESSED){ gamesnd_play_iface(SND_GENERAL_FAIL); } if ( (hotkey >= 0) && (my_wnd->keypress == hotkey) ){ gamesnd_play_iface(SND_GENERAL_FAIL); } } // do callback if the button is disabled if (mouse_on_me && B1_JUST_PRESSED){ if (m_disabled_function != NULL) { m_disabled_function(); } } return; } // check focus and derived focus with one variable if (my_wnd->selected_gadget == this) { focus = 1; } // show alternate cursor, perhaps? maybe_show_custom_cursor(); if ( !mouse_on_me ) { next_repeat = 0; } else { m_flags |= BF_HIGHLIGHTED; if ( !(old_flags & BF_HIGHLIGHTED) ) { int do_callback = 1; m_flags |= BF_JUST_HIGHLIGHTED; // if a callback exists, call it if (m_just_highlighted_function) { if ( m_flags & BF_SKIP_FIRST_HIGHLIGHT_CALLBACK ) { if ( first_callback ) { do_callback = 0; } } first_callback = 0; if ( do_callback ) { m_just_highlighted_function(); } } } } // check if mouse is pressed if ( B1_PRESSED && mouse_on_me ) { m_flags |= BF_DOWN; capture_mouse(); } // check if hotkey is down or not if ( (hotkey >= 0) && (my_wnd->keypress == hotkey) ) { m_flags |= BF_DOWN | BF_CLICKED; } // only check for space/enter keystrokes if we are not ignoring the focus (this is the // default behavior) if ( !(m_flags & BF_IGNORE_FOCUS) ) { if ( focus && (hotkey_if_focus >= 0) ) { if (my_wnd->keypress == hotkey_if_focus) m_flags |= BF_DOWN | BF_CLICKED; if ( (hotkey_if_focus == KEY_SPACEBAR) && (my_wnd->keypress == KEY_ENTER) ) m_flags |= BF_DOWN | BF_CLICKED; } } // handler for button not down if ( !(m_flags & BF_DOWN) ) { next_repeat = 0; if ( (old_flags & BF_DOWN) && !(old_flags & BF_CLICKED) ) // check for release of mouse, not hotkey m_flags |= BF_JUST_RELEASED; // non-repeating buttons behave sort of uniquely.. They activate when released over button if (!(m_flags & BF_REPEATS)) { if ( (m_flags & BF_JUST_RELEASED) && (m_flags & BF_HIGHLIGHTED) ) m_flags |= BF_CLICKED; } return; } // check if button just went down this frame if ( !(old_flags & BF_DOWN) ) { m_flags |= BF_JUST_PRESSED; m_press_linger = timestamp(100); if (user_function) user_function(); if (m_flags & BF_REPEATS) { next_repeat = timestamp(B_REPEAT_TIME * 3); m_flags |= BF_CLICKED; } } // check if a repeat event should occur if ( timestamp_elapsed(next_repeat) && (m_flags & BF_REPEATS) ) { next_repeat = timestamp(B_REPEAT_TIME); m_flags |= BF_CLICKED; m_press_linger = timestamp(100); } // check for double click occurance if (B1_DOUBLE_CLICKED && mouse_on_me) { m_flags |= BF_DOUBLE_CLICKED; m_press_linger = timestamp(100); } }
int frame_skip() { static int frame_rate_cnt = FRAME_RATE; #ifdef VITA if (u_base == 0) { u_base = sceKernelGetProcessTimeWide(); return 0; } u_base+=u_frm; if (num_skips>=10) { num_skips=0; frame_reset(); return 1; } if (num_skips) { num_skips--; return 1; } u_ref = sceKernelGetProcessTimeWide(); /* If not there yet */ if (u_ref<u_base) { sceKernelDelayThread((u_base-u_ref)); if ((frame_rate_cnt-=frames_per_second)<=0) { frame_rate_cnt+=FRAME_RATE; return 0; } else return 1; } else { num_skips=(u_ref-u_base)/u_frm; return 0; } #else if (base.tv_sec==0) { gettimeofday(&base, NULL); u_base=(base.tv_sec*USC)+base.tv_usec; return 0; } u_base+=u_frm; if (num_skips>=10) { num_skips=0; frame_reset(); return 1; } if (num_skips) { num_skips--; return 1; } gettimeofday(&ref, NULL); u_ref=(ref.tv_sec*USC)+ref.tv_usec; /* If not there yet */ if (u_ref<u_base) { usleep((u_base-u_ref)); if ((frame_rate_cnt-=frames_per_second)<=0) { frame_rate_cnt+=FRAME_RATE; return 0; } else return 1; } else { num_skips=(u_ref-u_base)/u_frm; return 0; } #endif }
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 ); }
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 ); }
//#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 ); }*/ } }