diff options
Diffstat (limited to 'host/lib/include/uhdlib')
72 files changed, 2592 insertions, 2530 deletions
diff --git a/host/lib/include/uhdlib/experts/expert_container.hpp b/host/lib/include/uhdlib/experts/expert_container.hpp index da52f6f4a..0beae5504 100644 --- a/host/lib/include/uhdlib/experts/expert_container.hpp +++ b/host/lib/include/uhdlib/experts/expert_container.hpp @@ -8,185 +8,189 @@  #ifndef INCLUDED_UHD_EXPERTS_EXPERT_CONTAINER_HPP  #define INCLUDED_UHD_EXPERTS_EXPERT_CONTAINER_HPP -#include <uhdlib/experts/expert_nodes.hpp>  #include <uhd/config.hpp>  #include <uhd/utils/noncopyable.hpp> -#include <memory> +#include <uhdlib/experts/expert_nodes.hpp>  #include <boost/thread/recursive_mutex.hpp> +#include <memory>  namespace uhd { namespace experts { -    enum auto_resolve_mode_t { -        AUTO_RESOLVE_OFF, -        AUTO_RESOLVE_ON_READ, -        AUTO_RESOLVE_ON_WRITE, -        AUTO_RESOLVE_ON_READ_WRITE -    }; - -    class UHD_API expert_container : private uhd::noncopyable, public node_retriever_t { -    public: //Methods -        typedef std::shared_ptr<expert_container> sptr; - -        virtual ~expert_container() {}; - -        /*! -         * Return the name of this container -         */ -        virtual const std::string& get_name() const = 0; - -        /*! -         * Resolves all the nodes in this expert graph. -         * -         * Dependency analysis is performed on the graph and nodes -         * are resolved in a topologically sorted order to ensure -         * that no nodes receive stale data. -         * Nodes and their dependencies are resolved only if they are -         * dirty i.e. their contained values have changed since the -         * last resolve. -         * This call requires an acyclic expert graph. -         * -         * \param force If true then ignore dirty state and resolve all nodes -         * \throws uhd::runtime_error if graph cannot be resolved -         */ -        virtual void resolve_all(bool force = false) = 0; - -        /*! -         * Resolves all the nodes that depend on the specified node. -         * -         * Dependency analysis is performed on the graph and nodes -         * are resolved in a topologically sorted order to ensure -         * that no nodes receive stale data. -         * Nodes and their dependencies are resolved only if they are -         * dirty i.e. their contained values have changed since the -         * last resolve. -         * This call requires an acyclic expert graph. -         * -         * \param node_name Name of the node to start resolving from -         * \throws uhd::lookup_error if node_name not in container -         * \throws uhd::runtime_error if graph cannot be resolved -         * -         */ -        virtual void resolve_from(const std::string& node_name) = 0; - -        /*! -         * Resolves all the specified node and all of its dependencies. -         * -         * Dependency analysis is performed on the graph and nodes -         * are resolved in a topologically sorted order to ensure -         * that no nodes receive stale data. -         * Nodes and their dependencies are resolved only if they are -         * dirty i.e. their contained values have changed since the -         * last resolve. -         * This call requires an acyclic expert graph. -         * -         * \param node_name Name of the node to resolve -         * \throws uhd::lookup_error if node_name not in container -         * \throws uhd::runtime_error if graph cannot be resolved -         * -         */ -        virtual void resolve_to(const std::string& node_name) = 0; - -        /*! -         * Return a node retriever object for this container -         */ -        virtual const node_retriever_t& node_retriever() const = 0; - -        /*! -         * Returns a DOT (graph description language) representation -         * of the expert graph. The output has labels for the node -         * name, node type (data or worker) and the underlying -         * data type for each node. -         * -         */ -        virtual std::string to_dot() const = 0; - -        /*! -         * Runs several sanity checks on the underlying graph to -         * flag dependency issues. Outputs of the checks are -         * logged to the console so UHD_EXPERTS_VERBOSE_LOGGING -         * must be enabled to see the results -         * -         */ -        virtual void debug_audit() const = 0; - -    private: -        /*! -         * Lookup a node with the specified name in the contained graph -         * -         * If the node is found, a reference to the node is returned. -         * If the node is not found, uhd::lookup_error is thrown -         * lookup can return a data or a worker node -         * \implements uhd::experts::node_retriever_t -         * -         * \param name Name of the node to find -         * -         */ -        virtual const dag_vertex_t& lookup(const std::string& name) const = 0; -        virtual dag_vertex_t& retrieve(const std::string& name) const = 0; - -        /*! -         * expert_factory is a friend of expert_container and -         * handles all operations that change the structure of -         * the underlying dependency graph. -         * The expert_container instance owns all data and worker -         * nodes and is responsible for release storage on destruction. -         * However, the expert_factory allocates storage for the -         * node and passes them into the expert_container using the -         * following "protected" API calls. -         * -         */ -        friend class expert_factory; - -        /*! -         * Creates an empty instance of expert_container with the -         * specified name. -         * -         * \param name Name of the container -         */ -        static sptr make(const std::string& name); - -        /*! -         * Returns a reference to the resolver mutex. -         * -         * The resolver mutex guarantees that external operations -         * to data-nodes are serialized with resolves of this -         * container. -         * -         */ -        virtual boost::recursive_mutex& resolve_mutex() = 0; - -        /*! -         * Add a data node to the expert graph -         * -         * \param data_node Pointer to a fully constructed data node object -         * \resolve_mode Auto resolve options: Choose from "disabled" and resolve on "read", "write" or "both" -         * \throws uhd::runtime_error if node already exists or is of a wrong type (recoverable) -         * \throws uhd::assertion_error for other failures (unrecoverable. will clear the graph) -         * -         */ -        virtual void add_data_node(dag_vertex_t* data_node, auto_resolve_mode_t resolve_mode = AUTO_RESOLVE_OFF) = 0; - -        /*! -         * Add a worker node to the expert graph -         * -         * \param worker Pointer to a fully constructed worker object -         * \throws uhd::runtime_error if worker already exists or is of a wrong type (recoverable) -         * \throws uhd::assertion_error for other failures (unrecoverable. will clear the graph) -         * -         */ -        virtual void add_worker(worker_node_t* worker) = 0; - -        /*! -         * Release all storage for this object. This will delete all contained -         * data and worker nodes and remove all dependency relationship and -         * resolve callbacks. -         * -         * The object will be restored to its newly constructed state. Will not -         * throw. -         */ -        virtual void clear() = 0; -    }; - -}} +enum auto_resolve_mode_t { +    AUTO_RESOLVE_OFF, +    AUTO_RESOLVE_ON_READ, +    AUTO_RESOLVE_ON_WRITE, +    AUTO_RESOLVE_ON_READ_WRITE +}; + +class UHD_API expert_container : private uhd::noncopyable, public node_retriever_t +{ +public: // Methods +    typedef std::shared_ptr<expert_container> sptr; + +    virtual ~expert_container(){}; + +    /*! +     * Return the name of this container +     */ +    virtual const std::string& get_name() const = 0; + +    /*! +     * Resolves all the nodes in this expert graph. +     * +     * Dependency analysis is performed on the graph and nodes +     * are resolved in a topologically sorted order to ensure +     * that no nodes receive stale data. +     * Nodes and their dependencies are resolved only if they are +     * dirty i.e. their contained values have changed since the +     * last resolve. +     * This call requires an acyclic expert graph. +     * +     * \param force If true then ignore dirty state and resolve all nodes +     * \throws uhd::runtime_error if graph cannot be resolved +     */ +    virtual void resolve_all(bool force = false) = 0; + +    /*! +     * Resolves all the nodes that depend on the specified node. +     * +     * Dependency analysis is performed on the graph and nodes +     * are resolved in a topologically sorted order to ensure +     * that no nodes receive stale data. +     * Nodes and their dependencies are resolved only if they are +     * dirty i.e. their contained values have changed since the +     * last resolve. +     * This call requires an acyclic expert graph. +     * +     * \param node_name Name of the node to start resolving from +     * \throws uhd::lookup_error if node_name not in container +     * \throws uhd::runtime_error if graph cannot be resolved +     * +     */ +    virtual void resolve_from(const std::string& node_name) = 0; + +    /*! +     * Resolves all the specified node and all of its dependencies. +     * +     * Dependency analysis is performed on the graph and nodes +     * are resolved in a topologically sorted order to ensure +     * that no nodes receive stale data. +     * Nodes and their dependencies are resolved only if they are +     * dirty i.e. their contained values have changed since the +     * last resolve. +     * This call requires an acyclic expert graph. +     * +     * \param node_name Name of the node to resolve +     * \throws uhd::lookup_error if node_name not in container +     * \throws uhd::runtime_error if graph cannot be resolved +     * +     */ +    virtual void resolve_to(const std::string& node_name) = 0; + +    /*! +     * Return a node retriever object for this container +     */ +    virtual const node_retriever_t& node_retriever() const = 0; + +    /*! +     * Returns a DOT (graph description language) representation +     * of the expert graph. The output has labels for the node +     * name, node type (data or worker) and the underlying +     * data type for each node. +     * +     */ +    virtual std::string to_dot() const = 0; + +    /*! +     * Runs several sanity checks on the underlying graph to +     * flag dependency issues. Outputs of the checks are +     * logged to the console so UHD_EXPERTS_VERBOSE_LOGGING +     * must be enabled to see the results +     * +     */ +    virtual void debug_audit() const = 0; + +private: +    /*! +     * Lookup a node with the specified name in the contained graph +     * +     * If the node is found, a reference to the node is returned. +     * If the node is not found, uhd::lookup_error is thrown +     * lookup can return a data or a worker node +     * \implements uhd::experts::node_retriever_t +     * +     * \param name Name of the node to find +     * +     */ +    virtual const dag_vertex_t& lookup(const std::string& name) const = 0; +    virtual dag_vertex_t& retrieve(const std::string& name) const     = 0; + +    /*! +     * expert_factory is a friend of expert_container and +     * handles all operations that change the structure of +     * the underlying dependency graph. +     * The expert_container instance owns all data and worker +     * nodes and is responsible for release storage on destruction. +     * However, the expert_factory allocates storage for the +     * node and passes them into the expert_container using the +     * following "protected" API calls. +     * +     */ +    friend class expert_factory; + +    /*! +     * Creates an empty instance of expert_container with the +     * specified name. +     * +     * \param name Name of the container +     */ +    static sptr make(const std::string& name); + +    /*! +     * Returns a reference to the resolver mutex. +     * +     * The resolver mutex guarantees that external operations +     * to data-nodes are serialized with resolves of this +     * container. +     * +     */ +    virtual boost::recursive_mutex& resolve_mutex() = 0; + +    /*! +     * Add a data node to the expert graph +     * +     * \param data_node Pointer to a fully constructed data node object +     * \resolve_mode Auto resolve options: Choose from "disabled" and resolve on "read", +     * "write" or "both" \throws uhd::runtime_error if node already exists or is of a +     * wrong type (recoverable) \throws uhd::assertion_error for other failures +     * (unrecoverable. will clear the graph) +     * +     */ +    virtual void add_data_node( +        dag_vertex_t* data_node, auto_resolve_mode_t resolve_mode = AUTO_RESOLVE_OFF) = 0; + +    /*! +     * Add a worker node to the expert graph +     * +     * \param worker Pointer to a fully constructed worker object +     * \throws uhd::runtime_error if worker already exists or is of a wrong type +     * (recoverable) \throws uhd::assertion_error for other failures (unrecoverable. will +     * clear the graph) +     * +     */ +    virtual void add_worker(worker_node_t* worker) = 0; + +    /*! +     * Release all storage for this object. This will delete all contained +     * data and worker nodes and remove all dependency relationship and +     * resolve callbacks. +     * +     * The object will be restored to its newly constructed state. Will not +     * throw. +     */ +    virtual void clear() = 0; +}; + +}} // namespace uhd::experts  #endif /* INCLUDED_UHD_EXPERTS_EXPERT_CONTAINER_HPP */ diff --git a/host/lib/include/uhdlib/experts/expert_factory.hpp b/host/lib/include/uhdlib/experts/expert_factory.hpp index 9e07aa47f..47308d046 100644 --- a/host/lib/include/uhdlib/experts/expert_factory.hpp +++ b/host/lib/include/uhdlib/experts/expert_factory.hpp @@ -18,311 +18,333 @@  namespace uhd { namespace experts { +/*! + * expert_factory is a friend of expert_container and + * handles all operations to create and change the structure of + * the an expert container. + * The expert_factory allocates storage for the nodes in the + * expert_container and passes allocated objects to the container + * using private APIs. The expert_container instance owns all + * data and workernodes and is responsible for releasing their + * storage on destruction. + * + */ +class UHD_API expert_factory : public uhd::noncopyable +{ +public:      /*! -     * expert_factory is a friend of expert_container and -     * handles all operations to create and change the structure of -     * the an expert container. -     * The expert_factory allocates storage for the nodes in the -     * expert_container and passes allocated objects to the container -     * using private APIs. The expert_container instance owns all -     * data and workernodes and is responsible for releasing their -     * storage on destruction. +     * Creates an empty instance of expert_container with the +     * specified name.       * +     * \param name Name of the container       */ -    class UHD_API expert_factory : public uhd::noncopyable { -    public: +    static expert_container::sptr create_container(const std::string& name); -        /*! -         * Creates an empty instance of expert_container with the -         * specified name. -         * -         * \param name Name of the container -         */ -        static expert_container::sptr create_container( -            const std::string& name -        ); - -        /*! -         * Add a data node to the expert graph. -         * -         * \param container A shared pointer to the container to add the node to -         * \param name The name of the data node -         * \param init_val The initial value of the data node -         * \param mode The auto resolve mode -         * -         * Requirements for data_t -         * - Must have a default constructor -         * - Must have a copy constructor -         * - Must have an assignment operator (=) -         * - Must have an equality operator (==) -         */ -        template<typename data_t> -        inline static void add_data_node( -            expert_container::sptr container, -            const std::string& name, -            const data_t& init_val, -            const auto_resolve_mode_t mode = AUTO_RESOLVE_OFF -        ) { -            container->add_data_node(new data_node_t<data_t>(name, init_val), mode); -        } +    /*! +     * Add a data node to the expert graph. +     * +     * \param container A shared pointer to the container to add the node to +     * \param name The name of the data node +     * \param init_val The initial value of the data node +     * \param mode The auto resolve mode +     * +     * Requirements for data_t +     * - Must have a default constructor +     * - Must have a copy constructor +     * - Must have an assignment operator (=) +     * - Must have an equality operator (==) +     */ +    template <typename data_t> +    inline static void add_data_node(expert_container::sptr container, +        const std::string& name, +        const data_t& init_val, +        const auto_resolve_mode_t mode = AUTO_RESOLVE_OFF) +    { +        container->add_data_node(new data_node_t<data_t>(name, init_val), mode); +    } -        /*! -         * Add a expert property to a property tree AND an expert graph -         * -         * \param container A shared pointer to the expert container to add the node to -         * \param subtree A shared pointer to subtree to add the property to -         * \param path The path of the property in the subtree -         * \param name The name of the data node in the expert graph -         * \param init_val The initial value of the data node -         * \param mode The auto resolve mode -         * -         * Requirements for data_t -         * - Must have a default constructor -         * - Must have a copy constructor -         * - Must have an assignment operator (=) -         * - Must have an equality operator (==) -         */ -        template<typename data_t> -        inline static property<data_t>& add_prop_node( -            expert_container::sptr container, -            property_tree::sptr subtree, -            const fs_path &path, -            const std::string& name, -            const data_t& init_val, -            const auto_resolve_mode_t mode = AUTO_RESOLVE_OFF -        ) { -            property<data_t>& prop = subtree->create<data_t>(path, property_tree::MANUAL_COERCE); -            data_node_t<data_t>* node_ptr = -                new data_node_t<data_t>(name, init_val, &container->resolve_mutex()); -            prop.set(init_val); -            prop.add_desired_subscriber(std::bind(&data_node_t<data_t>::commit, node_ptr, std::placeholders::_1)); -            prop.set_publisher(std::bind(&data_node_t<data_t>::retrieve, node_ptr)); -            container->add_data_node(node_ptr, mode); -            return prop; -        } +    /*! +     * Add a expert property to a property tree AND an expert graph +     * +     * \param container A shared pointer to the expert container to add the node to +     * \param subtree A shared pointer to subtree to add the property to +     * \param path The path of the property in the subtree +     * \param name The name of the data node in the expert graph +     * \param init_val The initial value of the data node +     * \param mode The auto resolve mode +     * +     * Requirements for data_t +     * - Must have a default constructor +     * - Must have a copy constructor +     * - Must have an assignment operator (=) +     * - Must have an equality operator (==) +     */ +    template <typename data_t> +    inline static property<data_t>& add_prop_node(expert_container::sptr container, +        property_tree::sptr subtree, +        const fs_path& path, +        const std::string& name, +        const data_t& init_val, +        const auto_resolve_mode_t mode = AUTO_RESOLVE_OFF) +    { +        property<data_t>& prop = +            subtree->create<data_t>(path, property_tree::MANUAL_COERCE); +        data_node_t<data_t>* node_ptr = +            new data_node_t<data_t>(name, init_val, &container->resolve_mutex()); +        prop.set(init_val); +        prop.add_desired_subscriber( +            std::bind(&data_node_t<data_t>::commit, node_ptr, std::placeholders::_1)); +        prop.set_publisher(std::bind(&data_node_t<data_t>::retrieve, node_ptr)); +        container->add_data_node(node_ptr, mode); +        return prop; +    } -        /*! -         * Add a expert property to a property tree AND an expert graph. -         * The property is registered with the path as the identifier for -         * both the property subtree and the expert container -         * -         * \param container A shared pointer to the expert container to add the node to -         * \param subtree A shared pointer to subtree to add the property to -         * \param path The path of the property in the subtree -         * \param init_val The initial value of the data node -         * \param mode The auto resolve mode -         * -         */ -        template<typename data_t> -        inline static property<data_t>& add_prop_node( -            expert_container::sptr container, -            property_tree::sptr subtree, -            const fs_path &path, -            const data_t& init_val, -            const auto_resolve_mode_t mode = AUTO_RESOLVE_OFF -        ) { -            return add_prop_node(container, subtree, path, path, init_val, mode); -        } +    /*! +     * Add a expert property to a property tree AND an expert graph. +     * The property is registered with the path as the identifier for +     * both the property subtree and the expert container +     * +     * \param container A shared pointer to the expert container to add the node to +     * \param subtree A shared pointer to subtree to add the property to +     * \param path The path of the property in the subtree +     * \param init_val The initial value of the data node +     * \param mode The auto resolve mode +     * +     */ +    template <typename data_t> +    inline static property<data_t>& add_prop_node(expert_container::sptr container, +        property_tree::sptr subtree, +        const fs_path& path, +        const data_t& init_val, +        const auto_resolve_mode_t mode = AUTO_RESOLVE_OFF) +    { +        return add_prop_node(container, subtree, path, path, init_val, mode); +    } -        /*! -         * Add a dual expert property to a property tree AND an expert graph. -         * A dual property is a desired and coerced value pair -         * -         * \param container A shared pointer to the expert container to add the node to -         * \param subtree A shared pointer to subtree to add the property to -         * \param path The path of the property in the subtree -         * \param desired_name The name of the desired data node in the expert graph -         * \param desired_name The name of the coerced data node in the expert graph -         * \param init_val The initial value of both the data nodes -         * \param mode The auto resolve mode -         * -         * Requirements for data_t -         * - Must have a default constructor -         * - Must have a copy constructor -         * - Must have an assignment operator (=) -         * - Must have an equality operator (==) -         */ -        template<typename data_t> -        inline static property<data_t>& add_dual_prop_node( -            expert_container::sptr container, -            property_tree::sptr subtree, -            const fs_path &path, -            const std::string& desired_name, -            const std::string& coerced_name, -            const data_t& init_val, -            const auto_resolve_mode_t mode = AUTO_RESOLVE_OFF -        ) { -            bool auto_resolve_desired = (mode==AUTO_RESOLVE_ON_WRITE or mode==AUTO_RESOLVE_ON_READ_WRITE); -            bool auto_resolve_coerced = (mode==AUTO_RESOLVE_ON_READ or mode==AUTO_RESOLVE_ON_READ_WRITE); +    /*! +     * Add a dual expert property to a property tree AND an expert graph. +     * A dual property is a desired and coerced value pair +     * +     * \param container A shared pointer to the expert container to add the node to +     * \param subtree A shared pointer to subtree to add the property to +     * \param path The path of the property in the subtree +     * \param desired_name The name of the desired data node in the expert graph +     * \param desired_name The name of the coerced data node in the expert graph +     * \param init_val The initial value of both the data nodes +     * \param mode The auto resolve mode +     * +     * Requirements for data_t +     * - Must have a default constructor +     * - Must have a copy constructor +     * - Must have an assignment operator (=) +     * - Must have an equality operator (==) +     */ +    template <typename data_t> +    inline static property<data_t>& add_dual_prop_node(expert_container::sptr container, +        property_tree::sptr subtree, +        const fs_path& path, +        const std::string& desired_name, +        const std::string& coerced_name, +        const data_t& init_val, +        const auto_resolve_mode_t mode = AUTO_RESOLVE_OFF) +    { +        bool auto_resolve_desired = +            (mode == AUTO_RESOLVE_ON_WRITE or mode == AUTO_RESOLVE_ON_READ_WRITE); +        bool auto_resolve_coerced = +            (mode == AUTO_RESOLVE_ON_READ or mode == AUTO_RESOLVE_ON_READ_WRITE); -            property<data_t>& prop = subtree->create<data_t>(path, property_tree::MANUAL_COERCE); -            data_node_t<data_t>* desired_node_ptr = -                new data_node_t<data_t>(desired_name, init_val, &container->resolve_mutex()); -            data_node_t<data_t>* coerced_node_ptr = -                new data_node_t<data_t>(coerced_name, init_val, &container->resolve_mutex()); -            prop.set(init_val); -            prop.set_coerced(init_val); -            prop.add_desired_subscriber(std::bind(&data_node_t<data_t>::commit, desired_node_ptr, std::placeholders::_1)); -            prop.set_publisher(std::bind(&data_node_t<data_t>::retrieve, coerced_node_ptr)); +        property<data_t>& prop = +            subtree->create<data_t>(path, property_tree::MANUAL_COERCE); +        data_node_t<data_t>* desired_node_ptr = +            new data_node_t<data_t>(desired_name, init_val, &container->resolve_mutex()); +        data_node_t<data_t>* coerced_node_ptr = +            new data_node_t<data_t>(coerced_name, init_val, &container->resolve_mutex()); +        prop.set(init_val); +        prop.set_coerced(init_val); +        prop.add_desired_subscriber(std::bind( +            &data_node_t<data_t>::commit, desired_node_ptr, std::placeholders::_1)); +        prop.set_publisher(std::bind(&data_node_t<data_t>::retrieve, coerced_node_ptr)); -            container->add_data_node(desired_node_ptr, -                auto_resolve_desired ? AUTO_RESOLVE_ON_WRITE : AUTO_RESOLVE_OFF); -            container->add_data_node(coerced_node_ptr, -                auto_resolve_coerced ? AUTO_RESOLVE_ON_READ : AUTO_RESOLVE_OFF); -            return prop; -        } +        container->add_data_node(desired_node_ptr, +            auto_resolve_desired ? AUTO_RESOLVE_ON_WRITE : AUTO_RESOLVE_OFF); +        container->add_data_node(coerced_node_ptr, +            auto_resolve_coerced ? AUTO_RESOLVE_ON_READ : AUTO_RESOLVE_OFF); +        return prop; +    } -        /*! -         * Add a dual expert property to a property tree AND an expert graph. -         * A dual property is a desired and coerced value pair -         * The property is registered with path/desired as the desired node -         * name and path/coerced as the coerced node name -         * -         * \param container A shared pointer to the expert container to add the node to -         * \param subtree A shared pointer to subtree to add the property to -         * \param path The path of the property in the subtree -         * \param init_val The initial value of both the data nodes -         * \param mode The auto resolve mode -         * -         */ -        template<typename data_t> -        inline static property<data_t>& add_dual_prop_node( -            expert_container::sptr container, -            property_tree::sptr subtree, -            const fs_path &path, -            const data_t& init_val, -            const auto_resolve_mode_t mode = AUTO_RESOLVE_OFF -        ) { -            return add_dual_prop_node(container, subtree, path, path + "/desired", path + "/coerced", init_val, mode); -        } +    /*! +     * Add a dual expert property to a property tree AND an expert graph. +     * A dual property is a desired and coerced value pair +     * The property is registered with path/desired as the desired node +     * name and path/coerced as the coerced node name +     * +     * \param container A shared pointer to the expert container to add the node to +     * \param subtree A shared pointer to subtree to add the property to +     * \param path The path of the property in the subtree +     * \param init_val The initial value of both the data nodes +     * \param mode The auto resolve mode +     * +     */ +    template <typename data_t> +    inline static property<data_t>& add_dual_prop_node(expert_container::sptr container, +        property_tree::sptr subtree, +        const fs_path& path, +        const data_t& init_val, +        const auto_resolve_mode_t mode = AUTO_RESOLVE_OFF) +    { +        return add_dual_prop_node(container, +            subtree, +            path, +            path + "/desired", +            path + "/coerced", +            init_val, +            mode); +    } -        /*! -         * Add a worker node to the expert graph. -         * The expert_container owns and manages storage for the worker -         * -         * \tparam worker_t Data type of the worker class -         * -         * \param container A shared pointer to the container to add the node to -         * -         */ -        template<typename worker_t> -        inline static void add_worker_node( -            expert_container::sptr container -        ) { -            container->add_worker(new worker_t()); -        } +    /*! +     * Add a worker node to the expert graph. +     * The expert_container owns and manages storage for the worker +     * +     * \tparam worker_t Data type of the worker class +     * +     * \param container A shared pointer to the container to add the node to +     * +     */ +    template <typename worker_t> +    inline static void add_worker_node(expert_container::sptr container) +    { +        container->add_worker(new worker_t()); +    } -        /*! -         * Add a worker node to the expert graph. -         * The expert_container owns and manages storage for the worker -         * -         * \tparam worker_t Data type of the worker class -         * \tparam arg1_t Data type of the first argument to the constructor -         * \tparam ... -         * \tparam argN_t Data type of the Nth argument to the constructor -         * -         * \param container A shared pointer to the container to add the node to -         * \param arg1 First arg to ctor -         * \param ... -         * \param argN Nth arg to ctor -         * -         */ -        template<typename worker_t, typename arg1_t> -        inline static void add_worker_node( -            expert_container::sptr container, -            arg1_t const & arg1 -        ) { -            container->add_worker(new worker_t(arg1)); -        } +    /*! +     * Add a worker node to the expert graph. +     * The expert_container owns and manages storage for the worker +     * +     * \tparam worker_t Data type of the worker class +     * \tparam arg1_t Data type of the first argument to the constructor +     * \tparam ... +     * \tparam argN_t Data type of the Nth argument to the constructor +     * +     * \param container A shared pointer to the container to add the node to +     * \param arg1 First arg to ctor +     * \param ... +     * \param argN Nth arg to ctor +     * +     */ +    template <typename worker_t, typename arg1_t> +    inline static void add_worker_node( +        expert_container::sptr container, arg1_t const& arg1) +    { +        container->add_worker(new worker_t(arg1)); +    } -        template<typename worker_t, typename arg1_t, typename arg2_t> -        inline static void add_worker_node( -            expert_container::sptr container, -            arg1_t const & arg1, -            arg2_t const & arg2 -        ) { -            container->add_worker(new worker_t(arg1, arg2)); -        } +    template <typename worker_t, typename arg1_t, typename arg2_t> +    inline static void add_worker_node( +        expert_container::sptr container, arg1_t const& arg1, arg2_t const& arg2) +    { +        container->add_worker(new worker_t(arg1, arg2)); +    } -        template<typename worker_t, typename arg1_t, typename arg2_t, typename arg3_t> -        inline static void add_worker_node( -            expert_container::sptr container, -            arg1_t const & arg1, -            arg2_t const & arg2, -            arg3_t const & arg3 -        ) { -            container->add_worker(new worker_t(arg1, arg2, arg3)); -        } +    template <typename worker_t, typename arg1_t, typename arg2_t, typename arg3_t> +    inline static void add_worker_node(expert_container::sptr container, +        arg1_t const& arg1, +        arg2_t const& arg2, +        arg3_t const& arg3) +    { +        container->add_worker(new worker_t(arg1, arg2, arg3)); +    } -        template<typename worker_t, typename arg1_t, typename arg2_t, typename arg3_t, typename arg4_t> -        inline static void add_worker_node( -            expert_container::sptr container, -            arg1_t const & arg1, -            arg2_t const & arg2, -            arg3_t const & arg3, -            arg4_t const & arg4 -        ) { -            container->add_worker(new worker_t(arg1, arg2, arg3, arg4)); -        } +    template <typename worker_t, +        typename arg1_t, +        typename arg2_t, +        typename arg3_t, +        typename arg4_t> +    inline static void add_worker_node(expert_container::sptr container, +        arg1_t const& arg1, +        arg2_t const& arg2, +        arg3_t const& arg3, +        arg4_t const& arg4) +    { +        container->add_worker(new worker_t(arg1, arg2, arg3, arg4)); +    } -        template<typename worker_t, typename arg1_t, typename arg2_t, typename arg3_t, typename arg4_t, -                                    typename arg5_t> -        inline static void add_worker_node( -            expert_container::sptr container, -            arg1_t const & arg1, -            arg2_t const & arg2, -            arg3_t const & arg3, -            arg4_t const & arg4, -            arg5_t const & arg5 -        ) { -            container->add_worker(new worker_t(arg1, arg2, arg3, arg4, arg5)); -        } +    template <typename worker_t, +        typename arg1_t, +        typename arg2_t, +        typename arg3_t, +        typename arg4_t, +        typename arg5_t> +    inline static void add_worker_node(expert_container::sptr container, +        arg1_t const& arg1, +        arg2_t const& arg2, +        arg3_t const& arg3, +        arg4_t const& arg4, +        arg5_t const& arg5) +    { +        container->add_worker(new worker_t(arg1, arg2, arg3, arg4, arg5)); +    } -        template<typename worker_t, typename arg1_t, typename arg2_t, typename arg3_t, typename arg4_t, -                                    typename arg5_t, typename arg6_t> -        inline static void add_worker_node( -            expert_container::sptr container, -            arg1_t const & arg1, -            arg2_t const & arg2, -            arg3_t const & arg3, -            arg4_t const & arg4, -            arg5_t const & arg5, -            arg6_t const & arg6 -        ) { -            container->add_worker(new worker_t(arg1, arg2, arg3, arg4, arg5, arg6)); -        } +    template <typename worker_t, +        typename arg1_t, +        typename arg2_t, +        typename arg3_t, +        typename arg4_t, +        typename arg5_t, +        typename arg6_t> +    inline static void add_worker_node(expert_container::sptr container, +        arg1_t const& arg1, +        arg2_t const& arg2, +        arg3_t const& arg3, +        arg4_t const& arg4, +        arg5_t const& arg5, +        arg6_t const& arg6) +    { +        container->add_worker(new worker_t(arg1, arg2, arg3, arg4, arg5, arg6)); +    } -        template<typename worker_t, typename arg1_t, typename arg2_t, typename arg3_t, typename arg4_t, -                                    typename arg5_t, typename arg6_t, typename arg7_t> -        inline static void add_worker_node( -            expert_container::sptr container, -            arg1_t const & arg1, -            arg2_t const & arg2, -            arg3_t const & arg3, -            arg4_t const & arg4, -            arg5_t const & arg5, -            arg6_t const & arg6, -            arg7_t const & arg7 -        ) { -            container->add_worker(new worker_t(arg1, arg2, arg3, arg4, arg5, arg6, arg7)); -        } +    template <typename worker_t, +        typename arg1_t, +        typename arg2_t, +        typename arg3_t, +        typename arg4_t, +        typename arg5_t, +        typename arg6_t, +        typename arg7_t> +    inline static void add_worker_node(expert_container::sptr container, +        arg1_t const& arg1, +        arg2_t const& arg2, +        arg3_t const& arg3, +        arg4_t const& arg4, +        arg5_t const& arg5, +        arg6_t const& arg6, +        arg7_t const& arg7) +    { +        container->add_worker(new worker_t(arg1, arg2, arg3, arg4, arg5, arg6, arg7)); +    } -        template<typename worker_t, typename arg1_t, typename arg2_t, typename arg3_t, typename arg4_t, -                                    typename arg5_t, typename arg6_t, typename arg7_t, typename arg8_t> -        inline static void add_worker_node( -            expert_container::sptr container, -            arg1_t const & arg1, -            arg2_t const & arg2, -            arg3_t const & arg3, -            arg4_t const & arg4, -            arg5_t const & arg5, -            arg6_t const & arg6, -            arg7_t const & arg7, -            arg7_t const & arg8 -        ) { -            container->add_worker(new worker_t(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)); -        } -    }; -}} +    template <typename worker_t, +        typename arg1_t, +        typename arg2_t, +        typename arg3_t, +        typename arg4_t, +        typename arg5_t, +        typename arg6_t, +        typename arg7_t, +        typename arg8_t> +    inline static void add_worker_node(expert_container::sptr container, +        arg1_t const& arg1, +        arg2_t const& arg2, +        arg3_t const& arg3, +        arg4_t const& arg4, +        arg5_t const& arg5, +        arg6_t const& arg6, +        arg7_t const& arg7, +        arg7_t const& arg8) +    { +        container->add_worker( +            new worker_t(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)); +    } +}; +}} // namespace uhd::experts  #endif /* INCLUDED_UHD_EXPERTS_EXPERT_FACTORY_HPP */ diff --git a/host/lib/include/uhdlib/experts/expert_nodes.hpp b/host/lib/include/uhdlib/experts/expert_nodes.hpp index 665c0e579..b9a0f57bd 100644 --- a/host/lib/include/uhdlib/experts/expert_nodes.hpp +++ b/host/lib/include/uhdlib/experts/expert_nodes.hpp @@ -10,464 +10,544 @@  #include <uhd/config.hpp>  #include <uhd/exception.hpp> +#include <uhd/types/time_spec.hpp>  #include <uhd/utils/dirty_tracked.hpp>  #include <uhd/utils/noncopyable.hpp> -#include <uhd/types/time_spec.hpp> -#include <functional> -#include <boost/thread/recursive_mutex.hpp> -#include <boost/thread.hpp> +#include <stdint.h>  #include <boost/core/demangle.hpp> -#include <memory> +#include <boost/thread.hpp> +#include <boost/thread/recursive_mutex.hpp> +#include <functional>  #include <list> -#include <stdint.h> +#include <memory>  namespace uhd { namespace experts { -    enum node_class_t  { CLASS_WORKER, CLASS_DATA, CLASS_PROPERTY }; -    enum node_access_t { ACCESS_READER, ACCESS_WRITER }; -    enum node_author_t { AUTHOR_NONE, AUTHOR_USER, AUTHOR_EXPERT }; - -    /*!--------------------------------------------------------- -     * class dag_vertex_t -     * -     * This serves as the base class for all nodes in the expert -     * graph. Data nodes and workers are derived from this class. -     * --------------------------------------------------------- -     */ -    class dag_vertex_t : private uhd::noncopyable { -    public: -        typedef std::function<void(std::string)> callback_func_t; - -        virtual ~dag_vertex_t() {} - -        // Getters for basic info about the node -        inline node_class_t get_class() const { -            return _class; -        } - -        inline const std::string& get_name() const { -            return _name; -        } - -        virtual const std::string& get_dtype() const = 0; - -        virtual std::string to_string() const = 0; - -        // Graph resolution specific -        virtual bool is_dirty() const = 0; -        virtual void mark_clean() = 0; -        virtual void resolve() = 0; - -        // External callbacks -        virtual void set_write_callback(const callback_func_t& func) = 0; -        virtual bool has_write_callback() const = 0; -        virtual void clear_write_callback() = 0; -        virtual void set_read_callback(const callback_func_t& func) = 0; -        virtual bool has_read_callback() const = 0; -        virtual void clear_read_callback() = 0; - -    protected: -        dag_vertex_t(const node_class_t c, const std::string& n): -            _class(c), _name(n) {} - -    private: -        const node_class_t  _class; -        const std::string   _name; -    }; - -    class data_node_printer { -    public: -        //Generic implementation -        template<typename data_t> -        static std::string print(const data_t& val) { -            std::ostringstream os; -            os << val; -            return os.str(); -        } - -        static std::string print(const uint8_t& val) { -            std::ostringstream os; -            os << int(val); -            return os.str(); -        } - -        static std::string print(const time_spec_t time) { -            std::ostringstream os; -            os << time.get_real_secs(); -            return os.str(); -        } -    }; - -    /*!--------------------------------------------------------- -     * class data_node_t -     * -     * The data node class hold a passive piece of data in the -     * expert graph. A data node is clean if its underlying data -     * is clean. Access to the underlying data is provided using -     * two methods: -     * 1. Special accessor classes (for R/W enforcement) -     * 2. External clients (via commit and retrieve). This access -     *    is protected by the callback mutex. -     * -     * Requirements for data_t -     * - Must have a default constructor -     * - Must have a copy constructor -     * - Must have an assignment operator (=) -     * - Must have an equality operator (==) -     * --------------------------------------------------------- -     */ -    template<typename data_t> -    class data_node_t : public dag_vertex_t { -    public: -        // A data_node_t instance can have a type of CLASS_DATA or CLASS_PROPERTY -        // In general a data node is a property if it can be accessed and modified -        // from the outside world (of experts) using read and write callbacks. We -        // assume that if a callback mutex is passed into the data node that it will -        // be accessed from the outside and tag the data node as a PROPERTY. -        data_node_t(const std::string& name, boost::recursive_mutex* mutex = NULL) : -            dag_vertex_t(mutex?CLASS_PROPERTY:CLASS_DATA, name), _callback_mutex(mutex), _data(), _author(AUTHOR_NONE) {} - -        data_node_t(const std::string& name, const data_t& value, boost::recursive_mutex* mutex = NULL) : -            dag_vertex_t(mutex?CLASS_PROPERTY:CLASS_DATA, name), _callback_mutex(mutex), _data(value), _author(AUTHOR_NONE) {} - -        // Basic info -        virtual const std::string& get_dtype() const { -            static const std::string dtype( -                boost::core::demangle(typeid(data_t).name())); -            return dtype; -        } - -        virtual std::string to_string() const { -            return data_node_printer::print(get()); -        } - -        inline node_author_t get_author() const { -            return _author; -        } - -        // Graph resolution specific -        virtual bool is_dirty() const { -            return _data.is_dirty(); -        } - -        virtual void mark_clean() { -            _data.mark_clean(); -        } - -        void resolve() { -            //NOP -        } - -        // Data node specific setters and getters (for the framework) -        void set(const data_t& value) { -            _data = value; -            _author = AUTHOR_EXPERT; -        } - -        const data_t& get() const { -            return _data; -        } - -        // Data node specific setters and getters (for external entities) -        void commit(const data_t& value) { -            if (_callback_mutex == NULL) throw uhd::assertion_error("node " + get_name() + " is missing the callback mutex"); -            boost::lock_guard<boost::recursive_mutex> lock(*_callback_mutex); -            set(value); -            _author = AUTHOR_USER; -            if (is_dirty() and has_write_callback()) { -                _wr_callback(std::string(get_name()));  //Put the name on the stack before calling -            } -        } - -        const data_t retrieve() const { -            if (_callback_mutex == NULL) throw uhd::assertion_error("node " + get_name() + " is missing the callback mutex"); -            boost::lock_guard<boost::recursive_mutex> lock(*_callback_mutex); -            if (has_read_callback()) { -                _rd_callback(std::string(get_name())); -            } -            return get(); -        } - -    private: -        // External callbacks -        virtual void set_write_callback(const callback_func_t& func) { -            _wr_callback = func; -        } - -        virtual bool has_write_callback() const { -            return bool(_wr_callback); -        } - -        virtual void clear_write_callback() { -            _wr_callback = nullptr; -        } - -        virtual void set_read_callback(const callback_func_t& func) { -            _rd_callback = func; -        } - -        virtual bool has_read_callback() const { -            return bool(_rd_callback); -        } - -        virtual void clear_read_callback() { -            _rd_callback = nullptr; -        } - -        boost::recursive_mutex* _callback_mutex; -        callback_func_t         _rd_callback; -        callback_func_t         _wr_callback; -        dirty_tracked<data_t>   _data; -        node_author_t           _author; -    }; - -    /*!--------------------------------------------------------- -     * class node_retriever_t -     * -     * Node storage is managed by a framework class so we need -     * and interface to find and retrieve data nodes to associate -     * with accessors. -     * --------------------------------------------------------- -     */ -    class node_retriever_t { -    public: -        virtual ~node_retriever_t() {} -        virtual const dag_vertex_t& lookup(const std::string& name) const = 0; -    private: -        friend class data_accessor_t; -        virtual dag_vertex_t& retrieve(const std::string& name) const = 0; -    }; - -    /*!--------------------------------------------------------- -     * class data_accessor_t -     * -     * Accessors provide protected access to data nodes and help -     * establish dependency relationships. -     * --------------------------------------------------------- -     */ -    class data_accessor_t { -    public: -        virtual ~data_accessor_t() {} - -        virtual bool is_reader() const = 0; -        virtual bool is_writer() const = 0; -        virtual dag_vertex_t& node() const = 0; -    protected: -        data_accessor_t(const node_retriever_t& r, const std::string& n): -            _vertex(r.retrieve(n)) {} -        dag_vertex_t& _vertex; -    }; - -    template<typename data_t> -    class data_accessor_base : public data_accessor_t { -    public: -        virtual ~data_accessor_base() {} - -        virtual bool is_reader() const { -            return _access == ACCESS_READER; -        } - -        virtual bool is_writer() const { -            return _access == ACCESS_WRITER; -        } - -        inline bool is_dirty() const { -            return _datanode->is_dirty(); -        } - -        inline node_class_t get_class() const { -            return _datanode->get_class(); -        } - -        inline node_author_t get_author() const { -            return _datanode->get_author(); -        } - -    protected: -        data_accessor_base( -            const node_retriever_t& r, const std::string& n, const node_access_t a) : -                data_accessor_t(r, n), _datanode(NULL), _access(a) -        { -            _datanode = dynamic_cast< data_node_t<data_t>* >(&node()); -            if (_datanode == NULL) { -                throw uhd::type_error("Expected data type for node " + n + -                                      " was " + boost::core::demangle(typeid(data_t).name()) + -                                      " but got " + node().get_dtype()); -            } -        } - -        data_node_t<data_t>*    _datanode; -        const node_access_t     _access; - -    private: -        virtual dag_vertex_t& node() const { -            return _vertex; -        } -    }; - -    /*!--------------------------------------------------------- -     * class data_reader_t -     * -     * Accessor to read the value of a data node and to establish -     * a data node => worker node dependency -     * --------------------------------------------------------- -     */ -    template<typename data_t> -    class data_reader_t : public data_accessor_base<data_t> { -    public: -        data_reader_t(const node_retriever_t& retriever, const std::string& node) : -            data_accessor_base<data_t>( -                retriever, node, ACCESS_READER) {} - -        inline const data_t& get() const { -            return data_accessor_base<data_t>::_datanode->get(); -        } - -        inline operator const data_t&() const { -            return get(); -        } - -        inline bool operator==(const data_t& rhs) { -            return get() == rhs; -        } - -        inline bool operator!=(const data_t& rhs) { -            return !(get() == rhs); -        } -    }; - -    /*!--------------------------------------------------------- -     * class data_reader_t -     * -     * Accessor to read and write the value of a data node and -     * to establish a worker node => data node dependency -     * --------------------------------------------------------- -     */ -    template<typename data_t> -    class data_writer_t : public data_accessor_base<data_t> { -    public: -        data_writer_t(const node_retriever_t& retriever, const std::string& node) : -            data_accessor_base<data_t>( -                retriever, node, ACCESS_WRITER) {} - -        inline const data_t& get() const { -            return data_accessor_base<data_t>::_datanode->get(); -        } - -        inline operator const data_t&() const { -            return get(); -        } - -        inline bool operator==(const data_t& rhs) { -            return get() == rhs; -        } - -        inline bool operator!=(const data_t& rhs) { -            return !(get() == rhs); -        } - -        inline void set(const data_t& value) { -            data_accessor_base<data_t>::_datanode->set(value); -        } - -        inline data_writer_t<data_t>& operator=(const data_t& value) { -            set(value); -            return *this; -        } - -        inline data_writer_t<data_t>& operator=(const data_writer_t<data_t>& value) { -            set(value.get()); -            return *this; -        } +enum node_class_t { CLASS_WORKER, CLASS_DATA, CLASS_PROPERTY }; +enum node_access_t { ACCESS_READER, ACCESS_WRITER }; +enum node_author_t { AUTHOR_NONE, AUTHOR_USER, AUTHOR_EXPERT }; + +/*!--------------------------------------------------------- + * class dag_vertex_t + * + * This serves as the base class for all nodes in the expert + * graph. Data nodes and workers are derived from this class. + * --------------------------------------------------------- + */ +class dag_vertex_t : private uhd::noncopyable +{ +public: +    typedef std::function<void(std::string)> callback_func_t; + +    virtual ~dag_vertex_t() {} + +    // Getters for basic info about the node +    inline node_class_t get_class() const +    { +        return _class; +    } + +    inline const std::string& get_name() const +    { +        return _name; +    } + +    virtual const std::string& get_dtype() const = 0; + +    virtual std::string to_string() const = 0; + +    // Graph resolution specific +    virtual bool is_dirty() const = 0; +    virtual void mark_clean()     = 0; +    virtual void resolve()        = 0; + +    // External callbacks +    virtual void set_write_callback(const callback_func_t& func) = 0; +    virtual bool has_write_callback() const                      = 0; +    virtual void clear_write_callback()                          = 0; +    virtual void set_read_callback(const callback_func_t& func)  = 0; +    virtual bool has_read_callback() const                       = 0; +    virtual void clear_read_callback()                           = 0; + +protected: +    dag_vertex_t(const node_class_t c, const std::string& n) : _class(c), _name(n) {} + +private: +    const node_class_t _class; +    const std::string _name;  }; -    /*!--------------------------------------------------------- -     * class worker_node_t -     * -     * A node class to implement a function that consumes -     * zero or more input data nodes and emits zero or more output -     * data nodes. The worker can also operate on other non-expert -     * interfaces because worker_node_t is abstract and the client -     * is required to implement the "resolve" method in a subclass. -     * --------------------------------------------------------- -     */ -    class worker_node_t : public dag_vertex_t { -    public: -        worker_node_t(const std::string& name) : -            dag_vertex_t(CLASS_WORKER, name) {} - -        // Worker node specific -        std::list<std::string> get_inputs() const { -            std::list<std::string> retval; -            for(data_accessor_t* acc:  _inputs) { -                retval.push_back(acc->node().get_name()); -            } -            return retval; -        } - -        std::list<std::string> get_outputs() const { -            std::list<std::string> retval; -            for(data_accessor_t* acc:  _outputs) { -                retval.push_back(acc->node().get_name()); -            } -            return retval; -        } - -    protected: -        // This function is used to bind data accessors -        // to this worker. Accessors can be read/write -        // and the binding will ensure proper dependency -        // handling. -        void bind_accessor(data_accessor_t& accessor) { -            if (accessor.is_reader()) { -                _inputs.push_back(&accessor); -            } else if (accessor.is_writer()) { -                _outputs.push_back(&accessor); -            } else { -                throw uhd::assertion_error("Invalid accessor type"); -            } -        } +class data_node_printer +{ +public: +    // Generic implementation +    template <typename data_t> +    static std::string print(const data_t& val) +    { +        std::ostringstream os; +        os << val; +        return os.str(); +    } + +    static std::string print(const uint8_t& val) +    { +        std::ostringstream os; +        os << int(val); +        return os.str(); +    } + +    static std::string print(const time_spec_t time) +    { +        std::ostringstream os; +        os << time.get_real_secs(); +        return os.str(); +    } +}; -    private: -        // Graph resolution specific -        virtual bool is_dirty() const { -            bool inputs_dirty = false; -            for(data_accessor_t* acc:  _inputs) { -                inputs_dirty |= acc->node().is_dirty(); -            } -            return inputs_dirty; -        } +/*!--------------------------------------------------------- + * class data_node_t + * + * The data node class hold a passive piece of data in the + * expert graph. A data node is clean if its underlying data + * is clean. Access to the underlying data is provided using + * two methods: + * 1. Special accessor classes (for R/W enforcement) + * 2. External clients (via commit and retrieve). This access + *    is protected by the callback mutex. + * + * Requirements for data_t + * - Must have a default constructor + * - Must have a copy constructor + * - Must have an assignment operator (=) + * - Must have an equality operator (==) + * --------------------------------------------------------- + */ +template <typename data_t> +class data_node_t : public dag_vertex_t +{ +public: +    // A data_node_t instance can have a type of CLASS_DATA or CLASS_PROPERTY +    // In general a data node is a property if it can be accessed and modified +    // from the outside world (of experts) using read and write callbacks. We +    // assume that if a callback mutex is passed into the data node that it will +    // be accessed from the outside and tag the data node as a PROPERTY. +    data_node_t(const std::string& name, boost::recursive_mutex* mutex = NULL) +        : dag_vertex_t(mutex ? CLASS_PROPERTY : CLASS_DATA, name) +        , _callback_mutex(mutex) +        , _data() +        , _author(AUTHOR_NONE) +    { +    } + +    data_node_t(const std::string& name, +        const data_t& value, +        boost::recursive_mutex* mutex = NULL) +        : dag_vertex_t(mutex ? CLASS_PROPERTY : CLASS_DATA, name) +        , _callback_mutex(mutex) +        , _data(value) +        , _author(AUTHOR_NONE) +    { +    } + +    // Basic info +    virtual const std::string& get_dtype() const +    { +        static const std::string dtype(boost::core::demangle(typeid(data_t).name())); +        return dtype; +    } + +    virtual std::string to_string() const +    { +        return data_node_printer::print(get()); +    } + +    inline node_author_t get_author() const +    { +        return _author; +    } + +    // Graph resolution specific +    virtual bool is_dirty() const +    { +        return _data.is_dirty(); +    } + +    virtual void mark_clean() +    { +        _data.mark_clean(); +    } + +    void resolve() +    { +        // NOP +    } + +    // Data node specific setters and getters (for the framework) +    void set(const data_t& value) +    { +        _data   = value; +        _author = AUTHOR_EXPERT; +    } + +    const data_t& get() const +    { +        return _data; +    } + +    // Data node specific setters and getters (for external entities) +    void commit(const data_t& value) +    { +        if (_callback_mutex == NULL) +            throw uhd::assertion_error( +                "node " + get_name() + " is missing the callback mutex"); +        boost::lock_guard<boost::recursive_mutex> lock(*_callback_mutex); +        set(value); +        _author = AUTHOR_USER; +        if (is_dirty() and has_write_callback()) { +            _wr_callback( +                std::string(get_name())); // Put the name on the stack before calling +        } +    } + +    const data_t retrieve() const +    { +        if (_callback_mutex == NULL) +            throw uhd::assertion_error( +                "node " + get_name() + " is missing the callback mutex"); +        boost::lock_guard<boost::recursive_mutex> lock(*_callback_mutex); +        if (has_read_callback()) { +            _rd_callback(std::string(get_name())); +        } +        return get(); +    } + +private: +    // External callbacks +    virtual void set_write_callback(const callback_func_t& func) +    { +        _wr_callback = func; +    } + +    virtual bool has_write_callback() const +    { +        return bool(_wr_callback); +    } + +    virtual void clear_write_callback() +    { +        _wr_callback = nullptr; +    } + +    virtual void set_read_callback(const callback_func_t& func) +    { +        _rd_callback = func; +    } + +    virtual bool has_read_callback() const +    { +        return bool(_rd_callback); +    } + +    virtual void clear_read_callback() +    { +        _rd_callback = nullptr; +    } + +    boost::recursive_mutex* _callback_mutex; +    callback_func_t _rd_callback; +    callback_func_t _wr_callback; +    dirty_tracked<data_t> _data; +    node_author_t _author; +}; -        virtual void mark_clean() { -            for(data_accessor_t* acc:  _inputs) { -                acc->node().mark_clean(); -            } -        } +/*!--------------------------------------------------------- + * class node_retriever_t + * + * Node storage is managed by a framework class so we need + * and interface to find and retrieve data nodes to associate + * with accessors. + * --------------------------------------------------------- + */ +class node_retriever_t +{ +public: +    virtual ~node_retriever_t() {} +    virtual const dag_vertex_t& lookup(const std::string& name) const = 0; + +private: +    friend class data_accessor_t; +    virtual dag_vertex_t& retrieve(const std::string& name) const = 0; +}; -        virtual void resolve() = 0; +/*!--------------------------------------------------------- + * class data_accessor_t + * + * Accessors provide protected access to data nodes and help + * establish dependency relationships. + * --------------------------------------------------------- + */ +class data_accessor_t +{ +public: +    virtual ~data_accessor_t() {} + +    virtual bool is_reader() const     = 0; +    virtual bool is_writer() const     = 0; +    virtual dag_vertex_t& node() const = 0; + +protected: +    data_accessor_t(const node_retriever_t& r, const std::string& n) +        : _vertex(r.retrieve(n)) +    { +    } +    dag_vertex_t& _vertex; +}; -        // Basic type info -        virtual const std::string& get_dtype() const { -            static const std::string dtype = "<worker>"; -            return dtype; -        } +template <typename data_t> +class data_accessor_base : public data_accessor_t +{ +public: +    virtual ~data_accessor_base() {} + +    virtual bool is_reader() const +    { +        return _access == ACCESS_READER; +    } + +    virtual bool is_writer() const +    { +        return _access == ACCESS_WRITER; +    } + +    inline bool is_dirty() const +    { +        return _datanode->is_dirty(); +    } + +    inline node_class_t get_class() const +    { +        return _datanode->get_class(); +    } + +    inline node_author_t get_author() const +    { +        return _datanode->get_author(); +    } + +protected: +    data_accessor_base( +        const node_retriever_t& r, const std::string& n, const node_access_t a) +        : data_accessor_t(r, n), _datanode(NULL), _access(a) +    { +        _datanode = dynamic_cast<data_node_t<data_t>*>(&node()); +        if (_datanode == NULL) { +            throw uhd::type_error("Expected data type for node " + n + " was " +                                  + boost::core::demangle(typeid(data_t).name()) +                                  + " but got " + node().get_dtype()); +        } +    } + +    data_node_t<data_t>* _datanode; +    const node_access_t _access; + +private: +    virtual dag_vertex_t& node() const +    { +        return _vertex; +    } +}; -        virtual std::string to_string() const { -            return "<worker>"; -        } +/*!--------------------------------------------------------- + * class data_reader_t + * + * Accessor to read the value of a data node and to establish + * a data node => worker node dependency + * --------------------------------------------------------- + */ +template <typename data_t> +class data_reader_t : public data_accessor_base<data_t> +{ +public: +    data_reader_t(const node_retriever_t& retriever, const std::string& node) +        : data_accessor_base<data_t>(retriever, node, ACCESS_READER) +    { +    } + +    inline const data_t& get() const +    { +        return data_accessor_base<data_t>::_datanode->get(); +    } + +    inline operator const data_t&() const +    { +        return get(); +    } + +    inline bool operator==(const data_t& rhs) +    { +        return get() == rhs; +    } + +    inline bool operator!=(const data_t& rhs) +    { +        return !(get() == rhs); +    } +}; -        // Workers don't have callbacks so implement stubs -        virtual void set_write_callback(const callback_func_t&) {} -        virtual bool has_write_callback() const { return false; } -        virtual void clear_write_callback() {} -        virtual void set_read_callback(const callback_func_t&) {} -        virtual bool has_read_callback() const { return false; } -        virtual void clear_read_callback() {} +/*!--------------------------------------------------------- + * class data_reader_t + * + * Accessor to read and write the value of a data node and + * to establish a worker node => data node dependency + * --------------------------------------------------------- + */ +template <typename data_t> +class data_writer_t : public data_accessor_base<data_t> +{ +public: +    data_writer_t(const node_retriever_t& retriever, const std::string& node) +        : data_accessor_base<data_t>(retriever, node, ACCESS_WRITER) +    { +    } + +    inline const data_t& get() const +    { +        return data_accessor_base<data_t>::_datanode->get(); +    } + +    inline operator const data_t&() const +    { +        return get(); +    } + +    inline bool operator==(const data_t& rhs) +    { +        return get() == rhs; +    } + +    inline bool operator!=(const data_t& rhs) +    { +        return !(get() == rhs); +    } + +    inline void set(const data_t& value) +    { +        data_accessor_base<data_t>::_datanode->set(value); +    } + +    inline data_writer_t<data_t>& operator=(const data_t& value) +    { +        set(value); +        return *this; +    } + +    inline data_writer_t<data_t>& operator=(const data_writer_t<data_t>& value) +    { +        set(value.get()); +        return *this; +    } +}; -        std::list<data_accessor_t*> _inputs; -        std::list<data_accessor_t*> _outputs; -    }; +/*!--------------------------------------------------------- + * class worker_node_t + * + * A node class to implement a function that consumes + * zero or more input data nodes and emits zero or more output + * data nodes. The worker can also operate on other non-expert + * interfaces because worker_node_t is abstract and the client + * is required to implement the "resolve" method in a subclass. + * --------------------------------------------------------- + */ +class worker_node_t : public dag_vertex_t +{ +public: +    worker_node_t(const std::string& name) : dag_vertex_t(CLASS_WORKER, name) {} + +    // Worker node specific +    std::list<std::string> get_inputs() const +    { +        std::list<std::string> retval; +        for (data_accessor_t* acc : _inputs) { +            retval.push_back(acc->node().get_name()); +        } +        return retval; +    } + +    std::list<std::string> get_outputs() const +    { +        std::list<std::string> retval; +        for (data_accessor_t* acc : _outputs) { +            retval.push_back(acc->node().get_name()); +        } +        return retval; +    } + +protected: +    // This function is used to bind data accessors +    // to this worker. Accessors can be read/write +    // and the binding will ensure proper dependency +    // handling. +    void bind_accessor(data_accessor_t& accessor) +    { +        if (accessor.is_reader()) { +            _inputs.push_back(&accessor); +        } else if (accessor.is_writer()) { +            _outputs.push_back(&accessor); +        } else { +            throw uhd::assertion_error("Invalid accessor type"); +        } +    } + +private: +    // Graph resolution specific +    virtual bool is_dirty() const +    { +        bool inputs_dirty = false; +        for (data_accessor_t* acc : _inputs) { +            inputs_dirty |= acc->node().is_dirty(); +        } +        return inputs_dirty; +    } + +    virtual void mark_clean() +    { +        for (data_accessor_t* acc : _inputs) { +            acc->node().mark_clean(); +        } +    } + +    virtual void resolve() = 0; + +    // Basic type info +    virtual const std::string& get_dtype() const +    { +        static const std::string dtype = "<worker>"; +        return dtype; +    } + +    virtual std::string to_string() const +    { +        return "<worker>"; +    } + +    // Workers don't have callbacks so implement stubs +    virtual void set_write_callback(const callback_func_t&) {} +    virtual bool has_write_callback() const +    { +        return false; +    } +    virtual void clear_write_callback() {} +    virtual void set_read_callback(const callback_func_t&) {} +    virtual bool has_read_callback() const +    { +        return false; +    } +    virtual void clear_read_callback() {} + +    std::list<data_accessor_t*> _inputs; +    std::list<data_accessor_t*> _outputs; +}; -}} +}} // namespace uhd::experts  #endif /* INCLUDED_UHD_EXPERTS_EXPERT_NODE_HPP */ diff --git a/host/lib/include/uhdlib/rfnoc/async_msg.hpp b/host/lib/include/uhdlib/rfnoc/async_msg.hpp index 8abdb27b8..988801dc3 100644 --- a/host/lib/include/uhdlib/rfnoc/async_msg.hpp +++ b/host/lib/include/uhdlib/rfnoc/async_msg.hpp @@ -8,78 +8,80 @@  #define INCLUDED_UHD_RFNOC_ASYNC_MSG_HPP  #include <uhd/config.hpp> -#include <uhd/types/time_spec.hpp>  #include <uhd/types/sid.hpp> +#include <uhd/types/time_spec.hpp>  #include <vector>  namespace uhd { namespace rfnoc { -    /*! -     * Async message. -     */ -    struct async_msg_t -    { -        //! Has time? -        bool has_time_spec; - -        //! When the async event occurred. -        time_spec_t time_spec; +/*! + * Async message. + */ +struct async_msg_t +{ +    //! Has time? +    bool has_time_spec; -        /*! -         * The type of event for a receive async message call. -         */ -        enum event_code_t { -            //! Nothing happened. -            EVENT_CODE_NONE = 0x00, -            //! A burst was successfully transmitted. -            EVENT_CODE_BURST_ACK  = 0x1, -            //! An internal send buffer has emptied. -            EVENT_CODE_UNDERFLOW  = 0x2, -            //! Same. We use the terms 'underrun' and 'underflow' interchangeably. -            EVENT_CODE_UNDERRUN  = EVENT_CODE_UNDERFLOW, -            //! Packet loss or reordering between source and destination, -            //  at start of burst (i.e. the first packet after an EOB packet -            //  had the wrong sequence number). -            EVENT_CODE_SEQ_ERROR  = 0x4, -            //! Like EVENT_CODE_SEQ_ERROR, but within a burst (i.e., any packet -            //  other than the first packet had an error) -            EVENT_CODE_SEQ_ERROR_IN_BURST  = 0x20, -            //! Data packet had time that was late. -            EVENT_CODE_LATE_DATA_ERROR = 0x8, -            //! Command packet had time that was late. -            EVENT_CODE_LATE_CMD_ERROR = 0x8, -            //! Packet is carrying arbitrary payload -            EVENT_CODE_USER_PAYLOAD = 0x40, +    //! When the async event occurred. +    time_spec_t time_spec; -            // TODO: For now, we combine legacy TX and RX messages. -            EVENT_CODE_OVERFLOW     = 0x8, -            EVENT_CODE_OVERRUN     = EVENT_CODE_OVERFLOW, -            //! Multi-channel alignment failed. -            EVENT_CODE_ALIGNMENT    = 0xc, -            //! The packet could not be parsed. -            EVENT_CODE_BAD_PACKET   = 0xf -        } event_code; +    /*! +     * The type of event for a receive async message call. +     */ +    enum event_code_t { +        //! Nothing happened. +        EVENT_CODE_NONE = 0x00, +        //! A burst was successfully transmitted. +        EVENT_CODE_BURST_ACK = 0x1, +        //! An internal send buffer has emptied. +        EVENT_CODE_UNDERFLOW = 0x2, +        //! Same. We use the terms 'underrun' and 'underflow' interchangeably. +        EVENT_CODE_UNDERRUN = EVENT_CODE_UNDERFLOW, +        //! Packet loss or reordering between source and destination, +        //  at start of burst (i.e. the first packet after an EOB packet +        //  had the wrong sequence number). +        EVENT_CODE_SEQ_ERROR = 0x4, +        //! Like EVENT_CODE_SEQ_ERROR, but within a burst (i.e., any packet +        //  other than the first packet had an error) +        EVENT_CODE_SEQ_ERROR_IN_BURST = 0x20, +        //! Data packet had time that was late. +        EVENT_CODE_LATE_DATA_ERROR = 0x8, +        //! Command packet had time that was late. +        EVENT_CODE_LATE_CMD_ERROR = 0x8, +        //! Packet is carrying arbitrary payload +        EVENT_CODE_USER_PAYLOAD = 0x40, -        /*! -         * A special payload populated by custom FPGA fabric. -         */ -        std::vector<uint32_t> payload; +        // TODO: For now, we combine legacy TX and RX messages. +        EVENT_CODE_OVERFLOW = 0x8, +        EVENT_CODE_OVERRUN  = EVENT_CODE_OVERFLOW, +        //! Multi-channel alignment failed. +        EVENT_CODE_ALIGNMENT = 0xc, +        //! The packet could not be parsed. +        EVENT_CODE_BAD_PACKET = 0xf +    } event_code; -        //! The SID on the async message packet -        uint32_t sid; +    /*! +     * A special payload populated by custom FPGA fabric. +     */ +    std::vector<uint32_t> payload; -        async_msg_t(const size_t payload_size=4) : -              has_time_spec(false), -              time_spec(0.0), -              event_code(EVENT_CODE_NONE), -              payload(payload_size, 0), -              sid(0) -        {} -        //! Return the the id of src block that throw eror -        uint32_t get_error_src() const { return sid_t(sid).get_src_endpoint(); } -    }; +    //! The SID on the async message packet +    uint32_t sid; +    async_msg_t(const size_t payload_size = 4) +        : has_time_spec(false) +        , time_spec(0.0) +        , event_code(EVENT_CODE_NONE) +        , payload(payload_size, 0) +        , sid(0) +    {      } -} -#endif /* INCLUDED_UHD_RFNOC_ASYNC_MSG_HPP */ +    //! Return the the id of src block that throw eror +    uint32_t get_error_src() const +    { +        return sid_t(sid).get_src_endpoint(); +    } +}; +}} // namespace uhd::rfnoc +#endif /* INCLUDED_UHD_RFNOC_ASYNC_MSG_HPP */ diff --git a/host/lib/include/uhdlib/rfnoc/block_container.hpp b/host/lib/include/uhdlib/rfnoc/block_container.hpp index 3c75892a4..800902d06 100644 --- a/host/lib/include/uhdlib/rfnoc/block_container.hpp +++ b/host/lib/include/uhdlib/rfnoc/block_container.hpp @@ -7,10 +7,10 @@  #ifndef INCLUDED_LIBUHD_BLOCK_CONTAINER_HPP  #define INCLUDED_LIBUHD_BLOCK_CONTAINER_HPP -#include <uhd/rfnoc/noc_block_base.hpp>  #include <uhd/rfnoc/block_id.hpp> -#include <boost/units/detail/utility.hpp> +#include <uhd/rfnoc/noc_block_base.hpp>  #include <unordered_set> +#include <boost/units/detail/utility.hpp>  #include <mutex>  #include <vector> @@ -64,4 +64,3 @@ private:  }}} /* namespace uhd::rfnoc::detail */  #endif /* INCLUDED_LIBUHD_BLOCK_CONTAINER_HPP */ - diff --git a/host/lib/include/uhdlib/rfnoc/chdr_ctrl_xport.hpp b/host/lib/include/uhdlib/rfnoc/chdr_ctrl_xport.hpp index d4564e935..d32ab7222 100644 --- a/host/lib/include/uhdlib/rfnoc/chdr_ctrl_xport.hpp +++ b/host/lib/include/uhdlib/rfnoc/chdr_ctrl_xport.hpp @@ -136,8 +136,8 @@ public:  private:      chdr_ctrl_xport(const chdr_ctrl_xport&) = delete; -    void _release_cb(uhd::transport::frame_buff::uptr buff, -        uhd::transport::recv_link_if* recv_link); +    void _release_cb( +        uhd::transport::frame_buff::uptr buff, uhd::transport::recv_link_if* recv_link);      bool _ctrl_recv_cb(uhd::transport::frame_buff::uptr& buff); diff --git a/host/lib/include/uhdlib/rfnoc/chdr_packet.hpp b/host/lib/include/uhdlib/rfnoc/chdr_packet.hpp index cc729de6c..355c15da2 100644 --- a/host/lib/include/uhdlib/rfnoc/chdr_packet.hpp +++ b/host/lib/include/uhdlib/rfnoc/chdr_packet.hpp @@ -120,8 +120,8 @@ public:       * \param num_mdata The number of metadata words for calculation       * \return The offset of the payload in a packet with the given params       */ -    virtual size_t calculate_payload_offset(const packet_type_t pkt_type, -        const uint8_t num_mdata = 0) const = 0; +    virtual size_t calculate_payload_offset( +        const packet_type_t pkt_type, const uint8_t num_mdata = 0) const = 0;      //! Shortcut to return the const metadata pointer cast as a specific type      template <typename data_t> diff --git a/host/lib/include/uhdlib/rfnoc/chdr_types.hpp b/host/lib/include/uhdlib/rfnoc/chdr_types.hpp index 393996c6b..25a7c8905 100644 --- a/host/lib/include/uhdlib/rfnoc/chdr_types.hpp +++ b/host/lib/include/uhdlib/rfnoc/chdr_types.hpp @@ -209,8 +209,10 @@ private:      }      template <typename field_t> -    static inline uint64_t set_field( -        const uint64_t old_val, const field_t field, const size_t offset, const size_t width) +    static inline uint64_t set_field(const uint64_t old_val, +        const field_t field, +        const size_t offset, +        const size_t width)      {          return (old_val & ~(mask(width) << offset))                 | ((static_cast<uint64_t>(field) & mask(width)) << offset); diff --git a/host/lib/include/uhdlib/rfnoc/clock_iface.hpp b/host/lib/include/uhdlib/rfnoc/clock_iface.hpp index 06e54e67c..1a9f18bd5 100644 --- a/host/lib/include/uhdlib/rfnoc/clock_iface.hpp +++ b/host/lib/include/uhdlib/rfnoc/clock_iface.hpp @@ -11,8 +11,8 @@  #include <uhd/exception.hpp>  #include <uhd/utils/log.hpp>  #include <atomic> -#include <string>  #include <memory> +#include <string>  namespace uhd { namespace rfnoc { diff --git a/host/lib/include/uhdlib/rfnoc/ctrlport_endpoint.hpp b/host/lib/include/uhdlib/rfnoc/ctrlport_endpoint.hpp index 8f54932e5..11c456775 100644 --- a/host/lib/include/uhdlib/rfnoc/ctrlport_endpoint.hpp +++ b/host/lib/include/uhdlib/rfnoc/ctrlport_endpoint.hpp @@ -8,8 +8,8 @@  #define INCLUDED_LIBUHD_RFNOC_CTRLPORT_ENDPOINT_HPP  #include <uhd/rfnoc/register_iface.hpp> -#include <uhdlib/rfnoc/clock_iface.hpp>  #include <uhdlib/rfnoc/chdr_types.hpp> +#include <uhdlib/rfnoc/clock_iface.hpp>  #include <memory>  namespace uhd { namespace rfnoc { diff --git a/host/lib/include/uhdlib/rfnoc/device_id.hpp b/host/lib/include/uhdlib/rfnoc/device_id.hpp index d4cecc840..c86dd04df 100644 --- a/host/lib/include/uhdlib/rfnoc/device_id.hpp +++ b/host/lib/include/uhdlib/rfnoc/device_id.hpp @@ -19,4 +19,3 @@ device_id_t allocate_device_id();  }} /* namespace uhd::rfnoc */  #endif /* INCLUDED_LIBUHD_DEVICE_ID_HPP */ - diff --git a/host/lib/include/uhdlib/rfnoc/epid_allocator.hpp b/host/lib/include/uhdlib/rfnoc/epid_allocator.hpp index 8306b98a4..482cb1dac 100644 --- a/host/lib/include/uhdlib/rfnoc/epid_allocator.hpp +++ b/host/lib/include/uhdlib/rfnoc/epid_allocator.hpp @@ -43,8 +43,8 @@ public:       * \param chdr_ctrl_xport The ctrl xport to use for initializing the SEP/EPID       * \return The allocated EPID       */ -    sep_id_t allocate_epid(const sep_addr_t& addr, mgmt::mgmt_portal& mgmt_portal, -        chdr_ctrl_xport& xport); +    sep_id_t allocate_epid( +        const sep_addr_t& addr, mgmt::mgmt_portal& mgmt_portal, chdr_ctrl_xport& xport);      /*! \brief Get a pre-allocated EPID. Throws an exception is not allocated       * diff --git a/host/lib/include/uhdlib/rfnoc/graph.hpp b/host/lib/include/uhdlib/rfnoc/graph.hpp index c7b06d636..e54c2fe7e 100644 --- a/host/lib/include/uhdlib/rfnoc/graph.hpp +++ b/host/lib/include/uhdlib/rfnoc/graph.hpp @@ -40,11 +40,11 @@ public:       */      void connect(node_ref_t src_node, node_ref_t dst_node, graph_edge_t edge_info); -    //void disconnect(node_ref_t src_node, -        //node_ref_t dst_node, -        //const size_t src_port, -        //const size_t dst_port); -        // +    // void disconnect(node_ref_t src_node, +    // node_ref_t dst_node, +    // const size_t src_port, +    // const size_t dst_port); +    //      /*! Commit graph and run initial checks       * @@ -138,7 +138,7 @@ private:      };      using ForwardEdgePredicate = ForwardBackwardEdgePredicate<true>; -    using BackEdgePredicate = ForwardBackwardEdgePredicate<false>; +    using BackEdgePredicate    = ForwardBackwardEdgePredicate<false>;      //! Vertex predicate, only selects nodes with dirty props      struct DirtyNodePredicate; diff --git a/host/lib/include/uhdlib/rfnoc/mgmt_portal.hpp b/host/lib/include/uhdlib/rfnoc/mgmt_portal.hpp index 9251634bd..ecb90e4e9 100644 --- a/host/lib/include/uhdlib/rfnoc/mgmt_portal.hpp +++ b/host/lib/include/uhdlib/rfnoc/mgmt_portal.hpp @@ -72,8 +72,7 @@ public:      // \param addr The physical address of the stream endpoint      // \param epid The endpoint ID to assign to this endpoint      // -    virtual void register_endpoint( -        const sep_addr_t& addr, const sep_id_t& epid) = 0; +    virtual void register_endpoint(const sep_addr_t& addr, const sep_id_t& epid) = 0;      //! Get information about a discovered (reachable) stream endpoint      // diff --git a/host/lib/include/uhdlib/rfnoc/node_accessor.hpp b/host/lib/include/uhdlib/rfnoc/node_accessor.hpp index 517d2b517..bd4af96f4 100644 --- a/host/lib/include/uhdlib/rfnoc/node_accessor.hpp +++ b/host/lib/include/uhdlib/rfnoc/node_accessor.hpp @@ -93,7 +93,8 @@ public:       *       * This will call node_t::receive_action() (see that for details).       */ -    void send_action(node_t* node, const res_source_info& port_info, action_info::sptr action) +    void send_action( +        node_t* node, const res_source_info& port_info, action_info::sptr action)      {          node->receive_action(port_info, action);      } diff --git a/host/lib/include/uhdlib/rfnoc/radio_control_impl.hpp b/host/lib/include/uhdlib/rfnoc/radio_control_impl.hpp index 4864707e1..1a78d7cab 100644 --- a/host/lib/include/uhdlib/rfnoc/radio_control_impl.hpp +++ b/host/lib/include/uhdlib/rfnoc/radio_control_impl.hpp @@ -52,16 +52,18 @@ public:       * RF-specific API calls       *************************************************************************/      // Setters -    virtual void set_tx_antenna(const std::string &ant, const size_t chan); -    virtual void set_rx_antenna(const std::string &ant, const size_t chan); +    virtual void set_tx_antenna(const std::string& ant, const size_t chan); +    virtual void set_rx_antenna(const std::string& ant, const size_t chan);      virtual double set_tx_frequency(const double freq, const size_t chan);      virtual double set_rx_frequency(const double freq, const size_t chan);      virtual void set_tx_tune_args(const uhd::device_addr_t&, const size_t chan);      virtual void set_rx_tune_args(const uhd::device_addr_t&, const size_t chan);      virtual double set_tx_gain(const double gain, const size_t chan); -    virtual double set_tx_gain(const double gain, const std::string& name, const size_t chan); +    virtual double set_tx_gain( +        const double gain, const std::string& name, const size_t chan);      virtual double set_rx_gain(const double gain, const size_t chan); -    virtual double set_rx_gain(const double gain, const std::string& name, const size_t chan); +    virtual double set_rx_gain( +        const double gain, const std::string& name, const size_t chan);      virtual void set_rx_agc(const bool enable, const size_t chan);      virtual double set_tx_bandwidth(const double bandwidth, const size_t chan);      virtual double set_rx_bandwidth(const double bandwidth, const size_t chan); @@ -118,8 +120,7 @@ public:      virtual std::vector<std::string> get_tx_lo_names(const size_t chan) const;      virtual std::vector<std::string> get_tx_lo_sources(          const std::string& name, const size_t chan); -    virtual freq_range_t get_tx_lo_freq_range( -        const std::string& name, const size_t chan); +    virtual freq_range_t get_tx_lo_freq_range(const std::string& name, const size_t chan);      virtual void set_tx_lo_source(          const std::string& src, const std::string& name, const size_t chan);      virtual const std::string get_tx_lo_source( @@ -147,9 +148,8 @@ public:       * GPIO Controls       *************************************************************************/      virtual std::vector<std::string> get_gpio_banks() const; -    virtual void set_gpio_attr(const std::string& bank, -        const std::string& attr, -        const uint32_t value); +    virtual void set_gpio_attr( +        const std::string& bank, const std::string& attr, const uint32_t value);      virtual uint32_t get_gpio_attr(const std::string& bank, const std::string& attr);      /************************************************************************** @@ -185,16 +185,20 @@ public:       *       * See rfnoc_block_radio_regs.vh for details       */ -    struct regmap { -        static const uint32_t REG_COMPAT_NUM = 0x00;  // Compatibility number register offset -        static const uint32_t REG_RADIO_WIDTH   = 0x1000 + 0x04;   // Upper 16 bits is sample width, lower 16 bits is NSPC +    struct regmap +    { +        static const uint32_t REG_COMPAT_NUM = +            0x00; // Compatibility number register offset +        static const uint32_t REG_RADIO_WIDTH = +            0x1000 + 0x04; // Upper 16 bits is sample width, lower 16 bits is NSPC          static const uint32_t RADIO_BASE_ADDR = 0x1000;          static const uint32_t REG_CHAN_OFFSET = 128; -        static const uint32_t RADIO_ADDR_W     = 7;     // Address space size per radio +        static const uint32_t RADIO_ADDR_W    = 7; // Address space size per radio          // General Radio Registers -        static const uint32_t REG_LOOPBACK_EN   = 0x00;   // Loopback enable (connect Tx output to Rx input) +        static const uint32_t REG_LOOPBACK_EN = +            0x00; // Loopback enable (connect Tx output to Rx input)          // Note on the RX and TX Control Registers: These are per-channel,          // which means the values here are offsets. The base address per @@ -202,35 +206,48 @@ public:          // channel index.          // RX Control Registers -        static const uint32_t REG_RX_STATUS            = 0x10; // Status of Rx radio -        static const uint32_t REG_RX_CMD               = 0x14; // The next radio command to execute -        static const uint32_t REG_RX_CMD_NUM_WORDS_LO  = 0x18; // Number of radio words for the next command (low word) -        static const uint32_t REG_RX_CMD_NUM_WORDS_HI  = 0x1C; // Number of radio words for the next command (high word) -        static const uint32_t REG_RX_CMD_TIME_LO       = 0x20; // Time for the next command (low word) -        static const uint32_t REG_RX_CMD_TIME_HI       = 0x24; // Time for the next command (high word) -        static const uint32_t REG_RX_MAX_WORDS_PER_PKT = 0x28; // Maximum packet length to build from Rx data -        static const uint32_t REG_RX_ERR_PORT          = 0x2C; // Port ID for error reporting -        static const uint32_t REG_RX_ERR_REM_PORT      = 0x30; // Remote port ID for error reporting -        static const uint32_t REG_RX_ERR_REM_EPID      = 0x34; // Remote EPID (endpoint ID) for error reporting -        static const uint32_t REG_RX_ERR_ADDR          = 0x38; // Offset to which to write error code (ADDR+0) and time (ADDR+8) -        static const uint32_t REG_RX_DATA              = 0x3C; -        static const uint32_t REG_RX_HAS_TIME          = 0x70; // Set to one if radio output packets should have timestamps +        static const uint32_t REG_RX_STATUS = 0x10; // Status of Rx radio +        static const uint32_t REG_RX_CMD    = 0x14; // The next radio command to execute +        static const uint32_t REG_RX_CMD_NUM_WORDS_LO = +            0x18; // Number of radio words for the next command (low word) +        static const uint32_t REG_RX_CMD_NUM_WORDS_HI = +            0x1C; // Number of radio words for the next command (high word) +        static const uint32_t REG_RX_CMD_TIME_LO = +            0x20; // Time for the next command (low word) +        static const uint32_t REG_RX_CMD_TIME_HI = +            0x24; // Time for the next command (high word) +        static const uint32_t REG_RX_MAX_WORDS_PER_PKT = +            0x28; // Maximum packet length to build from Rx data +        static const uint32_t REG_RX_ERR_PORT = 0x2C; // Port ID for error reporting +        static const uint32_t REG_RX_ERR_REM_PORT = +            0x30; // Remote port ID for error reporting +        static const uint32_t REG_RX_ERR_REM_EPID = +            0x34; // Remote EPID (endpoint ID) for error reporting +        static const uint32_t REG_RX_ERR_ADDR = +            0x38; // Offset to which to write error code (ADDR+0) and time (ADDR+8) +        static const uint32_t REG_RX_DATA = 0x3C; +        static const uint32_t REG_RX_HAS_TIME = +            0x70; // Set to one if radio output packets should have timestamps          // TX Control Registers -        static const uint32_t REG_TX_IDLE_VALUE   = 0x40; // Value to output when transmitter is idle +        static const uint32_t REG_TX_IDLE_VALUE = +            0x40; // Value to output when transmitter is idle          static const uint32_t REG_TX_ERROR_POLICY = 0x44; // Tx error policy          static const uint32_t REG_TX_ERR_PORT     = 0x48; // Port ID for error reporting -        static const uint32_t REG_TX_ERR_REM_PORT = 0x4C; // Remote port ID for error reporting -        static const uint32_t REG_TX_ERR_REM_EPID = 0x50; // Remote EPID (endpoint ID) for error reporting -        static const uint32_t REG_TX_ERR_ADDR     = 0x54; // Offset to which to write error code (ADDR+0) and time (ADDR+8) - -        static const uint32_t RX_CMD_STOP       = 0; // Stop acquiring at end of next packet -        static const uint32_t RX_CMD_FINITE     = 1; // Acquire NUM_SAMPS then stop +        static const uint32_t REG_TX_ERR_REM_PORT = +            0x4C; // Remote port ID for error reporting +        static const uint32_t REG_TX_ERR_REM_EPID = +            0x50; // Remote EPID (endpoint ID) for error reporting +        static const uint32_t REG_TX_ERR_ADDR = +            0x54; // Offset to which to write error code (ADDR+0) and time (ADDR+8) + +        static const uint32_t RX_CMD_STOP   = 0; // Stop acquiring at end of next packet +        static const uint32_t RX_CMD_FINITE = 1; // Acquire NUM_SAMPS then stop          static const uint32_t RX_CMD_CONTINUOUS = 2; // Acquire until stopped          static const uint32_t RX_CMD_TIMED_POS = 31; -        static const uint32_t PERIPH_BASE = 0x80000; +        static const uint32_t PERIPH_BASE       = 0x80000;          static const uint32_t PERIPH_REG_OFFSET = 8;          static const uint32_t SWREG_TX_ERR      = 0x0000; diff --git a/host/lib/include/uhdlib/rfnoc/reg_iface_adapter.hpp b/host/lib/include/uhdlib/rfnoc/reg_iface_adapter.hpp index 9a5dd39f4..f0eb78be4 100644 --- a/host/lib/include/uhdlib/rfnoc/reg_iface_adapter.hpp +++ b/host/lib/include/uhdlib/rfnoc/reg_iface_adapter.hpp @@ -13,12 +13,11 @@  #include <memory>  //! Convenience macro to generate a reg_iface_adapter from within an RFNoC block -#define RFNOC_MAKE_WB_IFACE(BASE_OFFSET, CHAN)                               \ -    std::make_shared<reg_iface_adapter>(                                   \ -        [this]() -> register_iface& { return regs(); },                      \ -        [this, chan = CHAN]() { return get_command_time(chan); },            \ -        [this, chan = CHAN](                                                 \ -            const uhd::time_spec_t& time) { set_command_time(time, chan); }, \ +#define RFNOC_MAKE_WB_IFACE(BASE_OFFSET, CHAN)                                          \ +    std::make_shared<reg_iface_adapter>([this]() -> register_iface& { return regs(); }, \ +        [this, chan = CHAN]() { return get_command_time(chan); },                       \ +        [this, chan = CHAN](                                                            \ +            const uhd::time_spec_t& time) { set_command_time(time, chan); },            \          BASE_OFFSET)  namespace uhd { namespace rfnoc { @@ -39,7 +38,7 @@ class UHD_API reg_iface_adapter : public uhd::timed_wb_iface  public:      using regs_accessor_t = std::function<register_iface&(void)>;      using time_accessor_t = std::function<uhd::time_spec_t(void)>; -    using time_setter_t = std::function<void(const uhd::time_spec_t&)>; +    using time_setter_t   = std::function<void(const uhd::time_spec_t&)>;      /*!       * \param regs_accessor Function object to retrieve the register_iface diff --git a/host/lib/include/uhdlib/rfnoc/rpc_block_ctrl.hpp b/host/lib/include/uhdlib/rfnoc/rpc_block_ctrl.hpp index 91091d8c2..5125aef84 100644 --- a/host/lib/include/uhdlib/rfnoc/rpc_block_ctrl.hpp +++ b/host/lib/include/uhdlib/rfnoc/rpc_block_ctrl.hpp @@ -10,8 +10,7 @@  #include <uhd/types/device_addr.hpp>  #include <uhdlib/utils/rpc.hpp> -namespace uhd { -    namespace rfnoc { +namespace uhd { namespace rfnoc {  /*! Abstraction for RPC client   * @@ -30,12 +29,9 @@ public:       * \param block_args Additional block arguments       */      virtual void set_rpc_client( -        uhd::rpc_client::sptr rpcc, -        const uhd::device_addr_t &block_args -    ) = 0; - +        uhd::rpc_client::sptr rpcc, const uhd::device_addr_t& block_args) = 0;  }; -}} +}} // namespace uhd::rfnoc  #endif /* INCLUDED_LIBUHD_RFNOC_RPC_BLOCK_CTRL_HPP */ diff --git a/host/lib/include/uhdlib/transport/dpdk_io_service_client.hpp b/host/lib/include/uhdlib/transport/dpdk_io_service_client.hpp index d994fe376..300ca00b5 100644 --- a/host/lib/include/uhdlib/transport/dpdk_io_service_client.hpp +++ b/host/lib/include/uhdlib/transport/dpdk_io_service_client.hpp @@ -145,7 +145,8 @@ public:              // first dequeue operation fails, even though we push onto it before              // setting complete to true. Retrying successfully dequeues a value              // in those cases. -            while (rte_ring_dequeue(_buffer_queue, (void**)&buff_ptr)) {} +            while (rte_ring_dequeue(_buffer_queue, (void**)&buff_ptr)) { +            }          }          return frame_buff::uptr(buff_ptr);      } @@ -200,7 +201,8 @@ public:          size_t queue_size        = (size_t)exp2(ceil(log2(num_recv_frames + 1)));          dpdk::port_id_t nic_port = link->get_port()->get_port_id();          uint16_t id              = io_srv->_get_unique_client_id(); -	UHD_LOG_DEBUG("DPDK::IO_SERVICE", "Creating recv client with queue size of " << queue_size); +        UHD_LOG_DEBUG( +            "DPDK::IO_SERVICE", "Creating recv client with queue size of " << queue_size);          char name[16];          snprintf(name, sizeof(name), "rx%hu-%hu", nic_port, id);          _recv_queue = rte_ring_create( @@ -255,7 +257,8 @@ public:              // first dequeue operation fails, even though we push onto it before              // setting complete to true. Retrying successfully dequeues a value              // in those cases. -            while (rte_ring_dequeue(_recv_queue, (void**)&buff_ptr)) {} +            while (rte_ring_dequeue(_recv_queue, (void**)&buff_ptr)) { +            }          }          return frame_buff::uptr(buff_ptr);      } diff --git a/host/lib/include/uhdlib/transport/liberio_link.hpp b/host/lib/include/uhdlib/transport/liberio_link.hpp index 8ab90976a..6cd550572 100644 --- a/host/lib/include/uhdlib/transport/liberio_link.hpp +++ b/host/lib/include/uhdlib/transport/liberio_link.hpp @@ -44,8 +44,7 @@ public:          liberio_chan_put(_chan);      } -    liberio_frame_buff(const liberio_frame_buff& src) -        : liberio_frame_buff(src._chan) {} +    liberio_frame_buff(const liberio_frame_buff& src) : liberio_frame_buff(src._chan) {}      UHD_FORCE_INLINE size_t get(int32_t timeout_ms)      { @@ -55,7 +54,7 @@ public:              return 0;          }          _packet_size = liberio_buf_get_len(_buff, 0); -        _data = liberio_buf_get_mem(_buff, 0); +        _data        = liberio_buf_get_mem(_buff, 0);          return _packet_size;      } @@ -67,6 +66,7 @@ public:          _buff = nullptr;          _data = nullptr;      } +  private:      struct liberio_buf* _buff = nullptr;      struct liberio_chan* _chan; @@ -75,7 +75,7 @@ private:  class liberio_adapter_info : public adapter_info  {  public: -    liberio_adapter_info() = default; +    liberio_adapter_info()  = default;      ~liberio_adapter_info() = default;      std::string to_string() @@ -102,8 +102,9 @@ class liberio_link : public recv_link_base<liberio_link>,  public:      using sptr = std::shared_ptr<liberio_link>; -    liberio_link( -        const std::string& tx_path, const std::string& rx_path, const link_params_t& params); +    liberio_link(const std::string& tx_path, +        const std::string& rx_path, +        const link_params_t& params);      ~liberio_link(); diff --git a/host/lib/include/uhdlib/transport/rx_streamer_impl.hpp b/host/lib/include/uhdlib/transport/rx_streamer_impl.hpp index 04cd12c59..491a5ab98 100644 --- a/host/lib/include/uhdlib/transport/rx_streamer_impl.hpp +++ b/host/lib/include/uhdlib/transport/rx_streamer_impl.hpp @@ -75,8 +75,7 @@ class rx_streamer_impl : public rx_streamer  public:      //! Constructor      rx_streamer_impl(const size_t num_ports, const uhd::stream_args_t stream_args) -        : _zero_copy_streamer(num_ports) -        , _in_buffs(num_ports) +        : _zero_copy_streamer(num_ports), _in_buffs(num_ports)      {          if (stream_args.cpu_format.empty()) {              throw uhd::value_error("[rx_stream] Must provide a cpu_format!"); @@ -95,7 +94,8 @@ public:      }      //! Connect a new channel to the streamer -    // FIXME: Needs some way to handle virtual channels, since xport could be shared among them +    // FIXME: Needs some way to handle virtual channels, since xport could be shared among +    // them      virtual void connect_channel(const size_t channel, typename transport_t::uptr xport)      {          const size_t mtu = xport->get_max_payload_size(); @@ -144,8 +144,8 @@ public:          size_t total_samps_recv =              _recv_one_packet(buffs, nsamps_per_buff, metadata, eov_positions, timeout_ms); -        if (one_packet or metadata.end_of_burst or -            (eov_positions.data() and eov_positions.remaining() == 0)) { +        if (one_packet or metadata.end_of_burst +            or (eov_positions.data() and eov_positions.remaining() == 0)) {              return total_samps_recv;          } @@ -260,9 +260,8 @@ private:      {          if (_buff_samps_remaining == 0) {              // Current set of buffers has expired, get the next one -            _buff_samps_remaining = -                _zero_copy_streamer.get_recv_buffs( -                    _in_buffs, metadata, eov_positions, timeout_ms); +            _buff_samps_remaining = _zero_copy_streamer.get_recv_buffs( +                _in_buffs, metadata, eov_positions, timeout_ms);              _fragment_offset_in_samps = 0;          } else {              // There are samples still left in the current set of buffers @@ -309,8 +308,7 @@ private:          _converters[chan]->conv(buffer_ptr, out_buffs, num_samps);          // Advance the pointer for the source buffer -        _in_buffs[chan] = -            buffer_ptr + num_samps * _convert_info.bytes_per_otw_item; +        _in_buffs[chan] = buffer_ptr + num_samps * _convert_info.bytes_per_otw_item;          if (_buff_samps_remaining == num_samps) {              _zero_copy_streamer.release_recv_buff(chan); @@ -318,8 +316,7 @@ private:      }      //! Create converters and initialize _convert_info -    void _setup_converters(const size_t num_ports, -        const uhd::stream_args_t stream_args) +    void _setup_converters(const size_t num_ports, const uhd::stream_args_t stream_args)      {          // Note to code archaeologists: In the past, we had to also specify the          // endianness here, but that is no longer necessary because we can make diff --git a/host/lib/include/uhdlib/transport/rx_streamer_zero_copy.hpp b/host/lib/include/uhdlib/transport/rx_streamer_zero_copy.hpp index 98588c6f5..86f13f28d 100644 --- a/host/lib/include/uhdlib/transport/rx_streamer_zero_copy.hpp +++ b/host/lib/include/uhdlib/transport/rx_streamer_zero_copy.hpp @@ -35,8 +35,8 @@ public:      ~eov_data_wrapper()      { -        _metadata.eov_positions = _data; -        _metadata.eov_positions_size = _size; +        _metadata.eov_positions       = _data; +        _metadata.eov_positions_size  = _size;          _metadata.eov_positions_count = _write_pos;      } @@ -69,14 +69,14 @@ public:  private:      uhd::rx_metadata_t& _metadata; -    size_t*            _data; -    size_t             _size; -    size_t             _remaining; -    size_t             _write_pos; -    size_t             _running_sample_count; +    size_t* _data; +    size_t _size; +    size_t _remaining; +    size_t _write_pos; +    size_t _running_sample_count;  }; -} // namespace uhd::transport::detail +} // namespace detail  /*!   * Implementation of rx streamer manipulation of frame buffers and packet info. @@ -269,9 +269,8 @@ public:          // channel 0 is checked for eov--in most cases, it should be the          // same for all channels.          if (eov_positions.data() && eov) { -            eov_positions.push_back( -                eov_positions.get_running_sample_count() + -                info_0.payload_bytes / _bytes_per_item); +            eov_positions.push_back(eov_positions.get_running_sample_count() +                                    + info_0.payload_bytes / _bytes_per_item);          }          // Done with these packets, save timestamp info for next call diff --git a/host/lib/include/uhdlib/transport/tx_streamer_impl.hpp b/host/lib/include/uhdlib/transport/tx_streamer_impl.hpp index d6555ad35..c1cc3156f 100644 --- a/host/lib/include/uhdlib/transport/tx_streamer_impl.hpp +++ b/host/lib/include/uhdlib/transport/tx_streamer_impl.hpp @@ -90,9 +90,9 @@ public:  private:      size_t* _eov_positions; -    size_t  _eov_positions_size; -    size_t  _remaining; -    size_t  _read_pos; +    size_t _eov_positions_size; +    size_t _remaining; +    size_t _read_pos;  };  } // namespace detail diff --git a/host/lib/include/uhdlib/transport/udp_boost_asio_link.hpp b/host/lib/include/uhdlib/transport/udp_boost_asio_link.hpp index 88ad6e518..6b350e997 100644 --- a/host/lib/include/uhdlib/transport/udp_boost_asio_link.hpp +++ b/host/lib/include/uhdlib/transport/udp_boost_asio_link.hpp @@ -33,7 +33,9 @@ class udp_boost_asio_adapter_info : public adapter_info  {  public:      udp_boost_asio_adapter_info(boost::asio::ip::udp::socket& s) -        : _src_ip(s.local_endpoint().address()) {} +        : _src_ip(s.local_endpoint().address()) +    { +    }      ~udp_boost_asio_adapter_info() {} diff --git a/host/lib/include/uhdlib/transport/udp_common.hpp b/host/lib/include/uhdlib/transport/udp_common.hpp index e17deff9e..6deb265d4 100644 --- a/host/lib/include/uhdlib/transport/udp_common.hpp +++ b/host/lib/include/uhdlib/transport/udp_common.hpp @@ -132,7 +132,8 @@ UHD_INLINE void send_udp_packet(int sock_fd, void* mem, size_t len)      // This is known to occur at least on some OSX systems.      // But it should be safe to always check for the error.      while (true) { -        const ssize_t ret = uhd::narrow_cast<ssize_t>(::send(sock_fd, (const char*)mem, len, 0)); +        const ssize_t ret = +            uhd::narrow_cast<ssize_t>(::send(sock_fd, (const char*)mem, len, 0));          if (ret == ssize_t(len))              break;          if (ret == -1 and errno == ENOBUFS) { diff --git a/host/lib/include/uhdlib/usrp/common/ad9361_ctrl.hpp b/host/lib/include/uhdlib/usrp/common/ad9361_ctrl.hpp index f30694dbf..c059a3a09 100644 --- a/host/lib/include/uhdlib/usrp/common/ad9361_ctrl.hpp +++ b/host/lib/include/uhdlib/usrp/common/ad9361_ctrl.hpp @@ -45,27 +45,23 @@ public:      virtual ~ad9361_ctrl(void) {}      //! make a new codec control object -    static sptr make_spi( -        ad9361_params::sptr client_settings, +    static sptr make_spi(ad9361_params::sptr client_settings,          uhd::spi_iface::sptr spi_iface, -        uint32_t slave_num -    ); +        uint32_t slave_num);      static sptr make_spi( -        ad9361_params::sptr client_settings, -        ad9361_io::sptr spi_io_iface -    ); +        ad9361_params::sptr client_settings, ad9361_io::sptr spi_io_iface);      //! Get a list of gain names for RX or TX -    static std::vector<std::string> get_gain_names(const std::string &/*which*/) +    static std::vector<std::string> get_gain_names(const std::string& /*which*/)      {          return std::vector<std::string>(1, "PGA");      }      //! get the gain range for a particular gain element -    static uhd::meta_range_t get_gain_range(const std::string &which) +    static uhd::meta_range_t get_gain_range(const std::string& which)      { -        if(which[0] == 'R') { +        if (which[0] == 'R') {              return uhd::meta_range_t(0.0, 76.0, 1.0);          } else {              return uhd::meta_range_t(0.0, 89.75, 0.25); @@ -81,29 +77,28 @@ public:      //! get the filter range for the frontend which      static uhd::meta_range_t get_bw_filter_range(void)      { -        return uhd::meta_range_t(ad9361_device_t::AD9361_MIN_BW, ad9361_device_t::AD9361_MAX_BW); +        return uhd::meta_range_t( +            ad9361_device_t::AD9361_MIN_BW, ad9361_device_t::AD9361_MAX_BW);      }      //! get the clock rate range for the frontend      static uhd::meta_range_t get_clock_rate_range(void)      { -        return uhd::meta_range_t( -                ad9361_device_t::AD9361_MIN_CLOCK_RATE, -                ad9361_device_t::AD9361_MAX_CLOCK_RATE -        ); +        return uhd::meta_range_t(ad9361_device_t::AD9361_MIN_CLOCK_RATE, +            ad9361_device_t::AD9361_MAX_CLOCK_RATE);      }      //! set the filter bandwidth for the frontend's analog low pass -    virtual double set_bw_filter(const std::string &/*which*/, const double /*bw*/) = 0; +    virtual double set_bw_filter(const std::string& /*which*/, const double /*bw*/) = 0;      //! set the gain for a particular gain element -    virtual double set_gain(const std::string &which, const double value) = 0; +    virtual double set_gain(const std::string& which, const double value) = 0;      //! Enable or disable the AGC module -    virtual void set_agc(const std::string &which, bool enable) = 0; +    virtual void set_agc(const std::string& which, bool enable) = 0;      //! configure the AGC module to slow or fast mode -    virtual void set_agc_mode(const std::string &which, const std::string &mode) = 0; +    virtual void set_agc_mode(const std::string& which, const std::string& mode) = 0;      //! set a new clock rate, return the exact value      virtual double set_clock_rate(const double rate) = 0; @@ -112,55 +107,60 @@ public:      virtual void set_active_chains(bool tx1, bool tx2, bool rx1, bool rx2) = 0;      //! set which timing mode is used -    virtual void set_timing_mode(const std::string &timing_mode) = 0; +    virtual void set_timing_mode(const std::string& timing_mode) = 0;      //! tune the given frontend, return the exact value -    virtual double tune(const std::string &which, const double value) = 0; +    virtual double tune(const std::string& which, const double value) = 0;      //! set the DC offset for I and Q manually -    void set_dc_offset(const std::string &, const std::complex<double>) +    void set_dc_offset(const std::string&, const std::complex<double>)      { -        //This feature should not be used according to Analog Devices -        throw uhd::runtime_error("ad9361_ctrl::set_dc_offset this feature is not supported on this device."); +        // This feature should not be used according to Analog Devices +        throw uhd::runtime_error( +            "ad9361_ctrl::set_dc_offset this feature is not supported on this device.");      }      //! enable or disable the BB/RF DC tracking feature -    virtual void set_dc_offset_auto(const std::string &which, const bool on) = 0; +    virtual void set_dc_offset_auto(const std::string& which, const bool on) = 0;      //! set the IQ correction value manually -    void set_iq_balance(const std::string &, const std::complex<double>) +    void set_iq_balance(const std::string&, const std::complex<double>)      { -        //This feature should not be used according to Analog Devices -        throw uhd::runtime_error("ad9361_ctrl::set_iq_balance this feature is not supported on this device."); +        // This feature should not be used according to Analog Devices +        throw uhd::runtime_error( +            "ad9361_ctrl::set_iq_balance this feature is not supported on this device.");      }      //! enable or disable the quadrature calibration -    virtual void set_iq_balance_auto(const std::string &which, const bool on) = 0; +    virtual void set_iq_balance_auto(const std::string& which, const bool on) = 0;      //! get the current frequency for the given frontend -    virtual double get_freq(const std::string &which) = 0; +    virtual double get_freq(const std::string& which) = 0;      //! turn on/off Catalina's data port loopback      virtual void data_port_loopback(const bool on) = 0;      //! read internal RSSI sensor -    virtual sensor_value_t get_rssi(const std::string &which) = 0; +    virtual sensor_value_t get_rssi(const std::string& which) = 0;      //! read the internal temp sensor      virtual sensor_value_t get_temperature() = 0;      //! List all available filters by name -    virtual std::vector<std::string> get_filter_names(const std::string &which) = 0; +    virtual std::vector<std::string> get_filter_names(const std::string& which) = 0;      //! Return a list of all filters -    virtual filter_info_base::sptr get_filter(const std::string &which, const std::string &filter_name) = 0; +    virtual filter_info_base::sptr get_filter( +        const std::string& which, const std::string& filter_name) = 0;      //! Write back a filter -    virtual void set_filter(const std::string &which, const std::string &filter_name, const filter_info_base::sptr) = 0; +    virtual void set_filter(const std::string& which, +        const std::string& filter_name, +        const filter_info_base::sptr) = 0;      virtual void output_digital_test_tone(bool enb) = 0;  }; -}} +}} // namespace uhd::usrp  #endif /* INCLUDED_AD9361_CTRL_HPP */ diff --git a/host/lib/include/uhdlib/usrp/common/ad936x_manager.hpp b/host/lib/include/uhdlib/usrp/common/ad936x_manager.hpp index 2d21d55e7..d65983c72 100644 --- a/host/lib/include/uhdlib/usrp/common/ad936x_manager.hpp +++ b/host/lib/include/uhdlib/usrp/common/ad936x_manager.hpp @@ -8,15 +8,15 @@  #ifndef INCLUDED_AD9361_MANAGER_HPP  #define INCLUDED_AD9361_MANAGER_HPP -#include <uhd/types/wb_iface.hpp> -#include <uhd/utils/math.hpp>  #include <uhd/property_tree.hpp>  #include <uhd/types/direction.hpp> +#include <uhd/types/wb_iface.hpp> +#include <uhd/utils/math.hpp>  #include <uhdlib/usrp/common/ad9361_ctrl.hpp> -#include <boost/format.hpp> -#include <memory>  #include <stdint.h> +#include <boost/format.hpp>  #include <functional> +#include <memory>  namespace uhd { namespace usrp { @@ -45,12 +45,9 @@ public:       * \param codec_ctrl The actual AD936x control object       * \param n_frontends Number of frontends (1 or 2)       */ -    static sptr make( -            const ad9361_ctrl::sptr &codec_ctrl, -            const size_t n_frontends -    ); +    static sptr make(const ad9361_ctrl::sptr& codec_ctrl, const size_t n_frontends); -    virtual ~ad936x_manager(void) {}; +    virtual ~ad936x_manager(void){};      /*! Put the AD936x into a default state.       * @@ -67,14 +64,13 @@ public:       *       * \param iface An interface to the associated radio control core       * \param iface The radio control core's address to write the loopback value -     * \param iface The radio control core's readback address to read back the returned value +     * \param iface The radio control core's readback address to read back the returned +     * value       *       * \throws a uhd::runtime_error if the loopback value didn't match.       */ -    virtual void loopback_self_test( -            std::function<void(uint32_t)> poker_functor, -            std::function<uint64_t()> peeker_functor -    ) = 0; +    virtual void loopback_self_test(std::function<void(uint32_t)> poker_functor, +        std::function<uint64_t()> peeker_functor) = 0;      /*! Determine a tick rate that will work with a given sampling rate       *  (assuming a DDC/DUC chain is also available elsewhere). @@ -97,10 +93,7 @@ public:       * \returns a valid tick rate that can be used with the given rate       * \throws a uhd::value_error if \p lcm_rate exceeds the max tick rate       */ -    virtual double get_auto_tick_rate( -            const double lcm_rate, -            size_t num_chans -    ) = 0; +    virtual double get_auto_tick_rate(const double lcm_rate, size_t num_chans) = 0;      /*! Check if a given sampling rate is within the available analog bandwidth.       * @@ -110,11 +103,9 @@ public:      /*! Populate the property tree for the device frontend       */ -    virtual void populate_frontend_subtree( -            uhd::property_tree::sptr subtree, -            const std::string &key, -            uhd::direction_t dir -    ) = 0; +    virtual void populate_frontend_subtree(uhd::property_tree::sptr subtree, +        const std::string& key, +        uhd::direction_t dir) = 0;  }; /* class ad936x_manager */ diff --git a/host/lib/include/uhdlib/usrp/common/adf4001_ctrl.hpp b/host/lib/include/uhdlib/usrp/common/adf4001_ctrl.hpp index 8aa449539..0c1b06458 100644 --- a/host/lib/include/uhdlib/usrp/common/adf4001_ctrl.hpp +++ b/host/lib/include/uhdlib/usrp/common/adf4001_ctrl.hpp @@ -15,28 +15,28 @@  #include <uhd/types/serial.hpp>  #include <uhdlib/usrp/cores/spi_core_3000.hpp> -#include <boost/thread/thread.hpp>  #include <stdint.h> +#include <boost/thread/thread.hpp>  namespace uhd { namespace usrp { -class adf4001_regs_t { +class adf4001_regs_t +{  public: -      /* Function prototypes */      uint32_t get_reg(uint8_t addr);      adf4001_regs_t(void);      /* Register values / addresses */ -    uint16_t ref_counter; //14 bits -    uint16_t n; //13 bits -    uint8_t charge_pump_current_1; //3 bits -    uint8_t charge_pump_current_2; //3 bits +    uint16_t ref_counter; // 14 bits +    uint16_t n; // 13 bits +    uint8_t charge_pump_current_1; // 3 bits +    uint8_t charge_pump_current_2; // 3 bits      enum anti_backlash_width_t { -        ANTI_BACKLASH_WIDTH_2_9NS = 0, -        ANTI_BACKLASH_WIDTH_1_3NS = 1, -        ANTI_BACKLASH_WIDTH_6_0NS = 2, +        ANTI_BACKLASH_WIDTH_2_9NS     = 0, +        ANTI_BACKLASH_WIDTH_1_3NS     = 1, +        ANTI_BACKLASH_WIDTH_6_0NS     = 2,          ANTI_BACKLASH_WIDTH_2_9NS_WAT = 3      };      anti_backlash_width_t anti_backlash_width; @@ -46,31 +46,25 @@ public:          LOCK_DETECT_PRECISION_5CYC = 1      };      lock_detect_precision_t lock_detect_precision; -    enum charge_pump_gain_t { -        CHARGE_PUMP_GAIN_1 = 0, -        CHARGE_PUMP_GAIN_2 = 1 -    }; +    enum charge_pump_gain_t { CHARGE_PUMP_GAIN_1 = 0, CHARGE_PUMP_GAIN_2 = 1 };      charge_pump_gain_t charge_pump_gain; -    enum counter_reset_t { -        COUNTER_RESET_NORMAL = 0, -        COUNTER_RESET_RESET = 1 -    }; -    counter_reset_t    counter_reset; +    enum counter_reset_t { COUNTER_RESET_NORMAL = 0, COUNTER_RESET_RESET = 1 }; +    counter_reset_t counter_reset;      enum power_down_t {          POWER_DOWN_NORMAL = 0, -        POWER_DOWN_ASYNC = 1, -        POWER_DOWN_SYNC = 3 +        POWER_DOWN_ASYNC  = 1, +        POWER_DOWN_SYNC   = 3      };      power_down_t power_down;      enum muxout_t {          MUXOUT_TRISTATE_OUT = 0, -        MUXOUT_DLD = 1, -        MUXOUT_NDIV = 2, -        MUXOUT_AVDD = 3, -        MUXOUT_RDIV = 4, -        MUXOUT_NCH_OD_ALD = 5, -        MUXOUT_SDO = 6, -        MUXOUT_GND = 7 +        MUXOUT_DLD          = 1, +        MUXOUT_NDIV         = 2, +        MUXOUT_AVDD         = 3, +        MUXOUT_RDIV         = 4, +        MUXOUT_NCH_OD_ALD   = 5, +        MUXOUT_SDO          = 6, +        MUXOUT_GND          = 7      };      muxout_t muxout;      enum phase_detector_polarity_t { @@ -78,20 +72,17 @@ public:          PHASE_DETECTOR_POLARITY_POSITIVE = 1      };      phase_detector_polarity_t phase_detector_polarity; -    enum charge_pump_mode_t { -        CHARGE_PUMP_NORMAL = 0, -        CHARGE_PUMP_TRISTATE = 1 -    }; +    enum charge_pump_mode_t { CHARGE_PUMP_NORMAL = 0, CHARGE_PUMP_TRISTATE = 1 };      charge_pump_mode_t charge_pump_mode;      enum fastlock_mode_t {          FASTLOCK_MODE_DISABLED = 0, -        FASTLOCK_MODE_1 = 1, -        FASTLOCK_MODE_2 = 2 +        FASTLOCK_MODE_1        = 1, +        FASTLOCK_MODE_2        = 2      };      fastlock_mode_t fastlock_mode;      enum timer_counter_control_t { -        TIMEOUT_3CYC = 0, -        TIMEOUT_7CYC = 1, +        TIMEOUT_3CYC  = 0, +        TIMEOUT_7CYC  = 1,          TIMEOUT_11CYC = 2,          TIMEOUT_15CYC = 3,          TIMEOUT_19CYC = 4, @@ -111,7 +102,8 @@ public:  }; -class adf4001_ctrl { +class adf4001_ctrl +{  public:      adf4001_ctrl(uhd::spi_iface::sptr _spi, int slaveno);      virtual void set_lock_to_ext_ref(bool external); @@ -126,6 +118,6 @@ private:      void write_reg(uint8_t addr);  }; -}} +}} // namespace uhd::usrp  #endif diff --git a/host/lib/include/uhdlib/usrp/common/adf435x.hpp b/host/lib/include/uhdlib/usrp/common/adf435x.hpp index 7989420dd..e805f9754 100644 --- a/host/lib/include/uhdlib/usrp/common/adf435x.hpp +++ b/host/lib/include/uhdlib/usrp/common/adf435x.hpp @@ -17,9 +17,9 @@  #include <uhd/utils/log.hpp>  #include <uhdlib/utils/math.hpp>  #include <uhdlib/utils/narrow.hpp> -#include <functional>  #include <boost/math/special_functions/round.hpp>  #include <boost/thread.hpp> +#include <functional>  #include <vector>  class adf435x_iface diff --git a/host/lib/include/uhdlib/usrp/common/adf535x.hpp b/host/lib/include/uhdlib/usrp/common/adf535x.hpp index 6af8556be..65e552844 100644 --- a/host/lib/include/uhdlib/usrp/common/adf535x.hpp +++ b/host/lib/include/uhdlib/usrp/common/adf535x.hpp @@ -17,8 +17,8 @@  #include <uhdlib/utils/narrow.hpp>  #include <stdint.h>  #include <boost/format.hpp> -#include <functional>  #include <algorithm> +#include <functional>  #include <iomanip>  #include <utility>  #include <vector> diff --git a/host/lib/include/uhdlib/usrp/common/apply_corrections.hpp b/host/lib/include/uhdlib/usrp/common/apply_corrections.hpp index fca566493..dffefffea 100644 --- a/host/lib/include/uhdlib/usrp/common/apply_corrections.hpp +++ b/host/lib/include/uhdlib/usrp/common/apply_corrections.hpp @@ -12,7 +12,7 @@  #include <uhd/property_tree.hpp>  #include <string> -namespace uhd{ namespace usrp{ +namespace uhd { namespace usrp {  void apply_tx_fe_corrections(property_tree::sptr sub_tree, // starts at mboards/x      const std::string& db_serial, @@ -34,6 +34,6 @@ void apply_rx_fe_corrections(property_tree::sptr sub_tree, // starts at mboards/      const fs_path rx_fe_corr_path,      const double rx_lo_freq // actual lo freq  ); -}} //namespace uhd::usrp +}} // namespace uhd::usrp  #endif /* INCLUDED_LIBUHD_USRP_COMMON_APPLY_CORRECTIONS_HPP */ diff --git a/host/lib/include/uhdlib/usrp/common/async_packet_handler.hpp b/host/lib/include/uhdlib/usrp/common/async_packet_handler.hpp index de9d17001..957afe7c1 100644 --- a/host/lib/include/uhdlib/usrp/common/async_packet_handler.hpp +++ b/host/lib/include/uhdlib/usrp/common/async_packet_handler.hpp @@ -14,61 +14,52 @@  #include <uhd/utils/byteswap.hpp>  #include <uhd/utils/log.hpp> -namespace uhd{ namespace usrp{ +namespace uhd { namespace usrp { -    template <typename to_host_type> -    void load_metadata_from_buff( -        const to_host_type &to_host, -        async_metadata_t &metadata, -        const transport::vrt::if_packet_info_t &if_packet_info, -        const uint32_t *vrt_hdr, -        const double tick_rate, -        const size_t channel = 0 -    ){ -        const uint32_t *payload = vrt_hdr + if_packet_info.num_header_words32; +template <typename to_host_type> +void load_metadata_from_buff(const to_host_type& to_host, +    async_metadata_t& metadata, +    const transport::vrt::if_packet_info_t& if_packet_info, +    const uint32_t* vrt_hdr, +    const double tick_rate, +    const size_t channel = 0) +{ +    const uint32_t* payload = vrt_hdr + if_packet_info.num_header_words32; -        //load into metadata -        metadata.channel = channel; -        metadata.has_time_spec = if_packet_info.has_tsf; -        if (tick_rate == 0.0) { -            metadata.time_spec = 0.0; -        } else { -            metadata.time_spec = time_spec_t::from_ticks(if_packet_info.tsf, tick_rate); -        } -        metadata.event_code = async_metadata_t::event_code_t(to_host(payload[0]) & 0xff); +    // load into metadata +    metadata.channel       = channel; +    metadata.has_time_spec = if_packet_info.has_tsf; +    if (tick_rate == 0.0) { +        metadata.time_spec = 0.0; +    } else { +        metadata.time_spec = time_spec_t::from_ticks(if_packet_info.tsf, tick_rate); +    } +    metadata.event_code = async_metadata_t::event_code_t(to_host(payload[0]) & 0xff); -        //load user payload -        for (size_t i = 1; i < if_packet_info.num_payload_words32; i++){ -            if (i-1 == 4) break; //limit of 4 words32 -            metadata.user_payload[i-1] = to_host(payload[i]); -        } +    // load user payload +    for (size_t i = 1; i < if_packet_info.num_payload_words32; i++) { +        if (i - 1 == 4) +            break; // limit of 4 words32 +        metadata.user_payload[i - 1] = to_host(payload[i]);      } +} -    UHD_INLINE void standard_async_msg_prints(const async_metadata_t &metadata) -    { -        if (metadata.event_code & -            ( async_metadata_t::EVENT_CODE_UNDERFLOW -            | async_metadata_t::EVENT_CODE_UNDERFLOW_IN_PACKET) -            ) -        { -            UHD_LOG_FASTPATH("U") -        } -        else if (metadata.event_code & -            ( async_metadata_t::EVENT_CODE_SEQ_ERROR -            | async_metadata_t::EVENT_CODE_SEQ_ERROR_IN_BURST) -            ) -        { -            UHD_LOG_FASTPATH("S") -        } -        else if (metadata.event_code & -            async_metadata_t::EVENT_CODE_TIME_ERROR -            ) -        { -            UHD_LOG_FASTPATH("L") -        } +UHD_INLINE void standard_async_msg_prints(const async_metadata_t& metadata) +{ +    if (metadata.event_code +        & (async_metadata_t::EVENT_CODE_UNDERFLOW +              | async_metadata_t::EVENT_CODE_UNDERFLOW_IN_PACKET)) { +        UHD_LOG_FASTPATH("U") +    } else if (metadata.event_code +               & (async_metadata_t::EVENT_CODE_SEQ_ERROR +                     | async_metadata_t::EVENT_CODE_SEQ_ERROR_IN_BURST)) { +        UHD_LOG_FASTPATH("S") +    } else if (metadata.event_code & async_metadata_t::EVENT_CODE_TIME_ERROR) { +        UHD_LOG_FASTPATH("L")      } +} -}} //namespace uhd::usrp +}} // namespace uhd::usrp  #endif /* INCLUDED_LIBUHD_USRP_COMMON_ASYNC_PACKET_HANDLER_HPP */ diff --git a/host/lib/include/uhdlib/usrp/common/fx2_ctrl.hpp b/host/lib/include/uhdlib/usrp/common/fx2_ctrl.hpp index 8579787f4..23498c96e 100644 --- a/host/lib/include/uhdlib/usrp/common/fx2_ctrl.hpp +++ b/host/lib/include/uhdlib/usrp/common/fx2_ctrl.hpp @@ -13,26 +13,27 @@  #include <uhd/utils/noncopyable.hpp>  #include <memory> -#define FL_BEGIN               0 -#define FL_END                 2 -#define FL_XFER                1 -#define USRP_HASH_SLOT_0_ADDR  0xe1e0 -#define USRP_HASH_SLOT_1_ADDR  0xe1f0 -#define VRQ_FPGA_LOAD          0x02 -#define VRQ_FPGA_SET_RESET     0x04 +#define FL_BEGIN 0 +#define FL_END 2 +#define FL_XFER 1 +#define USRP_HASH_SLOT_0_ADDR 0xe1e0 +#define USRP_HASH_SLOT_1_ADDR 0xe1f0 +#define VRQ_FPGA_LOAD 0x02 +#define VRQ_FPGA_SET_RESET 0x04  #define VRQ_FPGA_SET_TX_ENABLE 0x05  #define VRQ_FPGA_SET_RX_ENABLE 0x06 -#define VRQ_FPGA_SET_TX_RESET  0x0a -#define VRQ_FPGA_SET_RX_RESET  0x0b -#define VRQ_I2C_READ           0x81 -#define VRQ_I2C_WRITE          0x08 -#define VRQ_SET_LED            0x01 -#define VRT_VENDOR_IN          0xC0 -#define VRT_VENDOR_OUT         0x40 - -namespace uhd{ namespace usrp{ - -class fx2_ctrl : uhd::noncopyable, public uhd::i2c_iface{ +#define VRQ_FPGA_SET_TX_RESET 0x0a +#define VRQ_FPGA_SET_RX_RESET 0x0b +#define VRQ_I2C_READ 0x81 +#define VRQ_I2C_WRITE 0x08 +#define VRQ_SET_LED 0x01 +#define VRT_VENDOR_IN 0xC0 +#define VRT_VENDOR_OUT 0x40 + +namespace uhd { namespace usrp { + +class fx2_ctrl : uhd::noncopyable, public uhd::i2c_iface +{  public:      typedef std::shared_ptr<fx2_ctrl> sptr; @@ -54,8 +55,7 @@ public:       * \param filename name of firmware file       * \param force reload firmware if already loaded       */ -    virtual void usrp_load_firmware(std::string filename, -                                   bool force = false) = 0; +    virtual void usrp_load_firmware(std::string filename, bool force = false) = 0;      /*!       * Load fpga file onto usrp @@ -79,10 +79,10 @@ public:       * \return number of bytes read or error       */      virtual int usrp_control_read(uint8_t request, -                                  uint16_t value, -                                  uint16_t index, -                                  unsigned char *buff, -                                  uint16_t length) = 0; +        uint16_t value, +        uint16_t index, +        unsigned char* buff, +        uint16_t length) = 0;      /*!       * Submit an OUT transfer @@ -94,10 +94,10 @@ public:       * \return number of bytes written or error       */      virtual int usrp_control_write(uint8_t request, -                                   uint16_t value, -                                   uint16_t index, -                                   unsigned char *buff, -                                   uint16_t length) = 0; +        uint16_t value, +        uint16_t index, +        unsigned char* buff, +        uint16_t length) = 0;      /*!       * Perform an I2C write @@ -107,9 +107,7 @@ public:       * \return number of bytes written or error       */ -    virtual int usrp_i2c_write(uint16_t i2c_addr, -                               unsigned char *buf, -                               uint16_t len) = 0; +    virtual int usrp_i2c_write(uint16_t i2c_addr, unsigned char* buf, uint16_t len) = 0;      /*!       * Perform an I2C read @@ -119,9 +117,7 @@ public:       * \return number of bytes read or error       */ -    virtual int usrp_i2c_read(uint16_t i2c_addr, -                               unsigned char *buf, -                               uint16_t len) = 0; +    virtual int usrp_i2c_read(uint16_t i2c_addr, unsigned char* buf, uint16_t len) = 0;      //! enable/disable the rx path      virtual void usrp_rx_enable(bool on) = 0; @@ -133,6 +129,6 @@ public:      virtual void usrp_fpga_reset(bool on) = 0;  }; -}} //namespace uhd::usrp +}} // namespace uhd::usrp  #endif /* INCLUDED_LIBUHD_USRP_COMMON_FX2_CTRL_HPP */ diff --git a/host/lib/include/uhdlib/usrp/common/io_service_args.hpp b/host/lib/include/uhdlib/usrp/common/io_service_args.hpp index bdf1fa592..e294df8ee 100644 --- a/host/lib/include/uhdlib/usrp/common/io_service_args.hpp +++ b/host/lib/include/uhdlib/usrp/common/io_service_args.hpp @@ -64,13 +64,13 @@ struct io_service_args_t      size_t num_poll_offload_threads = 1;      //! CPU affinity of offload threads, if wait_mode is set to BLOCK -    std::map<size_t,size_t> recv_offload_thread_cpu; +    std::map<size_t, size_t> recv_offload_thread_cpu;      //! CPU affinity of offload threads, if wait_mode is set to BLOCK      std::map<size_t, size_t> send_offload_thread_cpu;      //! CPU affinity of offload threads, if wait_mode is set to POLL -    std::map<size_t,size_t> poll_offload_thread_cpu; +    std::map<size_t, size_t> poll_offload_thread_cpu;  };  /*! Reads I/O service args from provided dictionary diff --git a/host/lib/include/uhdlib/usrp/common/lmx2592.hpp b/host/lib/include/uhdlib/usrp/common/lmx2592.hpp index 9ee3f944f..74a4df437 100644 --- a/host/lib/include/uhdlib/usrp/common/lmx2592.hpp +++ b/host/lib/include/uhdlib/usrp/common/lmx2592.hpp @@ -12,9 +12,9 @@  #include <uhd/utils/math.hpp>  #include <uhd/utils/safe_call.hpp>  #include <boost/format.hpp> -#include <functional>  #include <algorithm>  #include <cstdint> +#include <functional>  #include <utility>  #include <vector> diff --git a/host/lib/include/uhdlib/usrp/common/max287x.hpp b/host/lib/include/uhdlib/usrp/common/max287x.hpp index 08ee5b16d..5e23649ef 100644 --- a/host/lib/include/uhdlib/usrp/common/max287x.hpp +++ b/host/lib/include/uhdlib/usrp/common/max287x.hpp @@ -16,13 +16,13 @@  #include <uhd/utils/log.hpp>  #include <uhd/utils/math.hpp>  #include <uhd/utils/safe_call.hpp> +#include <stdint.h>  #include <boost/assign.hpp> -#include <functional>  #include <boost/math/special_functions/round.hpp> -#include <vector>  #include <chrono> +#include <functional>  #include <thread> -#include <stdint.h> +#include <vector>  /**   * MAX287x interface @@ -37,7 +37,7 @@ public:      /**       * LD Pin Modes       */ -    typedef enum{ +    typedef enum {          LD_PIN_MODE_LOW,          LD_PIN_MODE_DLD,          LD_PIN_MODE_ALD, @@ -47,7 +47,7 @@ public:      /**       * MUXOUT Modes       */ -    typedef enum{ +    typedef enum {          MUXOUT_TRI_STATE,          MUXOUT_HIGH,          MUXOUT_LOW, @@ -62,7 +62,7 @@ public:      /**       * Charge Pump Currents       */ -    typedef enum{ +    typedef enum {          CHARGE_PUMP_CURRENT_0_32MA,          CHARGE_PUMP_CURRENT_0_64MA,          CHARGE_PUMP_CURRENT_0_96MA, @@ -84,7 +84,7 @@ public:      /**       * Output Powers       */ -    typedef enum{ +    typedef enum {          OUTPUT_POWER_M4DBM,          OUTPUT_POWER_M1DBM,          OUTPUT_POWER_2DBM, @@ -108,7 +108,8 @@ public:       * @param write write function       * @return shared pointer to object       */ -    template <typename max287X_t> static sptr make(write_fn write) +    template <typename max287X_t> +    static sptr make(write_fn write)      {          return sptr(new max287X_t(write));      } @@ -116,7 +117,7 @@ public:      /**       * Destructor       */ -    virtual ~max287x_iface() {}; +    virtual ~max287x_iface(){};      /**       * Power up the synthesizer @@ -142,10 +143,7 @@ public:       * @return actual frequency       */      virtual double set_frequency( -                double target_freq, -                double ref_freq, -                double target_pfd_freq, -                bool is_int_n) = 0; +        double target_freq, double ref_freq, double target_pfd_freq, bool is_int_n) = 0;      /**       * Set output power @@ -231,10 +229,7 @@ public:      virtual void shutdown(void);      virtual bool is_shutdown(void);      virtual double set_frequency( -        double target_freq, -        double ref_freq, -        double target_pfd_freq, -        bool is_int_n); +        double target_freq, double ref_freq, double target_pfd_freq, bool is_int_n);      virtual void set_output_power(output_power_t power);      virtual void set_ld_pin_mode(ld_pin_mode_t mode);      virtual void set_muxout_mode(muxout_mode_t mode); @@ -268,17 +263,16 @@ public:      max2870(write_fn func) : max287x<max2870_regs_t>(func) {}      ~max2870() {}      double set_frequency( -        double target_freq, -        double ref_freq, -        double target_pfd_freq, -        bool is_int_n) +        double target_freq, double ref_freq, double target_pfd_freq, bool is_int_n)      { -        _regs.cpoc = is_int_n ? max2870_regs_t::CPOC_ENABLED : max2870_regs_t::CPOC_DISABLED; -        _regs.feedback_select = target_freq >= 3.0e9 ? -            max2870_regs_t::FEEDBACK_SELECT_DIVIDED : -            max2870_regs_t::FEEDBACK_SELECT_FUNDAMENTAL; - -        return max287x<max2870_regs_t>::set_frequency(target_freq, ref_freq, target_pfd_freq, is_int_n); +        _regs.cpoc = is_int_n ? max2870_regs_t::CPOC_ENABLED +                              : max2870_regs_t::CPOC_DISABLED; +        _regs.feedback_select = target_freq >= 3.0e9 +                                    ? max2870_regs_t::FEEDBACK_SELECT_DIVIDED +                                    : max2870_regs_t::FEEDBACK_SELECT_FUNDAMENTAL; + +        return max287x<max2870_regs_t>::set_frequency( +            target_freq, ref_freq, target_pfd_freq, is_int_n);      }      void commit(void)      { @@ -360,46 +354,41 @@ class max2871 : public max287x<max2871_regs_t>  {  public:      max2871(write_fn func) : max287x<max2871_regs_t>(func) {} -    ~max2871() {}; +    ~max2871(){};      void set_muxout_mode(muxout_mode_t mode)      { -        switch(mode) -        { -        case MUXOUT_SYNC: -            _regs.muxout = max2871_regs_t::MUXOUT_SYNC; -            break; -        case MUXOUT_SPI: -            _regs.muxout = max2871_regs_t::MUXOUT_SPI; -            break; -        default: -            max287x<max2871_regs_t>::set_muxout_mode(mode); +        switch (mode) { +            case MUXOUT_SYNC: +                _regs.muxout = max2871_regs_t::MUXOUT_SYNC; +                break; +            case MUXOUT_SPI: +                _regs.muxout = max2871_regs_t::MUXOUT_SPI; +                break; +            default: +                max287x<max2871_regs_t>::set_muxout_mode(mode);          }      }      double set_frequency( -        double target_freq, -        double ref_freq, -        double target_pfd_freq, -        bool is_int_n) +        double target_freq, double ref_freq, double target_pfd_freq, bool is_int_n)      {          _regs.feedback_select = max2871_regs_t::FEEDBACK_SELECT_DIVIDED; -        double freq = max287x<max2871_regs_t>::set_frequency(target_freq, ref_freq, target_pfd_freq, is_int_n); +        double freq           = max287x<max2871_regs_t>::set_frequency( +            target_freq, ref_freq, target_pfd_freq, is_int_n);          // To support phase synchronization on MAX2871, the same VCO          // subband must be manually programmed on all synthesizers and          // several registers must be set to specific values. -        if (_config_for_sync) -        { +        if (_config_for_sync) {              // Need to manually program VCO value              static const double MIN_VCO_FREQ = 3e9; -            double vco_freq = target_freq; +            double vco_freq                  = target_freq;              while (vco_freq < MIN_VCO_FREQ) -                vco_freq *=2; +                vco_freq *= 2;              uint8_t vco_index = 0xFF; -            for(const vco_map_t::value_type &vco:  max2871_vco_map) -            { -                if (uhd::math::fp_compare::fp_compare_epsilon<double>(vco_freq) < vco.second.stop()) -                { +            for (const vco_map_t::value_type& vco : max2871_vco_map) { +                if (uhd::math::fp_compare::fp_compare_epsilon<double>(vco_freq) +                    < vco.second.stop()) {                      vco_index = vco.first;                      break;                  } @@ -408,19 +397,18 @@ public:                  throw uhd::index_error("Invalid VCO frequency");              // Settings required for phase synchronization as per MAX2871 datasheet -            _regs.shutdown_vas = max2871_regs_t::SHUTDOWN_VAS_DISABLED; -            _regs.vco = vco_index; +            _regs.shutdown_vas       = max2871_regs_t::SHUTDOWN_VAS_DISABLED; +            _regs.vco                = vco_index;              _regs.low_noise_and_spur = max2871_regs_t::LOW_NOISE_AND_SPUR_LOW_NOISE; -            _regs.f01 = max2871_regs_t::F01_FRAC_N; -            _regs.aux_output_select = max2871_regs_t::AUX_OUTPUT_SELECT_DIVIDED; -        } -        else -        { +            _regs.f01                = max2871_regs_t::F01_FRAC_N; +            _regs.aux_output_select  = max2871_regs_t::AUX_OUTPUT_SELECT_DIVIDED; +        } else {              // Reset values to defaults -            _regs.shutdown_vas = max2871_regs_t::SHUTDOWN_VAS_ENABLED;  // turn VCO auto selection on +            _regs.shutdown_vas = +                max2871_regs_t::SHUTDOWN_VAS_ENABLED; // turn VCO auto selection on              _regs.low_noise_and_spur = max2871_regs_t::LOW_NOISE_AND_SPUR_LOW_SPUR_2; -            _regs.f01 = max2871_regs_t::F01_AUTO; -            _regs.aux_output_select = max2871_regs_t::AUX_OUTPUT_SELECT_FUNDAMENTAL; +            _regs.f01                = max2871_regs_t::F01_AUTO; +            _regs.aux_output_select  = max2871_regs_t::AUX_OUTPUT_SELECT_FUNDAMENTAL;          }          return freq; @@ -430,17 +418,18 @@ public:      {          max287x<max2871_regs_t>::commit(); -        // According to Maxim support, the following factors must be true to allow for phase synchronization -        if (_regs.int_n_mode == max2871_regs_t::INT_N_MODE_FRAC_N and -            _regs.feedback_select == max2871_regs_t::FEEDBACK_SELECT_DIVIDED and -            _regs.aux_output_select == max2871_regs_t::AUX_OUTPUT_SELECT_DIVIDED and -            _regs.rf_divider_select <= max2871_regs_t::RF_DIVIDER_SELECT_DIV16 and -            _regs.low_noise_and_spur == max2871_regs_t::LOW_NOISE_AND_SPUR_LOW_NOISE and -            _regs.f01 == max2871_regs_t::F01_FRAC_N and -            _regs.reference_doubler == max2871_regs_t::REFERENCE_DOUBLER_DISABLED and -            _regs.reference_divide_by_2 == max2871_regs_t::REFERENCE_DIVIDE_BY_2_DISABLED and -            _regs.r_counter_10_bit == 1) -        { +        // According to Maxim support, the following factors must be true to allow for +        // phase synchronization +        if (_regs.int_n_mode == max2871_regs_t::INT_N_MODE_FRAC_N +            and _regs.feedback_select == max2871_regs_t::FEEDBACK_SELECT_DIVIDED +            and _regs.aux_output_select == max2871_regs_t::AUX_OUTPUT_SELECT_DIVIDED +            and _regs.rf_divider_select <= max2871_regs_t::RF_DIVIDER_SELECT_DIV16 +            and _regs.low_noise_and_spur == max2871_regs_t::LOW_NOISE_AND_SPUR_LOW_NOISE +            and _regs.f01 == max2871_regs_t::F01_FRAC_N +            and _regs.reference_doubler == max2871_regs_t::REFERENCE_DOUBLER_DISABLED +            and _regs.reference_divide_by_2 +                    == max2871_regs_t::REFERENCE_DIVIDE_BY_2_DISABLED +            and _regs.r_counter_10_bit == 1) {              _can_sync = true;          } else {              _can_sync = false; @@ -456,12 +445,12 @@ public:  // include it here.  template <typename max287x_regs_t> -max287x<max287x_regs_t>::max287x(write_fn func) : -        _can_sync(false), -        _config_for_sync(false), -        _write_all_regs(true), -        _write(func), -        _delay_after_write(true) +max287x<max287x_regs_t>::max287x(write_fn func) +    : _can_sync(false) +    , _config_for_sync(false) +    , _write_all_regs(true) +    , _write(func) +    , _delay_after_write(true)  {      power_up();  } @@ -469,16 +458,13 @@ max287x<max287x_regs_t>::max287x(write_fn func) :  template <typename max287x_regs_t>  max287x<max287x_regs_t>::~max287x()  { -    UHD_SAFE_CALL -    ( -        shutdown(); -    ) +    UHD_SAFE_CALL(shutdown();)  }  template <typename max287x_regs_t>  void max287x<max287x_regs_t>::power_up(void)  { -    _regs.power_down = max287x_regs_t::POWER_DOWN_NORMAL; +    _regs.power_down    = max287x_regs_t::POWER_DOWN_NORMAL;      _regs.double_buffer = max287x_regs_t::DOUBLE_BUFFER_ENABLED;      // According to MAX287x data sheets: @@ -489,7 +475,7 @@ void max287x<max287x_regs_t>::power_up(void)      // The first write and the 20ms wait are done here.  The second write      // is done when any other function that does a write to the registers      // is called (such as tuning). -    _write_all_regs = true; +    _write_all_regs    = true;      _delay_after_write = true;      commit();      _write_all_regs = true; // Next call to commit() writes all regs @@ -498,9 +484,9 @@ void max287x<max287x_regs_t>::power_up(void)  template <typename max287x_regs_t>  void max287x<max287x_regs_t>::shutdown(void)  { -    _regs.rf_output_enable = max287x_regs_t::RF_OUTPUT_ENABLE_DISABLED; +    _regs.rf_output_enable  = max287x_regs_t::RF_OUTPUT_ENABLE_DISABLED;      _regs.aux_output_enable = max287x_regs_t::AUX_OUTPUT_ENABLE_DISABLED; -    _regs.power_down = max287x_regs_t::POWER_DOWN_SHUTDOWN; +    _regs.power_down        = max287x_regs_t::POWER_DOWN_SHUTDOWN;      commit();  } @@ -512,50 +498,48 @@ bool max287x<max287x_regs_t>::is_shutdown(void)  template <typename max287x_regs_t>  double max287x<max287x_regs_t>::set_frequency( -    double target_freq, -    double ref_freq, -    double target_pfd_freq, -    bool is_int_n) +    double target_freq, double ref_freq, double target_pfd_freq, bool is_int_n)  { -    //map rf divider select output dividers to enums -    static const uhd::dict<int, typename max287x_regs_t::rf_divider_select_t> rfdivsel_to_enum = -        boost::assign::map_list_of -        (1,   max287x_regs_t::RF_DIVIDER_SELECT_DIV1) -        (2,   max287x_regs_t::RF_DIVIDER_SELECT_DIV2) -        (4,   max287x_regs_t::RF_DIVIDER_SELECT_DIV4) -        (8,   max287x_regs_t::RF_DIVIDER_SELECT_DIV8) -        (16,  max287x_regs_t::RF_DIVIDER_SELECT_DIV16) -        (32,  max287x_regs_t::RF_DIVIDER_SELECT_DIV32) -        (64,  max287x_regs_t::RF_DIVIDER_SELECT_DIV64) -        (128, max287x_regs_t::RF_DIVIDER_SELECT_DIV128); - -    //map mode setting to valid integer divider (N) values -    static const uhd::range_t int_n_mode_div_range(16,65535,1); -    static const uhd::range_t frac_n_mode_div_range(19,4091,1); - -    //other ranges and constants from MAX287X datasheets -    static const uhd::range_t clock_div_range(1,4095,1); -    static const uhd::range_t r_range(1,1023,1); +    // map rf divider select output dividers to enums +    static const uhd::dict<int, typename max287x_regs_t::rf_divider_select_t> +        rfdivsel_to_enum = +            boost::assign::map_list_of(1, max287x_regs_t::RF_DIVIDER_SELECT_DIV1)( +                2, max287x_regs_t::RF_DIVIDER_SELECT_DIV2)( +                4, max287x_regs_t::RF_DIVIDER_SELECT_DIV4)( +                8, max287x_regs_t::RF_DIVIDER_SELECT_DIV8)( +                16, max287x_regs_t::RF_DIVIDER_SELECT_DIV16)( +                32, max287x_regs_t::RF_DIVIDER_SELECT_DIV32)( +                64, max287x_regs_t::RF_DIVIDER_SELECT_DIV64)( +                128, max287x_regs_t::RF_DIVIDER_SELECT_DIV128); + +    // map mode setting to valid integer divider (N) values +    static const uhd::range_t int_n_mode_div_range(16, 65535, 1); +    static const uhd::range_t frac_n_mode_div_range(19, 4091, 1); + +    // other ranges and constants from MAX287X datasheets +    static const uhd::range_t clock_div_range(1, 4095, 1); +    static const uhd::range_t r_range(1, 1023, 1);      static const double MIN_VCO_FREQ = 3e9; -    static const double BS_FREQ = 50e3; -    static const int MAX_BS_VALUE = 1023; - -    int T = 0; -    int D = ref_freq <= 10.0e6 ? 1 : 0; -    int R = 0; -    int BS = 0; -    int N = 0; -    int FRAC = 0; -    int MOD = 4095; -    int RFdiv = 1; +    static const double BS_FREQ      = 50e3; +    static const int MAX_BS_VALUE    = 1023; + +    int T           = 0; +    int D           = ref_freq <= 10.0e6 ? 1 : 0; +    int R           = 0; +    int BS          = 0; +    int N           = 0; +    int FRAC        = 0; +    int MOD         = 4095; +    int RFdiv       = 1;      double pfd_freq = target_pfd_freq; -    bool feedback_divided = (_regs.feedback_select == max287x_regs_t::FEEDBACK_SELECT_DIVIDED); +    bool feedback_divided = +        (_regs.feedback_select == max287x_regs_t::FEEDBACK_SELECT_DIVIDED); -    //increase RF divider until acceptable VCO frequency (MIN freq for MAX287x VCO is 3GHz) +    // increase RF divider until acceptable VCO frequency (MIN freq for MAX287x VCO is +    // 3GHz)      UHD_ASSERT_THROW(target_freq > 0);      double vco_freq = target_freq; -    while (vco_freq < MIN_VCO_FREQ) -    { +    while (vco_freq < MIN_VCO_FREQ) {          vco_freq *= 2;          RFdiv *= 2;      } @@ -580,56 +564,60 @@ double max287x<max287x_regs_t>::set_frequency(       *     N = f_vco/f_pfd - FRAC/MOD = f_vco*((R*(T+1))/(f_ref*(1+D))) - FRAC/MOD       * f_rf  = f_vco/RFdiv       */ -    for(R = int(ref_freq*(1+D)/(target_pfd_freq*(1+T))); R <= r_range.stop(); R++) -    { -        //PFD input frequency = f_ref/R ... ignoring Reference doubler/divide-by-2 (D & T) -        pfd_freq = ref_freq*(1+D)/(R*(1+T)); +    for (R = int(ref_freq * (1 + D) / (target_pfd_freq * (1 + T))); R <= r_range.stop(); +         R++) { +        // PFD input frequency = f_ref/R ... ignoring Reference doubler/divide-by-2 (D & +        // T) +        pfd_freq = ref_freq * (1 + D) / (R * (1 + T)); -        //keep the PFD frequency at or below target +        // keep the PFD frequency at or below target          if (pfd_freq > target_pfd_freq)              continue; -        //ignore fractional part of tuning -        N = int((vco_freq/pfd_freq)/fb_divisor); +        // ignore fractional part of tuning +        N = int((vco_freq / pfd_freq) / fb_divisor); -        //Fractional-N calculation -        FRAC = int(boost::math::round(((vco_freq/pfd_freq)/fb_divisor - N)*MOD)); +        // Fractional-N calculation +        FRAC = int(boost::math::round(((vco_freq / pfd_freq) / fb_divisor - N) * MOD)); -        if(is_int_n) -        { -            if (FRAC > (MOD / 2)) //Round integer such that actual freq is closest to target +        if (is_int_n) { +            if (FRAC +                > (MOD / 2)) // Round integer such that actual freq is closest to target                  N++;              FRAC = 0;          } -        //keep N within int divider requirements -        if(is_int_n) -        { -            if(N <= int_n_mode_div_range.start()) continue; -            if(N >= int_n_mode_div_range.stop()) continue; -        } -        else -        { -            if(N <= frac_n_mode_div_range.start()) continue; -            if(N >= frac_n_mode_div_range.stop()) continue; +        // keep N within int divider requirements +        if (is_int_n) { +            if (N <= int_n_mode_div_range.start()) +                continue; +            if (N >= int_n_mode_div_range.stop()) +                continue; +        } else { +            if (N <= frac_n_mode_div_range.start()) +                continue; +            if (N >= frac_n_mode_div_range.stop()) +                continue;          } -        //keep pfd freq low enough to achieve 50kHz BS clock +        // keep pfd freq low enough to achieve 50kHz BS clock          BS = static_cast<int>(std::ceil(pfd_freq / BS_FREQ)); -        if(BS <= MAX_BS_VALUE) break; +        if (BS <= MAX_BS_VALUE) +            break;      }      UHD_ASSERT_THROW(R <= r_range.stop()); -    //Reference divide-by-2 for 50% duty cycle +    // Reference divide-by-2 for 50% duty cycle      // if R even, move one divide by 2 to to regs.reference_divide_by_2 -    if(R % 2 == 0) -    { +    if (R % 2 == 0) {          T = 1;          R /= 2;      } -    //actual frequency calculation -    double actual_freq = double((N + (double(FRAC)/double(MOD)))*ref_freq*(1+int(D))/(R*(1+int(T)))) * fb_divisor / RFdiv; +    // actual frequency calculation +    double actual_freq = double((N + (double(FRAC) / double(MOD))) * ref_freq +                                * (1 + int(D)) / (R * (1 + int(T)))) +                         * fb_divisor / RFdiv;      UHD_LOGGER_TRACE("MAX287X")          << boost::format("Intermediates: ref=%0.2f, outdiv=%f, fbdiv=%f") % ref_freq @@ -645,40 +633,38 @@ double max287x<max287x_regs_t>::set_frequency(                 % (target_freq / 1e6) % (actual_freq / 1e6) % (vco_freq / 1e6)                 % (pfd_freq / 1e6) % (pfd_freq / BS / 1e6); -    //load the register values +    // load the register values      _regs.rf_output_enable = max287x_regs_t::RF_OUTPUT_ENABLE_ENABLED; -    if(is_int_n) { -        _regs.cpl = max287x_regs_t::CPL_DISABLED; -        _regs.ldf = max287x_regs_t::LDF_INT_N; +    if (is_int_n) { +        _regs.cpl        = max287x_regs_t::CPL_DISABLED; +        _regs.ldf        = max287x_regs_t::LDF_INT_N;          _regs.int_n_mode = max287x_regs_t::INT_N_MODE_INT_N;      } else { -        _regs.cpl = max287x_regs_t::CPL_ENABLED; -        _regs.ldf = max287x_regs_t::LDF_FRAC_N; +        _regs.cpl        = max287x_regs_t::CPL_ENABLED; +        _regs.ldf        = max287x_regs_t::LDF_FRAC_N;          _regs.int_n_mode = max287x_regs_t::INT_N_MODE_FRAC_N;      }      _regs.lds = pfd_freq <= 32e6 ? max287x_regs_t::LDS_SLOW : max287x_regs_t::LDS_FAST;      _regs.frac_12_bit = FRAC; -    _regs.int_16_bit = N; -    _regs.mod_12_bit = MOD; -    _regs.clock_divider_12_bit = std::max(int(clock_div_range.start()), int(std::ceil(400e-6*pfd_freq/MOD))); +    _regs.int_16_bit  = N; +    _regs.mod_12_bit  = MOD; +    _regs.clock_divider_12_bit = +        std::max(int(clock_div_range.start()), int(std::ceil(400e-6 * pfd_freq / MOD)));      UHD_ASSERT_THROW(_regs.clock_divider_12_bit <= clock_div_range.stop()); -    _regs.r_counter_10_bit = R; -    _regs.reference_divide_by_2 = T ? -        max287x_regs_t::REFERENCE_DIVIDE_BY_2_ENABLED : -        max287x_regs_t::REFERENCE_DIVIDE_BY_2_DISABLED; -    _regs.reference_doubler = D ? -        max287x_regs_t::REFERENCE_DOUBLER_ENABLED : -        max287x_regs_t::REFERENCE_DOUBLER_DISABLED; +    _regs.r_counter_10_bit      = R; +    _regs.reference_divide_by_2 = T ? max287x_regs_t::REFERENCE_DIVIDE_BY_2_ENABLED +                                    : max287x_regs_t::REFERENCE_DIVIDE_BY_2_DISABLED; +    _regs.reference_doubler = D ? max287x_regs_t::REFERENCE_DOUBLER_ENABLED +                                : max287x_regs_t::REFERENCE_DOUBLER_DISABLED;      _regs.band_select_clock_div = BS & 0xFF; -    _regs.bs_msb = (BS & 0x300) >> 8; +    _regs.bs_msb                = (BS & 0x300) >> 8;      UHD_ASSERT_THROW(rfdivsel_to_enum.has_key(RFdiv));      _regs.rf_divider_select = rfdivsel_to_enum[RFdiv]; -    if (_regs.clock_div_mode == max287x_regs_t::CLOCK_DIV_MODE_FAST_LOCK) -    { +    if (_regs.clock_div_mode == max287x_regs_t::CLOCK_DIV_MODE_FAST_LOCK) {          // Charge pump current needs to be set to lowest value in fast lock mode          _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_0_32MA;          // Make sure the register containing the charge pump current is written @@ -691,165 +677,163 @@ double max287x<max287x_regs_t>::set_frequency(  template <typename max287x_regs_t>  void max287x<max287x_regs_t>::set_output_power(output_power_t power)  { -    switch (power) -    { -    case OUTPUT_POWER_M4DBM: -        _regs.output_power = max287x_regs_t::OUTPUT_POWER_M4DBM; -        break; -    case OUTPUT_POWER_M1DBM: -        _regs.output_power = max287x_regs_t::OUTPUT_POWER_M1DBM; -        break; -    case OUTPUT_POWER_2DBM: -        _regs.output_power = max287x_regs_t::OUTPUT_POWER_2DBM; -        break; -    case OUTPUT_POWER_5DBM: -        _regs.output_power = max287x_regs_t::OUTPUT_POWER_5DBM; -        break; -    default: -        UHD_THROW_INVALID_CODE_PATH(); +    switch (power) { +        case OUTPUT_POWER_M4DBM: +            _regs.output_power = max287x_regs_t::OUTPUT_POWER_M4DBM; +            break; +        case OUTPUT_POWER_M1DBM: +            _regs.output_power = max287x_regs_t::OUTPUT_POWER_M1DBM; +            break; +        case OUTPUT_POWER_2DBM: +            _regs.output_power = max287x_regs_t::OUTPUT_POWER_2DBM; +            break; +        case OUTPUT_POWER_5DBM: +            _regs.output_power = max287x_regs_t::OUTPUT_POWER_5DBM; +            break; +        default: +            UHD_THROW_INVALID_CODE_PATH();      }  }  template <typename max287x_regs_t>  void max287x<max287x_regs_t>::set_ld_pin_mode(ld_pin_mode_t mode)  { -    switch(mode) -    { -    case LD_PIN_MODE_LOW: -        _regs.ld_pin_mode = max287x_regs_t::LD_PIN_MODE_LOW; -        break; -    case LD_PIN_MODE_DLD: -        _regs.ld_pin_mode = max287x_regs_t::LD_PIN_MODE_DLD; -        break; -    case LD_PIN_MODE_ALD: -        _regs.ld_pin_mode = max287x_regs_t::LD_PIN_MODE_ALD; -        break; -    case LD_PIN_MODE_HIGH: -        _regs.ld_pin_mode = max287x_regs_t::LD_PIN_MODE_HIGH; -        break; -    default: -        UHD_THROW_INVALID_CODE_PATH(); +    switch (mode) { +        case LD_PIN_MODE_LOW: +            _regs.ld_pin_mode = max287x_regs_t::LD_PIN_MODE_LOW; +            break; +        case LD_PIN_MODE_DLD: +            _regs.ld_pin_mode = max287x_regs_t::LD_PIN_MODE_DLD; +            break; +        case LD_PIN_MODE_ALD: +            _regs.ld_pin_mode = max287x_regs_t::LD_PIN_MODE_ALD; +            break; +        case LD_PIN_MODE_HIGH: +            _regs.ld_pin_mode = max287x_regs_t::LD_PIN_MODE_HIGH; +            break; +        default: +            UHD_THROW_INVALID_CODE_PATH();      }  }  template <typename max287x_regs_t>  void max287x<max287x_regs_t>::set_muxout_mode(muxout_mode_t mode)  { -    switch(mode) -    { -    case MUXOUT_TRI_STATE: -        _regs.muxout = max287x_regs_t::MUXOUT_TRI_STATE; -        break; -    case MUXOUT_HIGH: -        _regs.muxout = max287x_regs_t::MUXOUT_HIGH; -        break; -    case MUXOUT_LOW: -        _regs.muxout = max287x_regs_t::MUXOUT_LOW; -        break; -    case MUXOUT_RDIV: -        _regs.muxout = max287x_regs_t::MUXOUT_RDIV; -        break; -    case MUXOUT_NDIV: -        _regs.muxout = max287x_regs_t::MUXOUT_NDIV; -        break; -    case MUXOUT_ALD: -        _regs.muxout = max287x_regs_t::MUXOUT_ALD; -        break; -    case MUXOUT_DLD: -        _regs.muxout = max287x_regs_t::MUXOUT_DLD; -        break; -    default: -        UHD_THROW_INVALID_CODE_PATH(); +    switch (mode) { +        case MUXOUT_TRI_STATE: +            _regs.muxout = max287x_regs_t::MUXOUT_TRI_STATE; +            break; +        case MUXOUT_HIGH: +            _regs.muxout = max287x_regs_t::MUXOUT_HIGH; +            break; +        case MUXOUT_LOW: +            _regs.muxout = max287x_regs_t::MUXOUT_LOW; +            break; +        case MUXOUT_RDIV: +            _regs.muxout = max287x_regs_t::MUXOUT_RDIV; +            break; +        case MUXOUT_NDIV: +            _regs.muxout = max287x_regs_t::MUXOUT_NDIV; +            break; +        case MUXOUT_ALD: +            _regs.muxout = max287x_regs_t::MUXOUT_ALD; +            break; +        case MUXOUT_DLD: +            _regs.muxout = max287x_regs_t::MUXOUT_DLD; +            break; +        default: +            UHD_THROW_INVALID_CODE_PATH();      }  }  template <typename max287x_regs_t>  void max287x<max287x_regs_t>::set_charge_pump_current(charge_pump_current_t cp_current)  { -    switch(cp_current) -    { -    case CHARGE_PUMP_CURRENT_0_32MA: -        _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_0_32MA; -        break; -    case CHARGE_PUMP_CURRENT_0_64MA: -        _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_0_64MA; -        break; -    case CHARGE_PUMP_CURRENT_0_96MA: -        _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_0_96MA; -        break; -    case CHARGE_PUMP_CURRENT_1_28MA: -        _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_1_28MA; -        break; -    case CHARGE_PUMP_CURRENT_1_60MA: -        _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_1_60MA; -        break; -    case CHARGE_PUMP_CURRENT_1_92MA: -        _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_1_92MA; -        break; -    case CHARGE_PUMP_CURRENT_2_24MA: -        _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_2_24MA; -        break; -    case CHARGE_PUMP_CURRENT_2_56MA: -        _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_2_56MA; -        break; -    case CHARGE_PUMP_CURRENT_2_88MA: -        _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_2_88MA; -        break; -    case CHARGE_PUMP_CURRENT_3_20MA: -        _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_3_20MA; -        break; -    case CHARGE_PUMP_CURRENT_3_52MA: -        _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_3_52MA; -        break; -    case CHARGE_PUMP_CURRENT_3_84MA: -        _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_3_84MA; -        break; -    case CHARGE_PUMP_CURRENT_4_16MA: -        _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_4_16MA; -        break; -    case CHARGE_PUMP_CURRENT_4_48MA: -        _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_4_48MA; -        break; -    case CHARGE_PUMP_CURRENT_4_80MA: -        _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_4_80MA; -        break; -    case CHARGE_PUMP_CURRENT_5_12MA: -        _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_5_12MA; -        break; -    default: -        UHD_THROW_INVALID_CODE_PATH(); +    switch (cp_current) { +        case CHARGE_PUMP_CURRENT_0_32MA: +            _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_0_32MA; +            break; +        case CHARGE_PUMP_CURRENT_0_64MA: +            _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_0_64MA; +            break; +        case CHARGE_PUMP_CURRENT_0_96MA: +            _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_0_96MA; +            break; +        case CHARGE_PUMP_CURRENT_1_28MA: +            _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_1_28MA; +            break; +        case CHARGE_PUMP_CURRENT_1_60MA: +            _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_1_60MA; +            break; +        case CHARGE_PUMP_CURRENT_1_92MA: +            _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_1_92MA; +            break; +        case CHARGE_PUMP_CURRENT_2_24MA: +            _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_2_24MA; +            break; +        case CHARGE_PUMP_CURRENT_2_56MA: +            _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_2_56MA; +            break; +        case CHARGE_PUMP_CURRENT_2_88MA: +            _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_2_88MA; +            break; +        case CHARGE_PUMP_CURRENT_3_20MA: +            _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_3_20MA; +            break; +        case CHARGE_PUMP_CURRENT_3_52MA: +            _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_3_52MA; +            break; +        case CHARGE_PUMP_CURRENT_3_84MA: +            _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_3_84MA; +            break; +        case CHARGE_PUMP_CURRENT_4_16MA: +            _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_4_16MA; +            break; +        case CHARGE_PUMP_CURRENT_4_48MA: +            _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_4_48MA; +            break; +        case CHARGE_PUMP_CURRENT_4_80MA: +            _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_4_80MA; +            break; +        case CHARGE_PUMP_CURRENT_5_12MA: +            _regs.charge_pump_current = max287x_regs_t::CHARGE_PUMP_CURRENT_5_12MA; +            break; +        default: +            UHD_THROW_INVALID_CODE_PATH();      }  }  template <typename max287x_regs_t>  void max287x<max287x_regs_t>::set_auto_retune(bool enabled)  { -    _regs.retune = enabled ? max287x_regs_t::RETUNE_ENABLED : max287x_regs_t::RETUNE_DISABLED; +    _regs.retune = enabled ? max287x_regs_t::RETUNE_ENABLED +                           : max287x_regs_t::RETUNE_DISABLED;  }  template <>  inline void max287x<max2871_regs_t>::set_auto_retune(bool enabled)  { -    _regs.retune = enabled ? max2871_regs_t::RETUNE_ENABLED : max2871_regs_t::RETUNE_DISABLED; -    _regs.vas_dly = enabled ? max2871_regs_t::VAS_DLY_ENABLED : max2871_regs_t::VAS_DLY_DISABLED; +    _regs.retune = enabled ? max2871_regs_t::RETUNE_ENABLED +                           : max2871_regs_t::RETUNE_DISABLED; +    _regs.vas_dly = enabled ? max2871_regs_t::VAS_DLY_ENABLED +                            : max2871_regs_t::VAS_DLY_DISABLED;  }  template <typename max287x_regs_t>  void max287x<max287x_regs_t>::set_clock_divider_mode(clock_divider_mode_t mode)  { -    switch(mode) -    { -    case CLOCK_DIV_MODE_CLOCK_DIVIDER_OFF: -        _regs.clock_div_mode = max287x_regs_t::CLOCK_DIV_MODE_CLOCK_DIVIDER_OFF; -        break; -    case CLOCK_DIV_MODE_FAST_LOCK: -        _regs.clock_div_mode = max287x_regs_t::CLOCK_DIV_MODE_FAST_LOCK; -        break; -    case CLOCK_DIV_MODE_PHASE: -        _regs.clock_div_mode = max287x_regs_t::CLOCK_DIV_MODE_PHASE; -        break; -    default: -        UHD_THROW_INVALID_CODE_PATH(); +    switch (mode) { +        case CLOCK_DIV_MODE_CLOCK_DIVIDER_OFF: +            _regs.clock_div_mode = max287x_regs_t::CLOCK_DIV_MODE_CLOCK_DIVIDER_OFF; +            break; +        case CLOCK_DIV_MODE_FAST_LOCK: +            _regs.clock_div_mode = max287x_regs_t::CLOCK_DIV_MODE_FAST_LOCK; +            break; +        case CLOCK_DIV_MODE_PHASE: +            _regs.clock_div_mode = max287x_regs_t::CLOCK_DIV_MODE_PHASE; +            break; +        default: +            UHD_THROW_INVALID_CODE_PATH();      }  } @@ -857,25 +841,25 @@ template <typename max287x_regs_t>  void max287x<max287x_regs_t>::set_cycle_slip_mode(bool enabled)  {      if (enabled) -        throw uhd::runtime_error("Cycle slip mode not supported on this MAX287x synthesizer."); +        throw uhd::runtime_error( +            "Cycle slip mode not supported on this MAX287x synthesizer.");  }  template <typename max287x_regs_t>  void max287x<max287x_regs_t>::set_low_noise_and_spur(low_noise_and_spur_t mode)  { -    switch(mode) -    { -    case LOW_NOISE_AND_SPUR_LOW_NOISE: -        _regs.low_noise_and_spur = max287x_regs_t::LOW_NOISE_AND_SPUR_LOW_NOISE; -        break; -    case LOW_NOISE_AND_SPUR_LOW_SPUR_1: -        _regs.low_noise_and_spur = max287x_regs_t::LOW_NOISE_AND_SPUR_LOW_SPUR_1; -        break; -    case LOW_NOISE_AND_SPUR_LOW_SPUR_2: -        _regs.low_noise_and_spur = max287x_regs_t::LOW_NOISE_AND_SPUR_LOW_SPUR_2; -        break; -    default: -        UHD_THROW_INVALID_CODE_PATH(); +    switch (mode) { +        case LOW_NOISE_AND_SPUR_LOW_NOISE: +            _regs.low_noise_and_spur = max287x_regs_t::LOW_NOISE_AND_SPUR_LOW_NOISE; +            break; +        case LOW_NOISE_AND_SPUR_LOW_SPUR_1: +            _regs.low_noise_and_spur = max287x_regs_t::LOW_NOISE_AND_SPUR_LOW_SPUR_1; +            break; +        case LOW_NOISE_AND_SPUR_LOW_SPUR_2: +            _regs.low_noise_and_spur = max287x_regs_t::LOW_NOISE_AND_SPUR_LOW_SPUR_2; +            break; +        default: +            UHD_THROW_INVALID_CODE_PATH();      }  } @@ -892,21 +876,18 @@ void max287x<max287x_regs_t>::commit()      std::set<uint32_t> changed_regs;      // Get only regs with changes -    if (_write_all_regs) -    { +    if (_write_all_regs) {          for (int addr = 5; addr >= 0; addr--)              regs.push_back(_regs.get_reg(uint32_t(addr)));      } else {          try { -            changed_regs = _regs.template get_changed_addrs<uint32_t> (); +            changed_regs = _regs.template get_changed_addrs<uint32_t>();              // register 0 must be written to apply double buffered fields -            if (changed_regs.size() > 0) -            { +            if (changed_regs.size() > 0) {                  changed_regs.insert(0);              } -            for (int addr = 5; addr >= 0; addr--) -            { +            for (int addr = 5; addr >= 0; addr--) {                  if (changed_regs.find(uint32_t(addr)) != changed_regs.end())                      regs.push_back(_regs.get_reg(uint32_t(addr)));              } @@ -921,8 +902,7 @@ void max287x<max287x_regs_t>::commit()      _regs.save_state();      _write_all_regs = false; -    if (_delay_after_write) -    { +    if (_delay_after_write) {          std::this_thread::sleep_for(std::chrono::milliseconds(20));          _delay_after_write = false;      } diff --git a/host/lib/include/uhdlib/usrp/common/mpmd_mb_controller.hpp b/host/lib/include/uhdlib/usrp/common/mpmd_mb_controller.hpp index 8111d05b8..25d32ee28 100644 --- a/host/lib/include/uhdlib/usrp/common/mpmd_mb_controller.hpp +++ b/host/lib/include/uhdlib/usrp/common/mpmd_mb_controller.hpp @@ -27,7 +27,10 @@ public:      mpmd_mb_controller(uhd::rpc_client::sptr rpcc, uhd::device_addr_t device_info);      //! Return reference to the RPC client -    uhd::rpc_client::sptr get_rpc_client() { return _rpc; } +    uhd::rpc_client::sptr get_rpc_client() +    { +        return _rpc; +    }      /**************************************************************************       * Timekeeper API diff --git a/host/lib/include/uhdlib/usrp/common/recv_packet_demuxer.hpp b/host/lib/include/uhdlib/usrp/common/recv_packet_demuxer.hpp index c61e0ba99..09882378e 100644 --- a/host/lib/include/uhdlib/usrp/common/recv_packet_demuxer.hpp +++ b/host/lib/include/uhdlib/usrp/common/recv_packet_demuxer.hpp @@ -10,24 +10,28 @@  #include <uhd/config.hpp>  #include <uhd/transport/zero_copy.hpp> -#include <memory>  #include <stdint.h> +#include <memory> -namespace uhd{ namespace usrp{ +namespace uhd { namespace usrp { -    class recv_packet_demuxer{ -    public: -        typedef std::shared_ptr<recv_packet_demuxer> sptr; +class recv_packet_demuxer +{ +public: +    typedef std::shared_ptr<recv_packet_demuxer> sptr; -        virtual ~recv_packet_demuxer(void) = 0; +    virtual ~recv_packet_demuxer(void) = 0; -        //! Make a new demuxer from a transport and parameters -        static sptr make(transport::zero_copy_if::sptr transport, const size_t size, const uint32_t sid_base); +    //! Make a new demuxer from a transport and parameters +    static sptr make(transport::zero_copy_if::sptr transport, +        const size_t size, +        const uint32_t sid_base); -        //! Get a buffer at the given index from the transport -        virtual transport::managed_recv_buffer::sptr get_recv_buff(const size_t index, const double timeout) = 0; -    }; +    //! Get a buffer at the given index from the transport +    virtual transport::managed_recv_buffer::sptr get_recv_buff( +        const size_t index, const double timeout) = 0; +}; -}} //namespace uhd::usrp +}} // namespace uhd::usrp  #endif /* INCLUDED_LIBUHD_USRP_COMMON_RECV_PACKET_DEMUXER_HPP */ diff --git a/host/lib/include/uhdlib/usrp/common/recv_packet_demuxer_3000.hpp b/host/lib/include/uhdlib/usrp/common/recv_packet_demuxer_3000.hpp index bb5b070c5..4d20e17cc 100644 --- a/host/lib/include/uhdlib/usrp/common/recv_packet_demuxer_3000.hpp +++ b/host/lib/include/uhdlib/usrp/common/recv_packet_demuxer_3000.hpp @@ -10,140 +10,156 @@  #include <uhd/config.hpp>  #include <uhd/transport/zero_copy.hpp> -#include <uhd/utils/log.hpp>  #include <uhd/types/time_spec.hpp>  #include <uhd/utils/byteswap.hpp> +#include <uhd/utils/log.hpp> +#include <stdint.h>  #include <boost/thread.hpp> +#include <chrono> +#include <map>  #include <memory>  #include <queue> -#include <map> -#include <chrono> -#include <stdint.h> -namespace uhd{ namespace usrp{ +namespace uhd { namespace usrp { -    struct recv_packet_demuxer_3000 : std::enable_shared_from_this<recv_packet_demuxer_3000> +struct recv_packet_demuxer_3000 : std::enable_shared_from_this<recv_packet_demuxer_3000> +{ +    typedef std::shared_ptr<recv_packet_demuxer_3000> sptr; +    static sptr make(transport::zero_copy_if::sptr xport)      { -        typedef std::shared_ptr<recv_packet_demuxer_3000> sptr; -        static sptr make(transport::zero_copy_if::sptr xport) -        { -            return sptr(new recv_packet_demuxer_3000(xport)); -        } +        return sptr(new recv_packet_demuxer_3000(xport)); +    } -        recv_packet_demuxer_3000(transport::zero_copy_if::sptr xport): -            _xport(xport) -        {/*NOP*/} +    recv_packet_demuxer_3000(transport::zero_copy_if::sptr xport) : _xport(xport) +    { /*NOP*/ +    } -        transport::managed_recv_buffer::sptr get_recv_buff(const uint32_t sid, const double timeout) +    transport::managed_recv_buffer::sptr get_recv_buff( +        const uint32_t sid, const double timeout) +    { +        const auto exit_time = std::chrono::high_resolution_clock::now() +                               + std::chrono::microseconds(int64_t(timeout * 1e6)); +        transport::managed_recv_buffer::sptr buff; +        buff = _internal_get_recv_buff(sid, timeout); +        while (not buff) // loop until timeout          { -            const auto exit_time = std::chrono::high_resolution_clock::now() -                                   + std::chrono::microseconds(int64_t(timeout * 1e6)); -            transport::managed_recv_buffer::sptr buff; -            buff = _internal_get_recv_buff(sid, timeout); -            while (not buff) //loop until timeout -            { -                const auto delta = exit_time - std::chrono::high_resolution_clock::now(); -                const double new_timeout = -                    std::chrono::duration_cast<std::chrono::duration<double>>(delta) -                        .count(); -                if (new_timeout < 0.0) { -                    break; -                } -                buff = _internal_get_recv_buff(sid, new_timeout); +            const auto delta = exit_time - std::chrono::high_resolution_clock::now(); +            const double new_timeout = +                std::chrono::duration_cast<std::chrono::duration<double>>(delta).count(); +            if (new_timeout < 0.0) { +                break;              } -            return buff; +            buff = _internal_get_recv_buff(sid, new_timeout);          } +        return buff; +    } + +    transport::managed_recv_buffer::sptr _internal_get_recv_buff( +        const uint32_t sid, const double timeout) +    { +        transport::managed_recv_buffer::sptr buff; -        transport::managed_recv_buffer::sptr _internal_get_recv_buff(const uint32_t sid, const double timeout) +        //---------------------------------------------------------- +        //-- Check the queue to see if we already have a buffer +        //----------------------------------------------------------          { -            transport::managed_recv_buffer::sptr buff; - -            //---------------------------------------------------------- -            //-- Check the queue to see if we already have a buffer -            //---------------------------------------------------------- -            { -                boost::mutex::scoped_lock l(mutex); -                queue_type_t &queue = _queues[sid]; -                if (not queue.empty()) -                { -                    buff = queue.front(); -                    queue.front().reset(); -                    queue.pop(); -                    return buff; -                } -            } -            { -                buff = _xport->get_recv_buff(timeout); -                if (buff) -                { -                    const uint32_t new_sid = uhd::wtohx(buff->cast<const uint32_t *>()[1]); -                    if (new_sid != sid) -                    { -                        boost::mutex::scoped_lock l(mutex); -                        if (_queues.count(new_sid) == 0) UHD_LOGGER_ERROR("STREAMER") -                            << "recv packet demuxer unexpected sid 0x" << std::hex << new_sid << std::dec -                            ; -                        else _queues[new_sid].push(buff); -                        buff.reset(); -                    } -                } +            boost::mutex::scoped_lock l(mutex); +            queue_type_t& queue = _queues[sid]; +            if (not queue.empty()) { +                buff = queue.front(); +                queue.front().reset(); +                queue.pop(); +                return buff;              } -            return buff;          } - -        void realloc_sid(const uint32_t sid)          { -            boost::mutex::scoped_lock l(mutex); -            while(not _queues[sid].empty()) //allocated and clears if already allocated -            { -                _queues[sid].pop(); +            buff = _xport->get_recv_buff(timeout); +            if (buff) { +                const uint32_t new_sid = uhd::wtohx(buff->cast<const uint32_t*>()[1]); +                if (new_sid != sid) { +                    boost::mutex::scoped_lock l(mutex); +                    if (_queues.count(new_sid) == 0) +                        UHD_LOGGER_ERROR("STREAMER") +                            << "recv packet demuxer unexpected sid 0x" << std::hex +                            << new_sid << std::dec; +                    else +                        _queues[new_sid].push(buff); +                    buff.reset(); +                }              }          } +        return buff; +    } -        transport::zero_copy_if::sptr make_proxy(const uint32_t sid); - -        typedef std::queue<transport::managed_recv_buffer::sptr> queue_type_t; -        std::map<uint32_t, queue_type_t> _queues; -        transport::zero_copy_if::sptr _xport; -        boost::mutex mutex; -    }; - -    struct recv_packet_demuxer_proxy_3000 : transport::zero_copy_if +    void realloc_sid(const uint32_t sid)      { -        recv_packet_demuxer_proxy_3000(recv_packet_demuxer_3000::sptr demux, transport::zero_copy_if::sptr xport, const uint32_t sid): -            _demux(demux), _xport(xport), _sid(sid) +        boost::mutex::scoped_lock l(mutex); +        while (not _queues[sid].empty()) // allocated and clears if already allocated          { -            _demux->realloc_sid(_sid); //causes clear +            _queues[sid].pop();          } +    } -        ~recv_packet_demuxer_proxy_3000(void) -        { -            _demux->realloc_sid(_sid); //causes clear -        } +    transport::zero_copy_if::sptr make_proxy(const uint32_t sid); -        size_t get_num_recv_frames(void) const {return _xport->get_num_recv_frames();} -        size_t get_recv_frame_size(void) const {return _xport->get_recv_frame_size();} -        transport::managed_recv_buffer::sptr get_recv_buff(double timeout) -        { -            return _demux->get_recv_buff(_sid, timeout); -        } -        size_t get_num_send_frames(void) const {return _xport->get_num_send_frames();} -        size_t get_send_frame_size(void) const {return _xport->get_send_frame_size();} -        transport::managed_send_buffer::sptr get_send_buff(double timeout) -        { -            return _xport->get_send_buff(timeout); -        } +    typedef std::queue<transport::managed_recv_buffer::sptr> queue_type_t; +    std::map<uint32_t, queue_type_t> _queues; +    transport::zero_copy_if::sptr _xport; +    boost::mutex mutex; +}; + +struct recv_packet_demuxer_proxy_3000 : transport::zero_copy_if +{ +    recv_packet_demuxer_proxy_3000(recv_packet_demuxer_3000::sptr demux, +        transport::zero_copy_if::sptr xport, +        const uint32_t sid) +        : _demux(demux), _xport(xport), _sid(sid) +    { +        _demux->realloc_sid(_sid); // causes clear +    } -        recv_packet_demuxer_3000::sptr _demux; -        transport::zero_copy_if::sptr _xport; -        const uint32_t _sid; -    }; +    ~recv_packet_demuxer_proxy_3000(void) +    { +        _demux->realloc_sid(_sid); // causes clear +    } -    inline transport::zero_copy_if::sptr recv_packet_demuxer_3000::make_proxy(const uint32_t sid) +    size_t get_num_recv_frames(void) const      { -        return transport::zero_copy_if::sptr(new recv_packet_demuxer_proxy_3000(this->shared_from_this(), _xport, sid)); +        return _xport->get_num_recv_frames();      } +    size_t get_recv_frame_size(void) const +    { +        return _xport->get_recv_frame_size(); +    } +    transport::managed_recv_buffer::sptr get_recv_buff(double timeout) +    { +        return _demux->get_recv_buff(_sid, timeout); +    } +    size_t get_num_send_frames(void) const +    { +        return _xport->get_num_send_frames(); +    } +    size_t get_send_frame_size(void) const +    { +        return _xport->get_send_frame_size(); +    } +    transport::managed_send_buffer::sptr get_send_buff(double timeout) +    { +        return _xport->get_send_buff(timeout); +    } + +    recv_packet_demuxer_3000::sptr _demux; +    transport::zero_copy_if::sptr _xport; +    const uint32_t _sid; +}; + +inline transport::zero_copy_if::sptr recv_packet_demuxer_3000::make_proxy( +    const uint32_t sid) +{ +    return transport::zero_copy_if::sptr( +        new recv_packet_demuxer_proxy_3000(this->shared_from_this(), _xport, sid)); +} -}} //namespace uhd::usrp +}} // namespace uhd::usrp  #endif /* INCLUDED_LIBUHD_USRP_COMMON_RECV_PACKET_DEMUXER_3000_HPP */ diff --git a/host/lib/include/uhdlib/usrp/common/validate_subdev_spec.hpp b/host/lib/include/uhdlib/usrp/common/validate_subdev_spec.hpp index f2f3ce035..eb56da12e 100644 --- a/host/lib/include/uhdlib/usrp/common/validate_subdev_spec.hpp +++ b/host/lib/include/uhdlib/usrp/common/validate_subdev_spec.hpp @@ -9,20 +9,18 @@  #define INCLUDED_LIBUHD_USRP_COMMON_VALIDATE_SUBDEV_SPEC_HPP  #include <uhd/config.hpp> -#include <uhd/usrp/subdev_spec.hpp>  #include <uhd/property_tree.hpp> +#include <uhd/usrp/subdev_spec.hpp>  #include <string> -namespace uhd{ namespace usrp{ +namespace uhd { namespace usrp { -    //! Validate a subdev spec against a property tree -    void validate_subdev_spec( -        property_tree::sptr tree, -        const subdev_spec_t &spec, -        const std::string &type, //rx or tx -        const std::string &mb = "0" -    ); +//! Validate a subdev spec against a property tree +void validate_subdev_spec(property_tree::sptr tree, +    const subdev_spec_t& spec, +    const std::string& type, // rx or tx +    const std::string& mb = "0"); -}} //namespace uhd::usrp +}} // namespace uhd::usrp  #endif /* INCLUDED_LIBUHD_USRP_COMMON_VALIDATE_SUBDEV_SPEC_HPP */ diff --git a/host/lib/include/uhdlib/usrp/constrained_device_args.hpp b/host/lib/include/uhdlib/usrp/constrained_device_args.hpp index edb0dd2fc..7c516f80c 100644 --- a/host/lib/include/uhdlib/usrp/constrained_device_args.hpp +++ b/host/lib/include/uhdlib/usrp/constrained_device_args.hpp @@ -8,311 +8,334 @@  #ifndef INCLUDED_LIBUHD_USRP_COMMON_CONSTRAINED_DEV_ARGS_HPP  #define INCLUDED_LIBUHD_USRP_COMMON_CONSTRAINED_DEV_ARGS_HPP -#include <uhd/types/device_addr.hpp>  #include <uhd/exception.hpp> -#include <boost/format.hpp> +#include <uhd/types/device_addr.hpp> +#include <unordered_map>  #include <boost/algorithm/string.hpp>  #include <boost/assign/list_of.hpp> -#include <vector> -#include <string> +#include <boost/format.hpp>  #include <sstream> -#include <unordered_map> +#include <string> +#include <vector> -namespace uhd { -namespace usrp { +namespace uhd { namespace usrp { +/*! + * constrained_device_args_t provides a base and utilities to + * map key=value pairs passed in through the device creation + * args interface (device_addr_t). + * + * Inherit from this class to create typed device specific + * arguments and use the base class methods to handle parsing + * the device_addr or any key=value string to populate the args + * + * This file contains a library of different types of args the + * the user can pass in. The library can be extended to support + * non-intrinsic types by the client. + * + */ +class constrained_device_args_t +{ +public: // Types      /*! -     * constrained_device_args_t provides a base and utilities to -     * map key=value pairs passed in through the device creation -     * args interface (device_addr_t). -     * -     * Inherit from this class to create typed device specific -     * arguments and use the base class methods to handle parsing -     * the device_addr or any key=value string to populate the args -     * -     * This file contains a library of different types of args the -     * the user can pass in. The library can be extended to support -     * non-intrinsic types by the client. -     * +     * Base argument type. All other arguments inherit from this.       */ -    class constrained_device_args_t { -    public: //Types +    class generic_arg +    { +    public: +        generic_arg(const std::string& key) : _key(key) {} +        inline const std::string& key() const +        { +            return _key; +        } +        inline virtual std::string to_string() const = 0; -        /*! -         * Base argument type. All other arguments inherit from this. -         */ -        class generic_arg { -        public: -            generic_arg(const std::string& key): _key(key) {} -            inline const std::string& key() const { return _key; } -            inline virtual std::string to_string() const = 0; -        private: -            std::string _key; -        }; +    private: +        std::string _key; +    }; -        /*! -         * String argument type. Can be case sensitive or insensitive -         */ -        template<bool case_sensitive> -        class str_arg : public generic_arg { -        public: -            str_arg(const std::string& name, const std::string& default_value) : -                generic_arg(name) { set(default_value); } +    /*! +     * String argument type. Can be case sensitive or insensitive +     */ +    template <bool case_sensitive> +    class str_arg : public generic_arg +    { +    public: +        str_arg(const std::string& name, const std::string& default_value) +            : generic_arg(name) +        { +            set(default_value); +        } -            inline void set(const std::string& value) { -                _value = case_sensitive ? value : boost::algorithm::to_lower_copy(value); -            } -            inline const std::string& get() const { -                return _value; -            } -            inline void parse(const std::string& str_rep) { -                set(str_rep); -            } -            inline virtual std::string to_string() const { -                return key() + "=" + get(); -            } -            inline bool operator==(const std::string& rhs) const { -                return get() == boost::algorithm::to_lower_copy(rhs); -            } -        private: -            std::string _value; -        }; -        typedef str_arg<false>  str_ci_arg; -        typedef str_arg<true>   str_cs_arg; +        inline void set(const std::string& value) +        { +            _value = case_sensitive ? value : boost::algorithm::to_lower_copy(value); +        } +        inline const std::string& get() const +        { +            return _value; +        } +        inline void parse(const std::string& str_rep) +        { +            set(str_rep); +        } +        inline virtual std::string to_string() const +        { +            return key() + "=" + get(); +        } +        inline bool operator==(const std::string& rhs) const +        { +            return get() == boost::algorithm::to_lower_copy(rhs); +        } -        /*! -         * Numeric argument type. The template type data_t allows the -         * client to constrain the type of the number. -         */ -        template<typename data_t> -        class num_arg : public generic_arg { -        public: -            num_arg(const std::string& name, const data_t default_value) : -                generic_arg(name) { set(default_value); } +    private: +        std::string _value; +    }; +    typedef str_arg<false> str_ci_arg; +    typedef str_arg<true> str_cs_arg; -            inline void set(const data_t value) { -                _value = value; -            } -            inline const data_t get() const { -                return _value; -            } -            inline void parse(const std::string& str_rep) { -                try { -                    _value = boost::lexical_cast<data_t>(str_rep); -                } catch (std::exception& ex) { -                    throw uhd::value_error(str(boost::format( -                        "Error parsing numeric parameter %s: %s.") % -                        key() % ex.what() -                    )); -                } -            } -            inline virtual std::string to_string() const { -                return key() + "=" + std::to_string(get()); -            } -        private: -            data_t _value; -        }; +    /*! +     * Numeric argument type. The template type data_t allows the +     * client to constrain the type of the number. +     */ +    template <typename data_t> +    class num_arg : public generic_arg +    { +    public: +        num_arg(const std::string& name, const data_t default_value) : generic_arg(name) +        { +            set(default_value); +        } -        /*! -         * Enumeration argument type. The template type enum_t allows the -         * client to use their own enum and specify a string mapping for -         * the values of the enum -         */ -        template<typename enum_t> -        class enum_arg : public generic_arg { -        public: -            enum_arg( -                const std::string& name, -                const enum_t default_value, -                const std::unordered_map<std::string, enum_t>& values) : -                    generic_arg(name), _str_values(_enum_map_to_lowercase<enum_t>(values)) -            { -                set(default_value); -            } -            inline void set(const enum_t value) { -                _value = value; -            } -            inline const enum_t get() const { -                return _value; +        inline void set(const data_t value) +        { +            _value = value; +        } +        inline const data_t get() const +        { +            return _value; +        } +        inline void parse(const std::string& str_rep) +        { +            try { +                _value = boost::lexical_cast<data_t>(str_rep); +            } catch (std::exception& ex) { +                throw uhd::value_error( +                    str(boost::format("Error parsing numeric parameter %s: %s.") % key() +                        % ex.what()));              } -            inline void parse( -                    const std::string& str_rep, -                    const bool assert_invalid = true -            ) { -                const std::string str_rep_lowercase = -                    boost::algorithm::to_lower_copy(str_rep); -                if (_str_values.count(str_rep_lowercase) == 0) { -                    if (assert_invalid) { -                        std::string valid_values_str = ""; -                        for (const auto &value : _str_values) { -                            valid_values_str += -                                (valid_values_str.empty()?"":", ") -                                + value.first; -                        } -                        throw uhd::value_error(str(boost::format( -                            "Invalid device arg value: %s=%s (Valid: {%s})") % -                            key() % str_rep % valid_values_str -                        )); -                    } else { -                        return; -                    } -                } +        } +        inline virtual std::string to_string() const +        { +            return key() + "=" + std::to_string(get()); +        } -                set(_str_values.at(str_rep_lowercase)); -            } -            inline virtual std::string to_string() const { -                std::string repr; -                for (const auto& value : _str_values) { -                    if (value.second == _value) { -                        repr = value.first; -                        break; +    private: +        data_t _value; +    }; + +    /*! +     * Enumeration argument type. The template type enum_t allows the +     * client to use their own enum and specify a string mapping for +     * the values of the enum +     */ +    template <typename enum_t> +    class enum_arg : public generic_arg +    { +    public: +        enum_arg(const std::string& name, +            const enum_t default_value, +            const std::unordered_map<std::string, enum_t>& values) +            : generic_arg(name), _str_values(_enum_map_to_lowercase<enum_t>(values)) +        { +            set(default_value); +        } +        inline void set(const enum_t value) +        { +            _value = value; +        } +        inline const enum_t get() const +        { +            return _value; +        } +        inline void parse(const std::string& str_rep, const bool assert_invalid = true) +        { +            const std::string str_rep_lowercase = +                boost::algorithm::to_lower_copy(str_rep); +            if (_str_values.count(str_rep_lowercase) == 0) { +                if (assert_invalid) { +                    std::string valid_values_str = ""; +                    for (const auto& value : _str_values) { +                        valid_values_str += +                            (valid_values_str.empty() ? "" : ", ") + value.first;                      } +                    throw uhd::value_error( +                        str(boost::format("Invalid device arg value: %s=%s (Valid: {%s})") +                            % key() % str_rep % valid_values_str)); +                } else { +                    return;                  } +            } -                UHD_ASSERT_THROW(!repr.empty()); -                return key() + "=" + repr; +            set(_str_values.at(str_rep_lowercase)); +        } +        inline virtual std::string to_string() const +        { +            std::string repr; +            for (const auto& value : _str_values) { +                if (value.second == _value) { +                    repr = value.first; +                    break; +                }              } -        private: -            enum_t                                         _value; -            const std::unordered_map<std::string, enum_t>  _str_values; -        }; +            UHD_ASSERT_THROW(!repr.empty()); +            return key() + "=" + repr; +        } -        /*! -         * Boolean argument type. -         */ -        class bool_arg : public generic_arg { -        public: -            bool_arg(const std::string& name, const bool default_value) : -                generic_arg(name) { set(default_value); } +    private: +        enum_t _value; +        const std::unordered_map<std::string, enum_t> _str_values; +    }; -            inline void set(const bool value) { -                _value = value; -            } -            inline bool get() const { -                return _value; -            } -            inline void parse(const std::string& str_rep) { -                try { -                    _value = (std::stoi(str_rep) != 0); -                } catch (std::exception& ex) { -                    if (str_rep.empty()) { -                        //If str_rep is empty then the device_addr was set -                        //without a value which means that the user "set" the flag -                        _value = true; -                    } else if (boost::algorithm::to_lower_copy(str_rep) == "true" || -                        boost::algorithm::to_lower_copy(str_rep) == "yes" || -                        boost::algorithm::to_lower_copy(str_rep) == "y" || -                        str_rep == "1" -                        ) { -                        _value = true; -                    } else if (boost::algorithm::to_lower_copy(str_rep) == "false" || -                            boost::algorithm::to_lower_copy(str_rep) == "no" || -                            boost::algorithm::to_lower_copy(str_rep) == "n" || -                            str_rep == "0" -                            ) { -                        _value = false; -                    } else { -                        throw uhd::value_error(str(boost::format( -                            "Error parsing boolean parameter %s: %s.") % -                            key() % ex.what() -                        )); -                    } +    /*! +     * Boolean argument type. +     */ +    class bool_arg : public generic_arg +    { +    public: +        bool_arg(const std::string& name, const bool default_value) : generic_arg(name) +        { +            set(default_value); +        } + +        inline void set(const bool value) +        { +            _value = value; +        } +        inline bool get() const +        { +            return _value; +        } +        inline void parse(const std::string& str_rep) +        { +            try { +                _value = (std::stoi(str_rep) != 0); +            } catch (std::exception& ex) { +                if (str_rep.empty()) { +                    // If str_rep is empty then the device_addr was set +                    // without a value which means that the user "set" the flag +                    _value = true; +                } else if (boost::algorithm::to_lower_copy(str_rep) == "true" +                           || boost::algorithm::to_lower_copy(str_rep) == "yes" +                           || boost::algorithm::to_lower_copy(str_rep) == "y" +                           || str_rep == "1") { +                    _value = true; +                } else if (boost::algorithm::to_lower_copy(str_rep) == "false" +                           || boost::algorithm::to_lower_copy(str_rep) == "no" +                           || boost::algorithm::to_lower_copy(str_rep) == "n" +                           || str_rep == "0") { +                    _value = false; +                } else { +                    throw uhd::value_error( +                        str(boost::format("Error parsing boolean parameter %s: %s.") +                            % key() % ex.what()));                  }              } -            inline virtual std::string to_string() const { -                return key() + "=" + (get() ? "true" : "false"); -            } -        private: -            bool _value; -        }; +        } +        inline virtual std::string to_string() const +        { +            return key() + "=" + (get() ? "true" : "false"); +        } -    public: //Methods -        constrained_device_args_t() {} -        virtual ~constrained_device_args_t() {} +    private: +        bool _value; +    }; -        void parse(const std::string& str_args) { -            device_addr_t dev_args(str_args); -            _parse(dev_args); -        } +public: // Methods +    constrained_device_args_t() {} +    virtual ~constrained_device_args_t() {} -        void parse(const device_addr_t& dev_args) { -            _parse(dev_args); -        } +    void parse(const std::string& str_args) +    { +        device_addr_t dev_args(str_args); +        _parse(dev_args); +    } -        inline virtual std::string to_string() const = 0; +    void parse(const device_addr_t& dev_args) +    { +        _parse(dev_args); +    } -        template <typename arg_type> -        void parse_arg_default( -            const device_addr_t& dev_args, -            arg_type& constrained_arg -        ) { -            if (dev_args.has_key(constrained_arg.key())) { -                constrained_arg.parse(dev_args[constrained_arg.key()]); -            } +    inline virtual std::string to_string() const = 0; + +    template <typename arg_type> +    void parse_arg_default(const device_addr_t& dev_args, arg_type& constrained_arg) +    { +        if (dev_args.has_key(constrained_arg.key())) { +            constrained_arg.parse(dev_args[constrained_arg.key()]);          } +    } -    protected:  //Methods -        //Override _parse to provide an implementation to parse all -        //client specific device args -        virtual void _parse(const device_addr_t& dev_args) = 0; +protected: // Methods +    // Override _parse to provide an implementation to parse all +    // client specific device args +    virtual void _parse(const device_addr_t& dev_args) = 0; -        /*! -         * Utility: Ensure that the value of the device arg is between min and max -         */ -        template<typename num_data_t> -        static inline void _enforce_range(const num_arg<num_data_t>& arg, const num_data_t& min, const num_data_t& max) { -            if (arg.get() > max || arg.get() < min) { -                throw uhd::value_error(str(boost::format( -                    "Invalid device arg value: %s (Minimum: %s, Maximum: %s)") % -                    arg.to_string() % -                    std::to_string(min) % std::to_string(max))); -            } +    /*! +     * Utility: Ensure that the value of the device arg is between min and max +     */ +    template <typename num_data_t> +    static inline void _enforce_range( +        const num_arg<num_data_t>& arg, const num_data_t& min, const num_data_t& max) +    { +        if (arg.get() > max || arg.get() < min) { +            throw uhd::value_error(str( +                boost::format("Invalid device arg value: %s (Minimum: %s, Maximum: %s)") +                % arg.to_string() % std::to_string(min) % std::to_string(max)));          } +    } -        /*! -         * Utility: Ensure that the value of the device arg is is contained in valid_values -         */ -        template<typename arg_t, typename data_t> -        static inline void _enforce_discrete(const arg_t& arg, const std::vector<data_t>& valid_values) { -            bool match = false; -            for(const data_t& val:  valid_values) { -                if (val == arg.get()) { -                    match = true; -                    break; -                } +    /*! +     * Utility: Ensure that the value of the device arg is is contained in valid_values +     */ +    template <typename arg_t, typename data_t> +    static inline void _enforce_discrete( +        const arg_t& arg, const std::vector<data_t>& valid_values) +    { +        bool match = false; +        for (const data_t& val : valid_values) { +            if (val == arg.get()) { +                match = true; +                break;              } -            if (!match) { -                std::string valid_values_str; -                for (size_t i = 0; i < valid_values.size(); i++) { -                    std::stringstream valid_values_ss; -                    valid_values_ss << ((i==0)?"":", ") << valid_values[i]; -                    throw uhd::value_error(str(boost::format( -                        "Invalid device arg value: %s (Valid: {%s})") % -                        arg.to_string() % valid_values_ss.str() -                    )); -                } +        } +        if (!match) { +            std::string valid_values_str; +            for (size_t i = 0; i < valid_values.size(); i++) { +                std::stringstream valid_values_ss; +                valid_values_ss << ((i == 0) ? "" : ", ") << valid_values[i]; +                throw uhd::value_error( +                    str(boost::format("Invalid device arg value: %s (Valid: {%s})") +                        % arg.to_string() % valid_values_ss.str()));              }          } +    } -        //! Helper for enum_arg: Create a new map where keys are converted to -        //  lowercase. -        template<typename enum_t> -        static std::unordered_map<std::string, enum_t> _enum_map_to_lowercase( -            const std::unordered_map<std::string, enum_t>& in_map -        ) { -            std::unordered_map<std::string, enum_t> new_map; -            for (const auto& str_to_enum : in_map) { -                new_map.insert( -                    std::pair<std::string, enum_t>( -                        boost::algorithm::to_lower_copy(str_to_enum.first), -                        str_to_enum.second -                    ) -                ); -            } -            return new_map; +    //! Helper for enum_arg: Create a new map where keys are converted to +    //  lowercase. +    template <typename enum_t> +    static std::unordered_map<std::string, enum_t> _enum_map_to_lowercase( +        const std::unordered_map<std::string, enum_t>& in_map) +    { +        std::unordered_map<std::string, enum_t> new_map; +        for (const auto& str_to_enum : in_map) { +            new_map.insert(std::pair<std::string, enum_t>( +                boost::algorithm::to_lower_copy(str_to_enum.first), str_to_enum.second));          } -    }; -}} //namespaces +        return new_map; +    } +}; +}} // namespace uhd::usrp  #endif /* INCLUDED_LIBUHD_USRP_COMMON_CONSTRAINED_DEV_ARGS_HPP */ diff --git a/host/lib/include/uhdlib/usrp/cores/dsp_core_utils.hpp b/host/lib/include/uhdlib/usrp/cores/dsp_core_utils.hpp index 2632f4a1f..5e1c90845 100644 --- a/host/lib/include/uhdlib/usrp/cores/dsp_core_utils.hpp +++ b/host/lib/include/uhdlib/usrp/cores/dsp_core_utils.hpp @@ -13,12 +13,10 @@  /*! For a requested frequency and sampling rate, return the   *  correct frequency word (to set the CORDIC) and the actual frequency.   */ -void get_freq_and_freq_word( -        const double requested_freq, -        const double tick_rate, -        double &actual_freq, -        int32_t &freq_word -); +void get_freq_and_freq_word(const double requested_freq, +    const double tick_rate, +    double& actual_freq, +    int32_t& freq_word);  /*! For a requested frequency and sampling rate, return the   *  correct frequency word (to set the CORDIC) and the actual frequency. diff --git a/host/lib/include/uhdlib/usrp/cores/gpio_core_200.hpp b/host/lib/include/uhdlib/usrp/cores/gpio_core_200.hpp index d6f104be1..920dd1e3c 100644 --- a/host/lib/include/uhdlib/usrp/cores/gpio_core_200.hpp +++ b/host/lib/include/uhdlib/usrp/cores/gpio_core_200.hpp @@ -9,15 +9,16 @@  #define INCLUDED_LIBUHD_USRP_GPIO_CORE_200_HPP  #include <uhd/config.hpp> +#include <uhd/types/wb_iface.hpp>  #include <uhd/usrp/dboard_iface.hpp>  #include <uhd/usrp/gpio_defs.hpp>  #include <uhd/utils/noncopyable.hpp> -#include <memory> -#include <uhd/types/wb_iface.hpp> -#include <map>  #include <stdint.h> +#include <map> +#include <memory> -class gpio_core_200 : uhd::noncopyable{ +class gpio_core_200 : uhd::noncopyable +{  public:      typedef std::shared_ptr<gpio_core_200> sptr; @@ -27,8 +28,7 @@ public:      virtual ~gpio_core_200(void) = 0;      //! makes a new GPIO core from iface and slave base -    static sptr make( -        uhd::wb_iface::sptr iface, const size_t base, const size_t rb_addr); +    static sptr make(uhd::wb_iface::sptr iface, const size_t base, const size_t rb_addr);      //! 1 = ATR      virtual void set_pin_ctrl( @@ -36,8 +36,10 @@ public:      virtual uint16_t get_pin_ctrl(unit_t unit) = 0; -    virtual void set_atr_reg( -        const unit_t unit, const atr_reg_t atr, const uint16_t value, const uint16_t mask) = 0; +    virtual void set_atr_reg(const unit_t unit, +        const atr_reg_t atr, +        const uint16_t value, +        const uint16_t mask) = 0;      virtual uint16_t get_atr_reg(unit_t unit, atr_reg_t reg) = 0; @@ -56,7 +58,8 @@ public:  };  //! Simple wrapper for 32 bit write only -class gpio_core_200_32wo : uhd::noncopyable{ +class gpio_core_200_32wo : uhd::noncopyable +{  public:      typedef std::shared_ptr<gpio_core_200_32wo> sptr; diff --git a/host/lib/include/uhdlib/usrp/cores/i2c_core_100_wb32.hpp b/host/lib/include/uhdlib/usrp/cores/i2c_core_100_wb32.hpp index 42e57ca16..15afda0ef 100644 --- a/host/lib/include/uhdlib/usrp/cores/i2c_core_100_wb32.hpp +++ b/host/lib/include/uhdlib/usrp/cores/i2c_core_100_wb32.hpp @@ -10,11 +10,12 @@  #include <uhd/config.hpp>  #include <uhd/types/serial.hpp> -#include <uhd/utils/noncopyable.hpp>  #include <uhd/types/wb_iface.hpp> +#include <uhd/utils/noncopyable.hpp>  #include <memory> -class i2c_core_100_wb32 : uhd::noncopyable, public uhd::i2c_iface{ +class i2c_core_100_wb32 : uhd::noncopyable, public uhd::i2c_iface +{  public:      typedef std::shared_ptr<i2c_core_100_wb32> sptr; diff --git a/host/lib/include/uhdlib/usrp/cores/i2c_core_200.hpp b/host/lib/include/uhdlib/usrp/cores/i2c_core_200.hpp index 6d987b68a..2f6c4da79 100644 --- a/host/lib/include/uhdlib/usrp/cores/i2c_core_200.hpp +++ b/host/lib/include/uhdlib/usrp/cores/i2c_core_200.hpp @@ -10,12 +10,13 @@  #include <uhd/config.hpp>  #include <uhd/types/serial.hpp> +#include <uhd/types/wb_iface.hpp>  #include <uhd/utils/noncopyable.hpp>  #include <boost/utility.hpp>  #include <memory> -#include <uhd/types/wb_iface.hpp> -class i2c_core_200 : uhd::noncopyable, public uhd::i2c_iface{ +class i2c_core_200 : uhd::noncopyable, public uhd::i2c_iface +{  public:      typedef std::shared_ptr<i2c_core_200> sptr; diff --git a/host/lib/include/uhdlib/usrp/cores/radio_ctrl_core_3000.hpp b/host/lib/include/uhdlib/usrp/cores/radio_ctrl_core_3000.hpp index 427a72586..c94217e82 100644 --- a/host/lib/include/uhdlib/usrp/cores/radio_ctrl_core_3000.hpp +++ b/host/lib/include/uhdlib/usrp/cores/radio_ctrl_core_3000.hpp @@ -8,12 +8,12 @@  #ifndef INCLUDED_LIBUHD_USRP_RADIO_CTRL_3000_HPP  #define INCLUDED_LIBUHD_USRP_RADIO_CTRL_3000_HPP -#include <uhd/utils/msg_task.hpp> -#include <uhd/types/time_spec.hpp>  #include <uhd/transport/zero_copy.hpp> +#include <uhd/types/time_spec.hpp>  #include <uhd/types/wb_iface.hpp> -#include <memory> +#include <uhd/utils/msg_task.hpp>  #include <boost/utility.hpp> +#include <memory>  #include <string>  /*! @@ -27,22 +27,20 @@ public:      virtual ~radio_ctrl_core_3000(void) = 0;      //! Make a new control object -    static sptr make( -        const bool big_endian, +    static sptr make(const bool big_endian,          uhd::transport::zero_copy_if::sptr ctrl_xport,          uhd::transport::zero_copy_if::sptr resp_xport,          const uint32_t sid, -        const std::string &name = "0" -    ); +        const std::string& name = "0");      //! Hold a ref to a task thats feeding push response      virtual void hold_task(uhd::msg_task::sptr task) = 0;      //! Push a response externall (resp_xport is NULL) -    virtual void push_response(const uint32_t *buff) = 0; +    virtual void push_response(const uint32_t* buff) = 0;      //! Set the command time that will activate -    virtual void set_time(const uhd::time_spec_t &time) = 0; +    virtual void set_time(const uhd::time_spec_t& time) = 0;      //! Get the command time that will activate      virtual uhd::time_spec_t get_time(void) = 0; diff --git a/host/lib/include/uhdlib/usrp/cores/rx_dsp_core_200.hpp b/host/lib/include/uhdlib/usrp/cores/rx_dsp_core_200.hpp index 240838495..7f0cd9995 100644 --- a/host/lib/include/uhdlib/usrp/cores/rx_dsp_core_200.hpp +++ b/host/lib/include/uhdlib/usrp/cores/rx_dsp_core_200.hpp @@ -11,31 +11,32 @@  #include <uhd/config.hpp>  #include <uhd/stream.hpp>  #include <uhd/types/ranges.hpp> -#include <uhd/utils/noncopyable.hpp> -#include <memory>  #include <uhd/types/stream_cmd.hpp>  #include <uhd/types/wb_iface.hpp> +#include <uhd/utils/noncopyable.hpp> +#include <memory>  #include <string> -class rx_dsp_core_200 : uhd::noncopyable{ +class rx_dsp_core_200 : uhd::noncopyable +{  public:      typedef std::shared_ptr<rx_dsp_core_200> sptr;      virtual ~rx_dsp_core_200(void) = 0; -    static sptr make( -        uhd::wb_iface::sptr iface, -        const size_t dsp_base, const size_t ctrl_base, -        const uint32_t sid, const bool lingering_packet = false -    ); +    static sptr make(uhd::wb_iface::sptr iface, +        const size_t dsp_base, +        const size_t ctrl_base, +        const uint32_t sid, +        const bool lingering_packet = false);      virtual void clear(void) = 0;      virtual void set_nsamps_per_packet(const size_t nsamps) = 0; -    virtual void issue_stream_command(const uhd::stream_cmd_t &stream_cmd) = 0; +    virtual void issue_stream_command(const uhd::stream_cmd_t& stream_cmd) = 0; -    virtual void set_mux(const std::string &mode, const bool fe_swapped = false) = 0; +    virtual void set_mux(const std::string& mode, const bool fe_swapped = false) = 0;      virtual void set_tick_rate(const double rate) = 0; @@ -53,7 +54,7 @@ public:      virtual void handle_overflow(void) = 0; -    virtual void setup(const uhd::stream_args_t &stream_args) = 0; +    virtual void setup(const uhd::stream_args_t& stream_args) = 0;  };  #endif /* INCLUDED_LIBUHD_USRP_RX_DSP_CORE_200_HPP */ diff --git a/host/lib/include/uhdlib/usrp/cores/rx_frontend_core_200.hpp b/host/lib/include/uhdlib/usrp/cores/rx_frontend_core_200.hpp index 6a91f83da..8c51dac6c 100644 --- a/host/lib/include/uhdlib/usrp/cores/rx_frontend_core_200.hpp +++ b/host/lib/include/uhdlib/usrp/cores/rx_frontend_core_200.hpp @@ -9,14 +9,15 @@  #define INCLUDED_LIBUHD_USRP_TX_FRONTEND_CORE_200_HPP  #include <uhd/config.hpp> -#include <uhd/types/wb_iface.hpp>  #include <uhd/property_tree.hpp> +#include <uhd/types/wb_iface.hpp>  #include <uhd/utils/noncopyable.hpp> -#include <memory>  #include <complex> +#include <memory>  #include <string> -class rx_frontend_core_200 : uhd::noncopyable{ +class rx_frontend_core_200 : uhd::noncopyable +{  public:      static const std::complex<double> DEFAULT_DC_OFFSET_VALUE;      static const bool DEFAULT_DC_OFFSET_ENABLE; @@ -32,12 +33,11 @@ public:      virtual void set_dc_offset_auto(const bool enb) = 0; -    virtual std::complex<double> set_dc_offset(const std::complex<double> &off) = 0; +    virtual std::complex<double> set_dc_offset(const std::complex<double>& off) = 0; -    virtual void set_iq_balance(const std::complex<double> &cor) = 0; +    virtual void set_iq_balance(const std::complex<double>& cor) = 0;      virtual void populate_subtree(uhd::property_tree::sptr subtree) = 0; -  };  #endif /* INCLUDED_LIBUHD_USRP_TX_FRONTEND_CORE_200_HPP */ diff --git a/host/lib/include/uhdlib/usrp/cores/rx_frontend_core_3000.hpp b/host/lib/include/uhdlib/usrp/cores/rx_frontend_core_3000.hpp index b1dfd307e..d340d6f4d 100644 --- a/host/lib/include/uhdlib/usrp/cores/rx_frontend_core_3000.hpp +++ b/host/lib/include/uhdlib/usrp/cores/rx_frontend_core_3000.hpp @@ -13,8 +13,8 @@  #include <uhd/types/wb_iface.hpp>  #include <uhd/usrp/fe_connection.hpp>  #include <uhd/utils/noncopyable.hpp> -#include <memory>  #include <complex> +#include <memory>  #include <string>  class rx_frontend_core_3000 : uhd::noncopyable diff --git a/host/lib/include/uhdlib/usrp/cores/rx_vita_core_3000.hpp b/host/lib/include/uhdlib/usrp/cores/rx_vita_core_3000.hpp index 615ca2319..0f1850ddc 100644 --- a/host/lib/include/uhdlib/usrp/cores/rx_vita_core_3000.hpp +++ b/host/lib/include/uhdlib/usrp/cores/rx_vita_core_3000.hpp @@ -11,10 +11,10 @@  #include <uhd/config.hpp>  #include <uhd/stream.hpp>  #include <uhd/types/ranges.hpp> -#include <uhd/utils/noncopyable.hpp> -#include <memory>  #include <uhd/types/stream_cmd.hpp>  #include <uhd/types/wb_iface.hpp> +#include <uhd/utils/noncopyable.hpp> +#include <memory>  #include <string>  class rx_vita_core_3000 : uhd::noncopyable @@ -24,16 +24,13 @@ public:      virtual ~rx_vita_core_3000(void) = 0; -    static sptr make( -        uhd::wb_iface::sptr iface, -        const size_t base -    ); +    static sptr make(uhd::wb_iface::sptr iface, const size_t base);      virtual void clear(void) = 0;      virtual void set_nsamps_per_packet(const size_t nsamps) = 0; -    virtual void issue_stream_command(const uhd::stream_cmd_t &stream_cmd) = 0; +    virtual void issue_stream_command(const uhd::stream_cmd_t& stream_cmd) = 0;      virtual void set_tick_rate(const double rate) = 0; @@ -41,7 +38,7 @@ public:      virtual void handle_overflow(void) = 0; -    virtual void setup(const uhd::stream_args_t &stream_args) = 0; +    virtual void setup(const uhd::stream_args_t& stream_args) = 0;      virtual void configure_flow_control(const size_t window_size) = 0; diff --git a/host/lib/include/uhdlib/usrp/cores/spi_core_3000.hpp b/host/lib/include/uhdlib/usrp/cores/spi_core_3000.hpp index 4d08071f7..6dc0474ce 100644 --- a/host/lib/include/uhdlib/usrp/cores/spi_core_3000.hpp +++ b/host/lib/include/uhdlib/usrp/cores/spi_core_3000.hpp @@ -10,16 +10,15 @@  #include <uhd/config.hpp>  #include <uhd/types/serial.hpp> -#include <uhd/utils/noncopyable.hpp>  #include <uhd/types/wb_iface.hpp> -#include <memory> -#include <memory> +#include <uhd/utils/noncopyable.hpp>  #include <functional> +#include <memory>  class spi_core_3000 : uhd::noncopyable, public uhd::spi_iface  {  public: -    using sptr = std::shared_ptr<spi_core_3000>; +    using sptr        = std::shared_ptr<spi_core_3000>;      using poke32_fn_t = std::function<void(uint32_t, uint32_t)>;      using peek32_fn_t = std::function<uint32_t(uint32_t)>; diff --git a/host/lib/include/uhdlib/usrp/cores/time64_core_200.hpp b/host/lib/include/uhdlib/usrp/cores/time64_core_200.hpp index 4001d7d4d..27ef775f8 100644 --- a/host/lib/include/uhdlib/usrp/cores/time64_core_200.hpp +++ b/host/lib/include/uhdlib/usrp/cores/time64_core_200.hpp @@ -10,18 +10,20 @@  #include <uhd/config.hpp>  #include <uhd/types/time_spec.hpp> -#include <uhd/utils/noncopyable.hpp>  #include <uhd/types/wb_iface.hpp> +#include <uhd/utils/noncopyable.hpp>  #include <boost/utility.hpp>  #include <memory>  #include <string>  #include <vector> -class time64_core_200 : uhd::noncopyable{ +class time64_core_200 : uhd::noncopyable +{  public:      typedef std::shared_ptr<time64_core_200> sptr; -    struct readback_bases_type{ +    struct readback_bases_type +    {          size_t rb_hi_now, rb_lo_now;          size_t rb_hi_pps, rb_lo_pps;      }; @@ -29,9 +31,9 @@ public:      virtual ~time64_core_200(void) = 0;      //! makes a new time64 core from iface and slave base -    static sptr make( -        uhd::wb_iface::sptr iface, const size_t base, -        const readback_bases_type &readback_bases, +    static sptr make(uhd::wb_iface::sptr iface, +        const size_t base, +        const readback_bases_type& readback_bases,          const size_t mimo_delay_cycles = 0 // 0 means no-mimo      ); @@ -43,14 +45,13 @@ public:      virtual uhd::time_spec_t get_time_last_pps(void) = 0; -    virtual void set_time_now(const uhd::time_spec_t &time) = 0; +    virtual void set_time_now(const uhd::time_spec_t& time) = 0; -    virtual void set_time_next_pps(const uhd::time_spec_t &time) = 0; +    virtual void set_time_next_pps(const uhd::time_spec_t& time) = 0; -    virtual void set_time_source(const std::string &source) = 0; +    virtual void set_time_source(const std::string& source) = 0;      virtual std::vector<std::string> get_time_sources(void) = 0; -  };  #endif /* INCLUDED_LIBUHD_USRP_TIME64_CORE_200_HPP */ diff --git a/host/lib/include/uhdlib/usrp/cores/time_core_3000.hpp b/host/lib/include/uhdlib/usrp/cores/time_core_3000.hpp index 8031ed130..93575bfaa 100644 --- a/host/lib/include/uhdlib/usrp/cores/time_core_3000.hpp +++ b/host/lib/include/uhdlib/usrp/cores/time_core_3000.hpp @@ -10,9 +10,9 @@  #include <uhd/config.hpp>  #include <uhd/types/time_spec.hpp> +#include <uhd/types/wb_iface.hpp>  #include <uhd/utils/noncopyable.hpp>  #include <memory> -#include <uhd/types/wb_iface.hpp>  class time_core_3000 : uhd::noncopyable  { @@ -28,10 +28,9 @@ public:      virtual ~time_core_3000(void) = 0;      //! makes a new time core from iface and slave base -    static sptr make( -        uhd::wb_iface::sptr iface, const size_t base, -        const readback_bases_type &readback_bases -    ); +    static sptr make(uhd::wb_iface::sptr iface, +        const size_t base, +        const readback_bases_type& readback_bases);      virtual void self_test(void) = 0; @@ -41,12 +40,11 @@ public:      virtual uhd::time_spec_t get_time_last_pps(void) = 0; -    virtual void set_time_now(const uhd::time_spec_t &time) = 0; - -    virtual void set_time_sync(const uhd::time_spec_t &time) = 0; +    virtual void set_time_now(const uhd::time_spec_t& time) = 0; -    virtual void set_time_next_pps(const uhd::time_spec_t &time) = 0; +    virtual void set_time_sync(const uhd::time_spec_t& time) = 0; +    virtual void set_time_next_pps(const uhd::time_spec_t& time) = 0;  };  #endif /* INCLUDED_LIBUHD_USRP_TIME_CORE_3000_HPP */ diff --git a/host/lib/include/uhdlib/usrp/cores/tx_dsp_core_200.hpp b/host/lib/include/uhdlib/usrp/cores/tx_dsp_core_200.hpp index 86a704c66..55423bceb 100644 --- a/host/lib/include/uhdlib/usrp/cores/tx_dsp_core_200.hpp +++ b/host/lib/include/uhdlib/usrp/cores/tx_dsp_core_200.hpp @@ -11,21 +11,21 @@  #include <uhd/config.hpp>  #include <uhd/stream.hpp>  #include <uhd/types/ranges.hpp> +#include <uhd/types/wb_iface.hpp>  #include <uhd/utils/noncopyable.hpp>  #include <memory> -#include <uhd/types/wb_iface.hpp> -class tx_dsp_core_200 : uhd::noncopyable{ +class tx_dsp_core_200 : uhd::noncopyable +{  public:      typedef std::shared_ptr<tx_dsp_core_200> sptr;      virtual ~tx_dsp_core_200(void) = 0; -    static sptr make( -        uhd::wb_iface::sptr iface, -        const size_t dsp_base, const size_t ctrl_base, -        const uint32_t sid -    ); +    static sptr make(uhd::wb_iface::sptr iface, +        const size_t dsp_base, +        const size_t ctrl_base, +        const uint32_t sid);      virtual void clear(void) = 0; @@ -45,7 +45,7 @@ public:      virtual void set_updates(const size_t cycles_per_up, const size_t packets_per_up) = 0; -    virtual void setup(const uhd::stream_args_t &stream_args) = 0; +    virtual void setup(const uhd::stream_args_t& stream_args) = 0;  };  #endif /* INCLUDED_LIBUHD_USRP_TX_DSP_CORE_200_HPP */ diff --git a/host/lib/include/uhdlib/usrp/cores/tx_frontend_core_200.hpp b/host/lib/include/uhdlib/usrp/cores/tx_frontend_core_200.hpp index 8a7178bb4..23a097085 100644 --- a/host/lib/include/uhdlib/usrp/cores/tx_frontend_core_200.hpp +++ b/host/lib/include/uhdlib/usrp/cores/tx_frontend_core_200.hpp @@ -9,14 +9,15 @@  #define INCLUDED_LIBUHD_USRP_RX_FRONTEND_CORE_200_HPP  #include <uhd/config.hpp> -#include <uhd/types/wb_iface.hpp>  #include <uhd/property_tree.hpp> +#include <uhd/types/wb_iface.hpp>  #include <uhd/utils/noncopyable.hpp> -#include <memory>  #include <complex> +#include <memory>  #include <string> -class tx_frontend_core_200 : uhd::noncopyable{ +class tx_frontend_core_200 : uhd::noncopyable +{  public:      typedef std::shared_ptr<tx_frontend_core_200> sptr; @@ -25,16 +26,16 @@ public:      virtual ~tx_frontend_core_200(void) = 0; -    static sptr make(uhd::wb_iface::sptr iface, const size_t base, const size_t offset=4); +    static sptr make( +        uhd::wb_iface::sptr iface, const size_t base, const size_t offset = 4); -    virtual void set_mux(const std::string &mode) = 0; +    virtual void set_mux(const std::string& mode) = 0; -    virtual std::complex<double> set_dc_offset(const std::complex<double> &off) = 0; +    virtual std::complex<double> set_dc_offset(const std::complex<double>& off) = 0; -    virtual void set_iq_balance(const std::complex<double> &cor) = 0; +    virtual void set_iq_balance(const std::complex<double>& cor) = 0;      virtual void populate_subtree(uhd::property_tree::sptr subtree) = 0; -  };  #endif /* INCLUDED_LIBUHD_USRP_RX_FRONTEND_CORE_200_HPP */ diff --git a/host/lib/include/uhdlib/usrp/cores/tx_vita_core_3000.hpp b/host/lib/include/uhdlib/usrp/cores/tx_vita_core_3000.hpp index 9d03549de..22b6865c1 100644 --- a/host/lib/include/uhdlib/usrp/cores/tx_vita_core_3000.hpp +++ b/host/lib/include/uhdlib/usrp/cores/tx_vita_core_3000.hpp @@ -11,10 +11,10 @@  #include <uhd/config.hpp>  #include <uhd/stream.hpp>  #include <uhd/types/ranges.hpp> -#include <uhd/utils/noncopyable.hpp> -#include <memory>  #include <uhd/types/stream_cmd.hpp>  #include <uhd/types/wb_iface.hpp> +#include <uhd/utils/noncopyable.hpp> +#include <memory>  #include <string>  class tx_vita_core_3000 : uhd::noncopyable @@ -22,30 +22,22 @@ class tx_vita_core_3000 : uhd::noncopyable  public:      typedef std::shared_ptr<tx_vita_core_3000> sptr; -    enum fc_monitor_loc { -        FC_DEFAULT, -        FC_PRE_RADIO, -        FC_PRE_FIFO -    }; +    enum fc_monitor_loc { FC_DEFAULT, FC_PRE_RADIO, FC_PRE_FIFO };      virtual ~tx_vita_core_3000(void) = 0; -    static sptr make( -        uhd::wb_iface::sptr iface, +    static sptr make(uhd::wb_iface::sptr iface,          const size_t base, -        fc_monitor_loc fc_location = FC_PRE_RADIO -    ); +        fc_monitor_loc fc_location = FC_PRE_RADIO); -    static sptr make_no_radio_buff( -        uhd::wb_iface::sptr iface, -        const size_t base -    ); +    static sptr make_no_radio_buff(uhd::wb_iface::sptr iface, const size_t base);      virtual void clear(void) = 0; -    virtual void setup(const uhd::stream_args_t &stream_args) = 0; +    virtual void setup(const uhd::stream_args_t& stream_args) = 0; -    virtual void configure_flow_control(const size_t cycs_per_up, const size_t pkts_per_up) = 0; +    virtual void configure_flow_control( +        const size_t cycs_per_up, const size_t pkts_per_up) = 0;  };  #endif /* INCLUDED_LIBUHD_USRP_TX_VITA_CORE_3000_HPP */ diff --git a/host/lib/include/uhdlib/usrp/cores/user_settings_core_200.hpp b/host/lib/include/uhdlib/usrp/cores/user_settings_core_200.hpp index 810c8fd7e..717b4a8b1 100644 --- a/host/lib/include/uhdlib/usrp/cores/user_settings_core_200.hpp +++ b/host/lib/include/uhdlib/usrp/cores/user_settings_core_200.hpp @@ -9,12 +9,13 @@  #define INCLUDED_LIBUHD_USRP_USER_SETTINGS_CORE_200_HPP  #include <uhd/config.hpp> -#include <uhd/utils/noncopyable.hpp>  #include <uhd/types/wb_iface.hpp> +#include <uhd/utils/noncopyable.hpp>  #include <boost/utility.hpp>  #include <memory> -class user_settings_core_200 : uhd::noncopyable{ +class user_settings_core_200 : uhd::noncopyable +{  public:      typedef std::shared_ptr<user_settings_core_200> sptr;      typedef std::pair<uint8_t, uint32_t> user_reg_t; @@ -23,7 +24,7 @@ public:      static sptr make(uhd::wb_iface::sptr iface, const size_t base); -    virtual void set_reg(const user_reg_t ®) = 0; +    virtual void set_reg(const user_reg_t& reg) = 0;  };  #endif /* INCLUDED_LIBUHD_USRP_USER_SETTINGS_CORE_200_HPP */ diff --git a/host/lib/include/uhdlib/usrp/cores/user_settings_core_3000.hpp b/host/lib/include/uhdlib/usrp/cores/user_settings_core_3000.hpp index 4b6d0bd6c..002b04a3f 100644 --- a/host/lib/include/uhdlib/usrp/cores/user_settings_core_3000.hpp +++ b/host/lib/include/uhdlib/usrp/cores/user_settings_core_3000.hpp @@ -9,17 +9,18 @@  #define INCLUDED_LIBUHD_USRP_USER_SETTINGS_CORE_3000_HPP  #include <uhd/config.hpp> +#include <uhd/types/wb_iface.hpp>  #include <boost/utility.hpp>  #include <memory> -#include <uhd/types/wb_iface.hpp> -class user_settings_core_3000 : public uhd::wb_iface { +class user_settings_core_3000 : public uhd::wb_iface +{  public:      virtual ~user_settings_core_3000() {} -    static sptr make( -        wb_iface::sptr iface, -        const wb_addr_type sr_base_addr, const wb_addr_type rb_reg_addr); +    static sptr make(wb_iface::sptr iface, +        const wb_addr_type sr_base_addr, +        const wb_addr_type rb_reg_addr);  };  #endif /* INCLUDED_LIBUHD_USRP_USER_SETTINGS_CORE_3000_HPP */ diff --git a/host/lib/include/uhdlib/usrp/gpio_defs.hpp b/host/lib/include/uhdlib/usrp/gpio_defs.hpp index b16ea7311..09d74cfad 100644 --- a/host/lib/include/uhdlib/usrp/gpio_defs.hpp +++ b/host/lib/include/uhdlib/usrp/gpio_defs.hpp @@ -13,115 +13,90 @@  namespace uhd { namespace usrp { namespace gpio_atr { -    enum gpio_atr_mode_t { -        MODE_ATR  = 0,   //Output driven by the auto-transmit-receive engine -        MODE_GPIO = 1    //Output value is static -    }; - -    enum gpio_ddr_t { -        DDR_INPUT   = 0, -        DDR_OUTPUT  = 1 -    }; - -    enum gpio_attr_t { -        GPIO_SRC, -        GPIO_CTRL, -        GPIO_DDR, -        GPIO_OUT, -        GPIO_ATR_0X, -        GPIO_ATR_RX, -        GPIO_ATR_TX, -        GPIO_ATR_XX, -        GPIO_READBACK -    }; - -    static const std::string GPIO_ATTR_SRC = "SRC"; -    //! Attribute name for GPIO control. -    static const std::string GPIO_ATTR_CTRL = "CTRL"; -    //! Attribute name for GPIO data direction register. -    static const std::string GPIO_ATTR_DDR = "DDR"; -    //! Attribute name for GPIO ouput value. -    static const std::string GPIO_ATTR_OUT = "OUT"; -    //! Attribute name for GPIO ATR idle state register. -    static const std::string GPIO_ATTR_ATR0X = "ATR_0X"; -    //! Attribute name for GPIO ATR receive only register. -    static const std::string GPIO_ATTR_ATRRX = "ATR_RX"; -    //! Attribute name for GPIO ATR transmit only register. -    static const std::string GPIO_ATTR_ATRTX = "ATR_TX"; -    //! Attribute name for GPIO ATR  full duplex state register. -    static const std::string GPIO_ATTR_ATRXX = "ATR_XX"; -    //!  Attribute name for GPIO READBACK  register. -    static const std::string GPIO_ATTR_READBACK = "READBACK"; - -    typedef std::map<gpio_attr_t, std::string> gpio_attr_map_t; - -    static const gpio_attr_map_t gpio_attr_map{ -        {GPIO_SRC,       GPIO_ATTR_SRC}, -        {GPIO_CTRL,      GPIO_ATTR_CTRL}, -        {GPIO_DDR,       GPIO_ATTR_DDR}, -        {GPIO_OUT,       GPIO_ATTR_OUT}, -        {GPIO_ATR_0X,    GPIO_ATTR_ATR0X}, -        {GPIO_ATR_RX,    GPIO_ATTR_ATRRX}, -        {GPIO_ATR_TX,    GPIO_ATTR_ATRTX}, -        {GPIO_ATR_XX,    GPIO_ATTR_ATRXX}, -        {GPIO_READBACK,  GPIO_ATTR_READBACK} -    }; - -    static const std::map<gpio_attr_t, std::map<uint32_t, std::string>> attr_value_map{ -        {GPIO_CTRL, {{0, "ATR"},   {1, "GPIO"}}}, -        {GPIO_DDR,  {{0, "INPUT"}, {1, "OUTPUT"}}} -    }; - -    static const std::map<std::string, gpio_attr_t> gpio_attr_rev_map{ -        {GPIO_ATTR_SRC,      GPIO_SRC}, -        {GPIO_ATTR_CTRL,     GPIO_CTRL}, -        {GPIO_ATTR_DDR,      GPIO_DDR}, -        {GPIO_ATTR_OUT,      GPIO_OUT}, -        {GPIO_ATTR_ATR0X,    GPIO_ATR_0X}, -        {GPIO_ATTR_ATRRX,    GPIO_ATR_RX}, -        {GPIO_ATTR_ATRTX,    GPIO_ATR_TX}, -        {GPIO_ATTR_ATRXX,    GPIO_ATR_XX}, -        {GPIO_ATTR_READBACK, GPIO_READBACK} -    }; - -    static const gpio_attr_map_t default_attr_value_map{ -        {GPIO_SRC,  "RADIO_0/0"}, -        {GPIO_CTRL, "GPIO"}, -        {GPIO_DDR,  "INPUT"} -    }; - -    static const std::map<std::string, uint32_t> gpio_level_map{ -        {"HIGH",  1}, -        {"LOW",   0}, -        {"ON",    1}, -        {"OFF",   0}, -        {"TRUE",  1}, -        {"FALSE", 0} -    }; - -    static const std::map<std::string, uint32_t> gpio_direction{ -        {"OUT",    1}, -        {"IN",     0}, -        {"OUTPUT", 1}, -        {"INPUT",  0} -    }; - -    static const std::map<std::string, uint32_t> gpio_ctrl_mode{ -        {"ATR",  0}, -        {"GPIO", 1} -    }; - -    static const std::map<std::string, std::map<std::string, uint32_t>> gpio_attr_value_pair{ -        {GPIO_ATTR_CTRL,     uhd::usrp::gpio_atr::gpio_ctrl_mode}, -        {GPIO_ATTR_DDR,      uhd::usrp::gpio_atr::gpio_direction}, -        {GPIO_ATTR_OUT,      uhd::usrp::gpio_atr::gpio_level_map}, -        {GPIO_ATTR_ATR0X,    uhd::usrp::gpio_atr::gpio_level_map}, -        {GPIO_ATTR_ATRRX,    uhd::usrp::gpio_atr::gpio_level_map}, -        {GPIO_ATTR_ATRTX,    uhd::usrp::gpio_atr::gpio_level_map}, -        {GPIO_ATTR_ATRXX,    uhd::usrp::gpio_atr::gpio_level_map}, -        {GPIO_ATTR_READBACK, uhd::usrp::gpio_atr::gpio_level_map} -    }; - -}}} //namespaces +enum gpio_atr_mode_t { +    MODE_ATR  = 0, // Output driven by the auto-transmit-receive engine +    MODE_GPIO = 1 // Output value is static +}; + +enum gpio_ddr_t { DDR_INPUT = 0, DDR_OUTPUT = 1 }; + +enum gpio_attr_t { +    GPIO_SRC, +    GPIO_CTRL, +    GPIO_DDR, +    GPIO_OUT, +    GPIO_ATR_0X, +    GPIO_ATR_RX, +    GPIO_ATR_TX, +    GPIO_ATR_XX, +    GPIO_READBACK +}; + +static const std::string GPIO_ATTR_SRC = "SRC"; +//! Attribute name for GPIO control. +static const std::string GPIO_ATTR_CTRL = "CTRL"; +//! Attribute name for GPIO data direction register. +static const std::string GPIO_ATTR_DDR = "DDR"; +//! Attribute name for GPIO ouput value. +static const std::string GPIO_ATTR_OUT = "OUT"; +//! Attribute name for GPIO ATR idle state register. +static const std::string GPIO_ATTR_ATR0X = "ATR_0X"; +//! Attribute name for GPIO ATR receive only register. +static const std::string GPIO_ATTR_ATRRX = "ATR_RX"; +//! Attribute name for GPIO ATR transmit only register. +static const std::string GPIO_ATTR_ATRTX = "ATR_TX"; +//! Attribute name for GPIO ATR  full duplex state register. +static const std::string GPIO_ATTR_ATRXX = "ATR_XX"; +//!  Attribute name for GPIO READBACK  register. +static const std::string GPIO_ATTR_READBACK = "READBACK"; + +typedef std::map<gpio_attr_t, std::string> gpio_attr_map_t; + +static const gpio_attr_map_t gpio_attr_map{{GPIO_SRC, GPIO_ATTR_SRC}, +    {GPIO_CTRL, GPIO_ATTR_CTRL}, +    {GPIO_DDR, GPIO_ATTR_DDR}, +    {GPIO_OUT, GPIO_ATTR_OUT}, +    {GPIO_ATR_0X, GPIO_ATTR_ATR0X}, +    {GPIO_ATR_RX, GPIO_ATTR_ATRRX}, +    {GPIO_ATR_TX, GPIO_ATTR_ATRTX}, +    {GPIO_ATR_XX, GPIO_ATTR_ATRXX}, +    {GPIO_READBACK, GPIO_ATTR_READBACK}}; + +static const std::map<gpio_attr_t, std::map<uint32_t, std::string>> attr_value_map{ +    {GPIO_CTRL, {{0, "ATR"}, {1, "GPIO"}}}, {GPIO_DDR, {{0, "INPUT"}, {1, "OUTPUT"}}}}; + +static const std::map<std::string, gpio_attr_t> gpio_attr_rev_map{ +    {GPIO_ATTR_SRC, GPIO_SRC}, +    {GPIO_ATTR_CTRL, GPIO_CTRL}, +    {GPIO_ATTR_DDR, GPIO_DDR}, +    {GPIO_ATTR_OUT, GPIO_OUT}, +    {GPIO_ATTR_ATR0X, GPIO_ATR_0X}, +    {GPIO_ATTR_ATRRX, GPIO_ATR_RX}, +    {GPIO_ATTR_ATRTX, GPIO_ATR_TX}, +    {GPIO_ATTR_ATRXX, GPIO_ATR_XX}, +    {GPIO_ATTR_READBACK, GPIO_READBACK}}; + +static const gpio_attr_map_t default_attr_value_map{ +    {GPIO_SRC, "RADIO_0/0"}, {GPIO_CTRL, "GPIO"}, {GPIO_DDR, "INPUT"}}; + +static const std::map<std::string, uint32_t> gpio_level_map{ +    {"HIGH", 1}, {"LOW", 0}, {"ON", 1}, {"OFF", 0}, {"TRUE", 1}, {"FALSE", 0}}; + +static const std::map<std::string, uint32_t> gpio_direction{ +    {"OUT", 1}, {"IN", 0}, {"OUTPUT", 1}, {"INPUT", 0}}; + +static const std::map<std::string, uint32_t> gpio_ctrl_mode{{"ATR", 0}, {"GPIO", 1}}; + +static const std::map<std::string, std::map<std::string, uint32_t>> gpio_attr_value_pair{ +    {GPIO_ATTR_CTRL, uhd::usrp::gpio_atr::gpio_ctrl_mode}, +    {GPIO_ATTR_DDR, uhd::usrp::gpio_atr::gpio_direction}, +    {GPIO_ATTR_OUT, uhd::usrp::gpio_atr::gpio_level_map}, +    {GPIO_ATTR_ATR0X, uhd::usrp::gpio_atr::gpio_level_map}, +    {GPIO_ATTR_ATRRX, uhd::usrp::gpio_atr::gpio_level_map}, +    {GPIO_ATTR_ATRTX, uhd::usrp::gpio_atr::gpio_level_map}, +    {GPIO_ATTR_ATRXX, uhd::usrp::gpio_atr::gpio_level_map}, +    {GPIO_ATTR_READBACK, uhd::usrp::gpio_atr::gpio_level_map}}; + +}}} // namespace uhd::usrp::gpio_atr  #endif /* INCLUDED_LIBUHD_USRP_GPIO_DEFS_LIB_HPP */ diff --git a/host/lib/include/uhdlib/utils/atomic.hpp b/host/lib/include/uhdlib/utils/atomic.hpp index 303df1bc9..98b1cfa7b 100644 --- a/host/lib/include/uhdlib/utils/atomic.hpp +++ b/host/lib/include/uhdlib/utils/atomic.hpp @@ -14,62 +14,65 @@  #include <atomic>  #include <chrono> -namespace uhd{ +namespace uhd { -    /*! DEPRECATED -- Will be removed in coming versions of UHD. -     * -     * Spin-wait on a condition with a timeout. -     * \param cond an atomic variable to compare -     * \param value compare to atomic for true/false -     * \param timeout the timeout in seconds -     * \return true for cond == value, false for timeout -     */ -    template<typename T> -    UHD_INLINE bool spin_wait_with_timeout( -        std::atomic<T> &cond, -        const T value, -        const double timeout -    ){ -        if (cond == value) return true; -        const auto exit_time = std::chrono::high_resolution_clock::now() -                               + std::chrono::microseconds(int64_t(timeout * 1e6)); -        while (cond != value) { -            if (std::chrono::high_resolution_clock::now() > exit_time) { -                return false; -            } -            boost::this_thread::interruption_point(); -            boost::this_thread::yield(); -        } +/*! DEPRECATED -- Will be removed in coming versions of UHD. + * + * Spin-wait on a condition with a timeout. + * \param cond an atomic variable to compare + * \param value compare to atomic for true/false + * \param timeout the timeout in seconds + * \return true for cond == value, false for timeout + */ +template <typename T> +UHD_INLINE bool spin_wait_with_timeout( +    std::atomic<T>& cond, const T value, const double timeout) +{ +    if (cond == value)          return true; +    const auto exit_time = std::chrono::high_resolution_clock::now() +                           + std::chrono::microseconds(int64_t(timeout * 1e6)); +    while (cond != value) { +        if (std::chrono::high_resolution_clock::now() > exit_time) { +            return false; +        } +        boost::this_thread::interruption_point(); +        boost::this_thread::yield();      } +    return true; +} -    /*! DEPRECATED -- Will be removed in coming versions of UHD. -     * -     * Claimer class to provide synchronization for multi-thread access. -     * Claiming enables buffer classes to be used with a buffer queue. -     */ -    class simple_claimer{ -    public: -        simple_claimer(void){ -            this->release(); -        } +/*! DEPRECATED -- Will be removed in coming versions of UHD. + * + * Claimer class to provide synchronization for multi-thread access. + * Claiming enables buffer classes to be used with a buffer queue. + */ +class simple_claimer +{ +public: +    simple_claimer(void) +    { +        this->release(); +    } -        UHD_INLINE void release(void){ -            _locked = false; -        } +    UHD_INLINE void release(void) +    { +        _locked = false; +    } -        UHD_INLINE bool claim_with_wait(const double timeout){ -            if (spin_wait_with_timeout(_locked, false, timeout)){ -                _locked = true; -                return true; -            } -            return false; +    UHD_INLINE bool claim_with_wait(const double timeout) +    { +        if (spin_wait_with_timeout(_locked, false, timeout)) { +            _locked = true; +            return true;          } +        return false; +    } -    private: -        std::atomic<bool> _locked; -    }; +private: +    std::atomic<bool> _locked; +}; -} //namespace uhd +} // namespace uhd  #endif /* INCLUDED_UHD_UTILS_ATOMIC_HPP */ diff --git a/host/lib/include/uhdlib/utils/auto_timer.hpp b/host/lib/include/uhdlib/utils/auto_timer.hpp index 227750a2f..5d1c88911 100644 --- a/host/lib/include/uhdlib/utils/auto_timer.hpp +++ b/host/lib/include/uhdlib/utils/auto_timer.hpp @@ -17,46 +17,50 @@  #ifdef UHD_PLATFORM_WIN32  // Defines struct tm -#include "time.h" - -#include <windows.h> - -#include <uhd/utils/msg.hpp> +#    include "time.h" +#    include <uhd/utils/msg.hpp> +#    include <windows.h>  /*! - * Inserts a timer that logs the duration of its existence (construction to destruction) and the context string to UHD_MSG - * \param context The context string to log in addition to the duration. String buffer MUST be maintained by caling code throughout lifetime of timer object. + * Inserts a timer that logs the duration of its existence (construction to destruction) + * and the context string to UHD_MSG \param context The context string to log in addition + * to the duration. String buffer MUST be maintained by caling code throughout lifetime of + * timer object.   */ -#define PROFILE_TIMING(context) \ -   uhd::_auto_timer::auto_timer ___at(context); +#    define PROFILE_TIMING(context) uhd::_auto_timer::auto_timer ___at(context);  /*! - * Inserts a timer that logs the duration (if exceeds threshold) of its existence (construction to destruction) and the context string to UHD_MSG - * \param context The context string to log in addition to the duration. String buffer MUST be maintained by caling code throughout lifetime of timer object. - * \param threshold Only if the lifetime of the timer exceeds this value will it be logged + * Inserts a timer that logs the duration (if exceeds threshold) of its existence + * (construction to destruction) and the context string to UHD_MSG \param context The + * context string to log in addition to the duration. String buffer MUST be maintained by + * caling code throughout lifetime of timer object. \param threshold Only if the lifetime + * of the timer exceeds this value will it be logged   */ -#define PROFILE_TIMING_WITH_THRESHOLD(context,threshold) \ -   uhd::_auto_timer::auto_timer ___at(context,threshold); +#    define PROFILE_TIMING_WITH_THRESHOLD(context, threshold) \ +        uhd::_auto_timer::auto_timer ___at(context, threshold); - /*! - * Inserts a timer that logs the duration of its existence (construction to destruction) and the context string to UHD_MSG - * \param context The context string to log in addition to the duration. String buffer MUST be maintained by caling code throughout lifetime of timer object. - * \param unitScale Report duration in ms or us (kUnitScaleMS or kUnitScaleUS) +/*! + * Inserts a timer that logs the duration of its existence (construction to destruction) + * and the context string to UHD_MSG \param context The context string to log in addition + * to the duration. String buffer MUST be maintained by caling code throughout lifetime of + * timer object. \param unitScale Report duration in ms or us (kUnitScaleMS or + * kUnitScaleUS)   */ -#define PROFILE_TIMING_WITH_SCALE(context,unitScale) \ -   uhd::_auto_timer::auto_timer ___at(context,0,unitScale); - - /*! - * Inserts a timer that logs the duration (if exceeds threshold) of its existence (construction to destruction) and the context string to UHD_MSG - * \param context The context string to log in addition to the duration. String buffer MUST be maintained by caling code throughout lifetime of timer object. - * \param threshold Only if the lifetime of the timer exceeds this value will it be logged - * \param unitScale Report duration in ms or us (kUnitScaleMS or kUnitScaleUS) +#    define PROFILE_TIMING_WITH_SCALE(context, unitScale) \ +        uhd::_auto_timer::auto_timer ___at(context, 0, unitScale); + +/*! + * Inserts a timer that logs the duration (if exceeds threshold) of its existence + * (construction to destruction) and the context string to UHD_MSG \param context The + * context string to log in addition to the duration. String buffer MUST be maintained by + * caling code throughout lifetime of timer object. \param threshold Only if the lifetime + * of the timer exceeds this value will it be logged \param unitScale Report duration in + * ms or us (kUnitScaleMS or kUnitScaleUS)   */ -#define PROFILE_TIMING_WITH_THRESHOLD_AND_SCALE(context,threshold,unitScale) \ -   uhd::_auto_timer::auto_timer ___at(context,threshold,unitScale); +#    define PROFILE_TIMING_WITH_THRESHOLD_AND_SCALE(context, threshold, unitScale) \ +        uhd::_auto_timer::auto_timer ___at(context, threshold, unitScale); -namespace uhd { -   namespace _auto_timer { +namespace uhd { namespace _auto_timer {  static const uint64_t kUnitScaleMS = 1000;  static const uint64_t kUnitScaleUS = 1000000; @@ -65,72 +69,66 @@ static const uint64_t kUnitScaleUS = 1000000;  class auto_timer  {  public: - -   auto_timer( -      const char* context, -      uint64_t reporting_threshold = 0, -      uint64_t unit_scale = kUnitScaleUS) : -      _context(context), -      _reporting_threshold(reporting_threshold), -      _unit_scale(unit_scale) -   { -      ::QueryPerformanceCounter(&_start_time); -      switch (unit_scale) -      { -      case kUnitScaleMS: -         _unit_scale_str = "ms"; -         break; -      case kUnitScaleUS: -      default: -         _unit_scale_str = "us"; -         break; -      } -   } - -   ~auto_timer() -   { -      LARGE_INTEGER freq; -      uint64_t diff_time = 0; - -      ::QueryPerformanceCounter(&_end_time); -      QueryPerformanceFrequency(&freq); -      diff_time = -         (uint64_t)(_end_time.QuadPart - _start_time.QuadPart)* -         _unit_scale / -         freq.QuadPart; - -      if (diff_time >= _reporting_threshold) -      { -         UHD_MSG(status) << "^ " << _context << "\t" << std::dec << diff_time << _unit_scale_str << std::endl; -      } - -   } +    auto_timer(const char* context, +        uint64_t reporting_threshold = 0, +        uint64_t unit_scale          = kUnitScaleUS) +        : _context(context) +        , _reporting_threshold(reporting_threshold) +        , _unit_scale(unit_scale) +    { +        ::QueryPerformanceCounter(&_start_time); +        switch (unit_scale) { +            case kUnitScaleMS: +                _unit_scale_str = "ms"; +                break; +            case kUnitScaleUS: +            default: +                _unit_scale_str = "us"; +                break; +        } +    } + +    ~auto_timer() +    { +        LARGE_INTEGER freq; +        uint64_t diff_time = 0; + +        ::QueryPerformanceCounter(&_end_time); +        QueryPerformanceFrequency(&freq); +        diff_time = (uint64_t)(_end_time.QuadPart - _start_time.QuadPart) * _unit_scale +                    / freq.QuadPart; + +        if (diff_time >= _reporting_threshold) { +            UHD_MSG(status) << "^ " << _context << "\t" << std::dec << diff_time +                            << _unit_scale_str << std::endl; +        } +    }  private: -   // Usage -   auto_timer(); -   auto_timer(const auto_timer&); +    // Usage +    auto_timer(); +    auto_timer(const auto_timer&); -   LARGE_INTEGER _start_time; -   LARGE_INTEGER _end_time; -   uint64_t _unit_scale; -   uint64_t _reporting_threshold; -   const char* _context; -   char* _unit_scale_str; +    LARGE_INTEGER _start_time; +    LARGE_INTEGER _end_time; +    uint64_t _unit_scale; +    uint64_t _reporting_threshold; +    const char* _context; +    char* _unit_scale_str;  }; // class auto_timer -}} //namespace uhd::_auto_timer +}} // namespace uhd::_auto_timer -#else //non-windows platforms +#else // non-windows platforms -#define PROFILE_TIMING(context)  +#    define PROFILE_TIMING(context) -#define PROFILE_TIMING_WITH_THRESHOLD(context,threshold)  +#    define PROFILE_TIMING_WITH_THRESHOLD(context, threshold) -#define PROFILE_TIMING_WITH_SCALE(context,unitScale)  +#    define PROFILE_TIMING_WITH_SCALE(context, unitScale) -#define PROFILE_TIMING_WITH_THRESHOLD_AND_SCALE(context,threshold,unitScale)  +#    define PROFILE_TIMING_WITH_THRESHOLD_AND_SCALE(context, threshold, unitScale)  #endif diff --git a/host/lib/include/uhdlib/utils/compat_check.hpp b/host/lib/include/uhdlib/utils/compat_check.hpp index 8fe96d118..708c5ab16 100644 --- a/host/lib/include/uhdlib/utils/compat_check.hpp +++ b/host/lib/include/uhdlib/utils/compat_check.hpp @@ -12,31 +12,27 @@  namespace uhd { -    /*! Checks for FPGA compatibility, and throws an exception on mismatch. -     * -     * \throws uhd::runtime_error on mismatch. -     */ -    void assert_fpga_compat( -        const size_t uhd_major, -        const size_t uhd_minor, -        const uint64_t fpga_compat, -        const std::string& fpga_component, -        const std::string& log_component, -        const bool fail_on_minor_behind=false -    ); +/*! Checks for FPGA compatibility, and throws an exception on mismatch. + * + * \throws uhd::runtime_error on mismatch. + */ +void assert_fpga_compat(const size_t uhd_major, +    const size_t uhd_minor, +    const uint64_t fpga_compat, +    const std::string& fpga_component, +    const std::string& log_component, +    const bool fail_on_minor_behind = false); -    /*! Checks for FPGA compatibility, and throws an exception on mismatch. -     * -     * \throws uhd::runtime_error on mismatch. -     */ -    void assert_fpga_compat( -        const size_t uhd_major, -        const size_t uhd_minor, -        const uint32_t fpga_compat, -        const std::string& fpga_component, -        const std::string& log_component, -        const bool fail_on_minor_behind=false -    ); +/*! Checks for FPGA compatibility, and throws an exception on mismatch. + * + * \throws uhd::runtime_error on mismatch. + */ +void assert_fpga_compat(const size_t uhd_major, +    const size_t uhd_minor, +    const uint32_t fpga_compat, +    const std::string& fpga_component, +    const std::string& log_component, +    const bool fail_on_minor_behind = false);  } /* namespace uhd */ diff --git a/host/lib/include/uhdlib/utils/config_parser.hpp b/host/lib/include/uhdlib/utils/config_parser.hpp index 0cff0868d..13a6346e8 100644 --- a/host/lib/include/uhdlib/utils/config_parser.hpp +++ b/host/lib/include/uhdlib/utils/config_parser.hpp @@ -35,20 +35,20 @@ public:       *       * \throws uhd::runtime_error if the parsing failed.       */ -    config_parser(const std::string &path=""); +    config_parser(const std::string& path = "");      /*! Load another config file and update the current values.       *       * If a value exists in both the new and current file, the new value wins.       */ -    void read_file(const std::string &path); +    void read_file(const std::string& path);      //! Return a list of sections      std::vector<std::string> sections();      //! Return a list of options (keys) in a section, or an empty list if      //  section does not exist -    std::vector<std::string> options(const std::string §ion); +    std::vector<std::string> options(const std::string& section);      /*! Return the value of a key       * @@ -57,15 +57,12 @@ public:       * \param def Default value, in case the key does not exist       */      template <typename T> -    T get( -            const std::string §ion, -            const std::string &key, -            const T &def -    ) { +    T get(const std::string& section, const std::string& key, const T& def) +    {          try {              const auto child = _pt.get_child(section);              return child.get<T>(key, def); -        } catch (const boost::property_tree::ptree_bad_path &) { +        } catch (const boost::property_tree::ptree_bad_path&) {              return def;          }      } @@ -78,27 +75,20 @@ public:       * \throws uhd::key_error if the key or the section don't exist       */      template <typename T> -    T get( -            const std::string §ion, -            const std::string &key -    ) { +    T get(const std::string& section, const std::string& key) +    {          try {              const auto child = _pt.get_child(section);              return child.get<T>(key); -        } catch (const boost::property_tree::ptree_bad_path &) { -            throw uhd::key_error( -                std::string("[config_parser] Key ") + key + -                " not found in section " + section -            ); +        } catch (const boost::property_tree::ptree_bad_path&) { +            throw uhd::key_error(std::string("[config_parser] Key ") + key +                                 + " not found in section " + section);          }      }      template <typename T> -    void set( -            const std::string §ion, -            const std::string &key, -            const T &value -    ) { +    void set(const std::string& section, const std::string& key, const T& value) +    {          _pt.put<T>(section + "." + key, value);      } diff --git a/host/lib/include/uhdlib/utils/eeprom_utils.hpp b/host/lib/include/uhdlib/utils/eeprom_utils.hpp index 5104e1530..53390b200 100644 --- a/host/lib/include/uhdlib/utils/eeprom_utils.hpp +++ b/host/lib/include/uhdlib/utils/eeprom_utils.hpp @@ -7,19 +7,19 @@  #include <uhd/types/byte_vector.hpp>  #include <uhd/types/dict.hpp>  #include <uhd/types/mac_addr.hpp> -#include <boost/asio/ip/address_v4.hpp>  #include <uhd/utils/log.hpp> +#include <boost/asio/ip/address_v4.hpp>  #include <string>  #include <vector> -static const size_t SERIAL_LEN = 9; +static const size_t SERIAL_LEN   = 9;  static const size_t NAME_MAX_LEN = 32 - SERIAL_LEN;  //! convert a string to a byte vector to write to eeprom -uhd::byte_vector_t string_to_uint16_bytes(const std::string &num_str); +uhd::byte_vector_t string_to_uint16_bytes(const std::string& num_str);  //! convert a byte vector read from eeprom to a string -std::string uint16_bytes_to_string(const uhd::byte_vector_t &bytes); +std::string uint16_bytes_to_string(const uhd::byte_vector_t& bytes);  /*!   * Check for duplicate values within a given set of keys.  Assumes the desire @@ -37,21 +37,18 @@ std::string uint16_bytes_to_string(const uhd::byte_vector_t &bytes);   * \return true if duplicates are found, false if not   */  template <typename field_type> -bool check_for_duplicates( -    const std::string& error_label, +bool check_for_duplicates(const std::string& error_label,      const uhd::dict<std::string, std::string>& new_eeprom,      const uhd::dict<std::string, std::string>& curr_eeprom,      const std::string& category, -    const std::vector<std::string>& keys -) { +    const std::vector<std::string>& keys) +{      bool has_duplicates = false; -    for (size_t i = 0; i < keys.size(); i++) -    { +    for (size_t i = 0; i < keys.size(); i++) {          bool found_duplicate = false; -        auto key = keys[i]; +        auto key             = keys[i]; -        if (not new_eeprom.has_key(key)) -        { +        if (not new_eeprom.has_key(key)) {              continue;          } @@ -59,38 +56,33 @@ bool check_for_duplicates(          // Check other values in new_eeprom for duplicate          // Starting at key index i+1 so the same duplicate is not found twice -        for (size_t j = i+1; j < keys.size(); j++) -        { +        for (size_t j = i + 1; j < keys.size(); j++) {              auto other_key = keys[j]; -            if (not new_eeprom.has_key(other_key)) -            { +            if (not new_eeprom.has_key(other_key)) {                  continue;              }              auto other_value = field_type::from_string(new_eeprom[other_key]).to_string(); -            if (value == other_value) -            { +            if (value == other_value) {                  // Value is a duplicate of another supplied value -                UHD_LOG_ERROR(error_label, "Duplicate " << category << " " -                    << new_eeprom[key] << " is supplied for both " << key -                    << " and " << other_key); +                UHD_LOG_ERROR(error_label, +                    "Duplicate " << category << " " << new_eeprom[key] +                                 << " is supplied for both " << key << " and " +                                 << other_key);                  found_duplicate = true;              }          }          // Check all keys in curr_eeprom for duplicate value -        for (auto other_key: keys) -        { +        for (auto other_key : keys) {              // Skip any keys in new_eeprom -            if (new_eeprom.has_key(other_key)) -            { +            if (new_eeprom.has_key(other_key)) {                  continue;              } -            if (value == curr_eeprom[other_key]) -            { +            if (value == curr_eeprom[other_key]) {                  // Value is duplicate of one in the EEPROM -                UHD_LOG_ERROR(error_label, "Duplicate " << category << " " -                    << new_eeprom[key] << " is already in use for " -                    << other_key); +                UHD_LOG_ERROR(error_label, +                    "Duplicate " << category << " " << new_eeprom[key] +                                 << " is already in use for " << other_key);                  found_duplicate = true;              }          } diff --git a/host/lib/include/uhdlib/utils/ihex.hpp b/host/lib/include/uhdlib/utils/ihex.hpp index ac12a83b5..58e4d5637 100644 --- a/host/lib/include/uhdlib/utils/ihex.hpp +++ b/host/lib/include/uhdlib/utils/ihex.hpp @@ -8,9 +8,8 @@  #ifndef INCLUDED_IHEX_READER_HPP  #define INCLUDED_IHEX_READER_HPP -#include <functional> -#include <functional>  #include <stdint.h> +#include <functional>  #include <string>  #include <vector> @@ -20,12 +19,13 @@ class ihex_reader  {  public:      // Arguments are: lower address bits, upper address bits, buff, length -    typedef std::function<int(uint16_t,uint16_t,unsigned char*,uint16_t)> record_handle_type; +    typedef std::function<int(uint16_t, uint16_t, unsigned char*, uint16_t)> +        record_handle_type;      /*       * \param ihex_filename Path to the *.ihx file       */ -    ihex_reader(const std::string &ihex_filename); +    ihex_reader(const std::string& ihex_filename);      /*! Read an Intel HEX file and handle it record by record.       * @@ -46,7 +46,7 @@ public:       *       * \throws uhd::io_error if the HEX file is corrupted or unreadable.       */ -    void to_bin_file(const std::string &bin_filename); +    void to_bin_file(const std::string& bin_filename);      /*! Copy the ihex file into a buffer.       * @@ -66,4 +66,3 @@ private:  }; /* namespace uhd */  #endif /* INCLUDED_IHEX_READER_HPP */ - diff --git a/host/lib/include/uhdlib/utils/isatty.hpp b/host/lib/include/uhdlib/utils/isatty.hpp index cb8d07afb..03ca23893 100644 --- a/host/lib/include/uhdlib/utils/isatty.hpp +++ b/host/lib/include/uhdlib/utils/isatty.hpp @@ -14,40 +14,40 @@ namespace uhd {  #ifdef UHD_PLATFORM_WIN32 -#   include <io.h> - -    /*! Portable version of isatty() -     * -     * We call it is_a_tty() to distinguish from the from the POSIX version. -     * Also, we simply return a Boolean since the Windows version doesn't set -     * errno. -     */ -    bool is_a_tty(const int fd) -    { -        return uhd::narrow_cast<bool>(_isatty(fd)); -    } +#    include <io.h> + +/*! Portable version of isatty() + * + * We call it is_a_tty() to distinguish from the from the POSIX version. + * Also, we simply return a Boolean since the Windows version doesn't set + * errno. + */ +bool is_a_tty(const int fd) +{ +    return uhd::narrow_cast<bool>(_isatty(fd)); +}  #elif _POSIX_C_SOURCE >= _200112L  #    include <unistd.h> -    /*! Portable version of isatty() -     * -     * We call it is_a_tty() to distinguish from the from the POSIX version. -     * Also, we simply return a Boolean since the Windows version doesn't set -     * errno. -     */ -    bool is_a_tty(const int fd) -    { -        return isatty(fd); -    } +/*! Portable version of isatty() + * + * We call it is_a_tty() to distinguish from the from the POSIX version. + * Also, we simply return a Boolean since the Windows version doesn't set + * errno. + */ +bool is_a_tty(const int fd) +{ +    return isatty(fd); +}  #else -    bool is_a_tty(const int fd) -    { -        return false; -    } +bool is_a_tty(const int fd) +{ +    return false; +}  #endif diff --git a/host/lib/include/uhdlib/utils/math.hpp b/host/lib/include/uhdlib/utils/math.hpp index bcb1b4395..924459ec9 100644 --- a/host/lib/include/uhdlib/utils/math.hpp +++ b/host/lib/include/uhdlib/utils/math.hpp @@ -18,8 +18,9 @@ namespace uhd { namespace math {  /*! log2(num), rounded up to the nearest integer.   */  template <class T> -T ceil_log2(T num){ -    return std::ceil(std::log(num)/std::log(T(2))); +T ceil_log2(T num) +{ +    return std::ceil(std::log(num) / std::log(T(2)));  }  /** diff --git a/host/lib/include/uhdlib/utils/narrow.hpp b/host/lib/include/uhdlib/utils/narrow.hpp index 25acb63d4..daedd55db 100644 --- a/host/lib/include/uhdlib/utils/narrow.hpp +++ b/host/lib/include/uhdlib/utils/narrow.hpp @@ -50,7 +50,7 @@  #if defined(_MSC_VER)  #    pragma warning(push)  #    pragma warning(disable : 4127) // conditional expression is constant -#endif                          // _MSC_VER +#endif // _MSC_VER  namespace uhd { @@ -83,8 +83,9 @@ inline T narrow(U u)      if (static_cast<U>(t) != u) {          throw narrowing_error("");      } -    if (!std::integral_constant<bool, std::is_signed<T>::value == std::is_signed<U>::value>::value -            && ((t < T{}) != (u < U{}))) { +    if (!std::integral_constant<bool, +            std::is_signed<T>::value == std::is_signed<U>::value>::value +        && ((t < T{}) != (u < U{}))) {          throw narrowing_error("");      }      return t; diff --git a/host/lib/include/uhdlib/utils/paths.hpp b/host/lib/include/uhdlib/utils/paths.hpp index d74973301..7f0dc4046 100644 --- a/host/lib/include/uhdlib/utils/paths.hpp +++ b/host/lib/include/uhdlib/utils/paths.hpp @@ -11,14 +11,13 @@  namespace uhd { -    /*! Expand environment variables in paths, like Python's -     *  os.path.expandvars(). -     * -     * If expansion fails, will simply return the original path. -     */ -    std::string path_expandvars(const std::string& path); +/*! Expand environment variables in paths, like Python's + *  os.path.expandvars(). + * + * If expansion fails, will simply return the original path. + */ +std::string path_expandvars(const std::string& path);  } /* namespace uhd */  #endif /* INCLUDED_UHDLIB_UTILS_PATHS_HPP */ - diff --git a/host/lib/include/uhdlib/utils/prefs.hpp b/host/lib/include/uhdlib/utils/prefs.hpp index e528450cd..6d75ac7ea 100644 --- a/host/lib/include/uhdlib/utils/prefs.hpp +++ b/host/lib/include/uhdlib/utils/prefs.hpp @@ -13,76 +13,75 @@  namespace uhd { namespace prefs { -    /*! Return a reference to an object representing the UHD config file -     *  state. -     * -     * Note: Don't call this in static initializers. -     */ -    config_parser& get_uhd_config(); +/*! Return a reference to an object representing the UHD config file + *  state. + * + * Note: Don't call this in static initializers. + */ +config_parser& get_uhd_config(); -    /*! Convenience function to update device args with settings from -     *  config files. -     * -     * Assume the user has a configuration file as such: -     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.ini} -     * [type=b200] -     * master_clock_rate=20e6 -     * -     * [serial=f42f9b] ; Let's assume this is another B200 -     * master_clock_rate=10e6 -     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -     * If get_usrp_args() gets called with "type" key equal to "b200", it will -     * first apply the `master_clock_rate=20e6` settings, as if they had been -     * passed in as device args into the initialization sequence. If the device -     * happens to have the serial number listed above, i.e., "serial" equals -     * "f42f9b", then the new value `master_clock_rate=10e6` will get applied. -     * -     * If the user actually specified their own value of `master_clock_rate`, -     * that value would get applied. -     * -     * -     * \param user_args After getting the device args from the config -     *                  files, all of these key/value pairs will be applied -     *                  and will overwrite the settings from config files -     *                  if they exist. -     */ -    uhd::device_addr_t get_usrp_args(const uhd::device_addr_t &user_args); +/*! Convenience function to update device args with settings from + *  config files. + * + * Assume the user has a configuration file as such: + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.ini} + * [type=b200] + * master_clock_rate=20e6 + * + * [serial=f42f9b] ; Let's assume this is another B200 + * master_clock_rate=10e6 + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * If get_usrp_args() gets called with "type" key equal to "b200", it will + * first apply the `master_clock_rate=20e6` settings, as if they had been + * passed in as device args into the initialization sequence. If the device + * happens to have the serial number listed above, i.e., "serial" equals + * "f42f9b", then the new value `master_clock_rate=10e6` will get applied. + * + * If the user actually specified their own value of `master_clock_rate`, + * that value would get applied. + * + * + * \param user_args After getting the device args from the config + *                  files, all of these key/value pairs will be applied + *                  and will overwrite the settings from config files + *                  if they exist. + */ +uhd::device_addr_t get_usrp_args(const uhd::device_addr_t& user_args); -    /*! Convenience function to update global DPDK args with settings from -     * config files. -     * -     * Searches for a profile attached to the dpdk-conf key, like this: -     * [dpdk-conf=myconfig] -     * num_mbufs=4095 -     * mbuf_cache_size=315 -     * mtu=8000 -     * -     * \param user_args After getting the device args from the config -     *                  files, all of these key/value pairs will be applied -     *                  and will overwrite the settings from config files -     *                  if they exist. -     */ -    uhd::device_addr_t get_dpdk_args(const uhd::device_addr_t &user_args); +/*! Convenience function to update global DPDK args with settings from + * config files. + * + * Searches for a profile attached to the dpdk-conf key, like this: + * [dpdk-conf=myconfig] + * num_mbufs=4095 + * mbuf_cache_size=315 + * mtu=8000 + * + * \param user_args After getting the device args from the config + *                  files, all of these key/value pairs will be applied + *                  and will overwrite the settings from config files + *                  if they exist. + */ +uhd::device_addr_t get_dpdk_args(const uhd::device_addr_t& user_args); -    /*! Convenience function to update per-NIC DPDK args with settings from -     * config files. -     * -     * Grabs settings based on provided MAC address. Sections created like so: -     * [dpdk-mac=00:01:02:03:04:05] -     * dpdk-ipv4 = 192.168.20.1/24 -     * dpdk-io-cpu = 1 -     * -     * [dpdk-mac=00:01:02:03:04:06] -     * dpdk-ipv4 = 192.168.40.1/24 -     * dpdk-io-cpu = 1 -     * -     * \param user_args After getting the device args from the config -     *                  files, all of these key/value pairs will be applied -     *                  and will overwrite the settings from config files -     *                  if they exist. -     */ -    uhd::device_addr_t get_dpdk_nic_args(const uhd::device_addr_t &user_args); +/*! Convenience function to update per-NIC DPDK args with settings from + * config files. + * + * Grabs settings based on provided MAC address. Sections created like so: + * [dpdk-mac=00:01:02:03:04:05] + * dpdk-ipv4 = 192.168.20.1/24 + * dpdk-io-cpu = 1 + * + * [dpdk-mac=00:01:02:03:04:06] + * dpdk-ipv4 = 192.168.40.1/24 + * dpdk-io-cpu = 1 + * + * \param user_args After getting the device args from the config + *                  files, all of these key/value pairs will be applied + *                  and will overwrite the settings from config files + *                  if they exist. + */ +uhd::device_addr_t get_dpdk_nic_args(const uhd::device_addr_t& user_args);  }} /* namespace uhd::prefs */  #endif /* INCLUDED_LIBUHD_UTILS_PREFS_HPP */ - diff --git a/host/lib/include/uhdlib/utils/semaphore.hpp b/host/lib/include/uhdlib/utils/semaphore.hpp index ae77ed102..fc869d64a 100644 --- a/host/lib/include/uhdlib/utils/semaphore.hpp +++ b/host/lib/include/uhdlib/utils/semaphore.hpp @@ -9,7 +9,7 @@  #include <mutex>  #ifndef INCLUDED_UHDLIB_UTILS_SEMAPHORE_HPP -#define INCLUDED_UHDLIB_UTILS_SEMAPHORE_HPP +#    define INCLUDED_UHDLIB_UTILS_SEMAPHORE_HPP  namespace uhd { diff --git a/host/lib/include/uhdlib/utils/system_time.hpp b/host/lib/include/uhdlib/utils/system_time.hpp index 30cd5a673..1465460d2 100644 --- a/host/lib/include/uhdlib/utils/system_time.hpp +++ b/host/lib/include/uhdlib/utils/system_time.hpp @@ -8,11 +8,11 @@  namespace uhd { -    /*! -     * Get the system time in time_spec_t format. -     * Uses the highest precision clock available. -     * \return the system time as a time_spec_t -     */ -    time_spec_t get_system_time(void); +/*! + * Get the system time in time_spec_t format. + * Uses the highest precision clock available. + * \return the system time as a time_spec_t + */ +time_spec_t get_system_time(void);  }; /* namespace uhd */  | 
