rtdebug.h 5.3 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 24 25 26 27 28 29
#ifndef __RTDEBUG_H__
#define __RTDEBUG_H__

#include <rtconfig.h>

/* Using this macro to control all kernel debug features. */
#ifdef RT_DEBUG

/* Turn on some of these (set to non-zero) to debug kernel */
30
#ifndef RT_DEBUG_MEM
31
#define RT_DEBUG_MEM                   0
32 33
#endif

34
#ifndef RT_DEBUG_MEMHEAP
35
#define RT_DEBUG_MEMHEAP               0
36 37
#endif

38
#ifndef RT_DEBUG_MODULE
39
#define RT_DEBUG_MODULE                0
40 41 42
#endif

#ifndef RT_DEBUG_SCHEDULER
43
#define RT_DEBUG_SCHEDULER             0
44 45 46
#endif

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

#ifndef RT_DEBUG_THREAD
51
#define RT_DEBUG_THREAD                0
52 53 54
#endif

#ifndef RT_DEBUG_TIMER
55
#define RT_DEBUG_TIMER                 0
56 57 58
#endif

#ifndef RT_DEBUG_IRQ
59
#define RT_DEBUG_IRQ                   0
60 61 62
#endif

#ifndef RT_DEBUG_IPC
63
#define RT_DEBUG_IPC                   0
64
#endif
65

B
bernard 已提交
66 67 68 69
#ifndef RT_DEBUG_INIT
#define RT_DEBUG_INIT					0
#endif

70 71
/* Turn on this to enable context check */
#ifndef RT_DEBUG_CONTEXT_CHECK
72
#define RT_DEBUG_CONTEXT_CHECK         1
73
#endif
74

75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
#define RT_DEBUG_LOG(type, message)                                           \
do                                                                            \
{                                                                             \
    if (type)                                                                 \
        rt_kprintf message;                                                   \
}                                                                             \
while (0)

#define RT_ASSERT(EX)                                                         \
if (!(EX))                                                                    \
{                                                                             \
    volatile char dummy = 0;                                                  \
    rt_kprintf("(%s) assert failed at %s:%d \n", #EX, __FUNCTION__, __LINE__);\
    while (dummy == 0);                                                       \
}
90

91 92
/* Macro to check current context */
#if RT_DEBUG_CONTEXT_CHECK
93 94 95 96 97 98 99 100 101 102 103 104 105
#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 已提交
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125

/* "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)
126 127
#else
#define RT_DEBUG_NOT_IN_INTERRUPT
G
Grissiom 已提交
128
#define RT_DEBUG_IN_THREAD_CONTEXT
129
#endif
130

131 132 133
#else /* RT_DEBUG */

#define RT_ASSERT(EX)
134
#define RT_DEBUG_LOG(type, message)
135
#define RT_DEBUG_NOT_IN_INTERRUPT
136 137 138 139

#endif /* RT_DEBUG */

#endif /* __RTDEBUG_H__ */