Skip to content

Commit 5ab3de0

Browse files
committed
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.
1 parent 5f13881 commit 5ab3de0

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

platform/mbed_critical.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ bool core_util_are_interrupts_enabled(void)
3737
#endif
3838
}
3939

40+
bool core_util_is_isr_active(void)
41+
{
42+
#if defined(__CORTEX_A9)
43+
switch(__get_CPSR() & 0x1FU) {
44+
case MODE_USR:
45+
case MODE_SYS:
46+
return false;
47+
case MODE_SVC:
48+
default:
49+
return true;
50+
}
51+
#else
52+
return (__get_IPSR() != 0U);
53+
#endif
54+
}
55+
4056
MBED_WEAK void core_util_critical_section_enter(void)
4157
{
4258
bool interrupts_disabled = !core_util_are_interrupts_enabled();

platform/mbed_critical.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ extern "C" {
4141
*/
4242
bool core_util_are_interrupts_enabled(void);
4343

44+
/** Determine if this code is executing from an interrupt
45+
*
46+
* This function can be called to determine if the code is running on interrupt context.
47+
* @note
48+
* NOTE:
49+
* This function works for both cortex-A and cortex-M, although the underlyng implementation
50+
* differs.
51+
* @return true if in an isr, false otherwise
52+
*/
53+
bool core_util_is_isr_active(void);
54+
4455
/** Mark the start of a critical section
4556
*
4657
* This function should be called to mark the start of a critical section of code.

0 commit comments

Comments
 (0)