1 /* 2 * File: lms7_device.h 3 * Author: ignas 4 * 5 * Created on March 9, 2016, 12:54 PM 6 */ 7 8 #ifndef LMS7_DEVICE_H 9 #define LMS7_DEVICE_H 10 #include "LMS7002M.h" 11 #include "lime/LimeSuite.h" 12 #include <vector> 13 #include <string> 14 #include "Streamer.h" 15 #include "IConnection.h" 16 17 class RFE_Device; 18 19 namespace lime 20 { 21 class LIME_API LMS7_Device 22 { 23 public: 24 struct Range { 25 Range(double a = 0, double b = 0){ min = a, max = b; }; 26 double min; 27 double max; 28 }; 29 virtual ~LMS7_Device(); 30 LMS7_Device(LMS7_Device *obj = nullptr); 31 lime::IConnection* GetConnection(unsigned chan =0); 32 lime::FPGA* GetFPGA(); 33 virtual int Init(); 34 virtual int EnableChannel(bool dir_tx, unsigned chan, bool enabled); 35 int Reset(); 36 virtual unsigned GetNumChannels(const bool tx=false) const; 37 virtual int SetRate(double f_MHz, int oversample); 38 virtual int SetRate(bool tx, double f_MHz, unsigned oversample = 0); 39 virtual int SetRate(unsigned ch, double rxRate, double txRate, unsigned oversample = 0); 40 int SetFPGAInterfaceFreq(int interp = -1, int dec = -1, double txPhase = 999, double rxPhase = 999); 41 virtual double GetRate(bool tx, unsigned chan, double *rf_rate_Hz = NULL) const; 42 virtual Range GetRateRange(bool dir = false, unsigned chan = 0)const; 43 virtual std::vector<std::string> GetPathNames(bool dir_tx, unsigned chan = 0) const; 44 virtual int SetPath(bool tx,unsigned chan, unsigned path); 45 int GetPath(bool tx, unsigned chan) const; 46 virtual int SetFrequency(bool tx, unsigned chan, double f_Hz); 47 double GetFrequency(bool tx, unsigned chan) const; 48 virtual Range GetFrequencyRange(bool tx) const; 49 virtual Range GetRxPathBand(unsigned path, unsigned chan) const; 50 virtual Range GetTxPathBand(unsigned path, unsigned chan) const; 51 int SetLPF(bool tx, unsigned chan, bool en, double bandwidth=-1); 52 double GetLPFBW(bool tx,unsigned chan) const; 53 Range GetLPFRange(bool tx,unsigned chan) const; 54 int SetGFIRCoef(bool tx, unsigned chan, lms_gfir_t filt, const double* coef, unsigned count); 55 int GetGFIRCoef(bool tx, unsigned chan, lms_gfir_t filt, double* coef) const; 56 int SetGFIR(bool tx, unsigned chan, lms_gfir_t filt, bool enabled); 57 int SetGain(bool dir_tx, unsigned chan, double value, const std::string &name = ""); 58 double GetGain(bool dir_tx, unsigned chan, const std::string &name = "") const; 59 Range GetGainRange(bool dir_tx, unsigned chan, const std::string &name = "") const; 60 int SetTestSignal(bool dir_tx, unsigned chan, lms_testsig_t sig, int16_t dc_i = 0, int16_t dc_q = 0); 61 int GetTestSignal(bool dir_tx, unsigned chan) const; 62 int SetNCOFreq(bool tx, unsigned ch, int ind, double freq); 63 double GetNCOFreq(bool tx, unsigned ch, int ind) const; 64 int SetNCOPhase(bool tx, unsigned ch, int ind, double phase); 65 double GetNCOPhase(bool tx, unsigned ch, int ind) const; 66 virtual int Calibrate(bool dir_tx, unsigned chan, double bw, unsigned flags); 67 virtual std::vector<std::string> GetProgramModes() const; 68 virtual int Program(const std::string& mode, const char* data, size_t len, lime::IConnection::ProgrammingCallback callback) const; 69 double GetClockFreq(unsigned clk_id, int channel = -1) const; 70 virtual int SetClockFreq(unsigned clk_id, double freq, int channel = -1); 71 lms_dev_info_t* GetInfo(); 72 int Synchronize(bool toChip); 73 int SetLogCallback(void(*func)(const char* cstr, const unsigned int type)); 74 int EnableCache(bool enable); 75 double GetChipTemperature(int ind = -1) const; 76 int LoadConfig(const char *filename, int ind = -1); 77 int SaveConfig(const char *filename, int ind = -1) const; 78 int ReadLMSReg(uint16_t address, int ind = -1) const; 79 int WriteLMSReg(uint16_t address, uint16_t val, int ind = -1) const; 80 int ReadFPGAReg(uint16_t address) const; 81 int WriteFPGAReg(uint16_t address, uint16_t val) const; 82 uint16_t ReadParam(const struct LMS7Parameter& param, int channel = -1, bool forceReadFromChip = false) const; 83 int ReadParam(const std::string& param, int channel = -1, bool forceReadFromChip = false) const; 84 int WriteParam(const struct LMS7Parameter& param, uint16_t val, int channel = -1); 85 int WriteParam(const std::string& param, uint16_t val, int channel = -1); 86 int SetActiveChip(unsigned ind); 87 lime::LMS7002M* GetLMS(int index = -1) const; 88 int UploadWFM(const void **samples, uint8_t chCount, int sample_count, lime::StreamConfig::StreamDataFormat fmt) const; 89 static LMS7_Device* CreateDevice(const lime::ConnectionHandle& handle, LMS7_Device *obj = nullptr); 90 static std::vector<lime::ConnectionHandle> GetDeviceList(); 91 int ConfigureGFIR(bool tx, unsigned ch, bool enabled, double bandwidth); 92 93 lime::StreamChannel* SetupStream(const lime::StreamConfig &config); 94 int DestroyStream(lime::StreamChannel* streamID); 95 uint64_t GetHardwareTimestamp(void) const; 96 void SetHardwareTimestamp(const uint64_t now); 97 98 int MCU_AGCStart(uint32_t wantedRSSI); 99 int MCU_AGCStop(); 100 101 RFE_Device* GetLimeRFE() const; 102 void SetLimeRFE(RFE_Device* dev); 103 104 protected: 105 106 struct ChannelInfo 107 { 108 public: ChannelInfoChannelInfo109 ChannelInfo(): lpf_bw(0), gfir_bw(-1.0), cF_offset_nco(0), sample_rate(30e6), freq(-1.0){} 110 double lpf_bw; 111 double gfir_bw; 112 double cF_offset_nco; 113 double sample_rate; 114 double freq; 115 }; 116 lms_dev_info_t devInfo; 117 std::vector<ChannelInfo> tx_channels; 118 std::vector<ChannelInfo> rx_channels; 119 lime::IConnection* connection; 120 std::vector<lime::LMS7002M*> lms_list; 121 lime::LMS7002M* SelectChannel(unsigned chan) const; 122 unsigned lms_chip_id; 123 std::vector<lime::Streamer*> mStreamers; 124 lime::FPGA* fpga; 125 RFE_Device* limeRFE; 126 }; 127 128 } 129 130 #endif /* LMS7_DEVICE_H */ 131 132