rtdebug.h 5.5 KB
Newer Older
D
dzzxzz 已提交
1 2 3
/*
 * File      : rtdebug.h
 * This file is part of RT-Thread RTOS
D
dzzxzz 已提交
4
 * COPYRIGHT (C) 2006 - 2012, 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 31 32 33 34 35 36 37 38
/* 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
#endif

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

39 40 41 42
/* Using this macro to control all kernel debug features. */
#ifdef RT_DEBUG

/* Turn on some of these (set to non-zero) to debug kernel */
43
#ifndef RT_DEBUG_MEM
44
#define RT_DEBUG_MEM                   0
45 46
#endif

47
#ifndef RT_DEBUG_MEMHEAP
48
#define RT_DEBUG_MEMHEAP               0
49 50
#endif

51
#ifndef RT_DEBUG_MODULE
52
#define RT_DEBUG_MODULE                0
53 54 55
#endif

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

#ifndef RT_DEBUG_SLAB
60
#define RT_DEBUG_SLAB                  0
61 62 63
#endif

#ifndef RT_DEBUG_THREAD
64
#define RT_DEBUG_THREAD                0
65 66 67
#endif

#ifndef RT_DEBUG_TIMER
68
#define RT_DEBUG_TIMER                 0
69 70 71
#endif

#ifndef RT_DEBUG_IRQ
72
#define RT_DEBUG_IRQ                   0
73 74 75
#endif

#ifndef RT_DEBUG_IPC
76
#define RT_DEBUG_IPC                   0
77
#endif
78

B
bernard 已提交
79
#ifndef RT_DEBUG_INIT
80
#define RT_DEBUG_INIT                  0
B
bernard 已提交
81 82
#endif

83 84
/* Turn on this to enable context check */
#ifndef RT_DEBUG_CONTEXT_CHECK
85
#define RT_DEBUG_CONTEXT_CHECK         1
86
#endif
87

88 89 90 91 92 93 94 95 96 97 98
#define RT_DEBUG_LOG(type, message)                                           \
do                                                                            \
{                                                                             \
    if (type)                                                                 \
        rt_kprintf message;                                                   \
}                                                                             \
while (0)

#define RT_ASSERT(EX)                                                         \
if (!(EX))                                                                    \
{                                                                             \
99
    rt_assert_handler(#EX, __FUNCTION__, __LINE__);                           \
100
}
101

102 103
/* Macro to check current context */
#if RT_DEBUG_CONTEXT_CHECK
104 105 106 107 108 109 110 111 112 113 114 115 116
#define RT_DEBUG_NOT_IN_INTERRUPT                                             \
do                                                                            \
{                                                                             \
    rt_base_t level;                                                          \
    level = rt_hw_interrupt_disable();                                        \
    if (rt_interrupt_get_nest() != 0)                                         \
    {                                                                         \
        rt_kprintf("Function[%s] shall not used in ISR\n", __FUNCTION__);     \
        RT_ASSERT(0)                                                          \
    }                                                                         \
    rt_hw_interrupt_enable(level);                                            \
}                                                                             \
while (0)
G
Grissiom 已提交
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136

/* "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)
137 138
#else
#define RT_DEBUG_NOT_IN_INTERRUPT
G
Grissiom 已提交
139
#define RT_DEBUG_IN_THREAD_CONTEXT
140
#endif
141

142 143 144
#else /* RT_DEBUG */

#define RT_ASSERT(EX)
145
#define RT_DEBUG_LOG(type, message)
146
#define RT_DEBUG_NOT_IN_INTERRUPT
147
#define RT_DEBUG_IN_THREAD_CONTEXT
148 149 150 151

#endif /* RT_DEBUG */

#endif /* __RTDEBUG_H__ */