aboutsummaryrefslogtreecommitdiffstats
path: root/mpm/lib/mykonos
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2017-04-19 18:55:16 -0700
committerMartin Braun <martin.braun@ettus.com>2017-12-22 15:03:46 -0800
commit36365930a6035e18dc3ec07d401d73e7730af8cf (patch)
tree5d1c2e3653c3f2edce464328fdf03eafaaffd476 /mpm/lib/mykonos
parent0cdf67ad33628af28cf92ef4ad7eaa63c712b8b5 (diff)
downloaduhd-36365930a6035e18dc3ec07d401d73e7730af8cf.tar.gz
uhd-36365930a6035e18dc3ec07d401d73e7730af8cf.tar.bz2
uhd-36365930a6035e18dc3ec07d401d73e7730af8cf.zip
mpm: Fixed a plethora of SPI-related issues
Diffstat (limited to 'mpm/lib/mykonos')
-rw-r--r--mpm/lib/mykonos/ad937x_ctrl.cpp7
-rw-r--r--mpm/lib/mykonos/ad937x_device.cpp43
-rw-r--r--mpm/lib/mykonos/ad937x_device.hpp4
-rw-r--r--mpm/lib/mykonos/adi_ctrl.cpp19
-rw-r--r--mpm/lib/mykonos/config/ad937x_config_t.cpp3
-rw-r--r--mpm/lib/mykonos/config/ad937x_config_t.hpp4
6 files changed, 50 insertions, 30 deletions
diff --git a/mpm/lib/mykonos/ad937x_ctrl.cpp b/mpm/lib/mykonos/ad937x_ctrl.cpp
index dc4682598..d6360dad6 100644
--- a/mpm/lib/mykonos/ad937x_ctrl.cpp
+++ b/mpm/lib/mykonos/ad937x_ctrl.cpp
@@ -22,6 +22,7 @@
#include <sstream>
#include <set>
#include <functional>
+#include <iostream>
using namespace mpm::ad937x::device;
@@ -123,9 +124,10 @@ public:
uhd::spi_iface::sptr iface,
mpm::ad937x::gpio::gain_pins_t gain_pins) :
spi_mutex(spi_mutex),
- device(iface, gain_pins)
+ device(iface.get(), gain_pins),
+ _iface(iface)
{
-
+ /* nop */
}
virtual void begin_initialization()
@@ -379,6 +381,7 @@ public:
private:
ad937x_device device;
std::shared_ptr<std::mutex> spi_mutex;
+ uhd::spi_iface::sptr _iface;
};
ad937x_ctrl::sptr ad937x_ctrl::make(std::shared_ptr<std::mutex> spi_mutex, uhd::spi_iface::sptr iface, mpm::ad937x::gpio::gain_pins_t gain_pins)
diff --git a/mpm/lib/mykonos/ad937x_device.cpp b/mpm/lib/mykonos/ad937x_device.cpp
index 663acbf30..138e4e165 100644
--- a/mpm/lib/mykonos/ad937x_device.cpp
+++ b/mpm/lib/mykonos/ad937x_device.cpp
@@ -20,6 +20,8 @@
#include "adi/mykonos_gpio.h"
#include "adi/mykonos_debug/mykonos_dbgjesd.h"
+#include <boost/format.hpp>
+
#include <functional>
#include <iostream>
@@ -112,16 +114,16 @@ void ad937x_device::_call_gpio_api_function(std::function<mykonosGpioErr_t()> fu
}
}
-void ad937x_device::_call_debug_api_function(std::function<mykonosDbgErr_t()> func)
-{
- auto error = func();
- if (error != MYKONOS_ERR_DBG_OK)
- {
- std::cout << getDbgJesdMykonosErrorMessage(error);
- // TODO: make UHD exception
- //throw std::exception(getMykonosErrorMessage(error));
- }
-}
+//void ad937x_device::_call_debug_api_function(std::function<mykonosDbgErr_t()> func)
+//{
+ //auto error = func();
+ //if (error != MYKONOS_ERR_DBG_OK)
+ //{
+ //std::cout << getDbgJesdMykonosErrorMessage(error);
+ //// TODO: make UHD exception
+ ////throw std::exception(getMykonosErrorMessage(error));
+ //}
+//}
// TODO: delete this comment closer to release
/*
@@ -193,14 +195,17 @@ void ad937x_device::begin_initialization()
{
// TODO: make this reset actually do something (implement CMB_HardReset or replace)
_call_api_function(std::bind(MYKONOS_resetDevice, mykonos_config.device));
+ _call_api_function(std::bind(MYKONOS_initialize, mykonos_config.device));
- if (get_product_id() != AD9371_PRODUCT_ID)
+ uint8_t product_id = get_product_id();
+ if (product_id != AD9371_PRODUCT_ID)
{
- throw runtime_error("AD9371 product ID does not match expected ID!");
+ throw runtime_error(str(
+ boost::format("AD9371 product ID does not match expected ID! Read: %X Expected: %X")
+ % int(product_id) % int(AD9371_PRODUCT_ID)
+ ));
}
- _call_api_function(std::bind(MYKONOS_initialize, mykonos_config.device));
-
if (!get_pll_lock_status(pll_t::CLK_SYNTH))
{
throw runtime_error("AD937x CLK_SYNTH PLL failed to lock in initialize()");
@@ -267,7 +272,7 @@ uint8_t ad937x_device::get_deframer_status()
uint8_t ad937x_device::get_deframer_irq()
{
uint8_t irq_status = 0;
- _call_debug_api_function(std::bind(MYKONOS_deframerGetIrq, mykonos_config.device, &irq_status));
+ //_call_debug_api_function(std::bind(MYKONOS_deframerGetIrq, mykonos_config.device, &irq_status));
return irq_status;
}
@@ -284,11 +289,17 @@ void ad937x_device::enable_jesd_loopback(uint8_t enable)
_call_api_function(std::bind(MYKONOS_setRxFramerDataSource, mykonos_config.device, enable));
}
-ad937x_device::ad937x_device(spi_iface::sptr iface, gain_pins_t gain_pins) :
+ad937x_device::ad937x_device(spi_iface* iface, gain_pins_t gain_pins) :
full_spi_settings(iface),
mykonos_config(&full_spi_settings.spi_settings),
gain_ctrl(gain_pins)
{
+ std::cout << "full spi settings addr " << &full_spi_settings << std::endl;
+ iface->read_spi(0, uhd::spi_config_t::EDGE_RISE, 400, 24);
+ std::cout << "adi spi settings addr " << &(full_spi_settings.spi_settings) << std::endl;
+ std::cout << "iface addr " << std::hex << iface << std::dec << std::endl;
+
+ std::cout << "myk dev addr " << std::hex << mykonos_config.device->spiSettings << std::dec << std::endl;
}
diff --git a/mpm/lib/mykonos/ad937x_device.hpp b/mpm/lib/mykonos/ad937x_device.hpp
index 1b21a5a04..729912adf 100644
--- a/mpm/lib/mykonos/ad937x_device.hpp
+++ b/mpm/lib/mykonos/ad937x_device.hpp
@@ -39,7 +39,7 @@ public:
enum class gain_mode_t { MANUAL, AUTOMATIC, HYBRID };
enum class pll_t {CLK_SYNTH, RX_SYNTH, TX_SYNTH, SNIFF_SYNTH, CALPLL_SDM};
- ad937x_device(uhd::spi_iface::sptr iface, mpm::ad937x::gpio::gain_pins_t gain_pins);
+ ad937x_device(uhd::spi_iface* iface, mpm::ad937x::gpio::gain_pins_t gain_pins);
void begin_initialization();
void finish_initialization();
@@ -96,7 +96,7 @@ private:
void _call_api_function(std::function<mykonosErr_t()> func);
void _call_gpio_api_function(std::function<mykonosGpioErr_t()> func);
- void _call_debug_api_function(std::function<mykonosDbgErr_t()> func);
+ //void _call_debug_api_function(std::function<mykonosDbgErr_t()> func);
static uint8_t _convert_rx_gain(double gain);
static uint16_t _convert_tx_gain(double gain);
diff --git a/mpm/lib/mykonos/adi_ctrl.cpp b/mpm/lib/mykonos/adi_ctrl.cpp
index c7fcceaa9..9a5f73607 100644
--- a/mpm/lib/mykonos/adi_ctrl.cpp
+++ b/mpm/lib/mykonos/adi_ctrl.cpp
@@ -24,7 +24,9 @@
#include <chrono>
#include <thread>
-ad9371_spiSettings_t::ad9371_spiSettings_t(uhd::spi_iface::sptr uhd_iface) :
+static const uint32_t MYKONOS_READ_BIT = (1 << 23);
+
+ad9371_spiSettings_t::ad9371_spiSettings_t(uhd::spi_iface* uhd_iface) :
spi_iface(uhd_iface)
{
spi_settings.chipSelectIndex = 0; // set later
@@ -98,7 +100,7 @@ commonErr_t CMB_SPIWriteByte(spiSettings_t *spiSettings, uint16_t addr, uint8_t
mpm_spi->spi_iface->write_spi(spiSettings->chipSelectIndex, config, data_word, 24);
return COMMONERR_OK;
} catch (const std::exception &e) {
- // ... error handling ...
+ std::cout << "AAAAAAAAAAAAH" << std::endl;
}
return COMMONERR_FAILED;
}
@@ -124,7 +126,7 @@ commonErr_t CMB_SPIWriteBytes(spiSettings_t *spiSettings, uint16_t *addr, uint8_
}
return COMMONERR_OK;
} catch (const std::exception &e) {
- // ... error handling ...
+ std::cout << "AAAAAAAAAAAAH" << std::endl;
}
return COMMONERR_FAILED;
}
@@ -141,13 +143,14 @@ commonErr_t CMB_SPIReadByte (spiSettings_t *spiSettings, uint16_t addr, uint8_t
ad9371_spiSettings_t *mpm_spi = ad9371_spiSettings_t::make(spiSettings);
uhd::spi_config_t config(_get_edge(*spiSettings));
- uint32_t data_word = (0) | (addr << 8);
+ uint32_t read_word = MYKONOS_READ_BIT | (addr << 8);
try {
*readdata = static_cast<uint8_t>(
- mpm_spi->spi_iface->read_spi(spiSettings->chipSelectIndex, config, data_word, 24));
+ mpm_spi->spi_iface->read_spi(spiSettings->chipSelectIndex, config, read_word, 24));
return COMMONERR_OK;
} catch (const std::exception &e) {
+ std::cout << "AAAAAAAAAAAAH READ" << std::endl;
// ... error handling ...
}
return COMMONERR_FAILED;
@@ -170,6 +173,7 @@ commonErr_t CMB_SPIWriteField(
mpm_spi->spi_iface->write_spi(spiSettings->chipSelectIndex, config, write_word, 24);
return COMMONERR_OK;
} catch (const std::exception &e) {
+ std::cout << "AAAAAAAAAAAAH WRITE FIELD" << std::endl;
// ... error handling ...
}
return COMMONERR_FAILED;
@@ -184,13 +188,14 @@ commonErr_t CMB_SPIReadField(
) {
ad9371_spiSettings_t *mpm_spi = ad9371_spiSettings_t::make(spiSettings);
uhd::spi_config_t config(_get_edge(*spiSettings));
- uint32_t read_word = (0) | (addr << 8);
+ uint32_t read_word = MYKONOS_READ_BIT | (addr << 8);
try {
uint32_t value = mpm_spi->spi_iface->read_spi(spiSettings->chipSelectIndex, config, read_word, 24);
*field_val = static_cast<uint8_t>((value & mask) >> start_bit);
return COMMONERR_OK;
} catch (const std::exception &e) {
+ std::cout << "AAAAAAAAAAAAH READ FIELD" << std::endl;
/* ... error handling ... */
}
return COMMONERR_FAILED;
@@ -250,7 +255,7 @@ commonErr_t CMB_closeLog(void)
commonErr_t CMB_writeToLog(ADI_LOGLEVEL level, uint8_t deviceIndex, uint32_t errorCode, const char *comment)
{
- std::cout << level << " " << errorCode << " " << comment << std::endl;
+ std::cout << "[CMB_writeToLog] level==" << level << " errorCode==" << errorCode << " " << comment << std::endl;
return COMMONERR_OK;
}
commonErr_t CMB_flushLog(void)
diff --git a/mpm/lib/mykonos/config/ad937x_config_t.cpp b/mpm/lib/mykonos/config/ad937x_config_t.cpp
index 941690d06..eac294299 100644
--- a/mpm/lib/mykonos/config/ad937x_config_t.cpp
+++ b/mpm/lib/mykonos/config/ad937x_config_t.cpp
@@ -24,6 +24,8 @@ ad937x_config_t::ad937x_config_t(spiSettings_t* sps)
_assign_default_configuration();
_init_pointers();
+
+ device = &_device;
}
void ad937x_config_t::_assign_default_configuration()
@@ -70,7 +72,6 @@ void ad937x_config_t::_assign_default_configuration()
void ad937x_config_t::_init_pointers()
{
- _device.spiSettings = &_spiSettings;
_device.rx = &_rx;
_device.tx = &_tx;
_device.obsRx = &_obsRx;
diff --git a/mpm/lib/mykonos/config/ad937x_config_t.hpp b/mpm/lib/mykonos/config/ad937x_config_t.hpp
index 5663517c7..94d14c733 100644
--- a/mpm/lib/mykonos/config/ad937x_config_t.hpp
+++ b/mpm/lib/mykonos/config/ad937x_config_t.hpp
@@ -28,7 +28,8 @@ class ad937x_config_t : public boost::noncopyable
// a user could technically modify the pointers in the structs, but we have no way of preventing that
public:
ad937x_config_t(spiSettings_t* sps);
- mykonosDevice_t * const device = &_device;
+ //mykonosDevice_t * const device = &_device;
+ mykonosDevice_t * device;
ad937x_fir rx_fir_config;
ad937x_fir tx_fir_config;
@@ -40,7 +41,6 @@ private:
// in general, this organization stinks
// TODO: group and make more sense of these fields and pointers
- spiSettings_t _spiSettings;
mykonosRxSettings_t _rx;
mykonosTxSettings_t _tx;
mykonosObsRxSettings_t _obsRx;