void cleanup_upon_sig(int sig __attribute__((unused))) { time_t actual_duration; if (finished) return; finished = 1; rt_timer_stop(); rt_sem_delete(&display_sem); if (do_histogram || do_stats) dump_hist_stats(); time(&test_end); actual_duration = test_end - test_start; if (!test_duration) test_duration = actual_duration; gavgjitter /= (test_loops ?: 2)-1; printf("---|------------|------------|------------|--------|-------------------------\n" "RTS|%12ld|%12ld|%12ld|%8ld| %.2ld:%.2ld:%.2ld/%.2d:%.2d:%.2d\n", gminjitter, gavgjitter, gmaxjitter, goverrun, actual_duration / 3600,(actual_duration / 60) % 60,actual_duration % 60, test_duration / 3600,(test_duration / 60) % 60,test_duration % 60); if (histogram_avg) free(histogram_avg); if (histogram_max) free(histogram_max); if (histogram_min) free(histogram_min); exit(0); }
void rtgui_timer_stop (rtgui_timer_t* timer) { RT_ASSERT(timer != RT_NULL); /* stop rt-thread timer */ rt_timer_stop(&(timer->timer)); }
/* normally the tone frequency should be 31 to 4978, refer to piches.h */ void tone(uint8_t pin, uint16_t frequency, unsigned long duration) { static struct rt_timer timer2, timer3; rt_timer_t timer; RT_ASSERT(frequency * 2 < UINT16_MAX); if(pin < 2 || pin > 3) return; if (pin == 2) { timer = &timer2; } else if (pin == 3) { timer = &timer3; } rt_timer_stop(timer); rt_timer_init(timer, "pwmkill", pwm_shutdown, (void*) pin, rt_tick_from_millisecond(duration), RT_TIMER_FLAG_ONE_SHOT); TIM_config(pin, frequency); pwmConfig(pin, UINT8_MAX / 2); rt_timer_start(timer); }
static void s3c2410_intc_stylus_updown(void) { rt_uint32_t data0; rt_uint32_t data1; int updown; data0 = ADCDAT0; data1 = ADCDAT1; updown = (!(data0 & S3C2410_ADCDAT0_UPDOWN)) && (!(data1 & S3C2410_ADCDAT0_UPDOWN)); /* rt_kprintf("stylus: %s\n", updown? "down" : "up"); */ if (updown) { touch_timer_fire(0); } else { /* stop timer */ rt_timer_stop(touch->poll_timer); touch->first_down_report = RT_TRUE; if (ts.xp >= 0 && ts.yp >= 0) { report_touch_input(updown); } ts.count = 0; ADCTSC = WAIT4INT(0); } SUBSRCPND |= BIT_SUB_TC; }
static int logDeleteBlock(int id) { int i; struct log_ops * ops; struct log_ops * opsNext; for (i=0; i<LOG_MAX_BLOCKS; i++) if (logBlocks[i].id == id) break; if (i >= LOG_MAX_BLOCKS) { ERROR("trying to delete block id %d that doesn't exist.", id); return ENOENT; } ops = logBlocks[i].ops; while (ops) { opsNext = ops->next; opsFree(ops); ops = opsNext; } if (logBlocks[i].timer != 0) { //xTimerStop(logBlocks[i].timer, portMAX_DELAY); rt_timer_stop(logBlocks[i].timer); //xTimerDelete(logBlocks[i].timer, portMAX_DELAY); rt_timer_delete(logBlocks[i].timer); logBlocks[i].timer = 0; } logBlocks[i].id = BLOCK_ID_FREE; return 0; }
void rtgui_timer_stop(rtgui_timer_t *timer) { RT_ASSERT(timer != RT_NULL); /* stop rt-thread timer */ timer->state = RTGUI_TIMER_ST_INIT; rt_timer_stop(&(timer->timer)); }
/* * Save the rendered image to disk. */ static void renderio(scenedef * scene) { flt iotime; char msgtxt[256]; rt_timerhandle ioth; /* I/O timer handle */ ioth=rt_timer_create(); rt_timer_start(ioth); if (scene->imgbufformat == RT_IMAGE_BUFFER_RGB96F) { if (scene->imgprocess & RT_IMAGE_NORMALIZE) { normalize_rgb96f(scene->hres, scene->vres, (float *) scene->img); rt_ui_message(MSG_0, "Post-processing: normalizing pixel values."); } if (scene->imgprocess & RT_IMAGE_GAMMA) { gamma_rgb96f(scene->hres, scene->vres, (float *) scene->img, scene->imggamma); rt_ui_message(MSG_0, "Post-processing: gamma correcting pixel values."); } } else if (scene->imgbufformat == RT_IMAGE_BUFFER_RGB24) { if (scene->imgprocess & (RT_IMAGE_NORMALIZE | RT_IMAGE_GAMMA)) rt_ui_message(MSG_0, "Can't post-process 24-bit integer image data"); } /* support cropping of output images for SPECMPI benchmarks */ if (scene->imgcrop.cropmode == RT_CROP_DISABLED) { writeimage(scene->outfilename, scene->hres, scene->vres, scene->img, scene->imgbufformat, scene->imgfileformat); } else { /* crop image before writing if necessary */ if (scene->imgbufformat == RT_IMAGE_BUFFER_RGB96F) { float *imgcrop; imgcrop = image_crop_rgb96f(scene->hres, scene->vres, scene->img, scene->imgcrop.xres, scene->imgcrop.yres, scene->imgcrop.xstart, scene->imgcrop.ystart); writeimage(scene->outfilename, scene->imgcrop.xres, scene->imgcrop.yres, imgcrop, scene->imgbufformat, scene->imgfileformat); free(imgcrop); } else if (scene->imgbufformat == RT_IMAGE_BUFFER_RGB24) { unsigned char *imgcrop; imgcrop = image_crop_rgb24(scene->hres, scene->vres, scene->img, scene->imgcrop.xres, scene->imgcrop.yres, scene->imgcrop.xstart, scene->imgcrop.ystart); writeimage(scene->outfilename, scene->imgcrop.xres, scene->imgcrop.yres, imgcrop, scene->imgbufformat, scene->imgfileformat); free(imgcrop); } } rt_timer_stop(ioth); iotime = rt_timer_time(ioth); rt_timer_destroy(ioth); sprintf(msgtxt, " Image I/O Time: %10.4f seconds", iotime); rt_ui_message(MSG_0, msgtxt); }
/// Stop timer osStatus osTimerStop(osTimerId timer_id) { rt_err_t result; result = rt_timer_stop(timer_id); if (result == RT_EOK) return osOK; else return osErrorOS; }
/* 定时器超时函数 */ static void timeout1(void* parameter) { rt_kprintf("periodic timer is timeout\n"); count ++; /* 停止定时器自身 */ if (count >= 8) { /* 停止定时器 */ rt_timer_stop(timer1); count = 0; } }
void cleanup_module(void) { int i; rt_timer_stop(); // kill tasks for(i = 0; i < NTASKS; i++) { rt_task_del(&td[i].task); } rtf_destroy(FROM_KERN); }
void timer_conrol(void) { timeout_value+=10; rt_timer_control(timer_test, RT_TIMER_CTRL_SET_TIME, (void *)&timeout_value); // rt_kprintf("timer timeout time set to %d !\n", timeout_value); if (timeout_value==500) { rt_timer_stop(timer_test); /* 停止定时器 */ rt_kprintf("timer stoped !\n"); } if (timeout_value>=510) { /* 再次启动定时器 */ rt_timer_start(timer_test); timeout_value=10; rt_timer_control(timer_test, RT_TIMER_CTRL_SET_TIME, (void *)&timeout_value); } }
static int logStopBlock(int id) { int i; for (i=0; i<LOG_MAX_BLOCKS; i++) if (logBlocks[i].id == id) break; if (i >= LOG_MAX_BLOCKS) { ERROR("Trying to stop block id %d that doesn't exist.\n", id); return ENOENT; } //xTimerStop(logBlocks[i].timer, portMAX_DELAY); rt_timer_stop(logBlocks[i].timer); return 0; }
void cleanup_upon_sig(int sig __attribute__((unused))) { time_t actual_duration; long gmaxj, gminj, gavgj; if (finished) return; finished = 1; if (!hard_timer_running) { rt_timer_stop(); } rt_sem_delete(&display_sem); if (do_histogram || do_stats) dump_hist_stats(); time(&test_end); actual_duration = test_end - test_start - WARMUP_TIME; if (!test_duration) test_duration = actual_duration; gavgjitter /= (test_loops > 1 ? test_loops : 2)-1; gminj = rt_timer_tsc2ns(gminjitter); gmaxj = rt_timer_tsc2ns(gmaxjitter); gavgj = rt_timer_tsc2ns(gavgjitter); printf("---|------------|------------|------------|--------|-------------------------\n" "RTS|%12ld|%12ld|%12ld|%8ld| %.2ld:%.2ld:%.2ld/%.2d:%.2d:%.2d\n", gminj, gavgj, gmaxj, goverrun, actual_duration / 3600, (actual_duration / 60) % 60, actual_duration % 60, test_duration / 3600, (test_duration / 60) % 60, test_duration % 60); if (histogram_avg) free(histogram_avg); if (histogram_max) free(histogram_max); if (histogram_min) free(histogram_min); exit(0); }
/** * This function will resume a rms task and put it into ready queue */ rt_err_t rt_rms_resume(rt_rms_t rms) { register rt_base_t temp; /* rms check */ RT_ASSERT(rms != RT_NULL); temp = rt_hw_interrupt_disable(); rt_list_remove(&(rms->rlist)); rt_timer_stop(&rms->thread->thread_timer); rt_hw_interrupt_enable(temp); rt_schedule_insert_rms(rms); return RT_RMS_EOK; }
void led_flash(rt_uint32_t led,rt_uint32_t freq) { rt_timer_t set_timer; switch(led) { case 0: set_timer = &timer1; break; // case 1: // set_timer = &timer2; // break; // // case 2: // set_timer = &timer3; // break; // // case 3: // set_timer = &timer4; // break; // // default: // rt_timer_stop(&timer1); // rt_timer_stop(&timer2); // rt_timer_stop(&timer3); // rt_timer_stop(&timer4); // return; } if(freq == 0) { rt_timer_stop(set_timer); return; } freq/=10; rt_timer_control(set_timer,RT_TIMER_CTRL_SET_TIME,(void*)&freq); rt_timer_start(set_timer); }
void lip_update_local(t_nmea_rmc *p_rmc, float *p_accu) { vam_envar_t *p_vam = &p_cms_envar->vam; if (p_rmc){ p_vam->local.pos.lat = (float)p_rmc->latitude; p_vam->local.pos.lon = (float)p_rmc->longitude; if (p_vam->local.speed != (float)p_rmc->speed) { p_vam->local.speed = (float)p_rmc->speed; vsm_update_bsm_bcast_timer(p_vam); } /* 解决停车speed<=3 heading=0的问题, 使用>5km/h的heading */ if((p_rmc->heading >= 5.0) && (p_rmc->heading <= 360.0)) { p_vam->local.dir = (float)p_rmc->heading; } //dump_pos(&p_vam->local); if (!(p_vam->flag&VAM_FLAG_GPS_FIXED)){ p_vam->flag |= VAM_FLAG_GPS_FIXED; rt_kprintf("gps is captured.\n"); if (p_vam->evt_handler[VAM_EVT_GPS_STATUS]){ (p_vam->evt_handler[VAM_EVT_GPS_STATUS])((void *)1); } } /* refresh the timer */ rt_timer_stop(p_vam->timer_gps_life); rt_timer_start(p_vam->timer_gps_life); if(p_vam->evt_handler[VAM_EVT_LOCAL_UPDATE]){ (p_vam->evt_handler[VAM_EVT_LOCAL_UPDATE])(&p_vam->local); } } if (p_accu){ p_vam->local.pos.accu = *p_accu; } }
int main(int argc, char *argv[]) { int ret; unsigned int i; struct sockaddr_in local_addr; struct in_addr dest_ip; while (1) { switch (getopt(argc, argv, "d:s:t")) { case 'd': dest_ip_s = optarg; break; case 's': size = atoi(optarg); break; case 't': start_timer = 1; break; case -1: goto end_of_opt; default: printf("usage: %s -d <dest_ip> -s <size> -t\n", argv[0]); return 0; } } end_of_opt: inet_aton(dest_ip_s, &dest_ip); if (size > 65505) size = 65505; signal(SIGTERM, catch_signal); signal(SIGINT, catch_signal); mlockall(MCL_CURRENT|MCL_FUTURE); printf("destination ip address %s=%08x\n", dest_ip_s, dest_ip.s_addr); printf("size %d\n", size); printf("start timer %d\n", start_timer); /* fill output buffer with test pattern */ for (i = 0; i < sizeof(buffer_out); i++) buffer_out[i] = i & 0xFF; /* create rt-socket */ sock = socket_rt(AF_INET,SOCK_DGRAM,0); if (sock < 0) { printf(" socket_rt() = %d!\n", sock); return sock; } /* extend the socket pool */ ret = ioctl_rt(sock, RTNET_RTIOC_EXTPOOL, &add_rtskbs); if (ret != (int)add_rtskbs) { printf(" ioctl_rt(RT_IOC_SO_EXTPOOL) = %d\n", ret); close_rt(sock); return -1; } /* bind the rt-socket to a port */ memset(&local_addr, 0, sizeof(struct sockaddr_in)); local_addr.sin_family = AF_INET; local_addr.sin_port = htons(PORT); local_addr.sin_addr.s_addr = INADDR_ANY; ret = bind_rt(sock, (struct sockaddr *)&local_addr, sizeof(struct sockaddr_in)); if (ret < 0) { printf(" bind_rt() = %d!\n", ret); close_rt(sock); return ret; } /* set destination address */ memset(&dest_addr, 0, sizeof(struct sockaddr_in)); dest_addr.sin_family = AF_INET; dest_addr.sin_port = htons(PORT); dest_addr.sin_addr = dest_ip; if (start_timer) { rt_timer_start(TM_ONESHOT); } ret = rt_task_create(&rt_recv_task, "Receiver", 0, 10, 0); if (ret != 0) { printf(" rt_task_create(recv) = %d!\n", ret); close_rt(sock); return ret; } ret = rt_task_create(&rt_xmit_task, "Sender", 0, 9, 0); if (ret != 0) { printf(" rt_task_create(xmit) = %d!\n", ret); close_rt(sock); rt_task_delete(&rt_recv_task); return ret; } rt_task_start(&rt_recv_task, recv_msg, NULL); rt_task_start(&rt_xmit_task, xmit_msg, NULL); pause(); if (start_timer) rt_timer_stop(); /* Important: First close the socket! */ while (close_rt(sock) == -EAGAIN) { printf("frag-ip: Socket busy - waiting...\n"); sleep(1); } rt_task_delete(&rt_xmit_task); rt_task_delete(&rt_recv_task); return 0; }
void vMBMasterPortTimersDisable() { rt_timer_stop(&timer); }
/* * Check the scene to determine whether or not any parameters that affect * the thread pool, the persistent message passing primitives, or other * infrastructure needs to be reconfigured before rendering commences. */ void rendercheck(scenedef * scene) { flt runtime; rt_timerhandle stth; /* setup time timer handle */ if (scene->verbosemode && scene->mynode == 0) { char msgtxt[1024]; int i, totalcpus; flt totalspeed; rt_ui_message(MSG_0, "CPU Information:"); totalspeed = 0.0; totalcpus = 0; for (i=0; i<scene->nodes; i++) { sprintf(msgtxt, " Node %4d: %2d CPUs, CPU Speed %4.2f, Node Speed %6.2f Name: %s", i, scene->cpuinfo[i].numcpus, scene->cpuinfo[i].cpuspeed, scene->cpuinfo[i].nodespeed, scene->cpuinfo[i].machname); rt_ui_message(MSG_0, msgtxt); totalcpus += scene->cpuinfo[i].numcpus; totalspeed += scene->cpuinfo[i].nodespeed; } sprintf(msgtxt, " Total CPUs: %d", totalcpus); rt_ui_message(MSG_0, msgtxt); sprintf(msgtxt, " Total Speed: %f\n", totalspeed); rt_ui_message(MSG_0, msgtxt); } rt_barrier_sync(); /* synchronize all nodes at this point */ stth=rt_timer_create(); rt_timer_start(stth); /* Time the preprocessing of the scene database */ rt_autoshader(scene); /* Adapt to the shading features needed at runtime */ /* Hierarchical grid ray tracing acceleration scheme */ if (scene->boundmode == RT_BOUNDING_ENABLED) engrid_scene(scene, scene->boundthresh); /* if any clipping groups exist, we have to use appropriate */ /* intersection testing logic */ if (scene->cliplist != NULL) { scene->flags |= RT_SHADE_CLIPPING; } /* if there was a preexisting image, free it before continuing */ if (scene->imginternal && (scene->img != NULL)) { free(scene->img); scene->img = NULL; } /* Allocate a new image buffer if necessary */ if (scene->img == NULL) { scene->imginternal = 1; if (scene->verbosemode && scene->mynode == 0) { rt_ui_message(MSG_0, "Allocating Image Buffer."); } /* allocate the image buffer accordinate to pixel format */ if (scene->imgbufformat == RT_IMAGE_BUFFER_RGB24) { scene->img = malloc(scene->hres * scene->vres * 3); } else if (scene->imgbufformat == RT_IMAGE_BUFFER_RGB96F) { scene->img = malloc(sizeof(float) * scene->hres * scene->vres * 3); } else { rt_ui_message(MSG_0, "Illegal image buffer format specifier!"); } if (scene->img == NULL) { scene->imginternal = 0; rt_ui_message(MSG_0, "Warning: Failed To Allocate Image Buffer!"); } } /* if any threads are leftover from a previous scene, and the */ /* scene has changed significantly, we have to collect, and */ /* respawn the worker threads, since lots of things may have */ /* changed which would affect them. */ destroy_render_threads(scene); create_render_threads(scene); /* allocate and initialize persistent scanline receive buffers */ /* which are used by the parallel message passing code. */ scene->parbuf = rt_init_scanlinereceives(scene); /* the scene has been successfully prepared for rendering */ /* unless it gets modified in certain ways, we don't need to */ /* pre-process it ever again. */ scene->scenecheck = 0; rt_timer_stop(stth); /* Preprocessing is finished, stop timing */ runtime=rt_timer_time(stth); rt_timer_destroy(stth); /* Print out relevent timing info */ if (scene->mynode == 0) { char msgtxt[256]; sprintf(msgtxt, "Preprocessing Time: %10.4f seconds",runtime); rt_ui_message(MSG_0, msgtxt); } }
int ray(int argc, char **argv) { #else int main(int argc, char **argv) { #endif SceneHandle scene; unsigned int rc; argoptions opt; char * filename; int node, fileindex; rt_timerhandle parsetimer; size_t len; node = rt_initialize(&argc, &argv); rt_set_ui_message(my_ui_message); rt_set_ui_progress(my_ui_progress); if (node == 0) { printf("Tachyon Parallel/Multiprocessor Ray Tracer Version %s \n", TACHYON_VERSION_STRING); printf("Copyright 1994-2010, John E. Stone <*****@*****.**> \n"); printf("------------------------------------------------------------ \n"); } if ((rc = getargs(argc, argv, &opt, node)) != 0) { rt_finalize(); exit(rc); } if (opt.numfiles > 1) { printf("Rendering %d scene files.\n", opt.numfiles); } for (fileindex=0; fileindex<opt.numfiles; fileindex++) { scene = rt_newscene(); /* process command line overrides */ presceneoptions(&opt, scene); filename = opt.filenames[fileindex]; if (opt.numfiles > 1) { printf("\nRendering scene file %d of %d, %s\n", fileindex+1, opt.numfiles, filename); } parsetimer=rt_timer_create(); rt_timer_start(parsetimer); len = strlen(filename); if (len > 4 && (!strcmp(filename+len-4, ".nff") || !strcmp(filename+len-4, ".NFF"))) { rc = ParseNFF(filename, scene); /* must be an NFF file */ } else if (len > 3 && (!strcmp(filename+len-3, ".ac") || !strcmp(filename+len-3, ".AC"))) { rc = ParseAC3D(filename, scene); /* Must be an AC3D file */ } #ifdef USELIBMGF else if (len > 4 && (!strcmp(filename+len-4, ".mgf") || !strcmp(filename+len-4, ".MGF"))) { rc = ParseMGF(filename, scene, 1); /* Must be an MGF file */ } #endif else { rc = readmodel(filename, scene); /* Assume its a Tachyon scene file */ } rt_timer_stop(parsetimer); if (rc == PARSENOERR && node == 0) printf("Scene Parsing Time: %10.4f seconds\n", rt_timer_time(parsetimer)); rt_timer_destroy(parsetimer); if (rc != PARSENOERR && node == 0) { switch(rc) { case PARSEBADFILE: printf("Parser failed due to nonexistent input file: %s\n", filename); break; case PARSEBADSUBFILE: printf("Parser failed due to nonexistent included file.\n"); break; case PARSEBADSYNTAX: printf("Parser failed due to an input file syntax error.\n"); break; case PARSEEOF: printf("Parser unexpectedly hit an end of file.\n"); break; case PARSEALLOCERR: printf("Parser ran out of memory.\n"); break; } if (fileindex+1 < opt.numfiles) printf("Aborting render, continuing with next scene file...\n"); else printf("Aborting render.\n"); rt_deletescene(scene); /* free the scene */ continue; /* process the next scene */ } /* process command line overrides */ postsceneoptions(&opt, scene); /* choose which rendering mode to use */ if (opt.usecamfile == 1) { return animate_scene(opt, scene, node); /* fly using prerecorded data */ } else if (strlen(opt.spaceball) > 0) { return fly_scene(opt, scene, node); /* fly with spaceball etc */ } else { if (opt.numfiles > 1 && opt.nosave != 1) { char multioutfilename[FILENAME_MAX]; sprintf(multioutfilename, opt.outfilename, fileindex); rt_outputfile(scene, multioutfilename); } rt_renderscene(scene); /* Render a single frame */ } rt_deletescene(scene); /* free the scene, get ready for next one */ } rt_finalize(); /* close down the rendering library and MPI */ freeoptions(&opt); /* free parsed command line option data */ return 0; }
/* * main loop for creating animations by playing recorded camera fly-throughs */ static int animate_scene(argoptions opt, SceneHandle scene, int node) { char outfilename[1000]; FILE * camfp; dispHandle * dh = NULL; if (node == 0) dh = tachyon_display_create(scene); /* if we have a camera file, then animate.. */ if ((camfp = fopen(opt.camfilename, "r")) != NULL) { floatvec cv, cu, cc; apivector cmv, cmu, cmc; int frameno = 0; float fps; rt_timerhandle fpstimer; rt_timerhandle animationtimer; rt_set_ui_message(NULL); rt_set_ui_progress(NULL); if (node == 0) printf("Running Camera File: %s\n", opt.camfilename); fpstimer=rt_timer_create(); animationtimer=rt_timer_create(); rt_timer_start(animationtimer); while (!feof(camfp)) { fscanf(camfp, "%f %f %f %f %f %f %f %f %f", &cv.x, &cv.y, &cv.z, &cu.x, &cu.y, &cu.z, &cc.x, &cc.y, &cc.z); cmv.x = cv.x; cmv.y = cv.y; cmv.z = cv.z; cmu.x = cu.x; cmu.y = cu.y; cmu.z = cu.z; cmc.x = cc.x; cmc.y = cc.y; cmc.z = cc.z; if (frameno != 0) { rt_timer_stop(fpstimer); fps = 1.0f / rt_timer_time(fpstimer); } else { fps = 0.0; } rt_timer_start(fpstimer); outfilename[0] = '\0'; if (opt.nosave == 1) { if (node == 0) { printf("\rRendering Frame: %9d %10.4f FPS ", frameno, fps); fflush(stdout); } } else { sprintf(outfilename, opt.outfilename, frameno); if (node == 0) { printf("\rRendering Frame to %s (%10.4f FPS) ", outfilename, fps); fflush(stdout); } } rt_outputfile(scene, outfilename); rt_camera_position(scene, cmc, cmv, cmu); rt_renderscene(scene); if (dh != NULL) tachyon_display_draw(dh); frameno++; } rt_timer_stop(animationtimer); fps = frameno / rt_timer_time(animationtimer); if (node == 0) { printf("\rCompleted animation of %d frames \n", frameno); printf("Animation Time: %10.4f seconds (Averaged %7.4f FPS)\n", rt_timer_time(animationtimer), fps); } rt_timer_destroy(fpstimer); fclose(camfp); } else { if (node == 0) { printf("Couldn't open camera file: %s\n", opt.camfilename); printf("Aborting render.\n"); } rt_deletescene(scene); /* free the scene */ rt_finalize(); /* close down the rendering library and MPI */ return -1; } if (node == 0) { printf("\nFinished Running Camera.\n"); if (dh !=NULL) tachyon_display_delete(dh); } rt_deletescene(scene); /* free the scene */ rt_finalize(); /* close down the rendering library and MPI */ return 0; }
/* * main loop for creating animations by flying using a spaceball * or other 3-D input mechanism. */ static int fly_scene(argoptions opt, SceneHandle scene, int node) { dispHandle * dh = NULL; int done = 0; int frameno = 0; float fps; rt_timerhandle fpstimer; rt_timerhandle animationtimer; char outfilename[1]; #if defined(USESPACEBALL) sbHandle * bh = NULL; #endif if (node == 0) dh = tachyon_display_create(scene); rt_set_ui_message(NULL); rt_set_ui_progress(NULL); if (node == 0) printf("Interactive Camera Flight\n"); outfilename[0] = '\0'; rt_outputfile(scene, outfilename); fpstimer=rt_timer_create(); animationtimer=rt_timer_create(); #if defined(USESPACEBALL) if (node == 0) { #if 1 bh = tachyon_init_spaceball(scene, opt.spaceball); #else if (rt_numnodes() < 2) { bh = tachyon_init_spaceball(scene, opt.spaceball); } else { printf("WARNING: Spaceball mode disabled when running with distributed memory"); } #endif } #endif rt_timer_start(animationtimer); while (!done) { if (frameno != 0) { rt_timer_stop(fpstimer); fps = 1.0f / rt_timer_time(fpstimer); } else { fps = 0.0; } rt_timer_start(fpstimer); if (node == 0) { printf("\rRendering Frame: %9d %10.4f FPS ", frameno, fps); fflush(stdout); } #if defined(USESPACEBALL) if (bh != NULL) done = tachyon_spaceball_update(bh, scene); #endif rt_renderscene(scene); if (dh != NULL) tachyon_display_draw(dh); frameno++; } rt_timer_stop(animationtimer); fps = frameno / rt_timer_time(animationtimer); if (node == 0) { printf("\rCompleted animation of %d frames \n", frameno); printf("Animation Time: %10.4f seconds (Averaged %7.4f FPS)\n", rt_timer_time(animationtimer), fps); } rt_timer_destroy(fpstimer); if (node == 0) { printf("\nFinished Running Camera.\n"); if (dh !=NULL) tachyon_display_delete(dh); } rt_deletescene(scene); /* free the scene */ rt_finalize(); /* close down the rendering library and MPI */ return 0; }
/***************************************************************************//** * @brief * Write to IIC device * * @details * * @note * * @param[in] dev * Pointer to device descriptor * * @param[in] pos * Slave address * * @param[in] buffer * Poniter to the buffer * * @param[in] size * Buffer size in byte * * @return * Error code ******************************************************************************/ static rt_size_t rt_iic_write ( rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size) { rt_err_t err_code; rt_size_t write_size; struct efm32_iic_device_t* iic; I2C_TransferSeq_TypeDef seq; I2C_TransferReturn_TypeDef ret; if (!size) { return 0; } err_code = RT_EOK; write_size = 0; iic = (struct efm32_iic_device_t*)dev->user_data; /* Lock device */ if (rt_hw_interrupt_check()) { ret = rt_sem_take(iic->lock, RT_WAITING_NO); } else { ret = rt_sem_take(iic->lock, RT_WAITING_FOREVER); } if (ret != RT_EOK) { return ret; } if (iic->state & IIC_STATE_MASTER) { seq.addr = (rt_uint16_t)pos << 1; seq.flags = I2C_FLAG_WRITE; /* Set write buffer pointer and size */ seq.buf[0].data = (rt_uint8_t *)buffer; seq.buf[0].len = size; } else { // TODO: Slave mode TX } /* Do a polled transfer */ iic->timeout = false; rt_timer_stop(iic->timer); rt_timer_start(iic->timer); ret = I2C_TransferInit(iic->iic_device, &seq); while ((ret == i2cTransferInProgress) && !iic->timeout) { ret = I2C_Transfer(iic->iic_device); } if (ret != i2cTransferDone) { err_code = (rt_err_t)ret; } else { write_size = size; } /* Unlock device */ rt_sem_release(iic->lock); /* set error code */ rt_set_errno(err_code); return write_size; }
/***************************************************************************//** * @brief * Read from IIC device * * @details * * @note * * @param[in] dev * Pointer to device descriptor * * @param[in] pos * Slave address * * @param[in] buffer * Poniter to the buffer * * @param[in] size * Buffer size in byte * * @return * Error code ******************************************************************************/ static rt_size_t rt_iic_read ( rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size) { rt_err_t err_code; rt_size_t read_size; struct efm32_iic_device_t* iic; I2C_TransferSeq_TypeDef seq; I2C_TransferReturn_TypeDef ret; if (!size) { return 0; } err_code = RT_EOK; read_size = 0; iic = (struct efm32_iic_device_t*)dev->user_data; /* Lock device */ if (rt_hw_interrupt_check()) { ret = rt_sem_take(iic->lock, RT_WAITING_NO); } else { ret = rt_sem_take(iic->lock, RT_WAITING_FOREVER); } if (ret != RT_EOK) { return ret; } if (iic->state & IIC_STATE_MASTER) { seq.addr = (rt_uint16_t)pos << 1; if (*(rt_uint8_t *)buffer == IIC_OP_READ_ONLY) { seq.flags = I2C_FLAG_READ; /* Set read buffer pointer and size */ seq.buf[0].data = (rt_uint8_t *)buffer; seq.buf[0].len = size; } else { seq.flags = I2C_FLAG_WRITE_READ; /* Set register to be read */ seq.buf[0].data = (rt_uint8_t *)buffer; seq.buf[0].len = 1; /* Set read buffer pointer and size */ seq.buf[1].data = (rt_uint8_t *)buffer; seq.buf[1].len = size; } /* Do a polled transfer */ iic->timeout = false; rt_timer_stop(iic->timer); rt_timer_start(iic->timer); ret = I2C_TransferInit(iic->iic_device, &seq); while ((ret == i2cTransferInProgress) && !iic->timeout) { ret = I2C_Transfer(iic->iic_device); } if (ret != i2cTransferDone) { iic_debug("IIC: read error %x\n", ret); iic_debug("IIC: read address %x\n", seq.addr); iic_debug("IIC: read data0 %x -> %x\n", seq.buf[0].data, *seq.buf[0].data); iic_debug("IIC: read len0 %x\n", seq.buf[0].len); iic_debug("IIC: read data1 %x -> %x\n", seq.buf[1].data, *seq.buf[1].data); iic_debug("IIC: read len1 %x\n", seq.buf[1].len); err_code = (rt_err_t)ret; } else { read_size = size; iic_debug("IIC: read size %d\n", read_size); } } else { rt_uint8_t* ptr; ptr = buffer; /* interrupt mode Rx */ while (size) { rt_base_t level; struct efm32_iic_int_mode_t *int_rx; int_rx = iic->rx_buffer; /* disable interrupt */ level = rt_hw_interrupt_disable(); if (int_rx->read_index != int_rx->save_index) { /* read a character */ *ptr++ = int_rx->data_ptr[int_rx->read_index]; size--; /* move to next position */ int_rx->read_index ++; if (int_rx->read_index >= IIC_RX_BUFFER_SIZE) { int_rx->read_index = 0; } } else { /* set error code */ err_code = -RT_EEMPTY; /* enable interrupt */ rt_hw_interrupt_enable(level); break; } /* enable interrupt */ rt_hw_interrupt_enable(level); } read_size = (rt_uint32_t)ptr - (rt_uint32_t)buffer; iic_debug("IIC: slave read size %d\n", read_size); } /* Unlock device */ rt_sem_release(iic->lock); /* set error code */ rt_set_errno(err_code); return read_size; }
/* * Render the scene */ void renderscene(scenedef * scene) { flt runtime; rt_timerhandle rtth; /* render time timer handle */ /* if certain key aspects of the scene parameters have been changed */ /* since the last frame rendered, or when rendering the scene the */ /* first time, various setup, initialization and memory allocation */ /* routines need to be run in order to prepare for rendering. */ if (scene->scenecheck) rendercheck(scene); if (scene->mynode == 0) rt_ui_progress(0); /* print 0% progress at start of rendering */ /* * Core Ray Tracing Code * * Ideally, as little as possible other than this code should be * executed for rendering a frame. Most if not all memory allocations * should be done outside of the core code, and all setup should be * done outside of here. This will give the best speed when rendering * walk-throughs and similar things. */ rtth=rt_timer_create(); /* create/init rendering timer */ rt_timer_start(rtth); /* start ray tracing timer */ camera_init(scene); /* Initialize all aspects of camera system */ #if defined(MPI) && defined(THR) /* reset the rows counter for this frame */ rt_atomic_int_set(((thr_parms *) scene->threadparms)[0].rowsdone, 0); #endif #ifdef THR /* if using threads, wake up the child threads... */ rt_thread_barrier(((thr_parms *) scene->threadparms)[0].runbar, 1); #endif #ifdef MPI /* if using message passing, start persistent receives */ rt_start_scanlinereceives(scene->parbuf); /* start scanline receives */ #endif /* Actually Ray Trace The Image */ thread_trace(&((thr_parms *) scene->threadparms)[0]); #ifdef MPI rt_waitscanlines(scene->parbuf); /* wait for all scanlines to recv/send */ #endif rt_timer_stop(rtth); /* stop timer for ray tracing runtime */ runtime=rt_timer_time(rtth); rt_timer_destroy(rtth); /* * End of Core Ray Tracing Code * * Anything after here should be UI, tear-down, or reset code * */ if (scene->mynode == 0) { char msgtxt[256]; rt_ui_progress(100); /* print 100% progress when finished rendering */ sprintf(msgtxt, "\n Ray Tracing Time: %10.4f seconds", runtime); rt_ui_message(MSG_0, msgtxt); if (scene->writeimagefile) renderio(scene); } } /* end of renderscene() */