From 4e62b9a7578119dd4f0e7578a450bc6d10160843 Mon Sep 17 00:00:00 2001 From: Ricardas Jonaitis Date: Fri, 9 Feb 2024 16:36:18 +0200 Subject: [PATCH] Partial fix of compilation errors on Windows --- CMakeLists.txt | 2 +- amarisoft-plugin/CMakeLists.txt | 6 ++- src/DSP/Equalizer.cpp | 1 + src/FPGA_common/FPGA_common.cpp | 10 ++-- src/boards/LMS7002M_SDRDevice.cpp | 1 + src/boards/LimeSDR/CMakeLists.txt | 28 +---------- src/boards/LimeSDR_Mini/CMakeLists.txt | 46 +------------------ src/boards/LimeSDR_Mini/LimeSDR_MiniEntry.cpp | 4 +- src/boards/LimeSDR_X3/CMakeLists.txt | 2 +- src/boards/LimeSDR_XTRX/CMakeLists.txt | 2 +- src/boards/MMX8/CMakeLists.txt | 2 +- src/cli/limeTRX.cpp | 7 +-- src/comms/PCIe/CMakeLists.txt | 2 +- src/comms/PCIe/LitePCIe.cpp | 16 ++++--- src/comms/USB/CMakeLists.txt | 33 +------------ src/comms/USB/FT601/CMakeLists.txt | 37 ++++++++++++--- src/comms/USB/FT601/FT601.cpp | 6 ++- src/comms/USB/FT601/FT601.h | 1 - .../USB/FT601/USBTransferContext_FT601.h | 1 - src/comms/USB/FX3/CMakeLists.txt | 38 ++++++++++++--- src/comms/USB/TRXLooper_USB.cpp | 14 +++--- src/comms/USB/USBEntry.cpp | 9 ++-- src/comms/USB/USBGeneric.cpp | 4 +- src/examples/basicRX.cpp | 2 +- src/examples/basicTX.cpp | 2 +- src/include/limesuite/LMS7002M.h | 1 + src/lms7002m/LMS7002M.cpp | 2 + src/lms7002m/LMS7002M_validation.cpp | 8 ++-- src/memory/MemoryPool.cpp | 4 ++ src/parsers/CoefficientFileParser.cpp | 2 +- src/protocols/SamplesPacket.h | 2 +- src/vectorization/samplesConversion.cpp | 32 +++++-------- src/vectorization/samplesConversion.h | 12 ++--- 33 files changed, 146 insertions(+), 193 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ea73cfe3a..1946e5759 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) + add_definitions(-D_CRT_SECURE_NO_WARNINGS -DNOGDI -DNOMINMAX) set( MSVC_MULTITHREAD_COMPILE_FLAGS "/MP") set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MSVC_MULTITHREAD_COMPILE_FLAGS}" ) diff --git a/amarisoft-plugin/CMakeLists.txt b/amarisoft-plugin/CMakeLists.txt index 6dce790c4..03bfd628c 100644 --- a/amarisoft-plugin/CMakeLists.txt +++ b/amarisoft-plugin/CMakeLists.txt @@ -6,9 +6,13 @@ set(CMAKE_BUILD_TYPE "Release") include(FeatureSummary) include(CMakeDependentOption) -cmake_dependent_option(ENABLE_AMARISOFT_PLUGIN "Build LimeSuite integration to Amarisoft" ON "ENABLE_LIBRARY" OFF) +cmake_dependent_option(ENABLE_AMARISOFT_PLUGIN "Build LimeSuite integration to Amarisoft" ON "UNIX;ENABLE_LIBRARY" OFF) add_feature_info(AMARISOFT_PLUGIN ENABLE_AMARISOFT_PLUGIN "LimeSuite Amarisoft integration plugin") +if (NOT ENABLE_AMARISOFT_PLUGIN) + return() +endif() + #include modules for finding libraries set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") diff --git a/src/DSP/Equalizer.cpp b/src/DSP/Equalizer.cpp index 30595c4d0..dc4b8ae1f 100644 --- a/src/DSP/Equalizer.cpp +++ b/src/DSP/Equalizer.cpp @@ -3,6 +3,7 @@ #include "Register.h" #include "limesuite/IComms.h" +#define _USE_MATH_DEFINES #include #include #include diff --git a/src/FPGA_common/FPGA_common.cpp b/src/FPGA_common/FPGA_common.cpp index 558e7aca7..f9abae5ed 100644 --- a/src/FPGA_common/FPGA_common.cpp +++ b/src/FPGA_common/FPGA_common.cpp @@ -441,7 +441,7 @@ OpStatus FPGA::SetPllFrequency(const uint8_t pllIndex, const double inputFreq, F lime::debug("FPGA SetPllFrequency: PLL[%i] input:%.3f MHz clockCount:%i", pllIndex, inputFreq / 1e6, clockCount); WriteRegistersBatch batch(this); const auto timeout = chrono::seconds(3); - if (not fpgaPort) + if (!fpgaPort) return ReportError(OpStatus::IO_FAILURE, "ConfigureFPGA_PLL: connection port is NULL"); const bool waitForDone = HasWaitForDone(ReadRegister(0)); // read targetDevice @@ -463,7 +463,7 @@ OpStatus FPGA::SetPllFrequency(const uint8_t pllIndex, const double inputFreq, F clocks[i].phaseShift_deg, clocks[i].findPhase); willDoPhaseSearch |= clocks[i].findPhase; - if (clocks[i].outFrequency < PLLlowerLimit && not clocks[i].bypass) + if (clocks[i].outFrequency < PLLlowerLimit && !clocks[i].bypass) return ReportError( OpStatus::OUT_OF_RANGE, "FPGA SetPllFrequency: PLL[%i], clock[%i] must be >=%g MHz", pllIndex, i, PLLlowerLimit / 1e6); } @@ -570,13 +570,13 @@ OpStatus FPGA::SetPllFrequency(const uint8_t pllIndex, const double inputFreq, F const int C = ceil(Fvco / clocks[i].outFrequency); if (i < 8) { - if (not clocks[i].bypass && C != 1) + if (!clocks[i].bypass && C != 1) c7_c0_odds_byps &= ~(1 << (i * 2)); //enable output c7_c0_odds_byps |= (C % 2) << (i * 2 + 1); //odd bit } else { - if (not clocks[i].bypass && C != 1) + if (!clocks[i].bypass && C != 1) c15_c8_odds_byps &= ~(1 << ((i - 8) * 2)); //enable output c15_c8_odds_byps |= (C % 2) << ((i - 8) * 2 + 1); //odd bit } @@ -624,7 +624,7 @@ OpStatus FPGA::SetPllFrequency(const uint8_t pllIndex, const double inputFreq, F OpStatus FPGA::SetDirectClocking(int clockIndex) { - if (not fpgaPort) + if (!fpgaPort) return ReportError(OpStatus::IO_FAILURE, "SetDirectClocking: connection port is NULL"); uint16_t drct_clk_ctrl_0005 = ReadRegister(0x0005); diff --git a/src/boards/LMS7002M_SDRDevice.cpp b/src/boards/LMS7002M_SDRDevice.cpp index d7dfa687c..06847e82a 100644 --- a/src/boards/LMS7002M_SDRDevice.cpp +++ b/src/boards/LMS7002M_SDRDevice.cpp @@ -7,6 +7,7 @@ #include "Logger.h" #include "TRXLooper.h" +#include #include #include #include diff --git a/src/boards/LimeSDR/CMakeLists.txt b/src/boards/LimeSDR/CMakeLists.txt index e946057d5..c7feed53d 100644 --- a/src/boards/LimeSDR/CMakeLists.txt +++ b/src/boards/LimeSDR/CMakeLists.txt @@ -1,26 +1,6 @@ ######################################################################## ## Support for LimeSDR board ######################################################################## - -if(WIN32) - find_package(CyAPI) - set(USB_FOUND ${CYAPI_FOUND}) - set(USB_INCLUDE_DIRS ${CYAPI_INCLUDE_DIRS}) - set(USB_LIBRARIES ${CYAPI_LIBRARIES} SetupAPI) -elseif(UNIX) - find_package(libusb-1.0) - set(USB_FOUND ${LIBUSB_1_FOUND}) - set(USB_INCLUDE_DIRS ${LIBUSB_1_INCLUDE_DIRS}) - set(USB_LIBRARIES ${LIBUSB_1_LIBRARIES}) -endif() - -if (NOT USB_FOUND) - message(STATUS "USB libraries for LimeSDR support not found. Requires libusb-1.0 or CyAPI") -else() - message(STATUS "USB_INCLUDE_DIRS: ${USB_INCLUDE_DIRS}") - message(STATUS "USB_LIBRARIES: ${USB_LIBRARIES}") -endif() - set(THIS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/boards/LimeSDR) set(LIMESDR_SOURCES @@ -29,16 +9,12 @@ set(LIMESDR_SOURCES ${THIS_SOURCE_DIR}/USB_CSR_Pipe_SDR.cpp ) -set(LIMESDR_LIBRARIES - ${USB_LIBRARIES} -) - ######################################################################## ## Feature registration ######################################################################## include(FeatureSummary) include(CMakeDependentOption) -cmake_dependent_option(ENABLE_LIMESDR_USB "Enable LimeSDR support" ON "ENABLE_LIBRARY;USB_FOUND" OFF) +cmake_dependent_option(ENABLE_LIMESDR_USB "Enable LimeSDR support" ON "ENABLE_LIBRARY;ENABLE_USB_FX3" OFF) add_feature_info(BoardLimeSDR ENABLE_LIMESDR_USB "LimeSDR board support") if (NOT ENABLE_LIMESDR_USB) return() @@ -49,4 +25,4 @@ endif() ######################################################################## target_include_directories(${MAIN_LIBRARY_NAME} PUBLIC ${USB_INCLUDE_DIRS} ${THIS_SOURCE_DIR}) target_sources(${MAIN_LIBRARY_NAME} PRIVATE ${LIMESDR_SOURCES}) -target_link_libraries(${MAIN_LIBRARY_NAME} PUBLIC ${LIMESDR_LIBRARIES}) +target_link_libraries(${MAIN_LIBRARY_NAME} PRIVATE ${LIMESDR_LIBRARIES}) diff --git a/src/boards/LimeSDR_Mini/CMakeLists.txt b/src/boards/LimeSDR_Mini/CMakeLists.txt index be1746abb..4ee632e09 100644 --- a/src/boards/LimeSDR_Mini/CMakeLists.txt +++ b/src/boards/LimeSDR_Mini/CMakeLists.txt @@ -1,45 +1,6 @@ ######################################################################## ## Support for LimeSDR Mini v1 board ######################################################################## - -if(WIN32) - set(USB_FOUND TRUE) - set(USB_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/external/FTD3XXLibrary) - - #library directory based on x64 vs x86 - if (CMAKE_SIZEOF_VOID_P EQUAL 8) - set(FTD3XX_LIB_DIR ${USB_INCLUDE_DIRS}/x64) - else() - set(FTD3XX_LIB_DIR ${USB_INCLUDE_DIRS}/Win32) - endif() - - #default is to use static libs - option(FTD3XX_STATIC "Use static libs for FTD3XX" TRUE) - - #when using static libs specify FTD3XX_STATIC - if (FTD3XX_STATIC) - set(USB_LIBRARIES ${FTD3XX_LIB_DIR}/Static/FTD3XX.lib SetupAPI) - add_definitions(-DFTD3XX_STATIC) - - #when using dynamic libs install the dll to bin/ - else() - set(USB_LIBRARIES ${FTD3XX_LIB_DIR}/FTD3XX.lib SetupAPI) - install(FILES ${FTD3XX_LIB_DIR}/FTD3XX.dll DESTINATION bin) - endif() -elseif(UNIX) - find_package(libusb-1.0) - set(USB_FOUND ${LIBUSB_1_FOUND}) - set(USB_INCLUDE_DIRS ${LIBUSB_1_INCLUDE_DIRS}) - set(USB_LIBRARIES ${LIBUSB_1_LIBRARIES}) -endif() - -if (NOT USB_FOUND) - message(STATUS "USB libraries for LimeSDR support not found. Requires libusb-1.0 or CyAPI") -else() - message(STATUS "USB_INCLUDE_DIRS: ${USB_INCLUDE_DIRS}") - message(STATUS "USB_LIBRARIES: ${USB_LIBRARIES}") -endif() - set(THIS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/boards/LimeSDR_Mini) set(LIMESDR_MINI_SOURCES @@ -49,16 +10,12 @@ set(LIMESDR_MINI_SOURCES ${THIS_SOURCE_DIR}/USB_CSR_Pipe_Mini.cpp ) -set(LIMESDR_MINI_LIBRARIES - ${USB_LIBRARIES} -) - ######################################################################## ## Feature registration ######################################################################## include(FeatureSummary) include(CMakeDependentOption) -cmake_dependent_option(ENABLE_LIMESDR_MINI "Enable LimeSDR Mini support" ON "ENABLE_LIBRARY;USB_FOUND" OFF) +cmake_dependent_option(ENABLE_LIMESDR_MINI "Enable LimeSDR Mini support" ON "ENABLE_LIBRARY;ENABLE_USB_FTDI" OFF) add_feature_info(BoardLimeSDR_Mini ENABLE_LIMESDR_MINI "LimeSDR Mini board support") if (NOT ENABLE_LIMESDR_MINI) return() @@ -69,4 +26,3 @@ endif() ######################################################################## target_include_directories(${MAIN_LIBRARY_NAME} PUBLIC ${USB_INCLUDE_DIRS} ${THIS_SOURCE_DIR}) target_sources(${MAIN_LIBRARY_NAME} PRIVATE ${LIMESDR_MINI_SOURCES}) -target_link_libraries(${MAIN_LIBRARY_NAME} PUBLIC ${LIMESDR_MINI_LIBRARIES}) diff --git a/src/boards/LimeSDR_Mini/LimeSDR_MiniEntry.cpp b/src/boards/LimeSDR_Mini/LimeSDR_MiniEntry.cpp index e79a1ec75..b10e243ba 100644 --- a/src/boards/LimeSDR_Mini/LimeSDR_MiniEntry.cpp +++ b/src/boards/LimeSDR_Mini/LimeSDR_MiniEntry.cpp @@ -66,11 +66,9 @@ std::vector LimeSDR_MiniEntry::enumerate(const DeviceHandle& hint) ftStatus = FT_GetDeviceInfoDetail(i, &Flags, nullptr, nullptr, nullptr, SerialNumber, Description, nullptr); if (!FT_FAILED(ftStatus)) { - ConnectionHandle handle; + DeviceHandle handle; handle.media = Flags & FT_FLAGS_SUPERSPEED ? "USB 3" : Flags & FT_FLAGS_HISPEED ? "USB 2" : "USB"; - handle.module = "FT601"; handle.name = Description; - handle.index = i; handle.serial = SerialNumber; // Add handle conditionally, filter by serial number if (hint.serial.empty() || handle.serial.find(hint.serial) != std::string::npos) diff --git a/src/boards/LimeSDR_X3/CMakeLists.txt b/src/boards/LimeSDR_X3/CMakeLists.txt index 80bf9f89e..39d59e9a7 100644 --- a/src/boards/LimeSDR_X3/CMakeLists.txt +++ b/src/boards/LimeSDR_X3/CMakeLists.txt @@ -17,7 +17,7 @@ set(LIMESDR_X3_SOURCES ######################################################################## include(FeatureSummary) include(CMakeDependentOption) -cmake_dependent_option(ENABLE_LIMESDR_X3 "Enable LimeSDR X3 board support" ON "ENABLE_LIBRARY" OFF) +cmake_dependent_option(ENABLE_LIMESDR_X3 "Enable LimeSDR X3 board support" ON "ENABLE_LIBRARY;ENABLE_LITE_PCIE" OFF) add_feature_info(ENABLE_LIMESDR_X3 ENABLE_LIMESDR_X3 "LimeSDR X3 board support") if (NOT ENABLE_LIMESDR_X3) return() diff --git a/src/boards/LimeSDR_XTRX/CMakeLists.txt b/src/boards/LimeSDR_XTRX/CMakeLists.txt index 5ec8446eb..d54a820ad 100644 --- a/src/boards/LimeSDR_XTRX/CMakeLists.txt +++ b/src/boards/LimeSDR_XTRX/CMakeLists.txt @@ -16,7 +16,7 @@ set(LIMESDR_XTRX_SOURCES ######################################################################## include(FeatureSummary) include(CMakeDependentOption) -cmake_dependent_option(ENABLE_LIMESDR_XTRX "Enable LimeSDR XTRX support" ON "ENABLE_LIBRARY" OFF) +cmake_dependent_option(ENABLE_LIMESDR_XTRX "Enable LimeSDR XTRX support" ON "ENABLE_LIBRARY;ENABLE_LITE_PCIE" OFF) add_feature_info(BoardLimeSDRXTRX ENABLE_LIMESDR_XTRX "LimeSDR XTRX board support") if (NOT ENABLE_LIMESDR_XTRX) return() diff --git a/src/boards/MMX8/CMakeLists.txt b/src/boards/MMX8/CMakeLists.txt index 2bced2d27..2ac86d258 100644 --- a/src/boards/MMX8/CMakeLists.txt +++ b/src/boards/MMX8/CMakeLists.txt @@ -14,7 +14,7 @@ set(MM_X8_SOURCES ######################################################################## include(FeatureSummary) include(CMakeDependentOption) -cmake_dependent_option(ENABLE_LIMESDR_MMX8 "Enable LimeMM-X8 board support" ON "ENABLE_LIBRARY" OFF) +cmake_dependent_option(ENABLE_LIMESDR_MMX8 "Enable LimeMM-X8 board support" ON "ENABLE_LIBRARY;ENABLE_LITE_PCIE" OFF) add_feature_info(ENABLE_LIMESDR_MMX8 ENABLE_LIMESDR_MMX8 "LimeSDR MM-X8 board support") if (NOT ENABLE_LIMESDR_MMX8) return() diff --git a/src/cli/limeTRX.cpp b/src/cli/limeTRX.cpp index 2416e86b6..c91f723e4 100644 --- a/src/cli/limeTRX.cpp +++ b/src/cli/limeTRX.cpp @@ -10,6 +10,7 @@ #include "kissFFT/kiss_fft.h" #include #include + // #define USE_GNU_PLOT 1 #ifdef USE_GNU_PLOT #include "gnuPlotPipe.h" @@ -80,7 +81,7 @@ enum Args { HELP = 'h', DEVICE = 'd', CHIP = 'c', - INPUT = 'i', + INPUTFILE = 'i', OUTPUT = 'o', SAMPLES_COUNT = 's', TIME = 't', @@ -328,7 +329,7 @@ int main(int argc, char** argv) static struct option long_options[] = { { "help", no_argument, 0, Args::HELP }, { "device", required_argument, 0, Args::DEVICE }, { "chip", required_argument, 0, Args::CHIP }, - { "input", required_argument, 0, Args::INPUT }, + { "input", required_argument, 0, Args::INPUTFILE }, { "output", required_argument, 0, Args::OUTPUT }, { "looptx", no_argument, 0, Args::LOOPTX }, { "samplesCount", required_argument, 0, Args::SAMPLES_COUNT }, @@ -380,7 +381,7 @@ int main(int argc, char** argv) case Args::LOOPTX: loopTx = true; break; - case Args::INPUT: + case Args::INPUTFILE: if (optarg != NULL) { tx = true; diff --git a/src/comms/PCIe/CMakeLists.txt b/src/comms/PCIe/CMakeLists.txt index 4ef848a2d..17fecc7ac 100644 --- a/src/comms/PCIe/CMakeLists.txt +++ b/src/comms/PCIe/CMakeLists.txt @@ -14,7 +14,7 @@ set(COMMS_LITE_PCIE_SOURCES ######################################################################## include(FeatureSummary) include(CMakeDependentOption) -cmake_dependent_option(ENABLE_LITE_PCIE "Enable Lite PCIe" ON "ENABLE_LIBRARY" OFF) +cmake_dependent_option(ENABLE_LITE_PCIE "Enable Lite PCIe" ON "UNIX;ENABLE_LIBRARY" OFF) add_feature_info(ConnectionLitePCIe ENABLE_LITE_PCIE "Lite PCIe Connection support") if (NOT ENABLE_LITE_PCIE) return() diff --git a/src/comms/PCIe/LitePCIe.cpp b/src/comms/PCIe/LitePCIe.cpp index e16764d3b..7d7d857ff 100644 --- a/src/comms/PCIe/LitePCIe.cpp +++ b/src/comms/PCIe/LitePCIe.cpp @@ -1,16 +1,20 @@ #include "LitePCIe.h" -#include -#include + #include -#include -#include -#include #include #include #include - #include "Logger.h" +#ifdef __unix__ + #include + #include + #include + #include + #include + #include "software/kernel/litepcie.h" +#endif + using namespace std; using namespace lime; using namespace std::literals::string_literals; diff --git a/src/comms/USB/CMakeLists.txt b/src/comms/USB/CMakeLists.txt index c8f90f091..cd12750a4 100644 --- a/src/comms/USB/CMakeLists.txt +++ b/src/comms/USB/CMakeLists.txt @@ -6,19 +6,6 @@ set(THIS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/comms/USB) include(${THIS_SOURCE_DIR}/FT601/CMakeLists.txt) include(${THIS_SOURCE_DIR}/FX3/CMakeLists.txt) -message(STATUS "USB_INCLUDE_DIRS: ${USB_INCLUDE_DIRS}") -message(STATUS "USB_LIBRARIES: ${USB_LIBRARIES}") - -set(CONNECTION_FX3_SOURCES - ${THIS_SOURCE_DIR}/FX3/FX3.cpp - ${THIS_SOURCE_DIR}/FX3/USBTransferContext_FX3.cpp -) - -set(CONNECTION_FT601_SOURCES - ${THIS_SOURCE_DIR}/FT601/FT601.cpp - ${THIS_SOURCE_DIR}/FT601/USBTransferContext_FT601.cpp -) - set(COMMS_USB_SOURCES ${THIS_SOURCE_DIR}/LMS64C_FPGA_Over_USB.cpp ${THIS_SOURCE_DIR}/LMS64C_LMS7002M_Over_USB.cpp @@ -26,28 +13,10 @@ set(COMMS_USB_SOURCES ${THIS_SOURCE_DIR}/USBEntry.cpp ${THIS_SOURCE_DIR}/USBGeneric.cpp ${THIS_SOURCE_DIR}/USBTransferContext.cpp - ${CONNECTION_FX3_SOURCES} - ${CONNECTION_FT601_SOURCES} ) -set(CONNECTION_FX3_LIBRARIES - ${USB_LIBRARIES} -) - -######################################################################## -## Feature registration -######################################################################## -include(FeatureSummary) -include(CMakeDependentOption) -cmake_dependent_option(ENABLE_FX3 "Enable FX3" ON "ENABLE_LIBRARY;USB_FOUND" OFF) -add_feature_info(ConnectionFX3 ENABLE_FX3 "FX3 Connection support") -if (NOT ENABLE_FX3) - return() -endif() - ######################################################################## ## Add to library ######################################################################## -target_include_directories(${MAIN_LIBRARY_NAME} PUBLIC ${USB_INCLUDE_DIRS} ${THIS_SOURCE_DIR}) +target_include_directories(${MAIN_LIBRARY_NAME} PUBLIC ${THIS_SOURCE_DIR}) target_sources(${MAIN_LIBRARY_NAME} PRIVATE ${COMMS_USB_SOURCES}) -target_link_libraries(${MAIN_LIBRARY_NAME} PUBLIC ${CONNECTION_FX3_LIBRARIES}) diff --git a/src/comms/USB/FT601/CMakeLists.txt b/src/comms/USB/FT601/CMakeLists.txt index a9a65d055..d9236c39d 100644 --- a/src/comms/USB/FT601/CMakeLists.txt +++ b/src/comms/USB/FT601/CMakeLists.txt @@ -1,6 +1,6 @@ if(WIN32) - set(USB_FOUND TRUE) - set(USB_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/external/FTD3XXLibrary) + set(FTDI_FOUND TRUE) + set(FTDI_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/external/FTD3XXLibrary) #library directory based on x64 vs x86 if (CMAKE_SIZEOF_VOID_P EQUAL 8) @@ -14,17 +14,40 @@ if(WIN32) #when using static libs specify FTD3XX_STATIC if (FTD3XX_STATIC) - set(USB_LIBRARIES ${FTD3XX_LIB_DIR}/Static/FTD3XX.lib SetupAPI) + set(FTDI_LIBRARIES ${FTD3XX_LIB_DIR}/Static/FTD3XX.lib SetupAPI) add_definitions(-DFTD3XX_STATIC) #when using dynamic libs install the dll to bin/ else() - set(USB_LIBRARIES ${FTD3XX_LIB_DIR}/FTD3XX.lib SetupAPI) + set(FTDI_LIBRARIES ${FTD3XX_LIB_DIR}/FTD3XX.lib SetupAPI) install(FILES ${FTD3XX_LIB_DIR}/FTD3XX.dll DESTINATION bin) endif() + + message(STATUS "FTDI_INCLUDE_DIRS: ${FTDI_INCLUDE_DIRS}") + message(STATUS "FTDI_LIBRARIES: ${FTDI_LIBRARIES}") elseif(UNIX) find_package(libusb-1.0) - set(USB_FOUND ${LIBUSB_1_FOUND}) - set(USB_INCLUDE_DIRS ${LIBUSB_1_INCLUDE_DIRS}) - set(USB_LIBRARIES ${LIBUSB_1_LIBRARIES}) + set(FTDI_FOUND ${LIBUSB_1_FOUND}) + if (NOT ${FTDI_FOUND}) + message(WARNING "libusb-1.0 libraries not found. Omitting FTDI USB support") + endif() + set(FTDI_INCLUDE_DIRS ${LIBUSB_1_INCLUDE_DIRS}) + set(FTDI_LIBRARIES ${LIBUSB_1_LIBRARIES}) +endif() + +include(FeatureSummary) +include(CMakeDependentOption) +cmake_dependent_option(ENABLE_USB_FTDI "Enable FT601" ON "FTDI_FOUND" OFF) +add_feature_info(USB_FTDI ENABLE_USB_FTDI "USB support for FTDI") +if (NOT ENABLE_USB_FTDI) + return() endif() + +set(CONNECTION_FT601_SOURCES + ${CMAKE_CURRENT_LIST_DIR}/FT601.cpp + ${CMAKE_CURRENT_LIST_DIR}/USBTransferContext_FT601.cpp +) + +target_include_directories(${MAIN_LIBRARY_NAME} PRIVATE ${FTDI_INCLUDE_DIRS} ${THIS_SOURCE_DIR}) +target_sources(${MAIN_LIBRARY_NAME} PRIVATE ${CONNECTION_FT601_SOURCES}) +target_link_libraries(${MAIN_LIBRARY_NAME} PUBLIC ${FTDI_LIBRARIES}) diff --git a/src/comms/USB/FT601/FT601.cpp b/src/comms/USB/FT601/FT601.cpp index 81d40a3e1..26b381b65 100644 --- a/src/comms/USB/FT601/FT601.cpp +++ b/src/comms/USB/FT601/FT601.cpp @@ -3,7 +3,7 @@ #include "DeviceExceptions.h" #include "USBTransferContext_FT601.h" -using namespace lime; +namespace lime { static const int STREAM_BULK_WRITE_ADDRESS = 0x03; static const int STREAM_BULK_READ_ADDRESS = 0x83; @@ -37,7 +37,7 @@ bool FT601::Connect(uint16_t vid, uint16_t pid, const std::string& serial) if (FT_FAILED(ftStatus)) { ReportError(ENODEV, "Failed to list USB Devices"); - return -1; + return false; } FT_AbortPipe(mFTHandle, STREAM_BULK_READ_ADDRESS); @@ -371,3 +371,5 @@ int FT601::FT_SetStreamPipe(unsigned char ep, size_t size) return 0; } #endif + +} // namespace lime diff --git a/src/comms/USB/FT601/FT601.h b/src/comms/USB/FT601/FT601.h index 2070a7b06..456e2f053 100644 --- a/src/comms/USB/FT601/FT601.h +++ b/src/comms/USB/FT601/FT601.h @@ -3,7 +3,6 @@ #include "USBGeneric.h" #ifndef __unix__ - #include "windows.h" #include "FTD3XXLibrary/FTD3XX.h" #endif diff --git a/src/comms/USB/FT601/USBTransferContext_FT601.h b/src/comms/USB/FT601/USBTransferContext_FT601.h index b607af02b..251f89da6 100644 --- a/src/comms/USB/FT601/USBTransferContext_FT601.h +++ b/src/comms/USB/FT601/USBTransferContext_FT601.h @@ -4,7 +4,6 @@ #include "USBTransferContext.h" #ifndef __unix__ - #include "windows.h" #include "FTD3XXLibrary/FTD3XX.h" #endif diff --git a/src/comms/USB/FX3/CMakeLists.txt b/src/comms/USB/FX3/CMakeLists.txt index 2654ec3b4..88f0282b4 100644 --- a/src/comms/USB/FX3/CMakeLists.txt +++ b/src/comms/USB/FX3/CMakeLists.txt @@ -1,11 +1,37 @@ if(WIN32) find_package(CyAPI) - set(USB_FOUND ${CYAPI_FOUND}) - set(USB_INCLUDE_DIRS ${CYAPI_INCLUDE_DIRS}) - set(USB_LIBRARIES ${CYAPI_LIBRARIES} SetupAPI) + set(FX3_FOUND ${CYAPI_FOUND}) + set(FX3_INCLUDE_DIRS ${CYAPI_INCLUDE_DIRS}) + set(FX3_LIBRARIES ${CYAPI_LIBRARIES} SetupAPI) + if (FX3_FOUND) + message(STATUS "FX3_INCLUDE_DIRS: ${FX3_INCLUDE_DIRS}") + message(STATUS "FX3_LIBRARIES: ${FX3_LIBRARIES}") + else() + message(WARNING "CYAPI SDK not found. Omitting Cypress FX3 USB support") + endif() elseif(UNIX) find_package(libusb-1.0) - set(USB_FOUND ${LIBUSB_1_FOUND}) - set(USB_INCLUDE_DIRS ${LIBUSB_1_INCLUDE_DIRS}) - set(USB_LIBRARIES ${LIBUSB_1_LIBRARIES}) + set(FX3_FOUND ${LIBUSB_1_FOUND}) + if (NOT ${FX3_FOUND}) + message(WARNING "libusb-1.0 libraries not found. Omitting Cypress FX3 USB support") + endif() + set(FX3_INCLUDE_DIRS ${LIBUSB_1_INCLUDE_DIRS}) + set(FX3_LIBRARIES ${LIBUSB_1_LIBRARIES}) endif() + +include(FeatureSummary) +include(CMakeDependentOption) +cmake_dependent_option(ENABLE_USB_FX3 "Enable FX3" ON "FX3_FOUND" OFF) +add_feature_info(USB_FX3 ENABLE_USB_FX3 "USB support for Cypress FX3") +if (NOT ENABLE_USB_FX3) + return() +endif() + +set(CONNECTION_FX3_SOURCES + ${CMAKE_CURRENT_LIST_DIR}/FX3.cpp + ${CMAKE_CURRENT_LIST_DIR}/USBTransferContext_FX3.cpp +) + +target_include_directories(${MAIN_LIBRARY_NAME} PRIVATE ${FX3_INCLUDE_DIRS} ${THIS_SOURCE_DIR}) +target_sources(${MAIN_LIBRARY_NAME} PRIVATE ${CONNECTION_FX3_SOURCES}) +target_link_libraries(${MAIN_LIBRARY_NAME} PUBLIC ${FX3_LIBRARIES}) diff --git a/src/comms/USB/TRXLooper_USB.cpp b/src/comms/USB/TRXLooper_USB.cpp index d714a7eea..b7f8bb805 100644 --- a/src/comms/USB/TRXLooper_USB.cpp +++ b/src/comms/USB/TRXLooper_USB.cpp @@ -120,16 +120,16 @@ void TRXLooper_USB::TransmitPacketsLoop() SamplesPacketType* srcPkt = nullptr; bool isBufferFull = false; - uint payloadSize = 0; - uint bytesUsed = 0; - uint packetsCreated = 0; + uint32_t payloadSize = 0; + uint32_t bytesUsed = 0; + uint32_t packetsCreated = 0; const bool packed = mConfig.linkFormat == SDRDevice::StreamConfig::DataFormat::I12; - uint samplesInPkt = (packed ? 1360 : 1020) / conversion.channelCount; + uint32_t samplesInPkt = (packed ? 1360 : 1020) / conversion.channelCount; const bool mimo = std::max(mConfig.channels.at(lime::TRXDir::Tx).size(), mConfig.channels.at(lime::TRXDir::Rx).size()) > 1; const int bytesForFrame = (packed ? 3 : 4) * (mimo ? 2 : 1); - uint maxPayloadSize = std::min(4080u, bytesForFrame * samplesInPkt); + uint32_t maxPayloadSize = std::min(4080u, bytesForFrame * samplesInPkt); const uint8_t safeTxEndPt = txEndPt; // To make sure no undefined behaviour happens when killing the thread @@ -191,8 +191,8 @@ void TRXLooper_USB::TransmitPacketsLoop() header->ignoreTimestamp(!srcPkt->useTimestamp); - const uint freeSpace = std::min(maxPayloadSize - payloadSize, bufferSize - bytesUsed); - uint transferCount = std::min(freeSpace / bytesForFrame, static_cast(srcPkt->size())); + const uint32_t freeSpace = std::min(maxPayloadSize - payloadSize, bufferSize - bytesUsed); + uint32_t transferCount = std::min(freeSpace / bytesForFrame, static_cast(srcPkt->size())); transferCount = std::min(transferCount, samplesInPkt); if (transferCount > 0) diff --git a/src/comms/USB/USBEntry.cpp b/src/comms/USB/USBEntry.cpp index 86d4e7a27..b59f05906 100644 --- a/src/comms/USB/USBEntry.cpp +++ b/src/comms/USB/USBEntry.cpp @@ -47,14 +47,12 @@ USBEntry::~USBEntry() std::vector USBEntry::enumerate(const DeviceHandle& hint) { -#ifdef __unix__ std::vector handles; if (!hint.media.empty() && hint.media.find("USB") == std::string::npos) - { return handles; - } +#ifdef __unix__ libusb_device** devs; // Pointer to pointer of device, used to retrieve a list of devices int usbDeviceCount = libusb_get_device_list(ctx, &devs); @@ -98,9 +96,10 @@ std::vector USBEntry::enumerate(const DeviceHandle& hint) } libusb_free_device_list(devs, 1); - - return handles; +#else + // TODO: implement for windows #endif + return handles; } #ifdef __unix__ diff --git a/src/comms/USB/USBGeneric.cpp b/src/comms/USB/USBGeneric.cpp index 1e9ada12b..17724b996 100644 --- a/src/comms/USB/USBGeneric.cpp +++ b/src/comms/USB/USBGeneric.cpp @@ -197,7 +197,7 @@ void USBGeneric::Disconnect() int32_t USBGeneric::BulkTransfer(uint8_t endPointAddr, uint8_t* data, int length, int32_t timeout_ms) { long len = 0; - if (not IsConnected()) + if (!IsConnected()) { throw std::runtime_error("BulkTransfer: USB device is not connected"); } @@ -225,7 +225,7 @@ int32_t USBGeneric::ControlTransfer( int requestType, int request, int value, int index, uint8_t* data, uint32_t length, int32_t timeout_ms) { long len = length; - if (not IsConnected()) + if (!IsConnected()) { throw std::runtime_error("ControlTransfer: USB device is not connected"); } diff --git a/src/examples/basicRX.cpp b/src/examples/basicRX.cpp index c3eb956fa..936171dc6 100644 --- a/src/examples/basicRX.cpp +++ b/src/examples/basicRX.cpp @@ -108,7 +108,7 @@ int main(int argc, char** argv) std::cout << "Stream started ...\n"; signal(SIGINT, intHandler); - const uint fftSize = 16384; + const unsigned int fftSize = 16384; complex32f_t** rxSamples = new complex32f_t*[2]; // allocate two channels for simplicity for (int i = 0; i < 2; ++i) rxSamples[i] = new complex32f_t[fftSize]; diff --git a/src/examples/basicTX.cpp b/src/examples/basicTX.cpp index a54c9c349..145a428db 100644 --- a/src/examples/basicTX.cpp +++ b/src/examples/basicTX.cpp @@ -105,7 +105,7 @@ int main(int argc, char** argv) std::vector> txPattern(2); const int txPacketCount = 4; const int samplesInPkt = 1024; - for (uint i = 0; i < txPattern.size(); ++i) + for (size_t i = 0; i < txPattern.size(); ++i) { txPattern[i].resize(txPacketCount * samplesInPkt); for (int j = 0; j < txPacketCount; ++j) diff --git a/src/include/limesuite/LMS7002M.h b/src/include/limesuite/LMS7002M.h index 06d0bdc9b..94f8f60fe 100644 --- a/src/include/limesuite/LMS7002M.h +++ b/src/include/limesuite/LMS7002M.h @@ -12,6 +12,7 @@ #include "limesuite/LMS7002M_parameters.h" #include "limesuite/OpStatus.h" +#include #include #include #include diff --git a/src/lms7002m/LMS7002M.cpp b/src/lms7002m/LMS7002M.cpp index b6deb6272..50e5717a5 100644 --- a/src/lms7002m/LMS7002M.cpp +++ b/src/lms7002m/LMS7002M.cpp @@ -6,6 +6,8 @@ #include "limesuite/LMS7002M.h" +#define _USE_MATH_DEFINES + #include #include #include diff --git a/src/lms7002m/LMS7002M_validation.cpp b/src/lms7002m/LMS7002M_validation.cpp index 94d84b901..6c1ea165c 100644 --- a/src/lms7002m/LMS7002M_validation.cpp +++ b/src/lms7002m/LMS7002M_validation.cpp @@ -61,15 +61,15 @@ bool LMS7002M_Validate(const SDRDevice::SDRConfig& cfg, std::vector for (int i = 0; i < 2; ++i) { const SDRDevice::ChannelConfig& ch = cfg.channel[i]; - if (ch.rx.enabled && not InRange(ch.rx.centerFrequency, minLO, maxLO)) + if (ch.rx.enabled && !InRange(ch.rx.centerFrequency, minLO, maxLO)) errors.push_back(strFormat("Rx ch%i LO (%g) out of range [%g:%g]", i, ch.rx.centerFrequency, minLO, maxLO)); - if (ch.tx.enabled && not InRange(ch.tx.centerFrequency, minLO, maxLO)) + if (ch.tx.enabled && !InRange(ch.tx.centerFrequency, minLO, maxLO)) errors.push_back(strFormat("Tx ch%i LO (%g) out of range [%g:%g]", i, ch.tx.centerFrequency, minLO, maxLO)); - if (ch.rx.enabled && not InRange(ch.rx.path, 0, 3)) + if (ch.rx.enabled && !InRange(ch.rx.path, 0, 3)) errors.push_back(strFormat("Rx ch%i invalid path(%i)", i, ch.rx.path)); - if (ch.tx.enabled && not InRange(ch.tx.path, 0, 2)) + if (ch.tx.enabled && !InRange(ch.tx.path, 0, 2)) errors.push_back(strFormat("Tx ch%i invalid path(%i)", i, ch.tx.path)); if (abs(ch.rx.NCOoffset) > ch.rx.sampleRate / 2) diff --git a/src/memory/MemoryPool.cpp b/src/memory/MemoryPool.cpp index 618606cfd..24fd52821 100644 --- a/src/memory/MemoryPool.cpp +++ b/src/memory/MemoryPool.cpp @@ -16,7 +16,11 @@ MemoryPool::MemoryPool(int blockCount, int blockSize, int alignment, const std:: { for (int i = 0; i < blockCount; ++i) { +#if __unix__ void* ptr = aligned_alloc(alignment, blockSize); +#else + void* ptr = _aligned_malloc(alignment, blockSize); +#endif if (!ptr) { throw std::runtime_error("Failed to allocate memory"); diff --git a/src/parsers/CoefficientFileParser.cpp b/src/parsers/CoefficientFileParser.cpp index f57624245..908d746c3 100644 --- a/src/parsers/CoefficientFileParser.cpp +++ b/src/parsers/CoefficientFileParser.cpp @@ -33,7 +33,7 @@ void CoefficientFileParser::parseMultilineComments(std::ifstream& file, std::str view = token; } - uint commentLevelsDeep = 1; + unsigned int commentLevelsDeep = 1; while (commentLevelsDeep != 0) // Multiline comments can be nested { diff --git a/src/protocols/SamplesPacket.h b/src/protocols/SamplesPacket.h index afc73cf8f..3f6208375 100644 --- a/src/protocols/SamplesPacket.h +++ b/src/protocols/SamplesPacket.h @@ -13,7 +13,7 @@ namespace lime { template class SamplesPacket { public: - static constexpr int headerSize = sizeof(SamplesPacket); + static constexpr int headerSize = 3 * sizeof(uint8_t*) * chCount + 17; static SamplesPacket* ConstructSamplesPacket(void* vptr, uint32_t samplesCount, uint8_t frameSize) { uint8_t* ptr = reinterpret_cast(vptr); diff --git a/src/vectorization/samplesConversion.cpp b/src/vectorization/samplesConversion.cpp index 855898cda..820936d1c 100644 --- a/src/vectorization/samplesConversion.cpp +++ b/src/vectorization/samplesConversion.cpp @@ -6,8 +6,7 @@ namespace lime { // templates with fixed iteration count allow to produce more efficient instructions -template -static void fastPath_complex16_to_complex32f(complex32f_t* __restrict__ dest, const complex16_t* __restrict__ src) +template static void fastPath_complex16_to_complex32f(complex32f_t* dest, const complex16_t* src) { constexpr float scale = 1.0f / 32768.0f; for (uint16_t i = 0; i < srcCount; i += 2) @@ -20,8 +19,7 @@ static void fastPath_complex16_to_complex32f(complex32f_t* __restrict__ dest, co } } -static void slowPath_complex16_to_complex32f( - complex32f_t* __restrict__ dest, const complex16_t* __restrict__ src, uint32_t srcCount) +static void slowPath_complex16_to_complex32f(complex32f_t* dest, const complex16_t* src, uint32_t srcCount) { constexpr float scale = 1.0f / 32768.0f; for (uint16_t i = 0; i < srcCount; i += 2) @@ -34,7 +32,7 @@ static void slowPath_complex16_to_complex32f( } } -void complex16_to_complex32f(complex32f_t* __restrict__ dest, const complex16_t* __restrict__ src, uint32_t srcCount) +void complex16_to_complex32f(complex32f_t* dest, const complex16_t* src, uint32_t srcCount) { switch (srcCount) { @@ -57,8 +55,7 @@ void complex16_to_complex32f(complex32f_t* __restrict__ dest, const complex16_t* } template -static void fastPath_complex16_to_complex32f_unzip( - complex32f_t* __restrict__ destA, complex32f_t* __restrict__ destB, const complex16_t* __restrict__ src) +static void fastPath_complex16_to_complex32f_unzip(complex32f_t* destA, complex32f_t* destB, const complex16_t* src) { constexpr float scale = 1.0f / 32768.0f; for (uint32_t i = 0; i < srcCount / 2; i++) @@ -73,7 +70,7 @@ static void fastPath_complex16_to_complex32f_unzip( } static void slowPath_complex16_to_complex32f_unzip( - complex32f_t* __restrict__ destA, complex32f_t* __restrict__ destB, const complex16_t* __restrict__ src, uint32_t srcCount) + complex32f_t* destA, complex32f_t* destB, const complex16_t* src, uint32_t srcCount) { constexpr float scale = 1.0f / 32768.0f; for (uint32_t i = 0; i < srcCount / 2; i++) @@ -87,8 +84,7 @@ static void slowPath_complex16_to_complex32f_unzip( } } -void complex16_to_complex32f_unzip( - complex32f_t* __restrict__ destA, complex32f_t* __restrict__ destB, const complex16_t* __restrict__ src, uint32_t srcCount) +void complex16_to_complex32f_unzip(complex32f_t* destA, complex32f_t* destB, const complex16_t* src, uint32_t srcCount) { switch (srcCount) { @@ -110,8 +106,7 @@ void complex16_to_complex32f_unzip( } } -template -static void fastPath_complex32f_to_complex16(complex16_t* __restrict__ dest, const complex32f_t* __restrict__ src) +template static void fastPath_complex32f_to_complex16(complex16_t* dest, const complex32f_t* src) { const int16_t scale = 32767; for (uint32_t i = 0; i < srcCount; i++) @@ -121,8 +116,7 @@ static void fastPath_complex32f_to_complex16(complex16_t* __restrict__ dest, con } } -static void slowPath_complex32f_to_complex16( - complex16_t* __restrict__ dest, const complex32f_t* __restrict__ src, uint32_t srcCount) +static void slowPath_complex32f_to_complex16(complex16_t* dest, const complex32f_t* src, uint32_t srcCount) { const int16_t scale = 32767; for (uint32_t i = 0; i < srcCount; i++) @@ -132,7 +126,7 @@ static void slowPath_complex32f_to_complex16( } } -void complex32f_to_complex16(complex16_t* __restrict__ dest, const complex32f_t* __restrict__ src, uint32_t srcCount) +void complex32f_to_complex16(complex16_t* dest, const complex32f_t* src, uint32_t srcCount) { switch (srcCount) { @@ -155,8 +149,7 @@ void complex32f_to_complex16(complex16_t* __restrict__ dest, const complex32f_t* } template -static void fastPath_complex32f_to_complex16_zip( - complex16_t* __restrict__ dest, const complex32f_t* __restrict__ srcA, const complex32f_t* __restrict__ srcB) +static void fastPath_complex32f_to_complex16_zip(complex16_t* dest, const complex32f_t* srcA, const complex32f_t* srcB) { constexpr int16_t scale = 32767; for (uint32_t i = 0; i < srcCount; i++) @@ -170,7 +163,7 @@ static void fastPath_complex32f_to_complex16_zip( } static void slowPath_complex32f_to_complex16_zip( - complex16_t* __restrict__ dest, const complex32f_t* __restrict__ srcA, const complex32f_t* __restrict__ srcB, uint32_t srcCount) + complex16_t* dest, const complex32f_t* srcA, const complex32f_t* srcB, uint32_t srcCount) { constexpr int16_t scale = 32767; for (uint32_t i = 0; i < srcCount; i++) @@ -183,8 +176,7 @@ static void slowPath_complex32f_to_complex16_zip( } } -void complex32f_to_complex16_zip( - complex16_t* __restrict__ dest, const complex32f_t* __restrict__ srcA, const complex32f_t* __restrict__ srcB, uint32_t srcCount) +void complex32f_to_complex16_zip(complex16_t* dest, const complex32f_t* srcA, const complex32f_t* srcB, uint32_t srcCount) { switch (srcCount) { diff --git a/src/vectorization/samplesConversion.h b/src/vectorization/samplesConversion.h index 161446250..d3fcb1531 100644 --- a/src/vectorization/samplesConversion.h +++ b/src/vectorization/samplesConversion.h @@ -6,15 +6,11 @@ namespace lime { -void complex16_to_complex32f(complex32f_t* __restrict__ dest, const complex16_t* __restrict__ src, uint32_t count); -void complex16_to_complex32f_unzip( - complex32f_t* __restrict__ destA, complex32f_t* __restrict__ destB, const complex16_t* __restrict__ src, uint32_t srcCount); +void complex16_to_complex32f(complex32f_t* dest, const complex16_t* src, uint32_t count); +void complex16_to_complex32f_unzip(complex32f_t* destA, complex32f_t* destB, const complex16_t* src, uint32_t srcCount); -void complex32f_to_complex16(complex16_t* __restrict__ dest, const complex32f_t* __restrict__ src, uint32_t count); -void complex32f_to_complex16_zip(complex16_t* __restrict__ dest, - const complex32f_t* __restrict__ srcA, - const complex32f_t* __restrict__ srcB, - uint32_t srcCount); +void complex32f_to_complex16(complex16_t* dest, const complex32f_t* src, uint32_t count); +void complex32f_to_complex16_zip(complex16_t* dest, const complex32f_t* srcA, const complex32f_t* srcB, uint32_t srcCount); } // namespace lime