2013-11-27 16:28:31 +01:00
|
|
|
/*
|
2014-04-01 11:46:21 +02:00
|
|
|
* Copyright (C) 2014 Freie Universität Berlin
|
2010-09-22 15:10:42 +02:00
|
|
|
*
|
2014-08-23 15:43:13 +02:00
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
2013-11-27 16:28:31 +01:00
|
|
|
*/
|
2014-02-11 18:15:43 +01:00
|
|
|
|
2013-11-27 16:28:31 +01:00
|
|
|
/**
|
2019-01-07 15:36:14 +01:00
|
|
|
* @ingroup core_util
|
2010-09-22 15:10:42 +02:00
|
|
|
* @{
|
2013-11-27 16:28:31 +01:00
|
|
|
*
|
2015-05-22 07:34:41 +02:00
|
|
|
* @file
|
2013-11-27 16:28:31 +01:00
|
|
|
* @brief Debug-header
|
|
|
|
*
|
2015-04-21 09:45:21 +02:00
|
|
|
* @details If *ENABLE_DEBUG* is defined inside an implementation file, all
|
2015-09-11 23:15:59 +02:00
|
|
|
* calls to ::DEBUG will work the same as *printf* and output the
|
|
|
|
* given information to stdout. If *ENABLE_DEBUG* is not defined,
|
|
|
|
* all calls to ::DEBUG will be ignored.
|
2013-11-27 16:28:31 +01:00
|
|
|
*
|
2014-01-28 11:50:12 +01:00
|
|
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
2010-09-22 15:10:42 +02:00
|
|
|
*/
|
2014-02-11 18:15:43 +01:00
|
|
|
|
2015-03-26 17:07:04 +01:00
|
|
|
#ifndef DEBUG_H
|
|
|
|
#define DEBUG_H
|
2014-02-11 18:15:43 +01:00
|
|
|
|
2014-10-13 14:44:28 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "sched.h"
|
2015-06-02 18:01:16 +02:00
|
|
|
#include "thread.h"
|
2014-10-13 14:44:28 +02:00
|
|
|
|
2014-10-09 01:18:16 +02:00
|
|
|
#ifdef __cplusplus
|
2015-02-10 19:56:01 +01:00
|
|
|
extern "C" {
|
2014-10-09 01:18:16 +02:00
|
|
|
#endif
|
|
|
|
|
2015-02-10 19:56:01 +01:00
|
|
|
/**
|
|
|
|
* @def ENABLE_DEBUG
|
|
|
|
* @brief This macro can be defined as 0 or other on a file-based level.
|
2015-09-11 23:15:59 +02:00
|
|
|
* @ref DEBUG() will generate output only if ENABLE_DEBUG is non-zero.
|
2015-02-10 19:56:01 +01:00
|
|
|
*/
|
|
|
|
|
2014-04-01 11:46:21 +02:00
|
|
|
/**
|
2015-04-21 09:45:21 +02:00
|
|
|
* @def DEBUG_PRINT
|
|
|
|
*
|
|
|
|
* @brief Print debug information if the calling thread stack is large enough
|
2014-04-01 11:46:21 +02:00
|
|
|
*
|
2014-05-27 16:26:47 +02:00
|
|
|
* Use this macro the same as `printf`. When `DEVELHELP` is defined inside an
|
2015-04-21 09:45:21 +02:00
|
|
|
* implementation file, all usages of ::DEBUG_PRINT will print the given
|
|
|
|
* information to stdout after verifying the stack is big enough. If `DEVELHELP`
|
2014-05-27 16:26:47 +02:00
|
|
|
* is not set, this check is not performed. (CPU exception may occur)
|
2014-04-01 11:46:21 +02:00
|
|
|
*/
|
2015-09-12 12:43:15 +02:00
|
|
|
#ifdef DEVELHELP
|
2015-05-22 14:31:23 +02:00
|
|
|
#include "cpu_conf.h"
|
2014-03-03 00:25:09 +01:00
|
|
|
#define DEBUG_PRINT(...) \
|
|
|
|
do { \
|
2018-05-17 23:06:44 +02:00
|
|
|
if ((sched_active_thread == NULL) || (sched_active_thread->stack_size >= THREAD_EXTRA_STACKSIZE_PRINTF)) { \
|
2014-03-03 00:25:09 +01:00
|
|
|
printf(__VA_ARGS__); \
|
|
|
|
} \
|
|
|
|
else { \
|
2019-11-20 19:09:47 +01:00
|
|
|
puts("Cannot debug, stack too small. Consider using DEBUG_PUTS()."); \
|
2014-03-03 00:25:09 +01:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#else
|
|
|
|
#define DEBUG_PRINT(...) printf(__VA_ARGS__)
|
|
|
|
#endif
|
|
|
|
|
2014-04-01 11:46:21 +02:00
|
|
|
/**
|
2017-04-10 16:11:49 +02:00
|
|
|
* @name Debugging defines
|
2014-04-01 11:46:21 +02:00
|
|
|
* @{
|
|
|
|
*/
|
2016-03-24 10:20:46 +01:00
|
|
|
#ifndef ENABLE_DEBUG
|
|
|
|
#define ENABLE_DEBUG (0)
|
|
|
|
#endif
|
2015-02-12 12:54:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @def DEBUG_FUNC
|
|
|
|
*
|
|
|
|
* @brief Contains the function name if given compiler supports it.
|
|
|
|
* Otherwise it is an empty string.
|
|
|
|
*/
|
|
|
|
# if defined(__cplusplus) && defined(__GNUC__)
|
|
|
|
# define DEBUG_FUNC __PRETTY_FUNCTION__
|
|
|
|
# elif __STDC_VERSION__ >= 199901L
|
|
|
|
# define DEBUG_FUNC __func__
|
|
|
|
# elif __GNUC__ >= 2
|
|
|
|
# define DEBUG_FUNC __FUNCTION__
|
|
|
|
# else
|
2015-02-12 14:30:32 +01:00
|
|
|
# define DEBUG_FUNC ""
|
2015-02-12 12:54:07 +01:00
|
|
|
# endif
|
|
|
|
|
2015-04-21 09:45:21 +02:00
|
|
|
/**
|
|
|
|
* @def DEBUG
|
|
|
|
*
|
|
|
|
* @brief Print debug information to stdout
|
|
|
|
*
|
|
|
|
* @note Another name for ::DEBUG_PRINT
|
|
|
|
*/
|
2016-03-24 10:20:46 +01:00
|
|
|
#define DEBUG(...) if (ENABLE_DEBUG) DEBUG_PRINT(__VA_ARGS__)
|
2019-11-20 19:09:47 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @def DEBUG_PUTS
|
|
|
|
*
|
|
|
|
* @brief Print debug information to stdout using puts(), so no stack size
|
|
|
|
* restrictions do apply.
|
|
|
|
*/
|
|
|
|
#define DEBUG_PUTS(str) if (ENABLE_DEBUG) puts(str)
|
2013-11-27 16:28:31 +01:00
|
|
|
/** @} */
|
2014-04-01 11:46:21 +02:00
|
|
|
|
2015-07-07 11:47:32 +02:00
|
|
|
/**
|
|
|
|
* @def DEBUG_EXTRA_STACKSIZE
|
|
|
|
*
|
|
|
|
* @brief Extra stacksize needed when ENABLE_DEBUG==1
|
|
|
|
*/
|
|
|
|
#if ENABLE_DEBUG
|
|
|
|
#define DEBUG_EXTRA_STACKSIZE THREAD_EXTRA_STACKSIZE_PRINTF
|
|
|
|
#else
|
|
|
|
#define DEBUG_EXTRA_STACKSIZE (0)
|
|
|
|
#endif
|
|
|
|
|
2014-10-09 01:18:16 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-03-26 17:07:04 +01:00
|
|
|
#endif /* DEBUG_H */
|
2014-04-01 11:46:21 +02:00
|
|
|
/** @} */
|