Explorar el Código

Provide an interface for logging debug messages

Suren A. Chilingaryan hace 9 años
padre
commit
8da61292f5
Se han modificado 11 ficheros con 63 adiciones y 26 borrados
  1. 6 9
      dma/ipe.c
  2. 0 1
      dma/ipe_private.h
  3. 1 0
      dma/nwl_engine.c
  4. 2 6
      dma/nwl_engine_buffers.h
  5. 0 3
      dma/nwl_private.h
  6. 3 3
      pcilib/CMakeLists.txt
  7. 16 0
      pcilib/debug.c
  8. 23 0
      pcilib/debug.h
  9. 7 1
      pcilib/error.c
  10. 1 0
      pcilib/error.h
  11. 4 3
      pcilib/pcilib.h

+ 6 - 9
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;

+ 0 - 1
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 */

+ 1 - 0
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"

+ 2 - 6
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;
 }

+ 0 - 3
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"

+ 3 - 3
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
 )

+ 16 - 0
pcilib/debug.c

@@ -0,0 +1,16 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+#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);
+}
+

+ 23 - 0
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 */

+ 7 - 1
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;

+ 1 - 0
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__)

+ 4 - 3
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 {