summaryrefslogtreecommitdiffstats
path: root/pcilib
diff options
context:
space:
mode:
Diffstat (limited to 'pcilib')
-rw-r--r--pcilib/CMakeLists.txt6
-rw-r--r--pcilib/debug.c16
-rw-r--r--pcilib/debug.h23
-rw-r--r--pcilib/error.c8
-rw-r--r--pcilib/error.h1
-rw-r--r--pcilib/pcilib.h7
6 files changed, 54 insertions, 7 deletions
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 <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);
+}
+
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 {