1 /*
2 * Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #ifndef NRFX_LOG_H__
33 #define NRFX_LOG_H__
34 #include<lk/debug.h>
35
36 // THIS IS A TEMPLATE FILE.
37 // It should be copied to a suitable location within the host environment into
38 // which nrfx is integrated, and the following macros should be provided with
39 // appropriate implementations.
40 // And this comment should be removed from the customized file.
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46
47 #ifndef NRFX_ENABLE_LOGGING
48 #define NRFX_ENABLE_LOGGING 0
49 #endif
50 /**
51 * @defgroup nrfx_log nrfx_log.h
52 * @{
53 * @ingroup nrfx
54 *
55 * @brief This file contains macros that should be implemented according to
56 * the needs of the host environment into which @em nrfx is integrated.
57 */
58
59
60 /**
61 * @brief Macro for logging a message with the severity level ERROR.
62 *
63 * @param format printf-style format string, optionally followed by arguments
64 * to be formatted and inserted in the resulting string.
65 */
66 #if NRFX_ENABLE_LOGGING
67 #define NRFX_LOG_ERROR(a...) dprintf(CRITICAL, "NRFX_ERROR:"); \
68 dprintf(CRITICAL, a); \
69 dprintf(CRITICAL,"\n")
70 #else
71 #define NRFX_LOG_ERROR(a...)
72 #endif
73
74 /**
75 * @brief Macro for logging a message with the severity level WARNING.
76 *
77 * @param format printf-style format string, optionally followed by arguments
78 * to be formatted and inserted in the resulting string.
79 */
80 #if NRFX_ENABLE_LOGGING
81 #define NRFX_LOG_WARNING(a...) dprintf(INFO, "NRFX_WARNING:"); \
82 dprintf(INFO, a); \
83 dprintf(INFO,"\n")
84 #else
85 #define NRFX_LOG_WARNING(a...)
86 #endif
87 /**
88 * @brief Macro for logging a message with the severity level INFO.
89 *
90 * @param format printf-style format string, optionally followed by arguments
91 * to be formatted and inserted in the resulting string.
92 */
93 #if NRFX_ENABLE_LOGGING
94 #define NRFX_LOG_INFO(a...) dprintf(INFO, "NRFX_INFO:"); \
95 dprintf(INFO, a); \
96 dprintf(INFO,"\n")
97 #else
98 #define NRFX_LOG_INFO(a...)
99 #endif
100 /**
101 * @brief Macro for logging a message with the severity level DEBUG.
102 *
103 * @param format printf-style format string, optionally followed by arguments
104 * to be formatted and inserted in the resulting string.
105 */
106 #if NRFX_ENABLE_LOGGING
107 #define NRFX_LOG_DEBUG(a...) dprintf(SPEW, "NRFX_DEBUG:"); \
108 dprintf(SPEW, a); \
109 dprintf(SPEW,"\n")
110 #else
111 #define NRFX_LOG_DEBUG(a...)
112 #endif
113
114 /**
115 * @brief Macro for logging a memory dump with the severity level ERROR.
116 *
117 * @param[in] p_memory Pointer to the memory region to be dumped.
118 * @param[in] length Length of the memory region in bytes.
119 */
120 #define NRFX_LOG_HEXDUMP_ERROR(p_memory, length)
121
122 /**
123 * @brief Macro for logging a memory dump with the severity level WARNING.
124 *
125 * @param[in] p_memory Pointer to the memory region to be dumped.
126 * @param[in] length Length of the memory region in bytes.
127 */
128 #define NRFX_LOG_HEXDUMP_WARNING(p_memory, length)
129
130 /**
131 * @brief Macro for logging a memory dump with the severity level INFO.
132 *
133 * @param[in] p_memory Pointer to the memory region to be dumped.
134 * @param[in] length Length of the memory region in bytes.
135 */
136 #define NRFX_LOG_HEXDUMP_INFO(p_memory, length)
137
138 /**
139 * @brief Macro for logging a memory dump with the severity level DEBUG.
140 *
141 * @param[in] p_memory Pointer to the memory region to be dumped.
142 * @param[in] length Length of the memory region in bytes.
143 */
144 #define NRFX_LOG_HEXDUMP_DEBUG(p_memory, length)
145
146
147 /**
148 * @brief Macro for getting the textual representation of a given error code.
149 *
150 * @param[in] error_code Error code.
151 *
152 * @return String containing the textual representation of the error code.
153 */
154 #define NRFX_LOG_ERROR_STRING_GET(error_code) nrfx_get_err_str(error_code)
155
156 /** @} */
157 #define NRFX_ERR_STRING(x) \
158 case NRFX_ERROR_##x: \
159 return "NRFX_ERROR_"#x;
160
nrfx_get_err_str(nrfx_err_t code)161 static inline const char* nrfx_get_err_str(nrfx_err_t code) {
162 switch(code) {
163 case NRFX_SUCCESS:
164 return "NRFX_SUCCESS";
165 case NRFX_ERROR_NULL:
166 return "NRFX_ERROR_NULL";
167 NRFX_ERR_STRING(INTERNAL)
168 NRFX_ERR_STRING(NO_MEM)
169 NRFX_ERR_STRING(NOT_SUPPORTED)
170 NRFX_ERR_STRING(INVALID_PARAM)
171 NRFX_ERR_STRING(INVALID_STATE)
172 NRFX_ERR_STRING(INVALID_LENGTH)
173 NRFX_ERR_STRING(TIMEOUT)
174 NRFX_ERR_STRING(FORBIDDEN)
175 NRFX_ERR_STRING(INVALID_ADDR)
176 NRFX_ERR_STRING(BUSY)
177 NRFX_ERR_STRING(ALREADY_INITIALIZED)
178 NRFX_ERR_STRING(DRV_TWI_ERR_OVERRUN)
179 NRFX_ERR_STRING(DRV_TWI_ERR_ANACK)
180 NRFX_ERR_STRING(DRV_TWI_ERR_DNACK)
181 default:
182 return "UNKNOWN NRFX ERROR CODE";
183 }
184 }
185
186 #ifdef __cplusplus
187 }
188 #endif
189
190 #endif // NRFX_LOG_H__
191