Loading...
Searching...
No Matches
mb_controller.hpp
Go to the documentation of this file.
//
// Copyright 2019 Ettus Research, a National Instruments Brand
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
#pragma once
#include <uhd/config.hpp>
#include <uhd/features/discoverable_feature_getter_iface.hpp>
#include <uhd/types/device_addr.hpp>
#include <uhd/types/sensors.hpp>
#include <uhd/types/time_spec.hpp>
#include <uhd/usrp/mboard_eeprom.hpp>
#include <uhd/utils/noncopyable.hpp>
#include <unordered_map>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <memory>
#include <string>
#include <vector>
namespace uhd { namespace rfnoc {
class UHD_API mb_controller
: public uhd::noncopyable,
public virtual ::uhd::features::discoverable_feature_getter_iface
{
public:
using sptr = std::shared_ptr<mb_controller>;
using sync_source_t = device_addr_t;
using sync_source_updater_t = std::function<void(const sync_source_t& sync_source)>;
~mb_controller() override = default;
/**************************************************************************
* Timebase API
*************************************************************************/
class UHD_API timekeeper
{
public:
using sptr = std::shared_ptr<timekeeper>;
using write_period_fn_t = std::function<void(uint64_t)>;
timekeeper();
virtual ~timekeeper() {}
uhd::time_spec_t get_time_now(void);
virtual uint64_t get_ticks_now() = 0;
uhd::time_spec_t get_time_last_pps(void);
virtual uint64_t get_ticks_last_pps() = 0;
void set_time_now(const uhd::time_spec_t& time);
virtual void set_ticks_now(const uint64_t ticks) = 0;
void set_time_next_pps(const uhd::time_spec_t& time);
virtual void set_ticks_next_pps(const uint64_t ticks) = 0;
double get_tick_rate()
{
return _tick_rate;
}
protected:
void set_tick_rate(const double rate);
virtual void set_period(const uint64_t period_ns) = 0;
private:
double _tick_rate = 1.0;
};
// on this device.
//
// Most USRPs have one timekeeper. Refer to the manual for your device
// family for potential exceptions to this behavior. Custom FPGA images
// may also implement multiple timekeepers for various purposes.
size_t get_num_timekeepers() const;
//
// For most USRPs, timekeeper index 0 is used to access the main timekeeper.
// When using a USRP with multiple timekeepers, refer to the relevant device
// family manual for more information on timekeeper mapping and enumeration.
//
// Custom FPGA images can implement multiple timekeepers.
//
// To make sure that \p tk_idx is a valid value, get_num_timekeepers() can
// be used to query the number of timekeepers available.
//
// \throws uhd::index_error if \p tk_idx is not valid
timekeeper::sptr get_timekeeper(const size_t tk_idx) const;
/**************************************************************************
* Motherboard Control
*************************************************************************/
virtual void init() {}
virtual std::string get_mboard_name() const = 0;
virtual void set_time_source(const std::string& source) = 0;
virtual std::string get_time_source() const = 0;
virtual std::vector<std::string> get_time_sources() const = 0;
virtual void set_clock_source(const std::string& source) = 0;
virtual std::string get_clock_source() const = 0;
virtual std::vector<std::string> get_clock_sources() const = 0;
virtual void set_sync_source(
const std::string& clock_source, const std::string& time_source) = 0;
virtual void set_sync_source(const uhd::device_addr_t& sync_source) = 0;
virtual uhd::device_addr_t get_sync_source() const = 0;
virtual std::vector<uhd::device_addr_t> get_sync_sources() = 0;
virtual void set_clock_source_out(const bool enb) = 0;
virtual void set_time_source_out(const bool enb) = 0;
virtual uhd::sensor_value_t get_sensor(const std::string& name) = 0;
virtual std::vector<std::string> get_sensor_names() = 0;
virtual uhd::usrp::mboard_eeprom_t get_eeprom() = 0;
virtual bool synchronize(std::vector<mb_controller::sptr>& mb_controllers,
const uhd::time_spec_t& time_spec = uhd::time_spec_t(0.0),
const bool quiet = false);
virtual std::vector<std::string> get_gpio_banks() const;
virtual std::vector<std::string> get_gpio_srcs(const std::string& bank) const;
virtual std::vector<std::string> get_gpio_src(const std::string& bank);
virtual void set_gpio_src(
const std::string& bank, const std::vector<std::string>& src);
virtual void register_sync_source_updater(sync_source_updater_t callback_f);
protected:
void register_timekeeper(const size_t idx, timekeeper::sptr tk);
private:
/**************************************************************************
* Attributes
*************************************************************************/
std::unordered_map<size_t, timekeeper::sptr> _timekeepers;
};
}} // namespace uhd::rfnoc
uhd::device_addr_t
Definition device_addr.hpp:39
uhd::features::discoverable_feature_getter_iface
Definition discoverable_feature_getter_iface.hpp:18
uhd::rfnoc::mb_controller::timekeeper::set_ticks_now
virtual void set_ticks_now(const uint64_t ticks)=0
uhd::rfnoc::mb_controller::timekeeper::~timekeeper
virtual ~timekeeper()
Definition mb_controller.hpp:70
uhd::rfnoc::mb_controller::timekeeper::get_time_last_pps
uhd::time_spec_t get_time_last_pps(void)
uhd::rfnoc::mb_controller::timekeeper::set_time_next_pps
void set_time_next_pps(const uhd::time_spec_t &time)
uhd::rfnoc::mb_controller::timekeeper::get_time_now
uhd::time_spec_t get_time_now(void)
uhd::rfnoc::mb_controller::timekeeper::get_ticks_now
virtual uint64_t get_ticks_now()=0
uhd::rfnoc::mb_controller::timekeeper::set_period
virtual void set_period(const uint64_t period_ns)=0
uhd::rfnoc::mb_controller::timekeeper::set_time_now
void set_time_now(const uhd::time_spec_t &time)
uhd::rfnoc::mb_controller::timekeeper::sptr
std::shared_ptr< timekeeper > sptr
Definition mb_controller.hpp:65
uhd::rfnoc::mb_controller::timekeeper::set_ticks_next_pps
virtual void set_ticks_next_pps(const uint64_t ticks)=0
uhd::rfnoc::mb_controller::timekeeper::timekeeper
timekeeper()
uhd::rfnoc::mb_controller::timekeeper::get_tick_rate
double get_tick_rate()
Definition mb_controller.hpp:167
uhd::rfnoc::mb_controller::timekeeper::write_period_fn_t
std::function< void(uint64_t)> write_period_fn_t
Definition mb_controller.hpp:66
uhd::rfnoc::mb_controller::timekeeper::set_tick_rate
void set_tick_rate(const double rate)
uhd::rfnoc::mb_controller::timekeeper::get_ticks_last_pps
virtual uint64_t get_ticks_last_pps()=0
uhd::rfnoc::mb_controller
Definition mb_controller.hpp:31
uhd::rfnoc::mb_controller::get_mboard_name
virtual std::string get_mboard_name() const =0
uhd::rfnoc::mb_controller::get_eeprom
virtual uhd::usrp::mboard_eeprom_t get_eeprom()=0
uhd::rfnoc::mb_controller::get_timekeeper
timekeeper::sptr get_timekeeper(const size_t tk_idx) const
Return a reference to the tk_idx-th timekeeper on this motherboard.
uhd::rfnoc::mb_controller::init
virtual void init()
Definition mb_controller.hpp:221
uhd::rfnoc::mb_controller::get_sensor
virtual uhd::sensor_value_t get_sensor(const std::string &name)=0
uhd::rfnoc::mb_controller::get_gpio_banks
virtual std::vector< std::string > get_gpio_banks() const
uhd::rfnoc::mb_controller::sync_source_t
device_addr_t sync_source_t
Definition mb_controller.hpp:34
uhd::rfnoc::mb_controller::set_time_source
virtual void set_time_source(const std::string &source)=0
uhd::rfnoc::mb_controller::register_sync_source_updater
virtual void register_sync_source_updater(sync_source_updater_t callback_f)
uhd::rfnoc::mb_controller::set_sync_source
virtual void set_sync_source(const std::string &clock_source, const std::string &time_source)=0
uhd::rfnoc::mb_controller::get_time_sources
virtual std::vector< std::string > get_time_sources() const =0
uhd::rfnoc::mb_controller::get_time_source
virtual std::string get_time_source() const =0
uhd::rfnoc::mb_controller::sptr
std::shared_ptr< mb_controller > sptr
Definition mb_controller.hpp:33
uhd::rfnoc::mb_controller::get_sync_sources
virtual std::vector< uhd::device_addr_t > get_sync_sources()=0
uhd::rfnoc::mb_controller::get_clock_source
virtual std::string get_clock_source() const =0
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::rfnoc::mb_controller::set_clock_source_out
virtual void set_clock_source_out(const bool enb)=0
uhd::rfnoc::mb_controller::set_gpio_src
virtual void set_gpio_src(const std::string &bank, const std::vector< std::string > &src)
uhd::rfnoc::mb_controller::~mb_controller
~mb_controller() override=default
uhd::rfnoc::mb_controller::get_sensor_names
virtual std::vector< std::string > get_sensor_names()=0
uhd::rfnoc::mb_controller::get_num_timekeepers
size_t get_num_timekeepers() const
Returns the number of timekeepers, which equals the number of timebases.
uhd::rfnoc::mb_controller::synchronize
virtual bool synchronize(std::vector< mb_controller::sptr > &mb_controllers, const uhd::time_spec_t &time_spec=uhd::time_spec_t(0.0), const bool quiet=false)
uhd::rfnoc::mb_controller::set_sync_source
virtual void set_sync_source(const uhd::device_addr_t &sync_source)=0
uhd::rfnoc::mb_controller::set_clock_source
virtual void set_clock_source(const std::string &source)=0
uhd::rfnoc::mb_controller::get_gpio_src
virtual std::vector< std::string > get_gpio_src(const std::string &bank)
uhd::rfnoc::mb_controller::register_timekeeper
void register_timekeeper(const size_t idx, timekeeper::sptr tk)
uhd::rfnoc::mb_controller::get_clock_sources
virtual std::vector< std::string > get_clock_sources() const =0
uhd::rfnoc::mb_controller::set_time_source_out
virtual void set_time_source_out(const bool enb)=0
uhd::rfnoc::mb_controller::get_sync_source
virtual uhd::device_addr_t get_sync_source() const =0
uhd::rfnoc::mb_controller::get_gpio_srcs
virtual std::vector< std::string > get_gpio_srcs(const std::string &bank) const
uhd::time_spec_t
Definition time_spec.hpp:31
UHD_API
#define UHD_API
Definition config.h:87
config.hpp
device_addr.hpp
discoverable_feature_getter_iface.hpp
mboard_eeprom.hpp
uhd::rfnoc
Definition actions.hpp:24
uhd::usrp::mboard_eeprom_t
uhd::dict< std::string, std::string > mboard_eeprom_t
Definition mboard_eeprom.hpp:27
uhd
Definition build_info.hpp:12
uhd::noncopyable
boost::noncopyable noncopyable
Definition noncopyable.hpp:45
noncopyable.hpp
sensors.hpp
uhd::sensor_value_t
Definition sensors.hpp:29
time_spec.hpp