13 #include <mach/mach_time.h>
14 #include <CoreServices/CoreServices.h>
15 static int64_t s_PerformanceFrequency;
16 static bool s_bPerformanceInit =
false;
20 #if defined(MSWindows)
21 static LARGE_INTEGER s_PerformanceFrequency;
22 static bool s_bPerformanceInit =
false;
25 #if defined(AJALinux) || defined(AJA_LINUX)
27 #if (_POSIX_TIMERS > 0)
28 #ifdef _POSIX_MONOTONIC_CLOCK
29 #define AJA_USE_CLOCK_GETTIME
31 #undef AJA_USE_CLOCK_GETTIME
35 #ifdef AJA_USE_CLOCK_GETTIME
49 memset(rxBuf,0,
sizeof(rxBuf));
62 int byte_len = (int)strlen((
char*)
txBuf);
63 int word_len = ((byte_len + 4) - (byte_len %4))/4;
85 uint32_t * pBuf =
txBuf;
86 for (
int i = 0; i < word_len; i++)
104 uint32_t * pBuf = (uint32_t*)rxBuf;
105 memset(rxBuf,0,
sizeof(rxBuf));
126 if (seqNum == currentSeqNum())
152 for (uint32_t i=0; i<count; i++)
187 while (SOM != 0xffffffff)
189 bool rv =
readMB(SOM,timeout);
209 if (getElapsedTime() > timeout)
222 if (getElapsedTime() > timeout)
253 chanOffset = channelOffset;
254 chanNumber = channelNumber;
303 response.assign((
char*)rxBuf);
306 void CNTV2MailBox::startTimer()
308 _startTime = getSystemMilliseconds();
311 uint64_t CNTV2MailBox::getElapsedTime()
313 return (getSystemMilliseconds() - _startTime);
316 int64_t CNTV2MailBox::getSystemCounter()
318 #if defined(MSWindows)
319 LARGE_INTEGER performanceCounter;
321 performanceCounter.QuadPart = 0;
322 if (!QueryPerformanceCounter(&performanceCounter))
327 return (int64_t)performanceCounter.QuadPart;
331 return (int64_t) mach_absolute_time();
334 #if defined(AJALinux) || defined(AJA_LINUX)
335 #ifdef AJA_USE_CLOCK_GETTIME
338 return (ts.tv_sec * ((int64_t)1000000)) + (ts.tv_nsec / (int64_t)1000);
343 gettimeofday( &tv, &tz );
344 return (int64_t)((int64_t)tv.tv_sec * (int64_t)1000000 + tv.tv_usec);
350 int64_t CNTV2MailBox::getSystemFrequency()
352 #if defined(MSWindows)
353 if (!s_bPerformanceInit)
355 QueryPerformanceFrequency(&s_PerformanceFrequency);
356 s_bPerformanceInit =
true;
359 return (int64_t)s_PerformanceFrequency.QuadPart;
363 if (!s_bPerformanceInit)
366 static mach_timebase_info_data_t sTimebaseInfo;
367 uint64_t ticks = 1000000000;
369 if ( sTimebaseInfo.denom == 0 )
371 (
void) mach_timebase_info(&sTimebaseInfo);
376 int64_t nanoSeconds = ticks * sTimebaseInfo.numer / sTimebaseInfo.denom;
379 s_PerformanceFrequency = ticks * 1000000000 / nanoSeconds;
380 s_bPerformanceInit =
true;
383 return s_PerformanceFrequency;
386 #if defined(AJALinux) || defined(AJA_LINUX)
391 uint64_t CNTV2MailBox::getSystemMilliseconds()
393 uint64_t ticks = getSystemCounter();
394 uint64_t ticksPerSecond = getSystemFrequency();
400 ms = uint64_t((
double(ticks) /
double(ticksPerSecond)) * 1000.);