rtdebug.h 5.7 KB
Newer Older
D
dzzxzz 已提交
1 2 3
/*
 * File      : rtdebug.h
 * This file is part of RT-Thread RTOS
B
Bernard Xiong 已提交
4
 * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
D
dzzxzz 已提交
5
 *
B
Bernard Xiong 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18
 *  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.
D
dzzxzz 已提交
19
 */
B
Bernard Xiong 已提交
20

21 22 23
#ifndef __RTDEBUG_H__
#define __RTDEBUG_H__

24 25
#include <rtconfig.h>

B
bernard 已提交
26 27 28 29 30
/* 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
31

32 33
#if defined(RT_USING_LWIP) && !defined(SAL_USING_POSIX)
#error "POSIX poll/select, stdin need file BSD socket API(SAL_USING_POSIX)"
34 35 36 37 38 39
#endif

#if !defined(RT_USING_LIBC)
#error "POSIX layer need standard C library(RT_USING_LIBC)"
#endif

B
bernard 已提交
40 41 42 43 44 45 46 47
#endif

#ifdef RT_USING_POSIX_TERMIOS
#if !defined(RT_USING_POSIX)
#error "termios need POSIX layer(RT_USING_POSIX)"
#endif
#endif

48 49 50 51
/* Using this macro to control all kernel debug features. */
#ifdef RT_DEBUG

/* Turn on some of these (set to non-zero) to debug kernel */
52
#ifndef RT_DEBUG_MEM
53
#define RT_DEBUG_MEM                   0
54 55
#endif

56
#ifndef RT_DEBUG_MEMHEAP
57
#define RT_DEBUG_MEMHEAP               0
58 59
#endif

60
#ifndef RT_DEBUG_MODULE
61
#define RT_DEBUG_MODULE                0
62 63 64
#endif

#ifndef RT_DEBUG_SCHEDULER
65
#define RT_DEBUG_SCHEDULER             0
66 67 68
#endif

#ifndef RT_DEBUG_SLAB
69
#define RT_DEBUG_SLAB                  0
70 71 72
#endif

#ifndef RT_DEBUG_THREAD
73
#define RT_DEBUG_THREAD                0
74 75 76
#endif

#ifndef RT_DEBUG_TIMER
77
#define RT_DEBUG_TIMER                 0
78 79 80
#endif

#ifndef RT_DEBUG_IRQ
81
#define RT_DEBUG_IRQ                   0
82 83 84
#endif

#ifndef RT_DEBUG_IPC
85
#define RT_DEBUG_IPC                   0
86
#endif
87

B
bernard 已提交
88
#ifndef RT_DEBUG_INIT
89
#define RT_DEBUG_INIT                  0
B
bernard 已提交
90 91
#endif

92 93
/* Turn on this to enable context check */
#ifndef RT_DEBUG_CONTEXT_CHECK
94
#define RT_DEBUG_CONTEXT_CHECK         1
95
#endif
96

97 98 99 100 101 102 103 104 105 106 107
#define RT_DEBUG_LOG(type, message)                                           \
do                                                                            \
{                                                                             \
    if (type)                                                                 \
        rt_kprintf message;                                                   \
}                                                                             \
while (0)

#define RT_ASSERT(EX)                                                         \
if (!(EX))                                                                    \
{                                                                             \
108
    rt_assert_handler(#EX, __FUNCTION__, __LINE__);                           \
109
}
110

111 112
/* Macro to check current context */
#if RT_DEBUG_CONTEXT_CHECK
113 114 115 116 117 118 119
#define RT_DEBUG_NOT_IN_INTERRUPT                                             \
do                                                                            \
{                                                                             \
    rt_base_t level;                                                          \
    level = rt_hw_interrupt_disable();                                        \
    if (rt_interrupt_get_nest() != 0)                                         \
    {                                                                         \
Z
ZHANG Jinglong 已提交
120
        rt_kprintf("Function[%s] shall not be used in ISR\n", __FUNCTION__);  \
121 122 123 124 125
        RT_ASSERT(0)                                                          \
    }                                                                         \
    rt_hw_interrupt_enable(level);                                            \
}                                                                             \
while (0)
G
Grissiom 已提交
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145

/* "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)
146 147
#else
#define RT_DEBUG_NOT_IN_INTERRUPT
G
Grissiom 已提交
148
#define RT_DEBUG_IN_THREAD_CONTEXT
149
#endif
150

151 152 153
#else /* RT_DEBUG */

#define RT_ASSERT(EX)
154
#define RT_DEBUG_LOG(type, message)
155
#define RT_DEBUG_NOT_IN_INTERRUPT
156
#define RT_DEBUG_IN_THREAD_CONTEXT
157 158 159 160

#endif /* RT_DEBUG */

#endif /* __RTDEBUG_H__ */