27
27
#define EXCLUSIVE_ACCESS (!defined (__CORTEX_M0) && !defined (__CORTEX_M0PLUS))
28
28
29
29
static volatile uint32_t interrupt_enable_counter = 0 ;
30
- static volatile uint32_t critical_interrupts_disabled = 0 ;
30
+ static volatile bool critical_interrupts_disabled = false ;
31
31
32
- static inline uint32_t get_interrupts_disabled (void )
32
+ bool core_util_are_interrupts_enabled (void )
33
33
{
34
34
#if defined(__CORTEX_A9 )
35
- uint32_t interrupts_disabled = ( __get_CPSR () & 0x80 ) >> 7 ;
35
+ return (( __get_CPSR () & 0x80 ) == 0 ) ;
36
36
#else
37
- uint32_t interrupts_disabled = __get_PRIMASK ( );
37
+ return (( __get_PRIMASK () & 0x1 ) == 0 );
38
38
#endif
39
- return interrupts_disabled ;
40
39
}
41
40
42
41
void core_util_critical_section_enter ()
43
42
{
44
- uint32_t interrupts_disabled = get_interrupts_disabled ();
43
+ bool interrupts_disabled = ! core_util_are_interrupts_enabled ();
45
44
__disable_irq ();
46
45
47
46
/* Save the interrupt disabled state as it was prior to any nested critical section lock use */
48
47
if (!interrupt_enable_counter ) {
49
- critical_interrupts_disabled = interrupts_disabled & 0x1 ;
48
+ critical_interrupts_disabled = interrupts_disabled ;
50
49
}
51
50
52
51
/* 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()
56
55
// FIXME
57
56
#ifndef FEATURE_UVISOR
58
57
if (interrupt_enable_counter > 0 ) {
59
- MBED_ASSERT (interrupts_disabled & 0x1 );
58
+ MBED_ASSERT (interrupts_disabled );
60
59
}
61
60
#else
62
61
#warning "core_util_critical_section_enter needs fixing to work from unprivileged code"
@@ -71,9 +70,9 @@ void core_util_critical_section_exit()
71
70
72
71
// FIXME
73
72
#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 */
75
74
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 */
77
76
#else
78
77
#warning "core_util_critical_section_exit needs fixing to work from unprivileged code"
79
78
#endif /* FEATURE_UVISOR */
0 commit comments