The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Thu Nov 08 11:45:42 2018 +0000
Revision:
171:3a7713b1edbc
Parent:
TARGET_NRF51_DONGLE/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/libraries/util/nrf_log.h@169:a7c7b631e539
mbed library. Release version 164

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 143:86740a56073b 1 #ifndef NRF_LOG_H_
AnnaBridge 143:86740a56073b 2 #define NRF_LOG_H_
AnnaBridge 143:86740a56073b 3
AnnaBridge 143:86740a56073b 4 #ifndef DOXYGEN
AnnaBridge 143:86740a56073b 5
AnnaBridge 143:86740a56073b 6 #include <stdint.h>
AnnaBridge 143:86740a56073b 7 #include <stdarg.h>
AnnaBridge 143:86740a56073b 8 #include <app_util.h>
AnnaBridge 143:86740a56073b 9
AnnaBridge 143:86740a56073b 10 #ifndef NRF_LOG_USES_RTT
AnnaBridge 143:86740a56073b 11 #define NRF_LOG_USES_RTT 0
AnnaBridge 143:86740a56073b 12 #endif
AnnaBridge 143:86740a56073b 13
AnnaBridge 143:86740a56073b 14 #ifndef NRF_LOG_USES_UART
AnnaBridge 143:86740a56073b 15 #define NRF_LOG_USES_UART 0
AnnaBridge 143:86740a56073b 16 #endif
AnnaBridge 143:86740a56073b 17
AnnaBridge 143:86740a56073b 18 #ifndef NRF_LOG_USES_RAW_UART
AnnaBridge 143:86740a56073b 19 #define NRF_LOG_USES_RAW_UART 0
AnnaBridge 143:86740a56073b 20 #endif
AnnaBridge 143:86740a56073b 21
AnnaBridge 143:86740a56073b 22 #ifndef NRF_LOG_USES_COLORS
AnnaBridge 143:86740a56073b 23 #define NRF_LOG_USES_COLORS 1
AnnaBridge 143:86740a56073b 24 #endif
AnnaBridge 143:86740a56073b 25
AnnaBridge 143:86740a56073b 26 #if NRF_LOG_USES_COLORS == 1
AnnaBridge 143:86740a56073b 27 #define NRF_LOG_COLOR_DEFAULT "\x1B[0m"
AnnaBridge 143:86740a56073b 28 #define NRF_LOG_COLOR_BLACK "\x1B[1;30m"
AnnaBridge 143:86740a56073b 29 #define NRF_LOG_COLOR_RED "\x1B[1;31m"
AnnaBridge 143:86740a56073b 30 #define NRF_LOG_COLOR_GREEN "\x1B[1;32m"
AnnaBridge 143:86740a56073b 31 #define NRF_LOG_COLOR_YELLOW "\x1B[1;33m"
AnnaBridge 143:86740a56073b 32 #define NRF_LOG_COLOR_BLUE "\x1B[1;34m"
AnnaBridge 143:86740a56073b 33 #define NRF_LOG_COLOR_MAGENTA "\x1B[1;35m"
AnnaBridge 143:86740a56073b 34 #define NRF_LOG_COLOR_CYAN "\x1B[1;36m"
AnnaBridge 143:86740a56073b 35 #define NRF_LOG_COLOR_WHITE "\x1B[1;37m"
AnnaBridge 143:86740a56073b 36 #else
AnnaBridge 143:86740a56073b 37 #define NRF_LOG_COLOR_DEFAULT
AnnaBridge 143:86740a56073b 38 #define NRF_LOG_COLOR_BLACK
AnnaBridge 143:86740a56073b 39 #define NRF_LOG_COLOR_RED
AnnaBridge 143:86740a56073b 40 #define NRF_LOG_COLOR_GREEN
AnnaBridge 143:86740a56073b 41 #define NRF_LOG_COLOR_YELLOW
AnnaBridge 143:86740a56073b 42 #define NRF_LOG_COLOR_BLUE
AnnaBridge 143:86740a56073b 43 #define NRF_LOG_COLOR_MAGENTA
AnnaBridge 143:86740a56073b 44 #define NRF_LOG_COLOR_CYAN
AnnaBridge 143:86740a56073b 45 #define NRF_LOG_COLOR_WHITE
AnnaBridge 143:86740a56073b 46 #endif
AnnaBridge 143:86740a56073b 47
AnnaBridge 143:86740a56073b 48 #if defined(NRF_LOG_USES_RTT) && NRF_LOG_USES_RTT == 1
AnnaBridge 143:86740a56073b 49
AnnaBridge 143:86740a56073b 50 #define LOG_TERMINAL_NORMAL (0)
AnnaBridge 143:86740a56073b 51 #define LOG_TERMINAL_ERROR (1)
AnnaBridge 143:86740a56073b 52 #define LOG_TERMINAL_INPUT (0)
AnnaBridge 143:86740a56073b 53
AnnaBridge 143:86740a56073b 54 /**@brief Function for initializing the SEGGER RTT logger.
AnnaBridge 143:86740a56073b 55 *
AnnaBridge 143:86740a56073b 56 * @details See <a href="https://www.segger.com/jlink-rtt.html" target="_blank">segger.com</a>
AnnaBridge 143:86740a56073b 57 * for information about SEGGER Real Time Transfer (RTT).
AnnaBridge 143:86740a56073b 58 *
AnnaBridge 143:86740a56073b 59 * This function is available only when NRF_LOG_USES_RTT is defined as 1.
AnnaBridge 143:86740a56073b 60 *
AnnaBridge 143:86740a56073b 61 * @note Do not call this function directly. Use the macro @ref NRF_LOG_INIT instead.
AnnaBridge 143:86740a56073b 62 *
AnnaBridge 143:86740a56073b 63 * @retval NRF_SUCCESS If initialization was successful.
AnnaBridge 143:86740a56073b 64 * @retval NRF_ERROR Otherwise.
AnnaBridge 143:86740a56073b 65 */
AnnaBridge 143:86740a56073b 66 uint32_t log_rtt_init(void);
AnnaBridge 143:86740a56073b 67
AnnaBridge 143:86740a56073b 68 /**@brief Function for writing a printf string using RTT.
AnnaBridge 143:86740a56073b 69 *
AnnaBridge 143:86740a56073b 70 * @details The printf implementation in SEGGER's RTT is more efficient than
AnnaBridge 143:86740a56073b 71 * the standard implementation. However, printf requires more processor time
AnnaBridge 143:86740a56073b 72 * than other logging functions. Therefore, applications that require logging
AnnaBridge 143:86740a56073b 73 * but need it to interfere as little as possible with the execution, should
AnnaBridge 143:86740a56073b 74 * avoid using printf.
AnnaBridge 143:86740a56073b 75 *
AnnaBridge 143:86740a56073b 76 * This function is available only when NRF_LOG_USES_RTT is defined as 1.
AnnaBridge 143:86740a56073b 77 *
AnnaBridge 143:86740a56073b 78 * @note Do not call this function directly. Use one of the following macros instead:
AnnaBridge 143:86740a56073b 79 * - @ref NRF_LOG_PRINTF
AnnaBridge 143:86740a56073b 80 * - @ref NRF_LOG_PRINTF_DEBUG
AnnaBridge 143:86740a56073b 81 * - @ref NRF_LOG_PRINTF_ERROR
AnnaBridge 143:86740a56073b 82 *
AnnaBridge 143:86740a56073b 83 * @param terminal_index Segger RTT terminal index to use as output.
AnnaBridge 143:86740a56073b 84 * @param format_msg Printf format string.
AnnaBridge 143:86740a56073b 85 */
AnnaBridge 143:86740a56073b 86 void log_rtt_printf(int terminal_index, char * format_msg, ...);
AnnaBridge 143:86740a56073b 87
AnnaBridge 143:86740a56073b 88 /**@brief Function for writing a string using RTT.
AnnaBridge 143:86740a56073b 89 *
AnnaBridge 143:86740a56073b 90 * @details The string to write must be null-terminated, but the null termination will not be stored
AnnaBridge 143:86740a56073b 91 * in the ring buffer.
AnnaBridge 143:86740a56073b 92 * The impact of running this function should be very low compared to writing to UART.
AnnaBridge 143:86740a56073b 93 *
AnnaBridge 143:86740a56073b 94 * This function is available only when NRF_LOG_USES_RTT is defined as 1.
AnnaBridge 143:86740a56073b 95 *
AnnaBridge 143:86740a56073b 96 * @note Do not call this function directly. Use one of the following macros instead:
AnnaBridge 143:86740a56073b 97 * - @ref NRF_LOG
AnnaBridge 143:86740a56073b 98 * - @ref NRF_LOG_DEBUG
AnnaBridge 143:86740a56073b 99 * - @ref NRF_LOG_ERROR
AnnaBridge 143:86740a56073b 100 *
AnnaBridge 143:86740a56073b 101 * @param terminal_index Segger RTT terminal index to use as output.
AnnaBridge 143:86740a56073b 102 * @param num_args Number of arguments.
AnnaBridge 143:86740a56073b 103 */
AnnaBridge 143:86740a56073b 104 void log_rtt_write_string(int terminal_index, int num_args, ...);
AnnaBridge 143:86740a56073b 105
AnnaBridge 143:86740a56073b 106 /**@brief Function for writing an integer as HEX using RTT.
AnnaBridge 143:86740a56073b 107 *
AnnaBridge 143:86740a56073b 108 * The output data is formatted as, for example, 0x89ABCDEF.
AnnaBridge 143:86740a56073b 109 *
AnnaBridge 143:86740a56073b 110 * This function is available only when NRF_LOG_USES_RTT is defined as 1.
AnnaBridge 143:86740a56073b 111 *
AnnaBridge 143:86740a56073b 112 * @note Do not call this function directly. Use one of the following macros instead:
AnnaBridge 143:86740a56073b 113 * - @ref NRF_LOG_HEX
AnnaBridge 143:86740a56073b 114 * - @ref NRF_LOG_HEX_DEBUG
AnnaBridge 143:86740a56073b 115 * - @ref NRF_LOG_HEX_ERROR
AnnaBridge 143:86740a56073b 116 *
AnnaBridge 143:86740a56073b 117 * @param terminal_index Segger RTT terminal index to use as output.
AnnaBridge 143:86740a56073b 118 * @param value Integer value to be printed as HEX.
AnnaBridge 143:86740a56073b 119 */
AnnaBridge 143:86740a56073b 120 void log_rtt_write_hex(int terminal_index, uint32_t value);
AnnaBridge 143:86740a56073b 121
AnnaBridge 143:86740a56073b 122 /**@brief Function for writing a single character as HEX using RTT.
AnnaBridge 143:86740a56073b 123 *
AnnaBridge 143:86740a56073b 124 * The output string is formatted as, for example, AA.
AnnaBridge 143:86740a56073b 125 *
AnnaBridge 143:86740a56073b 126 * This function is available only when NRF_LOG_USES_RTT is defined as 1.
AnnaBridge 143:86740a56073b 127 *
AnnaBridge 143:86740a56073b 128 * @note Do not call this function directly. Use one of the following macros instead:
AnnaBridge 143:86740a56073b 129 * - @ref NRF_LOG_HEX_CHAR
AnnaBridge 143:86740a56073b 130 * - @ref NRF_LOG_HEX_CHAR_DEBUG
AnnaBridge 143:86740a56073b 131 * - @ref NRF_LOG_HEX_CHAR_ERROR
AnnaBridge 143:86740a56073b 132 *
AnnaBridge 143:86740a56073b 133 * @param terminal_index Segger RTT terminal index to use as output.
AnnaBridge 143:86740a56073b 134 * @param value Character to print as HEX.
AnnaBridge 143:86740a56073b 135 */
AnnaBridge 143:86740a56073b 136 void log_rtt_write_hex_char(int terminal_index, uint8_t value);
AnnaBridge 143:86740a56073b 137
AnnaBridge 143:86740a56073b 138 /**@brief Function for checking if data is available in the input buffer.
AnnaBridge 143:86740a56073b 139 *
AnnaBridge 143:86740a56073b 140 * This function is available only when NRF_LOG_USES_RTT is defined as 1.
AnnaBridge 143:86740a56073b 141 *
AnnaBridge 143:86740a56073b 142 * @note Do not call this function directly. Use @ref NRF_LOG_HAS_INPUT instead.
AnnaBridge 143:86740a56073b 143 *
AnnaBridge 143:86740a56073b 144 * @retval 1 If characters are available to read.
AnnaBridge 143:86740a56073b 145 * @retval 0 If no characters are available.
AnnaBridge 143:86740a56073b 146 */
AnnaBridge 143:86740a56073b 147 int log_rtt_has_input(void);
AnnaBridge 143:86740a56073b 148
AnnaBridge 143:86740a56073b 149 /**@brief Function for reading one character from the input buffer.
AnnaBridge 143:86740a56073b 150 *
AnnaBridge 143:86740a56073b 151 * @param[out] p_char Pointer where to store the character.
AnnaBridge 143:86740a56073b 152 *
AnnaBridge 143:86740a56073b 153 * This function is available only when NRF_LOG_USES_RTT is defined as 1.
AnnaBridge 143:86740a56073b 154 *
AnnaBridge 143:86740a56073b 155 * @note Do not call this function directly. Use @ref NRF_LOG_READ_INPUT instead.
AnnaBridge 143:86740a56073b 156 *
AnnaBridge 143:86740a56073b 157 * @retval NRF_SUCCESS If the character was read out.
AnnaBridge 143:86740a56073b 158 * @retval NRF_ERROR_INVALID_DATA If no character could be read.
AnnaBridge 143:86740a56073b 159 */
AnnaBridge 143:86740a56073b 160 uint32_t log_rtt_read_input(char* p_char);
AnnaBridge 143:86740a56073b 161
AnnaBridge 143:86740a56073b 162 #define NRF_LOG_INIT() log_rtt_init() /*!< Initialize the module. */
AnnaBridge 143:86740a56073b 163
AnnaBridge 143:86740a56073b 164 #define NRF_LOG_PRINTF(...) log_rtt_printf(LOG_TERMINAL_NORMAL, ##__VA_ARGS__) /*!< Print a log message using printf. */
AnnaBridge 143:86740a56073b 165 #define NRF_LOG_PRINTF_DEBUG(...) log_rtt_printf(LOG_TERMINAL_NORMAL, ##__VA_ARGS__) /*!< If DEBUG is set, print a log message using printf. */
AnnaBridge 143:86740a56073b 166 #define NRF_LOG_PRINTF_ERROR(...) log_rtt_printf(LOG_TERMINAL_ERROR, ##__VA_ARGS__) /*!< Print a log message using printf to the error stream. */
AnnaBridge 143:86740a56073b 167
AnnaBridge 143:86740a56073b 168 #define NRF_LOG(...) log_rtt_write_string(LOG_TERMINAL_NORMAL, NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__) /*!< Print a log message. The input string must be null-terminated. */
AnnaBridge 143:86740a56073b 169 #define NRF_LOG_DEBUG(...) log_rtt_write_string(LOG_TERMINAL_NORMAL, NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__) /*!< If DEBUG is set, print a log message. The input string must be null-terminated. */
AnnaBridge 143:86740a56073b 170 #define NRF_LOG_ERROR(...) log_rtt_write_string(LOG_TERMINAL_ERROR, NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__) /*!< Print a log message to the error stream. The input string must be null-terminated. */
AnnaBridge 143:86740a56073b 171
AnnaBridge 143:86740a56073b 172 #define NRF_LOG_HEX(val) log_rtt_write_hex(LOG_TERMINAL_NORMAL, val) /*!< Log an integer as HEX value (example output: 0x89ABCDEF). */
AnnaBridge 143:86740a56073b 173 #define NRF_LOG_HEX_DEBUG(val) log_rtt_write_hex(LOG_TERMINAL_NORMAL, val) /*!< If DEBUG is set, log an integer as HEX value (example output: 0x89ABCDEF). */
AnnaBridge 143:86740a56073b 174 #define NRF_LOG_HEX_ERROR(val) log_rtt_write_hex(LOG_TERMINAL_ERROR, val) /*!< Log an integer as HEX value to the error stream (example output: 0x89ABCDEF). */
AnnaBridge 143:86740a56073b 175
AnnaBridge 143:86740a56073b 176 #define NRF_LOG_HEX_CHAR(val) log_rtt_write_hex_char(LOG_TERMINAL_NORMAL, val) /*!< Log a character as HEX value (example output: AA). */
AnnaBridge 143:86740a56073b 177 #define NRF_LOG_HEX_CHAR_DEBUG(val) log_rtt_write_hex_char(LOG_TERMINAL_NORMAL, val) /*!< If DEBUG is set, log a character as HEX value (example output: AA). */
AnnaBridge 143:86740a56073b 178 #define NRF_LOG_HEX_CHAR_ERROR(val) log_rtt_write_hex_char(LOG_TERMINAL_ERROR, val) /*!< Log a character as HEX value to the error stream (example output: AA). */
AnnaBridge 143:86740a56073b 179
AnnaBridge 143:86740a56073b 180 #define NRF_LOG_HAS_INPUT() log_rtt_has_input() /*!< Check if the input buffer has unconsumed characters. */
AnnaBridge 143:86740a56073b 181 #define NRF_LOG_READ_INPUT(p_char) log_rtt_read_input(p_char) /*!< Consume a character from the input buffer. */
AnnaBridge 143:86740a56073b 182
AnnaBridge 143:86740a56073b 183 #if !defined(DEBUG) && !defined(DOXYGEN)
AnnaBridge 143:86740a56073b 184
AnnaBridge 143:86740a56073b 185 #undef NRF_LOG_DEBUG
AnnaBridge 143:86740a56073b 186 #define NRF_LOG_DEBUG(...)
AnnaBridge 143:86740a56073b 187
AnnaBridge 143:86740a56073b 188 #undef NRF_LOG_STR_DEBUG
AnnaBridge 143:86740a56073b 189 #define NRF_LOG_STR_DEBUG(...)
AnnaBridge 143:86740a56073b 190
AnnaBridge 143:86740a56073b 191 #undef NRF_LOG_HEX_DEBUG
AnnaBridge 143:86740a56073b 192 #define NRF_LOG_HEX_DEBUG(...)
AnnaBridge 143:86740a56073b 193
AnnaBridge 143:86740a56073b 194 #undef NRF_LOG_HEX_CHAR_DEBUG
AnnaBridge 143:86740a56073b 195 #define NRF_LOG_HEX_CHAR_DEBUG(...)
AnnaBridge 143:86740a56073b 196
AnnaBridge 143:86740a56073b 197 #endif // !defined(DEBUG) && !defined(DOXYGEN)
AnnaBridge 143:86740a56073b 198
AnnaBridge 143:86740a56073b 199 #elif defined(NRF_LOG_USES_UART) && NRF_LOG_USES_UART == 1
AnnaBridge 143:86740a56073b 200
AnnaBridge 143:86740a56073b 201 /**@brief Function for initializing the UART logger.
AnnaBridge 143:86740a56073b 202 *
AnnaBridge 143:86740a56073b 203 * This function is available only when NRF_LOG_USES_UART is defined as 1.
AnnaBridge 143:86740a56073b 204 *
AnnaBridge 143:86740a56073b 205 * @note Do not call this function directly. Use the macro @ref NRF_LOG_INIT instead.
AnnaBridge 143:86740a56073b 206 *
AnnaBridge 143:86740a56073b 207 * @retval NRF_SUCCESS If initialization was successful.
AnnaBridge 143:86740a56073b 208 * @retval NRF_ERROR Otherwise.
AnnaBridge 143:86740a56073b 209 */
AnnaBridge 143:86740a56073b 210 uint32_t log_uart_init(void);
AnnaBridge 143:86740a56073b 211
AnnaBridge 143:86740a56073b 212 /**@brief Function for logging a printf string to UART.
AnnaBridge 143:86740a56073b 213 *
AnnaBridge 143:86740a56073b 214 * @details Printf requires more processor time
AnnaBridge 143:86740a56073b 215 * than other logging functions. Therefore, applications that require logging
AnnaBridge 143:86740a56073b 216 * but need it to interfere as little as possible with the execution, should
AnnaBridge 143:86740a56073b 217 * avoid using printf.
AnnaBridge 143:86740a56073b 218 *
AnnaBridge 143:86740a56073b 219 * This function is available only when NRF_LOG_USES_UART is defined as 1.
AnnaBridge 143:86740a56073b 220 *
AnnaBridge 143:86740a56073b 221 * @note This function is non-blocking. If too much data is sent to the UART,
AnnaBridge 143:86740a56073b 222 * some characters might be skipped.
AnnaBridge 143:86740a56073b 223 *
AnnaBridge 143:86740a56073b 224 * @note Do not call this function directly. Use one of the following macros instead:
AnnaBridge 143:86740a56073b 225 * - @ref NRF_LOG_PRINTF
AnnaBridge 143:86740a56073b 226 * - @ref NRF_LOG_PRINTF_DEBUG
AnnaBridge 143:86740a56073b 227 * - @ref NRF_LOG_PRINTF_ERROR
AnnaBridge 143:86740a56073b 228 *
AnnaBridge 143:86740a56073b 229 * @param format_msg Printf format string.
AnnaBridge 143:86740a56073b 230 */
AnnaBridge 143:86740a56073b 231 void log_uart_printf(const char * format_msg, ...);
AnnaBridge 143:86740a56073b 232
AnnaBridge 143:86740a56073b 233 /**@brief Function for logging a single character to UART.
AnnaBridge 143:86740a56073b 234 *
AnnaBridge 143:86740a56073b 235 * This function is available only when NRF_LOG_USES_UART is defined as 1.
AnnaBridge 143:86740a56073b 236 *
AnnaBridge 143:86740a56073b 237 * @param c Character.
AnnaBridge 143:86740a56073b 238 */
AnnaBridge 143:86740a56073b 239 void log_uart_write_char(const char c);
AnnaBridge 143:86740a56073b 240
AnnaBridge 143:86740a56073b 241 /**@brief Function for logging null-terminated strings to UART.
AnnaBridge 143:86740a56073b 242 *
AnnaBridge 143:86740a56073b 243 * @details This function is more efficient than using printf.
AnnaBridge 143:86740a56073b 244 * The null termination will not be logged.
AnnaBridge 143:86740a56073b 245 *
AnnaBridge 143:86740a56073b 246 * This function is available only when NRF_LOG_USES_UART is defined as 1.
AnnaBridge 143:86740a56073b 247 *
AnnaBridge 143:86740a56073b 248 * @note Do not call this function directly. Use one of the following macros instead:
AnnaBridge 143:86740a56073b 249 * - @ref NRF_LOG
AnnaBridge 143:86740a56073b 250 * - @ref NRF_LOG_DEBUG
AnnaBridge 143:86740a56073b 251 * - @ref NRF_LOG_ERROR
AnnaBridge 143:86740a56073b 252 *
AnnaBridge 143:86740a56073b 253 * @param num_args Number of arguments.
AnnaBridge 143:86740a56073b 254 */
AnnaBridge 143:86740a56073b 255 void log_uart_write_string_many(int num_args, ...);
AnnaBridge 143:86740a56073b 256
AnnaBridge 143:86740a56073b 257
AnnaBridge 143:86740a56073b 258 /**@brief Function for logging a null-terminated string to UART.
AnnaBridge 143:86740a56073b 259 *
AnnaBridge 143:86740a56073b 260 * @details This function is more efficient than using printf.
AnnaBridge 143:86740a56073b 261 * The null termination will not be logged.
AnnaBridge 143:86740a56073b 262 *
AnnaBridge 143:86740a56073b 263 * This function is available only when NRF_LOG_USES_UART is defined as 1.
AnnaBridge 143:86740a56073b 264 *
AnnaBridge 143:86740a56073b 265 * @note Do not call this function directly. Use one of the following macros instead:
AnnaBridge 143:86740a56073b 266 * - @ref NRF_LOG
AnnaBridge 143:86740a56073b 267 * - @ref NRF_LOG_DEBUG
AnnaBridge 143:86740a56073b 268 * - @ref NRF_LOG_ERROR
AnnaBridge 143:86740a56073b 269 *
AnnaBridge 143:86740a56073b 270 * @param msg Null-terminated string.
AnnaBridge 143:86740a56073b 271 */
AnnaBridge 143:86740a56073b 272 void log_uart_write_string(const char* msg);
AnnaBridge 143:86740a56073b 273
AnnaBridge 143:86740a56073b 274
AnnaBridge 143:86740a56073b 275 /**@brief Function for logging an integer value as HEX to UART.
AnnaBridge 143:86740a56073b 276 *
AnnaBridge 143:86740a56073b 277 * @details The output data is formatted as, for example, 0x89ABCDEF.
AnnaBridge 143:86740a56073b 278 * This function is more efficient than printf.
AnnaBridge 143:86740a56073b 279 *
AnnaBridge 143:86740a56073b 280 * This function is available only when NRF_LOG_USES_UART is defined as 1.
AnnaBridge 143:86740a56073b 281 *
AnnaBridge 143:86740a56073b 282 * @note This function is non-blocking. If too much data is sent to the UART,
AnnaBridge 143:86740a56073b 283 * some characters might be skipped.
AnnaBridge 143:86740a56073b 284 *
AnnaBridge 143:86740a56073b 285 * @note Do not call this function directly. Use one of the following macros instead:
AnnaBridge 143:86740a56073b 286 * - @ref NRF_LOG_HEX
AnnaBridge 143:86740a56073b 287 * - @ref NRF_LOG_HEX_DEBUG
AnnaBridge 143:86740a56073b 288 * - @ref NRF_LOG_HEX_ERROR
AnnaBridge 143:86740a56073b 289 *
AnnaBridge 143:86740a56073b 290 * @param value Integer value to be printed as HEX.
AnnaBridge 143:86740a56073b 291 */
AnnaBridge 143:86740a56073b 292 void log_uart_write_hex(uint32_t value);
AnnaBridge 143:86740a56073b 293
AnnaBridge 143:86740a56073b 294 /**@brief Function for logging a single character as HEX to UART.
AnnaBridge 143:86740a56073b 295 *
AnnaBridge 143:86740a56073b 296 * @details The output string is formatted as, for example, AA.
AnnaBridge 143:86740a56073b 297 *
AnnaBridge 143:86740a56073b 298 * This function is available only when NRF_LOG_USES_UART is defined as 1.
AnnaBridge 143:86740a56073b 299 *
AnnaBridge 143:86740a56073b 300 * @note This function is non-blocking. If too much data is sent to the UART,
AnnaBridge 143:86740a56073b 301 * some characters might be skipped.
AnnaBridge 143:86740a56073b 302 *
AnnaBridge 143:86740a56073b 303 * @note Do not call this function directly. Use one of the following macros instead:
AnnaBridge 143:86740a56073b 304 * - @ref NRF_LOG_HEX_CHAR
AnnaBridge 143:86740a56073b 305 * - @ref NRF_LOG_HEX_CHAR_DEBUG
AnnaBridge 143:86740a56073b 306 * - @ref NRF_LOG_HEX_CHAR_ERROR
AnnaBridge 143:86740a56073b 307 *
AnnaBridge 143:86740a56073b 308 * @param c Character.
AnnaBridge 143:86740a56073b 309 */
AnnaBridge 143:86740a56073b 310 void log_uart_write_hex_char(uint8_t c);
AnnaBridge 143:86740a56073b 311
AnnaBridge 143:86740a56073b 312 /**@brief Function for checking if data is available in the input buffer.
AnnaBridge 143:86740a56073b 313 *
AnnaBridge 143:86740a56073b 314 * This function is available only when NRF_LOG_USES_UART is defined as 1.
AnnaBridge 143:86740a56073b 315 *
AnnaBridge 143:86740a56073b 316 * @note Do not call this function directly. Use @ref NRF_LOG_HAS_INPUT instead.
AnnaBridge 143:86740a56073b 317 *
AnnaBridge 143:86740a56073b 318 * @retval 1 If characters are available to read.
AnnaBridge 143:86740a56073b 319 * @retval 0 If no characters are available.
AnnaBridge 143:86740a56073b 320 */
AnnaBridge 143:86740a56073b 321 int log_uart_has_input(void);
AnnaBridge 143:86740a56073b 322
AnnaBridge 143:86740a56073b 323 /**@brief Function for reading one character from the input buffer.
AnnaBridge 143:86740a56073b 324 *
AnnaBridge 143:86740a56073b 325 * @param[out] p_char Pointer where to store the character.
AnnaBridge 143:86740a56073b 326 *
AnnaBridge 143:86740a56073b 327 * This function is available only when NRF_LOG_USES_UART is defined as 1.
AnnaBridge 143:86740a56073b 328 *
AnnaBridge 143:86740a56073b 329 * @note Do not call this function directly. Use NRF_LOG_READ_INPUT instead.
AnnaBridge 143:86740a56073b 330 *
AnnaBridge 143:86740a56073b 331 * @retval NRF_SUCCESS If the character was read out.
AnnaBridge 143:86740a56073b 332 * @retval NRF_ERROR_INVALID_DATA If no character could be read.
AnnaBridge 143:86740a56073b 333 */
AnnaBridge 143:86740a56073b 334 uint32_t log_uart_read_input(char* p_char);
AnnaBridge 143:86740a56073b 335
AnnaBridge 143:86740a56073b 336
AnnaBridge 143:86740a56073b 337 #define NRF_LOG_INIT() log_uart_init() /*!< Initialize the module. */
AnnaBridge 143:86740a56073b 338
AnnaBridge 143:86740a56073b 339 #define NRF_LOG_PRINTF(...) log_uart_printf(__VA_ARGS__) /*!< Print a log message using printf. */
AnnaBridge 143:86740a56073b 340 #define NRF_LOG_PRINTF_DEBUG(...) log_uart_printf(__VA_ARGS__) /*!< If DEBUG is set, print a log message using printf. */
AnnaBridge 143:86740a56073b 341 #define NRF_LOG_PRINTF_ERROR(...) log_uart_printf(__VA_ARGS__) /*!< Print a log message using printf to the error stream. */
AnnaBridge 143:86740a56073b 342
AnnaBridge 143:86740a56073b 343 #define NRF_LOG(...) log_uart_write_string_many(NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__) /*!< Print a log message. The input string must be null-terminated. */
AnnaBridge 143:86740a56073b 344 #define NRF_LOG_DEBUG(...) log_uart_write_string_many(NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__) /*!< If DEBUG is set, print a log message. The input string must be null-terminated. */
AnnaBridge 143:86740a56073b 345 #define NRF_LOG_ERROR(...) log_uart_write_string_many(NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__) /*!< Print a log message to the error stream. The input string must be null-terminated. */
AnnaBridge 143:86740a56073b 346
AnnaBridge 143:86740a56073b 347 #define NRF_LOG_HEX(val) log_uart_write_hex(val) /*!< Log an integer as HEX value (example output: 0x89ABCDEF). */
AnnaBridge 143:86740a56073b 348 #define NRF_LOG_HEX_DEBUG(val) log_uart_write_hex(val) /*!< If DEBUG is set, log an integer as HEX value (example output: 0x89ABCDEF). */
AnnaBridge 143:86740a56073b 349 #define NRF_LOG_HEX_ERROR(val) log_uart_write_hex(val) /*!< Log an integer as HEX value to the error stream (example output: 0x89ABCDEF). */
AnnaBridge 143:86740a56073b 350
AnnaBridge 143:86740a56073b 351 #define NRF_LOG_HEX_CHAR(val) log_uart_write_hex_char(val) /*!< Log a character as HEX value (example output: AA). */
AnnaBridge 143:86740a56073b 352 #define NRF_LOG_HEX_CHAR_DEBUG(val) log_uart_write_hex_char(val) /*!< If DEBUG is set, log a character as HEX value (example output: AA). */
AnnaBridge 143:86740a56073b 353 #define NRF_LOG_HEX_CHAR_ERROR(val) log_uart_write_hex_char(val) /*!< Log a character as HEX value to the error stream (example output: AA). */
AnnaBridge 143:86740a56073b 354
AnnaBridge 143:86740a56073b 355 #define NRF_LOG_HAS_INPUT() log_uart_has_input() /*!< Check if the input buffer has unconsumed characters. */
AnnaBridge 143:86740a56073b 356 #define NRF_LOG_READ_INPUT(p_char) log_uart_read_input(p_char) /*!< Consume a character from the input buffer. */
AnnaBridge 143:86740a56073b 357
AnnaBridge 143:86740a56073b 358 #if !defined(DEBUG) && !defined(DOXYGEN)
AnnaBridge 143:86740a56073b 359
AnnaBridge 143:86740a56073b 360 #undef NRF_LOG_DEBUG
AnnaBridge 143:86740a56073b 361 #define NRF_LOG_DEBUG(...)
AnnaBridge 143:86740a56073b 362
AnnaBridge 143:86740a56073b 363 #undef NRF_LOG_PRINTF_DEBUG
AnnaBridge 143:86740a56073b 364 #define NRF_LOG_PRINTF_DEBUG(...)
AnnaBridge 143:86740a56073b 365
AnnaBridge 143:86740a56073b 366 #undef NRF_LOG_STR_DEBUG
AnnaBridge 143:86740a56073b 367 #define NRF_LOG_STR_DEBUG(...)
AnnaBridge 143:86740a56073b 368
AnnaBridge 143:86740a56073b 369 #undef NRF_LOG_HEX_DEBUG
AnnaBridge 143:86740a56073b 370 #define NRF_LOG_HEX_DEBUG(...)
AnnaBridge 143:86740a56073b 371
AnnaBridge 143:86740a56073b 372 #undef NRF_LOG_HEX_CHAR_DEBUG
AnnaBridge 143:86740a56073b 373 #define NRF_LOG_HEX_CHAR_DEBUG(...)
AnnaBridge 143:86740a56073b 374
AnnaBridge 143:86740a56073b 375 #endif // !defined(DEBUG) && !defined(DOXYGEN)
AnnaBridge 143:86740a56073b 376
AnnaBridge 143:86740a56073b 377 #elif defined(NRF_LOG_USES_RAW_UART) && NRF_LOG_USES_RAW_UART == 1
AnnaBridge 143:86740a56073b 378
AnnaBridge 143:86740a56073b 379 /**@brief Function for initializing the raw UART logger.
AnnaBridge 143:86740a56073b 380 *
AnnaBridge 143:86740a56073b 381 * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
AnnaBridge 143:86740a56073b 382 *
AnnaBridge 143:86740a56073b 383 * @note Do not call this function directly. Use the macro @ref NRF_LOG_INIT instead.
AnnaBridge 143:86740a56073b 384 *
AnnaBridge 143:86740a56073b 385 * @retval NRF_SUCCESS If initialization was successful.
AnnaBridge 143:86740a56073b 386 * @retval NRF_ERROR Otherwise.
AnnaBridge 143:86740a56073b 387 */
AnnaBridge 143:86740a56073b 388 uint32_t log_raw_uart_init(void);
AnnaBridge 143:86740a56073b 389
AnnaBridge 143:86740a56073b 390 /**@brief Function for logging a printf string to raw UART.
AnnaBridge 143:86740a56073b 391 *
AnnaBridge 143:86740a56073b 392 * @details Printf requires more processor time
AnnaBridge 143:86740a56073b 393 * than other logging functions. Therefore, applications that require logging
AnnaBridge 143:86740a56073b 394 * but need it to interfere as little as possible with the execution, should
AnnaBridge 143:86740a56073b 395 * avoid using printf.
AnnaBridge 143:86740a56073b 396 *
AnnaBridge 143:86740a56073b 397 * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
AnnaBridge 143:86740a56073b 398 *
AnnaBridge 143:86740a56073b 399 * @note This function is non-blocking. If too much data is sent to the UART,
AnnaBridge 143:86740a56073b 400 * some characters might be skipped.
AnnaBridge 143:86740a56073b 401 *
AnnaBridge 143:86740a56073b 402 * @note Do not call this function directly. Use one of the following macros instead:
AnnaBridge 143:86740a56073b 403 * - @ref NRF_LOG_PRINTF
AnnaBridge 143:86740a56073b 404 * - @ref NRF_LOG_PRINTF_DEBUG
AnnaBridge 143:86740a56073b 405 * - @ref NRF_LOG_PRINTF_ERROR
AnnaBridge 143:86740a56073b 406 *
AnnaBridge 143:86740a56073b 407 * @param format_msg Printf format string.
AnnaBridge 143:86740a56073b 408 */
AnnaBridge 143:86740a56073b 409 void log_raw_uart_printf(const char * format_msg, ...);
AnnaBridge 143:86740a56073b 410
AnnaBridge 143:86740a56073b 411 /**@brief Function for logging a single character to raw UART.
AnnaBridge 143:86740a56073b 412 *
AnnaBridge 143:86740a56073b 413 * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
AnnaBridge 143:86740a56073b 414 *
AnnaBridge 143:86740a56073b 415 * @param c Character.
AnnaBridge 143:86740a56073b 416 */
AnnaBridge 143:86740a56073b 417 void log_raw_uart_write_char(const char c);
AnnaBridge 143:86740a56073b 418
AnnaBridge 143:86740a56073b 419 /**@brief Function for logging null-terminated strings to raw UART.
AnnaBridge 143:86740a56073b 420 *
AnnaBridge 143:86740a56073b 421 * @details This function is more efficient than using printf.
AnnaBridge 143:86740a56073b 422 * The null termination will not be logged.
AnnaBridge 143:86740a56073b 423 *
AnnaBridge 143:86740a56073b 424 * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
AnnaBridge 143:86740a56073b 425 *
AnnaBridge 143:86740a56073b 426 * @note Do not call this function directly. Use one of the following macros instead:
AnnaBridge 143:86740a56073b 427 * - @ref NRF_LOG
AnnaBridge 143:86740a56073b 428 * - @ref NRF_LOG_DEBUG
AnnaBridge 143:86740a56073b 429 * - @ref NRF_LOG_ERROR
AnnaBridge 143:86740a56073b 430 *
AnnaBridge 143:86740a56073b 431 * @param num_args Number of arguments.
AnnaBridge 143:86740a56073b 432 */
AnnaBridge 143:86740a56073b 433 void log_raw_uart_write_string_many(int num_args, ...);
AnnaBridge 143:86740a56073b 434
AnnaBridge 143:86740a56073b 435
AnnaBridge 143:86740a56073b 436 /**@brief Function for logging a null-terminated string to raw UART.
AnnaBridge 143:86740a56073b 437 *
AnnaBridge 143:86740a56073b 438 * @details This function is more efficient than using printf.
AnnaBridge 143:86740a56073b 439 * The null termination will not be logged.
AnnaBridge 143:86740a56073b 440 *
AnnaBridge 143:86740a56073b 441 * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
AnnaBridge 143:86740a56073b 442 *
AnnaBridge 143:86740a56073b 443 * @note Do not call this function directly. Use one of the following macros instead:
AnnaBridge 143:86740a56073b 444 * - @ref NRF_LOG
AnnaBridge 143:86740a56073b 445 * - @ref NRF_LOG_DEBUG
AnnaBridge 143:86740a56073b 446 * - @ref NRF_LOG_ERROR
AnnaBridge 143:86740a56073b 447 *
AnnaBridge 143:86740a56073b 448 * @param str Null-terminated string.
AnnaBridge 143:86740a56073b 449 */
AnnaBridge 143:86740a56073b 450 void log_raw_uart_write_string(const char * str);
AnnaBridge 143:86740a56073b 451
AnnaBridge 143:86740a56073b 452 /**@brief Function for logging an integer value as HEX to raw UART.
AnnaBridge 143:86740a56073b 453 *
AnnaBridge 143:86740a56073b 454 * @details The output data is formatted as, for example, 0x89ABCDEF.
AnnaBridge 143:86740a56073b 455 * This function is more efficient than printf.
AnnaBridge 143:86740a56073b 456 *
AnnaBridge 143:86740a56073b 457 * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
AnnaBridge 143:86740a56073b 458 *
AnnaBridge 143:86740a56073b 459 * @note This function is non-blocking. If too much data is sent to the UART,
AnnaBridge 143:86740a56073b 460 * some characters might be skipped.
AnnaBridge 143:86740a56073b 461 *
AnnaBridge 143:86740a56073b 462 * @note Do not call this function directly. Use one of the following macros instead:
AnnaBridge 143:86740a56073b 463 * - @ref NRF_LOG_HEX
AnnaBridge 143:86740a56073b 464 * - @ref NRF_LOG_HEX_DEBUG
AnnaBridge 143:86740a56073b 465 * - @ref NRF_LOG_HEX_ERROR
AnnaBridge 143:86740a56073b 466 *
AnnaBridge 143:86740a56073b 467 * @param value Integer value to be printed as HEX.
AnnaBridge 143:86740a56073b 468 */
AnnaBridge 143:86740a56073b 469 void log_raw_uart_write_hex(uint32_t value);
AnnaBridge 143:86740a56073b 470
AnnaBridge 143:86740a56073b 471 /**@brief Function for logging a single character as HEX to raw UART.
AnnaBridge 143:86740a56073b 472 *
AnnaBridge 143:86740a56073b 473 * @details The output string is formatted as, for example, AA.
AnnaBridge 143:86740a56073b 474 *
AnnaBridge 143:86740a56073b 475 * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
AnnaBridge 143:86740a56073b 476 *
AnnaBridge 143:86740a56073b 477 * @note This function is non-blocking. If too much data is sent to the UART,
AnnaBridge 143:86740a56073b 478 * some characters might be skipped.
AnnaBridge 143:86740a56073b 479 *
AnnaBridge 143:86740a56073b 480 * @note Do not call this function directly. Use one of the following macros instead:
AnnaBridge 143:86740a56073b 481 * - @ref NRF_LOG_HEX_CHAR
AnnaBridge 143:86740a56073b 482 * - @ref NRF_LOG_HEX_CHAR_DEBUG
AnnaBridge 143:86740a56073b 483 * - @ref NRF_LOG_HEX_CHAR_ERROR
AnnaBridge 143:86740a56073b 484 *
AnnaBridge 143:86740a56073b 485 * @param c Character.
AnnaBridge 143:86740a56073b 486 */
AnnaBridge 143:86740a56073b 487 void log_raw_uart_write_hex_char(uint8_t c);
AnnaBridge 143:86740a56073b 488
AnnaBridge 143:86740a56073b 489 /**@brief Function for checking if data is available in the input buffer.
AnnaBridge 143:86740a56073b 490 *
AnnaBridge 143:86740a56073b 491 * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
AnnaBridge 143:86740a56073b 492 *
AnnaBridge 143:86740a56073b 493 * @note Do not call this function directly. Use @ref NRF_LOG_HAS_INPUT instead.
AnnaBridge 143:86740a56073b 494 *
AnnaBridge 143:86740a56073b 495 * @retval 1 If characters are available to read.
AnnaBridge 143:86740a56073b 496 * @retval 0 If no characters are available.
AnnaBridge 143:86740a56073b 497 */
AnnaBridge 143:86740a56073b 498 int log_raw_uart_has_input(void);
AnnaBridge 143:86740a56073b 499
AnnaBridge 143:86740a56073b 500 /**@brief Function for reading one character from the input buffer.
AnnaBridge 143:86740a56073b 501 *
AnnaBridge 143:86740a56073b 502 * @param[out] p_char Pointer where to store the character.
AnnaBridge 143:86740a56073b 503 *
AnnaBridge 143:86740a56073b 504 * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
AnnaBridge 143:86740a56073b 505 *
AnnaBridge 143:86740a56073b 506 * @note Do not call this function directly. Use NRF_LOG_READ_INPUT instead.
AnnaBridge 143:86740a56073b 507 *
AnnaBridge 143:86740a56073b 508 * @retval NRF_SUCCESS If the character was read out.
AnnaBridge 143:86740a56073b 509 * @retval NRF_ERROR_INVALID_DATA If no character could be read.
AnnaBridge 143:86740a56073b 510 */
AnnaBridge 143:86740a56073b 511
AnnaBridge 143:86740a56073b 512 uint32_t log_raw_uart_read_input(char* p_char);
AnnaBridge 143:86740a56073b 513
AnnaBridge 143:86740a56073b 514 #define NRF_LOG_INIT() log_raw_uart_init() /*!< nitialize the module. */
AnnaBridge 143:86740a56073b 515
AnnaBridge 143:86740a56073b 516 #define NRF_LOG_PRINTF(...) log_raw_uart_printf(__VA_ARGS__) /*!< Print a log message using printf. */
AnnaBridge 143:86740a56073b 517 #define NRF_LOG_PRINTF_DEBUG(...) log_raw_uart_printf(__VA_ARGS__) /*!< If DEBUG is set, print a log message using printf. */
AnnaBridge 143:86740a56073b 518 #define NRF_LOG_PRINTF_ERROR(...) log_raw_uart_printf(__VA_ARGS__) /*!< Print a log message using printf to the error stream. */
AnnaBridge 143:86740a56073b 519
AnnaBridge 143:86740a56073b 520 #define NRF_LOG(...) log_raw_uart_write_string_many(NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__) /*!< Print a log message. The input string must be null-terminated. */
AnnaBridge 143:86740a56073b 521 #define NRF_LOG_DEBUG(...) log_raw_uart_write_string_many(NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__) /*!< If DEBUG is set, print a log message. The input string must be null-terminated. */
AnnaBridge 143:86740a56073b 522 #define NRF_LOG_ERROR(...) log_raw_uart_write_string_many(NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__) /*!< Print a log message to the error stream. The input string must be null-terminated. */
AnnaBridge 143:86740a56073b 523
AnnaBridge 143:86740a56073b 524 #define NRF_LOG_HEX(val) log_raw_uart_write_hex(val) /*!< Log an integer as HEX value (example output: 0x89ABCDEF). */
AnnaBridge 143:86740a56073b 525 #define NRF_LOG_HEX_DEBUG(val) log_raw_uart_write_hex(val) /*!< If DEBUG is set, log an integer as HEX value (example output: 0x89ABCDEF). */
AnnaBridge 143:86740a56073b 526 #define NRF_LOG_HEX_ERROR(val) log_raw_uart_write_hex(val) /*!< Log an integer as HEX value to the error stream (example output: 0x89ABCDEF). */
AnnaBridge 143:86740a56073b 527
AnnaBridge 143:86740a56073b 528 #define NRF_LOG_HEX_CHAR(val) log_raw_uart_write_hex_char(val) /*!< Log a character as HEX value (example output: AA). */
AnnaBridge 143:86740a56073b 529 #define NRF_LOG_HEX_CHAR_DEBUG(val) log_raw_uart_write_hex_char(val) /*!< If DEBUG is set, log a character as HEX value (example output: AA). */
AnnaBridge 143:86740a56073b 530 #define NRF_LOG_HEX_CHAR_ERROR(val) log_raw_uart_write_hex_char(val) /*!< Log a character as HEX value to the error stream (example output: AA). */
AnnaBridge 143:86740a56073b 531
AnnaBridge 143:86740a56073b 532 #define NRF_LOG_HAS_INPUT() log_raw_uart_has_input() /*!< Check if the input buffer has unconsumed characters. */
AnnaBridge 143:86740a56073b 533 #define NRF_LOG_READ_INPUT(p_char) log_raw_uart_read_input(p_char) /*!< Consume a character from the input buffer. */
AnnaBridge 143:86740a56073b 534
AnnaBridge 143:86740a56073b 535 #if !defined(DEBUG) && !defined(DOXYGEN)
AnnaBridge 143:86740a56073b 536
AnnaBridge 143:86740a56073b 537 #undef NRF_LOG_DEBUG
AnnaBridge 143:86740a56073b 538 #define NRF_LOG_DEBUG(...)
AnnaBridge 143:86740a56073b 539
AnnaBridge 143:86740a56073b 540 #undef NRF_LOG_PRINTF_DEBUG
AnnaBridge 143:86740a56073b 541 #define NRF_LOG_PRINTF_DEBUG(...)
AnnaBridge 143:86740a56073b 542
AnnaBridge 143:86740a56073b 543 #undef NRF_LOG_STR_DEBUG
AnnaBridge 143:86740a56073b 544 #define NRF_LOG_STR_DEBUG(...)
AnnaBridge 143:86740a56073b 545
AnnaBridge 143:86740a56073b 546 #undef NRF_LOG_HEX_DEBUG
AnnaBridge 143:86740a56073b 547 #define NRF_LOG_HEX_DEBUG(...)
AnnaBridge 143:86740a56073b 548
AnnaBridge 143:86740a56073b 549 #undef NRF_LOG_HEX_CHAR_DEBUG
AnnaBridge 143:86740a56073b 550 #define NRF_LOG_HEX_CHAR_DEBUG(...)
AnnaBridge 143:86740a56073b 551
AnnaBridge 143:86740a56073b 552 #endif // !defined(DEBUG) && !defined(DOXYGEN)
AnnaBridge 143:86740a56073b 553
AnnaBridge 143:86740a56073b 554 #else
AnnaBridge 143:86740a56073b 555
AnnaBridge 143:86740a56073b 556 #include "nrf_error.h"
AnnaBridge 143:86740a56073b 557 #include "nordic_common.h"
AnnaBridge 143:86740a56073b 558
AnnaBridge 143:86740a56073b 559 // Empty definitions
AnnaBridge 143:86740a56073b 560
AnnaBridge 143:86740a56073b 561 #define NRF_LOG_INIT() NRF_SUCCESS
AnnaBridge 143:86740a56073b 562 #define NRF_LOG(...)
AnnaBridge 143:86740a56073b 563 #define NRF_LOG_DEBUG(...)
AnnaBridge 143:86740a56073b 564 #define NRF_LOG_ERROR(...)
AnnaBridge 143:86740a56073b 565
AnnaBridge 143:86740a56073b 566 #define NRF_LOG_PRINTF(...)
AnnaBridge 143:86740a56073b 567 #define NRF_LOG_PRINTF_DEBUG(...)
AnnaBridge 143:86740a56073b 568 #define NRF_LOG_PRINTF_ERROR(...)
AnnaBridge 143:86740a56073b 569
AnnaBridge 143:86740a56073b 570 #define NRF_LOG_HEX(val)
AnnaBridge 143:86740a56073b 571 #define NRF_LOG_HEX_DEBUG(val)
AnnaBridge 143:86740a56073b 572 #define NRF_LOG_HEX_ERROR(val)
AnnaBridge 143:86740a56073b 573
AnnaBridge 143:86740a56073b 574 #define NRF_LOG_HEX_CHAR(val)
AnnaBridge 143:86740a56073b 575 #define NRF_LOG_HEX_CHAR_DEBUG(val)
AnnaBridge 143:86740a56073b 576 #define NRF_LOG_HEX_CHAR_ERROR(val)
AnnaBridge 143:86740a56073b 577
AnnaBridge 143:86740a56073b 578 #define NRF_LOG_HAS_INPUT() 0
AnnaBridge 143:86740a56073b 579 #define NRF_LOG_READ_INPUT(ignore) NRF_SUCCESS
AnnaBridge 143:86740a56073b 580
AnnaBridge 143:86740a56073b 581 #endif
AnnaBridge 143:86740a56073b 582
AnnaBridge 143:86740a56073b 583 /**@brief Function for writing HEX values.
AnnaBridge 143:86740a56073b 584 *
AnnaBridge 143:86740a56073b 585 * @note This function not thread-safe. It is written for convenience.
AnnaBridge 143:86740a56073b 586 * If you log from different application contexts, you might get different results.
AnnaBridge 143:86740a56073b 587 *
AnnaBridge 143:86740a56073b 588 * @retval NULL By default.
AnnaBridge 143:86740a56073b 589 */
AnnaBridge 143:86740a56073b 590 const char* log_hex(uint32_t value);
AnnaBridge 143:86740a56073b 591
AnnaBridge 143:86740a56073b 592 /**@brief Function for writing HEX characters.
AnnaBridge 143:86740a56073b 593 *
AnnaBridge 143:86740a56073b 594 * @note This function not thread-safe. It is written for convenience.
AnnaBridge 143:86740a56073b 595 * If you log from different application contexts, you might get different results.
AnnaBridge 143:86740a56073b 596 *
AnnaBridge 143:86740a56073b 597 * @retval NULL By default.
AnnaBridge 143:86740a56073b 598 */
AnnaBridge 143:86740a56073b 599 const char* log_hex_char(const char value);
AnnaBridge 143:86740a56073b 600
AnnaBridge 143:86740a56073b 601
AnnaBridge 143:86740a56073b 602
AnnaBridge 143:86740a56073b 603
AnnaBridge 143:86740a56073b 604 #else // DOXYGEN
AnnaBridge 143:86740a56073b 605
AnnaBridge 143:86740a56073b 606 /** @defgroup nrf_log UART/RTT logging
AnnaBridge 143:86740a56073b 607 * @{
AnnaBridge 143:86740a56073b 608 * @ingroup app_common
AnnaBridge 143:86740a56073b 609 *
AnnaBridge 143:86740a56073b 610 * @brief Library to output logging information over SEGGER's Real Time Transfer
AnnaBridge 143:86740a56073b 611 * (RTT), UART, or raw UART.
AnnaBridge 143:86740a56073b 612 *
AnnaBridge 143:86740a56073b 613 * This library provides macros that call the respective functions depending on
AnnaBridge 143:86740a56073b 614 * which protocol is used. Define LOG_USES_RTT=1 to enable logging over RTT,
AnnaBridge 143:86740a56073b 615 * NRF_LOG_USES_UART=1 to enable logging over UART, or NRF_LOG_USES_RAW_UART=1
AnnaBridge 143:86740a56073b 616 * to enable logging over raw UART. One of these defines must be set for any of
AnnaBridge 143:86740a56073b 617 * the macros to have effect. If you choose to not output information, all
AnnaBridge 143:86740a56073b 618 * logging macros can be left in the code without any cost; they will just be
AnnaBridge 143:86740a56073b 619 * ignored.
AnnaBridge 143:86740a56073b 620 */
AnnaBridge 143:86740a56073b 621
AnnaBridge 143:86740a56073b 622
AnnaBridge 143:86740a56073b 623
AnnaBridge 143:86740a56073b 624 /**@brief Macro for initializing the logger.
AnnaBridge 143:86740a56073b 625 *
AnnaBridge 143:86740a56073b 626 * @retval NRF_SUCCESS If initialization was successful.
AnnaBridge 143:86740a56073b 627 * @retval NRF_ERROR Otherwise.
AnnaBridge 143:86740a56073b 628 */
AnnaBridge 143:86740a56073b 629 uint32_t NRF_LOG_INIT(void);
AnnaBridge 143:86740a56073b 630
AnnaBridge 143:86740a56073b 631 /**@brief Macro for logging null-terminated strings.
AnnaBridge 143:86740a56073b 632 *
AnnaBridge 143:86740a56073b 633 * @details This function is more efficient than using printf.
AnnaBridge 143:86740a56073b 634 * The null termination will not be logged.
AnnaBridge 143:86740a56073b 635 *
AnnaBridge 143:86740a56073b 636 * @param msg Null-terminated string.
AnnaBridge 143:86740a56073b 637 */
AnnaBridge 143:86740a56073b 638 void NRF_LOG(const char* msg);
AnnaBridge 143:86740a56073b 639
AnnaBridge 143:86740a56073b 640 /**@brief Macro for logging a printf string.
AnnaBridge 143:86740a56073b 641 *
AnnaBridge 143:86740a56073b 642 * @details Printf requires more processor time
AnnaBridge 143:86740a56073b 643 * than other logging functions. Therefore, applications that require logging
AnnaBridge 143:86740a56073b 644 * but need it to interfere as little as possible with the execution, should
AnnaBridge 143:86740a56073b 645 * avoid using printf.
AnnaBridge 143:86740a56073b 646 *
AnnaBridge 143:86740a56073b 647 * @note When NRF_LOG_USES_UART is set to 1, this macro is non-blocking.
AnnaBridge 143:86740a56073b 648 * If too much data is sent, some characters might be skipped.
AnnaBridge 143:86740a56073b 649 *
AnnaBridge 143:86740a56073b 650 * @param format_msg Printf format string.
AnnaBridge 143:86740a56073b 651 * @param ... Additional arguments replacing format specifiers in format_msg.
AnnaBridge 143:86740a56073b 652 */
AnnaBridge 143:86740a56073b 653 void NRF_LOG_PRINTF(const char * format_msg, ...);
AnnaBridge 143:86740a56073b 654
AnnaBridge 143:86740a56073b 655 /**@brief Macro for logging an integer value as HEX.
AnnaBridge 143:86740a56073b 656 *
AnnaBridge 143:86740a56073b 657 * @details The output data is formatted as, for example, 0x89ABCDEF.
AnnaBridge 143:86740a56073b 658 * This function is more efficient than printf.
AnnaBridge 143:86740a56073b 659 *
AnnaBridge 143:86740a56073b 660 * @note When NRF_LOG_USES_UART is set to 1, this macro is non-blocking.
AnnaBridge 143:86740a56073b 661 * If too much data is sent, some characters might be skipped.
AnnaBridge 143:86740a56073b 662 *
AnnaBridge 143:86740a56073b 663 * @param value Integer value to be printed as HEX.
AnnaBridge 143:86740a56073b 664 */
AnnaBridge 143:86740a56073b 665 void NRF_LOG_HEX(uint32_t value);
AnnaBridge 143:86740a56073b 666
AnnaBridge 143:86740a56073b 667 /**@brief Macro for logging a single character as HEX.
AnnaBridge 143:86740a56073b 668 *
AnnaBridge 143:86740a56073b 669 * @details The output string is formatted as, for example, AA.
AnnaBridge 143:86740a56073b 670 *
AnnaBridge 143:86740a56073b 671 * @note When NRF_LOG_USES_UART is set to 1, this macro is non-blocking.
AnnaBridge 143:86740a56073b 672 * If too much data is sent, some characters might be skipped.
AnnaBridge 143:86740a56073b 673 *
AnnaBridge 143:86740a56073b 674 * @param c Character.
AnnaBridge 143:86740a56073b 675 */
AnnaBridge 143:86740a56073b 676 void NRF_LOG_HEX_CHAR(uint8_t c);
AnnaBridge 143:86740a56073b 677
AnnaBridge 143:86740a56073b 678 /**@brief Macro for checking if data is available in the input buffer.
AnnaBridge 143:86740a56073b 679 *
AnnaBridge 143:86740a56073b 680 * @note When NRF_LOG_USES_UART is set to 1, this macro is non-blocking.
AnnaBridge 143:86740a56073b 681 * If too much data is sent, some characters might be skipped.
AnnaBridge 143:86740a56073b 682 *
AnnaBridge 143:86740a56073b 683 * @retval 1 If characters are available to read.
AnnaBridge 143:86740a56073b 684 * @retval 0 If no characters are available.
AnnaBridge 143:86740a56073b 685 */
AnnaBridge 143:86740a56073b 686 int NRF_LOG_HAS_INPUT(void);
AnnaBridge 143:86740a56073b 687
AnnaBridge 143:86740a56073b 688 /**@brief Macro for reading one character from the input buffer.
AnnaBridge 143:86740a56073b 689 *
AnnaBridge 143:86740a56073b 690 * @param[out] p_char Pointer where to store the character.
AnnaBridge 143:86740a56073b 691 *
AnnaBridge 143:86740a56073b 692 * @retval NRF_SUCCESS If the character was read out.
AnnaBridge 143:86740a56073b 693 * @retval NRF_ERROR_INVALID_DATA If no character could be read.
AnnaBridge 143:86740a56073b 694 */
AnnaBridge 143:86740a56073b 695 uint32_t NRF_LOG_READ_INPUT(char* p_char);
AnnaBridge 143:86740a56073b 696
AnnaBridge 143:86740a56073b 697 /** @} */
AnnaBridge 143:86740a56073b 698 #endif // DOXYGEN
AnnaBridge 143:86740a56073b 699 #endif // NRF_LOG_H_