nRF Connect SDK API 2.8.99
Loading...
Searching...
No Matches
macros_common.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
7#ifndef _MACROS_H_
8#define _MACROS_H_
9
10#include <errno.h>
11
12/* Error check. If != 0, print err code and call _SysFatalErrorHandler in main.
13 * For debug mode all LEDs are turned on in case of an error.
14 */
15
16#define PRINT_AND_OOPS(code) \
17 do { \
18 LOG_ERR("ERR_CHK Err_code: [%d] @ line: %d\t", code, __LINE__); \
19 k_oops(); \
20 } while (0)
21
22#define ERR_CHK(err_code) \
23 do { \
24 if (err_code) { \
25 PRINT_AND_OOPS(err_code); \
26 } \
27 } while (0)
28
29#define ERR_CHK_MSG(err_code, msg) \
30 do { \
31 if (err_code) { \
32 LOG_ERR("%s", msg); \
33 PRINT_AND_OOPS(err_code); \
34 } \
35 } while (0)
36
37#if (defined(CONFIG_INIT_STACKS) && defined(CONFIG_THREAD_ANALYZER))
38
39#define STACK_USAGE_PRINT(thread_name, p_thread) \
40 do { \
41 static uint64_t thread_ts; \
42 size_t unused_space_in_thread_bytes; \
43 if (k_uptime_get() - thread_ts > CONFIG_PRINT_STACK_USAGE_MS) { \
44 k_thread_stack_space_get(p_thread, &unused_space_in_thread_bytes); \
45 thread_ts = k_uptime_get(); \
46 LOG_DBG("Unused space in %s thread: %d bytes", thread_name, \
47 unused_space_in_thread_bytes); \
48 } \
49 } while (0)
50#else
51#define STACK_USAGE_PRINT(thread_name, p_stack)
52#endif /* (defined(CONFIG_INIT_STACKS) && defined(CONFIG_THREAD_ANALYZER)) */
53
54#ifndef MIN
55#define MIN(a, b) (((a) < (b)) ? (a) : (b))
56#endif /* MIN */
57
58#define COLOR_BLACK "\x1B[0;30m"
59#define COLOR_RED "\x1B[0;31m"
60#define COLOR_GREEN "\x1B[0;32m"
61#define COLOR_YELLOW "\x1B[0;33m"
62#define COLOR_BLUE "\x1B[0;34m"
63#define COLOR_MAGENTA "\x1B[0;35m"
64#define COLOR_CYAN "\x1B[0;36m"
65#define COLOR_WHITE "\x1B[0;37m"
66
67#define COLOR_RESET "\x1b[0m"
68
69#define BIT_SET(REG, BIT) ((REG) |= (BIT))
70#define BIT_CLEAR(REG, BIT) ((REG) &= ~(BIT))
71
72#endif /* _MACROS_H_ */