diff options
Diffstat (limited to 'host/lib/include/uhdlib')
| -rw-r--r-- | host/lib/include/uhdlib/rfnoc/async_msg.hpp | 85 | ||||
| -rw-r--r-- | host/lib/include/uhdlib/rfnoc/async_msg_handler.hpp | 86 | ||||
| -rw-r--r-- | host/lib/include/uhdlib/rfnoc/graph_impl.hpp | 23 | 
3 files changed, 191 insertions, 3 deletions
diff --git a/host/lib/include/uhdlib/rfnoc/async_msg.hpp b/host/lib/include/uhdlib/rfnoc/async_msg.hpp new file mode 100644 index 000000000..8abdb27b8 --- /dev/null +++ b/host/lib/include/uhdlib/rfnoc/async_msg.hpp @@ -0,0 +1,85 @@ +// +// Copyright 2018 Ettus Research, a National Instruments Company +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#ifndef INCLUDED_UHD_RFNOC_ASYNC_MSG_HPP +#define INCLUDED_UHD_RFNOC_ASYNC_MSG_HPP + +#include <uhd/config.hpp> +#include <uhd/types/time_spec.hpp> +#include <uhd/types/sid.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; + +        /*! +         * 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, + +            // 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; + +        /*! +         * A special payload populated by custom FPGA fabric. +         */ +        std::vector<uint32_t> payload; + +        //! 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) +        {} +        //! Return the the id of src block that throw eror +        uint32_t get_error_src() const { return sid_t(sid).get_src_endpoint(); } +    }; + +    } +} +#endif /* INCLUDED_UHD_RFNOC_ASYNC_MSG_HPP */ + diff --git a/host/lib/include/uhdlib/rfnoc/async_msg_handler.hpp b/host/lib/include/uhdlib/rfnoc/async_msg_handler.hpp new file mode 100644 index 000000000..1f67d05a1 --- /dev/null +++ b/host/lib/include/uhdlib/rfnoc/async_msg_handler.hpp @@ -0,0 +1,86 @@ +// +// Copyright 2016 Ettus Research LLC +// Copyright 2018 Ettus Research, a National Instruments Company +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#ifndef INCLUDED_LIBUHD_RFNOC_AYNC_MSG_HANDLER_HPP +#define INCLUDED_LIBUHD_RFNOC_AYNC_MSG_HANDLER_HPP + +#include <uhd/rfnoc/graph.hpp> +#include <uhd/transport/zero_copy.hpp> +#include <uhd/types/sid.hpp> +#include <uhd/types/endianness.hpp> +#include <uhdlib/rfnoc/async_msg.hpp> +#include <boost/noncopyable.hpp> +#include <functional> + +namespace uhd { namespace rfnoc { + +/*! Async message handler for a uhd::rfnoc::graph + * + */ +class async_msg_handler : boost::noncopyable +{ +public: +    typedef boost::shared_ptr<async_msg_handler> sptr; +    typedef std::function<void(const async_msg_t&)> async_handler_type; + +    /*! +     * \param recv A transport on which async messages are received +     * \param send A transport on which to send response messages +     * \param sid The source part of this is taken as the local address of the +     *            transports. The remote part is ignored. +     */ +    static sptr make( +        uhd::transport::zero_copy_if::sptr recv, +        uhd::transport::zero_copy_if::sptr send, +        uhd::sid_t sid, +        uhd::endianness_t endianness +    ); + +    /*! Register an event handler. +     * +     * When any message is received with the given event code, +     * \p handler is called with the async message data as an argument. +     * +     * Note that \p handler is called if a message includes a certain event +     * code, but it does not have to be exclusive. Example: If there are two +     * event handlers registered, one for EVENT_CODE_OVERRUN and one for +     * EVENT_CODE_BAD_PACKET, and a message includes both those event codes, +     * then both event handlers are called. +     * +     * Multiple handlers per event code may be registered. The order they are +     * called in is non-deterministic. +     * +     * \returns The number of event handlers registered for this event code. +     *          Should never return anything less than 1. +     */ +    virtual int register_event_handler( +            const async_msg_t::event_code_t event_code, +            async_handler_type handler +    ) = 0; + +    /*! Post async messages into this message handler. +     * +     * This is the entry point for all async messages. When a message +     * is posted here, the following actions take place: +     * - If applicable, an event handler is called with \p metadata as the +     *   argument +     * - Some messages print error codes (e.g. O, U, L, S) +     */ +    virtual void post_async_msg( +            const async_msg_t &metadata +    ) = 0; + +    /*! Return the 16-bit address of this async message +    */ +    virtual uint32_t get_local_addr() const = 0; +}; + + +}}; /* namespace uhd::rfnoc */ + +#endif /* INCLUDED_LIBUHD_RFNOC_AYNC_MSG_HANDLER_HPP */ +// vim: sw=4 et: diff --git a/host/lib/include/uhdlib/rfnoc/graph_impl.hpp b/host/lib/include/uhdlib/rfnoc/graph_impl.hpp index 404369618..8da88b94f 100644 --- a/host/lib/include/uhdlib/rfnoc/graph_impl.hpp +++ b/host/lib/include/uhdlib/rfnoc/graph_impl.hpp @@ -8,6 +8,7 @@  #ifndef INCLUDED_LIBUHD_RFNOC_GRAPH_IMPL_HPP  #define INCLUDED_LIBUHD_RFNOC_GRAPH_IMPL_HPP +#include "async_msg_handler.hpp"  #include <uhd/rfnoc/graph.hpp>  #include <uhd/device3.hpp> @@ -16,6 +17,9 @@ namespace uhd { namespace rfnoc {  class graph_impl : public graph  {  public: +    /************************************************************************ +     * Structors +     ***********************************************************************/      /*!       * \param name An optional name to describe this graph       * \param device_ptr Weak pointer to the originating device3 @@ -23,10 +27,10 @@ public:       */      graph_impl(              const std::string &name, -            boost::weak_ptr<uhd::device3> device_ptr -            //async_msg_handler::sptr msg_handler +            boost::weak_ptr<uhd::device3> device_ptr, +            async_msg_handler::sptr msg_handler      ); -    virtual ~graph_impl() {}; +    virtual ~graph_impl() {}      /************************************************************************       * Connection API @@ -66,12 +70,25 @@ public:  private: +    void handle_overruns(const async_msg_t& async_msg); + +    //! Maps 16-bit addresses to block IDs +    std::map<uint32_t, block_id_t> _block_id_map; + +    //! For any given block, look up the MIMO group +    std::map<uint32_t, size_t> _mimo_group_map; + +    //! For any MIMO group, store the list of blocks in that group +    std::map<size_t, std::set<block_id_t> > _mimo_groups; +      //! Optional: A string to describe this graph      const std::string _name;      //! Reference to the generating device object      const boost::weak_ptr<uhd::device3> _device_ptr; +    //! Reference to the async message handler +    async_msg_handler::sptr _msg_handler;  };  }} /* namespace uhd::rfnoc */  | 
