2011-09-23 13:57:31 +08:00
|
|
|
/*
|
|
|
|
* File : rtdebug.h
|
|
|
|
* This file is part of RT-Thread RTOS
|
2018-02-09 16:58:20 +08:00
|
|
|
* COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
|
2011-09-23 13:57:31 +08:00
|
|
|
*
|
2013-06-24 17:06:09 +08:00
|
|
|
* 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 2 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, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2011-09-23 13:57:31 +08:00
|
|
|
*/
|
2013-06-24 17:06:09 +08:00
|
|
|
|
2011-06-12 18:01:48 +08:00
|
|
|
#ifndef __RTDEBUG_H__
|
|
|
|
#define __RTDEBUG_H__
|
|
|
|
|
2014-01-17 22:32:32 +08:00
|
|
|
#include <rtconfig.h>
|
|
|
|
|
2017-10-17 22:27:06 +08:00
|
|
|
/* settings depend check */
|
|
|
|
#ifdef RT_USING_POSIX
|
|
|
|
#if !defined(RT_USING_DFS) || !defined(RT_USING_DFS_DEVFS)
|
|
|
|
#error "POSIX poll/select, stdin need file system(RT_USING_DFS) and device file system(RT_USING_DFS_DEVFS)"
|
|
|
|
#endif
|
2017-10-18 17:27:48 +08:00
|
|
|
|
|
|
|
#if defined(RT_USING_LWIP) && !defined(RT_USING_DFS_NET)
|
|
|
|
#error "POSIX poll/select, stdin need file BSD socket API(RT_USING_DFS_NET)"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(RT_USING_LIBC)
|
|
|
|
#error "POSIX layer need standard C library(RT_USING_LIBC)"
|
|
|
|
#endif
|
|
|
|
|
2017-10-17 22:27:06 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef RT_USING_POSIX_TERMIOS
|
|
|
|
#if !defined(RT_USING_POSIX)
|
|
|
|
#error "termios need POSIX layer(RT_USING_POSIX)"
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2011-06-12 18:01:48 +08:00
|
|
|
/* Using this macro to control all kernel debug features. */
|
|
|
|
#ifdef RT_DEBUG
|
|
|
|
|
|
|
|
/* Turn on some of these (set to non-zero) to debug kernel */
|
2011-06-13 10:40:24 +08:00
|
|
|
#ifndef RT_DEBUG_MEM
|
2012-09-05 14:52:35 +08:00
|
|
|
#define RT_DEBUG_MEM 0
|
2011-06-13 10:40:24 +08:00
|
|
|
#endif
|
|
|
|
|
2012-04-14 11:52:56 +08:00
|
|
|
#ifndef RT_DEBUG_MEMHEAP
|
2012-09-05 14:52:35 +08:00
|
|
|
#define RT_DEBUG_MEMHEAP 0
|
2012-04-14 11:52:56 +08:00
|
|
|
#endif
|
|
|
|
|
2011-06-13 10:40:24 +08:00
|
|
|
#ifndef RT_DEBUG_MODULE
|
2012-09-05 14:52:35 +08:00
|
|
|
#define RT_DEBUG_MODULE 0
|
2011-06-13 10:40:24 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef RT_DEBUG_SCHEDULER
|
2012-09-05 14:52:35 +08:00
|
|
|
#define RT_DEBUG_SCHEDULER 0
|
2011-06-13 10:40:24 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef RT_DEBUG_SLAB
|
2012-09-05 14:52:35 +08:00
|
|
|
#define RT_DEBUG_SLAB 0
|
2011-06-13 10:40:24 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef RT_DEBUG_THREAD
|
2012-09-05 14:52:35 +08:00
|
|
|
#define RT_DEBUG_THREAD 0
|
2011-06-13 10:40:24 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef RT_DEBUG_TIMER
|
2012-09-05 14:52:35 +08:00
|
|
|
#define RT_DEBUG_TIMER 0
|
2011-06-13 10:40:24 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef RT_DEBUG_IRQ
|
2012-09-05 14:52:35 +08:00
|
|
|
#define RT_DEBUG_IRQ 0
|
2011-06-13 10:40:24 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef RT_DEBUG_IPC
|
2012-09-05 14:52:35 +08:00
|
|
|
#define RT_DEBUG_IPC 0
|
2011-06-13 10:40:24 +08:00
|
|
|
#endif
|
2011-06-12 18:01:48 +08:00
|
|
|
|
2013-07-24 07:33:48 +08:00
|
|
|
#ifndef RT_DEBUG_INIT
|
2014-01-11 16:37:13 +08:00
|
|
|
#define RT_DEBUG_INIT 0
|
2013-07-24 07:33:48 +08:00
|
|
|
#endif
|
|
|
|
|
2011-06-15 07:59:42 +08:00
|
|
|
/* Turn on this to enable context check */
|
|
|
|
#ifndef RT_DEBUG_CONTEXT_CHECK
|
2012-09-05 14:52:35 +08:00
|
|
|
#define RT_DEBUG_CONTEXT_CHECK 1
|
2011-06-13 10:40:24 +08:00
|
|
|
#endif
|
2011-06-12 18:01:48 +08:00
|
|
|
|
2012-09-05 14:52:35 +08:00
|
|
|
#define RT_DEBUG_LOG(type, message) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
if (type) \
|
|
|
|
rt_kprintf message; \
|
|
|
|
} \
|
|
|
|
while (0)
|
|
|
|
|
|
|
|
#define RT_ASSERT(EX) \
|
|
|
|
if (!(EX)) \
|
|
|
|
{ \
|
2015-08-03 16:07:30 +08:00
|
|
|
rt_assert_handler(#EX, __FUNCTION__, __LINE__); \
|
2012-09-05 14:52:35 +08:00
|
|
|
}
|
2011-06-12 18:01:48 +08:00
|
|
|
|
2011-06-15 07:59:42 +08:00
|
|
|
/* Macro to check current context */
|
|
|
|
#if RT_DEBUG_CONTEXT_CHECK
|
2012-09-05 14:52:35 +08:00
|
|
|
#define RT_DEBUG_NOT_IN_INTERRUPT \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
rt_base_t level; \
|
|
|
|
level = rt_hw_interrupt_disable(); \
|
|
|
|
if (rt_interrupt_get_nest() != 0) \
|
|
|
|
{ \
|
2018-02-09 16:58:20 +08:00
|
|
|
rt_kprintf("Function[%s] shall not ne used in ISR\n", __FUNCTION__); \
|
2012-09-05 14:52:35 +08:00
|
|
|
RT_ASSERT(0) \
|
|
|
|
} \
|
|
|
|
rt_hw_interrupt_enable(level); \
|
|
|
|
} \
|
|
|
|
while (0)
|
2013-10-11 22:46:05 +08:00
|
|
|
|
|
|
|
/* "In thread context" means:
|
|
|
|
* 1) the scheduler has been started
|
|
|
|
* 2) not in interrupt context.
|
|
|
|
*/
|
|
|
|
#define RT_DEBUG_IN_THREAD_CONTEXT \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
rt_base_t level; \
|
|
|
|
level = rt_hw_interrupt_disable(); \
|
|
|
|
if (rt_thread_self() == RT_NULL) \
|
|
|
|
{ \
|
|
|
|
rt_kprintf("Function[%s] shall not be used before scheduler start\n", \
|
|
|
|
__FUNCTION__); \
|
|
|
|
RT_ASSERT(0) \
|
|
|
|
} \
|
|
|
|
RT_DEBUG_NOT_IN_INTERRUPT; \
|
|
|
|
rt_hw_interrupt_enable(level); \
|
|
|
|
} \
|
|
|
|
while (0)
|
2012-09-05 14:28:28 +08:00
|
|
|
#else
|
|
|
|
#define RT_DEBUG_NOT_IN_INTERRUPT
|
2013-10-11 22:46:05 +08:00
|
|
|
#define RT_DEBUG_IN_THREAD_CONTEXT
|
2011-06-15 07:59:42 +08:00
|
|
|
#endif
|
2012-09-05 14:28:28 +08:00
|
|
|
|
2011-06-12 18:01:48 +08:00
|
|
|
#else /* RT_DEBUG */
|
|
|
|
|
|
|
|
#define RT_ASSERT(EX)
|
2012-09-05 14:52:35 +08:00
|
|
|
#define RT_DEBUG_LOG(type, message)
|
2011-06-15 07:59:42 +08:00
|
|
|
#define RT_DEBUG_NOT_IN_INTERRUPT
|
2013-10-12 10:58:56 +08:00
|
|
|
#define RT_DEBUG_IN_THREAD_CONTEXT
|
2011-06-12 18:01:48 +08:00
|
|
|
|
|
|
|
#endif /* RT_DEBUG */
|
|
|
|
|
|
|
|
#endif /* __RTDEBUG_H__ */
|