diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml index 0af565b3b2..d3a5a82e3c 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/cmake.yml b/.github/workflows/cmake.yml index 2bae504ab0..e51b1cec74 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.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.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 + 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}} diff --git a/.github/workflows/gtest.yml b/.github/workflows/gtest.yml index 69f016834a..ad59f31c88 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,47 @@ 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, ] 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 + + - 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 -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 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 + diff --git a/.gitignore b/.gitignore index 93ec35fb5a..303db2d6a8 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,7 @@ docs/LMS_API_Documentation/* /debian/limesuite-images20.10.* !/debian/limesuite-images20.10.*.in /debian/debhelper-build-stamp +/.vs +/out/ +/CMakeSettings.json +/deps/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 2710917a93..5194a0bf38 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}" ) @@ -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/cmake/Modules/FindCyAPI.cmake b/cmake/Modules/FindCyAPI.cmake index 16fb55da04..48087df443 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/external/msvc/getopt.h b/external/msvc/getopt.h index 6c834b48dc..90db904887 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/CMakeLists.txt b/src/CMakeLists.txt index aa3e170234..14a42b03c5 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 a0e4392e11..b1e5757d08 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__ @@ -34,8 +35,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/Logger.h b/src/Logger.h index b4a0a38c57..5a21272c7f 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/StreamComposite.cpp b/src/StreamComposite.cpp index ea63b88079..81e0c8fe9b 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/SystemResources.in.cpp b/src/SystemResources.in.cpp index fac4ec4f42..db5b1fbb65 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/LimeSDR.cpp b/src/boards/LimeSDR/LimeSDR.cpp index 3f300e62a7..8affef4e68 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 3cddede7ab..f47112b872 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__ @@ -48,7 +47,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) { @@ -77,8 +76,14 @@ 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__ diff --git a/src/boards/LimeSDR/USB_CSR_Pipe_SDR.cpp b/src/boards/LimeSDR/USB_CSR_Pipe_SDR.cpp index 0a68f3ddab..ebac15a500 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,11 +33,22 @@ 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); } return port.ControlTransfer( - LIBUSB_REQUEST_TYPE_VENDOR, CTR_W_REQCODE, CTR_W_VALUE, CTR_W_INDEX, const_cast(data), length, timeout_ms); +#ifdef __unix__ + 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); } int USB_CSR_Pipe_SDR::Read(uint8_t* data, size_t length, int timeout_ms) @@ -57,9 +57,20 @@ 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); } return port.ControlTransfer( - LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN, CTR_R_REQCODE, CTR_R_VALUE, CTR_R_INDEX, data, length, timeout_ms); +#ifdef __unix__ + 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); } diff --git a/src/boards/LimeSDR_Mini/LimeSDR_MiniEntry.cpp b/src/boards/LimeSDR_Mini/LimeSDR_MiniEntry.cpp index b10e243ba4..c4072150fc 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 @@ -83,8 +84,15 @@ 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/boards/LimeSDR_X3/SlaveSelectShim.h b/src/boards/LimeSDR_X3/SlaveSelectShim.h index ba93083426..ad4ab1a8ff 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/boards_wxgui/pnlBoardControls.cpp b/src/boards_wxgui/pnlBoardControls.cpp index c50f898146..bd36caea89 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/common.h b/src/cli/common.h index aa60eec25e..8577b676af 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 48f0931c53..5e88fae3f0 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 5efd9c667c..ee66262bdd 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 a782b1a152..bd551353e1 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 85c8bf9787..ef06d75dab 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 c91f723e42..a9fe0c135e 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 @@ -19,12 +20,12 @@ using namespace lime; using namespace std; -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; } @@ -63,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/PCIe/LitePCIe.h b/src/comms/PCIe/LitePCIe.h index 77b9746ad3..ae95d62df2 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 f01e314bba..4df7d31df5 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 26b381b658..9a4c5fc9f6 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; @@ -149,23 +151,26 @@ 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) { lime::error("ERROR BEGIN DATA TRANSFER %d", ftStatus); - contexts[index].used = false; + context->used = false; return -1; } @@ -174,43 +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 && contexts[contextHandle].used == true) + if (contextHandle < 0) { - DWORD dwRet = WaitForSingleObject(contexts[contextHandle].inOvLap.hEvent, timeout_ms); + return true; + } - if (dwRet == WAIT_OBJECT_0) - { - return true; - } + USBTransferContext_FT601* context = &dynamic_cast(contexts)[contextHandle]; + + if (!context->used) + { + return true; //there is nothing to wait for (signal wait finished) } - return true; //there is nothing to wait for (signal wait finished) + DWORD dwRet = WaitForSingleObject(context->inOvLap->hEvent, timeout_ms); + + if (dwRet == WAIT_OBJECT_0) + { + return true; + } + + 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; + return 0; + } - ftStatus = FT_GetOverlappedResult(mFTHandle, &contexts[contextHandle].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, &contexts[contextHandle].inOvLap); - contexts[contextHandle].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) @@ -219,10 +239,12 @@ 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 (context->used && context->endPointAddr == endPointAddr) { - FT_ReleaseOverlapped(mFTHandle, &contexts[i].inOvLap); - contexts[i].used = false; + FT_ReleaseOverlapped(mFTHandle, context->inOvLap); + context->used = false; } } @@ -235,8 +257,56 @@ 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() +{ + 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 456e2f0537..25187be210 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(); @@ -44,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/FT601/USBTransferContext_FT601.cpp b/src/comms/USB/FT601/USBTransferContext_FT601.cpp index 05c9e53197..aecd9d6c25 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/FT601/USBTransferContext_FT601.h b/src/comms/USB/FT601/USBTransferContext_FT601.h index 251f89da60..719a84eb7c 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 48a3e6484a..e89f85ee3d 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/FX3.cpp b/src/comms/USB/FX3/FX3.cpp index 31f5418e40..700173ee46 100644 --- a/src/comms/USB/FX3/FX3.cpp +++ b/src/comms/USB/FX3/FX3.cpp @@ -1,11 +1,35 @@ #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) { +#ifndef __unix__ + std::scoped_lock lock{ FX3mutex }; + + 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() @@ -16,7 +40,89 @@ FX3::~FX3() 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()) + { + return ReportError(ERANGE, "FX3::Connect: Device index out of range"); + } + + if (USBDevicePrimary->Open(index) == false) + { + return ReportError(-1, "FX3::Connect: 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; @@ -36,11 +142,111 @@ void FX3::Disconnect() libusb_close(dev_handle); dev_handle = nullptr; } +#else + std::scoped_lock lock{ FX3mutex }; + + 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__ + std::scoped_lock lock{ FX3mutex }; + + 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) +{ + std::scoped_lock lock{ FX3mutex }; + + switch (endPoint) + { + case FX3::CONTROL_BULK_OUT_ADDRESS: // Write + if (OutCtrlBulkEndPt) + { + LONG longLength = static_cast(length); + if (OutCtrlBulkEndPt->XferData(data, longLength)) + { + return length; + } + } + break; + case FX3::CONTROL_BULK_IN_ADDRESS: // Read + if (InCtrlBulkEndPt) + { + LONG longLength = static_cast(length); + + if (InCtrlBulkEndPt->XferData(data, longLength)) + { + return length; + } + } + break; + default: + throw std::logic_error("Invalid endpoint"s); + } + return 0; +} + +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 + 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; + } + } + break; + default: + throw std::logic_error("Invalid request type"s); + } + return 0; +} + int FX3::BeginDataXfer(uint8_t* buffer, uint32_t length, uint8_t endPointAddr) { int index = GetUSBContextIndex(); @@ -50,10 +256,27 @@ int FX3::BeginDataXfer(uint8_t* buffer, uint32_t length, uint8_t endPointAddr) return -1; } - if (InEndPt[endPointAddr & 0xF]) + std::scoped_lock lock{ FX3mutex }; + USBTransferContext_FX3* FX3context = &static_cast(contexts)[index]; + + switch (endPointAddr) { - contexts[index].EndPt = InEndPt[endPointAddr & 0xF]; - contexts[index].context = contexts[index].EndPt->BeginDataXfer(buffer, length, contexts[index].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(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"s); } return index; @@ -61,42 +284,117 @@ 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) + bool 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) { - 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 true; } - return 0; + USBTransferContext_FX3* FX3context = &static_cast(contexts)[contextHandle]; + + if (!FX3context->used) + { + return 0; + } + + std::scoped_lock lock{ FX3mutex }; + + long len = length; + bool status = FX3context->EndPt->FinishDataXfer(buffer, len, FX3context->inOvLap, FX3context->context); + FX3context->used = false; + FX3context->Reset(); + + if (!status) + { + return 0; + } + + return len; } void FX3::AbortEndpointXfers(uint8_t endPointAddr) { for (int i = 0; i < MAX_EP_CNT; i++) { + std::scoped_lock lock{ FX3mutex }; + if (InEndPt[i] && InEndPt[i]->Address == endPointAddr) { InEndPt[i]->Abort(); } + + if (OutEndPt[i] && OutEndPt[i]->Address == endPointAddr) + { + OutEndPt[i]->Abort(); + } } 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() +{ + 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 e4d6f792c5..a5ccfc12b7 100644 --- a/src/comms/USB/FX3/FX3.h +++ b/src/comms/USB/FX3/FX3.h @@ -9,6 +9,10 @@ #include #include +#ifndef __unix__ + #include "CyAPI.h" +#endif // !__unix__ + namespace lime { /** @brief A class for communicating with devices using the Cypress USB 3.0 CYUSB3014-BZXC USB controller. */ @@ -21,11 +25,55 @@ 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 + + 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 + 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; + + std::mutex FX3mutex; #endif }; diff --git a/src/comms/USB/FX3/USBTransferContext_FX3.h b/src/comms/USB/FX3/USBTransferContext_FX3.h index 43752a264c..5774006bae 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 { @@ -23,7 +24,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 65390876cd..3356283db5 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 17724b9963..912d25079a 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/USBGeneric.h b/src/comms/USB/USBGeneric.h index 8c9cf4c97f..d779d8c164 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/comms/USB/USBTransferContext.h b/src/comms/USB/USBTransferContext.h index e85086da9d..7d60d26e83 100644 --- a/src/comms/USB/USBTransferContext.h +++ b/src/comms/USB/USBTransferContext.h @@ -16,6 +16,11 @@ #endif #endif +#ifndef __unix__ + #include + #undef ERROR +#endif + namespace lime { /** @brief Base class for a USB transfer context. */ @@ -34,6 +39,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 c4fddc0482..9cb9fbc13e 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/OpStatus.h b/src/include/limesuite/OpStatus.h index 915b506d4e..78f107afa2 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/include/limesuite/SDRDevice.h b/src/include/limesuite/SDRDevice.h index 3c06df7cd8..3d7c407124 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/lms7002_wxgui/lms7002_dlgGFIR_Coefficients.cpp b/src/lms7002_wxgui/lms7002_dlgGFIR_Coefficients.cpp index 85329ecedb..33f0d71c7a 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/lms7002_wxgui/lms7002_pnlMCU_BD_view.cpp b/src/lms7002_wxgui/lms7002_pnlMCU_BD_view.cpp index 98bab9ca43..9c0359116b 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()) { diff --git a/src/lms7002m/LMS7002M.cpp b/src/lms7002m/LMS7002M.cpp index 50e5717a5e..367a96bf05 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 24fd528215..35a50a66a1 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) { @@ -39,11 +39,21 @@ MemoryPool::~MemoryPool() while (!mFreeBlocks.empty()) { void* ptr = mFreeBlocks.top(); +#ifdef __unix__ free(ptr); +#else + _aligned_free(ptr); +#endif mFreeBlocks.pop(); } for (auto ptr : mUsedBlocks) + { +#ifdef __unix__ free(ptr); +#else + _aligned_free(ptr); +#endif + } } void* MemoryPool::Allocate(int size) diff --git a/src/parsers/CoefficientFileParser.cpp b/src/parsers/CoefficientFileParser.cpp index 908d746c3d..b864b3ce52 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 5fb927c2f0..d333522ff9 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/CMakeLists.txt b/src/tests/CMakeLists.txt index 2248f558f3..069efaec1a 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) @@ -32,14 +52,14 @@ 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) 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/tests/boards/LimeSDR/USB_CSR_Pipe_SDRTest.cpp b/src/tests/boards/LimeSDR/USB_CSR_Pipe_SDRTest.cpp index 602c173259..f9969c3062 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,8 @@ 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 +38,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 +69,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 +86,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 6a5539853b..00d0b703ec 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 ae5ad42fed..83fd276a42 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 3d0bbb609e..e442fd12fc 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; diff --git a/src/tests/parsers/CoefficientFileParserTest.cpp b/src/tests/parsers/CoefficientFileParserTest.cpp index c786a26a12..0c35b327d4 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); diff --git a/src/threadHelper/threadHelper.cpp b/src/threadHelper/threadHelper.cpp index 0efb192cfd..30448b47ce 100644 --- a/src/threadHelper/threadHelper.cpp +++ b/src/threadHelper/threadHelper.cpp @@ -4,6 +4,7 @@ #include #else #include + #undef ERROR #endif #include "Logger.h" @@ -143,7 +144,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; diff --git a/src/utilities_gui/pnlMiniLog.cpp b/src/utilities_gui/pnlMiniLog.cpp index 90654f68ab..dc9a94c309 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)