51 #define BASENAME(_file) ((strrchr(_file, '/') ? : (strrchr(_file, '\\') ? : _file))+1) 57 #define csp_assert(exp) \ 60 char *assertion = #exp; \ 61 const char *file = BASENAME(__FILE__); \ 62 int line = __LINE__; \ 63 printf("\E[1;31m[%02"PRIu8"] Assertion \'%s\' failed in %s:%d\E[0m\r\n", \ 64 csp_get_address(), assertion, file, line); \ 65 if (csp_assert_fail_action) \ 66 csp_assert_fail_action(assertion, file, line); \ 70 #define csp_assert(...) do {} while (0) 74 #include <avr/pgmspace.h> 75 #define CONSTSTR(data) PSTR(data) 81 #define printf(s, ...) printf_P(PSTR(s), ## __VA_ARGS__) 82 #define sscanf(buf, s, ...) sscanf_P(buf, PSTR(s), ## __VA_ARGS__) 83 #define scanf(s, ...) scanf_P(PSTR(s), ## __VA_ARGS__) 84 #define sprintf(buf, s, ...) sprintf_P(buf, PSTR(s), ## __VA_ARGS__) 85 #define snprintf(buf, size, s, ...) snprintf_P(buf, size, PSTR(s), ## __VA_ARGS__) 87 #define CONSTSTR(data) data 92 #define csp_debug(level, format, ...) do { if (csp_debug_level_enabled[level]) { do_csp_debug(level, CONSTSTR("[%02"PRIu8"] %s:%d " format), csp_get_address(), BASENAME(__FILE__), __LINE__, ##__VA_ARGS__);}} while(0) 94 #define csp_debug(level, format, ...) do { if (csp_debug_level_enabled[level]) { do_csp_debug(level, CONSTSTR(format), ##__VA_ARGS__);}} while(0) 97 #define csp_debug(...) do {} while (0) 100 #ifdef CSP_LOG_LEVEL_ERROR 101 #define csp_log_error(format, ...) csp_debug(CSP_ERROR, format, ##__VA_ARGS__) 103 #define csp_log_error(...) do {} while (0) 106 #ifdef CSP_LOG_LEVEL_WARN 107 #define csp_log_warn(format, ...) csp_debug(CSP_WARN, format, ##__VA_ARGS__) 109 #define csp_log_warn(...) do {} while (0) 112 #ifdef CSP_LOG_LEVEL_INFO 113 #define csp_log_info(format, ...) csp_debug(CSP_INFO, format, ##__VA_ARGS__) 115 #define csp_log_info(...) do {} while (0) 118 #ifdef CSP_LOG_LEVEL_DEBUG 119 #define csp_log_buffer(format, ...) csp_debug(CSP_BUFFER, format, ##__VA_ARGS__) 120 #define csp_log_packet(format, ...) csp_debug(CSP_PACKET, format, ##__VA_ARGS__) 121 #define csp_log_protocol(format, ...) csp_debug(CSP_PROTOCOL, format, ##__VA_ARGS__) 122 #define csp_log_lock(format, ...) csp_debug(CSP_LOCK, format, ##__VA_ARGS__) 124 #define csp_log_buffer(...) do {} while (0) 125 #define csp_log_packet(...) do {} while (0) 126 #define csp_log_protocol(...) do {} while (0) 127 #define csp_log_lock(...) do {} while (0) 161 #endif // _CSP_DEBUG_H_ Definition: csp_debug.h:45
int csp_debug_get_level(csp_debug_level_t level)
Get current debug level value.
Definition: csp_debug.h:42
void csp_debug_set_level(csp_debug_level_t level, bool value)
Set debug level.
Definition: csp_debug.h:44
csp_debug_level_t
Debug levels.
Definition: csp_debug.h:38
void csp_debug_toggle_level(csp_debug_level_t level)
Toggle debug level on/off.
Definition: csp_debug.h:41
Definition: csp_debug.h:43
void do_csp_debug(csp_debug_level_t level, const char *format,...)
This function should not be used directly, use csp_log_<level>() macro instead.
Definition: csp_debug.h:40
void csp_assert_fail_action(char *assertion, const char *file, int line)
Definition: csp_debug.h:39
unsigned char csp_debug_level_enabled[]