/* * load clump info group information by scanning entire toc. */ static void loadcig(Arena *arena) { uint32_t i, j, ncig, nci; ArenaCIG *cig; ClumpInfo *ci; uint64_t offset; int ms; if(arena->cig || arena->ncig < 0) return; // fprint(2, "loadcig %s\n", arena->name); ncig = (arena->memstats.clumps+ArenaCIGSize-1) / ArenaCIGSize; if(ncig == 0){ arena->cig = vtmalloc(1); arena->ncig = 0; return; } ms = msec(); cig = vtmalloc(ncig*sizeof cig[0]); ci = vtmalloc(ArenaCIGSize*sizeof ci[0]); offset = 0; for(i=0; i<ncig; i++){ nci = readclumpinfos(arena, i*ArenaCIGSize, ci, ArenaCIGSize); cig[i].offset = offset; for(j=0; j<nci; j++) offset += ClumpSize + ci[j].size; if(nci < ArenaCIGSize){ if(i != ncig-1){ vtfree(ci); vtfree(cig); arena->ncig = -1; fprint(2, "loadcig %s: got %ud cigs, expected %ud\n", arena->name, i+1, ncig); goto out; } } } vtfree(ci); arena->ncig = ncig; arena->cig = cig; out: ms = msec() - ms; addstat2(StatCigLoad, 1, StatCigLoadTime, ms); }
void main(void) { init(); // configure ports brkrst_init(); // enable break-detect pus=EEPROMread(ADDR); // read last powerup counter value pus++; // increase it EEPROMwrite(ADDR, pus); // write new value back to EEPROM while(1) { P2=pus; // blink current powerup counter msec(200); P2=0x00; msec(200); } }
void TokenBuffer<T>::pop() { while (sink_running_) { // Proceed only if buffer_ has data std::unique_lock<std::mutex> lk(cv_m_); if (cv_.wait_for(lk, msec(10)) == std::cv_status::timeout) continue; // Publish objects when they are requested until the buffer // is empty while (buffer_.read_available() > 0) { // START CRITICAL SECTION // //////////////////////////// // Wait for sources to read sink_.wait(); buffer_.pop(*shared_token_); // Tell sources there is new data sink_.post(); //////////////////////////// // END CRITICAL SECTION // } } }
string VSTime::toString() const { string result = ""; char buf1[10] = {0,}; char buf2[10] = {0,}; char buf3[10] = {0,}; char buf4[10] = {0,}; sprintf(buf1, "%d", hour()); sprintf(buf2, "%d", minute()); sprintf(buf3, "%d", second()); sprintf(buf4, "%d", msec()); string hour = string(buf1); string minute = string(buf2); string second = string(buf3); string msec = string(buf4); if (hour.size() == 1) hour = "0" + hour; if (minute.size() == 1) minute = "0" + minute; if (second.size() == 1) second = "0" + second; if (msec.size() == 1) msec = "00" + msec; if (msec.size() == 2) msec = "0" + msec; result += hour + ":"; // hour result += minute + ":"; // minute result += second + ":"; // second result += msec; // msec return result; }
static void bench_runner( bench_policy pol, const char *title, ilka_bench_fn_t fn, void *ctx, size_t threads) { const double duration = 1 * msec(); const size_t iterations = 1000; size_t dist_len = threads * iterations; double dist[dist_len]; memset(dist, 0, dist_len * sizeof(double)); size_t n = 1; double elapsed = -1; for (; elapsed < duration; n *= 2) { ilka_assert(n < 100UL * 1000 * 1000 * 1000, "bench doesn't scale with n"); pol(fn, ctx, n, threads, dist); elapsed = 0; for (size_t i = 0; i < threads; ++i) elapsed += dist[i]; elapsed /= threads; } for (size_t i = 0; i < iterations; ++i) pol(fn, ctx, n, threads, &dist[i * threads]); bench_report(title, n, threads, dist, dist_len); }
/* add a capability, throwing out any old ones */ static void addcap(uchar *hash) { Caphash *p, *t, **l; p = smalloc(sizeof *p); memmove(p->hash, hash, Hashlen); p->next = nil; p->ticks = msec(); qlock(&capalloc.l); /* trim extras */ while(capalloc.nhash >= Maxhash){ t = capalloc.first; if(t == nil) panic("addcap"); capalloc.first = t->next; free(t); capalloc.nhash--; } /* add new one */ for(l = &capalloc.first; *l != nil; l = &(*l)->next) ; *l = p; capalloc.nhash++; qunlock(&capalloc.l); }
zystm() { zystm_calls++; if (zystm_calls == 1) zzz_init(); /* / process times are in 60ths of second, multiply by 100 / to get 6000ths of second, divide by 6 to get 100ths */ #if WINNT SET_IA( msec() ); #else struct tms timebuf; timebuf.tms_utime = 0; /* be sure to init in case failure */ times( &timebuf ); /* get process times */ /* CLK_TCK is clock ticks/second: * # of seconds = tms_utime / CLK_TCK * # of milliseconds = tms_utime * 1000 / CLK_TCK * * To avoid overflow, use * # of milliseconds = tms_utime * (1000/10) / (CLK_TCK / 10) */ SET_IA( (timebuf.tms_utime * (1000/10)) / (CLK_TCK/10) ); #endif return NORMAL_RETURN; }
uint8_t localTimeSecFrac() { uint64_t millisec = msec(); millisec = millisec / 100; // 1/10th seconds millisec = millisec % 10; return millisec; }
int nrand(int n) { if(randn == 0) seedrand(); randn = randn*1103515245 + 12345 + msec(); return (randn>>16) % n; }
THREAD_RET particles_thread(void *arg) { long tmr, lastRefresh; thread_s *t = (thread_s *) arg; lastRefresh = msec(); while(!stop) { tmr = msec(); loop_particles(t->from, t->to, (msec()-lastRefresh)/1000.0f); lastRefresh = msec(); tmr = msec() - tmr; if(tmr<30) SDL_Delay(30-tmr); } THREAD_EXIT; }
inline BTime dateTimeToBTime(QDateTime dateTime) { auto date = dateTime.date(); auto time = dateTime.time(); BTime btime; btime.year = date.year(); btime.day = date.dayOfYear(); btime.hour = time.hour(); btime.min = time.minute(); btime.sec = time.second(); btime.fract = time.msec(); return btime; }
int lookupscore(u8int score[VtScoreSize], int type, IAddr *ia) { int ms, ret; IEntry d; if(icachelookup(score, type, ia) >= 0){ addstat(StatIcacheRead, 1); return 0; } ms = msec(); addstat(StatIcacheFill, 1); if(loadientry(mainindex, score, type, &d) < 0) ret = -1; else{ ret = 0; insertscore(score, &d.ia, IEClean, nil); *ia = d.ia; } addstat2(StatIcacheRead, 1, StatIcacheReadTime, msec() - ms); return ret; }
std::string RealTime::toText(bool fixedDp) const { if (*this < RealTime::zeroTime) return "-" + (-*this).toText(); std::stringstream out; if (sec >= 3600) { out << (sec / 3600) << ":"; } if (sec >= 60) { out << (sec % 3600) / 60 << ":"; } if (sec >= 10) { out << ((sec % 60) / 10); } out << (sec % 10); int ms = msec(); if (ms != 0) { out << "."; out << (ms / 100); ms = ms % 100; if (ms != 0) { out << (ms / 10); ms = ms % 10; } else if (fixedDp) { out << "0"; } if (ms != 0) { out << ms; } else if (fixedDp) { out << "0"; } } else if (fixedDp) { out << ".000"; } #if (__GNUC__ < 3) out << std::ends; #endif std::string s = out.str(); return s; }
ulong procalarm(ulong time) { Proc **l, *f; ulong when, old, now; now = msec(); if(up->alarm) old = up->alarm - now; else old = 0; if(time == 0) { up->alarm = 0; return old; } when = time+now; qlock(&alarms.lk); l = &alarms.head; for(f = *l; f; f = f->palarm) { if(up == f){ *l = f->palarm; break; } l = &f->palarm; } up->palarm = 0; if(alarms.head) { l = &alarms.head; for(f = *l; f; f = f->palarm) { if(f->alarm > when) { up->palarm = f; *l = up; goto done; } l = &f->palarm; } *l = up; } else alarms.head = up; done: up->alarm = when; setalarm(); qunlock(&alarms.lk); return old; }
void MumbleClient::HandlePing(const MumbleProto::Ping& ping) { m_tcpPingCount++; if (ping.has_timestamp()) { // time delta auto timeDelta = msec().count() - ping.timestamp(); // which ping this is in the history list size_t thisPing = m_tcpPingCount - 1; // move pings down if (thisPing >= _countof(m_tcpPings)) { for (size_t i = 1; i < _countof(m_tcpPings); i++) { m_tcpPings[i - 1] = m_tcpPings[i]; } thisPing = _countof(m_tcpPings) - 1; } // store this ping m_tcpPings[thisPing] = timeDelta; // calculate average uint32_t avgCount = 0; for (size_t i = 0; i < thisPing; i++) { avgCount += m_tcpPings[i]; } m_tcpPingAverage = avgCount / float(thisPing + 1); // calculate variance float varianceCount = 0; for (size_t i = 0; i < thisPing; i++) { auto var = float(m_tcpPings[i]) - m_tcpPingAverage; varianceCount += var; } m_tcpPingVariance = varianceCount / (thisPing + 1); } }
std::string RealTime::toText(bool fixedDp) const { if (*this < RealTime::zeroTime) return "-" + (-*this).toText(); std::stringstream out; if (sec >= 3600) { out << (sec / 3600) << ":"; } if (sec >= 60) { int minutes = (sec % 3600) / 60; if (sec >= 3600 && minutes < 10) out << "0"; out << minutes << ":"; } if (sec >= 10) { out << ((sec % 60) / 10); } out << (sec % 10); int ms = msec(); if (ms != 0) { out << "."; out << (ms / 100); ms = ms % 100; if (ms != 0) { out << (ms / 10); ms = ms % 10; } else if (fixedDp) { out << "0"; } if (ms != 0) { out << ms; } else if (fixedDp) { out << "0"; } } else if (fixedDp) { out << ".000"; } std::string s = out.str(); return s; }
void NLog::run() { unsigned long this_diff = 0; unsigned long this_count = 0; while ( active_ ) { list_head buf_list; INIT_LIST_HEAD( &buf_list ); int ret = get_write_buffer_list( buf_list ); if( ret == 0 ) { this_diff = msec(); BufferNode *buffer = NULL; while( !list_empty( &buf_list ) ) { list_head *pos = buf_list.next; list_del( pos ); buffer = list_entry( pos, BufferNode, link_ ); if( !buffer ) { ERR(2)("[LOG] err!!! run invalid buffer ..."); continue; } this_count++; switch ( buffer->type ) { // 控制台模式,所有的log都显示在终端 // 可以配置显示颜色 if( buffer->type == LOG_TYPE_ERROR && !daemon_mode_ ) { FILE *file = log_[buffer->type]; /* 红色 */ char head[] = "\e[31m\e[1m"; char tail[] = "\e[0m"; fwrite( head, strlen(head), sizeof(char), file ); fwrite( buffer->buff, buffer->len, sizeof(char), file ); fwrite( tail, strlen(tail), sizeof(char), file ); fflush( file ); } else { FILE *file = log_[buffer->type]; fwrite( buffer->buff, buffer->len, sizeof(char), file ); fflush( file ); } } delete_buffer( buffer ); }
static void setalarm(void) { Proc *p; ulong now; now = msec(); if(alarmtimer.tt) timerdel(&alarmtimer); while((p = alarms.head) && p->alarm == 0) alarms.head = p->palarm; if(p == nil) return; alarmtimer.tf = soundalarms; alarmtimer.tmode = Trelative; alarmtimer.tns = (p->alarm - now)*1000000LL; timeradd(&alarmtimer); }
/// Blocks until the latch has counted down to zero or hit no. of msecs, whichever comes first . int Cdl::wait() { boost::unique_lock<boost::mutex> lock( mutex ); boost::chrono::milliseconds msec(500); boost::cv_status res; //while ( count > 0 ) //{ res = cond_var.wait_for(lock, msec); if (res == boost::cv_status::timeout) return 0; //time expired else if (count == 0) return 1; //countdown hit zero else return -1; // countdown did not hit zero, and interval not up! //} //return 1; //countdown hit zero }
NLog::NLog( int _buf_max ) { buf_count_ = 0; last_tick_ = msec(); time_len_ = 0; bzero( time_str_, sizeof( time_str_ ) ); bzero( time_file_name_, sizeof( time_file_name_ ) ); pthread_mutexattr_t ma; pthread_mutexattr_init( &ma ); pthread_mutexattr_settype( &ma, PTHREAD_MUTEX_RECURSIVE ); pthread_mutex_init(&mutex_, &ma); pthread_mutexattr_destroy( &ma ); pthread_mutexattr_init( &ma ); pthread_mutexattr_settype( &ma, PTHREAD_MUTEX_RECURSIVE ); pthread_mutex_init(&buf_count_mtx_, &ma); pthread_mutexattr_destroy( &ma ); olog_fn_ = 0; olog_ln_ = 0; daemon_mode_ = 0; bzero( log_path_, sizeof( log_path_ ) ); bzero( event_log_path_, sizeof( event_log_path_ ) ); bzero( log_, sizeof( log_ ) ); last_mod_min_ = -1; switch_flag_ = 0; INIT_LIST_HEAD( &write_list_ ); INIT_LIST_HEAD( &free_list_ ); buf_mem_ = new BufferNode[_buf_max]; buf_max_ = _buf_max; buf_new_ = 0; for ( int i = 0; i < _buf_max; ++i ){ list_add_tail( &(buf_mem_[i].link_), &free_list_ ); } process_timer(); }
void activatetab(const u16 tab) { if (g->tabs[g->curtab].web && g->curtab != tab) { g->tabs[g->curtab].web->hide(); saveurlbar(); } g->curtab = tab; g->tabs[g->curtab].lastactive = msec(); if (g->tabs[g->curtab].web) g->tabs[g->curtab].web->show(); windowtitle(); searchenginestate(); urlbarstate(); g->status->hidefind(); g->status->refreshzoom(); g->w->redraw(); if (g->tabs[g->curtab].state == TS_WEB && g->tabs[g->curtab].web) g->tabs[g->curtab].web->take_focus(); }
static void soundalarms(Ureg *u, Timer *t) { ulong now; Proc *rp; now = msec(); qlock(&alarms.lk); while((rp = alarms.head) && rp->alarm <= now){ if(rp->alarm != 0){ if(!canqlock(&rp->debug)) break; if(!waserror()){ postnote(rp, 0, "alarm", NUser); poperror(); } qunlock(&rp->debug); rp->alarm = 0; } alarms.head = rp->palarm; } setalarm(); qunlock(&alarms.lk); }
static double usec() { return msec() / 1000; }
fwrite( head, strlen(head), sizeof(char), file ); fwrite( buffer->buff, buffer->len, sizeof(char), file ); fwrite( tail, strlen(tail), sizeof(char), file ); fflush( file ); } else { FILE *file = log_[buffer->type]; fwrite( buffer->buff, buffer->len, sizeof(char), file ); fflush( file ); } } delete_buffer( buffer ); } /*! 写日志部分 */ unsigned long now = msec(); this_diff = now - this_diff; if( now - last_tick_ > THREAD_LOG_PER_MS ) { pthread_mutex_lock( &buf_count_mtx_ ); unsigned long tmp_count = buf_count_; pthread_mutex_unlock( &buf_count_mtx_ ); write_tick( "[LOGBUFFER] process count = %ld use time = %ld left_num = %ld", this_count, this_diff, tmp_count ); last_tick_ = now; } } if ( active_ == false ){ break; }
bool WTime::writeSpecial(const std::string& f, unsigned& i, std::stringstream& result, bool useAMPM) const { char buf[30]; switch (f[i]) { case 'h': if (f[i + 1] == 'h') { ++i; result << Utils::pad_itoa(useAMPM ? pmhour() : hour(), 2, buf); } else result << Utils::itoa(useAMPM ? pmhour() : hour(), buf); return true; case 'H': if (f[i + 1] == 'H') { ++i; result << Utils::pad_itoa(hour(), 2, buf); } else result << Utils::itoa(hour(), buf); return true; case 'm': if (f[i + 1] == 'm') { ++i; result << Utils::pad_itoa(minute(), 2, buf); } else result << Utils::itoa(minute(), buf); return true; case 's': if (f[i + 1] == 's') { ++i; result << Utils::pad_itoa(second(), 2, buf); } else result << Utils::itoa(second(), buf); return true; case 'z': if (f.substr(i + 1, 2) == "zz") { i += 2; result << Utils::pad_itoa(msec(), 3, buf); } else result << Utils::itoa(msec(), buf); return true; case 'a': case 'A': if (f[i + 1] == 'p' || f[i + 1] == 'P') ++i; if (hour() < 12) result << ((f[i] == 'a') ? "am" : "AM"); else result << ((f[i] == 'p') ? "pm" : "PM"); return true; default: return false; } }
int main (int argc, char ** argv) { u8 ** board[2]; u32 numberOfSamples = NUMBEROFSAMPLES; u32 numberOfChannels = NUMBEROFCHANNELS; u32 samplePeriodDivisor = SAMPLEPERIODDIVISOR; tBoolean continuous = kTrue; int fd, fd2, ic; struct timeval origin, before, after[8]; opterr = 0; char c; int opt_D=0, opt_o=0, D=0, opt_F=0, opt_T=0, opt_r=80; int opt_e=0, opt_I=0, opt_b=-1, opt_B=-1, opt_i=0, adc_range=0; int opt_M=0, opt_R=0, opt_at=0, opt_p=1; i32 value[8]; f32 scaled; i32 rescaled; u32 n = 0; int j; FILE * param, * calibr[2]={NULL,NULL}; int cadence; struct dma_channel dma; static struct scale_table adc_scale, dac_scale[2][2]; int scan_fd; dma.status = DMA_IDLE; printf("niconf - starting ...\n"); /* * get some setup values */ param = fopen(CHANNELS, "r"); if (!param || fscanf (param, "%d", &numberOfChannels) != 1) { printf ("niconf: could not get channels value\n"); exit (-1); } while ((c = getopt (argc, argv, "c:d:r:p:s:x:ItiDoeMRFTb:B:vh")) != -1) switch (c) { case 'c': if (optarg) numberOfChannels = atoi(optarg); break; case 'd': if (optarg) samplePeriodDivisor = atoi(optarg); break; case 'r': if (optarg) opt_r = atoi(optarg); break; case 'I': if (opt_i) { printf ("%s - the interrupt system will not " "be enabled\n", NAM); exit (-1); } opt_I = 1; break; case 't': opt_at = 1; break; case 'i': if (opt_I) { printf ("%s - the interrupt system will " "not be enabled\n", NAM); exit (-1); } opt_i = 1; break; case 'D': opt_D = 1; break; case 'o': opt_o = 1; break; case 's': if (optarg) numberOfSamples = atoi(optarg); break; case 'p': if (optarg) opt_p = atoi(optarg); break; case 'x': if (optarg) adc_range = atoi(optarg); break; case 'e': opt_e = 1; break; case 'M': opt_M = 1; break; case 'R': opt_R = 1; break; case 'F': opt_F = 1; break; case 'T': opt_T = 1; break; case 'b': opt_b = strtol(optarg, NULL, 0); break; case 'B': opt_B = strtol(optarg, NULL, 0); break; case 'v': D += 1; break; case 'h': default: if (c != 'h') { fprintf (stderr, "### Unknown option: -%c.\n", optopt); fprintf (stderr, display); exit (-1); } fprintf (stderr, display); exit (0); } /* * We need get a lock on /dev/spm/scan so nobody can * modify irq parameters during board configuration. * The lock will be released when niconf exits. */ scan_fd = open("/dev/spm/scan", O_RDWR | O_NONBLOCK); if (scan_fd < 0) { printf ("niconf: could not obtain lock on scan: %d\n", scan_fd); exit (-1); } /* * find and activate the board */ board[0] = acquire_board("/dev/spm/nibac0", D, &fd); if (board[0]) { printf ("%s - Found master board as nibac0\n", NAM); dma.fd = fd; dma.memap[0] = board[0][2] + DMA_CHANNEL_1; dma.memap[1] = board[0][3] + DMA_CHANNEL_1; if (D>1) { printf ("%s - board mapped at: %p %p %p %p %p\n", NAM, board[0][0], board[0][1], board[0][2], board[0][3], board[0][4]); } } board[1] = acquire_board("/dev/spm/nibac1", D, &fd2); if (board[1]) { printf ("%s - Found slave board as nibac1\n", NAM); if (D>1) { printf ("%s - board mapped at: %p %p %p %p %p\n", NAM, board[1][0], board[1][1], board[1][2], board[1][3], board[1][4]); } } if (board[0] == 0 && board[1] == 0) exit (-1); /* * configure the board */ if (opt_F || opt_I) { /* * Master board configuration */ if (board[0]) { /* disable all board interrupts */ write32(board[0][2], 0x10, 0x40150000); /* stop DMA operation */ NIBIT (dma.memap, ChannelOperation, write, Stop, 1); gettimeofday(&before, NULL); while (NIBIT(dma.memap, ChannelStatus, read, DmaDone) != 1) { gettimeofday(&origin, NULL); if (usec(&origin, &before) > 100000) { printf ("Could not get DMA stopped\n"); exit (-1); } } NIREG (board[0], Interrupt_A_Enable,write, 0); NIBIT (board[0], G0_DMA_Config, set, G0_DMA_Enable, 0); NIBIT (board[0], G0_DMA_Config, write, G0_DMA_Int_Enable, 0); /* disarm board and reset DMA */ ai_disarm (board[0]); NIBIT (dma.memap, ChannelOperation, write, Stop, 1); dma.state = DMA_STOPPED; NIBIT (board[0], AI_AO_Select,set,AI_DMA_Select,0); NIREG (board[0], AI_AO_Select, flush); /* Analog Input reset and configure */ board_reset(board[0]); configure_timebase (board[0]); pll_reset (board[0]); analog_trigger_reset (board[0]); ai_reset (board[0]); if (D) printf ("%s - reset and configure completed\n", NAM); /* setup for adc input */ ai_personalize (board[0], _kAI_CONVERT_Output_SelectActive_High); ai_clear_fifo (board[0]); ai_disarm (board[0]); ai_clear_configuration_memory (board[0]); u32 i; for (i = 0; i < numberOfChannels; i++) { ai_configure_channel (board[0], i, /* channel number */ adc_range, /* gain */ _kAI_Config_PolarityBipolar, _kAI_Config_Channel_TypeDifferential, /* last channel? */ (i == numberOfChannels-1)? kTrue:kFalse); } ai_set_fifo_request_mode (board[0]); ai_environmentalize (board[0]); ai_hardware_gating (board[0]); ai_trigger (board[0], _kAI_START1_SelectPulse, _kAI_START1_PolarityRising_Edge, _kAI_START2_SelectPulse, _kAI_START2_PolarityRising_Edge); ai_sample_stop (board[0], (numberOfChannels > 1)? kTrue:kFalse); /* multi channel? */ if (!opt_e) continuous = kFalse; ai_number_of_samples (board[0], numberOfSamples, /* postrigger samples */ 0, /* pretrigger samples */ continuous); /* continuous? */ param = fopen( "/sys/module/spm_dev/parameters/cadence_usec", "r"); if (param) { if (fscanf (param, "%d", &cadence) != 1) cadence = 0; fclose (param); if (cadence) { samplePeriodDivisor = cadence * 20; if (D) printf ( "%s - using divisor %d -> %d" "usec from cadence_usec\n", NAM, samplePeriodDivisor, cadence); } } else { if (D) printf ( "%s - using divisor %d -> %d usec\n", NAM, samplePeriodDivisor, samplePeriodDivisor/20); } ai_sample_start ( board[0], samplePeriodDivisor, /* period divisor */ samplePeriodDivisor, /* 3 , delay divisor */ _kAI_START_SelectSI_TC, _kAI_START_PolarityRising_Edge); ai_convert ( board[0], opt_r, /* 280 */ // convert period divisor 3, // convert delay divisor kFalse); // external sample clock? ai_clear_fifo (board[0]); if (D) printf ("%s - adc setup completed\n", NAM); } /* * read calibration data and configure DAC and digital lines * on both boards */ for ( j=0 ; j<2 ; j++ ) { if (board[j] == 0) continue; /* * read eeprom for calibration information */ u32 eeprom_size = 1024; eeprom_read_MSeries (board[j], board[j][4], eeprom_size); if (D>=2) { printf ("\n%s - %s\n\n", NAM, "Calibration memory content"); dump_memory (board[j][4], eeprom_size); } if (D) printf ("%s - eeprom reading completed\n", NAM); /* * analog output reset */ ao_reset (board[j]); ao_personalize (board[j]); ao_reset_waveform_channels (board[j]); ao_clear_fifo (board[j]); /* * unground AO reference */ NIBIT(board[j],AO_Calibration,write, AO_RefGround,kFalse); /* * analog output configure */ ao_configure_dac (board[j], 0, 0xF, _kAO_DAC_PolarityBipolar, _kAO_Update_ModeImmediate); ao_configure_dac (board[j], 1, 0xF, _kAO_DAC_PolarityBipolar, _kAO_Update_ModeImmediate); if (D) printf ("%s - DAC configuration completed " "on board %d at %p\n", NAM, j, board[j]); /* * configure digital IO */ NIREG (board[j], DIO_Direction, write, 0xff); } } /* * configure DMA */ if (opt_R) { param = fopen(DMA_USE, "r"); if (!param || fscanf (param, "%d", &opt_M) != 1) { printf ("niconf: could not get dma_use value\n"); exit (-1); } fclose (param); printf ("Keeping DMA channel to state: %d\n", opt_M); param = fopen(SAMPLES_PP, "r"); if (!param || fscanf (param, "%d", &opt_p) != 1) { printf ("niconf: could not get samples value\n"); exit (-1); } fclose (param); printf ("Keeping samples to value: %d\n", opt_p); } if (board[0]) { if (opt_I && opt_M) { printf ("%s - starting DMA configuration\n", NAM); NIBIT (board[0], AI_AO_Select,set,AI_DMA_Select,1); NIREG (board[0], AI_AO_Select, flush); dma.mode = DMA_RING; dma.direction = DMA_IN; dma.drq = 0; dma.size = 2 * numberOfChannels * opt_p; if (dma.size > 4095) { printf ("niconf: huge DMA buffer! " "Please, reduce!\n"); exit (-1); } dma.transfer_width = DMA_16_BIT; /* read from module parameters the physical address of dma buffer */ param = fopen(PHYSICAL_ADDRESS, "r"); if (!param || fscanf (param, "%u", (u32 *) &dma.physical_address) != 1) { printf ("niconf: dma address not available\n"); exit (-1); } fclose (param); dma_configure (&dma); NIBIT (dma.memap, ChannelOperation, write, Start, 1); dma.state = DMA_STARTED; printf ("%s - dma configuration complete\n", NAM); } else if (opt_I || opt_F) { /* deactivate DMA */ NIBIT (dma.memap, ChannelOperation, write, Stop, 1); dma.state = DMA_STOPPED; NIBIT (board[0], AI_AO_Select,set,AI_DMA_Select,0); NIREG (board[0], AI_AO_Select, flush); } } /* * set dma_use flag in module parameters */ if (opt_I || opt_F) { param = fopen(DMA_USE, "w"); if (!param || fprintf (param, "%c\n", opt_M ? '1' : '0') != 2) { printf ("niconf: could not set dma_use flag\n"); exit (-1); } fclose (param); } /* * activate the interrupt system */ if (opt_I && board[0]) { printf ("%s - Activating the interrupt system\n", NAM); /* enable Mite interrupt IO=1 */ write32(board[0][2], 0x08, 0x01000000); if (opt_M) { /* enable board and DMA interrupt */ write32(board[0][2], 0x10, 0x80020000); // NIBIT (board[0], G0_DMA_Config, set, G0_DMA_Enable, 1); // NIBIT (board[0], G0_DMA_Config, write, // G0_DMA_Int_Enable, 1); } else { /* enable board interrupt */ write32(board[0][2], 0x10, 0x80000000); NIBIT (board[0], Interrupt_Control, write, Interrupt_Group_A_Enable, 1); NIBIT (board[0], Interrupt_A_Enable,write, AI_STOP_Interrupt_Enable, 1); NIREG (board[0], Interrupt_B_Enable,write, 0); } if (D) printf ("%s - interrupt activation " "completed\n", NAM); } /* * read ADC and DAC scale coefficients * */ if (board[0]) { calibr[0] = fopen("/tmp/spm.calibration.master", "w"); if (!calibr[0]) { printf ("niconf: could not open %s\n", "spm.calibration.master"); exit (-1); } ai_get_scaling_coefficients (board[0][4], adc_range == 4 ? 3 : adc_range, 0, 0, &adc_scale); fprintf (calibr[0], "ADC nibac %d %g %g %g %g\n", adc_scale.order, adc_scale.c[0],adc_scale.c[1], adc_scale.c[2],adc_scale.c[3]); if (D>1) printf ( "%s - adc scaling coefficients: %d %g %g %g %g\n", NAM, adc_scale.order, adc_scale.c[0],adc_scale.c[1], adc_scale.c[2],adc_scale.c[3]); } for ( j=0 ; j<2 ; j++ ) { if (D>1) printf ("%s - DAC scale for board %d: %p\n", NAM, j, board[j]); if (board[j] == 0) continue; if (j == 1) { calibr[1] = fopen("/tmp/spm.calibration.slave", "w"); if (!calibr[1]) { printf ("niconf: could not open %s\n", "spm.calibration.slave"); exit (-1); } } ao_get_scaling_coefficients (board[j][4], 0, 0, 0, &dac_scale[j][0]); ao_get_scaling_coefficients (board[j][4], 0, 0, 1, &dac_scale[j][1]); fprintf (calibr[j], "DAC nibac %d %g %g %g %g\n", dac_scale[j][0].order, dac_scale[j][0].c[0], dac_scale[j][0].c[1], dac_scale[j][0].c[2], dac_scale[j][0].c[3]); fprintf (calibr[j], "DAC nibac %d %g %g %g %g\n", dac_scale[j][1].order, dac_scale[j][1].c[0], dac_scale[j][1].c[1], dac_scale[j][1].c[2], dac_scale[j][1].c[3]); printf ("%s - dac 0 scaling coefficients: %d %g %g\n", NAM, dac_scale[j][0].order, dac_scale[j][0].c[0], dac_scale[j][0].c[1]); printf ("%s - dac 1 scaling coefficients: %d %g %g\n", NAM, dac_scale[j][1].order, dac_scale[j][1].c[0], dac_scale[j][1].c[1]); } if (D>1) printf ("%s - scale coefficients completed\n", NAM); if (calibr[0]) fclose (calibr[0]); if (calibr[1]) fclose (calibr[1]); /* * * put out bits to digital lines * */ if (opt_b >= 0 ) { if (board[0]) { NIREG (board[0], Static_Digital_Output, write, (u8) 0xff & opt_b); printf ("%s - wrote digital output: 0x%x\n", NAM, NIREG (board[0], Static_Digital_Input, read)); } else { printf ("%s - %s\n", NAM, "sorry, '-b' option requires a master board"); } } if (opt_B >= 0) { if (board[1]) { NIREG (board[1], Static_Digital_Output, write, (u8) 0xff & opt_b); printf ("%s - wrote digital output: 0x%x\n", NAM, NIREG (board[1], Static_Digital_Input, read)); } else { printf ("%s - %s\n", NAM, "sorry, '-B' option requires a second board"); } } /* * all done - arm and start the board */ if (opt_at && board[0]) { ai_arm (board[0], kTrue); ai_start (board[0]); } /* * * read adc data from board * */ if (opt_i && board[0]) { /* read data polling fifo */ printf ("%s - going to read ADC from user space\n", NAM); /* disable the board interrupt */ write32(board[0][2], 0x10, 0x40000000); usleep (100); if (opt_o) printf ("\n"); gettimeofday(&origin, NULL); before = origin; while (opt_e || !numberOfSamples || (n < numberOfChannels*numberOfSamples)) { for ( ic=0 ; ic<numberOfChannels ; ic++ ) { while (NIBIT(board[0],AI_Status_1,read, AI_FIFO_Empty_St)) {} gettimeofday(after+ic, NULL); value[ic] = NIREG(board[0],AI_FIFO_Data,read); } if (!opt_o) printf ("\n"); printf ("\r%4d %6.3f %8ld ", n/numberOfChannels, msec(&after[0], &origin)/1000., usec(after, &before)); for ( ic=0 ; ic<numberOfChannels ; ic++ ) { ai_polynomial_scaler (value+ic, &scaled, &adc_scale); if (opt_T && ic) printf ("%6ld", usec(after+ic, after+ic-1)); printf ("%9.3f", scaled); if (opt_D && ic < 2) { /* loop to DAC */ ao_linear_scaler (&rescaled, &scaled, &dac_scale[0][ic]); NIREG(board[0], DAC_Direct_Data, ic, write,(*( value+ic))/2); } n++; fflush(NULL); } before = after[0]; } printf ("\n\n"); } close (scan_fd); return 0; }
int writeqlump(Lump *u, Packet *p, int creator, uint ms) { ZBlock *flat; Packet *old; IAddr ia; int ok; if(lookupscore(u->score, u->type, &ia) == 0){ if(verifywrites == 0){ /* assume the data is here! */ packetfree(p); ms = msec() - ms; addstat2(StatRpcWriteOld, 1, StatRpcWriteOldTime, ms); return 0; } /* * if the read fails, * assume it was corrupted data and store the block again */ old = readilump(u, &ia, u->score); if(old != nil){ ok = 0; if(packetcmp(p, old) != 0){ uchar nscore[VtScoreSize]; packetsha1(old, nscore); if(scorecmp(u->score, nscore) != 0) seterr(EStrange, "readilump returned bad data %V not %V", nscore, u->score); else seterr(EStrange, "score collision %V", u->score); ok = -1; } packetfree(p); packetfree(old); ms = msec() - ms; addstat2(StatRpcWriteOld, 1, StatRpcWriteOldTime, ms); return ok; } logerr(EAdmin, "writelump: read %V failed, rewriting: %r\n", u->score); } flat = packet2zblock(p, packetsize(p)); ok = storeclump(mainindex, flat, u->score, u->type, creator, &ia); freezblock(flat); if(ok == 0) insertlump(u, p); else packetfree(p); if(syncwrites){ flushdcache(); flushicache(); flushdcache(); } ms = msec() - ms; addstat2(StatRpcWriteNew, 1, StatRpcWriteNewTime, ms); return ok; }
int main(int argc, char *argv[]) { struct timeval start, end; time_t when; int ch, i, qflag, dflag, r; uint16_t type = T_A; char buf[1024], *host; dflag = 0; qflag = 0; while((ch = getopt(argc, argv, "deqt:")) != -1) { switch(ch) { case 'd': dflag = 1; break; case 'e': long_err += 1; break; case 'q': qflag = 1; break; case 't': if ((type = strtotype(optarg)) == 0) usage(); break; default: usage(); /* NOTREACHED */ } } argc -= optind; argv += optind; for (i = 0; i < argc; i++) { if (i) printf("\n"); printf("===> \"%s\"\n", argv[i]); host = gethostarg(argv[i]); errno = 0; h_errno = 0; gai_errno = 0; rrset_errno = 0; if (gettimeofday(&start, NULL) != 0) err(1, "gettimeofday"); if (qflag) r = res_query(host, C_IN, type, buf, sizeof(buf)); else r = res_search(host, C_IN, type, buf, sizeof(buf)); if (gettimeofday(&end, NULL) != 0) err(1, "gettimeofday"); if (r != -1) { dump_packet(buf, r); printf("\n"); if (dflag) { printf(";; Query time: %d msec\n", msec(start, end)); when = time(NULL); printf(";; WHEN: %s", ctime(&when)); } printf(";; MSG SIZE rcvd: %i\n", r); } print_errors(); } return (0); }
void write_test(char *dev, unsigned int blocks, int blocksize, int repeats) { int fd; int size; char buffer[blocksize]; unsigned int towrite; unsigned int start_time; unsigned int end_time; unsigned int time_taken; int i; float bps; for(size=0; size<blocksize; size++) { buffer[size]=size; } fd = open(dev,O_RDWR); if(!fd) { printf("Error: unable to open %s for writing.\n",dev); exit(10); } size = numblocks(fd); if(size==0) { printf("Error: unable to get media size.\n"); close(fd); exit(0); } if(blocks>size) { printf("More blocks requested than media size. Reducing.\n"); blocks = size; } if(blocks==0) { blocks=size; } printf("Testing write of %s from 0 to %d with %d byte blocks...\n", dev,blocks-1,blocksize); start_time = msec(); for(i=0; i<repeats; i++) { lseek(fd,0,SEEK_SET); towrite = blocks * 1024; while(towrite > 0) { if(towrite>blocksize) { towrite -= write(fd,buffer,blocksize); } else { towrite -= write(fd,buffer,towrite); } } } end_time = msec(); close(fd); time_taken = end_time - start_time; bps = (float)((blocks*repeats) * 1024) / ((float)time_taken / 1000.0); printf("Time taken: %f seconds. Speed: %f KBytes/second\n", time_taken / 1000.0, bps/1024.0); }
void MultiShot::setShotSeq() { shotSeq->shot = 0; if( tabWidget->currentIndex() == 0 ) { /* * Exposure bracketing. */ int mode = camera->getShootingMode(); if( mode == kEdsAEMode_Manual ) { shotSeq->type = ShotSeq::ExposureBracketingManual; setShutterSpeeds(); } else { shotSeq->type = ShotSeq::ExposureBracketingAv; setCompensations(); } shotSeq->frames = 2 * eFrames->value() + 1; shotSeq->delay = 0; shotSeq->bulbMode = false; } else if( tabWidget->currentIndex() == 1 ) { /* * Focus bracketing. */ shotSeq->type = ShotSeq::FocusBracketing; shotSeq->frames = fFrames->value(); shotSeq->delay = 0; shotSeq->bulbMode = false; int index = fStep->currentIndex(); int step = fStep->itemData( index ).toInt(); shotSeq->bracket[0] = 0; for( int i = 1; i < shotSeq->frames; i++ ) { shotSeq->bracket[i] = step; } } else if( tabWidget->currentIndex() == 2 ) { /* * Interval. */ shotSeq->type = ShotSeq::Interval; shotSeq->frames = iFrames->value(); shotSeq->delay = msec( iDelay->time() ); shotSeq->interval = msec( iInterval->time() ); if( camera->shutterInBulbMode() ) { shotSeq->bulbMode = true; shotSeq->shutter = msec( iBulb->time() ); if( shotSeq->interval < shotSeq->shutter ) { shotSeq->interval = shotSeq->shutter; } } else { shotSeq->bulbMode = false; shotSeq->shutter = Map::toShutterSpeed( camera->getTv() ); } if( shotSeq->interval < shotSeq->shutter ) { shotSeq->interval = 0; // shoot as fast as possible } } // interval else { /* * Stitch. */ shotSeq->type = ShotSeq::Stitch; shotSeq->frames = columns->value() * rows->value(); shotSeq->delay = 0; shotSeq->bulbMode = false; } // stitch }