Skip to content

Commit

Permalink
M2KAnalogOut: Add support for auto_rearm attribute
Browse files Browse the repository at this point in the history
- Introduce the auto_rearm attribute to the AnalogOut class.
- This attribute controls the behavior of the DAC when configured to start on a trigger event.
- When auto_rearm is disabled, all previously loaded buffers will be sent to the DAC output upon the trigger event.
- When auto_rearm is enabled, each previously loaded buffer will be sent to the DAC output on each trigger event.

Signed-off-by: Adrian Stanea <[email protected]>
  • Loading branch information
Adrian-Stanea committed Jun 20, 2024
1 parent 8703161 commit 51725c0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
26 changes: 26 additions & 0 deletions include/libm2k/analog/m2kanalogout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
}
Expand Down
21 changes: 20 additions & 1 deletion src/analog/m2kanalogout_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ M2kAnalogOutImpl::M2kAnalogOutImpl(iio_context *ctx, std::vector<std::string> 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"));
Expand Down Expand Up @@ -743,4 +746,20 @@ double M2kAnalogOutImpl::getMaximumSamplerate(unsigned int chn_idx)
libm2k::M2kHardwareTrigger *M2kAnalogOutImpl::getTrigger()
{
return m_trigger;
}
}

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");
}
3 changes: 3 additions & 0 deletions src/analog/m2kanalogout_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<libm2k::utils::DeviceGeneric> m_m2k_fabric;
Expand All @@ -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<unsigned int> m_nb_kernel_buffers;
std::vector<bool> m_raw_enable_available;
std::vector<bool> m_raw_available;
Expand Down

0 comments on commit 51725c0

Please sign in to comment.