From 8da61292f595c5e700a4fef981b0e0d07910b4b2 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Thu, 30 Apr 2015 19:51:49 +0200 Subject: Provide an interface for logging debug messages --- dma/ipe.c | 15 ++++++--------- dma/ipe_private.h | 1 - dma/nwl_engine.c | 1 + dma/nwl_engine_buffers.h | 8 ++------ dma/nwl_private.h | 3 --- pcilib/CMakeLists.txt | 6 +++--- pcilib/debug.c | 16 ++++++++++++++++ pcilib/debug.h | 23 +++++++++++++++++++++++ pcilib/error.c | 8 +++++++- pcilib/error.h | 1 + pcilib/pcilib.h | 7 ++++--- 11 files changed, 63 insertions(+), 26 deletions(-) create mode 100644 pcilib/debug.c create mode 100644 pcilib/debug.h diff --git a/dma/ipe.c b/dma/ipe.c index 439b231..855109c 100644 --- a/dma/ipe.c +++ b/dma/ipe.c @@ -12,6 +12,7 @@ #include "pcilib.h" #include "error.h" #include "tools.h" +#include "debug.h" #include "ipe.h" #include "ipe_private.h" @@ -425,9 +426,7 @@ int dma_ipe_stream_read(pcilib_dma_context_t *vctx, pcilib_dma_engine_t dma, uin // case PCILIB_STREAMING_CHECK: wait = 0; break; } -#ifdef IPEDMA_DEBUG - printf("Waiting for data: %u (last read) 0x%x (last read addr) 0x%x (last_written)\n", ctx->last_read, ctx->last_read_addr, *last_written_addr_ptr); -#endif /* IPEDMA_DEBUG */ + pcilib_debug(DMA, "Waiting for data: %u (last read) 0x%x (last read addr) 0x%x (last_written)\n", ctx->last_read, ctx->last_read_addr, *last_written_addr_ptr); gettimeofday(&start, NULL); memcpy(&cur, &start, sizeof(struct timeval)); @@ -442,10 +441,10 @@ int dma_ipe_stream_read(pcilib_dma_context_t *vctx, pcilib_dma_engine_t dma, uin // Failing out if we exited on timeout if ((ctx->last_read_addr == (*last_written_addr_ptr))||(*last_written_addr_ptr == 0)) { #ifdef IPEDMA_SUPPORT_EMPTY_DETECTED -# ifdef IPEDMA_DEBUG +# ifdef PCILIB_DEBUG_DMA if ((wait)&&(*last_written_addr_ptr)&&(!*empty_detected_ptr)) - pcilib_warning("The empty_detected flag is not set, but no data arrived within %lu us\n", wait); -# endif /* IPEDMA_DEBUG */ + pcilib_debug(DMA, "The empty_detected flag is not set, but no data arrived within %lu us\n", wait); +# endif /* PCILIB_DEBUG_DMA */ #endif /* IPEDMA_SUPPORT_EMPTY_DETECTED */ return (ret&PCILIB_STREAMING_FAIL)?PCILIB_ERROR_TIMEOUT:0; } @@ -454,9 +453,7 @@ int dma_ipe_stream_read(pcilib_dma_context_t *vctx, pcilib_dma_engine_t dma, uin cur_read = ctx->last_read + 1; if (cur_read == ctx->ring_size) cur_read = 0; -#ifdef IPEDMA_DEBUG - printf("Reading: %u (last read) 0x%x (last read addr) 0x%x (last_written)\n", cur_read, ctx->last_read_addr, *last_written_addr_ptr); -#endif /* IPEDMA_DEBUG */ + pcilib_debug(DMA, "Reading: %u (last read) 0x%x (last read addr) 0x%x (last_written)\n", cur_read, ctx->last_read_addr, *last_written_addr_ptr); #ifdef IPEDMA_DETECT_PACKETS if ((*empty_detected_ptr)&&(pcilib_kmem_get_block_ba(ctx->dmactx.pcilib, ctx->pages, cur_read) == (*last_written_addr_ptr))) packet_flags = PCILIB_DMA_FLAG_EOP; diff --git a/dma/ipe_private.h b/dma/ipe_private.h index 161e609..f6aa2f7 100644 --- a/dma/ipe_private.h +++ b/dma/ipe_private.h @@ -11,7 +11,6 @@ #define IPEDMA_DESCRIPTOR_SIZE 128 #define IPEDMA_DESCRIPTOR_ALIGNMENT 64 -//#define IPEDMA_DEBUG //#define IPEDMA_BUG_DMARD /**< No register read during DMA transfer */ //#define IPEDMA_DETECT_PACKETS /**< Using empty_deceted flag */ #define IPEDMA_SUPPORT_EMPTY_DETECTED /**< Avoid waiting for data when empty_detected flag is set in hardware */ diff --git a/dma/nwl_engine.c b/dma/nwl_engine.c index 6930533..15ae27e 100644 --- a/dma/nwl_engine.c +++ b/dma/nwl_engine.c @@ -10,6 +10,7 @@ #include "pcilib.h" #include "error.h" #include "tools.h" +#include "debug.h" #include "nwl_private.h" #include "nwl_defines.h" diff --git a/dma/nwl_engine_buffers.h b/dma/nwl_engine_buffers.h index 71fb736..d3af079 100644 --- a/dma/nwl_engine_buffers.h +++ b/dma/nwl_engine_buffers.h @@ -33,9 +33,7 @@ static int dma_nwl_compute_read_s2c_pointers(nwl_dma_t *ctx, pcilib_nwl_engine_c return PCILIB_ERROR_INVALID_STATE; } -#ifdef DEBUG_NWL - printf("S2C: %lu %lu\n", ectx->tail, ectx->head); -#endif /* DEBUG_NWL */ + pcilib_debug(DMA, "S2C: %lu %lu\n", ectx->tail, ectx->head); return 0; } @@ -61,9 +59,7 @@ static int dma_nwl_compute_read_c2s_pointers(nwl_dma_t *ctx, pcilib_nwl_engine_c ectx->tail = ectx->head + 1; if (ectx->tail == PCILIB_NWL_DMA_PAGES) ectx->tail = 0; -#ifdef DEBUG_NWL - printf("C2S: %lu %lu\n", ectx->tail, ectx->head); -#endif /* DEBUG_NWL */ + pcilib_debug(DMA, "C2S: %lu %lu\n", ectx->tail, ectx->head); return 0; } diff --git a/dma/nwl_private.h b/dma/nwl_private.h index 1d60169..08f0feb 100644 --- a/dma/nwl_private.h +++ b/dma/nwl_private.h @@ -17,9 +17,6 @@ typedef struct pcilib_nwl_engine_context_s pcilib_nwl_engine_context_t; #define PCILIB_NWL_REGISTER_TIMEOUT 10000 /**< us */ -//#define DEBUG_HARDWARE -//#define DEBUG_NWL - #include "nwl.h" #include "nwl_irq.h" #include "nwl_engine.h" diff --git a/pcilib/CMakeLists.txt b/pcilib/CMakeLists.txt index 70bd5f0..b1b56bf 100644 --- a/pcilib/CMakeLists.txt +++ b/pcilib/CMakeLists.txt @@ -3,8 +3,8 @@ include_directories( ${CMAKE_SOURCE_DIR}/pcilib ) -set(HEADERS pcilib.h pci.h export.h model.h bank.h register.h kmem.h irq.h dma.h event.h plugin.h tools.h error.h config.h) -add_library(pcilib SHARED pci.c export.c model.c bank.c register.c kmem.c irq.c dma.c event.c plugin.c tools.c error.c) +set(HEADERS pcilib.h pci.h export.h model.h bank.h register.h kmem.h irq.h dma.h event.h plugin.h tools.h error.h debug.h config.h) +add_library(pcilib SHARED pci.c export.c model.c bank.c register.c kmem.c irq.c dma.c event.c plugin.c tools.c error.c debug.c) target_link_libraries(pcilib dma protocols ${CMAKE_THREAD_LIBS_INIT} ${UFODECODE_LIBRARIES} ${CMAKE_DL_LIBS}) add_dependencies(pcilib dma protocols) @@ -16,6 +16,6 @@ install(FILES pcilib.h DESTINATION include ) -install(FILES bank.h register.h dma.h event.h model.h error.h tools.h export.h +install(FILES bank.h register.h dma.h event.h model.h error.h debug.h tools.h export.h DESTINATION include/pcilib ) diff --git a/pcilib/debug.c b/pcilib/debug.c new file mode 100644 index 0000000..f07e1e6 --- /dev/null +++ b/pcilib/debug.c @@ -0,0 +1,16 @@ +#include +#include +#include + +#include "error.h" + +void pcilib_debug_message(const char *function, const char *file, int line, const char *format, ...) { + va_list va; + + if (!getenv(function)) return; + + va_start(va, format); + pcilib_log_vmessage(file, line, PCILIB_LOG_DEBUG, format, va); + va_end(va); +} + diff --git a/pcilib/debug.h b/pcilib/debug.h new file mode 100644 index 0000000..f9134be --- /dev/null +++ b/pcilib/debug.h @@ -0,0 +1,23 @@ +#ifndef _PCILIB_DEBUG_H +#define _PCILIB_DEBUG_H + +#define PCILIB_DEBUG + +#ifdef PCILIB_DEBUG +# define PCILIB_DEBUG_DMA +#endif /* PCILIB_DEBUG */ + + +#ifdef PCILIB_DEBUG_DMA +# define PCILIB_DEBUG_DMA_CALL(function, ...) pcilib_debug_message (#function, __FILE__, __LINE__, __VA_ARGS__) +#else /* PCILIB_DEBUG_DMA */ +# define PCILIB_DEBUG_DMA_CALL(function, ...) +#endif /* PCILIB_DEBUG_DMA */ + +#define pcilib_debug(function, ...) \ + PCILIB_DEBUG_##function##_CALL(PCILIB_DEBUG_##function, __VA_ARGS__) + +void pcilib_debug_message(const char *function, const char *file, int line, const char *format, ...); + + +#endif /* _PCILIB_DEBUG_H */ diff --git a/pcilib/error.c b/pcilib/error.c index 538534b..ad38622 100644 --- a/pcilib/error.c +++ b/pcilib/error.c @@ -19,13 +19,19 @@ static pcilib_logger_t pcilib_logger = pcilib_print_error; void pcilib_log_message(const char *file, int line, pcilib_log_priority_t prio, const char *msg, ...) { va_list va; - if (prio >= pcilib_logger_min_prio) { + if ((!prio)||(prio >= pcilib_logger_min_prio)) { va_start(va, msg); pcilib_logger(pcilib_logger_argument, file, line, prio, msg, va); va_end(va); } } +void pcilib_log_vmessage(const char *file, int line, pcilib_log_priority_t prio, const char *msg, va_list va) { + if ((!prio)||(prio >= pcilib_logger_min_prio)) { + pcilib_logger(pcilib_logger_argument, file, line, prio, msg, va); + } +} + int pcilib_set_logger(pcilib_log_priority_t min_prio, pcilib_logger_t logger, void *arg) { pcilib_logger_min_prio = min_prio; diff --git a/pcilib/error.h b/pcilib/error.h index 5b5f8b1..e94fd25 100644 --- a/pcilib/error.h +++ b/pcilib/error.h @@ -27,6 +27,7 @@ enum { } pcilib_errot_t; void pcilib_log_message(const char *file, int line, pcilib_log_priority_t prio, const char *msg, ...); +void pcilib_log_vmessage(const char *file, int line, pcilib_log_priority_t prio, const char *msg, va_list va); #define pcilib_log(prio, ...) \ pcilib_log_message(__FILE__, __LINE__, prio, __VA_ARGS__) diff --git a/pcilib/pcilib.h b/pcilib/pcilib.h index 232daf8..f5853d3 100644 --- a/pcilib/pcilib.h +++ b/pcilib/pcilib.h @@ -23,9 +23,10 @@ typedef unsigned int pcilib_irq_hw_source_t; typedef uint32_t pcilib_irq_source_t; typedef enum { - PCILIB_LOG_INFO, - PCILIB_LOG_WARNING, - PCILIB_LOG_ERROR + PCILIB_LOG_DEBUG = 0, /**< Debug messages will be always printed as they should be filtered based on setting of corresponding environmental variable */ + PCILIB_LOG_INFO, /**< Informational message are suppresed by default */ + PCILIB_LOG_WARNING, /**< Warnings messages indicate that something unexpected happen, but application can continue */ + PCILIB_LOG_ERROR /**< The error which is impossible to handle on this level of library */ } pcilib_log_priority_t; typedef enum { -- cgit v1.2.3