Skip to content

Commit 2292794

Browse files
committed
Reverse the logic to get_interrupts_disabled() to are_interrupts_enabled()
and update the using functions accordingly. Usage: bool interrupts_enabled = are_interrupts_enabled() Remove superfluos shift in are_interrupts_enabled().
1 parent 9f052bc commit 2292794

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

hal/api/critical.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ extern "C" {
2525
#endif
2626

2727

28-
/** Determine the current interrupts disabled state
28+
/** Determine the current interrupts enabled state
2929
*
30-
* This function can be called to determine whether or not interrupts are currently disabled.
30+
* This function can be called to determine whether or not interrupts are currently enabled.
3131
* \note
3232
* NOTE:
3333
* This function works for both cortex-A and cortex-M, although the underlyng implementation
3434
* differs.
35-
* @return true if interrupts are disabled, false otherwise
35+
* @return true if interrupts are enabled, false otherwise
3636
*/
37-
bool get_interrupts_disabled(void);
37+
bool are_interrupts_enabled(void);
3838

3939
/** Mark the start of a critical section
4040
*

hal/common/critical.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,18 @@
2929
static volatile uint32_t interrupt_enable_counter = 0;
3030
static volatile bool critical_interrupts_disabled = false;
3131

32-
bool get_interrupts_disabled(void)
32+
bool are_interrupts_enabled(void)
3333
{
3434
#if defined(__CORTEX_A9)
35-
bool interrupts_disabled = (bool)(((__get_CPSR() & 0x80) >> 7) & 0x1);
35+
return ((__get_CPSR() & 0x80) == 0);
3636
#else
37-
bool interrupts_disabled = (bool)(__get_PRIMASK() & 0x1);
37+
return ((__get_PRIMASK() & 0x1) == 0);
3838
#endif
39-
return interrupts_disabled;
4039
}
4140

4241
void core_util_critical_section_enter()
4342
{
44-
bool interrupts_disabled = get_interrupts_disabled();
43+
bool interrupts_disabled = !are_interrupts_enabled();
4544
__disable_irq();
4645

4746
/* Save the interrupt disabled state as it was prior to any nested critical section lock use */
@@ -71,7 +70,7 @@ void core_util_critical_section_exit()
7170

7271
// FIXME
7372
#ifndef FEATURE_UVISOR
74-
bool interrupts_disabled = get_interrupts_disabled(); /* get the current interrupt disabled state */
73+
bool interrupts_disabled = !are_interrupts_enabled(); /* get the current interrupt disabled state */
7574

7675
MBED_ASSERT(interrupts_disabled); /* Interrupts must be disabled on invoking an exit from a critical section */
7776
#else

0 commit comments

Comments
 (0)