Update function get_interrupts_disabled() to return a bool value rather

than an integer. This removes the need for all users to mask the returned
value with 0x1 to determine interrupt status.
Expose this function externally to allow other users to check interrupt
status in a manner which will work for both cortex-A and cortex-M .
Usage:
bool disabled = get_interrupts_disabled();
pull/1883/head
Anna Bridge 2016-06-08 18:41:19 +01:00
parent 9197f94f14
commit 9f052bc500
2 changed files with 21 additions and 9 deletions

View File

@ -24,6 +24,18 @@
extern "C" {
#endif
/** Determine the current interrupts disabled state
*
* This function can be called to determine whether or not interrupts are currently disabled.
* \note
* NOTE:
* This function works for both cortex-A and cortex-M, although the underlyng implementation
* differs.
* @return true if interrupts are disabled, false otherwise
*/
bool get_interrupts_disabled(void);
/** Mark the start of a critical section
*
* This function should be called to mark the start of a critical section of code.

View File

@ -27,26 +27,26 @@
#define EXCLUSIVE_ACCESS (!defined (__CORTEX_M0) && !defined (__CORTEX_M0PLUS))
static volatile uint32_t interrupt_enable_counter = 0;
static volatile uint32_t critical_interrupts_disabled = 0;
static volatile bool critical_interrupts_disabled = false;
static inline uint32_t get_interrupts_disabled(void)
bool get_interrupts_disabled(void)
{
#if defined(__CORTEX_A9)
uint32_t interrupts_disabled = (__get_CPSR() & 0x80) >> 7;
bool interrupts_disabled = (bool)(((__get_CPSR() & 0x80) >> 7) & 0x1);
#else
uint32_t interrupts_disabled = __get_PRIMASK();
bool interrupts_disabled = (bool)(__get_PRIMASK() & 0x1);
#endif
return interrupts_disabled;
}
void core_util_critical_section_enter()
{
uint32_t interrupts_disabled = get_interrupts_disabled();
bool interrupts_disabled = get_interrupts_disabled();
__disable_irq();
/* Save the interrupt disabled state as it was prior to any nested critical section lock use */
if (!interrupt_enable_counter) {
critical_interrupts_disabled = interrupts_disabled & 0x1;
critical_interrupts_disabled = interrupts_disabled;
}
/* If the interrupt_enable_counter overflows or we are in a nested critical section and interrupts
@ -56,7 +56,7 @@ void core_util_critical_section_enter()
// FIXME
#ifndef FEATURE_UVISOR
if (interrupt_enable_counter > 0) {
MBED_ASSERT(interrupts_disabled & 0x1);
MBED_ASSERT(interrupts_disabled);
}
#else
#warning "core_util_critical_section_enter needs fixing to work from unprivileged code"
@ -71,9 +71,9 @@ void core_util_critical_section_exit()
// FIXME
#ifndef FEATURE_UVISOR
uint32_t interrupts_disabled = get_interrupts_disabled(); /* get the current interrupt disabled state */
bool interrupts_disabled = get_interrupts_disabled(); /* get the current interrupt disabled state */
MBED_ASSERT(interrupts_disabled & 0x1); /* Interrupts must be disabled on invoking an exit from a critical section */
MBED_ASSERT(interrupts_disabled); /* Interrupts must be disabled on invoking an exit from a critical section */
#else
#warning "core_util_critical_section_exit needs fixing to work from unprivileged code"
#endif /* FEATURE_UVISOR */