Skip to content

Commit

Permalink
LimeSDR Windows build: upgraded to LimeSuite 17.06.0
Browse files Browse the repository at this point in the history
  • Loading branch information
f4exb committed Aug 10, 2017
1 parent 22900b8 commit f546af5
Show file tree
Hide file tree
Showing 12 changed files with 393 additions and 433 deletions.
4 changes: 3 additions & 1 deletion liblimesuite/liblimesuite.pro
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ INCLUDEPATH += $$LIBLIMESUITESRC/external/cpp-feather-ini-parser
SOURCES = $$LIBLIMESUITESRC/src/ADF4002/ADF4002.cpp\
$$LIBLIMESUITESRC/src/API/lms7_api.cpp\
$$LIBLIMESUITESRC/src/API/lms7_device.cpp\
$$LIBLIMESUITESRC/src/API/qLimeSDR.cpp\
src/BuiltinConnections.cpp\
$$LIBLIMESUITESRC/src/ConnectionRegistry/ConnectionHandle.cpp\
$$LIBLIMESUITESRC/src/ConnectionRegistry/ConnectionRegistry.cpp\
Expand All @@ -44,8 +45,8 @@ SOURCES = $$LIBLIMESUITESRC/src/ADF4002/ADF4002.cpp\
srcmw/ConnectionSTREAM/ConnectionSTREAMing.cpp\
srcmw/ConnectionSTREAM/ConnectionSTREAMEntry.cpp\
srcmw/Connection_uLimeSDR/Connection_uLimeSDR.cpp\
srcmw/Connection_uLimeSDR/Connection_uLimeSDREntry.cpp\
srcmw/Connection_uLimeSDR/Connection_uLimeSDRing.cpp\
srcmw/Connection_uLimeSDR/Connection_uLimeSDREntry.cpp\
$$LIBLIMESUITESRC/src/ConnectionXillybus/ConnectionXillybus.cpp\
$$LIBLIMESUITESRC/src/ConnectionXillybus/ConnectionXillybusEntry.cpp\
$$LIBLIMESUITESRC/src/ConnectionXillybus/ConnectionXillybusing.cpp\
Expand Down Expand Up @@ -77,6 +78,7 @@ SOURCES = $$LIBLIMESUITESRC/src/ADF4002/ADF4002.cpp\

HEADERS = $$LIBLIMESUITESRC/src/ADF4002/ADF4002.h\
$$LIBLIMESUITESRC/src/API/lms7_device.h\
$$LIBLIMESUITESRC/src/API/qLimeSDR.h\
$$LIBLIMESUITESRC/src/ConnectionRegistry/ConnectionHandle.h\
$$LIBLIMESUITESRC/src/ConnectionRegistry/ConnectionRegistry.h\
$$LIBLIMESUITESRC/src/ConnectionRegistry/IConnection.h\
Expand Down
141 changes: 80 additions & 61 deletions liblimesuite/srcmw/ConnectionSTREAM/ConnectionSTREAM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ using namespace std;

using namespace lime;

const uint8_t ConnectionSTREAM::streamBulkOutAddr = 0x01;
const uint8_t ConnectionSTREAM::streamBulkInAddr = 0x81;
const uint8_t ConnectionSTREAM::ctrlBulkOutAddr = 0x0F;
const uint8_t ConnectionSTREAM::ctrlBulkInAddr = 0x8F;

