diff options
| -rw-r--r-- | host/lib/usrp/common/lmk04828.cpp | 91 | ||||
| -rw-r--r-- | host/lib/usrp/common/lmk04828.hpp | 27 | ||||
| -rw-r--r-- | mpm/dboards/magnesium_manager.cpp | 2 | ||||
| -rw-r--r-- | mpm/include/mpm/lmk04828/lmk04828_spi_iface.hpp | 2 | ||||
| -rw-r--r-- | mpm/python/lmk02848_py.hpp | 13 | ||||
| -rw-r--r-- | mpm/python/pyusrp_periphs.cpp | 1 | 
6 files changed, 85 insertions, 51 deletions
| diff --git a/host/lib/usrp/common/lmk04828.cpp b/host/lib/usrp/common/lmk04828.cpp index fd681291f..6a0f5fd14 100644 --- a/host/lib/usrp/common/lmk04828.cpp +++ b/host/lib/usrp/common/lmk04828.cpp @@ -18,64 +18,71 @@  #include "lmk04828.hpp"  #include "lmk04828_regs.hpp"  #include "uhd/exception.hpp" +#include <iostream>  using namespace uhd; -static const uint32_t LMK04828_ID_DEVICE_TYPE = 6; -static const uint32_t LMK04828_ID_PROD_LSB    = 91; -static const uint32_t LMK04828_ID_PROD_MSB    = 208; -static const uint32_t LMK04828_ID_MASKREV     = 32; -class lmk04828_impl : public lmk04828_iface +lmk04828_iface::lmk04828_iface(write_fn_t write_fn, read_fn_t read_fn) : _write_fn(write_fn), _read_fn(read_fn)  { -public: -    lmk04828_impl(write_fn_t write_fn, read_fn_t read_fn) : _write_fn(write_fn), _read_fn(read_fn) -    { -    } +} -    ~lmk04828_impl() -    { +void lmk04828_iface::verify_chip_id() +{ +    // Check ID Device Type, ID Prod, and ID Maskrev registers +    uint8_t id_device_type = _read_fn(3); +    // assert(id_device_type == 6); +    if (id_device_type != 6){ +        printf("id_device_type is not 6!");      } +} -    void verify_chip_id() -    { -        // Check ID Device Type, ID Prod, and ID Maskrev registers -        uint8_t id_device_type = _read_fn(3); +uint8_t lmk04828_iface::get_chip_id(){ +    uint8_t id_device_type = _read_fn(3); +    return id_device_type; +} -        // assert(id_device_type == 6); -        if (id_device_type != 6){ -            printf("id_device_type is not 6!"); -        } -    } +void lmk04828_iface::init() +{ +    // Configure the LMK to start producing clocks +// TODO: Convert to use ic_reg_map fields once values are finalized/working +    std::vector<uint32_t> write_addrs = { +        0x000000,0x000000,0x000002,0x000149,0x00014A,0x000100,0x000101,0x000103,0x000104,0x000105,0x000106,0x000107,0x000120,0x000121,0x000123,0x000124,0x000125,0x000126,0x000127,0x000130,0x000131,0x000133,0x000134,0x000135,0x000136,0x000137,0x000128,0x000129,0x00012B,0x00012C,0x00012D,0x00012E,0x00012F,0x000108,0x000109,0x00010B,0x00010C,0x00010D,0x00010E,0x00010F,0x000118,0x000119,0x00011B,0x00011C,0x00011D,0x00011E,0x00011F,0x000138,0x00013F,0x000140,0x000144,0x000146,0x000147,0x00014B,0x00014C,0x000153,0x000154,0x000155,0x000156,0x000157,0x000158,0x000159,0x00015A,0x00015B,0x00015E,0x000160,0x000161,0x000162,0x000163,0x000164,0x000165,0x000166,0x000167,0x000168,0x00016E,0x000173,0x000169,0x00016C,0x00016D}; -    uint8_t get_chip_id(){ -        uint8_t id_device_type = _read_fn(3); -        return id_device_type; -    } +    std::vector<uint32_t> write_data = { +        0x000090,0x000010,0x000000,0x000040,0x000033,0x000078,0x000055,0x000000,0x000020,0x000000,0x0000F1,0x000055,0x000078,0x000055,0x000000,0x000020,0x000000,0x0000F1,0x000055,0x000078,0x000055,0x000000,0x000020,0x000000,0x0000F1,0x000005,0x000078,0x000055,0x000000,0x000000,0x000000,0x0000F0,0x000050,0x00007E,0x000055,0x000000,0x000000,0x000000,0x0000F0,0x000055,0x000078,0x000055,0x000000,0x000020,0x000000,0x0000F1,0x000000,0x000030,0x000009,0x000000,0x000000,0x000010,0x00001A,0x00000D,0x0000F6,0x000000,0x000001,0x000000,0x00000A,0x000000,0x000001,0x000000,0x00007D,0x0000DB,0x000000,0x000000,0x000004,0x0000A0,0x000000,0x000000,0x000019,0x000000,0x000000,0x000019,0x00006B,0x000000,0x000051,0x000000,0x000000}; -    void init() -    { -        // Configure the LMK to start producing clocks -        throw new uhd::not_implemented_error("Not needed for MPM bringup"); +    std::vector<uint32_t> writes {}; +    for (size_t index = 0; index < write_addrs.size(); index++) { +        writes.push_back((write_addrs[index] << 11) | write_data[index]);       } -     -    void send_sysref_pulse() -    { -        // Produce a single sysref pulse -        throw new uhd::not_implemented_error("Not needed for MPM bringup"); + +    std::cout << "LMK Initialization writes" << std::endl; +    for (uint32_t reg : writes) { +        std::cout << std::hex << reg << " ";       } +    std::cout << std::endl; -private: -     -    lmk04828_regs_t _regs; -     -    write_fn_t _write_fn; -    read_fn_t _read_fn; -}; +    _write_fn(writes); +} -lmk04828_iface::sptr lmk04828_iface::make(write_fn_t write_fn, read_fn_t read_fn) +void lmk04828_iface::send_sysref_pulse()  { -    return sptr(new lmk04828_impl(write_fn, read_fn)); +    // Configure the LMK to issue a single SysRef pulse each time SYNC is asserted +      +    // TODO: Convert to use ic reg map fields once functional +    // Addr 0x139 Value 0x2 +    // Addr 0x144 Value 0xFF +    // Addr 0x143 Value 0x52 + +    std::vector<uint32_t> writes = { +        (0x139 << 11) | 0x2, +        (0x144 << 11) | 0xFF, +        (0x143 << 11) | 0x52 +    }; + +    _write_fn(writes);  } + diff --git a/host/lib/usrp/common/lmk04828.hpp b/host/lib/usrp/common/lmk04828.hpp index ff063379c..80a7a8917 100644 --- a/host/lib/usrp/common/lmk04828.hpp +++ b/host/lib/usrp/common/lmk04828.hpp @@ -1,5 +1,5 @@  // -// Copyright 2015 Ettus Research LLC +// Copyright 2017 Ettus Research LLC  //  // This program is free software: you can redistribute it and/or modify  // it under the terms of the GNU General Public License as published by @@ -23,6 +23,11 @@  #include <vector>  #include <stdint.h> +static const uint32_t LMK04828_ID_DEVICE_TYPE = 6; +static const uint32_t LMK04828_ID_PROD_LSB    = 91; +static const uint32_t LMK04828_ID_PROD_MSB    = 208; +static const uint32_t LMK04828_ID_MASKREV     = 32; +  class lmk04828_iface  {  public: @@ -30,16 +35,24 @@ public:      typedef boost::function<void(std::vector<uint32_t>)> write_fn_t;       typedef boost::function<uint8_t(uint32_t)> read_fn_t; -    static sptr make(write_fn_t write_fn, read_fn_t read_fn); +    //static sptr (write_fn_t write_fn, read_fn_t read_fn); +    lmk04828_iface(write_fn_t, read_fn_t); + +    ~lmk04828_iface() {} -    virtual ~lmk04828_iface() {} +    void verify_chip_id(); -    virtual void verify_chip_id() = 0; +    uint8_t get_chip_id(); -    virtual uint8_t get_chip_id() = 0; +    void init(); -    virtual void init() = 0; +    void send_sysref_pulse(); -    virtual void send_sysref_pulse() = 0; +private: +    // use IC Reg Map once values stabilize +//    lmk04828_regs_t _regs; +     +    write_fn_t _write_fn; +    read_fn_t _read_fn;  };  #endif diff --git a/mpm/dboards/magnesium_manager.cpp b/mpm/dboards/magnesium_manager.cpp index 8639a7ff1..adbac5918 100644 --- a/mpm/dboards/magnesium_manager.cpp +++ b/mpm/dboards/magnesium_manager.cpp @@ -26,7 +26,7 @@ magnesium_periph_manager::magnesium_periph_manager(      ): _spi_mutex(std::make_shared<std::mutex>())  {      _clock_spi = lmk04828_spi_iface::make(mpm::spi::spidev_iface::make(lmk_spidev)); -    _clock_ctrl = lmk04828_iface::make(_clock_spi->get_write_fn(), _clock_spi->get_read_fn()); +    _clock_ctrl = boost::make_shared<lmk04828_iface>(lmk04828_iface(_clock_spi->get_write_fn(), _clock_spi->get_read_fn()));      _mykonos_spi = mpm::spi::spidev_iface::make(mykonos_spidev);      _mykonos_ctrl = ad937x_ctrl::make(_spi_mutex, _mykonos_spi, mpm::ad937x::gpio::gain_pins_t());  }; diff --git a/mpm/include/mpm/lmk04828/lmk04828_spi_iface.hpp b/mpm/include/mpm/lmk04828/lmk04828_spi_iface.hpp index 2743977dc..af068c9e0 100644 --- a/mpm/include/mpm/lmk04828/lmk04828_spi_iface.hpp +++ b/mpm/include/mpm/lmk04828/lmk04828_spi_iface.hpp @@ -32,11 +32,11 @@ private:  void export_lmk(){      LIBMPM_BOOST_PREAMBLE("lmk04828")      bp::class_<lmk04828_iface, boost::shared_ptr<lmk04828_iface>, boost::noncopyable >("lmk04828_iface", bp::no_init) -        .def("make", &lmk04828_iface::make)          .def("verify_chip_id", &lmk04828_iface::verify_chip_id)          .def("get_chip_id", &lmk04828_iface::get_chip_id)          .def("init", &lmk04828_iface::init)          .def("send_sysref_pulse", &lmk04828_iface::send_sysref_pulse)     ;  } +//        .def("make", &lmk04828_iface::make)  #endif diff --git a/mpm/python/lmk02848_py.hpp b/mpm/python/lmk02848_py.hpp new file mode 100644 index 000000000..5b0b89a1c --- /dev/null +++ b/mpm/python/lmk02848_py.hpp @@ -0,0 +1,13 @@ +#include "../../host/lib/usrp/common/lmk04828.hpp" + +#ifdef LIBMPM_PYTHON +void export_(){ +    LIBMPM_BOOST_PREAMBLE("lmk04828") +    bp::class_<lmk04828_iface>("lmk04828", bp::init<lmk04828_iface::write_fn_t, lmk04828_iface::read_fn_t>()) +        .def("verify_chip_id", &lmk04828_iface::verify_chip_id) +        .def("get_chip_id", &lmk04828_iface::get_chip_id) +        .def("init", &lmk04828_iface::init) +        .def("send_sysref_pulse", &lmk04828_iface::send_sysref_pulse) +    ; +} +#endif diff --git a/mpm/python/pyusrp_periphs.cpp b/mpm/python/pyusrp_periphs.cpp index 9f6378763..77d358eca 100644 --- a/mpm/python/pyusrp_periphs.cpp +++ b/mpm/python/pyusrp_periphs.cpp @@ -31,6 +31,7 @@  #include "mpm/ad937x/ad937x_ctrl.hpp"  #include "mpm/lmk04828//lmk04828_spi_iface.hpp"  #include "mpm/dboards/magnesium_manager.hpp" +#include "lmk02848_py.hpp"  //#include "lib_periphs.hpp"  //#include "dboards.hpp"  #include <boost/noncopyable.hpp> | 
