1 /*
2  * Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef NRFX_LOG_H__
8 #define NRFX_LOG_H__
9 
10 #include <zephyr/logging/log.h>
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 #define NRFX_MODULE_PREFIX  _CONCAT(NRFX_, NRFX_LOG_MODULE)
17 /*
18  * The following macros from nrfx_config control the log messages coming from
19  * a given module:
20  * - NRFX_<module>_CONFIG_LOG_ENABLED enables the messages (when set to 1)
21  * - NRFX_<module>_CONFIG_LOG_LEVEL specifies the severity level of the messages
22  *   that are to be output.
23  */
24 #if !IS_ENABLED(_CONCAT(NRFX_MODULE_PREFIX, _CONFIG_LOG_ENABLED))
25 #define NRFX_MODULE_CONFIG_LOG_LEVEL 0
26 #else
27 #define NRFX_MODULE_CONFIG_LOG_LEVEL \
28 	_CONCAT(NRFX_MODULE_PREFIX, _CONFIG_LOG_LEVEL)
29 #endif
30 
31 #if	NRFX_MODULE_CONFIG_LOG_LEVEL == 0
32 #define NRFX_MODULE_LOG_LEVEL		LOG_LEVEL_NONE
33 #elif	NRFX_MODULE_CONFIG_LOG_LEVEL == 1
34 #define NRFX_MODULE_LOG_LEVEL		LOG_LEVEL_ERR
35 #elif	NRFX_MODULE_CONFIG_LOG_LEVEL == 2
36 #define NRFX_MODULE_LOG_LEVEL		LOG_LEVEL_WRN
37 #elif	NRFX_MODULE_CONFIG_LOG_LEVEL == 3
38 #define NRFX_MODULE_LOG_LEVEL		LOG_LEVEL_INF
39 #elif	NRFX_MODULE_CONFIG_LOG_LEVEL == 4
40 #define NRFX_MODULE_LOG_LEVEL		LOG_LEVEL_DBG
41 #endif
42 LOG_MODULE_REGISTER(NRFX_MODULE_PREFIX, NRFX_MODULE_LOG_LEVEL);
43 
44 /**
45  * @defgroup nrfx_log nrfx_log.h
46  * @{
47  * @ingroup nrfx
48  *
49  * @brief This file contains macros that should be implemented according to
50  *        the needs of the host environment into which @em nrfx is integrated.
51  */
52 
53 /**
54  * @brief Macro for logging a message with the severity level ERROR.
55  *
56  * @param ... printf-style format string, optionally followed by arguments
57  *            to be formatted and inserted in the resulting string.
58  */
59 #define NRFX_LOG_ERROR(...)  LOG_ERR(__VA_ARGS__)
60 
61 /**
62  * @brief Macro for logging a message with the severity level WARNING.
63  *
64  * @param ... printf-style format string, optionally followed by arguments
65  *            to be formatted and inserted in the resulting string.
66  */
67 #define NRFX_LOG_WARNING(...)  LOG_WRN(__VA_ARGS__)
68 
69 /**
70  * @brief Macro for logging a message with the severity level INFO.
71  *
72  * @param ... printf-style format string, optionally followed by arguments
73  *            to be formatted and inserted in the resulting string.
74  */
75 #define NRFX_LOG_INFO(...)  LOG_INF(__VA_ARGS__)
76 
77 /**
78  * @brief Macro for logging a message with the severity level DEBUG.
79  *
80  * @param ... printf-style format string, optionally followed by arguments
81  *            to be formatted and inserted in the resulting string.
82  */
83 #define NRFX_LOG_DEBUG(...)  LOG_DBG(__VA_ARGS__)
84 
85 /**
86  * @brief Macro for logging a memory dump with the severity level ERROR.
87  *
88  * @param[in] p_memory Pointer to the memory region to be dumped.
89  * @param[in] length   Length of the memory region in bytes.
90  */
91 #define NRFX_LOG_HEXDUMP_ERROR(p_memory, length) \
92 	LOG_HEXDUMP_ERR(p_memory, length, "")
93 
94 /**
95  * @brief Macro for logging a memory dump with the severity level WARNING.
96  *
97  * @param[in] p_memory Pointer to the memory region to be dumped.
98  * @param[in] length   Length of the memory region in bytes.
99  */
100 #define NRFX_LOG_HEXDUMP_WARNING(p_memory, length) \
101 	LOG_HEXDUMP_WRN(p_memory, length, "")
102 
103 /**
104  * @brief Macro for logging a memory dump with the severity level INFO.
105  *
106  * @param[in] p_memory Pointer to the memory region to be dumped.
107  * @param[in] length   Length of the memory region in bytes.
108  */
109 #define NRFX_LOG_HEXDUMP_INFO(p_memory, length) \
110 	LOG_HEXDUMP_INF(p_memory, length, "")
111 
112 /**
113  * @brief Macro for logging a memory dump with the severity level DEBUG.
114  *
115  * @param[in] p_memory Pointer to the memory region to be dumped.
116  * @param[in] length   Length of the memory region in bytes.
117  */
118 #define NRFX_LOG_HEXDUMP_DEBUG(p_memory, length) \
119 	LOG_HEXDUMP_DBG(p_memory, length, "")
120 
121 /**
122  * @brief Macro for getting the textual representation of a given error code.
123  *
124  * @param[in] error_code Error code.
125  *
126  * @return String containing the textual representation of the error code.
127  */
128 #define NRFX_LOG_ERROR_STRING_GET(error_code)  nrfx_error_string_get(error_code)
129 extern char const *nrfx_error_string_get(nrfx_err_t code);
130 
131 /** @} */
132 
133 #ifdef __cplusplus
134 }
135 #endif
136 
137 #endif // NRFX_LOG_H__
138