rtdebug.h 4.5 KB
Newer Older
D
dzzxzz 已提交
1
/*
mysterywolf's avatar
mysterywolf 已提交
2
 * Copyright (c) 2006-2021, RT-Thread Development Team
B
Bernard Xiong 已提交
3
 *
4
 * SPDX-License-Identifier: Apache-2.0
mysterywolf's avatar
mysterywolf 已提交
5 6 7
 *
 * Change Logs:
 * Date                 Author             Notes
8 9
 */

10 11 12
#ifndef __RTDEBUG_H__
#define __RTDEBUG_H__

13 14
#include <rtconfig.h>

15 16 17 18
/* Using this macro to control all kernel debug features. */
#ifdef RT_DEBUG

/* Turn on some of these (set to non-zero) to debug kernel */
19
#ifndef RT_DEBUG_MEM
20
#define RT_DEBUG_MEM                   0
21 22
#endif

23
#ifndef RT_DEBUG_MEMHEAP
24
#define RT_DEBUG_MEMHEAP               0
25 26
#endif

27
#ifndef RT_DEBUG_MODULE
28
#define RT_DEBUG_MODULE                0
29 30 31
#endif

#ifndef RT_DEBUG_SCHEDULER
32
#define RT_DEBUG_SCHEDULER             0
33 34 35
#endif

#ifndef RT_DEBUG_SLAB
36
#define RT_DEBUG_SLAB                  0
37 38 39
#endif

#ifndef RT_DEBUG_THREAD
40
#define RT_DEBUG_THREAD                0
41 42 43
#endif

#ifndef RT_DEBUG_TIMER
44
#define RT_DEBUG_TIMER                 0
45 46 47
#endif

#ifndef RT_DEBUG_IRQ
48
#define RT_DEBUG_IRQ                   0
49 50 51
#endif

#ifndef RT_DEBUG_IPC
52
#define RT_DEBUG_IPC                   0
53
#endif
54

B
bernard 已提交
55
#ifndef RT_DEBUG_INIT
56
#define RT_DEBUG_INIT                  0
B
bernard 已提交
57 58
#endif

59 60
/* Turn on this to enable context check */
#ifndef RT_DEBUG_CONTEXT_CHECK
61
#define RT_DEBUG_CONTEXT_CHECK         1
62
#endif
63

64 65 66 67 68 69 70 71 72 73 74
#define RT_DEBUG_LOG(type, message)                                           \
do                                                                            \
{                                                                             \
    if (type)                                                                 \
        rt_kprintf message;                                                   \
}                                                                             \
while (0)

#define RT_ASSERT(EX)                                                         \
if (!(EX))                                                                    \
{                                                                             \
75
    rt_assert_handler(#EX, __FUNCTION__, __LINE__);                           \
76
}
77

78 79
/* Macro to check current context */
#if RT_DEBUG_CONTEXT_CHECK
80 81 82 83 84 85 86
#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 已提交
87
        rt_kprintf("Function[%s] shall not be used in ISR\n", __FUNCTION__);  \
88 89 90 91 92
        RT_ASSERT(0)                                                          \
    }                                                                         \
    rt_hw_interrupt_enable(level);                                            \
}                                                                             \
while (0)
G
Grissiom 已提交
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112

/* "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)
113 114
#else
#define RT_DEBUG_NOT_IN_INTERRUPT
G
Grissiom 已提交
115
#define RT_DEBUG_IN_THREAD_CONTEXT
116
#endif
117

118 119 120
#else /* RT_DEBUG */

#define RT_ASSERT(EX)
121
#define RT_DEBUG_LOG(type, message)
122
#define RT_DEBUG_NOT_IN_INTERRUPT
123
#define RT_DEBUG_IN_THREAD_CONTEXT
124 125 126 127

#endif /* RT_DEBUG */

#endif /* __RTDEBUG_H__ */