USRP Hardware Driver and USRP Manual  Version: 4.6.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 <functional>
18 #include <memory>
19 #include <vector>
20 
21 namespace uhd { namespace rfnoc {
22 
26  : public uhd::noncopyable,
28 {
29 public:
30  using sptr = std::shared_ptr<mb_controller>;
32 
38  using sync_source_updater_t = std::function<void(const sync_source_t& sync_source)>;
39 
40  ~mb_controller() override = default;
41 
42  /**************************************************************************
43  * Timebase API
44  *************************************************************************/
60  {
61  public:
62  using sptr = std::shared_ptr<timekeeper>;
63  using write_period_fn_t = std::function<void(uint64_t)>;
64 
65  timekeeper();
66 
67  virtual ~timekeeper() {}
68 
86  uhd::time_spec_t get_time_now(void);
87 
102  virtual uint64_t get_ticks_now() = 0;
103 
111  uhd::time_spec_t get_time_last_pps(void);
112 
117  virtual uint64_t get_ticks_last_pps() = 0;
118 
124  void set_time_now(const uhd::time_spec_t& time);
125 
133  virtual void set_ticks_now(const uint64_t ticks) = 0;
134 
140  void set_time_next_pps(const uhd::time_spec_t& time);
141 
155  virtual void set_ticks_next_pps(const uint64_t ticks) = 0;
156 
159  double get_tick_rate()
160  {
161  return _tick_rate;
162  }
163 
164  protected:
173  void set_tick_rate(const double rate);
174 
179  virtual void set_period(const uint64_t period_ns) = 0;
180 
181  private:
183  double _tick_rate = 1.0;
184  };
185 
187  // on this device.
188  //
189  // Most USRPs have one timekeeper. Refer to the manual for your device
190  // family for potential exceptions to this behavior. Custom FPGA images
191  // may also implement multiple timekeepers for various purposes.
192  size_t get_num_timekeepers() const;
193 
195  //
196  // For most USRPs, timekeeper index 0 is used to access the main timekeeper.
197  // When using a USRP with multiple timekeepers, refer to the relevant device
198  // family manual for more information on timekeeper mapping and enumeration.
199  //
200  // Custom FPGA images can implement multiple timekeepers.
201  //
202  // To make sure that \p tk_idx is a valid value, get_num_timekeepers() can
203  // be used to query the number of timekeepers available.
204  //
205  // \throws uhd::index_error if \p tk_idx is not valid
206  timekeeper::sptr get_timekeeper(const size_t tk_idx) const;
207 
208  /**************************************************************************
209  * Motherboard Control
210  *************************************************************************/
213  virtual void init() {}
214 
219  virtual std::string get_mboard_name() const = 0;
220 
262  virtual void set_time_source(const std::string& source) = 0;
263 
268  virtual std::string get_time_source() const = 0;
269 
274  virtual std::vector<std::string> get_time_sources() const = 0;
275 
317  virtual void set_clock_source(const std::string& source) = 0;
318 
323  virtual std::string get_clock_source() const = 0;
324 
329  virtual std::vector<std::string> get_clock_sources() const = 0;
330 
340  virtual void set_sync_source(
341  const std::string& clock_source, const std::string& time_source) = 0;
342 
364  virtual void set_sync_source(const uhd::device_addr_t& sync_source) = 0;
365 
370  virtual uhd::device_addr_t get_sync_source() const = 0;
371 
376  virtual std::vector<uhd::device_addr_t> get_sync_sources() = 0;
377 
385  virtual void set_clock_source_out(const bool enb) = 0;
386 
394  virtual void set_time_source_out(const bool enb) = 0;
395 
401  virtual uhd::sensor_value_t get_sensor(const std::string& name) = 0;
402 
407  virtual std::vector<std::string> get_sensor_names() = 0;
408 
411  virtual uhd::usrp::mboard_eeprom_t get_eeprom() = 0;
412 
448  virtual bool synchronize(std::vector<mb_controller::sptr>& mb_controllers,
449  const uhd::time_spec_t& time_spec = uhd::time_spec_t(0.0),
450  const bool quiet = false);
451 
457  virtual std::vector<std::string> get_gpio_banks() const;
458 
464  virtual std::vector<std::string> get_gpio_srcs(const std::string& bank) const;
465 
468  virtual std::vector<std::string> get_gpio_src(const std::string& bank);
469 
477  virtual void set_gpio_src(
478  const std::string& bank, const std::vector<std::string>& src);
479 
488  virtual void register_sync_source_updater(sync_source_updater_t callback_f);
489 
490 protected:
494  void register_timekeeper(const size_t idx, timekeeper::sptr tk);
495 
496 private:
497  /**************************************************************************
498  * Attributes
499  *************************************************************************/
500  std::unordered_map<size_t, timekeeper::sptr> _timekeepers;
501 };
502 
503 }} // namespace uhd::rfnoc
boost::noncopyable noncopyable
Definition: noncopyable.hpp:45
std::function< void(uint64_t)> write_period_fn_t
Definition: mb_controller.hpp:63
Definition: mb_controller.hpp:25
Definition: time_spec.hpp:28
double get_tick_rate()
Definition: mb_controller.hpp:159
virtual void init()
Definition: mb_controller.hpp:213
virtual ~timekeeper()
Definition: mb_controller.hpp:67
Definition: build_info.hpp:12
std::function< void(const sync_source_t &sync_source)> sync_source_updater_t
Definition: mb_controller.hpp:38
Definition: sensors.hpp:28
Definition: discoverable_feature_getter_iface.hpp:17
source
Identify the source of calibration data, i.e., where was it stored.
Definition: database.hpp:23
std::shared_ptr< timekeeper > sptr
Definition: mb_controller.hpp:62
std::shared_ptr< mb_controller > sptr
Definition: mb_controller.hpp:30
Definition: mb_controller.hpp:59
#define UHD_API
Definition: config.h:87
Definition: device_addr.hpp:37