diff --git a/include/libm2k/analog/m2kanalogout.hpp b/include/libm2k/analog/m2kanalogout.hpp index 0b06c910..f0133804 100644 --- a/include/libm2k/analog/m2kanalogout.hpp +++ b/include/libm2k/analog/m2kanalogout.hpp @@ -495,6 +495,32 @@ class LIBM2K_API M2kAnalogOut * @return A pointer to the hardware trigger */ virtual libm2k::M2kHardwareTrigger* getTrigger() = 0; + + + /** + * @brief Allows sequential output of multiple buffers with each trigger event. + * @param enable A boolean value that enables or disables the buffer rearm functionality. + * + * @note When disabled, all buffers will be sent at once. Opt to concatenate multiple small buffers into a single buffer to avoid timing problems. + * @note When enabled, each previously pushed buffer will be sent sequentially with each trigger event. + * @note For non-cyclic mode each buffer is sent only once. + * @note In cyclic mode: + * - If rearm is disabled, the buffer will be sent continuously. + * - If rearm is enabled, the buffer will be sent once for every trigger event. + * @note Due to hardware limitation, in non-cyclic mode, the channel will idle with the first sample of the next buffer. + * @note Only available from firmware v0.33. + */ + virtual void setBufferRearmOnTrigger(bool enable) = 0; + + + /** + * @brief Retrieve the value of the attribute that controls buffer rearm on trigger + * @note The buffer rearm on trigger is disabled by default. + * @note The attribute is shared between both channels. + * @note Only available from firmware v0.33. + * @return A boolean value corresponding to the state of the rearm on trigger. + */ + virtual bool getBufferRearmOnTrigger() = 0; }; } } diff --git a/src/analog/m2kanalogout_impl.cpp b/src/analog/m2kanalogout_impl.cpp index ae30c70a..41d69497 100644 --- a/src/analog/m2kanalogout_impl.cpp +++ b/src/analog/m2kanalogout_impl.cpp @@ -75,6 +75,9 @@ M2kAnalogOutImpl::M2kAnalogOutImpl(iio_context *ctx, std::vector da // data_available attribute exists only in firmware versions newer than 0.23 m_dma_data_available = getDacDevice(0)->hasBufferAttribute("data_available"); + // auto_rearm_trigger attribute is only available in firmware versions newer than 0.33 + m_auto_rearm_trigger_available = getDacDevice(0)->hasGlobalAttribute("auto_rearm_trigger"); + m_raw_enable_available.push_back(getDacDevice(0)->getChannel(0, true)->hasAttribute("raw_enable")); m_raw_enable_available.push_back(getDacDevice(1)->getChannel(0, true)->hasAttribute("raw_enable")); m_raw_available.push_back(getDacDevice(0)->getChannel(0, true)->hasAttribute("raw")); @@ -743,4 +746,20 @@ double M2kAnalogOutImpl::getMaximumSamplerate(unsigned int chn_idx) libm2k::M2kHardwareTrigger *M2kAnalogOutImpl::getTrigger() { return m_trigger; -} \ No newline at end of file +} + +void M2kAnalogOutImpl::setBufferRearmOnTrigger(bool enable) +{ + if (!m_auto_rearm_trigger_available) { + THROW_M2K_EXCEPTION("Invalid firmware version: 0.33 or greater is required.", libm2k::EXC_INVALID_FIRMWARE_VERSION); + } + m_dac_devices[0]->setBoolValue(enable, "auto_rearm_trigger"); +} + +bool M2kAnalogOutImpl::getBufferRearmOnTrigger() +{ + if (!m_auto_rearm_trigger_available) { + THROW_M2K_EXCEPTION("Invalid firmware version: 0.33 or greater is required.", libm2k::EXC_INVALID_FIRMWARE_VERSION); + } + return m_dac_devices[0]->getBoolValue("auto_rearm_trigger"); +} diff --git a/src/analog/m2kanalogout_impl.hpp b/src/analog/m2kanalogout_impl.hpp index 217355d1..28277a66 100644 --- a/src/analog/m2kanalogout_impl.hpp +++ b/src/analog/m2kanalogout_impl.hpp @@ -96,6 +96,8 @@ class M2kAnalogOutImpl : public M2kAnalogOut unsigned short setVoltageRaw(unsigned int chn_idx, unsigned short raw) override; libm2k::M2kHardwareTrigger* getTrigger() override; + void setBufferRearmOnTrigger(bool enable) override; + bool getBufferRearmOnTrigger() override; private: std::shared_ptr m_m2k_fabric; @@ -110,6 +112,7 @@ class M2kAnalogOutImpl : public M2kAnalogOut bool m_dma_start_sync_available; bool m_dma_data_available; + bool m_auto_rearm_trigger_available; std::vector m_nb_kernel_buffers; std::vector m_raw_enable_available; std::vector m_raw_available;