Skip to content

Commit

Permalink
M2kHardwareTrigger: Add trigger out for analogical interface.
Browse files Browse the repository at this point in the history
Both DACs share the same trigger mechanism - only one DAC should be used
in order to configure the triggering system.
Implement the functionalities based on the generic definitions.

Signed-off-by: Teo Perisanu <[email protected]>
  • Loading branch information
Teo Perisanu authored and Teo Perisanu committed Jun 24, 2020
1 parent 8388364 commit 3696e12
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 0 deletions.
42 changes: 42 additions & 0 deletions include/libm2k/m2khardwaretrigger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,48 @@ class LIBM2K_API M2kHardwareTrigger
* @return the trigger condition
*/
virtual M2K_TRIGGER_CONDITION_DIGITAL getDigitalOutCondition() const = 0;


/**
* @brief Select which interface triggers the AnalogOut.
* @param src: of type M2K_TRIGGER_OUT_SOURCE:\n
* SRC_OUT_NONE - no trigger events
* SRC_OUT_TRIGGER_IN - trigger events on the TI(trigger in) pin trigger the DigitalOut interface;\n
* SRC_OUT_TRIGGER_OUT - trigger events on the TO(trigger out) pin trigger the DigitalOut interface;\n
* SRC_OUT_ANALOG_IN - trigger events on the AnalogIn interface trigger the DigitalOut interface;\n
* SRC_OUT_DIGITAL_IN - trigger events on the DigitalIn interface trigger the DigitalOut interface;\n
* @note Only available from firmware v0.26.
*/
virtual void setAnalogOutSource(M2K_TRIGGER_OUT_SOURCE src) = 0;


/**
* @brief Retrieve the source of the AnalogOut interface trigger event.
* @return M2K_TRIGGER_OUT_SOURCE :\n
* SRC_OUT_NONE;\n
* SRC_OUT_TRIGGER_IN;\n
* SRC_OUT_TRIGGER_OUT;\n
* SRC_OUT_ANALOG_IN;\n
* SRC_OUT_DIGITAL_IN;\n
* @note Only available from firmware v0.26.
*/
virtual M2K_TRIGGER_OUT_SOURCE getAnalogOutSource() const = 0;


/**
* @brief Set the trigger condition for the TI/TO in order to trigger the AnalogOut interface
* @param cond the specific trigger condition
*
* @note to have any effect the digital out source must be set to TI or TO
*/
virtual void setAnalogOutCondition(M2K_TRIGGER_CONDITION_DIGITAL cond) = 0;


/**
* @brief Get the trigger condition of the TI/TO pins that triggers the AnalogOut interface
* @return the trigger condition
*/
virtual M2K_TRIGGER_CONDITION_DIGITAL getAnalogOutCondition() const = 0;
};
}

Expand Down
22 changes: 22 additions & 0 deletions src/m2khardwaretrigger_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,25 @@ M2K_TRIGGER_CONDITION_DIGITAL M2kHardwareTriggerImpl::getDigitalOutCondition() c
throw_exception(EXC_INVALID_FIRMWARE_VERSION,"v0.26");
return NO_TRIGGER_DIGITAL;
}

void M2kHardwareTriggerImpl::setAnalogOutSource(M2K_TRIGGER_OUT_SOURCE src)
{
throw_exception(EXC_INVALID_FIRMWARE_VERSION,"v0.26");
}

M2K_TRIGGER_OUT_SOURCE M2kHardwareTriggerImpl::getAnalogOutSource() const
{
throw_exception(EXC_INVALID_FIRMWARE_VERSION,"v0.26");
return SRC_OUT_NONE;
}

void M2kHardwareTriggerImpl::setAnalogOutCondition(M2K_TRIGGER_CONDITION_DIGITAL cond)
{
throw_exception(EXC_INVALID_FIRMWARE_VERSION,"v0.26");
}

M2K_TRIGGER_CONDITION_DIGITAL M2kHardwareTriggerImpl::getAnalogOutCondition() const
{
throw_exception(EXC_INVALID_FIRMWARE_VERSION,"v0.26");
return NO_TRIGGER_DIGITAL;
}
5 changes: 5 additions & 0 deletions src/m2khardwaretrigger_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ class M2kHardwareTriggerImpl : public M2kHardwareTrigger
M2K_TRIGGER_OUT_SOURCE getDigitalOutSource() const override;
void setDigitalOutCondition(M2K_TRIGGER_CONDITION_DIGITAL cond) override;
M2K_TRIGGER_CONDITION_DIGITAL getDigitalOutCondition() const override;
void setAnalogOutSource(M2K_TRIGGER_OUT_SOURCE src) override;
M2K_TRIGGER_OUT_SOURCE getAnalogOutSource() const override;
void setAnalogOutCondition(M2K_TRIGGER_CONDITION_DIGITAL cond) override;
M2K_TRIGGER_CONDITION_DIGITAL getAnalogOutCondition() const override;

