Add function to check for ISR context

Add the function core_util_in_isr() so code can determine if it is
running in the context of an ISR.
pull/4389/head
Russ Butler 2017-05-24 16:29:11 -05:00 committed by Russ Butler
parent 5f138810a9
commit 5ab3de0bfa
2 changed files with 27 additions and 0 deletions

View File

@ -37,6 +37,22 @@ bool core_util_are_interrupts_enabled(void)
#endif
}
bool core_util_is_isr_active(void)
{
#if defined(__CORTEX_A9)
switch(__get_CPSR() & 0x1FU) {
case MODE_USR:
case MODE_SYS:
return false;
case MODE_SVC:
default:
return true;
}
#else
return (__get_IPSR() != 0U);
#endif
}
MBED_WEAK void core_util_critical_section_enter(void)
{
bool interrupts_disabled = !core_util_are_interrupts_enabled();

View File

@ -41,6 +41,17 @@ extern "C" {
*/
bool core_util_are_interrupts_enabled(void);
/** Determine if this code is executing from an interrupt
*
* This function can be called to determine if the code is running on interrupt context.
* @note
* NOTE:
* This function works for both cortex-A and cortex-M, although the underlyng implementation
* differs.
* @return true if in an isr, false otherwise
*/
bool core_util_is_isr_active(void);
/** Mark the start of a critical section
*
* This function should be called to mark the start of a critical section of code.