rtdebug.h 3.4 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 6 7 8 9 10
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rt-thread.org/license/LICENSE
 */
 
11 12 13 14 15 16 17 18 19
#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 */
20
#ifndef RT_DEBUG_MEM
21
#define RT_DEBUG_MEM                   0
22 23
#endif

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

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

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

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

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

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

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

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

56 57
/* Turn on this to enable context check */
#ifndef RT_DEBUG_CONTEXT_CHECK
58
#define RT_DEBUG_CONTEXT_CHECK         1
59
#endif
60

61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
#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);                                                       \
}
76

77 78
/* Macro to check current context */
#if RT_DEBUG_CONTEXT_CHECK
79 80 81 82 83 84 85 86 87 88 89 90 91
#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)
92 93
#else
#define RT_DEBUG_NOT_IN_INTERRUPT
94
#endif
95

96 97 98
#else /* RT_DEBUG */

#define RT_ASSERT(EX)
99
#define RT_DEBUG_LOG(type, message)
100
#define RT_DEBUG_NOT_IN_INTERRUPT
101 102 103 104

#endif /* RT_DEBUG */

#endif /* __RTDEBUG_H__ */