Expand Down Expand Up @@ -70,6 +68,9 @@ ConnectionSTREAM::ConnectionSTREAM(void *arg, const std::string &vidpid, const s
OutCtrlEndPt3 = nullptr;
InCtrlBulkEndPt = nullptr;
OutCtrlBulkEndPt = nullptr;
for (int i = 0; i < MAX_EP_CNT; i++)
InEndPt[i] = OutEndPt[i] = nullptr;

#else
dev_handle = nullptr;
ctx = (libusb_context *)arg;
Expand Down Expand Up @@ -178,15 +179,6 @@ double ConnectionSTREAM::DetectRefClk(void)
*/
ConnectionSTREAM::~ConnectionSTREAM()
{
for(auto i : mTxStreams)
ControlStream((size_t)i, false);
for(auto i : mRxStreams)
ControlStream((size_t)i, false);
for(auto i : mTxStreams)
CloseStream((size_t)i);
for(auto i : mRxStreams)
CloseStream((size_t)i);
UpdateThreads();
Close();
#ifndef __unix__
delete USBDevicePrimary;
Expand Down Expand Up @@ -230,22 +222,23 @@ int ConnectionSTREAM::Open(const std::string &vidpid, const std::string &serial,
OutCtrlEndPt3->Index = CTR_W_INDEX;
OutCtrlEndPt3->TimeOut = 3000;

for (int i=0; i<USBDevicePrimary->EndPointCount(); i++)
if(USBDevicePrimary->EndPoints[i]->Address == streamBulkOutAddr)
for (int i = 0; i < USBDevicePrimary->EndPointCount(); i++)
{
auto adr = USBDevicePrimary->EndPoints[i]->Address;
if (adr < ctrlBulkOutAddr)
{
OutEndPt = USBDevicePrimary->EndPoints[i];
long len = OutEndPt->MaxPktSize * 64;
OutEndPt->SetXferSize(len);
break;
OutEndPt[adr] = USBDevicePrimary->EndPoints[i];
long len = OutEndPt[adr]->MaxPktSize * 64;
OutEndPt[adr]->SetXferSize(len);
}
for (int i=0; i<USBDevicePrimary->EndPointCount(); i++)
if(USBDevicePrimary->EndPoints[i]->Address == streamBulkInAddr)
else if (adr < ctrlBulkInAddr)
{
InEndPt = USBDevicePrimary->EndPoints[i];
long len = InEndPt->MaxPktSize * 64;
InEndPt->SetXferSize(len);
break;
adr &= 0xF;
InEndPt[adr] = USBDevicePrimary->EndPoints[i];
long len = InEndPt[adr]->MaxPktSize * 64;
InEndPt[adr]->SetXferSize(len);
}
}

InCtrlBulkEndPt = nullptr;
for (int i=0; i<USBDevicePrimary->EndPointCount(); i++)
Expand Down Expand Up @@ -356,21 +349,21 @@ int ConnectionSTREAM::Open(const std::string &vidpid, const std::string &serial,
void ConnectionSTREAM::Close()
{
#ifndef __unix__
USBDevicePrimary->Close();
InEndPt = nullptr;
OutEndPt = nullptr;
InCtrlBulkEndPt = nullptr;
OutCtrlBulkEndPt = nullptr;
if (InCtrlEndPt3)
{
delete InCtrlEndPt3;
InCtrlEndPt3 = nullptr;
}
if (OutCtrlEndPt3)
{
delete OutCtrlEndPt3;
OutCtrlEndPt3 = nullptr;
}
USBDevicePrimary->Close();
for (int i = 0; i < MAX_EP_CNT; i++)
InEndPt[i] = OutEndPt[i] = nullptr;
InCtrlBulkEndPt = nullptr;
OutCtrlBulkEndPt = nullptr;
if (InCtrlEndPt3)
{
delete InCtrlEndPt3;
InCtrlEndPt3 = nullptr;
}
if (OutCtrlEndPt3)
{
delete OutCtrlEndPt3;
OutCtrlEndPt3 = nullptr;
}
#else
if(dev_handle != 0)
{
Expand Down Expand Up @@ -532,9 +525,10 @@ void callback_libusbtransfer(libusb_transfer *trans)
@brief Starts asynchronous data reading from board
@param *buffer buffer where to store received data
@param length number of bytes to read
@param streamBulkInAddr endpoint index?
@return handle of transfer context
*/
int ConnectionSTREAM::BeginDataReading(char *buffer, uint32_t length)
int ConnectionSTREAM::BeginDataReading(char *buffer, uint32_t length, const uint8_t streamBulkInAddr)
{
int i = 0;
bool contextFound = false;
Expand All @@ -554,8 +548,11 @@ int ConnectionSTREAM::BeginDataReading(char *buffer, uint32_t length)
}
contexts[i].used = true;
#ifndef __unix__
if(InEndPt)
contexts[i].context = InEndPt->BeginDataXfer((unsigned char*)buffer, length, contexts[i].inOvLap);
if (InEndPt[streamBulkInAddr & 0xF])
{
contexts[i].EndPt = InEndPt[streamBulkInAddr & 0xF];
contexts[i].context = contexts[i].EndPt->BeginDataXfer((unsigned char*)buffer, length, contexts[i].inOvLap);
}
return i;
#else
unsigned int Timeout = 500;
Expand Down Expand Up @@ -587,8 +584,7 @@ int ConnectionSTREAM::WaitForReading(int contextHandle, unsigned int timeout_ms)
{
#ifndef __unix__
int status = 0;
if(InEndPt)
status = InEndPt->WaitForXfer(contexts[contextHandle].inOvLap, timeout_ms);
status = contexts[contextHandle].EndPt->WaitForXfer(contexts[contextHandle].inOvLap, timeout_ms);
return status;
#else
auto t1 = chrono::high_resolution_clock::now();
Expand Down Expand Up @@ -622,8 +618,7 @@ int ConnectionSTREAM::FinishDataReading(char *buffer, uint32_t length, int conte
#ifndef __unix__
int status = 0;
long len = length;
if(InEndPt)
status = InEndPt->FinishDataXfer((unsigned char*)buffer, len, contexts[contextHandle].inOvLap, contexts[contextHandle].context);
status = contexts[contextHandle].EndPt->FinishDataXfer((unsigned char*)buffer, len, contexts[contextHandle].inOvLap, contexts[contextHandle].context);
contexts[contextHandle].used = false;
contexts[contextHandle].reset();
return len;
Expand All @@ -641,14 +636,16 @@ int ConnectionSTREAM::FinishDataReading(char *buffer, uint32_t length, int conte
/**
@brief Aborts reading operations
*/
void ConnectionSTREAM::AbortReading()
void ConnectionSTREAM::AbortReading(int ep)
{
#ifndef __unix__
InEndPt->Abort();
for (int i = 0; i < MAX_EP_CNT; i++)
if (InEndPt[i] && InEndPt[i]->Address == ep)
InEndPt[i]->Abort();
#else
for(int i=0; i<USB_MAX_CONTEXTS; ++i)
{
if(contexts[i].used)
if(contexts[i].used && contexts[i].transfer->endpoint == ep)
libusb_cancel_transfer( contexts[i].transfer );
}
#endif
Expand All @@ -658,9 +655,10 @@ void ConnectionSTREAM::AbortReading()
@brief Starts asynchronous data Sending to board
@param *buffer buffer to send
@param length number of bytes to send
@param streamBulkOutAddr endpoint index?
@return handle of transfer context
*/
int ConnectionSTREAM::BeginDataSending(const char *buffer, uint32_t length)
int ConnectionSTREAM::BeginDataSending(const char *buffer, uint32_t length, const uint8_t streamBulkOutAddr)
{
int i = 0;
//find not used context
Expand All @@ -677,8 +675,11 @@ int ConnectionSTREAM::BeginDataSending(const char *buffer, uint32_t length)
return -1;
contextsToSend[i].used = true;
#ifndef __unix__
if(OutEndPt)
contextsToSend[i].context = OutEndPt->BeginDataXfer((unsigned char*)buffer, length, contextsToSend[i].inOvLap);
if (OutEndPt[streamBulkOutAddr])
{
contextsToSend[i].EndPt = OutEndPt[streamBulkOutAddr];
contextsToSend[i].context = contextsToSend[i].EndPt->BeginDataXfer((unsigned char*)buffer, length, contextsToSend[i].inOvLap);
}
return i;
#else
unsigned int Timeout = 500;
Expand Down Expand Up @@ -708,12 +709,11 @@ int ConnectionSTREAM::WaitForSending(int contextHandle, unsigned int timeout_ms)
{
if( contextsToSend[contextHandle].used == true )
{
#ifndef __unix__
# ifndef __unix__
int status = 0;
if(OutEndPt)
status = OutEndPt->WaitForXfer(contextsToSend[contextHandle].inOvLap, timeout_ms);
status = contextsToSend[contextHandle].EndPt->WaitForXfer(contextsToSend[contextHandle].inOvLap, timeout_ms);
return status;
#else
# else
auto t1 = chrono::high_resolution_clock::now();
auto t2 = chrono::high_resolution_clock::now();

Expand All @@ -725,7 +725,7 @@ int ConnectionSTREAM::WaitForSending(int contextHandle, unsigned int timeout_ms)
t2 = chrono::high_resolution_clock::now();
}
return contextsToSend[contextHandle].done == true;
#endif
# endif
}
else
return 0;
Expand All @@ -744,8 +744,7 @@ int ConnectionSTREAM::FinishDataSending(const char *buffer, uint32_t length, int
{
#ifndef __unix__
long len = length;
if(OutEndPt)
OutEndPt->FinishDataXfer((unsigned char*)buffer, len, contextsToSend[contextHandle].inOvLap, contextsToSend[contextHandle].context);
contextsToSend[contextHandle].EndPt->FinishDataXfer((unsigned char*)buffer, len, contextsToSend[contextHandle].inOvLap, contextsToSend[contextHandle].context);
contextsToSend[contextHandle].used = false;
contextsToSend[contextHandle].reset();
return len;
Expand All @@ -763,19 +762,39 @@ int ConnectionSTREAM::FinishDataSending(const char *buffer, uint32_t length, int
/**
@brief Aborts sending operations
*/
void ConnectionSTREAM::AbortSending()
void ConnectionSTREAM::AbortSending(int ep)
{
#ifndef __unix__
OutEndPt->Abort();
for (int i = 0; i < MAX_EP_CNT; i++)
if (OutEndPt[i] && OutEndPt[i]->Address == ep)
OutEndPt[i]->Abort();
#else
for (int i = 0; i<USB_MAX_CONTEXTS; ++i)
{
if(contextsToSend[i].used)
if(contextsToSend[i].used && contextsToSend[i].transfer->endpoint == ep)
libusb_cancel_transfer(contextsToSend[i].transfer);
}
#endif
}

int ConnectionSTREAM::SendData(const char* buffer, int length, int epIndex, int timeout)
{
const unsigned char ep = 0x01;
int context = BeginDataSending((char*)buffer, length, ep);
if (WaitForSending(context, timeout)==false)
AbortSending(ep);
return FinishDataSending((char*)buffer, length , context);
}

int ConnectionSTREAM::ReceiveData(char* buffer, int length, int epIndex, int timeout)
{
const unsigned char ep = 0x81;
int context = BeginDataReading(buffer, length, ep);
if (WaitForReading(context, timeout) == false)
AbortReading(ep);
return FinishDataReading(buffer, length, context);
}

int ConnectionSTREAM::ProgramWrite(const char *buffer, const size_t length, const int programmingMode, const int device, ProgrammingCallback callback)
{
if (device == LMS64CProtocol::FX3 && programmingMode == 1)
Expand Down
27 changes: 14 additions & 13 deletions liblimesuite/srcmw/ConnectionSTREAM/ConnectionSTREAM.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class USBTransferContext
memset(inOvLap, 0, sizeof(OVERLAPPED));
inOvLap->hEvent = CreateEvent(NULL, false, false, NULL);
context = NULL;
EndPt = nullptr;
#else
transfer = libusb_alloc_transfer(0);
bytesXfered = 0;
Expand Down Expand Up @@ -80,6 +81,7 @@ class USBTransferContext
static int idCounter;
#ifndef __unix__
PUCHAR context;
CCyUSBEndPoint* EndPt;
OVERLAPPED* inOvLap;
#else
libusb_transfer* transfer;
Expand All @@ -106,27 +108,27 @@ class ConnectionSTREAM : public ILimeSDRStreaming
virtual int Write(const unsigned char* buffer, int length, int timeout_ms = 100) override;
virtual int Read(unsigned char* buffer, int length, int timeout_ms = 100) override;

virtual int UploadWFM(const void* const* samples, uint8_t chCount, size_t sample_count, StreamConfig::StreamDataFormat format) override;

//hooks to update FPGA plls when baseband interface data rate is changed
virtual int UpdateExternalDataRate(const size_t channel, const double txRate, const double rxRate) override;
virtual int UpdateExternalDataRate(const size_t channel, const double txRate, const double rxRate, const double txPhase, const double rxPhase) override;
virtual int ProgramWrite(const char *buffer, const size_t length, const int programmingMode, const int device, ProgrammingCallback callback) override;
int ProgramUpdate(const bool download, ProgrammingCallback callback);
int ReadRawStreamData(char* buffer, unsigned length, int timeout_ms = 100)override;
int ReadRawStreamData(char* buffer, unsigned length, int epIndex, int timeout_ms = 100)override;
protected:
virtual void ReceivePacketsLoop(const ThreadData args) override;
virtual void TransmitPacketsLoop(const ThreadData args) override;
virtual void ReceivePacketsLoop(Streamer* args) override;
virtual void TransmitPacketsLoop(Streamer* args) override;
int SendData(const char* buffer, int length, int epIndex = 0, int timeout = 100)override;
int ReceiveData(char* buffer, int length, int epIndex = 0, int timeout = 100)override;

virtual int BeginDataReading(char* buffer, uint32_t length);
virtual int BeginDataReading(char* buffer, uint32_t length, const uint8_t streamBulkInAddr = 0x81);
virtual int WaitForReading(int contextHandle, unsigned int timeout_ms);
virtual int FinishDataReading(char* buffer, uint32_t length, int contextHandle);
virtual void AbortReading();
virtual void AbortReading(int ep);

virtual int BeginDataSending(const char* buffer, uint32_t length);
virtual int BeginDataSending(const char* buffer, uint32_t length, const uint8_t streamBulkOutAddr = 0x01);
virtual int WaitForSending(int contextHandle, uint32_t timeout_ms);
virtual int FinishDataSending(const char* buffer, uint32_t length, int contextHandle);
virtual void AbortSending();
virtual void AbortSending(int ep);

int ResetStreamBuffers() override;
eConnectionType GetType(void) {return USB_PORT;}
Expand All @@ -139,14 +141,15 @@ class ConnectionSTREAM : public ILimeSDRStreaming
bool isConnected;

#ifndef __unix__
static const int MAX_EP_CNT = 16;
CCyFX3Device* USBDevicePrimary;
//control endpoints
CCyControlEndPoint* InCtrlEndPt3;
CCyControlEndPoint* OutCtrlEndPt3;

//end points for samples reading and writing
CCyUSBEndPoint* InEndPt;
CCyUSBEndPoint* OutEndPt;
CCyUSBEndPoint* InEndPt[MAX_EP_CNT];
CCyUSBEndPoint* OutEndPt[MAX_EP_CNT];

CCyUSBEndPoint* InCtrlBulkEndPt;
CCyUSBEndPoint* OutCtrlBulkEndPt;
Expand All @@ -157,8 +160,6 @@ class ConnectionSTREAM : public ILimeSDRStreaming
int fx3_usbboot_download(unsigned char *buf, int len);
int ram_write(unsigned char *buf, unsigned int ramAddress, int len);
#endif
static const uint8_t streamBulkOutAddr;
static const uint8_t streamBulkInAddr;
static const uint8_t ctrlBulkOutAddr;
static const uint8_t ctrlBulkInAddr;
static const std::set<uint8_t> commandsToBulkCtrlHw1;
Expand Down
Loading

0 comments on commit f546af5

Please sign in to comment.