USRP Hardware Driver and USRP Manual  Version: 4.8.0.0
UHD and USRP Manual
mb_controller.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2019 Ettus Research, a National Instruments Brand
3 //
4 // SPDX-License-Identifier: GPL-3.0-or-later
5 //
6 
7 #pragma once
8 
9 #include <uhd/config.hpp>
12 #include <uhd/types/sensors.hpp>
13 #include <uhd/types/time_spec.hpp>
16 #include <unordered_map>
17 #include <cstddef>
18 #include <cstdint>
19 #include <functional>
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 namespace uhd { namespace rfnoc {
25 
29  : public uhd::noncopyable,
31 {
32 public:
33  using sptr = std::shared_ptr<mb_controller>;
35 
41  using sync_source_updater_t = std::function<void(const sync_source_t& sync_source)>;
42 
43  ~mb_controller() override = default;
44 
45  /**************************************************************************
46  * Timebase API
47  *************************************************************************/
63  {
64  public:
65  using sptr = std::shared_ptr<timekeeper>;
66  using write_period_fn_t = std::function<void(uint64_t)>;
67 
69 
70  virtual ~timekeeper() {}
71 
89  uhd::time_spec_t get_time_now(void);
90 
105  virtual uint64_t get_ticks_now() = 0;
106 
114  uhd::time_spec_t get_time_last_pps(void);
115 
120  virtual uint64_t get_ticks_last_pps() = 0;
121 
127  void set_time_now(const uhd::time_spec_t& time);
128 
136  virtual void set_ticks_now(const uint64_t ticks) = 0;
137 
148  void set_time_next_pps(const uhd::time_spec_t& time);
149 
163  virtual void set_ticks_next_pps(const uint64_t ticks) = 0;
164 
167  double get_tick_rate()
168  {
169  return _tick_rate;
170  }
171 
172  protected:
181  void set_tick_rate(const double rate);
182 
187  virtual void set_period(const uint64_t period_ns) = 0;
188 
189  private:
191  double _tick_rate = 1.0;
192  };
193 
195  // on this device.
196  //
197  // Most USRPs have one timekeeper. Refer to the manual for your device
198  // family for potential exceptions to this behavior. Custom FPGA images
199  // may also implement multiple timekeepers for various purposes.
200  size_t get_num_timekeepers() const;
201 
203  //
204  // For most USRPs, timekeeper index 0 is used to access the main timekeeper.
205  // When using a USRP with multiple timekeepers, refer to the relevant device
206  // family manual for more information on timekeeper mapping and enumeration.
207  //
208  // Custom FPGA images can implement multiple timekeepers.
209  //
210  // To make sure that \p tk_idx is a valid value, get_num_timekeepers() can
211  // be used to query the number of timekeepers available.
212  //
213  // \throws uhd::index_error if \p tk_idx is not valid
214  timekeeper::sptr get_timekeeper(const size_t tk_idx) const;
215 
216  /**************************************************************************
217  * Motherboard Control
218  *************************************************************************/
221  virtual void init() {}
222 
227  virtual std::string get_mboard_name() const = 0;
228 
270  virtual void set_time_source(const std::string& source) = 0;
271 
276  virtual std::string get_time_source() const = 0;
277 
282  virtual std::vector<std::string> get_time_sources() const = 0;
283 
325  virtual void set_clock_source(const std::string& source) = 0;
326 
331  virtual std::string get_clock_source() const = 0;
332 
337  virtual std::vector<std::string> get_clock_sources() const = 0;
338 
348  virtual void set_sync_source(
349  const std::string& clock_source, const std::string& time_source) = 0;
350 
380  virtual void set_sync_source(const uhd::device_addr_t& sync_source) = 0;
381 
386  virtual uhd::device_addr_t get_sync_source() const = 0;
387 
392  virtual std::vector<uhd::device_addr_t> get_sync_sources() = 0;
393 
401  virtual void set_clock_source_out(const bool enb) = 0;
402 
410  virtual void set_time_source_out(const bool enb) = 0;
411 
417  virtual uhd::sensor_value_t get_sensor(const std::string& name) = 0;
418 
423  virtual std::vector<std::string> get_sensor_names() = 0;
424 
427  virtual uhd::usrp::mboard_eeprom_t get_eeprom() = 0;
428 
464  virtual bool synchronize(std::vector<mb_controller::sptr>& mb_controllers,
465  const uhd::time_spec_t& time_spec = uhd::time_spec_t(0.0),
466  const bool quiet = false);
467 
473  virtual std::vector<std::string> get_gpio_banks() const;
474 
480  virtual std::vector<std::string> get_gpio_srcs(const std::string& bank) const;
481 
484  virtual std::vector<std::string> get_gpio_src(const std::string& bank);
485 
493  virtual void set_gpio_src(
494  const std::string& bank, const std::vector<std::string>& src);
495 
504  virtual void register_sync_source_updater(sync_source_updater_t callback_f);
505 
506 protected:
510  void register_timekeeper(const size_t idx, timekeeper::sptr tk);
511 
512 private:
513  /**************************************************************************
514  * Attributes
515  *************************************************************************/
516  std::unordered_map<size_t, timekeeper::sptr> _timekeepers;
517 };
518 
519 }} // namespace uhd::rfnoc
uhd::rfnoc::mb_controller::init
virtual void init()
Definition: mb_controller.hpp:221
sensors.hpp
device_addr.hpp
uhd::features::discoverable_feature_getter_iface
Definition: discoverable_feature_getter_iface.hpp:17
time_spec.hpp
config.hpp
uhd::rfnoc::mb_controller::timekeeper
Definition: mb_controller.hpp:62
discoverable_feature_getter_iface.hpp
uhd::rfnoc::mb_controller
Definition: mb_controller.hpp:28
UHD_API
#define UHD_API
Definition: config.h:87
uhd::usrp::cal::source
source
Identify the source of calibration data, i.e., where was it stored.
Definition: database.hpp:22
noncopyable.hpp
uhd::device_addr_t
Definition: device_addr.hpp:38
uhd::rfnoc::mb_controller::timekeeper::sptr
std::shared_ptr< timekeeper > sptr
Definition: mb_controller.hpp:67
uhd::rfnoc::mb_controller::timekeeper::write_period_fn_t
std::function< void(uint64_t)> write_period_fn_t
Definition: mb_controller.hpp:68
uhd::rfnoc::mb_controller::sptr
std::shared_ptr< mb_controller > sptr
Definition: mb_controller.hpp:33
uhd
Definition: build_info.hpp:12
uhd::time_spec_t
Definition: time_spec.hpp:28
uhd::rfnoc::mb_controller::sync_source_updater_t
std::function< void(const sync_source_t &sync_source)> sync_source_updater_t
Definition: mb_controller.hpp:41
uhd::dict< std::string, std::string >
mboard_eeprom.hpp
uhd::noncopyable
boost::noncopyable noncopyable
Definition: noncopyable.hpp:45
uhd::sensor_value_t
Definition: sensors.hpp:28