irq.c 1.9 KB
Newer Older
1 2 3
/*
 * File      : irq.c
 * This file is part of RT-Thread RTOS
D
dzzxzz 已提交
4
 * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
5 6 7
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
B
bernard.xiong 已提交
8
 * http://www.rt-thread.org/license/LICENSE
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 * Change Logs:
 * Date           Author       Notes
 * 2006-02-24     Bernard      first version
 * 2006-05-03     Bernard      add IRQ_DEBUG
 */

#include <rthw.h>
#include <rtthread.h>

/* #define IRQ_DEBUG */

/**
 * @addtogroup Kernel
 */

/*@{*/

27
volatile rt_uint8_t rt_interrupt_nest;
28 29 30 31 32 33 34 35

/**
 * This function will be invoked by BSP, when enter interrupt service routine
 *
 * @note please don't invoke this routine in application
 *
 * @see rt_interrupt_leave
 */
D
dzzxzz 已提交
36
void rt_interrupt_enter(void)
37
{
D
dzzxzz@gmail.com 已提交
38
    rt_base_t level;
B
bernard.xiong 已提交
39

D
dzzxzz@gmail.com 已提交
40
    RT_DEBUG_LOG(RT_DEBUG_IRQ, ("irq coming..., irq nest:%d\n",
41
                                rt_interrupt_nest));
42

D
dzzxzz@gmail.com 已提交
43 44 45
    level = rt_hw_interrupt_disable();
    rt_interrupt_nest ++;
    rt_hw_interrupt_enable(level);
46
}
47
RTM_EXPORT(rt_interrupt_enter);
48 49 50 51 52 53 54 55

/**
 * This function will be invoked by BSP, when leave interrupt service routine
 *
 * @note please don't invoke this routine in application
 *
 * @see rt_interrupt_enter
 */
D
dzzxzz 已提交
56
void rt_interrupt_leave(void)
57
{
D
dzzxzz@gmail.com 已提交
58
    rt_base_t level;
59

D
dzzxzz@gmail.com 已提交
60 61
    RT_DEBUG_LOG(RT_DEBUG_IRQ, ("irq leave, irq nest:%d\n",
                                rt_interrupt_nest));
62

D
dzzxzz@gmail.com 已提交
63 64 65
    level = rt_hw_interrupt_disable();
    rt_interrupt_nest --;
    rt_hw_interrupt_enable(level);
66
}
67
RTM_EXPORT(rt_interrupt_leave);
68

69 70 71
/**
 * This function will return the nest of interrupt.
 * 
D
dzzxzz@gmail.com 已提交
72
 * User application can invoke this function to get whether current
73 74 75 76 77 78
 * context is interrupt context.
 * 
 * @return the number of nested interrupts.
 */
rt_uint8_t rt_interrupt_get_nest(void)
{
D
dzzxzz@gmail.com 已提交
79
    return rt_interrupt_nest;
80
}
81 82 83 84
RTM_EXPORT(rt_interrupt_get_nest);

RTM_EXPORT(rt_hw_interrupt_disable);
RTM_EXPORT(rt_hw_interrupt_enable);
85 86

/*@}*/
87