Skip to content

Commit

Permalink
Digital: Retrieve trigger out.
Browse files Browse the repository at this point in the history
Add the out trigger as an attribute inside m2k.
Add getter inside digital interface for trigger out.

Signed-off-by: Teo Perisanu <[email protected]>
  • Loading branch information
Teo Perisanu authored and Teo Perisanu committed May 15, 2020
1 parent d9649ec commit 785646b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
8 changes: 8 additions & 0 deletions include/libm2k/digital/m2kdigital.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <libm2k/digital/enums.hpp>
#include <libm2k/analog/enums.hpp>
#include <libm2k/m2khardwaretrigger.hpp>
#include <libm2k/m2kouthardwaretrigger.hpp>
#include <string>
#include <vector>

Expand Down Expand Up @@ -352,6 +353,13 @@ class LIBM2K_API M2kDigital
virtual libm2k::M2kHardwareTrigger* getTrigger() = 0;


/**
* @brief Get the hardware trigger out handler
* @return the trigger object
*/
virtual libm2k::M2kOutHardwareTrigger* getOutTrigger() = 0;


/**
* @brief Set the kernel buffers for input to a specific value
* @param count the number of kernel buffers
Expand Down
11 changes: 10 additions & 1 deletion src/digital/m2kdigital_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ std::vector<std::string> M2kDigitalImpl::m_output_mode = {
"push-pull",
};

M2kDigitalImpl::M2kDigitalImpl(struct iio_context *ctx, std::string logic_dev, bool sync, M2kHardwareTrigger *trigger)
M2kDigitalImpl::M2kDigitalImpl(struct iio_context *ctx, std::string logic_dev, bool sync, M2kHardwareTrigger *trigger, M2kOutHardwareTrigger *trigger_out)
{
__try {
m_dev_generic = make_shared<DeviceGeneric>(ctx, logic_dev);
Expand All @@ -48,6 +48,7 @@ M2kDigitalImpl::M2kDigitalImpl(struct iio_context *ctx, std::string logic_dev, b
}

m_trigger = trigger;
m_trigger_out = trigger_out;
m_dev_name_write = logic_dev + "-tx";
m_dev_name_read = logic_dev + "-rx";

Expand Down Expand Up @@ -347,6 +348,14 @@ M2kHardwareTrigger* M2kDigitalImpl::getTrigger()
return m_trigger;
}

M2kOutHardwareTrigger* M2kDigitalImpl::getOutTrigger()
{
if (!m_trigger_out) {
throw_exception(EXC_INVALID_PARAMETER, "Digital TX trigger is not available");
}
return m_trigger_out;
}

void M2kDigitalImpl::setOutputMode(DIO_CHANNEL chn, DIO_MODE mode)
{
std::string output_mode = m_output_mode[mode];
Expand Down
4 changes: 3 additions & 1 deletion src/digital/m2kdigital_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace digital {
class M2kDigitalImpl : public M2kDigital
{
public:
M2kDigitalImpl(struct iio_context* ctx, std::string logic_dev, bool sync, M2kHardwareTrigger *trigger);
M2kDigitalImpl(struct iio_context* ctx, std::string logic_dev, bool sync, M2kHardwareTrigger *trigger, M2kOutHardwareTrigger *trigger_out);
virtual ~M2kDigitalImpl();

void reset();
Expand Down Expand Up @@ -85,6 +85,7 @@ class M2kDigitalImpl : public M2kDigital
void setCyclic(bool cyclic);

libm2k::M2kHardwareTrigger* getTrigger();
libm2k::M2kOutHardwareTrigger* getOutTrigger() override;

void setKernelBuffersCountIn(unsigned int count);
void setKernelBuffersCountOut(unsigned int count);
Expand All @@ -108,6 +109,7 @@ class M2kDigitalImpl : public M2kDigital
std::vector<bool> m_tx_channels_enabled;
std::vector<bool> m_rx_channels_enabled;
libm2k::M2kHardwareTrigger *m_trigger;
libm2k::M2kOutHardwareTrigger *m_trigger_out;
static std::vector<std::string> m_output_mode;

void syncDevice();
Expand Down
13 changes: 9 additions & 4 deletions src/m2k_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "analog/m2kpowersupply_impl.hpp"
#include "m2khardwaretrigger_impl.hpp"
#include "m2khardwaretrigger_v0.24_impl.hpp"
#include "m2kouthardwaretrigger_impl.hpp"
#include "m2kcalibration_impl.hpp"
#include <libm2k/analog/dmm.hpp>
#include "utils/channel.hpp"
Expand Down Expand Up @@ -66,13 +67,17 @@ M2kImpl::M2kImpl(std::string uri, iio_context* ctx, std::string name, bool sync)

m_firmware_version = getFirmwareVersion();

int diff = Utils::compareVersions(m_firmware_version, "v0.24");
if (diff < 0) { //m_firmware_version < 0.24
int diff_v024 = Utils::compareVersions(m_firmware_version, "v0.24");
if (diff_v024 < 0) { //m_firmware_version < 0.24
m_trigger = new M2kHardwareTriggerImpl(ctx);
} else {
m_trigger = new M2kHardwareTriggerV024Impl(ctx);
}

// TODO replace v0.25 -> v0.26 and change the comp condition
int diff_v026 = Utils::compareVersions(m_firmware_version, "v0.25");
if (diff_v026 < 0) {
m_trigger_out = new M2kOutHardwareTriggerImpl(ctx);
}
if (!m_trigger) {
throw_exception(EXC_INVALID_PARAMETER, "Can't instantiate M2K board; M2K trigger is invalid.");
}
Expand Down Expand Up @@ -187,7 +192,7 @@ void M2kImpl::scanAllPowerSupply()

void M2kImpl::scanAllDigital()
{
libm2k::digital::M2kDigital* logic = new libm2k::digital::M2kDigitalImpl(m_context, "m2k-logic-analyzer", m_sync, m_trigger);
libm2k::digital::M2kDigital* logic = new libm2k::digital::M2kDigitalImpl(m_context, "m2k-logic-analyzer", m_sync, m_trigger, m_trigger_out);
m_instancesDigital.push_back(logic);
}

Expand Down
2 changes: 2 additions & 0 deletions src/m2k_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

namespace libm2k {
class M2kHardwareTrigger;
class M2kOutHardwareTrigger;
class M2kCalibration;

namespace context {
Expand Down Expand Up @@ -73,6 +74,7 @@ class M2kImpl : public M2k, public ContextImpl
private:
M2kCalibration* m_calibration;
libm2k::M2kHardwareTrigger *m_trigger;
libm2k::M2kOutHardwareTrigger *m_trigger_out;
std::vector<analog::M2kAnalogOut*> m_instancesAnalogOut;
std::vector<analog::M2kAnalogIn*> m_instancesAnalogIn;
std::vector<analog::M2kPowerSupply*> m_instancesPowerSupply;
Expand Down

0 comments on commit 785646b

Please sign in to comment.