From fc8b23d3a8b024ac58e00c8ea58222ff04a908b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Petkevi=C4=8Dius?= Date: Mon, 12 Feb 2024 14:01:18 +0200 Subject: [PATCH 01/22] Successfully compile a Windows build --- .gitignore | 3 ++ src/CMakeLists.txt | 2 +- src/Logger.cpp | 4 ++- src/StreamComposite.cpp | 9 +++--- src/cli/common.h | 1 - src/cli/limeConfig.cpp | 3 +- src/cli/limeDevice.cpp | 1 + src/cli/limeFLASH.cpp | 1 + src/cli/limeSPI.cpp | 3 +- src/cli/limeTRX.cpp | 1 + src/comms/PCIe/LitePCIe.h | 8 ++++-- src/comms/USB/FT601/CMakeLists.txt | 4 +-- src/comms/USB/FT601/FT601.cpp | 28 ++++++++++++------- .../USB/FT601/USBTransferContext_FT601.h | 3 +- src/comms/USB/FX3/CMakeLists.txt | 2 +- src/comms/USB/FX3/USBTransferContext_FX3.h | 1 - src/comms/USB/USBEntry.h | 1 + src/comms/USB/USBGeneric.cpp | 6 +++- src/comms/USB/USBTransferContext.h | 6 ++++ src/examples/CMakeLists.txt | 4 ++- src/include/limesuite/SDRDevice.h | 4 +-- src/lms7002m/LMS7002M.cpp | 2 +- src/memory/MemoryPool.cpp | 8 +++++- src/tests/CMakeLists.txt | 2 +- src/threadHelper/threadHelper.cpp | 2 +- 25 files changed, 74 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index 93ec35fb5..3f35e043c 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,6 @@ docs/LMS_API_Documentation/* /debian/limesuite-images20.10.* !/debian/limesuite-images20.10.*.in /debian/debhelper-build-stamp +/.vs +/out/ +/CMakeSettings.json diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index aa3e17023..14a42b03c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -126,7 +126,7 @@ if (ENABLE_LIBRARY) target_compile_definitions(${MAIN_LIBRARY_NAME} PUBLIC "LIME_DLL") endif() - if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND ENABLE_CODE_COVERAGE) + if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND ENABLE_CODE_COVERAGE AND (NOT MSVC)) include(CodeCoverage) append_coverage_compiler_flags_to_target(${MAIN_LIBRARY_NAME}) endif() diff --git a/src/Logger.cpp b/src/Logger.cpp index a0e4392e1..0b1bdfe86 100644 --- a/src/Logger.cpp +++ b/src/Logger.cpp @@ -34,8 +34,10 @@ static const char* errToStr(const int errnum) NULL); return buff; #else + #ifndef __unix__ + strerror_s(buff, sizeof(buff), errnum); + #elif !(defined(__GLIBC__) && defined(__GNU_SOURCE)) //http://linux.die.net/man/3/strerror_r - #if !(defined(__GLIBC__) && defined(__GNU_SOURCE)) auto result = strerror_r(errnum, buff, sizeof(buff)); (void)result; #else diff --git a/src/StreamComposite.cpp b/src/StreamComposite.cpp index ea63b8807..81e0c8fe9 100644 --- a/src/StreamComposite.cpp +++ b/src/StreamComposite.cpp @@ -100,12 +100,13 @@ template int StreamComposite::StreamTx(const T* const* samples, uint32_ } // force instantiate functions with these types -template int StreamComposite::StreamRx(lime::complex16_t** samples, uint32_t count, SDRDevice::StreamMeta* meta); -template int StreamComposite::StreamRx( +template LIME_API int StreamComposite::StreamRx( + lime::complex16_t** samples, uint32_t count, SDRDevice::StreamMeta* meta); +template LIME_API int StreamComposite::StreamRx( lime::complex32f_t** samples, uint32_t count, SDRDevice::StreamMeta* meta); -template int StreamComposite::StreamTx( +template LIME_API int StreamComposite::StreamTx( const lime::complex16_t* const* samples, uint32_t count, const SDRDevice::StreamMeta* meta); -template int StreamComposite::StreamTx( +template LIME_API int StreamComposite::StreamTx( const lime::complex32f_t* const* samples, uint32_t count, const SDRDevice::StreamMeta* meta); } // namespace lime diff --git a/src/cli/common.h b/src/cli/common.h index aa60eec25..8577b676a 100644 --- a/src/cli/common.h +++ b/src/cli/common.h @@ -10,7 +10,6 @@ #include #include #include -#include #include "limesuite/DeviceHandle.h" #include "limesuite/DeviceRegistry.h" diff --git a/src/cli/limeConfig.cpp b/src/cli/limeConfig.cpp index 48f0931c5..5e88fae3f 100644 --- a/src/cli/limeConfig.cpp +++ b/src/cli/limeConfig.cpp @@ -1,8 +1,9 @@ #include "cli/common.h" #include "limesuite/LMS7002M.h" -#include +#include #include +#include using namespace std; using namespace lime; diff --git a/src/cli/limeDevice.cpp b/src/cli/limeDevice.cpp index 5efd9c667..ee66262bd 100644 --- a/src/cli/limeDevice.cpp +++ b/src/cli/limeDevice.cpp @@ -1,4 +1,5 @@ #include "cli/common.h" +#include using namespace std; using namespace lime; diff --git a/src/cli/limeFLASH.cpp b/src/cli/limeFLASH.cpp index a782b1a15..bd551353e 100644 --- a/src/cli/limeFLASH.cpp +++ b/src/cli/limeFLASH.cpp @@ -1,4 +1,5 @@ #include "cli/common.h" +#include using namespace std; using namespace lime; diff --git a/src/cli/limeSPI.cpp b/src/cli/limeSPI.cpp index 85c8bf978..ef06d75da 100644 --- a/src/cli/limeSPI.cpp +++ b/src/cli/limeSPI.cpp @@ -1,7 +1,8 @@ #include "cli/common.h" -#include +#include #include +#include using namespace std; using namespace lime; diff --git a/src/cli/limeTRX.cpp b/src/cli/limeTRX.cpp index c91f723e4..563b6653f 100644 --- a/src/cli/limeTRX.cpp +++ b/src/cli/limeTRX.cpp @@ -10,6 +10,7 @@ #include "kissFFT/kiss_fft.h" #include #include +#include // #define USE_GNU_PLOT 1 #ifdef USE_GNU_PLOT diff --git a/src/comms/PCIe/LitePCIe.h b/src/comms/PCIe/LitePCIe.h index 77b9746ad..ae95d62df 100644 --- a/src/comms/PCIe/LitePCIe.h +++ b/src/comms/PCIe/LitePCIe.h @@ -4,12 +4,16 @@ #include #include -#include "software/kernel/litepcie.h" +#include "limesuite/config.h" + +#ifdef __unix__ + #include "software/kernel/litepcie.h" +#endif // __unix__ namespace lime { /** @brief Class for communicating with a PCIe device. */ -class LitePCIe +class LIME_API LitePCIe { public: static std::vector GetDevicesWithPattern(const std::string& regex); diff --git a/src/comms/USB/FT601/CMakeLists.txt b/src/comms/USB/FT601/CMakeLists.txt index f01e314bb..4df7d31df 100644 --- a/src/comms/USB/FT601/CMakeLists.txt +++ b/src/comms/USB/FT601/CMakeLists.txt @@ -4,9 +4,9 @@ if(WIN32) #library directory based on x64 vs x86 if (CMAKE_SIZEOF_VOID_P EQUAL 8) - set(FTD3XX_LIB_DIR ${USB_INCLUDE_DIRS}/x64) + set(FTD3XX_LIB_DIR ${FTDI_INCLUDE_DIRS}/x64) else() - set(FTD3XX_LIB_DIR ${USB_INCLUDE_DIRS}/Win32) + set(FTD3XX_LIB_DIR ${FTDI_INCLUDE_DIRS}/Win32) endif() #default is to use static libs diff --git a/src/comms/USB/FT601/FT601.cpp b/src/comms/USB/FT601/FT601.cpp index 26b381b65..0a18a0b1a 100644 --- a/src/comms/USB/FT601/FT601.cpp +++ b/src/comms/USB/FT601/FT601.cpp @@ -149,18 +149,21 @@ int FT601::BeginDataXfer(uint8_t* buffer, uint32_t length, uint8_t endPointAddr) ULONG ulActual; FT_STATUS ftStatus = FT_OK; - FT_InitializeOverlapped(mFTHandle, &contexts[index].inOvLap); + + USBTransferContext_FT601* context = &dynamic_cast(contexts)[index]; + + FT_InitializeOverlapped(mFTHandle, context->inOvLap); if (endPointAddr == STREAM_BULK_READ_ADDRESS) { - ftStatus = FT_ReadPipe(mFTHandle, STREAM_BULK_READ_ADDRESS, buffer, length, &ulActual, &contexts[index].inOvLap); + ftStatus = FT_ReadPipe(mFTHandle, STREAM_BULK_READ_ADDRESS, buffer, length, &ulActual, context->inOvLap); } else { - ftStatus = FT_WritePipe(mFTHandle, STREAM_BULK_WRITE_ADDRESS, buffer, length, &ulActual, &contexts[index].inOvLap); + ftStatus = FT_WritePipe(mFTHandle, STREAM_BULK_WRITE_ADDRESS, buffer, length, &ulActual, context->inOvLap); } - contexts[index].endPointAddr = endPointAddr; + context->endPointAddr = endPointAddr; if (ftStatus != FT_IO_PENDING) { @@ -174,9 +177,11 @@ int FT601::BeginDataXfer(uint8_t* buffer, uint32_t length, uint8_t endPointAddr) bool FT601::WaitForXfer(int contextHandle, uint32_t timeout_ms) { + if (contextHandle >= 0 && contexts[contextHandle].used == true) { - DWORD dwRet = WaitForSingleObject(contexts[contextHandle].inOvLap.hEvent, timeout_ms); + USBTransferContext_FT601* context = &dynamic_cast(contexts)[contextHandle]; + DWORD dwRet = WaitForSingleObject(context->inOvLap->hEvent, timeout_ms); if (dwRet == WAIT_OBJECT_0) { @@ -193,8 +198,9 @@ int FT601::FinishDataXfer(uint8_t* buffer, uint32_t length, int contextHandle) { ULONG ulActualBytesTransferred; FT_STATUS ftStatus = FT_OK; + USBTransferContext_FT601* context = &dynamic_cast(contexts)[contextHandle]; - ftStatus = FT_GetOverlappedResult(mFTHandle, &contexts[contextHandle].inOvLap, &ulActualBytesTransferred, FALSE); + ftStatus = FT_GetOverlappedResult(mFTHandle, context->inOvLap, &ulActualBytesTransferred, FALSE); if (ftStatus != FT_OK) { @@ -205,8 +211,8 @@ int FT601::FinishDataXfer(uint8_t* buffer, uint32_t length, int contextHandle) length = ulActualBytesTransferred; } - FT_ReleaseOverlapped(mFTHandle, &contexts[contextHandle].inOvLap); - contexts[contextHandle].used = false; + FT_ReleaseOverlapped(mFTHandle, context->inOvLap); + context->used = false; return length; } @@ -219,9 +225,11 @@ void FT601::AbortEndpointXfers(uint8_t endPointAddr) for (int i = 0; i < USB_MAX_CONTEXTS; ++i) { - if (contexts[i].used == true && contexts[i].endPointAddr == endPointAddr) + USBTransferContext_FT601* context = &dynamic_cast(contexts)[i]; + + if (contexts[i].used == true && context->endPointAddr == endPointAddr) { - FT_ReleaseOverlapped(mFTHandle, &contexts[i].inOvLap); + FT_ReleaseOverlapped(mFTHandle, context->inOvLap); contexts[i].used = false; } } diff --git a/src/comms/USB/FT601/USBTransferContext_FT601.h b/src/comms/USB/FT601/USBTransferContext_FT601.h index 251f89da6..719a84eb7 100644 --- a/src/comms/USB/FT601/USBTransferContext_FT601.h +++ b/src/comms/USB/FT601/USBTransferContext_FT601.h @@ -16,8 +16,7 @@ class USBTransferContext_FT601 : public USBTransferContext USBTransferContext_FT601(); #ifndef __unix__ - PUCHAR context; - OVERLAPPED inOvLap; + LPOVERLAPPED inOvLap; uint8_t endPointAddr; #endif }; diff --git a/src/comms/USB/FX3/CMakeLists.txt b/src/comms/USB/FX3/CMakeLists.txt index 48a3e6484..e89f85ee3 100644 --- a/src/comms/USB/FX3/CMakeLists.txt +++ b/src/comms/USB/FX3/CMakeLists.txt @@ -1,6 +1,6 @@ if(WIN32) find_package(CyAPI) - set_package_properties(CyAPI + set_package_properties(CyAPI PROPERTIES TYPE RECOMMENDED PURPOSE "Adds USB communication support for Cypress FX3 chip" ) diff --git a/src/comms/USB/FX3/USBTransferContext_FX3.h b/src/comms/USB/FX3/USBTransferContext_FX3.h index 43752a264..994275317 100644 --- a/src/comms/USB/FX3/USBTransferContext_FX3.h +++ b/src/comms/USB/FX3/USBTransferContext_FX3.h @@ -23,7 +23,6 @@ class USBTransferContext_FX3 : public USBTransferContext bool Reset() override; #ifndef __unix__ - PUCHAR context; CCyUSBEndPoint* EndPt; OVERLAPPED* inOvLap; #endif diff --git a/src/comms/USB/USBEntry.h b/src/comms/USB/USBEntry.h index 65390876c..3356283db 100644 --- a/src/comms/USB/USBEntry.h +++ b/src/comms/USB/USBEntry.h @@ -3,6 +3,7 @@ #include "limesuite/DeviceRegistry.h" #include "USBEntry.h" +#include #include #ifdef __unix__ diff --git a/src/comms/USB/USBGeneric.cpp b/src/comms/USB/USBGeneric.cpp index 17724b996..912d25079 100644 --- a/src/comms/USB/USBGeneric.cpp +++ b/src/comms/USB/USBGeneric.cpp @@ -179,7 +179,7 @@ void USBGeneric::Disconnect() contexts[i].transfer->dev_handle = dev_handle; } } -#endif + std::unique_lock lock{ contextsLock }; for (int i = 0; i < USB_MAX_CONTEXTS; ++i) @@ -189,6 +189,7 @@ void USBGeneric::Disconnect() AbortEndpointXfers(contexts[i].transfer->endpoint); } } +#endif delete[] contexts; contexts = nullptr; @@ -304,6 +305,7 @@ int USBGeneric::BeginDataXfer(uint8_t* buffer, uint32_t length, uint8_t endPoint return i; #endif + return 0; } bool USBGeneric::WaitForXfer(int contextHandle, uint32_t timeout_ms) @@ -388,6 +390,7 @@ int USBGeneric::GetUSBContextIndex() void USBGeneric::WaitForXfers(uint8_t endPointAddr) { +#ifdef __unix__ for (int i = 0; i < USB_MAX_CONTEXTS; ++i) { if (contexts[i].used && contexts[i].transfer->endpoint == endPointAddr) @@ -396,6 +399,7 @@ void USBGeneric::WaitForXfers(uint8_t endPointAddr) FinishDataXfer(nullptr, 0, i); } } +#endif } } // namespace lime diff --git a/src/comms/USB/USBTransferContext.h b/src/comms/USB/USBTransferContext.h index e85086da9..49bb01065 100644 --- a/src/comms/USB/USBTransferContext.h +++ b/src/comms/USB/USBTransferContext.h @@ -16,6 +16,10 @@ #endif #endif +#ifndef __unix__ + #include +#endif + namespace lime { /** @brief Base class for a USB transfer context. */ @@ -34,6 +38,8 @@ class USBTransferContext std::atomic done; std::mutex transferLock; std::condition_variable cv; +#else + PUCHAR context; #endif }; diff --git a/src/examples/CMakeLists.txt b/src/examples/CMakeLists.txt index c4fddc048..9cb9fbc13 100644 --- a/src/examples/CMakeLists.txt +++ b/src/examples/CMakeLists.txt @@ -49,4 +49,6 @@ target_link_libraries(legacyGpio_example PUBLIC ${MAIN_LIBRARY_NAME}) add_executable(legacySingleRX legacy/singleRX.cpp) set_target_properties(legacySingleRX PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${examplesOutputDir}/legacy RUNTIME_OUTPUT_NAME singleRX) target_link_libraries(legacySingleRX PUBLIC ${MAIN_LIBRARY_NAME}) -target_compile_options(legacySingleRX PRIVATE -Wno-unused-but-set-variable) +if(CMAKE_COMPILER_IS_GNUCXX) + target_compile_options(legacySingleRX PRIVATE -Wno-unused-but-set-variable) +endif() diff --git a/src/include/limesuite/SDRDevice.h b/src/include/limesuite/SDRDevice.h index 3c06df7cd..3d7c40712 100644 --- a/src/include/limesuite/SDRDevice.h +++ b/src/include/limesuite/SDRDevice.h @@ -114,7 +114,7 @@ class LIME_API SDRDevice std::size_t totalCount; std::size_t usedCount; - float ratio() { return static_cast(usedCount) / totalCount; } + float ratio() const { return static_cast(usedCount) / totalCount; } }; StreamStats() { memset(this, 0, sizeof(StreamStats)); } @@ -139,7 +139,7 @@ class LIME_API SDRDevice }; // channels order and data transmission formats setup - struct StreamConfig { + struct LIME_API StreamConfig { struct Extras { Extras(); bool usePoll; diff --git a/src/lms7002m/LMS7002M.cpp b/src/lms7002m/LMS7002M.cpp index 50e5717a5..367a96bf0 100644 --- a/src/lms7002m/LMS7002M.cpp +++ b/src/lms7002m/LMS7002M.cpp @@ -140,7 +140,7 @@ void LMS7002M::Log(const char* text, LogType type) } //Compatibility for vasprintf under MSVC -#ifdef _MSC_VER +#if defined(_MSC_VER) || !defined(__unix__) int vasprintf(char** strp, const char* fmt, va_list ap) { int r = _vscprintf(fmt, ap); diff --git a/src/memory/MemoryPool.cpp b/src/memory/MemoryPool.cpp index 24fd52821..d67becd5f 100644 --- a/src/memory/MemoryPool.cpp +++ b/src/memory/MemoryPool.cpp @@ -19,7 +19,7 @@ MemoryPool::MemoryPool(int blockCount, int blockSize, int alignment, const std:: #if __unix__ void* ptr = aligned_alloc(alignment, blockSize); #else - void* ptr = _aligned_malloc(alignment, blockSize); + void* ptr = _aligned_malloc(blockSize, alignment); #endif if (!ptr) { @@ -43,7 +43,13 @@ MemoryPool::~MemoryPool() mFreeBlocks.pop(); } for (auto ptr : mUsedBlocks) + { +#ifdef __unix__ free(ptr); +#else + _aligned_free(ptr); +#endif + } } void* MemoryPool::Allocate(int size) diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 2248f558f..ef5160fe0 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -39,7 +39,7 @@ endif() include(GoogleTest) gtest_discover_tests(${LIME_TEST_SUITE_NAME}) -if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND ENABLE_CODE_COVERAGE) +if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND ENABLE_CODE_COVERAGE AND (NOT MSVC)) include(CodeCoverage) setup_target_for_coverage_lcov(NAME ${LIME_TEST_SUITE_NAME}_coverage EXECUTABLE ${LIME_TEST_SUITE_NAME} EXCLUDE "/usr/*" "build/*" "external/*" "tests/*") target_link_libraries(${LIME_TEST_SUITE_NAME} PUBLIC gcov) diff --git a/src/threadHelper/threadHelper.cpp b/src/threadHelper/threadHelper.cpp index 0efb192cf..7a826dbc6 100644 --- a/src/threadHelper/threadHelper.cpp +++ b/src/threadHelper/threadHelper.cpp @@ -143,7 +143,7 @@ int lime::SetOSThreadPriority(ThreadPriority priority, ThreadPolicy /*policy*/, break; } - if (!SetThreadPriority(thread->native_handle(), win_priority)) + if (!SetThreadPriority(reinterpret_cast(thread->native_handle()), win_priority)) { lime::debug("SetThreadPriority: Failed to set priority(%d)", win_priority); return -1; From a819dd794f9d1a6b3da1b52cf45337458eb8261c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Petkevi=C4=8Dius?= Date: Mon, 12 Feb 2024 14:57:10 +0200 Subject: [PATCH 02/22] SDR-Mini Windows support --- src/boards/LimeSDR_Mini/LimeSDR_MiniEntry.cpp | 12 +- src/comms/USB/FT601/FT601.cpp | 106 +++++++++++++----- src/comms/USB/FT601/FT601.h | 3 + .../USB/FT601/USBTransferContext_FT601.cpp | 4 + src/comms/USB/FX3/FX3.cpp | 34 ++++++ src/comms/USB/FX3/FX3.h | 2 + src/comms/USB/USBGeneric.h | 2 +- src/memory/MemoryPool.cpp | 4 + 8 files changed, 135 insertions(+), 32 deletions(-) diff --git a/src/boards/LimeSDR_Mini/LimeSDR_MiniEntry.cpp b/src/boards/LimeSDR_Mini/LimeSDR_MiniEntry.cpp index b10e243ba..725f3790b 100644 --- a/src/boards/LimeSDR_Mini/LimeSDR_MiniEntry.cpp +++ b/src/boards/LimeSDR_Mini/LimeSDR_MiniEntry.cpp @@ -83,8 +83,16 @@ std::vector LimeSDR_MiniEntry::enumerate(const DeviceHandle& hint) SDRDevice* LimeSDR_MiniEntry::make(const DeviceHandle& handle) { const auto splitPos = handle.addr.find(":"); - const uint16_t vid = std::stoi(handle.addr.substr(0, splitPos), nullptr, 16); - const uint16_t pid = std::stoi(handle.addr.substr(splitPos + 1), nullptr, 16); + + uint16_t vid = 0; + uint16_t pid = 0; + + if (splitPos != std::string::npos) + { + vid = std::stoi(handle.addr.substr(0, splitPos), nullptr, 16); + pid = std::stoi(handle.addr.substr(splitPos + 1), nullptr, 16); + + } auto usbComms = std::make_shared( #ifdef __unix__ diff --git a/src/comms/USB/FT601/FT601.cpp b/src/comms/USB/FT601/FT601.cpp index 0a18a0b1a..c3b180322 100644 --- a/src/comms/USB/FT601/FT601.cpp +++ b/src/comms/USB/FT601/FT601.cpp @@ -15,6 +15,8 @@ FT601::FT601(void* usbContext) : USBGeneric(usbContext) #ifdef __unix , mUsbCounter(0) +#else + , mFTHandle(nullptr) #endif { } @@ -115,7 +117,7 @@ int32_t FT601::BulkTransfer(uint8_t endPointAddr, uint8_t* data, int length, int DWORD dwRet = WaitForSingleObject(vOverlapped.hEvent, timeout_ms); if (dwRet == WAIT_OBJECT_0 || dwRet == WAIT_TIMEOUT) { - if (FT_GetOverlappedResult(mFTHandle, &vOverlapped, &ulBytesTransferred, FALSE) == FALSE) + if (FT_GetOverlappedResult(mFTHandle, &vOverlapped, &ulBytesTransferred, FALSE) != FT_OK) { ReinitPipe(endPointAddr); ulBytesTransferred = -1; @@ -168,7 +170,7 @@ int FT601::BeginDataXfer(uint8_t* buffer, uint32_t length, uint8_t endPointAddr) if (ftStatus != FT_IO_PENDING) { lime::error("ERROR BEGIN DATA TRANSFER %d", ftStatus); - contexts[index].used = false; + context->used = false; return -1; } @@ -177,46 +179,58 @@ int FT601::BeginDataXfer(uint8_t* buffer, uint32_t length, uint8_t endPointAddr) bool FT601::WaitForXfer(int contextHandle, uint32_t timeout_ms) { + if (contextHandle < 0) + { + return true; + } + + USBTransferContext_FT601* context = &dynamic_cast(contexts)[contextHandle]; - if (contextHandle >= 0 && contexts[contextHandle].used == true) + if (!context->used) { - USBTransferContext_FT601* context = &dynamic_cast(contexts)[contextHandle]; - DWORD dwRet = WaitForSingleObject(context->inOvLap->hEvent, timeout_ms); + return true; //there is nothing to wait for (signal wait finished) + } - if (dwRet == WAIT_OBJECT_0) - { - return true; - } + DWORD dwRet = WaitForSingleObject(context->inOvLap->hEvent, timeout_ms); + + if (dwRet == WAIT_OBJECT_0) + { + return true; } - return true; //there is nothing to wait for (signal wait finished) + return false; } int FT601::FinishDataXfer(uint8_t* buffer, uint32_t length, int contextHandle) { - if (contextHandle >= 0 && contexts[contextHandle].used == true) + if (contextHandle < 0) + { + return 0; + } + + USBTransferContext_FT601* context = &dynamic_cast(contexts)[contextHandle]; + if (!context->used) { - ULONG ulActualBytesTransferred; - FT_STATUS ftStatus = FT_OK; - USBTransferContext_FT601* context = &dynamic_cast(contexts)[contextHandle]; + return 0; + } - ftStatus = FT_GetOverlappedResult(mFTHandle, context->inOvLap, &ulActualBytesTransferred, FALSE); + ULONG ulActualBytesTransferred; + FT_STATUS ftStatus = FT_OK; - if (ftStatus != FT_OK) - { - length = 0; - } - else - { - length = ulActualBytesTransferred; - } + ftStatus = FT_GetOverlappedResult(mFTHandle, context->inOvLap, &ulActualBytesTransferred, FALSE); - FT_ReleaseOverlapped(mFTHandle, context->inOvLap); - context->used = false; - return length; + if (ftStatus != FT_OK) + { + length = 0; + } + else + { + length = ulActualBytesTransferred; } - return 0; + FT_ReleaseOverlapped(mFTHandle, context->inOvLap); + context->used = false; + return length; } void FT601::AbortEndpointXfers(uint8_t endPointAddr) @@ -227,10 +241,10 @@ void FT601::AbortEndpointXfers(uint8_t endPointAddr) { USBTransferContext_FT601* context = &dynamic_cast(contexts)[i]; - if (contexts[i].used == true && context->endPointAddr == endPointAddr) + if (context->used == true && context->endPointAddr == endPointAddr) { FT_ReleaseOverlapped(mFTHandle, context->inOvLap); - contexts[i].used = false; + context->used = false; } } @@ -245,6 +259,40 @@ void FT601::AbortEndpointXfers(uint8_t endPointAddr) } #endif +int FT601::GetUSBContextIndex() +{ + std::unique_lock lock{ contextsLock }; + + USBTransferContext_FT601* FT601contexts = static_cast(contexts); + + if (FT601contexts == nullptr) + { + return -1; + } + + int i = 0; + bool contextFound = false; + // Find not used context + for (i = 0; i < USB_MAX_CONTEXTS; i++) + { + if (!FT601contexts[i].used) + { + contextFound = true; + break; + } + } + + if (!contextFound) + { + lime::error("No contexts left for reading or sending data"s); + return -1; + } + + FT601contexts[i].used = true; + + return i; +} + int FT601::ResetStreamBuffers() { #ifndef __unix__ diff --git a/src/comms/USB/FT601/FT601.h b/src/comms/USB/FT601/FT601.h index 456e2f053..6a87fcdcf 100644 --- a/src/comms/USB/FT601/FT601.h +++ b/src/comms/USB/FT601/FT601.h @@ -1,6 +1,8 @@ #pragma once #include "USBGeneric.h" +#include "limesuite/config.h" +#include "USBTransferContext_FT601.h" #ifndef __unix__ #include "FTD3XXLibrary/FTD3XX.h" @@ -37,6 +39,7 @@ class FT601 : public USBGeneric virtual int FinishDataXfer(uint8_t* buffer, uint32_t length, int contextHandle) override; virtual void AbortEndpointXfers(uint8_t endPointAddr) override; #endif + virtual int GetUSBContextIndex() override; int ResetStreamBuffers(); diff --git a/src/comms/USB/FT601/USBTransferContext_FT601.cpp b/src/comms/USB/FT601/USBTransferContext_FT601.cpp index 05c9e5319..aecd9d6c2 100644 --- a/src/comms/USB/FT601/USBTransferContext_FT601.cpp +++ b/src/comms/USB/FT601/USBTransferContext_FT601.cpp @@ -4,6 +4,10 @@ using namespace lime; USBTransferContext_FT601::USBTransferContext_FT601() : USBTransferContext() +#ifndef __unix__ + , inOvLap(new OVERLAPPED()) + , endPointAddr(0) +#endif { #ifndef __unix__ context = NULL; diff --git a/src/comms/USB/FX3/FX3.cpp b/src/comms/USB/FX3/FX3.cpp index 31f5418e4..598d32730 100644 --- a/src/comms/USB/FX3/FX3.cpp +++ b/src/comms/USB/FX3/FX3.cpp @@ -100,3 +100,37 @@ void FX3::AbortEndpointXfers(uint8_t endPointAddr) WaitForXfers(endPointAddr); } #endif + +int FX3::GetUSBContextIndex() +{ + std::unique_lock lock{ contextsLock }; + + USBTransferContext_FX3* FX3contexts = static_cast(contexts); + + if (FX3contexts == nullptr) + { + return -1; + } + + int i = 0; + bool contextFound = false; + // Find not used context + for (i = 0; i < USB_MAX_CONTEXTS; i++) + { + if (!FX3contexts[i].used) + { + contextFound = true; + break; + } + } + + if (!contextFound) + { + lime::error("No contexts left for reading or sending data"s); + return -1; + } + + FX3contexts[i].used = true; + + return i; +} diff --git a/src/comms/USB/FX3/FX3.h b/src/comms/USB/FX3/FX3.h index e4d6f792c..629e2d8ec 100644 --- a/src/comms/USB/FX3/FX3.h +++ b/src/comms/USB/FX3/FX3.h @@ -27,6 +27,8 @@ class FX3 : public USBGeneric virtual int FinishDataXfer(uint8_t* buffer, uint32_t length, int contextHandle) override; virtual void AbortEndpointXfers(uint8_t endPointAddr) override; #endif + + virtual int GetUSBContextIndex() override; }; } // namespace lime diff --git a/src/comms/USB/USBGeneric.h b/src/comms/USB/USBGeneric.h index 8c9cf4c97..d779d8c16 100644 --- a/src/comms/USB/USBGeneric.h +++ b/src/comms/USB/USBGeneric.h @@ -51,7 +51,7 @@ class USBGeneric bool isConnected; - int GetUSBContextIndex(); + virtual int GetUSBContextIndex(); virtual void WaitForXfers(uint8_t endPointAddr); #ifdef __unix__ diff --git a/src/memory/MemoryPool.cpp b/src/memory/MemoryPool.cpp index d67becd5f..35a50a66a 100644 --- a/src/memory/MemoryPool.cpp +++ b/src/memory/MemoryPool.cpp @@ -39,7 +39,11 @@ MemoryPool::~MemoryPool() while (!mFreeBlocks.empty()) { void* ptr = mFreeBlocks.top(); +#ifdef __unix__ free(ptr); +#else + _aligned_free(ptr); +#endif mFreeBlocks.pop(); } for (auto ptr : mUsedBlocks) From cebe195ff8f0fdfaf0a41e7160f37f3824d500e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Petkevi=C4=8Dius?= Date: Mon, 12 Feb 2024 16:28:37 +0200 Subject: [PATCH 03/22] Fix Cypress compilation --- .gitignore | 1 + cmake/Modules/FindCyAPI.cmake | 18 +++------ src/boards/LimeSDR/LimeSDREntry.cpp | 2 +- src/boards/LimeSDR/USB_CSR_Pipe_SDR.cpp | 4 ++ src/comms/USB/FX3/FX3.cpp | 49 +++++++++++++++++-------- src/comms/USB/FX3/FX3.h | 20 ++++++++++ 6 files changed, 64 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index 3f35e043c..303db2d6a 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ docs/LMS_API_Documentation/* /.vs /out/ /CMakeSettings.json +/deps/ diff --git a/cmake/Modules/FindCyAPI.cmake b/cmake/Modules/FindCyAPI.cmake index 16fb55da0..48087df44 100644 --- a/cmake/Modules/FindCyAPI.cmake +++ b/cmake/Modules/FindCyAPI.cmake @@ -29,19 +29,11 @@ if(MSVC) mark_as_advanced(CYAPI_HEADER_FILE) get_filename_component(CYAPI_INCLUDE_DIRS "${CYAPI_HEADER_FILE}" PATH) - if(MSVC) - if(CMAKE_CL_64) - set(CYAPI_ARCH x64) - else(CMAKE_CL_64) - set(CYAPI_ARCH x86) - endif(CMAKE_CL_64) - elseif(CMAKE_COMPILER_IS_GNUCC) - if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(CYAPI_ARCH x64) - else(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(CYAPI_ARCH x86) - endif(CMAKE_SIZEOF_VOID_P EQUAL 8) - endif() + if(CMAKE_CL_64) + set(CYAPI_ARCH x64) + else(CMAKE_CL_64) + set(CYAPI_ARCH x86) + endif(CMAKE_CL_64) find_library(CYAPI_LIBRARY NAMES diff --git a/src/boards/LimeSDR/LimeSDREntry.cpp b/src/boards/LimeSDR/LimeSDREntry.cpp index 3cddede7a..816126462 100644 --- a/src/boards/LimeSDR/LimeSDREntry.cpp +++ b/src/boards/LimeSDR/LimeSDREntry.cpp @@ -48,7 +48,7 @@ std::vector LimeSDREntry::enumerate(const DeviceHandle& hint) } CCyUSBDevice device; - if (device.DeviceCount()) + if (device.DeviceCount() > 0) { for (int i = 0; i < device.DeviceCount(); ++i) { diff --git a/src/boards/LimeSDR/USB_CSR_Pipe_SDR.cpp b/src/boards/LimeSDR/USB_CSR_Pipe_SDR.cpp index 0a68f3dda..7ce5e1b78 100644 --- a/src/boards/LimeSDR/USB_CSR_Pipe_SDR.cpp +++ b/src/boards/LimeSDR/USB_CSR_Pipe_SDR.cpp @@ -47,8 +47,10 @@ int USB_CSR_Pipe_SDR::Write(const uint8_t* data, size_t length, int timeout_ms) return port.BulkTransfer(CONTROL_BULK_OUT_ADDRESS, const_cast(data), length, timeout_ms); } +#ifdef __unix__ return port.ControlTransfer( LIBUSB_REQUEST_TYPE_VENDOR, CTR_W_REQCODE, CTR_W_VALUE, CTR_W_INDEX, const_cast(data), length, timeout_ms); +#endif // __unix__ } int USB_CSR_Pipe_SDR::Read(uint8_t* data, size_t length, int timeout_ms) @@ -60,6 +62,8 @@ int USB_CSR_Pipe_SDR::Read(uint8_t* data, size_t length, int timeout_ms) return port.BulkTransfer(CONTROL_BULK_IN_ADDRESS, data, length, timeout_ms); } +#ifdef __unix__ return port.ControlTransfer( LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN, CTR_R_REQCODE, CTR_R_VALUE, CTR_R_INDEX, data, length, timeout_ms); +#endif } diff --git a/src/comms/USB/FX3/FX3.cpp b/src/comms/USB/FX3/FX3.cpp index 598d32730..8ad18594d 100644 --- a/src/comms/USB/FX3/FX3.cpp +++ b/src/comms/USB/FX3/FX3.cpp @@ -1,7 +1,9 @@ #include "FX3.h" #include "USBTransferContext_FX3.h" +#include "Logger.h" using namespace lime; +using namespace std::literals::string_literals; FX3::FX3(void* usbContext) : USBGeneric(usbContext) @@ -50,10 +52,12 @@ int FX3::BeginDataXfer(uint8_t* buffer, uint32_t length, uint8_t endPointAddr) return -1; } + USBTransferContext_FX3* FX3context = &static_cast(contexts)[index]; + if (InEndPt[endPointAddr & 0xF]) { - contexts[index].EndPt = InEndPt[endPointAddr & 0xF]; - contexts[index].context = contexts[index].EndPt->BeginDataXfer(buffer, length, contexts[index].inOvLap); + FX3context->EndPt = InEndPt[endPointAddr & 0xF]; + FX3context->context = FX3context->EndPt->BeginDataXfer(buffer, length, FX3context->inOvLap); } return index; @@ -61,30 +65,43 @@ int FX3::BeginDataXfer(uint8_t* buffer, uint32_t length, uint8_t endPointAddr) bool FX3::WaitForXfer(int contextHandle, uint32_t timeout_ms) { - if (contextHandle >= 0 && contexts[contextHandle].used == true) + if (contextHandle < 0) + { + return true; + } + + USBTransferContext_FX3* FX3context = &static_cast(contexts)[contextHandle]; + + if (!FX3context->used) { - int status = 0; - status = contexts[contextHandle].EndPt->WaitForXfer(contexts[contextHandle].inOvLap, timeout_ms); - return status; + return true; //there is nothing to wait for (signal wait finished) } - return true; //there is nothing to wait for (signal wait finished) + int status = 0; + status = FX3context->EndPt->WaitForXfer(FX3context->inOvLap, timeout_ms); + return status; } int FX3::FinishDataXfer(uint8_t* buffer, uint32_t length, int contextHandle) { - if (contextHandle >= 0 && contexts[contextHandle].used == true) + if (contextHandle < 0) + { + return true; + } + + USBTransferContext_FX3* FX3context = &static_cast(contexts)[contextHandle]; + + if (!FX3context->used) { - int status = 0; - long len = length; - status = contexts[contextHandle].EndPt->FinishDataXfer( - (unsigned char*)buffer, len, contexts[contextHandle].inOvLap, contexts[contextHandle].context); - contexts[contextHandle].used = false; - contexts[contextHandle].reset(); - return len; + return 0; } - return 0; + int status = 0; + long len = length; + status = FX3context->EndPt->FinishDataXfer((unsigned char*)buffer, len, FX3context->inOvLap, FX3context->context); + FX3context->used = false; + FX3context->Reset(); + return len; } void FX3::AbortEndpointXfers(uint8_t endPointAddr) diff --git a/src/comms/USB/FX3/FX3.h b/src/comms/USB/FX3/FX3.h index 629e2d8ec..af3bb52ab 100644 --- a/src/comms/USB/FX3/FX3.h +++ b/src/comms/USB/FX3/FX3.h @@ -9,6 +9,11 @@ #include #include +#ifndef __unix__ + #include "windows.h" + #include "CyAPI.h" +#endif // !__unix__ + namespace lime { /** @brief A class for communicating with devices using the Cypress USB 3.0 CYUSB3014-BZXC USB controller. */ @@ -29,6 +34,21 @@ class FX3 : public USBGeneric #endif virtual int GetUSBContextIndex() override; + +#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[MAX_EP_CNT]; + CCyUSBEndPoint* OutEndPt[MAX_EP_CNT]; + + CCyUSBEndPoint* InCtrlBulkEndPt; + CCyUSBEndPoint* OutCtrlBulkEndPt; +#endif }; } // namespace lime From afcba2eca0382226c85d63368c0d6edad8a94af6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Petkevi=C4=8Dius?= Date: Tue, 13 Feb 2024 12:14:53 +0200 Subject: [PATCH 04/22] Minor Windows GUI compile fix --- src/lms7002_wxgui/lms7002_pnlMCU_BD_view.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lms7002_wxgui/lms7002_pnlMCU_BD_view.cpp b/src/lms7002_wxgui/lms7002_pnlMCU_BD_view.cpp index 98bab9ca4..9c0359116 100644 --- a/src/lms7002_wxgui/lms7002_pnlMCU_BD_view.cpp +++ b/src/lms7002_wxgui/lms7002_pnlMCU_BD_view.cpp @@ -608,7 +608,7 @@ void lms7002_pnlMCU_BD_view::OnbtnLoadTestFileClick(wxCommandEvent& event) temps = temps + m_sTxtFileName; lblTestResultsFile->SetLabel(temps); - std::ifstream inFile(m_sTxtFileName); + std::ifstream inFile(std::string{ m_sTxtFileName }); if (inFile.is_open()) { @@ -908,7 +908,7 @@ void lms7002_pnlMCU_BD_view::OnbtnRunTestClick(wxCommandEvent& event) wxString m_sTxtFileName = _("lms7suite_mcu/TestResults.txt"); lblTestResultsFile->SetLabel("Test results file: " + m_sTxtFileName); - std::ifstream inFile(m_sTxtFileName); + std::ifstream inFile(std::string{ m_sTxtFileName }); if (inFile.is_open()) { From d73b995ca003b5170f8c6f6b9c032d1cccc0157e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Petkevi=C4=8Dius?= Date: Tue, 13 Feb 2024 12:27:36 +0200 Subject: [PATCH 05/22] FX3 support --- src/boards/LimeSDR/LimeSDR.cpp | 17 +- src/boards/LimeSDR/LimeSDREntry.cpp | 10 +- src/boards/LimeSDR/USB_CSR_Pipe_SDR.cpp | 21 +- src/boards/LimeSDR_Mini/LimeSDR_MiniEntry.cpp | 1 - src/comms/USB/FX3/FX3.cpp | 219 +++++++++++++++++- src/comms/USB/FX3/FX3.h | 22 ++ 6 files changed, 254 insertions(+), 36 deletions(-) diff --git a/src/boards/LimeSDR/LimeSDR.cpp b/src/boards/LimeSDR/LimeSDR.cpp index 3f300e62a..8affef4e6 100644 --- a/src/boards/LimeSDR/LimeSDR.cpp +++ b/src/boards/LimeSDR/LimeSDR.cpp @@ -12,6 +12,7 @@ #include "lms7002m/LMS7002M_validation.h" #include "protocols/LMS64CProtocol.h" #include "limesuite/DeviceNode.h" +#include "FX3/FX3.h" #include #include @@ -31,22 +32,8 @@ #endif #endif -#define CTR_W_REQCODE 0xC1 -#define CTR_W_VALUE 0x0000 -#define CTR_W_INDEX 0x0000 - -#define CTR_R_REQCODE 0xC0 -#define CTR_R_VALUE 0x0000 -#define CTR_R_INDEX 0x0000 - using namespace lime; -static const uint8_t CONTROL_BULK_OUT_ADDRESS = 0x0F; -static const uint8_t CONTROL_BULK_IN_ADDRESS = 0x8F; - -static const uint8_t STREAM_BULK_OUT_ADDRESS = 0x01; -static const uint8_t STREAM_BULK_IN_ADDRESS = 0x81; - static const uint8_t SPI_LMS7002M = 0; static const uint8_t SPI_FPGA = 1; @@ -646,7 +633,7 @@ OpStatus LimeSDR::StreamSetup(const StreamConfig& config, uint8_t moduleIndex) } mStreamers.at(moduleIndex) = - new TRXLooper_USB(mStreamPort, mFPGA, mLMSChips.at(moduleIndex), STREAM_BULK_IN_ADDRESS, STREAM_BULK_OUT_ADDRESS); + new TRXLooper_USB(mStreamPort, mFPGA, mLMSChips.at(moduleIndex), FX3::STREAM_BULK_IN_ADDRESS, FX3::STREAM_BULK_OUT_ADDRESS); return mStreamers.at(moduleIndex)->Setup(config); } diff --git a/src/boards/LimeSDR/LimeSDREntry.cpp b/src/boards/LimeSDR/LimeSDREntry.cpp index 816126462..0e2ce69b5 100644 --- a/src/boards/LimeSDR/LimeSDREntry.cpp +++ b/src/boards/LimeSDR/LimeSDREntry.cpp @@ -77,9 +77,15 @@ std::vector LimeSDREntry::enumerate(const DeviceHandle& hint) SDRDevice* LimeSDREntry::make(const DeviceHandle& handle) { const auto splitPos = handle.addr.find(":"); - const uint16_t vid = std::stoi(handle.addr.substr(0, splitPos), nullptr, 16); - const uint16_t pid = std::stoi(handle.addr.substr(splitPos + 1), nullptr, 16); + uint16_t vid = 0; + uint16_t pid = 0; + if (splitPos != std::string::npos) + { + vid = std::stoi(handle.addr.substr(0, splitPos), nullptr, 16); + pid = std::stoi(handle.addr.substr(splitPos + 1), nullptr, 16); + } + auto usbComms = std::make_shared( #ifdef __unix__ ctx diff --git a/src/boards/LimeSDR/USB_CSR_Pipe_SDR.cpp b/src/boards/LimeSDR/USB_CSR_Pipe_SDR.cpp index 7ce5e1b78..d35346685 100644 --- a/src/boards/LimeSDR/USB_CSR_Pipe_SDR.cpp +++ b/src/boards/LimeSDR/USB_CSR_Pipe_SDR.cpp @@ -8,17 +8,6 @@ using namespace lime; -static const int CTR_W_REQCODE = 0xC1; -static const int CTR_W_VALUE = 0x0000; -static const int CTR_W_INDEX = 0x0000; - -static const int CTR_R_REQCODE = 0xC0; -static const int CTR_R_VALUE = 0x0000; -static const int CTR_R_INDEX = 0x0000; - -static const uint8_t CONTROL_BULK_OUT_ADDRESS = 0x0F; -static const uint8_t CONTROL_BULK_IN_ADDRESS = 0x8F; - static const std::set commandsToBulkTransfer = { LMS64CProtocol::CMD_BRDSPI_WR, LMS64CProtocol::CMD_BRDSPI_RD, @@ -44,12 +33,14 @@ int USB_CSR_Pipe_SDR::Write(const uint8_t* data, size_t length, int timeout_ms) if (commandsToBulkTransfer.find(pkt->cmd) != commandsToBulkTransfer.end()) { - return port.BulkTransfer(CONTROL_BULK_OUT_ADDRESS, const_cast(data), length, timeout_ms); + return port.BulkTransfer(FX3::CONTROL_BULK_OUT_ADDRESS, const_cast(data), length, timeout_ms); } #ifdef __unix__ return port.ControlTransfer( LIBUSB_REQUEST_TYPE_VENDOR, CTR_W_REQCODE, CTR_W_VALUE, CTR_W_INDEX, const_cast(data), length, timeout_ms); +#else + return port.ControlTransfer(0, 0, 0, 0, const_cast(data), length, timeout_ms); #endif // __unix__ } @@ -59,11 +50,13 @@ int USB_CSR_Pipe_SDR::Read(uint8_t* data, size_t length, int timeout_ms) if (commandsToBulkTransfer.find(pkt->cmd) != commandsToBulkTransfer.end()) { - return port.BulkTransfer(CONTROL_BULK_IN_ADDRESS, data, length, timeout_ms); + return port.BulkTransfer(FX3::CONTROL_BULK_IN_ADDRESS, data, length, timeout_ms); } #ifdef __unix__ return port.ControlTransfer( LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN, CTR_R_REQCODE, CTR_R_VALUE, CTR_R_INDEX, data, length, timeout_ms); -#endif +#else + return port.ControlTransfer(1, 0, 0, 0, const_cast(data), length, timeout_ms); +#endif // __unix__ } diff --git a/src/boards/LimeSDR_Mini/LimeSDR_MiniEntry.cpp b/src/boards/LimeSDR_Mini/LimeSDR_MiniEntry.cpp index 725f3790b..4741a74b0 100644 --- a/src/boards/LimeSDR_Mini/LimeSDR_MiniEntry.cpp +++ b/src/boards/LimeSDR_Mini/LimeSDR_MiniEntry.cpp @@ -91,7 +91,6 @@ SDRDevice* LimeSDR_MiniEntry::make(const DeviceHandle& handle) { vid = std::stoi(handle.addr.substr(0, splitPos), nullptr, 16); pid = std::stoi(handle.addr.substr(splitPos + 1), nullptr, 16); - } auto usbComms = std::make_shared( diff --git a/src/comms/USB/FX3/FX3.cpp b/src/comms/USB/FX3/FX3.cpp index 8ad18594d..a9462205b 100644 --- a/src/comms/USB/FX3/FX3.cpp +++ b/src/comms/USB/FX3/FX3.cpp @@ -8,6 +8,26 @@ using namespace std::literals::string_literals; FX3::FX3(void* usbContext) : USBGeneric(usbContext) { +#ifndef __unix__ + if (usbContext == nullptr) + { + USBDevicePrimary = new CCyFX3Device(); + } + else + { + USBDevicePrimary = new CCyFX3Device(*(CCyFX3Device*)usbContext); + } + + InCtrlEndPt3 = nullptr; + OutCtrlEndPt3 = nullptr; + InCtrlBulkEndPt = nullptr; + OutCtrlBulkEndPt = nullptr; + + for (int i = 0; i < MAX_EP_CNT; ++i) + { + InEndPt[i] = OutEndPt[i] = nullptr; + } +#endif } FX3::~FX3() @@ -18,7 +38,87 @@ FX3::~FX3() bool FX3::Connect(uint16_t vid, uint16_t pid, const std::string& serial) { Disconnect(); +#ifndef __unix__ + unsigned int index = 0; + if (index > USBDevicePrimary->DeviceCount()) + { + return ReportError(ERANGE, "ConnectionSTREAM: Device index out of range"); + } + + if (USBDevicePrimary->Open(index) == false) + { + return ReportError(-1, "ConnectionSTREAM: Failed to open device"); + } + + if (InCtrlEndPt3) + { + delete InCtrlEndPt3; + InCtrlEndPt3 = nullptr; + } + InCtrlEndPt3 = new CCyControlEndPoint(*USBDevicePrimary->ControlEndPt); + + if (OutCtrlEndPt3) + { + delete OutCtrlEndPt3; + OutCtrlEndPt3 = nullptr; + } + OutCtrlEndPt3 = new CCyControlEndPoint(*USBDevicePrimary->ControlEndPt); + + InCtrlEndPt3->ReqCode = CTR_R_REQCODE; + InCtrlEndPt3->Value = CTR_R_VALUE; + InCtrlEndPt3->Index = CTR_R_INDEX; + InCtrlEndPt3->TimeOut = 3000; + + OutCtrlEndPt3->ReqCode = CTR_W_REQCODE; + OutCtrlEndPt3->Value = CTR_W_VALUE; + OutCtrlEndPt3->Index = CTR_W_INDEX; + OutCtrlEndPt3->TimeOut = 3000; + + for (int i = 0; i < USBDevicePrimary->EndPointCount(); ++i) + { + auto adr = USBDevicePrimary->EndPoints[i]->Address; + if (adr < CONTROL_BULK_OUT_ADDRESS) + { + OutEndPt[adr] = USBDevicePrimary->EndPoints[i]; + long len = OutEndPt[adr]->MaxPktSize * 64; + OutEndPt[adr]->SetXferSize(len); + } + else if (adr < CONTROL_BULK_IN_ADDRESS) + { + 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) + { + if (USBDevicePrimary->EndPoints[i]->Address == CONTROL_BULK_IN_ADDRESS) + { + InCtrlBulkEndPt = USBDevicePrimary->EndPoints[i]; + InCtrlBulkEndPt->TimeOut = 1000; + break; + } + } + + OutCtrlBulkEndPt = nullptr; + for (int i = 0; i < USBDevicePrimary->EndPointCount(); ++i) + { + if (USBDevicePrimary->EndPoints[i]->Address == CONTROL_BULK_OUT_ADDRESS) + { + OutCtrlBulkEndPt = USBDevicePrimary->EndPoints[i]; + OutCtrlBulkEndPt->TimeOut = 1000; + break; + } + } + + bool isSuccessful = true; + isConnected = true; +#else bool isSuccessful = USBGeneric::Connect(vid, pid, serial); +#endif if (!isSuccessful) { return false; @@ -38,11 +138,100 @@ void FX3::Disconnect() libusb_close(dev_handle); dev_handle = nullptr; } +#else + 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; + } #endif isConnected = false; } +bool FX3::IsConnected() +{ +#ifndef __unix__ + return USBDevicePrimary->IsOpen() && isConnected; +#else + return isConnected; +#endif +} + #ifndef __unix__ +int32_t FX3::BulkTransfer(uint8_t endPoint, uint8_t* data, int length, int32_t timeout_ms) +{ + switch (endPoint) + { + case FX3::CONTROL_BULK_OUT_ADDRESS: // Write + if (OutCtrlEndPt3) + { + LONG longLength = static_cast(length); + if (OutCtrlBulkEndPt->XferData(data, longLength)) + { + return length; + } + } + break; + case FX3::CONTROL_BULK_IN_ADDRESS: // Read + if (endPoint) + { + LONG longLength = static_cast(length); + + if (InCtrlBulkEndPt->XferData(data, longLength)) + { + return length; + } + } + break; + default: + throw std::logic_error("Invalid endpoint"); + } + return 0; +} + +int32_t FX3::ControlTransfer(int requestType, int request, int value, int index, uint8_t* data, uint32_t length, int32_t timeout_ms) +{ + switch (requestType) + { + case 0: // Write + if (OutCtrlEndPt3) + { + LONG longLength = static_cast(length); + if (OutCtrlEndPt3->Write(data, longLength)) + { + return length; + } + } + break; + case 1: // Read + if (InCtrlEndPt3) + { + LONG longLength = static_cast(length); + + if (InCtrlEndPt3->Read(data, longLength)) + { + return length; + } + } + } + return 0; +} + int FX3::BeginDataXfer(uint8_t* buffer, uint32_t length, uint8_t endPointAddr) { int index = GetUSBContextIndex(); @@ -54,10 +243,26 @@ int FX3::BeginDataXfer(uint8_t* buffer, uint32_t length, uint8_t endPointAddr) USBTransferContext_FX3* FX3context = &static_cast(contexts)[index]; - if (InEndPt[endPointAddr & 0xF]) + switch (endPointAddr) { - FX3context->EndPt = InEndPt[endPointAddr & 0xF]; - FX3context->context = FX3context->EndPt->BeginDataXfer(buffer, length, FX3context->inOvLap); + case FX3::STREAM_BULK_OUT_ADDRESS: // Tx/Write + if (OutEndPt[STREAM_BULK_OUT_ADDRESS]) + { + FX3context->EndPt = OutEndPt[STREAM_BULK_OUT_ADDRESS]; + FX3context->context = + FX3context->EndPt->BeginDataXfer(reinterpret_cast(buffer), length, FX3context->inOvLap); + } + + break; + case FX3::STREAM_BULK_IN_ADDRESS: // Rx/Read + if (InEndPt[endPointAddr & 0xF]) + { + FX3context->EndPt = InEndPt[endPointAddr & 0xF]; + FX3context->context = FX3context->EndPt->BeginDataXfer(buffer, length, FX3context->inOvLap); + } + break; + default: + throw std::logic_error("Invalid endpoint for an FX3 connection"); } return index; @@ -98,7 +303,8 @@ int FX3::FinishDataXfer(uint8_t* buffer, uint32_t length, int contextHandle) int status = 0; long len = length; - status = FX3context->EndPt->FinishDataXfer((unsigned char*)buffer, len, FX3context->inOvLap, FX3context->context); + status = + FX3context->EndPt->FinishDataXfer(reinterpret_cast(buffer), len, FX3context->inOvLap, FX3context->context); FX3context->used = false; FX3context->Reset(); return len; @@ -112,6 +318,11 @@ void FX3::AbortEndpointXfers(uint8_t endPointAddr) { InEndPt[i]->Abort(); } + + if (OutEndPt[i] && OutEndPt[i]->Address == endPointAddr) + { + OutEndPt[i]->Abort(); + } } WaitForXfers(endPointAddr); diff --git a/src/comms/USB/FX3/FX3.h b/src/comms/USB/FX3/FX3.h index af3bb52ab..82c949920 100644 --- a/src/comms/USB/FX3/FX3.h +++ b/src/comms/USB/FX3/FX3.h @@ -26,11 +26,19 @@ class FX3 : public USBGeneric virtual bool Connect(uint16_t vid, uint16_t pid, const std::string& serial = "") override; virtual void Disconnect() override; + virtual bool IsConnected() override; + #ifndef __unix__ virtual int BeginDataXfer(uint8_t* buffer, uint32_t length, uint8_t endPointAddr) override; virtual bool WaitForXfer(int contextHandle, uint32_t timeout_ms) override; virtual int FinishDataXfer(uint8_t* buffer, uint32_t length, int contextHandle) override; virtual void AbortEndpointXfers(uint8_t endPointAddr) override; + + virtual int32_t BulkTransfer(uint8_t endPoint, uint8_t* data, int length, int32_t timeout_ms = defaultTimeout) override; + + virtual int32_t ControlTransfer( + int requestType, int request, int value, int index, uint8_t* data, uint32_t length, int32_t timeout_ms = defaultTimeout) + override; #endif virtual int GetUSBContextIndex() override; @@ -49,6 +57,20 @@ class FX3 : public USBGeneric CCyUSBEndPoint* InCtrlBulkEndPt; CCyUSBEndPoint* OutCtrlBulkEndPt; #endif + + static constexpr int CTR_W_REQCODE = 0xC1; + static constexpr int CTR_W_VALUE = 0x0000; + static constexpr int CTR_W_INDEX = 0x0000; + + static constexpr int CTR_R_REQCODE = 0xC0; + static constexpr int CTR_R_VALUE = 0x0000; + static constexpr int CTR_R_INDEX = 0x0000; + + static constexpr uint8_t CONTROL_BULK_OUT_ADDRESS = 0x0F; + static constexpr uint8_t CONTROL_BULK_IN_ADDRESS = 0x8F; + + static constexpr uint8_t STREAM_BULK_OUT_ADDRESS = 0x01; + static constexpr uint8_t STREAM_BULK_IN_ADDRESS = 0x81; }; } // namespace lime From 31b9e98cd953b88bdd5051c788b81de44d51d44d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Petkevi=C4=8Dius?= Date: Tue, 13 Feb 2024 12:29:47 +0200 Subject: [PATCH 06/22] Linux build fix --- src/boards/LimeSDR/USB_CSR_Pipe_SDR.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/boards/LimeSDR/USB_CSR_Pipe_SDR.cpp b/src/boards/LimeSDR/USB_CSR_Pipe_SDR.cpp index d35346685..e43da7696 100644 --- a/src/boards/LimeSDR/USB_CSR_Pipe_SDR.cpp +++ b/src/boards/LimeSDR/USB_CSR_Pipe_SDR.cpp @@ -37,8 +37,13 @@ int USB_CSR_Pipe_SDR::Write(const uint8_t* data, size_t length, int timeout_ms) } #ifdef __unix__ - return port.ControlTransfer( - LIBUSB_REQUEST_TYPE_VENDOR, CTR_W_REQCODE, CTR_W_VALUE, CTR_W_INDEX, const_cast(data), length, timeout_ms); + return port.ControlTransfer(LIBUSB_REQUEST_TYPE_VENDOR, + FX3::CTR_W_REQCODE, + FX3::CTR_W_VALUE, + FX3::CTR_W_INDEX, + const_cast(data), + length, + timeout_ms); #else return port.ControlTransfer(0, 0, 0, 0, const_cast(data), length, timeout_ms); #endif // __unix__ @@ -54,8 +59,13 @@ int USB_CSR_Pipe_SDR::Read(uint8_t* data, size_t length, int timeout_ms) } #ifdef __unix__ - return port.ControlTransfer( - LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN, CTR_R_REQCODE, CTR_R_VALUE, CTR_R_INDEX, data, length, timeout_ms); + return port.ControlTransfer(LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN, + FX3::CTR_R_REQCODE, + FX3::CTR_R_VALUE, + FX3::CTR_R_INDEX, + data, + length, + timeout_ms); #else return port.ControlTransfer(1, 0, 0, 0, const_cast(data), length, timeout_ms); #endif // __unix__ From 3989f838ea67b33fc3d23a71e1baec92041f49e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Petkevi=C4=8Dius?= Date: Tue, 13 Feb 2024 15:02:34 +0200 Subject: [PATCH 07/22] Minor changes --- src/comms/USB/FX3/FX3.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/comms/USB/FX3/FX3.cpp b/src/comms/USB/FX3/FX3.cpp index a9462205b..5b408ec87 100644 --- a/src/comms/USB/FX3/FX3.cpp +++ b/src/comms/USB/FX3/FX3.cpp @@ -39,15 +39,15 @@ bool FX3::Connect(uint16_t vid, uint16_t pid, const std::string& serial) { Disconnect(); #ifndef __unix__ - unsigned int index = 0; + unsigned char index = 0; if (index > USBDevicePrimary->DeviceCount()) { - return ReportError(ERANGE, "ConnectionSTREAM: Device index out of range"); + return ReportError(ERANGE, "FX3::Connect: Device index out of range"); } if (USBDevicePrimary->Open(index) == false) { - return ReportError(-1, "ConnectionSTREAM: Failed to open device"); + return ReportError(-1, "FX3::Connect: Failed to open device"); } if (InCtrlEndPt3) @@ -178,7 +178,7 @@ int32_t FX3::BulkTransfer(uint8_t endPoint, uint8_t* data, int length, int32_t t switch (endPoint) { case FX3::CONTROL_BULK_OUT_ADDRESS: // Write - if (OutCtrlEndPt3) + if (OutCtrlBulkEndPt) { LONG longLength = static_cast(length); if (OutCtrlBulkEndPt->XferData(data, longLength)) @@ -188,7 +188,7 @@ int32_t FX3::BulkTransfer(uint8_t endPoint, uint8_t* data, int length, int32_t t } break; case FX3::CONTROL_BULK_IN_ADDRESS: // Read - if (endPoint) + if (InCtrlBulkEndPt) { LONG longLength = static_cast(length); @@ -228,6 +228,8 @@ int32_t FX3::ControlTransfer(int requestType, int request, int value, int index, return length; } } + default: + throw std::logic_error("Invalid request type"); } return 0; } @@ -249,8 +251,7 @@ int FX3::BeginDataXfer(uint8_t* buffer, uint32_t length, uint8_t endPointAddr) if (OutEndPt[STREAM_BULK_OUT_ADDRESS]) { FX3context->EndPt = OutEndPt[STREAM_BULK_OUT_ADDRESS]; - FX3context->context = - FX3context->EndPt->BeginDataXfer(reinterpret_cast(buffer), length, FX3context->inOvLap); + FX3context->context = FX3context->EndPt->BeginDataXfer(buffer, length, FX3context->inOvLap); } break; @@ -282,8 +283,7 @@ bool FX3::WaitForXfer(int contextHandle, uint32_t timeout_ms) return true; //there is nothing to wait for (signal wait finished) } - int status = 0; - status = FX3context->EndPt->WaitForXfer(FX3context->inOvLap, timeout_ms); + bool status = FX3context->EndPt->WaitForXfer(FX3context->inOvLap, timeout_ms); return status; } @@ -301,12 +301,16 @@ int FX3::FinishDataXfer(uint8_t* buffer, uint32_t length, int contextHandle) return 0; } - int status = 0; long len = length; - status = - FX3context->EndPt->FinishDataXfer(reinterpret_cast(buffer), len, FX3context->inOvLap, FX3context->context); + bool status = FX3context->EndPt->FinishDataXfer(buffer, len, FX3context->inOvLap, FX3context->context); FX3context->used = false; FX3context->Reset(); + + if (!status) + { + return 0; + } + return len; } From 4dbbcc4e30b8712c3f854401234ba663b4900f0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Petkevi=C4=8Dius?= Date: Tue, 13 Feb 2024 15:19:06 +0200 Subject: [PATCH 08/22] Format fixes --- src/boards/LimeSDR/LimeSDREntry.cpp | 2 +- src/comms/USB/FX3/FX3.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/boards/LimeSDR/LimeSDREntry.cpp b/src/boards/LimeSDR/LimeSDREntry.cpp index 0e2ce69b5..fd3bc7c57 100644 --- a/src/boards/LimeSDR/LimeSDREntry.cpp +++ b/src/boards/LimeSDR/LimeSDREntry.cpp @@ -85,7 +85,7 @@ SDRDevice* LimeSDREntry::make(const DeviceHandle& handle) vid = std::stoi(handle.addr.substr(0, splitPos), nullptr, 16); pid = std::stoi(handle.addr.substr(splitPos + 1), nullptr, 16); } - + auto usbComms = std::make_shared( #ifdef __unix__ ctx diff --git a/src/comms/USB/FX3/FX3.h b/src/comms/USB/FX3/FX3.h index 82c949920..037376225 100644 --- a/src/comms/USB/FX3/FX3.h +++ b/src/comms/USB/FX3/FX3.h @@ -68,7 +68,7 @@ class FX3 : public USBGeneric static constexpr uint8_t CONTROL_BULK_OUT_ADDRESS = 0x0F; static constexpr uint8_t CONTROL_BULK_IN_ADDRESS = 0x8F; - + static constexpr uint8_t STREAM_BULK_OUT_ADDRESS = 0x01; static constexpr uint8_t STREAM_BULK_IN_ADDRESS = 0x81; }; From e971ecaaf9f053b864a24db5f885cd053261d286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Petkevi=C4=8Dius?= Date: Tue, 13 Feb 2024 15:21:33 +0200 Subject: [PATCH 09/22] Enable Windows GitHub Actions build --- .github/workflows/cmake.yml | 95 +++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 2bae504ab..94cdaf2ae 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -2,7 +2,7 @@ name: CMake on: push: - branches: [ master, litepcie-update ] + branches: [master, litepcie-update] pull_request: env: @@ -11,56 +11,57 @@ env: CMAKE_BUILD_PARALLEL_LEVEL: 2 SOAPY_SDR_BRANCH: master INSTALL_PREFIX: ${{github.workspace}}/deps - + jobs: build: runs-on: ${{ matrix.os }} strategy: - matrix: - os: [ubuntu-latest] - # os: [ubuntu-latest, macos-latest, windows-latest] + matrix: + os: + [ubuntu-latest, windows-latest] + # os: [ubuntu-latest, macos-latest, windows-latest] steps: - - uses: actions/checkout@v2 - - - name: Install linux dependencies - if: matrix.os == 'ubuntu-latest' - run: | - sudo apt-get update - sudo apt-get install -qq libusb-1.0-0-dev libwxbase3.0-dev libwxgtk3.0-gtk3-dev liboctave-dev - - - name: Install osx dependencies - if: matrix.os == 'macos-latest' - run: brew install libusb wxmac - - - name: Download windows dependencies - if: matrix.os == 'windows-latest' - run: | - mkdir ${{github.workspace}}/deps - curl -o ${{github.workspace}}/deps/FX3SDK.zip -L https://downloads.myriadrf.org/project/limesuite/appveyor/FX3SDK.zip - 7z x ${{github.workspace}}/deps/FX3SDK.zip -o${{github.workspace}}/deps/FX3SDK - curl -o ${{github.workspace}}/deps/wxWidgets-headers.7z -L https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.5/wxWidgets-3.1.5-headers.7z - 7z x ${{github.workspace}}/deps/wxWidgets-headers.7z -o${{github.workspace}}/deps/wxWidgets - curl -o ${{github.workspace}}/deps/wxWidgets.7z -L https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.5/wxMSW-3.1.5_vc14x_x64_Dev.7z - 7z x ${{github.workspace}}/deps/wxWidgets.7z -o${{github.workspace}}/deps/wxWidgets - - - name: install SoapySDR from source - run: | - git clone https://github.com/pothosware/SoapySDR.git - cd SoapySDR - git checkout ${{env.SOAPY_SDR_BRANCH}} - mkdir build && cd build - cmake ../ -DCMAKE_INSTALL_PREFIX=${{env.INSTALL_PREFIX}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENABLE_APPS=OFF -DENABLE_TESTS=OFF -DENABLE_PYTHON=OFF -DENABLE_PYTHON3=OFF - cmake --build . - cmake --build . --target install - - - name: Configure CMake (windows) - if: matrix.os == 'windows-latest' - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENABLE_EVB7COM=ON -DCMAKE_INSTALL_PREFIX=${{env.INSTALL_PREFIX}} -DwxWidgets_ROOT_DIR=${{github.workspace}}/deps/wxWidgets -DFX3_SDK_PATH=${{github.workspace}}/deps/FX3SDK - - - name: Configure CMake (linux) - if: matrix.os != 'windows-latest' - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENABLE_EVB7COM=ON -DCMAKE_INSTALL_PREFIX=${{env.INSTALL_PREFIX}} + - uses: actions/checkout@v2 + + - name: Install linux dependencies + if: matrix.os == 'ubuntu-latest' + run: | + sudo apt-get update + sudo apt-get install -qq libusb-1.0-0-dev libwxbase3.0-dev libwxgtk3.0-gtk3-dev liboctave-dev + + - name: Install osx dependencies + if: matrix.os == 'macos-latest' + run: brew install libusb wxmac + + - name: Download windows dependencies + if: matrix.os == 'windows-latest' + run: | + mkdir ${{github.workspace}}/deps + curl -o ${{github.workspace}}/deps/FX3SDK.zip -L https://downloads.myriadrf.org/project/limesuite/appveyor/FX3SDK.zip + 7z x ${{github.workspace}}/deps/FX3SDK.zip -o${{github.workspace}}/deps/FX3SDK + curl -o ${{github.workspace}}/deps/wxWidgets-headers.7z -L https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.5/wxWidgets-3.1.5-headers.7z + 7z x ${{github.workspace}}/deps/wxWidgets-headers.7z -o${{github.workspace}}/deps/wxWidgets + curl -o ${{github.workspace}}/deps/wxWidgets.7z -L https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.5/wxMSW-3.1.5_vc14x_x64_Dev.7z + 7z x ${{github.workspace}}/deps/wxWidgets.7z -o${{github.workspace}}/deps/wxWidgets + + - name: install SoapySDR from source + run: | + git clone https://github.com/pothosware/SoapySDR.git + cd SoapySDR + git checkout ${{env.SOAPY_SDR_BRANCH}} + mkdir build && cd build + cmake ../ -DCMAKE_INSTALL_PREFIX=${{env.INSTALL_PREFIX}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENABLE_APPS=OFF -DENABLE_TESTS=OFF -DENABLE_PYTHON=OFF -DENABLE_PYTHON3=OFF + cmake --build . + cmake --build . --target install + + - name: Configure CMake (windows) + if: matrix.os == 'windows-latest' + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENABLE_EVB7COM=ON -DCMAKE_INSTALL_PREFIX=${{env.INSTALL_PREFIX}} -DwxWidgets_ROOT_DIR=${{github.workspace}}/deps/wxWidgets -DFX3_SDK_PATH=${{github.workspace}}/deps/FX3SDK + + - name: Configure CMake (linux) + if: matrix.os != 'windows-latest' + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENABLE_EVB7COM=ON -DCMAKE_INSTALL_PREFIX=${{env.INSTALL_PREFIX}} - - name: Build - run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + - name: Build + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} From d3f270fdc9badf5645b2c958d30b5ff086eb8714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Petkevi=C4=8Dius?= Date: Tue, 13 Feb 2024 15:22:02 +0200 Subject: [PATCH 10/22] Auto-format other two workflows as well --- .github/workflows/clang-format.yml | 50 +++++++++---------- .github/workflows/gtest.yml | 79 +++++++++++++++--------------- 2 files changed, 65 insertions(+), 64 deletions(-) diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml index 0af565b3b..d3a5a82e3 100644 --- a/.github/workflows/clang-format.yml +++ b/.github/workflows/clang-format.yml @@ -2,7 +2,7 @@ name: clang-format on: push: - branches: [ master, litepcie-update ] + branches: [master, litepcie-update] pull_request: jobs: @@ -10,27 +10,27 @@ jobs: runs-on: [ubuntu-latest] steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get install -qq clang-format colordiff - - - name: Run clang-format - run: | - before="${{ github.event.pull_request.base.sha }}" - if [ "$before" == "" ]; then - before="${{ github.event.before }}" - fi - - diff=$(git-clang-format --diff --commit "$before") - [ "$diff" = "no modified files to format" ] && exit 0 - [ "$diff" = "clang-format did not modify any files" ] && exit 0 - - printf "\033[1mYou have introduced coding style breakages, suggested changes:\n\n" - - echo "$diff" | colordiff - exit 1 + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -qq clang-format colordiff + + - name: Run clang-format + run: | + before="${{ github.event.pull_request.base.sha }}" + if [ "$before" == "" ]; then + before="${{ github.event.before }}" + fi + + diff=$(git-clang-format --diff --commit "$before") + [ "$diff" = "no modified files to format" ] && exit 0 + [ "$diff" = "clang-format did not modify any files" ] && exit 0 + + printf "\033[1mYou have introduced coding style breakages, suggested changes:\n\n" + + echo "$diff" | colordiff + exit 1 diff --git a/.github/workflows/gtest.yml b/.github/workflows/gtest.yml index 69f016834..f4fe23126 100644 --- a/.github/workflows/gtest.yml +++ b/.github/workflows/gtest.yml @@ -2,7 +2,7 @@ name: GTest tests on: push: - branches: [ master, litepcie-update ] + branches: [master, litepcie-update] pull_request: env: @@ -16,43 +16,44 @@ jobs: build: runs-on: ${{ matrix.os }} strategy: - matrix: - os: [ubuntu-latest] - # os: [ubuntu-latest, macos-latest, windows-latest] + matrix: + os: + [ubuntu-latest] + # os: [ubuntu-latest, macos-latest, windows-latest] steps: - - uses: actions/checkout@v2 - - - name: Install linux dependencies - if: matrix.os == 'ubuntu-latest' - run: | - sudo apt-get update - sudo apt-get install -qq libusb-1.0-0-dev - - - name: Install osx dependencies - if: matrix.os == 'macos-latest' - run: brew install libusb wxmac - - - name: Download windows dependencies - if: matrix.os == 'windows-latest' - run: | - mkdir ${{github.workspace}}/deps - curl -o ${{github.workspace}}/deps/FX3SDK.zip -L https://downloads.myriadrf.org/project/limesuite/appveyor/FX3SDK.zip - 7z x ${{github.workspace}}/deps/FX3SDK.zip -o${{github.workspace}}/deps/FX3SDK - curl -o ${{github.workspace}}/deps/wxWidgets-headers.7z -L https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.5/wxWidgets-3.1.5-headers.7z - 7z x ${{github.workspace}}/deps/wxWidgets-headers.7z -o${{github.workspace}}/deps/wxWidgets - curl -o ${{github.workspace}}/deps/wxWidgets.7z -L https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.5/wxMSW-3.1.5_vc14x_x64_Dev.7z - 7z x ${{github.workspace}}/deps/wxWidgets.7z -o${{github.workspace}}/deps/wxWidgets - - - name: Configure CMake (windows) - if: matrix.os == 'windows-latest' - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENABLE_EVB7COM=ON -DCMAKE_INSTALL_PREFIX=${{env.INSTALL_PREFIX}} -DwxWidgets_ROOT_DIR=${{github.workspace}}/deps/wxWidgets -DFX3_SDK_PATH=${{github.workspace}}/deps/FX3SDK - - - name: Configure CMake (linux) - if: matrix.os != 'windows-latest' - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENABLE_EVB7COM=ON -DCMAKE_INSTALL_PREFIX=${{env.INSTALL_PREFIX}} -DBUILD_SHARED_LIBS=OFF -DBINARY_OUTPUT_DIR=${{github.workspace}}/build/bin/ - - - name: Build and run tests - run: | - cmake --build ${{github.workspace}}/build --config LimeSuite2Test - ${{github.workspace}}/build/bin/LimeSuite2Test + - uses: actions/checkout@v2 + + - name: Install linux dependencies + if: matrix.os == 'ubuntu-latest' + run: | + sudo apt-get update + sudo apt-get install -qq libusb-1.0-0-dev + + - name: Install osx dependencies + if: matrix.os == 'macos-latest' + run: brew install libusb wxmac + + - name: Download windows dependencies + if: matrix.os == 'windows-latest' + run: | + mkdir ${{github.workspace}}/deps + curl -o ${{github.workspace}}/deps/FX3SDK.zip -L https://downloads.myriadrf.org/project/limesuite/appveyor/FX3SDK.zip + 7z x ${{github.workspace}}/deps/FX3SDK.zip -o${{github.workspace}}/deps/FX3SDK + curl -o ${{github.workspace}}/deps/wxWidgets-headers.7z -L https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.5/wxWidgets-3.1.5-headers.7z + 7z x ${{github.workspace}}/deps/wxWidgets-headers.7z -o${{github.workspace}}/deps/wxWidgets + curl -o ${{github.workspace}}/deps/wxWidgets.7z -L https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.5/wxMSW-3.1.5_vc14x_x64_Dev.7z + 7z x ${{github.workspace}}/deps/wxWidgets.7z -o${{github.workspace}}/deps/wxWidgets + + - name: Configure CMake (windows) + if: matrix.os == 'windows-latest' + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENABLE_EVB7COM=ON -DCMAKE_INSTALL_PREFIX=${{env.INSTALL_PREFIX}} -DwxWidgets_ROOT_DIR=${{github.workspace}}/deps/wxWidgets -DFX3_SDK_PATH=${{github.workspace}}/deps/FX3SDK + + - name: Configure CMake (linux) + if: matrix.os != 'windows-latest' + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENABLE_EVB7COM=ON -DCMAKE_INSTALL_PREFIX=${{env.INSTALL_PREFIX}} -DBUILD_SHARED_LIBS=OFF -DBINARY_OUTPUT_DIR=${{github.workspace}}/build/bin/ + + - name: Build and run tests + run: | + cmake --build ${{github.workspace}}/build --config LimeSuite2Test + ${{github.workspace}}/build/bin/LimeSuite2Test From 4211fe93af062bf8e8fb71cadc94f3766385b3be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Petkevi=C4=8Dius?= Date: Tue, 13 Feb 2024 15:33:17 +0200 Subject: [PATCH 11/22] Update wxWidgets --- .github/workflows/cmake.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 94cdaf2ae..e51b1cec7 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -40,9 +40,9 @@ jobs: mkdir ${{github.workspace}}/deps curl -o ${{github.workspace}}/deps/FX3SDK.zip -L https://downloads.myriadrf.org/project/limesuite/appveyor/FX3SDK.zip 7z x ${{github.workspace}}/deps/FX3SDK.zip -o${{github.workspace}}/deps/FX3SDK - curl -o ${{github.workspace}}/deps/wxWidgets-headers.7z -L https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.5/wxWidgets-3.1.5-headers.7z + curl -o ${{github.workspace}}/deps/wxWidgets-headers.7z -L https://github.com/wxWidgets/wxWidgets/releases/download/v3.2.4/wxWidgets-3.2.4-headers.7z 7z x ${{github.workspace}}/deps/wxWidgets-headers.7z -o${{github.workspace}}/deps/wxWidgets - curl -o ${{github.workspace}}/deps/wxWidgets.7z -L https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.5/wxMSW-3.1.5_vc14x_x64_Dev.7z + curl -o ${{github.workspace}}/deps/wxWidgets.7z -L https://github.com/wxWidgets/wxWidgets/releases/download/v3.2.4/wxMSW-3.2.4_vc14x_x64_Dev.7z 7z x ${{github.workspace}}/deps/wxWidgets.7z -o${{github.workspace}}/deps/wxWidgets - name: install SoapySDR from source From c261736b864ca0819ee29f0674a3dff55d97fbc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Petkevi=C4=8Dius?= Date: Tue, 13 Feb 2024 16:36:30 +0200 Subject: [PATCH 12/22] Removing the -NOGDI tag to fix a compile error, have to add in some `#undef ERROR` instead, because Windows --- CMakeLists.txt | 2 +- src/Logger.cpp | 1 + src/Logger.h | 2 ++ src/cli/limeConfig.cpp | 2 ++ src/cli/limeTRX.cpp | 2 ++ src/include/limesuite/OpStatus.h | 2 ++ src/utilities_gui/pnlMiniLog.cpp | 2 ++ 7 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2710917a9..95e72e6fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -135,7 +135,7 @@ endif() if (MSVC) include_directories(${PROJECT_SOURCE_DIR}/external/msvc) - add_definitions(-D_CRT_SECURE_NO_WARNINGS -DNOGDI -DNOMINMAX) + add_definitions(-D_CRT_SECURE_NO_WARNINGS -DNOMINMAX) set( MSVC_MULTITHREAD_COMPILE_FLAGS "/MP") set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MSVC_MULTITHREAD_COMPILE_FLAGS}" ) diff --git a/src/Logger.cpp b/src/Logger.cpp index 0b1bdfe86..b1e5757d0 100644 --- a/src/Logger.cpp +++ b/src/Logger.cpp @@ -11,6 +11,7 @@ #ifdef _MSC_VER #define thread_local __declspec(thread) #include + #undef ERROR #endif #ifdef __APPLE__ diff --git a/src/Logger.h b/src/Logger.h index b4a0a38c5..5a21272c7 100644 --- a/src/Logger.h +++ b/src/Logger.h @@ -15,6 +15,8 @@ #include #include +#undef ERROR + namespace lime { enum class LogLevel : uint8_t { diff --git a/src/cli/limeConfig.cpp b/src/cli/limeConfig.cpp index 5e88fae3f..a958e00f2 100644 --- a/src/cli/limeConfig.cpp +++ b/src/cli/limeConfig.cpp @@ -5,6 +5,8 @@ #include #include +#undef ERROR + using namespace std; using namespace lime; diff --git a/src/cli/limeTRX.cpp b/src/cli/limeTRX.cpp index 563b6653f..9b926895d 100644 --- a/src/cli/limeTRX.cpp +++ b/src/cli/limeTRX.cpp @@ -20,6 +20,8 @@ using namespace lime; using namespace std; +#undef ERROR + std::mutex globalGnuPlotMutex; // Seems multiple plot pipes can't be used concurently bool stopProgram(false); diff --git a/src/include/limesuite/OpStatus.h b/src/include/limesuite/OpStatus.h index 915b506d4..78f107afa 100644 --- a/src/include/limesuite/OpStatus.h +++ b/src/include/limesuite/OpStatus.h @@ -1,6 +1,8 @@ #ifndef LIME_OPSTATUS_H #define LIME_OPSTATUS_H +#undef ERROR + namespace lime { enum class OpStatus { diff --git a/src/utilities_gui/pnlMiniLog.cpp b/src/utilities_gui/pnlMiniLog.cpp index 90654f68a..dc9a94c30 100644 --- a/src/utilities_gui/pnlMiniLog.cpp +++ b/src/utilities_gui/pnlMiniLog.cpp @@ -1,6 +1,8 @@ #include "pnlMiniLog.h" #include "dlgFullMessageLog.h" +#undef ERROR + static wxTextAttr mDefaultStyle; pnlMiniLog::pnlMiniLog(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) From e76d52ccda7bda52a8762d7b1412f683acadc123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Petkevi=C4=8Dius?= Date: Wed, 14 Feb 2024 10:15:19 +0200 Subject: [PATCH 13/22] Remove some unnecessary "Windows.h" includes --- external/msvc/getopt.h | 1 - src/SystemResources.in.cpp | 2 ++ src/boards/LimeSDR/LimeSDREntry.cpp | 1 - src/boards/LimeSDR_Mini/LimeSDR_MiniEntry.cpp | 1 + src/boards_wxgui/pnlBoardControls.cpp | 5 +++-- src/cli/limeConfig.cpp | 2 -- src/cli/limeTRX.cpp | 8 +++----- src/comms/USB/FX3/FX3.h | 1 - src/comms/USB/FX3/USBTransferContext_FX3.h | 1 + src/comms/USB/USBTransferContext.h | 1 + src/threadHelper/threadHelper.cpp | 1 + 11 files changed, 12 insertions(+), 12 deletions(-) diff --git a/external/msvc/getopt.h b/external/msvc/getopt.h index 6c834b48d..90db90488 100644 --- a/external/msvc/getopt.h +++ b/external/msvc/getopt.h @@ -21,7 +21,6 @@ #include #include #include -#include #ifdef __cplusplus extern "C" { diff --git a/src/SystemResources.in.cpp b/src/SystemResources.in.cpp index fac4ec4f4..db5b1fbb6 100644 --- a/src/SystemResources.in.cpp +++ b/src/SystemResources.in.cpp @@ -17,6 +17,8 @@ #include #include + #undef ERROR + //access mode constants #define F_OK 0 #define R_OK 2 diff --git a/src/boards/LimeSDR/LimeSDREntry.cpp b/src/boards/LimeSDR/LimeSDREntry.cpp index fd3bc7c57..f47112b87 100644 --- a/src/boards/LimeSDR/LimeSDREntry.cpp +++ b/src/boards/LimeSDR/LimeSDREntry.cpp @@ -9,7 +9,6 @@ #include #ifndef __unix__ - #include "windows.h" #include "CyAPI.h" #else #ifdef __GNUC__ diff --git a/src/boards/LimeSDR_Mini/LimeSDR_MiniEntry.cpp b/src/boards/LimeSDR_Mini/LimeSDR_MiniEntry.cpp index 4741a74b0..c4072150f 100644 --- a/src/boards/LimeSDR_Mini/LimeSDR_MiniEntry.cpp +++ b/src/boards/LimeSDR_Mini/LimeSDR_MiniEntry.cpp @@ -14,6 +14,7 @@ #ifndef __unix__ #include "windows.h" #include "FTD3XXLibrary/FTD3XX.h" + #undef ERROR #else #ifdef __GNUC__ #pragma GCC diagnostic push diff --git a/src/boards_wxgui/pnlBoardControls.cpp b/src/boards_wxgui/pnlBoardControls.cpp index c50f89814..bd36caea8 100644 --- a/src/boards_wxgui/pnlBoardControls.cpp +++ b/src/boards_wxgui/pnlBoardControls.cpp @@ -1,13 +1,15 @@ #include "pnlBoardControls.h" #include -#include "lime/LimeSuite.h" #ifdef __BORLANDC__ #pragma hdrstop #endif //__BORLANDC__ #ifndef WX_PRECOMP #include #endif //WX_PRECOMP +#include +#undef ERROR +#include "lime/LimeSuite.h" #include "pnluLimeSDR.h" #include "pnlLimeSDR.h" #include "pnlBuffers.h" @@ -16,7 +18,6 @@ #include "ADCUnits.h" #include -#include #include #include "lms7suiteEvents.h" #include "limesuite/SDRDevice.h" diff --git a/src/cli/limeConfig.cpp b/src/cli/limeConfig.cpp index a958e00f2..5e88fae3f 100644 --- a/src/cli/limeConfig.cpp +++ b/src/cli/limeConfig.cpp @@ -5,8 +5,6 @@ #include #include -#undef ERROR - using namespace std; using namespace lime; diff --git a/src/cli/limeTRX.cpp b/src/cli/limeTRX.cpp index 9b926895d..a9fe0c135 100644 --- a/src/cli/limeTRX.cpp +++ b/src/cli/limeTRX.cpp @@ -20,14 +20,12 @@ using namespace lime; using namespace std; -#undef ERROR - -std::mutex globalGnuPlotMutex; // Seems multiple plot pipes can't be used concurently +std::mutex globalGnuPlotMutex; // Seems multiple plot pipes can't be used concurrently bool stopProgram(false); void intHandler(int dummy) { - //std::cerr << "Stoppping\n"; + //std::cerr << "Stopping\n"; stopProgram = true; } @@ -66,7 +64,7 @@ static int printHelp(void) cerr << " -s, --samplesCount\t\t Number of samples to receive" << endl; cerr << " -t, --time\t\t Time duration in milliseconds to receive" << endl; cerr << " -f, --fft\t\t Display Rx FFT plot" << endl; - cerr << " --contellation\t\t Display IQ constellation plot" << endl; + cerr << " --constellation\t\t Display IQ constellation plot" << endl; cerr << " -l, --log\t\t Log verbosity: info, warning, error, verbose, debug" << endl; cerr << " --mimo [channelCount]\t\t use multiple channels" << endl; cerr << " --repeater [delaySamples]\t\t retransmit received samples with a delay" << endl; diff --git a/src/comms/USB/FX3/FX3.h b/src/comms/USB/FX3/FX3.h index 037376225..feb6181c8 100644 --- a/src/comms/USB/FX3/FX3.h +++ b/src/comms/USB/FX3/FX3.h @@ -10,7 +10,6 @@ #include #ifndef __unix__ - #include "windows.h" #include "CyAPI.h" #endif // !__unix__ diff --git a/src/comms/USB/FX3/USBTransferContext_FX3.h b/src/comms/USB/FX3/USBTransferContext_FX3.h index 994275317..5774006ba 100644 --- a/src/comms/USB/FX3/USBTransferContext_FX3.h +++ b/src/comms/USB/FX3/USBTransferContext_FX3.h @@ -6,6 +6,7 @@ #ifndef __unix__ #include "windows.h" #include "CyAPI.h" + #undef ERROR #endif namespace lime { diff --git a/src/comms/USB/USBTransferContext.h b/src/comms/USB/USBTransferContext.h index 49bb01065..7d60d26e8 100644 --- a/src/comms/USB/USBTransferContext.h +++ b/src/comms/USB/USBTransferContext.h @@ -18,6 +18,7 @@ #ifndef __unix__ #include + #undef ERROR #endif namespace lime { diff --git a/src/threadHelper/threadHelper.cpp b/src/threadHelper/threadHelper.cpp index 7a826dbc6..30448b47c 100644 --- a/src/threadHelper/threadHelper.cpp +++ b/src/threadHelper/threadHelper.cpp @@ -4,6 +4,7 @@ #include #else #include + #undef ERROR #endif #include "Logger.h" From d83f8affaa3374a206995f33af14b4b84b21fd1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Petkevi=C4=8Dius?= Date: Wed, 14 Feb 2024 10:44:21 +0200 Subject: [PATCH 14/22] Add a mutex to FX3 code, fix multithreading issues --- src/comms/USB/FX3/FX3.cpp | 19 ++++++++++++++++++- src/comms/USB/FX3/FX3.h | 2 ++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/comms/USB/FX3/FX3.cpp b/src/comms/USB/FX3/FX3.cpp index 5b408ec87..42337fa74 100644 --- a/src/comms/USB/FX3/FX3.cpp +++ b/src/comms/USB/FX3/FX3.cpp @@ -9,6 +9,8 @@ FX3::FX3(void* usbContext) : USBGeneric(usbContext) { #ifndef __unix__ + std::scoped_lock lock{ FX3mutex }; + if (usbContext == nullptr) { USBDevicePrimary = new CCyFX3Device(); @@ -39,6 +41,8 @@ bool FX3::Connect(uint16_t vid, uint16_t pid, const std::string& serial) { Disconnect(); #ifndef __unix__ + std::scoped_lock lock{ FX3mutex }; + unsigned char index = 0; if (index > USBDevicePrimary->DeviceCount()) { @@ -139,6 +143,8 @@ void FX3::Disconnect() dev_handle = nullptr; } #else + std::scoped_lock lock{ FX3mutex }; + USBDevicePrimary->Close(); for (int i = 0; i < MAX_EP_CNT; ++i) { @@ -166,6 +172,8 @@ void FX3::Disconnect() bool FX3::IsConnected() { #ifndef __unix__ + std::scoped_lock lock{ FX3mutex }; + return USBDevicePrimary->IsOpen() && isConnected; #else return isConnected; @@ -175,6 +183,8 @@ bool FX3::IsConnected() #ifndef __unix__ int32_t FX3::BulkTransfer(uint8_t endPoint, uint8_t* data, int length, int32_t timeout_ms) { + std::scoped_lock lock{ FX3mutex }; + switch (endPoint) { case FX3::CONTROL_BULK_OUT_ADDRESS: // Write @@ -206,6 +216,8 @@ int32_t FX3::BulkTransfer(uint8_t endPoint, uint8_t* data, int length, int32_t t int32_t FX3::ControlTransfer(int requestType, int request, int value, int index, uint8_t* data, uint32_t length, int32_t timeout_ms) { + std::scoped_lock lock{ FX3mutex }; + switch (requestType) { case 0: // Write @@ -228,6 +240,7 @@ int32_t FX3::ControlTransfer(int requestType, int request, int value, int index, return length; } } + break; default: throw std::logic_error("Invalid request type"); } @@ -243,6 +256,7 @@ int FX3::BeginDataXfer(uint8_t* buffer, uint32_t length, uint8_t endPointAddr) return -1; } + std::scoped_lock lock{ FX3mutex }; USBTransferContext_FX3* FX3context = &static_cast(contexts)[index]; switch (endPointAddr) @@ -253,7 +267,6 @@ int FX3::BeginDataXfer(uint8_t* buffer, uint32_t length, uint8_t endPointAddr) FX3context->EndPt = OutEndPt[STREAM_BULK_OUT_ADDRESS]; FX3context->context = FX3context->EndPt->BeginDataXfer(buffer, length, FX3context->inOvLap); } - break; case FX3::STREAM_BULK_IN_ADDRESS: // Rx/Read if (InEndPt[endPointAddr & 0xF]) @@ -301,6 +314,8 @@ int FX3::FinishDataXfer(uint8_t* buffer, uint32_t length, int contextHandle) return 0; } + std::scoped_lock lock{ FX3mutex }; + long len = length; bool status = FX3context->EndPt->FinishDataXfer(buffer, len, FX3context->inOvLap, FX3context->context); FX3context->used = false; @@ -316,6 +331,8 @@ int FX3::FinishDataXfer(uint8_t* buffer, uint32_t length, int contextHandle) void FX3::AbortEndpointXfers(uint8_t endPointAddr) { + std::scoped_lock lock{ FX3mutex }; + for (int i = 0; i < MAX_EP_CNT; i++) { if (InEndPt[i] && InEndPt[i]->Address == endPointAddr) diff --git a/src/comms/USB/FX3/FX3.h b/src/comms/USB/FX3/FX3.h index feb6181c8..8ffcf6a49 100644 --- a/src/comms/USB/FX3/FX3.h +++ b/src/comms/USB/FX3/FX3.h @@ -55,6 +55,8 @@ class FX3 : public USBGeneric CCyUSBEndPoint* InCtrlBulkEndPt; CCyUSBEndPoint* OutCtrlBulkEndPt; + + std::mutex FX3mutex; #endif static constexpr int CTR_W_REQCODE = 0xC1; From 1d20c740dd99e95943b3aa592292c8b959937125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Petkevi=C4=8Dius?= Date: Wed, 14 Feb 2024 11:04:18 +0200 Subject: [PATCH 15/22] Add string literals in FX3 throws --- src/comms/USB/FX3/FX3.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/comms/USB/FX3/FX3.cpp b/src/comms/USB/FX3/FX3.cpp index 42337fa74..b7acc228f 100644 --- a/src/comms/USB/FX3/FX3.cpp +++ b/src/comms/USB/FX3/FX3.cpp @@ -209,7 +209,7 @@ int32_t FX3::BulkTransfer(uint8_t endPoint, uint8_t* data, int length, int32_t t } break; default: - throw std::logic_error("Invalid endpoint"); + throw std::logic_error("Invalid endpoint"s); } return 0; } @@ -242,7 +242,7 @@ int32_t FX3::ControlTransfer(int requestType, int request, int value, int index, } break; default: - throw std::logic_error("Invalid request type"); + throw std::logic_error("Invalid request type"s); } return 0; } @@ -276,7 +276,7 @@ int FX3::BeginDataXfer(uint8_t* buffer, uint32_t length, uint8_t endPointAddr) } break; default: - throw std::logic_error("Invalid endpoint for an FX3 connection"); + throw std::logic_error("Invalid endpoint for an FX3 connection"s); } return index; From 76e426b4b57924b073248eb4457124cf34ae9f3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Petkevi=C4=8Dius?= Date: Wed, 14 Feb 2024 11:09:59 +0200 Subject: [PATCH 16/22] Reimplement USBGeneric::WaitForXfers for Windows as well --- src/comms/USB/USBGeneric.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/comms/USB/USBGeneric.cpp b/src/comms/USB/USBGeneric.cpp index 912d25079..871e6f442 100644 --- a/src/comms/USB/USBGeneric.cpp +++ b/src/comms/USB/USBGeneric.cpp @@ -390,16 +390,18 @@ int USBGeneric::GetUSBContextIndex() void USBGeneric::WaitForXfers(uint8_t endPointAddr) { -#ifdef __unix__ for (int i = 0; i < USB_MAX_CONTEXTS; ++i) { +#ifdef __unix__ if (contexts[i].used && contexts[i].transfer->endpoint == endPointAddr) +#else + if (contexts[i].used) +#endif { WaitForXfer(i, 250); FinishDataXfer(nullptr, 0, i); } } -#endif } } // namespace lime From f51971de609c0c3a6df3b5609798921a5909dffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Petkevi=C4=8Dius?= Date: Wed, 14 Feb 2024 11:28:54 +0200 Subject: [PATCH 17/22] Properly fix up WaitForXfers --- src/comms/USB/FT601/FT601.cpp | 16 +++++++++++++++- src/comms/USB/FT601/FT601.h | 1 + src/comms/USB/FX3/FX3.cpp | 19 +++++++++++++++++-- src/comms/USB/FX3/FX3.h | 31 +++++++++++++++++-------------- src/comms/USB/USBGeneric.cpp | 6 ++---- 5 files changed, 52 insertions(+), 21 deletions(-) diff --git a/src/comms/USB/FT601/FT601.cpp b/src/comms/USB/FT601/FT601.cpp index c3b180322..9a4c5fc9f 100644 --- a/src/comms/USB/FT601/FT601.cpp +++ b/src/comms/USB/FT601/FT601.cpp @@ -241,7 +241,7 @@ void FT601::AbortEndpointXfers(uint8_t endPointAddr) { USBTransferContext_FT601* context = &dynamic_cast(contexts)[i]; - if (context->used == true && context->endPointAddr == endPointAddr) + if (context->used && context->endPointAddr == endPointAddr) { FT_ReleaseOverlapped(mFTHandle, context->inOvLap); context->used = false; @@ -257,6 +257,20 @@ void FT601::AbortEndpointXfers(uint8_t endPointAddr) WaitForXfers(endPointAddr); } + +void FT601::WaitForXfers(uint8_t endPointAddr) +{ + for (int i = 0; i < USB_MAX_CONTEXTS; ++i) + { + USBTransferContext_FT601* context = &dynamic_cast(contexts)[i]; + + if (context->endPointAddr == endPointAddr) + { + WaitForXfer(i, 250); + FinishDataXfer(nullptr, 0, i); + } + } +} #endif int FT601::GetUSBContextIndex() diff --git a/src/comms/USB/FT601/FT601.h b/src/comms/USB/FT601/FT601.h index 6a87fcdcf..25187be21 100644 --- a/src/comms/USB/FT601/FT601.h +++ b/src/comms/USB/FT601/FT601.h @@ -47,6 +47,7 @@ class FT601 : public USBGeneric #ifndef __unix__ FT_HANDLE mFTHandle; int ReinitPipe(unsigned char ep); + virtual void WaitForXfers(uint8_t endPointAddr) override; #else int FT_SetStreamPipe(unsigned char ep, size_t size); int FT_FlushPipe(unsigned char ep); diff --git a/src/comms/USB/FX3/FX3.cpp b/src/comms/USB/FX3/FX3.cpp index b7acc228f..700173ee4 100644 --- a/src/comms/USB/FX3/FX3.cpp +++ b/src/comms/USB/FX3/FX3.cpp @@ -331,10 +331,10 @@ int FX3::FinishDataXfer(uint8_t* buffer, uint32_t length, int contextHandle) void FX3::AbortEndpointXfers(uint8_t endPointAddr) { - std::scoped_lock lock{ FX3mutex }; - for (int i = 0; i < MAX_EP_CNT; i++) { + std::scoped_lock lock{ FX3mutex }; + if (InEndPt[i] && InEndPt[i]->Address == endPointAddr) { InEndPt[i]->Abort(); @@ -348,6 +348,21 @@ void FX3::AbortEndpointXfers(uint8_t endPointAddr) WaitForXfers(endPointAddr); } + +void FX3::WaitForXfers(uint8_t endPointAddr) +{ + for (int i = 0; i < USB_MAX_CONTEXTS; ++i) + { + USBTransferContext_FX3* FX3context = &static_cast(contexts)[i]; + + if (FX3context->used && + ((OutEndPt[i] && OutEndPt[i]->Address == endPointAddr) || (InEndPt[i] && InEndPt[i]->Address == endPointAddr))) + { + WaitForXfer(i, 250); + FinishDataXfer(nullptr, 0, i); + } + } +} #endif int FX3::GetUSBContextIndex() diff --git a/src/comms/USB/FX3/FX3.h b/src/comms/USB/FX3/FX3.h index 8ffcf6a49..a5ccfc12b 100644 --- a/src/comms/USB/FX3/FX3.h +++ b/src/comms/USB/FX3/FX3.h @@ -40,9 +40,26 @@ class FX3 : public USBGeneric override; #endif + static constexpr int CTR_W_REQCODE = 0xC1; + static constexpr int CTR_W_VALUE = 0x0000; + static constexpr int CTR_W_INDEX = 0x0000; + + static constexpr int CTR_R_REQCODE = 0xC0; + static constexpr int CTR_R_VALUE = 0x0000; + static constexpr int CTR_R_INDEX = 0x0000; + + static constexpr uint8_t CONTROL_BULK_OUT_ADDRESS = 0x0F; + static constexpr uint8_t CONTROL_BULK_IN_ADDRESS = 0x8F; + + static constexpr uint8_t STREAM_BULK_OUT_ADDRESS = 0x01; + static constexpr uint8_t STREAM_BULK_IN_ADDRESS = 0x81; + + protected: virtual int GetUSBContextIndex() override; #ifndef __unix__ + virtual void WaitForXfers(uint8_t endPointAddr) override; + static const int MAX_EP_CNT = 16; CCyFX3Device* USBDevicePrimary; //control endpoints @@ -58,20 +75,6 @@ class FX3 : public USBGeneric std::mutex FX3mutex; #endif - - static constexpr int CTR_W_REQCODE = 0xC1; - static constexpr int CTR_W_VALUE = 0x0000; - static constexpr int CTR_W_INDEX = 0x0000; - - static constexpr int CTR_R_REQCODE = 0xC0; - static constexpr int CTR_R_VALUE = 0x0000; - static constexpr int CTR_R_INDEX = 0x0000; - - static constexpr uint8_t CONTROL_BULK_OUT_ADDRESS = 0x0F; - static constexpr uint8_t CONTROL_BULK_IN_ADDRESS = 0x8F; - - static constexpr uint8_t STREAM_BULK_OUT_ADDRESS = 0x01; - static constexpr uint8_t STREAM_BULK_IN_ADDRESS = 0x81; }; } // namespace lime diff --git a/src/comms/USB/USBGeneric.cpp b/src/comms/USB/USBGeneric.cpp index 871e6f442..912d25079 100644 --- a/src/comms/USB/USBGeneric.cpp +++ b/src/comms/USB/USBGeneric.cpp @@ -390,18 +390,16 @@ int USBGeneric::GetUSBContextIndex() void USBGeneric::WaitForXfers(uint8_t endPointAddr) { +#ifdef __unix__ for (int i = 0; i < USB_MAX_CONTEXTS; ++i) { -#ifdef __unix__ if (contexts[i].used && contexts[i].transfer->endpoint == endPointAddr) -#else - if (contexts[i].used) -#endif { WaitForXfer(i, 250); FinishDataXfer(nullptr, 0, i); } } +#endif } } // namespace lime From 72788f520d98b93dab12ff3a8fbc2882ea578a7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Petkevi=C4=8Dius?= Date: Wed, 14 Feb 2024 14:00:25 +0200 Subject: [PATCH 18/22] Get GTest to build on Windows --- CMakeLists.txt | 5 ++- src/boards/LimeSDR/USB_CSR_Pipe_SDR.cpp | 20 +++++---- src/boards/LimeSDR_X3/SlaveSelectShim.h | 3 +- src/tests/CMakeLists.txt | 32 +++++++++++--- .../boards/LimeSDR/USB_CSR_Pipe_SDRTest.cpp | 43 +++++++++++-------- .../boards/LimeSDR_X3/SlaveSelectShimTest.cpp | 2 +- src/tests/comms/PCIe/LitePCIeMock.h | 2 +- src/tests/comms/PCIe/PCIE_CSR_PipeTest.cpp | 2 +- 8 files changed, 71 insertions(+), 38 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 95e72e6fe..5194a0bf3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -182,8 +182,11 @@ if(ENABLE_TESTING) set(INSTALL_GMOCK OFF) # Don't install the GMock headers set(INSTALL_GTEST OFF) # Don't install the GTest headers - FetchContent_MakeAvailable(googletest) + if (MSVC) + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + endif() + FetchContent_MakeAvailable(googletest) enable_testing() endif() diff --git a/src/boards/LimeSDR/USB_CSR_Pipe_SDR.cpp b/src/boards/LimeSDR/USB_CSR_Pipe_SDR.cpp index e43da7696..ebac15a50 100644 --- a/src/boards/LimeSDR/USB_CSR_Pipe_SDR.cpp +++ b/src/boards/LimeSDR/USB_CSR_Pipe_SDR.cpp @@ -36,17 +36,19 @@ int USB_CSR_Pipe_SDR::Write(const uint8_t* data, size_t length, int timeout_ms) return port.BulkTransfer(FX3::CONTROL_BULK_OUT_ADDRESS, const_cast(data), length, timeout_ms); } + return port.ControlTransfer( #ifdef __unix__ - return port.ControlTransfer(LIBUSB_REQUEST_TYPE_VENDOR, + LIBUSB_REQUEST_TYPE_VENDOR +#else + 0 +#endif // __unix__ + , FX3::CTR_W_REQCODE, FX3::CTR_W_VALUE, FX3::CTR_W_INDEX, const_cast(data), length, timeout_ms); -#else - return port.ControlTransfer(0, 0, 0, 0, const_cast(data), length, timeout_ms); -#endif // __unix__ } int USB_CSR_Pipe_SDR::Read(uint8_t* data, size_t length, int timeout_ms) @@ -58,15 +60,17 @@ int USB_CSR_Pipe_SDR::Read(uint8_t* data, size_t length, int timeout_ms) return port.BulkTransfer(FX3::CONTROL_BULK_IN_ADDRESS, data, length, timeout_ms); } + return port.ControlTransfer( #ifdef __unix__ - return port.ControlTransfer(LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN, + LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN +#else + 1 +#endif // __unix__ + , FX3::CTR_R_REQCODE, FX3::CTR_R_VALUE, FX3::CTR_R_INDEX, data, length, timeout_ms); -#else - return port.ControlTransfer(1, 0, 0, 0, const_cast(data), length, timeout_ms); -#endif // __unix__ } diff --git a/src/boards/LimeSDR_X3/SlaveSelectShim.h b/src/boards/LimeSDR_X3/SlaveSelectShim.h index ba9308342..ad4ab1a8f 100644 --- a/src/boards/LimeSDR_X3/SlaveSelectShim.h +++ b/src/boards/LimeSDR_X3/SlaveSelectShim.h @@ -1,13 +1,14 @@ #ifndef LIME_SLAVESELECTSHIM_H #define LIME_SLAVESELECTSHIM_H +#include "limesuite/config.h" #include "limesuite/IComms.h" #include namespace lime { /** @brief Communications helper to divert data to specific device. */ -class SlaveSelectShim : public ISPI +class LIME_API SlaveSelectShim : public ISPI { public: SlaveSelectShim(std::shared_ptr comms, uint32_t slaveId); diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index ef5160fe0..5e45e05e0 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -1,12 +1,6 @@ set(LIME_TEST_SUITE_NAME LimeSuite2Test) set(LIME_TEST_SUITE_SOURCES - boards/LimeSDR/LimeSDRTest.cpp - boards/LimeSDR/USB_CSR_Pipe_SDRTest.cpp - boards/LimeSDR_Mini/LimeSDR_MiniTest.cpp - boards/LimeSDR_Mini/USB_CSR_Pipe_MiniTest.cpp - boards/LimeSDR_X3/SlaveSelectShimTest.cpp - comms/PCIe/PCIE_CSR_PipeTest.cpp parsers/CoefficientFileParserTest.cpp protocols/LMS64CProtocol/CustomParameterReadTest.cpp protocols/LMS64CProtocol/CustomParameterWriteTest.cpp @@ -21,6 +15,32 @@ set(LIME_TEST_SUITE_SOURCES protocols/LMS64CProtocol/LMS7002M_SPITest.cpp ) +if (ENABLE_LIMESDR_X3) + set(LIME_TEST_SUITE_SOURCES ${LIME_TEST_SUITE_SOURCES} + boards/LimeSDR_X3/SlaveSelectShimTest.cpp + ) +endif() + +if (ENABLE_LITE_PCIE) + set(LIME_TEST_SUITE_SOURCES ${LIME_TEST_SUITE_SOURCES} + comms/PCIe/PCIE_CSR_PipeTest.cpp + ) +endif() + +if (ENABLE_LIMESDR_USB) + set(LIME_TEST_SUITE_SOURCES ${LIME_TEST_SUITE_SOURCES} + boards/LimeSDR/LimeSDRTest.cpp + boards/LimeSDR/USB_CSR_Pipe_SDRTest.cpp + ) +endif() + +if (ENABLE_LIMESDR_MINI) + set(LIME_TEST_SUITE_SOURCES ${LIME_TEST_SUITE_SOURCES} + boards/LimeSDR_Mini/LimeSDR_MiniTest.cpp + boards/LimeSDR_Mini/USB_CSR_Pipe_MiniTest.cpp + ) +endif() + add_executable(${LIME_TEST_SUITE_NAME} ${LIME_TEST_SUITE_SOURCES}) target_include_directories(${LIME_TEST_SUITE_NAME} PUBLIC ${LIME_SUITE_INCLUDES} tests) diff --git a/src/tests/boards/LimeSDR/USB_CSR_Pipe_SDRTest.cpp b/src/tests/boards/LimeSDR/USB_CSR_Pipe_SDRTest.cpp index 602c17325..f3fe900d3 100644 --- a/src/tests/boards/LimeSDR/USB_CSR_Pipe_SDRTest.cpp +++ b/src/tests/boards/LimeSDR/USB_CSR_Pipe_SDRTest.cpp @@ -10,17 +10,6 @@ using namespace lime::testing; using ::testing::_; using ::testing::Pointer; -static const int CTR_W_REQCODE = 0xC1; -static const int CTR_W_VALUE = 0x0000; -static const int CTR_W_INDEX = 0x0000; - -static const int CTR_R_REQCODE = 0xC0; -static const int CTR_R_VALUE = 0x0000; -static const int CTR_R_INDEX = 0x0000; - -static const uint8_t CONTROL_BULK_OUT_ADDRESS = 0x0F; -static const uint8_t CONTROL_BULK_IN_ADDRESS = 0x8F; - TEST(USB_CSR_Pipe_SDR, WriteBulkTransfer) { FX3Mock mockConnection{}; @@ -32,7 +21,7 @@ TEST(USB_CSR_Pipe_SDR, WriteBulkTransfer) int timeout = 100; int length = sizeof(LMS64CPacket); - EXPECT_CALL(mockConnection, BulkTransfer(CONTROL_BULK_OUT_ADDRESS, Pointer(reinterpret_cast(&pkt)), length, timeout)) + EXPECT_CALL(mockConnection, BulkTransfer(FX3::CONTROL_BULK_OUT_ADDRESS, Pointer(reinterpret_cast(&pkt)), length, timeout)) .Times(1); pipe.Write(reinterpret_cast(&pkt), length, timeout); } @@ -48,15 +37,23 @@ TEST(USB_CSR_Pipe_SDR, WriteControlTransfer) int timeout = 100; int length = sizeof(LMS64CPacket); +#ifdef __unix__ EXPECT_CALL(mockConnection, ControlTransfer(LIBUSB_REQUEST_TYPE_VENDOR, - CTR_W_REQCODE, - CTR_W_VALUE, - CTR_W_INDEX, + FX3::CTR_W_REQCODE, + FX3::CTR_W_VALUE, + FX3::CTR_W_INDEX, Pointer(reinterpret_cast(&pkt)), length, timeout)) .Times(1); +#else + EXPECT_CALL(mockConnection, + ControlTransfer( + 0, FX3::CTR_W_REQCODE, FX3::CTR_W_VALUE, FX3::CTR_W_INDEX, Pointer(reinterpret_cast(&pkt)), length, timeout)) + .Times(1); +#endif + pipe.Write(reinterpret_cast(&pkt), length, timeout); } @@ -71,7 +68,8 @@ TEST(USB_CSR_Pipe_SDR, ReadBulkTransfer) int timeout = 100; int length = sizeof(LMS64CPacket); - EXPECT_CALL(mockConnection, BulkTransfer(CONTROL_BULK_IN_ADDRESS, Pointer(reinterpret_cast(&pkt)), length, timeout)) + EXPECT_CALL( + mockConnection, BulkTransfer(FX3::CONTROL_BULK_IN_ADDRESS, Pointer(reinterpret_cast(&pkt)), length, timeout)) .Times(1); pipe.Read(reinterpret_cast(&pkt), length, timeout); } @@ -87,14 +85,21 @@ TEST(USB_CSR_Pipe_SDR, ReadControlTransfer) int timeout = 100; int length = sizeof(LMS64CPacket); +#ifdef __unix__ EXPECT_CALL(mockConnection, ControlTransfer(LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN, - CTR_R_REQCODE, - CTR_R_VALUE, - CTR_R_INDEX, + FX3::CTR_R_REQCODE, + FX3::CTR_R_VALUE, + FX3::CTR_R_INDEX, Pointer(reinterpret_cast(&pkt)), length, timeout)) .Times(1); +#else + EXPECT_CALL(mockConnection, + ControlTransfer( + 1, FX3::CTR_R_REQCODE, FX3::CTR_R_VALUE, FX3::CTR_R_INDEX, Pointer(reinterpret_cast(&pkt)), length, timeout)) + .Times(1); +#endif pipe.Read(reinterpret_cast(&pkt), length, timeout); } diff --git a/src/tests/boards/LimeSDR_X3/SlaveSelectShimTest.cpp b/src/tests/boards/LimeSDR_X3/SlaveSelectShimTest.cpp index 6a5539853..00d0b703e 100644 --- a/src/tests/boards/LimeSDR_X3/SlaveSelectShimTest.cpp +++ b/src/tests/boards/LimeSDR_X3/SlaveSelectShimTest.cpp @@ -3,7 +3,7 @@ #include #include "tests/include/limesuite/CommsMock.h" -#include "SlaveSelectShim.h" +#include "LimeSDR_X3/SlaveSelectShim.h" using namespace lime; using namespace lime::testing; diff --git a/src/tests/comms/PCIe/LitePCIeMock.h b/src/tests/comms/PCIe/LitePCIeMock.h index ae5ad42fe..83fd276a4 100644 --- a/src/tests/comms/PCIe/LitePCIeMock.h +++ b/src/tests/comms/PCIe/LitePCIeMock.h @@ -3,7 +3,7 @@ #include -#include "LitePCIe.h" +#include "comms/PCIe/LitePCIe.h" namespace lime::testing { diff --git a/src/tests/comms/PCIe/PCIE_CSR_PipeTest.cpp b/src/tests/comms/PCIe/PCIE_CSR_PipeTest.cpp index 3d0bbb609..e442fd12f 100644 --- a/src/tests/comms/PCIe/PCIE_CSR_PipeTest.cpp +++ b/src/tests/comms/PCIe/PCIE_CSR_PipeTest.cpp @@ -2,7 +2,7 @@ #include #include "LitePCIeMock.h" -#include "PCIeCommon.h" +#include "comms/PCIe/PCIeCommon.h" #include "LMS64CProtocol.h" using namespace lime; From c5bc4691e1fa8d08821ed128ed0b6103ff71b948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Petkevi=C4=8Dius?= Date: Wed, 14 Feb 2024 15:10:10 +0200 Subject: [PATCH 19/22] Fix CoefficientFileParser tests --- .../lms7002_dlgGFIR_Coefficients.cpp | 6 +- src/parsers/CoefficientFileParser.cpp | 47 +++++++++----- src/parsers/CoefficientFileParser.h | 15 +++-- .../boards/LimeSDR/USB_CSR_Pipe_SDRTest.cpp | 3 +- .../parsers/CoefficientFileParserTest.cpp | 62 ++++++++++++------- 5 files changed, 89 insertions(+), 44 deletions(-) diff --git a/src/lms7002_wxgui/lms7002_dlgGFIR_Coefficients.cpp b/src/lms7002_wxgui/lms7002_dlgGFIR_Coefficients.cpp index 85329eced..33f0d71c7 100644 --- a/src/lms7002_wxgui/lms7002_dlgGFIR_Coefficients.cpp +++ b/src/lms7002_wxgui/lms7002_dlgGFIR_Coefficients.cpp @@ -120,7 +120,8 @@ void lms7002_dlgGFIR_Coefficients::OnLoadFromFile(wxCommandEvent& event) return; std::vector coefficients(200, 0); - int iVal = lime::CoefficientFileParser::getCoefficients(dlg.GetPath().ToStdString(), coefficients, 200); + auto parser = CoefficientFileParser(dlg.GetPath().ToStdString()); + int iVal = parser.getCoefficients(coefficients, 200); switch (iVal) { @@ -166,7 +167,8 @@ void lms7002_dlgGFIR_Coefficients::OnSaveToFile(wxCommandEvent& event) gridCoef->GetCellValue(i, 0).ToDouble(&coefficients[i]); } - lime::CoefficientFileParser::saveToFile(dlg.GetPath().ToStdString(), coefficients); + auto parser = CoefficientFileParser(dlg.GetPath().ToStdString()); + parser.saveToFile(coefficients); } void lms7002_dlgGFIR_Coefficients::OnClearTable(wxCommandEvent& event) diff --git a/src/parsers/CoefficientFileParser.cpp b/src/parsers/CoefficientFileParser.cpp index 908d746c3..b864b3ce5 100644 --- a/src/parsers/CoefficientFileParser.cpp +++ b/src/parsers/CoefficientFileParser.cpp @@ -17,6 +17,11 @@ using namespace lime; using namespace std::literals::string_literals; using namespace std::literals::string_view_literals; +CoefficientFileParser::CoefficientFileParser(const std::filesystem::path& filename) + : filename(filename) +{ +} + void CoefficientFileParser::parseMultilineComments(std::ifstream& file, std::string& token) { std::string_view view = token; @@ -96,20 +101,35 @@ void CoefficientFileParser::parseMultilineComments(std::ifstream& file, std::str // *************************************************************** CoefficientFileParser::ErrorCodes CoefficientFileParser::getValue(std::ifstream& file, double& value) { - file >> value; - if (!file.fail()) + std::string token = ""s; + + tokenBuffer >> value; + if (!tokenBuffer.fail()) { return ErrorCodes::SUCCESS; } - if (file.eof()) + if (!tokenBuffer.eof()) { - return ErrorCodes::END_OF_FILE; + tokenBuffer.clear(); + tokenBuffer >> token; } + else + { + file >> value; + if (!file.fail()) + { + return ErrorCodes::SUCCESS; + } - file.clear(); - std::string token; - file >> token; + if (file.eof()) + { + return ErrorCodes::END_OF_FILE; + } + + file.clear(); + file >> token; + } bool hasValueBeenRead = false; @@ -164,12 +184,7 @@ CoefficientFileParser::ErrorCodes CoefficientFileParser::getValue(std::ifstream& } } - // Rewind file by the amount of unparsed characters. - std::size_t charsToUnget = token.size(); - for (std::size_t i = 0; i < charsToUnget; ++i) - { - file.unget(); - } + tokenBuffer = std::stringstream{ token }; return ErrorCodes::SUCCESS; } @@ -182,7 +197,7 @@ CoefficientFileParser::ErrorCodes CoefficientFileParser::getValue(std::ifstream& // -5 too many coefficients in the file // >=0 number of the coefficients read // *************************************************************** -int CoefficientFileParser::getCoefficients(const std::filesystem::path& filename, std::vector& coefficients, int max) +int CoefficientFileParser::getCoefficients(std::vector& coefficients, int max) { if (filename.empty()) { @@ -231,14 +246,14 @@ int CoefficientFileParser::getCoefficients(const std::filesystem::path& filename // *************************************************************** // Saves given coefficients to fir file // *************************************************************** -void CoefficientFileParser::saveToFile(const std::filesystem::path& filename, const std::vector& coefficients) +void CoefficientFileParser::saveToFile(const std::vector& coefficients) { std::ofstream fout; fout.open(filename, std::ios::out); fout << "/* ******************************************************************"sv << std::endl; fout << " FILE:\t"sv; - fout << filename.filename().c_str() << std::endl; + fout << filename.filename().generic_string() << std::endl; fout << " DESCRIPTION:\t"sv << std::endl; fout << " DATE:\t"sv << std::endl; diff --git a/src/parsers/CoefficientFileParser.h b/src/parsers/CoefficientFileParser.h index 5fb927c2f..d333522ff 100644 --- a/src/parsers/CoefficientFileParser.h +++ b/src/parsers/CoefficientFileParser.h @@ -9,8 +9,10 @@ #include "limesuite/config.h" +#include #include #include +#include #include #include @@ -19,8 +21,10 @@ namespace lime { class LIME_API CoefficientFileParser { public: - static int getCoefficients(const std::filesystem::path& filename, std::vector& coefficients, int max); - static void saveToFile(const std::filesystem::path& filename, const std::vector& coefficients); + CoefficientFileParser(const std::filesystem::path& filename); + + int getCoefficients(std::vector& coefficients, int max); + void saveToFile(const std::vector& coefficients); private: enum class ErrorCodes : int8_t { @@ -32,8 +36,11 @@ class LIME_API CoefficientFileParser TOO_MANY_COEFFS = -5, }; - static ErrorCodes getValue(std::ifstream& file, double& value); - static void parseMultilineComments(std::ifstream& file, std::string& token); + ErrorCodes getValue(std::ifstream& file, double& value); + void parseMultilineComments(std::ifstream& file, std::string& token); + + std::filesystem::path filename; + std::stringstream tokenBuffer; }; } // namespace lime diff --git a/src/tests/boards/LimeSDR/USB_CSR_Pipe_SDRTest.cpp b/src/tests/boards/LimeSDR/USB_CSR_Pipe_SDRTest.cpp index f3fe900d3..f9969c306 100644 --- a/src/tests/boards/LimeSDR/USB_CSR_Pipe_SDRTest.cpp +++ b/src/tests/boards/LimeSDR/USB_CSR_Pipe_SDRTest.cpp @@ -21,7 +21,8 @@ TEST(USB_CSR_Pipe_SDR, WriteBulkTransfer) int timeout = 100; int length = sizeof(LMS64CPacket); - EXPECT_CALL(mockConnection, BulkTransfer(FX3::CONTROL_BULK_OUT_ADDRESS, Pointer(reinterpret_cast(&pkt)), length, timeout)) + EXPECT_CALL( + mockConnection, BulkTransfer(FX3::CONTROL_BULK_OUT_ADDRESS, Pointer(reinterpret_cast(&pkt)), length, timeout)) .Times(1); pipe.Write(reinterpret_cast(&pkt), length, timeout); } diff --git a/src/tests/parsers/CoefficientFileParserTest.cpp b/src/tests/parsers/CoefficientFileParserTest.cpp index c786a26a1..0c35b327d 100644 --- a/src/tests/parsers/CoefficientFileParserTest.cpp +++ b/src/tests/parsers/CoefficientFileParserTest.cpp @@ -110,7 +110,8 @@ TEST(CoefficientFileParser, StandardOutputFile) expectedResult.resize(40, 0); std::vector coefficients(40, 0); - int actualReturn = CoefficientFileParser::getCoefficients(fileName, coefficients, 40); + auto parser = CoefficientFileParser(fileName); + int actualReturn = parser.getCoefficients(coefficients, 40); EXPECT_EQ(actualReturn, 40); EXPECT_THAT(coefficients, expectedResult); @@ -138,7 +139,8 @@ TEST(CoefficientFileParser, SingleLineComments) expectedResult.resize(10, 0); std::vector coefficients(10, 0); - int actualReturn = CoefficientFileParser::getCoefficients(fileName, coefficients, 10); + auto parser = CoefficientFileParser(fileName); + int actualReturn = parser.getCoefficients(coefficients, 10); EXPECT_EQ(actualReturn, 4); EXPECT_THAT(coefficients, expectedResult); @@ -164,7 +166,8 @@ TEST(CoefficientFileParser, SinglelineCommentsMultilineCommentIsIgnored) expectedResult.resize(10, 0); std::vector coefficients(10, 0); - int actualReturn = CoefficientFileParser::getCoefficients(fileName, coefficients, 10); + auto parser = CoefficientFileParser(fileName); + int actualReturn = parser.getCoefficients(coefficients, 10); EXPECT_EQ(actualReturn, 2); EXPECT_THAT(coefficients, expectedResult); @@ -190,7 +193,8 @@ TEST(CoefficientFileParser, SingleLineCommentFileEnd) expectedResult.resize(10, 0); std::vector coefficients(10, 0); - int actualReturn = CoefficientFileParser::getCoefficients(fileName, coefficients, 10); + auto parser = CoefficientFileParser(fileName); + int actualReturn = parser.getCoefficients(coefficients, 10); EXPECT_EQ(actualReturn, 3); EXPECT_THAT(coefficients, expectedResult); @@ -214,7 +218,8 @@ TEST(CoefficientFileParser, SingleLineCommentImmediateFileEnd) expectedResult.resize(10, 0); std::vector coefficients(10, 0); - int actualReturn = CoefficientFileParser::getCoefficients(fileName, coefficients, 10); + auto parser = CoefficientFileParser(fileName); + int actualReturn = parser.getCoefficients(coefficients, 10); EXPECT_EQ(actualReturn, 1); EXPECT_THAT(coefficients, expectedResult); @@ -239,7 +244,8 @@ TEST(CoefficientFileParser, MultilineCommentsSingleLine) expectedResult.resize(10, 0); std::vector coefficients(10, 0); - int actualReturn = CoefficientFileParser::getCoefficients(fileName, coefficients, 10); + auto parser = CoefficientFileParser(fileName); + int actualReturn = parser.getCoefficients(coefficients, 10); EXPECT_EQ(actualReturn, 5); EXPECT_THAT(coefficients, expectedResult); @@ -267,7 +273,8 @@ TEST(CoefficientFileParser, MultilineCommentsMultiLine) expectedResult.resize(10, 0); std::vector coefficients(10, 0); - int actualReturn = CoefficientFileParser::getCoefficients(fileName, coefficients, 10); + auto parser = CoefficientFileParser(fileName); + int actualReturn = parser.getCoefficients(coefficients, 10); EXPECT_EQ(actualReturn, 4); EXPECT_THAT(coefficients, expectedResult); @@ -295,7 +302,8 @@ TEST(CoefficientFileParser, MultilineCommentsNested) expectedResult.resize(10, 0); std::vector coefficients(10, 0); - int actualReturn = CoefficientFileParser::getCoefficients(fileName, coefficients, 10); + auto parser = CoefficientFileParser(fileName); + int actualReturn = parser.getCoefficients(coefficients, 10); EXPECT_EQ(actualReturn, 4); EXPECT_THAT(coefficients, expectedResult); @@ -320,7 +328,8 @@ TEST(CoefficientFileParser, MultilineCommentsUnclosed) expectedResult.resize(10, 0); std::vector coefficients(10, 0); - int actualReturn = CoefficientFileParser::getCoefficients(fileName, coefficients, 10); + auto parser = CoefficientFileParser(fileName); + int actualReturn = parser.getCoefficients(coefficients, 10); EXPECT_EQ(actualReturn, 1); EXPECT_THAT(coefficients, expectedResult); @@ -344,7 +353,8 @@ TEST(CoefficientFileParser, MultilineCommentsUnclosedImmediateEndOfFile) expectedResult.resize(10, 0); std::vector coefficients(10, 0); - int actualReturn = CoefficientFileParser::getCoefficients(fileName, coefficients, 10); + auto parser = CoefficientFileParser(fileName); + int actualReturn = parser.getCoefficients(coefficients, 10); EXPECT_EQ(actualReturn, 0); EXPECT_THAT(coefficients, expectedResult); @@ -369,7 +379,8 @@ TEST(CoefficientFileParser, CommasAreWhitespace) expectedResult.resize(10, 0); std::vector coefficients(10, 0); - int actualReturn = CoefficientFileParser::getCoefficients(fileName, coefficients, 10); + auto parser = CoefficientFileParser(fileName); + int actualReturn = parser.getCoefficients(coefficients, 10); EXPECT_EQ(actualReturn, 3); EXPECT_THAT(coefficients, expectedResult); @@ -382,7 +393,9 @@ TEST(CoefficientFileParser, NoFilenameProvided) const std::string fileName = ""; std::vector coefficients(10, 0); - int actualReturn = CoefficientFileParser::getCoefficients(fileName, coefficients, 10); + auto parser = CoefficientFileParser(fileName); + + int actualReturn = parser.getCoefficients(coefficients, 10); EXPECT_EQ(actualReturn, -3); } @@ -394,7 +407,8 @@ TEST(CoefficientFileParser, NonExistentFilenameProvided) const std::string fileName = testSuiteName + "_" + testName + ".fir"; std::vector coefficients(10, 0); - int actualReturn = CoefficientFileParser::getCoefficients(fileName, coefficients, 10); + auto parser = CoefficientFileParser(fileName); + int actualReturn = parser.getCoefficients(coefficients, 10); EXPECT_EQ(actualReturn, -4); } @@ -415,7 +429,8 @@ TEST(CoefficientFileParser, EmptyFile) expectedResult.resize(10, 0); std::vector coefficients(10, 0); - int actualReturn = CoefficientFileParser::getCoefficients(fileName, coefficients, 10); + auto parser = CoefficientFileParser(fileName); + int actualReturn = parser.getCoefficients(coefficients, 10); EXPECT_EQ(actualReturn, 0); EXPECT_THAT(coefficients, expectedResult); @@ -439,7 +454,8 @@ TEST(CoefficientFileParser, TooManyCoefficients) expectedResult.resize(1, 0); std::vector coefficients(1, 0); - int actualReturn = CoefficientFileParser::getCoefficients(fileName, coefficients, 1); + auto parser = CoefficientFileParser(fileName); + int actualReturn = parser.getCoefficients(coefficients, 1); EXPECT_EQ(actualReturn, -5); EXPECT_THAT(coefficients, expectedResult); @@ -463,7 +479,8 @@ TEST(CoefficientFileParser, SyntaxError) expectedResult.resize(1, 0); std::vector coefficients(1, 0); - int actualReturn = CoefficientFileParser::getCoefficients(fileName, coefficients, 1); + auto parser = CoefficientFileParser(fileName); + int actualReturn = parser.getCoefficients(coefficients, 1); EXPECT_EQ(actualReturn, -2); EXPECT_THAT(coefficients, expectedResult); @@ -487,7 +504,8 @@ TEST(CoefficientFileParser, EndOfFileWithComma) expectedResult.resize(1, 0); std::vector coefficients(1, 0); - int actualReturn = CoefficientFileParser::getCoefficients(fileName, coefficients, 1); + auto parser = CoefficientFileParser(fileName); + int actualReturn = parser.getCoefficients(coefficients, 1); EXPECT_EQ(actualReturn, 1); EXPECT_THAT(coefficients, expectedResult); @@ -513,13 +531,14 @@ TEST(CoefficientFileParser, SaveFile) const std::string fileName = testSuiteName + "_" + testName + ".fir"; const std::vector input{ 0.111111, -0.222222, 0.333333 }; - - CoefficientFileParser::saveToFile(fileName, input); + auto parser = CoefficientFileParser(fileName); + parser.saveToFile(input); std::ifstream in(fileName); std::string actualFileContents; std::getline(in, actualFileContents, '\0'); + in.close(); EXPECT_EQ(actualFileContents, fileContents); @@ -544,13 +563,14 @@ TEST(CoefficientFileParser, SaveFileInSubfolder) const std::string fileName = "./" + testSuiteName + "_" + testName + ".fir"; // Use this folder as the testing path. const std::vector input{ 0.111111, -0.222222, 0.333333 }; - - CoefficientFileParser::saveToFile(fileName, input); + auto parser = CoefficientFileParser(fileName); + parser.saveToFile(input); std::ifstream in(fileName); std::string actualFileContents; std::getline(in, actualFileContents, '\0'); + in.close(); EXPECT_EQ(actualFileContents, fileContents); From 42d192df7cf03e3006913c080f9748797052a476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Petkevi=C4=8Dius?= Date: Wed, 14 Feb 2024 15:10:38 +0200 Subject: [PATCH 20/22] Enable GTest action on Windows as well --- .github/workflows/gtest.yml | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/.github/workflows/gtest.yml b/.github/workflows/gtest.yml index f4fe23126..64962f78a 100644 --- a/.github/workflows/gtest.yml +++ b/.github/workflows/gtest.yml @@ -18,8 +18,8 @@ jobs: strategy: matrix: os: - [ubuntu-latest] - # os: [ubuntu-latest, macos-latest, windows-latest] + [ubuntu-latest, windows-latest] + # os: [ubuntu-latest, macos-latest, ] steps: - uses: actions/checkout@v2 @@ -47,13 +47,20 @@ jobs: - name: Configure CMake (windows) if: matrix.os == 'windows-latest' - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENABLE_EVB7COM=ON -DCMAKE_INSTALL_PREFIX=${{env.INSTALL_PREFIX}} -DwxWidgets_ROOT_DIR=${{github.workspace}}/deps/wxWidgets -DFX3_SDK_PATH=${{github.workspace}}/deps/FX3SDK + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENABLE_EVB7COM=ON -DCMAKE_INSTALL_PREFIX=${{env.INSTALL_PREFIX}} -DwxWidgets_ROOT_DIR=${{github.workspace}}/deps/wxWidgets -DFX3_SDK_PATH=${{github.workspace}}/deps/FX3SDK -DBUILD_SHARED_LIBS=OFF - name: Configure CMake (linux) if: matrix.os != 'windows-latest' run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENABLE_EVB7COM=ON -DCMAKE_INSTALL_PREFIX=${{env.INSTALL_PREFIX}} -DBUILD_SHARED_LIBS=OFF -DBINARY_OUTPUT_DIR=${{github.workspace}}/build/bin/ - - name: Build and run tests - run: | - cmake --build ${{github.workspace}}/build --config LimeSuite2Test - ${{github.workspace}}/build/bin/LimeSuite2Test + - name: Build tests + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target LimeSuite2Test + + - name: Run tests (Linux) + if: matrix.os != 'windows-latest' + run: ${{github.workspace}}/build/bin/LimeSuite2Test + + - name: Run tests (Windows) + if: matrix.os == 'windows-latest' + run: ${{github.workspace}}/build/bin/${{env.BUILD_TYPE}}/LimeSuite2Test.exe + From 482a7377f7c7d1f2383d7f67a67fe2fae46dc2aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Petkevi=C4=8Dius?= Date: Wed, 14 Feb 2024 15:43:34 +0200 Subject: [PATCH 21/22] Clean up unneeded Windows dependencies in GTest build --- .github/workflows/gtest.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/gtest.yml b/.github/workflows/gtest.yml index 64962f78a..ad59f31c8 100644 --- a/.github/workflows/gtest.yml +++ b/.github/workflows/gtest.yml @@ -40,10 +40,6 @@ jobs: mkdir ${{github.workspace}}/deps curl -o ${{github.workspace}}/deps/FX3SDK.zip -L https://downloads.myriadrf.org/project/limesuite/appveyor/FX3SDK.zip 7z x ${{github.workspace}}/deps/FX3SDK.zip -o${{github.workspace}}/deps/FX3SDK - curl -o ${{github.workspace}}/deps/wxWidgets-headers.7z -L https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.5/wxWidgets-3.1.5-headers.7z - 7z x ${{github.workspace}}/deps/wxWidgets-headers.7z -o${{github.workspace}}/deps/wxWidgets - curl -o ${{github.workspace}}/deps/wxWidgets.7z -L https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.5/wxMSW-3.1.5_vc14x_x64_Dev.7z - 7z x ${{github.workspace}}/deps/wxWidgets.7z -o${{github.workspace}}/deps/wxWidgets - name: Configure CMake (windows) if: matrix.os == 'windows-latest' From da698d341b88ef4bf2463e44b96fa218ca291080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Petkevi=C4=8Dius?= Date: Wed, 14 Feb 2024 15:58:27 +0200 Subject: [PATCH 22/22] Fix tests compile path --- src/tests/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 5e45e05e0..069efaec1 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -52,8 +52,8 @@ target_link_libraries( GTest::gmock_main ) -if (BINARY_OUTPUT_DIR) - set_target_properties(${LIME_TEST_SUITE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${BINARY_OUTPUT_DIR}) +if (CMAKE_BINARY_DIR) + set_target_properties(${LIME_TEST_SUITE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") endif() include(GoogleTest)