Compare commits
6 commits
master
...
dev-thread
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3712a78fd9 | ||
|
|
38876e19c8 | ||
|
|
60ae4d0683 | ||
|
|
eadce58336 | ||
|
|
4dc30c0159 | ||
|
|
b1ab659d6d |
55 changed files with 425 additions and 635 deletions
11
debian/copyright
vendored
11
debian/copyright
vendored
|
|
@ -60,17 +60,6 @@ License: OpenCores-I2C
|
||||||
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
POSSIBILITY OF SUCH DAMAGE.
|
POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
Files: host/cmake/modules/FindLibPThreadsWin32.cmake
|
|
||||||
Copyright: 2008-2009 Hendrik Sattler
|
|
||||||
2013-2018 Nuand LLC
|
|
||||||
License: GPL-2+
|
|
||||||
Comment: This is file is based off of the FindLibUSB.cmake file written by
|
|
||||||
Hendrik Sattler, from the OpenOBEX project (licensed GPLv2/LGPL). (If
|
|
||||||
this is not correct, please contact us so we can attribute the author
|
|
||||||
appropriately.)
|
|
||||||
https://github.com/zuckschwerdt/openobex/blob/master/CMakeModules/FindLibUSB.cmake
|
|
||||||
http://dev.zuckschwerdt.org/openobex/
|
|
||||||
|
|
||||||
Files: host/cmake/modules/FindLibUSB.cmake
|
Files: host/cmake/modules/FindLibUSB.cmake
|
||||||
Copyright: 2008-2009 Hendrik Sattler
|
Copyright: 2008-2009 Hendrik Sattler
|
||||||
2013-2018 Nuand LLC
|
2013-2018 Nuand LLC
|
||||||
|
|
|
||||||
|
|
@ -230,29 +230,6 @@ add_custom_target(uninstall
|
||||||
# Windows-only, Post build: Copy libraries to our build output directory
|
# Windows-only, Post build: Copy libraries to our build output directory
|
||||||
################################################################################
|
################################################################################
|
||||||
if(WIN32 AND NOT CMAKE_CROSSCOMPILING)
|
if(WIN32 AND NOT CMAKE_CROSSCOMPILING)
|
||||||
find_package(LibPThreadsWin32)
|
|
||||||
if(LIBPTHREADSWIN32_FOUND)
|
|
||||||
set(WIN_RUNTIME_ITEMS ${WIN_RUNTIME_ITEMS}
|
|
||||||
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/licenses/pthreads-win32/COPYING.LIB.txt"
|
|
||||||
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/pthreadVC2.dll")
|
|
||||||
|
|
||||||
add_custom_command(
|
|
||||||
OUTPUT "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/licenses/pthreads-win32/COPYING.LIB.txt"
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
|
||||||
"${LIBPTHREADSWIN32_LIB_COPYING}"
|
|
||||||
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/licenses/pthreads-win32/COPYING.LIB.txt"
|
|
||||||
COMMENT "Copying pthreads-win32 license to output directory..."
|
|
||||||
)
|
|
||||||
|
|
||||||
add_custom_command(
|
|
||||||
OUTPUT "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/pthreadVC2.dll"
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
|
||||||
"${LIBPTHREADSWIN32_DLL}"
|
|
||||||
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/"
|
|
||||||
COMMENT "Copying pthreadVC2.dll to output directory..."
|
|
||||||
)
|
|
||||||
endif(LIBPTHREADSWIN32_FOUND)
|
|
||||||
|
|
||||||
if(LIBUSB_FOUND)
|
if(LIBUSB_FOUND)
|
||||||
set(WIN_RUNTIME_ITEMS ${WIN_RUNTIME_ITEMS}
|
set(WIN_RUNTIME_ITEMS ${WIN_RUNTIME_ITEMS}
|
||||||
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/licenses/libusb/COPYING"
|
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/licenses/libusb/COPYING"
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,6 @@ Windows users that wish to use a Cypress driver/library based libbladeRF backend
|
||||||
### CMake ###
|
### CMake ###
|
||||||
[CMake][CMake.org] is used to build the items in this directory. \>= v2.8.5 is required, but the latest available version is recommended.
|
[CMake][CMake.org] is used to build the items in this directory. \>= v2.8.5 is required, but the latest available version is recommended.
|
||||||
|
|
||||||
### pthreads-win32 - Windows-only ###
|
|
||||||
Windows users will need to get [pthreads-win32], and may (with newer Windows versions) need to build it from scratch.
|
|
||||||
|
|
||||||
## Build ##
|
## Build ##
|
||||||
|
|
||||||
### Linux and OSX ###
|
### Linux and OSX ###
|
||||||
|
|
@ -63,7 +60,6 @@ This process was most recently validated on Windows 10 Enterprise with CMake 3.9
|
||||||
- If you run into any failures, check these items, then re-run Configure:
|
- If you run into any failures, check these items, then re-run Configure:
|
||||||
- LIBUSB_PATH (and ENABLE_BACKEND_LIBUSB) - for using libusb
|
- LIBUSB_PATH (and ENABLE_BACKEND_LIBUSB) - for using libusb
|
||||||
- FX3_SDK_PATH (and ENABLE_BACKEND_CYAPI) - for using the Cypress driver
|
- FX3_SDK_PATH (and ENABLE_BACKEND_CYAPI) - for using the Cypress driver
|
||||||
- LIBPTHREADSWIN32_PATH
|
|
||||||
- Adjust options as desired and re-run the "Configure" command as needed. Values in red are new, and should be reviewed before running "Configure" again to get the red out.
|
- Adjust options as desired and re-run the "Configure" command as needed. Values in red are new, and should be reviewed before running "Configure" again to get the red out.
|
||||||
- Click the CMake GUI's "Generate" button.
|
- Click the CMake GUI's "Generate" button.
|
||||||
- In the ```build``` directory, a Visual Studio solution will now exist. You can click "Open Project" to get there.
|
- In the ```build``` directory, a Visual Studio solution will now exist. You can click "Open Project" to get there.
|
||||||
|
|
@ -71,21 +67,6 @@ This process was most recently validated on Windows 10 Enterprise with CMake 3.9
|
||||||
- Upon building the solution, build artifacts will be present in: ```build\output\<build type>```
|
- Upon building the solution, build artifacts will be present in: ```build\output\<build type>```
|
||||||
- ```<build_type>``` may refer to Debug or Release, for example
|
- ```<build_type>``` may refer to Debug or Release, for example
|
||||||
|
|
||||||
#### pthreads-win32 ####
|
|
||||||
If you are using a newer version of Windows / Visual Studio and are getting ```error C0211: 'timespec': 'struct' type redefinition``` when trying to build bladeRF, you will need to rebuild pthreads-win32. The below process seems to work with pthreads-w32 2.9.1.
|
|
||||||
|
|
||||||
- Get full source tree from [pthreads-win32] website, and unpack someplace convenient
|
|
||||||
- In Visual Studio, open `pthreads-w32-2-9-1-release\pthreads.2\pthread.dsw` (one-way upgrade is OK)
|
|
||||||
- Right-click the solution, select "Retarget solution", hit OK.
|
|
||||||
- Change "Solution Configurations" dropdown to "Release" ("Debug" doesn't work, but that's OK)
|
|
||||||
- Edit pthread.h to add `#define HAVE_STRUCT_TIMESPEC` and `#define PTW32_ARCHx64` near the top, just below the include guard
|
|
||||||
- Build the solution
|
|
||||||
|
|
||||||
- Back over in the bladeRF CMake:
|
|
||||||
- File -> Delete Cache
|
|
||||||
- Redo the "Configure" dance as before
|
|
||||||
- Point `LIBPTHREADSWIN32_PATH` to the `pthreads-w32-2-9-1-release\pthreads.2` directory you were just working in
|
|
||||||
|
|
||||||
## CMake Options and Flags ##
|
## CMake Options and Flags ##
|
||||||
|
|
||||||
Below is a list of useful and project-specific CMake options. Please see the [CMake documentation] for
|
Below is a list of useful and project-specific CMake options. Please see the [CMake documentation] for
|
||||||
|
|
@ -120,4 +101,3 @@ more information.
|
||||||
[CMake documentation]: http://www.cmake.org/cmake/help/documentation.html (Cmake documentation)
|
[CMake documentation]: http://www.cmake.org/cmake/help/documentation.html (Cmake documentation)
|
||||||
[Cypress FX3 SDK]: http://www.cypress.com/?rID=57990 (Cypress FX3 SDK)
|
[Cypress FX3 SDK]: http://www.cypress.com/?rID=57990 (Cypress FX3 SDK)
|
||||||
[redhat144967]: https://bugzilla.redhat.com/show_bug.cgi?id=144967 (Red Hat Bugzilla - Bug 144967)
|
[redhat144967]: https://bugzilla.redhat.com/show_bug.cgi?id=144967 (Red Hat Bugzilla - Bug 144967)
|
||||||
[pthreads-win32]: https://sourceware.org/pthreads-win32/ (POSIX Threads for Win32)
|
|
||||||
|
|
|
||||||
|
|
@ -1,113 +0,0 @@
|
||||||
# This is file is based off of the FindLibUSB.cmake file written by Hendrik Sattler,
|
|
||||||
# from the OpenOBEX project (licensed GPLv2/LGPL). (If this is not correct,
|
|
||||||
# please contact us so we can attribute the author appropriately.)
|
|
||||||
#
|
|
||||||
# https://github.com/zuckschwerdt/openobex/blob/master/CMakeModules/FindLibUSB.cmake
|
|
||||||
# http://dev.zuckschwerdt.org/openobex/
|
|
||||||
#
|
|
||||||
# Find pthreads-win32
|
|
||||||
#
|
|
||||||
# This requires the LIBPTHREADSWIN32_PATH variable to be set to the path to the
|
|
||||||
# a pthreads-win32 release, such as the Pre-built.2 directory from the 2.9.1 release:
|
|
||||||
# ftp://sourceware.org/pub/pthreads-win32/pthreads-w32-2-9-1-release.zip
|
|
||||||
#
|
|
||||||
# The following standard variables get defined:
|
|
||||||
# LIBPTHREADSWIN32_FOUND: true if LibUSB was found
|
|
||||||
# LIBPTHREADSWIN32_HEADER_FILE: the location of the C header file
|
|
||||||
# LIBPTHREADSWIN32_INCLUDE_DIRS: the directories that contain headers
|
|
||||||
# LIBPTHREADSWIN32_LIBRARIES: the library files
|
|
||||||
# LIBPTHREADSWIN32_LIB_COPYING: the license associated with the library
|
|
||||||
# LIBPTHREADSWIN32_DLL: the pthreadVC2.dll file
|
|
||||||
|
|
||||||
if(DEFINED __INCLUDED_BLADERF_FINDLIBPTHREADSWIN32_CMAKE)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
set(__INCLUDED_BLADERF_FINDLIBPTHREADSWIN32_CMAKE TRUE)
|
|
||||||
|
|
||||||
include ( CheckLibraryExists )
|
|
||||||
include ( CheckIncludeFile )
|
|
||||||
|
|
||||||
set(LIBPTHREADSWIN32_PATH
|
|
||||||
"C:/Program Files (x86)/pthreads-win32"
|
|
||||||
CACHE
|
|
||||||
PATH
|
|
||||||
"Path to win-pthreads files. (This is generally only needed for Windows users who downloaded binary distributions.)"
|
|
||||||
)
|
|
||||||
|
|
||||||
find_file ( LIBPTHREADSWIN32_HEADER_FILE
|
|
||||||
NAMES
|
|
||||||
pthread.h
|
|
||||||
PATHS
|
|
||||||
${LIBPTHREADSWIN32_PATH}
|
|
||||||
PATH_SUFFIXES
|
|
||||||
include include
|
|
||||||
)
|
|
||||||
mark_as_advanced ( LIBPTHREADSWIN32_HEADER_FILE )
|
|
||||||
get_filename_component ( LIBPTHREADSWIN32_INCLUDE_DIRS "${LIBPTHREADSWIN32_HEADER_FILE}" PATH )
|
|
||||||
|
|
||||||
if ( WIN32 )
|
|
||||||
if ( MSVC )
|
|
||||||
if ( CMAKE_CL_64 )
|
|
||||||
set ( LIBPTHREADSWIN32_LIBRARY_PATH_SUFFIX x64 )
|
|
||||||
else ( CMAKE_CL_64 )
|
|
||||||
set ( LIBPTHREADSWIN32_LIBRARY_PATH_SUFFIX x86 )
|
|
||||||
endif ( CMAKE_CL_64 )
|
|
||||||
elseif ( CMAKE_COMPILER_IS_GNUCC )
|
|
||||||
if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
|
|
||||||
set ( LIBPTHREADSWIN32_LIBRARY_PATH_SUFFIX x64 )
|
|
||||||
else ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
|
|
||||||
set ( LIBPTHREADSWIN32_LIBRARY_PATH_SUFFIX x86 )
|
|
||||||
endif ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
|
|
||||||
endif ( MSVC )
|
|
||||||
|
|
||||||
find_library ( PTHREAD_LIBRARY
|
|
||||||
NAMES
|
|
||||||
pthreadVC2
|
|
||||||
PATHS
|
|
||||||
${LIBPTHREADSWIN32_PATH}
|
|
||||||
PATH_SUFFIXES
|
|
||||||
lib/${LIBPTHREADSWIN32_LIBRARY_PATH_SUFFIX}
|
|
||||||
)
|
|
||||||
|
|
||||||
mark_as_advanced ( PTHREAD_LIBRARY )
|
|
||||||
if ( PTHREAD_LIBRARY )
|
|
||||||
set ( LIBPTHREADSWIN32_LIBRARIES ${PTHREAD_LIBRARY} )
|
|
||||||
endif ( PTHREAD_LIBRARY )
|
|
||||||
|
|
||||||
find_file ( PTHREAD_DLL
|
|
||||||
NAMES
|
|
||||||
pthreadVC2.dll
|
|
||||||
PATHS
|
|
||||||
${LIBPTHREADSWIN32_PATH}
|
|
||||||
PATH_SUFFIXES
|
|
||||||
dll/${LIBPTHREADSWIN32_LIBRARY_PATH_SUFFIX}
|
|
||||||
.
|
|
||||||
)
|
|
||||||
|
|
||||||
mark_as_advanced ( PTHREAD_DLL )
|
|
||||||
if ( PTHREAD_DLL )
|
|
||||||
set ( LIBPTHREADSWIN32_DLL ${PTHREAD_DLL} )
|
|
||||||
endif ( PTHREAD_DLL )
|
|
||||||
|
|
||||||
else ( WIN32 )
|
|
||||||
message(FATAL_ERROR "This file only supports Windows")
|
|
||||||
endif ( WIN32 )
|
|
||||||
|
|
||||||
set ( LIBPTHREADSWIN32_LIB_COPYING
|
|
||||||
"${LIBPTHREADSWIN32_PATH}/COPYING.LIB" )
|
|
||||||
if ( NOT EXISTS ${LIBPTHREADSWIN32_LIB_COPYING} )
|
|
||||||
message(FATAL_ERROR "Unable to find pthread-win32 COPYING.LIB file")
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if ( LIBPTHREADSWIN32_INCLUDE_DIRS AND LIBPTHREADSWIN32_LIBRARIES AND LIBPTHREADSWIN32_DLL )
|
|
||||||
set ( LIBPTHREADSWIN32_FOUND true )
|
|
||||||
endif ( LIBPTHREADSWIN32_INCLUDE_DIRS AND LIBPTHREADSWIN32_LIBRARIES AND LIBPTHREADSWIN32_DLL )
|
|
||||||
|
|
||||||
if ( LIBPTHREADSWIN32_FOUND )
|
|
||||||
set ( CMAKE_REQUIRED_INCLUDES "${LIBPTHREADSWIN32_INCLUDE_DIRS}" )
|
|
||||||
check_include_file ( "{LIBPTHREADSWIN32_HEADER_FILE}" LIBPTHREADSWIN32_FOUND )
|
|
||||||
endif ( LIBPTHREADSWIN32_FOUND )
|
|
||||||
|
|
||||||
if ( NOT LIBPTHREADSWIN32_FOUND )
|
|
||||||
message ( FATAL_ERROR "pthreads-win32 not found. If you're using a binary distribution, try setting -DLIBPTHREADSWIN32_PATH=<path_to_win_pthread_files>." )
|
|
||||||
endif ( NOT LIBPTHREADSWIN32_FOUND )
|
|
||||||
|
|
@ -32,11 +32,30 @@
|
||||||
/* Currently, only pthreads is supported. In the future, native windows threads
|
/* Currently, only pthreads is supported. In the future, native windows threads
|
||||||
* may be used; one of the objectives of this file is to ease that transistion.
|
* may be used; one of the objectives of this file is to ease that transistion.
|
||||||
*/
|
*/
|
||||||
#include <pthread.h>
|
|
||||||
#include "rel_assert.h"
|
#include "rel_assert.h"
|
||||||
|
|
||||||
#define MUTEX pthread_mutex_t
|
#if (defined(_WIN32) || defined(USE_NATIVE_THREADS)) && \
|
||||||
|
!defined(DO_NOT_USE_PTHREADS)
|
||||||
|
// Do not use pthreads on Windows
|
||||||
|
#undef USE_PTHREADS
|
||||||
|
#else
|
||||||
|
// Use pthreads on non-Windows platforms
|
||||||
|
#undef USE_PTHREADS
|
||||||
|
#define USE_PTHREADS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_PTHREADS
|
||||||
|
|
||||||
|
/* Use pthreads */
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <time.h>
|
||||||
|
#define CLOCK_REALTIME 0
|
||||||
|
|
||||||
|
#define THREAD pthread_t
|
||||||
|
#define MUTEX pthread_mutex_t
|
||||||
|
#define COND pthread_cond_t
|
||||||
#ifdef ENABLE_LOCK_CHECKS
|
#ifdef ENABLE_LOCK_CHECKS
|
||||||
# define MUTEX_INIT(m) do { \
|
# define MUTEX_INIT(m) do { \
|
||||||
int status; \
|
int status; \
|
||||||
|
|
@ -64,11 +83,103 @@
|
||||||
int status = pthread_mutex_destroy(m); \
|
int status = pthread_mutex_destroy(m); \
|
||||||
assert(status == 0 && "Mutex destroy failure");\
|
assert(status == 0 && "Mutex destroy failure");\
|
||||||
} while (0)
|
} while (0)
|
||||||
#else
|
#else /* ENABLE_LOCK_CHECKS */
|
||||||
|
|
||||||
#define MUTEX_INIT(m) pthread_mutex_init(m, NULL)
|
#define MUTEX_INIT(m) pthread_mutex_init(m, NULL)
|
||||||
#define MUTEX_LOCK(m) pthread_mutex_lock(m)
|
#define MUTEX_LOCK(m) pthread_mutex_lock(m)
|
||||||
#define MUTEX_UNLOCK(m) pthread_mutex_unlock(m)
|
#define MUTEX_UNLOCK(m) pthread_mutex_unlock(m)
|
||||||
#define MUTEX_DESTROY(m) pthread_mutex_destroy(m)
|
#define MUTEX_DESTROY(m) pthread_mutex_destroy(m)
|
||||||
#endif
|
|
||||||
|
#endif /* ENABLE_LOCK_CHECKS */
|
||||||
|
|
||||||
|
# define THREAD_CREATE(x,y,z) pthread_create(x, NULL, y, z)
|
||||||
|
# define THREAD_SUCCESS 0
|
||||||
|
# define THREAD_TIMEOUT ETIMEDOUT
|
||||||
|
# define THREAD_CANCEL(m) pthread_cancel(m)
|
||||||
|
# define THREAD_JOIN(t, s) pthread_join(t, s)
|
||||||
|
# define THREAD_EXIT(s) pthread_exit(s)
|
||||||
|
|
||||||
|
# define COND_INIT(m) pthread_cond_init(m, NULL)
|
||||||
|
# define COND_SIGNAL(m) pthread_cond_signal(m)
|
||||||
|
// POSIX implementation as a function
|
||||||
|
static inline int posix_cond_timedwait(pthread_cond_t *c,
|
||||||
|
pthread_mutex_t *m,
|
||||||
|
unsigned int t)
|
||||||
|
{
|
||||||
|
struct timespec ts;
|
||||||
|
clock_gettime(CLOCK_REALTIME, &ts);
|
||||||
|
ts.tv_sec += t / 1000;
|
||||||
|
ts.tv_nsec += (t % 1000) * 1000000;
|
||||||
|
if (ts.tv_nsec >= 1000000000) {
|
||||||
|
ts.tv_sec++;
|
||||||
|
ts.tv_nsec -= 1000000000;
|
||||||
|
}
|
||||||
|
return pthread_cond_timedwait(c, m, &ts) == ETIMEDOUT ? -1 : 0;
|
||||||
|
}
|
||||||
|
#define COND_TIMED_WAIT(c, m, t) posix_cond_timedwait(c, m, t)
|
||||||
|
|
||||||
|
#define COND_WAIT(c, m) pthread_cond_wait(c, m)
|
||||||
|
|
||||||
|
|
||||||
|
#else /* USE_PTHREADS */
|
||||||
|
#include <windows.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
/* Use C11 threads */
|
||||||
|
//#include <threads.h>
|
||||||
|
|
||||||
|
#define THREAD HANDLE // For thread handles
|
||||||
|
#define MUTEX CRITICAL_SECTION // For mutexes
|
||||||
|
#define COND CONDITION_VARIABLE // For condition variables
|
||||||
|
|
||||||
|
#ifdef ENABLE_LOCK_CHECKS
|
||||||
|
# define MUTEX_INIT(m) do { \
|
||||||
|
int status; \
|
||||||
|
status = mtx_init(m, mtx_plain | mtx_recursive); \
|
||||||
|
assert(status == thrd_success && "Mutex init failure"); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
# define MUTEX_LOCK(m) do { \
|
||||||
|
int status = mtx_lock(m); \
|
||||||
|
assert(status == thrd_success && "Mutex lock failure");\
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
# define MUTEX_UNLOCK(m) do { \
|
||||||
|
int status = mtx_unlock(m); \
|
||||||
|
assert(status == thrd_success && "Mutex unlock failure");\
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
# define MUTEX_DESTROY(m) do { \
|
||||||
|
mtx_destroy(m); \
|
||||||
|
} while (0)
|
||||||
|
#else /* ENABLE_LOCK_CHECKS */
|
||||||
|
|
||||||
|
#define MUTEX_INIT(m) InitializeCriticalSection(m)
|
||||||
|
#define MUTEX_LOCK(m) EnterCriticalSection(m)
|
||||||
|
#define MUTEX_UNLOCK(m) LeaveCriticalSection(m)
|
||||||
|
#define MUTEX_DESTROY(m) DeleteCriticalSection(m)
|
||||||
|
|
||||||
|
#endif /* ENABLE_LOCK_CHECKS */
|
||||||
|
|
||||||
|
|
||||||
|
# define THREAD_CREATE(handle, func, arg) \
|
||||||
|
((*(handle) = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)(func), \
|
||||||
|
(LPVOID)(arg), 0, NULL)) == NULL ? GetLastError() : 0)
|
||||||
|
|
||||||
|
|
||||||
|
# define THREAD_SUCCESS 0
|
||||||
|
# define THREAD_TIMEOUT WAIT_TIMEOUT
|
||||||
|
# define THREAD_CANCEL(m) TerminateThread(m, 0)
|
||||||
|
# define THREAD_JOIN(t, s) WaitForSingleObject(t, INFINITE)
|
||||||
|
# define THREAD_EXIT(s) ExitThread(s)
|
||||||
|
|
||||||
|
# define COND_INIT(m) (InitializeConditionVariable(m), 0)
|
||||||
|
# define COND_SIGNAL(m) WakeConditionVariable(m)
|
||||||
|
# define COND_TIMED_WAIT(c, m, t) \
|
||||||
|
(SleepConditionVariableCS(c, m, t) ? 0 : GetLastError())
|
||||||
|
# define COND_WAIT(c, m) (!SleepConditionVariableCS(c, m, INFINITE))
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* USE_PTHREADS */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
#ifndef WIN_CLOCK_GETTIME_H_
|
#ifndef WIN_CLOCK_GETTIME_H_
|
||||||
#define WIN_CLOCK_GETTIME_H_
|
#define WIN_CLOCK_GETTIME_H_
|
||||||
|
|
||||||
#include <pthread.h>
|
#include "thread.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
#ifndef WIN_GETTIMEOFDAY_H_
|
#ifndef WIN_GETTIMEOFDAY_H_
|
||||||
#define WIN_GETTIMEOFDAY_H_
|
#define WIN_GETTIMEOFDAY_H_
|
||||||
|
|
||||||
#include <pthread.h>
|
#include "thread.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
#ifndef WIN_NANOSLEEP_H_
|
#ifndef WIN_NANOSLEEP_H_
|
||||||
#define WIN_NANOSLEEP_H_
|
#define WIN_NANOSLEEP_H_
|
||||||
|
|
||||||
#include <pthread.h>
|
#include "thread.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
|
||||||
|
|
@ -48,9 +48,10 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
#include <time.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "host_config.h"
|
#include "host_config.h"
|
||||||
#include "pthread.h"
|
#include "thread.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
|
||||||
9
host/common/thirdparty/ad936x/CMakeLists.txt
vendored
9
host/common/thirdparty/ad936x/CMakeLists.txt
vendored
|
|
@ -94,16 +94,7 @@ target_include_directories(ad936x PUBLIC
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
add_definitions(-DHAVE_STRUCT_TIMESPEC)
|
add_definitions(-DHAVE_STRUCT_TIMESPEC)
|
||||||
target_include_directories(ad936x PUBLIC ${MSVC_C99_INCLUDES})
|
target_include_directories(ad936x PUBLIC ${MSVC_C99_INCLUDES})
|
||||||
|
|
||||||
find_package(LibPThreadsWin32 REQUIRED)
|
|
||||||
if(LIBPTHREADSWIN32_FOUND)
|
|
||||||
set(HAVE_THREADS true)
|
set(HAVE_THREADS true)
|
||||||
target_include_directories(ad936x PUBLIC ${LIBPTHREADSWIN32_INCLUDE_DIRS})
|
|
||||||
set(LIBAD936X_LIBS
|
|
||||||
${LIBAD936X_LIBS} ${LIBPTHREADSWIN32_LIBRARIES})
|
|
||||||
else()
|
|
||||||
set(HAVE_THREADS false)
|
|
||||||
endif()
|
|
||||||
else(MSVC)
|
else(MSVC)
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
if(Threads_FOUND)
|
if(Threads_FOUND)
|
||||||
|
|
|
||||||
|
|
@ -196,16 +196,7 @@ set(LIBBLADERF_INCLUDES
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
set(LIBBLADERF_INCLUDES ${LIBBLADERF_INCLUDES} ${MSVC_C99_INCLUDES})
|
set(LIBBLADERF_INCLUDES ${LIBBLADERF_INCLUDES} ${MSVC_C99_INCLUDES})
|
||||||
|
|
||||||
find_package(LibPThreadsWin32 REQUIRED)
|
|
||||||
if(LIBPTHREADSWIN32_FOUND)
|
|
||||||
set(HAVE_THREADS true)
|
set(HAVE_THREADS true)
|
||||||
set(LIBBLADERF_INCLUDES
|
|
||||||
${LIBBLADERF_INCLUDES} ${LIBPTHREADSWIN32_INCLUDE_DIRS})
|
|
||||||
set(LIBBLADERF_LIBS
|
|
||||||
${LIBBLADERF_LIBS} ${LIBPTHREADSWIN32_LIBRARIES})
|
|
||||||
else()
|
|
||||||
set(HAVE_THREADS false)
|
|
||||||
endif()
|
|
||||||
else(MSVC)
|
else(MSVC)
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
if(Threads_FOUND)
|
if(Threads_FOUND)
|
||||||
|
|
@ -280,11 +271,6 @@ if(ENABLE_BACKEND_CYAPI)
|
||||||
set(LIBBLADERF_INCLUDES ${LIBBLADERF_INCLUDES} ${CYAPI_INCLUDE_DIRS})
|
set(LIBBLADERF_INCLUDES ${LIBBLADERF_INCLUDES} ${CYAPI_INCLUDE_DIRS})
|
||||||
endif(ENABLE_BACKEND_CYAPI)
|
endif(ENABLE_BACKEND_CYAPI)
|
||||||
|
|
||||||
if(MSVC)
|
|
||||||
set(LIBBLADERF_INCLUDES ${LIBBLADERF_INCLUDES}
|
|
||||||
${LIBPTHREADSWIN32_INCLUDE_DIRS})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(ENABLE_LIBBLADERF_SYNC_LOG_VERBOSE AND ENABLE_LIBBLADERF_LOGGING)
|
if(ENABLE_LIBBLADERF_SYNC_LOG_VERBOSE AND ENABLE_LIBBLADERF_LOGGING)
|
||||||
add_definitions(-DENABLE_LIBBLADERF_SYNC_LOG_VERBOSE)
|
add_definitions(-DENABLE_LIBBLADERF_SYNC_LOG_VERBOSE)
|
||||||
endif()
|
endif()
|
||||||
|
|
@ -437,11 +423,9 @@ add_library(libbladerf_shared SHARED ${LIBBLADERF_SOURCE})
|
||||||
# Build configuration
|
# Build configuration
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
if(MSVC)
|
if(NOT MSVC)
|
||||||
set(LIBBLADERF_LIBS ${LIBBLADERF_LIBS} ${LIBPTHREADSWIN32_LIBRARIES})
|
|
||||||
else()
|
|
||||||
set(LIBBLADERF_LIBS ${LIBBLADERF_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
set(LIBBLADERF_LIBS ${LIBBLADERF_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||||
endif(MSVC)
|
endif(NOT MSVC)
|
||||||
|
|
||||||
if(ENABLE_BACKEND_LIBUSB)
|
if(ENABLE_BACKEND_LIBUSB)
|
||||||
set(LIBBLADERF_LIBS ${LIBBLADERF_LIBS} ${LIBUSB_LIBRARIES})
|
set(LIBBLADERF_LIBS ${LIBBLADERF_LIBS} ${LIBUSB_LIBRARIES})
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <pthread.h>
|
#include "thread.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "bladeRF.h" /* Firmware interface */
|
#include "bladeRF.h" /* Firmware interface */
|
||||||
|
|
||||||
|
|
@ -707,7 +707,7 @@ static int cyapi_stream(void *driver, struct bladerf_stream *stream,
|
||||||
data->transfers[i].buffer = NULL;
|
data->transfers[i].buffer = NULL;
|
||||||
data->transfers[i].handle = NULL;
|
data->transfers[i].handle = NULL;
|
||||||
data->num_avail++;
|
data->num_avail++;
|
||||||
pthread_cond_signal(&stream->can_submit_buffer);
|
COND_SIGNAL(&stream->can_submit_buffer);
|
||||||
|
|
||||||
if (next_buffer == BLADERF_STREAM_SHUTDOWN) {
|
if (next_buffer == BLADERF_STREAM_SHUTDOWN) {
|
||||||
done = true;
|
done = true;
|
||||||
|
|
@ -792,20 +792,20 @@ int cyapi_submit_stream_buffer(void *driver, struct bladerf_stream *stream,
|
||||||
return BLADERF_ERR_UNEXPECTED;
|
return BLADERF_ERR_UNEXPECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (data->num_avail == 0 && status == 0) {
|
while (data->num_avail == 0 && status == THREAD_SUCCESS) {
|
||||||
status = pthread_cond_timedwait(&stream->can_submit_buffer,
|
status = COND_TIMED_WAIT(&stream->can_submit_buffer,
|
||||||
&stream->lock,
|
&stream->lock,
|
||||||
&timeout_abs);
|
&timeout_abs);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while (data->num_avail == 0 && status == 0) {
|
while (data->num_avail == 0 && status == THREAD_SUCCESS) {
|
||||||
status = pthread_cond_wait(&stream->can_submit_buffer,
|
status = COND_WAIT(&stream->can_submit_buffer,
|
||||||
&stream->lock);
|
&stream->lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status == ETIMEDOUT) {
|
if (status == THREAD_TIMEOUT) {
|
||||||
return BLADERF_ERR_TIMEOUT;
|
return BLADERF_ERR_TIMEOUT;
|
||||||
} else if (status != 0) {
|
} else if (status != 0) {
|
||||||
return BLADERF_ERR_UNEXPECTED;
|
return BLADERF_ERR_UNEXPECTED;
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
#include "host_config.h"
|
#include "host_config.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <pthread.h>
|
#include "thread.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <libusb.h>
|
#include <libusb.h>
|
||||||
#if 1 == BLADERF_OS_FREEBSD
|
#if 1 == BLADERF_OS_FREEBSD
|
||||||
|
|
@ -1054,7 +1054,7 @@ static void LIBUSB_CALL lusb_stream_cb(struct libusb_transfer *transfer)
|
||||||
} else {
|
} else {
|
||||||
stream_data->transfer_status[transfer_i] = TRANSFER_AVAIL;
|
stream_data->transfer_status[transfer_i] = TRANSFER_AVAIL;
|
||||||
stream_data->num_avail++;
|
stream_data->num_avail++;
|
||||||
pthread_cond_signal(&stream->can_submit_buffer);
|
COND_SIGNAL(&stream->can_submit_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check to see if the transfer has been cancelled or errored */
|
/* Check to see if the transfer has been cancelled or errored */
|
||||||
|
|
@ -1409,7 +1409,6 @@ int lusb_submit_stream_buffer(void *driver, struct bladerf_stream *stream,
|
||||||
{
|
{
|
||||||
int status = 0;
|
int status = 0;
|
||||||
struct lusb_stream_data *stream_data = stream->backend_data;
|
struct lusb_stream_data *stream_data = stream->backend_data;
|
||||||
struct timespec timeout_abs;
|
|
||||||
|
|
||||||
if (buffer == BLADERF_STREAM_SHUTDOWN) {
|
if (buffer == BLADERF_STREAM_SHUTDOWN) {
|
||||||
if (stream_data->num_avail == stream_data->num_transfers) {
|
if (stream_data->num_avail == stream_data->num_transfers) {
|
||||||
|
|
@ -1430,25 +1429,20 @@ int lusb_submit_stream_buffer(void *driver, struct bladerf_stream *stream,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeout_ms != 0) {
|
if (timeout_ms != 0) {
|
||||||
status = populate_abs_timeout(&timeout_abs, timeout_ms);
|
while (stream_data->num_avail == 0 && status == THREAD_SUCCESS) {
|
||||||
if (status != 0) {
|
status = COND_TIMED_WAIT(&stream->can_submit_buffer,
|
||||||
return BLADERF_ERR_UNEXPECTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (stream_data->num_avail == 0 && status == 0) {
|
|
||||||
status = pthread_cond_timedwait(&stream->can_submit_buffer,
|
|
||||||
&stream->lock,
|
&stream->lock,
|
||||||
&timeout_abs);
|
timeout_ms);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while (stream_data->num_avail == 0 && status == 0) {
|
while (stream_data->num_avail == 0 && status == THREAD_SUCCESS) {
|
||||||
status = pthread_cond_wait(&stream->can_submit_buffer,
|
status = COND_WAIT(&stream->can_submit_buffer,
|
||||||
&stream->lock);
|
&stream->lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status == ETIMEDOUT) {
|
if (status == THREAD_TIMEOUT) {
|
||||||
log_debug("%s: Timed out waiting for a transfer to become available.\n",
|
log_debug("%s: Timed out waiting for a transfer to become available.\n",
|
||||||
__FUNCTION__);
|
__FUNCTION__);
|
||||||
return BLADERF_ERR_TIMEOUT;
|
return BLADERF_ERR_TIMEOUT;
|
||||||
|
|
|
||||||
|
|
@ -66,12 +66,12 @@ int async_init_stream(struct bladerf_stream **stream,
|
||||||
|
|
||||||
MUTEX_INIT(&lstream->lock);
|
MUTEX_INIT(&lstream->lock);
|
||||||
|
|
||||||
if (pthread_cond_init(&lstream->can_submit_buffer, NULL) != 0) {
|
if (COND_INIT(&lstream->can_submit_buffer) != THREAD_SUCCESS) {
|
||||||
free(lstream);
|
free(lstream);
|
||||||
return BLADERF_ERR_UNEXPECTED;
|
return BLADERF_ERR_UNEXPECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pthread_cond_init(&lstream->stream_started, NULL) != 0) {
|
if (COND_INIT(&lstream->stream_started) != THREAD_SUCCESS) {
|
||||||
free(lstream);
|
free(lstream);
|
||||||
return BLADERF_ERR_UNEXPECTED;
|
return BLADERF_ERR_UNEXPECTED;
|
||||||
}
|
}
|
||||||
|
|
@ -203,7 +203,7 @@ int async_run_stream(struct bladerf_stream *stream, bladerf_channel_layout layou
|
||||||
MUTEX_LOCK(&stream->lock);
|
MUTEX_LOCK(&stream->lock);
|
||||||
stream->layout = layout;
|
stream->layout = layout;
|
||||||
stream->state = STREAM_RUNNING;
|
stream->state = STREAM_RUNNING;
|
||||||
pthread_cond_signal(&stream->stream_started);
|
COND_SIGNAL(&stream->stream_started);
|
||||||
MUTEX_UNLOCK(&stream->lock);
|
MUTEX_UNLOCK(&stream->lock);
|
||||||
|
|
||||||
status = dev->backend->stream(stream, layout);
|
status = dev->backend->stream(stream, layout);
|
||||||
|
|
@ -218,32 +218,23 @@ int async_submit_stream_buffer(struct bladerf_stream *stream,
|
||||||
bool nonblock)
|
bool nonblock)
|
||||||
{
|
{
|
||||||
int status = 0;
|
int status = 0;
|
||||||
struct timespec timeout_abs;
|
|
||||||
|
|
||||||
MUTEX_LOCK(&stream->lock);
|
MUTEX_LOCK(&stream->lock);
|
||||||
|
|
||||||
if (buffer != BLADERF_STREAM_SHUTDOWN) {
|
if (buffer != BLADERF_STREAM_SHUTDOWN) {
|
||||||
if (stream->state != STREAM_RUNNING && timeout_ms != 0) {
|
|
||||||
status = populate_abs_timeout(&timeout_abs, timeout_ms);
|
|
||||||
if (status != 0) {
|
|
||||||
log_debug("Failed to populate timeout value\n");
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (stream->state != STREAM_RUNNING) {
|
while (stream->state != STREAM_RUNNING) {
|
||||||
log_debug("Buffer submitted while stream's not running. "
|
log_debug("Buffer submitted while stream's not running. "
|
||||||
"Waiting for stream to start.\n");
|
"Waiting for stream to start.\n");
|
||||||
|
|
||||||
if (timeout_ms == 0) {
|
if (timeout_ms == 0) {
|
||||||
status = pthread_cond_wait(&stream->stream_started,
|
status = COND_WAIT(&stream->stream_started,
|
||||||
&stream->lock);
|
&stream->lock);
|
||||||
} else {
|
} else {
|
||||||
status = pthread_cond_timedwait(&stream->stream_started,
|
status = COND_TIMED_WAIT(&stream->stream_started,
|
||||||
&stream->lock, &timeout_abs);
|
&stream->lock, timeout_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status == ETIMEDOUT) {
|
if (status == THREAD_TIMEOUT) {
|
||||||
status = BLADERF_ERR_TIMEOUT;
|
status = BLADERF_ERR_TIMEOUT;
|
||||||
log_debug("%s: %u ms timeout expired",
|
log_debug("%s: %u ms timeout expired",
|
||||||
__FUNCTION__, timeout_ms);
|
__FUNCTION__, timeout_ms);
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,6 @@
|
||||||
#ifndef STREAMING_ASYNC_H_
|
#ifndef STREAMING_ASYNC_H_
|
||||||
#define STREAMING_ASYNC_H_
|
#define STREAMING_ASYNC_H_
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
#include <libbladeRF.h>
|
#include <libbladeRF.h>
|
||||||
|
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
|
@ -58,8 +56,8 @@ struct bladerf_stream {
|
||||||
/* The following items must be accessed atomically */
|
/* The following items must be accessed atomically */
|
||||||
int error_code;
|
int error_code;
|
||||||
bladerf_stream_state state;
|
bladerf_stream_state state;
|
||||||
pthread_cond_t can_submit_buffer;
|
COND can_submit_buffer;
|
||||||
pthread_cond_t stream_started;
|
COND stream_started;
|
||||||
void *backend_data;
|
void *backend_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -237,7 +237,7 @@ int sync_init(struct bladerf_sync *sync,
|
||||||
__FUNCTION__, sync->meta.samples_per_msg);
|
__FUNCTION__, sync->meta.samples_per_msg);
|
||||||
|
|
||||||
MUTEX_INIT(&sync->buf_mgmt.lock);
|
MUTEX_INIT(&sync->buf_mgmt.lock);
|
||||||
pthread_cond_init(&sync->buf_mgmt.buf_ready, NULL);
|
COND_INIT(&sync->buf_mgmt.buf_ready);
|
||||||
|
|
||||||
sync->buf_mgmt.status = (sync_buffer_status*) malloc(num_buffers * sizeof(sync_buffer_status));
|
sync->buf_mgmt.status = (sync_buffer_status*) malloc(num_buffers * sizeof(sync_buffer_status));
|
||||||
if (sync->buf_mgmt.status == NULL) {
|
if (sync->buf_mgmt.status == NULL) {
|
||||||
|
|
@ -332,22 +332,18 @@ static int wait_for_buffer(struct buffer_mgmt *b,
|
||||||
unsigned int dbg_idx)
|
unsigned int dbg_idx)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
struct timespec timeout;
|
|
||||||
|
|
||||||
if (timeout_ms == 0) {
|
if (timeout_ms == 0) {
|
||||||
log_verbose("%s: Infinite wait for buffer[%d] (status: %d).\n",
|
log_verbose("%s: Infinite wait for buffer[%d] (status: %d).\n",
|
||||||
dbg_name, dbg_idx, b->status[dbg_idx]);
|
dbg_name, dbg_idx, b->status[dbg_idx]);
|
||||||
status = pthread_cond_wait(&b->buf_ready, &b->lock);
|
status = COND_WAIT(&b->buf_ready, &b->lock);
|
||||||
} else {
|
} else {
|
||||||
log_verbose("%s: Timed wait for buffer[%d] (status: %d).\n", dbg_name,
|
log_verbose("%s: Timed wait for buffer[%d] (status: %d).\n", dbg_name,
|
||||||
dbg_idx, b->status[dbg_idx]);
|
dbg_idx, b->status[dbg_idx]);
|
||||||
status = populate_abs_timeout(&timeout, timeout_ms);
|
status = COND_TIMED_WAIT(&b->buf_ready, &b->lock, timeout_ms);
|
||||||
if (status == 0) {
|
|
||||||
status = pthread_cond_timedwait(&b->buf_ready, &b->lock, &timeout);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status == ETIMEDOUT) {
|
if (status == THREAD_TIMEOUT) {
|
||||||
log_error("%s: Timed out waiting for buf_ready after %d ms\n",
|
log_error("%s: Timed out waiting for buf_ready after %d ms\n",
|
||||||
__FUNCTION__, timeout_ms);
|
__FUNCTION__, timeout_ms);
|
||||||
status = BLADERF_ERR_TIMEOUT;
|
status = BLADERF_ERR_TIMEOUT;
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@
|
||||||
#define STREAMING_SYNC_H_
|
#define STREAMING_SYNC_H_
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
#include <libbladeRF.h>
|
#include <libbladeRF.h>
|
||||||
|
|
||||||
|
|
@ -88,7 +87,7 @@ struct buffer_mgmt {
|
||||||
|
|
||||||
|
|
||||||
MUTEX lock;
|
MUTEX lock;
|
||||||
pthread_cond_t buf_ready; /**< Buffer produced by RX callback, or
|
COND buf_ready; /**< Buffer produced by RX callback, or
|
||||||
* buffer emptied by TX callback */
|
* buffer emptied by TX callback */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ static void *rx_callback(struct bladerf *dev,
|
||||||
/* This buffer is now ready for the consumer */
|
/* This buffer is now ready for the consumer */
|
||||||
b->status[samples_idx] = SYNC_BUFFER_FULL;
|
b->status[samples_idx] = SYNC_BUFFER_FULL;
|
||||||
b->actual_lengths[samples_idx] = num_samples;
|
b->actual_lengths[samples_idx] = num_samples;
|
||||||
pthread_cond_signal(&b->buf_ready);
|
COND_SIGNAL(&b->buf_ready);
|
||||||
|
|
||||||
/* Update the state of the buffer being submitted next */
|
/* Update the state of the buffer being submitted next */
|
||||||
next_idx = b->prod_i;
|
next_idx = b->prod_i;
|
||||||
|
|
@ -155,7 +155,7 @@ static void *tx_callback(struct bladerf *dev,
|
||||||
completed_idx = sync_buf2idx(b, samples);
|
completed_idx = sync_buf2idx(b, samples);
|
||||||
assert(b->status[completed_idx] == SYNC_BUFFER_IN_FLIGHT);
|
assert(b->status[completed_idx] == SYNC_BUFFER_IN_FLIGHT);
|
||||||
b->status[completed_idx] = SYNC_BUFFER_EMPTY;
|
b->status[completed_idx] = SYNC_BUFFER_EMPTY;
|
||||||
pthread_cond_signal(&b->buf_ready);
|
COND_SIGNAL(&b->buf_ready);
|
||||||
|
|
||||||
/* If the callback is assigned to be the submitter, there are
|
/* If the callback is assigned to be the submitter, there are
|
||||||
* buffers pending submission */
|
* buffers pending submission */
|
||||||
|
|
@ -230,25 +230,25 @@ int sync_worker_init(struct bladerf_sync *s)
|
||||||
MUTEX_INIT(&s->worker->state_lock);
|
MUTEX_INIT(&s->worker->state_lock);
|
||||||
MUTEX_INIT(&s->worker->request_lock);
|
MUTEX_INIT(&s->worker->request_lock);
|
||||||
|
|
||||||
status = pthread_cond_init(&s->worker->state_changed, NULL);
|
status = COND_INIT(&s->worker->state_changed);
|
||||||
if (status != 0) {
|
if (status != THREAD_SUCCESS) {
|
||||||
log_debug("%s worker: pthread_cond_init(state_changed) failed: %d\n",
|
log_debug("%s worker: cond_init(state_changed) failed: %d\n",
|
||||||
worker2str(s), status);
|
worker2str(s), status);
|
||||||
status = BLADERF_ERR_UNEXPECTED;
|
status = BLADERF_ERR_UNEXPECTED;
|
||||||
goto worker_init_out;
|
goto worker_init_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = pthread_cond_init(&s->worker->requests_pending, NULL);
|
status = COND_INIT(&s->worker->requests_pending);
|
||||||
if (status != 0) {
|
if (status != THREAD_SUCCESS) {
|
||||||
log_debug("%s worker: pthread_cond_init(requests_pending) failed: %d\n",
|
log_debug("%s worker: cond_init(requests_pending) failed: %d\n",
|
||||||
worker2str(s), status);
|
worker2str(s), status);
|
||||||
status = BLADERF_ERR_UNEXPECTED;
|
status = BLADERF_ERR_UNEXPECTED;
|
||||||
goto worker_init_out;
|
goto worker_init_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = pthread_create(&s->worker->thread, NULL, sync_worker_task, s);
|
status = THREAD_CREATE(&s->worker->thread, sync_worker_task, s);
|
||||||
if (status != 0) {
|
if (status != THREAD_SUCCESS) {
|
||||||
log_debug("%s worker: pthread_create failed: %d\n", worker2str(s),
|
log_debug("%s worker: create failed: %d\n", worker2str(s),
|
||||||
status);
|
status);
|
||||||
status = BLADERF_ERR_UNEXPECTED;
|
status = BLADERF_ERR_UNEXPECTED;
|
||||||
goto worker_init_out;
|
goto worker_init_out;
|
||||||
|
|
@ -274,7 +274,7 @@ worker_init_out:
|
||||||
}
|
}
|
||||||
|
|
||||||
void sync_worker_deinit(struct sync_worker *w,
|
void sync_worker_deinit(struct sync_worker *w,
|
||||||
pthread_mutex_t *lock, pthread_cond_t *cond)
|
MUTEX *lock, COND *cond)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
|
|
@ -289,7 +289,7 @@ void sync_worker_deinit(struct sync_worker *w,
|
||||||
|
|
||||||
if (lock != NULL && cond != NULL) {
|
if (lock != NULL && cond != NULL) {
|
||||||
MUTEX_LOCK(lock);
|
MUTEX_LOCK(lock);
|
||||||
pthread_cond_signal(cond);
|
COND_SIGNAL(cond);
|
||||||
MUTEX_UNLOCK(lock);
|
MUTEX_UNLOCK(lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -297,10 +297,10 @@ void sync_worker_deinit(struct sync_worker *w,
|
||||||
|
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
log_warning("Timed out while stopping worker. Canceling thread.\n");
|
log_warning("Timed out while stopping worker. Canceling thread.\n");
|
||||||
pthread_cancel(w->thread);
|
THREAD_CANCEL(w->thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_join(w->thread, NULL);
|
THREAD_JOIN(w->thread, NULL);
|
||||||
log_verbose("%s: Worker joined.\n", __FUNCTION__);
|
log_verbose("%s: Worker joined.\n", __FUNCTION__);
|
||||||
|
|
||||||
async_deinit_stream(w->stream);
|
async_deinit_stream(w->stream);
|
||||||
|
|
@ -312,7 +312,7 @@ void sync_worker_submit_request(struct sync_worker *w, unsigned int request)
|
||||||
{
|
{
|
||||||
MUTEX_LOCK(&w->request_lock);
|
MUTEX_LOCK(&w->request_lock);
|
||||||
w->requests |= request;
|
w->requests |= request;
|
||||||
pthread_cond_signal(&w->requests_pending);
|
COND_SIGNAL(&w->requests_pending);
|
||||||
MUTEX_UNLOCK(&w->request_lock);
|
MUTEX_UNLOCK(&w->request_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -320,31 +320,14 @@ int sync_worker_wait_for_state(struct sync_worker *w, sync_worker_state state,
|
||||||
unsigned int timeout_ms)
|
unsigned int timeout_ms)
|
||||||
{
|
{
|
||||||
int status = 0;
|
int status = 0;
|
||||||
struct timespec timeout_abs;
|
|
||||||
const int nsec_per_sec = 1000 * 1000 * 1000;
|
|
||||||
|
|
||||||
if (timeout_ms != 0) {
|
if (timeout_ms != 0) {
|
||||||
const unsigned int timeout_sec = timeout_ms / 1000;
|
|
||||||
|
|
||||||
status = clock_gettime(CLOCK_REALTIME, &timeout_abs);
|
|
||||||
if (status != 0) {
|
|
||||||
return BLADERF_ERR_UNEXPECTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
timeout_abs.tv_sec += timeout_sec;
|
|
||||||
timeout_abs.tv_nsec += (timeout_ms % 1000) * 1000 * 1000;
|
|
||||||
|
|
||||||
if (timeout_abs.tv_nsec >= nsec_per_sec) {
|
|
||||||
timeout_abs.tv_sec += timeout_abs.tv_nsec / nsec_per_sec;
|
|
||||||
timeout_abs.tv_nsec %= nsec_per_sec;
|
|
||||||
}
|
|
||||||
|
|
||||||
MUTEX_LOCK(&w->state_lock);
|
MUTEX_LOCK(&w->state_lock);
|
||||||
status = 0;
|
status = 0;
|
||||||
while (w->state != state && status == 0) {
|
while (w->state != state && status == THREAD_SUCCESS) {
|
||||||
status = pthread_cond_timedwait(&w->state_changed,
|
status = COND_TIMED_WAIT(&w->state_changed,
|
||||||
&w->state_lock,
|
&w->state_lock,
|
||||||
&timeout_abs);
|
timeout_ms);
|
||||||
}
|
}
|
||||||
MUTEX_UNLOCK(&w->state_lock);
|
MUTEX_UNLOCK(&w->state_lock);
|
||||||
|
|
||||||
|
|
@ -352,7 +335,7 @@ int sync_worker_wait_for_state(struct sync_worker *w, sync_worker_state state,
|
||||||
MUTEX_LOCK(&w->state_lock);
|
MUTEX_LOCK(&w->state_lock);
|
||||||
while (w->state != state) {
|
while (w->state != state) {
|
||||||
log_verbose(": Waiting for state change, current = %d\n", w->state);
|
log_verbose(": Waiting for state change, current = %d\n", w->state);
|
||||||
status = pthread_cond_wait(&w->state_changed,
|
status = COND_WAIT(&w->state_changed,
|
||||||
&w->state_lock);
|
&w->state_lock);
|
||||||
}
|
}
|
||||||
MUTEX_UNLOCK(&w->state_lock);
|
MUTEX_UNLOCK(&w->state_lock);
|
||||||
|
|
@ -362,7 +345,7 @@ int sync_worker_wait_for_state(struct sync_worker *w, sync_worker_state state,
|
||||||
log_debug("%s: Wait on state change failed: %s\n",
|
log_debug("%s: Wait on state change failed: %s\n",
|
||||||
__FUNCTION__, strerror(status));
|
__FUNCTION__, strerror(status));
|
||||||
|
|
||||||
if (status == ETIMEDOUT) {
|
if (status == THREAD_TIMEOUT) {
|
||||||
status = BLADERF_ERR_TIMEOUT;
|
status = BLADERF_ERR_TIMEOUT;
|
||||||
} else {
|
} else {
|
||||||
status = BLADERF_ERR_UNEXPECTED;
|
status = BLADERF_ERR_UNEXPECTED;
|
||||||
|
|
@ -392,7 +375,7 @@ static void set_state(struct sync_worker *w, sync_worker_state state)
|
||||||
{
|
{
|
||||||
MUTEX_LOCK(&w->state_lock);
|
MUTEX_LOCK(&w->state_lock);
|
||||||
w->state = state;
|
w->state = state;
|
||||||
pthread_cond_signal(&w->state_changed);
|
COND_SIGNAL(&w->state_changed);
|
||||||
MUTEX_UNLOCK(&w->state_lock);
|
MUTEX_UNLOCK(&w->state_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -408,7 +391,7 @@ static sync_worker_state exec_idle_state(struct bladerf_sync *s)
|
||||||
while (s->worker->requests == 0) {
|
while (s->worker->requests == 0) {
|
||||||
log_verbose("%s worker: Waiting for pending requests\n", worker2str(s));
|
log_verbose("%s worker: Waiting for pending requests\n", worker2str(s));
|
||||||
|
|
||||||
pthread_cond_wait(&s->worker->requests_pending,
|
COND_WAIT(&s->worker->requests_pending,
|
||||||
&s->worker->request_lock);
|
&s->worker->request_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -434,7 +417,7 @@ static sync_worker_state exec_idle_state(struct bladerf_sync *s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_cond_signal(&s->buf_mgmt.buf_ready);
|
COND_SIGNAL(&s->buf_mgmt.buf_ready);
|
||||||
} else {
|
} else {
|
||||||
s->buf_mgmt.prod_i = s->stream_config.num_xfers;
|
s->buf_mgmt.prod_i = s->stream_config.num_xfers;
|
||||||
|
|
||||||
|
|
@ -477,7 +460,7 @@ static void exec_running_state(struct bladerf_sync *s)
|
||||||
* the stream error code back to the API caller */
|
* the stream error code back to the API caller */
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
MUTEX_LOCK(&s->buf_mgmt.lock);
|
MUTEX_LOCK(&s->buf_mgmt.lock);
|
||||||
pthread_cond_signal(&s->buf_mgmt.buf_ready);
|
COND_SIGNAL(&s->buf_mgmt.buf_ready);
|
||||||
MUTEX_UNLOCK(&s->buf_mgmt.lock);
|
MUTEX_UNLOCK(&s->buf_mgmt.lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
#include "host_config.h"
|
#include "host_config.h"
|
||||||
#include "sync.h"
|
#include "sync.h"
|
||||||
#include <libbladeRF.h>
|
#include <libbladeRF.h>
|
||||||
#include <pthread.h>
|
#include "thread.h"
|
||||||
|
|
||||||
#if BLADERF_OS_WINDOWS || BLADERF_OS_OSX
|
#if BLADERF_OS_WINDOWS || BLADERF_OS_OSX
|
||||||
#include "clock_gettime.h"
|
#include "clock_gettime.h"
|
||||||
|
|
@ -49,7 +49,7 @@ typedef enum {
|
||||||
} sync_worker_state;
|
} sync_worker_state;
|
||||||
|
|
||||||
struct sync_worker {
|
struct sync_worker {
|
||||||
pthread_t thread;
|
THREAD thread;
|
||||||
|
|
||||||
struct bladerf_stream *stream;
|
struct bladerf_stream *stream;
|
||||||
bladerf_stream_cb cb;
|
bladerf_stream_cb cb;
|
||||||
|
|
@ -58,7 +58,7 @@ struct sync_worker {
|
||||||
sync_worker_state state;
|
sync_worker_state state;
|
||||||
int err_code;
|
int err_code;
|
||||||
MUTEX state_lock;
|
MUTEX state_lock;
|
||||||
pthread_cond_t state_changed; /* Worker thread uses this to inform a
|
COND state_changed; /* Worker thread uses this to inform a
|
||||||
* waiting main thread about a state
|
* waiting main thread about a state
|
||||||
* change */
|
* change */
|
||||||
|
|
||||||
|
|
@ -66,7 +66,7 @@ struct sync_worker {
|
||||||
* the sync->buf_mgmt.lock
|
* the sync->buf_mgmt.lock
|
||||||
*/
|
*/
|
||||||
unsigned int requests;
|
unsigned int requests;
|
||||||
pthread_cond_t requests_pending;
|
COND requests_pending;
|
||||||
MUTEX request_lock;
|
MUTEX request_lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -90,8 +90,8 @@ int sync_worker_init(struct bladerf_sync *s);
|
||||||
* workers.
|
* workers.
|
||||||
*/
|
*/
|
||||||
void sync_worker_deinit(struct sync_worker *w,
|
void sync_worker_deinit(struct sync_worker *w,
|
||||||
pthread_mutex_t *lock,
|
MUTEX *lock,
|
||||||
pthread_cond_t *cond);
|
COND *cond);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wait for state change with optional timeout
|
* Wait for state change with optional timeout
|
||||||
|
|
|
||||||
|
|
@ -34,21 +34,15 @@ set(SRC
|
||||||
set(TEST_CONFIG_FILE_LIBS libbladerf_shared)
|
set(TEST_CONFIG_FILE_LIBS libbladerf_shared)
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
find_package(LibPThreadsWin32 REQUIRED)
|
|
||||||
set(TEST_CONFIG_FILE_INCLUDES
|
set(TEST_CONFIG_FILE_INCLUDES
|
||||||
${TEST_CONFIG_FILE_INCLUDES}
|
${TEST_CONFIG_FILE_INCLUDES}
|
||||||
${MSVC_C99_INCLUDES}
|
${MSVC_C99_INCLUDES}
|
||||||
${LIBPTHREADSWIN32_INCLUDE_DIRS}
|
|
||||||
)
|
)
|
||||||
set(SRC
|
set(SRC
|
||||||
${SRC}
|
${SRC}
|
||||||
${BLADERF_HOST_COMMON_SOURCE_DIR}/windows/clock_gettime.c
|
${BLADERF_HOST_COMMON_SOURCE_DIR}/windows/clock_gettime.c
|
||||||
${BLADERF_HOST_COMMON_SOURCE_DIR}/windows/mkdtemp.c
|
${BLADERF_HOST_COMMON_SOURCE_DIR}/windows/mkdtemp.c
|
||||||
)
|
)
|
||||||
set(TEST_CONFIG_FILE_LIBS
|
|
||||||
${TEST_CONFIG_FILE_LIBS}
|
|
||||||
${LIBPTHREADSWIN32_LIBRARIES}
|
|
||||||
)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_definitions(-DLIBBLADERF_SEARCH_PREFIX="${CMAKE_INSTALL_PREFIX}")
|
add_definitions(-DLIBBLADERF_SEARCH_PREFIX="${CMAKE_INSTALL_PREFIX}")
|
||||||
|
|
|
||||||
|
|
@ -13,14 +13,10 @@ endif()
|
||||||
|
|
||||||
set(LIBS libbladerf_shared)
|
set(LIBS libbladerf_shared)
|
||||||
|
|
||||||
if(MSVC)
|
if(NOT MSVC)
|
||||||
find_package(LibPThreadsWin32 REQUIRED)
|
|
||||||
set(INCLUDES ${INCLUDES} ${LIBPTHREADSWIN32_INCLUDE_DIRS})
|
|
||||||
set(LIBS ${LIBS} ${LIBPTHREADSWIN32_LIBRARIES})
|
|
||||||
else(MSVC)
|
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||||
endif(MSVC)
|
endif(NOT MSVC)
|
||||||
|
|
||||||
set(SRC
|
set(SRC
|
||||||
src/main.c
|
src/main.c
|
||||||
|
|
|
||||||
|
|
@ -27,15 +27,15 @@
|
||||||
* while concurrently runing full duplex streams via the sync interface */
|
* while concurrently runing full duplex streams via the sync interface */
|
||||||
|
|
||||||
#include "test_ctrl.h"
|
#include "test_ctrl.h"
|
||||||
#include <pthread.h>
|
#include "thread.h"
|
||||||
|
|
||||||
DECLARE_TEST_CASE(threads);
|
DECLARE_TEST_CASE(threads);
|
||||||
|
|
||||||
struct sync_task {
|
struct sync_task {
|
||||||
struct bladerf *dev;
|
struct bladerf *dev;
|
||||||
bladerf_direction direction;
|
bladerf_direction direction;
|
||||||
pthread_t thread;
|
THREAD thread;
|
||||||
pthread_mutex_t lock;
|
MUTEX lock;
|
||||||
bool launched;
|
bool launched;
|
||||||
bool run;
|
bool run;
|
||||||
int status;
|
int status;
|
||||||
|
|
@ -53,7 +53,7 @@ struct thread_state {
|
||||||
struct app_params *p;
|
struct app_params *p;
|
||||||
failure_count failures;
|
failure_count failures;
|
||||||
struct thread_test_case const *tc;
|
struct thread_test_case const *tc;
|
||||||
pthread_t thread;
|
THREAD thread;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct thread_test_case tc[] = {
|
static const struct thread_test_case tc[] = {
|
||||||
|
|
@ -69,9 +69,9 @@ static const struct thread_test_case tc[] = {
|
||||||
|
|
||||||
static inline void get_sync_task_state(struct sync_task *t, bool *run)
|
static inline void get_sync_task_state(struct sync_task *t, bool *run)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&t->lock);
|
MUTEX_LOCK(&t->lock);
|
||||||
*run = t->run;
|
*run = t->run;
|
||||||
pthread_mutex_unlock(&t->lock);
|
MUTEX_UNLOCK(&t->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *stream_task(void *arg)
|
static void *stream_task(void *arg)
|
||||||
|
|
@ -129,9 +129,9 @@ out:
|
||||||
}
|
}
|
||||||
|
|
||||||
free(samples);
|
free(samples);
|
||||||
pthread_mutex_lock(&t->lock);
|
MUTEX_LOCK(&t->lock);
|
||||||
t->status = status;
|
t->status = status;
|
||||||
pthread_mutex_unlock(&t->lock);
|
MUTEX_UNLOCK(&t->lock);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -144,15 +144,15 @@ static void init_task(struct sync_task *t,
|
||||||
t->run = true;
|
t->run = true;
|
||||||
t->status = 0;
|
t->status = 0;
|
||||||
t->direction = dir;
|
t->direction = dir;
|
||||||
pthread_mutex_init(&t->lock, NULL);
|
MUTEX_INIT(&t->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int launch_task(struct sync_task *t)
|
static int launch_task(struct sync_task *t)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
status = pthread_create(&t->thread, NULL, stream_task, t);
|
status = THREAD_CREATE(&t->thread, stream_task, t);
|
||||||
if (0 == status) {
|
if (THREAD_SUCCESS == status) {
|
||||||
t->launched = true;
|
t->launched = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -162,10 +162,10 @@ static int launch_task(struct sync_task *t)
|
||||||
static inline int deinit_task(struct sync_task *t)
|
static inline int deinit_task(struct sync_task *t)
|
||||||
{
|
{
|
||||||
if (t->launched) {
|
if (t->launched) {
|
||||||
pthread_mutex_lock(&t->lock);
|
MUTEX_LOCK(&t->lock);
|
||||||
t->run = false;
|
t->run = false;
|
||||||
pthread_mutex_unlock(&t->lock);
|
MUTEX_UNLOCK(&t->lock);
|
||||||
pthread_join(t->thread, NULL);
|
THREAD_JOIN(t->thread, NULL);
|
||||||
return t->status;
|
return t->status;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -257,9 +257,9 @@ failure_count test_threads(struct bladerf *dev, struct app_params *p, bool quiet
|
||||||
}
|
}
|
||||||
|
|
||||||
status =
|
status =
|
||||||
pthread_create(&threads[i].thread, NULL, run_test_fn, &threads[i]);
|
THREAD_CREATE(&threads[i].thread, run_test_fn, &threads[i]);
|
||||||
|
|
||||||
if (0 == status) {
|
if (THREAD_SUCCESS == status) {
|
||||||
PRINT(" Started test_%s thread...\n", threads[i].tc->test->name);
|
PRINT(" Started test_%s thread...\n", threads[i].tc->test->name);
|
||||||
threads[i].launched = true;
|
threads[i].launched = true;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -271,7 +271,7 @@ failure_count test_threads(struct bladerf *dev, struct app_params *p, bool quiet
|
||||||
|
|
||||||
for (i = 0; i < num_threads; i++) {
|
for (i = 0; i < num_threads; i++) {
|
||||||
if (threads[i].launched) {
|
if (threads[i].launched) {
|
||||||
pthread_join(threads[i].thread, NULL);
|
THREAD_JOIN(threads[i].thread, NULL);
|
||||||
PRINT("\n Joined test_%s thread.\n", threads[i].tc->test->name);
|
PRINT("\n Joined test_%s thread.\n", threads[i].tc->test->name);
|
||||||
failures += threads[i].failures;
|
failures += threads[i].failures;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,14 +14,10 @@ endif()
|
||||||
|
|
||||||
set(LIBS libbladerf_shared)
|
set(LIBS libbladerf_shared)
|
||||||
|
|
||||||
if(MSVC)
|
if(NOT MSVC)
|
||||||
find_package(LibPThreadsWin32 REQUIRED)
|
|
||||||
set(INCLUDES ${INCLUDES} ${LIBPTHREADSWIN32_INCLUDE_DIRS})
|
|
||||||
set(LIBS ${LIBS} ${LIBPTHREADSWIN32_LIBRARIES})
|
|
||||||
else(MSVC)
|
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||||
endif(MSVC)
|
endif(NOT MSVC)
|
||||||
|
|
||||||
add_definitions(-DLOGGING_ENABLED=1)
|
add_definitions(-DLOGGING_ENABLED=1)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,13 +29,12 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
#include "conversions.h"
|
#include "conversions.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "test_common.h"
|
#include "test_common.h"
|
||||||
#include <libbladeRF.h>
|
#include <libbladeRF.h>
|
||||||
#include "async.h"
|
#include "async.h"
|
||||||
|
#include "thread.h"
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* Type definitions
|
* Type definitions
|
||||||
|
|
@ -453,7 +452,7 @@ int main(int argc, char *argv[])
|
||||||
struct rx_buffer_state rx_state;
|
struct rx_buffer_state rx_state;
|
||||||
struct tx_buffer_state tx_state;
|
struct tx_buffer_state tx_state;
|
||||||
struct bladerf_stream *rx_stream, *tx_stream;
|
struct bladerf_stream *rx_stream, *tx_stream;
|
||||||
pthread_t rx_thread, tx_thread;
|
THREAD rx_thread, tx_thread;
|
||||||
bladerf_log_level level;
|
bladerf_log_level level;
|
||||||
int status;
|
int status;
|
||||||
bool ok;
|
bool ok;
|
||||||
|
|
@ -716,9 +715,9 @@ int main(int argc, char *argv[])
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = pthread_create(&tx_thread, NULL, tx_streamer, tx_stream);
|
status = THREAD_CREATE(&tx_thread, tx_streamer, tx_stream);
|
||||||
if (status < 0) {
|
if (status != THREAD_SUCCESS) {
|
||||||
log_error("pthread_create(TX): %s\n", strerror(status));
|
log_error("THREAD_CREATE(TX): %s\n", strerror(status));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -728,16 +727,16 @@ int main(int argc, char *argv[])
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = pthread_create(&rx_thread, NULL, rx_streamer, rx_stream);
|
status = THREAD_CREATE(&rx_thread, rx_streamer, rx_stream);
|
||||||
if (status < 0) {
|
if (status != THREAD_SUCCESS) {
|
||||||
log_error("pthread_create(RX): %s\n", strerror(status));
|
log_error("THREAD_CREATE(RX): %s\n", strerror(status));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_info("Loopback test running. Press Ctrl-C to exit...\n");
|
log_info("Loopback test running. Press Ctrl-C to exit...\n");
|
||||||
|
|
||||||
pthread_join(tx_thread, NULL);
|
THREAD_JOIN(tx_thread, NULL);
|
||||||
pthread_join(rx_thread, NULL);
|
THREAD_JOIN(rx_thread, NULL);
|
||||||
|
|
||||||
log_info("IQ Matches: %zu / %zu (%.1f%%)\n", good_count,
|
log_info("IQ Matches: %zu / %zu (%.1f%%)\n", good_count,
|
||||||
good_count + bad_count,
|
good_count + bad_count,
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,6 @@ set(LIBS libbladerf_shared)
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
set(INCLUDES ${INCLUDES} ${MSVC_C99_INCLUDES})
|
set(INCLUDES ${INCLUDES} ${MSVC_C99_INCLUDES})
|
||||||
find_package(LibPThreadsWin32 REQUIRED)
|
|
||||||
set(INCLUDES ${INCLUDES} ${LIBPTHREADSWIN32_INCLUDE_DIRS})
|
|
||||||
set(LIBS ${LIBS} ${LIBPTHREADSWIN32_LIBRARIES})
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(SRC
|
set(SRC
|
||||||
|
|
|
||||||
|
|
@ -19,14 +19,10 @@ else()
|
||||||
add_definitions(-DLIBBLADERF_SEARCH_PREFIX="${CMAKE_INSTALL_PREFIX}")
|
add_definitions(-DLIBBLADERF_SEARCH_PREFIX="${CMAKE_INSTALL_PREFIX}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(MSVC)
|
if(NOT MSVC)
|
||||||
find_package(LibPThreadsWin32 REQUIRED)
|
|
||||||
set(INCLUDES ${INCLUDES} ${LIBPTHREADSWIN32_INCLUDE_DIRS})
|
|
||||||
set(LIBS ${LIBS} ${LIBPTHREADSWIN32_LIBRARIES})
|
|
||||||
else(MSVC)
|
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||||
endif(MSVC)
|
endif(NOT MSVC)
|
||||||
|
|
||||||
set(SRC
|
set(SRC
|
||||||
src/main.c
|
src/main.c
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,7 @@ set(SRC
|
||||||
set(LIBS libbladerf_shared)
|
set(LIBS libbladerf_shared)
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
find_package(LibPThreadsWin32 REQUIRED)
|
set(INCLUDES ${INCLUDES} ${MSVC_C99_INCLUDES})
|
||||||
set(INCLUDES ${INCLUDES} ${LIBPTHREADSWIN32_INCLUDE_DIRS} ${MSVC_C99_INCLUDES})
|
|
||||||
set(LIBS ${LIBS} ${LIBPTHREADSWIN32_LIBRARIES})
|
|
||||||
set(SRC ${SRC} ${BLADERF_HOST_COMMON_SOURCE_DIR}/windows/getopt_long.c)
|
set(SRC ${SRC} ${BLADERF_HOST_COMMON_SOURCE_DIR}/windows/getopt_long.c)
|
||||||
else(MSVC)
|
else(MSVC)
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
|
|
|
||||||
|
|
@ -32,12 +32,12 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <pthread.h>
|
|
||||||
#include <libbladeRF.h>
|
#include <libbladeRF.h>
|
||||||
|
|
||||||
#include "devcfg.h"
|
#include "devcfg.h"
|
||||||
#include "conversions.h"
|
#include "conversions.h"
|
||||||
#include "minmax.h"
|
#include "minmax.h"
|
||||||
|
#include "thread.h"
|
||||||
|
|
||||||
|
|
||||||
#define OPTIONS DEVCFG_OPTIONS_BASE "r:S:"
|
#define OPTIONS DEVCFG_OPTIONS_BASE "r:S:"
|
||||||
|
|
@ -221,7 +221,7 @@ int main(int argc, char *argv[])
|
||||||
int status = EXIT_FAILURE;
|
int status = EXIT_FAILURE;
|
||||||
struct option *options = NULL;
|
struct option *options = NULL;
|
||||||
struct app_params params;
|
struct app_params params;
|
||||||
pthread_t rx_thread, tx_thread;
|
THREAD rx_thread, tx_thread;
|
||||||
bool rx_launched = false;
|
bool rx_launched = false;
|
||||||
bool tx_launched = false;
|
bool tx_launched = false;
|
||||||
|
|
||||||
|
|
@ -266,8 +266,8 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params.rx) {
|
if (params.rx) {
|
||||||
status = pthread_create(&rx_thread, NULL, rx_task, ¶ms);
|
status = THREAD_CREATE(&rx_thread, rx_task, ¶ms);
|
||||||
if (status != 0) {
|
if (status != THREAD_SUCCESS) {
|
||||||
fprintf(stderr, "Failed to launch RX thread: %s\n", strerror(status));
|
fprintf(stderr, "Failed to launch RX thread: %s\n", strerror(status));
|
||||||
params.rx = false;
|
params.rx = false;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -276,8 +276,8 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params.tx) {
|
if (params.tx) {
|
||||||
status = pthread_create(&tx_thread, NULL, tx_task, ¶ms);
|
status = THREAD_CREATE(&tx_thread, tx_task, ¶ms);
|
||||||
if (status != 0) {
|
if (status != THREAD_SUCCESS) {
|
||||||
fprintf(stderr, "Failed to launch TX thread: %s\n", strerror(status));
|
fprintf(stderr, "Failed to launch TX thread: %s\n", strerror(status));
|
||||||
params.tx = false;
|
params.tx = false;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -286,11 +286,11 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rx_launched) {
|
if (rx_launched) {
|
||||||
pthread_join(rx_thread, NULL);
|
THREAD_JOIN(rx_thread, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tx_launched) {
|
if (tx_launched) {
|
||||||
pthread_join(tx_thread, NULL);
|
THREAD_JOIN(tx_thread, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
cmake_minimum_required(VERSION 3.5)
|
cmake_minimum_required(VERSION 3.5)
|
||||||
project(libbladeRF_test_repeater C)
|
project(libbladeRF_test_repeater C)
|
||||||
|
|
||||||
if(MSVC)
|
if(NOT MSVC)
|
||||||
find_package(LibPThreadsWin32 REQUIRED)
|
|
||||||
else(MSVC)
|
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
endif(MSVC)
|
endif(NOT MSVC)
|
||||||
|
|
||||||
set(TEST_REPEATER_SRC
|
set(TEST_REPEATER_SRC
|
||||||
src/main.c
|
src/main.c
|
||||||
|
|
@ -28,7 +26,6 @@ set(TEST_REPEATER_INCLUDE
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
set(TEST_REPEATER_INCLUDE ${TEST_REPEATER_INCLUDE}
|
set(TEST_REPEATER_INCLUDE ${TEST_REPEATER_INCLUDE}
|
||||||
${BLADERF_HOST_COMMON_INCLUDE_DIRS}/windows
|
${BLADERF_HOST_COMMON_INCLUDE_DIRS}/windows
|
||||||
${LIBPTHREADSWIN32_INCLUDE_DIRS}
|
|
||||||
${MSVC_C99_INCLUDES}
|
${MSVC_C99_INCLUDES}
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
@ -41,10 +38,5 @@ set(TEST_REPEATER_LIBS
|
||||||
libbladerf_shared
|
libbladerf_shared
|
||||||
${CMAKE_THREAD_LIBS_INIT})
|
${CMAKE_THREAD_LIBS_INIT})
|
||||||
|
|
||||||
|
|
||||||
if(LIBPTHREADSWIN32_FOUND)
|
|
||||||
set(TEST_REPEATER_LIBS ${TEST_REPEATER_LIBS} ${LIBPTHREADSWIN32_LIBRARIES})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
target_link_libraries(libbladeRF_test_repeater
|
target_link_libraries(libbladeRF_test_repeater
|
||||||
${TEST_REPEATER_LIBS})
|
${TEST_REPEATER_LIBS})
|
||||||
|
|
@ -64,10 +64,10 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <pthread.h>
|
|
||||||
#include <libbladeRF.h>
|
#include <libbladeRF.h>
|
||||||
#include "rel_assert.h"
|
#include "rel_assert.h"
|
||||||
|
|
||||||
|
#include "thread.h"
|
||||||
#include "repeater.h"
|
#include "repeater.h"
|
||||||
#include "minmax.h"
|
#include "minmax.h"
|
||||||
|
|
||||||
|
|
@ -152,9 +152,9 @@ static char get_key()
|
||||||
|
|
||||||
/* Thread-safe wrapper around fprintf(stderr, ...) */
|
/* Thread-safe wrapper around fprintf(stderr, ...) */
|
||||||
#define print_error(repeater_, ...) do { \
|
#define print_error(repeater_, ...) do { \
|
||||||
pthread_mutex_lock(&repeater_->stderr_lock); \
|
MUTEX_LOCK(&repeater_->stderr_lock); \
|
||||||
fprintf(stderr, __VA_ARGS__); \
|
fprintf(stderr, __VA_ARGS__); \
|
||||||
pthread_mutex_unlock(&repeater_->stderr_lock); \
|
MUTEX_UNLOCK(&repeater_->stderr_lock); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define GAIN_TXVGA1_MIN -35
|
#define GAIN_TXVGA1_MIN -35
|
||||||
|
|
@ -189,22 +189,22 @@ struct buf_mgmt
|
||||||
size_t num_buffers; /* # of sample buffers */
|
size_t num_buffers; /* # of sample buffers */
|
||||||
|
|
||||||
/* Used to signal the TX thread when a few samplse have been buffered up */
|
/* Used to signal the TX thread when a few samplse have been buffered up */
|
||||||
pthread_cond_t samples_available;
|
COND samples_available;
|
||||||
|
|
||||||
pthread_mutex_t lock;
|
MUTEX lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct repeater
|
struct repeater
|
||||||
{
|
{
|
||||||
struct bladerf *device;
|
struct bladerf *device;
|
||||||
|
|
||||||
pthread_t rx_task;
|
THREAD rx_task;
|
||||||
struct bladerf_stream *rx_stream;
|
struct bladerf_stream *rx_stream;
|
||||||
|
|
||||||
pthread_t tx_task;
|
THREAD tx_task;
|
||||||
struct bladerf_stream *tx_stream;
|
struct bladerf_stream *tx_stream;
|
||||||
|
|
||||||
pthread_mutex_t stderr_lock;
|
MUTEX stderr_lock;
|
||||||
|
|
||||||
struct buf_mgmt buf_mgmt;
|
struct buf_mgmt buf_mgmt;
|
||||||
|
|
||||||
|
|
@ -247,7 +247,7 @@ static void *tx_stream_callback(struct bladerf *dev,
|
||||||
void *ret;
|
void *ret;
|
||||||
struct repeater *repeater = (struct repeater *)user_data;
|
struct repeater *repeater = (struct repeater *)user_data;
|
||||||
|
|
||||||
pthread_mutex_lock(&repeater->buf_mgmt.lock);
|
MUTEX_LOCK(&repeater->buf_mgmt.lock);
|
||||||
|
|
||||||
if (repeater->buf_mgmt.tx_idx < 0) {
|
if (repeater->buf_mgmt.tx_idx < 0) {
|
||||||
ret = NULL;
|
ret = NULL;
|
||||||
|
|
@ -271,7 +271,7 @@ static void *tx_stream_callback(struct bladerf *dev,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&repeater->buf_mgmt.lock);
|
MUTEX_UNLOCK(&repeater->buf_mgmt.lock);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
@ -284,21 +284,21 @@ void * tx_task_run(void *repeater_)
|
||||||
|
|
||||||
/* Wait for RX task to buffer up some samples before we begin
|
/* Wait for RX task to buffer up some samples before we begin
|
||||||
* consuming them */
|
* consuming them */
|
||||||
pthread_mutex_lock(&repeater->buf_mgmt.lock);
|
MUTEX_LOCK(&repeater->buf_mgmt.lock);
|
||||||
while(repeater->buf_mgmt.num_filled < repeater->buf_mgmt.prefill_count &&
|
while(repeater->buf_mgmt.num_filled < repeater->buf_mgmt.prefill_count &&
|
||||||
repeater->buf_mgmt.tx_idx >= 0) {
|
repeater->buf_mgmt.tx_idx >= 0) {
|
||||||
|
|
||||||
status = pthread_cond_wait(&repeater->buf_mgmt.samples_available,
|
status = COND_WAIT(&repeater->buf_mgmt.samples_available,
|
||||||
&repeater->buf_mgmt.lock);
|
&repeater->buf_mgmt.lock);
|
||||||
|
|
||||||
if (status != 0) {
|
if (status != THREAD_SUCCESS) {
|
||||||
print_error(repeater, "TX startup wait failed (%d)\n", status);
|
print_error(repeater, "TX startup wait failed (%d)\n", status);
|
||||||
exit_early = true;
|
exit_early = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exit_early |= repeater->buf_mgmt.tx_idx < 0;
|
exit_early |= repeater->buf_mgmt.tx_idx < 0;
|
||||||
pthread_mutex_unlock(&repeater->buf_mgmt.lock);
|
MUTEX_UNLOCK(&repeater->buf_mgmt.lock);
|
||||||
|
|
||||||
if (!exit_early) {
|
if (!exit_early) {
|
||||||
/* Call stream */
|
/* Call stream */
|
||||||
|
|
@ -325,7 +325,7 @@ static void *rx_stream_callback(struct bladerf *dev,
|
||||||
struct repeater *repeater = (struct repeater *)user_data;
|
struct repeater *repeater = (struct repeater *)user_data;
|
||||||
void *ret;
|
void *ret;
|
||||||
|
|
||||||
pthread_mutex_lock(&repeater->buf_mgmt.lock);
|
MUTEX_LOCK(&repeater->buf_mgmt.lock);
|
||||||
|
|
||||||
if (repeater->buf_mgmt.rx_idx < 0) {
|
if (repeater->buf_mgmt.rx_idx < 0) {
|
||||||
ret = NULL;
|
ret = NULL;
|
||||||
|
|
@ -346,10 +346,10 @@ static void *rx_stream_callback(struct bladerf *dev,
|
||||||
} else {
|
} else {
|
||||||
repeater->buf_mgmt.num_filled++;
|
repeater->buf_mgmt.num_filled++;
|
||||||
}
|
}
|
||||||
pthread_cond_signal(&repeater->buf_mgmt.samples_available);
|
COND_SIGNAL(&repeater->buf_mgmt.samples_available);
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&repeater->buf_mgmt.lock);
|
MUTEX_UNLOCK(&repeater->buf_mgmt.lock);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
@ -372,9 +372,9 @@ static inline void repeater_init(struct repeater *repeater,
|
||||||
{
|
{
|
||||||
memset(repeater, 0, sizeof(*repeater));
|
memset(repeater, 0, sizeof(*repeater));
|
||||||
|
|
||||||
pthread_mutex_init(&repeater->stderr_lock, NULL);
|
MUTEX_INIT(&repeater->stderr_lock);
|
||||||
pthread_mutex_init(&repeater->buf_mgmt.lock, NULL);
|
MUTEX_INIT(&repeater->buf_mgmt.lock);
|
||||||
pthread_cond_init(&repeater->buf_mgmt.samples_available, NULL);
|
COND_INIT(&repeater->buf_mgmt.samples_available);
|
||||||
|
|
||||||
repeater->buf_mgmt.num_filled = 0;
|
repeater->buf_mgmt.num_filled = 0;
|
||||||
repeater->buf_mgmt.num_buffers = config->num_buffers;
|
repeater->buf_mgmt.num_buffers = config->num_buffers;
|
||||||
|
|
@ -607,15 +607,15 @@ static int start_tasks(struct repeater *repeater)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
status = pthread_create(&repeater->rx_task, NULL, rx_task_run, repeater);
|
status = THREAD_CREATE(&repeater->rx_task, rx_task_run, repeater);
|
||||||
if (status < 0) {
|
if (status != THREAD_SUCCESS) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = pthread_create(&repeater->tx_task, NULL, tx_task_run, repeater);
|
status = THREAD_CREATE(&repeater->tx_task, tx_task_run, repeater);
|
||||||
if (status < 0) {
|
if (status != THREAD_SUCCESS) {
|
||||||
pthread_cancel(repeater->rx_task);
|
THREAD_CANCEL(repeater->rx_task);
|
||||||
pthread_join(repeater->rx_task, NULL);
|
THREAD_JOIN(repeater->rx_task, NULL);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -625,18 +625,18 @@ static int start_tasks(struct repeater *repeater)
|
||||||
static void stop_tasks(struct repeater *repeater)
|
static void stop_tasks(struct repeater *repeater)
|
||||||
{
|
{
|
||||||
print_error(repeater, "Stoppping RX and tasks...\r\n");
|
print_error(repeater, "Stoppping RX and tasks...\r\n");
|
||||||
pthread_mutex_lock(&repeater->buf_mgmt.lock);
|
MUTEX_LOCK(&repeater->buf_mgmt.lock);
|
||||||
repeater->buf_mgmt.tx_idx = -1;
|
repeater->buf_mgmt.tx_idx = -1;
|
||||||
repeater->buf_mgmt.rx_idx = -1;
|
repeater->buf_mgmt.rx_idx = -1;
|
||||||
pthread_mutex_unlock(&repeater->buf_mgmt.lock);
|
MUTEX_UNLOCK(&repeater->buf_mgmt.lock);
|
||||||
pthread_join(repeater->rx_task, NULL);
|
THREAD_JOIN(repeater->rx_task, NULL);
|
||||||
|
|
||||||
/* Fire off the "samples available" signal to the TX thread, in case
|
/* Fire off the "samples available" signal to the TX thread, in case
|
||||||
* it is still awaiting for the prefill completion */
|
* it is still awaiting for the prefill completion */
|
||||||
pthread_mutex_lock(&repeater->buf_mgmt.lock);
|
MUTEX_LOCK(&repeater->buf_mgmt.lock);
|
||||||
pthread_cond_signal(&repeater->buf_mgmt.samples_available);
|
COND_SIGNAL(&repeater->buf_mgmt.samples_available);
|
||||||
pthread_mutex_unlock(&repeater->buf_mgmt.lock);
|
MUTEX_UNLOCK(&repeater->buf_mgmt.lock);
|
||||||
pthread_join(repeater->tx_task, NULL);
|
THREAD_JOIN(repeater->tx_task, NULL);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,14 +12,10 @@ endif()
|
||||||
|
|
||||||
set(LIBS libbladerf_shared)
|
set(LIBS libbladerf_shared)
|
||||||
|
|
||||||
if(MSVC)
|
if(NOT MSVC)
|
||||||
find_package(LibPThreadsWin32 REQUIRED)
|
|
||||||
set(INCLUDES ${INCLUDES} ${LIBPTHREADSWIN32_INCLUDE_DIRS})
|
|
||||||
set(LIBS ${LIBS} ${LIBPTHREADSWIN32_LIBRARIES})
|
|
||||||
else(MSVC)
|
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||||
endif(MSVC)
|
endif(NOT MSVC)
|
||||||
|
|
||||||
set(SRC
|
set(SRC
|
||||||
src/main.c
|
src/main.c
|
||||||
|
|
|
||||||
|
|
@ -14,14 +14,10 @@ endif()
|
||||||
|
|
||||||
set(LIBS libbladerf_shared)
|
set(LIBS libbladerf_shared)
|
||||||
|
|
||||||
if(MSVC)
|
if(NOT MSVC)
|
||||||
find_package(LibPThreadsWin32 REQUIRED)
|
|
||||||
set(INCLUDES ${INCLUDES} ${LIBPTHREADSWIN32_INCLUDE_DIRS})
|
|
||||||
set(LIBS ${LIBS} ${LIBPTHREADSWIN32_LIBRARIES})
|
|
||||||
else(MSVC)
|
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||||
endif(MSVC)
|
endif(NOT MSVC)
|
||||||
|
|
||||||
set(SRC
|
set(SRC
|
||||||
src/main.c
|
src/main.c
|
||||||
|
|
|
||||||
|
|
@ -12,14 +12,10 @@ endif()
|
||||||
|
|
||||||
set(TEST_SYNC_LIBS libbladerf_shared)
|
set(TEST_SYNC_LIBS libbladerf_shared)
|
||||||
|
|
||||||
if(MSVC)
|
if(NOT MSVC)
|
||||||
find_package(LibPThreadsWin32 REQUIRED)
|
|
||||||
set(TEST_SYNC_INCLUDES ${TEST_SYNC_INCLUDES} ${LIBPTHREADSWIN32_INCLUDE_DIRS})
|
|
||||||
set(TEST_SYNC_LIBS ${TEST_SYNC_LIBS} ${LIBPTHREADSWIN32_LIBRARIES})
|
|
||||||
else(MSVC)
|
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
set(TEST_SYNC_LIBS ${TEST_SYNC_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
set(TEST_SYNC_LIBS ${TEST_SYNC_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||||
endif(MSVC)
|
endif(NOT MSVC)
|
||||||
|
|
||||||
add_definitions(-DLOGGING_ENABLED=1)
|
add_definitions(-DLOGGING_ENABLED=1)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <pthread.h>
|
#include "thread.h"
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <libbladeRF.h>
|
#include <libbladeRF.h>
|
||||||
|
|
||||||
|
|
@ -40,7 +40,7 @@ static struct task_args {
|
||||||
struct bladerf *dev;
|
struct bladerf *dev;
|
||||||
|
|
||||||
struct test_params *p;
|
struct test_params *p;
|
||||||
pthread_t thread;
|
THREAD thread;
|
||||||
int status;
|
int status;
|
||||||
bool quit;
|
bool quit;
|
||||||
} rx_args, tx_args;
|
} rx_args, tx_args;
|
||||||
|
|
@ -365,7 +365,7 @@ int test_run(struct test_params *p)
|
||||||
tx_args.quit = false;
|
tx_args.quit = false;
|
||||||
|
|
||||||
log_debug("Starting TX task\n");
|
log_debug("Starting TX task\n");
|
||||||
if (pthread_create(&tx_args.thread, NULL, tx_task, &tx_args) != 0) {
|
if (THREAD_CREATE(&tx_args.thread, tx_task, &tx_args) != THREAD_SUCCESS) {
|
||||||
fclose(p->in_file);
|
fclose(p->in_file);
|
||||||
p->in_file = NULL;
|
p->in_file = NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -378,7 +378,7 @@ int test_run(struct test_params *p)
|
||||||
rx_args.quit = false;
|
rx_args.quit = false;
|
||||||
|
|
||||||
log_debug("Starting RX task\n");
|
log_debug("Starting RX task\n");
|
||||||
if (pthread_create(&rx_args.thread, NULL, rx_task, &rx_args) != 0) {
|
if (THREAD_CREATE(&rx_args.thread, rx_task, &rx_args) != THREAD_SUCCESS) {
|
||||||
fclose(p->out_file);
|
fclose(p->out_file);
|
||||||
p->out_file = NULL;
|
p->out_file = NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -387,12 +387,12 @@ int test_run(struct test_params *p)
|
||||||
log_debug("Running...\n");
|
log_debug("Running...\n");
|
||||||
|
|
||||||
if (p->in_file != NULL) {
|
if (p->in_file != NULL) {
|
||||||
pthread_join(tx_args.thread, NULL);
|
THREAD_JOIN(tx_args.thread, NULL);
|
||||||
log_debug("Joined TX task\n");
|
log_debug("Joined TX task\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p->out_file != NULL) {
|
if (p->out_file != NULL) {
|
||||||
pthread_join(rx_args.thread, NULL);
|
THREAD_JOIN(rx_args.thread, NULL);
|
||||||
log_debug("Joined RX task\n");
|
log_debug("Joined RX task\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,14 +14,10 @@ endif()
|
||||||
|
|
||||||
set(LIBS libbladerf_shared)
|
set(LIBS libbladerf_shared)
|
||||||
|
|
||||||
if(MSVC)
|
if(NOT MSVC)
|
||||||
find_package(LibPThreadsWin32 REQUIRED)
|
|
||||||
set(INCLUDES ${INCLUDES} ${LIBPTHREADSWIN32_INCLUDE_DIRS})
|
|
||||||
set(LIBS ${LIBS} ${LIBPTHREADSWIN32_LIBRARIES})
|
|
||||||
else()
|
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||||
endif(MSVC)
|
endif(NOT MSVC)
|
||||||
|
|
||||||
|
|
||||||
set(SRC
|
set(SRC
|
||||||
|
|
|
||||||
|
|
@ -284,10 +284,10 @@ void *loopback_burst_rx_task (void *args)
|
||||||
burst_num, bladerf_strerror(status));
|
burst_num, bladerf_strerror(status));
|
||||||
} else if (meta.status & BLADERF_META_STATUS_OVERRUN) {
|
} else if (meta.status & BLADERF_META_STATUS_OVERRUN) {
|
||||||
fprintf(stderr, "Error: RX overrun detected.\n");
|
fprintf(stderr, "Error: RX overrun detected.\n");
|
||||||
pthread_mutex_lock(&t->lock);
|
MUTEX_LOCK(&t->lock);
|
||||||
t->stop = true;
|
t->stop = true;
|
||||||
t->rx_ready = true;
|
t->rx_ready = true;
|
||||||
pthread_mutex_unlock(&t->lock);
|
MUTEX_UNLOCK(&t->lock);
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
printf("Read %-8u samples @ 0x%08"PRIx64" (%-8"PRIu64")\n",
|
printf("Read %-8u samples @ 0x%08"PRIx64" (%-8"PRIu64")\n",
|
||||||
|
|
@ -336,9 +336,9 @@ void *loopback_burst_rx_task (void *args)
|
||||||
* rid ourselves of any junk in the RX FIFOs and are
|
* rid ourselves of any junk in the RX FIFOs and are
|
||||||
* ready to start the test */
|
* ready to start the test */
|
||||||
next_state = WAIT_FOR_BURST_START;
|
next_state = WAIT_FOR_BURST_START;
|
||||||
pthread_mutex_lock(&t->lock);
|
MUTEX_LOCK(&t->lock);
|
||||||
t->rx_ready = true;
|
t->rx_ready = true;
|
||||||
pthread_mutex_unlock(&t->lock);
|
MUTEX_UNLOCK(&t->lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -443,9 +443,9 @@ void *loopback_burst_rx_task (void *args)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_lock(&t->lock);
|
MUTEX_LOCK(&t->lock);
|
||||||
stop = t->stop;
|
stop = t->stop;
|
||||||
pthread_mutex_unlock(&t->lock);
|
MUTEX_UNLOCK(&t->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
|
|
@ -459,9 +459,9 @@ void *loopback_burst_rx_task (void *args)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Ensure the TX side is signalled to stop, if it isn't already */
|
/* Ensure the TX side is signalled to stop, if it isn't already */
|
||||||
pthread_mutex_lock(&t->lock);
|
MUTEX_LOCK(&t->lock);
|
||||||
t->stop = true;
|
t->stop = true;
|
||||||
pthread_mutex_unlock(&t->lock);
|
MUTEX_UNLOCK(&t->lock);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -514,10 +514,10 @@ void *loopback_burst_rx_task_rf (void *args)
|
||||||
burst_num, bladerf_strerror(status));
|
burst_num, bladerf_strerror(status));
|
||||||
} else if (meta.status & BLADERF_META_STATUS_OVERRUN) {
|
} else if (meta.status & BLADERF_META_STATUS_OVERRUN) {
|
||||||
fprintf(stderr, "Error: RX overrun detected.\n");
|
fprintf(stderr, "Error: RX overrun detected.\n");
|
||||||
pthread_mutex_lock(&t->lock);
|
MUTEX_LOCK(&t->lock);
|
||||||
t->stop = true;
|
t->stop = true;
|
||||||
t->rx_ready = true;
|
t->rx_ready = true;
|
||||||
pthread_mutex_unlock(&t->lock);
|
MUTEX_UNLOCK(&t->lock);
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
printf("Read %-8u samples @ 0x%08"PRIx64" (%-8"PRIu64")\n",
|
printf("Read %-8u samples @ 0x%08"PRIx64" (%-8"PRIu64")\n",
|
||||||
|
|
@ -565,9 +565,9 @@ void *loopback_burst_rx_task_rf (void *args)
|
||||||
* rid ourselves of any junk in the RX FIFOs and are
|
* rid ourselves of any junk in the RX FIFOs and are
|
||||||
* ready to start the test */
|
* ready to start the test */
|
||||||
next_state = WAIT_FOR_BURST_START;
|
next_state = WAIT_FOR_BURST_START;
|
||||||
pthread_mutex_lock(&t->lock);
|
MUTEX_LOCK(&t->lock);
|
||||||
t->rx_ready = true;
|
t->rx_ready = true;
|
||||||
pthread_mutex_unlock(&t->lock);
|
MUTEX_UNLOCK(&t->lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -672,9 +672,9 @@ void *loopback_burst_rx_task_rf (void *args)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_lock(&t->lock);
|
MUTEX_LOCK(&t->lock);
|
||||||
stop = t->stop;
|
stop = t->stop;
|
||||||
pthread_mutex_unlock(&t->lock);
|
MUTEX_UNLOCK(&t->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
|
|
@ -688,9 +688,9 @@ void *loopback_burst_rx_task_rf (void *args)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Ensure the TX side is signalled to stop, if it isn't already */
|
/* Ensure the TX side is signalled to stop, if it isn't already */
|
||||||
pthread_mutex_lock(&t->lock);
|
MUTEX_LOCK(&t->lock);
|
||||||
t->stop = true;
|
t->stop = true;
|
||||||
pthread_mutex_unlock(&t->lock);
|
MUTEX_UNLOCK(&t->lock);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,8 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <pthread.h>
|
|
||||||
#include <libbladeRF.h>
|
#include <libbladeRF.h>
|
||||||
|
#include "thread.h"
|
||||||
|
|
||||||
#define LOOPBACK_TX_MAGNITUDE 2000
|
#define LOOPBACK_TX_MAGNITUDE 2000
|
||||||
#define LOOPBACK_RX_POWER_THRESH (256 * 256)
|
#define LOOPBACK_RX_POWER_THRESH (256 * 256)
|
||||||
|
|
@ -40,7 +40,7 @@ struct loopback_burst_test {
|
||||||
struct loopback_burst *bursts;
|
struct loopback_burst *bursts;
|
||||||
unsigned int num_bursts;
|
unsigned int num_bursts;
|
||||||
|
|
||||||
pthread_mutex_t lock;
|
MUTEX lock;
|
||||||
bool stop;
|
bool stop;
|
||||||
bool rx_ready;
|
bool rx_ready;
|
||||||
bladerf_frequency frequency;
|
bladerf_frequency frequency;
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <pthread.h>
|
#include "thread.h"
|
||||||
#include <libbladeRF.h>
|
#include <libbladeRF.h>
|
||||||
#include "test_timestamps.h"
|
#include "test_timestamps.h"
|
||||||
|
|
||||||
|
|
@ -77,8 +77,8 @@ static struct async_task
|
||||||
size_t curr_buf_idx;
|
size_t curr_buf_idx;
|
||||||
size_t n_buffers;
|
size_t n_buffers;
|
||||||
|
|
||||||
pthread_t thread;
|
THREAD thread;
|
||||||
pthread_mutex_t lock;
|
MUTEX lock;
|
||||||
} rx_task, tx_task;
|
} rx_task, tx_task;
|
||||||
|
|
||||||
void *callback(struct bladerf *dev, struct bladerf_stream *stream,
|
void *callback(struct bladerf *dev, struct bladerf_stream *stream,
|
||||||
|
|
@ -90,7 +90,7 @@ void *callback(struct bladerf *dev, struct bladerf_stream *stream,
|
||||||
void *ret;
|
void *ret;
|
||||||
|
|
||||||
|
|
||||||
pthread_mutex_lock(&t->lock);
|
MUTEX_LOCK(&t->lock);
|
||||||
|
|
||||||
t->curr_buf_idx = (t->curr_buf_idx + 1) % t->n_buffers;
|
t->curr_buf_idx = (t->curr_buf_idx + 1) % t->n_buffers;
|
||||||
ret = t->buffers[t->curr_buf_idx];
|
ret = t->buffers[t->curr_buf_idx];
|
||||||
|
|
@ -112,7 +112,7 @@ void *callback(struct bladerf *dev, struct bladerf_stream *stream,
|
||||||
ret = BLADERF_STREAM_SHUTDOWN;
|
ret = BLADERF_STREAM_SHUTDOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&t->lock);
|
MUTEX_UNLOCK(&t->lock);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -146,10 +146,10 @@ static void *stream_task(void *arg)
|
||||||
bladerf_deinit_stream(stream);
|
bladerf_deinit_stream(stream);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
pthread_mutex_lock(&t->lock);
|
MUTEX_LOCK(&t->lock);
|
||||||
t->state = TASK_STOPPED;
|
t->state = TASK_STOPPED;
|
||||||
t->exit_status = status;
|
t->exit_status = status;
|
||||||
pthread_mutex_unlock(&t->lock);
|
MUTEX_UNLOCK(&t->lock);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -217,8 +217,8 @@ static int init_if(struct bladerf *dev, struct app_params *p, bladerf_module m,
|
||||||
t->fmt = fmt;
|
t->fmt = fmt;
|
||||||
t->state = state = TASK_UNINITIALIZED;
|
t->state = state = TASK_UNINITIALIZED;
|
||||||
|
|
||||||
status = pthread_create(&t->thread, NULL, stream_task, t);
|
status = THREAD_CREATE(&t->thread, stream_task, t);
|
||||||
if (status != 0) {
|
if (status != THREAD_SUCCESS) {
|
||||||
fprintf(stderr, "Failed to launch %s task\n",
|
fprintf(stderr, "Failed to launch %s task\n",
|
||||||
m == BLADERF_MODULE_RX ? "RX" : "TX");
|
m == BLADERF_MODULE_RX ? "RX" : "TX");
|
||||||
return status;
|
return status;
|
||||||
|
|
@ -226,15 +226,15 @@ static int init_if(struct bladerf *dev, struct app_params *p, bladerf_module m,
|
||||||
|
|
||||||
do {
|
do {
|
||||||
usleep(25000);
|
usleep(25000);
|
||||||
pthread_mutex_lock(&t->lock);
|
MUTEX_LOCK(&t->lock);
|
||||||
state = t->state;
|
state = t->state;
|
||||||
pthread_mutex_unlock(&t->lock);
|
MUTEX_UNLOCK(&t->lock);
|
||||||
} while (state == TASK_UNINITIALIZED);
|
} while (state == TASK_UNINITIALIZED);
|
||||||
|
|
||||||
/* This may have already stopped if an invalid configuration was
|
/* This may have already stopped if an invalid configuration was
|
||||||
* detected. */
|
* detected. */
|
||||||
if (state == TASK_STOPPED) {
|
if (state == TASK_STOPPED) {
|
||||||
pthread_join(t->thread, NULL);
|
THREAD_JOIN(t->thread, NULL);
|
||||||
if (t->exit_status != exp_status) {
|
if (t->exit_status != exp_status) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Uexpected status when configuring async %s: %s\n",
|
"Uexpected status when configuring async %s: %s\n",
|
||||||
|
|
@ -274,23 +274,23 @@ static int deinit_if(struct bladerf *dev, bladerf_module m, bool sync,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_lock(&t->lock);
|
MUTEX_LOCK(&t->lock);
|
||||||
state = t->state;
|
state = t->state;
|
||||||
pthread_mutex_unlock(&t->lock);
|
MUTEX_UNLOCK(&t->lock);
|
||||||
|
|
||||||
while (state != TASK_STOPPED) {
|
while (state != TASK_STOPPED) {
|
||||||
pthread_mutex_lock(&t->lock);
|
MUTEX_LOCK(&t->lock);
|
||||||
t->state = TASK_SHUTDOWN_REQUESTED;
|
t->state = TASK_SHUTDOWN_REQUESTED;
|
||||||
pthread_mutex_unlock(&t->lock);
|
MUTEX_UNLOCK(&t->lock);
|
||||||
|
|
||||||
usleep(25000);
|
usleep(25000);
|
||||||
|
|
||||||
pthread_mutex_lock(&t->lock);
|
MUTEX_LOCK(&t->lock);
|
||||||
state = t->state;
|
state = t->state;
|
||||||
pthread_mutex_unlock(&t->lock);
|
MUTEX_UNLOCK(&t->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_join(t->thread, NULL);
|
THREAD_JOIN(t->thread, NULL);
|
||||||
|
|
||||||
if (t->exit_status != exp_status) {
|
if (t->exit_status != exp_status) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
|
|
@ -331,7 +331,7 @@ static void init_task_info(struct bladerf *dev, struct app_params *p,
|
||||||
t->n_buffers = 16;
|
t->n_buffers = 16;
|
||||||
t->curr_buf_idx = 0;
|
t->curr_buf_idx = 0;
|
||||||
|
|
||||||
pthread_mutex_init(&t->lock, NULL);
|
MUTEX_INIT(&t->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
int test_fn_format_mismatch(struct bladerf *dev, struct app_params *p)
|
int test_fn_format_mismatch(struct bladerf *dev, struct app_params *p)
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,6 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <pthread.h>
|
|
||||||
#include <libbladeRF.h>
|
#include <libbladeRF.h>
|
||||||
#include "test_timestamps.h"
|
#include "test_timestamps.h"
|
||||||
#include "loopback.h"
|
#include "loopback.h"
|
||||||
|
|
@ -88,9 +87,9 @@ static void * tx_task(void *args)
|
||||||
i + 1, samples_left, bladerf_strerror(status));
|
i + 1, samples_left, bladerf_strerror(status));
|
||||||
|
|
||||||
/* Stop the RX worker */
|
/* Stop the RX worker */
|
||||||
pthread_mutex_lock(&t->lock);
|
MUTEX_LOCK(&t->lock);
|
||||||
t->stop = true;
|
t->stop = true;
|
||||||
pthread_mutex_unlock(&t->lock);
|
MUTEX_UNLOCK(&t->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
meta.flags &= ~BLADERF_META_FLAG_TX_BURST_START;
|
meta.flags &= ~BLADERF_META_FLAG_TX_BURST_START;
|
||||||
|
|
@ -109,15 +108,15 @@ static void * tx_task(void *args)
|
||||||
bladerf_strerror(status));
|
bladerf_strerror(status));
|
||||||
|
|
||||||
/* Stop the RX worker */
|
/* Stop the RX worker */
|
||||||
pthread_mutex_lock(&t->lock);
|
MUTEX_LOCK(&t->lock);
|
||||||
t->stop = true;
|
t->stop = true;
|
||||||
pthread_mutex_unlock(&t->lock);
|
MUTEX_UNLOCK(&t->lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_lock(&t->lock);
|
MUTEX_LOCK(&t->lock);
|
||||||
stop = t->stop;
|
stop = t->stop;
|
||||||
pthread_mutex_unlock(&t->lock);
|
MUTEX_UNLOCK(&t->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for samples to finish */
|
/* Wait for samples to finish */
|
||||||
|
|
@ -195,10 +194,10 @@ int test_fn_loopback_onoff(struct bladerf *dev, struct app_params *p)
|
||||||
{
|
{
|
||||||
int status = 0;
|
int status = 0;
|
||||||
struct loopback_burst_test test;
|
struct loopback_burst_test test;
|
||||||
pthread_t tx_thread;
|
THREAD tx_thread;
|
||||||
bool tx_started = false;
|
bool tx_started = false;
|
||||||
|
|
||||||
pthread_t rx_thread;
|
THREAD rx_thread;
|
||||||
bool rx_started = false;
|
bool rx_started = false;
|
||||||
bool rx_ready = false;
|
bool rx_ready = false;
|
||||||
|
|
||||||
|
|
@ -208,7 +207,7 @@ int test_fn_loopback_onoff(struct bladerf *dev, struct app_params *p)
|
||||||
test.stop = false;
|
test.stop = false;
|
||||||
test.rx_ready = false;
|
test.rx_ready = false;
|
||||||
|
|
||||||
pthread_mutex_init(&test.lock, NULL);
|
MUTEX_INIT(&test.lock);
|
||||||
|
|
||||||
test.bursts = (struct loopback_burst *) malloc(test.num_bursts * sizeof(test.bursts[0]));
|
test.bursts = (struct loopback_burst *) malloc(test.num_bursts * sizeof(test.bursts[0]));
|
||||||
if (test.bursts == NULL) {
|
if (test.bursts == NULL) {
|
||||||
|
|
@ -225,8 +224,8 @@ int test_fn_loopback_onoff(struct bladerf *dev, struct app_params *p)
|
||||||
|
|
||||||
printf("Starting bursts...\n");
|
printf("Starting bursts...\n");
|
||||||
|
|
||||||
status = pthread_create(&rx_thread, NULL, loopback_burst_rx_task, &test);
|
status = THREAD_CREATE(&rx_thread, loopback_burst_rx_task, &test);
|
||||||
if (status != 0) {
|
if (status != THREAD_SUCCESS) {
|
||||||
fprintf(stderr, "Failed to start RX thread: %s\n", strerror(status));
|
fprintf(stderr, "Failed to start RX thread: %s\n", strerror(status));
|
||||||
goto out;
|
goto out;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -235,13 +234,13 @@ int test_fn_loopback_onoff(struct bladerf *dev, struct app_params *p)
|
||||||
|
|
||||||
while (!rx_ready) {
|
while (!rx_ready) {
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
pthread_mutex_lock(&test.lock);
|
MUTEX_LOCK(&test.lock);
|
||||||
rx_ready = test.rx_ready;
|
rx_ready = test.rx_ready;
|
||||||
pthread_mutex_unlock(&test.lock);
|
MUTEX_UNLOCK(&test.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
status = pthread_create(&tx_thread, NULL, tx_task, &test);
|
status = THREAD_CREATE(&tx_thread, tx_task, &test);
|
||||||
if (status != 0) {
|
if (status != THREAD_SUCCESS) {
|
||||||
fprintf(stderr, "Failed to start TX thread: %s\n", strerror(status));
|
fprintf(stderr, "Failed to start TX thread: %s\n", strerror(status));
|
||||||
goto out;
|
goto out;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -250,11 +249,11 @@ int test_fn_loopback_onoff(struct bladerf *dev, struct app_params *p)
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (tx_started) {
|
if (tx_started) {
|
||||||
pthread_join(tx_thread, NULL);
|
THREAD_JOIN(tx_thread, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rx_started) {
|
if (rx_started) {
|
||||||
pthread_join(rx_thread, NULL);
|
THREAD_JOIN(rx_thread, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(test.bursts);
|
free(test.bursts);
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <pthread.h>
|
#include "thread.h"
|
||||||
#include <libbladeRF.h>
|
#include <libbladeRF.h>
|
||||||
#include "test_timestamps.h"
|
#include "test_timestamps.h"
|
||||||
#include "loopback.h"
|
#include "loopback.h"
|
||||||
|
|
@ -88,9 +88,9 @@ static void * tx_task(void *args)
|
||||||
i + 1, samples_left, bladerf_strerror(status));
|
i + 1, samples_left, bladerf_strerror(status));
|
||||||
|
|
||||||
/* Stop the RX worker */
|
/* Stop the RX worker */
|
||||||
pthread_mutex_lock(&t->lock);
|
MUTEX_LOCK(&t->lock);
|
||||||
t->stop = true;
|
t->stop = true;
|
||||||
pthread_mutex_unlock(&t->lock);
|
MUTEX_UNLOCK(&t->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
meta.flags &= ~BLADERF_META_FLAG_TX_BURST_START;
|
meta.flags &= ~BLADERF_META_FLAG_TX_BURST_START;
|
||||||
|
|
@ -109,15 +109,15 @@ static void * tx_task(void *args)
|
||||||
bladerf_strerror(status));
|
bladerf_strerror(status));
|
||||||
|
|
||||||
/* Stop the RX worker */
|
/* Stop the RX worker */
|
||||||
pthread_mutex_lock(&t->lock);
|
MUTEX_LOCK(&t->lock);
|
||||||
t->stop = true;
|
t->stop = true;
|
||||||
pthread_mutex_unlock(&t->lock);
|
MUTEX_UNLOCK(&t->lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_lock(&t->lock);
|
MUTEX_LOCK(&t->lock);
|
||||||
stop = t->stop;
|
stop = t->stop;
|
||||||
pthread_mutex_unlock(&t->lock);
|
MUTEX_UNLOCK(&t->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for samples to finish */
|
/* Wait for samples to finish */
|
||||||
|
|
@ -199,10 +199,10 @@ int test_fn_loopback_onoff_rf(struct bladerf *dev, struct app_params *p)
|
||||||
return 0;
|
return 0;
|
||||||
int status = 0;
|
int status = 0;
|
||||||
struct loopback_burst_test test;
|
struct loopback_burst_test test;
|
||||||
pthread_t tx_thread;
|
THREAD tx_thread;
|
||||||
bool tx_started = false;
|
bool tx_started = false;
|
||||||
|
|
||||||
pthread_t rx_thread;
|
THREAD rx_thread;
|
||||||
bool rx_started = false;
|
bool rx_started = false;
|
||||||
bool rx_ready = false;
|
bool rx_ready = false;
|
||||||
|
|
||||||
|
|
@ -213,7 +213,7 @@ int test_fn_loopback_onoff_rf(struct bladerf *dev, struct app_params *p)
|
||||||
test.rx_ready = false;
|
test.rx_ready = false;
|
||||||
test.frequency = 100e6;
|
test.frequency = 100e6;
|
||||||
|
|
||||||
pthread_mutex_init(&test.lock, NULL);
|
MUTEX_INIT(&test.lock);
|
||||||
|
|
||||||
fprintf(stderr, "[WARNING] loopback_onoff_rf under construction\n");
|
fprintf(stderr, "[WARNING] loopback_onoff_rf under construction\n");
|
||||||
fprintf(stderr, "[WARNING] Failure expected\n");
|
fprintf(stderr, "[WARNING] Failure expected\n");
|
||||||
|
|
@ -234,8 +234,8 @@ int test_fn_loopback_onoff_rf(struct bladerf *dev, struct app_params *p)
|
||||||
|
|
||||||
printf("Starting bursts...\n");
|
printf("Starting bursts...\n");
|
||||||
|
|
||||||
status = pthread_create(&rx_thread, NULL, loopback_burst_rx_task_rf, &test);
|
status = THREAD_CREATE(&rx_thread, loopback_burst_rx_task_rf, &test);
|
||||||
if (status != 0) {
|
if (status != THREAD_SUCCESS) {
|
||||||
fprintf(stderr, "Failed to start RX thread: %s\n", strerror(status));
|
fprintf(stderr, "Failed to start RX thread: %s\n", strerror(status));
|
||||||
goto out;
|
goto out;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -244,13 +244,13 @@ int test_fn_loopback_onoff_rf(struct bladerf *dev, struct app_params *p)
|
||||||
|
|
||||||
while (!rx_ready) {
|
while (!rx_ready) {
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
pthread_mutex_lock(&test.lock);
|
MUTEX_LOCK(&test.lock);
|
||||||
rx_ready = test.rx_ready;
|
rx_ready = test.rx_ready;
|
||||||
pthread_mutex_unlock(&test.lock);
|
MUTEX_UNLOCK(&test.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
status = pthread_create(&tx_thread, NULL, tx_task, &test);
|
status = THREAD_CREATE(&tx_thread, tx_task, &test);
|
||||||
if (status != 0) {
|
if (status != THREAD_SUCCESS) {
|
||||||
fprintf(stderr, "Failed to start TX thread: %s\n", strerror(status));
|
fprintf(stderr, "Failed to start TX thread: %s\n", strerror(status));
|
||||||
goto out;
|
goto out;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -259,11 +259,11 @@ int test_fn_loopback_onoff_rf(struct bladerf *dev, struct app_params *p)
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (tx_started) {
|
if (tx_started) {
|
||||||
pthread_join(tx_thread, NULL);
|
THREAD_JOIN(tx_thread, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rx_started) {
|
if (rx_started) {
|
||||||
pthread_join(rx_thread, NULL);
|
THREAD_JOIN(rx_thread, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(test.bursts);
|
free(test.bursts);
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <pthread.h>
|
#include "thread.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <libbladeRF.h>
|
#include <libbladeRF.h>
|
||||||
#include "test_timestamps.h"
|
#include "test_timestamps.h"
|
||||||
|
|
@ -284,9 +284,9 @@ static void * tx_task(void *args)
|
||||||
status = tx_samples(t, samples, &meta, t->bursts[i].duration, i);
|
status = tx_samples(t, samples, &meta, t->bursts[i].duration, i);
|
||||||
|
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
pthread_mutex_lock(&t->lock);
|
MUTEX_LOCK(&t->lock);
|
||||||
stop = t->stop = true;
|
stop = t->stop = true;
|
||||||
pthread_mutex_unlock(&t->lock);
|
MUTEX_UNLOCK(&t->lock);
|
||||||
} else {
|
} else {
|
||||||
meta.flags = BLADERF_META_FLAG_TX_UPDATE_TIMESTAMP;
|
meta.flags = BLADERF_META_FLAG_TX_UPDATE_TIMESTAMP;
|
||||||
|
|
||||||
|
|
@ -296,9 +296,9 @@ static void * tx_task(void *args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pthread_mutex_lock(&t->lock);
|
MUTEX_LOCK(&t->lock);
|
||||||
stop = t->stop;
|
stop = t->stop;
|
||||||
pthread_mutex_unlock(&t->lock);
|
MUTEX_UNLOCK(&t->lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -341,10 +341,10 @@ int test_fn_loopback_onoff_zp(struct bladerf *dev, struct app_params *p)
|
||||||
{
|
{
|
||||||
int status = 0;
|
int status = 0;
|
||||||
struct loopback_burst_test test;
|
struct loopback_burst_test test;
|
||||||
pthread_t tx_thread;
|
THREAD tx_thread;
|
||||||
bool tx_started = false;
|
bool tx_started = false;
|
||||||
|
|
||||||
pthread_t rx_thread;
|
THREAD rx_thread;
|
||||||
bool rx_started = false;
|
bool rx_started = false;
|
||||||
bool rx_ready = false;
|
bool rx_ready = false;
|
||||||
|
|
||||||
|
|
@ -354,7 +354,7 @@ int test_fn_loopback_onoff_zp(struct bladerf *dev, struct app_params *p)
|
||||||
test.stop = false;
|
test.stop = false;
|
||||||
test.rx_ready = false;
|
test.rx_ready = false;
|
||||||
|
|
||||||
pthread_mutex_init(&test.lock, NULL);
|
MUTEX_INIT(&test.lock);
|
||||||
|
|
||||||
test.bursts = (struct loopback_burst *) malloc(test.num_bursts * sizeof(test.bursts[0]));
|
test.bursts = (struct loopback_burst *) malloc(test.num_bursts * sizeof(test.bursts[0]));
|
||||||
if (test.bursts == NULL) {
|
if (test.bursts == NULL) {
|
||||||
|
|
@ -371,8 +371,8 @@ int test_fn_loopback_onoff_zp(struct bladerf *dev, struct app_params *p)
|
||||||
|
|
||||||
printf("Starting bursts...\n");
|
printf("Starting bursts...\n");
|
||||||
|
|
||||||
status = pthread_create(&rx_thread, NULL, loopback_burst_rx_task, &test);
|
status = THREAD_CREATE(&rx_thread, loopback_burst_rx_task, &test);
|
||||||
if (status != 0) {
|
if (status != THREAD_SUCCESS) {
|
||||||
fprintf(stderr, "Failed to start RX thread: %s\n", strerror(status));
|
fprintf(stderr, "Failed to start RX thread: %s\n", strerror(status));
|
||||||
goto out;
|
goto out;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -381,13 +381,13 @@ int test_fn_loopback_onoff_zp(struct bladerf *dev, struct app_params *p)
|
||||||
|
|
||||||
while (!rx_ready) {
|
while (!rx_ready) {
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
pthread_mutex_lock(&test.lock);
|
MUTEX_LOCK(&test.lock);
|
||||||
rx_ready = test.rx_ready;
|
rx_ready = test.rx_ready;
|
||||||
pthread_mutex_unlock(&test.lock);
|
MUTEX_UNLOCK(&test.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
status = pthread_create(&tx_thread, NULL, tx_task, &test);
|
status = THREAD_CREATE(&tx_thread, tx_task, &test);
|
||||||
if (status != 0) {
|
if (status != THREAD_SUCCESS) {
|
||||||
fprintf(stderr, "Failed to start TX thread: %s\n", strerror(status));
|
fprintf(stderr, "Failed to start TX thread: %s\n", strerror(status));
|
||||||
goto out;
|
goto out;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -396,11 +396,11 @@ int test_fn_loopback_onoff_zp(struct bladerf *dev, struct app_params *p)
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (tx_started) {
|
if (tx_started) {
|
||||||
pthread_join(tx_thread, NULL);
|
THREAD_JOIN(tx_thread, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rx_started) {
|
if (rx_started) {
|
||||||
pthread_join(rx_thread, NULL);
|
THREAD_JOIN(rx_thread, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(test.bursts);
|
free(test.bursts);
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,11 @@
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <libbladeRF.h>
|
#include <libbladeRF.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <pthread.h>
|
|
||||||
#include "conversions.h"
|
#include "conversions.h"
|
||||||
#include "test_timestamps.h"
|
#include "test_timestamps.h"
|
||||||
#include "test_txrx_hwloop.h"
|
#include "test_txrx_hwloop.h"
|
||||||
#include "minmax.h"
|
#include "minmax.h"
|
||||||
|
#include "thread.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include "gettimeofday.h"
|
#include "gettimeofday.h"
|
||||||
|
|
@ -97,8 +97,8 @@ int main(int argc, char *argv[]) {
|
||||||
bladerf_log_level log_level;
|
bladerf_log_level log_level;
|
||||||
|
|
||||||
/** Threading */
|
/** Threading */
|
||||||
pthread_t thread_rx;
|
THREAD thread_rx;
|
||||||
pthread_t thread_loopcompare;
|
THREAD thread_loopcompare;
|
||||||
thread_args args_loopbackcompare;
|
thread_args args_loopbackcompare;
|
||||||
thread_args args_rx;
|
thread_args args_rx;
|
||||||
|
|
||||||
|
|
@ -231,14 +231,14 @@ int main(int argc, char *argv[]) {
|
||||||
args_rx.is_rx_device = true;
|
args_rx.is_rx_device = true;
|
||||||
args_rx.dev = dev_rx;
|
args_rx.dev = dev_rx;
|
||||||
args_rx.tc = &test;
|
args_rx.tc = &test;
|
||||||
pthread_create(&thread_rx, NULL, rx_task, &args_rx);
|
THREAD_CREATE(&thread_rx, rx_task, &args_rx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (test.compare == true) {
|
if (test.compare == true) {
|
||||||
args_loopbackcompare.is_rx_device = false;
|
args_loopbackcompare.is_rx_device = false;
|
||||||
args_loopbackcompare.dev = dev_tx;
|
args_loopbackcompare.dev = dev_tx;
|
||||||
args_loopbackcompare.tc = &test;
|
args_loopbackcompare.tc = &test;
|
||||||
pthread_create(&thread_loopcompare, NULL, rx_task, &args_loopbackcompare);
|
THREAD_CREATE(&thread_loopcompare, rx_task, &args_loopbackcompare);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < test.iterations && status == 0; i++) {
|
for (i = 0; i < test.iterations && status == 0; i++) {
|
||||||
|
|
@ -287,12 +287,12 @@ int main(int argc, char *argv[]) {
|
||||||
printf("TX finished in %.4f seconds\n", time_passed);
|
printf("TX finished in %.4f seconds\n", time_passed);
|
||||||
out:
|
out:
|
||||||
if (!test.just_tx) {
|
if (!test.just_tx) {
|
||||||
pthread_join(thread_rx, NULL);
|
THREAD_JOIN(thread_rx, NULL);
|
||||||
bladerf_close(dev_rx);
|
bladerf_close(dev_rx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (test.compare)
|
if (test.compare)
|
||||||
pthread_join(thread_loopcompare, NULL);
|
THREAD_JOIN(thread_loopcompare, NULL);
|
||||||
|
|
||||||
status_out = bladerf_enable_module(dev_tx, BLADERF_MODULE_TX, false);
|
status_out = bladerf_enable_module(dev_tx, BLADERF_MODULE_TX, false);
|
||||||
if (status_out != 0) {
|
if (status_out != 0) {
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include "thread.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
struct test_case {
|
struct test_case {
|
||||||
|
|
@ -326,6 +327,6 @@ void *rx_task(void *args) {
|
||||||
cleanup:
|
cleanup:
|
||||||
free(samples);
|
free(samples);
|
||||||
free(file_name);
|
free(file_name);
|
||||||
pthread_exit(NULL);
|
THREAD_EXIT(NULL);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ mkdir %BUILDDIR64%
|
||||||
pushd %BUILDDIR64%
|
pushd %BUILDDIR64%
|
||||||
echo ====================== Configuring 64-bit build ======================
|
echo ====================== Configuring 64-bit build ======================
|
||||||
cmake -G %CMAKE_GENERATOR_64% -DCMAKE_BUILD_TYPE=%BUILD_TYPE% ^
|
cmake -G %CMAKE_GENERATOR_64% -DCMAKE_BUILD_TYPE=%BUILD_TYPE% ^
|
||||||
-DLIBUSB_PATH=%LIBUSB% -DLIBPTHREADSWIN32_PATH=%PTHREADS% ^
|
-DLIBUSB_PATH=%LIBUSB% ^
|
||||||
..\bladeRF\host ^
|
..\bladeRF\host ^
|
||||||
|| goto EXIT_FAILURE
|
|| goto EXIT_FAILURE
|
||||||
|
|
||||||
|
|
@ -138,7 +138,7 @@ echo[
|
||||||
echo[
|
echo[
|
||||||
echo ====================== Configuring 32-bit build ======================
|
echo ====================== Configuring 32-bit build ======================
|
||||||
cmake -G %CMAKE_GENERATOR_32% -DCMAKE_BUILD_TYPE=%BUILD_TYPE% ^
|
cmake -G %CMAKE_GENERATOR_32% -DCMAKE_BUILD_TYPE=%BUILD_TYPE% ^
|
||||||
-DLIBUSB_PATH=%LIBUSB% -DLIBPTHREADSWIN32_PATH=%PTHREADS% ^
|
-DLIBUSB_PATH=%LIBUSB% ^
|
||||||
..\bladeRF\host ^
|
..\bladeRF\host ^
|
||||||
|| goto EXIT_FAILURE
|
|| goto EXIT_FAILURE
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
cmake_minimum_required(VERSION 3.5)
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
|
||||||
add_subdirectory(bladeRF-cli)
|
add_subdirectory(bladeRF-cli)
|
||||||
|
|
||||||
|
if(NOT MSVC)
|
||||||
add_subdirectory(bladeRF-fsk/c)
|
add_subdirectory(bladeRF-fsk/c)
|
||||||
|
endif()
|
||||||
|
|
@ -28,11 +28,9 @@ configure_file(
|
||||||
find_package(LibTecla)
|
find_package(LibTecla)
|
||||||
find_package(LibEdit)
|
find_package(LibEdit)
|
||||||
|
|
||||||
if(MSVC)
|
if(NOT MSVC)
|
||||||
find_package(LibPThreadsWin32 REQUIRED)
|
|
||||||
else(MSVC)
|
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
endif(MSVC)
|
endif(NOT MSVC)
|
||||||
|
|
||||||
find_program(PANDOC_EXECUTABLE pandoc)
|
find_program(PANDOC_EXECUTABLE pandoc)
|
||||||
find_program(BASH_EXECUTABLE bash)
|
find_program(BASH_EXECUTABLE bash)
|
||||||
|
|
@ -169,7 +167,6 @@ endif()
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
set(CLI_INCLUDE_DIRS ${CLI_INCLUDE_DIRS}
|
set(CLI_INCLUDE_DIRS ${CLI_INCLUDE_DIRS}
|
||||||
${BLADERF_HOST_COMMON_INCLUDE_DIRS}/windows
|
${BLADERF_HOST_COMMON_INCLUDE_DIRS}/windows
|
||||||
${LIBPTHREADSWIN32_INCLUDE_DIRS}
|
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
@ -266,7 +263,7 @@ set(CLI_LINK_LIBRARIES
|
||||||
|
|
||||||
if(NOT MSVC)
|
if(NOT MSVC)
|
||||||
set(CLI_LINK_LIBRARIES ${CLI_LINK_LIBRARIES} m)
|
set(CLI_LINK_LIBRARIES ${CLI_LINK_LIBRARIES} m)
|
||||||
endif()
|
endif(NOT MSVC)
|
||||||
|
|
||||||
if(ENABLE_LIBTECLA)
|
if(ENABLE_LIBTECLA)
|
||||||
set(CLI_LINK_LIBRARIES ${CLI_LINK_LIBRARIES} ${LIBTECLA_LIBRARIES})
|
set(CLI_LINK_LIBRARIES ${CLI_LINK_LIBRARIES} ${LIBTECLA_LIBRARIES})
|
||||||
|
|
@ -280,10 +277,6 @@ elseif(ENABLE_LIBEDIT)
|
||||||
set(CLI_LINK_LIBRARIES ${CLI_LINK_LIBRARIES} ${LIBEDIT_LIBRARIES})
|
set(CLI_LINK_LIBRARIES ${CLI_LINK_LIBRARIES} ${LIBEDIT_LIBRARIES})
|
||||||
endif(ENABLE_LIBTECLA)
|
endif(ENABLE_LIBTECLA)
|
||||||
|
|
||||||
if(LIBPTHREADSWIN32_FOUND)
|
|
||||||
set(CLI_LINK_LIBRARIES ${CLI_LINK_LIBRARIES} ${LIBPTHREADSWIN32_LIBRARIES})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(LIBC_VERSION)
|
if(LIBC_VERSION)
|
||||||
# clock_gettime() was moved from librt -> libc in 2.17
|
# clock_gettime() was moved from librt -> libc in 2.17
|
||||||
if(${LIBC_VERSION} VERSION_LESS "2.17")
|
if(${LIBC_VERSION} VERSION_LESS "2.17")
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <pthread.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@
|
||||||
*/
|
*/
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <pthread.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
@ -36,6 +35,7 @@
|
||||||
#include "parse.h"
|
#include "parse.h"
|
||||||
#include "rel_assert.h"
|
#include "rel_assert.h"
|
||||||
#include "rxtx_impl.h"
|
#include "rxtx_impl.h"
|
||||||
|
#include "thread.h"
|
||||||
#include "doc/cmd_help.h"
|
#include "doc/cmd_help.h"
|
||||||
|
|
||||||
int gen_write_fmt_sample(FILE *fp, enum rxtx_fmt fmt, int16_t s_i, int16_t s_q) {
|
int gen_write_fmt_sample(FILE *fp, enum rxtx_fmt fmt, int16_t s_i, int16_t s_q) {
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <pthread.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <pthread.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "host_config.h"
|
#include "host_config.h"
|
||||||
|
|
@ -112,7 +111,7 @@ void rxtx_set_state(struct rxtx_data *rxtx, enum rxtx_state state)
|
||||||
{
|
{
|
||||||
MUTEX_LOCK(&rxtx->task_mgmt.lock);
|
MUTEX_LOCK(&rxtx->task_mgmt.lock);
|
||||||
rxtx->task_mgmt.state = state;
|
rxtx->task_mgmt.state = state;
|
||||||
pthread_cond_signal(&rxtx->task_mgmt.signal_state_change);
|
COND_SIGNAL(&rxtx->task_mgmt.signal_state_change);
|
||||||
MUTEX_UNLOCK(&rxtx->task_mgmt.lock);
|
MUTEX_UNLOCK(&rxtx->task_mgmt.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -158,7 +157,7 @@ void rxtx_submit_request(struct rxtx_data *rxtx, unsigned char req)
|
||||||
{
|
{
|
||||||
MUTEX_LOCK(&rxtx->task_mgmt.lock);
|
MUTEX_LOCK(&rxtx->task_mgmt.lock);
|
||||||
rxtx->task_mgmt.req |= req;
|
rxtx->task_mgmt.req |= req;
|
||||||
pthread_cond_signal(&rxtx->task_mgmt.signal_req);
|
COND_SIGNAL(&rxtx->task_mgmt.signal_req);
|
||||||
MUTEX_UNLOCK(&rxtx->task_mgmt.lock);
|
MUTEX_UNLOCK(&rxtx->task_mgmt.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -415,9 +414,9 @@ struct rxtx_data *rxtx_data_alloc(bladerf_direction dir)
|
||||||
ret->task_mgmt.state = RXTX_STATE_IDLE;
|
ret->task_mgmt.state = RXTX_STATE_IDLE;
|
||||||
ret->task_mgmt.req = 0;
|
ret->task_mgmt.req = 0;
|
||||||
MUTEX_INIT(&ret->task_mgmt.lock);
|
MUTEX_INIT(&ret->task_mgmt.lock);
|
||||||
pthread_cond_init(&ret->task_mgmt.signal_req, NULL);
|
COND_INIT(&ret->task_mgmt.signal_req);
|
||||||
pthread_cond_init(&ret->task_mgmt.signal_done, NULL);
|
COND_INIT(&ret->task_mgmt.signal_done);
|
||||||
pthread_cond_init(&ret->task_mgmt.signal_state_change, NULL);
|
COND_INIT(&ret->task_mgmt.signal_state_change);
|
||||||
ret->task_mgmt.main_task_waiting = false;
|
ret->task_mgmt.main_task_waiting = false;
|
||||||
|
|
||||||
/* Initialize error management */
|
/* Initialize error management */
|
||||||
|
|
@ -434,9 +433,9 @@ int rxtx_startup(struct cli_state *s, bladerf_direction dir)
|
||||||
|
|
||||||
if (rxtx_is_tx(dir)) {
|
if (rxtx_is_tx(dir)) {
|
||||||
rxtx_set_state(s->tx, RXTX_STATE_INIT);
|
rxtx_set_state(s->tx, RXTX_STATE_INIT);
|
||||||
status = pthread_create(&s->tx->task_mgmt.thread, NULL, tx_task, s);
|
status = THREAD_CREATE(&s->tx->task_mgmt.thread, tx_task, s);
|
||||||
|
|
||||||
if (status < 0) {
|
if (status != THREAD_SUCCESS) {
|
||||||
rxtx_set_state(s->tx, RXTX_STATE_FAIL);
|
rxtx_set_state(s->tx, RXTX_STATE_FAIL);
|
||||||
} else {
|
} else {
|
||||||
status = rxtx_wait_for_state(s->tx, RXTX_STATE_IDLE, 0);
|
status = rxtx_wait_for_state(s->tx, RXTX_STATE_IDLE, 0);
|
||||||
|
|
@ -446,9 +445,8 @@ int rxtx_startup(struct cli_state *s, bladerf_direction dir)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rxtx_set_state(s->rx, RXTX_STATE_INIT);
|
rxtx_set_state(s->rx, RXTX_STATE_INIT);
|
||||||
status = pthread_create(&s->rx->task_mgmt.thread, NULL, rx_task, s);
|
status = THREAD_CREATE(&s->rx->task_mgmt.thread, rx_task, s);
|
||||||
|
if (status != THREAD_SUCCESS) {
|
||||||
if (status < 0) {
|
|
||||||
rxtx_set_state(s->rx, RXTX_STATE_FAIL);
|
rxtx_set_state(s->rx, RXTX_STATE_FAIL);
|
||||||
} else {
|
} else {
|
||||||
status = rxtx_wait_for_state(s->rx, RXTX_STATE_IDLE, 0);
|
status = rxtx_wait_for_state(s->rx, RXTX_STATE_IDLE, 0);
|
||||||
|
|
@ -478,7 +476,7 @@ void rxtx_shutdown(struct cli_state *s, struct rxtx_data *rxtx)
|
||||||
|
|
||||||
if (rxtx->task_mgmt.started && rxtx_get_state(rxtx) != RXTX_STATE_FAIL) {
|
if (rxtx->task_mgmt.started && rxtx_get_state(rxtx) != RXTX_STATE_FAIL) {
|
||||||
rxtx_submit_request(rxtx, RXTX_TASK_REQ_SHUTDOWN);
|
rxtx_submit_request(rxtx, RXTX_TASK_REQ_SHUTDOWN);
|
||||||
pthread_join(rxtx->task_mgmt.thread, NULL);
|
THREAD_JOIN(rxtx->task_mgmt.thread, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(rxtx->file_mgmt.path);
|
free(rxtx->file_mgmt.path);
|
||||||
|
|
@ -741,7 +739,7 @@ void rxtx_task_exec_idle(struct rxtx_data *rxtx, unsigned char *requests)
|
||||||
/* Wait until we're asked to start or shutdown */
|
/* Wait until we're asked to start or shutdown */
|
||||||
while (!(*requests & (RXTX_TASK_REQ_START | RXTX_TASK_REQ_SHUTDOWN))) {
|
while (!(*requests & (RXTX_TASK_REQ_START | RXTX_TASK_REQ_SHUTDOWN))) {
|
||||||
MUTEX_LOCK(&rxtx->task_mgmt.lock);
|
MUTEX_LOCK(&rxtx->task_mgmt.lock);
|
||||||
pthread_cond_wait(&rxtx->task_mgmt.signal_req, &rxtx->task_mgmt.lock);
|
COND_WAIT(&rxtx->task_mgmt.signal_req, &rxtx->task_mgmt.lock);
|
||||||
*requests = rxtx->task_mgmt.req;
|
*requests = rxtx->task_mgmt.req;
|
||||||
MUTEX_UNLOCK(&rxtx->task_mgmt.lock);
|
MUTEX_UNLOCK(&rxtx->task_mgmt.lock);
|
||||||
}
|
}
|
||||||
|
|
@ -791,7 +789,6 @@ int rxtx_handle_wait(struct cli_state *s,
|
||||||
int status = CLI_RET_UNKNOWN;
|
int status = CLI_RET_UNKNOWN;
|
||||||
bool ok;
|
bool ok;
|
||||||
unsigned int timeout_ms = 0;
|
unsigned int timeout_ms = 0;
|
||||||
struct timespec timeout_abs;
|
|
||||||
enum rxtx_state state;
|
enum rxtx_state state;
|
||||||
|
|
||||||
static const struct numeric_suffix times[] = {
|
static const struct numeric_suffix times[] = {
|
||||||
|
|
@ -825,29 +822,13 @@ int rxtx_handle_wait(struct cli_state *s,
|
||||||
MUTEX_UNLOCK(&s->dev_lock);
|
MUTEX_UNLOCK(&s->dev_lock);
|
||||||
|
|
||||||
if (timeout_ms != 0) {
|
if (timeout_ms != 0) {
|
||||||
const unsigned int timeout_sec = timeout_ms / 1000;
|
|
||||||
|
|
||||||
status = clock_gettime(CLOCK_REALTIME, &timeout_abs);
|
|
||||||
if (status != 0) {
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
timeout_abs.tv_sec += timeout_sec;
|
|
||||||
timeout_abs.tv_nsec += (timeout_ms % 1000) * 1000 * 1000;
|
|
||||||
|
|
||||||
if (timeout_abs.tv_nsec >= NSEC_PER_SEC) {
|
|
||||||
timeout_abs.tv_sec += timeout_abs.tv_nsec / NSEC_PER_SEC;
|
|
||||||
timeout_abs.tv_nsec %= NSEC_PER_SEC;
|
|
||||||
}
|
|
||||||
|
|
||||||
MUTEX_LOCK(&rxtx->task_mgmt.lock);
|
MUTEX_LOCK(&rxtx->task_mgmt.lock);
|
||||||
rxtx->task_mgmt.main_task_waiting = true;
|
rxtx->task_mgmt.main_task_waiting = true;
|
||||||
while (rxtx->task_mgmt.main_task_waiting) {
|
while (rxtx->task_mgmt.main_task_waiting) {
|
||||||
status =
|
status = COND_TIMED_WAIT(&rxtx->task_mgmt.signal_done,
|
||||||
pthread_cond_timedwait(&rxtx->task_mgmt.signal_done,
|
&rxtx->task_mgmt.lock, timeout_ms);
|
||||||
&rxtx->task_mgmt.lock, &timeout_abs);
|
|
||||||
|
|
||||||
if (status == ETIMEDOUT) {
|
if (status == THREAD_TIMEOUT) {
|
||||||
rxtx->task_mgmt.main_task_waiting = false;
|
rxtx->task_mgmt.main_task_waiting = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -857,19 +838,18 @@ int rxtx_handle_wait(struct cli_state *s,
|
||||||
MUTEX_LOCK(&rxtx->task_mgmt.lock);
|
MUTEX_LOCK(&rxtx->task_mgmt.lock);
|
||||||
rxtx->task_mgmt.main_task_waiting = true;
|
rxtx->task_mgmt.main_task_waiting = true;
|
||||||
while (rxtx->task_mgmt.main_task_waiting) {
|
while (rxtx->task_mgmt.main_task_waiting) {
|
||||||
status = pthread_cond_wait(&rxtx->task_mgmt.signal_done,
|
status = COND_WAIT(&rxtx->task_mgmt.signal_done,
|
||||||
&rxtx->task_mgmt.lock);
|
&rxtx->task_mgmt.lock);
|
||||||
}
|
}
|
||||||
MUTEX_UNLOCK(&rxtx->task_mgmt.lock);
|
MUTEX_UNLOCK(&rxtx->task_mgmt.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
|
||||||
/* Re-acquire the device control lock, as the top-level command handler
|
/* Re-acquire the device control lock, as the top-level command handler
|
||||||
* will be unlocking this when it's done */
|
* will be unlocking this when it's done */
|
||||||
MUTEX_LOCK(&s->dev_lock);
|
MUTEX_LOCK(&s->dev_lock);
|
||||||
|
|
||||||
/* Expected and OK condition */
|
/* Expected and OK condition */
|
||||||
if (status == ETIMEDOUT) {
|
if (status == THREAD_TIMEOUT) {
|
||||||
status = 0;
|
status = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -887,7 +867,7 @@ bool rxtx_release_wait(struct rxtx_data *rxtx)
|
||||||
MUTEX_LOCK(&rxtx->task_mgmt.lock);
|
MUTEX_LOCK(&rxtx->task_mgmt.lock);
|
||||||
was_waiting = rxtx->task_mgmt.main_task_waiting;
|
was_waiting = rxtx->task_mgmt.main_task_waiting;
|
||||||
rxtx->task_mgmt.main_task_waiting = false;
|
rxtx->task_mgmt.main_task_waiting = false;
|
||||||
pthread_cond_signal(&rxtx->task_mgmt.signal_done);
|
COND_SIGNAL(&rxtx->task_mgmt.signal_done);
|
||||||
MUTEX_UNLOCK(&rxtx->task_mgmt.lock);
|
MUTEX_UNLOCK(&rxtx->task_mgmt.lock);
|
||||||
|
|
||||||
return was_waiting;
|
return was_waiting;
|
||||||
|
|
@ -898,36 +878,19 @@ int rxtx_wait_for_state(struct rxtx_data *rxtx,
|
||||||
unsigned int timeout_ms)
|
unsigned int timeout_ms)
|
||||||
{
|
{
|
||||||
int status = 0;
|
int status = 0;
|
||||||
struct timespec timeout_abs;
|
|
||||||
|
|
||||||
if (timeout_ms != 0) {
|
if (timeout_ms != 0) {
|
||||||
const unsigned int timeout_sec = timeout_ms / 1000;
|
|
||||||
|
|
||||||
status = clock_gettime(CLOCK_REALTIME, &timeout_abs);
|
|
||||||
if (status != 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
timeout_abs.tv_sec += timeout_sec;
|
|
||||||
timeout_abs.tv_nsec += (timeout_ms % 1000) * 1000 * 1000;
|
|
||||||
|
|
||||||
if (timeout_abs.tv_nsec >= NSEC_PER_SEC) {
|
|
||||||
timeout_abs.tv_sec += timeout_abs.tv_nsec / NSEC_PER_SEC;
|
|
||||||
timeout_abs.tv_nsec %= NSEC_PER_SEC;
|
|
||||||
}
|
|
||||||
|
|
||||||
MUTEX_LOCK(&rxtx->task_mgmt.lock);
|
MUTEX_LOCK(&rxtx->task_mgmt.lock);
|
||||||
while (rxtx->task_mgmt.state != req_state && status == 0) {
|
while (rxtx->task_mgmt.state != req_state && status == THREAD_SUCCESS) {
|
||||||
status =
|
status = COND_TIMED_WAIT(&rxtx->task_mgmt.signal_state_change,
|
||||||
pthread_cond_timedwait(&rxtx->task_mgmt.signal_state_change,
|
&rxtx->task_mgmt.lock, timeout_ms);
|
||||||
&rxtx->task_mgmt.lock, &timeout_abs);
|
|
||||||
}
|
}
|
||||||
MUTEX_UNLOCK(&rxtx->task_mgmt.lock);
|
MUTEX_UNLOCK(&rxtx->task_mgmt.lock);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
MUTEX_LOCK(&rxtx->task_mgmt.lock);
|
MUTEX_LOCK(&rxtx->task_mgmt.lock);
|
||||||
while (rxtx->task_mgmt.state != req_state) {
|
while (rxtx->task_mgmt.state != req_state) {
|
||||||
status = pthread_cond_wait(&rxtx->task_mgmt.signal_state_change,
|
status = COND_WAIT(&rxtx->task_mgmt.signal_state_change,
|
||||||
&rxtx->task_mgmt.lock);
|
&rxtx->task_mgmt.lock);
|
||||||
}
|
}
|
||||||
MUTEX_UNLOCK(&rxtx->task_mgmt.lock);
|
MUTEX_UNLOCK(&rxtx->task_mgmt.lock);
|
||||||
|
|
|
||||||
|
|
@ -102,16 +102,16 @@ struct file_mgmt {
|
||||||
|
|
||||||
/* Task and thread management */
|
/* Task and thread management */
|
||||||
struct task_mgmt {
|
struct task_mgmt {
|
||||||
pthread_t thread; /* Handle to thread in which the task runs */
|
THREAD thread; /* Handle to thread in which the task runs */
|
||||||
bool started; /* Has the thread been started? */
|
bool started; /* Has the thread been started? */
|
||||||
|
|
||||||
enum rxtx_state state; /* Task state */
|
enum rxtx_state state; /* Task state */
|
||||||
uint8_t req; /* Requests for state change. See
|
uint8_t req; /* Requests for state change. See
|
||||||
* RXTX_TASK_REQ_* bitmasks */
|
* RXTX_TASK_REQ_* bitmasks */
|
||||||
MUTEX lock; /* Must be held to access 'req' or 'state' */
|
MUTEX lock; /* Must be held to access 'req' or 'state' */
|
||||||
pthread_cond_t signal_req; /* Signal when a request has been made */
|
COND signal_req; /* Signal when a request has been made */
|
||||||
pthread_cond_t signal_done; /* Signal when task finishes work */
|
COND signal_done; /* Signal when task finishes work */
|
||||||
pthread_cond_t signal_state_change; /* Signal after state change */
|
COND signal_state_change; /* Signal after state change */
|
||||||
bool main_task_waiting; /* Main task is blocked waiting */
|
bool main_task_waiting; /* Main task is blocked waiting */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@
|
||||||
*/
|
*/
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <pthread.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
@ -31,6 +30,7 @@
|
||||||
#include "minmax.h"
|
#include "minmax.h"
|
||||||
#include "parse.h"
|
#include "parse.h"
|
||||||
#include "rel_assert.h"
|
#include "rel_assert.h"
|
||||||
|
#include "thread.h"
|
||||||
#include "rxtx_impl.h"
|
#include "rxtx_impl.h"
|
||||||
|
|
||||||
/* The DAC range is [-2048, 2047] */
|
/* The DAC range is [-2048, 2047] */
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@
|
||||||
*/
|
*/
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <pthread.h>
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
@ -31,6 +30,7 @@
|
||||||
#include "cmd/rxtx.h"
|
#include "cmd/rxtx.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "script.h"
|
#include "script.h"
|
||||||
|
#include "thread.h"
|
||||||
|
|
||||||
/* There's currently only ever 1 active cli_state */
|
/* There's currently only ever 1 active cli_state */
|
||||||
static struct cli_state *cli_state;
|
static struct cli_state *cli_state;
|
||||||
|
|
@ -105,7 +105,7 @@ struct cli_state *cli_state_create()
|
||||||
cli_state->dev_info.is_bladerf_x40_x115 = false;
|
cli_state->dev_info.is_bladerf_x40_x115 = false;
|
||||||
cli_state->dev_info.is_bladerf_micro = false;
|
cli_state->dev_info.is_bladerf_micro = false;
|
||||||
|
|
||||||
pthread_mutex_init(&cli_state->dev_lock, NULL);
|
MUTEX_INIT(&cli_state->dev_lock);
|
||||||
|
|
||||||
cli_state->rx = rxtx_data_alloc(BLADERF_RX);
|
cli_state->rx = rxtx_data_alloc(BLADERF_RX);
|
||||||
if (!cli_state->rx) {
|
if (!cli_state->rx) {
|
||||||
|
|
@ -305,25 +305,25 @@ const char *cli_strerror(int error, int lib_error)
|
||||||
|
|
||||||
void cli_error_init(struct cli_error *e)
|
void cli_error_init(struct cli_error *e)
|
||||||
{
|
{
|
||||||
pthread_mutex_init(&e->lock, NULL);
|
MUTEX_INIT(&e->lock);
|
||||||
e->type = ETYPE_CLI;
|
e->type = ETYPE_CLI;
|
||||||
e->value = 0;
|
e->value = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_last_error(struct cli_error *e, enum error_type type, int error)
|
void set_last_error(struct cli_error *e, enum error_type type, int error)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&e->lock);
|
MUTEX_LOCK(&e->lock);
|
||||||
e->type = type;
|
e->type = type;
|
||||||
e->value = error;
|
e->value = error;
|
||||||
pthread_mutex_unlock(&e->lock);
|
MUTEX_UNLOCK(&e->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_last_error(struct cli_error *e, enum error_type *type, int *error)
|
void get_last_error(struct cli_error *e, enum error_type *type, int *error)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&e->lock);
|
MUTEX_LOCK(&e->lock);
|
||||||
*type = e->type;
|
*type = e->type;
|
||||||
*error = e->value;
|
*error = e->value;
|
||||||
pthread_mutex_unlock(&e->lock);
|
MUTEX_UNLOCK(&e->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
int expand_and_open(const char *filename, const char *mode, FILE **file)
|
int expand_and_open(const char *filename, const char *mode, FILE **file)
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@
|
||||||
#include "host_config.h"
|
#include "host_config.h"
|
||||||
#include "str_queue.h"
|
#include "str_queue.h"
|
||||||
#include <libbladeRF.h>
|
#include <libbladeRF.h>
|
||||||
#include <pthread.h>
|
#include "thread.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
@ -88,7 +88,7 @@ enum error_type {
|
||||||
struct cli_error {
|
struct cli_error {
|
||||||
int value; /**< Last command error */
|
int value; /**< Last command error */
|
||||||
enum error_type type; /**< Type/source of last error */
|
enum error_type type; /**< Type/source of last error */
|
||||||
pthread_mutex_t lock;
|
MUTEX lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -106,7 +106,7 @@ struct cli_dev_info {
|
||||||
struct cli_state {
|
struct cli_state {
|
||||||
struct bladerf *dev; /**< Device currently in use */
|
struct bladerf *dev; /**< Device currently in use */
|
||||||
struct cli_dev_info dev_info; /**< Cached device information */
|
struct cli_dev_info dev_info; /**< Cached device information */
|
||||||
pthread_mutex_t dev_lock; /**< Should be held when performing
|
MUTEX dev_lock; /**< Should be held when performing
|
||||||
* any "device conrol" calls */
|
* any "device conrol" calls */
|
||||||
|
|
||||||
int last_lib_error; /**< Last libbladeRF error */
|
int last_lib_error; /**< Last libbladeRF error */
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <pthread.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <libbladeRF.h>
|
#include <libbladeRF.h>
|
||||||
#include "input/input.h"
|
#include "input/input.h"
|
||||||
|
|
@ -32,6 +31,7 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "cmd.h"
|
#include "cmd.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
#include "thread.h"
|
||||||
|
|
||||||
#if BLADERF_OS_WINDOWS
|
#if BLADERF_OS_WINDOWS
|
||||||
#include "setenv.h"
|
#include "setenv.h"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue