aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristofer Jonsson <kristofer.jonsson@arm.com>2020-08-05 11:46:52 +0200
committerKristofer Jonsson <kristofer.jonsson@arm.com>2020-08-11 16:15:09 +0200
commitc05c98831fda3cc1b6138f2a888ce01caebb9983 (patch)
tree050d0d156654fed2bb4140e53e574eaf8e51adae
parent3c4391763b45c693e54b17b47e9bd65f0b3427c6 (diff)
downloadethos-u-core-driver-c05c98831fda3cc1b6138f2a888ce01caebb9983.tar.gz
Set default log severity in headers
Change-Id: Ia984092db29cc5f1294ecdcf5c2b6b744c6d32b2
-rw-r--r--CMakeLists.txt31
-rw-r--r--src/ethosu_common.h31
2 files changed, 34 insertions, 28 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0dab28f..b857280 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -27,7 +27,10 @@ project(ethosu_core_driver VERSION 0.0.1)
option(DRIVER_PMU_AUTOINIT "Enable PMU boot auto-initialization" 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")
+
+set(LOG_NAMES emerg alert crit err warning notice info debug)
+set(ETHOSU_LOG_SEVERITY "info" CACHE STRING "Driver log severity level ${LOG_NAMES}")
+set_property(CACHE ETHOSU_LOG_SEVERITY PROPERTY STRINGS ${LOG_NAMES})
#
# Global settings
@@ -49,12 +52,10 @@ else()
message(FATAL_ERROR "Unsupported compiler ${CMAKE_SYSTEM_PROCESSOR}.")
endif()
-# 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}")
+# Check that ETHOSU_LOG_SEVERITY has one of the supported levels
+list(FIND LOG_NAMES ${ETHOSU_LOG_SEVERITY} LOG_SEVERITY)
+if (${LOG_SEVERITY} EQUAL -1)
+ message(FATAL_ERROR "Unsupported log level ${ETHOSU_LOG_SEVERITY}")
endif()
# Enable PMU boot auto-initialization
@@ -75,18 +76,8 @@ 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()
+# Set the log level for the target
+target_compile_definitions(ethosu_core_driver PRIVATE ETHOSU_LOG_SEVERITY=${LOG_SEVERITY})
#
# Print build status
@@ -96,5 +87,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_SEVERITY : ${DRIVER_LOG_SEVERITY} (${DRIVER_LOG_SEVERITY_NAME})")
+message(STATUS "ETHOSU_LOG_SEVERITY : ${ETHOSU_LOG_SEVERITY}")
message(STATUS "*******************************************************")
diff --git a/src/ethosu_common.h b/src/ethosu_common.h
index b22bffd..04acea2 100644
--- a/src/ethosu_common.h
+++ b/src/ethosu_common.h
@@ -32,7 +32,22 @@
* Defines
******************************************************************************/
-#if defined(DRIVER_LOG_SEVERITY) && (DRIVER_LOG_SEVERITY >= LOG_SEVERITY_EMERG)
+// Log severity levels
+#define ETHOSU_LOG_EMERG 0
+#define ETHOSU_LOG_ALERT 1
+#define ETHOSU_LOG_CRIT 2
+#define ETHOSU_LOG_ERR 3
+#define ETHOSU_LOG_WARN 4
+#define ETHOSU_LOG_NOTICE 5
+#define ETHOSU_LOG_INFO 6
+#define ETHOSU_LOG_DEBUG 7
+
+// Define default log severity
+#ifndef ETHOSU_LOG_SEVERITY
+#define ETHOSU_LOG_SEVERITY ETHOSU_LOG_WARN
+#endif
+
+#if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_EMERG
#define LOG_EMERG(format, ...) \
fprintf(stderr, format, ##__VA_ARGS__); \
fflush(stderr); \
@@ -41,7 +56,7 @@
#define LOG_EMERG(format, ...)
#endif
-#if defined(DRIVER_LOG_SEVERITY) && (DRIVER_LOG_SEVERITY >= LOG_SEVERITY_ALERT)
+#if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_ALERT
#define LOG_ALERT(format, ...) \
fprintf(stderr, format, ##__VA_ARGS__); \
fflush(stderr); \
@@ -50,7 +65,7 @@
#define LOG_ALERT(format, ...)
#endif
-#if defined(DRIVER_LOG_SEVERITY) && (DRIVER_LOG_SEVERITY >= LOG_SEVERITY_CRIT)
+#if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_CRIT
#define LOG_CRIT(format, ...) \
fprintf(stderr, format, ##__VA_ARGS__); \
fflush(stderr); \
@@ -59,7 +74,7 @@
#define LOG_CRIT(format, ...)
#endif
-#if defined(DRIVER_LOG_SEVERITY) && (DRIVER_LOG_SEVERITY >= LOG_SEVERITY_ERR)
+#if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_ERR
#define LOG_ERR(format, ...) \
fprintf(stderr, format, ##__VA_ARGS__); \
fflush(stderr)
@@ -67,25 +82,25 @@
#define LOG_ERR(format, ...)
#endif
-#if defined(DRIVER_LOG_SEVERITY) && (DRIVER_LOG_SEVERITY >= LOG_SEVERITY_WARN)
+#if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_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)
+#if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_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)
+#if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_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)
+#if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_DEBUG
#define LOG_DEBUG(format, ...) fprintf(stdout, format, ##__VA_ARGS__)
#else
#define LOG_DEBUG(format, ...)