diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index c66171fd..149a0a27 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -25,8 +25,14 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake/modules) # Firmware <--> Host common files set(BLADERF_FW_COMMON_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/../firmware_common) -# Source common amongst host software -set(BLADERF_HOST_COMMON_DIR ${CMAKE_CURRENT_LIST_DIR}/common) +# Source and headers common amongst host software +set(BLADERF_HOST_COMMON_INCLUDE_DIRS + ${CMAKE_CURRENT_LIST_DIR}/common + ${CMAKE_CURRENT_BINARY_DIR}/common +) + +set(BLADERF_HOST_COMMON_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/common) + ################################################################################ # Compiler configuration @@ -72,14 +78,29 @@ if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR endif("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") +############################### +# System configuration +############################### + +# Linux (TODO determine if this will actually be sufficient for BSD) +if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "BSD") + set(BLADERF_OS_LINUX 1) +elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set(BLADERF_OS_OSX 1) +elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + set(BLADERF_OS_WINDOWS 1) +else() + message(FATAL_ERROR "Unsupported host operating system: ${CMAKE_SYSTEM_NAME}") +endif() ################################################################################ # Process subdirectories ################################################################################ +add_subdirectory(common) add_subdirectory(libraries) -add_subdirectory(utilities) add_subdirectory(misc) +add_subdirectory(utilities) ################################################################################ # Create uninstall target diff --git a/host/common/CMakeLists.txt b/host/common/CMakeLists.txt new file mode 100644 index 00000000..ea95b90e --- /dev/null +++ b/host/common/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 2.8) +project(bladerf_host_common C) + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/host_config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/host_config.h + @ONLY +) diff --git a/host/common/host_config.h.in b/host/common/host_config.h.in new file mode 100644 index 00000000..23c4228e --- /dev/null +++ b/host/common/host_config.h.in @@ -0,0 +1,82 @@ +#ifndef HOST_CONFIG_H__ +#define HOST_CONFIG_H__ + +#cmakedefine01 BLADERF_OS_LINUX +#cmakedefine01 BLADERF_OS_OSX +#cmakedefine01 BLADERF_OS_WINDOWS + +#if !(BLADERF_OS_LINUX || BLADERF_OS_OSX || BLADERF_OS_WINDOWS) +# error "Build not configured for any supported operating systems" +#endif + +#if 1 < (BLADERF_OS_LINUX + BLADERF_OS_OSX + BLADERF_OS_WINDOWS) +#error "Build configured for multiple operating systems" +#endif + + + + +/******************************************************************************* + * Endianness conversions + * + * HOST_TO_LE16 16-bit host endianness to little endian conversion + * LE16_TO_HOST 16-bit little endian to host endianness conversion + * HOST_TO_BE16 16-bit host endianness to big endian conversion + * BE16_TO_HOST 16-bit big endian to host endianness conversion + ******************************************************************************/ + +/*----------------------- + * Linux + *---------------------*/ +#if BLADERF_OS_LINUX +#include + +#define HOST_TO_LE16(val) htole16(val) +#define LE16_TO_HOST(val) le16toh(val) +#define HOST_TO_BE16(val) htobe16(val) +#define BE16_TO_HOST(val) be16toh(val) + +/*----------------------- + * Apple OSX + *---------------------*/ +#elif BLADERF_OS_OSX +#include + +#define HOST_TO_LE16(val) OSSwapHostToLittleInt16(val) +#define LE16_TO_HOST(val) OSSwapLittleToHostInt16(val) +#define HOST_TO_BE16(val) OSSwapHostToBigInt16(val) +#define BE16_TO_HOST(val) OSSwapBigToHostInt16(val) + +/*----------------------- + * Windows + *---------------------*/ +#elif BLADERF_OS_WINDOWS +#include + +/* We'll assume little endian for Windows platforms: + * http://blogs.msdn.com/b/larryosterman/archive/2005/06/07/426334.aspx + */ +#define HOST_TO_LE16(val) (val) +#define LE16_TO_HOST(val) (val) +#define HOST_TO_BE16(val) _byteswap_ushort(val) +#define BE16_TO_HOST(val) _byteswap_ushort(val) + +/*----------------------- + * Unsupported or bug + *---------------------*/ +#else +#error "Encountered an OS that we do not have endian wrappers for?" +#endif + + +/******************************************************************************* + * Miscellaneous fixups + ******************************************************************************/ + +/* Windows does not appear to provide strtok_r, but appears to provide a + * strtok_s which presents the same interface */ +#if BLADERF_OS_WINDOWS +#define strtok_r strtok_s +#endif + +#endif diff --git a/host/libraries/libbladeRF/CMakeLists.txt b/host/libraries/libbladeRF/CMakeLists.txt index c37fe8c3..cdd15a45 100644 --- a/host/libraries/libbladeRF/CMakeLists.txt +++ b/host/libraries/libbladeRF/CMakeLists.txt @@ -91,7 +91,7 @@ endif() ################################################################################ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/src - ${BLADERF_HOST_COMMON_DIR} + ${BLADERF_HOST_COMMON_INCLUDE_DIRS} ${BLADERF_FW_COMMON_INCLUDE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/src ${LIBUSB_INCLUDE_DIRS} @@ -127,7 +127,7 @@ set(LIBBLADERF_SOURCE src/lms.c src/si5338.c src/version.h - ${BLADERF_HOST_COMMON_DIR}/conversions.c + ${BLADERF_HOST_COMMON_SOURCE_DIR}/conversions.c ) if(ENABLE_BACKEND_LIBUSB) diff --git a/host/libraries/libbladeRF/src/backend/libusb.c b/host/libraries/libbladeRF/src/backend/libusb.c index 93af78c9..572e0d1f 100644 --- a/host/libraries/libbladeRF/src/backend/libusb.c +++ b/host/libraries/libbladeRF/src/backend/libusb.c @@ -7,7 +7,6 @@ #include #include #include -#include #include #include @@ -742,8 +741,8 @@ static int lusb_get_fw_version(struct bladerf *dev, status = BLADERF_ERR_IO; *maj = *min = 0; } else { - *maj = (unsigned int) le16toh(fw_ver.major); - *min = (unsigned int) le16toh(fw_ver.minor); + *maj = (unsigned int) LE16_TO_HOST(fw_ver.major); + *min = (unsigned int) LE16_TO_HOST(fw_ver.minor); } return status; diff --git a/host/libraries/libbladeRF/src/bladerf_priv.h b/host/libraries/libbladeRF/src/bladerf_priv.h index e99973e6..1636b31f 100644 --- a/host/libraries/libbladeRF/src/bladerf_priv.h +++ b/host/libraries/libbladeRF/src/bladerf_priv.h @@ -6,6 +6,7 @@ #include #include +#include "host_config.h" /* Reserved values for bladerf_devinfo fields to indicate "undefined" */ #define DEVINFO_SERIAL_ANY "ANY" diff --git a/host/utilities/bladeRF-cli/CMakeLists.txt b/host/utilities/bladeRF-cli/CMakeLists.txt index 3f550204..7a8c86cf 100644 --- a/host/utilities/bladeRF-cli/CMakeLists.txt +++ b/host/utilities/bladeRF-cli/CMakeLists.txt @@ -41,7 +41,7 @@ set(BLADERF_CLI_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/src/cmd ${CMAKE_CURRENT_SOURCE_DIR}/src/interactive ${CMAKE_CURRENT_BINARY_DIR}/src - ${BLADERF_HOST_COMMON_DIR} + ${BLADERF_HOST_COMMON_INCLUDE_DIRS} ${libbladeRF_SOURCE_DIR}/include ) @@ -67,6 +67,7 @@ set(BLADERF_CLI_SOURCE src/cmd/probe.c src/cmd/rxtx.c src/cmd/version.c + ${BLADERF_HOST_COMMON_SOURCE_DIR}/conversions.c ) if(ENABLE_INTERACTIVE_TECLA) diff --git a/host/utilities/bladeRF-cli/src/cmd/rxtx.c b/host/utilities/bladeRF-cli/src/cmd/rxtx.c index 80aa0e5e..585818d3 100644 --- a/host/utilities/bladeRF-cli/src/cmd/rxtx.c +++ b/host/utilities/bladeRF-cli/src/cmd/rxtx.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -21,6 +20,7 @@ #include "cmd.h" #include "conversions.h" #include "minmax.h" +#include "host_config.h" #define RXTX_CMDSTR_START "start" #define RXTX_CMDSTR_STOP "stop" diff --git a/host/utilities/bladeRF-cli/src/common.h b/host/utilities/bladeRF-cli/src/common.h index 6e270a4e..a9f1d06e 100644 --- a/host/utilities/bladeRF-cli/src/common.h +++ b/host/utilities/bladeRF-cli/src/common.h @@ -4,6 +4,7 @@ #include #include #include + /** * Differentiates error code types */