diff options
| author | Josh Blum <josh@joshknows.com> | 2012-02-09 17:59:48 -0800 | 
|---|---|---|
| committer | Josh Blum <josh@joshknows.com> | 2012-02-09 17:59:48 -0800 | 
| commit | 115100034071b3b58de1fce7c795995f6ee615a1 (patch) | |
| tree | 48909ad3435835d0ec70631faf252285368c8b41 | |
| parent | b6da2fe9af84663fa4dda923833e2319433b6f20 (diff) | |
| download | uhd-115100034071b3b58de1fce7c795995f6ee615a1.tar.gz uhd-115100034071b3b58de1fce7c795995f6ee615a1.tar.bz2 uhd-115100034071b3b58de1fce7c795995f6ee615a1.zip | |
uhd: various tweaks for compiler warns and valgrind
| -rw-r--r-- | host/examples/test_messages.cpp | 3 | ||||
| -rw-r--r-- | host/lib/types/time_spec.cpp | 14 | ||||
| -rw-r--r-- | host/lib/usrp/b100/io_impl.cpp | 2 | ||||
| -rw-r--r-- | host/lib/usrp/cores/rx_dsp_core_200.cpp | 2 | ||||
| -rw-r--r-- | host/lib/usrp/e100/io_impl.cpp | 2 | ||||
| -rw-r--r-- | host/lib/usrp/usrp1/soft_time_ctrl.cpp | 4 | ||||
| -rw-r--r-- | host/lib/usrp/usrp2/io_impl.cpp | 3 | ||||
| -rw-r--r-- | host/lib/usrp/usrp2/usrp2_iface.cpp | 13 | ||||
| -rw-r--r-- | host/tests/convert_test.cpp | 4 | 
9 files changed, 28 insertions, 19 deletions
| diff --git a/host/examples/test_messages.cpp b/host/examples/test_messages.cpp index f24a172d1..afb092092 100644 --- a/host/examples/test_messages.cpp +++ b/host/examples/test_messages.cpp @@ -26,6 +26,7 @@  #include <boost/bind.hpp>  #include <boost/format.hpp>  #include <cstdlib> +#include <ctime>  #include <complex>  #include <iostream> @@ -326,7 +327,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){      }      //run the tests, pick at random -    std::srand(uhd::time_spec_t::get_system_time().get_full_secs()); +    std::srand((unsigned int) time(NULL));      for (size_t n = 0; n < ntests; n++){          std::string key = tests.keys()[std::rand() % tests.size()];          bool pass = tests[key](usrp, rx_stream, tx_stream); diff --git a/host/lib/types/time_spec.cpp b/host/lib/types/time_spec.cpp index 176ee8079..0c3a3dbea 100644 --- a/host/lib/types/time_spec.cpp +++ b/host/lib/types/time_spec.cpp @@ -38,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_ticks(nanosecs, intmax_t(1e9)); +    return time_spec_t::from_ticks(nanosecs, 1e9);  }  #endif /* HAVE_MACH_ABSOLUTE_TIME */ @@ -80,6 +80,10 @@ time_spec_t time_spec_t::get_system_time(void){      } \  } +UHD_INLINE long long fast_llround(const double x){ +    return (long long)(x + 0.5); // assumption of non-negativity +} +  time_spec_t::time_spec_t(double secs){      time_spec_init(0, secs);  } @@ -94,7 +98,7 @@ time_spec_t::time_spec_t(time_t full_secs, long tick_count, double tick_rate){  }  time_spec_t time_spec_t::from_ticks(long long ticks, double tick_rate){ -    const imaxdiv_t divres = imaxdiv(ticks, tick_rate); +    const imaxdiv_t divres = imaxdiv(ticks, fast_llround(tick_rate));      return time_spec_t(time_t(divres.quot), double(divres.rem)/tick_rate);  } @@ -102,12 +106,12 @@ time_spec_t time_spec_t::from_ticks(long long ticks, double tick_rate){   * Time spec accessors   **********************************************************************/  long time_spec_t::get_tick_count(double tick_rate) const{ -    return long(this->get_frac_secs()*tick_rate + 0.5); +    return long(fast_llround(this->get_frac_secs()*tick_rate));  }  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)); +    return fast_llround(this->get_frac_secs()*tick_rate) + \ +    (this->get_full_secs() * fast_llround(tick_rate));  }  double time_spec_t::get_real_secs(void) const{ diff --git a/host/lib/usrp/b100/io_impl.cpp b/host/lib/usrp/b100/io_impl.cpp index bd60e75cf..d7effcac1 100644 --- a/host/lib/usrp/b100/io_impl.cpp +++ b/host/lib/usrp/b100/io_impl.cpp @@ -41,7 +41,7 @@ using namespace uhd::transport;   **********************************************************************/  struct b100_impl::io_impl{      io_impl(void): -        async_msg_fifo(100/*messages deep*/) +        async_msg_fifo(1000/*messages deep*/)      { /* NOP */ }      zero_copy_if::sptr data_transport; diff --git a/host/lib/usrp/cores/rx_dsp_core_200.cpp b/host/lib/usrp/cores/rx_dsp_core_200.cpp index ea0384dbe..cebf92f6a 100644 --- a/host/lib/usrp/cores/rx_dsp_core_200.cpp +++ b/host/lib/usrp/cores/rx_dsp_core_200.cpp @@ -121,7 +121,7 @@ public:          //issue the stream command          _iface->poke32(REG_RX_CTRL_STREAM_CMD, cmd_word); -        const boost::uint64_t ticks = stream_cmd.time_spec.to_ticks(_tick_rate); +        const boost::uint64_t ticks = (stream_cmd.stream_now)? 0 : stream_cmd.time_spec.to_ticks(_tick_rate);          _iface->poke32(REG_RX_CTRL_TIME_HI, boost::uint32_t(ticks >> 32));          _iface->poke32(REG_RX_CTRL_TIME_LO, boost::uint32_t(ticks >> 0)); //latches the command      } diff --git a/host/lib/usrp/e100/io_impl.cpp b/host/lib/usrp/e100/io_impl.cpp index f8e15f3fd..b090e45c7 100644 --- a/host/lib/usrp/e100/io_impl.cpp +++ b/host/lib/usrp/e100/io_impl.cpp @@ -50,7 +50,7 @@ using namespace uhd::transport;   **********************************************************************/  struct e100_impl::io_impl{      io_impl(void): -        false_alarm(0), async_msg_fifo(100/*messages deep*/) +        false_alarm(0), async_msg_fifo(1000/*messages deep*/)      { /* NOP */ }      double tick_rate; //set by update tick rate method diff --git a/host/lib/usrp/usrp1/soft_time_ctrl.cpp b/host/lib/usrp/usrp1/soft_time_ctrl.cpp index b8af8af06..90b3a92da 100644 --- a/host/lib/usrp/usrp1/soft_time_ctrl.cpp +++ b/host/lib/usrp/usrp1/soft_time_ctrl.cpp @@ -39,8 +39,8 @@ public:          _nsamps_remaining(0),          _stream_mode(stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS),          _cmd_queue(2), -        _async_msg_queue(100), -        _inline_msg_queue(100), +        _async_msg_queue(1000), +        _inline_msg_queue(1000),          _stream_on_off(stream_on_off)      {          //synchronously spawn a new thread diff --git a/host/lib/usrp/usrp2/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp index f0c159f16..221b747cb 100644 --- a/host/lib/usrp/usrp2/io_impl.cpp +++ b/host/lib/usrp/usrp2/io_impl.cpp @@ -135,7 +135,8 @@ private:  struct usrp2_impl::io_impl{      io_impl(void): -        async_msg_fifo(100/*messages deep*/) +        async_msg_fifo(1000/*messages deep*/), +        tick_rate(1 /*non-zero default*/)      {          /* NOP */      } diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index f3d474a2d..eeba6756e 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -87,7 +87,7 @@ public:          //Obtain the firmware's compat number.          //Save the response compat number for communication.          //TODO can choose to reject certain older compat numbers -        usrp2_ctrl_data_t ctrl_data; +        usrp2_ctrl_data_t ctrl_data = usrp2_ctrl_data_t();          ctrl_data.id = htonl(USRP2_CTRL_ID_WAZZUP_BRO);          ctrl_data = ctrl_send_and_recv(ctrl_data, 0, ~0);          if (ntohl(ctrl_data.id) != USRP2_CTRL_ID_WAZZUP_DUDE) @@ -126,10 +126,9 @@ public:      bool is_device_locked(void){          boost::uint32_t lock_secs = this->get_reg<boost::uint32_t, USRP2_REG_ACTION_FW_PEEK32>(U2_FW_REG_LOCK_TIME);          boost::uint32_t lock_gpid = this->get_reg<boost::uint32_t, USRP2_REG_ACTION_FW_PEEK32>(U2_FW_REG_LOCK_GPID); -        boost::uint32_t curr_secs = this->peek32(U2_REG_TIME64_LO_RB_IMM)/100e6;          //if the difference is larger, assume not locked anymore -        if (curr_secs - lock_secs >= 3) return false; +        if (this->get_curr_secs() - lock_secs >= 3) return false;          //otherwise only lock if the device hash is different that ours          return lock_gpid != boost::uint32_t(get_gpid()); @@ -137,12 +136,16 @@ public:      void lock_task(void){          //re-lock in task -        boost::uint32_t curr_secs = this->peek32(U2_REG_TIME64_LO_RB_IMM)/100e6; -        this->get_reg<boost::uint32_t, USRP2_REG_ACTION_FW_POKE32>(U2_FW_REG_LOCK_TIME, curr_secs); +        this->get_reg<boost::uint32_t, USRP2_REG_ACTION_FW_POKE32>(U2_FW_REG_LOCK_TIME, this->get_curr_secs());          //sleep for a bit          boost::this_thread::sleep(boost::posix_time::milliseconds(1500));      } +    boost::uint32_t get_curr_secs(void){ +        //may not be the right tick rate, but this is ok for locking purposes +        return boost::uint32_t(this->peek32(U2_REG_TIME64_LO_RB_IMM)/100e6); +    } +  /***********************************************************************   * Peek and Poke   **********************************************************************/ diff --git a/host/tests/convert_test.cpp b/host/tests/convert_test.cpp index d82014d3f..6b0ae53a9 100644 --- a/host/tests/convert_test.cpp +++ b/host/tests/convert_test.cpp @@ -124,8 +124,8 @@ static void test_convert_types_for_floats(      //fill the input samples      std::vector<data_type> input(nsamps), output(nsamps);      BOOST_FOREACH(data_type &in, input) in = data_type( -        ((std::rand()/value_type(RAND_MAX/2)) - 1)*extra_scale, -        ((std::rand()/value_type(RAND_MAX/2)) - 1)*extra_scale +        ((std::rand()/value_type(RAND_MAX/2)) - 1)*float(extra_scale), +        ((std::rand()/value_type(RAND_MAX/2)) - 1)*float(extra_scale)      );      //run the loopback and test | 
