USRP Hardware Driver and USRP Manual  Version: 4.3.0.0-1-g4d6b7263f
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 <functional>
18 #include <memory>
19 #include <vector>
20 
21 namespace uhd { namespace rfnoc {
22 
27 {
28 public:
29  using sptr = std::shared_ptr<mb_controller>;
31 
37  using sync_source_updater_t = std::function<void(const sync_source_t& sync_source)>;
38 
39  virtual ~mb_controller() {}
40 
41  /**************************************************************************
42  * Timebase API
43  *************************************************************************/
50  {
51  public:
52  using sptr = std::shared_ptr<timekeeper>;
53  using write_period_fn_t = std::function<void(uint64_t)>;
54 
55  timekeeper();
56 
57  virtual ~timekeeper() {}
58 
68  uhd::time_spec_t get_time_now(void);
69 
76  virtual uint64_t get_ticks_now() = 0;
77 
85  uhd::time_spec_t get_time_last_pps(void);
86 
91  virtual uint64_t get_ticks_last_pps() = 0;
92 
95  void set_time_now(const uhd::time_spec_t& time);
96 
99  virtual void set_ticks_now(const uint64_t ticks) = 0;
100 
103  void set_time_next_pps(const uhd::time_spec_t& time);
104 
107  virtual void set_ticks_next_pps(const uint64_t ticks) = 0;
108 
111  double get_tick_rate()
112  {
113  return _tick_rate;
114  }
115 
116  protected:
125  void set_tick_rate(const double rate);
126 
131  virtual void set_period(const uint64_t period_ns) = 0;
132 
133  private:
135  double _tick_rate = 1.0;
136  };
137 
139  // on this device.
140  size_t get_num_timekeepers() const;
141 
143  //
144  // \throws uhd::index_error if \p tk_idx is not valid
145  timekeeper::sptr get_timekeeper(const size_t tk_idx) const;
146 
147  /**************************************************************************
148  * Motherboard Control
149  *************************************************************************/
152  virtual void init() {}
153 
158  virtual std::string get_mboard_name() const = 0;
159 
201  virtual void set_time_source(const std::string& source) = 0;
202 
207  virtual std::string get_time_source() const = 0;
208 
213  virtual std::vector<std::string> get_time_sources() const = 0;
214 
256  virtual void set_clock_source(const std::string& source) = 0;
257 
262  virtual std::string get_clock_source() const = 0;
263 
268  virtual std::vector<std::string> get_clock_sources() const = 0;
269 
279  virtual void set_sync_source(
280  const std::string& clock_source, const std::string& time_source) = 0;
281 
303  virtual void set_sync_source(const uhd::device_addr_t& sync_source) = 0;
304 
309  virtual uhd::device_addr_t get_sync_source() const = 0;
310 
315  virtual std::vector<uhd::device_addr_t> get_sync_sources() = 0;
316 
324  virtual void set_clock_source_out(const bool enb) = 0;
325 
333  virtual void set_time_source_out(const bool enb) = 0;
334 
340  virtual uhd::sensor_value_t get_sensor(const std::string& name) = 0;
341 
346  virtual std::vector<std::string> get_sensor_names() = 0;
347 
350  virtual uhd::usrp::mboard_eeprom_t get_eeprom() = 0;
351 
366  virtual bool synchronize(std::vector<mb_controller::sptr>& mb_controllers,
367  const uhd::time_spec_t& time_spec = uhd::time_spec_t(0.0),
368  const bool quiet = false);
369 
375  virtual std::vector<std::string> get_gpio_banks() const;
376 
382  virtual std::vector<std::string> get_gpio_srcs(const std::string& bank) const;
383 
386  virtual std::vector<std::string> get_gpio_src(const std::string& bank);
387 
395  virtual void set_gpio_src(
396  const std::string& bank, const std::vector<std::string>& src);
397 
406  virtual void register_sync_source_updater(sync_source_updater_t callback_f);
407 
408 protected:
412  void register_timekeeper(const size_t idx, timekeeper::sptr tk);
413 
414 private:
415  /**************************************************************************
416  * Attributes
417  *************************************************************************/
418  std::unordered_map<size_t, timekeeper::sptr> _timekeepers;
419 };
420 
421 }} // namespace uhd::rfnoc
boost::noncopyable noncopyable
Definition: noncopyable.hpp:45
std::function< void(uint64_t)> write_period_fn_t
Definition: mb_controller.hpp:53
Definition: mb_controller.hpp:25
Definition: time_spec.hpp:28
double get_tick_rate()
Definition: mb_controller.hpp:111
virtual void init()
Definition: mb_controller.hpp:152
virtual ~timekeeper()
Definition: mb_controller.hpp:57
Definition: build_info.hpp:12
std::function< void(const sync_source_t &sync_source)> sync_source_updater_t
Definition: mb_controller.hpp:37
Definition: sensors.hpp:28
virtual ~mb_controller()
Definition: mb_controller.hpp:39
Definition: discoverable_feature_getter_iface.hpp:17
source
Identify the source of calibration data, i.e., where was it stored.
Definition: database.hpp:22
std::shared_ptr< timekeeper > sptr
Definition: mb_controller.hpp:52
std::shared_ptr< mb_controller > sptr
Definition: mb_controller.hpp:29
Definition: mb_controller.hpp:49
#define UHD_API
Definition: config.h:87
Definition: device_addr.hpp:37