From 7a1b2c146217d0500a5d20ecb9cf4eb74b38947e Mon Sep 17 00:00:00 2001 From: Jon Szymaniak Date: Mon, 21 Oct 2013 22:30:38 -0400 Subject: [PATCH] common, libbladeRF: log.c support can be disabled at compile-time CMake option added to disable log.c for libbladeRF. Adjustments made to other files as needed to address warnings (becoming errors via -Werror and /Wx). Removed return values for log-related functions, as these were unused and made it slightly more annoying to make this change. The libbladeRF minor version has been bumped to note this change in the currently unstable series v0.x.x series. --- host/common/include/log.h | 17 ++++++++----- host/common/src/log.c | 17 ++++--------- host/libraries/libbladeRF/CMakeLists.txt | 9 ++++++- .../libraries/libbladeRF/include/libbladeRF.h | 7 +++--- .../libraries/libbladeRF/src/backend/libusb.c | 21 +++++++++------- host/libraries/libbladeRF/src/bladerf.c | 4 ++-- host/utilities/common/src/ezusb.c | 24 ++++++++++--------- 7 files changed, 55 insertions(+), 44 deletions(-) diff --git a/host/common/include/log.h b/host/common/include/log.h index 089e958c..21a65949 100644 --- a/host/common/include/log.h +++ b/host/common/include/log.h @@ -57,10 +57,12 @@ * @param level The severity level of the message * @param format The printf-style format string * @param ... Optional values for format specifier substitution - * - * @return The number of characters written to the log */ -int log_write(bladerf_log_level level, const char *format, ...); +#ifdef LOGGING_ENABLED +void log_write(bladerf_log_level level, const char *format, ...); +#else +#define log_write(level, format, ...) do {} while(0) +#endif /** @@ -70,9 +72,12 @@ int log_write(bladerf_log_level level, const char *format, ...); * the previous log level. * * @param level The new log level filter value - * - * @return The previous log level */ -bladerf_log_level log_set_verbosity(bladerf_log_level level); +#ifdef LOGGING_ENABLED +void log_set_verbosity(bladerf_log_level level); +#else +#define log_set_verbosity(level) do {} while (0) +#endif + #endif diff --git a/host/common/src/log.c b/host/common/src/log.c index 260aa5ea..5369a9fe 100644 --- a/host/common/src/log.c +++ b/host/common/src/log.c @@ -1,13 +1,12 @@ +#ifdef LOGGING_ENABLED #include #include #include static bladerf_log_level filter_level = BLADERF_LOG_LEVEL_INFO; -int log_write(bladerf_log_level level, const char *format, ...) +void log_write(bladerf_log_level level, const char *format, ...) { - int ret = 0; - /* Only process this message if its level exceeds the current threshold */ if (level >= filter_level) { @@ -15,19 +14,13 @@ int log_write(bladerf_log_level level, const char *format, ...) /* Write the log message */ va_start(args, format); - ret = vfprintf(stderr, format, args); + vfprintf(stderr, format, args); va_end(args); } - - return ret; } -bladerf_log_level log_set_verbosity(bladerf_log_level level) +void log_set_verbosity(bladerf_log_level level) { - /* Replace the old level with the new level and return the old level */ - bladerf_log_level old_level = filter_level; filter_level = level; - - return old_level; } - +#endif diff --git a/host/libraries/libbladeRF/CMakeLists.txt b/host/libraries/libbladeRF/CMakeLists.txt index 93e0b1bd..cb66ec1e 100644 --- a/host/libraries/libbladeRF/CMakeLists.txt +++ b/host/libraries/libbladeRF/CMakeLists.txt @@ -6,7 +6,7 @@ project(libbladeRF C) ################################################################################ set(VERSION_INFO_MAJOR 0) -set(VERSION_INFO_MINOR 8) +set(VERSION_INFO_MINOR 9) set(VERSION_INFO_PATCH 0) set(VERSION_INFO_EXTRA "git") include(Version) @@ -34,6 +34,8 @@ endif() # Configuration options ################################################################################ +option(ENABLE_LIBBLADERF_LOGGING "Enable log messages in libbladeRF" ON) + ############################## # Backend Support ############################## @@ -67,6 +69,11 @@ configure_file( ################################################################################ # Additional compiler options ################################################################################ +if(ENABLE_LIBBLADERF_LOGGING) + add_definitions(-DLOGGING_ENABLED) +endif() + + if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" ) diff --git a/host/libraries/libbladeRF/include/libbladeRF.h b/host/libraries/libbladeRF/include/libbladeRF.h index d4a23222..a7b3d7de 100644 --- a/host/libraries/libbladeRF/include/libbladeRF.h +++ b/host/libraries/libbladeRF/include/libbladeRF.h @@ -244,7 +244,8 @@ typedef enum { BLADERF_LOG_LEVEL_INFO, /**< Information level logging */ BLADERF_LOG_LEVEL_WARNING, /**< Warning level logging */ BLADERF_LOG_LEVEL_ERROR, /**< Error level logging */ - BLADERF_LOG_LEVEL_CRITICAL /**< Fatal error level logging */ + BLADERF_LOG_LEVEL_CRITICAL, /**< Fatal error level logging */ + BLADERF_LOG_LEVEL_SILENT /**< No output */ } bladerf_log_level; /** @@ -1162,10 +1163,8 @@ API_EXPORT void bladerf_version(struct bladerf_version *version); * the previous log level. * * @param level The new log level filter value - * - * @return The previous log level */ -API_EXPORT bladerf_log_level bladerf_log_set_verbosity(bladerf_log_level level); +API_EXPORT void bladerf_log_set_verbosity(bladerf_log_level level); /** @} (End of FN_MISC) */ diff --git a/host/libraries/libbladeRF/src/backend/libusb.c b/host/libraries/libbladeRF/src/backend/libusb.c index 335bbdc7..6acc38c7 100644 --- a/host/libraries/libbladeRF/src/backend/libusb.c +++ b/host/libraries/libbladeRF/src/backend/libusb.c @@ -485,7 +485,6 @@ static int lusb_open(struct bladerf **device, struct bladerf_devinfo *info) struct bladerf_lusb *lusb = NULL; libusb_device **list; struct bladerf_devinfo thisinfo; - const struct libusb_version *version; libusb_context *context; @@ -499,8 +498,15 @@ static int lusb_open(struct bladerf **device, struct bladerf_devinfo *info) goto lusb_open_done; } - version = libusb_get_version(); - log_verbose( "Using libusb version %d.%d.%d.%d\n", version->major, version->minor, version->micro, version->nano ); + /* We can only print this out when log output is enabled, or else we'll + * get snagged by -Werror=unused-but-set-variable */ +# ifdef LOG_ENABLED + { + const struct libusb_version *version; + version = libusb_get_version(); + log_verbose( "Using libusb version %d.%d.%d.%d\n", version->major, version->minor, version->micro, version->nano ); + } +# endif count = libusb_get_device_list( context, &list ); /* Iterate through all the USB devices */ @@ -1042,7 +1048,7 @@ static int verify_flash(struct bladerf *dev, uint32_t addr, uint8_t *image, uint32_t len) { int status = 0; - int page_addr, page_len, i, idx; + int page_addr, page_len, i; uint8_t page_buf[BLADERF_FLASH_PAGE_SIZE]; uint8_t *image_page; @@ -1065,12 +1071,11 @@ static int verify_flash(struct bladerf *dev, uint32_t addr, status = verify_page(page_buf, image_page); if(status < 0) { - idx = abs(status); log_error("bladeRF firmware verification failed at flash " " address 0x%02x. Read 0x%02X, expected 0x%02X\n", - flash_from_pages(i) + idx, - page_buf[idx], - image_page[idx] + flash_from_pages(i) + abs(status), + page_buf[abs(status)], + image_page[abs(status)] ); return BLADERF_ERR_IO; diff --git a/host/libraries/libbladeRF/src/bladerf.c b/host/libraries/libbladeRF/src/bladerf.c index f676c904..4186b99d 100644 --- a/host/libraries/libbladeRF/src/bladerf.c +++ b/host/libraries/libbladeRF/src/bladerf.c @@ -920,9 +920,9 @@ void bladerf_version(struct bladerf_version *version) version->describe = LIBBLADERF_VERSION; } -bladerf_log_level bladerf_log_set_verbosity(bladerf_log_level level) +void bladerf_log_set_verbosity(bladerf_log_level level) { - return log_set_verbosity(level); + log_set_verbosity(level); } /*------------------------------------------------------------------------------ diff --git a/host/utilities/common/src/ezusb.c b/host/utilities/common/src/ezusb.c index 798d0856..f3150c91 100644 --- a/host/utilities/common/src/ezusb.c +++ b/host/utilities/common/src/ezusb.c @@ -180,11 +180,12 @@ static bool ezusb_cpucs(libusb_device_handle *device, uint32_t addr, bool doRun) /* We may get an I/O error from libusbx as the device disappears */ ((!doRun) || (status != LIBUSB_ERROR_IO))) { - const char *mesg = "can't modify CPUCS"; - if (status < 0) - log_error("%s: %s\n", mesg, libusb_error_name(status)); - else - log_info("%s\n", mesg); + if (status < 0) { + log_error("Can't modify CPUCS: %s\n", mesg, + libusb_error_name(status)); + } else { + log_info("Can't modify CPUCS\n", mesg); + } return false; } else return true; @@ -207,11 +208,12 @@ static bool ezusb_fx3_jump(libusb_device_handle *device, uint32_t addr) /* We may get an I/O error from libusbx as the device disappears */ if ((status != 0) && (status != LIBUSB_ERROR_IO)) { - const char *mesg = "failed to send jump command"; - if (status < 0) - log_error("%s: %s\n", mesg, libusb_error_name(status)); - else - log_info("%s\n", mesg); + if (status < 0) { + log_error("Failed to send jump command: %s\n", + mesg, libusb_error_name(status)); + } else { + log_info("Failed to send jump command\n", mesg); + } return false; } else return true; @@ -669,7 +671,7 @@ static int fx3_load_ram(libusb_device_handle *device, const char *path) fclose(image); return -7; } - + fclose(image); // transfer execution to Program Entry