diff options
Diffstat (limited to 'mpm/lib')
-rw-r--r-- | mpm/lib/lmk04828/lmk04828_spi_iface.cpp | 2 | ||||
-rw-r--r-- | mpm/lib/mykonos/ad937x_ctrl.cpp | 7 | ||||
-rw-r--r-- | mpm/lib/mykonos/ad937x_device.cpp | 43 | ||||
-rw-r--r-- | mpm/lib/mykonos/ad937x_device.hpp | 4 | ||||
-rw-r--r-- | mpm/lib/mykonos/adi_ctrl.cpp | 19 | ||||
-rw-r--r-- | mpm/lib/mykonos/config/ad937x_config_t.cpp | 3 | ||||
-rw-r--r-- | mpm/lib/mykonos/config/ad937x_config_t.hpp | 4 | ||||
-rw-r--r-- | mpm/lib/spi/spidev_iface.cpp | 37 |
8 files changed, 80 insertions, 39 deletions
diff --git a/mpm/lib/lmk04828/lmk04828_spi_iface.cpp b/mpm/lib/lmk04828/lmk04828_spi_iface.cpp index d0ae26063..1251f4535 100644 --- a/mpm/lib/lmk04828/lmk04828_spi_iface.cpp +++ b/mpm/lib/lmk04828/lmk04828_spi_iface.cpp @@ -30,7 +30,7 @@ uint8_t lmk04828_spi_iface::spi_read(uint32_t addr) { // r/w[23] 0[22:21] addr[20:8] data[7:0] = 24 bits uint32_t transaction = 0; transaction |= LMK_SPI_READ_FLAG << LMK_SPI_READ_FLAG_OFFSET; - transaction &= LMK_SPI_RESERVED_FIELD_MASK; + //transaction &= LMK_SPI_RESERVED_FIELD_MASK; transaction |= addr << LMK_SPI_READ_ADDR_OFFSET; uint32_t data = _spi_iface->read_spi(DEFAULT_SLAVE, config, transaction, LMK_SPI_NUM_BITS); 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; diff --git a/mpm/lib/spi/spidev_iface.cpp b/mpm/lib/spi/spidev_iface.cpp index 7108759f8..88ee46824 100644 --- a/mpm/lib/spi/spidev_iface.cpp +++ b/mpm/lib/spi/spidev_iface.cpp @@ -23,6 +23,8 @@ #include <linux/spi/spidev.h> #include <boost/format.hpp> +#include <iostream> + using namespace mpm::spi; /****************************************************************************** @@ -45,34 +47,53 @@ public: )); } - ret = ioctl(_fd, SPI_IOC_WR_MODE32, &_mode); + int MODE = 3; + ret = ioctl(_fd, SPI_IOC_WR_MODE32, &MODE); if (ret == -1) { - throw std::runtime_error("Could not set spidev mode"); + throw std::runtime_error(str( + boost::format("Could not set spidev mode to %X for spidev %s") + % uint16_t(_mode) % device + )); } ret = ioctl(_fd, SPI_IOC_RD_MODE32, &_mode); if (ret == -1) { - throw std::runtime_error("Could not get spidev mode"); + throw std::runtime_error(str( + boost::format("Could not get spidev mode for spidev %s") + % device + )); } ret = ioctl(_fd, SPI_IOC_WR_BITS_PER_WORD, &_bits); if (ret == -1) { - throw std::runtime_error("Could not set spidev bits per word"); + throw std::runtime_error(str( + boost::format("Could not set spidev bits per word to %d for spidev %s") + % uint16_t(_bits) % device + )); } ret = ioctl(_fd, SPI_IOC_RD_BITS_PER_WORD, &_bits); if (ret == -1) { - throw std::runtime_error("Could not get spidev bits per word"); + throw std::runtime_error(str( + boost::format("Could not get spidev bits per word for spidev %s") + % device + )); } ret = ioctl(_fd, SPI_IOC_WR_MAX_SPEED_HZ, &_speed); if (ret == -1) { - throw std::runtime_error("Could not set spidev max speed"); + throw std::runtime_error(str( + boost::format("Could not set spidev max speed to %d for spidev %s") + % _speed % device + )); } ret = ioctl(_fd, SPI_IOC_RD_MAX_SPEED_HZ, &_speed); if (ret == -1) { - throw std::runtime_error("Could not get spidev max speed"); + throw std::runtime_error(str( + boost::format("Could not get spidev max speed for spidev %s") + % device + )); } } @@ -138,7 +159,7 @@ public: private: int _fd; - uint8_t _mode = SPI_CPHA | SPI_CPOL; + uint32_t _mode = SPI_CPHA | SPI_CPOL; uint32_t _speed = 2000000; uint8_t _bits = 8; uint16_t _delay = 0; |