2009-07-03 06:48:23 +08:00
|
|
|
/*
|
|
|
|
* File : irq.c
|
|
|
|
* This file is part of RT-Thread RTOS
|
2012-03-17 14:43:49 +08:00
|
|
|
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
|
2009-07-03 06:48:23 +08:00
|
|
|
*
|
2013-06-24 17:06:09 +08:00
|
|
|
* 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.
|
2009-07-03 06:48:23 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2006-02-24 Bernard first version
|
|
|
|
* 2006-05-03 Bernard add IRQ_DEBUG
|
2016-08-09 11:29:11 +08:00
|
|
|
* 2016-08-09 ArdaFu add interrupt enter and leave hook.
|
2009-07-03 06:48:23 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rthw.h>
|
|
|
|
#include <rtthread.h>
|
|
|
|
|
2016-08-09 11:29:11 +08:00
|
|
|
#ifdef RT_USING_HOOK
|
|
|
|
|
|
|
|
static void (*rt_interrupt_enter_hook)(void);
|
|
|
|
static void (*rt_interrupt_leave_hook)(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup Hook
|
|
|
|
* This function set a hook function when the system enter a interrupt
|
|
|
|
*
|
|
|
|
* @note the hook function must be simple and never be blocked or suspend.
|
|
|
|
*/
|
|
|
|
void rt_interrupt_enter_sethook(void (*hook)(void))
|
|
|
|
{
|
|
|
|
rt_interrupt_enter_hook = hook;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @ingroup Hook
|
|
|
|
* This function set a hook function when the system exit a interrupt.
|
|
|
|
*
|
|
|
|
* @note the hook function must be simple and never be blocked or suspend.
|
|
|
|
*/
|
|
|
|
void rt_interrupt_leave_sethook(void (*hook)(void))
|
|
|
|
{
|
|
|
|
rt_interrupt_leave_hook = hook;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
/* #define IRQ_DEBUG */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup Kernel
|
|
|
|
*/
|
|
|
|
|
2016-08-19 10:08:35 +08:00
|
|
|
/**@{*/
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2010-03-09 07:09:40 +08:00
|
|
|
volatile rt_uint8_t rt_interrupt_nest;
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2011-09-21 11:56:42 +08:00
|
|
|
void rt_interrupt_enter(void)
|
2009-07-03 06:48:23 +08:00
|
|
|
{
|
2012-12-21 11:33:25 +08:00
|
|
|
rt_base_t level;
|
2009-12-25 20:18:53 +08:00
|
|
|
|
2012-12-21 11:33:25 +08:00
|
|
|
RT_DEBUG_LOG(RT_DEBUG_IRQ, ("irq coming..., irq nest:%d\n",
|
2012-12-20 15:25:19 +08:00
|
|
|
rt_interrupt_nest));
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2012-12-21 11:33:25 +08:00
|
|
|
level = rt_hw_interrupt_disable();
|
|
|
|
rt_interrupt_nest ++;
|
2016-08-09 11:29:11 +08:00
|
|
|
RT_OBJECT_HOOK_CALL(rt_interrupt_enter_hook,());
|
2012-12-21 11:33:25 +08:00
|
|
|
rt_hw_interrupt_enable(level);
|
2009-07-03 06:48:23 +08:00
|
|
|
}
|
2013-01-08 21:05:02 +08:00
|
|
|
RTM_EXPORT(rt_interrupt_enter);
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2011-09-21 11:56:42 +08:00
|
|
|
void rt_interrupt_leave(void)
|
2009-07-03 06:48:23 +08:00
|
|
|
{
|
2012-12-21 11:33:25 +08:00
|
|
|
rt_base_t level;
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2012-12-21 11:33:25 +08:00
|
|
|
RT_DEBUG_LOG(RT_DEBUG_IRQ, ("irq leave, irq nest:%d\n",
|
|
|
|
rt_interrupt_nest));
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2012-12-21 11:33:25 +08:00
|
|
|
level = rt_hw_interrupt_disable();
|
|
|
|
rt_interrupt_nest --;
|
2016-08-09 11:29:11 +08:00
|
|
|
RT_OBJECT_HOOK_CALL(rt_interrupt_leave_hook,());
|
2012-12-21 11:33:25 +08:00
|
|
|
rt_hw_interrupt_enable(level);
|
2011-06-15 07:59:42 +08:00
|
|
|
}
|
2013-01-08 21:05:02 +08:00
|
|
|
RTM_EXPORT(rt_interrupt_leave);
|
2011-06-12 18:01:48 +08:00
|
|
|
|
2011-06-15 07:59:42 +08:00
|
|
|
/**
|
|
|
|
* This function will return the nest of interrupt.
|
2013-06-24 17:06:09 +08:00
|
|
|
*
|
2012-06-18 20:21:03 +08:00
|
|
|
* User application can invoke this function to get whether current
|
2011-06-15 07:59:42 +08:00
|
|
|
* context is interrupt context.
|
2013-06-24 17:06:09 +08:00
|
|
|
*
|
2011-06-15 07:59:42 +08:00
|
|
|
* @return the number of nested interrupts.
|
|
|
|
*/
|
|
|
|
rt_uint8_t rt_interrupt_get_nest(void)
|
|
|
|
{
|
2012-12-21 11:33:25 +08:00
|
|
|
return rt_interrupt_nest;
|
2009-07-03 06:48:23 +08:00
|
|
|
}
|
2013-01-08 21:05:02 +08:00
|
|
|
RTM_EXPORT(rt_interrupt_get_nest);
|
|
|
|
|
|
|
|
RTM_EXPORT(rt_hw_interrupt_disable);
|
|
|
|
RTM_EXPORT(rt_hw_interrupt_enable);
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2016-08-19 10:08:35 +08:00
|
|
|
/**@}*/
|
2011-06-15 07:59:42 +08:00
|
|
|
|