rtdebug.h 4.9 KB
Newer Older
D
dzzxzz 已提交
1
/*
2
 * Copyright (c) 2006-2018, RT-Thread Development Team
B
Bernard Xiong 已提交
3
 *
4 5 6
 * SPDX-License-Identifier: Apache-2.0
 */

7 8 9
#ifndef __RTDEBUG_H__
#define __RTDEBUG_H__

10 11
#include <rtconfig.h>

B
bernard 已提交
12 13 14 15 16
/* 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
17 18 19 20 21

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

B
bernard 已提交
22 23 24 25 26 27 28 29
#endif

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

30 31 32 33
/* Using this macro to control all kernel debug features. */
#ifdef RT_DEBUG

/* Turn on some of these (set to non-zero) to debug kernel */
34
#ifndef RT_DEBUG_MEM
35
#define RT_DEBUG_MEM                   0
36 37
#endif

38
#ifndef RT_DEBUG_MEMHEAP
39
#define RT_DEBUG_MEMHEAP               0
40 41
#endif

42
#ifndef RT_DEBUG_MODULE
43
#define RT_DEBUG_MODULE                0
44 45 46
#endif

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

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

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

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

#ifndef RT_DEBUG_IRQ
63
#define RT_DEBUG_IRQ                   0
64 65 66
#endif

#ifndef RT_DEBUG_IPC
67
#define RT_DEBUG_IPC                   0
68
#endif
69

B
bernard 已提交
70
#ifndef RT_DEBUG_INIT
71
#define RT_DEBUG_INIT                  0
B
bernard 已提交
72 73
#endif

74 75
/* Turn on this to enable context check */
#ifndef RT_DEBUG_CONTEXT_CHECK
76
#define RT_DEBUG_CONTEXT_CHECK         1
77
#endif
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))                                                                    \
{                                                                             \
90
    rt_assert_handler(#EX, __FUNCTION__, __LINE__);                           \
91
}
92

93 94
/* Macro to check current context */
#if RT_DEBUG_CONTEXT_CHECK
95 96 97 98 99 100 101
#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 已提交
102
        rt_kprintf("Function[%s] shall not be used in ISR\n", __FUNCTION__);  \
103 104 105 106 107
        RT_ASSERT(0)                                                          \
    }                                                                         \
    rt_hw_interrupt_enable(level);                                            \
}                                                                             \
while (0)
G
Grissiom 已提交
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127

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

133 134 135
#else /* RT_DEBUG */

#define RT_ASSERT(EX)
136
#define RT_DEBUG_LOG(type, message)
137
#define RT_DEBUG_NOT_IN_INTERRUPT
138
#define RT_DEBUG_IN_THREAD_CONTEXT
139 140 141 142

#endif /* RT_DEBUG */

#endif /* __RTDEBUG_H__ */