protected:
struct iio_device *m_trigger_device;
std::vector<Channel *> m_analog_channels;
Expand Down
34 changes: 34 additions & 0 deletions src/m2khardwaretrigger_v0.26_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,27 @@ libm2k::M2kHardwareTriggerV026Impl::M2kHardwareTriggerV026Impl(struct iio_contex
bool hasTriggerSource;
bool hasTriggerCondition;
m_digital_trigger_device = make_shared<libm2k::utils::DeviceOut>(ctx, "m2k-logic-analyzer-tx");
// both dac a and dac b share the same trigger
m_analog_trigger_device = make_shared<libm2k::utils::DeviceOut>(ctx, "m2k-dac-a");
if (!m_digital_trigger_device) {
throw_exception(EXC_INVALID_PARAMETER, "No digital TX trigger available");
}
if (!m_analog_trigger_device) {
throw_exception(EXC_INVALID_PARAMETER, "No analog TX trigger available");
}

hasTriggerSource = m_digital_trigger_device->hasGlobalAttribute(m_source_attr);
hasTriggerCondition = m_digital_trigger_device->hasGlobalAttribute(m_condition_attr);
if (!hasTriggerSource || !hasTriggerCondition) {
throw_exception(EXC_INVALID_PARAMETER, "Analog TX trigger is not available");
}

hasTriggerSource = m_analog_trigger_device->hasGlobalAttribute(m_source_attr);
hasTriggerCondition = m_analog_trigger_device->hasGlobalAttribute(m_condition_attr);
if (!hasTriggerSource || !hasTriggerCondition) {
throw_exception(EXC_INVALID_PARAMETER, "Analog TX trigger is not available");
}

if (init) {
reset();
}
Expand All @@ -70,6 +82,9 @@ void libm2k::M2kHardwareTriggerV026Impl::reset()
M2kHardwareTriggerV024Impl::reset();
setDigitalOutSource(SRC_OUT_NONE);
setDigitalOutCondition(NO_TRIGGER_DIGITAL);
setAnalogOutSource(SRC_OUT_NONE);
setAnalogOutCondition(NO_TRIGGER_DIGITAL);
}

void libm2k::M2kHardwareTriggerV026Impl::setDigitalOutSource(libm2k::M2K_TRIGGER_OUT_SOURCE src)
{
Expand All @@ -90,6 +105,25 @@ libm2k::M2K_TRIGGER_CONDITION_DIGITAL libm2k::M2kHardwareTriggerV026Impl::getDig
{
return getTriggerOutCondition(m_digital_trigger_device);
}

void libm2k::M2kHardwareTriggerV026Impl::setAnalogOutSource(libm2k::M2K_TRIGGER_OUT_SOURCE src)
{
setTriggerOutSource(src, m_analog_trigger_device);
}

libm2k::M2K_TRIGGER_OUT_SOURCE libm2k::M2kHardwareTriggerV026Impl::getAnalogOutSource() const
{
return getTriggerOutSource(m_analog_trigger_device);
}

void libm2k::M2kHardwareTriggerV026Impl::setAnalogOutCondition(libm2k::M2K_TRIGGER_CONDITION_DIGITAL cond)
{
setTriggerOutCondition(cond, m_analog_trigger_device);
}

libm2k::M2K_TRIGGER_CONDITION_DIGITAL libm2k::M2kHardwareTriggerV026Impl::getAnalogOutCondition() const
{
return getTriggerOutCondition(m_analog_trigger_device);
}

void libm2k::M2kHardwareTriggerV026Impl::setTriggerOutSource(libm2k::M2K_TRIGGER_OUT_SOURCE src,
Expand Down
9 changes: 9 additions & 0 deletions src/m2khardwaretrigger_v0.26_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,22 @@ class M2kHardwareTriggerV026Impl : public M2kHardwareTriggerV024Impl {

M2K_TRIGGER_CONDITION_DIGITAL getDigitalOutCondition() const override;

void setAnalogOutSource(M2K_TRIGGER_OUT_SOURCE src) override;

M2K_TRIGGER_OUT_SOURCE getAnalogOutSource() const override;

void setAnalogOutCondition(M2K_TRIGGER_CONDITION_DIGITAL cond) override;

M2K_TRIGGER_CONDITION_DIGITAL getAnalogOutCondition() const override;

protected:
void setTriggerOutSource(M2K_TRIGGER_OUT_SOURCE src, const std::shared_ptr<libm2k::utils::DeviceOut>& device);
M2K_TRIGGER_OUT_SOURCE getTriggerOutSource(const std::shared_ptr<libm2k::utils::DeviceOut>& device) const;
void setTriggerOutCondition(M2K_TRIGGER_CONDITION_DIGITAL cond, const std::shared_ptr<libm2k::utils::DeviceOut>& device);
M2K_TRIGGER_CONDITION_DIGITAL getTriggerOutCondition(const std::shared_ptr<libm2k::utils::DeviceOut>& device) const;

std::shared_ptr<libm2k::utils::DeviceOut> m_digital_trigger_device;
std::shared_ptr<libm2k::utils::DeviceOut> m_analog_trigger_device;

static std::vector<std::string> m_trigger_source;
static std::vector<std::string> m_trigger_cond;
Expand Down

0 comments on commit 3696e12

Please sign in to comment.