From bfe4982ac3aa5f75eba89f25e896a0455c6b2930 Mon Sep 17 00:00:00 2001 From: Ashish Chaudhari Date: Thu, 12 Feb 2015 09:14:54 -0800 Subject: usrp3: Added tracing library to usrp3 firmware --- firmware/usrp3/include/trace.h | 80 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 firmware/usrp3/include/trace.h (limited to 'firmware/usrp3') diff --git a/firmware/usrp3/include/trace.h b/firmware/usrp3/include/trace.h new file mode 100644 index 000000000..c1bc63caa --- /dev/null +++ b/firmware/usrp3/include/trace.h @@ -0,0 +1,80 @@ +// +// Copyright 2015 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +#ifndef INCLUDED_TRACE_H +#define INCLUDED_TRACE_H + +#include +#include +#include + +/* + * Enables basic conditional tracing support + * If UHD_FW_TRACE_LEVEL is defined, all messages + * with a verbosity >= UHD_FW_TRACE_LEVEL will be + * printed. + */ + +#define UHD_FW_TRACE_LEVEL 13 + +typedef enum +{ + /* 0-9: Use for performance/restricted debugging */ + ERROR = 10, + WARN = 11, + INFO = 12, + /* 13-19: Use for general debugging */ + DEBUG = 20, //Verbose! +} trace_level_t; + +static inline int _trace_typecheck_conv(trace_level_t lvl) { + return (int)lvl; +} + +#define UHD_FW_PRINTF(...) printf(__VA_ARGS__) +#define UHD_FW_BEAUTIFY_LVL(lvl) "[" #lvl "] " + +/* + * UHD_FW_TRACE(, ) + * - Simple trace. Print the messages with the log level as the prefix and \n at the end + * + * UHD_FW_TRACE_FSTR(, , ) + * - Trace format string with the log level as the prefix and \n at the end + * + * UHD_FW_TRACE_SHORT(, ) + * - Simple trace. Print the messages without the log level prefix or \n at the end + * + * UHD_FW_TRACE_FSTR_SHORT(, , ) + * - Trace format string without the log level prefix or \n at the end + */ +#ifdef UHD_FW_TRACE_LEVEL + #define UHD_FW_TRACE(lvl, fmt) \ + if (UHD_FW_TRACE_LEVEL >= _trace_typecheck_conv(lvl)) UHD_FW_PRINTF(UHD_FW_BEAUTIFY_LVL(lvl) fmt "\r\n"); + #define UHD_FW_TRACE_FSTR(lvl, fmt, ...) \ + if (UHD_FW_TRACE_LEVEL >= _trace_typecheck_conv(lvl)) UHD_FW_PRINTF(UHD_FW_BEAUTIFY_LVL(lvl) fmt "\r\n", __VA_ARGS__); + #define UHD_FW_TRACE_SHORT(lvl, fmt) \ + if (UHD_FW_TRACE_LEVEL >= _trace_typecheck_conv(lvl)) UHD_FW_PRINTF(fmt); + #define UHD_FW_TRACE_FSTR_SHORT(lvl, fmt, ...) \ + if (UHD_FW_TRACE_LEVEL >= _trace_typecheck_conv(lvl)) UHD_FW_PRINTF(fmt, __VA_ARGS__); +#else + #define UHD_FW_TRACE(lvl, fmt) ; + #define UHD_FW_TRACE_FSTR(lvl, fmt, ...) ; + #define UHD_FW_TRACE_SHORT(lvl, fmt) ; + #define UHD_FW_TRACE_FSTR_SHORT(lvl, fmt, ...) ; +#endif + +#endif /* INCLUDED_TRACE_H */ -- cgit v1.2.3