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/rfnoc/mb_controller.hpp> 10 #include <uhdlib/utils/rpc.hpp> 11 #include <memory> 12 13 namespace uhd { namespace rfnoc { 14 15 /*! MPM-Specific version of the mb_controller 16 * 17 * Reminder: There is one of these per motherboard. 18 * 19 * This motherboard controller abstracts out a bunch of RPC calls. 20 */ 21 class mpmd_mb_controller : public mb_controller 22 { 23 public: 24 using sptr = std::shared_ptr<mpmd_mb_controller>; 25 26 mpmd_mb_controller(uhd::rpc_client::sptr rpcc, uhd::device_addr_t device_info); 27 28 //! Return reference to the RPC client get_rpc_client()29 uhd::rpc_client::sptr get_rpc_client() 30 { 31 return _rpc; 32 } 33 34 /************************************************************************** 35 * Timekeeper API 36 *************************************************************************/ 37 //! MPM-specific version of the timekeeper controls 38 // 39 // MPM devices talk to MPM via RPC to control the timekeeper 40 class mpmd_timekeeper : public mb_controller::timekeeper 41 { 42 public: 43 using sptr = std::shared_ptr<mpmd_timekeeper>; 44 mpmd_timekeeper(const size_t tk_idx,uhd::rpc_client::sptr rpc_client)45 mpmd_timekeeper(const size_t tk_idx, uhd::rpc_client::sptr rpc_client) 46 : _tk_idx(tk_idx), _rpc(rpc_client) 47 { 48 // nop 49 } 50 51 uint64_t get_ticks_now(); 52 uint64_t get_ticks_last_pps(); 53 void set_ticks_now(const uint64_t ticks); 54 void set_ticks_next_pps(const uint64_t ticks); 55 void set_period(const uint64_t period_ns); 56 57 /*! Update the tick rate 58 * Note: This is separate from set_tick_rate because the latter is 59 * protected, and we need to implement mpmd-specific functionality here 60 */ 61 void update_tick_rate(const double tick_rate); 62 63 private: 64 const size_t _tk_idx; 65 uhd::rpc_client::sptr _rpc; 66 }; 67 68 /************************************************************************** 69 * Motherboard Control API (see mb_controller.hpp) 70 *************************************************************************/ 71 std::string get_mboard_name() const; 72 void set_time_source(const std::string& source); 73 std::string get_time_source() const; 74 std::vector<std::string> get_time_sources() const; 75 void set_clock_source(const std::string& source); 76 std::string get_clock_source() const; 77 std::vector<std::string> get_clock_sources() const; 78 void set_sync_source(const std::string& clock_source, const std::string& time_source); 79 void set_sync_source(const uhd::device_addr_t& sync_source); 80 uhd::device_addr_t get_sync_source() const; 81 std::vector<uhd::device_addr_t> get_sync_sources(); 82 void set_clock_source_out(const bool enb); 83 void set_time_source_out(const bool enb); 84 uhd::sensor_value_t get_sensor(const std::string& name); 85 std::vector<std::string> get_sensor_names(); 86 uhd::usrp::mboard_eeprom_t get_eeprom(); 87 std::vector<std::string> get_gpio_banks() const; 88 std::vector<std::string> get_gpio_srcs(const std::string& bank) const; 89 std::vector<std::string> get_gpio_src(const std::string& bank); 90 void set_gpio_src(const std::string& bank, const std::vector<std::string>& src); 91 92 private: 93 /************************************************************************** 94 * Attributes 95 *************************************************************************/ 96 //! Reference to RPC interface 97 mutable uhd::rpc_client::sptr _rpc; 98 99 uhd::device_addr_t _device_info; 100 101 //! List of MB sensor names 102 std::unordered_set<std::string> _sensor_names; 103 104 //! Cache of available GPIO sources 105 std::vector<std::string> _gpio_banks; 106 std::unordered_map<std::string, std::vector<std::string>> _gpio_srcs; 107 }; 108 109 }} // namespace uhd::rfnoc 110