diff options
author | Martin Braun <martin.braun@ettus.com> | 2017-05-11 12:04:45 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2017-12-22 15:03:53 -0800 |
commit | b39dafa1eebf327a8bbd3959a3c54e85707b56aa (patch) | |
tree | 5b3b4688a5c24404cc7e4ec20442e9e742c8cbaa | |
parent | e6858a61a81d0ff1762e4b8434fe781acf2fc1ab (diff) | |
download | uhd-b39dafa1eebf327a8bbd3959a3c54e85707b56aa.tar.gz uhd-b39dafa1eebf327a8bbd3959a3c54e85707b56aa.tar.bz2 uhd-b39dafa1eebf327a8bbd3959a3c54e85707b56aa.zip |
mpm: Enabled selection of SPI mode
-rw-r--r-- | mpm/include/mpm/spi/spi_iface.hpp | 3 | ||||
-rw-r--r-- | mpm/include/mpm/spi/spi_regs_iface.hpp | 1 | ||||
-rw-r--r-- | mpm/lib/spi/spi_regs_iface.cpp | 3 | ||||
-rw-r--r-- | mpm/lib/spi/spidev_iface.cpp | 13 | ||||
-rw-r--r-- | mpm/python/usrp_mpm/dboard_manager/eiscat.py | 62 | ||||
-rw-r--r-- | mpm/python/usrp_mpm/dboard_manager/magnesium.py | 2 |
6 files changed, 55 insertions, 29 deletions
diff --git a/mpm/include/mpm/spi/spi_iface.hpp b/mpm/include/mpm/spi/spi_iface.hpp index 8f8eaa2ec..d3f387ff3 100644 --- a/mpm/include/mpm/spi/spi_iface.hpp +++ b/mpm/include/mpm/spi/spi_iface.hpp @@ -45,7 +45,8 @@ namespace mpm { namespace spi { */ static sptr make_spidev( const std::string &device, - const int speed_hz + const int speed_hz, + const int spi_mode=3 ); }; diff --git a/mpm/include/mpm/spi/spi_regs_iface.hpp b/mpm/include/mpm/spi/spi_regs_iface.hpp index 072e15dc4..a28817db2 100644 --- a/mpm/include/mpm/spi/spi_regs_iface.hpp +++ b/mpm/include/mpm/spi/spi_regs_iface.hpp @@ -35,6 +35,7 @@ namespace mpm { namespace spi { mpm::types::regs_iface::sptr make_spidev_regs_iface( const std::string &device, const int speed_hz, + const int spi_mode, uint32_t addr_shift, uint32_t data_shift, uint32_t read_flags, diff --git a/mpm/lib/spi/spi_regs_iface.cpp b/mpm/lib/spi/spi_regs_iface.cpp index a84a14997..ab9e089f8 100644 --- a/mpm/lib/spi/spi_regs_iface.cpp +++ b/mpm/lib/spi/spi_regs_iface.cpp @@ -102,13 +102,14 @@ regs_iface::sptr mpm::spi::make_spi_regs_iface( mpm::types::regs_iface::sptr mpm::spi::make_spidev_regs_iface( const std::string &device, const int speed_hz, + const int spi_mode, uint32_t addr_shift, uint32_t data_shift, uint32_t read_flags, uint32_t write_flags ) { auto spi_iface_sptr = mpm::spi::spi_iface::make_spidev( - device, speed_hz + device, speed_hz, spi_mode ); return std::make_shared<spi_regs_iface_impl>( spi_iface_sptr, diff --git a/mpm/lib/spi/spidev_iface.cpp b/mpm/lib/spi/spidev_iface.cpp index fe37f16d5..74cb6bc88 100644 --- a/mpm/lib/spi/spidev_iface.cpp +++ b/mpm/lib/spi/spidev_iface.cpp @@ -37,8 +37,10 @@ public: spidev_iface_impl( const std::string &device, - const int max_speed_hz - ) : _speed(max_speed_hz) + const int max_speed_hz, + const int spi_mode + ) : _speed(max_speed_hz), + _mode(spi_mode) { if (!init_spi( @@ -94,7 +96,7 @@ public: private: int _fd; - uint32_t _mode = SPI_CPHA | SPI_CPOL; + const uint32_t _mode; uint32_t _speed = 2000000; uint8_t _bits = 8; uint16_t _delay = 0; @@ -105,10 +107,11 @@ private: *****************************************************************************/ spi_iface::sptr spi_iface::make_spidev( const std::string &device, - const int speed_hz + const int speed_hz, + const int spi_mode ) { return std::make_shared<spidev_iface_impl>( - device, speed_hz + device, speed_hz, spi_mode ); } diff --git a/mpm/python/usrp_mpm/dboard_manager/eiscat.py b/mpm/python/usrp_mpm/dboard_manager/eiscat.py index 98aab2a03..71857ecac 100644 --- a/mpm/python/usrp_mpm/dboard_manager/eiscat.py +++ b/mpm/python/usrp_mpm/dboard_manager/eiscat.py @@ -40,24 +40,35 @@ PWR2_5V_ADC1_SPI_EN = 1<<13 ADC_RESET = 0x2008 -def create_spidev_iface(dev_node): +def create_spidev_iface_sane(dev_node): """ - Create a regs iface from a spidev node + Create a regs iface from a spidev node (sane values) """ - SPI_SPEED_HZ = 1000000 - SPI_ADDR_SHIFT = 8 - SPI_DATA_SHIFT = 0 - SPI_READ_FLAG = 1<<23 - SPI_WRIT_FLAG = 0 return lib.spi.make_spidev_regs_iface( dev_node, - SPI_SPEED_HZ, - SPI_ADDR_SHIFT, - SPI_DATA_SHIFT, - SPI_READ_FLAG, - SPI_WRIT_FLAG + 1000000, # Speed (Hz) + 3, # SPI mode + 8, # Addr shift + 0, # Data shift + 1<<23, # Read flag + 0, # Write flag ) +def create_spidev_iface_phasedac(dev_node): + """ + Create a regs iface from a spidev node (ADS5681) + """ + return lib.spi.make_spidev_regs_iface( + dev_node, + 1000000, # Speed (Hz) + 1, # SPI mode + 20, # Addr shift + 8, # Data shift + 0, # Read flag + 0, # Write flag + ) + + class ADS54J56(object): """ Controls for ADS54J56 ADC @@ -184,7 +195,6 @@ class MMCM(object): self.RADIO_CLK2X_ENABLE | \ self.RADIO_CLK3X_ENABLE ) - self.log.trace("Clocks enabled readback: 0x{:x}".format(self.peek32())) return True @@ -347,7 +357,14 @@ class EISCAT(DboardManagerBase): spi_chipselect = { "lmk": 0, "adc0": 1, - "adc1": 2 + "adc1": 2, + # "phase_dac": 3, + } + spi_factories = { + "lmk": create_spidev_iface_sane, + "adc0": create_spidev_iface_sane, + "adc1": create_spidev_iface_sane, + # "phase_dac": create_spidev_iface_phasedac, } def __init__(self, slot_idx, **kwargs): @@ -356,9 +373,6 @@ class EISCAT(DboardManagerBase): self.log.trace("Initializing EISCAT daughterboard, slot index {}".format(self.slot_idx)) self.initialized = False self.ref_clock_freq = 10e6 - self.log.trace("Loading SPI interfaces...") - self._spi_ifaces = {key: create_spidev_iface(self._spi_nodes[key]) for key in self._spi_nodes} - self.log.info("Loaded SPI interfaces!") # Define some attributes so that PyLint stays quiet: self.radio_regs = None self.jesd_cores = None @@ -366,6 +380,7 @@ class EISCAT(DboardManagerBase): self.adc0 = None self.adc1 = None self.mmcm = None + self._spi_ifaces = None def init_device(self): """ @@ -373,11 +388,6 @@ class EISCAT(DboardManagerBase): This assumes that an appropriate overlay was loaded. """ - self.log.trace("Loading SPI interfaces...") - for chip, spi_dev_node in iteritems(self._spi_nodes): - self._spi_ifaces[chip] = create_spidev_iface(spi_dev_node) - self.log.info("Loaded SPI interfaces!") - self.log.debug("spidev device node map: {}".format(self._spi_nodes)) self.log.trace("Getting uio...") self.radio_regs = UIO(label="jesd204b-regs", read_only=False) # Create JESD cores. They will also test the UIO regs on initialization. @@ -393,6 +403,14 @@ class EISCAT(DboardManagerBase): self.radio_regs.poke32(ADC_RESET, 0x0000) # TODO put this somewhere else + # Load SPI devices. Note: They won't be usable until _init_power() was called. + self.log.trace("Loading SPI interfaces...") + self._spi_ifaces = { + key: self.spi_factories[key](self._spi_nodes[key]) + for key in self._spi_nodes + } + self.log.info("Loaded SPI interfaces!") + # Initialize Clocking self.mmcm = MMCM(self.radio_regs, self.log) self._init_power(self.radio_regs) diff --git a/mpm/python/usrp_mpm/dboard_manager/magnesium.py b/mpm/python/usrp_mpm/dboard_manager/magnesium.py index eb07864df..edb9a24db 100644 --- a/mpm/python/usrp_mpm/dboard_manager/magnesium.py +++ b/mpm/python/usrp_mpm/dboard_manager/magnesium.py @@ -33,6 +33,7 @@ def create_spidev_iface(dev_node): Create a regs iface from a spidev node """ SPI_SPEED_HZ = 1000000 + SPI_MODE = 3 SPI_ADDR_SHIFT = 8 SPI_DATA_SHIFT = 0 SPI_READ_FLAG = 1<<23 @@ -40,6 +41,7 @@ def create_spidev_iface(dev_node): return lib.spi.make_spidev_regs_iface( dev_node, SPI_SPEED_HZ, + SPI_MODE, SPI_ADDR_SHIFT, SPI_DATA_SHIFT, SPI_READ_FLAG, |