From 6bd43946a71173cbf0f1d318843ba34d6849dc30 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Fri, 7 Jun 2019 21:37:15 -0700 Subject: rfnoc: Add shutdown feature to blocks On destruction, the rfnoc_graph will call shutdown() on all blocks. This allows a safe de-initialization of blocks independent of the lifetime of the noc_block_base::sptr. Also adds the shutdown feature to null_block_control. --- host/include/uhd/rfnoc/noc_block_base.hpp | 29 +++++++++++++++++++++++++++++ host/include/uhd/rfnoc/node.hpp | 7 +++++++ 2 files changed, 36 insertions(+) (limited to 'host/include') diff --git a/host/include/uhd/rfnoc/noc_block_base.hpp b/host/include/uhd/rfnoc/noc_block_base.hpp index e951ffc72..45a1f5738 100644 --- a/host/include/uhd/rfnoc/noc_block_base.hpp +++ b/host/include/uhd/rfnoc/noc_block_base.hpp @@ -160,6 +160,25 @@ protected: */ std::shared_ptr get_mb_controller(); + /*! Safely de-initialize the block + * + * This function is called by the framework when the RFNoC session is about + * to finish to allow blocks to safely perform actions to shut down a block. + * For example, if your block is producing samples, like a radio or signal + * generator, this is a good place to issue a "stop" command. + * + * After this function is called, register access is no more possible. So + * make sure not to interact with regs() after this was called. Future + * access to regs() won't throw, but will print error messages and do + * nothing. + * + * The rationale for having this separate from the destructor is because + * rfnoc_graph allows exporting references to blocks, and this function + * ensures that blocks are safely shut down when the rest of the device + * control goes away. + */ + virtual void deinit(); + private: /*! Update the tick rate of this block * @@ -168,6 +187,16 @@ private: */ void _set_tick_rate(const double tick_rate); + /*! Perform a shutdown sequence. + * + * - Call deinit() + * - Invalidate regs() + */ + void shutdown(); + + /************************************************************************** + * Attributes + **************************************************************************/ //! This block's Noc-ID noc_id_t _noc_id; diff --git a/host/include/uhd/rfnoc/node.hpp b/host/include/uhd/rfnoc/node.hpp index f9a1272e1..04b3d863f 100644 --- a/host/include/uhd/rfnoc/node.hpp +++ b/host/include/uhd/rfnoc/node.hpp @@ -350,6 +350,13 @@ protected: virtual bool check_topology(const std::vector& connected_inputs, const std::vector& connected_outputs); + /*! Perform a shutdown sequence + * + * This is mostly relevant for noc_block_base implementations. See also + * noc_block_base::shutdown(). + */ + virtual void shutdown(); + /************************************************************************** * Attributes *************************************************************************/ -- cgit v1.2.3