2727#define EXCLUSIVE_ACCESS (!defined (__CORTEX_M0) && !defined (__CORTEX_M0PLUS))
2828
2929static volatile uint32_t interrupt_enable_counter = 0 ;
30- static volatile uint32_t critical_interrupts_disabled = 0 ;
30+ static volatile bool critical_interrupts_disabled = false ;
3131
32- static inline uint32_t get_interrupts_disabled (void )
32+ bool core_util_are_interrupts_enabled (void )
3333{
3434#if defined(__CORTEX_A9 )
35- uint32_t interrupts_disabled = ( __get_CPSR () & 0x80 ) >> 7 ;
35+ return (( __get_CPSR () & 0x80 ) == 0 ) ;
3636#else
37- uint32_t interrupts_disabled = __get_PRIMASK ( );
37+ return (( __get_PRIMASK () & 0x1 ) == 0 );
3838#endif
39- return interrupts_disabled ;
4039}
4140
4241void core_util_critical_section_enter ()
4342{
44- uint32_t interrupts_disabled = get_interrupts_disabled ();
43+ bool interrupts_disabled = ! core_util_are_interrupts_enabled ();
4544 __disable_irq ();
4645
4746 /* Save the interrupt disabled state as it was prior to any nested critical section lock use */
4847 if (!interrupt_enable_counter ) {
49- critical_interrupts_disabled = interrupts_disabled & 0x1 ;
48+ critical_interrupts_disabled = interrupts_disabled ;
5049 }
5150
5251 /* If the interrupt_enable_counter overflows or we are in a nested critical section and interrupts
@@ -56,7 +55,7 @@ void core_util_critical_section_enter()
5655// FIXME
5756#ifndef FEATURE_UVISOR
5857 if (interrupt_enable_counter > 0 ) {
59- MBED_ASSERT (interrupts_disabled & 0x1 );
58+ MBED_ASSERT (interrupts_disabled );
6059 }
6160#else
6261#warning "core_util_critical_section_enter needs fixing to work from unprivileged code"
@@ -71,9 +70,9 @@ void core_util_critical_section_exit()
7170
7271// FIXME
7372#ifndef FEATURE_UVISOR
74- uint32_t interrupts_disabled = get_interrupts_disabled (); /* get the current interrupt disabled state */
73+ bool interrupts_disabled = ! core_util_are_interrupts_enabled (); /* get the current interrupt disabled state */
7574
76- MBED_ASSERT (interrupts_disabled & 0x1 ); /* Interrupts must be disabled on invoking an exit from a critical section */
75+ MBED_ASSERT (interrupts_disabled ); /* Interrupts must be disabled on invoking an exit from a critical section */
7776#else
7877#warning "core_util_critical_section_exit needs fixing to work from unprivileged code"
7978#endif /* FEATURE_UVISOR */
0 commit comments