Skip to content

Commit d9ed493

Browse files
committed
Android support
1 parent fcf9423 commit d9ed493

7 files changed

Lines changed: 73 additions & 8 deletions

File tree

fx3_firmware/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ option(ENABLE_BLADERF_FIRMWARE
5858
"Build firmware for the bladeRF 1.0"
5959
ON
6060
)
61+
if(BLADERF_OS_ANDROID)
62+
set(ENABLE_BLADERF_FIRMWARE OFF)
63+
endif()
6164

6265
################################################################################
6366
# Build Configuration

host/CMakeLists.txt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ option(BUILD_DOCUMENTATION
5151
"Enable build and install of manpages and other documentation."
5252
OFF)
5353

54+
option(BUILD_BLADERF_UTILITIES
55+
"Build bladeRF utilities (e.g. bladeRF-cli)."
56+
ON)
57+
58+
if(BLADERF_OS_ANDROID)
59+
set(BUILD_BLADERF_UTILITIES OFF)
60+
endif()
61+
5462
option(TREAT_WARNINGS_AS_ERRORS
5563
"Treat compiler warnings as errors."
5664
ON)
@@ -86,7 +94,9 @@ option(BUILD_AD936X_DEBUG
8694
OFF)
8795
# We do this prior to the rest of host/common, as the compile options are
8896
# going to be different.
89-
add_subdirectory(common/thirdparty/ad936x)
97+
if(BUILD_AD936X)
98+
add_subdirectory(common/thirdparty/ad936x)
99+
endif(BUILD_AD936X)
90100

91101
################################################################################
92102
# Compiler configuration
@@ -161,6 +171,9 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR CYGWIN)
161171
endif()
162172
endif(NOT CMAKE_CROSSCOMPILING AND NOT CYGWIN)
163173

174+
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android")
175+
set(BLADERF_OS_ANDROID 1)
176+
164177
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
165178
set(BLADERF_OS_FREEBSD 1)
166179

@@ -211,7 +224,11 @@ endif()
211224
################################################################################
212225
add_subdirectory(libraries)
213226
add_subdirectory(misc)
214-
add_subdirectory(utilities)
227+
228+
if(BUILD_BLADERF_UTILITIES)
229+
add_subdirectory(utilities)
230+
endif()
231+
215232
add_subdirectory(common)
216233

217234
################################################################################

host/common/include/host_config.h.in

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,42 @@
3131
#cmakedefine01 BLADERF_OS_FREEBSD
3232
#cmakedefine01 BLADERF_OS_OSX
3333
#cmakedefine01 BLADERF_OS_WINDOWS
34+
#cmakedefine01 BLADERF_OS_ANDROID
3435
#cmakedefine01 BLADERF_BIG_ENDIAN
3536

36-
#if !(BLADERF_OS_LINUX || BLADERF_OS_OSX || BLADERF_OS_WINDOWS || BLADERF_OS_FREEBSD)
37+
38+
#if !(BLADERF_OS_LINUX || BLADERF_OS_OSX || BLADERF_OS_WINDOWS || BLADERF_OS_FREEBSD || BLADERF_OS_ANDROID)
3739
# error "Build not configured for any supported operating systems"
3840
#endif
3941

4042
#if 1 < (BLADERF_OS_LINUX + BLADERF_OS_OSX + BLADERF_OS_WINDOWS + BLADERF_OS_FREEBSD)
4143
#error "Build configured for multiple operating systems"
4244
#endif
4345

46+
#ifdef BLADERF_OS_ANDROID
47+
#include <unistd.h>
48+
#include <sys/types.h>
49+
#include <stdlib.h>
50+
#include <pwd.h>
51+
52+
static inline struct passwd *bladerf_android_getpwuid_stub(uid_t uid)
53+
{
54+
static struct passwd pwd;
55+
static char fallback_dir[] = "/";
56+
const char *home;
57+
58+
(void)uid;
59+
60+
home = getenv("HOME");
61+
pwd.pw_dir = (char *)(home != NULL ? home : fallback_dir);
62+
63+
return &pwd;
64+
}
65+
66+
#define getpwuid(uid) bladerf_android_getpwuid_stub(uid)
67+
68+
#endif
69+
4470
#cmakedefine01 HAVE_CLOCK_GETTIME
4571

