/******************************************************************************* * @brief delay precise microsecond function * @author zhanggaoxin * @date 2012-12-26 * @param [in]us: delay microsecond time * @return T_VOID *******************************************************************************/ T_VOID delay_us(T_U32 us) { if (REG32(REG_TIMER2_CTRL) & TIMER_ENABLE_BIT) { T_U32 second1, second2; T_U32 tick1, tick2; T_U32 tickdiff; tickdiff = us * CLK_PER_US; tick1 = get_tick_count(&second1); while (1) { tick2 = get_tick_count(&second2); if (((second2 - second1)*CRYSTAL_CLOCK + tick2 - tick1) >= tickdiff) { return; } } } else { //当CPU频率不小于116M的时候是准确的 //用于Timer2尚未使能的系统启动阶段,此时CPU为116M T_U32 tmp; T_U32 i, sum; sum = (us * 10) / 6; for (i=0; i<=sum; i++) { tmp = REG32(REG_CHIP_ID); } } }
long kbd_get_autoclicked_key() { register long key, t; key=kbd_get_clicked_key(); if (key && (key != last_kbd_key)) { last_kbd_key = key; press_count = 0; last_kbd_time = get_tick_count(); return key; } else { if (last_kbd_key && kbd_is_key_pressed(last_kbd_key)) { t = get_tick_count(); if (t-last_kbd_time > ((press_count) ? KBD_REPEAT_DELAY : KBD_INITIAL_DELAY)) { ++press_count; last_kbd_time = t; return last_kbd_key; } else { return 0; } } else { last_kbd_key = 0; return 0; } } }
void calibrate_delay(void) { int sample = 0; int count = 0; DWORD tick_count1 = 0L; DWORD tick_count2 = 0L; one_ms_delay = 0; for (sample = 0; sample < DELAY_SAMPLES; ++sample) { count = 0; tick_count1 = get_tick_count(); while ((tick_count2 = get_tick_count()) == tick_count1) {}; do { delay_loop(DELAY_CHECK_LOOPS); count++; } while ((tick_count1 = get_tick_count()) == tick_count2); one_ms_delay += (int)((DELAY_CHECK_LOOPS * (DWORD)count) / (tick_count1 - tick_count2)); } one_ms_delay /= DELAY_SAMPLES; }
static void __attribute__((optimize("O0"))) bench_mem_read(int *buff) { long t; register unsigned int i, n, x; register int *buf = buff; t = get_tick_count(); for (n=0; n<1024; ++n) for (i=0; i<0x10000/4; ++i) x = buf[i]; t = get_tick_count() - t; bench.memory_read_bps = 0x10000*100 / (t/10) * 1024; }
/******************************************************************************* * Function name - mget_url_smooth * * Description - Performs actual fetching of urls for a whole batch. Starts * with initial fetch by mperform_smooth () and further acts * using mperform_smooth () on select events * * Input - *bctx - pointer to the batch of contexts * * Return Code/Output - On Success - 0, on Error -1 ********************************************************************************/ static int mget_url_smooth (batch_context* bctx) { int max_timeout_msec = 1000; unsigned long now_time = get_tick_count (); int cycle_counter = 0; int still_running = 0; struct timeval timeout; mperform_smooth (bctx, &now_time, &still_running); while (max_timeout_msec > 0) { int rc, maxfd; fd_set fdread, fdwrite, fdexcep; FD_ZERO(&fdread); FD_ZERO(&fdwrite); FD_ZERO(&fdexcep); timeout.tv_sec = 0; timeout.tv_usec = 250000; max_timeout_msec -= timeout.tv_sec*1000 + timeout.tv_usec * 0.001; curl_multi_fdset(bctx->multiple_handle, &fdread, &fdwrite, &fdexcep, &maxfd); //fprintf (stderr, "%s - Waiting for %d clients with seconds %f.\n", //name, still_running, max_timeout); rc = select (maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout); switch(rc) { case -1: /* select error */ break; case 0: /* timeout */ now_time = get_tick_count (); default: /* timeout or readable/writable sockets */ mperform_smooth (bctx, &now_time, &still_running); break; } if (!(++cycle_counter % TIME_RECALCULATION_CYCLES_NUM)) { now_time = get_tick_count (); } dispatch_expired_timers (bctx, now_time); } return 0; }
void lens_set_zoom_point(long newpt) { #if defined (CAMERA_s95) long startTime; #endif if (newpt < 0) { newpt = 0; } else if (newpt >= zoom_points) { newpt = zoom_points-1; } #if defined(CAMERA_sx30) // SX30 - Can't find zoom_status, _MoveZoomLensWithPoint crashes camera // _PT_MoveOpticalZoomAt works, and updates PROPCASE_OPTICAL_ZOOM_POSITION; but doesn't wait for zoom to finish extern void _PT_MoveOpticalZoomAt(long*); if (lens_get_zoom_point() != newpt) { _PT_MoveOpticalZoomAt(&newpt); while (zoom_busy) msleep(10); } #elif defined(CAMERA_g12) // G12 - Can't find zoom_status, _MoveZoomLensWithPoint works anyway; but doesn't wait for zoom to finish if (lens_get_zoom_point() != newpt) { _MoveZoomLensWithPoint((short*)&newpt); while (zoom_busy) msleep(10); _SetPropertyCase(PROPCASE_OPTICAL_ZOOM_POSITION, &newpt, sizeof(newpt)); } #else // !CAMERA_g12 _MoveZoomLensWithPoint((short*)&newpt); #if defined (CAMERA_s95) // this will hang sometimes on s95 when zoom_busy gets stuck as a 1 // we add a timeout as a work-around for this problem startTime = get_tick_count(); while (get_tick_count() < (startTime + 2000)) { if (!zoom_busy) break; } #else // !CAMERA_s95 while (zoom_busy) ; #endif // CAMERA_s95 if (newpt==0) zoom_status=ZOOM_OPTICAL_MIN; else if (newpt >= zoom_points) zoom_status=ZOOM_OPTICAL_MAX; else zoom_status=ZOOM_OPTICAL_MEDIUM; _SetPropertyCase(PROPCASE_OPTICAL_ZOOM_POSITION, &newpt, sizeof(newpt)); #endif // CAMERA_g12 }
void View::pre_display() { //info("display: lock"); view_sync.enter(); //begin time measuring double time_start = get_tick_count(); //antialising is supported through accumulation buffer (FIXME: use ARB_MULTISAMPLE if available) if (!hq_frame) { clear_background(); on_display(); } else { display_antialiased(); hq_frame = false; } if (b_help) draw_help(); else if (b_scale) scale_dispatch(); //draw current rendring time # ifdef _DEBUG draw_fps(); # endif //wait to finish glFinish(); //calculate statistics rendering_frames[rendering_frames_top] = get_tick_count() - time_start; rendering_frames_top = (rendering_frames_top + 1) % FPS_FRAME_SIZE; if (want_screenshot) { glReadBuffer(GL_BACK_LEFT); save_screenshot_internal(screenshot_filename.c_str()); want_screenshot = false; } glutSwapBuffers(); //frame synchronization frame_ready = true; view_sync.signal_drawing_finished(); view_sync.leave(); }
void run_render(window_t *win, void *render) { int ev; oskey_t key; int button; realtime = get_tick_count(); exp_time = -1; while(win->win_command != WIN_CLOSED) { wait_time = exp_time - realtime; ev = check_os_event(); realtime = get_tick_count(); // if(exp_time < realtime) // exp_time = update_timers(realtime); switch(ev) { case MSG_PAINT: do_sys_draw(win); break; case 2: key = get_key(); if( key.state == 0) send_message((ctrl_t*)win, ev, 0, key.code); break; case 3: button = get_os_button(); if(button == 1) win->win_command = WIN_CLOSED; break; case 6: do_sys_mouse(win); break; default: break; }; render_time(render); }; };
//------------------------------------------------------------------- static void __attribute__((optimize("O0"))) bench_screen_write() { long t; register unsigned int i, s; register char c; register char *scr; scr = vid_get_bitmap_fb(); s = camera_screen.buffer_size; t = get_tick_count(); for (c=0; c<64; ++c) for (i=0; i<s; ++i) scr[i] = c; t = get_tick_count() - t; bench.screen_output_bps = s*64*100 / (t/10); }
static void __attribute__((optimize("O0"))) bench_screen_read() { long t; register unsigned int i, n, s; register char c; register char *scr; scr = vid_get_viewport_active_buffer(); s = camera_screen.width * vid_get_viewport_height() * 3; t = get_tick_count(); for (n=0; n<64; ++n) for (i=0; i<s; ++i) c = scr[i]; t = get_tick_count() - t; bench.screen_input_bps = s*64*100 / (t/10); }
void run_window(window_t *win) { int ev; oskey_t key; // buttons = get_mouse_buttons(); // wheels = get_mouse_wheels(); realtime = get_tick_count(); exp_time = -1; while(1) { wait_time = exp_time - realtime; ev = wait_for_event(wait_time); realtime = get_tick_count(); // if(exp_time < realtime) // exp_time = update_timers(realtime); switch(ev) { case MSG_PAINT: do_sys_draw(win); continue; case 2: printf("key pressed\n"); key = get_key(); if( key.state == 0) send_message((ctrl_t*)win, ev, 0, key.code); continue; case 3: printf("Button pressed\n"); continue; case 6: do_sys_mouse(win); continue; default: printf("event %d\n", ev); continue; }; }; }
void usbmuxd_log(enum loglevel level, const char *fmt, ...) { va_list ap; char *fs; struct timeval ts; struct tm *tp; if(level > log_level) return; get_tick_count(&ts); tp = localtime(&ts.tv_sec); fs = malloc(20 + strlen(fmt)); if(log_syslog) { sprintf(fs, "[%d] %s\n", level, fmt); } else { strftime(fs, 10, "[%H:%M:%S", tp); sprintf(fs+9, ".%03d][%d] %s\n", (int)(ts.tv_usec / 1000), level, fmt); } va_start(ap, fmt); if (log_syslog) { vsyslog(level_to_syslog_level(level), fs, ap); } else { vfprintf(stderr, fs, ap); } va_end(ap); free(fs); }
//------------------------------------------------------------------- int gui_read_kbd_process() { switch (kbd_get_autoclicked_key() | get_jogdial_direction()) { case JOGDIAL_LEFT: case KEY_ZOOM_OUT: case KEY_UP: case KEY_LEFT: if (conf.reader_pos>0) { conf.reader_pos -= 45*15; if (conf.reader_pos<0) conf.reader_pos=0; read_to_draw = 1; } break; case JOGDIAL_RIGHT: case KEY_ZOOM_IN: case KEY_DOWN: case KEY_RIGHT: case KEY_SHOOT_HALF: if ((conf.reader_pos+read_on_screen)<read_file_size) { conf.reader_pos += read_on_screen; read_to_draw = 1; } break; case KEY_SET: break; case KEY_DISPLAY: pause = !pause; gui_read_draw_scroll_indicator(); last_time = get_tick_count(); break; case KEY_MENU: gui_read_kbd_leave(); break; } return 0; }
void console_add_line(const char *str) { // Set console_autoredraw to -1 to stop script print statements from being displayed on screen // Can be used to send script output to a file (using print_screen function); but not have it displayed // on the LCD. if (console_autoredraw == -1) return; console_ensure_inited(); console_start_line(); do { char *cur = console_buf[console_cur_line]; int curlen = strlen(cur); int left = console_line_length - curlen; if (strlen(str) > left) { strncpy(cur + curlen, str, left); cur[console_line_length] = 0; console_start_line(); str += left; } else { strcat(cur, str); break; } } while(1); // ToDo: this should probably only be done if console_autoredraw == 0; but that breaks existing scripts (e.g. EDI.lua) console_displayed = 0; console_last_modified = get_tick_count(); }
int CImConn::Send(void *data, int len) { m_last_send_tick = get_tick_count(); ++g_send_pkt_cnt; if (m_busy) { m_out_buff.Write(data, len); return len; } int offset = 0; int remain = len; while (remain > 0) { int send_size = remain; if (send_size > NETLIB_MAX_SOCKET_BUF_SIZE) { send_size = NETLIB_MAX_SOCKET_BUF_SIZE; } int ret = netlib_send(m_handle, (char*) data + offset, send_size); if (ret <= 0) { ret = 0; break; } offset += ret; remain -= ret; } if (remain > 0) { m_out_buff.Write((char*) data + offset, remain); m_busy = true; } return len; }
long BrucoSession::get_session_id() { ScopedLock lock(session_id_mutex_); long session_id = get_tick_count() % 1000000000; return session_id; }
int main(int argc, char **argv) { srand(get_tick_count()); memset(&kb, 0, sizeof(kb)); set_keys(); player_init(&p1); smp_alloc((void*)&p1); graphics_init(); physics_init(); glutInit(&argc, argv); glutInitWindowPosition(200, 100); glutInitWindowSize(window_x, window_y); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutCreateWindow(PROGRAM_NAME); glutDisplayFunc(graphics_loop); glutIdleFunc(graphics_loop); glutReshapeFunc(reshape); glutKeyboardFunc(kb_controller_dn_char); glutKeyboardUpFunc(kb_controller_up_char); glutSpecialFunc(kb_controller_dn); glutSpecialUpFunc(kb_controller_up); glutMouseFunc(mouse_handler); glutMotionFunc(mouse_motion_handler); glutPassiveMotionFunc(mouse_motion_handler); threads.phys_main = thread_create(physics_loop, NULL); glutMainLoop(); return EXIT_SUCCESS; }
int CHttpConn::Send(void* data, int len) { m_last_send_tick = get_tick_count(); if (m_busy) { m_out_buf.Write(data, len); return len; } int ret = netlib_send(m_sock_handle, data, len); if (ret < 0) ret = 0; if (ret < len) { m_out_buf.Write((char*) data + ret, len - ret); m_busy = true; //log("not send all, remain=%d", m_out_buf.GetWriteOffset()); } else { OnSendComplete(); } return len; }
//------------------------------------------------------------------- int gui_read_init(const char* file) { static struct STD_stat st; read_file = safe_open(file, O_RDONLY, 0777); if (strcmp(file, conf.reader_file)!=0) { conf.reader_pos = 0; strcpy(conf.reader_file, file); } read_on_screen = 0; read_file_size = (read_file>=0 && safe_stat((char*)file, &st)==0)?st.st_size:0; if (read_file_size<=conf.reader_pos) { conf.reader_pos = 0; } pause = 0; read_to_draw = 1; x=camera_screen.ts_button_border+6; y=FONT_HEIGHT; w=camera_screen.width-camera_screen.ts_button_border*2-6-6-8; h=camera_screen.height-y; last_time = get_tick_count(); reader_is_active=1; old_mode = gui_set_mode(&GUI_MODE_READ); draw_filled_rect(0, 0, camera_screen.width-1, y-1, MAKE_COLOR(COLOR_BLACK, COLOR_BLACK)); draw_filled_rect(0, y, camera_screen.width-1, camera_screen.height-1, MAKE_COLOR(BG_COLOR(conf.reader_color), BG_COLOR(conf.reader_color))); gui_read_draw_scroll_indicator(); gui_read_draw_batt(); return (read_file >= 0); }
void console_draw(int force_redraw) { char buf[MAX_CONSOLE_LINE_LENGTH+1]; console_ensure_inited(); twoColors col = user_color(conf.osd_color); long t = get_tick_count(); if (t <= console_last_modified + (conf.console_timeout*1000)) // Redraw if changed { if ((console_displayed == 0) || force_redraw) { int y = (console_y + console_max_lines - 1) * FONT_HEIGHT; int x = console_x * FONT_WIDTH + camera_screen.disp_left; int c, i; for (c = 0, i = console_cur_line; c < console_num_lines; ++c, --i) { if (i < 0) i = MAX_CONSOLE_HISTORY-1; strncpy(buf,console_buf[i],console_line_length); buf[console_line_length] = 0; draw_string_justified(x, y - c * FONT_HEIGHT, buf, col, 0, console_line_length * FONT_WIDTH, TEXT_LEFT|TEXT_FILL); console_displayed = 1; } } } else if (console_displayed && !camera_info.state.state_kbd_script_run) // Erase if drawn and script not running { gui_set_need_restore(); console_displayed = 0; } }
//------------------------------------------------------------------- int gui_read_init(const char* file) { running = 1; static struct stat st; read_file = open(file, O_RDONLY, 0777); if (strcmp(file, conf.reader_file)!=0) { conf.reader_pos = 0; strcpy(conf.reader_file, file); } read_on_screen = 0; read_file_size = (read_file>=0 && stat((char*)file, &st)==0)?st.st_size:0; if (read_file_size<=conf.reader_pos) { conf.reader_pos = 0; } pause = 0; read_to_draw = 1; x=camera_screen.disp_left+6; y=FONT_HEIGHT; w=camera_screen.disp_width-6-6-8; h=camera_screen.height-y; last_time = get_tick_count(); reader_is_active=1; old_mode = gui_set_mode(&GUI_MODE_READ); return (read_file >= 0); }
int CHttpConn::Send(void* data, int len) { m_last_send_tick = get_tick_count(); if (m_busy) { m_out_buf.Write(data, len); return len; } int ret = netlib_send(m_sock_handle, data, len); if (ret <= 0) { if (errno == EAGAIN || errno == EWOULDBLOCK) { ret = 0; } else { log("close on error=%d", errno); OnClose(); return -1; } } if (ret < len) { m_out_buf.Write((char*)data + ret, len - ret); m_busy = true; //log("not send all, remain=%d ", m_out_buf.GetWriteOffset()); } else { OnWriteCompelete(); } return len; }
unsigned long RegisterTimer(int milisecond, P2PTimerProc callback, void* pParam, int nRepeatTime) { struct time_node* pTimerNode; struct time_node* pTemp; Position it, itPrev; pTimerNode = (struct time_node*)malloc(sizeof(struct time_node)); pTimerNode->pPtr = pParam; pTimerNode->OnTimer = callback; pTimerNode->ulNextTime = get_tick_count() + milisecond; pTimerNode->nRemainCount = nRepeatTime; pTimerNode->ulID = g_ulTimerSeq++; pTimerNode->nInterval = milisecond; lstLock(g_timer); it = lstFirst(g_timer); itPrev = lstHeader(g_timer); while(it != NULL) { pTemp = (struct time_node*)lstRetrieve(it); if(pTemp->ulNextTime > pTimerNode->ulNextTime) break; itPrev = it; it = lstAdvance(it); } lstInsert(g_timer, pTimerNode, itPrev); lstUnLock(g_timer); NotifyHandler(); return pTimerNode->ulID; }
ErrorID_t error_mode(cwiid_wiimote_t *wiimote, volatile WiimoteStatusDataType *wiimote_status) { debug_print("@%u: An error has occurred\n", get_tick_count()); shutdown_application(-1); return ERR_UNKN; }
static void physics_init(void) { phys_buffer_cap = 100; phys_buffer = malloc(sizeof(struct phys_obj*) * phys_buffer_cap); phys_buffer_mtx = mutex_create(); spawn_phys_obj((void*)&p1); restart_last_tick = get_tick_count(); }
void term_schedule_vbell(int already_started, int startpoint) { int ticks_gone = already_started ? get_tick_count() - startpoint : 0; int ticks = 100 - ticks_gone; if ((term.in_vbell = ticks > 0)) win_set_timer(vbell_cb, ticks); }
//============================================================================== String Timer::elapsed_time() { elapsed_time_ = get_tick_count() - start_time_; char buf[16]; sprintf(buf, "%.02f s.", (float)elapsed_time_ / 1000); return buf; }
static void movement_calc(void *o) { struct missile *m = o; float target_dist = FLT_MAX; if (m->target != NULL) { target_dist = vector_magnitude(m->pos, m->target->pos); target_dist -= m->hb[0].rad; target_dist -= m->target->hb[0].rad; } if ( (m->life_time != 0 && get_tick_count() - m->init_time > m->life_time) || (m->frag && target_dist < 0.05*world_scale) ) { if (m->frag) { missile_frag(m); } if (m->target != NULL) { remove_reset_ptr((void*)m->target, &m->target); } m->is_alive = false; explode(m); return; } if (m->target == NULL) { remove_reset_ptr((void*)m->target, &m->target); if (!m->dumb) { m->target = acquire_target(m->firer); if (m->target != NULL) { puts("required target"); } } return; } if ( !m->target->is_alive || !timed_out_r(&m->last_ctrl_tick, CTRL_RATE)) { return; } float dx = -m->target->pos.x + m->pos.x; float dy = +m->target->pos.y - m->pos.y; float old_rot = m->rotation; m->rotation = rad_to_degd(atan2(dx, dy)); const float MAX_ROT = 10; if (old_rot > m->rotation) { if (old_rot - m->rotation > MAX_ROT || fmod(360 + old_rot - m->rotation, 360) > MAX_ROT) { m->rotation = old_rot - MAX_ROT; } } else { if (m->rotation - old_rot > MAX_ROT || fmod(360 + m->rotation - old_rot, 360) > MAX_ROT) { m->rotation = old_rot + MAX_ROT; } } float mag = xy_magnitude(m->vel.x, m->vel.y); m->vel.x = vector_x(mag, 180 + m->rotation); m->vel.y = vector_y(mag, m->rotation); m->accel = 0; }
void log_api(uint32_t index, int is_success, uintptr_t return_value, uint64_t hash, last_error_t *lasterr, ...) { va_list args; char idx[4]; va_start(args, lasterr); EnterCriticalSection(&g_mutex); if(g_api_init[index] == 0) { log_explain(index); g_api_init[index] = 1; } LeaveCriticalSection(&g_mutex); bson b; bson_init_size(&b, mem_suggested_size(1024)); bson_append_int(&b, "I", index); bson_append_int(&b, "T", get_current_thread_id()); bson_append_int(&b, "t", get_tick_count() - g_starttick); bson_append_long(&b, "h", hash); // If failure has been determined, then log the last error as well. if(is_success == 0) { bson_append_int(&b, "e", lasterr->lasterror); bson_append_int(&b, "E", lasterr->nt_status); } #if DEBUG if(index != sig_index_exception()) { _log_stacktrace(&b); } #endif bson_append_start_array(&b, "args"); bson_append_int(&b, "0", is_success); bson_append_long(&b, "1", return_value); int argnum = 2, override = 0; for (const char *fmt = sig_paramtypes(index); *fmt != 0; fmt++) { ultostr(argnum++, idx, 10); // Limitation override. Instead of displaying this right away in the // report we turn it into a buffer (much like the dropped files). if(*fmt == '!') { override = 1; argnum--; fmt++; } if(*fmt == 's') { const char *s = va_arg(args, const char *); log_string(&b, idx, s, copy_strlen(s)); } else if(*fmt == 'S') {
ErrorID_t wait_for_wiimotedata(volatile WiimoteStatusDataType *wiimote_status, int32_t timeout) { ErrorID_t ret_val = ERR_NONE; #if _MUTEX_ENABLE static struct timespec abstime; if (0 < timeout) { update_timeout_value(&abstime, timeout); ret_val = pthread_cond_timedwait(&cond, &mutex, &abstime); if (ETIMEDOUT == ret_val) { fprintf(stderr, "@%u: Wiimote data timeout.\n", get_tick_count()); } } else { ret_val = pthread_cond_wait(&cond, &mutex); } if (0 <= ret_val) { #if (_DEBUG >= 2) fprintf(stderr, "@%u: Wiimote data received.\n", get_tick_count()); #endif } #else uint32_t start_time = get_tick_count(); wiimote_data_ready = false; while (!wiimote_data_ready) { if (check_for_timeout(get_tick_count(), start_time, timeout)) { debug_print("%u: wiimote data timeout, timeout = %d\n", get_tick_count(), timeout); return ERR_WII_DATA_TIMEOUT; } usleep(25 * 1000); } #endif return ret_val; }