rtdebug.h 5.6 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 34 35

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

B
bernard 已提交
36 37 38 39 40 41 42 43
#endif

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

44 45 46 47
/* Using this macro to control all kernel debug features. */
#ifdef RT_DEBUG

/* Turn on some of these (set to non-zero) to debug kernel */
48
#ifndef RT_DEBUG_MEM
49
#define RT_DEBUG_MEM                   0
50 51
#endif

52
#ifndef RT_DEBUG_MEMHEAP
53
#define RT_DEBUG_MEMHEAP               0
54 55
#endif

56
#ifndef RT_DEBUG_MODULE
57
#define RT_DEBUG_MODULE                0
58 59 60
#endif

#ifndef RT_DEBUG_SCHEDULER
61
#define RT_DEBUG_SCHEDULER             0
62 63 64
#endif

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

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

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

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

#ifndef RT_DEBUG_IPC
81
#define RT_DEBUG_IPC                   0
82
#endif
83

B
bernard 已提交
84
#ifndef RT_DEBUG_INIT
85
#define RT_DEBUG_INIT                  0
B
bernard 已提交
86 87
#endif

88 89
/* Turn on this to enable context check */
#ifndef RT_DEBUG_CONTEXT_CHECK
90
#define RT_DEBUG_CONTEXT_CHECK         1
91
#endif
92

93 94 95 96 97 98 99 100 101 102 103
#define RT_DEBUG_LOG(type, message)                                           \
do                                                                            \
{                                                                             \
    if (type)                                                                 \
        rt_kprintf message;                                                   \
}                                                                             \
while (0)

#define RT_ASSERT(EX)                                                         \
if (!(EX))                                                                    \
{                                                                             \
104
    rt_assert_handler(#EX, __FUNCTION__, __LINE__);                           \
105
}
106

107 108
/* Macro to check current context */
#if RT_DEBUG_CONTEXT_CHECK
109 110 111 112 113 114 115
#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 已提交
116
        rt_kprintf("Function[%s] shall not be used in ISR\n", __FUNCTION__);  \
117 118 119 120 121
        RT_ASSERT(0)                                                          \
    }                                                                         \
    rt_hw_interrupt_enable(level);                                            \
}                                                                             \
while (0)
G
Grissiom 已提交
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141

/* "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)
142 143
#else
#define RT_DEBUG_NOT_IN_INTERRUPT
G
Grissiom 已提交
144
#define RT_DEBUG_IN_THREAD_CONTEXT
145
#endif
146

147 148 149
#else /* RT_DEBUG */

#define RT_ASSERT(EX)
150
#define RT_DEBUG_LOG(type, message)
151
#define RT_DEBUG_NOT_IN_INTERRUPT
152
#define RT_DEBUG_IN_THREAD_CONTEXT
153 154 155 156

#endif /* RT_DEBUG */

#endif /* __RTDEBUG_H__ */