void timer_set_time(double time) { if (time != time || time < 0.0 || time > 18446744073.0) return; timerOffset = get_timer_value() - (unsigned long) (time * 1000000); }
void os_tick_init(uint32_t os_ticks_per_sec, int prio) { ticks_per_ostick = RTC_FREQ / os_ticks_per_sec; last_tick_time = get_timer_value(); set_mtimecmp(last_tick_time + ticks_per_ostick); set_csr(mie, MIP_MTIP); }
void timer_interrupt_handler(void) { uint64_t time = get_timer_value(); int delta = (int)(time - last_tick_time); last_tick_time = time; int ticks = delta / ticks_per_ostick; set_mtimecmp(time + ticks_per_ostick); os_time_advance(ticks); }
void* thread_disconnector() { if (DEBUG == 1) printf("DEBUG thread_disconnector: begin\n"); while (1) { int i=0; for (;i<connected_count;++i) { if (DEBUG==1) printf("DEBUG thread_disconnector: time: %f\n",get_timer_value(i)); if (get_timer_value(i) > 10000.0f) { if (DEBUG == 1) { printf("DEBUG thread_disconnector: client %d doesnt response\n",i); print_timers(); } sem_wait(&semaphore); // przesunac cl_names memcpy(cl_names+i, cl_names+i+1,sizeof(cl_names[i])*(connected_count-i-1)); // przesunac cl_addr memcpy(cl_addr+i, cl_addr+i+1,sizeof(cl_addr[i])*(connected_count-i-1)); // przesunac timery memcpy(timers_start+i, timers_start+i+1,sizeof(timers_start[i])*(connected_count-i-1)); --connected_count; sem_post(&semaphore); if (DEBUG == 1) { printf("DEBUG thread_disconnector: client %d shifting finished\n",i); print_timers(); } } } sleep(1); } }
unsigned int get_elapse_ms() { unsigned long long tmp; unsigned int timer_get = 0; timer_get = get_timer_value(); #ifdef CONFIG_USE_TIMER_STAMP timer_get = (unsigned int)0xFFFFFFFF - timer_get; #endif tmp = (unsigned long long)(timer_get & 0xFFFFFFFF); tmp = (tmp*1000)>>15; return (unsigned int)tmp; }
void *user_timer(EVENT_MSG *msg,void **usr) { int x; static int lastvalue=0; usr; if (msg->msg==E_WATCH) { *otevri_zavoru=1; x=get_timer_value(); x-=lastvalue; lastvalue+=x; if (x) send_message(E_TIMER,x); } return &user_timer; }
// [ref] ${IVT_HOME}/examples/ParticleFilterDemo/src/main.cpp void particle_filter_example() { const int NUMBER_OF_PARTICLES = 200; const int width = 400; const int height = 300; CByteImage image(width, height, CByteImage::eGrayScale); CByteImage color(width, height, CByteImage::eRGB24); MyRegion region; int k = 40; #ifdef TRACK_3D double result_configuration[DIMENSION_3D]; CParticleFilter3D particle_filter(NUMBER_OF_PARTICLES, width, height, k); #else double result_configuration[DIMENSION_2D]; CParticleFilter2D particle_filter(NUMBER_OF_PARTICLES, width, height, k); #endif // gui CApplicationHandlerInterface *pApplicationHandler = CreateApplicationHandler(); pApplicationHandler->Reset(); CMainWindowInterface *pMainWindow = CreateMainWindow(0, 0, width, height, "Particle Filter Demo"); WIDGET_HANDLE pImageWidget = pMainWindow->AddImage(0, 0, width, height); pMainWindow->Show(); for (int i = 0; i < 600; ++i) { unsigned int t = get_timer_value(true); local::SimulateMovement(&image); particle_filter.SetImage(&image); particle_filter.ParticleFilter(result_configuration); #ifdef TRACK_3D k = int(result_configuration[2] + 0.5); #endif region.min_x = int(result_configuration[0] - k + 0.5); region.min_y = int(result_configuration[1] - k + 0.5); region.max_x = int(result_configuration[0] + k + 0.5); region.max_y = int(result_configuration[1] + k + 0.5); ImageProcessor::ConvertImage(&image, &color); PrimitivesDrawer::DrawRegion(&color, region, 255, 0, 0, 2); pMainWindow->SetImage(pImageWidget, &color); if (pApplicationHandler->ProcessEventsAndGetExit()) break; while (get_timer_value() - t < 1000000.0 / 30); } delete pMainWindow; delete pApplicationHandler; }
// init application and run int Run() { CBitmapCapture capture(DEMO_IMAGE); // open camera if (!capture.OpenCamera()) { printf("error: could not open camera\n"); return 1; } const int width = capture.GetWidth(); const int height = capture.GetHeight(); // create temp image for the image processing CByteImage image(width, height, capture.GetType()); CByteImage grayImage(width, height, CByteImage::eGrayScale); CByteImage tempImage(width, height, CByteImage::eGrayScale); CByteImage visualizationImage(width, height, CByteImage::eRGB24); CByteImage *pImage = ℑ // create an application handler CApplicationHandlerInterface *pApplicationHandler = CreateApplicationHandler(); pApplicationHandler->Reset(); // create a main window m_pMainWindow = CreateMainWindow(0, 0, width, height + 190, "Hough Line Detection Demo"); // events are sent to this class, hence this class needs to have the CMainWindowEventInterface m_pMainWindow->SetEventCallback(this); // create an image widget to display a window WIDGET_HANDLE pImageWidget = m_pMainWindow->AddImage(0, 190, width, height); // add a label and a slider for the low threshold WIDGET_HANDLE pLabelCannyLow = m_pMainWindow->AddLabel(15, 15, 200, 30, "Canny low threshold: 0"); m_pSliderCannyLow = m_pMainWindow->AddSlider(15, 30, 200, 40, 0, 1020, 102, m_nCannyLowThreshold); // add a label and a slider for the high threshold WIDGET_HANDLE pLabelCannyHigh = m_pMainWindow->AddLabel(15, 70, 200, 30, "Canny high threshold: 0"); m_pSliderCannyHigh = m_pMainWindow->AddSlider(15, 85, 200, 40, 0, 1020, 102, m_nCannyHighThreshold); // add a label and a slider for the number of lines to extract WIDGET_HANDLE pLabelLines = m_pMainWindow->AddLabel(260, 15, 200, 30, "Circles to extract: 0 lines"); m_pSliderLinesToExtract = m_pMainWindow->AddSlider(260, 30, 200, 40, 0, 30, 5, m_nCirclesToExtract); // add labels/sliders for specifying the radius interval of interest WIDGET_HANDLE pLabelMinRadius = m_pMainWindow->AddLabel(260, 70, 200, 30, "Min radius: 0"); m_pSliderMinRadius = m_pMainWindow->AddSlider(260, 85, 200, 40, 1, 200, 5, m_nMinRadius); WIDGET_HANDLE pLabelMaxRadius = m_pMainWindow->AddLabel(260, 125, 200, 30, "Max radius: 0"); m_pSliderMaxRadius = m_pMainWindow->AddSlider(260, 140, 200, 40, 1, 200, 5, m_nMaxRadius); // add a button to toggle between the original image and the processed one m_pButton = m_pMainWindow->AddButton(510, 80, 110, 35, "Show Edges"); // add a labels to display processing stats WIDGET_HANDLE pLabelMS = m_pMainWindow->AddLabel(560, 15, 70, 20, "0 ms"); WIDGET_HANDLE pLabelFPS = m_pMainWindow->AddLabel(560, 45, 70, 20, "0 fps"); // make the window visible m_pMainWindow->Show(); char buffer[1024]; CVec3dArray resultListCircles(50); CDynamicArrayTemplate<int> resultHits(50); CVec2dArray edgePoints(10000), edgeDirections(10000); // main loop while (!pApplicationHandler->ProcessEventsAndGetExit()) { if (!capture.CaptureImage(&pImage)) break; // this is for visualization purposes only ImageProcessor::ConvertImage(pImage, &visualizationImage); get_timer_value(true); // convert input image to grayscale image ImageProcessor::ConvertImage(&image, &tempImage, true); // smooth image ImageProcessor::GaussianSmooth3x3(&tempImage, &grayImage); // detect edges with Canny edge detector ImageProcessor::Canny(&grayImage, edgePoints, edgeDirections, m_nCannyLowThreshold, m_nCannyHighThreshold); // detect lines with Hough transform ImageProcessor::HoughTransformCircles(edgePoints, edgeDirections, width, height, m_nMinRadius, m_nMaxRadius, m_nCirclesToExtract, 1, resultListCircles, resultHits, &visualizationImage); const unsigned int t = get_timer_value(); // display the speed stats sprintf(buffer, "%2.2f ms", t / 1000.0f); m_pMainWindow->SetText(pLabelMS, buffer); sprintf(buffer, "%3.2f fps", 1000000.0f / t); m_pMainWindow->SetText(pLabelFPS, buffer); sprintf(buffer, "Canny low threshold: %i", m_nCannyLowThreshold); m_pMainWindow->SetText(pLabelCannyLow, buffer); sprintf(buffer, "Canny high threshold: %i", m_nCannyHighThreshold); m_pMainWindow->SetText(pLabelCannyHigh, buffer); sprintf(buffer, "Min radius: %i", m_nMinRadius); m_pMainWindow->SetText(pLabelMinRadius, buffer); sprintf(buffer, "Max radius: %i", m_nMaxRadius); m_pMainWindow->SetText(pLabelMaxRadius, buffer); sprintf(buffer, "Circles to extract: %i", m_nCirclesToExtract); m_pMainWindow->SetText(pLabelLines, buffer); // display either the original image or the processed image if (m_bShowEdges) { ImageProcessor::Canny(&grayImage, &grayImage, m_nCannyLowThreshold, m_nCannyHighThreshold); m_pMainWindow->SetImage(pImageWidget, &grayImage); } else m_pMainWindow->SetImage(pImageWidget, &visualizationImage); } delete m_pMainWindow; delete pApplicationHandler; return 0; }
double timer_get_time(void) { return (double) (get_timer_value() - timerOffset) / 1000000; }