libbladeRF & bladeRF-CLI: Fixed build issues. Moved backend config info.
From henceforth, all backend selection should live in the backend_config.h.in file, so backend.c or backend.h doesn't get muddied with #ifdef's.
This commit is contained in:
parent
38a921e13b
commit
df05b174ec
38 changed files with 355 additions and 383 deletions
|
|
@ -1,4 +1,4 @@
|
|||
# Copyright 2012 Nuand, LLC.
|
||||
# Copyright 2013 Nuand, LLC.
|
||||
#
|
||||
# This file is part of the bladeRF project
|
||||
#
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
# This file has been borrowed from the gr-osmosdr project (GPLv3)
|
||||
# Author: Dimitri Stolnikov
|
||||
#
|
||||
# http://openbsc.osmocom.org/trac/wiki/OsmocomOverview
|
||||
# http://git.osmocom.org/gr-osmosdr/log/cmake/Modules/FindLibbladeRF.cmake
|
||||
#
|
||||
if(NOT LIBBLADERF_FOUND)
|
||||
pkg_check_modules (LIBBLADERF_PKG libbladeRF)
|
||||
find_path(LIBBLADERF_INCLUDE_DIR NAMES libbladeRF.h
|
||||
PATHS
|
||||
${LIBBLADERF_PKG_INCLUDE_DIRS}
|
||||
/usr/include
|
||||
/usr/local/include
|
||||
)
|
||||
|
||||
find_library(LIBBLADERF_LIBRARIES NAMES bladeRF
|
||||
PATHS
|
||||
${LIBBLADERF_PKG_LIBRARY_DIRS}
|
||||
/usr/lib
|
||||
/usr/local/lib
|
||||
)
|
||||
|
||||
if(LIBBLADERF_INCLUDE_DIR AND LIBBLADERF_LIBRARIES)
|
||||
set(LIBBLADERF_FOUND TRUE CACHE INTERNAL "libbladeRF found")
|
||||
message(STATUS "Found libbladeRF: ${LIBBLADERF_INCLUDE_DIR}, ${LIBBLADERF_LIBRARIES}")
|
||||
else(LIBBLADERF_INCLUDE_DIR AND LIBBLADERF_LIBRARIES)
|
||||
set(LIBBLADERF_FOUND FALSE CACHE INTERNAL "libbladeRF found")
|
||||
message(STATUS "libbladeRF not found.")
|
||||
endif(LIBBLADERF_INCLUDE_DIR AND LIBBLADERF_LIBRARIES)
|
||||
|
||||
mark_as_advanced(LIBBLADERF_INCLUDE_DIR LIBBLADERF_LIBRARIES)
|
||||
|
||||
endif(NOT LIBBLADERF_FOUND)
|
||||
|
||||
|
|
@ -1,214 +1,2 @@
|
|||
# Copyright 2012 Nuand, LLC.
|
||||
#
|
||||
# This file is part of the bladeRF project
|
||||
#
|
||||
# TODO license text here (see top-level COPYING for time being)
|
||||
#
|
||||
# Portions of this file have been borrowed from and/or inspired by
|
||||
# the CMakeLists.txt from the rtl-sdr project (GPLv2)
|
||||
# http://sdr.osmocom.org/trac/wiki/rtl-sdr
|
||||
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
project(libbladeRF C)
|
||||
|
||||
################################################################################
|
||||
# Version information
|
||||
################################################################################
|
||||
|
||||
set(VERSION_INFO_MAJOR 0)
|
||||
set(VERSION_INFO_MINOR 3)
|
||||
set(VERSION_INFO_PATCH 0)
|
||||
set(VERSION_INFO_EXTRA "git")
|
||||
include(Version)
|
||||
|
||||
set(VERSION "${VERSION_INFO}")
|
||||
set(LIBVER "${VERSION_INFO_BASE}")
|
||||
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/src/version.h
|
||||
@ONLY
|
||||
)
|
||||
|
||||
################################################################################
|
||||
# Configuration options
|
||||
################################################################################
|
||||
|
||||
##############################
|
||||
# Backend Support
|
||||
##############################
|
||||
|
||||
option(BACKEND_LIBUSB
|
||||
"Enable libusb backend support"
|
||||
ON
|
||||
)
|
||||
|
||||
option(LIBUSB_DETACH_KERNEL_DRIVER
|
||||
"Enable calls to libusb_detach_kernel_driver(). Not supported in Windows."
|
||||
ON
|
||||
)
|
||||
|
||||
option(BACKEND_LINUX_DRIVER
|
||||
"Enable Linux driver backend support."
|
||||
OFF
|
||||
)
|
||||
|
||||
# Ensure we've got at least one backend enabled
|
||||
if(NOT BACKEND_LIBUSB AND NOT BACKEND_LINUX_DRIVER)
|
||||
message(FATAL_ERROR
|
||||
"No libbladeRF backends are enabled. "
|
||||
"Please enable one or more backends." )
|
||||
endif()
|
||||
|
||||
|
||||
# Detach kernel not supported in Windows
|
||||
if(CMAKE_HOST_WIN32)
|
||||
set(LIBUSB_DETACH_KERNEL_DRIVER OFF)
|
||||
endif()
|
||||
|
||||
################################################################################
|
||||
# Additional compiler options
|
||||
################################################################################
|
||||
if("${CMAKE_CC_COMPILER_ID}" STREQUAL "GNU" OR
|
||||
"${CMAKE_CC_COMPILER_ID}" STREQUAL "Clang" )
|
||||
# ADD_DEFINITIONS(-fvisibility=hidden)
|
||||
endif()
|
||||
|
||||
################################################################################
|
||||
# Include paths
|
||||
################################################################################
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
${BLADERF_COMMON_INCLUDE_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}/src
|
||||
${LIBUSB_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
################################################################################
|
||||
# Build dependencies
|
||||
################################################################################
|
||||
find_package(PkgConfig)
|
||||
|
||||
if(BACKEND_LIBUSB)
|
||||
find_package(LibUSB)
|
||||
if(NOT LIBUSB_FOUND)
|
||||
message(FATAL_ERROR "libusb-1.0 required to use for libusb backend")
|
||||
endif(NOT LIBUSB_FOUND)
|
||||
|
||||
# TODO stricter LibUSB version check? IIRC we actually require >= 1.0.10?
|
||||
endif(BACKEND_LIBUSB)
|
||||
|
||||
if(BACKEND_LINUX_DRIVER)
|
||||
# TODO find Linux Driver?
|
||||
endif()
|
||||
|
||||
################################################################################
|
||||
# Configure source files
|
||||
################################################################################
|
||||
set(LIBBLADERF_SOURCE
|
||||
src/backend.c
|
||||
src/bladerf.c
|
||||
src/bladerf_priv.c
|
||||
src/conversions.c
|
||||
src/device_identifier.c
|
||||
src/file_ops.c
|
||||
src/lms.c
|
||||
src/si5338.c
|
||||
src/version.h
|
||||
)
|
||||
|
||||
if(BACKEND_LIBUSB)
|
||||
set(LIBBLADERF_SOURCE ${LIBBLADERF_SOURCE} src/backend/libusb.c)
|
||||
endif()
|
||||
|
||||
if(BACKEND_LINUX_DRIVER)
|
||||
set(LIBBLADERF_SOURCE ${LIBBLADERF_SOURCE} src/linux.c)
|
||||
endif()
|
||||
|
||||
add_library(libbladerf_shared SHARED ${LIBBLADERF_SOURCE})
|
||||
|
||||
################################################################################
|
||||
# Build configuration
|
||||
################################################################################
|
||||
|
||||
if(BACKEND_LIBUSB)
|
||||
target_link_libraries(libbladerf_shared ${LIBUSB_LIBRARIES})
|
||||
endif()
|
||||
|
||||
# Adjust our output name
|
||||
set_target_properties(libbladerf_shared PROPERTIES OUTPUT_NAME bladeRF)
|
||||
|
||||
# Set shared library version
|
||||
set_target_properties(libbladerf_shared PROPERTIES SOVERSION ${VERSION_INFO_MAJOR})
|
||||
|
||||
|
||||
################################################################################
|
||||
# Misc. installation config
|
||||
################################################################################
|
||||
|
||||
if(NOT DEFINED LIB_INSTALL_DIR)
|
||||
set(LIB_INSTALL_DIR lib)
|
||||
endif()
|
||||
|
||||
################################################################################
|
||||
# Install udev rules
|
||||
################################################################################
|
||||
# TODO
|
||||
|
||||
################################################################################
|
||||
# Generate pkg-config file
|
||||
################################################################################
|
||||
add_subdirectory(include)
|
||||
foreach(inc ${LIBBLADERF_INCLUDE_DIR})
|
||||
list(APPEND LIBBLADERF_PC_CFLAGS "-I${inc}")
|
||||
endforeach()
|
||||
|
||||
foreach(lib ${LIBBLADERF_LIBRARY_DIRS})
|
||||
list(APPEND LIBBLADERF_PC_PRIV_LIBS "-L${lib}")
|
||||
endforeach()
|
||||
|
||||
if(BACKEND_LIBUSB)
|
||||
# TODO set(LIBBLADERF_PC_REQUIRES ${LIBBLADERF_PC_REQUIRES} libusb-1.0 = ?)
|
||||
endif()
|
||||
|
||||
set(LIBBLADERF_PC_PREFIX ${CMAKE_INSTALL_PREFIX})
|
||||
set(LIBBLADERF_PC_EXEC_PREFIX \${prefix})
|
||||
set(LIBBLADERF_PC_LIBDIR \${exec_prefix}/${LIB_INSTALL_DIR})
|
||||
set(LIBBLADERF_PC_INCLUDEDIR \${prefix}/include)
|
||||
set(LIBBLADERF_PC_VERSION ${VERSION})
|
||||
|
||||
# Use space-delimiter in the .pc file, rather than CMake's semicolon separator
|
||||
string(REPLACE ";" " " LIBBLADERF_PC_CFLAGS "${LIBBLADERF_PC_CFLAGS}")
|
||||
string(REPLACE ";" " " LIBBLADERF_PC_LIBS "${LIBBLADERF_PC_LIBS}")
|
||||
|
||||
# Unset these to avoid hard-coded paths in a cross-environment
|
||||
if(CMAKE_CROSSCOMPILING)
|
||||
unset(LIBBLADERF_PC_CFLAGS)
|
||||
unset(LIBBLADERF_PC_LIBS)
|
||||
endif()
|
||||
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/libbladeRF.pc.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/libbladeRF.pc
|
||||
@ONLY
|
||||
)
|
||||
|
||||
install(
|
||||
FILES ${CMAKE_CURRENT_BINARY_DIR}/libbladeRF.pc
|
||||
DESTINATION ${LIB_INSTALL_DIR}/pkgconfig/
|
||||
)
|
||||
|
||||
################################################################################
|
||||
# Library installation information
|
||||
################################################################################
|
||||
install(TARGETS libbladerf_shared
|
||||
LIBRARY DESTINATION ${LIB_INSTALL_DIR} # .so/.dylib
|
||||
ARCHIVE DESTINATION ${LIB_INSTALL_DIR} # .a/.lib
|
||||
RUNTIME DESTINATION bin # .dll
|
||||
)
|
||||
|
||||
|
||||
################################################################################
|
||||
# Informational output
|
||||
################################################################################
|
||||
message(STATUS "libbladeRF version: ${VERSION_INFO}")
|
||||
add_subdirectory(libbladeRF)
|
||||
|
|
|
|||
220
host/libraries/libbladeRF/CMakeLists.txt
Normal file
220
host/libraries/libbladeRF/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,220 @@
|
|||
# Copyright 2012 Nuand, LLC.
|
||||
#
|
||||
# This file is part of the bladeRF project
|
||||
#
|
||||
# TODO license text here (see top-level COPYING for time being)
|
||||
#
|
||||
# Portions of this file have been borrowed from and/or inspired by
|
||||
# the CMakeLists.txt from the rtl-sdr project (GPLv2)
|
||||
# http://sdr.osmocom.org/trac/wiki/rtl-sdr
|
||||
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
project(libbladeRF C)
|
||||
|
||||
################################################################################
|
||||
# Version information
|
||||
################################################################################
|
||||
|
||||
set(VERSION_INFO_MAJOR 0)
|
||||
set(VERSION_INFO_MINOR 3)
|
||||
set(VERSION_INFO_PATCH 0)
|
||||
set(VERSION_INFO_EXTRA "git")
|
||||
include(Version)
|
||||
|
||||
set(VERSION "${VERSION_INFO}")
|
||||
set(LIBVER "${VERSION_INFO_BASE}")
|
||||
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/src/version.h
|
||||
@ONLY
|
||||
)
|
||||
|
||||
################################################################################
|
||||
# Configuration options
|
||||
################################################################################
|
||||
|
||||
##############################
|
||||
# Backend Support
|
||||
##############################
|
||||
|
||||
option(ENABLE_BACKEND_LIBUSB
|
||||
"Enable libusb backend support"
|
||||
ON
|
||||
)
|
||||
|
||||
option(LIBUSB_DETACH_KERNEL_DRIVER
|
||||
"Enable calls to libusb_detach_kernel_driver(). Not supported in Windows."
|
||||
ON
|
||||
)
|
||||
|
||||
option(ENABLE_BACKEND_LINUX_DRIVER
|
||||
"Enable Linux driver backend support."
|
||||
OFF
|
||||
)
|
||||
|
||||
# Ensure we've got at least one backend enabled
|
||||
if(NOT ENABLE_BACKEND_LIBUSB AND NOT ENABLE_BACKEND_LINUX_DRIVER)
|
||||
message(FATAL_ERROR
|
||||
"No libbladeRF backends are enabled. "
|
||||
"Please enable one or more backends." )
|
||||
endif()
|
||||
|
||||
|
||||
# Detach kernel not supported in Windows
|
||||
if(CMAKE_HOST_WIN32)
|
||||
set(LIBUSB_DETACH_KERNEL_DRIVER OFF)
|
||||
endif()
|
||||
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/backend_config.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/src/backend_config.h
|
||||
@ONLY
|
||||
)
|
||||
|
||||
################################################################################
|
||||
# Additional compiler options
|
||||
################################################################################
|
||||
if("${CMAKE_CC_COMPILER_ID}" STREQUAL "GNU" OR
|
||||
"${CMAKE_CC_COMPILER_ID}" STREQUAL "Clang" )
|
||||
# add_definitions(-fvisibility=hidden)
|
||||
endif()
|
||||
|
||||
################################################################################
|
||||
# Include paths
|
||||
################################################################################
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
${BLADERF_COMMON_INCLUDE_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}/src
|
||||
${LIBUSB_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
################################################################################
|
||||
# Build dependencies
|
||||
################################################################################
|
||||
find_package(PkgConfig)
|
||||
|
||||
if(ENABLE_BACKEND_LIBUSB)
|
||||
find_package(LibUSB)
|
||||
if(NOT LIBUSB_FOUND)
|
||||
message(FATAL_ERROR "libusb-1.0 required to use for libusb backend")
|
||||
endif(NOT LIBUSB_FOUND)
|
||||
|
||||
# TODO stricter LibUSB version check? IIRC we actually require >= 1.0.10?
|
||||
endif(ENABLE_BACKEND_LIBUSB)
|
||||
|
||||
if(ENABLE_BACKEND_LINUX_DRIVER)
|
||||
# TODO find Linux Driver?
|
||||
endif()
|
||||
|
||||
################################################################################
|
||||
# Configure source files
|
||||
################################################################################
|
||||
set(LIBBLADERF_SOURCE
|
||||
src/backend.c
|
||||
src/bladerf.c
|
||||
src/bladerf_priv.c
|
||||
src/conversions.c
|
||||
src/device_identifier.c
|
||||
src/file_ops.c
|
||||
src/lms.c
|
||||
src/si5338.c
|
||||
src/version.h
|
||||
)
|
||||
|
||||
if(ENABLE_BACKEND_LIBUSB)
|
||||
set(LIBBLADERF_SOURCE ${LIBBLADERF_SOURCE} src/backend/libusb.c)
|
||||
endif()
|
||||
|
||||
if(ENABLE_BACKEND_LINUX_DRIVER)
|
||||
set(LIBBLADERF_SOURCE ${LIBBLADERF_SOURCE} src/linux.c)
|
||||
endif()
|
||||
|
||||
add_library(libbladerf_shared SHARED ${LIBBLADERF_SOURCE})
|
||||
|
||||
################################################################################
|
||||
# Build configuration
|
||||
################################################################################
|
||||
|
||||
if(ENABLE_BACKEND_LIBUSB)
|
||||
target_link_libraries(libbladerf_shared ${LIBUSB_LIBRARIES})
|
||||
endif()
|
||||
|
||||
# Adjust our output name
|
||||
set_target_properties(libbladerf_shared PROPERTIES OUTPUT_NAME bladeRF)
|
||||
|
||||
# Set shared library version
|
||||
set_target_properties(libbladerf_shared PROPERTIES SOVERSION ${VERSION_INFO_MAJOR})
|
||||
|
||||
|
||||
################################################################################
|
||||
# Misc. installation config
|
||||
################################################################################
|
||||
|
||||
if(NOT DEFINED LIB_INSTALL_DIR)
|
||||
set(LIB_INSTALL_DIR lib)
|
||||
endif()
|
||||
|
||||
################################################################################
|
||||
# Install udev rules
|
||||
################################################################################
|
||||
# TODO
|
||||
|
||||
################################################################################
|
||||
# Generate pkg-config file
|
||||
################################################################################
|
||||
add_subdirectory(include)
|
||||
foreach(inc ${LIBBLADERF_INCLUDE_DIR})
|
||||
list(APPEND LIBBLADERF_PC_CFLAGS "-I${inc}")
|
||||
endforeach()
|
||||
|
||||
foreach(lib ${LIBBLADERF_LIBRARY_DIRS})
|
||||
list(APPEND LIBBLADERF_PC_PRIV_LIBS "-L${lib}")
|
||||
endforeach()
|
||||
|
||||
if(ENABLE_BACKEND_LIBUSB)
|
||||
# TODO set(LIBBLADERF_PC_REQUIRES ${LIBBLADERF_PC_REQUIRES} libusb-1.0 = ?)
|
||||
endif()
|
||||
|
||||
set(LIBBLADERF_PC_PREFIX ${CMAKE_INSTALL_PREFIX})
|
||||
set(LIBBLADERF_PC_EXEC_PREFIX \${prefix})
|
||||
set(LIBBLADERF_PC_LIBDIR \${exec_prefix}/${LIB_INSTALL_DIR})
|
||||
set(LIBBLADERF_PC_INCLUDEDIR \${prefix}/include)
|
||||
set(LIBBLADERF_PC_VERSION ${VERSION})
|
||||
|
||||
# Use space-delimiter in the .pc file, rather than CMake's semicolon separator
|
||||
string(REPLACE ";" " " LIBBLADERF_PC_CFLAGS "${LIBBLADERF_PC_CFLAGS}")
|
||||
string(REPLACE ";" " " LIBBLADERF_PC_LIBS "${LIBBLADERF_PC_LIBS}")
|
||||
|
||||
# Unset these to avoid hard-coded paths in a cross-environment
|
||||
if(CMAKE_CROSSCOMPILING)
|
||||
unset(LIBBLADERF_PC_CFLAGS)
|
||||
unset(LIBBLADERF_PC_LIBS)
|
||||
endif()
|
||||
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/libbladeRF.pc.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/libbladeRF.pc
|
||||
@ONLY
|
||||
)
|
||||
|
||||
install(
|
||||
FILES ${CMAKE_CURRENT_BINARY_DIR}/libbladeRF.pc
|
||||
DESTINATION ${LIB_INSTALL_DIR}/pkgconfig/
|
||||
)
|
||||
|
||||
################################################################################
|
||||
# Library installation information
|
||||
################################################################################
|
||||
install(TARGETS libbladerf_shared
|
||||
LIBRARY DESTINATION ${LIB_INSTALL_DIR} # .so/.dylib
|
||||
ARCHIVE DESTINATION ${LIB_INSTALL_DIR} # .a/.lib
|
||||
RUNTIME DESTINATION bin # .dll
|
||||
)
|
||||
|
||||
|
||||
################################################################################
|
||||
# Informational output
|
||||
################################################################################
|
||||
message(STATUS "libbladeRF version: ${VERSION_INFO}")
|
||||
90
host/libraries/libbladeRF/src/backend.c
Normal file
90
host/libraries/libbladeRF/src/backend.c
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
#include <assert.h>
|
||||
|
||||
#include "backend.h"
|
||||
#include "backend_config.h"
|
||||
#include "debug.h"
|
||||
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
|
||||
|
||||
struct backend_table_entry {
|
||||
const bladerf_backend_t type;
|
||||
const struct bladerf_fn *fns;
|
||||
};
|
||||
|
||||
static const struct backend_table_entry backend_list[] = BLADERF_BACKEND_LIST;
|
||||
|
||||
int open_with_any_backend(struct bladerf **device,
|
||||
struct bladerf_devinfo *info)
|
||||
{
|
||||
size_t i;
|
||||
int status = BLADERF_ERR_NODEV;
|
||||
const size_t n_backends = ARRAY_SIZE(backend_list);
|
||||
|
||||
for (i = 0; i < n_backends && status != 0; i++) {
|
||||
status = backend_list[i].fns->open(device, info);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int backend_open(struct bladerf **device, struct bladerf_devinfo *info) {
|
||||
|
||||
size_t i;
|
||||
int status = BLADERF_ERR_NODEV;
|
||||
const size_t n_backends = ARRAY_SIZE(backend_list);
|
||||
|
||||
if (info->backend == BACKEND_ANY) {
|
||||
status = open_with_any_backend(device, info);
|
||||
} else {
|
||||
for (i = 0; i < n_backends; i++) {
|
||||
if (backend_list[i].type == info->backend) {
|
||||
status = backend_list[i].fns->open(device, info);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int backend_probe(struct bladerf_devinfo **devinfo_items, size_t *num_items)
|
||||
{
|
||||
int probe_status, backend_status;
|
||||
struct bladerf_devinfo_list list;
|
||||
size_t i;
|
||||
const size_t n_backends = ARRAY_SIZE(backend_list);
|
||||
|
||||
*devinfo_items = NULL;
|
||||
*num_items = 0;
|
||||
|
||||
probe_status = bladerf_devinfo_list_init(&list);
|
||||
|
||||
if (probe_status == 0) {
|
||||
for (i = 0; i < n_backends && probe_status == 0; i++) {
|
||||
backend_status = backend_list[i].fns->probe(&list);
|
||||
|
||||
/* Error out if a backend hit any concerning error */
|
||||
if (backend_status < 0 && backend_status != BLADERF_ERR_NODEV) {
|
||||
probe_status = backend_status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (probe_status == 0) {
|
||||
*num_items = list.num_elt;
|
||||
|
||||
if (*num_items != 0) {
|
||||
*devinfo_items = list.elt;
|
||||
} else {
|
||||
/* For no items, we end up passing back a NULL list to the
|
||||
* API caller, so we'll just free this up now */
|
||||
free(list.elt);
|
||||
probe_status = BLADERF_ERR_NODEV;
|
||||
}
|
||||
|
||||
} else {
|
||||
free(list.elt);
|
||||
}
|
||||
|
||||
return probe_status;
|
||||
}
|
||||
36
host/libraries/libbladeRF/src/backend_config.h.in
Normal file
36
host/libraries/libbladeRF/src/backend_config.h.in
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#ifndef BLADERF_BACKEND_CONFIG_H__
|
||||
#define BLADERF_BACKEND_CONFIG_H__
|
||||
|
||||
#cmakedefine ENABLE_BACKEND_LIBUSB
|
||||
#cmakedefine ENABLE_BACKEND_LINUX_DRIVER
|
||||
|
||||
#ifdef ENABLE_BACKEND_LIBUSB
|
||||
# include "backend/libusb.h"
|
||||
# define BACKEND_LIBUSB_FN_TBL_ENTRY \
|
||||
{BACKEND_LIBUSB, &bladerf_lusb_fn},
|
||||
#else
|
||||
# define BACKEND_LIBUSB_FN_TBL_ENTRY
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_BACKEND_LINUX_DRIVER
|
||||
# include "backend/linux.h"
|
||||
# define BACKEND_LINUX_DRIVER_FN_TBL_ENTRY \
|
||||
{ BACKEND_LINUX_DRIVER, &bladerf_linux_fn},
|
||||
#else
|
||||
# define BACKEND_LINUX_DRIVER_FN_TBL_ENTRY
|
||||
#endif
|
||||
|
||||
/* TODO complain if native drivers for multiple OSs are enabled */
|
||||
|
||||
#if !defined(ENABLE_BACKEND_LIBUSB) && \
|
||||
!defined(ENABLE_BACKEND_LINUX_DRIVER)
|
||||
#error "No backends are enabled - one more more must be enabled."
|
||||
#endif
|
||||
|
||||
/* This list should be ordered by preference (highest first) */
|
||||
#define BLADERF_BACKEND_LIST { \
|
||||
BACKEND_LIBUSB_FN_TBL_ENTRY \
|
||||
BACKEND_LINUX_DRIVER_FN_TBL_ENTRY \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,119 +0,0 @@
|
|||
#include <assert.h>
|
||||
|
||||
#include "backend.h"
|
||||
#include "debug.h"
|
||||
|
||||
#ifdef ENABLE_BACKEND_LIBUSB
|
||||
#include "backend/libusb.h"
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_BACKEND_LINUX_DRIVER
|
||||
#include "backend/linux.h"
|
||||
#endif
|
||||
|
||||
/* TODO complain if native drivers for multiple OSs are enabled */
|
||||
|
||||
/* This table should be in order of preferred precedence (first = highest) */
|
||||
static const struct bladerf_fn * backend_fns[] = {
|
||||
|
||||
#ifdef ENABLE_BACKEND_LIBUSB
|
||||
&bladerf_lusb_fn,
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_BACKEND_LINUX_DRIVER
|
||||
&bladerf_linux_fn,
|
||||
#endif
|
||||
|
||||
/* This table must be NULL terminated */
|
||||
NULL
|
||||
};
|
||||
|
||||
int open_with_any_backend(struct bladerf **device,
|
||||
struct bladerf_devinfo *info)
|
||||
{
|
||||
int status = BLADERF_ERR_NODEV;
|
||||
const struct bladerf_fn **fn_tbl;
|
||||
|
||||
for (fn_tbl = &backend_fns[0]; *fn_tbl != NULL && status != 0; fn_tbl++) {
|
||||
assert((*fn_tbl)->open);
|
||||
status = (*fn_tbl)->open(device, info);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/* To keep this from getting messy, the fn table could be a tuple:
|
||||
* <BACKEND_* , fn_tbl> and we could walk through it here...
|
||||
*
|
||||
* (Then again, how many backend will we ever have? 4?) */
|
||||
int backend_open(struct bladerf **device, struct bladerf_devinfo *info) {
|
||||
int status = BLADERF_ERR_INVAL;
|
||||
|
||||
switch (info->backend) {
|
||||
|
||||
#ifdef ENABLE_BACKEND_LIBUSB
|
||||
case BACKEND_LIBUSB:
|
||||
status = bladerf_lusb_fn.open(device, info);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_BACKEND_LINUX_DRIVER
|
||||
case BACKEND_LINUX:
|
||||
status = bladerf_linux_fn.open(device, info);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case BACKEND_ANY:
|
||||
status = open_with_any_backend(device, info);
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Bug - this shouldn't happend */
|
||||
dbg_printf("Invalid backend!\n");
|
||||
assert(0);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int backend_probe(struct bladerf_devinfo **devinfo_items, size_t *num_items)
|
||||
{
|
||||
int probe_status, backend_status;
|
||||
struct bladerf_devinfo_list list;
|
||||
const struct bladerf_fn **fn_tbl;
|
||||
|
||||
*devinfo_items = NULL;
|
||||
*num_items = 0;
|
||||
|
||||
probe_status = bladerf_devinfo_list_init(&list);
|
||||
|
||||
if (probe_status == 0) {
|
||||
for (fn_tbl = &backend_fns[0]; *fn_tbl != NULL && !probe_status; fn_tbl++) {
|
||||
assert((*fn_tbl)->probe);
|
||||
backend_status = (*fn_tbl)->probe(&list);
|
||||
|
||||
/* Error out if a backend hit any concerning error */
|
||||
if (backend_status < 0 && backend_status != BLADERF_ERR_NODEV) {
|
||||
probe_status = backend_status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (probe_status == 0) {
|
||||
*num_items = list.num_elt;
|
||||
|
||||
if (*num_items != 0) {
|
||||
*devinfo_items = list.elt;
|
||||
} else {
|
||||
/* For no items, we end up passing back a NULL list to the
|
||||
* API caller, so we'll just free this up now */
|
||||
free(list.elt);
|
||||
probe_status = BLADERF_ERR_NODEV;
|
||||
}
|
||||
|
||||
} else {
|
||||
free(list.elt);
|
||||
}
|
||||
|
||||
return probe_status;
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
# Copyright 2012 Nuand, LLC.
|
||||
# Copyright 2013 Nuand, LLC.
|
||||
#
|
||||
# This file is part of the bladeRF project
|
||||
#
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# Copyright 2012 Nuand, LLC.
|
||||
# Copyright 2013 Nuand, LLC.
|
||||
#
|
||||
# This file is part of the bladeRF project
|
||||
#
|
||||
|
|
|
|||
|
|
@ -1,7 +1,2 @@
|
|||
# Copyright 2012 Nuand, LLC.
|
||||
#
|
||||
# This file is part of the bladeRF project
|
||||
#
|
||||
# TODO license text here (see top-level COPYING for time being)
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
add_subdirectory(cli)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# Copyright 2012 Nuand, LLC.
|
||||
# Copyright 2013 Nuand, LLC.
|
||||
#
|
||||
# This file is part of the bladeRF project
|
||||
#
|
||||
|
|
@ -40,7 +40,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/src/cmd
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/interactive
|
||||
${CMAKE_CURRENT_BINARY_DIR}/src
|
||||
${LIBBLADERF_INCLUDE_DIR}
|
||||
${libbladeRF_SOURCE_DIR}/include
|
||||
${LIBTECLA_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
|
|
@ -74,11 +74,7 @@ add_executable(bladeRF-cli ${BLADERF_CLI_SOURCE})
|
|||
################################################################################
|
||||
find_package(PkgConfig)
|
||||
find_package(Threads)
|
||||
find_package(LibbladeRF)
|
||||
|
||||
if(NOT LIBBLADERF_FOUND)
|
||||
message(FATAL_ERROR "Unable to find libbladeRF")
|
||||
endif()
|
||||
#find_package(LibbladeRF)
|
||||
|
||||
if(ENABLE_INTERACTIVE_TECLA)
|
||||
find_package(LibTecla)
|
||||
|
|
@ -92,7 +88,7 @@ endif(ENABLE_INTERACTIVE_TECLA)
|
|||
# Build configuration
|
||||
################################################################################
|
||||
target_link_libraries(bladeRF-cli
|
||||
${LIBBLADERF_LIBRARIES}
|
||||
libbladerf_shared
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
${LIBTECLA_LIBRARIES}
|
||||
)
|
||||
|
|
@ -109,4 +105,4 @@ install(TARGETS bladeRF-cli DESTINATION ${BIN_INSTALL_DIR})
|
|||
################################################################################
|
||||
# Informational output
|
||||
################################################################################
|
||||
message(STATUS "bladeRF-cli version: ${VERSION_INFO}")
|
||||
message(STATUS "Configured to build bladeRF-cli version: ${VERSION_INFO}")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue