aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBhavik Patel <bhavik.patel@arm.com>2020-07-16 22:36:02 +0200
committerBhavik Patel <bhavik.patel@arm.com>2020-07-17 16:36:27 +0200
commitf50578199cca79b73596672a4838640130d1aa8f (patch)
tree738f2fa547eb622ac927157b822efc2781f5ab03
parentdae5be07b76e5361593d8c2fa4717970c2a5fc19 (diff)
downloadethos-u-core-driver-f50578199cca79b73596672a4838640130d1aa8f.tar.gz
MLBEDSW-2596 Add support to set driver log severity
The driver can log at one of the following levels: 0=emerg, 1=alert, 2=crit, 3=err, 4=warning, 5=notice, 6=info, 7=debug. The logs at or below the set level are printed whereas the higher level logs are not printed. Change-Id: I05a498d4c8c78112207187d9dceaa2386b138c5d
-rw-r--r--CMakeLists.txt26
-rw-r--r--src/ethosu_common.h58
2 files changed, 75 insertions, 9 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4651cf2..0dab28f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -25,9 +25,9 @@ project(ethosu_core_driver VERSION 0.0.1)
#
option(DRIVER_PMU_AUTOINIT "Enable PMU boot auto-initialization" OFF)
-option(DRIVER_LOG_SUPPORT "Enable logging." OFF)
set(CMSIS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmsis" CACHE PATH "Path to CMSIS.")
+set(DRIVER_LOG_SEVERITY "6" CACHE STRING "Driver log severity level 0=emerg, 1=alert, 2=crit, 3=err, 4=warning, 5=notice, 6=info, 7=debug")
#
# Global settings
@@ -49,9 +49,12 @@ else()
message(FATAL_ERROR "Unsupported compiler ${CMAKE_SYSTEM_PROCESSOR}.")
endif()
-# Enable logging support
-if(DRIVER_LOG_SUPPORT)
- add_compile_definitions(LOG_ENABLED)
+# Check that DRIVER_LOG_SEVERITY has one of the supported
+# levels.
+set(LOG_SEVERITY_VALUE 0 1 2 3 4 5 6 7)
+set(LOG_SEVERITY_NAME EMERG ALERT CRIT ERR WARNING NOTICE INFO DEBUG)
+if(NOT ${DRIVER_LOG_SEVERITY} IN_LIST LOG_SEVERITY_VALUE)
+ message(FATAL_ERROR "Unsupported driver log severity level ${DRIVER_LOG_SEVERITY}")
endif()
# Enable PMU boot auto-initialization
@@ -72,6 +75,19 @@ add_library(ethosu_core_driver STATIC)
target_include_directories(ethosu_core_driver PUBLIC include)
target_sources(ethosu_core_driver PRIVATE src/ethosu_driver.c src/ethosu_device.c src/ethosu_pmu.c)
+# Set the DRIVER_LOG_SEVERITY level for the target
+target_compile_definitions(ethosu_core_driver PRIVATE DRIVER_LOG_SEVERITY=${DRIVER_LOG_SEVERITY})
+
+foreach(S IN ZIP_LISTS LOG_SEVERITY_VALUE LOG_SEVERITY_NAME)
+ # This will add a define in the form of LOG_SEVERITY_INFO=6.
+ # This is to make the conditional check like
+ # (DRIVER_LOG_SEVERITY >= LOG_SEVERITY_INFO) possible.
+ target_compile_definitions(ethosu_core_driver PRIVATE LOG_SEVERITY_${S_1}=${S_0})
+ if(${DRIVER_LOG_SEVERITY} STREQUAL ${S_0})
+ set(DRIVER_LOG_SEVERITY_NAME ${S_1})
+ endif()
+endforeach()
+
#
# Print build status
#
@@ -80,5 +96,5 @@ message(STATUS "*******************************************************")
message(STATUS "PROJECT_NAME : ${PROJECT_NAME}")
message(STATUS "CMAKE_SYSTEM_PROCESSOR : ${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS "CMSIS_PATH : ${CMSIS_PATH}")
-message(STATUS "DRIVER_LOG_SUPPORT : ${DRIVER_LOG_SUPPORT}")
+message(STATUS "DRIVER_LOG_SEVERITY : ${DRIVER_LOG_SEVERITY} (${DRIVER_LOG_SEVERITY_NAME})")
message(STATUS "*******************************************************")
diff --git a/src/ethosu_common.h b/src/ethosu_common.h
index ce7a663..a5ea197 100644
--- a/src/ethosu_common.h
+++ b/src/ethosu_common.h
@@ -22,15 +22,65 @@
#include "ethosu55_interface.h"
#include "ethosu_device.h"
-#if !defined(LOG_ENABLED)
-#define LOG_INFO(format, ...)
-#define LOG_ERR(format, ...)
+#include <stdio.h>
+
+#if defined(DRIVER_LOG_SEVERITY) && (DRIVER_LOG_SEVERITY >= LOG_SEVERITY_EMERG)
+#define LOG_EMERG(format, ...) \
+ fprintf(stderr, format, ##__VA_ARGS__); \
+ fflush(stderr); \
+ exit(-1)
#else
-#define LOG_INFO(format, ...) fprintf(stdout, format, ##__VA_ARGS__)
+#define LOG_EMERG(format, ...)
+#endif
+
+#if defined(DRIVER_LOG_SEVERITY) && (DRIVER_LOG_SEVERITY >= LOG_SEVERITY_ALERT)
+#define LOG_ALERT(format, ...) \
+ fprintf(stderr, format, ##__VA_ARGS__); \
+ fflush(stderr); \
+ exit(-1)
+#else
+#define LOG_ALERT(format, ...)
+#endif
+
+#if defined(DRIVER_LOG_SEVERITY) && (DRIVER_LOG_SEVERITY >= LOG_SEVERITY_CRIT)
+#define LOG_CRIT(format, ...) \
+ fprintf(stderr, format, ##__VA_ARGS__); \
+ fflush(stderr); \
+ exit(-1)
+#else
+#define LOG_CRIT(format, ...)
+#endif
+
+#if defined(DRIVER_LOG_SEVERITY) && (DRIVER_LOG_SEVERITY >= LOG_SEVERITY_ERR)
#define LOG_ERR(format, ...) \
fprintf(stderr, format, ##__VA_ARGS__); \
fflush(stderr)
+#else
+#define LOG_ERR(format, ...)
+#endif
+
+#if defined(DRIVER_LOG_SEVERITY) && (DRIVER_LOG_SEVERITY >= LOG_SEVERITY_WARN)
+#define LOG_WARN(format, ...) fprintf(stdout, format, ##__VA_ARGS__)
+#else
+#define LOG_WARN(format, ...)
+#endif
+#if defined(DRIVER_LOG_SEVERITY) && (DRIVER_LOG_SEVERITY >= LOG_SEVERITY_NOTICE)
+#define LOG_NOTICE(format, ...) fprintf(stdout, format, ##__VA_ARGS__)
+#else
+#define LOG_NOTICE(format, ...)
+#endif
+
+#if defined(DRIVER_LOG_SEVERITY) && (DRIVER_LOG_SEVERITY >= LOG_SEVERITY_INFO)
+#define LOG_INFO(format, ...) fprintf(stdout, format, ##__VA_ARGS__)
+#else
+#define LOG_INFO(format, ...)
+#endif
+
+#if defined(DRIVER_LOG_SEVERITY) && (DRIVER_LOG_SEVERITY >= LOG_SEVERITY_DEBUG)
+#define LOG_DEBUG(format, ...) fprintf(stdout, format, ##__VA_ARGS__)
+#else
+#define LOG_DEBUG(format, ...)
#endif
#if defined(ASSERT_DISABLE)