diff --git a/lib/src/phy/rf/rf_uhd_rfnoc.h b/lib/src/phy/rf/rf_uhd_rfnoc.h index 95e8b19ef..d94b53596 100644 --- a/lib/src/phy/rf/rf_uhd_rfnoc.h +++ b/lib/src/phy/rf/rf_uhd_rfnoc.h @@ -32,7 +32,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -42,9 +44,6 @@ #ifdef UHD_ENABLE_CUSTOM_RFNOC #include #include -#else // UHD_ENABLE_CUSTOM_RFNOC -#include -#include #endif // UHD_ENABLE_CUSTOM_RFNOC #include "rf_uhd_safe.h" @@ -57,16 +56,11 @@ private: // Constant parameters const std::string RADIO_BLOCK_NAME = "Radio"; -#ifdef UHD_ENABLE_CUSTOM_RFNOC - const std::string DDC_BLOCK_NAME = "DDCch2"; - const std::string DUC_BLOCK_NAME = "DUCch2"; - typedef uhd::rfnoc::block_ctrl_base ddc_ctrl_t; - typedef uhd::rfnoc::block_ctrl_base duc_ctrl_t; -#else // UHD_ENABLE_CUSTOM_RFNOC const std::string DDC_BLOCK_NAME = "DDC"; const std::string DUC_BLOCK_NAME = "DUC"; - typedef uhd::rfnoc::ddc_block_ctrl ddc_ctrl_t; - typedef uhd::rfnoc::duc_block_ctrl duc_ctrl_t; +#ifdef UHD_ENABLE_CUSTOM_RFNOC + const std::string DDC_CUSTOM_BLOCK_NAME = "DDCch2"; + const std::string DUC_CUSTOM_BLOCK_NAME = "DUCch2"; #endif // UHD_ENABLE_CUSTOM_RFNOC const std::string DMA_FIFO_BLOCK_NAME = "DmaFIFO"; @@ -92,12 +86,12 @@ private: std::vector radio_id = {}; // DDC Control - std::vector ddc_ctrl = {}; - std::vector ddc_id = {}; + std::vector ddc_ctrl = {}; + std::vector ddc_id = {}; // DUC Control - std::vector duc_ctrl = {}; - std::vector duc_id = {}; + std::vector duc_ctrl = {}; + std::vector duc_id = {}; // DMA FIFO Control uhd::rfnoc::dma_fifo_block_ctrl::sptr dma_ctrl = {}; @@ -193,12 +187,28 @@ private: // Sleep for some time std::this_thread::sleep_for(SETUP_TIME_MS); + // Detect custom DDC +#ifdef UHD_ENABLE_CUSTOM_RFNOC + std::vector custom_ddc_list = device3->find_blocks(DDC_CUSTOM_BLOCK_NAME); + bool available_custom_ddc = not custom_ddc_list.empty(); +#endif // UHD_ENABLE_CUSTOM_RFNOC + // Create DDC control ddc_ctrl.resize(nof_radios); ddc_id.resize(nof_radios); for (size_t i = 0; i < nof_radios; i++) { - ddc_id[i] = uhd::rfnoc::block_id_t(0, DDC_BLOCK_NAME, i); - ddc_ctrl[i] = device3->get_block_ctrl(ddc_id[i]); + +#ifdef UHD_ENABLE_CUSTOM_RFNOC + if (available_custom_ddc) { + ddc_id[i] = uhd::rfnoc::block_id_t(0, DDC_CUSTOM_BLOCK_NAME, i); + ddc_ctrl[i] = device3->get_block_ctrl(ddc_id[i]); + } +#endif // UHD_ENABLE_CUSTOM_RFNOC + + if (ddc_ctrl[i] == nullptr) { + ddc_id[i] = uhd::rfnoc::block_id_t(0, DDC_BLOCK_NAME, i); + ddc_ctrl[i] = device3->get_block_ctrl(ddc_id[i]); + } for (size_t j = 0; j < nof_channels; j++) { @@ -212,12 +222,27 @@ private: } } + // Detect custom DUC +#ifdef UHD_ENABLE_CUSTOM_RFNOC + std::vector custom_duc_list = device3->find_blocks(DUC_CUSTOM_BLOCK_NAME); + bool available_custom_duc = not custom_duc_list.empty(); +#endif // UHD_ENABLE_CUSTOM_RFNOC + // Create DUC control duc_ctrl.resize(nof_radios); duc_id.resize(nof_radios); for (size_t i = 0; i < nof_radios; i++) { - duc_id[i] = uhd::rfnoc::block_id_t(0, DUC_BLOCK_NAME, i); - duc_ctrl[i] = device3->get_block_ctrl(duc_id[i]); +#ifdef UHD_ENABLE_CUSTOM_RFNOC + if (available_custom_duc) { + duc_id[i] = uhd::rfnoc::block_id_t(0, DUC_CUSTOM_BLOCK_NAME, i); + duc_ctrl[i] = device3->get_block_ctrl(duc_id[i]); + } +#endif // UHD_ENABLE_CUSTOM_RFNOC + + if (duc_ctrl[i] == nullptr) { + duc_id[i] = uhd::rfnoc::block_id_t(0, DUC_BLOCK_NAME, i); + duc_ctrl[i] = device3->get_block_ctrl(duc_id[i]); + } for (size_t j = 0; j < nof_channels; j++) {