Skip to content

Commit

Permalink
helper/log: add LOG_CUSTOM_LEVEL() macro
Browse files Browse the repository at this point in the history
Allow logging at a changeable level.

Add an example of usage in ftdi driver.
Log SWD commands with not OK response at debug level (3).
For commands which responded OK use debug io level (4)
not to flood the log.

Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Change-Id: I67a472b293f7ed9ee84cadb7c081803e9eeb1ad0
Reviewed-on: https://review.openocd.org/c/openocd/+/8151
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
  • Loading branch information
tom-van authored and borneoa committed Mar 16, 2024
1 parent 263dbc1 commit b63e065
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/helper/log.h
Expand Up @@ -114,6 +114,15 @@ extern int debug_level;
expr); \
} while (0)

#define LOG_CUSTOM_LEVEL(level, expr ...) \
do { \
enum log_levels _level = level; \
if (debug_level >= _level) \
log_printf_lf(_level, \
__FILE__, __LINE__, __func__, \
expr); \
} while (0)

#define LOG_INFO(expr ...) \
log_printf_lf(LOG_LVL_INFO, __FILE__, __LINE__, __func__, expr)

Expand Down
3 changes: 2 additions & 1 deletion src/jtag/drivers/ftdi.c
Expand Up @@ -1088,7 +1088,8 @@ static int ftdi_swd_run_queue(void)
/* Devices do not reply to DP_TARGETSEL write cmd, ignore received ack */
bool check_ack = swd_cmd_returns_ack(swd_cmd_queue[i].cmd);

LOG_DEBUG_IO("%s%s %s %s reg %X = %08"PRIx32,
LOG_CUSTOM_LEVEL((check_ack && ack != SWD_ACK_OK) ? LOG_LVL_DEBUG : LOG_LVL_DEBUG_IO,
"%s%s %s %s reg %X = %08" PRIx32,
check_ack ? "" : "ack ignored ",
ack == SWD_ACK_OK ? "OK" : ack == SWD_ACK_WAIT ? "WAIT" : ack == SWD_ACK_FAULT ? "FAULT" : "JUNK",
swd_cmd_queue[i].cmd & SWD_CMD_APNDP ? "AP" : "DP",
Expand Down

0 comments on commit b63e065

Please sign in to comment.