aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/types
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2012-02-06 16:40:42 -0800
committerJosh Blum <josh@joshknows.com>2012-02-06 16:40:42 -0800
commit5eec31fab45649b529428cda756d04bcdaeb3134 (patch)
treef130af1d4c7cdacef74a4918a1d72d3f3facadec /host/lib/types
parent5c56ca574ffdf7ad469ab3a3f54def944a978bee (diff)
downloaduhd-5eec31fab45649b529428cda756d04bcdaeb3134.tar.gz
uhd-5eec31fab45649b529428cda756d04bcdaeb3134.tar.bz2
uhd-5eec31fab45649b529428cda756d04bcdaeb3134.zip
dsp rework: implement 64 bit ticks, no seconds
Diffstat (limited to 'host/lib/types')
-rw-r--r--host/lib/types/time_spec.cpp29
1 files changed, 14 insertions, 15 deletions
diff --git a/host/lib/types/time_spec.cpp b/host/lib/types/time_spec.cpp
index 8e540c14c..176ee8079 100644
--- a/host/lib/types/time_spec.cpp
+++ b/host/lib/types/time_spec.cpp
@@ -1,5 +1,5 @@
//
-// Copyright 2011 Ettus Research LLC
+// Copyright 2011-2012 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -16,6 +16,7 @@
//
#include <uhd/types/time_spec.hpp>
+#include <inttypes.h> //imaxdiv, intmax_t
using namespace uhd;
@@ -23,18 +24,6 @@ using namespace uhd;
* Time spec system time
**********************************************************************/
-/*!
- * Creates a time spec from system counts:
- * TODO make part of API as a static factory function
- * The counts type is 64 bits and will overflow the ticks type of long.
- * Therefore, divmod the counts into seconds + sub-second counts first.
- */
-#include <inttypes.h> //imaxdiv, intmax_t
-static UHD_INLINE time_spec_t time_spec_t_from_counts(intmax_t counts, intmax_t freq){
- imaxdiv_t divres = imaxdiv(counts, freq);
- return time_spec_t(time_t(divres.quot), double(divres.rem)/freq);
-}
-
#ifdef HAVE_CLOCK_GETTIME
#include <time.h>
time_spec_t time_spec_t::get_system_time(void){
@@ -49,7 +38,7 @@ time_spec_t time_spec_t::get_system_time(void){
time_spec_t time_spec_t::get_system_time(void){
mach_timebase_info_data_t info; mach_timebase_info(&info);
intmax_t nanosecs = mach_absolute_time()*info.numer/info.denom;
- return time_spec_t_from_counts(nanosecs, intmax_t(1e9));
+ return time_spec_t::from_ticks(nanosecs, intmax_t(1e9));
}
#endif /* HAVE_MACH_ABSOLUTE_TIME */
@@ -60,7 +49,7 @@ time_spec_t time_spec_t::get_system_time(void){
LARGE_INTEGER counts, freq;
QueryPerformanceCounter(&counts);
QueryPerformanceFrequency(&freq);
- return time_spec_t_from_counts(counts.QuadPart, freq.QuadPart);
+ return time_spec_t::from_ticks(counts.QuadPart, freq.QuadPart);
}
#endif /* HAVE_QUERY_PERFORMANCE_COUNTER */
@@ -104,6 +93,11 @@ time_spec_t::time_spec_t(time_t full_secs, long tick_count, double tick_rate){
time_spec_init(full_secs, frac_secs);
}
+time_spec_t time_spec_t::from_ticks(long long ticks, double tick_rate){
+ const imaxdiv_t divres = imaxdiv(ticks, tick_rate);
+ return time_spec_t(time_t(divres.quot), double(divres.rem)/tick_rate);
+}
+
/***********************************************************************
* Time spec accessors
**********************************************************************/
@@ -111,6 +105,11 @@ long time_spec_t::get_tick_count(double tick_rate) const{
return long(this->get_frac_secs()*tick_rate + 0.5);
}
+long long time_spec_t::to_ticks(double tick_rate) const{
+ return (long long)(this->get_frac_secs()*tick_rate + 0.5) + \
+ (long long)((this->get_full_secs()) * (long long)(tick_rate));
+}
+
double time_spec_t::get_real_secs(void) const{
return this->_full_secs + this->_frac_secs;
}