4672
/*******************************************************************************
@@ -61,7 +87,7 @@
6187
/*-----------------------
6288
* Linux
6389
*---------------------*/
64-
#if BLADERF_OS_LINUX
90+
#if BLADERF_OS_LINUX || BLADERF_OS_ANDROID
6591
#include <endian.h>
6692

6793
#define HOST_TO_LE16(val) htole16(val)
@@ -153,6 +179,16 @@
153179
#error "Encountered an OS that we do not have endian wrappers for?"
154180
#endif
155181

182+
#if BLADERF_OS_ANDROID
183+
#define usleep(usec) do { \
184+
struct timespec ts; \
185+
ts.tv_sec = (usec) / 1000000; \
186+
ts.tv_nsec = ((usec) % 1000000) * 1000; \
187+
nanosleep(&ts, NULL); \
188+
} while (0)
189+
#define pthread_cancel(val) pthread_kill(val, SIGTERM)
190+
#endif
191+
156192
/*******************************************************************************
157193
* Endianness conversions for constants
158194
*

host/libraries/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ add_subdirectory(libbladeRF)
33

44
# Conditionally add the test directory
55
option(TEST_LIBBLADERF "Enables libbladeRF test output" ON)
6+
if(BLADERF_OS_ANDROID)
7+
set(TEST_LIBBLADERF OFF)
8+
endif()
9+
610
if(TEST_LIBBLADERF)
711
message(STATUS "libbladeRF_test: enabled")
812
add_subdirectory(libbladeRF_test)

host/libraries/libbladeRF/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ if(ENABLE_BACKEND_LIBUSB)
265265
else()
266266
message(WARNING "Not checking libbladeRF/libusb compatibility because LIBUSB_VERSION is not defined.")
267267
endif()
268-
set(LIBBLADERF_INCLUDES ${LIBBLADERF_INCLUDES} ${LIBUSB_INCLUDE_DIRS})
268+
set(LIBBLADERF_INCLUDES ${LIBBLADERF_INCLUDES} ${LIBUSB_INCLUDE_DIRS} "${LIBUSB_INCLUDE_DIR}")
269269
endif(NOT LIBUSB_FOUND)
270270
endif(ENABLE_BACKEND_LIBUSB)
271271

@@ -290,7 +290,8 @@ if(BUILD_AD936X)
290290
set(LIBBLADERF_LIBS ${LIBBLADERF_LIBS} ad936x)
291291
endif(BUILD_AD936X)
292292

293-
include_directories(${LIBBLADERF_INCLUDES})
293+
message(STATUS "libbladeRF includes: ${LIBBLADERF_INCLUDES}")
294+
include_directories(${LIBBLADERF_INCLUDES} )
294295

295296

296297
################################################################################

host/libraries/libbladeRF/src/device_calibration.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222

2323
#include <string.h>
2424
#include <stdio.h>
25+
#ifndef BLADERF_OS_ANDROID
2526
#include "common.h"
27+
#else
28+
#include <ad9361.h>
29+
#endif
2630
#include "libbladeRF.h"
2731
#include "board/board.h"
2832
#include "helpers/version.h"

host/libraries/libbladeRF/src/helpers/file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static size_t strip_last_path_entry(char *buf, char dir_delim)
178178
return len;
179179
}
180180

181-
#if BLADERF_OS_LINUX || BLADERF_OS_OSX || BLADERF_OS_FREEBSD
181+
#if BLADERF_OS_LINUX || BLADERF_OS_OSX || BLADERF_OS_FREEBSD || BLADERF_OS_ANDROID
182182
#define ACCESS_FILE_EXISTS F_OK
183183
#define DIR_DELIMETER '/'
184184

@@ -229,7 +229,7 @@ static inline size_t get_install_dir(char *buf, size_t max_len)
229229
return 0;
230230
}
231231

232-
#if BLADERF_OS_LINUX
232+
#if BLADERF_OS_LINUX || BLADERF_OS_ANDROID
233233
static inline size_t get_binary_dir(char *buf, size_t max_len)
234234
{
235235
ssize_t result = readlink("/proc/self/exe", buf, max_len);

0 commit comments

Comments
 (0)